ATLAS Offline Software
BoostedHadTopAndTopPairFilterTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 namespace DerivationFramework{
9 
10 //--------------------------------------------------------------------------
11 BoostedHadTopAndTopPairFilterTool::BoostedHadTopAndTopPairFilterTool(const std::string& t, const std::string& n, const IInterface* p)
12  : AthAlgTool(t,n,p)
13 {
14 
15  declareInterface<DerivationFramework::BoostedHadTopAndTopPairFilterTool>(this);
16  declareProperty("MCCollectionName",m_mcName ="TruthEvents");
17  declareProperty("cutPtOf", m_cutPtOf = 0);
18  // use values directly in filterFlag to make tool more flexible for now...
19  //declareProperty("tHadPtCut", m_tHadPtCut = 500000.0);
20  //declareProperty("tPairPtCut", m_tPairPtCut = 350000.0);
21 
22 }
23 
24 //--------------------------------------------------------------------------
26 
27 //--------------------------------------------------------------------------
28 StatusCode BoostedHadTopAndTopPairFilterTool::initialize() {ATH_MSG_INFO("Initialize " ); return StatusCode::SUCCESS; }
29 
30 //--------------------------------------------------------------------------
32 
33 //--------------------------------------------------------------------------
34  int BoostedHadTopAndTopPairFilterTool::filterFlag(double tHadPtCut, double tPairPtCut) const {
35 
36 
37  // if true, the event pass the filter :
38  int filterCode = 0;
39  bool passTopHad = false;
40  bool passTopPair = false;
41 
42  double topPt=0.0;
43  double topPx=0.0;
44  double topPy=0.0;
45  double topbarPt=0.0;
46  double topbarPx=0.0;
47  double topbarPy=0.0;
48 
49  double topChildrenPx=0.0;
50  double topChildrenPy=0.0;
51  double topbarChildrenPx=0.0;
52  double topbarChildrenPy=0.0;
53 
54  double hadtopPt = -1;
55  double hadtopbarPt = -1;
56  double hadtopChildrenPt = -1;
57 
58  double bPx=0.0;
59  double bPy=0.0;
60 
61  const xAOD::TruthEventContainer* xTruthEventContainer = 0;
62  if (evtStore()->retrieve(xTruthEventContainer,m_mcName).isFailure()) {
63  ATH_MSG_WARNING("could not retrieve TruthEventContainer " <<m_mcName);
64  return -1;
65  }
66  for ( const auto* truthevent : *xTruthEventContainer ) {
67 
68  // Loop over all truth particles in the event
69  for(unsigned int i = 0; i < truthevent->nTruthParticles(); i++){
70 
71  const xAOD::TruthParticle* part = truthevent->truthParticle(i);
72  // In release 21 we'll have a thinned truth record in the AODs.
73  // Specifically, geant particle are removed in most cases. The subsequent
74  // nullptr check is supposed to catch these truth particles,
75  // unfortunately however, there's no way to check whether this truth
76  // particle would have had an impact on what we do further down.
77  if (not part){
78  // We could possibly also use break since the thinned truth particles
79  // in principle should have no simulated particles.
80  continue;
81  }
82 
84  int pdgId = part->pdgId();
85 
86  // pdgId t quark = 6
87  if ( pdgId == 6 && isFinalParticle(part) ){
88  if ( part->pt() > topPt ){
89  topPx = part->px();
90  topPy = part->py();
91  topPt = part->pt();}
92  }
93 
94  if ( pdgId == -6 && isFinalParticle(part) ){
95  if ( part->pt() > topbarPt ){
96  topbarPx = part->px();
97  topbarPy = part->py();
98  topbarPt = part->pt();}
99  }
100 
101  // pdgId W boson = 24
102  if ( abs(pdgId) != 24 || !isFinalParticle(part) ) continue;
103 
104  // "part" is now a W boson
105  bPx=PxBofW(part);
106  bPy=PyBofW(part);
107  if (isFromTop(part)){
108  if (pdgId > 0) {
109  topChildrenPx=( part->px() + bPx );
110  topChildrenPy=( part->py() + bPy );
111  }
112  else {
113  topbarChildrenPx=( part->px() + bPx );
114  topbarChildrenPy=( part->py() + bPy );
115  }
116 
117  if (isHadronic(part)){
118  double pT = sqrt( pow( part->px() + bPx,2) + pow( part->py() + bPy,2));
119  if (pT > hadtopChildrenPt){
120  hadtopChildrenPt = pT;
121  if (pdgId > 0) hadtopPt = topPt;
122  else hadtopbarPt = topbarPt;
123  }
124  } // isHadronic
125  } // isFromTop
126  } // particle loop
127  } // event loop
128 
129 
130  double TTBarSysPt = sqrt( pow( topPx + topbarPx , 2 ) + pow( topPy + topbarPy , 2 ));
131  double TTBarChildrenSysPt = sqrt( pow( topChildrenPx + topbarChildrenPx , 2 ) + pow( topChildrenPy + topbarChildrenPy , 2 ));
132 
133  if (m_cutPtOf == 0){ // cut on the pT of top on the truth list
134  if (hadtopPt >= tHadPtCut || hadtopbarPt >= tHadPtCut ) passTopHad = true;
135  if (TTBarSysPt >= tPairPtCut ) passTopPair = true;
136  }
137  else if( m_cutPtOf == 1){ // cut on the pT of top decay products (b, q, qbar') on the truth list
138  if (hadtopChildrenPt >= tHadPtCut ) passTopHad = true;
139  if (TTBarChildrenSysPt >= tPairPtCut ) passTopPair = true;
140  }
141 
142 
143  //return which flags were passed
144  if ( !passTopPair && !passTopHad) filterCode = 0;
145  if ( passTopPair && !passTopHad) filterCode = 1;
146  if ( !passTopPair && passTopHad ) filterCode = 2;
147  if ( passTopPair && passTopHad ) filterCode = 3;
148  return filterCode;
149 }
150 
152 
153  if(!part->nParents()) return part;
154 
155  for(unsigned int i=0; i<part->nParents(); ++i){
156  const xAOD::TruthParticle* parent = part->parent(i);
157  if( part->pdgId() == parent->pdgId() ) return findInitial(parent);
158  }
159 
160  return part;
161 }
162 
163 //--------------------------------------------------------------------------
165 
166  if(!part->nParents()) return false;
167 
168  for(unsigned int i=0; i<part->nParents(); ++i){
169  const xAOD::TruthParticle* parent = part->parent(i);
170  if( abs( parent->pdgId() ) == 6 ) return true;
171  }
172 
173  return false;
174 }
175 
176 //--------------------------------------------------------------------------
178 
179  for(unsigned j = 0; j < part->nChildren(); j++){
180  const xAOD::TruthParticle* child = part->child(j);
181  if( abs(child->pdgId()) <= 5 ) return true;
182  }
183  return false;
184 }
185 
186 //--------------------------------------------------------------------------
188  int type = part->pdgId();
189  for(unsigned j = 0; j < part->nChildren(); j++){
190  const xAOD::TruthParticle* child = part->child(j);
191  int childtype = child->pdgId();
192  if( childtype == type ) return false;
193  }
194 
195  return true;
196 
197 }
198 
199 
200 //--------------------------------------------------------------------------
202 
203  const xAOD::TruthParticle* initpart = findInitial(part);
204 
205  double px=0.0;
206 
207  for(unsigned j = 0; j < initpart->nChildren(); j++){
208  const xAOD::TruthParticle* child = initpart->child(j);
209  if( abs( child->pdgId() ) == 5 ){
210  px = child->px();
211  }
212  }
213  return px;
214 }
215 
216 //--------------------------------------------------------------------------
218 
219  const xAOD::TruthParticle* initpart = findInitial(part);
220 
221  double py=0.0;
222 
223  for(unsigned j = 0; j < initpart->nChildren(); j++){
224  const xAOD::TruthParticle* child = initpart->child(j);
225  if( abs( child->pdgId() ) == 5 ){
226  py = child->py();
227  }
228  }
229  return py;
230 }
231 
232 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CalculateHighPtTerm.pT
pT
Definition: ICHEP2016/CalculateHighPtTerm.py:57
DerivationFramework::BoostedHadTopAndTopPairFilterTool::initialize
virtual StatusCode initialize()
Definition: BoostedHadTopAndTopPairFilterTool.cxx:28
test_pyathena.px
px
Definition: test_pyathena.py:18
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DerivationFramework::BoostedHadTopAndTopPairFilterTool::findInitial
const xAOD::TruthParticle * findInitial(const xAOD::TruthParticle *part) const
Definition: BoostedHadTopAndTopPairFilterTool.cxx:151
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::BoostedHadTopAndTopPairFilterTool::m_cutPtOf
int m_cutPtOf
Definition: BoostedHadTopAndTopPairFilterTool.h:43
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
DerivationFramework::BoostedHadTopAndTopPairFilterTool::~BoostedHadTopAndTopPairFilterTool
virtual ~BoostedHadTopAndTopPairFilterTool()
Definition: BoostedHadTopAndTopPairFilterTool.cxx:25
xAOD::TruthParticle_v1::px
float px() const
The x component of the particle's momentum.
xAOD::TruthParticle_v1::py
float py() const
The y component of the particle's momentum.
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::BoostedHadTopAndTopPairFilterTool::filterFlag
int filterFlag(double, double) const
Definition: BoostedHadTopAndTopPairFilterTool.cxx:34
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition: PowhegPy8EG_H2a.py:128
DerivationFramework::BoostedHadTopAndTopPairFilterTool::isFromTop
bool isFromTop(const xAOD::TruthParticle *part) const
Definition: BoostedHadTopAndTopPairFilterTool.cxx:164
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
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
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::BoostedHadTopAndTopPairFilterTool::finalize
virtual StatusCode finalize()
Definition: BoostedHadTopAndTopPairFilterTool.cxx:31
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
DerivationFramework::BoostedHadTopAndTopPairFilterTool::isHadronic
bool isHadronic(const xAOD::TruthParticle *part) const
Definition: BoostedHadTopAndTopPairFilterTool.cxx:177
test_pyathena.parent
parent
Definition: test_pyathena.py:15
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::BoostedHadTopAndTopPairFilterTool::m_mcName
std::string m_mcName
Definition: BoostedHadTopAndTopPairFilterTool.h:37
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::TruthParticle_v1::nChildren
size_t nChildren() const
Number of children of this particle.
Definition: TruthParticle_v1.cxx:140
Amg::py
@ py
Definition: GeoPrimitives.h:39
DerivationFramework::BoostedHadTopAndTopPairFilterTool::isFinalParticle
bool isFinalParticle(const xAOD::TruthParticle *part) const
Definition: BoostedHadTopAndTopPairFilterTool.cxx:187
MagicNumbers.h
DerivationFramework::BoostedHadTopAndTopPairFilterTool::BoostedHadTopAndTopPairFilterTool
BoostedHadTopAndTopPairFilterTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: BoostedHadTopAndTopPairFilterTool.cxx:11
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::TruthParticle_v1::child
const TruthParticle_v1 * child(size_t i=0) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
Definition: TruthParticle_v1.cxx:149
DerivationFramework::BoostedHadTopAndTopPairFilterTool::PxBofW
double PxBofW(const xAOD::TruthParticle *part) const
Definition: BoostedHadTopAndTopPairFilterTool.cxx:201
AthAlgTool
Definition: AthAlgTool.h:26
BoostedHadTopAndTopPairFilterTool.h
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
DerivationFramework::BoostedHadTopAndTopPairFilterTool::PyBofW
double PyBofW(const xAOD::TruthParticle *part) const
Definition: BoostedHadTopAndTopPairFilterTool.cxx:217