CMS 3D CMS Logo

METMonitor.cc
Go to the documentation of this file.
2 
4 
6 
8 
10 
11 // -----------------------------
12 // constructors and destructor
13 // -----------------------------
14 
16  : folderName_(iConfig.getParameter<std::string>("FolderName")),
17  metInputTag_(iConfig.getParameter<edm::InputTag>("met")),
18  jetInputTag_(iConfig.getParameter<edm::InputTag>("jets")),
19  eleInputTag_(iConfig.getParameter<edm::InputTag>("electrons")),
20  muoInputTag_(iConfig.getParameter<edm::InputTag>("muons")),
21  vtxInputTag_(iConfig.getParameter<edm::InputTag>("vertices")),
22  metToken_(consumes<reco::PFMETCollection>(metInputTag_)),
23  jetToken_(mayConsume<reco::PFJetCollection>(jetInputTag_)),
24  eleToken_(mayConsume<reco::GsfElectronCollection>(eleInputTag_)),
25  muoToken_(mayConsume<reco::MuonCollection>(muoInputTag_)),
26  vtxToken_(mayConsume<reco::VertexCollection>(vtxInputTag_)),
27  met_variable_binning_(
28  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("metBinning")),
29  met_binning_(getHistoPSet(
30  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("metPSet"))),
31  ls_binning_(
32  getHistoPSet(iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("lsPSet"))),
33  num_genTriggerEventFlag_(new GenericTriggerEventFlag(
34  iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"), consumesCollector(), *this)),
35  den_genTriggerEventFlag_(new GenericTriggerEventFlag(
36  iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"), consumesCollector(), *this)),
37  metSelection_(iConfig.getParameter<std::string>("metSelection")),
38  jetSelection_(iConfig.getParameter<std::string>("jetSelection")),
39  eleSelection_(iConfig.getParameter<std::string>("eleSelection")),
40  muoSelection_(iConfig.getParameter<std::string>("muoSelection")),
41  njets_(iConfig.getParameter<unsigned>("njets")),
42  nelectrons_(iConfig.getParameter<unsigned>("nelectrons")),
43  nmuons_(iConfig.getParameter<unsigned>("nmuons")) {
44  // this vector has to be alligned to the the number of Tokens accessed by this module
45  warningPrinted4token_.push_back(false); // PFMETCollection
46  warningPrinted4token_.push_back(false); // JetCollection
47  warningPrinted4token_.push_back(false); // GsfElectronCollection
48  warningPrinted4token_.push_back(false); // MuonCollection
49  warningPrinted4token_.push_back(false); // VertexCollection
50 }
51 
52 METMonitor::~METMonitor() = default;
53 
55  return METMonitor::MEbinning{
56  pset.getParameter<unsigned>("nbins"),
57  pset.getParameter<double>("xmin"),
58  pset.getParameter<double>("xmax"),
59  };
60 }
61 
63  return METMonitor::MEbinning{pset.getParameter<unsigned>("nbins"), 0., double(pset.getParameter<unsigned>("nbins"))};
64 }
65 
66 void METMonitor::setMETitle(METME& me, const std::string& titleX, const std::string& titleY) {
67  me.numerator->setAxisTitle(titleX, 1);
68  me.numerator->setAxisTitle(titleY, 2);
69  me.denominator->setAxisTitle(titleX, 1);
70  me.denominator->setAxisTitle(titleY, 2);
71 }
72 
74  METME& me,
75  const std::string& histname,
76  const std::string& histtitle,
77  int nbins,
78  double min,
79  double max) {
80  me.numerator = ibooker.book1D(histname + "_numerator", histtitle + " (numerator)", nbins, min, max);
81  me.denominator = ibooker.book1D(histname + "_denominator", histtitle + " (denominator)", nbins, min, max);
82 }
84  METME& me,
85  const std::string& histname,
86  const std::string& histtitle,
87  const std::vector<double>& binning) {
88  int nbins = binning.size() - 1;
89  std::vector<float> fbinning(binning.begin(), binning.end());
90  float* arr = &fbinning[0];
91  me.numerator = ibooker.book1D(histname + "_numerator", histtitle + " (numerator)", nbins, arr);
92  me.denominator = ibooker.book1D(histname + "_denominator", histtitle + " (denominator)", nbins, arr);
93 }
95  METME& me,
96  const std::string& histname,
97  const std::string& histtitle,
98  int nbinsX,
99  double xmin,
100  double xmax,
101  double ymin,
102  double ymax) {
103  me.numerator =
104  ibooker.bookProfile(histname + "_numerator", histtitle + " (numerator)", nbinsX, xmin, xmax, ymin, ymax);
105  me.denominator =
106  ibooker.bookProfile(histname + "_denominator", histtitle + " (denominator)", nbinsX, xmin, xmax, ymin, ymax);
107 }
109  METME& me,
110  const std::string& histname,
111  const std::string& histtitle,
112  int nbinsX,
113  double xmin,
114  double xmax,
115  int nbinsY,
116  double ymin,
117  double ymax) {
118  me.numerator =
119  ibooker.book2D(histname + "_numerator", histtitle + " (numerator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
120  me.denominator =
121  ibooker.book2D(histname + "_denominator", histtitle + " (denominator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
122 }
124  METME& me,
125  const std::string& histname,
126  const std::string& histtitle,
127  const std::vector<double>& binningX,
128  const std::vector<double>& binningY) {
129  int nbinsX = binningX.size() - 1;
130  std::vector<float> fbinningX(binningX.begin(), binningX.end());
131  float* arrX = &fbinningX[0];
132  int nbinsY = binningY.size() - 1;
133  std::vector<float> fbinningY(binningY.begin(), binningY.end());
134  float* arrY = &fbinningY[0];
135 
136  me.numerator = ibooker.book2D(histname + "_numerator", histtitle + " (numerator)", nbinsX, arrX, nbinsY, arrY);
137  me.denominator = ibooker.book2D(histname + "_denominator", histtitle + " (denominator)", nbinsX, arrX, nbinsY, arrY);
138 }
139 
140 void METMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
141  std::string histname, histtitle;
142 
143  std::string currentFolder = folderName_;
144  ibooker.setCurrentFolder(currentFolder);
145 
146  histname = "deltaphi_metjet1";
147  histtitle = "DPHI_METJ1";
148  bookME(ibooker, deltaphimetj1ME_, histname, histtitle, phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
149  setMETitle(deltaphimetj1ME_, "delta phi (met, j1)", "events / 0.1 rad");
150 
151  histname = "deltaphi_jet1jet2";
152  histtitle = "DPHI_J1J2";
153  bookME(ibooker, deltaphij1j2ME_, histname, histtitle, phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
154  setMETitle(deltaphij1j2ME_, "delta phi (j1, j2)", "events / 0.1 rad");
155 
156  histname = "met";
157  histtitle = "PFMET";
158  bookME(ibooker, metME_, histname, histtitle, met_binning_.nbins, met_binning_.xmin, met_binning_.xmax);
159  setMETitle(metME_, "PF MET [GeV]", "events / [GeV]");
160 
161  histname = "met_variable";
162  histtitle = "PFMET";
163  bookME(ibooker, metME_variableBinning_, histname, histtitle, met_variable_binning_);
164  setMETitle(metME_variableBinning_, "PF MET [GeV]", "events / [GeV]");
165 
166  histname = "metVsLS";
167  histtitle = "PFMET vs LS";
168  bookME(ibooker,
169  metVsLS_,
170  histname,
171  histtitle,
177  setMETitle(metVsLS_, "LS", "PF MET [GeV]");
178 
179  histname = "metPhi";
180  histtitle = "PFMET phi";
181  bookME(ibooker, metPhiME_, histname, histtitle, phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
182  setMETitle(metPhiME_, "PF MET #phi", "events / 0.1 rad");
183 
184  // Initialize the GenericTriggerEventFlag
186  num_genTriggerEventFlag_->initRun(iRun, iSetup);
188  den_genTriggerEventFlag_->initRun(iRun, iSetup);
189 }
190 
196  // Filter out events if Trigger Filtering is requested
197  if (den_genTriggerEventFlag_->on() && !den_genTriggerEventFlag_->accept(iEvent, iSetup))
198  return;
200  iEvent.getByToken(metToken_, metHandle);
201  if (!metHandle.isValid()) {
202  if (!warningPrinted4token_[0]) {
203  edm::LogWarning("METMonitor") << "skipping events because the collection " << metInputTag_.label().c_str()
204  << " is not available";
205  warningPrinted4token_[0] = true;
206  }
207  return;
208  }
209  reco::PFMET pfmet = metHandle->front();
210  if (!metSelection_(pfmet))
211  return;
212 
213  float met = pfmet.pt();
214  float phi = pfmet.phi();
215 
216  std::vector<reco::PFJet> jets;
218  iEvent.getByToken(jetToken_, jetHandle);
219  if (jetHandle.isValid()) {
220  if (jetHandle->size() < njets_)
221  return;
222  for (auto const& j : *jetHandle) {
223  if (jetSelection_(j)) {
224  jets.push_back(j);
225  }
226  }
227  } else {
228  if (!warningPrinted4token_[1]) {
229  if (jetInputTag_.label().empty())
230  edm::LogWarning("METMonitor") << "JetCollection not set";
231  else
232  edm::LogWarning("METMonitor") << "skipping events because the collection " << jetInputTag_.label().c_str()
233  << " is not available";
234  warningPrinted4token_[1] = true;
235  }
236  // if Handle is not valid, because the InputTag has been mis-configured, then skip the event
237  if (!jetInputTag_.label().empty())
238  return;
239  }
240  float deltaPhi_met_j1 = 10.0;
241  float deltaPhi_j1_j2 = 10.0;
242 
243  if (!jets.empty())
244  deltaPhi_met_j1 = fabs(deltaPhi(pfmet.phi(), jets[0].phi()));
245  if (jets.size() >= 2)
246  deltaPhi_j1_j2 = fabs(deltaPhi(jets[0].phi(), jets[1].phi()));
247 
248  std::vector<reco::GsfElectron> electrons;
250  iEvent.getByToken(eleToken_, eleHandle);
251  if (eleHandle.isValid()) {
252  if (eleHandle->size() < nelectrons_)
253  return;
254  for (auto const& e : *eleHandle) {
255  if (eleSelection_(e))
256  electrons.push_back(e);
257  }
258  if (electrons.size() < nelectrons_)
259  return;
260  } else {
261  if (!warningPrinted4token_[2]) {
262  warningPrinted4token_[2] = true;
263  if (eleInputTag_.label().empty())
264  edm::LogWarning("METMonitor") << "GsfElectronCollection not set";
265  else
266  edm::LogWarning("METMonitor") << "skipping events because the collection " << eleInputTag_.label().c_str()
267  << " is not available";
268  }
269  if (!eleInputTag_.label().empty())
270  return;
271  }
272 
275  iEvent.getByToken(vtxToken_, vtxHandle);
276  if (vtxHandle.isValid()) {
277  for (auto const& v : *vtxHandle) {
278  bool isFake = v.isFake();
279 
280  if (!isFake) {
281  vtx = v;
282  break;
283  }
284  }
285  } else {
286  if (!warningPrinted4token_[3]) {
287  warningPrinted4token_[3] = true;
288  if (vtxInputTag_.label().empty())
289  edm::LogWarning("METMonitor") << "VertexCollection is not set";
290  else
291  edm::LogWarning("METMonitor") << "skipping events because the collection " << vtxInputTag_.label().c_str()
292  << " is not available";
293  }
294  if (!vtxInputTag_.label().empty())
295  return;
296  }
297 
298  std::vector<reco::Muon> muons;
300  iEvent.getByToken(muoToken_, muoHandle);
301  if (muoHandle.isValid()) {
302  if (muoHandle->size() < nmuons_)
303  return;
304  for (auto const& m : *muoHandle) {
305  bool pass = m.isGlobalMuon() && m.isPFMuon() && m.globalTrack()->normalizedChi2() < 10. &&
306  m.globalTrack()->hitPattern().numberOfValidMuonHits() > 0 && m.numberOfMatchedStations() > 1 &&
307  fabs(m.muonBestTrack()->dxy(vtx.position())) < 0.2 &&
308  fabs(m.muonBestTrack()->dz(vtx.position())) < 0.5 &&
309  m.innerTrack()->hitPattern().numberOfValidPixelHits() > 0 &&
310  m.innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5;
311  if (muoSelection_(m) && pass)
312  muons.push_back(m);
313  }
314  if (muons.size() < nmuons_)
315  return;
316  } else {
317  if (!warningPrinted4token_[4]) {
318  warningPrinted4token_[4] = true;
319  if (muoInputTag_.label().empty())
320  edm::LogWarning("METMonitor") << "MuonCollection not set";
321  else
322  edm::LogWarning("METMonitor") << "skipping events because the collection " << muoInputTag_.label().c_str()
323  << " is not available";
324  }
325  if (!muoInputTag_.label().empty())
326  return;
327  }
328 
329  // filling histograms (denominator)
330  metME_.denominator->Fill(met);
332  metPhiME_.denominator->Fill(phi);
333  deltaphimetj1ME_.denominator->Fill(deltaPhi_met_j1);
334  deltaphij1j2ME_.denominator->Fill(deltaPhi_j1_j2);
335 
336  int ls = iEvent.id().luminosityBlock();
337  metVsLS_.denominator->Fill(ls, met);
338  // applying selection for numerator
339  if (num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup))
340  return;
341 
342  // filling histograms (num_genTriggerEventFlag_)
343  metME_.numerator->Fill(met);
345  metPhiME_.numerator->Fill(phi);
346  metVsLS_.numerator->Fill(ls, met);
347  deltaphimetj1ME_.numerator->Fill(deltaPhi_met_j1);
348  deltaphij1j2ME_.numerator->Fill(deltaPhi_j1_j2);
349 }
350 
352  pset.add<unsigned>("nbins");
353  pset.add<double>("xmin");
354  pset.add<double>("xmax");
355 }
356 
358  pset.add<unsigned int>("nbins", 2500);
359  pset.add<double>("xmin", 0.);
360  pset.add<double>("xmax", 2500.);
361 }
362 
365  desc.add<std::string>("FolderName", "HLT/MET");
366 
367  desc.add<edm::InputTag>("met", edm::InputTag("pfMet"));
368  desc.add<edm::InputTag>("jets", edm::InputTag("ak4PFJetsCHS"));
369  desc.add<edm::InputTag>("electrons", edm::InputTag("gedGsfElectrons"));
370  desc.add<edm::InputTag>("muons", edm::InputTag("muons"));
371  desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
372  desc.add<std::string>("metSelection", "pt > 0");
373  desc.add<std::string>("jetSelection", "pt > 0");
374  desc.add<std::string>("eleSelection", "pt > 0");
375  desc.add<std::string>("muoSelection", "pt > 0");
376  desc.add<unsigned>("njets", 0);
377  desc.add<unsigned>("nelectrons", 0);
378  desc.add<unsigned>("nmuons", 0);
379 
381  genericTriggerEventPSet.add<bool>("andOr");
382  genericTriggerEventPSet.add<edm::InputTag>("dcsInputTag", edm::InputTag("scalersRawToDigi"));
383  genericTriggerEventPSet.add<std::vector<int> >("dcsPartitions", {});
384  genericTriggerEventPSet.add<bool>("andOrDcs", false);
385  genericTriggerEventPSet.add<bool>("errorReplyDcs", true);
386  genericTriggerEventPSet.add<std::string>("dbLabel", "");
387  genericTriggerEventPSet.add<bool>("andOrHlt", true);
388  genericTriggerEventPSet.add<edm::InputTag>("hltInputTag", edm::InputTag("TriggerResults::HLT"));
389  genericTriggerEventPSet.add<std::vector<std::string> >("hltPaths", {});
390  genericTriggerEventPSet.add<std::string>("hltDBKey", "");
391  genericTriggerEventPSet.add<bool>("errorReplyHlt", false);
392  genericTriggerEventPSet.add<unsigned int>("verbosityLevel", 1);
393 
394  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
395  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
396 
399  fillHistoPSetDescription(metPSet);
400  histoPSet.add<edm::ParameterSetDescription>("metPSet", metPSet);
401  std::vector<double> bins = {0., 20., 40., 60., 80., 90., 100., 110., 120., 130., 140., 150., 160.,
402  170., 180., 190., 200., 220., 240., 260., 280., 300., 350., 400., 450., 1000.};
403  histoPSet.add<std::vector<double> >("metBinning", bins);
404 
407  histoPSet.add<edm::ParameterSetDescription>("lsPSet", lsPSet);
408 
409  desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
410 
411  descriptions.add("metMonitoring", desc);
412 }
413 
414 // Define this as a plug-in
void setMETitle(METME &me, const std::string &titleX, const std::string &titleY)
Definition: METMonitor.cc:66
StringCutObjectSelector< reco::PFJet, true > jetSelection_
Definition: METMonitor.h:146
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getParameter(std::string const &) const
unsigned nmuons_
Definition: METMonitor.h:152
edm::InputTag vtxInputTag_
Definition: METMonitor.h:123
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
Definition: METMonitor.h:143
MonitorElement * numerator
Definition: METMonitor.h:58
StringCutObjectSelector< reco::GsfElectron, true > eleSelection_
Definition: METMonitor.h:147
static MEbinning getHistoPSet(const edm::ParameterSet &pset)
Definition: METMonitor.cc:54
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
edm::InputTag muoInputTag_
Definition: METMonitor.h:122
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: METMonitor.h:129
double pt() const final
transverse momentum
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
Definition: METMonitor.h:142
edm::InputTag eleInputTag_
Definition: METMonitor.h:121
static MEbinning getHistoLSPSet(const edm::ParameterSet &pset)
Definition: METMonitor.cc:62
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
METME metME_variableBinning_
Definition: METMonitor.h:136
const Point & position() const
position
Definition: Vertex.h:113
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
~METMonitor() override
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
Definition: METMonitor.cc:351
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::string folderName_
Definition: METMonitor.h:116
unsigned njets_
Definition: METMonitor.h:150
void Fill(long long x)
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
Definition: METMonitor.cc:357
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< reco::GsfElectronCollection > eleToken_
Definition: METMonitor.h:127
MonitorElement * denominator
Definition: METMonitor.h:59
MEbinning met_binning_
Definition: METMonitor.h:132
edm::EDGetTokenT< reco::PFJetCollection > jetToken_
Definition: METMonitor.h:126
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
Definition: DQMStore.cc:333
edm::EDGetTokenT< reco::PFMETCollection > metToken_
Definition: METMonitor.h:125
StringCutObjectSelector< reco::Muon, true > muoSelection_
Definition: METMonitor.h:148
edm::EDGetTokenT< reco::MuonCollection > muoToken_
Definition: METMonitor.h:128
METME deltaphij1j2ME_
Definition: METMonitor.h:140
T min(T a, T b)
Definition: MathUtil.h:58
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:70
void bookME(DQMStore::IBooker &, METME &me, const std::string &histname, const std::string &histtitle, int nbins, double xmin, double xmax)
Definition: METMonitor.cc:73
static MEbinning phi_binning_
Definition: METMonitor.h:156
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: METMonitor.cc:195
def ls(path, rec=False)
Definition: eostools.py:349
unsigned nelectrons_
Definition: METMonitor.h:151
std::vector< double > met_variable_binning_
Definition: METMonitor.h:131
METME metPhiME_
Definition: METMonitor.h:138
void add(std::string const &label, ParameterSetDescription const &psetDescription)
METME metVsLS_
Definition: METMonitor.h:137
std::string const & label() const
Definition: InputTag.h:36
edm::InputTag metInputTag_
Definition: METMonitor.h:119
StringCutObjectSelector< reco::MET, true > metSelection_
Definition: METMonitor.h:145
edm::EventID id() const
Definition: EventBase.h:59
std::vector< PFJet > PFJetCollection
collection of PFJet objects
fixed size matrix
HLT enums.
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
MEbinning ls_binning_
Definition: METMonitor.h:133
edm::InputTag jetInputTag_
Definition: METMonitor.h:120
METMonitor(const edm::ParameterSet &)
Definition: METMonitor.cc:15
METME deltaphimetj1ME_
Definition: METMonitor.h:139
std::vector< bool > warningPrinted4token_
Definition: METMonitor.h:158
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: METMonitor.cc:140
METME metME_
Definition: METMonitor.h:135
double phi() const final
momentum azimuthal angle
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: METMonitor.cc:363
Definition: Run.h:45
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
Collection of PF MET.