ATLAS Offline Software
TTbarPlusHeavyFlavorFilterTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 namespace DerivationFramework{
9 
10 TTbarPlusHeavyFlavorFilterTool::TTbarPlusHeavyFlavorFilterTool(const std::string& t, const std::string& n, const IInterface* p)
11  : AthAlgTool(t,n,p)
12 {
13 
14  declareInterface<DerivationFramework::TTbarPlusHeavyFlavorFilterTool>(this);
15 
16  declareProperty("MCCollectionName",m_mcName="TruthEvents");
17  declareProperty("UsePileUp",m_usePileUp=false);
18  declareProperty("UseFinalStateHadrons",m_useFinalStateHadrons=false);
19  declareProperty("BpTMinCut",m_bPtMinCut=5000.);
20  declareProperty("BetaMaxCut",m_bEtaMaxCut=3.);
21  declareProperty("CpTMinCut",m_cPtMinCut=5000.);
22  declareProperty("CetaMaxCut",m_cEtaMaxCut=3.);
23  declareProperty("BMultiplicityCut",m_bMultiCut=1);
24  declareProperty("CMultiplicityCut",m_cMultiCut=1);
25  declareProperty("ExcludeBFromTTbar",m_excludeBFromTop=true);
26  declareProperty("ExcludeCFromTTbar",m_excludeCFromTop=true);
27 
28 }
29 
31 
33  ATH_MSG_INFO("Initialize " );
34  return StatusCode::SUCCESS;
35 }
36 
38  return StatusCode::SUCCESS;
39 }
40 
41 
43 
44  int nB=0;
45  int nC=0;
46 
47  int nBtop=0;
48  int nCtop=0;
49 
50  const xAOD::TruthEventContainer* xTruthEventContainer = 0;
51  if (evtStore()->retrieve(xTruthEventContainer,m_mcName).isFailure()) {
52  ATH_MSG_WARNING("could not retrieve TruthEventContainer " <<m_mcName);
53  return -1;
54  }
55 
56  for ( const auto* truthevent : *xTruthEventContainer ) {
57 
58  for(unsigned int i = 0; i < truthevent->nTruthParticles(); i++){
59 
60  const xAOD::TruthParticle* part = truthevent->truthParticle(i);
61  // In release 21 we'll have a thinned truth record in the AODs.
62  // Specifically, geant particle are removed in most cases. The subsequent
63  // nullptr check is supposed to catch these truth particles,
64  // unfortunately however, there's no way to check whether this truth
65  // particle would have had an impact on what we do further down.
66  if ( !part){
67  // We could possibly also use break since the thinned truth particles
68  // in principle should have no simulation particles.
69  continue;
70  }
71 
73 
74  bool isbquark=false;
75  bool iscquark=false;
76 
77  bool isbhadron=false;
78  bool ischadron=false;
79 
80  int pdgid = std::abs(part->pdgId());
81 
83  if(pdgid == 5 ){
84  isbquark=true;
85  }
86  else if(pdgid == 4 ){
87  iscquark=true;
88  }
90  isbhadron=true;
91  }
93  ischadron=true;
94  }
95  else {
96  continue;
97  }
98 
99  if( (isbquark || isbhadron) && !passBSelection(part) ) continue;
100  if( (iscquark || ischadron) && !passCSelection(part) ) continue;
101 
102  if(isbhadron || ischadron){
103  if(!isInitialHadron(part) && !m_useFinalStateHadrons) continue;
104  if(!isFinalHadron(part) && m_useFinalStateHadrons) continue;
105  }
106 
107  if(m_excludeBFromTop && isbquark){
108  bool islooping = isLooping(part);
109  if (isDirectlyFromTop(part)) ++nBtop;
110  if (isDirectlyFromWTop(part, islooping)) ++nBtop;
111  }
112  if(m_excludeCFromTop && iscquark){
113  bool islooping = isLooping(part);
114  if(isDirectlyFromTop(part))++nCtop;
115  if(isDirectlyFromWTop(part, islooping))++nCtop;
116  }
117 
118  bool ischadronfromb = isCHadronFromB(part);
119 
120  if(isbhadron) ++nB;
121  if(ischadron && !ischadronfromb) ++nC;
122 
123  }
124 
125  if(!m_usePileUp){
126  break;
127  }
128 
129  }
130 
131 
132  int nAddB=nB;
133  if(m_excludeBFromTop){
134  nAddB-=nBtop;
135  }
136 
137  int nAddC=nC;
138  if(m_excludeCFromTop){
139  nAddC-=nCtop;
140  }
141 
142  int flavortype=0;
143 
144  if(nAddC>=m_cMultiCut){
145  flavortype=4;
146  }
147 
148  if(nAddB>=m_bMultiCut){
149  flavortype=5;
150  }
151 
152  return flavortype;
153 
154 }
155 
156 
158 
159  double pt = part->pt();
160  double eta = fabs(part->eta());
161 
162  if(pt <m_bPtMinCut) return false;
163  if(eta > m_bEtaMaxCut) return false;
164 
165  return true;
166 
167 }
168 
170 
171  double pt = part->pt();
172  double eta = fabs(part->eta());
173  if (pt < m_cPtMinCut) return false;
174  if (eta > m_cEtaMaxCut) return false;
175  return true;
176 }
177 
179 
180  int qtype = std::abs(MC::leadingQuark(part));
181  for(unsigned int i=0; i<part->nParents(); ++i){
182  const xAOD::TruthParticle* parent = part->parent(i);
183  if (HepMC::uniqueID(part) == HepMC::uniqueID(parent) ) continue;
184  int mothertype = std::abs(MC::leadingQuark(parent));
185  if (mothertype == qtype ){
186  return false;
187  }
188  }
189 
190  return true;
191 }
192 
193 
195 
196  int qtype = std::abs(MC::leadingQuark(part));
197  for(unsigned j = 0; j < part->nChildren(); j++){
198  const xAOD::TruthParticle* child = part->child(j);
199  if (HepMC::uniqueID(part) == HepMC::uniqueID(child) ) continue;
200  int childtype = std::abs(MC::leadingQuark(child));
201  if (childtype == qtype ){
202  return false;
203  }
204  }
205  return true;
206 }
207 
209 
210  for(unsigned int i=0; i<part->nParents(); ++i){
211  const xAOD::TruthParticle* parent = part->parent(i);
212  if (HepMC::uniqueID(part) == HepMC::uniqueID(parent) ) continue;
213  int mothertype = std::abs(MC::leadingQuark(parent));
214  if (4 == mothertype || 5 == mothertype ){
215  return true;
216  }
217  if (isQuarkFromHadron(parent)) return true;
218  }
219  return false;
220 }
221 
223 
225 
226  for(unsigned int i=0; i<part->nParents(); ++i){
227  const xAOD::TruthParticle* parent = part->parent(i);
228  if (HepMC::uniqueID(part) == HepMC::uniqueID(parent) ) continue;
230  return true;
231  }
233  if(isCHadronFromB(parent)) return true;
234  }
235  }
236 
237  return false;
238 }
239 
240 bool TTbarPlusHeavyFlavorFilterTool::isLooping(const xAOD::TruthParticle* part, std::set<const xAOD::TruthParticle*> init_part) const {
241  init_part.insert(part);
242  for(unsigned int i=0; i<part->nParents(); ++i){
243  const xAOD::TruthParticle* parent = part->parent(i);
244  if (init_part.find(parent) != init_part.end()) return true;
245  if (isLooping(parent, init_part)) return true;
246  }
247  return false;
248 }
249 
251 
252  for(unsigned int i=0; i<part->nParents(); ++i){
253  const xAOD::TruthParticle* parent = part->parent(i);
254  if (HepMC::uniqueID(part) == HepMC::uniqueID(parent)) continue;
255  if (part->pdgId() == parent->pdgId() ){
256  return findInitial(parent, looping);
257  }
258  }
259  return part;
260 }
261 
263  const xAOD::TruthParticle* initpart = findInitial(part, looping);
264  return isDirectlyFromTop(initpart);
265 }
266 
268 
269  for(unsigned int i=0; i<part->nParents(); ++i){
270  const xAOD::TruthParticle* parent = part->parent(i);
271  if (HepMC::uniqueID(part) == HepMC::uniqueID(parent) ) continue;
272  if (std::abs( parent->pdgId() ) == 6 ) return true;
273  }
274  return false;
275 }
276 
278 
279  for(unsigned int i=0; i<part->nParents(); ++i){
280  const xAOD::TruthParticle* parent = part->parent(i);
281  if (HepMC::uniqueID(part) == HepMC::uniqueID(parent)) continue;
282  if (MC::isW(parent) ){
283  if (isFromTop(parent, looping) ) return true;
284  }
285  }
286  return false;
287 }
288 
289 
290 }
291 
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::m_bMultiCut
int m_bMultiCut
Definition: TTbarPlusHeavyFlavorFilterTool.h:52
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::passBSelection
bool passBSelection(const xAOD::TruthParticle *part) const
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:157
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::TTbarPlusHeavyFlavorFilterTool
TTbarPlusHeavyFlavorFilterTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:10
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::m_usePileUp
bool m_usePileUp
Definition: TTbarPlusHeavyFlavorFilterTool.h:44
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::isDirectlyFromTop
bool isDirectlyFromTop(const xAOD::TruthParticle *part) const
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:267
test_pyathena.pt
pt
Definition: test_pyathena.py:11
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::isLooping
bool isLooping(const xAOD::TruthParticle *part, std::set< const xAOD::TruthParticle * > init_part=std::set< const xAOD::TruthParticle * >()) const
init_part needed to detect looping graphs (sherpa) and to switch on using barcode to resolve it witho...
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:240
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::findInitial
const xAOD::TruthParticle * findInitial(const xAOD::TruthParticle *part, bool looping) const
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:250
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::m_excludeCFromTop
bool m_excludeCFromTop
Definition: TTbarPlusHeavyFlavorFilterTool.h:56
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::m_cEtaMaxCut
double m_cEtaMaxCut
Definition: TTbarPlusHeavyFlavorFilterTool.h:50
isBottomHadron
bool isBottomHadron(const T &p)
Definition: AtlasPID.h:466
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TTbarPlusHeavyFlavorFilterTool.h
tool to compute filter flag for ttbar+HF
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::filterFlag
int filterFlag() const
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:42
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::m_useFinalStateHadrons
bool m_useFinalStateHadrons
Definition: TTbarPlusHeavyFlavorFilterTool.h:45
HepMC::is_simulation_particle
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
Definition: MagicNumbers.h:299
lumiFormat.i
int i
Definition: lumiFormat.py:92
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::isInitialHadron
bool isInitialHadron(const xAOD::TruthParticle *part) const
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:178
leadingQuark
int leadingQuark(const T &p)
Definition: AtlasPID.h:444
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::isFinalHadron
bool isFinalHadron(const xAOD::TruthParticle *part) const
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:194
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:113
test_pyathena.parent
parent
Definition: test_pyathena.py:15
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::m_cPtMinCut
double m_cPtMinCut
Definition: TTbarPlusHeavyFlavorFilterTool.h:49
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::finalize
virtual StatusCode finalize()
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:37
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::m_excludeBFromTop
bool m_excludeBFromTop
Definition: TTbarPlusHeavyFlavorFilterTool.h:55
isW
bool isW(const T &p)
Definition: AtlasPID.h:167
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::m_mcName
std::string m_mcName
properties
Definition: TTbarPlusHeavyFlavorFilterTool.h:42
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::passCSelection
bool passCSelection(const xAOD::TruthParticle *part) const
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:169
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::isQuarkFromHadron
bool isQuarkFromHadron(const xAOD::TruthParticle *part) const
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:208
isCharmHadron
bool isCharmHadron(const T &p)
Definition: AtlasPID.h:465
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::m_bPtMinCut
double m_bPtMinCut
Definition: TTbarPlusHeavyFlavorFilterTool.h:47
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::initialize
virtual StatusCode initialize()
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:32
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::m_bEtaMaxCut
double m_bEtaMaxCut
Definition: TTbarPlusHeavyFlavorFilterTool.h:48
HepMCHelpers.h
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::~TTbarPlusHeavyFlavorFilterTool
virtual ~TTbarPlusHeavyFlavorFilterTool()
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:30
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::isFromTop
bool isFromTop(const xAOD::TruthParticle *part, bool looping) const
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:262
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::isDirectlyFromWTop
bool isDirectlyFromWTop(const xAOD::TruthParticle *part, bool looping) const
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:277
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::isCHadronFromB
bool isCHadronFromB(const xAOD::TruthParticle *part) const
Definition: TTbarPlusHeavyFlavorFilterTool.cxx:222
DerivationFramework::TTbarPlusHeavyFlavorFilterTool::m_cMultiCut
int m_cMultiCut
Definition: TTbarPlusHeavyFlavorFilterTool.h:53