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

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