CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PhotonMonitor.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 
33 
34 class PhotonMonitor : public DQMEDAnalyzer, public TriggerDQMBase {
35 public:
38 
41  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
42 
43 protected:
44  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
45  void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
46 
47 private:
48  const std::string folderName_;
49 
52 
53  edm::EDGetTokenT<reco::PFMETCollection> metToken_;
54  edm::EDGetTokenT<reco::PFJetCollection> jetToken_;
55  edm::EDGetTokenT<reco::GsfElectronCollection> eleToken_;
56  edm::EDGetTokenT<reco::PhotonCollection> photonToken_;
57 
60 
61  MEbinning photon_binning_;
62  MEbinning ls_binning_;
63 
72 
81 
82  double MAX_PHI1 = 3.2;
83  unsigned int N_PHI1 = 64;
84  const MEbinning phi_binning_1{N_PHI1, -MAX_PHI1, MAX_PHI1};
85 
86  double MAX_ETA = 1.4442;
87  unsigned int N_ETA = 34;
88  const MEbinning eta_binning_{N_ETA, -MAX_ETA, MAX_ETA};
89 
90  double MAX_r9 = 1;
91  double MIN_r9 = 0;
92  unsigned int N_r9 = 50;
93  const MEbinning r9_binning_{N_r9, MIN_r9, MAX_r9};
94 
95  double MAX_hoe = 0.02;
96  double MIN_hoe = 0;
97  const MEbinning hoe_binning_{N_r9, MIN_hoe, MAX_hoe};
98 
99  std::unique_ptr<GenericTriggerEventFlag> num_genTriggerEventFlag_;
100  std::unique_ptr<GenericTriggerEventFlag> den_genTriggerEventFlag_;
101 
106  unsigned int njets_;
107  unsigned int nphotons_;
108  unsigned int nelectrons_;
109 };
110 
112  : folderName_(iConfig.getParameter<std::string>("FolderName")),
113  requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
114  hltPathsAreValid_(false),
115  metToken_(consumes<reco::PFMETCollection>(iConfig.getParameter<edm::InputTag>("met"))),
116  jetToken_(mayConsume<reco::PFJetCollection>(iConfig.getParameter<edm::InputTag>("jets"))),
117  eleToken_(mayConsume<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons"))),
118  photonToken_(mayConsume<reco::PhotonCollection>(iConfig.getParameter<edm::InputTag>("photons"))),
119  photon_variable_binning_(
120  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("photonBinning")),
121  diphoton_mass_binning_(
122  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("massBinning")),
123  photon_binning_(getHistoPSet(
124  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("photonPSet"))),
125  ls_binning_(
126  getHistoPSet(iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("lsPSet"))),
128  iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"), consumesCollector(), *this)),
130  iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"), consumesCollector(), *this)),
131  metSelection_(iConfig.getParameter<std::string>("metSelection")),
132  jetSelection_(iConfig.getParameter<std::string>("jetSelection")),
133  eleSelection_(iConfig.getParameter<std::string>("eleSelection")),
134  photonSelection_(iConfig.getParameter<std::string>("photonSelection")),
135  njets_(iConfig.getParameter<unsigned int>("njets")),
136  nphotons_(iConfig.getParameter<unsigned int>("nphotons")),
137  nelectrons_(iConfig.getParameter<unsigned int>("nelectrons")) {}
138 
141  num_genTriggerEventFlag_.reset();
142  }
144  den_genTriggerEventFlag_.reset();
145  }
146 }
147 
148 void PhotonMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
149  // Initialize the GenericTriggerEventFlag
151  num_genTriggerEventFlag_->initRun(iRun, iSetup);
152  }
154  den_genTriggerEventFlag_->initRun(iRun, iSetup);
155  }
156 
157  // check if every HLT path specified in numerator and denominator has a valid match in the HLT Menu
159  den_genTriggerEventFlag_->on() && num_genTriggerEventFlag_->allHLTPathsAreValid() &&
160  den_genTriggerEventFlag_->allHLTPathsAreValid());
161 
162  // if valid HLT paths are required,
163  // create DQM outputs only if all paths are valid
165  return;
166  }
167 
168  std::string histname, histtitle;
169 
170  std::string currentFolder = folderName_;
171  ibooker.setCurrentFolder(currentFolder);
172 
173  histname = "photon_pt";
174  histtitle = "photon PT";
175  bookME(ibooker, photonME_, histname, histtitle, photon_binning_.nbins, photon_binning_.xmin, photon_binning_.xmax);
176  setMETitle(photonME_, "Photon pT [GeV]", "events / [GeV]");
177 
178  histname = "photon_pt_variable";
179  histtitle = "photon PT";
180  bookME(ibooker, photonME_variableBinning_, histname, histtitle, photon_variable_binning_);
181  setMETitle(photonME_variableBinning_, "Photon pT [GeV]", "events / [GeV]");
182 
183  histname = "photonVsLS";
184  histtitle = "photon pt vs LS";
185  bookME(ibooker,
186  photonVsLS_,
187  histname,
188  histtitle,
194  setMETitle(photonVsLS_, "LS", "Photon pT [GeV]");
195 
196  histname = "photon_phi";
197  histtitle = "Photon phi";
198  bookME(ibooker, photonPhiME_, histname, histtitle, phi_binning_1.nbins, phi_binning_1.xmin, phi_binning_1.xmax);
199  setMETitle(photonPhiME_, "Photon #phi", "events / 0.1 rad");
200 
201  histname = "photon_eta";
202  histtitle = "Photon eta";
203  bookME(ibooker, photonEtaME_, histname, histtitle, eta_binning_.nbins, eta_binning_.xmin, eta_binning_.xmax);
204  setMETitle(photonEtaME_, "Photon #eta", "events");
205 
206  histname = "photon_r9";
207  histtitle = "Photon r9";
208  bookME(ibooker, photonr9ME_, histname, histtitle, r9_binning_.nbins, r9_binning_.xmin, r9_binning_.xmax);
209  setMETitle(photonr9ME_, "Photon r9", "events");
210 
211  histname = "photon_hoE";
212  histtitle = "Photon hoverE";
213  bookME(ibooker, photonHoverEME_, histname, histtitle, hoe_binning_.nbins, hoe_binning_.xmin, hoe_binning_.xmax);
214  setMETitle(photonHoverEME_, "Photon hoE", "events");
215 
216  histname = "photon_etaphi";
217  histtitle = "Photon eta-phi";
218  bookME(ibooker,
220  histname,
221  histtitle,
228  setMETitle(photonEtaPhiME_, "#eta", "#phi");
229 
230  // for diphotons
231  if (nphotons_ > 1) {
232  histname = "diphoton_mass";
233  histtitle = "Diphoton mass";
234  bookME(ibooker, diphotonMassME_, histname, histtitle, diphoton_mass_binning_);
235  setMETitle(diphotonMassME_, "Diphoton mass", "events / 0.1");
236 
237  histname = "subphoton_pt";
238  histtitle = "subphoton PT";
239  bookME(
240  ibooker, subphotonME_, histname, histtitle, photon_binning_.nbins, photon_binning_.xmin, photon_binning_.xmax);
241  setMETitle(subphotonME_, "subPhoton pT [GeV]", "events / [GeV]");
242 
243  histname = "subphoton_eta";
244  histtitle = "subPhoton eta";
245  bookME(ibooker, subphotonEtaME_, histname, histtitle, eta_binning_.nbins, eta_binning_.xmin, eta_binning_.xmax);
246  setMETitle(subphotonEtaME_, "subPhoton #eta", "events / 0.1");
247 
248  histname = "subphoton_phi";
249  histtitle = "subPhoton phi";
250  bookME(ibooker, subphotonPhiME_, histname, histtitle, phi_binning_1.nbins, phi_binning_1.xmin, phi_binning_1.xmax);
251  setMETitle(subphotonPhiME_, "subPhoton #phi", "events / 0.1 rad");
252 
253  histname = "subphoton_r9";
254  histtitle = "subPhoton r9";
255  bookME(ibooker, subphotonr9ME_, histname, histtitle, r9_binning_.nbins, r9_binning_.xmin, r9_binning_.xmax);
256  setMETitle(subphotonr9ME_, "subPhoton r9", "events");
257 
258  histname = "subphoton_hoE";
259  histtitle = "subPhoton hoverE";
260  bookME(ibooker, subphotonHoverEME_, histname, histtitle, hoe_binning_.nbins, hoe_binning_.xmin, hoe_binning_.xmax);
261  setMETitle(subphotonHoverEME_, "subPhoton hoE", "events");
262 
263  histname = "subphoton_etaphi";
264  histtitle = "subPhoton eta-phi";
265  bookME(ibooker,
267  histname,
268  histtitle,
275  setMETitle(subphotonEtaPhiME_, "#eta", "#phi");
276  }
277 }
278 
280  // if valid HLT paths are required,
281  // analyze event only if all paths are valid
283  return;
284  }
285 
286  // Filter out events if Trigger Filtering is requested
287  if (den_genTriggerEventFlag_->on() && !den_genTriggerEventFlag_->accept(iEvent, iSetup)) {
288  return;
289  }
290 
292  iEvent.getByToken(metToken_, metHandle);
293  reco::PFMET pfmet = metHandle->front();
294  if (!metSelection_(pfmet))
295  return;
296 
297  //float met = pfmet.pt();
298  // float phi = pfmet.phi();
299 
301  iEvent.getByToken(jetToken_, jetHandle);
302  std::vector<reco::PFJet> jets;
303  jets.clear();
304  if (jetHandle->size() < njets_)
305  return;
306  for (auto const& j : *jetHandle) {
307  if (jetSelection_(j))
308  jets.push_back(j);
309  }
310  if (jets.size() < njets_)
311  return;
312 
314  iEvent.getByToken(eleToken_, eleHandle);
315  std::vector<reco::GsfElectron> electrons;
316  if (eleHandle->size() < nelectrons_)
317  return;
318  for (auto const& e : *eleHandle) {
319  if (eleSelection_(e))
320  electrons.push_back(e);
321  }
322  if (electrons.size() < nelectrons_)
323  return;
324 
326  iEvent.getByToken(photonToken_, photonHandle);
327  std::vector<reco::Photon> photons;
328  photons.clear();
329 
330  if (photonHandle->size() < nphotons_)
331  return;
332  for (auto const& p : *photonHandle) {
333  if (photonSelection_(p))
334  photons.push_back(p);
335  }
336  if (photons.size() < nphotons_)
337  return;
338 
339  // filling histograms (denominator)
340  int ls = iEvent.id().luminosityBlock();
341  if (!(photons.empty()))
342 
343  {
344  photonME_.denominator->Fill(photons[0].pt());
346  photonPhiME_.denominator->Fill(photons[0].phi());
347  photonEtaME_.denominator->Fill(photons[0].eta());
348  photonVsLS_.denominator->Fill(ls, photons[0].pt());
349  photonEtaPhiME_.denominator->Fill(photons[0].eta(), photons[0].phi());
350  photonr9ME_.denominator->Fill(photons[0].r9());
351  photonHoverEME_.denominator->Fill(photons[0].hadTowOverEm());
352  }
353 
354  if (nphotons_ > 1)
355  //filling diphoton histograms
356  {
357  subphotonME_.denominator->Fill(photons[1].pt());
358  subphotonEtaME_.denominator->Fill(photons[1].eta());
359  subphotonPhiME_.denominator->Fill(photons[1].phi());
360  subphotonEtaPhiME_.denominator->Fill(photons[1].eta(), photons[1].phi());
361  subphotonr9ME_.denominator->Fill(photons[1].r9());
362  subphotonHoverEME_.denominator->Fill(photons[1].hadTowOverEm());
364  sqrt(2 * photons[0].pt() * photons[1].pt() *
365  (cosh(photons[0].eta() - photons[1].eta()) - cos(photons[0].phi() - photons[1].phi()))));
366  }
367 
368  // applying selection for numerator
369  if (num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup))
370  return;
371 
372  // filling histograms (num_genTriggerEventFlag_)
373  if (!(photons.empty())) {
374  photonME_.numerator->Fill(photons[0].pt());
376  photonPhiME_.numerator->Fill(photons[0].phi());
377  photonEtaME_.numerator->Fill(photons[0].eta());
378  photonVsLS_.numerator->Fill(ls, photons[0].pt());
379  photonEtaPhiME_.numerator->Fill(photons[0].eta(), photons[0].phi());
380  photonr9ME_.numerator->Fill(photons[0].r9());
381  photonHoverEME_.numerator->Fill(photons[0].hadTowOverEm());
382  }
383  if (nphotons_ > 1)
384  //filling diphoton histograms
385  {
386  subphotonME_.numerator->Fill(photons[1].pt());
387  subphotonEtaME_.numerator->Fill(photons[1].eta());
388  subphotonPhiME_.numerator->Fill(photons[1].phi());
389  subphotonEtaPhiME_.numerator->Fill(photons[1].eta(), photons[1].phi());
390  subphotonr9ME_.numerator->Fill(photons[1].r9());
391  subphotonHoverEME_.numerator->Fill(photons[1].hadTowOverEm());
393  sqrt(2 * photons[0].pt() * photons[1].pt() *
394  (cosh(photons[0].eta() - photons[1].eta()) - cos(photons[0].phi() - photons[1].phi()))));
395  }
396 }
397 
400  desc.add<std::string>("FolderName", "HLT/Photon");
401  desc.add<bool>("requireValidHLTPaths", true);
402 
403  desc.add<edm::InputTag>("met", edm::InputTag("pfMet"));
404  desc.add<edm::InputTag>("jets", edm::InputTag("ak4PFJetsCHS"));
405  desc.add<edm::InputTag>("electrons", edm::InputTag("gedGsfElectrons"));
406  desc.add<edm::InputTag>("photons", edm::InputTag("gedPhotons"));
407  desc.add<std::string>("metSelection", "pt > 0");
408  desc.add<std::string>("jetSelection", "pt > 0");
409  desc.add<std::string>("eleSelection", "pt > 0");
410  desc.add<std::string>(
411  "photonSelection",
412  "pt > 145 && eta<1.4442 && hadTowOverEm<0.0597 && full5x5_sigmaIetaIeta()<0.01031 && chargedHadronIso<1.295");
413  //desc.add<std::string>("photonSelection", "pt > 145");
414  desc.add<unsigned int>("njets", 0);
415  desc.add<unsigned int>("nelectrons", 0);
416  desc.add<unsigned int>("nphotons", 0);
417 
418  edm::ParameterSetDescription genericTriggerEventPSet;
419  GenericTriggerEventFlag::fillPSetDescription(genericTriggerEventPSet);
420  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
421  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
422 
425  fillHistoPSetDescription(metPSet);
426  histoPSet.add<edm::ParameterSetDescription>("photonPSet", metPSet);
427  std::vector<double> bins = {0., 20., 40., 60., 80., 90., 100., 110., 120., 130., 140., 150., 160.,
428  170., 180., 190., 200., 220., 240., 260., 280., 300., 350., 400., 450., 1000.};
429  histoPSet.add<std::vector<double> >("photonBinning", bins);
430  std::vector<double> massbins = {90., 91., 92., 93., 94., 95., 96., 97., 98., 99., 100., 101., 102.,
431  103., 104., 105., 106., 107., 108., 109., 110., 115., 120., 130., 150., 200.};
432  histoPSet.add<std::vector<double> >("massBinning", massbins);
435  histoPSet.add<edm::ParameterSetDescription>("lsPSet", lsPSet);
436 
437  desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
438 
439  descriptions.add("photonMonitoring", desc);
440 }
441 
const MEbinning r9_binning_
unsigned int nelectrons_
const bool requireValidHLTPaths_
dqm::reco::DQMStore DQMStore
StringCutObjectSelector< reco::Photon, true > photonSelection_
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
ObjME subphotonEtaPhiME_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int N_ETA
den_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter< edm::ParameterSet >("denGenericTriggerEventPSet"), consumesCollector(),*this))
eleSelection_(iConfig.getParameter< std::string >("eleSelection"))
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
StringCutObjectSelector< reco::PFJet, true > jetSelection_
def ls
Definition: eostools.py:349
MEbinning ls_binning_
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
ls_binning_(getHistoPSet(iConfig.getParameter< edm::ParameterSet >("histoPSet").getParameter< edm::ParameterSet >("lsPSet")))
const std::string folderName_
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
void setMETitle(ObjME &me, const std::string &titleX, const std::string &titleY)
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
MEbinning photon_binning_
ObjME photonEtaPhiME_
void Fill(long long x)
StringCutObjectSelector< reco::MET, true > metSelection_
int iEvent
Definition: GenABIO.cc:224
unsigned int N_PHI1
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
ObjME subphotonEtaME_
ObjME subphotonr9ME_
ObjME photonME_variableBinning_
#define override(base_class)
edm::EDGetTokenT< reco::PhotonCollection > photonToken_
T sqrt(T t)
Definition: SSEVec.h:19
vector< PseudoJet > jets
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
MonitorElement * denominator
MonitorElement * numerator
ObjME subphotonME_variableBinning_
std::vector< double > diphoton_mass_binning_
njets_(iConfig.getParameter< unsigned int >("njets"))
metSelection_(iConfig.getParameter< std::string >("metSelection"))
edm::EDGetTokenT< reco::PFMETCollection > metToken_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
PhotonMonitor(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
metToken_(consumes< reco::PFMETCollection >(iConfig.getParameter< edm::InputTag >("met")))
num_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter< edm::ParameterSet >("numGenericTriggerEventPSet"), consumesCollector(),*this))
unsigned int N_r9
~PhotonMonitor() override
unsigned int nphotons_
bool hltPathsAreValid_
ObjME diphotonMassME_
StringCutObjectSelector< reco::GsfElectron, true > eleSelection_
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
const MEbinning hoe_binning_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ObjME subphotonHoverEME_
dqm::reco::MonitorElement MonitorElement
void bookME(DQMStore::IBooker &, ObjME &me, const std::string &histname, const std::string &histtitle, const uint nbins, const double xmin, const double xmax, const bool bookDen=true)
edm::EDGetTokenT< reco::PFJetCollection > jetToken_
ObjME photonHoverEME_
edm::EventID id() const
Definition: EventBase.h:59
unsigned int njets_
std::vector< PFJet > PFJetCollection
collection of PFJet objects
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
edm::EDGetTokenT< reco::GsfElectronCollection > eleToken_
std::vector< double > photon_variable_binning_
nphotons_(iConfig.getParameter< unsigned int >("nphotons"))
jetSelection_(iConfig.getParameter< std::string >("jetSelection"))
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
ObjME subphotonPhiME_
static void fillPSetDescription(edm::ParameterSetDescription &desc)
const MEbinning eta_binning_
const MEbinning phi_binning_1
Definition: Run.h:45
nelectrons_(iConfig.getParameter< unsigned int >("nelectrons"))
Collection of PF MET.