ATLAS Offline Software
ParentTwoChildrenFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 ParentTwoChildrenFilter::ParentTwoChildrenFilter(const std::string& name, ISvcLocator* pSvcLocator)
9  : GenFilter(name,pSvcLocator)
10 {
11  declareProperty("PDGParent",m_PDGParent);
12  declareProperty("PtMinParent",m_PtMinParent = 0.);
13  declareProperty("EtaRangeParent",m_EtaRangeParent = 10.0);
14  declareProperty("PDGChild",m_PDGChild);
15  declareProperty("PtMinChild",m_PtMinChild = 0.);
16  declareProperty("EtaRangeChild",m_EtaRangeChild = 10.0);
17 }
18 
19 
21  if (m_PDGParent.size() == 0) ATH_MSG_ERROR("PDGParent[] not set ");
22  if (m_PDGChild.size() == 0) ATH_MSG_ERROR("PDGChild[] not set ");
23  for (int i=0; i < int(m_PDGParent.size()); i++) ATH_MSG_DEBUG("PDGParent["<<i<<"] = " << m_PDGParent[i]);
24  ATH_MSG_DEBUG("PtMinParent = " << m_PtMinParent);
25  ATH_MSG_DEBUG("EtaRangeParent = " << m_EtaRangeParent);
26  for (int i=0; i < int(m_PDGChild.size()); i++) ATH_MSG_DEBUG("PDGChild["<<i<<"] = " << m_PDGChild[i]);
27  ATH_MSG_DEBUG("PtMinChild = " << m_PtMinChild);
28  ATH_MSG_DEBUG("EtaRangeChild = " << m_EtaRangeChild);
29  return StatusCode::SUCCESS;
30 }
31 
32 
34  ATH_MSG_DEBUG(" ParentTwoChildrenFilter filtering for: "
35  << "Parent (" << m_PDGParent[0] << ") --> Child (" << m_PDGChild[0] << ") + antiparticle and "
36  << "Parent (" << m_PDGParent[0] << ") --> Child (" << m_PDGChild[1] << ") + antiparticle." );
37  int N_Child[2][2];
38  for (int i = 0; i < 2; i++) {
39  N_Child[i][0] = 0;
40  N_Child[i][1] = 0;
41  }
42  for (McEventCollection::const_iterator itr = events()->begin(); itr != events()->end(); ++itr) {
43  const HepMC::GenEvent* genEvt = (*itr);
44  for (const auto& pitr: *genEvt) {
45  int id = pitr->pdg_id();
46  if (std::abs(id) != m_PDGParent[0]) continue;
47  if (pitr->momentum().perp() < m_PtMinParent) continue;
48  const HepMC::ConstGenVertexPtr& decayVtx = pitr->end_vertex();
49  // Verify if we got a valid pointer and retrieve the number of daughters
50  if (!decayVtx) continue;
51  int n_daughters = decayVtx->particles_out_size();
52 
53  if (n_daughters < 2) continue;
54 
55  int neutralPar = 0;
56  for(const auto& thisChild: *decayVtx) {
57  ATH_MSG_DEBUG(" ParentTwoChildrenFilter: parent ==> " <<pitr->pdg_id() << " child ===> " <<thisChild->pdg_id());
58  for (int i = 0; i < 2; i++) {
59  if ( std::abs(thisChild->pdg_id()) == m_PDGChild[i]) {
60  int antiparticle = ( MC::charge(m_PDGChild[i]) == 0 ? 1 : -1 ); // assume that zero charge particles are their own anti-particle
61  if ( thisChild->pdg_id() == m_PDGChild[i] ) {
62  if( (thisChild->momentum().perp() >= m_PtMinChild) ) {
63  if(antiparticle == 1) {
64  neutralPar++;
65  if(neutralPar == 1) N_Child[i][0]++;
66  }
67  else N_Child[i][0]++;
68  }
69  }
70  if ( thisChild->pdg_id() == antiparticle * m_PDGChild[i] ) {
71  if( (thisChild->momentum().perp() >= m_PtMinChild) ) {
72  if(antiparticle == 1){
73  if (neutralPar == 2) N_Child[i][1]++;
74  }
75  else N_Child[i][1]++;
76  }
77  }
78  }
79  }
80  }
81  }
82  }
83  setFilterPassed(N_Child[0][0] >= 1 && N_Child[0][1] >= 1 && N_Child[1][0] >= 1 && N_Child[1][1] >= 1);
84  return StatusCode::SUCCESS;
85 }
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ParentTwoChildrenFilter::ParentTwoChildrenFilter
ParentTwoChildrenFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ParentTwoChildrenFilter.cxx:8
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ParentTwoChildrenFilter::m_PDGChild
std::vector< int > m_PDGChild
Definition: ParentTwoChildrenFilter.h:24
ParentTwoChildrenFilter::filterEvent
virtual StatusCode filterEvent()
Definition: ParentTwoChildrenFilter.cxx:33
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
ParentTwoChildrenFilter::m_EtaRangeChild
double m_EtaRangeChild
Definition: ParentTwoChildrenFilter.h:26
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
ParentTwoChildrenFilter::m_EtaRangeParent
double m_EtaRangeParent
Definition: ParentTwoChildrenFilter.h:23
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ParentTwoChildrenFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: ParentTwoChildrenFilter.cxx:20
charge
double charge(const T &p)
Definition: AtlasPID.h:494
ParentTwoChildrenFilter::m_PDGParent
std::vector< int > m_PDGParent
Definition: ParentTwoChildrenFilter.h:21
ParentTwoChildrenFilter::m_PtMinParent
double m_PtMinParent
Definition: ParentTwoChildrenFilter.h:22
HepMC::ConstGenVertexPtr
const HepMC::GenVertex * ConstGenVertexPtr
Definition: GenVertex.h:60
ParentTwoChildrenFilter::m_PtMinChild
double m_PtMinChild
Definition: ParentTwoChildrenFilter.h:25
HepMCHelpers.h
ParentTwoChildrenFilter.h