Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

LeptonMatrixManager.cxx

Go to the documentation of this file.
00001 #include "AtlfastAlgs/LeptonMatrixManager.h"
00002 
00003 #include "AtlfastAlgs/LeptonBinData.h"
00004 #include "AtlfastAlgs/CorrelatedData.h"
00005 
00006 namespace Atlfast{
00007   using std::map;
00008   using std::vector;
00009   using std::ifstream;
00010   using std::abs;
00011 
00012   //-----------------------------------------------------------
00013   // PUBLIC: Constructor
00014   //-----------------------------------------------------------
00015   LeptonMatrixManager::LeptonMatrixManager(string config, int randSeed,
00016                                        MsgStream& log):
00017     m_config(config), m_log(log){
00018     m_file = "Atlfast_id_resol_mu_";
00019     m_file.append(config);
00020     m_file.append(".dat");
00021     m_correlatedData = new CorrelatedData(randSeed);
00022     this->initialise();
00023     m_log << MSG::INFO << "Constructed LeptonMatrixManager with configuration "
00024            << m_config <<endreq;
00025   }
00026   
00027   
00028   //-----------------------------------------------------------
00029   // PUBLIC: Destructor
00030   //-----------------------------------------------------------
00031   
00032   LeptonMatrixManager::~LeptonMatrixManager(){
00033     map<BinID, IBinData*>::iterator iter = m_binData.begin();
00034     map<BinID, IBinData*>::iterator end = m_binData.end();
00035       for (; iter!=end;++iter)
00036       {
00037       delete (iter->second);  // Is this right(m_binData=vector<*>)????
00038       }
00039 
00040   }
00041   
00042   //------------------------------------------------------------
00043   // PRIVATE: initialise : read file and construct data bins
00044   //------------------------------------------------------------
00045   
00046   void LeptonMatrixManager::initialise(){
00047     // open file
00048     ifstream input;
00049     input.open( m_file.c_str() );
00050     if (input) {
00051       m_log << MSG::INFO 
00052              << "LeptonMatrixManager: file " 
00053              << m_file
00054              << " open." 
00055              << endreq;
00056       
00057       double data;
00058       int nEtaVals;
00059       int nPTVals;
00060       
00061       // prepare containers
00062       vector<double> etaBins;
00063       vector<double> pTBins;
00064       
00065       // the are four correlations between the 5 variables
00066       vector< pair<double,double> > correlOrder; 
00067       correlOrder.push_back(pair<double,double>(3,5)); // phi / pt
00068       correlOrder.push_back(pair<double,double>(1,5)); // d0 / pt
00069       correlOrder.push_back(pair<double,double>(1,3)); // d0 / phi
00070       correlOrder.push_back(pair<double,double>(2,4)); // z0 / cotTheta
00071       
00072       
00073       // read eta and phi values and store them
00074       input >> nEtaVals;
00075       for (int i=0; i < nEtaVals; i++) {
00076         input >> data;
00077         etaBins.push_back(data);
00078       }
00079       
00080       input >> nPTVals;
00081       for (int i=0; i < nPTVals; i++) {
00082         input >> data;
00083         pTBins.push_back(data);
00084       }
00085       
00086       //========================================
00087       // make 9 resolution parameters for matrix
00088       HepMatrix etaPMatrix(nEtaVals, nPTVals,0);
00089       //stores nine parameters for each eta/pt bin:
00090       vector<HepMatrix> resParameters(9, etaPMatrix); 
00091       
00092       // read sigmas and correlations
00093       for (int iEta=0; iEta < nEtaVals; iEta++) {
00094         for (int iPT=0; iPT < nPTVals; iPT++) {
00095           //sigmas (diagonals)
00096           for (int i = 0; i < 5; i++) {
00097             input >> data;
00098             resParameters[i][iEta][iPT] = data*data;
00099           }
00100           // correlations
00101           vector< pair<double,double> >::iterator iOrder = correlOrder.begin();
00102           for (int i = 5; i < 9; i++) {
00103             input >> data;
00104             resParameters[i][iEta][iPT] = 
00105               data * sqrt(resParameters[(iOrder->first)-1][iEta][iPT]) * 
00106               sqrt(resParameters[(iOrder->second)-1][iEta][iPT]);
00107             iOrder++;
00108           }
00109         }
00110       }// end of make ===========================
00111       
00112       
00113       // make bins
00114       HepMatrix twoSquare(2,2,0);
00115       vector<HepMatrix> interpol(9, twoSquare);
00116       double iBin = 0;    
00117       
00118       for (int iEta = 0; iEta < (nEtaVals-1); iEta++) {
00119         for (int iPT = 0; iPT < (nPTVals-1); iPT++) {
00120           
00121           for (int i=0; i<9; i++) {
00122             interpol[i] = resParameters[i].sub(iEta+1,iEta+2,iPT+1, iPT+2);
00123           }
00124           
00125           BinID id(iBin, etaBins[iEta], etaBins[iEta+1],
00126                    pTBins[iPT], pTBins[iPT+1]);
00127           // make bin
00128           IBinData* binData = new LeptonBinData(id, interpol);      
00129           // enter bin data into map
00130           m_binData[id] = binData;
00131           iBin++;
00132         }
00133       }
00134       HeaderPrinter hp("Atlfast LeptonTrack Smearer:", m_log);
00135       hp.add("Data file                ", m_file);        
00136       hp.add("configuration            ", m_config);        
00137       hp.add("Number of Eta Bins       ", nEtaVals-1);
00138       hp.add("Eta Min                  ", etaBins.front());
00139       hp.add("Eta Max                  ", etaBins.back());
00140       hp.add("Number of Pt  Bins       ", nPTVals-1);
00141       hp.add("pT Min                   ", pTBins.front());
00142       hp.add("pT Max                   ", pTBins.back());
00143       hp.print();
00144       
00145     }else{ 
00146       m_log << MSG::WARNING 
00147              << "LeptonMatrixManager: no data file ( "
00148              <<m_file<<" )!!!!" 
00149              << endreq;
00150     }
00151     
00152   }
00153   
00154   //-----------------------------------------------------------
00155   // PUBLIC: getVariables : returns the correlated smear variables
00156   //                        from the sigma matrix corresponding
00157   //                        to a given track trajectory
00158   //-----------------------------------------------------------
00159   vector<double> LeptonMatrixManager::getVariables(const TrackTrajectory& track, 
00160                                                  HepMatrix& returnSigma) const{
00161     vector<double> variables;
00162     HepMatrix sigma;
00163     IBinData* binData = getBinData(track);
00164     sigma = binData->getMatrix(track);
00165     // do Dcorset and Dcorgen to get smear parameters
00166 
00167     variables = m_correlatedData->generate(m_correlatedData->root(sigma));
00168     scale(sigma);
00169     returnSigma = sigma;
00170     scale(variables);
00171     return variables;
00172   }
00173   
00174   //----------------------------------------------------------
00175   // Private: Scale variables and matrix
00176   //----------------------------------------------------------
00177   void LeptonMatrixManager::scale(HepMatrix& sigma) const{
00178     sigma(1,1) /= 1e8;
00179     sigma(2,2) /= 1e8;
00180     sigma(3,3) /= 1e6;
00181     sigma(4,4) /= 1e6;
00182     sigma(5,5) /= 1e6;
00183     sigma(1,3) = sigma(3,1) /= 1e7;
00184     sigma(1,5) = sigma(5,1) /= 1e7;
00185     sigma(2,4) = sigma(4,2) /= 1e7;
00186     sigma(3,5) = sigma(5,3) /= 1e6;
00187   }
00188   
00189   void LeptonMatrixManager::scale(vector<double>& variables) const{
00190     variables[0] /= 1e4;
00191     variables[1] /= 1e4;
00192     variables[2] /= 1e3;
00193     variables[3] /= 1e3;
00194     variables[4] /= 1e3;
00195   }
00196   
00197   
00198   //-----------------------------------------------------------
00199   // Private: getBinID : returns the BinID of bin corresponding
00200   //                     to a given track trajectory
00201   //-----------------------------------------------------------
00202   IBinData* LeptonMatrixManager::getBinData(const TrackTrajectory& track) const{
00203 
00204     TrackParameters traj = track.parameters();
00205     vector<double> etaPT;
00206     double eta = abs( traj.eta() ) ;
00207     double pT= abs( traj.pT() );
00208 
00209     // validity check
00210     double etaLow = ( (m_binData.begin())->first ).low(0);
00211     double etaHigh = ( (m_binData.rbegin())->first ).high(0);
00212     double pTLow = ( (m_binData.begin())->first ).low(1);
00213     double pTHigh = ( (m_binData.rbegin())->first ).high(1);
00214     if ( eta < etaLow ) eta = etaLow;
00215     if ( eta > etaHigh) eta = etaHigh;  
00216     if ( pT < pTLow ) pT = pTLow;
00217     if ( pT > pTHigh) pT = pTHigh;  
00218 
00219     // find BinID
00220     etaPT.push_back( eta );
00221     etaPT.push_back( pT );
00222     
00223     map<BinID, IBinData*>::const_iterator binIter = m_binData.begin();
00224     map<BinID, IBinData*>::const_iterator binEnd = m_binData.end();
00225 
00226     for (; binIter != binEnd; ++binIter){
00227       if (binIter->first.isInBin(etaPT)) return binIter->second;
00228     } 
00229     // OOPS! couldn't fin bin
00230     cout << "WARNING: LeptonMatrixManager - No bin; eta "<< eta <<", pT "<<pT<<endl;
00231     return (m_binData.begin())->second;
00232   }
00233   
00234   
00235 }// namespace

Generated on Tue Mar 18 11:18:24 2003 for AtlfastAlgs by doxygen1.3-rc1