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

TrackMaker.cxx

Go to the documentation of this file.
00001 // ================================================
00002 // TrackMaker class Implementation
00003 // ================================================
00004 //
00005 // THIS TEXT TO BE REPLACED BY ATLAS STANDARD FORMAT
00006 //
00007 // Namespace Atlfast::
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 // Gaudi includes
00026 #include "GaudiKernel/DataSvc.h"
00027 
00028 // Generator includes
00029 //#include "GeneratorObjects/McEventCollection.h"
00030 
00031 //--------------------------------
00032 // Constructors and destructors
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     // Setting the parameter defaults - these can be changed by user via
00044     // jobOptions
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     // Default paths for entities in the TES
00054     m_MC_eventLocation  = "/Event/McEventCollection";
00055     m_outputLocation    = "/Event/AtlfastTracks";
00056     
00057     // Declare the paramemters to Athena so that
00058     // they can be over-written via the job options file
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   // Destructor
00072   //----------------------------
00073   TrackMaker::~TrackMaker() {
00074     // These ought to be here, but appear to cause the job
00075     // to hang at termination time.
00076     // if( m_smearer    ) delete m_smearer ; 
00077     // if( m_mcSelector ) delete m_mcSelector ;
00078     delete m_ncutter;
00079     delete m_tesIO;
00080   } 
00081   
00082   
00083   //---------------------------------
00084   // initialise() 
00085   //---------------------------------
00086   
00087   StatusCode TrackMaker::initialize(){
00088     MsgStream log( messageService(), name() ) ;
00089     
00090     // Make a particle properties table. This will become a Gaudi service.
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     // Set up NCutter to select the required HepMC::GenParticles
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     //get the Global Event Data from singleton pattern
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   // finalise() 
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   // execute() method called once per event
00156   //----------------------------------------------
00157   //
00158   //  This algorithm creates smeared Tracks passing cuts. 
00159   //  It scans the list of HepMC::GenParticles from the Monte Carlo truth. 
00160   //  It creates a Track object by smearing the Trajectory track parameters
00161   //  corresponding to the HepMC::GenParticle. 
00162   // 
00163   //  It then applies kinematic criteria on the properties of the Track
00164   //  Those which pass the cuts are kept.
00165   //  Finally all successful ReconstructedParticles are added to 
00166   //the event store.
00167   //
00168   
00169   StatusCode TrackMaker::execute( ){
00170 
00171     //................................
00172     // make a message logging stream
00173     
00174     MsgStream log( messageService(), name() ) ;
00175     log << MSG::DEBUG << "Execute() " << endreq;
00176     
00177 
00178     //.........................................................
00179     // We now need to access the HepMC event record(s) in the event store
00180     // and iterate over them to extract HepMC::GenParticles.
00181     // This method will only select the particles which are required
00182     // and add them to a local store (mcParticles)
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     // Make a container object which will store pointers to all isolated 
00193     // Tracks which are successfully created.  Since it is going to go 
00194     // into the event store, it has to be a special Athena container. 
00195     // This is typedefined in an include file
00196     
00197     TrackCollection* tracks = new TrackCollection ;
00198     
00199 
00200     //.........................................................
00201     // From each mc Track create a reconstructed Track. 
00202     // If all requirements are satisfied add to the collection
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     // Register any Tracks which have been successfilly created in the 
00226     // transient event store. If there are none then we delete the empty list.
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   // create()
00240   //----------------------------------
00241   
00242   // Takes a single MC Particle and creates a Track
00243   // according to the desired criteria
00244   //
00245   // Note that we must NEW these particles so they can go to the TES
00246   // and if we decide that we do not want them, we must DELETE them
00247   // Once they are put to the TES, they are no longer our responsibility 
00248   // to delete
00249   
00250   Track* TrackMaker::create ( const HepMC::GenParticle* src ){
00251     
00252     MsgStream log( messageService(), name() ) ;
00253     // Construct the Trajectory parameters corresponding to the source particle
00254     TrackTrajectory originalTrajectory = this->extractTrajectory( src ) ;
00255 
00256     if (m_doSmearing) {
00257       
00258       // Ask our Smearer make a smeared set of Trajectory parameters
00259       // If this needs to be different for different particles then
00260       // it can be done here. Best  method of dispatching to be decided later
00261       Track myTrack(originalTrajectory, src);
00262       Track smearedTrack = m_smearer->smear(myTrack);
00263       
00264       // Return a new track
00265       Track* newTrack =  new Track( smearedTrack );
00266       return newTrack;
00267     } 
00268     else 
00269       {
00270         // Just return the track with unsmeared four-momentum
00271         return new Track( originalTrajectory, src ) ;
00272       }
00273   }
00274   
00275   
00276   
00277   //-------------------------------------------
00278   // isAcceptable
00279   //------------------------------------------
00280   
00281   // Decides whether a candidate is acceptable to this Maker, i.e. whether
00282   // it wants to proceed and add it to its output product collection
00283   // however there are no post creation conditions applied to tracks
00284   // in this version 
00285   
00286   //  bool TrackMaker::isAcceptable ( Track* candidate )
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     // test track for vl and vt
00293     if ( pdg == 11 || pdg == 13) {
00294       if ( vertex.perp() > m_vtMax ) return false;
00295     }
00296     return true ;
00297   }
00298   
00299   
00300   // Extract Trajectory parameters from HepMC::GenParticle
00301   TrackTrajectory 
00302   TrackMaker::extractTrajectory( const HepMC::GenParticle* particle ) {
00303     // look up vertex
00304     Hep3Vector vertex = (particle->production_vertex())->position().getV();
00305     // Get 4-momentum and explicitly convert to 3-momentum
00306     Hep3Vector threeMomentum = particle->momentum().getV() ;
00307     // Obtain charge of particle
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 } // end namespace bracket
00317 
00318 
00319 

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