ATLAS Offline Software
LeptonPairFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // --------------------------------------------------
6 //
7 // File: GeneratorFilters/src/LeptonPairFilter.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 
23 
24 // Framework Related Headers:-
25 #include "GaudiKernel/MsgStream.h"
26 
27 // Other classes used by this class:-
28 #include <math.h>
29 #include <vector>
30 #include <TLorentzVector.h>
31 
32 //--------------------------------------------------------------------------
34  ISvcLocator* pSvcLocator): GenFilter(name,pSvcLocator) {
35  //--------------------------------------------------------------------------
36  //by default the filter demands that there are exactly 0 SFOS lepton pairs
37  //if both Maximum and Minimum are negative, then no requirements
38  //are made on that pair type
39 
40  //Same-Flavor Opposite-Sign (SFOS)
41  declareProperty("NSFOS_Max", m_nSFOS_Max = 0);
42  declareProperty("NSFOS_Min", m_nSFOS_Min = 0);
43 
44  //Same-Flavor Same-Sign (SFSS)
45  declareProperty("NSFSS_Max", m_nSFSS_Max = -1);
46  declareProperty("NSFSS_Min", m_nSFSS_Min = -1);
47 
48  //Opposite-Flavor Opposite-Sign (OFOS)
49  declareProperty("NOFOS_Max", m_nOFOS_Max = -1);
50  declareProperty("NOFOS_Min", m_nOFOS_Min = -1);
51 
52  //Opposite-Flavor Same-Sign (OFSS)
53  declareProperty("NOFSS_Max", m_nOFSS_Max = -1);
54  declareProperty("NOFSS_Min", m_nOFSS_Min = -1);
55 
56  //Pair Sum (ask for some combination of different
57  //lepton pairs based on configuration)
58  declareProperty("NPairSum_Max", m_nPairSum_Max = -1);
59  declareProperty("NPairSum_Min", m_nPairSum_Min = -1);
60 
61  //configure which pairs to consider in sum
62  //by default don't consider any
63  declareProperty("UseSFOSInSum",m_bUseSFOSInSum = false);
64  declareProperty("UseSFSSInSum",m_bUseSFSSInSum = false);
65  declareProperty("UseOFOSInSum",m_bUseOFOSInSum = false);
66  declareProperty("UseOFSSInSum",m_bUseOFSSInSum = false);
67 
68  // only count leptons with a parent with M>20 GeV
69  declareProperty("OnlyMassiveParents",m_onlyMassiveParents = false);
70 
71  //kinematic requirements on leptons to consider
72  //this is NOT a veto on the leptons outside the requirements
73  declareProperty("Ptcut",m_Ptmin = 10000.);
74  declareProperty("Etacut",m_EtaRange = 10.0);
75 
76  //the filter is only applied if the
77  //if the number of leptons falls within this range
78  //otherwise the filter automatically passes
79  //if max < 0 it is ignored
80  declareProperty("NLeptons_Max",m_nLeptons_Max = -1);
81  declareProperty("NLeptons_Min",m_nLeptons_Min = 0);
82 }
83 
84 //--------------------------------------------------------------------------
86 //--------------------------------------------------------------------------
87 
88 }
89 
90 //---------------------------------------------------------------------------
92 //---------------------------------------------------------------------------
93  return StatusCode::SUCCESS;
94 }
95 
96 //---------------------------------------------------------------------------
98 //---------------------------------------------------------------------------
99  return StatusCode::SUCCESS;
100 }
101 
102 
103 //---------------------------------------------------------------------------
105 //---------------------------------------------------------------------------
106 
107  // Loop over all events in McEventCollection
108  std::vector<int> vLeptonPDGIDs;
109  std::vector<double> vLeptonPt;
110  std::vector<double> vLeptonEta;
111  std::vector< std::vector < int > > vLeptonParentPDGIDs;
113  for (itr = events()->begin(); itr!=events()->end(); ++itr) {
114  // Loop over all particles in the event
115  const HepMC::GenEvent* genEvt = (*itr);
116 #ifdef HEPMC3
117  for(const auto& pitr: genEvt->particles()) {
118  if( !MC::isStable(pitr) ) continue;
119  // check stable particles only
120  // We do not place requirements on their origins (updated: optionally rejecting hadron decays)
121  // save pdg ids of found leptons
122  // do not consider taus
123  if( std::abs(pitr->pdg_id()) != 11 && std::abs(pitr->pdg_id()) != 13) continue;
124  //only consider leptons which satisfy pt and eta requirements
125  if( (pitr->momentum().perp() < m_Ptmin) || std::abs(pitr->momentum().pseudoRapidity()) > m_EtaRange) continue;
127  {
128  auto p = pitr;
129  bool massiveParent = false;
130  while(p)
131  {
132  auto vxp = p->production_vertex();
133  if(!vxp) break;
134  if(vxp->particles_in().size()!=1) break;
135  p = vxp->particles_in().at(0);
136  const int pdg = std::abs(p->pdg_id());
137  if(!((pdg>=11 && pdg<=16) || pdg==22))
138  {
139  massiveParent = (p->generated_mass()>20000);
140  break;
141  }
142  }
143  if(!massiveParent) continue;
144  }
145  vLeptonPDGIDs.push_back(pitr->pdg_id());
146  vLeptonPt.push_back(pitr->momentum().perp());
147  vLeptonEta.push_back(pitr->momentum().pseudoRapidity());
148 
149  std::vector<int> parentPDG_tmp;
150  for (auto thisParent: pitr->production_vertex()->particles_in()) parentPDG_tmp.push_back(thisParent->pdg_id());
151  vLeptonParentPDGIDs.push_back(parentPDG_tmp);
152  }
153 #else
154  for(HepMC::GenEvent::particle_const_iterator pitr=genEvt->particles_begin();
155  pitr!=genEvt->particles_end(); ++pitr )
156  if( MC::isStable(*pitr) )
157  // check stable particles only
158  // We do not place requirements on their origins (updated: optionally rejecting hadron decays)
159  // save pdg ids of found leptons
160  // do not consider taus
161  {
162  if( MC::isElectron(*pitr) || MC::isMuon(*pitr) ){
163  //only consider leptons which satisfy pt and eta requirements
164  if( ((*pitr)->momentum().perp() >= m_Ptmin) && std::abs((*pitr)->momentum().pseudoRapidity()) <=m_EtaRange){
166  {
167  auto p = *pitr;
168  bool massiveParent = false;
169  while(p)
170  {
171  auto vxp = p->production_vertex();
172  if(!vxp) break;
173  if(vxp->particles_in_size()!=1) break;
174  p = *vxp->particles_in_const_begin();
175  if(!MC::isSMLepton(p) || MC::isPhoton(p))
176  {
177  massiveParent = (p->generated_mass()>20000);
178  break;
179  }
180  }
181  if(!massiveParent) continue;
182  }
183  vLeptonPDGIDs.push_back((*pitr)->pdg_id());
184  vLeptonPt.push_back((*pitr)->momentum().perp());
185  vLeptonEta.push_back((*pitr)->momentum().pseudoRapidity());
186  HepMC::GenVertex::particle_iterator firstParent =
187  (*pitr)->production_vertex()->particles_begin(HepMC::parents);
188  HepMC::GenVertex::particle_iterator endParent =
189  (*pitr)->production_vertex()->particles_end(HepMC::parents);
190  HepMC::GenVertex::particle_iterator thisParent = firstParent;
191  std::vector<int> parentPDG_tmp;
192  for(; thisParent != endParent; ++thisParent) parentPDG_tmp.push_back((*thisParent)->pdg_id());
193 
194  vLeptonParentPDGIDs.push_back(parentPDG_tmp);
195  }
196  }//end if pdg_id
197  }
198 #endif
199  }//end loop over collections
200 
201  int nLeptons = vLeptonPDGIDs.size();
202 
203  //Filter automatically passes if number of leptons is different than expected
204  if (!( (nLeptons >= m_nLeptons_Min) &&
205  (m_nLeptons_Max < 0 || nLeptons <= m_nLeptons_Max) )) {
206  ATH_MSG_INFO("# Lep = "<<nLeptons << " Pass" );
207  return StatusCode::SUCCESS;
208  }
209 
210  int nSFOS = 0;
211  int nSFSS = 0;
212  int nOFOS = 0;
213  int nOFSS = 0;
214 
215  int id1 = 0;
216  int id2 = 0;
217  //loop over all possible pair combinations of the leptons
218  //which were found.
219  for (unsigned int i = 0 ; i < vLeptonPDGIDs.size() ; i++){
220  //don't double count
221  for (unsigned int j = i ; j < vLeptonPDGIDs.size() ; j++){
222  //Do not compare the lepton with itself
223  if(i==j) continue;
224  id1 = vLeptonPDGIDs[i];
225  id2 = vLeptonPDGIDs[j];
226  //classify the pair and count it
227  if(std::abs(id1)==std::abs(id2) && id1*id2 < 0) nSFOS+=1;
228  else if(std::abs(id1)==std::abs(id2) && id1*id2 > 0) nSFSS+=1;
229  else if(std::abs(id1)!=std::abs(id2) && id1*id2 < 0) nOFOS+=1;
230  else if(std::abs(id1)!=std::abs(id2) && id1*id2 > 0) nOFSS+=1;
231  else ATH_MSG_ERROR( "Couldn't classify lepton pair" );
232  }
233  }
234 
235  //based on configuration
236  //create sum of multiple pair combinations
237  //which can alternatively be cut on instead
238  //of the individual ones
239  int nPairSum = 0;
240  if(m_bUseSFOSInSum) nPairSum+=nSFOS;
241  if(m_bUseSFSSInSum) nPairSum+=nSFSS;
242  if(m_bUseOFOSInSum) nPairSum+=nOFOS;
243  if(m_bUseOFSSInSum) nPairSum+=nOFSS;
244 
245 
246  bool passSFOS = false;
247  bool passSFSS = false;
248  bool passOFOS = false;
249  bool passOFSS = false;
250  bool passPairSum = false;
251  //Test if number of lepton pairs satisfies requirements
252  //The maximum requirement is ignored if it is negative
253  //No requirement is made if both min and max values are negative
254  ATH_MSG_INFO("# Lep " << vLeptonPDGIDs.size() << ", "<< nSFOS << " SFOS, "<<nSFSS<< " SFSS, " << nOFOS << " OFOS, " << nOFSS << " OFSS pairs ," << nPairSum << "summed pairs" );
255 
256  if(nSFOS >= m_nSFOS_Min && (m_nSFOS_Max<0 || nSFOS <= m_nSFOS_Max)) passSFOS=true;
257  if(nSFSS >= m_nSFSS_Min && (m_nSFSS_Max<0 || nSFSS <= m_nSFSS_Max)) passSFSS=true;
258  if(nOFOS >= m_nOFOS_Min && (m_nOFOS_Max<0 || nOFOS <= m_nOFOS_Max)) passOFOS=true;
259  if(nOFSS >= m_nOFSS_Min && (m_nOFSS_Max<0 || nOFSS <= m_nOFSS_Max)) passOFSS=true;
260  if(nPairSum >= m_nPairSum_Min && (m_nPairSum_Max<0 || nPairSum <= m_nPairSum_Max)) passPairSum=true;
261 
262  if(passSFOS && passSFSS && passOFOS && passOFSS && passPairSum){
263  ATH_MSG_INFO("Pass" );
264  for (unsigned int i = 0;i<vLeptonPDGIDs.size();i++){
265  int pdg = vLeptonPDGIDs[i];
266  double pt = vLeptonPt[i];
267  double eta = vLeptonEta[i];
268  msg(MSG::DEBUG) << pdg << ": Pt = "<<pt<<", Eta = "<<eta << ", Parent PDG: ";
269  for (unsigned int j=0;j<vLeptonParentPDGIDs[i].size();j++) msg(MSG::DEBUG) << vLeptonParentPDGIDs[i][j];
270  msg(MSG::DEBUG) << endmsg;
271  }
272  return StatusCode::SUCCESS;
273  }
274 
275  // if we get here we have failed
276  setFilterPassed(false);
277  ATH_MSG_INFO("Fail" );
278  return StatusCode::SUCCESS;
279 }
LeptonPairFilter::m_nOFOS_Min
int m_nOFOS_Min
Definition: LeptonPairFilter.h:44
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LeptonPairFilter::m_bUseSFSSInSum
bool m_bUseSFSSInSum
Definition: LeptonPairFilter.h:51
LeptonPairFilter::m_onlyMassiveParents
bool m_onlyMassiveParents
Definition: LeptonPairFilter.h:49
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
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
LeptonPairFilter::m_nSFOS_Max
int m_nSFOS_Max
Definition: LeptonPairFilter.h:39
LeptonPairFilter::filterFinalize
virtual StatusCode filterFinalize()
Definition: LeptonPairFilter.cxx:97
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
test_pyathena.pt
pt
Definition: test_pyathena.py:11
LeptonPairFilter::m_Ptmin
double m_Ptmin
Definition: LeptonPairFilter.h:54
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
isSMLepton
bool isSMLepton(const T &p)
Definition: AtlasPID.h:134
LeptonPairFilter::m_nOFOS_Max
int m_nOFOS_Max
Definition: LeptonPairFilter.h:43
LeptonPairFilter::LeptonPairFilter
LeptonPairFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LeptonPairFilter.cxx:33
LeptonPairFilter::m_nLeptons_Max
int m_nLeptons_Max
Definition: LeptonPairFilter.h:56
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
LeptonPairFilter::~LeptonPairFilter
virtual ~LeptonPairFilter()
Definition: LeptonPairFilter.cxx:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LeptonPairFilter::m_bUseSFOSInSum
bool m_bUseSFOSInSum
Definition: LeptonPairFilter.h:50
id2
HWIdentifier id2
Definition: LArRodBlockPhysicsV0.cxx:564
lumiFormat.i
int i
Definition: lumiFormat.py:92
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::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
LeptonPairFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: LeptonPairFilter.cxx:91
LeptonPairFilter::m_nPairSum_Min
int m_nPairSum_Min
Definition: LeptonPairFilter.h:48
LeptonPairFilter::m_nLeptons_Min
int m_nLeptons_Min
Definition: LeptonPairFilter.h:57
LeptonPairFilter::m_nPairSum_Max
int m_nPairSum_Max
Definition: LeptonPairFilter.h:47
LeptonPairFilter::filterEvent
virtual StatusCode filterEvent()
Definition: LeptonPairFilter.cxx:104
LeptonPairFilter::m_bUseOFSSInSum
bool m_bUseOFSSInSum
Definition: LeptonPairFilter.h:53
LeptonPairFilter::m_nSFOS_Min
int m_nSFOS_Min
Definition: LeptonPairFilter.h:40
LeptonPairFilter::m_nSFSS_Min
int m_nSFSS_Min
Definition: LeptonPairFilter.h:42
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LeptonPairFilter.h
LeptonPairFilter::m_nOFSS_Max
int m_nOFSS_Max
Definition: LeptonPairFilter.h:45
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
LeptonPairFilter::m_nOFSS_Min
int m_nOFSS_Min
Definition: LeptonPairFilter.h:46
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LeptonPairFilter::m_bUseOFOSInSum
bool m_bUseOFOSInSum
Definition: LeptonPairFilter.h:52
LeptonPairFilter::m_nSFSS_Max
int m_nSFSS_Max
Definition: LeptonPairFilter.h:41
LeptonPairFilter::m_EtaRange
double m_EtaRange
Definition: LeptonPairFilter.h:55
HepMCHelpers.h
isMuon
bool isMuon(const T &p)
Definition: AtlasPID.h:145