ATLAS Offline Software
HTFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Header for this module
8 
9 // Framework Related Headers
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/SystemOfUnits.h"
12 
13 // Used for retrieving the collection
14 #include "xAODJet/JetContainer.h"
16 #include "xAODTruth/TruthVertex.h"
17 #include "StoreGate/StoreGateSvc.h"
18 
19 // Other classes used by this class
21 #include "AtlasHepMC/GenEvent.h"
22 // #include "GeneratorObjects/McEventCollection.h"
24 
25 //--------------------------------------------------------------------------
26 
27 HTFilter::HTFilter(const std::string& name, ISvcLocator* pSvcLocator)
28  : GenFilter(name,pSvcLocator)
29  , m_total(0)
30  , m_passed(0)
31  , m_ptfailed(0)
32 {
34  declareProperty("MaxJetEta",m_MaxJetEta = 10.0);
35  declareProperty("TruthJetContainer", m_TruthJetContainerName = "AntiKt4TruthWZJets");
37  declareProperty("MaxHT",m_MaxHT = 14000.*Gaudi::Units::GeV);
38  declareProperty("UseNeutrinosFromWZTau",m_UseNu = false, "Include neutrinos from W/Z/tau decays in the calculation of HT");
39  declareProperty("UseLeptonsFromWZTau",m_UseLep = false, "Include e/mu from W/Z/tau decays in the HT");
40  declareProperty("MinLeptonPt",m_MinLepPt = 0*Gaudi::Units::GeV);
41  declareProperty("MaxLeptonEta",m_MaxLepEta = 10.0);
42 }
43 
44 //--------------------------------------------------------------------------
45 
47 }
48 
49 //---------------------------------------------------------------------------
50 
56  if (m_MaxHT<0) m_MaxHT=9e9;
57 
58  ATH_MSG_INFO( "Configured with " << m_MinJetPt << "<p_T GeV and abs(eta)<" << m_MaxJetEta << " for jets in " << m_TruthJetContainerName );
59  ATH_MSG_INFO( "Will require H_T in range " << m_MinHT << " < H_T < " << m_MaxHT );
60  if (m_UseNu) ATH_MSG_INFO( " including neutrinos" );
61  if (m_UseLep) ATH_MSG_INFO( " including W/Z/tau leptons in range " << m_MinLepPt << "<p_T GeV and abs(eta)<" << m_MaxLepEta );
62 
63  return StatusCode::SUCCESS;
64 }
65 
66 //---------------------------------------------------------------------------
67 
69  ATH_MSG_INFO( "Total efficiency: " << 100.*double(m_passed)/double(m_total) << "% ("
70  << 100.*double(m_ptfailed)/double(m_total) << "% failed p_T cuts)" );
71  return StatusCode::SUCCESS;
72 }
73 
74 //---------------------------------------------------------------------------
75 
77  m_total++; // Book keeping
78 
79 #ifdef HEPMC3
80 
81 
82 ATH_MSG_ERROR(" For HEPMC3 releases xAOD filters should be used. Exiting with ERROR. ");
83 return StatusCode::FAILURE;
84 
85 #endif
86 
87  // Get jet container out
88  const xAOD::JetContainer* truthjetTES = 0;
89  if ( !evtStore()->contains<xAOD::JetContainer>( m_TruthJetContainerName ) ||
90  evtStore()->retrieve( truthjetTES, m_TruthJetContainerName).isFailure() || !truthjetTES ){
91  ATH_MSG_INFO( "No xAOD::JetContainer found in StoreGate with key " << m_TruthJetContainerName );
92  setFilterPassed(m_MinHT<1.);
93  return StatusCode::SUCCESS;
94  }
95 
96  // Get HT
97  double HT = -1;
98  for (xAOD::JetContainer::const_iterator it_truth = (*truthjetTES).begin(); it_truth != (*truthjetTES).end() ; ++it_truth) {
99  if (!(*it_truth)) continue;
100  if ( (*it_truth)->pt()>m_MinJetPt*Gaudi::Units::GeV && std::abs((*it_truth)->eta())<m_MaxJetEta ) {
101  ATH_MSG_VERBOSE("Adding truth jet with pt " << (*it_truth)->pt()
102  << ", eta " << (*it_truth)->eta()
103  << ", phi " << (*it_truth)->phi()
104  << ", nconst = " << (*it_truth)->numConstituents());
105  HT += (*it_truth)->pt();
106  }
107  }
108 
109  // If we are asked to include neutrinos or leptons...
110  if (m_UseLep || m_UseNu){
111  // Get MC event collection
112  const McEventCollection* mecc = 0;
113  if ( evtStore()->retrieve(mecc).isFailure() || !mecc || mecc->size()<1 || !((*mecc)[0]) ){
114  ATH_MSG_WARNING( "Could not retrieve MC Event Collection - weight might not work" );
115  return StatusCode::SUCCESS;
116  }
117 
118  std::vector<HepMC::GenParticlePtr> WZleptons;
119  WZleptons.reserve(10);
120 
121  for (const auto& iter: *((*mecc)[0])){
122  if ( !iter ) continue;
123  int pdgid = iter->pdg_id();
124  if (m_UseNu && MC::isNeutrino(pdgid) && MC::isGenStable(iter)) {
125  if( Common::fromWZorTau(iter)) {
126  HT += iter->momentum().perp();
127  }
128  }
129  // pick muons and electrons specifically -- isLepton selects both charged leptons and neutrinos
130  if (m_UseLep && (std::abs(pdgid)==11 || std::abs(pdgid)==13) && MC::isGenStable(iter)
131  && (iter)->momentum().perp()>m_MinLepPt*Gaudi::Units::GeV && std::abs(iter->momentum().eta())<m_MaxLepEta) {
132 
133  if( Common::fromWZorTau(iter)) {
134  ATH_MSG_VERBOSE("Adding W/Z/tau lepton with pt " << iter);
135  HT += iter->momentum().perp();
136  }
137  }
138  }
139  } // End need to access MC Event
140 
141  HT /= Gaudi::Units::GeV; // Make sure we're in GeV
142  ATH_MSG_DEBUG( "HT: " << HT );
143 
144  if (HT<m_MinHT || HT>=m_MaxHT){
145  ATH_MSG_DEBUG( "Failed filter on HT: " << HT << " is not between " << m_MinHT << " and " << m_MaxHT );
146  setFilterPassed(false);
147  } else {
148  // Made it to the end - success!
149  m_passed++;
150  setFilterPassed(true);
151  }
152 
153  return StatusCode::SUCCESS;
154 }
155 
156 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
GenEvent.h
HTFilter::HTFilter
HTFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: HTFilter.cxx:27
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
HTFilter::m_UseNu
bool m_UseNu
Use neutrinos in HT.
Definition: HTFilter.h:33
HTFilter::m_ptfailed
long m_ptfailed
Number of events failing the pT cuts.
Definition: HTFilter.h:40
perp
Scalar perp() const
perp method - perpenticular length
Definition: AmgMatrixBasePlugin.h:35
HTFilter::m_MaxJetEta
double m_MaxJetEta
Max eta for the truth jets.
Definition: HTFilter.h:28
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
HTFilter::m_MaxLepEta
double m_MaxLepEta
Max eta for the truth jets.
Definition: HTFilter.h:32
isNeutrino
bool isNeutrino(const T &p)
APID: the fourth generation neutrinos are neutrinos.
Definition: AtlasPID.h:152
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
HTFilter::m_MaxHT
double m_MaxHT
Max HT for events.
Definition: HTFilter.h:30
HTFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: HTFilter.cxx:51
HTFilter::m_TruthJetContainerName
std::string m_TruthJetContainerName
Name of the truth jet container.
Definition: HTFilter.h:36
MC::isGenStable
bool isGenStable(const T &p)
Determine if the particle is stable at the generator (not det-sim) level,.
Definition: HepMCHelpers.h:36
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HTFilter::m_MinLepPt
double m_MinLepPt
Min pT for the truth jets.
Definition: HTFilter.h:31
HTFilter::m_passed
long m_passed
Number of events passing all cuts.
Definition: HTFilter.h:39
HTFilter::filterEvent
virtual StatusCode filterEvent()
Definition: HTFilter.cxx:76
HTFilter::m_MinHT
double m_MinHT
Min HT for events.
Definition: HTFilter.h:29
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
TruthVertex.h
HTFilter::m_total
long m_total
Total number of events tested.
Definition: HTFilter.h:38
Common.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
HTFilter::m_MinJetPt
double m_MinJetPt
Min pT for the truth jets.
Definition: HTFilter.h:27
HTFilter::~HTFilter
virtual ~HTFilter()
Definition: HTFilter.cxx:46
Common::fromWZorTau
bool fromWZorTau(const HepMC::ConstGenParticlePtr &part)
Definition: Common.cxx:93
JetContainer.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
HTFilter.h
HTFilter::filterFinalize
virtual StatusCode filterFinalize()
Definition: HTFilter.cxx:68
TruthParticle.h
HTFilter::m_UseLep
bool m_UseLep
Use leptons in HT.
Definition: HTFilter.h:34
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
HepMCHelpers.h