00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "AtlfastAlgs/TrackMaker.h"
00010 #include "AtlfastAlgs/TrackSmearer.h"
00011 #include "AtlfastAlgs/GlobalEventData.h"
00012
00013 #include "AtlfastUtils/HepMC_helper/IMCselector.h"
00014 #include "AtlfastUtils/HepMC_helper/IsCharged.h"
00015 #include "AtlfastUtils/HepMC_helper/IsFinalState.h"
00016 #include "AtlfastUtils/HepMC_helper/NCutter.h"
00017 #include "AtlfastUtils/HepMC_helper/MCCuts.h"
00018
00019 #include "CLHEP/Matrix/Matrix.h"
00020
00021 #include <cmath>
00022 #include <algorithm>
00023 #include <fstream>
00024
00025
00026 #include "GaudiKernel/DataSvc.h"
00027
00028
00029
00030
00031
00032
00033
00034
00035 using std::abs;
00036 using ::HepMatrix;
00037
00038 namespace Atlfast {
00039
00040 TrackMaker::TrackMaker ( const std::string& name, ISvcLocator* pSvcLocator )
00041 : Algorithm( name, pSvcLocator ), m_smearer(NULL){
00042
00043
00044
00045 m_mcPtMin = 0.5;
00046 m_mcEtaMax = 2.5;
00047 m_vlMax = 40.0;
00048 m_vtMax = 3.0;
00049 m_doSmearing = true;
00050 m_bField = 2.0;
00051 m_muConfig = "000";
00052
00053
00054 m_MC_eventLocation = "/Event/McEventCollection";
00055 m_outputLocation = "/Event/AtlfastTracks";
00056
00057
00058
00059 declareProperty( "McPtMinimum", m_mcPtMin ) ;
00060 declareProperty( "McEtaMaximum", m_mcEtaMax ) ;
00061 declareProperty( "vlMaximum", m_vlMax ) ;
00062 declareProperty( "vtMaximum", m_vtMax ) ;
00063 declareProperty( "DoSmearing", m_doSmearing );
00064 declareProperty( "Bfield", m_bField );
00065 declareProperty( "MC_eventLocation", m_MC_eventLocation ) ;
00066 declareProperty( "OutputLocation", m_outputLocation ) ;
00067 declareProperty( "MuonConfiguration", m_muConfig );
00068 }
00069
00070
00071
00072
00073 TrackMaker::~TrackMaker() {
00074
00075
00076
00077
00078 delete m_ncutter;
00079 delete m_tesIO;
00080 }
00081
00082
00083
00084
00085
00086
00087 StatusCode TrackMaker::initialize(){
00088 MsgStream log( messageService(), name() ) ;
00089
00090
00091 HepMC::IO_PDG_ParticleDataTable pdg_io("PDGTABLE");
00092 m_particleTable = *pdg_io.read_particle_data_table();
00093 m_particleTable.make_antiparticles_from_particles();
00094
00095
00096
00097 HepMC_helper::IMCselector* charged = new
00098 HepMC_helper::IsCharged() ;
00099 HepMC_helper::IMCselector* cuts = new
00100 HepMC_helper::MCCuts( m_mcPtMin, m_mcEtaMax ) ;
00101 HepMC_helper::IMCselector* finalState = new
00102 HepMC_helper::IsFinalState();
00103 vector<HepMC_helper::IMCselector*> selectors;
00104 selectors.push_back(finalState);
00105 selectors.push_back(charged);
00106 selectors.push_back(cuts);
00107
00108 m_ncutter = new HepMC_helper::NCutter(selectors);
00109
00110 delete cuts;
00111 delete charged;
00112 delete finalState;
00113
00114
00115 m_tesIO = new TesIO();
00116
00117
00118 GlobalEventData* ged = GlobalEventData::Instance();
00119 int lumi = ged->lumi();
00120 int randSeed = ged->randSeed() ;
00121 m_smearer = new TrackSmearer(m_muConfig, randSeed, log);
00122 log << MSG::DEBUG << "got lumi " << endreq;
00123 HeaderPrinter hp("Atlfast Track Maker:", log);
00124 hp.add("Luminosity ", lumi);
00125 hp.add("Minimum four-vector Pt ", m_mcPtMin);
00126 hp.add("Maximum four-vector Eta ", m_mcEtaMax);
00127 hp.add("Maximum Transverse Vertex ", m_vtMax);
00128 hp.add("Maximum Longitudinal Vertex ", m_vlMax);
00129 hp.add("Do Smearing ", m_doSmearing);
00130 hp.add("B Field ", m_bField);
00131 hp.add("Muon Configuration ", m_muConfig);
00132 hp.add("Random Number Seed ", randSeed);
00133 hp.add("MC location ", m_MC_eventLocation);
00134 hp.add("Output Location ", m_outputLocation);
00135 hp.print();
00136 log << MSG::INFO << "Initialised successfully " << endreq ;
00137 return StatusCode::SUCCESS ;
00138 }
00139
00140
00141
00142
00143
00144 StatusCode TrackMaker::finalize(){
00145
00146 MsgStream log( messageService(), name() ) ;
00147
00148 log << MSG::INFO << "Finalised successfully " << endreq ;
00149
00150 return StatusCode::SUCCESS ;
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 StatusCode TrackMaker::execute( ){
00170
00171
00172
00173
00174 MsgStream log( messageService(), name() ) ;
00175 log << MSG::DEBUG << "Execute() " << endreq;
00176
00177
00178
00179
00180
00181
00182
00183
00184 MCparticleCollection mcParticles ;
00185 TesIoStat stat;
00186 std::string message;
00187
00188 stat = m_tesIO->getMC( mcParticles, m_ncutter );
00189 message = stat? "Found MCparitcles in TES":"No MC particles found in TES";
00190 log<<MSG::DEBUG << message <<" "<<mcParticles.size()<<endreq;
00191
00192
00193
00194
00195
00196
00197 TrackCollection* tracks = new TrackCollection ;
00198
00199
00200
00201
00202
00203
00204 Track* candidate ;
00205 MCparticleCollectionCIter src ;
00206
00207 for( src = mcParticles.begin() ; src != mcParticles.end() ; ++src ) {
00208
00209 log << MSG::DEBUG << *src << endreq;
00210 candidate = this->create( *src );
00211 log << MSG::DEBUG << "Created: " << candidate << endreq;
00212
00213 if( this->isAcceptable( candidate ) ) {
00214 log << MSG::DEBUG << "Passed cuts" << endreq;
00215 tracks->push_back( candidate ) ;
00216 log << MSG::DEBUG << "pushed back track" <<endreq;
00217 }
00218 else {
00219 log << MSG::DEBUG << "Failed cuts" << endreq;
00220 delete candidate ;
00221 }
00222 }
00223
00224
00225
00226
00227
00228 stat = m_tesIO->store(tracks, m_outputLocation);
00229 message = stat? "Stored tracks in TES":"Error storing tracks in TES";
00230 log<<MSG::DEBUG << message <<" "<<tracks->size()<<endreq;
00231
00232 return stat;
00233
00234 }
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 Track* TrackMaker::create ( const HepMC::GenParticle* src ){
00251
00252 MsgStream log( messageService(), name() ) ;
00253
00254 TrackTrajectory originalTrajectory = this->extractTrajectory( src ) ;
00255
00256 if (m_doSmearing) {
00257
00258
00259
00260
00261 Track myTrack(originalTrajectory, src);
00262 Track smearedTrack = m_smearer->smear(myTrack);
00263
00264
00265 Track* newTrack = new Track( smearedTrack );
00266 return newTrack;
00267 }
00268 else
00269 {
00270
00271 return new Track( originalTrajectory, src ) ;
00272 }
00273 }
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 bool TrackMaker::isAcceptable ( Track* candidate ){
00288 HepPoint3D vertex = candidate->trajectory().startPoint();
00289 int pdg = abs(candidate->pdg_id() );
00290 if ( vertex.z() > m_vlMax ) return false;
00291
00292
00293 if ( pdg == 11 || pdg == 13) {
00294 if ( vertex.perp() > m_vtMax ) return false;
00295 }
00296 return true ;
00297 }
00298
00299
00300
00301 TrackTrajectory
00302 TrackMaker::extractTrajectory( const HepMC::GenParticle* particle ) {
00303
00304 Hep3Vector vertex = (particle->production_vertex())->position().getV();
00305
00306 Hep3Vector threeMomentum = particle->momentum().getV() ;
00307
00308 HepMC::ParticleData* data = m_particleTable[particle->pdg_id()] ;
00309 double charge = data->charge() ;
00310
00311 return TrackTrajectory( threeMomentum, vertex, charge, m_bField ) ;
00312
00313 }
00314
00315
00316 }
00317
00318
00319