diff --git a/PhysicsAnalysis/MCTruthClassifier/CMakeLists.txt b/PhysicsAnalysis/MCTruthClassifier/CMakeLists.txt index 63f27fe9abe54557a026153b6e202b7b87c68499..c545daad0af5b8b2f85ebddbcf4cf42d5d056f4e 100644 --- a/PhysicsAnalysis/MCTruthClassifier/CMakeLists.txt +++ b/PhysicsAnalysis/MCTruthClassifier/CMakeLists.txt @@ -1,3 +1,4 @@ +# $Id: CMakeLists.txt 779176 2016-10-19 10:15:04Z krasznaa $ ################################################################################ # Package: MCTruthClassifier ################################################################################ @@ -5,49 +6,79 @@ # Declare the package name: atlas_subdir( MCTruthClassifier ) +# Extra dependencies based on the environment: +set( extra_deps ) +set( extra_libs ) +if( XAOD_STANDALONE ) + set( extra_deps PRIVATE Control/xAODRootAccess ) +elseif( XAOD_ANALYSIS ) + set( extra_deps GaudiKernel ) + set( extra_libs GaudiKernel ) +else() + set( extra_deps GaudiKernel + Reconstruction/RecoTools/ParticlesInConeTools + PRIVATE + Generators/GeneratorObjects + Reconstruction/RecoTools/RecoToolInterfaces + Tracking/TrkEvent/TrkEventPrimitives + Tracking/TrkEvent/TrkParametersIdentificationHelpers + Control/AthenaKernel ) + set( extra_libs GaudiKernel + PRIVATE_LINK_LIBRARIES GeneratorObjects RecoToolInterfaces + TrkEventPrimitives TrkParametersIdentificationHelpers ) +endif() + # Declare the package's dependencies: -atlas_depends_on_subdirs( PUBLIC - Control/AthToolSupport/AsgTools - Event/xAOD/xAODCaloEvent - Event/xAOD/xAODEgamma - Event/xAOD/xAODJet - Event/xAOD/xAODMuon - Event/xAOD/xAODTracking - Event/xAOD/xAODTruth - GaudiKernel - Generators/GeneratorObjects - Reconstruction/RecoTools/ParticlesInConeTools - Reconstruction/RecoTools/RecoToolInterfaces - Tracking/TrkEvent/TrkEventPrimitives - Tracking/TrkEvent/TrkParametersIdentificationHelpers - PRIVATE - Control/AthenaKernel ) +atlas_depends_on_subdirs( + PUBLIC + Control/AthToolSupport/AsgTools + Event/xAOD/xAODCaloEvent + Event/xAOD/xAODEgamma + Event/xAOD/xAODJet + Event/xAOD/xAODMuon + Event/xAOD/xAODTracking + Event/xAOD/xAODTruth + ${extra_deps} ) # External dependencies: find_package( HepMC ) -find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread ) - -# Component(s) in the package: -atlas_add_library( MCTruthClassifierLib - src/*.cxx - Root/*.cxx - PUBLIC_HEADERS MCTruthClassifier - INCLUDE_DIRS ${HEPMC_INCLUDE_DIRS} - PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} - LINK_LIBRARIES ${HEPMC_LIBRARIES} AsgTools xAODCaloEvent xAODEgamma xAODJet xAODMuon xAODTracking xAODTruth GaudiKernel GeneratorObjects RecoToolInterfaces TrkEventPrimitives TrkParametersIdentificationHelpers - PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} ) - -atlas_add_component( MCTruthClassifier - src/components/*.cxx - INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS} - LINK_LIBRARIES ${ROOT_LIBRARIES} ${HEPMC_LIBRARIES} AsgTools xAODCaloEvent xAODEgamma xAODJet xAODMuon xAODTracking xAODTruth GaudiKernel GeneratorObjects RecoToolInterfaces TrkEventPrimitives TrkParametersIdentificationHelpers MCTruthClassifierLib ) +find_package( ROOT COMPONENTS Core RIO ) + +# Libraries in the package: +if( HEPMC_FOUND ) + atlas_add_library( MCTruthClassifierLib + MCTruthClassifier/*.h src/*.cxx Root/*.cxx + PUBLIC_HEADERS MCTruthClassifier + INCLUDE_DIRS ${HEPMC_INCLUDE_DIRS} + LINK_LIBRARIES ${HEPMC_LIBRARIES} AsgTools xAODCaloEvent xAODEgamma + xAODJet xAODMuon xAODTracking xAODTruth ${extra_libs} ) +else() + atlas_add_library( MCTruthClassifierLib + MCTruthClassifier/*.h src/*.cxx Root/*.cxx + PUBLIC_HEADERS MCTruthClassifier + LINK_LIBRARIES AsgTools xAODCaloEvent xAODEgamma + xAODJet xAODMuon xAODTracking xAODTruth ${extra_libs} ) +endif() + +if( NOT XAOD_STANDALONE ) + atlas_add_component( MCTruthClassifier + src/components/*.cxx + LINK_LIBRARIES GaudiKernel MCTruthClassifierLib ) +endif() atlas_add_dictionary( MCTruthClassifierDict - MCTruthClassifier/MCTruthClassifierDict.h - MCTruthClassifier/selection.xml - INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS} - LINK_LIBRARIES ${ROOT_LIBRARIES} ${HEPMC_LIBRARIES} AsgTools xAODCaloEvent xAODEgamma xAODJet xAODMuon xAODTracking xAODTruth GaudiKernel GeneratorObjects RecoToolInterfaces TrkEventPrimitives TrkParametersIdentificationHelpers MCTruthClassifierLib ) + MCTruthClassifier/MCTruthClassifierDict.h + MCTruthClassifier/selection.xml + LINK_LIBRARIES MCTruthClassifierLib ) + +# Executable(s) in the package: +if( XAOD_STANDALONE ) + atlas_add_executable( testClassifier + util/testClassifier.cxx + INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} + LINK_LIBRARIES ${ROOT_LIBRARIES} xAODRootAccess xAODEgamma + MCTruthClassifierLib ) +endif() # Install files from the package: atlas_install_python_modules( python/*.py ) - diff --git a/PhysicsAnalysis/MCTruthClassifier/MCTruthClassifier/IMCTruthClassifier.h b/PhysicsAnalysis/MCTruthClassifier/MCTruthClassifier/IMCTruthClassifier.h old mode 100755 new mode 100644 diff --git a/PhysicsAnalysis/MCTruthClassifier/Root/MCTruthClassifier.cxx b/PhysicsAnalysis/MCTruthClassifier/Root/MCTruthClassifier.cxx index c6f8b934a16044273fe4a5f92497606781542266..afd7e2ed931e3a33f8dafa9e3dc9da00e26c82d1 100644 --- a/PhysicsAnalysis/MCTruthClassifier/Root/MCTruthClassifier.cxx +++ b/PhysicsAnalysis/MCTruthClassifier/Root/MCTruthClassifier.cxx @@ -755,10 +755,15 @@ const xAOD::TruthParticle* MCTruthClassifier::getGenPart(const xAOD::TrackPartic theGenPartTmp=0; for(unsigned int ipOut=0; ipOut<EndVrtx->nOutgoingParticles();ipOut++){ const xAOD::TruthParticle* theDaugt=EndVrtx->outgoingParticle(ipOut); - if(!theDaugt) continue; - if(theDaugt->pdgId()==theGenParticle->pdgId()) theGenPartTmp=theDaugt; - if(theDaugt->pdgId()!=theGenParticle->pdgId()&&theDaugt->pdgId()!=22) + if(!theDaugt) { + continue; + } + if(theDaugt->pdgId()==theGenParticle->pdgId()) { + theGenPartTmp=theDaugt; + } + if(theDaugt->pdgId()!=theGenParticle->pdgId()&&theDaugt->pdgId()!=22){ theGenPartTmp=0; + } } itr++; @@ -771,12 +776,11 @@ const xAOD::TruthParticle* MCTruthClassifier::getGenPart(const xAOD::TrackPartic } else { EndVrtx = 0; - continue; } - } while (theGenPartTmp->pdgId()==theGenParticle->pdgId()&&theGenPartTmp->status()==2&& - EndVrtx!=0); + } while (theGenPartTmp && theGenPartTmp->pdgId()==theGenParticle->pdgId() + &&theGenPartTmp->status()==2&&EndVrtx!=0); - if(theGenPartTmp!=0 && theGenPartTmp->pdgId()==theGenParticle->pdgId()) { + if(theGenPartTmp && theGenPartTmp->pdgId()==theGenParticle->pdgId()) { theGenParticle=theGenPartTmp; } } @@ -849,7 +853,9 @@ ParticleOrigin MCTruthClassifier::defOrigOfElectron(const xAOD::TruthParticleCon ATH_MSG_DEBUG( "DefOrigOfElectron:: electron has more than one mother " ); m_Mother = getMother(thePriPart); - if(!m_Mother) return NonDefined; + if(!m_Mother) { + return NonDefined; + } m_MotherPDG = m_Mother->pdgId(); m_MotherBarcode = m_Mother->barcode(); m_MothOriVert = m_Mother->hasProdVtx() ? m_Mother->prodVtx() : 0 ; @@ -877,7 +883,9 @@ ParticleOrigin MCTruthClassifier::defOrigOfElectron(const xAOD::TruthParticleCon if(theP!=0){ thePriPart = theP; m_Mother = getMother(thePriPart); - if(!m_Mother) return NonDefined; + if(!m_Mother) { + return NonDefined; + } m_MotherPDG = m_Mother->pdgId(); m_MotherBarcode = m_Mother->barcode(); m_MothOriVert = m_Mother->hasProdVtx() ? m_Mother->prodVtx() : 0 ; @@ -1261,39 +1269,39 @@ ParticleOrigin MCTruthClassifier::defOrigOfMuon(const xAOD::TruthParticleContain long pPDG(0); const xAOD::TruthParticle* MotherParent(0); do { + // pPDG=0; + // const xAOD::TruthVertex* mother_prdVtx(0); const xAOD::TruthVertex* mother_endVtx(0); - - if(m_Mother) { - MotherParent=getMother(m_Mother); - //to prevent Sherpa loop - mother_prdVtx=m_Mother->hasProdVtx() ? m_Mother->prodVtx():0; - mother_endVtx=m_Mother->decayVtx(); - } - + MotherParent=getMother(m_Mother); + //to prevent Sherpa loop + mother_prdVtx=m_Mother->hasProdVtx() ? m_Mother->prodVtx():0; + mother_endVtx=m_Mother->decayVtx(); + // const xAOD::TruthVertex* parent_prdVtx(0); const xAOD::TruthVertex* parent_endVtx(0); if(MotherParent){ parent_prdVtx=MotherParent->hasProdVtx() ? MotherParent->prodVtx():0; parent_endVtx=MotherParent->decayVtx(); } - + // if(mother_endVtx==parent_prdVtx&&mother_prdVtx==parent_endVtx){ MotherParent=m_Mother; break; } // //to prevent Sherpa loop - if(m_Mother == MotherParent) {break;} + if(m_Mother == MotherParent) { + break; + } if(MotherParent) { - pPDG = MotherParent->pdgId(); + pPDG = MotherParent->pdgId(); + if(abs(pPDG)==13 || abs(pPDG)==15 || abs(pPDG)==24) { + m_Mother = MotherParent; + } } - - if(abs(pPDG)==13 || abs(pPDG)==15 || abs(pPDG)==24) { - m_Mother = MotherParent; - } } while ((abs(pPDG)==13 || abs(pPDG)==15 || abs(pPDG)==24) ); @@ -1441,7 +1449,7 @@ ParticleOrigin MCTruthClassifier::defOrigOfMuon(const xAOD::TruthParticleContain //--New Sherpa Z->mumu - if(partOriVert==m_MothOriVert&&partOriVert!=0){ + if(partOriVert==m_MothOriVert){ int NumOfMuLoop=0; int NumOfMuNeuLoop=0; int NumOfLepLoop=0; @@ -1807,7 +1815,8 @@ ParticleOrigin MCTruthClassifier::defOrigOfPhoton(const xAOD::TruthParticleConta m_NumOfDaug = partOriVert->nOutgoingParticles(); int NumOfNucFr(0),NumOfEl(0),NumOfPos(0),NumOfMu(0),NumOfTau(0), NumOfPht(0),NumOfLQ(0); - long DaugBarcode(0),DaugType(0), NumOfLep(0), NumOfNeut(0); + long DaugBarcode(0),DaugType(0), NumOfLep(0), NumOfNeut(0), NumOfPartons(0); + for(unsigned int ipOut=0;ipOut<partOriVert->nOutgoingParticles();ipOut++){ if(!partOriVert->outgoingParticle(ipOut)) continue; DaugType = partOriVert->outgoingParticle(ipOut)->pdgId(); @@ -1821,6 +1830,7 @@ ParticleOrigin MCTruthClassifier::defOrigOfPhoton(const xAOD::TruthParticleConta if(abs(DaugType) == 42) NumOfLQ++; if(abs(DaugType) == 11||abs(DaugType) == 13||abs(DaugType) == 15) NumOfLep++; if(abs(DaugType) == 12||abs(DaugType) == 14||abs(DaugType) == 16) NumOfNeut++; + if(abs(DaugType)<11 || (abs(DaugType)>16&&abs(DaugType)<43&&abs(DaugType)!=22)) NumOfPartons++; if(DaugType == m_MotherPDG ) DaugBarcode = partOriVert->outgoingParticle(ipOut)->barcode() ; } // cycle itrDaug @@ -2082,13 +2092,17 @@ ParticleOrigin MCTruthClassifier::defOrigOfPhoton(const xAOD::TruthParticleConta abs(m_MotherPDG)==33|| abs(m_MotherPDG)==34|| abs(m_MotherPDG)==5100039 // KK graviton - ) return HeavyBoson; + ) return HeavyBoson; if( abs(m_MotherPDG)<2000040&& - abs(m_MotherPDG)>1000001) return SUSY; + abs(m_MotherPDG)>1000001) return SUSY; + // Pythia8 gamma+jet samples + if ((m_MotherStatus==62||m_MotherStatus==52||m_MotherStatus==21||m_MotherStatus==22) && + thePriPart->status()==1 && NumOfPht==1 && m_NumOfDaug==(NumOfPht+NumOfPartons) ){ + return UndrPhot; + } - ParticleType pType = defTypeOfHadron(m_MotherPDG); if( (pType==BBbarMesonPart || pType==CCbarMesonPart ) && m_MothOriVert!=0&&isHardScatVrtx(m_MothOriVert)) m_isPrompt=true; @@ -2123,7 +2137,9 @@ ParticleOrigin MCTruthClassifier::defOrigOfNeutrino(const xAOD::TruthParticleCon ATH_MSG_DEBUG( "DefOrigOfNeutrino:: neutrino has more than one mother " ); m_Mother = getMother(thePriPart); - if(!m_Mother) return NonDefined; + if(!m_Mother) { + return NonDefined; + } m_MotherPDG = m_Mother->pdgId(); m_MotherBarcode = m_Mother->barcode(); m_MothOriVert = m_Mother->hasProdVtx() ? m_Mother->prodVtx() : 0; @@ -2151,13 +2167,21 @@ ParticleOrigin MCTruthClassifier::defOrigOfNeutrino(const xAOD::TruthParticleCon parent_prdVtx=MotherParent->hasProdVtx() ? MotherParent->prodVtx():0; parent_endVtx=MotherParent->decayVtx(); } - if(mother_endVtx==parent_prdVtx&&mother_prdVtx==parent_endVtx){ MotherParent=m_Mother; break;} + if(mother_endVtx==parent_prdVtx&&mother_prdVtx==parent_endVtx){ + MotherParent=m_Mother; + break; + } // - if(MotherParent) pPDG = MotherParent->pdgId(); + if(MotherParent) { + pPDG = MotherParent->pdgId(); + } //to prevent Sherpa loop - if(m_Mother == MotherParent) break; - - if(abs(pPDG)==nuFlav || abs(pPDG)==15 || abs(pPDG)==24) m_Mother = MotherParent; + if(m_Mother == MotherParent) { + break; + } + if(abs(pPDG)==nuFlav || abs(pPDG)==15 || abs(pPDG)==24) { + m_Mother = MotherParent; + } } while ((abs(pPDG)==nuFlav || abs(pPDG)==15 || abs(pPDG)==24) ); diff --git a/PhysicsAnalysis/MCTruthClassifier/python/MCTruthClassifierBase.py b/PhysicsAnalysis/MCTruthClassifier/python/MCTruthClassifierBase.py old mode 100755 new mode 100644 diff --git a/PhysicsAnalysis/MCTruthClassifier/src/components/MCTruthClassifier_entries.cxx b/PhysicsAnalysis/MCTruthClassifier/src/components/MCTruthClassifier_entries.cxx old mode 100755 new mode 100644 diff --git a/PhysicsAnalysis/MCTruthClassifier/src/components/MCTruthClassifier_load.cxx b/PhysicsAnalysis/MCTruthClassifier/src/components/MCTruthClassifier_load.cxx old mode 100755 new mode 100644 diff --git a/PhysicsAnalysis/MCTruthClassifier/util/testClassifier.cxx b/PhysicsAnalysis/MCTruthClassifier/util/testClassifier.cxx index 37579545891b7530514a99f008eb4b1092fa7b10..8c12b0b3538ee707770eb7cb2fd38c36d3cc1a08 100644 --- a/PhysicsAnalysis/MCTruthClassifier/util/testClassifier.cxx +++ b/PhysicsAnalysis/MCTruthClassifier/util/testClassifier.cxx @@ -42,10 +42,10 @@ int main( int argc, char* argv[] ) { Error( APP_NAME, " Usage: %s [xAOD file name]", APP_NAME ); return 1; } - + // Initialise the application: CHECK( xAOD::Init( APP_NAME ) ); - + // Open the input file: const TString fileName = argv[ 1 ]; Info( APP_NAME, "Opening file: %s", fileName.Data() ); @@ -53,7 +53,7 @@ int main( int argc, char* argv[] ) { CHECK( ifile.get() ); // Create a TEvent object: - xAOD::TEvent event( xAOD::TEvent::kBranchAccess ); + xAOD::TEvent event; CHECK( event.readFrom( ifile.get() ) ); Info( APP_NAME, "Number of events in the file: %i", static_cast< int >( event.getEntries() ) ); @@ -68,52 +68,47 @@ int main( int argc, char* argv[] ) { } MCTruthClassifier myClassifier ("myClassifier"); - myClassifier.initialize(); + CHECK( myClassifier.initialize() ); // Loop over the events: for( Long64_t entry = 0; entry < entries; ++entry ) { - + // Tell the object which entry to look at: event.getEntry( entry ); - + std::cout << "=================NEXT EVENT==========================" << std::endl; - + //Electrons - const xAOD::ElectronContainer* electrons = 0 ; + const xAOD::ElectronContainer* electrons = 0 ; CHECK( event.retrieve(electrons, "Electrons") ); - - if ( !event.retrieve( electrons, "Electrons" ).isSuccess() ){ // retrieve arguments: container type, container key - Error("execute()", "Failed to retrieve El container. Exiting." ); - } - xAOD::ElectronContainer::const_iterator el_it = electrons->begin(); + xAOD::ElectronContainer::const_iterator el_it = electrons->begin(); xAOD::ElectronContainer::const_iterator el_it_last = electrons->end(); unsigned int i = 0; - + for (; el_it != el_it_last; ++el_it, ++i) { const xAOD::Electron* el = (*el_it); - std::cout << "Electron " << el << " Num " << i << std::endl; - std::cout << "xAOD pt = " << (*el_it)->pt() << std::endl; + std::cout << "Electron " << el << " Num " << i << std::endl; + std::cout << "xAOD pt = " << (*el_it)->pt() << std::endl; Info (APP_NAME,"Electron #%d", i); - std::pair<MCTruthPartClassifier::ParticleType,MCTruthPartClassifier::ParticleOrigin> - classification = myClassifier.particleTruthClassifier(*el_it); + std::pair<MCTruthPartClassifier::ParticleType,MCTruthPartClassifier::ParticleOrigin> + classification = myClassifier.particleTruthClassifier(*el_it); static SG::AuxElement::Accessor<int> tT("truthType") ; if (tT.isAvailable(**el_it)){; - Info (APP_NAME,"Electron Type from Reco returns %d ", tT(**el_it) ); + Info (APP_NAME,"Electron Type from Reco returns %d ", tT(**el_it) ); } Info (APP_NAME,"Electron Type from Analysis Base returns %d ", classification.first ); static SG::AuxElement::Accessor<int> tO("truthOrigin") ; if (tO.isAvailable(**el_it)){; - Info (APP_NAME,"Electron Origin from Reco returns %d ", tO(**el_it) ); + Info (APP_NAME,"Electron Origin from Reco returns %d ", tO(**el_it) ); } Info (APP_NAME,"Electron Origin from Analysis Base returns %d ", classification.second ); } - Info( APP_NAME, - "===>>> done processing event #%lld ",entry); + Info( APP_NAME, "===>>> done processing event #%lld ",entry); } - myClassifier.finalize(); + CHECK( myClassifier.finalize() ); // Return gracefully: return 0; }