ATLAS Offline Software
DiPhotonFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include <vector>
8 #include "TMath.h"
9 
10 // Pt High --> Low
13 public:
15  return t1->momentum().perp2() > t2->momentum().perp2();
16  }
17 };
18 
19 
20 DiPhotonFilter::DiPhotonFilter(const std::string& name, ISvcLocator* pSvcLocator)
21  : GenFilter(name, pSvcLocator)
22 {
23  declareProperty("PtCut1st",m_Ptmin_1st = 20000.);
24  declareProperty("PtCut2nd",m_Ptmin_2nd = 15000.);
25  declareProperty("PtCutOthers",m_Ptmin_others = 15000.);
26  declareProperty("EtaCut1st",m_EtaRange_1st = 2.50);
27  declareProperty("EtaCut2nd",m_EtaRange_2nd = 2.50);
28  declareProperty("EtaCutOthers",m_EtaRange_others = 2.50);
29  declareProperty("DeltaRCutFrom",m_diphoton_deltaRmin = -1.);
30  declareProperty("DeltaRCutTo",m_diphoton_deltaRmax = -1.);
31  declareProperty("MassCutFrom",m_diphoton_massmin = -1.);
32  declareProperty("MassCutTo",m_diphoton_massmax = -1.);
33  declareProperty("Use1st2ndPhotons",m_use1st2ndPhotonsforMassAndDeltaRCuts = false);
34 }
35 
36 
38  ATH_MSG_INFO("*** filter condition ***");
39  ATH_MSG_INFO("At least two photons must be in an event.");
40  ATH_MSG_INFO("PtCut for the 1st photon = " << m_Ptmin_1st << " (CLHEP::MeV)");
41  ATH_MSG_INFO("PtCut for the 2nd photon = " << m_Ptmin_2nd << " (CLHEP::MeV)");
42  ATH_MSG_INFO("PtCut for other photons = " << m_Ptmin_others << " (CLHEP::MeV)");
43  ATH_MSG_INFO("EtaCut for the 1st photon = " << m_EtaRange_1st);
44  ATH_MSG_INFO("EtaCut for the 2nd photon = " << m_EtaRange_2nd);
45  ATH_MSG_INFO("EtaCut for other photons = " << m_EtaRange_others);
46  ATH_MSG_INFO("DeltaRCut(min) = " << m_diphoton_deltaRmin);
47  ATH_MSG_INFO("DeltaRCut(max) = " << m_diphoton_deltaRmax);
48  ATH_MSG_INFO("MassCut(min) = " << m_diphoton_massmin << " (CLHEP::MeV)");
49  ATH_MSG_INFO("MassCut(max) = " << m_diphoton_massmax << " (CLHEP::MeV)");
50  ATH_MSG_INFO(" negative value on MassCut(min,max) -> no limit in the cut");
51  ATH_MSG_INFO("Use only the 1st and the 2nd photons for mass and deltaR cuts, flag = " << m_use1st2ndPhotonsforMassAndDeltaRCuts);
52  return StatusCode::SUCCESS;
53 }
54 
55 
57  // get min pt
60 
61  ATH_MSG_DEBUG("min pt(photon) = " << ptcut << " (CLHEP::MeV)");
62 
63  // find truth photons
64  std::vector<HepMC::ConstGenParticlePtr> MCTruthPhotonList;
66  for (itr = events()->begin(); itr!=events()->end(); ++itr) {
67  // Loop over all particles in the event
68  const HepMC::GenEvent* genEvt = (*itr);
69  for (const auto& part: *genEvt) {
70  if ( MC::isPhoton(part) ) {
71  if ( MC::isStable(part) && (part->momentum().perp() >= ptcut) ) {
72  MCTruthPhotonList.push_back(part);
73  }
74  }
75  }
76  }
77 
78  // sort truth photons with pT
79  std::sort(MCTruthPhotonList.begin(), MCTruthPhotonList.end(), High2LowByGenParticleClassPt());
80 
81  // check conditions
82  bool isOK = true;
83  ATH_MSG_DEBUG("# of truth photons = " << MCTruthPhotonList.size());
84  if (MCTruthPhotonList.size() < 2) {
85  isOK = false;
86  } else {
87  std::vector<HepMC::ConstGenParticlePtr> MCTruthPhotonList2;
88  // check pT and eta to select truth photons
89  for (size_t i = 0; i < MCTruthPhotonList.size(); ++i) {
90  ATH_MSG_DEBUG(i << ": pT=" << MCTruthPhotonList[i]->momentum().perp() << ", eta=" << MCTruthPhotonList[i]->momentum().pseudoRapidity());
91  double ptmin = m_Ptmin_others;
92  double etamax = m_EtaRange_others;
93  if (MCTruthPhotonList2.size() == 0) {
95  etamax = m_EtaRange_1st;
96  } else if (MCTruthPhotonList2.size() == 1) {
98  etamax = m_EtaRange_2nd;
99  }
100  if (MCTruthPhotonList[i]->momentum().perp() >= ptmin &&
101  std::abs(MCTruthPhotonList[i]->momentum().pseudoRapidity()) <= etamax) {
102  MCTruthPhotonList2.push_back(MCTruthPhotonList[i]);
103  }
104  }
105  ATH_MSG_DEBUG("# of truth photons after pT and eta cut = " << MCTruthPhotonList2.size());
106 
107  if (MCTruthPhotonList2.size() < 2) {
108  isOK = false;
109  } else {
110  int nGood = 0;
112  double sumPx = MCTruthPhotonList2[0]->momentum().px()+MCTruthPhotonList2[1]->momentum().px();
113  double sumPy = MCTruthPhotonList2[0]->momentum().py()+MCTruthPhotonList2[1]->momentum().py();
114  double sumPz = MCTruthPhotonList2[0]->momentum().pz()+MCTruthPhotonList2[1]->momentum().pz();
115  double sumE = MCTruthPhotonList2[0]->momentum().e() +MCTruthPhotonList2[1]->momentum().e();
116  double m2 = sumE*sumE-(sumPx*sumPx+sumPy*sumPy+sumPz*sumPz);
117  double mGamGam = m2 >= 0. ? std::sqrt(m2) : -std::sqrt(-m2);
118  ATH_MSG_DEBUG("mass(gamgam) = " << mGamGam << " (CLHEP::MeV)");
119  double deltaEta = MCTruthPhotonList2[0]->momentum().pseudoRapidity() - MCTruthPhotonList2[1]->momentum().pseudoRapidity();
120  double deltaPhi = MCTruthPhotonList2[0]->momentum().phi() - MCTruthPhotonList2[1]->momentum().phi();
121  double deltaR = std::sqrt(deltaEta*deltaEta+deltaPhi*deltaPhi);
122  ATH_MSG_DEBUG("deltaR(gamgam) = " << deltaR);
123  int testMassDeltaRCuts = 0;
124  //check mass
125  if (m_diphoton_massmin >= 0. && m_diphoton_massmax >= 0.) {
126  if (mGamGam >= m_diphoton_massmin && mGamGam <= m_diphoton_massmax) ++testMassDeltaRCuts;
127  } else if (m_diphoton_massmin >= 0. && m_diphoton_massmax < 0.) {
128  if (mGamGam >= m_diphoton_massmin) ++testMassDeltaRCuts;
129  } else if (m_diphoton_massmin < 0. && m_diphoton_massmax >= 0.) {
130  if (mGamGam <= m_diphoton_massmax) ++testMassDeltaRCuts;
131  } else {
132  ++testMassDeltaRCuts;
133  }
134  // check deltaR
135  if (m_diphoton_deltaRmin >= 0. && m_diphoton_deltaRmax >= 0.) {
136  if (deltaR >= m_diphoton_deltaRmin && deltaR <= m_diphoton_deltaRmax) ++testMassDeltaRCuts;
137  } else if (m_diphoton_deltaRmin >= 0. && m_diphoton_deltaRmax < 0.) {
138  if (deltaR >= m_diphoton_deltaRmin) ++testMassDeltaRCuts;
139  } else if (m_diphoton_deltaRmin < 0. && m_diphoton_deltaRmax >= 0.) {
140  if (deltaR <= m_diphoton_deltaRmax) ++testMassDeltaRCuts;
141  } else {
142  ++testMassDeltaRCuts;
143  }
144  // count pairs
145  if (testMassDeltaRCuts == 2) ++nGood;
146  } else {
147  for (size_t i=0;i<MCTruthPhotonList2.size()-1;++i) {
148  for (size_t j=i+1;j<MCTruthPhotonList2.size();++j) {
149  double sumPx = MCTruthPhotonList2[i]->momentum().px()+MCTruthPhotonList2[j]->momentum().px();
150  double sumPy = MCTruthPhotonList2[i]->momentum().py()+MCTruthPhotonList2[j]->momentum().py();
151  double sumPz = MCTruthPhotonList2[i]->momentum().pz()+MCTruthPhotonList2[j]->momentum().pz();
152  double sumE = MCTruthPhotonList2[i]->momentum().e() +MCTruthPhotonList2[j]->momentum().e();
153  double m2 = sumE*sumE-(sumPx*sumPx+sumPy*sumPy+sumPz*sumPz);
154  double mGamGam = m2 >= 0. ? std::sqrt(m2) : -std::sqrt(-m2);
155  ATH_MSG_DEBUG("mass(gamgam) = " << mGamGam << " (CLHEP::MeV)");
156  double deltaEta = MCTruthPhotonList2[i]->momentum().pseudoRapidity() - MCTruthPhotonList2[j]->momentum().pseudoRapidity();
157  double deltaPhi = MCTruthPhotonList2[i]->momentum().phi() - MCTruthPhotonList2[j]->momentum().phi();
158  double deltaR = std::sqrt(deltaEta*deltaEta+deltaPhi*deltaPhi);
159  ATH_MSG_DEBUG("deltaR(gamgam) = " << deltaR);
160  int testMassDeltaRCuts = 0;
161  // check mass
162  if (m_diphoton_massmin >= 0. && m_diphoton_massmax >= 0.) {
163  if (mGamGam >= m_diphoton_massmin && mGamGam <= m_diphoton_massmax) ++testMassDeltaRCuts;
164  } else if (m_diphoton_massmin >= 0. && m_diphoton_massmax < 0.) {
165  if (mGamGam >= m_diphoton_massmin) ++testMassDeltaRCuts;
166  } else if (m_diphoton_massmin < 0. && m_diphoton_massmax >= 0.) {
167  if (mGamGam <= m_diphoton_massmax) ++testMassDeltaRCuts;
168  } else {
169  ++testMassDeltaRCuts;
170  }
171  // check deltaR
172  if (m_diphoton_deltaRmin >= 0. && m_diphoton_deltaRmax >= 0.) {
173  if (deltaR >= m_diphoton_deltaRmin && deltaR <= m_diphoton_deltaRmax) ++testMassDeltaRCuts;
174  } else if (m_diphoton_deltaRmin >= 0. && m_diphoton_deltaRmax < 0.) {
175  if (deltaR >= m_diphoton_deltaRmin) ++testMassDeltaRCuts;
176  } else if (m_diphoton_deltaRmin < 0. && m_diphoton_deltaRmax >= 0.) {
177  if (deltaR <= m_diphoton_deltaRmax) ++testMassDeltaRCuts;
178  } else {
179  ++testMassDeltaRCuts;
180  }
181  // count pairs
182  if (testMassDeltaRCuts == 2) ++nGood;
183  }
184  }
185  }
186 
187  ATH_MSG_DEBUG("# of good photon pair = " << nGood);
188  if (nGood == 0) isOK = false;
189  }
190  }
191 
192  ATH_MSG_DEBUG("flag(final decision) = " << isOK);
193  setFilterPassed(isOK);
194  return StatusCode::SUCCESS;
195 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.SystemOfUnits.m2
int m2
Definition: SystemOfUnits.py:92
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DiPhotonFilter.h
perp
Scalar perp() const
perp method - perpenticular length
Definition: AmgMatrixBasePlugin.h:35
DiPhotonFilter::m_EtaRange_2nd
double m_EtaRange_2nd
Definition: DiPhotonFilter.h:24
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
TrigJetMonitorAlgorithm.ptmin
ptmin
Definition: TrigJetMonitorAlgorithm.py:1081
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
Pythia8_A14_NNPDF23LO_forMGHT_EvtGen.ptcut
float ptcut
Definition: Pythia8_A14_NNPDF23LO_forMGHT_EvtGen.py:9
DiPhotonFilter::m_diphoton_massmin
double m_diphoton_massmin
Definition: DiPhotonFilter.h:29
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
P4Helpers::deltaEta
double deltaEta(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition: P4Helpers.h:53
lumiFormat.i
int i
Definition: lumiFormat.py:92
DiPhotonFilter::DiPhotonFilter
DiPhotonFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: DiPhotonFilter.cxx:20
DiPhotonFilter::m_diphoton_massmax
double m_diphoton_massmax
Definition: DiPhotonFilter.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
DiPhotonFilter::m_use1st2ndPhotonsforMassAndDeltaRCuts
bool m_use1st2ndPhotonsforMassAndDeltaRCuts
Definition: DiPhotonFilter.h:31
DiPhotonFilter::m_Ptmin_2nd
double m_Ptmin_2nd
Definition: DiPhotonFilter.h:23
High2LowByGenParticleClassPt
Definition: DiPhotonFilter.cxx:12
python.compareNtuple.nGood
nGood
Definition: compareNtuple.py:55
HepMC::ConstGenParticlePtr
const GenParticle * ConstGenParticlePtr
Definition: GenParticle.h:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DiPhotonFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: DiPhotonFilter.cxx:37
DiPhotonFilter::filterEvent
virtual StatusCode filterEvent()
Definition: DiPhotonFilter.cxx:56
DiPhotonFilter::m_EtaRange_1st
double m_EtaRange_1st
Definition: DiPhotonFilter.h:22
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
DiPhotonFilter::m_Ptmin_others
double m_Ptmin_others
Definition: DiPhotonFilter.h:25
DiPhotonFilter::m_EtaRange_others
double m_EtaRange_others
Definition: DiPhotonFilter.h:26
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
DiPhotonFilter::m_diphoton_deltaRmin
double m_diphoton_deltaRmin
Definition: DiPhotonFilter.h:27
High2LowByGenParticleClassPt::operator()
bool operator()(const HepMC::ConstGenParticlePtr &t1, const HepMC::ConstGenParticlePtr &t2) const
Definition: DiPhotonFilter.cxx:14
DiPhotonFilter::m_diphoton_deltaRmax
double m_diphoton_deltaRmax
Definition: DiPhotonFilter.h:28
makeComparison.deltaR
float deltaR
Definition: makeComparison.py:36
DiPhotonFilter::m_Ptmin_1st
double m_Ptmin_1st
Definition: DiPhotonFilter.h:21
HepMCHelpers.h