From d63cfe22970f553e2647b66d65d46aaf071a7001 Mon Sep 17 00:00:00 2001 From: Andrii Verbytskyi Date: Sat, 11 Dec 2021 20:06:18 +0100 Subject: [PATCH 1/3] Update TTbarWithJpsimumuFilter.cxx --- .../src/TTbarWithJpsimumuFilter.cxx | 52 ++++++++----------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/Generators/GeneratorFilters/src/TTbarWithJpsimumuFilter.cxx b/Generators/GeneratorFilters/src/TTbarWithJpsimumuFilter.cxx index 1c0e0810e08..76fafed6808 100644 --- a/Generators/GeneratorFilters/src/TTbarWithJpsimumuFilter.cxx +++ b/Generators/GeneratorFilters/src/TTbarWithJpsimumuFilter.cxx @@ -48,12 +48,8 @@ StatusCode TTbarWithJpsimumuFilter::filterEvent() { // Loop over all truth particles in the event // =========================================== - for(HepMC::GenEvent::particle_const_iterator pitr=genEvt->particles_begin();pitr!=genEvt->particles_end(); ++pitr ) { - - const HepMC::GenParticle* part = (*pitr); - - if(part->barcode() > 200000) break; - + for(auto part: *genEvt) { + if(HepMC::barcode(part) > 200000) break; if ( !passJpsiSelection(part) ) continue; isjpsi=true; @@ -70,42 +66,36 @@ StatusCode TTbarWithJpsimumuFilter::filterEvent() { } // ======================================================== -bool TTbarWithJpsimumuFilter::isLeptonDecay(const HepMC::GenParticle* part, int type) const{ - - HepMC::GenVertex* end = part->end_vertex(); - if(end){ - HepMC::GenVertex::particle_iterator firstChild = end->particles_begin(HepMC::children); - HepMC::GenVertex::particle_iterator endChild = end->particles_end(HepMC::children); - for(;firstChild!=endChild; ++firstChild){ - if( part->barcode() > (*firstChild)->barcode() ) continue; /// protection for sherpa - int childtype = abs((*firstChild)->pdg_id()); - - // debugging - //const HepMC::FourVector& p4 = (*firstChild)->momentum(); - //double pt = p4.perp(); - //double eta = fabs(p4.eta()); - //std::cout << " childtype = " << childtype - //<< " " << pt - //<< " " << eta - //<< std::endl; - +bool TTbarWithJpsimumuFilter::isLeptonDecay(HepMC::GenParticlePtr part, int type) const{ + + HepMC::GenVertexPtr end = part->end_vertex(); + if(!end) return true; + int partbarcode = HepMC::barcode(part); +#ifdef HEPMC3 + HepMC::GenVertex::particle_iterator firstChild = end->particles_begin(HepMC::children); + HepMC::GenVertex::particle_iterator endChild = end->particles_end(HepMC::children); + for(;firstChild!=endChild; ++firstChild){ + if( partbarcode > (*firstChild)->barcode() ) continue; /// protection for sherpa + int childtype = std::abs((*firstChild)->pdg_id()); if( childtype != type ){ return false; } - } - } - +#else +for (auto p: end->particles_out()) { + if (partbarcode > HepMC::barcode(p)) continue; + if (p->pdg_id() != type ) return false; + } +#endif return true; - } // ======================================================== -bool TTbarWithJpsimumuFilter::passJpsiSelection(const HepMC::GenParticle* part) const{ +bool TTbarWithJpsimumuFilter::passJpsiSelection(HepMC::ConstGenParticlePtr part) const{ const HepMC::FourVector& p4 = part->momentum(); double pt = p4.perp(); - double eta = fabs(p4.eta()); + double eta = std::abs(p4.eta()); if(ptm_JpsiEtaMaxCut) return false; -- GitLab From 403efc728b673131847be2ebfca37105529a8482 Mon Sep 17 00:00:00 2001 From: Andrii Verbytskyi Date: Sat, 11 Dec 2021 20:08:04 +0100 Subject: [PATCH 2/3] Update TTbarWithJpsimumuFilter.h --- .../GeneratorFilters/TTbarWithJpsimumuFilter.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Generators/GeneratorFilters/GeneratorFilters/TTbarWithJpsimumuFilter.h b/Generators/GeneratorFilters/GeneratorFilters/TTbarWithJpsimumuFilter.h index cf48ac02a65..61c3cc666dc 100644 --- a/Generators/GeneratorFilters/GeneratorFilters/TTbarWithJpsimumuFilter.h +++ b/Generators/GeneratorFilters/GeneratorFilters/TTbarWithJpsimumuFilter.h @@ -14,9 +14,6 @@ #include "GeneratorModules/GenFilter.h" -namespace HepMC{ - class GenParticle; -} class TTbarWithJpsimumuFilter: public GenFilter { public: @@ -36,10 +33,10 @@ class TTbarWithJpsimumuFilter: public GenFilter { double m_JpsiEtaMaxCut; // method to check if Jpsi decays into pair of leptons - bool isLeptonDecay(const HepMC::GenParticle* part, int type) const; + bool isLeptonDecay(HepMC::ConstGenParticlePtr part, int type) const; // method to check if Jpsi pass some selection criteria - bool passJpsiSelection(const HepMC::GenParticle* part) const; + bool passJpsiSelection(HepMC::ConstGenParticlePtr part) const; }; -- GitLab From 4cc889206587d40606d22db6afafc74d568e565c Mon Sep 17 00:00:00 2001 From: Andrii Verbytskyi Date: Sat, 11 Dec 2021 20:19:17 +0100 Subject: [PATCH 3/3] Fix the filter --- .../src/TTbarWithJpsimumuFilter.cxx | 129 +++++++++--------- 1 file changed, 63 insertions(+), 66 deletions(-) diff --git a/Generators/GeneratorFilters/src/TTbarWithJpsimumuFilter.cxx b/Generators/GeneratorFilters/src/TTbarWithJpsimumuFilter.cxx index 76fafed6808..d0a2de386b3 100644 --- a/Generators/GeneratorFilters/src/TTbarWithJpsimumuFilter.cxx +++ b/Generators/GeneratorFilters/src/TTbarWithJpsimumuFilter.cxx @@ -1,105 +1,102 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "GeneratorFilters/TTbarWithJpsimumuFilter.h" #include "GaudiKernel/MsgStream.h" //-------------------------------------------------------------------------- -TTbarWithJpsimumuFilter::TTbarWithJpsimumuFilter(const std::string& fname, - ISvcLocator* pSvcLocator) - : GenFilter(fname,pSvcLocator) - +TTbarWithJpsimumuFilter::TTbarWithJpsimumuFilter(const std::string& fname, + ISvcLocator* pSvcLocator) + : GenFilter(fname,pSvcLocator) + { - declareProperty("SelectJpsi",m_selectJpsi=true); - declareProperty("JpsipTMinCut",m_JpsiPtMinCut=0.); /// MeV - declareProperty("JpsietaMaxCut",m_JpsiEtaMaxCut=5.); + declareProperty("SelectJpsi",m_selectJpsi=true); + declareProperty("JpsipTMinCut",m_JpsiPtMinCut=0.); /// MeV + declareProperty("JpsietaMaxCut",m_JpsiEtaMaxCut=5.); } //-------------------------------------------------------------------------- -TTbarWithJpsimumuFilter::~TTbarWithJpsimumuFilter(){ - ///// +TTbarWithJpsimumuFilter::~TTbarWithJpsimumuFilter() { + ///// } //--------------------------------------------------------------------------- StatusCode TTbarWithJpsimumuFilter::filterInitialize() { - ATH_MSG_INFO("Initialized"); - return StatusCode::SUCCESS; + ATH_MSG_INFO("Initialized"); + return StatusCode::SUCCESS; } //--------------------------------------------------------------------------- StatusCode TTbarWithJpsimumuFilter::filterFinalize() { - ATH_MSG_INFO(" Events out of " << m_nPass+m_nFail << " passed the filter"); - return StatusCode::SUCCESS; + ATH_MSG_INFO(" Events out of " << m_nPass+m_nFail << " passed the filter"); + return StatusCode::SUCCESS; } //--------------------------------------------------------------------------- StatusCode TTbarWithJpsimumuFilter::filterEvent() { - //--------------------------------------------------------------------------- + //--------------------------------------------------------------------------- - bool pass = false; - bool isjpsi = false; + bool pass = false; + bool isjpsi = false; - McEventCollection::const_iterator itr; - for (itr = events_const()->begin(); itr!=events_const()->end(); ++itr) { - - const HepMC::GenEvent* genEvt = (*itr); - - // Loop over all truth particles in the event - // =========================================== - for(auto part: *genEvt) { - if(HepMC::barcode(part) > 200000) break; - if ( !passJpsiSelection(part) ) continue; - isjpsi=true; - - } /// loop on particles - - } // loop on events (only one at evgen - no PU) - - - if (m_selectJpsi && isjpsi) pass=true; - - setFilterPassed(pass); - return StatusCode::SUCCESS; + McEventCollection::const_iterator itr; + for (itr = events_const()->begin(); itr != events_const()->end(); ++itr) { + + const HepMC::GenEvent* genEvt = (*itr); + + // Loop over all truth particles in the event + // =========================================== + for(auto part: *genEvt) { + if(HepMC::barcode(part) > 200000) break; + if ( !passJpsiSelection(part) ) continue; + isjpsi=true; + + } /// loop on particles + } // loop on events (only one at evgen - no PU) + + if (m_selectJpsi && isjpsi) pass = true; + + setFilterPassed(pass); + return StatusCode::SUCCESS; } // ======================================================== -bool TTbarWithJpsimumuFilter::isLeptonDecay(HepMC::GenParticlePtr part, int type) const{ - - HepMC::GenVertexPtr end = part->end_vertex(); - if(!end) return true; - int partbarcode = HepMC::barcode(part); +bool TTbarWithJpsimumuFilter::isLeptonDecay(HepMC::ConstGenParticlePtr part, int type) const { + auto end = part->end_vertex(); + if(!end) return true; + int partbarcode = HepMC::barcode(part); #ifdef HEPMC3 - HepMC::GenVertex::particle_iterator firstChild = end->particles_begin(HepMC::children); - HepMC::GenVertex::particle_iterator endChild = end->particles_end(HepMC::children); - for(;firstChild!=endChild; ++firstChild){ - if( partbarcode > (*firstChild)->barcode() ) continue; /// protection for sherpa - int childtype = std::abs((*firstChild)->pdg_id()); - if( childtype != type ){ - return false; - } - } + for (auto p: end->particles_out()) { + if (partbarcode > HepMC::barcode(p)) continue; + if (std::abs(p->pdg_id()) != type ) return false; + } #else -for (auto p: end->particles_out()) { - if (partbarcode > HepMC::barcode(p)) continue; - if (p->pdg_id() != type ) return false; - } + HepMC::GenVertex::particle_iterator firstChild = end->particles_begin(HepMC::children); + HepMC::GenVertex::particle_iterator endChild = end->particles_end(HepMC::children); + for(; firstChild!=endChild; ++firstChild) { + if( partbarcode > (*firstChild)->barcode() ) continue; /// protection for sherpa + int childtype = std::abs((*firstChild)->pdg_id()); + if( childtype != type ) { + return false; + } + } #endif - return true; + return true; } // ======================================================== -bool TTbarWithJpsimumuFilter::passJpsiSelection(HepMC::ConstGenParticlePtr part) const{ +bool TTbarWithJpsimumuFilter::passJpsiSelection(HepMC::ConstGenParticlePtr part) const { + + const HepMC::FourVector& p4 = part->momentum(); + double pt = p4.perp(); + double eta = std::abs(p4.eta()); + + if (pt < m_JpsiPtMinCut) return false; + if (eta > m_JpsiEtaMaxCut) return false; - const HepMC::FourVector& p4 = part->momentum(); - double pt = p4.perp(); - double eta = std::abs(p4.eta()); - - if(ptm_JpsiEtaMaxCut) return false; + return true; - return true; - } -- GitLab