MuonMatrixManager.cxx

Go to the documentation of this file.
00001 #include "AtlfastAlgs/MuonMatrixManager.h"
00002 #include "PathResolver/PathResolver.h"
00003 #include <iostream>
00004 
00005 namespace Atlfast
00006 {
00007   using std::abs;
00008   using std::ifstream;
00009 
00010   //-----------------------------------------------------------
00011   // PUBLIC: Constructor
00012   //-----------------------------------------------------------
00013   MuonMatrixManager::MuonMatrixManager( string paramFile, int randSeed, MsgStream log ) : 
00014        m_file( paramFile ), 
00015        m_randSeed( randSeed )
00016   {
00017     m_log = &log;
00018     *m_log << MSG::INFO 
00019            << "Constructing MuonMatrixManager with parameter file " 
00020            << paramFile 
00021            << endreq;
00022     m_file = PathResolver::find_file( m_file, "DATAPATH" );
00023     m_correlatedData = new CorrelatedData(randSeed);
00024     this->initialise();
00025     *m_log << MSG::INFO << "Constructed MuonMatrixManager" << endreq;
00026   }
00027   
00028   
00029   //-----------------------------------------------------------
00030   // PUBLIC: Destructor
00031   //-----------------------------------------------------------
00032   MuonMatrixManager::~MuonMatrixManager()
00033   {
00034     delete m_correlatedData;
00035 
00036     map< BinID, IBinData* >::iterator iter = m_binData.begin();
00037     map< BinID, IBinData* >::iterator end  = m_binData.end();
00038     for ( ; iter != end; ++iter )  delete ( iter->second ); 
00039   }
00040   
00041   //------------------------------------------------------------
00042   // PRIVATE: initialise : read file and construct data bins
00043   //------------------------------------------------------------
00044   void MuonMatrixManager::initialise()
00045   {
00046     // open file
00047     ifstream input;
00048     input.open( m_file.c_str() );
00049     
00050     if (input) 
00051     {
00052       *m_log << MSG::INFO << "MuonMatrixManager: File " << m_file << " open." << endreq;
00053       
00054       double pTMin, etaMin, etaMax, rTBoundary;
00055       
00056       // read some parameters
00057       input >> pTMin;
00058       input >> etaMin;
00059       input >> etaMax;
00060       input >> m_nEtaBins;
00061       input >> m_nRTBins;
00062       
00063       // construct vector<binboundaries>
00064       double etaStep = ( etaMax - etaMin )/ double( m_nEtaBins );
00065       for ( int i = 0; i < m_nEtaBins; i++ )
00066       { 
00067         m_etaBoundaries.push_back( etaMin + etaStep/2. + double(i)*etaStep );
00068       }
00069       for ( int i = 0; i < m_nRTBins + 1; i++ )
00070       {
00071         input >> rTBoundary;
00072         m_rTBoundaries.push_back( rTBoundary );
00073       }
00074       
00075       // parameters are stored in rT bin blocks----
00076       // with parameters in format:
00077       // Gaussian sigmas: 
00078       //              C0(d0, z0, phi0, cot(theta0), q/pT), 
00079       //              C1(d0, z0, phi0, cot(theta0), q/pT), etc.
00080       // correlation coefficients rho: 
00081       //              C0(rho(d0,phi0), rho(d0,q/pT), rho(phi0,q/pT), rho(z0,cot(theta0))), 
00082       //              C1(rho(d0,phi0), rho(d0,q/pT), rho(phi0,q/pT), rho(z0,cot(theta0))), etc.
00083       //
00084       // coefficients C0,C1,C2,C3,C4 define pT-dependence of the respective quantities
00085       // according to f(pT) = C0 + C1/sqrt(pT) + C2/pT + C3/pT/sqrt(pT) + C4/pT^2
00086 
00087       // start bin id ints at zero
00088       int iBin = 0; 
00089       
00090       for ( int rt = 0; rt < m_nRTBins; rt++ )
00091       {
00092         // make vectors to hold all resolution parameters for this rt bin
00093         vector<double> empty;
00094         vector< vector<double> >  sigmaC0( m_nEtaBins, empty ); 
00095         vector< vector<double> >  sigmaC1( m_nEtaBins, empty );
00096         vector< vector<double> >  sigmaC2( m_nEtaBins, empty );
00097         vector< vector<double> >  sigmaC3( m_nEtaBins, empty );
00098         vector< vector<double> >  sigmaC4( m_nEtaBins, empty );
00099         vector< vector<double> >  correlationsC0( m_nEtaBins, empty );
00100         vector< vector<double> >  correlationsC1( m_nEtaBins, empty );
00101         vector< vector<double> >  correlationsC2( m_nEtaBins, empty );
00102         vector< vector<double> >  correlationsC3( m_nEtaBins, empty );
00103         vector< vector<double> >  correlationsC4( m_nEtaBins, empty );
00104         
00105         // read eta bin number of values for each C and parameter
00106         // read Gaussian sigmas
00107         fillVector( input, sigmaC0, 5 );
00108         fillVector( input, sigmaC1, 5 );
00109         fillVector( input, sigmaC2, 5 );
00110         fillVector( input, sigmaC3, 5 );
00111         fillVector( input, sigmaC4, 5 );
00112         // read correlations data
00113         fillVector( input, correlationsC0, 4 );
00114         fillVector( input, correlationsC1, 4 );
00115         fillVector( input, correlationsC2, 4 );
00116         fillVector( input, correlationsC3, 4 );
00117         fillVector( input, correlationsC4, 4 );
00118         
00119         // DATA READING FINISHED FOR THIS RT BIN
00120         // got all values, now make rT/eta bins and resolution objects
00121         for ( int i = 0; i < m_nEtaBins - 1; ++i ) 
00122         {         
00123           double etaLow  = m_etaBoundaries[i];
00124           double etaHigh = m_etaBoundaries[i+1];
00125           
00126           // make bin id with rT and eta boundaries
00127           BinID rTEtaBin( iBin, m_rTBoundaries[rt], m_rTBoundaries[rt+1], etaLow, etaHigh );
00128           
00129           //make parameter resolutions for each parameter
00130           vector<ParameterResolutions*> sigmas;
00131           vector<ParameterResolutions*> correlations;
00132           for ( int param = 0; param < 5; param++ ) 
00133           {
00134              vector<BinID> sigmaCoeffBins;
00135              sigmaCoeffBins.push_back( BinID( 0, sigmaC0[i][param], sigmaC0[i+1][param] ) );
00136              sigmaCoeffBins.push_back( BinID( 0, sigmaC1[i][param], sigmaC1[i+1][param] ) );
00137              sigmaCoeffBins.push_back( BinID( 0, sigmaC2[i][param], sigmaC2[i+1][param] ) );
00138              sigmaCoeffBins.push_back( BinID( 0, sigmaC3[i][param], sigmaC3[i+1][param] ) );
00139              sigmaCoeffBins.push_back( BinID( 0, sigmaC4[i][param], sigmaC4[i+1][param] ) );
00140              sigmas.push_back( new ParameterResolutions( sigmaCoeffBins, etaLow, etaHigh ) );
00141           }
00142           for ( int param = 0; param < 4; param++ ) 
00143           {
00144             vector<BinID> correlationsCoeffBins;
00145             correlationsCoeffBins.push_back( BinID( 0, correlationsC0[i][param], correlationsC0[i+1][param]) );
00146             correlationsCoeffBins.push_back( BinID( 0, correlationsC1[i][param], correlationsC1[i+1][param]) );
00147             correlationsCoeffBins.push_back( BinID( 0, correlationsC2[i][param], correlationsC2[i+1][param]) );
00148             correlationsCoeffBins.push_back( BinID( 0, correlationsC3[i][param], correlationsC3[i+1][param]) );
00149             correlationsCoeffBins.push_back( BinID( 0, correlationsC4[i][param], correlationsC4[i+1][param]) );
00150             correlations.push_back( new ParameterResolutions( correlationsCoeffBins, etaLow, etaHigh ) );
00151           }
00152           
00153           // Now make a bin data with edges rT and eta, containing the 
00154           // correlation data
00155           MuonBinData* binData = new MuonBinData( rTEtaBin, sigmas, correlations );
00156           
00157           // enter bin data into map
00158           m_binData[rTEtaBin] = binData;
00159           
00160           // increment bin ID
00161           iBin++;
00162           
00163         } // end of eta bin loop
00164       } // end of rT bin loop
00165 
00166       // close file
00167       input.close();
00168       
00169     }
00170     else  // no input file 
00171     { 
00172       *m_log << MSG::INFO 
00173              << "MuonMatrixManager: no data file ( " << m_file << " )!!!!" 
00174              << endreq;
00175     }
00176     
00177     makeHeader();
00178     
00179   }
00180   
00181   void MuonMatrixManager::makeHeader()
00182   {
00183     HeaderPrinter hp( "Atlfast MuonTrack Smearer:", *m_log );
00184     hp.add( "Total number of Bins     ", m_nRTBins * m_nEtaBins );
00185     hp.add( "rT Bin Min               ", m_rTBoundaries.front() );        
00186     hp.add( "rT Bin Max               ", m_rTBoundaries.back() );
00187     hp.add( "Number of rT Bins        ", m_nRTBins );
00188     hp.add( "Eta Bin Min              ", m_etaBoundaries.front() );        
00189     hp.add( "Eta Bin Max              ", m_etaBoundaries.back() );
00190     hp.add( "Number of Eta Bins       ", m_nEtaBins );
00191     hp.print();
00192   }
00193   
00194   //-----------------------------------------------------------
00195   // PRIVATE: fillVector
00196   //             reads n x M parameters into member variable
00197   //-----------------------------------------------------------
00198   void MuonMatrixManager::fillVector( ifstream& input, 
00199                                         vector< vector<double> >& myVector, 
00200                                         int M=5 )
00201   {
00202     double res;
00203     for ( int param = 0; param < M; param++ ) 
00204     { 
00205       vector< vector<double> >::iterator binIter = myVector.begin();
00206       for ( ; binIter != myVector.end(); binIter++ )
00207       {
00208         input >> res;
00209         binIter->push_back(res);
00210       } 
00211     }
00212   }
00213   
00214  
00215   //-----------------------------------------------------------
00216   // PUBLIC: getMatrix : returns the Sigma (=covariance) matrix 
00217   //                  corresponding to a given track trajectory
00218   //-----------------------------------------------------------
00219   vector<double> MuonMatrixManager::getVariables( const TrackTrajectory& track,
00220                                                     HepSymMatrix& returnSigma ) const
00221   {
00222     HepSymMatrix Sigma;
00223     vector<double> variables;
00224 
00225     IBinData* binData = getBinData(track);
00226     Sigma = binData->getMatrix(track);
00227     
00228     // do Dcorset and Dcorgen to get smear parameters
00229     variables = m_correlatedData->generate( m_correlatedData->root(Sigma) );
00230     
00231     returnSigma = Sigma;
00232     return variables;
00233   }
00234   
00235   
00236   //-----------------------------------------------------------
00237   // Private: getBinData : returns the IBinData of bin 
00238   //                 corresponding to a given track trajectory
00239   //-----------------------------------------------------------
00240   IBinData* MuonMatrixManager::getBinData( const TrackTrajectory& traj ) const
00241   {
00242     TrackParameters track = traj.parameters();
00243 
00244     vector<double> rTEta;
00245     double rT  = abs( traj.radius() );
00246     double eta = abs( track.eta() );
00247 
00248     // validity check
00249     double rTLow   = ( (m_binData.begin())->first ).low(0);
00250     double rTHigh  = ( (m_binData.rbegin())->first ).high(0);
00251     double etaLow  = ( (m_binData.begin())->first ).low(1);
00252     double etaHigh = ( (m_binData.rbegin())->first ).high(1);
00253 
00254     if ( rT < rTLow ) rT = rTLow;
00255     if ( rT > rTHigh) rT = rTHigh;  
00256     if ( eta < etaLow ) eta = etaLow;
00257     if ( eta > etaHigh) eta = etaHigh;  
00258 
00259     // find BinID
00260     rTEta.push_back(rT);
00261     rTEta.push_back(eta);
00262 
00263     map<BinID, IBinData*>::const_iterator binIter = m_binData.begin();
00264     map<BinID, IBinData*>::const_iterator binEnd  = m_binData.end();
00265 
00266     for ( ; binIter != binEnd; ++binIter )
00267     {
00268       if ( binIter->first.isInBin(rTEta) ) 
00269       {
00270         return binIter->second;
00271       }
00272     }
00273     
00274     // OOPS! couldn't fin bin
00275     *m_log << MSG::WARNING 
00276            << "WARNING: MuonMatrixManager - No bin; rT " << rT << ", eta " << eta 
00277            << endreq;
00278 
00279     return ( m_binData.begin() )->second;
00280   }
00281   
00282 }// namespace

Generated on Mon Sep 24 14:19:12 2007 for AtlfastAlgs by  doxygen 1.5.1