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

StandardNtupleMaker.cxx

Go to the documentation of this file.
00001 //  ====================================================================
00002 //  StandardNtupleMaker.cxx
00003 //  -----------------r---------------------------------------------------
00004 //
00005 //  This is the implementation of Standard Ntuple Maker which 
00006 //  creates the combined Ntuple based upon entities in the TES
00007 //  This code is based upon AtlfastSTLNtupAlg by E. Richter-Was 
00008 //  
00009 //
00010 //  Authors   : H.T. Phillips, P. Clarke, P. Sherwood, 
00011 //                 R. Steward, E. Richter-Was
00012 //
00013 //  ====================================================================
00014 #include "AtlfastAlgs/StandardNtupleMaker.h"
00015 #include "AtlfastAlgs/JetRecalibrator.h"
00016 
00017 #include "AtlfastUtils/HeaderPrinter.h"
00018 #include "AtlfastUtils/HepMC_helper/IsStatusxx.h"
00019 #include "AtlfastUtils/HepMC_helper/All.h"
00020 
00021 #include "AtlfastEvent/ReconstructedParticle.h"
00022 #include "AtlfastEvent/CollectionDefs.h"
00023 #include "AtlfastEvent/Jet.h"
00024 #include "AtlfastEvent/EventHeader.h"
00025 // Framework include files
00026 #include "GaudiKernel/PropertyMgr.h"
00027 #include "GaudiKernel/INTupleSvc.h"
00028 #include "GaudiKernel/ISvcLocator.h"
00029 #include "GaudiKernel/IDataProviderSvc.h"
00030 #include "GaudiKernel/MsgStream.h"
00031 #include "GaudiKernel/NTuple.h"
00032 #include "GaudiKernel/SmartDataPtr.h" //need for ntuple core code
00033 
00034 // CLHEP,HepMC
00035 #include "GeneratorObjects/McEventCollection.h"
00036 #include "HepMC/GenEvent.h"
00037 
00038 
00039 #include "GaudiKernel/ObjectList.h"
00040 
00041 // Example related include files
00042  //
00043 #include <cmath> 
00044 #include <pair.h>
00045 
00050 namespace Atlfast {
00051 
00052   StandardNtupleMaker::StandardNtupleMaker(const std::string& name, ISvcLocator* pSvcLocator) 
00053     :  Algorithm(name, pSvcLocator)      {
00054     
00055     m_atlfastEventLocation    = "/Event/Atlfast";
00056     m_jetLocation             = "/Event/AtlfastJets";
00057     m_jetBLocation            = "/Event/AtlfastBJets";
00058     m_electronLocation        = "/Event/AtlfastIsolatedElectrons";
00059     m_isolatedMuonLocation    = "/Event/AtlfastIsolatedMuons";
00060     m_nonIsolatedMuonLocation = "/Event/AtlfastNonIsolatedMuons";
00061     m_photonLocation          = "/Event/AtlfastIsolatedPhotons";
00062     //    m_trackLocation           = DEFAULT_trackLocation;
00063     m_mcTruthLocation         = "/Event/McEventCollection";
00064     m_bPhysicsLocation        = "/Event/AtlfastBPhysics";
00065     //    m_triggerLocation         = DEFAULT_triggerLocation;
00066     m_eventHeaderLocation     = "/Event/AtlfastEventHeader";
00067     
00068     declareProperty( "AtlfastEventLocation",    m_atlfastEventLocation );
00069     declareProperty( "JetLocation",             m_jetLocation );
00070     declareProperty( "JetBLocation",            m_jetBLocation );
00071     declareProperty( "ElectronLocation",        m_electronLocation );
00072     declareProperty( "IsolatedMuonLocation",    m_isolatedMuonLocation );
00073     declareProperty( "NonIsolatedMuonLocation", m_nonIsolatedMuonLocation );
00074     declareProperty( "PhotonLocation",          m_photonLocation );
00075     //    declareProperty( "TrackLocation", m_trackLocation );
00076     declareProperty( "McTruthLocation",         m_mcTruthLocation );
00077     declareProperty( "BPhysicsLocation",        m_bPhysicsLocation );
00078     //    declareProperty( "TriggerLocation",m_triggerLocation );
00079     declareProperty( "EventHeaderLocation",     m_eventHeaderLocation );
00080     
00081     
00082   }
00083   //********************************************************
00084   StandardNtupleMaker::~StandardNtupleMaker(){
00085     delete m_tesIO;
00086     delete m_jetCal;
00087   }
00088   
00089   // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
00090   
00091   StatusCode StandardNtupleMaker::initialize() {
00092     MsgStream log(msgSvc(), name());
00093     log << MSG::DEBUG << "Initialising SNM" << endreq;
00094     StatusCode status;
00095     
00096     m_nEvents = 0;   
00097     //
00098     log << MSG::DEBUG << "Ntuple call 51" << endreq;
00099     NTuple::Directory* col = 0;
00100     log << MSG::DEBUG << "About to open ntuple file" << endreq;
00101     NTupleFilePtr file1(ntupleSvc(), "/NTUPLES/FILE1");
00102     if ( file1 )    {
00103       log << MSG::DEBUG << "Opened ntuple file" << endreq;
00104       if ( !(col=ntupleSvc()->createDirectory("/NTUPLES/FILE1/Atlfast")) )   {
00105         log << MSG::ERROR << "Cannot create directory /NTUPLES/FILE1/Atlfast" 
00106             << endreq;  
00107         return StatusCode::FAILURE;
00108       }else{
00109         log << MSG::DEBUG << "Created ntuple directory" << endreq;
00110       }
00111     }
00112     else    {
00113       log << MSG::ERROR << "Cannot access file /NTUPLES/FILE1" << endreq;  
00114       return StatusCode::FAILURE;
00115     }
00116     // First: A column wise N tuple
00117     NTuplePtr nt1(ntupleSvc(), "/NTUPLES/FILE1/Atlfast/51");
00118     if ( !nt1 )    {    // Check if already booked
00119       nt1 = ntupleSvc()->book (col, 51, CLID_ColumnWiseTuple, "Atlfast51");
00120       if ( nt1 )    {
00121         log << MSG::DEBUG << "booked ntuple " << endreq;
00122         // Add an index column
00123         // Electrons
00124         status = nt1->addItem ("PLEPTONS/NELE"      , m_nele, 0, 12 );
00125         status = nt1->addItem ("PLEPTONS/KFELE"     , m_nele, m_codeele);
00126         status = nt1->addItem ("PLEPTONS/PXELE"     , m_nele, m_pxele);
00127         status = nt1->addItem ("PLEPTONS/PYELE"     , m_nele, m_pyele);
00128         status = nt1->addItem ("PLEPTONS/PZELE"     , m_nele, m_pzele);
00129         status = nt1->addItem ("PLEPTONS/EEELE"     , m_nele, m_eeele);
00130         // Photons
00131         status = nt1->addItem ("PPHOTONS/NPHO"      , m_npho, 0, 12 );
00132         status = nt1->addItem ("PPHOTONS/KFPHO"     , m_npho, m_codepho);
00133         status = nt1->addItem ("PPHOTONS/PXPHO"     , m_npho, m_pxpho);
00134         status = nt1->addItem ("PPHOTONS/PYPHO"     , m_npho, m_pypho);
00135         status = nt1->addItem ("PPHOTONS/PZPHO"     , m_npho, m_pzpho);
00136         status = nt1->addItem ("PPHOTONS/EEPHO"     , m_npho, m_eepho);
00137         // Muons (isolated)
00138         status = nt1->addItem ("PLEPTONS/NMUO"      , m_nmuo, 0, 12 );
00139         status = nt1->addItem ("PLEPTONS/KFMUO"     , m_nmuo, m_codemuo);
00140         status = nt1->addItem ("PLEPTONS/PXMUO"     , m_nmuo, m_pxmuo);
00141         status = nt1->addItem ("PLEPTONS/PYMUO"     , m_nmuo, m_pymuo);
00142         status = nt1->addItem ("PLEPTONS/PZMUO"     , m_nmuo, m_pzmuo);
00143         status = nt1->addItem ("PLEPTONS/EEMUO"     , m_nmuo, m_eemuo);
00144         // MuonsX (non-isolated)
00145         status = nt1->addItem ("PMUXS/NMUX"      , m_nmux, 0, 12 );
00146         status = nt1->addItem ("PMUXS/KFMUX"     , m_nmux, m_codemux);
00147         status = nt1->addItem ("PMUXS/PXMUX"     , m_nmux, m_pxmux);
00148         status = nt1->addItem ("PMUXS/PYMUX"     , m_nmux, m_pymux);
00149         status = nt1->addItem ("PMUXS/PZMUX"     , m_nmux, m_pzmux);
00150         status = nt1->addItem ("PMUXS/EEMUX"     , m_nmux, m_eemux);
00151         // Jets
00152         status = nt1->addItem ("PPJETS/NJET"      , m_njet, 0, 40 );
00153         status = nt1->addItem ("PPJETS/KFJET"     , m_njet, m_codejet);
00154         status = nt1->addItem ("PPJETS/PXJET"     , m_njet, m_pxjet);
00155         status = nt1->addItem ("PPJETS/PYJET"     , m_njet, m_pyjet);
00156         status = nt1->addItem ("PPJETS/PZJET"     , m_njet, m_pzjet);
00157         status = nt1->addItem ("PPJETS/EEJET"     , m_njet, m_eejet);
00158         status = nt1->addItem ("PPJETS/PTcalo"    , m_njet, m_ptcalo);
00159         status = nt1->addItem ("PPJETS/PTbjet"    , m_njet, m_ptbjet);
00160         status = nt1->addItem ("PPJETS/PTujet"    , m_njet, m_ptujet);
00161         // Jets calibrated by AtlfastB
00162         status = nt1->addItem ("PPJETS/NJETB"      , m_njetB, 0, 40 );
00163         status = nt1->addItem ("PPJETS/KFJETB"     , m_njetB, m_codejetB);
00164         status = nt1->addItem ("PPJETS/PXJETB"     , m_njetB, m_pxjetB);
00165         status = nt1->addItem ("PPJETS/PYJETB"     , m_njetB, m_pyjetB);
00166         status = nt1->addItem ("PPJETS/PZJETB"     , m_njetB, m_pzjetB);
00167         status = nt1->addItem ("PPJETS/EEJETB"     , m_njetB, m_eejetB);
00168         // History
00169         // History
00170         status = nt1->addItem ("PHISTORY/NPART"     , m_npart, 0, 40 );
00171         status = nt1->addItem ("PHISTORY/KPPART"    , m_npart, m_kppart);
00172         status = nt1->addItem ("PHISTORY/KSPART"    , m_npart, m_kspart);
00173         status = nt1->addItem ("PHISTORY/KFPART"    , m_npart, m_kfpart);
00174         status = nt1->addItem ("PHISTORY/KPMOTH"    , m_npart, m_kpmoth);
00175         status = nt1->addItem ("PHISTORY/KFMOTH"    , m_npart, m_kfmoth);
00176         status = nt1->addItem ("PHISTORY/PXPART"    , m_npart, m_pxpart);
00177         status = nt1->addItem ("PHISTORY/PYPART"    , m_npart, m_pypart);
00178         status = nt1->addItem ("PHISTORY/PZPART"    , m_npart, m_pzpart);
00179         status = nt1->addItem ("PHISTORY/EEPART"    , m_npart, m_eepart);
00180         
00181         //status = nt1->addItem ("PHISTORY/NPART"     , m_npart, 0, 40 );
00182         //status = nt1->addItem ("PHISTORY/KFPART"    , m_npart, m_kfpart);
00183         //status = nt1->addItem ("PHISTORY/PXPART"    , m_npart, m_pxpart);
00184         //status = nt1->addItem ("PHISTORY/PYPART"    , m_npart, m_pypart);
00185         //status = nt1->addItem ("PHISTORY/PZPART"    , m_npart, m_pzpart);
00186         //status = nt1->addItem ("PHISTORY/EEPART"    , m_npart, m_eepart);
00187         // Missing
00188         status = nt1->addItem ("INFO/ISUB"      , m_isub);
00189         status = nt1->addItem ("INFO/JETB"      , m_njetb);
00190         status = nt1->addItem ("INFO/JETC"      , m_njetc);
00191         status = nt1->addItem ("INFO/JETTAU"    , m_njettau);
00192         status = nt1->addItem ("PMISSING/PXMISS"    , m_pxmiss);
00193         status = nt1->addItem ("PMISSING/PYMISS"    , m_pymiss);
00194         status = nt1->addItem ("PMISSING/PXNUE"     , m_pxnue);
00195         status = nt1->addItem ("PMISSING/PYNUE"     , m_pynue);
00196         //tracks
00197         //status = nt1->addItem ("PTRACKS/NTRA"      , m_ntra, 0, 500 );
00198         //status = nt1->addItem ("PTRACKS/KPTRA"     , m_ntra, m_kpTruth);
00199         //status = nt1->addItem ("PTRACKS/KFTRA"     , m_ntra, m_kfTruth);
00200           //
00201         //status = nt1->addItem ("PTRACKS/KPM1TRA"   , m_ntra, m_kpm1tra);
00202         //status = nt1->addItem ("PTRACKS/KFM1TRA"   , m_ntra, m_kfm1tra);
00203         //status = nt1->addItem ("PTRACKS/KPM2TRA"   , m_ntra, m_kpm2tra);
00204         //status = nt1->addItem ("PTRACKS/KFM2TRA"   , m_ntra, m_kfm2tra);
00205         //status = nt1->addItem ("PTRACKS/KPM3TRA"   , m_ntra, m_kpm3tra);
00206         //status = nt1->addItem ("PTRACKS/KFM3TRA"   , m_ntra, m_kfm3tra);
00207         //status = nt1->addItem ("PTRACKS/KPM4TRA"   , m_ntra, m_kpm4tra);
00208         //status = nt1->addItem ("PTRACKS/KFM4TRA"   , m_ntra, m_kfm4tra);
00209         //status = nt1->addItem ("PTRACKS/KPM5TRA"   , m_ntra, m_kpm5tra);
00210         //status = nt1->addItem ("PTRACKS/KFM5TRA"   , m_ntra, m_kfm5tra);
00211         //status = nt1->addItem ("PTRACKS/KPM6TRA"   , m_ntra, m_kpm6tra);
00212         //status = nt1->addItem ("PTRACKS/KFM6TRA"   , m_ntra, m_kfm6tra);
00213           //
00214         //status = nt1->addItem ("PTRACKS/D0TRA  "      , m_ntra, m_d0Truth);
00215         //status = nt1->addItem ("PTRACKS/Z0TRA  "      , m_ntra, m_z0Truth);
00216         //status = nt1->addItem ("PTRACKS/PHITRA "      , m_ntra, m_phiTruth);
00217         //status = nt1->addItem ("PTRACKS/COTTRA "      , m_ntra, m_cotTruth);
00218         //status = nt1->addItem ("PTRACKS/PTINVTRA "    , m_ntra, m_ptInvTruth);
00219         //
00220         //status = nt1->addItem ("PTRACKS/D0TRACRU  "   , m_ntra, m_d0Track);
00221         //status = nt1->addItem ("PTRACKS/Z0TRACRU  "   , m_ntra, m_z0Track);
00222         //status = nt1->addItem ("PTRACKS/PHITRACRU "   , m_ntra, m_phiTrack);
00223         //status = nt1->addItem ("PTRACKS/COTTRACRU "   , m_ntra, m_cotTrack);
00224         //status = nt1->addItem ("PTRACKS/PTINVTRACRU " , m_ntra, m_ptInvTrack);
00225         //
00226         //status = nt1->addItem ("PTRACKS/CORR11TRA "   , m_ntra, m_corr11tra);
00227         //status = nt1->addItem ("PTRACKS/CORR21TRA "   , m_ntra, m_corr12tra);
00228         //status = nt1->addItem ("PTRACKS/CORR31TRA "   , m_ntra, m_corr13tra);
00229         //status = nt1->addItem ("PTRACKS/CORR41TRA "   , m_ntra, m_corr14tra);
00230         //status = nt1->addItem ("PTRACKS/CORR51TRA "   , m_ntra, m_corr15tra);
00231         //status = nt1->addItem ("PTRACKS/CORR22TRA "   , m_ntra, m_corr22tra);
00232         //status = nt1->addItem ("PTRACKS/CORR23TRA "   , m_ntra, m_corr23tra);
00233         //status = nt1->addItem ("PTRACKS/CORR24TRA "   , m_ntra, m_corr24tra);
00234         //status = nt1->addItem ("PTRACKS/CORR25TRA "   , m_ntra, m_corr25tra);
00235         //status = nt1->addItem ("PTRACKS/CORR33TRA "   , m_ntra, m_corr33tra);
00236         //status = nt1->addItem ("PTRACKS/CORR34TRA "   , m_ntra, m_corr34tra);
00237         //status = nt1->addItem ("PTRACKS/CORR34TRA "   , m_ntra, m_corr34tra);
00238         //status = nt1->addItem ("PTRACKS/CORR35TRA "   , m_ntra, m_corr35tra);
00239         //status = nt1->addItem ("PTRACKS/CORR44TRA "   , m_ntra, m_corr44tra);
00240         //status = nt1->addItem ("PTRACKS/CORR45TRA "   , m_ntra, m_corr45tra);
00241         //status = nt1->addItem ("PTRACKS/CORR55TRA "   , m_ntra, m_corr55tra);
00242       }
00243       else    {   // did not manage to book the N tuple....
00244         return StatusCode::FAILURE;
00245       }
00246     }
00247 
00248     m_jetCal = new JetRecalibrator();
00249     log<<MSG::DEBUG<<"returning sith status"<< status<<endreq;
00250     //    m_tesIO = new TesIO(eventDataService());
00251     m_tesIO = new TesIO();
00252 
00253     HeaderPrinter hp("Atlfast StandardNtuleMaker:", log);
00254     hp.add("MC location                 ", m_mcTruthLocation);
00255     hp.add("Electron Location           ", m_electronLocation);
00256     hp.add("Photon   Location           ", m_photonLocation);
00257     hp.add("Isolated Muon Location      ", m_isolatedMuonLocation);
00258     hp.add("Non-Isolated Muon Location  ", m_nonIsolatedMuonLocation);
00259     hp.add("Jet Location                ", m_jetLocation);
00260     hp.add("EventHeaderLocation         ", m_eventHeaderLocation );
00261     hp.print();
00262     //    declareProperty( "TriggerLocation",m_triggerLocation );
00263 
00264 
00265     return StatusCode::SUCCESS;
00266   }
00267   // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
00268   
00269   StatusCode StandardNtupleMaker::execute() {
00270     // This just makes the code below a bit easier to read (and type)
00271     MsgStream log(msgSvc(), name());
00272     log << MSG::DEBUG << "****Start execute()****" << endreq;
00273     
00274     // Counter of events processed
00275     if( m_nEvents % 50 == 0) {
00276       log << MSG::INFO << "    processing event number " 
00277           << m_nEvents << endreq;
00278     }     
00279     
00280     m_nEvents++;  
00281     
00282     StatusCode status;
00283 
00284     //-------------------
00285     // Retrieve Electrons 
00286     //-------------------
00287     std::vector<ReconstructedParticle*> rp;
00288     if(!m_tesIO->copy<ReconstructedParticleCollection>(rp,m_electronLocation)){
00289       log <<MSG::DEBUG << "Could not find Electrons"<<endreq;
00290     }
00291     log << MSG::DEBUG << "processing Electrons: " <<rp.size()<< endreq;
00292 
00293     std::vector<ReconstructedParticle*>::const_iterator irp  = rp.begin();
00294 
00295     m_nele = 0;
00296     for (; irp != rp.end(); ++irp) {
00297       m_codeele[m_nele] = (*irp)->pdg_id();
00298       m_pxele[m_nele]   = (*irp)->momentum().px();
00299       m_pyele[m_nele]   = (*irp)->momentum().py();
00300       m_pzele[m_nele]   = (*irp)->momentum().pz();
00301       m_eeele[m_nele]   = (*irp)->momentum().e();
00302       if (++m_nele == m_nele->range().distance() ) {
00303         log << MSG::WARNING << "Electron list truncated in Ntuple" << endreq;
00304         break;
00305       }
00306     }
00307 
00308     //-------------------
00309     // Retrieve Photons 
00310     //-------------------
00311 
00312     rp.clear();
00313     if(!m_tesIO->copy <ReconstructedParticleCollection>(rp, m_photonLocation)){
00314       log <<MSG::DEBUG << "Could not find Photons"<<endreq;
00315     }
00316     log << MSG::DEBUG << "processing Photons: " <<rp.size()<< endreq;
00317 
00318     irp  = rp.begin();
00319     
00320     m_npho = 0;
00321     for (; irp != rp.end(); ++irp) {
00322       m_codepho[m_npho] = (*irp)->pdg_id();
00323       m_pxpho[m_npho]   = (*irp)->momentum().px();
00324       m_pypho[m_npho]   = (*irp)->momentum().py();
00325       m_pzpho[m_npho]   = (*irp)->momentum().pz();
00326       m_eepho[m_npho]   = (*irp)->momentum().e();
00327       if (++m_npho == m_npho->range().distance() ) {
00328         log << MSG::WARNING << "Photon list truncated in Ntuple" << endreq;
00329         break;
00330       }
00331     }
00332 
00333     //-------------------
00334     // Retrieve Isolated Muons
00335     //-------------------
00336     
00337     rp.clear();
00338     if(!m_tesIO->copy
00339        <ReconstructedParticleCollection>(rp, m_isolatedMuonLocation)){
00340       log <<MSG::DEBUG << "Could not find Isolated Muons"<<endreq;
00341     }
00342     log << MSG::DEBUG << "Isolated Muons: " <<rp.size()<< endreq;
00343 
00344     irp  = rp.begin();
00345     
00346     m_nmuo = 0;
00347     
00348     for (; irp != rp.end(); ++irp) {
00349       m_codemuo[m_nmuo] = (*irp)->pdg_id();
00350       m_pxmuo[m_nmuo]   = (*irp)->momentum().px();
00351       m_pymuo[m_nmuo]   = (*irp)->momentum().py();
00352       m_pzmuo[m_nmuo]   = (*irp)->momentum().pz();
00353       m_eemuo[m_nmuo]   = (*irp)->momentum().e();
00354       if (++m_nmuo == m_nmuo->range().distance() ) {
00355         log << MSG::WARNING 
00356             << "Isolated Muon list truncated in Ntuple" << endreq;
00357         break;
00358       }
00359     }
00360 
00361     //-------------------
00362     // Retrieve NonIsolated Muons
00363     //-------------------
00364     
00365     rp.clear();
00366     if(!m_tesIO->copy
00367        <ReconstructedParticleCollection >(rp, m_nonIsolatedMuonLocation)){
00368       log <<MSG::DEBUG << "Could not find non Isolated muons"<<endreq;
00369     }
00370     log << MSG::DEBUG << "NonIsolated Muons: " <<rp.size()<< endreq;
00371     irp  = rp.begin();
00372     
00373     m_nmux = 0;
00374     
00375     for (; irp != rp.end(); ++irp) {
00376       m_codemux[m_nmux] = (*irp)->pdg_id();
00377       m_pxmux[m_nmux]   = (*irp)->momentum().px();
00378       m_pymux[m_nmux]   = (*irp)->momentum().py();
00379       m_pzmux[m_nmux]   = (*irp)->momentum().pz();
00380       m_eemux[m_nmux]   = (*irp)->momentum().e();
00381       if (++m_nmux == m_nmux->range().distance() ) {
00382         log << MSG::WARNING 
00383             << "Non-isolated Muon list truncated in Ntuple" << endreq;
00384         break;
00385       }
00386     }
00387 
00388     //-------------------
00389     // Retrieve Jets
00390     //-------------------
00391     
00392     std::vector<Jet*> jv;
00393     if(!m_tesIO->copy<JetCollection >(jv, m_jetLocation)){
00394       log <<MSG::DEBUG << "Could not find Jets"<<endreq;
00395     }
00396     log << MSG::DEBUG << "Processing Jets: " <<jv.size()<< endreq;
00397 
00398     std::vector<Jet*>::const_iterator ijv  = jv.begin();
00399     
00400     m_njet = 0;
00401     
00402     for (; ijv != jv.end(); ++ijv) {
00403       m_codejet[m_njet]= (*ijv)->pdg_id();
00404       m_pxjet[m_njet]  = (*ijv)->px();
00405       m_pyjet[m_njet]  = (*ijv)->py();
00406       m_pzjet[m_njet]  = (*ijv)->pz();
00407       m_eejet[m_njet]  = (*ijv)->e();
00408       m_ptcalo[m_njet] = (*ijv)->pT();
00409       m_ptbjet[m_njet] = m_jetCal->bCalibrate( (*ijv)->pT() );
00410       m_ptujet[m_njet] = m_jetCal->uCalibrate( (*ijv)->pT() );
00411       if ( ++m_njet == m_njet->range().distance() ) break;
00412     }
00413     log << MSG::DEBUG << " Jets in ntuple" << endreq;
00414 
00415 
00416     //-------------------
00417     // Retrieve AtlfastB Jets
00418     //-------------------
00419     
00420     std::vector<Jet*> jvb;
00421     if(!m_tesIO->copy<JetCollection >(jvb, m_jetBLocation)){
00422       log <<MSG::DEBUG << "Could not find AtlfastB Jets"<<endreq;
00423     }
00424     log << MSG::DEBUG << "Processing AtlfastB Jets: " <<jvb.size()<< endreq;
00425 
00426     ijv  = jvb.begin();
00427     
00428     m_njetB = 0;
00429     
00430     for (; ijv != jvb.end(); ++ijv) {
00431       m_codejetB[m_njetB]= (*ijv)->pdg_id();
00432       m_pxjetB[m_njetB]  = (*ijv)->px();
00433       m_pyjetB[m_njetB]  = (*ijv)->py();
00434       m_pzjetB[m_njetB]  = (*ijv)->pz();
00435       m_eejetB[m_njetB]  = (*ijv)->e();
00436       if ( ++m_njetB == m_njetB->range().distance() ) break;
00437     }
00438     log << MSG::DEBUG << " AtlfastB Jets in ntuple" << endreq;
00439 
00440     //-------------------
00441     // Retrieve Status 21 quarks (fudged with final state collector FIXME)
00442     //-------------------
00443     //***PS    std::vector<HepMC::GenParticle*> mc;
00444     //***PS    m_tesIO->getMC( mc, m_mcTruthLocation, &isf) ;
00445     //***PS
00446     //***PS    log << MSG::DEBUG << "Processing partons" <<mc.size()<< endreq;
00447     //***PS
00448     //***PS    std::vector<HepMC::GenParticle*>::const_iterator imc  = mc.begin();
00449     
00450     MCparticleCollection mc;
00451     //    TesIoStat stat = m_tesIO->getMC(mc, &isf);
00452 
00453     HepMC_helper::All* all= new  HepMC_helper::All;
00454     TesIoStat stat = m_tesIO->getMC(mc, all);
00455     delete all;
00456 
00457     if(stat){
00458       log << MSG::DEBUG << " found MC truth" << endreq;
00459     }else{
00460       log << MSG::ERROR << " MC truth not found in TES" << endreq;
00461     }
00462 
00463     MCparticleCollection::const_iterator imc = mc.begin();
00464     m_npart=0;
00465 
00466     HepMC_helper::IsStatusxx isf(3);
00467 
00468     for(;imc != mc.end(); ++imc){
00469       if(isf(*imc)){
00470         m_kppart[m_npart]  = (*imc)->barcode();
00471         m_kspart[m_npart]  = (*imc)->status()%100;
00472         m_kfpart[m_npart]  = (*imc)->pdg_id();
00473         std::pair<int, int> parentCodes = getParentCodes(imc);
00474         m_kfmoth[m_npart]  = parentCodes.first;      
00475         m_kpmoth[m_npart]  = parentCodes.second;
00476         //}else{
00477         m_pxpart[m_npart]  = (*imc)->momentum().x();
00478         m_pypart[m_npart]  = (*imc)->momentum().y();
00479         m_pzpart[m_npart]  = (*imc)->momentum().z();
00480         m_eepart[m_npart]  = (*imc)->momentum().e();
00481         ++m_npart;
00482       }
00483 
00484       if ( m_npart == m_npart->range().distance() ) break;
00485 
00486       //      m_kfpart[m_npart]  = (*imc)->pdg_id();
00487       //      m_pxpart[m_npart]  = (*imc)->momentum().x();
00488       //      m_pypart[m_npart]  = (*imc)->momentum().y();
00489       //      m_pzpart[m_npart]  = (*imc)->momentum().z();
00490       //      m_eepart[m_npart]  = (*imc)->momentum().e();
00491     }
00492     
00493     log << MSG::DEBUG << " Particles in ntuple" << endreq;      
00494     
00495     const DataHandle<EventHeader> theEventHeader;
00496     if(!(m_tesIO->getDH(theEventHeader))){
00497       log << MSG::ERROR<<"Could not find the event header in the TES"<<endreq;
00498     }
00499     
00500     if(theEventHeader.isValid()){
00501       m_isub   = 0;
00502       m_njetb  = theEventHeader->nBJets();
00503       m_njetc  = theEventHeader->nCJets();
00504       m_njettau= theEventHeader->nTauJets();
00505       m_pxmiss = theEventHeader->pMiss().x();
00506       m_pymiss = theEventHeader->pMiss().y();
00507       m_pxnue  = theEventHeader->pEscaped().x();
00508       m_pynue  = theEventHeader->pEscaped().y();
00509     } else {
00510       log << MSG::ERROR << " Invalid EventHeader data handle" << endreq;
00511     }
00512 
00513     log << MSG::DEBUG << " EventHeader quantities are in ntuple" << endreq;
00514 
00515     // Write out ntuples
00516     
00517     log << MSG::DEBUG << "Writing ntuple part 51" << endreq;
00518     status = ntupleSvc()->writeRecord("/NTUPLES/FILE1/Atlfast/51");
00519     if ( !status.isSuccess() ) log <<MSG::ERROR 
00520                                    <<"Cannot fill id 51"
00521                                    <<endreq;
00522     log << MSG::DEBUG << "Done all the ntuple writing" << endreq;
00523     return StatusCode::SUCCESS;
00524   }
00525   std::pair<int, int> 
00526   StandardNtupleMaker::getParentCodes(MCparticleCollection::const_iterator& 
00527                                       imc){
00528     
00529     HepMC::GenVertex* gv = (*imc)->production_vertex();
00530     if ( gv == 0 ){ return std::pair<int, int>(0,0);}
00531     
00532     if ( gv->particles_in_size() == 0 ) { return std::pair<int, int>(0,0); }
00533 
00534     HepMC::GenVertex::particle_iterator 
00535       pi = gv->particles_begin(HepMC::parents);
00536     if( *pi == 0 ){ return std::pair<int, int>(0,0); }
00537       
00538 
00539     return std::pair<int, int>( (*pi)->pdg_id(), (*pi)->barcode() );
00540   }
00541 
00542 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
00543   
00544   StatusCode StandardNtupleMaker::finalize() {
00545     
00546     MsgStream log(msgSvc(), name());
00547     log << MSG::INFO << "    Number of events processed      = " << m_nEvents << endreq;
00548     
00549     return StatusCode::SUCCESS;
00550   }
00551   
00552   
00553 } // end of namesapce bracket
00554 
00555 
00556 
00557 
00558 
00559 
00560 
00561 
00562 
00563 
00564 
00565 
00566 

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