00001 #include "AtlfastAlgs/BremMatrixManager.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
00012
00013 BremMatrixManager::BremMatrixManager( 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 BremMatrixManager with parameter file "
00020 << m_file
00021 << endreq;
00022 m_file = PathResolver::find_file( m_file, "DATAPATH" );
00023 this->initialise();
00024 *m_log << MSG::INFO << "Constructed BremMatrixManager" << endreq;
00025 }
00026
00027
00028
00029
00030
00031 BremMatrixManager::~BremMatrixManager()
00032 {
00033 map<BinID, BremBinData*>::iterator iter = m_binData.begin();
00034 map<BinID, BremBinData*>::iterator end = m_binData.end();
00035 for ( ; iter != end; ++iter )
00036 {
00037 delete ( iter->second );
00038 }
00039 }
00040
00041
00042
00043
00044 void BremMatrixManager::initialise()
00045 {
00046
00047 ifstream input;
00048 input.open( m_file.c_str() );
00049
00050 if (input)
00051 {
00052 *m_log << MSG::INFO << "BremMatrixManager: File " << m_file << " open." << endreq;
00053
00054 double pTMin, etaMin, etaMax, rtBoundary;
00055
00056
00057 input >> pTMin;
00058 input >> etaMin;
00059 input >> etaMax;
00060 input >> m_nEtaBins;
00061 input >> m_nRTBins;
00062
00063
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
00070 for ( int i = 0; i < m_nRTBins + 1; i++ )
00071 {
00072 input >> rtBoundary;
00073 m_rTBoundaries.push_back(rtBoundary);
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 int iBin = 0;
00090
00091 for ( int rt = 0; rt < m_nRTBins; rt++ )
00092 {
00093
00094 vector<double> empty;
00095
00096 vector< vector<double> > startPointsC0( m_nEtaBins, empty );
00097 vector< vector<double> > startPointsC1( m_nEtaBins, empty );
00098 vector< vector<double> > startPointsC2( m_nEtaBins, empty );
00099 vector< vector<double> > startPointsC3( m_nEtaBins, empty );
00100 vector< vector<double> > startPointsC4( m_nEtaBins, empty );
00101
00102 vector< vector<double> > slopesC0( m_nEtaBins, empty );
00103 vector< vector<double> > slopesC1( m_nEtaBins, empty );
00104 vector< vector<double> > slopesC2( m_nEtaBins, empty );
00105 vector< vector<double> > slopesC3( m_nEtaBins, empty );
00106 vector< vector<double> > slopesC4( m_nEtaBins, empty );
00107
00108 vector< vector<double> > sigmasC0( m_nEtaBins, empty );
00109 vector< vector<double> > sigmasC1( m_nEtaBins, empty );
00110 vector< vector<double> > sigmasC2( m_nEtaBins, empty );
00111 vector< vector<double> > sigmasC3( m_nEtaBins, empty );
00112 vector< vector<double> > sigmasC4( m_nEtaBins, empty );
00113
00114
00115
00116 fillVector( input, startPointsC0, 3 );
00117 fillVector( input, startPointsC1, 3 );
00118 fillVector( input, startPointsC2, 3 );
00119 fillVector( input, startPointsC3, 3 );
00120 fillVector( input, startPointsC4, 3 );
00121
00122
00123 fillVector( input, slopesC0, 3 );
00124 fillVector( input, slopesC1, 3 );
00125 fillVector( input, slopesC2, 3 );
00126 fillVector( input, slopesC3, 3 );
00127 fillVector( input, slopesC4, 3 );
00128
00129
00130 fillVector( input, sigmasC0, 3 );
00131 fillVector( input, sigmasC1, 3 );
00132 fillVector( input, sigmasC2, 3 );
00133 fillVector( input, sigmasC3, 3 );
00134 fillVector( input, sigmasC4, 3 );
00135
00136
00137
00138
00139 for ( int i = 0; i < m_nEtaBins - 1; ++i )
00140 {
00141 double etaLow = m_etaBoundaries[i];
00142 double etaHigh = m_etaBoundaries[i+1];
00143
00144
00145 BinID rTEtaBin( iBin, m_rTBoundaries[rt], m_rTBoundaries[rt+1], etaLow, etaHigh );
00146
00147
00148 vector<ParameterResolutions*> startPoints;
00149 vector<ParameterResolutions*> slopes;
00150 vector<ParameterResolutions*> sigmas;
00151 for ( int param = 0; param < 3; param++ )
00152 {
00153 vector<BinID> startPointCoeffBins;
00154 startPointCoeffBins.push_back( BinID( 0, startPointsC0[i][param], startPointsC0[i+1][param] ) );
00155 startPointCoeffBins.push_back( BinID( 0, startPointsC1[i][param], startPointsC1[i+1][param] ) );
00156 startPointCoeffBins.push_back( BinID( 0, startPointsC2[i][param], startPointsC2[i+1][param] ) );
00157 startPointCoeffBins.push_back( BinID( 0, startPointsC3[i][param], startPointsC3[i+1][param] ) );
00158 startPointCoeffBins.push_back( BinID( 0, startPointsC4[i][param], startPointsC4[i+1][param] ) );
00159 startPoints.push_back( new ParameterResolutions( startPointCoeffBins, etaLow, etaHigh ) );
00160
00161 vector<BinID> slopeCoeffBins;
00162 slopeCoeffBins.push_back( BinID( 0, slopesC0[i][param], slopesC0[i+1][param] ) );
00163 slopeCoeffBins.push_back( BinID( 0, slopesC1[i][param], slopesC1[i+1][param] ) );
00164 slopeCoeffBins.push_back( BinID( 0, slopesC2[i][param], slopesC2[i+1][param] ) );
00165 slopeCoeffBins.push_back( BinID( 0, slopesC3[i][param], slopesC3[i+1][param] ) );
00166 slopeCoeffBins.push_back( BinID( 0, slopesC4[i][param], slopesC4[i+1][param] ) );
00167 slopes.push_back( new ParameterResolutions( slopeCoeffBins, etaLow, etaHigh ) );
00168
00169 vector<BinID> sigmaCoeffBins;
00170 sigmaCoeffBins.push_back( BinID( 0, sigmasC0[i][param], sigmasC0[i+1][param] ) );
00171 sigmaCoeffBins.push_back( BinID( 0, sigmasC1[i][param], sigmasC1[i+1][param] ) );
00172 sigmaCoeffBins.push_back( BinID( 0, sigmasC2[i][param], sigmasC2[i+1][param] ) );
00173 sigmaCoeffBins.push_back( BinID( 0, sigmasC3[i][param], sigmasC3[i+1][param] ) );
00174 sigmaCoeffBins.push_back( BinID( 0, sigmasC4[i][param], sigmasC4[i+1][param] ) );
00175 sigmas.push_back( new ParameterResolutions( sigmaCoeffBins, etaLow, etaHigh ) );
00176 }
00177
00178
00179
00180 BremBinData* binData = new BremBinData( rTEtaBin, startPoints, slopes, sigmas, m_randSeed );
00181
00182
00183 m_binData[rTEtaBin] = binData;
00184
00185
00186 iBin++;
00187
00188 }
00189 }
00190
00191
00192 input.close();
00193
00194 }
00195 else
00196 {
00197 *m_log << MSG::INFO
00198 << "BremMatrixManager: no data file ( " << m_file << " )!!!!"
00199 << endreq;
00200 }
00201
00202 makeHeader();
00203
00204 }
00205
00206 void BremMatrixManager::makeHeader()
00207 {
00208 HeaderPrinter hp( "Atlfast BremMatrixManager:", *m_log );
00209 hp.add( "Total number of Bins ", m_nRTBins * m_nEtaBins );
00210 hp.add( "rT Bin Min ", m_rTBoundaries.front() );
00211 hp.add( "rT Bin Max ", m_rTBoundaries.back() );
00212 hp.add( "Number of rT Bins ", m_nRTBins );
00213 hp.add( "Eta Bin Min ", m_etaBoundaries.front() );
00214 hp.add( "Eta Bin Max ", m_etaBoundaries.back() );
00215 hp.add( "Number of Eta Bins ", m_nEtaBins );
00216 hp.print();
00217 }
00218
00219
00220
00221
00222
00223 void BremMatrixManager::fillVector( ifstream& input,
00224 vector< vector<double> >& myVector,
00225 int M = 3 )
00226 {
00227 double res;
00228 for ( int param = 0; param < M; param++ )
00229 {
00230 vector< vector<double> >::iterator binIter = myVector.begin();
00231 for ( ; binIter != myVector.end(); binIter++ )
00232 {
00233 input >> res;
00234 binIter->push_back(res);
00235 }
00236
00237 }
00238 }
00239
00240
00241
00242
00243
00244
00245 TrackTrajectory BremMatrixManager::getBremTrack( const TrackTrajectory& track ) const
00246 {
00247
00248 BremBinData* binData = getBinData(track);
00249
00250 TrackTrajectory newTrack = binData->getBremTrack(track);
00251
00252 return newTrack;
00253 }
00254
00255
00256
00257
00258
00259
00260 BremBinData* BremMatrixManager::getBinData( const TrackTrajectory& traj ) const
00261 {
00262 TrackParameters track = traj.parameters();
00263
00264 vector<double> rTEta;
00265 double rT = abs( traj.radius() );
00266 double eta = abs( track.eta() );
00267
00268
00269 double rTLow = ( (m_binData.begin())->first ).low(0);
00270 double rTHigh = ( (m_binData.rbegin())->first ).high(0);
00271 double etaLow = ( (m_binData.begin())->first ).low(1);
00272 double etaHigh = ( (m_binData.rbegin())->first ).high(1);
00273
00274 if ( rT < rTLow ) rT = rTLow;
00275 if ( rT > rTHigh ) rT = rTHigh;
00276 if ( eta < etaLow ) eta = etaLow;
00277 if ( eta > etaHigh ) eta = etaHigh;
00278
00279
00280 rTEta.push_back(rT);
00281 rTEta.push_back(eta);
00282
00283 map<BinID, BremBinData*>::const_iterator binIter = m_binData.begin();
00284 map<BinID, BremBinData*>::const_iterator binEnd = m_binData.end();
00285
00286 for ( ; binIter != binEnd; ++binIter )
00287 {
00288 if ( binIter->first.isInBin(rTEta) )
00289 {
00290 return binIter->second;
00291 }
00292 }
00293
00294 *m_log << MSG::WARNING
00295 << "WARNING: BremMatrixManager - No bin; rT " << rT << ", eta " << eta
00296 << endreq;
00297
00298 return ( m_binData.begin() )->second;
00299 }
00300
00301
00302 }