ATLAS Offline Software
xAODHeavyFlavorHadronFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "GaudiKernel/SystemOfUnits.h"
7 #include "xAODJet/JetContainer.h"
8 #include "CxxUtils/BasicTypes.h"
9 #include <cmath>
10 
11 
12 xAODHeavyFlavorHadronFilter::xAODHeavyFlavorHadronFilter(const std::string& name, ISvcLocator* pSvcLocator)
13  : GenFilter(name, pSvcLocator),
14  m_NPass(0), m_Nevt(0), m_NbPass(0),
15  m_NcPass(0), m_NBHadronPass(0), m_NDHadronPass(0),
16  m_NPDGIDPass(0)
17 {
18 
19 }
20 
21 
23  m_Nevt = 0;
24  m_NPass = 0;
25  m_NbPass = 0;
26  m_NcPass = 0;
27  m_NBHadronPass = 0;
28  m_NDHadronPass = 0;
29  m_NPDGIDPass = 0;
30  return StatusCode::SUCCESS;
31 }
32 
33 
35  ATH_MSG_INFO(m_NPass << " events out of " << m_Nevt << " passed the filter");
36  if (m_Request_bQuark) ATH_MSG_INFO(m_NbPass << " passed b-quark selection");
37  if (m_Request_cQuark) ATH_MSG_INFO(m_NcPass << " passed c-quark selection");
38  if (m_RequestBottom) ATH_MSG_INFO(m_NBHadronPass << " passed B Hadron selection");
39  if (m_RequestCharm) ATH_MSG_INFO(m_NDHadronPass << " passed Charm Hadron selection");
40  if (m_RequestSpecificPDGID) ATH_MSG_INFO(m_NPDGIDPass << " passed selection for PDG code " << m_PDGID);
41  return StatusCode::SUCCESS;
42 }
43 
44 
46  bool pass = false;
47  bool bPass = false;
48  bool cPass = false;
49  bool BHadronPass = false;
50  bool DHadronPass = false;
51  bool PDGIDPass = false;
52 
53  m_Nevt++;
54 
55  std::vector<xAOD::JetContainer::const_iterator> jets;
56  if (m_RequireTruthJet) {
57  const xAOD::JetContainer* truthjetTES;
59  for (xAOD::JetContainer::const_iterator j = truthjetTES->begin(); j != truthjetTES->end() ; ++j) {
60  if ((*j)->pt() > m_jetPtMin && std::abs((*j)->eta()) < m_jetEtaMax) {
61  jets.push_back(j);
62  }
63  }
64  }
65 
66  // Retrieve TruthGen container from xAOD Gen slimmer, contains all particles witout barcode_zero and
67 // duplicated barcode ones
68  const xAOD::TruthParticleContainer* xTruthParticleContainer;
69  if (evtStore()->retrieve(xTruthParticleContainer, "TruthGen").isFailure()) {
70  ATH_MSG_ERROR("No TruthParticle collection with name " << "TruthGen" << " found in StoreGate!");
71  return StatusCode::FAILURE;
72  }
73 
74  unsigned int nPart = xTruthParticleContainer->size();
75  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
76  const xAOD::TruthParticle* part = (*xTruthParticleContainer)[iPart];
77 
78  // b-quarks
79  // ==========
80  // Warning: Since no navigation is done, the filter does not distinguish
81  // between the final quark in the decay chain and intermediates
82  // That means the code is NOT appropriate for counting the number
83  // of heavy flavor quarks!
84  if (m_Request_bQuark && std::abs(part->pdgId())==5 &&
85  part->pt()> m_bPtMin &&
86  std::abs(part->rapidity())<m_bEtaMax) {
87  if (m_RequireTruthJet) {
88  TLorentzVector genpart(part->px(), part->py(), part->pz(), part->e());
89  for (uint i=0; i<jets.size(); i++) {
90  double dR = (*jets[i])->p4().DeltaR(genpart);
91  if (dR<m_deltaRFromTruth) bPass=true;
92  }
93  } else {
94  bPass = true;
95  }
96  }
97 
98  // c-quarks
99  // ========
100  // Warning: Since no navigation is done, the filter does not distinguish
101  // between the final quark in the decay chain and intermediates
102  // That means the code is NOT appropriate for counting the number
103  // of heavy flavor quarks!
104  if (m_Request_cQuark &&
105  std::abs(part->pdgId())==4 &&
106  part->pt()>m_cPtMin &&
107  std::abs(part->rapidity())<m_cEtaMax) {
108  if (m_RequireTruthJet) {
109  TLorentzVector genpart(part->px(), part->py(), part->pz(), part->e());
110  for (uint i=0; i<jets.size(); i++) {
111  double dR = (*jets[i])->p4().DeltaR(genpart);
112  if (dR<m_deltaRFromTruth) cPass=true;
113  }
114  } else {
115  cPass = true;
116  }
117  }
118 
119  // B hadrons
120  // =========
121  if (m_RequestBottom &&
122  isBwithWeakDK(part->pdgId()) &&
123  part->pt()>m_bottomPtMin &&
124  std::abs(part->rapidity())<m_bottomEtaMax) {
125  if (m_RequireTruthJet) {
126  TLorentzVector genpart(part->px(), part->py(), part->pz(), part->e());
127  for (uint i=0; i<jets.size(); i++) {
128  double dR = (*jets[i])->p4().DeltaR(genpart);
129  if (dR < m_deltaRFromTruth) BHadronPass=true;
130  }
131  } else {
132  BHadronPass = true;
133  }
134  }
135 
136  // Charm Hadrons
137  // ==============
138  if (m_RequestCharm &&
139  isDwithWeakDK(part->pdgId()) &&
140  part->pt()>m_charmPtMin &&
141  std::abs(part->rapidity())<m_charmEtaMax) {
142  if (m_RequireTruthJet) {
143  TLorentzVector genpart(part->px(), part->py(), part->pz(), part->e());
144  for (uint i=0; i<jets.size(); i++) {
145  double dR = (*jets[i])->p4().DeltaR(genpart);
146  if (dR < m_deltaRFromTruth) DHadronPass=true;
147  }
148  } else {
149  DHadronPass = true;
150  }
151  }
152 
153  // Request Specific PDGID
154  // =========================
155  bool pdgok = m_RequestSpecificPDGID &&
156  (part->pdgId() == m_PDGID ||
157  (m_PDGAntiParticleToo && std::abs(part->pdgId()) == m_PDGID));
158  if (pdgok && part->pt() > m_PDGPtMin &&
159  std::abs(part->rapidity()) < m_PDGEtaMax) {
160  if (m_RequireTruthJet) {
161  TLorentzVector genpart(part->px(), part->py(), part->pz(), part->e());
162  for (size_t i = 0; i < jets.size(); ++i) {
163  double dR = (*jets[i])->p4().DeltaR(genpart);
164  if (dR < m_deltaRFromTruth) PDGIDPass = true;
165  }
166  } else {
167  PDGIDPass = true;
168  }
169  }
170  }//end of Particle loop
171 
173  pass = BHadronPass || DHadronPass || bPass || cPass || PDGIDPass;
174  if (pass) m_NPass++;
175  if (bPass) m_NbPass++;
176  if (cPass) m_NcPass++;
177  if (BHadronPass) m_NBHadronPass++;
178  if (DHadronPass) m_NDHadronPass++;
179  if (PDGIDPass) m_NPDGIDPass++;
180  setFilterPassed(pass);
181 
182  return StatusCode::SUCCESS;
183 }
184 
185 
187  int id = std::abs(pID);
188  return ( id == 511 || // B+
189  id == 521 || // B0
190  id == 531 || // Bs
191  id == 541 || // Bc
192  id == 5122 || // Lambda_B
193  id == 5132 || // Xi_b-
194  id == 5232 || // X_b0
195  id == 5112 || // Sigma_b-
196  id == 5212 || // Sigma_b0
197  id == 5222 || // Sigma_b+
198  id == 5332 ); // Omega_B
199 }
200 
201 
203  int id = std::abs(pID);
204  return ( id == 411 || // D+
205  id == 421 || // D0
206  id == 431 || // Ds
207  id == 4122 || // Lambda_C
208  id == 4132 || // Xi_C^0
209  id == 4232 || // Xi_C^+
210  id == 4212 || // Xi_C^0
211  id == 4322 || // Xi'_C+ This is in fact EM not weak
212  id == 4332); // Omega_C
213 
214 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAODHeavyFlavorHadronFilter::m_cPtMin
Gaudi::Property< double > m_cPtMin
Definition: xAODHeavyFlavorHadronFilter.h:40
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
xAODHeavyFlavorHadronFilter::m_NbPass
int m_NbPass
Definition: xAODHeavyFlavorHadronFilter.h:62
xAODHeavyFlavorHadronFilter::m_jetPtMin
Gaudi::Property< double > m_jetPtMin
Definition: xAODHeavyFlavorHadronFilter.h:44
xAODHeavyFlavorHadronFilter::m_cEtaMax
Gaudi::Property< double > m_cEtaMax
Definition: xAODHeavyFlavorHadronFilter.h:42
xAODHeavyFlavorHadronFilter::m_charmEtaMax
Gaudi::Property< double > m_charmEtaMax
Definition: xAODHeavyFlavorHadronFilter.h:38
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAODHeavyFlavorHadronFilter::m_Request_cQuark
Gaudi::Property< bool > m_Request_cQuark
Definition: xAODHeavyFlavorHadronFilter.h:52
xAODHeavyFlavorHadronFilter::m_bEtaMax
Gaudi::Property< double > m_bEtaMax
Definition: xAODHeavyFlavorHadronFilter.h:43
xAODHeavyFlavorHadronFilter::m_charmPtMin
Gaudi::Property< double > m_charmPtMin
Definition: xAODHeavyFlavorHadronFilter.h:36
xAODHeavyFlavorHadronFilter.h
xAODHeavyFlavorHadronFilter::m_PDGAntiParticleToo
Gaudi::Property< bool > m_PDGAntiParticleToo
Definition: xAODHeavyFlavorHadronFilter.h:49
xAODHeavyFlavorHadronFilter::m_Nevt
int m_Nevt
Definition: xAODHeavyFlavorHadronFilter.h:61
xAODHeavyFlavorHadronFilter::m_PDGPtMin
Gaudi::Property< double > m_PDGPtMin
Definition: xAODHeavyFlavorHadronFilter.h:46
xAODHeavyFlavorHadronFilter::m_NBHadronPass
int m_NBHadronPass
Definition: xAODHeavyFlavorHadronFilter.h:64
xAODHeavyFlavorHadronFilter::xAODHeavyFlavorHadronFilter
xAODHeavyFlavorHadronFilter(const std::string &fname, ISvcLocator *pSvcLocator)
Definition: xAODHeavyFlavorHadronFilter.cxx:12
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
xAODHeavyFlavorHadronFilter::m_TruthJetContainerName
Gaudi::Property< std::string > m_TruthJetContainerName
Definition: xAODHeavyFlavorHadronFilter.h:57
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
xAODHeavyFlavorHadronFilter::m_NPass
int m_NPass
Definition: xAODHeavyFlavorHadronFilter.h:60
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
xAODHeavyFlavorHadronFilter::m_NPDGIDPass
int m_NPDGIDPass
Definition: xAODHeavyFlavorHadronFilter.h:66
xAODHeavyFlavorHadronFilter::m_jetEtaMax
Gaudi::Property< double > m_jetEtaMax
Definition: xAODHeavyFlavorHadronFilter.h:45
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
BasicTypes.h
Provide simplified clock_gettime() function for MacOSX.
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
xAODHeavyFlavorHadronFilter::isBwithWeakDK
bool isBwithWeakDK(const int pID) const
Definition: xAODHeavyFlavorHadronFilter.cxx:186
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAODHeavyFlavorHadronFilter::m_NcPass
int m_NcPass
Definition: xAODHeavyFlavorHadronFilter.h:63
xAODHeavyFlavorHadronFilter::isDwithWeakDK
bool isDwithWeakDK(const int pID) const
Definition: xAODHeavyFlavorHadronFilter.cxx:202
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAODHeavyFlavorHadronFilter::filterEvent
virtual StatusCode filterEvent()
Definition: xAODHeavyFlavorHadronFilter.cxx:45
xAODHeavyFlavorHadronFilter::m_RequireTruthJet
Gaudi::Property< bool > m_RequireTruthJet
Definition: xAODHeavyFlavorHadronFilter.h:55
xAODHeavyFlavorHadronFilter::m_bottomEtaMax
Gaudi::Property< double > m_bottomEtaMax
Definition: xAODHeavyFlavorHadronFilter.h:39
xAODHeavyFlavorHadronFilter::m_deltaRFromTruth
Gaudi::Property< double > m_deltaRFromTruth
Definition: xAODHeavyFlavorHadronFilter.h:56
xAODHeavyFlavorHadronFilter::m_RequestSpecificPDGID
Gaudi::Property< bool > m_RequestSpecificPDGID
Definition: xAODHeavyFlavorHadronFilter.h:54
xAODHeavyFlavorHadronFilter::m_RequestBottom
Gaudi::Property< bool > m_RequestBottom
Definition: xAODHeavyFlavorHadronFilter.h:51
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
skel.genpart
tuple genpart
Check that the actual generators, tune, and main PDF are consistent with the JO name.
Definition: skel.ABtoEVGEN.py:262
xAODHeavyFlavorHadronFilter::m_RequestCharm
Gaudi::Property< bool > m_RequestCharm
Definition: xAODHeavyFlavorHadronFilter.h:50
xAODHeavyFlavorHadronFilter::m_NDHadronPass
int m_NDHadronPass
Definition: xAODHeavyFlavorHadronFilter.h:65
JetContainer.h
xAODHeavyFlavorHadronFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: xAODHeavyFlavorHadronFilter.cxx:22
xAODHeavyFlavorHadronFilter::m_Request_bQuark
Gaudi::Property< bool > m_Request_bQuark
Definition: xAODHeavyFlavorHadronFilter.h:53
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
xAODHeavyFlavorHadronFilter::m_bPtMin
Gaudi::Property< double > m_bPtMin
Definition: xAODHeavyFlavorHadronFilter.h:41
xAODHeavyFlavorHadronFilter::filterFinalize
virtual StatusCode filterFinalize()
Definition: xAODHeavyFlavorHadronFilter.cxx:34
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAODHeavyFlavorHadronFilter::m_PDGEtaMax
Gaudi::Property< double > m_PDGEtaMax
Definition: xAODHeavyFlavorHadronFilter.h:47
xAODHeavyFlavorHadronFilter::m_bottomPtMin
Gaudi::Property< double > m_bottomPtMin
Definition: xAODHeavyFlavorHadronFilter.h:37
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAODHeavyFlavorHadronFilter::m_PDGID
Gaudi::Property< int > m_PDGID
Definition: xAODHeavyFlavorHadronFilter.h:48