ATLAS Offline Software
xAODXtoVVDecayFilterExtended.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 xAODXtoVVDecayFilterExtended::xAODXtoVVDecayFilterExtended(const std::string &name, ISvcLocator *pSvcLocator)
8  : GenFilter(name, pSvcLocator)
9 {
10  declareProperty("PDGGrandParent", m_PDGGrandParent);
11  declareProperty("PDGParent", m_PDGParent);
12  declareProperty("StatusParent", m_StatusParent);
13  declareProperty("PDGChild1", m_PDGChild1);
14  declareProperty("PDGChild2", m_PDGChild2);
15 
16  // initialize member variables (to make Coverity tool happy...)
17  m_nHtoVV = 0;
18  m_nGoodHtoVV = 0;
19 }
20 
22 {
23  ATH_MSG_INFO("PDGGrandParent(H) = " << m_PDGGrandParent << " will scan all ancestors to find PDGGrandParent");
24  ATH_MSG_INFO("PDGParent(V) = " << m_PDGParent << " "
25  << "StatusParent(V) = " << m_StatusParent);
26  if (m_PDGChild1.empty())
27  ATH_MSG_ERROR("PDGChild1[] not set ");
28  if (m_PDGChild2.empty())
29  ATH_MSG_ERROR("PDGChild2[] not set ");
30  for (size_t i = 0; i < m_PDGChild1.size(); ++i)
31  ATH_MSG_INFO("PDGChild1[" << i << "] = " << m_PDGChild1[i]);
32  for (size_t i = 0; i < m_PDGChild2.size(); ++i)
33  ATH_MSG_INFO("PDGChild2[" << i << "] = " << m_PDGChild2[i]);
34 
35  // init
36  m_nHtoVV = 0;
37  m_nGoodHtoVV = 0;
38  return StatusCode::SUCCESS;
39 }
40 
42 {
43  ATH_MSG_INFO("Statistics of X->VV, V->decay scanning all ancestors of V in order to find X");
44  ATH_MSG_INFO(" ALL X->VV " << m_nHtoVV);
45  ATH_MSG_INFO(" Good X->VV " << m_nGoodHtoVV);
46  if (m_nHtoVV != 0)
47  ATH_MSG_INFO(" Fraction " << double(m_nGoodHtoVV) / double(m_nHtoVV));
48  return StatusCode::SUCCESS;
49 }
50 
52 {
53  bool okPDGChild1 = false;
54  bool okPDGChild2 = false;
55  int nGoodParent = 0;
56 
57  // Retrieve full TruthEventContainer container
58  const xAOD::TruthEventContainer *xTruthEventContainer = NULL;
59  if (evtStore()->retrieve(xTruthEventContainer, "TruthEvents").isFailure())
60  {
61  ATH_MSG_ERROR("No TruthEvent collection with name "
62  << "TruthEvents"
63  << " found in StoreGate!");
64  return StatusCode::FAILURE;
65  }
66 
67  for (xAOD::TruthEventContainer::const_iterator itr = xTruthEventContainer->begin(); itr != xTruthEventContainer->end(); ++itr)
68  {
69  unsigned int nPart = (*itr)->nTruthParticles();
70  for (unsigned int iPart = 0; iPart < nPart; ++iPart)
71  {
72  const xAOD::TruthParticle *pitr = (*itr)->truthParticle(iPart);
73  if (std::abs(pitr->pdgId()) == m_PDGParent && pitr->status() == m_StatusParent)
74  {
75  bool isGrandParentOK = RunHistory(pitr);
76  ATH_MSG_DEBUG(" Grand Parent is OK? " << isGrandParentOK);
77  if (!isGrandParentOK)
78  continue;
79  ++nGoodParent;
80  FindAncestor(pitr->decayVtx(), m_PDGParent, okPDGChild1, okPDGChild2);
81  }
82  }
83  }
84  ATH_MSG_DEBUG("Result " << nGoodParent << " " << okPDGChild1 << " " << okPDGChild2);
85 
86  if (nGoodParent == 2)
87  {
88  ++m_nHtoVV;
89  if (okPDGChild1 && okPDGChild2)
90  {
91  ++m_nGoodHtoVV;
92  return StatusCode::SUCCESS;
93  }
94  }
95 
96  // If we get here we have failed
97  setFilterPassed(false);
98  return StatusCode::SUCCESS;
99 }
100 
101 // Runs the history of ancestors and returns TRUE if it finds the
102 // m_PDGGrandParent in the list of ansestors
104 {
105  if (!pitr->prodVtx())
106  {
107  ATH_MSG_DEBUG("No History for this case");
108  return false;
109  }
110  if (pitr->prodVtx()->nIncomingParticles() == 0)
111  {
112  ATH_MSG_DEBUG("No mother for this case");
113  return false;
114  }
115  int result = 999;
116 
117  // Check if the first mother is ok
118  pitr = CheckGrandparent(pitr, result);
119  ATH_MSG_DEBUG("Pointer PDG ID: " << pitr->pdgId());
120  if (std::abs(pitr->pdgId()) != m_PDGGrandParent && std::abs(pitr->pdgId()) != m_PDGParent)
121  return false;
122  if (result == m_PDGGrandParent)
123  return true;
124 
125  //set pitr_current to pitr of grand parent
126  auto pitr_current = pitr;
127  while (result >= 0)
128  {
129  pitr_current = CheckGrandparent(pitr_current, result);
130  ATH_MSG_DEBUG("Pointer PDG ID: " << pitr->pdgId());
131  if (std::abs(pitr_current->pdgId()) != m_PDGGrandParent && std::abs(pitr_current->pdgId()) != m_PDGParent)
132  return false;
133 
134  if (result == m_PDGGrandParent)
135  return true;
136  }
137 
138  return false;
139 }
140 
141 // checks whether the grandparent of a given particle is m_PDGGrandParent
142 // it returns the first mother
144 {
145 
146  if (!pitr->prodVtx())
147  {
148  ATH_MSG_DEBUG("No ancestor for this case");
149  result = -1;
150  return NULL;
151  }
152  bool isGrandParentOK = false;
153 
154  if (pitr->prodVtx()->nIncomingParticles() == 0)
155  {
156  ATH_MSG_DEBUG("No mother for this case");
157  result = -2;
158  return NULL;
159  }
160 
161  int n_mothers = 1;
162 
163  for (size_t thisMother_id = 0; thisMother_id < pitr->prodVtx()->nIncomingParticles(); thisMother_id++)
164  {
165  auto thisMother = pitr->prodVtx()->incomingParticle(thisMother_id);
166  ATH_MSG_DEBUG("Now on this mother: " << (thisMother)->pdgId() << " " << n_mothers);
167  if ((thisMother)->pdgId() != m_PDGGrandParent && std::abs((thisMother)->pdgId()) != m_PDGParent)
168  break;
169  if ((thisMother)->pdgId() == m_PDGGrandParent && n_mothers == 1)
170  {
171  isGrandParentOK = true;
172  }
173  n_mothers++;
174  }
175 
176  if (isGrandParentOK)
177  {
179  }
180  else
181  {
182  result = 0;
183  }
184 
185  return pitr->prodVtx()->incomingParticle(0);
186 }
187 
189  int targetPDGID, bool &okPDGChild1, bool &okPDGChild2)
190 {
191  if (!searchvertex)
192  return;
193  for (size_t thisMother_id = 0; thisMother_id < searchvertex->nOutgoingParticles(); thisMother_id++)
194  {
195  auto thisAncestor = searchvertex->outgoingParticle(thisMother_id);
196 
197  if (std::abs(thisAncestor->pdgId()) == targetPDGID)
198  { // same particle as parent
199  FindAncestor(thisAncestor->decayVtx(), targetPDGID, okPDGChild1, okPDGChild2);
200  }
201  else
202  {
203  if (!okPDGChild1)
204  {
205  for (size_t i = 0; i < m_PDGChild1.size(); ++i)
206  {
207  if (std::abs(thisAncestor->pdgId()) == m_PDGChild1[i])
208  {
209  okPDGChild1 = true;
210  break;
211  }
212  }
213  if (okPDGChild1)
214  break;
215  }
216  if (!okPDGChild2)
217  {
218  for (size_t i = 0; i < m_PDGChild2.size(); ++i)
219  {
220  if (std::abs(thisAncestor->pdgId()) == m_PDGChild2[i])
221  {
222  okPDGChild2 = true;
223  break;
224  }
225  }
226  if (okPDGChild2)
227  break;
228  }
229  }
230  }
231 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::TruthVertex_v1::nOutgoingParticles
size_t nOutgoingParticles() const
Get the number of outgoing particles.
xAODXtoVVDecayFilterExtended::m_nHtoVV
int m_nHtoVV
Definition: xAODXtoVVDecayFilterExtended.h:39
xAODXtoVVDecayFilterExtended::m_nGoodHtoVV
int m_nGoodHtoVV
Definition: xAODXtoVVDecayFilterExtended.h:40
xAODXtoVVDecayFilterExtended::RunHistory
bool RunHistory(const xAOD::TruthParticle *pitr)
Definition: xAODXtoVVDecayFilterExtended.cxx:103
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
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAODXtoVVDecayFilterExtended::filterEvent
virtual StatusCode filterEvent()
Definition: xAODXtoVVDecayFilterExtended.cxx:51
xAODXtoVVDecayFilterExtended.h
xAODXtoVVDecayFilterExtended::m_PDGChild1
std::vector< int > m_PDGChild1
Definition: xAODXtoVVDecayFilterExtended.h:36
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition: PowhegPy8EG_H2a.py:128
xAODXtoVVDecayFilterExtended::m_PDGChild2
std::vector< int > m_PDGChild2
Definition: xAODXtoVVDecayFilterExtended.h:37
xAODXtoVVDecayFilterExtended::m_PDGGrandParent
int m_PDGGrandParent
Definition: xAODXtoVVDecayFilterExtended.h:33
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
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
xAODXtoVVDecayFilterExtended::FindAncestor
void FindAncestor(const xAOD::TruthVertex *searchvertex, int targetPDGID, bool &okPDGChild1, bool &okPDGChild2)
Definition: xAODXtoVVDecayFilterExtended.cxx:188
xAOD::TruthVertex_v1::incomingParticle
const TruthParticle_v1 * incomingParticle(size_t index) const
Get one of the incoming particles.
Definition: TruthVertex_v1.cxx:71
xAODXtoVVDecayFilterExtended::xAODXtoVVDecayFilterExtended
xAODXtoVVDecayFilterExtended(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODXtoVVDecayFilterExtended.cxx:7
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAODXtoVVDecayFilterExtended::filterInitialize
virtual StatusCode filterInitialize()
Definition: xAODXtoVVDecayFilterExtended.cxx:21
xAOD::TruthParticle_v1::decayVtx
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
xAOD::TruthParticle_v1::prodVtx
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
Definition: TruthParticle_v1.cxx:80
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:41
xAODXtoVVDecayFilterExtended::filterFinalize
virtual StatusCode filterFinalize()
Definition: xAODXtoVVDecayFilterExtended.cxx:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAODXtoVVDecayFilterExtended::CheckGrandparent
const xAOD::TruthParticle * CheckGrandparent(const xAOD::TruthParticle *pitr, int &)
Definition: xAODXtoVVDecayFilterExtended.cxx:143
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
xAOD::TruthParticle_v1::status
int status() const
Status code.
xAODXtoVVDecayFilterExtended::m_PDGParent
int m_PDGParent
Definition: xAODXtoVVDecayFilterExtended.h:34
xAOD::TruthVertex_v1::nIncomingParticles
size_t nIncomingParticles() const
Get the number of incoming particles.
Definition: TruthVertex_v1.cxx:49
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
xAOD::TruthVertex_v1::outgoingParticle
const TruthParticle_v1 * outgoingParticle(size_t index) const
Get one of the outgoing particles.
Definition: TruthVertex_v1.cxx:121
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAODXtoVVDecayFilterExtended::m_StatusParent
int m_StatusParent
Definition: xAODXtoVVDecayFilterExtended.h:35