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

CBNT_Atlfast.cxx

Go to the documentation of this file.
00001 #include "AtlfastAlgs/CBNT_Atlfast.h"
00002 
00003 #include "AtlfastAlgs/StandardNtupleMaker.h"
00004 #include "AtlfastAlgs/JetRecalibrator.h"
00005 
00006 #include "AtlfastUtils/HeaderPrinter.h"
00007 #include "AtlfastUtils/HepMC_helper/IsStatusxx.h"
00008 #include "AtlfastUtils/HepMC_helper/All.h"
00009 
00010 #include "AtlfastEvent/ReconstructedParticle.h"
00011 #include "AtlfastEvent/CollectionDefs.h"
00012 #include "AtlfastEvent/Jet.h"
00013 #include "AtlfastEvent/EventHeader.h"
00014 
00015 // CLHEP,HepMC
00016 #include "GeneratorObjects/McEventCollection.h"
00017 #include "HepMC/GenEvent.h"
00018 
00019 
00020 
00021 #include <cmath> 
00022 #include <pair.h>
00023 
00024 #include "GaudiKernel/MsgStream.h"
00025 #include "GaudiKernel/ISvcLocator.h"
00026 
00027 #include "GaudiKernel/SmartDataPtr.h"
00028 #include "GaudiKernel/SmartDataLocator.h"
00029 #include "GaudiKernel/IDataProviderSvc.h"
00030 #include "StoreGate/StoreGateSvc.h"
00031 #include "StoreGate/DataHandle.h"
00032 
00033 #include "GaudiKernel/PropertyMgr.h"
00034 
00035 #include "GaudiKernel/INTupleSvc.h"
00036 #include "GaudiKernel/NTuple.h"
00037 
00038 
00039 #include <string>
00040 
00041 namespace Atlfast{
00042 //<<<<<< CONSTRUCTOR
00043 
00044   CBNT_Atlfast::CBNT_Atlfast(const std::string& name, 
00045                              ISvcLocator* pSvcLocator) : Algorithm(name, pSvcLocator),
00046                                                          m_NtupleLocID("/FILE1/CBNT/51") {
00047     m_atlfastEventLocation    = "/Event/Atlfast";
00048     m_jetLocation             = "/Event/AtlfastJets";
00049     m_jetBLocation            = "/Event/AtlfastBJets";
00050     m_electronLocation        = "/Event/AtlfastIsolatedElectrons";
00051     m_isolatedMuonLocation    = "/Event/AtlfastIsolatedMuons";
00052     m_nonIsolatedMuonLocation = "/Event/AtlfastNonIsolatedMuons";
00053     m_photonLocation          = "/Event/AtlfastIsolatedPhotons";
00054     m_mcTruthLocation         = "/Event/McEventCollection";
00055     m_bPhysicsLocation        = "/Event/AtlfastBPhysics";
00056     m_eventHeaderLocation     = "/Event/AtlfastEventHeader";
00057     
00058     declareProperty( "AtlfastEventLocation",    m_atlfastEventLocation );
00059     declareProperty( "JetLocation",             m_jetLocation );
00060     declareProperty( "JetBLocation",            m_jetBLocation );
00061     declareProperty( "ElectronLocation",        m_electronLocation );
00062     declareProperty( "IsolatedMuonLocation",    m_isolatedMuonLocation );
00063     declareProperty( "NonIsolatedMuonLocation", m_nonIsolatedMuonLocation );
00064     declareProperty( "PhotonLocation",          m_photonLocation );
00065     declareProperty( "McTruthLocation",         m_mcTruthLocation );
00066     declareProperty( "BPhysicsLocation",        m_bPhysicsLocation );
00067     declareProperty( "EventHeaderLocation",     m_eventHeaderLocation );
00068     declareProperty("NtupleLocID",m_NtupleLocID);
00069     
00070   }
00071   CBNT_Atlfast::~CBNT_Atlfast(){
00072     delete m_tesIO;
00073     delete m_jetCal;
00074   }
00075   
00076 //<<<<<< METHOD initialize
00077 
00078 StatusCode CBNT_Atlfast::initialize(){
00079 
00080   StatusCode sc;
00081   
00082   MsgStream log(messageService(), name());
00083   
00084   // access already booked ntuple m_NtupleLocID
00085   sc = accessNtuple();
00086   if (!sc) {
00087     return StatusCode::FAILURE;
00088   }
00089   
00090   NTuple::Tuple* nt=p_nt;
00091   
00092   //check the properties
00093   
00094   //declare more variables
00095   
00096   log << MSG::DEBUG << "declare more variables" << endreq;
00097   
00098   // Electrons
00099   sc = nt->addItem ("ATLFAST/NELE"      , m_nele, 0, 12 );
00100   sc = nt->addItem ("ATLFAST/KFELE"     , m_nele, m_codeele);
00101   sc = nt->addItem ("ATLFAST/PXELE"     , m_nele, m_pxele);
00102   sc = nt->addItem ("ATLFAST/PYELE"     , m_nele, m_pyele);
00103   sc = nt->addItem ("ATLFAST/PZELE"     , m_nele, m_pzele);
00104   sc = nt->addItem ("ATLFAST/EEELE"     , m_nele, m_eeele);
00105   // Photons
00106   sc = nt->addItem ("ATLFAST/NPHO"      , m_npho, 0, 12 );
00107   sc = nt->addItem ("ATLFAST/KFPHO"     , m_npho, m_codepho);
00108   sc = nt->addItem ("ATLFAST/PXPHO"     , m_npho, m_pxpho);
00109   sc = nt->addItem ("ATLFAST/PYPHO"     , m_npho, m_pypho);
00110   sc = nt->addItem ("ATLFAST/PZPHO"     , m_npho, m_pzpho);
00111   sc = nt->addItem ("ATLFAST/EEPHO"     , m_npho, m_eepho);
00112   // Muons (isolated)
00113   sc = nt->addItem ("ATLFAST/NMUO"      , m_nmuo, 0, 12 );
00114   sc = nt->addItem ("ATLFAST/KFMUO"     , m_nmuo, m_codemuo);
00115   sc = nt->addItem ("ATLFAST/PXMUO"     , m_nmuo, m_pxmuo);
00116   sc = nt->addItem ("ATLFAST/PYMUO"     , m_nmuo, m_pymuo);
00117   sc = nt->addItem ("ATLFAST/PZMUO"     , m_nmuo, m_pzmuo);
00118   sc = nt->addItem ("ATLFAST/EEMUO"     , m_nmuo, m_eemuo);
00119   // MuonsX (non-isolated)
00120   sc = nt->addItem ("ATLFAST/NMUX"      , m_nmux, 0, 12 );
00121   sc = nt->addItem ("ATLFAST/KFMUX"     , m_nmux, m_codemux);
00122   sc = nt->addItem ("ATLFAST/PXMUX"     , m_nmux, m_pxmux);
00123   sc = nt->addItem ("ATLFAST/PYMUX"     , m_nmux, m_pymux);
00124   sc = nt->addItem ("ATLFAST/PZMUX"     , m_nmux, m_pzmux);
00125   sc = nt->addItem ("ATLFAST/EEMUX"     , m_nmux, m_eemux);
00126   // Jets
00127   sc = nt->addItem ("ATLFAST/NJET"      , m_njet, 0, 40 );
00128   sc = nt->addItem ("ATLFAST/KFJET"     , m_njet, m_codejet);
00129   sc = nt->addItem ("ATLFAST/PXJET"     , m_njet, m_pxjet);
00130   sc = nt->addItem ("ATLFAST/PYJET"     , m_njet, m_pyjet);
00131   sc = nt->addItem ("ATLFAST/PZJET"     , m_njet, m_pzjet);
00132   sc = nt->addItem ("ATLFAST/EEJET"     , m_njet, m_eejet);
00133   sc = nt->addItem ("ATLFAST/PTcalo"    , m_njet, m_ptcalo);
00134   sc = nt->addItem ("ATLFAST/PTbjet"    , m_njet, m_ptbjet);
00135   sc = nt->addItem ("ATLFAST/PTujet"    , m_njet, m_ptujet);
00136   // Jets calibrated by AtlfastB
00137   sc = nt->addItem ("ATLFAST/NJETB"      , m_njetB, 0, 40 );
00138   sc = nt->addItem ("ATLFAST/KFJETB"     , m_njetB, m_codejetB);
00139   sc = nt->addItem ("ATLFAST/PXJETB"     , m_njetB, m_pxjetB);
00140   sc = nt->addItem ("ATLFAST/PYJETB"     , m_njetB, m_pyjetB);
00141   sc = nt->addItem ("ATLFAST/PZJETB"     , m_njetB, m_pzjetB);
00142   sc = nt->addItem ("ATLFAST/EEJETB"     , m_njetB, m_eejetB);
00143   // History
00144   sc = nt->addItem ("ATLFAST/NPART"     , m_npart, 0, 40 );
00145   sc = nt->addItem ("ATLFAST/KPPART"    , m_npart, m_kppart);
00146   sc = nt->addItem ("ATLFAST/KSPART"    , m_npart, m_kspart);
00147   sc = nt->addItem ("ATLFAST/KFPART"    , m_npart, m_kfpart);
00148   sc = nt->addItem ("ATLFAST/KPMOTH"    , m_npart, m_kpmoth);
00149   sc = nt->addItem ("ATLFAST/KFMOTH"    , m_npart, m_kfmoth);
00150   sc = nt->addItem ("ATLFAST/PXPART"    , m_npart, m_pxpart);
00151   sc = nt->addItem ("ATLFAST/PYPART"    , m_npart, m_pypart);
00152   sc = nt->addItem ("ATLFAST/PZPART"    , m_npart, m_pzpart);
00153   sc = nt->addItem ("ATLFAST/EEPART"    , m_npart, m_eepart);
00154   // Missing
00155   sc = nt->addItem ("ATLFAST/ISUB"      , m_isub);
00156   sc = nt->addItem ("ATLFAST/JETB"      , m_njetb);
00157   sc = nt->addItem ("ATLFAST/JETC"      , m_njetc);
00158   sc = nt->addItem ("ATLFAST/JETTAU"    , m_njettau);
00159   sc = nt->addItem ("ATLFAST/PXMISS"    , m_pxmiss);
00160   sc = nt->addItem ("ATLFAST/PYMISS"    , m_pymiss);
00161   sc = nt->addItem ("ATLFAST/PXNUE"     , m_pxnue);
00162   sc = nt->addItem ("ATLFAST/PYNUE"     , m_pynue);
00163   
00164   
00165   m_jetCal = new JetRecalibrator();
00166   m_tesIO = new TesIO();
00167   
00168   HeaderPrinter hp("Atlfast StandardNtuleMaker:", log);
00169   hp.add("MC location                 ", m_mcTruthLocation);
00170   hp.add("Electron Location           ", m_electronLocation);
00171   hp.add("Photon   Location           ", m_photonLocation);
00172   hp.add("Isolated Muon Location      ", m_isolatedMuonLocation);
00173   hp.add("Non-Isolated Muon Location  ", m_nonIsolatedMuonLocation);
00174   hp.add("Jet Location                ", m_jetLocation);
00175   hp.add("EventHeaderLocation         ", m_eventHeaderLocation );
00176   hp.print();
00177   return StatusCode::SUCCESS;
00178 
00179 }
00180 
00181 
00182 //<<<<<< METHOD execute
00183 
00184 StatusCode CBNT_Atlfast::execute(){
00185 
00186   MsgStream log(messageService(), name());
00187   log << MSG::DEBUG << "in execute() ..." << endreq;
00188 
00189   log << MSG::DEBUG << " -> retrieving all Atlfast stuff"<< endreq;
00190 
00191 
00192 
00193 
00194   //-------------------
00195   // Retrieve Electrons 
00196   //-------------------
00197   std::vector<ReconstructedParticle*> rp;
00198   if(!m_tesIO->copy<ReconstructedParticleCollection>(rp,m_electronLocation)){
00199     log <<MSG::DEBUG << "Could not find Electrons"<<endreq;
00200   }
00201   log << MSG::DEBUG << "processing Electrons: " <<rp.size()<< endreq;
00202   
00203   std::vector<ReconstructedParticle*>::const_iterator irp  = rp.begin();
00204 
00205   m_nele = 0;
00206   for (; irp != rp.end(); ++irp) {
00207     m_codeele[m_nele] = (*irp)->pdg_id();
00208     m_pxele[m_nele]   = (*irp)->momentum().px();
00209     m_pyele[m_nele]   = (*irp)->momentum().py();
00210     m_pzele[m_nele]   = (*irp)->momentum().pz();
00211     m_eeele[m_nele]   = (*irp)->momentum().e();
00212     if (++m_nele == m_nele->range().distance() ) {
00213       log << MSG::WARNING << "Electron list truncated in Ntuple" << endreq;
00214       break;
00215     }
00216   }
00217 
00218   //-------------------
00219   // Retrieve Photons 
00220   //-------------------
00221 
00222   rp.clear();
00223   if(!m_tesIO->copy <ReconstructedParticleCollection>(rp, m_photonLocation)){
00224     log <<MSG::DEBUG << "Could not find Photons"<<endreq;
00225   }
00226   log << MSG::DEBUG << "processing Photons: " <<rp.size()<< endreq;
00227   
00228   irp  = rp.begin();
00229   
00230   m_npho = 0;
00231   for (; irp != rp.end(); ++irp) {
00232     m_codepho[m_npho] = (*irp)->pdg_id();
00233     m_pxpho[m_npho]   = (*irp)->momentum().px();
00234     m_pypho[m_npho]   = (*irp)->momentum().py();
00235     m_pzpho[m_npho]   = (*irp)->momentum().pz();
00236     m_eepho[m_npho]   = (*irp)->momentum().e();
00237     if (++m_npho == m_npho->range().distance() ) {
00238       log << MSG::WARNING << "Photon list truncated in Ntuple" << endreq;
00239       break;
00240     }
00241   }
00242 
00243   //-------------------
00244   // Retrieve Isolated Muons
00245   //-------------------
00246     
00247   rp.clear();
00248   if(!m_tesIO->copy
00249      <ReconstructedParticleCollection>(rp, m_isolatedMuonLocation)){
00250     log <<MSG::DEBUG << "Could not find Isolated Muons"<<endreq;
00251   }
00252   log << MSG::DEBUG << "Isolated Muons: " <<rp.size()<< endreq;
00253   
00254   irp  = rp.begin();
00255   
00256   m_nmuo = 0;
00257   
00258   for (; irp != rp.end(); ++irp) {
00259     m_codemuo[m_nmuo] = (*irp)->pdg_id();
00260     m_pxmuo[m_nmuo]   = (*irp)->momentum().px();
00261     m_pymuo[m_nmuo]   = (*irp)->momentum().py();
00262     m_pzmuo[m_nmuo]   = (*irp)->momentum().pz();
00263     m_eemuo[m_nmuo]   = (*irp)->momentum().e();
00264     if (++m_nmuo == m_nmuo->range().distance() ) {
00265       log << MSG::WARNING 
00266           << "Isolated Muon list truncated in Ntuple" << endreq;
00267       break;
00268     }
00269   }
00270 
00271   //-------------------
00272   // Retrieve NonIsolated Muons
00273   //-------------------
00274   
00275   rp.clear();
00276   if(!m_tesIO->copy
00277      <ReconstructedParticleCollection >(rp, m_nonIsolatedMuonLocation)){
00278     log <<MSG::DEBUG << "Could not find non Isolated muons"<<endreq;
00279   }
00280   log << MSG::DEBUG << "NonIsolated Muons: " <<rp.size()<< endreq;
00281   irp  = rp.begin();
00282   
00283   m_nmux = 0;
00284   
00285   for (; irp != rp.end(); ++irp) {
00286     m_codemux[m_nmux] = (*irp)->pdg_id();
00287     m_pxmux[m_nmux]   = (*irp)->momentum().px();
00288     m_pymux[m_nmux]   = (*irp)->momentum().py();
00289     m_pzmux[m_nmux]   = (*irp)->momentum().pz();
00290     m_eemux[m_nmux]   = (*irp)->momentum().e();
00291     if (++m_nmux == m_nmux->range().distance() ) {
00292       log << MSG::WARNING 
00293           << "Non-isolated Muon list truncated in Ntuple" << endreq;
00294       break;
00295     }
00296   }
00297 
00298   //-------------------
00299   // Retrieve Jets
00300   //-------------------
00301   
00302   std::vector<Jet*> jv;
00303   if(!m_tesIO->copy<JetCollection >(jv, m_jetLocation)){
00304     log <<MSG::DEBUG << "Could not find Jets"<<endreq;
00305   }
00306   log << MSG::DEBUG << "Processing Jets: " <<jv.size()<< endreq;
00307   
00308   std::vector<Jet*>::const_iterator ijv  = jv.begin();
00309   
00310   m_njet = 0;
00311   
00312   for (; ijv != jv.end(); ++ijv) {
00313     m_codejet[m_njet]= (*ijv)->pdg_id();
00314     m_pxjet[m_njet]  = (*ijv)->px();
00315     m_pyjet[m_njet]  = (*ijv)->py();
00316     m_pzjet[m_njet]  = (*ijv)->pz();
00317     m_eejet[m_njet]  = (*ijv)->e();
00318     m_ptcalo[m_njet] = (*ijv)->pT();
00319     m_ptbjet[m_njet] = m_jetCal->bCalibrate( (*ijv)->pT() );
00320     m_ptujet[m_njet] = m_jetCal->uCalibrate( (*ijv)->pT() );
00321     if ( ++m_njet == m_njet->range().distance() ) break;
00322   }
00323   log << MSG::DEBUG << " Jets in ntuple" << endreq;
00324   
00325   
00326   //-------------------
00327   // Retrieve AtlfastB Jets
00328   //-------------------
00329     
00330   std::vector<Jet*> jvb;
00331   if(!m_tesIO->copy<JetCollection >(jvb, m_jetBLocation)){
00332     log <<MSG::DEBUG << "Could not find AtlfastB Jets"<<endreq;
00333   }
00334   log << MSG::DEBUG << "Processing AtlfastB Jets: " <<jvb.size()<< endreq;
00335   
00336   ijv  = jvb.begin();
00337   
00338   m_njetB = 0;
00339   
00340   for (; ijv != jvb.end(); ++ijv) {
00341     m_codejetB[m_njetB]= (*ijv)->pdg_id();
00342     m_pxjetB[m_njetB]  = (*ijv)->px();
00343     m_pyjetB[m_njetB]  = (*ijv)->py();
00344     m_pzjetB[m_njetB]  = (*ijv)->pz();
00345     m_eejetB[m_njetB]  = (*ijv)->e();
00346     if ( ++m_njetB == m_njetB->range().distance() ) break;
00347   }
00348   log << MSG::DEBUG << " AtlfastB Jets in ntuple" << endreq;
00349   
00350   
00351   MCparticleCollection mc;
00352   
00353   HepMC_helper::All* all= new  HepMC_helper::All;
00354   TesIoStat stat = m_tesIO->getMC(mc, all);
00355   delete all;
00356   
00357   if(stat){
00358     log << MSG::DEBUG << " found MC truth" << endreq;
00359   }else{
00360     log << MSG::ERROR << " MC truth not found in TES" << endreq;
00361   }
00362 
00363   MCparticleCollection::const_iterator imc = mc.begin();
00364   m_npart=0;
00365   
00366   HepMC_helper::IsStatusxx isf(3);
00367   
00368   for(;imc != mc.end(); ++imc){
00369     if(isf(*imc)){
00370       m_kppart[m_npart]  = (*imc)->barcode();
00371       m_kspart[m_npart]  = (*imc)->status()%100;
00372       m_kfpart[m_npart]  = (*imc)->pdg_id();
00373       std::pair<int, int> parentCodes = getParentCodes(imc);
00374       m_kfmoth[m_npart]  = parentCodes.first;        
00375       m_kpmoth[m_npart]  = parentCodes.second;
00376       m_pxpart[m_npart]  = (*imc)->momentum().x();
00377       m_pypart[m_npart]  = (*imc)->momentum().y();
00378       m_pzpart[m_npart]  = (*imc)->momentum().z();
00379       m_eepart[m_npart]  = (*imc)->momentum().e();
00380       ++m_npart;
00381     }
00382     
00383     if ( m_npart == m_npart->range().distance() ) break;
00384   }
00385   
00386   log << MSG::DEBUG << " Particles in ntuple" << endreq;      
00387     
00388   const DataHandle<EventHeader> theEventHeader;
00389   if(!(m_tesIO->getDH(theEventHeader))){
00390     log << MSG::ERROR<<"Could not find the event header in the TES"<<endreq;
00391   }
00392   
00393   if(theEventHeader.isValid()){
00394     m_isub   = 0;
00395     m_njetb  = theEventHeader->nBJets();
00396     m_njetc  = theEventHeader->nCJets();
00397     m_njettau= theEventHeader->nTauJets();
00398     m_pxmiss = theEventHeader->pMiss().x();
00399     m_pymiss = theEventHeader->pMiss().y();
00400     m_pxnue  = theEventHeader->pEscaped().x();
00401     m_pynue  = theEventHeader->pEscaped().y();
00402   } else {
00403     log << MSG::ERROR << " Invalid EventHeader data handle" << endreq;
00404   }
00405   
00406   log << MSG::DEBUG << " EventHeader quantities are in ntuple" << endreq;
00407 
00408 
00409   return StatusCode::SUCCESS;
00410 
00411 }
00412 
00413   std::pair<int, int> 
00414   CBNT_Atlfast::getParentCodes(MCparticleCollection::const_iterator& 
00415                                       imc){
00416     
00417     HepMC::GenVertex* gv = (*imc)->production_vertex();
00418     if ( gv == 0 ){ return std::pair<int, int>(0,0);}
00419     
00420     if ( gv->particles_in_size() == 0 ) { return std::pair<int, int>(0,0); }
00421 
00422     HepMC::GenVertex::particle_iterator 
00423       pi = gv->particles_begin(HepMC::parents);
00424     if( *pi == 0 ){ return std::pair<int, int>(0,0); }
00425       
00426 
00427     return std::pair<int, int>( (*pi)->pdg_id(), (*pi)->barcode() );
00428   }
00429 
00430 //<<<<<< METHOD finalize
00431 
00432 StatusCode CBNT_Atlfast::finalize() {
00433     //  MsgStream log(messageService(), name());
00434     //log << MSG::INFO << "in finalize() ..." << endreq;
00435   return StatusCode::SUCCESS;
00436 }
00437 
00438 
00439 // reaccess Ntuple (should already have been booked)
00440 StatusCode CBNT_Atlfast::accessNtuple() {
00441   MsgStream log(messageService(), name());
00442 
00443 //try to access it  
00444   NTuplePtr nt(ntupleService(),"/NTUPLES"+m_NtupleLocID);
00445 
00446   if (nt) 
00447   {
00448       p_nt=nt;
00449       log << MSG::INFO << "Ntuple " <<m_NtupleLocID 
00450           << " reaccessed! " << endreq;
00451       return StatusCode::SUCCESS;
00452   } else
00453   {
00454       log << MSG::FATAL << "Cannot reaccess " << m_NtupleLocID << endreq;
00455       return StatusCode::FAILURE;
00456   }
00457 }
00458  
00459 
00460 
00461 
00462 
00463 }

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