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

EventHeaderMaker.cxx

Go to the documentation of this file.
00001 // ================================================
00002 // EventHeaderMaker class Implementation
00003 // ================================================
00004 //
00005 // THIS TEXT TO BE REPLACED BY ATLAS STANDARD FORMAT
00006 //
00007 // Namespace Atlfast
00008 //
00009 
00010 #include "AtlfastAlgs/EventHeaderMaker.h"
00011 #include "AtlfastAlgs/MissingMomentum.h"
00012 #include "AtlfastAlgs/GlobalEventData.h"
00013 
00014 #include "AtlfastEvent/EventHeader.h"
00015 #include "AtlfastEvent/IKinematic.h"
00016 #include "AtlfastEvent/MsgStreamDefs.h"
00017 #include "AtlfastEvent/ReconstructedParticle.h"
00018 #include "AtlfastEvent/Cell.h"
00019 #include "AtlfastEvent/Cluster.h"
00020 #include "AtlfastEvent/ParticleCodes.h"
00021 #include "AtlfastEvent/CollectionDefs.h"
00022 #include "AtlfastEvent/MCparticleCollection.h"
00023 #include "AtlfastEvent/ReconstructedParticle.h"
00024 #include "AtlfastEvent/Jet.h"
00025 
00026 #include "AtlfastUtils/HeaderPrinter.h"
00027 #include "AtlfastUtils/TesIO.h"
00028 
00029 // standard library includes
00030 #include <cmath> 
00031 #include <string>
00032 #include <vector>
00033 #include <algorithm>
00034 #include <assert.h>
00035 
00036 // Gaudi includes
00037 #include "GaudiKernel/DataSvc.h"
00038 #include "StoreGate/DataHandle.h"
00039 #include "GaudiKernel/ISvcLocator.h"
00040 #include "GaudiKernel/MsgStream.h"
00041 
00042 
00043 //Generator includes
00044 #include "GeneratorObjects/McEventCollection.h"
00045 
00046 namespace Atlfast {
00047   //--------------------------------
00048   // Constructors and destructors
00049   //-------------------------------
00050   EventHeaderMaker::EventHeaderMaker 
00051   ( const std::string& name, ISvcLocator* pSvcLocator ) 
00052     : Algorithm( name, pSvcLocator ){
00053     
00054     // Default paths for entities in the TES
00055     m_electronLocation         = "/Event/AtlfastIsolatedElectrons";
00056     m_photonLocation           = "/Event/AtlfastIsolatedPhotons";
00057     m_isolatedMuonLocation     = "/Event/AtlfastIsolatedMuons";
00058     m_nonIsolatedMuonLocation  = "/Event/AtlfastNonIsolatedMuons";
00059     m_jetLocation              = "/Event/AtlfastJets";
00060     m_cellLocation             = "/Event/AtlfastCells";
00061     m_clusterLocation          = "/Event/AtlfastClusters";
00062     m_mcTruthLocation          = "/Event/McEventCollection";
00063     m_outputLocation           = "/Event/AtlfastEventHeader";
00064     m_missingMomentumLocation  = "/Event/AtlfastMissingMomentum";
00065     m_beamEnergy               = 7000.0;
00066     m_testMode                 = false;
00067     
00068     
00069     
00070     declareProperty( "MissingMomentumLocation", m_missingMomentumLocation ) ;
00071     declareProperty( "ElectronLocation",        m_electronLocation ) ;
00072     declareProperty( "PhotonLocation",          m_photonLocation );
00073     declareProperty( "IsolatedMuonLocation",    m_isolatedMuonLocation );
00074     declareProperty( "NonIsolatedMuonLocation", m_nonIsolatedMuonLocation );
00075     declareProperty( "JetLocation",             m_jetLocation );
00076     declareProperty( "McTruthLocation",         m_mcTruthLocation );
00077     declareProperty( "OutputLocation",          m_outputLocation );
00078     declareProperty( "BeamEnergy",              m_beamEnergy );
00079     
00080     declareProperty( "TestMode",                m_testMode ) ;
00081     
00082     
00083     
00084   }
00085   
00086   
00087   //-------------------------------------
00088   // Destructor 
00089   //-------------------------------------
00090   EventHeaderMaker::~EventHeaderMaker(){
00091     delete m_tesIO;
00092   }
00093 
00094   //---------------------------------
00095   // initialise() 
00096   //---------------------------------
00097   StatusCode EventHeaderMaker::initialize()
00098   {
00099     // .. put any initialisation in here...
00100     MsgStream log(messageService(), name());
00101     log << MSG::DEBUG << "in initialize()" << endreq;
00102     
00103     //set up the list of particles which are considered as "escaping"
00104     m_escapingParticles.push_back(ParticleCodes::NU_E);
00105     m_escapingParticles.push_back(ParticleCodes::NU_MU);
00106     m_escapingParticles.push_back(ParticleCodes::NU_TAU);
00107 
00108     //    m_tesIO = new TesIO(eventDataService());
00109     m_tesIO = new TesIO();
00110 
00111     //get the Global Event Data from singleton pattern
00112     GlobalEventData* ged = GlobalEventData::Instance();
00113     m_visibleToAtlas   = ged -> visibleToAtlas();
00114     m_lumi             = ged -> lumi();
00115     m_barrelForwardEta = ged ->  barrelForwardEta();
00116     HeaderPrinter hp("Atlfast EventHeader Maker:", log);
00117     hp.add("TestMode                    ", m_testMode);
00118     hp.add("EndCap Begins at (eta)      ", m_barrelForwardEta);
00119     hp.add("Luminosity                  ", m_lumi);
00120     hp.add("Beam Energy                 ", m_beamEnergy);
00121     hp.add("MC location                 ", m_mcTruthLocation);
00122     hp.add("Electron Location           ", m_electronLocation);
00123     hp.add("Photon   Location           ", m_photonLocation);
00124     hp.add("Isolated Muon Location      ", m_isolatedMuonLocation);
00125     hp.add("Non-Isolated Muon Location  ", m_nonIsolatedMuonLocation);
00126     hp.add("Jet Location                ", m_jetLocation);
00127     hp.add("Cell Location               ", m_cellLocation);
00128     hp.add("Cluster Location            ", m_clusterLocation);
00129     hp.add("Unused cell+cluster sum     ", m_missingMomentumLocation);
00130     hp.add("Output Location             ", m_outputLocation);    
00131     hp.print();
00132     
00133 
00134     
00135     
00136     return StatusCode::SUCCESS ;
00137   }
00138   
00139   //---------------------------------
00140   // finalise() 
00141   //---------------------------------
00142   StatusCode EventHeaderMaker::finalize()
00143   {
00144     // .. put any finalisation in here...
00145     MsgStream log( messageService(), name() ) ;
00146     log << MSG::INFO << "finalizing " << endreq;
00147     
00148     return StatusCode::SUCCESS ;
00149   }
00150   
00151   //----------------------------------------------
00152   // execute() method called once per event
00153   //----------------------------------------------
00154   StatusCode EventHeaderMaker::execute( )
00155   {
00156     
00157     //................................
00158     // make a message logging stream
00159     
00160     MsgStream log( messageService(), name() ) ;
00161     log << MSG::DEBUG << "Executing " << endreq;
00162     std::string mess;
00163     
00164       
00165 
00166     //
00167     // Check each particle list in turn and get the number of entries
00168     //
00169     int nElectrons         = 
00170       numberInList<ReconstructedParticleCollection>(m_electronLocation);
00171     int nPhotons           = 
00172       numberInList<ReconstructedParticleCollection>(m_photonLocation);
00173     int nIsolatedMuons     = 
00174       numberInList<ReconstructedParticleCollection>(m_isolatedMuonLocation);
00175     int nNonIsolatedMuons  = 
00176       numberInList<ReconstructedParticleCollection>(m_nonIsolatedMuonLocation);
00177     int nJets              = numberInList<JetCollection>(m_jetLocation);
00178     int nBJets             = numberJetFlavor(m_jetLocation,
00179                                              ParticleCodes::BQUARK);
00180     int nCJets             = numberJetFlavor(m_jetLocation,
00181                                              ParticleCodes::CQUARK);
00182     int nTauJets           = numberJetFlavor(m_jetLocation,
00183                                              ParticleCodes::TAU);
00184     nTauJets              += numberJetFlavor(m_jetLocation,
00185                                              -ParticleCodes::TAU);
00186     
00187     log << MSG::DEBUG << "Electrons: " << nElectrons << endreq;
00188     log << MSG::DEBUG << "Photons: " << nPhotons << endreq;
00189     log << MSG::DEBUG << "IsolatedMuons: " << nIsolatedMuons << endreq;
00190     log << MSG::DEBUG << "NonIsolatedMuons: " << nNonIsolatedMuons << endreq;
00191     log << MSG::DEBUG << "Jets: " << nJets << endreq;
00192     
00193     
00194     // Event Shape variable calculations
00195     
00196     double jetCircularity = 0.0; //FIXME not written yet
00197     double eventCircularity = 0.0; //FIXME not written yet
00198     double thrust = 0.0; //FIXME not written yet
00199     double oblateness = 0.0; //FIXME not written yet
00200     
00201     //missing momentum
00202     HepLorentzVector pMiss = missingMomentum(log);
00203     
00204     log << MSG::DEBUG << "Missing momentum " <<pMiss<<endreq; 
00205     
00206     HepLorentzVector pEscaped = escapedMomentum(log);
00207     
00208     log << MSG::DEBUG << "Escaped momentum " << pEscaped<<endreq;
00209 
00210     EventHeader* header = 
00211       new EventHeader(
00212                       nElectrons, 
00213                       nIsolatedMuons, 
00214                       nNonIsolatedMuons, 
00215                       nPhotons, 
00216                       nJets,
00217                       nBJets, 
00218                       nCJets, 
00219                       nTauJets, 
00220                       jetCircularity, 
00221                       eventCircularity,
00222                       thrust, 
00223                       oblateness, 
00224                       pMiss, 
00225                       pEscaped);
00226     
00227     TesIoStat stat = m_tesIO->store(header,m_outputLocation) ;
00228     std::string message = stat? "Stored Evt Header":"Failed to Evt Header";
00229     log<<MSG::DEBUG<<message<<endreq;
00230      return stat;
00231 
00232   }
00233   //-------------------------------------------------------
00234   // missingMomentum
00235   //-------------------------------------------------------
00236   HepLorentzVector EventHeaderMaker::missingMomentum(MsgStream& log) {
00237 
00238     HepLorentzVector unused(0., 0., 0., 0.);
00239     const DataHandle<MissingMomentum> mm;
00240     TesIoStat stat = m_tesIO->getDH(mm,m_missingMomentumLocation );
00241     if(!stat){
00242       log << MSG::WARNING<<"Could Not Find Missing momentum in TES"<<endreq;
00243       return unused;
00244     }
00245     log << MSG::DEBUG<<"Found Missing Momentum in TES"<<endreq;
00246 
00247     unused = mm->momentum();
00248 
00249     HepLorentzVector temp(0.0,0.0,0.0,0.0);
00250     
00251 
00252     temp = unused
00253       +  momentumSum<ReconstructedParticleCollection> (m_electronLocation)
00254       +  momentumSum<ReconstructedParticleCollection> (m_photonLocation)
00255       +  momentumSum<ReconstructedParticleCollection> (m_isolatedMuonLocation)
00256       +  momentumSum<JetCollection>                   (m_jetLocation)
00257       +  momentumSum<ReconstructedParticleCollection> (m_nonIsolatedMuonLocation)
00258       -  assocMomentumSum<JetCollection, ReconstructedParticle> (m_jetLocation)
00259       ;
00260 
00261     log<<MSG::DEBUG
00262        <<"Total Imbalanced momentum     "
00263        <<temp
00264        <<endreq;
00265 
00266 
00267 
00268     if(m_testMode){
00269         HepLorentzVector totCluster = 
00270           momentumSum<ClusterCollection> (m_clusterLocation);
00271 
00272         HepLorentzVector clusterAssE = 
00273           assocMomentumSum<ReconstructedParticleCollection, Cluster>
00274           (m_electronLocation);
00275 
00276         HepLorentzVector clusterAssP = 
00277           assocMomentumSum<ReconstructedParticleCollection, Cluster>
00278           (m_photonLocation);
00279 
00280         HepLorentzVector clusterAssM = 
00281           assocMomentumSum<ReconstructedParticleCollection, Cluster>
00282           (m_isolatedMuonLocation);
00283         
00284         HepLorentzVector clusterAssJ = 
00285           assocMomentumSum<JetCollection, Cluster>(m_jetLocation);
00286 
00287       HepLorentzVector clusterDiff = totCluster-
00288         clusterAssJ-
00289         clusterAssE-
00290         clusterAssM-
00291         clusterAssP;
00292 
00293       HepLorentzVector totCell = momentumSum<CellCollection>(m_cellLocation);
00294 
00295       HepLorentzVector cellAssCluster = 
00296         assocMomentumSum<ClusterCollection, Cell>(m_clusterLocation);
00297 
00298       HepLorentzVector cellDiff = totCell-cellAssCluster;
00299 
00300       HepLorentzVector diffS  = clusterDiff+cellDiff-unused;
00301       
00302 
00303       
00304       log<<MSG::DEBUG<<"Total cluster    "<<totCluster<<endreq;
00305       log<<MSG::DEBUG<<"Clus Ass Jet     "<<clusterAssJ<<endreq;
00306       log<<MSG::DEBUG<<"Clus Ass El      "<<clusterAssE<<endreq;
00307       log<<MSG::DEBUG<<"Clus Ass Mu      "<<clusterAssM<<endreq;
00308       log<<MSG::DEBUG<<"Clus Ass Ph      "<<clusterAssP<<endreq;
00309       log<<MSG::DEBUG<<"Clus diff        "<<clusterDiff<<endreq;
00310       log<<MSG::DEBUG<<"Total Cell       "<<totCell<<endreq;
00311       log<<MSG::DEBUG<<"Cell Ass Clus    "<<cellAssCluster<<endreq;
00312       log<<MSG::DEBUG<<"Clus diff        "<<cellDiff<<endreq;
00313       log<<MSG::DEBUG<<"Cell+Clus diff   "<<cellDiff<<endreq;
00314       log<<MSG::DEBUG<<"Unused           "<<unused<<endreq;
00315       log<<MSG::DEBUG<<"diff             "<<diffS<<endreq;
00316 
00317       log<<MSG::DEBUG<<endreq;
00318       
00319       assert( diffS.rho() <0.001);
00320 
00321 
00322 
00323 
00324 
00325       HepLorentzVector temp2 =  
00326         momentumSum<ReconstructedParticleCollection>    (m_electronLocation)
00327         +  momentumSum<ReconstructedParticleCollection> (m_photonLocation)
00328         +  momentumSum<ReconstructedParticleCollection> (m_isolatedMuonLocation)
00329         +  momentumSum<JetCollection>  (m_jetLocation)
00330         +  momentumSum<ClusterCollection> (m_clusterLocation)
00331         +  momentumSum<CellCollection> (m_cellLocation)
00332         +  momentumSum<ReconstructedParticleCollection> (m_nonIsolatedMuonLocation)
00333         
00334         - assocMomentumSum<ReconstructedParticleCollection, Cluster>
00335         (m_electronLocation)   
00336         
00337         - assocMomentumSum<ReconstructedParticleCollection, Cluster>
00338         (m_photonLocation)
00339         
00340         - assocMomentumSum<ReconstructedParticleCollection, Cluster>
00341         (m_nonIsolatedMuonLocation)
00342         
00343         -  assocMomentumSum<JetCollection, Cluster>
00344         (m_jetLocation)
00345         
00346         -  assocMomentumSum<JetCollection, ReconstructedParticle>
00347         (m_jetLocation)
00348 
00349         - assocMomentumSum<ClusterCollection, Cell>
00350         (m_clusterLocation);
00351 
00352       
00353       assert( (temp-temp2).rho() <0.001);
00354     }
00355     
00356     // calculate missing momentum from the reconstructed sum of momenta:
00357     //
00358     temp.setPx( -temp.px() );
00359     temp.setPy( -temp.py() );
00360     temp.setPz( -temp.pz() );
00361     temp.setE(  2.0*m_beamEnergy - temp.e() );
00362     
00363     return temp;
00364   }
00365   
00366   
00367   
00368   //-------------------------------------------------------
00369   // escapedMomentum
00370   //-------------------------------------------------------
00371   HepLorentzVector EventHeaderMaker::escapedMomentum(MsgStream& log) {
00372 
00373     HepLorentzVector temp(0.0,0.0,0.0,0.0);
00374 
00375     MCparticleCollection  mcParticles;
00376     TesIoStat stat = m_tesIO->getMC( mcParticles, m_visibleToAtlas ) ;
00377     std::string mess = 
00378       stat? "MC particles retrieved":"MC particles retrieve failed";
00379     log<<MSG::DEBUG<<mess<<endreq;
00380     
00381 
00382     MCparticleCollection::const_iterator part = mcParticles.begin();
00383     for (;part != mcParticles.end(); ++part) {
00384       temp += (*part)->momentum(); 
00385     }
00386 
00387     return temp;
00388   }
00389 
00390 } // end of namespace bracket
00391 
00392 
00393 
00394 
00395 
00396 
00397 
00398 
00399 
00400 
00401 
00402 

Generated on Tue Jan 28 09:57:13 2003 for AtlfastAlgs by doxygen1.3-rc1