ATLAS Offline Software
XtoVVDecayFilterExtended.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 
7 
8 XtoVVDecayFilterExtended::XtoVVDecayFilterExtended(const std::string& name, ISvcLocator* pSvcLocator)
9  : GenFilter(name, pSvcLocator)
10 {
11  declareProperty("PDGGrandParent", m_PDGGrandParent);
12  declareProperty("PDGParent", m_PDGParent);
13  declareProperty("StatusParent", m_StatusParent);
14  declareProperty("PDGChild1", m_PDGChild1);
15  declareProperty("PDGChild2", m_PDGChild2);
16 
17  // initialize member variables (to make Coverity tool happy...)
18  m_nHtoVV = 0;
19  m_nGoodHtoVV = 0;
20 
21 }
22 
23 
25  ATH_MSG_INFO("PDGGrandParent(H) = " << m_PDGGrandParent << " will scan all ancestors to find PDGGrandParent");
26  ATH_MSG_INFO("PDGParent(V) = " << m_PDGParent << " " << "StatusParent(V) = " << m_StatusParent);
27  if (m_PDGChild1.empty()) ATH_MSG_ERROR("PDGChild1[] not set ");
28  if (m_PDGChild2.empty()) ATH_MSG_ERROR("PDGChild2[] not set ");
29  for (size_t i = 0; i < m_PDGChild1.size(); ++i)
30  ATH_MSG_INFO("PDGChild1[" << i << "] = " << m_PDGChild1[i]);
31  for (size_t i = 0; i < m_PDGChild2.size(); ++i)
32  ATH_MSG_INFO("PDGChild2[" << i << "] = " << m_PDGChild2[i]);
33 
34  // init
35  m_nHtoVV = 0;
36  m_nGoodHtoVV = 0;
37  return StatusCode::SUCCESS;
38 }
39 
40 
42  ATH_MSG_INFO("Statistics of X->VV, V->decay scanning all ancestors of V in order to find X");
43  ATH_MSG_INFO(" ALL X->VV " << m_nHtoVV);
44  ATH_MSG_INFO(" Good X->VV " << m_nGoodHtoVV);
45  if (m_nHtoVV != 0) ATH_MSG_INFO(" Fraction " << double(m_nGoodHtoVV)/double(m_nHtoVV));
46  return StatusCode::SUCCESS;
47 }
48 
49 
51  bool okPDGChild1 = false;
52  bool okPDGChild2 = false;
53  int nGoodParent = 0;
54 
56  for (itr = events()->begin(); itr != events()->end(); ++itr) {
57  // Loop over all particles in the event
58  const HepMC::GenEvent* genEvt = (*itr);
59  for (const auto& pitr: *genEvt) {
60  if ( std::abs(pitr->pdg_id()) == m_PDGParent && pitr->status() == m_StatusParent) {
61  bool isGrandParentOK = RunHistory(pitr);
62  ATH_MSG_DEBUG(" Grand Parent is OK? " << isGrandParentOK);
63  if (!isGrandParentOK) continue;
64  ++nGoodParent;
65  FindAncestor(pitr->end_vertex(), m_PDGParent, okPDGChild1, okPDGChild2);
66  }
67  }
68  }
69  ATH_MSG_DEBUG("Result " << nGoodParent << " " << okPDGChild1 << " " << okPDGChild2);
70 
71  if (nGoodParent == 2) {
72  ++m_nHtoVV;
73  if (okPDGChild1 && okPDGChild2) {
74  ++m_nGoodHtoVV;
75  return StatusCode::SUCCESS;
76  }
77  }
78 
79  // If we get here we have failed
80  setFilterPassed(false);
81  return StatusCode::SUCCESS;
82 }
83 
84 // Runs the history of ancestors and returns TRUE if it finds the
85 // m_PDGGrandParent in the list of ansestors
87  auto pitr=input;
88  if (! pitr->production_vertex()) {
89  ATH_MSG_DEBUG("No History for this case");
90  return false;
91  }
92 #ifdef HEPMC3
93 
94  if (pitr->production_vertex()->particles_in().size()==0) {
95  ATH_MSG_DEBUG("No mother for this case");
96  return false;
97  }
98  int result = 999;
99 
100  // Check if the first mother is ok
101  pitr = CheckGrandparent(pitr, result);
102  ATH_MSG_DEBUG("Pointer PDG ID: " << pitr->pdg_id());
103  if(std::abs(pitr->pdg_id()) != m_PDGGrandParent && std::abs(pitr->pdg_id()) != m_PDGParent) return false;
104  if (result == m_PDGGrandParent) return true;
105 
106  // set pitr_current to grand parent pointer
107  auto pitr_current = pitr;
108  while ( result >= 0 ) {
109  pitr_current = CheckGrandparent(pitr_current, result);
110  ATH_MSG_DEBUG("Pointer PDG ID: " << pitr->pdg_id());
111  if(std::abs(pitr_current->pdg_id()) != m_PDGGrandParent && std::abs(pitr_current->pdg_id()) != m_PDGParent) return false;
112 
113  if (result == m_PDGGrandParent) return true;
114  }
115 #else
116  HepMC::GenVertex::particle_iterator firstMother = pitr->production_vertex()->particles_begin(HepMC::parents);
117  HepMC::GenVertex::particle_iterator endMother = pitr->production_vertex()->particles_end(HepMC::parents);
118  HepMC::GenVertex::particle_iterator thisMother = firstMother;
119  if (firstMother == endMother) {
120  ATH_MSG_DEBUG("No mother for this case");
121  return false;
122  }
123  int result = 999;
124  // Check if the first mother is ok
125  pitr = CheckGrandparent(pitr, result);
126  ATH_MSG_DEBUG("Pointer PDG ID: " << pitr->pdg_id());
127  if(std::abs(pitr->pdg_id()) != m_PDGGrandParent && std::abs(pitr->pdg_id()) != m_PDGParent) return false;
128  if (result == m_PDGGrandParent) return true;
129 
130  HepMC::ConstGenParticlePtr pitr_current = (*firstMother);
131  while ( result >= 0 ) {
132  pitr_current = CheckGrandparent(pitr_current, result);
133  ATH_MSG_DEBUG("Pointer PDG ID: " << pitr->pdg_id());
134  if(std::abs(pitr_current->pdg_id()) != m_PDGGrandParent && std::abs(pitr_current->pdg_id()) != m_PDGParent) return false;
135  if (result == m_PDGGrandParent) return true;
136  }
137 #endif
138 
139  return false;
140 }
141 
142 
143 // checks whether the grandparent of a given particle is m_PDGGrandParent
144 // it returns the first mother
146 
147  if (! pitr->production_vertex()) {
148  ATH_MSG_DEBUG("No ancestor for this case");
149  result=-1;
150  return NULL;
151  }
152  bool isGrandParentOK = false;
153 #ifdef HEPMC3
154  if (pitr->production_vertex()->particles_in().size()==0) {
155  ATH_MSG_DEBUG("No mother for this case");
156  result = -2;
157  return NULL;
158  }
159 
160  int n_mothers = 1;
161 
162  for (const auto& thisMother: pitr->production_vertex()->particles_in()) {
163  ATH_MSG_DEBUG("Now on this mother: " << (thisMother)->pdg_id() << " " << n_mothers);
164  if ( (thisMother)->pdg_id() != m_PDGGrandParent && std::abs((thisMother)->pdg_id()) != m_PDGParent)
165  break;
166  if ( (thisMother)->pdg_id() == m_PDGGrandParent && n_mothers == 1) { isGrandParentOK = true; }
167  n_mothers++;
168  }
169 
170  if (isGrandParentOK) {
172  }
173  else {
174  result = 0;
175  }
176 
177  return pitr->production_vertex()->particles_in()[0];
178 #else
179  HepMC::GenVertex::particle_iterator firstMother = pitr->production_vertex()->particles_begin(HepMC::parents);
180  HepMC::GenVertex::particle_iterator endMother = pitr->production_vertex()->particles_end(HepMC::parents);
181  HepMC::GenVertex::particle_iterator thisMother = firstMother;
182  if (firstMother == endMother) {
183  ATH_MSG_DEBUG("No mother for this case");
184  result = -2;
185  return NULL;
186  }
187 
188  int n_mothers = 1;
189 
190  for (; thisMother != endMother; ++thisMother) {
191  ATH_MSG_DEBUG("Now on this mother: " << (*thisMother)->pdg_id() << " " << n_mothers);
192  if ( (*thisMother)->pdg_id() != m_PDGGrandParent && std::abs((*thisMother)->pdg_id()) != m_PDGParent)
193  break;
194  if ( (*thisMother)->pdg_id() == m_PDGGrandParent && n_mothers == 1) { isGrandParentOK = true; }
195  n_mothers++;
196 
197  }
198  if (isGrandParentOK) {
200  }
201  else {
202  result = 0;
203  }
204  return (*firstMother);
205 #endif
206 }
207 
208 
210  int targetPDGID, bool& okPDGChild1, bool& okPDGChild2) const{
211  if (!searchvertex) return;
212  for (const auto& thisAncestor: *searchvertex){
213  if (std::abs(thisAncestor->pdg_id()) == targetPDGID) { //same particle as parent
214  FindAncestor(thisAncestor->end_vertex(), targetPDGID, okPDGChild1, okPDGChild2);
215  } else {
216  if (!okPDGChild1) {
217  for (size_t i = 0; i < m_PDGChild1.size(); ++i) {
218  if (std::abs(thisAncestor->pdg_id()) == m_PDGChild1[i]) {
219  okPDGChild1 = true;
220  break;
221  }
222  }
223  if (okPDGChild1) break;
224  }
225  if (!okPDGChild2) {
226  for (size_t i = 0; i < m_PDGChild2.size(); ++i) {
227  if (std::abs(thisAncestor->pdg_id()) == m_PDGChild2[i]) {
228  okPDGChild2 = true;
229  break;
230  }
231  }
232  if (okPDGChild2) break;
233  }
234  }
235  }
236 }
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
get_generator_info.result
result
Definition: get_generator_info.py:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
XtoVVDecayFilterExtended.h
XtoVVDecayFilterExtended::m_PDGGrandParent
int m_PDGGrandParent
Definition: XtoVVDecayFilterExtended.h:29
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
python.DecayParser.parents
parents
print ("==> buf:",buf)
Definition: DecayParser.py:31
XtoVVDecayFilterExtended::filterInitialize
virtual StatusCode filterInitialize()
Definition: XtoVVDecayFilterExtended.cxx:24
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
XtoVVDecayFilterExtended::m_PDGChild1
std::vector< int > m_PDGChild1
Definition: XtoVVDecayFilterExtended.h:32
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
XtoVVDecayFilterExtended::m_PDGChild2
std::vector< int > m_PDGChild2
Definition: XtoVVDecayFilterExtended.h:33
XtoVVDecayFilterExtended::m_PDGParent
int m_PDGParent
Definition: XtoVVDecayFilterExtended.h:30
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
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
XtoVVDecayFilterExtended::FindAncestor
void FindAncestor(const HepMC::ConstGenVertexPtr &searchvertex, int targetPDGID, bool &okPDGChild1, bool &okPDGChild2) const
Definition: XtoVVDecayFilterExtended.cxx:209
XtoVVDecayFilterExtended::m_nHtoVV
int m_nHtoVV
Definition: XtoVVDecayFilterExtended.h:35
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
XtoVVDecayFilterExtended::m_nGoodHtoVV
int m_nGoodHtoVV
Definition: XtoVVDecayFilterExtended.h:36
XtoVVDecayFilterExtended::RunHistory
bool RunHistory(const HepMC::ConstGenParticlePtr &pitr) const
Definition: XtoVVDecayFilterExtended.cxx:86
XtoVVDecayFilterExtended::filterEvent
virtual StatusCode filterEvent()
Definition: XtoVVDecayFilterExtended.cxx:50
XtoVVDecayFilterExtended::XtoVVDecayFilterExtended
XtoVVDecayFilterExtended(const std::string &name, ISvcLocator *pSvcLocator)
Definition: XtoVVDecayFilterExtended.cxx:8
XtoVVDecayFilterExtended::CheckGrandparent
HepMC::ConstGenParticlePtr CheckGrandparent(const HepMC::ConstGenParticlePtr &pitr, int &) const
Definition: XtoVVDecayFilterExtended.cxx:145
HepMC::ConstGenVertexPtr
const HepMC::GenVertex * ConstGenVertexPtr
Definition: GenVertex.h:60
XtoVVDecayFilterExtended::m_StatusParent
int m_StatusParent
Definition: XtoVVDecayFilterExtended.h:31
XtoVVDecayFilterExtended::filterFinalize
virtual StatusCode filterFinalize()
Definition: XtoVVDecayFilterExtended.cxx:41