ATLAS Offline Software
xAODLeptonPairFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // --------------------------------------------------
6 //
7 // File: GeneratorFilters/src/xAODLeptonPairFilter.cxx
8 // Description:
9 // Classify Pairs of leptons according to their flavor and sign combinations
10 // and filter on these classifications
11 // Same-Flavor Opposite-Sign (SFOS)
12 // Same-Flavor Same-Sign (SFSS)
13 // Opposite-Flavor Opposite-Sign (OFOS)
14 // Opposite-Flavor Same-Sign(OFSS)
15 //
16 // AuthorList:
17 // A Long: May 2014
18 //
19 // Header for this module:-
20 
22 
23 // Framework Related Headers:-
24 #include "GaudiKernel/MsgStream.h"
25 
26 // Other classes used by this class:-
27 #include <math.h>
28 #include <vector>
29 #include <TLorentzVector.h>
30 
32 
33 //--------------------------------------------------------------------------
35  ISvcLocator* pSvcLocator): GenFilter(name,pSvcLocator) {
36 }
37 
38 //--------------------------------------------------------------------------
40 //--------------------------------------------------------------------------
41 
42 }
43 
44 //---------------------------------------------------------------------------
46 //---------------------------------------------------------------------------
47  return StatusCode::SUCCESS;
48 }
49 
50 //---------------------------------------------------------------------------
52 //---------------------------------------------------------------------------
53  return StatusCode::SUCCESS;
54 }
55 
56 
57 //---------------------------------------------------------------------------
59 //---------------------------------------------------------------------------
60 
61  // Loop over all events in McEventCollection
62  std::vector<int> vLeptonPDGIDs;
63  std::vector<double> vLeptonPt;
64  std::vector<double> vLeptonEta;
65  std::vector< std::vector < size_t > > vLeptonParentPDGIDs;
66 
67 // Retrieve TruthGen container from xAOD Gen slimmer, contains all particles witout barcode_zero and
68 // duplicated barcode ones
69  const xAOD::TruthParticleContainer* xTruthParticleContainer;
70  if (evtStore()->retrieve(xTruthParticleContainer, "TruthGen").isFailure()) {
71  ATH_MSG_ERROR("No TruthParticle collection with name " << "TruthGen" << " found in StoreGate!");
72  return StatusCode::FAILURE;
73  }
74 
75  // Loop over all particles in the event
76  unsigned int nPart = xTruthParticleContainer->size();
77  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
78  const xAOD::TruthParticle* pitr = (*xTruthParticleContainer)[iPart];
79 
80  if( !MC::isStable(pitr) ) continue;
81  // check stable particles only
82  // We do not place requirements on their origins (updated: optionally rejecting hadron decays)
83  // save pdg ids of found leptons
84  // do not consider taus
85  if( std::abs(pitr->pdgId()) != 11 && std::abs(pitr->pdgId()) != 13) continue;
86  //only consider leptons which satisfy pt and eta requirements
87  if( (pitr->pt() < m_Ptmin) || std::abs(pitr->eta()) > m_EtaRange) continue;
89  {
90  auto p = pitr;
91  bool massiveParent = false;
92  while(p)
93  {
94  auto vxp = p->prodVtx();
95  if(!vxp) break;
96  if(vxp->nIncomingParticles()!=1) break;
97  p = vxp->incomingParticle(0);
98  const int pdg = std::abs(p->pdgId());
99  if(!((pdg>=11 && pdg<=16) || pdg==22))
100  {
101  massiveParent = (p->m()>20000);
102  break;
103  }
104  }
105  if(!massiveParent) continue;
106  }
107 
108  vLeptonPDGIDs.push_back(pitr->pdgId());
109  vLeptonPt.push_back(pitr->pt());
110  vLeptonEta.push_back(pitr->eta());
111 
112  std::vector<size_t> parentPDG_tmp;
113  for(size_t thisParent_id=0; pitr->prodVtx()->nIncomingParticles()<thisParent_id;thisParent_id++)
114  parentPDG_tmp.push_back(pitr->prodVtx()->incomingParticle(thisParent_id)->pdgId());
115  vLeptonParentPDGIDs.push_back(parentPDG_tmp);
116  } //loop over TruthParticles
117 
118 
119  int nLeptons = vLeptonPDGIDs.size();
120 
121  //Filter automatically passes if number of leptons is different than expected
122  if (!( (nLeptons >= m_nLeptons_Min) &&
123  (m_nLeptons_Max < 0 || nLeptons <= m_nLeptons_Max) )) {
124  ATH_MSG_INFO("# Lep = "<<nLeptons << " Pass" );
125  return StatusCode::SUCCESS;
126  }
127 
128  int nSFOS = 0;
129  int nSFSS = 0;
130  int nOFOS = 0;
131  int nOFSS = 0;
132 
133  int id1 = 0;
134  int id2 = 0;
135  //loop over all possible pair combinations of the leptons
136  //which were found.
137  for (unsigned int i = 0 ; i < vLeptonPDGIDs.size() ; i++){
138  //don't double count
139  for (unsigned int j = i ; j < vLeptonPDGIDs.size() ; j++){
140  //Do not compare the lepton with itself
141  if(i==j) continue;
142  id1 = vLeptonPDGIDs[i];
143  id2 = vLeptonPDGIDs[j];
144  //classify the pair and count it
145  if(std::abs(id1)==std::abs(id2) && id1*id2 < 0) nSFOS+=1;
146  else if(std::abs(id1)==std::abs(id2) && id1*id2 > 0) nSFSS+=1;
147  else if(std::abs(id1)!=std::abs(id2) && id1*id2 < 0) nOFOS+=1;
148  else if(std::abs(id1)!=std::abs(id2) && id1*id2 > 0) nOFSS+=1;
149  else ATH_MSG_ERROR( "Couldn't classify lepton pair" );
150  }
151  }
152 
153  //based on configuration
154  //create sum of multiple pair combinations
155  //which can alternatively be cut on instead
156  //of the individual ones
157  int nPairSum = 0;
158  if(m_bUseSFOSInSum) nPairSum+=nSFOS;
159  if(m_bUseSFSSInSum) nPairSum+=nSFSS;
160  if(m_bUseOFOSInSum) nPairSum+=nOFOS;
161  if(m_bUseOFSSInSum) nPairSum+=nOFSS;
162 
163 
164  bool passSFOS = false;
165  bool passSFSS = false;
166  bool passOFOS = false;
167  bool passOFSS = false;
168  bool passPairSum = false;
169  //Test if number of lepton pairs satisfies requirements
170  //The maximum requirement is ignored if it is negative
171  //No requirement is made if both min and max values are negative
172  ATH_MSG_INFO("# Lep " << vLeptonPDGIDs.size() << ", "<< nSFOS << " SFOS, "<<nSFSS<< " SFSS, " << nOFOS << " OFOS, " << nOFSS << " OFSS pairs ," << nPairSum << "summed pairs" );
173 
174  if(nSFOS >= m_nSFOS_Min && (m_nSFOS_Max<0 || nSFOS <= m_nSFOS_Max)) passSFOS=true;
175  if(nSFSS >= m_nSFSS_Min && (m_nSFSS_Max<0 || nSFSS <= m_nSFSS_Max)) passSFSS=true;
176  if(nOFOS >= m_nOFOS_Min && (m_nOFOS_Max<0 || nOFOS <= m_nOFOS_Max)) passOFOS=true;
177  if(nOFSS >= m_nOFSS_Min && (m_nOFSS_Max<0 || nOFSS <= m_nOFSS_Max)) passOFSS=true;
178  if(nPairSum >= m_nPairSum_Min && (m_nPairSum_Max<0 || nPairSum <= m_nPairSum_Max)) passPairSum=true;
179 
180  if(passSFOS && passSFSS && passOFOS && passOFSS && passPairSum){
181  ATH_MSG_INFO("Pass" );
182  for (unsigned int i = 0;i<vLeptonPDGIDs.size();i++){
183  int pdg = vLeptonPDGIDs[i];
184  double pt = vLeptonPt[i];
185  double eta = vLeptonEta[i];
186  msg(MSG::DEBUG) << pdg << ": Pt = "<<pt<<", Eta = "<<eta << ", Parent PDG: ";
187  for (unsigned int j=0;j<vLeptonParentPDGIDs[i].size();j++) msg(MSG::DEBUG) << vLeptonParentPDGIDs[i][j];
188  msg(MSG::DEBUG) << endmsg;
189  }
190  return StatusCode::SUCCESS;
191  }
192 
193  // if we get here we have failed
194  setFilterPassed(false);
195  ATH_MSG_INFO("Fail" );
196  return StatusCode::SUCCESS;
197 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAODLeptonPairFilter::m_nOFSS_Min
Gaudi::Property< int > m_nOFSS_Min
Definition: xAODLeptonPairFilter.h:62
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAODLeptonPairFilter::filterEvent
virtual StatusCode filterEvent()
Definition: xAODLeptonPairFilter.cxx:58
xAODLeptonPairFilter::m_EtaRange
Gaudi::Property< double > m_EtaRange
Definition: xAODLeptonPairFilter.h:83
xAODLeptonPairFilter.h
xAODLeptonPairFilter::m_bUseSFOSInSum
Gaudi::Property< bool > m_bUseSFOSInSum
Definition: xAODLeptonPairFilter.h:71
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
test_pyathena.pt
pt
Definition: test_pyathena.py:11
xAODLeptonPairFilter::m_onlyMassiveParents
Gaudi::Property< bool > m_onlyMassiveParents
Definition: xAODLeptonPairFilter.h:78
xAODLeptonPairFilter::filterFinalize
virtual StatusCode filterFinalize()
Definition: xAODLeptonPairFilter.cxx:51
xAODLeptonPairFilter::m_bUseSFSSInSum
Gaudi::Property< bool > m_bUseSFSSInSum
Definition: xAODLeptonPairFilter.h:72
xAODLeptonPairFilter::m_nSFOS_Max
Gaudi::Property< int > m_nSFOS_Max
Definition: xAODLeptonPairFilter.h:49
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
id2
HWIdentifier id2
Definition: LArRodBlockPhysicsV0.cxx:564
lumiFormat.i
int i
Definition: lumiFormat.py:92
xAODLeptonPairFilter::m_nSFOS_Min
Gaudi::Property< int > m_nSFOS_Min
Definition: xAODLeptonPairFilter.h:50
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
xAODLeptonPairFilter::m_nOFOS_Max
Gaudi::Property< int > m_nOFOS_Max
Definition: xAODLeptonPairFilter.h:57
xAOD::TruthVertex_v1::incomingParticle
const TruthParticle_v1 * incomingParticle(size_t index) const
Get one of the incoming particles.
Definition: TruthVertex_v1.cxx:71
xAODLeptonPairFilter::m_nLeptons_Min
Gaudi::Property< int > m_nLeptons_Min
Definition: xAODLeptonPairFilter.h:90
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::TruthParticle_v1::prodVtx
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
Definition: TruthParticle_v1.cxx:80
xAODLeptonPairFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: xAODLeptonPairFilter.cxx:45
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::TruthParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TruthParticle_v1.cxx:174
xAODLeptonPairFilter::m_nPairSum_Min
Gaudi::Property< int > m_nPairSum_Min
Definition: xAODLeptonPairFilter.h:67
xAODLeptonPairFilter::m_nOFOS_Min
Gaudi::Property< int > m_nOFOS_Min
Definition: xAODLeptonPairFilter.h:58
xAODLeptonPairFilter::m_nSFSS_Max
Gaudi::Property< int > m_nSFSS_Max
Definition: xAODLeptonPairFilter.h:53
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
xAODLeptonPairFilter::m_bUseOFOSInSum
Gaudi::Property< bool > m_bUseOFOSInSum
Definition: xAODLeptonPairFilter.h:73
xAOD::TruthVertex_v1::nIncomingParticles
size_t nIncomingParticles() const
Get the number of incoming particles.
Definition: TruthVertex_v1.cxx:49
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
xAODLeptonPairFilter::xAODLeptonPairFilter
xAODLeptonPairFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: xAODLeptonPairFilter.cxx:34
xAOD::TruthParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TruthParticle_v1.cxx:166
xAODLeptonPairFilter::m_Ptmin
Gaudi::Property< double > m_Ptmin
Definition: xAODLeptonPairFilter.h:82
xAODLeptonPairFilter::m_bUseOFSSInSum
Gaudi::Property< bool > m_bUseOFSSInSum
Definition: xAODLeptonPairFilter.h:74
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
xAODLeptonPairFilter::m_nLeptons_Max
Gaudi::Property< int > m_nLeptons_Max
Definition: xAODLeptonPairFilter.h:89
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAODLeptonPairFilter::m_nSFSS_Min
Gaudi::Property< int > m_nSFSS_Min
Definition: xAODLeptonPairFilter.h:54
xAODLeptonPairFilter::m_nOFSS_Max
Gaudi::Property< int > m_nOFSS_Max
Definition: xAODLeptonPairFilter.h:61
xAODLeptonPairFilter::~xAODLeptonPairFilter
virtual ~xAODLeptonPairFilter()
Definition: xAODLeptonPairFilter.cxx:39
HepMCHelpers.h
xAODLeptonPairFilter::m_nPairSum_Max
Gaudi::Property< int > m_nPairSum_Max
Definition: xAODLeptonPairFilter.h:66