CMS 3D CMS Logo

METplusTrackMonitor.cc
Go to the documentation of this file.
22 
24 public:
27 
29  ~METplusTrackMonitor() noexcept(true) override {}
30  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
31 
32 protected:
33  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
34  void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
35 
36 private:
38  const edm::InputTag& filterTag,
40 
42 
45 
51 
54 
55  std::vector<double> met_variable_binning_;
56  std::vector<double> muonPt_variable_binning_;
57 
63 
65  ObjME metVsLS_;
66  ObjME metPhiME_;
68  ObjME metVsHltMet_;
69 
71  ObjME muonPtVsLS_;
72  ObjME muonEtaME_;
75 
76  std::unique_ptr<GenericTriggerEventFlag> num_genTriggerEventFlag_;
77  std::unique_ptr<GenericTriggerEventFlag> den_genTriggerEventFlag_;
78 
83 
84  unsigned nmuons_;
85  unsigned njets_;
86 
88 
91 };
92 
94  : folderName_(iConfig.getParameter<std::string>("FolderName")),
95  requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
96  hltPathsAreValid_(false),
97  metToken_(consumes<reco::CaloMETCollection>(iConfig.getParameter<edm::InputTag>("met"))),
98  muonToken_(consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
99  jetToken_(consumes<reco::PFJetCollection>(iConfig.getParameter<edm::InputTag>("jets"))),
100  vtxToken_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))),
101  theTrigSummary_(consumes<trigger::TriggerEvent>(iConfig.getParameter<edm::InputTag>("trigSummary"))),
102  hltMetTag_(iConfig.getParameter<edm::InputTag>("hltMetFilter")),
103  trackLegFilterTag_(iConfig.getParameter<edm::InputTag>("trackLegFilter")),
104  met_variable_binning_(
105  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("metBinning")),
106  muonPt_variable_binning_(
107  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("ptBinning")),
108  met_binning_(getHistoPSet(
109  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("metPSet"))),
110  ls_binning_(
111  getHistoPSet(iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("lsPSet"))),
112  pt_binning_(
113  getHistoPSet(iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("ptPSet"))),
114  eta_binning_(getHistoPSet(
115  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("etaPSet"))),
116  phi_binning_(getHistoPSet(
117  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("phiPSet"))),
118  num_genTriggerEventFlag_(new GenericTriggerEventFlag(
119  iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"), consumesCollector(), *this)),
120  den_genTriggerEventFlag_(new GenericTriggerEventFlag(
121  iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"), consumesCollector(), *this)),
122  metSelection_(iConfig.getParameter<std::string>("metSelection")),
123  muonSelection_(iConfig.getParameter<std::string>("muonSelection")),
124  jetSelection_(iConfig.getParameter<std::string>("jetSelection")),
125  vtxSelection_(iConfig.getParameter<std::string>("vtxSelection")),
126  nmuons_(iConfig.getParameter<unsigned>("nmuons")),
127  njets_(iConfig.getParameter<unsigned>("njets")),
128  leadJetEtaCut_(iConfig.getParameter<double>("leadJetEtaCut")),
129  requireLeadMatched_(iConfig.getParameter<bool>("requireLeadMatched")),
130  maxMatchDeltaR_(iConfig.getParameter<double>("maxMatchDeltaR")) {}
131 
133  edm::Run const& iRun,
134  edm::EventSetup const& iSetup) {
135  // Initialize the GenericTriggerEventFlag
137  num_genTriggerEventFlag_->initRun(iRun, iSetup);
138  }
140  den_genTriggerEventFlag_->initRun(iRun, iSetup);
141  }
142 
143  // check if every HLT path specified in numerator and denominator has a valid match in the HLT Menu
145  den_genTriggerEventFlag_->on() && num_genTriggerEventFlag_->allHLTPathsAreValid() &&
146  den_genTriggerEventFlag_->allHLTPathsAreValid());
147 
148  // if valid HLT paths are required,
149  // create DQM outputs only if all paths are valid
151  return;
152  }
153 
154  std::string histname, histtitle;
155 
156  std::string currentFolder = folderName_;
157  ibooker.setCurrentFolder(currentFolder);
158 
159  // MET leg histograms
160  histname = "met_variable";
161  histtitle = "CaloMET";
162  bookME(ibooker, metME_variableBinning_, histname, histtitle, met_variable_binning_);
163  setMETitle(metME_variableBinning_, "CaloMET [GeV]", "events / [GeV]");
164 
165  histname = "metVsLS";
166  histtitle = "CaloMET vs LS";
167  bookME(ibooker,
168  metVsLS_,
169  histname,
170  histtitle,
176  setMETitle(metVsLS_, "LS", "CaloMET [GeV]");
177 
178  histname = "metPhi";
179  histtitle = "CaloMET phi";
180  bookME(ibooker, metPhiME_, histname, histtitle, phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
181  setMETitle(metPhiME_, "CaloMET #phi", "events / 0.2 rad");
182 
183  histname = "deltaphi_metjet1";
184  histtitle = "dPhi(CaloMET, jet1)";
185  bookME(ibooker, deltaphimetj1ME_, histname, histtitle, phi_binning_.nbins, 0, phi_binning_.xmax);
186  setMETitle(deltaphimetj1ME_, "#Delta#phi (CaloMET, j1)", "events / 0.1 rad");
187 
188  histname = "metVsHltMet";
189  histtitle = "CaloMET vs hltMet";
190  bookME(ibooker,
191  metVsHltMet_,
192  histname,
193  histtitle,
200  setMETitle(metVsHltMet_, "hltMet (online) [GeV]", "CaloMET (offline) [GeV]");
201 
202  // Track leg histograms
203 
204  histname = "muonPt_variable";
205  histtitle = "Muon PT";
206  bookME(ibooker, muonPtME_variableBinning_, histname, histtitle, muonPt_variable_binning_);
207  setMETitle(muonPtME_variableBinning_, "Muon p_{T} [GeV]", "events / [GeV]");
208 
209  histname = "muonEta";
210  histtitle = "Muon eta";
211  bookME(ibooker, muonEtaME_, histname, histtitle, eta_binning_.nbins, eta_binning_.xmin, eta_binning_.xmax);
212  setMETitle(muonEtaME_, "Muon #eta", "events / 0.2");
213 
214  histname = "deltaphi_muonmet";
215  histtitle = "dPhi(Muon, CaloMET)";
216  bookME(ibooker, deltaphimetmuonME_, histname, histtitle, phi_binning_.nbins, 0, phi_binning_.xmax);
217  setMETitle(deltaphimetmuonME_, "#Delta#phi (Muon, CaloMET)", "events / 0.1 rad");
218 
219  histname = "muonEtaVsPhi";
220  histtitle = "Muon eta vs phi";
221  bookME(ibooker,
223  histname,
224  histtitle,
231  setMETitle(muonEtaVsPhi_, "Muon #phi", "Muon #eta");
232 
233  histname = "muonPtVsLS";
234  histtitle = "Muon PT vs LS";
235  bookME(ibooker,
236  muonPtVsLS_,
237  histname,
238  histtitle,
243  pt_binning_.xmax);
244  setMETitle(muonPtVsLS_, "LS", "Muon p_{T} [GeV]");
245 }
246 
248  // if valid HLT paths are required,
249  // analyze event only if all paths are valid
251  return;
252  }
253 
254  // Filter out events if Trigger Filtering is requested
255  if (den_genTriggerEventFlag_->on() && !den_genTriggerEventFlag_->accept(iEvent, iSetup))
256  return;
257 
259  iEvent.getByToken(metToken_, metHandle);
260  reco::CaloMET caloMet = metHandle->front();
261  if (!metSelection_(caloMet))
262  return;
263 
264  float met = caloMet.pt();
265  float metPhi = caloMet.phi();
266 
268  iEvent.getByToken(jetToken_, jetsHandle);
269  if (jetsHandle->size() < njets_)
270  return;
271  std::vector<reco::PFJet> jets;
272  for (auto const& j : *jetsHandle) {
273  if (jetSelection_(j))
274  jets.push_back(j);
275  }
276  if (jets.size() < njets_)
277  return;
278  if (njets_ > 0 && !(jets.empty()) && fabs(jets[0].eta()) > leadJetEtaCut_)
279  return;
280  float deltaphi_metjet1 = !(jets.empty()) ? fabs(deltaPhi(caloMet.phi(), jets[0].phi())) : 10.0;
281 
283  iEvent.getByToken(vtxToken_, primaryVertices);
284  if (primaryVertices->empty())
285  return;
286  const reco::Vertex* pv = nullptr;
287  for (auto const& v : *primaryVertices) {
288  if (!vtxSelection_(v))
289  continue;
290  pv = &v;
291  break;
292  }
293  if (pv == nullptr)
294  return;
295 
297  iEvent.getByToken(muonToken_, muonHandle);
298  if (muonHandle->size() < nmuons_)
299  return;
300  std::vector<reco::Muon> muons;
301  for (auto const& m : *muonHandle) {
302  bool passTightID =
303  muon::isTightMuon(m, *pv) &&
304  m.innerTrack()->hitPattern().trackerLayersWithoutMeasurement(reco::HitPattern::MISSING_INNER_HITS) == 0 &&
305  m.innerTrack()->hitPattern().trackerLayersWithoutMeasurement(reco::HitPattern::TRACK_HITS) == 0;
306  if (muonSelection_(m) && passTightID)
307  muons.push_back(m);
308  }
309  if (muons.size() < nmuons_)
310  return;
311 
312  // Filling MET leg histograms (denominator)
314  metPhiME_.denominator->Fill(metPhi);
315  deltaphimetj1ME_.denominator->Fill(deltaphi_metjet1);
316 
317  int ls = iEvent.id().luminosityBlock();
319 
320  // Apply the selection for the MET leg numerator
323  if (!triggerSummary.isValid()) {
324  edm::LogError("METplusTrackMonitor") << "Invalid collection: TriggerSummary"
325  << "\n";
326  return;
327  }
328 
330  bool passesHltMetFilter = getHLTObj(triggerSummary, hltMetTag_, hltMet);
331 
332  if (!passesHltMetFilter)
333  return;
334 
335  // Filling MET leg histograms (numerator)
337  metPhiME_.numerator->Fill(metPhi);
338  deltaphimetj1ME_.numerator->Fill(deltaphi_metjet1);
341 
342  // Filling track leg histograms (denominator)
343  double leadMuonPt = !(muons.empty()) ? muons[0].pt() : -1.0;
344  double leadMuonEta = !(muons.empty()) ? muons[0].eta() : 10.0;
345  double leadMuonPhi = !(muons.empty()) ? muons[0].phi() : 10.0;
346  float deltaphi_metmuon = !(muons.empty()) ? fabs(deltaPhi(caloMet.phi(), muons[0].phi())) : 10.0;
347 
349  muonPtVsLS_.denominator->Fill(ls, leadMuonPt);
350  muonEtaME_.denominator->Fill(leadMuonEta);
351  deltaphimetmuonME_.denominator->Fill(deltaphi_metmuon);
352  muonEtaVsPhi_.denominator->Fill(leadMuonPhi, leadMuonEta);
353 
354  // Apply the selection for the track leg numerator
355  trigger::TriggerObject isoTrk;
356  bool passesTrackLegFilter = getHLTObj(triggerSummary, trackLegFilterTag_, isoTrk);
357 
358  // require track leg filter
359  if (!passesTrackLegFilter)
360  return;
361 
362  // if requested, require lead selected muon is matched to the track leg filter object
363  if (requireLeadMatched_ && !(muons.empty()) && deltaR(muons[0], isoTrk) < maxMatchDeltaR_)
364  return;
365 
366  // require the full HLT path is fired
367  if (num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup))
368  return;
369 
370  // Filling track leg histograms (denominator)
372  muonPtVsLS_.numerator->Fill(ls, leadMuonPt);
373  muonEtaME_.numerator->Fill(leadMuonEta);
374  deltaphimetmuonME_.numerator->Fill(deltaphi_metmuon);
375  muonEtaVsPhi_.numerator->Fill(leadMuonPhi, leadMuonEta);
376 }
377 
379  const edm::InputTag& filterTag,
380  trigger::TriggerObject& obj) const {
381  double leadingPt = -1.0;
382 
383  size_t filterIndex = trigSummary->filterIndex(filterTag);
385 
386  if (!(filterIndex >= trigSummary->sizeFilters())) {
387  const trigger::Keys& keys = trigSummary->filterKeys(filterIndex);
388  for (unsigned short key : keys) {
390  if (foundObject.pt() > leadingPt) {
391  obj = foundObject;
392  leadingPt = obj.pt();
393  }
394  }
395  }
396 
397  return (leadingPt > 0.0);
398 }
399 
402  desc.add<std::string>("FolderName", "HLT/MET");
403  desc.add<bool>("requireValidHLTPaths", true);
404 
405  desc.add<edm::InputTag>("met", edm::InputTag("caloMet"));
406  desc.add<edm::InputTag>("jets", edm::InputTag("ak4PFJetsCHS"));
407  desc.add<edm::InputTag>("electrons", edm::InputTag("gedGsfElectrons"));
408  desc.add<edm::InputTag>("muons", edm::InputTag("muons"));
409  desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
410  desc.add<edm::InputTag>("trigSummary", edm::InputTag("hltTriggerSummaryAOD"));
411  desc.add<edm::InputTag>("hltMetFilter", edm::InputTag("hltMET105", "", "HLT"));
412  desc.add<edm::InputTag>("trackLegFilter", edm::InputTag("hltTrk50Filter", "", "HLT"));
413 
414  desc.add<std::string>("metSelection", "pt > 0");
415  desc.add<std::string>("jetSelection", "pt > 0");
416  desc.add<std::string>("muonSelection", "pt > 0");
417  desc.add<std::string>("vtxSelection", "!isFake");
418  desc.add<unsigned>("njets", 0);
419  desc.add<unsigned>("nmuons", 0);
420  desc.add<double>("leadJetEtaCut", 2.4);
421  desc.add<bool>("requireLeadMatched", true);
422  desc.add<double>("maxMatchDeltaR", 0.1);
423 
426  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
427  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
428 
434 
439 
444 
445  std::vector<double> bins = {0., 20., 40., 60., 80., 90., 100., 110., 120., 130., 140., 150., 160.,
446  170., 180., 190., 200., 220., 240., 260., 280., 300., 350., 400., 450., 1000.};
447 
448  histoPSet.add<std::vector<double> >("metBinning", bins);
449  histoPSet.add<std::vector<double> >("ptBinning", bins);
450 
454 
455  desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
456 
457  descriptions.add("metPlusTrackMonitoring", desc);
458 }
459 
edm::EDGetTokenT< reco::PFJetCollection > jetToken_
METplusTrackMonitor(const edm::ParameterSet &)
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
dqm::reco::MonitorElement MonitorElement
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
const std::string folderName_
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
Log< level::Error, false > LogError
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
edm::InputTag trackLegFilterTag_
void setMETitle(ObjME &me, const std::string &titleX, const std::string &titleY)
dqm::reco::DQMStore DQMStore
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::vector< double > muonPt_variable_binning_
edm::EDGetTokenT< reco::MuonCollection > muonToken_
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
void Fill(long long x)
Collection of Calo MET.
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
std::vector< double > met_variable_binning_
MonitorElement * denominator
MonitorElement * numerator
key
prepare the HTCondor submission files and eventually submit them
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
StringCutObjectSelector< reco::CaloMET, true > metSelection_
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
StringCutObjectSelector< reco::PFJet, true > jetSelection_
def ls(path, rec=False)
Definition: eostools.py:349
StringCutObjectSelector< reco::Muon, true > muonSelection_
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
std::vector< size_type > Keys
StringCutObjectSelector< reco::Vertex, true > vtxSelection_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::CaloMETCollection > metToken_
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)
~METplusTrackMonitor() noexcept(true) override
std::vector< PFJet > PFJetCollection
collection of PFJet objects
fixed size matrix
HLT enums.
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
static void fillPSetDescription(edm::ParameterSetDescription &desc)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< trigger::TriggerEvent > theTrigSummary_
bool getHLTObj(const edm::Handle< trigger::TriggerEvent > &trigSummary, const edm::InputTag &filterTag, trigger::TriggerObject &obj) const
Definition: Run.h:45