CMS 3D CMS Logo

HeavyFlavorValidation.cc
Go to the documentation of this file.
1 
8 // Original Author: Zoltan Gecse
9 
10 #include <memory>
11 #include <initializer_list>
19 
35 
37 
40 
42 
43 #include "TLorentzVector.h"
44 
45 using namespace std;
46 using namespace edm;
47 using namespace reco;
48 using namespace l1extra;
49 using namespace trigger;
50 
52 public:
53  explicit HeavyFlavorValidation(const edm::ParameterSet &);
54  ~HeavyFlavorValidation() override;
55 
56 protected:
57  void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override;
58  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
59  void analyze(const edm::Event &, const edm::EventSetup &) override;
60 
61 private:
62  int getMotherId(const Candidate *p);
63  void match(MonitorElement *me,
64  vector<LeafCandidate> &from,
65  vector<LeafCandidate> &to,
66  double deltaRMatchingCut,
67  vector<int> &map);
68  void myBook2D(DQMStore::IBooker &ibooker,
69  TString name,
70  vector<double> &xBins,
71  TString xLabel,
72  vector<double> &yBins,
73  TString yLabel,
74  TString title);
75  void myBook2D(DQMStore::IBooker &ibooker,
76  TString name,
77  vector<double> &xBins,
78  TString xLabel,
79  vector<double> &yBins,
80  TString yLabel) {
81  myBook2D(ibooker, name, xBins, xLabel, yBins, yLabel, name);
82  }
83  void myBookProfile2D(DQMStore::IBooker &ibooker,
84  TString name,
85  vector<double> &xBins,
86  TString xLabel,
87  vector<double> &yBins,
88  TString yLabel,
89  TString title);
91  TString name,
92  vector<double> &xBins,
93  TString xLabel,
94  vector<double> &yBins,
95  TString yLabel) {
96  myBookProfile2D(ibooker, name, xBins, xLabel, yBins, yLabel, name);
97  }
98  void myBook1D(DQMStore::IBooker &ibooker, TString name, vector<double> &xBins, TString label, TString title);
99  void myBook1D(DQMStore::IBooker &ibooker, TString name, vector<double> &xBins, TString label) {
100  myBook1D(ibooker, name, xBins, label, name);
101  }
102 
112  int getFilterLevel(const std::string &moduleName, const HLTConfigProvider &hltConfig);
113 
114  string dqmFolder;
117 
126 
127  vector<int> motherIDs;
132  vector<double> deltaEtaBins;
133  vector<double> deltaPhiBins;
134  vector<double> muonPtBins;
135  vector<double> muonEtaBins;
136  vector<double> muonPhiBins;
137  vector<double> dimuonPtBins;
138  vector<double> dimuonEtaBins;
139  vector<double> dimuonDRBins;
140  map<TString, MonitorElement *> ME;
141  vector<pair<string, int> > filterNamesLevels;
142  const double muonMass;
143 };
144 
146  : //get parameters
147  dqmFolder(pset.getUntrackedParameter<string>("DQMFolder")),
148  triggerProcessName(pset.getUntrackedParameter<string>("TriggerProcessName")),
149  triggerPathName(pset.getUntrackedParameter<string>("TriggerPathName")),
150  motherIDs(pset.getUntrackedParameter<vector<int> >("MotherIDs")),
151  genGlobDeltaRMatchingCut(pset.getUntrackedParameter<double>("GenGlobDeltaRMatchingCut")),
152  globL1DeltaRMatchingCut(pset.getUntrackedParameter<double>("GlobL1DeltaRMatchingCut")),
153  globL2DeltaRMatchingCut(pset.getUntrackedParameter<double>("GlobL2DeltaRMatchingCut")),
154  globL3DeltaRMatchingCut(pset.getUntrackedParameter<double>("GlobL3DeltaRMatchingCut")),
155  deltaEtaBins(pset.getUntrackedParameter<vector<double> >("DeltaEtaBins")),
156  deltaPhiBins(pset.getUntrackedParameter<vector<double> >("DeltaPhiBins")),
157  muonPtBins(pset.getUntrackedParameter<vector<double> >("MuonPtBins")),
158  muonEtaBins(pset.getUntrackedParameter<vector<double> >("MuonEtaBins")),
159  muonPhiBins(pset.getUntrackedParameter<vector<double> >("MuonPhiBins")),
160  dimuonPtBins(pset.getUntrackedParameter<vector<double> >("DimuonPtBins")),
161  dimuonEtaBins(pset.getUntrackedParameter<vector<double> >("DimuonEtaBins")),
162  dimuonDRBins(pset.getUntrackedParameter<vector<double> >("DimuonDRBins")),
163  muonMass(0.106) {
164  triggerSummaryRAWTag = consumes<TriggerEventWithRefs>(
165  InputTag(pset.getUntrackedParameter<string>("TriggerSummaryRAW"), "", triggerProcessName));
167  consumes<TriggerEvent>(InputTag(pset.getUntrackedParameter<string>("TriggerSummaryAOD"), "", triggerProcessName));
168  triggerResultsTag = InputTag(pset.getUntrackedParameter<string>("TriggerResults"), "", triggerProcessName);
169  triggerResultsToken = consumes<TriggerResults>(triggerResultsTag);
170  recoMuonsTag = pset.getParameter<InputTag>("RecoMuons");
171  recoMuonsToken = consumes<MuonCollection>(recoMuonsTag);
172  genParticlesTag = pset.getParameter<InputTag>("GenParticles");
173  genParticlesToken = consumes<GenParticleCollection>(genParticlesTag);
174 }
175 
177  //discover HLT configuration
179  bool isChanged;
180  if (hltConfig.init(iRun, iSetup, triggerProcessName, isChanged)) {
181  LogDebug("HLTriggerOfflineHeavyFlavor")
182  << "Successfully initialized HLTConfigProvider with process name: " << triggerProcessName << endl;
183  } else {
184  LogWarning("HLTriggerOfflineHeavyFlavor")
185  << "Could not initialize HLTConfigProvider with process name: " << triggerProcessName << endl;
186  return;
187  }
188  vector<string> triggerNames = hltConfig.triggerNames();
189  for (const auto &trigName : triggerNames) {
190  // TString triggerName = trigName;
191  if (trigName.find(triggerPathName) != std::string::npos) {
192  vector<string> moduleNames = hltConfig.moduleLabels(trigName);
193  for (const auto &moduleName : moduleNames) {
195  if (level > 0) {
196  filterNamesLevels.push_back({moduleName, level});
197  }
198  }
199  break;
200  }
201  }
202 
203  if (filterNamesLevels.empty()) {
204  LogDebug("HLTriggerOfflineHeavyFlavor") << "Bad Trigger Path: " << triggerPathName << endl;
205  return;
206  } else {
208  str.reserve(
209  512); // avoid too many realloctions in the following loop (allows for filter names with roughly 100 chars each)
210  for (const auto &filters : filterNamesLevels)
211  str = str + " " + filters.first;
212  LogDebug("HLTriggerOfflineHeavyFlavor") << "Trigger Path: " << triggerPathName << " has filters:" << str;
213  }
214 }
215 
217  edm::Run const &iRun,
218  edm::EventSetup const &iSetup) {
219  ibooker.cd();
221 
222  // create Monitor Elements
223  // Eta Pt Single
224  myBook2D(ibooker, "genMuon_genEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)");
225  myBook2D(ibooker, "globMuon_genEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)");
226  myBook2D(ibooker, "globMuon_recoEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)");
227  myBook2D(ibooker, "pathMuon_recoEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)", triggerPathName);
228  myBook2D(ibooker, "resultMuon_recoEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)");
229  // Eta Pt Single Resolution
230  myBookProfile2D(ibooker, "resGlobGen_genEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)");
232  ibooker, "resPathGlob_recoEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)", triggerPathName);
233  // Eta Pt Double
234  myBook2D(ibooker, "genDimuon_genEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)");
235  myBook2D(ibooker, "globDimuon_genEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)");
236  myBook2D(ibooker, "globDimuon_recoEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)");
237  myBook2D(
238  ibooker, "pathDimuon_recoEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)", triggerPathName);
239  myBook2D(ibooker, "resultDimuon_recoEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)");
240  myBook2D(
241  ibooker, "diPathDimuon_recoEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)", triggerPathName);
242  // Eta Phi Single
243  myBook2D(ibooker, "genMuon_genEtaPhi", muonEtaBins, "#mu eta", muonPhiBins, "#mu phi");
244  myBook2D(ibooker, "globMuon_genEtaPhi", muonEtaBins, "#mu eta", muonPhiBins, "#mu phi");
245  myBook2D(ibooker, "globMuon_recoEtaPhi", muonEtaBins, "#mu eta", muonPhiBins, "#mu phi");
246  myBook2D(ibooker, "pathMuon_recoEtaPhi", muonEtaBins, "#mu eta", muonPhiBins, "#mu phi", triggerPathName);
247  myBook2D(ibooker, "resultMuon_recoEtaPhi", muonEtaBins, "#mu eta", muonPhiBins, "#mu phi");
248  // Rap Pt Double
249  myBook2D(ibooker, "genDimuon_genRapPt", dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)");
250  myBook2D(ibooker, "globDimuon_genRapPt", dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)");
251  myBook2D(ibooker, "globDimuon_recoRapPt", dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)");
252  myBook2D(ibooker,
253  "pathDimuon_recoRapPt",
255  "#mu#mu rapidity",
256  dimuonPtBins,
257  " #mu#mu pT (GeV)",
259  myBook2D(ibooker, "resultDimuon_recoRapPt", dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)");
260  myBook2D(ibooker,
261  "diPathDimuon_recoRapPt",
263  "#mu#mu rapidity",
264  dimuonPtBins,
265  " #mu#mu pT (GeV)",
267  // Pt DR Double
268  myBook2D(ibooker, "genDimuon_genPtDR", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP");
269  myBook2D(ibooker, "globDimuon_genPtDR", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP");
270  myBook2D(ibooker, "globDimuon_recoPtDR", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP");
271  myBook2D(ibooker,
272  "pathDimuon_recoPtDR",
273  dimuonPtBins,
274  " #mu#mu pT (GeV)",
275  dimuonDRBins,
276  "#mu#mu #Delta R at IP",
278  myBook2D(ibooker,
279  "diPathDimuon_recoPtDR",
280  dimuonPtBins,
281  " #mu#mu pT (GeV)",
282  dimuonDRBins,
283  "#mu#mu #Delta R at IP",
285  myBook2D(ibooker, "resultDimuon_recoPtDR", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP");
286  // Pt DRpos Double
287  myBook2D(ibooker, "globDimuon_recoPtDRpos", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R in MS");
288  myBook2D(ibooker,
289  "pathDimuon_recoPtDRpos",
290  dimuonPtBins,
291  " #mu#mu pT (GeV)",
292  dimuonDRBins,
293  "#mu#mu #Delta R in MS",
295  myBook2D(ibooker,
296  "diPathDimuon_recoPtDRpos",
297  dimuonPtBins,
298  " #mu#mu pT (GeV)",
299  dimuonDRBins,
300  "#mu#mu #Delta R in MS",
302  myBook2D(
303  ibooker, "resultDimuon_recoPtDRpos", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R in MS");
304 
305  // Matching
306  myBook2D(ibooker, "globGen_deltaEtaDeltaPhi", deltaEtaBins, "#Delta eta", deltaPhiBins, "#Delta phi");
307  myBook2D(
308  ibooker, "pathGlob_deltaEtaDeltaPhi", deltaEtaBins, "#Delta eta", deltaPhiBins, "#Delta phi", triggerPathName);
309  // Size of containers
310  vector<double> sizeBins;
311  sizeBins.push_back(10);
312  sizeBins.push_back(0);
313  sizeBins.push_back(10);
314  myBook1D(ibooker, "genMuon_size", sizeBins, "container size");
315  myBook1D(ibooker, "globMuon_size", sizeBins, "container size");
316  myBook1D(ibooker, "pathMuon_size", sizeBins, "container size", triggerPathName);
317 }
318 
320  if (filterNamesLevels.empty()) {
321  return;
322  }
323  //access the containers and create LeafCandidate copies
324  vector<LeafCandidate> genMuons;
327  if (genParticles.isValid()) {
328  for (GenParticleCollection::const_iterator p = genParticles->begin(); p != genParticles->end(); ++p) {
329  if (p->status() == 1 && std::abs(p->pdgId()) == 13 &&
330  (find(motherIDs.begin(), motherIDs.end(), -1) != motherIDs.end() ||
331  find(motherIDs.begin(), motherIDs.end(), getMotherId(&(*p))) != motherIDs.end())) {
332  genMuons.push_back(*p);
333  }
334  }
335  } else {
336  LogDebug("HLTriggerOfflineHeavyFlavor") << "Could not access GenParticleCollection" << endl;
337  }
339  ME["genMuon_size"]->Fill(genMuons.size());
340  LogDebug("HLTriggerOfflineHeavyFlavor")
341  << "GenParticleCollection from " << genParticlesTag << " has size: " << genMuons.size() << endl;
342 
343  vector<LeafCandidate> globMuons;
344  vector<LeafCandidate> globMuons_position;
345  Handle<MuonCollection> recoMuonsHandle;
346  iEvent.getByToken(recoMuonsToken, recoMuonsHandle);
347  if (recoMuonsHandle.isValid()) {
348  for (MuonCollection::const_iterator p = recoMuonsHandle->begin(); p != recoMuonsHandle->end(); ++p) {
349  if (p->isGlobalMuon()) {
350  globMuons.push_back(*p);
351  globMuons_position.push_back(LeafCandidate(p->charge(),
352  math::XYZTLorentzVector(p->outerTrack()->innerPosition().x(),
353  p->outerTrack()->innerPosition().y(),
354  p->outerTrack()->innerPosition().z(),
355  0.)));
356  }
357  }
358  } else {
359  LogDebug("HLTriggerOfflineHeavyFlavor") << "Could not access reco Muons" << endl;
360  }
361  ME["globMuon_size"]->Fill(globMuons.size());
362  LogDebug("HLTriggerOfflineHeavyFlavor")
363  << "Global Muons from " << recoMuonsTag << " has size: " << globMuons.size() << endl;
364 
365  // access RAW trigger event
366  vector<vector<LeafCandidate> > muonsAtFilter;
367  vector<vector<LeafCandidate> > muonPositionsAtFilter;
368  for (size_t i = 0; i < filterNamesLevels.size(); i++) {
369  muonsAtFilter.push_back(vector<LeafCandidate>());
370  muonPositionsAtFilter.push_back(vector<LeafCandidate>());
371  }
372  Handle<TriggerEventWithRefs> rawTriggerEvent;
373  iEvent.getByToken(triggerSummaryRAWTag, rawTriggerEvent);
374  if (rawTriggerEvent.isValid()) {
375  for (size_t i = 0; i < filterNamesLevels.size(); i++) {
376  size_t index = rawTriggerEvent->filterIndex(InputTag(filterNamesLevels[i].first, "", triggerProcessName));
377  if (index < rawTriggerEvent->size()) {
378  if (filterNamesLevels[i].second == 1) {
379  vector<L1MuonParticleRef> l1Cands;
380  rawTriggerEvent->getObjects(index, TriggerL1Mu, l1Cands);
381  for (size_t j = 0; j < l1Cands.size(); j++) {
382  muonsAtFilter[i].push_back(*l1Cands[j]);
383  }
384  } else {
385  vector<RecoChargedCandidateRef> hltCands;
386  rawTriggerEvent->getObjects(index, TriggerMuon, hltCands);
387  for (size_t j = 0; j < hltCands.size(); j++) {
388  muonsAtFilter[i].push_back(*hltCands[j]);
389  if (filterNamesLevels[i].second == 2) {
390  muonPositionsAtFilter[i].push_back(
391  LeafCandidate(hltCands[j]->charge(),
392  math::XYZTLorentzVector(hltCands[j]->track()->innerPosition().x(),
393  hltCands[j]->track()->innerPosition().y(),
394  hltCands[j]->track()->innerPosition().z(),
395  0.)));
396  }
397  }
398  }
399  }
400  //ME[TString::Format("filt%dMuon_size", int(i + 1))]->Fill(muonsAtFilter[i].size());
401  LogDebug("HLTriggerOfflineHeavyFlavor")
402  << "Filter \"" << filterNamesLevels[i].first << "\" has " << muonsAtFilter[i].size() << " muons" << endl;
403  }
404  } else {
405  LogDebug("HLTriggerOfflineHeavyFlavor") << "Could not access RAWTriggerEvent" << endl;
406  }
407 
408  // access AOD trigger event
409  vector<LeafCandidate> pathMuons;
410  Handle<TriggerEvent> aodTriggerEvent;
411  iEvent.getByToken(triggerSummaryAODTag, aodTriggerEvent);
412  if (aodTriggerEvent.isValid()) {
413  TriggerObjectCollection allObjects = aodTriggerEvent->getObjects();
414  for (int i = 0; i < aodTriggerEvent->sizeFilters(); i++) {
415  if (aodTriggerEvent->filterTag(i) == InputTag((filterNamesLevels.end() - 1)->first, "", triggerProcessName)) {
416  Keys keys = aodTriggerEvent->filterKeys(i);
417  for (size_t j = 0; j < keys.size(); j++) {
418  pathMuons.push_back(LeafCandidate(
419  allObjects[keys[j]].id() > 0 ? 1 : -1,
421  allObjects[keys[j]].pt(), allObjects[keys[j]].eta(), allObjects[keys[j]].phi(), muonMass)));
422  }
423  }
424  }
425  ME["pathMuon_size"]->Fill(pathMuons.size());
426  LogDebug("HLTriggerOfflineHeavyFlavor")
427  << "Path \"" << triggerPathName << "\" has " << pathMuons.size() << " muons at last filter \""
428  << (filterNamesLevels.end() - 1)->first << "\"" << endl;
429  } else {
430  LogDebug("HLTriggerOfflineHeavyFlavor") << "Could not access AODTriggerEvent" << endl;
431  }
432 
433  // access Trigger Results
434  bool triggerFired = false;
437  if (triggerResults.isValid()) {
438  LogDebug("HLTriggerOfflineHeavyFlavor") << "Successfully initialized " << triggerResultsTag << endl;
439  const edm::TriggerNames &triggerNames = iEvent.triggerNames(*triggerResults);
440  bool hlt_exists = false;
441  for (unsigned int i = 0; i != triggerNames.size(); i++) {
442  TString hlt_name = triggerNames.triggerName(i);
443  if (hlt_name.Contains(triggerPathName)) {
444  triggerFired = triggerResults->accept(i);
445  hlt_exists = true;
446  break;
447  }
448  }
449  if (!hlt_exists) {
450  LogDebug("HLTriggerOfflineHeavyFlavor") << triggerResultsTag << " has no trigger: " << triggerPathName << endl;
451  }
452  } else {
453  LogDebug("HLTriggerOfflineHeavyFlavor") << "Could not initialize " << triggerResultsTag << endl;
454  }
455 
456  //create matching maps
457  vector<int> glob_gen(genMuons.size(), -1);
458  match(ME["globGen_deltaEtaDeltaPhi"], genMuons, globMuons, genGlobDeltaRMatchingCut, glob_gen);
459  vector<vector<int> > filt_glob;
460  vector<int> path_glob(globMuons.size(), -1);
461  if ((filterNamesLevels.end() - 1)->second == 1) {
462  match(ME["pathGlob_deltaEtaDeltaPhi"], globMuons_position, pathMuons, globL1DeltaRMatchingCut, path_glob);
463  } else if ((filterNamesLevels.end() - 1)->second == 2) {
464  match(ME["pathGlob_deltaEtaDeltaPhi"], globMuons, pathMuons, globL2DeltaRMatchingCut, path_glob);
465  } else if ((filterNamesLevels.end() - 1)->second > 2) {
466  match(ME["pathGlob_deltaEtaDeltaPhi"], globMuons, pathMuons, globL3DeltaRMatchingCut, path_glob);
467  }
468 
469  //fill histos
470  bool first = true;
471  for (size_t i = 0; i < genMuons.size(); i++) {
472  ME["genMuon_genEtaPt"]->Fill(genMuons[i].eta(), genMuons[i].pt());
473  ME["genMuon_genEtaPhi"]->Fill(genMuons[i].eta(), genMuons[i].phi());
474  if (glob_gen[i] != -1) {
475  ME["resGlobGen_genEtaPt"]->Fill(
476  genMuons[i].eta(), genMuons[i].pt(), (globMuons[glob_gen[i]].pt() - genMuons[i].pt()) / genMuons[i].pt());
477  ME["globMuon_genEtaPt"]->Fill(genMuons[i].eta(), genMuons[i].pt());
478  ME["globMuon_genEtaPhi"]->Fill(genMuons[i].eta(), genMuons[i].phi());
479  ME["globMuon_recoEtaPt"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].pt());
480  ME["globMuon_recoEtaPhi"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].phi());
481  if (path_glob[glob_gen[i]] != -1) {
482  ME["resPathGlob_recoEtaPt"]->Fill(
483  globMuons[glob_gen[i]].eta(),
484  globMuons[glob_gen[i]].pt(),
485  (pathMuons[path_glob[glob_gen[i]]].pt() - globMuons[glob_gen[i]].pt()) / globMuons[glob_gen[i]].pt());
486  ME["pathMuon_recoEtaPt"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].pt());
487  ME["pathMuon_recoEtaPhi"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].phi());
488  }
489  //highest pt muon
490  if (first) {
491  first = false;
492  if (triggerFired) {
493  ME["resultMuon_recoEtaPt"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].pt());
494  ME["resultMuon_recoEtaPhi"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].phi());
495  }
496  }
497  }
498  }
499 
500  //fill dimuon histograms (highest pT, opposite charge)
501  int secondMuon = 0;
502  for (size_t j = 1; j < genMuons.size(); j++) {
503  if (genMuons[0].charge() * genMuons[j].charge() == -1) {
504  secondMuon = j;
505  break;
506  }
507  }
508  if (secondMuon > 0) {
509  //two generated
510  double genDimuonPt = (genMuons[0].p4() + genMuons[secondMuon].p4()).pt();
511  double genDimuonEta = (genMuons[0].p4() + genMuons[secondMuon].p4()).eta();
512  double genDimuonRap = (genMuons[0].p4() + genMuons[secondMuon].p4()).Rapidity();
513  double genDimuonDR = deltaR<LeafCandidate, LeafCandidate>(genMuons[0], genMuons[secondMuon]);
514  bool highPt = genMuons[0].pt() > 7. && genMuons[secondMuon].pt() > 7;
515  ME["genDimuon_genEtaPt"]->Fill(genDimuonEta, genDimuonPt);
516  ME["genDimuon_genRapPt"]->Fill(genDimuonRap, genDimuonPt);
517  if (highPt)
518  ME["genDimuon_genPtDR"]->Fill(genDimuonPt, genDimuonDR);
519  //two global
520  if (glob_gen[0] != -1 && glob_gen[secondMuon] != -1) {
521  ME["globDimuon_genEtaPt"]->Fill(genDimuonEta, genDimuonPt);
522  ME["globDimuon_genRapPt"]->Fill(genDimuonRap, genDimuonPt);
523  if (highPt)
524  ME["globDimuon_genPtDR"]->Fill(genDimuonPt, genDimuonDR);
525  double globDimuonPt = (globMuons[glob_gen[0]].p4() + globMuons[glob_gen[secondMuon]].p4()).pt();
526  double globDimuonEta = (globMuons[glob_gen[0]].p4() + globMuons[glob_gen[secondMuon]].p4()).eta();
527  double globDimuonRap = (globMuons[glob_gen[0]].p4() + globMuons[glob_gen[secondMuon]].p4()).Rapidity();
528  double globDimuonDR =
529  deltaR<LeafCandidate, LeafCandidate>(globMuons[glob_gen[0]], globMuons[glob_gen[secondMuon]]);
530  double globDimuonDRpos = deltaR<LeafCandidate, LeafCandidate>(globMuons_position[glob_gen[0]],
531  globMuons_position[glob_gen[secondMuon]]);
532  ME["globDimuon_recoEtaPt"]->Fill(globDimuonEta, globDimuonPt);
533  ME["globDimuon_recoRapPt"]->Fill(globDimuonRap, globDimuonPt);
534  if (highPt)
535  ME["globDimuon_recoPtDR"]->Fill(globDimuonPt, globDimuonDR);
536  if (highPt)
537  ME["globDimuon_recoPtDRpos"]->Fill(globDimuonPt, globDimuonDRpos);
538  if (path_glob[glob_gen[0]] != -1 && path_glob[glob_gen[secondMuon]] != -1) {
539  ME["diPathDimuon_recoEtaPt"]->Fill(globDimuonEta, globDimuonPt);
540  ME["diPathDimuon_recoRapPt"]->Fill(globDimuonRap, globDimuonPt);
541  if (highPt)
542  ME["diPathDimuon_recoPtDR"]->Fill(globDimuonPt, globDimuonDR);
543  if (highPt)
544  ME["diPathDimuon_recoPtDRpos"]->Fill(globDimuonPt, globDimuonDRpos);
545  }
546  //one path object
547  if (path_glob[glob_gen[0]] != -1 || path_glob[glob_gen[secondMuon]] != -1) {
548  ME["pathDimuon_recoEtaPt"]->Fill(globDimuonEta, globDimuonPt);
549  ME["pathDimuon_recoRapPt"]->Fill(globDimuonRap, globDimuonPt);
550  if (highPt)
551  ME["pathDimuon_recoPtDR"]->Fill(globDimuonPt, globDimuonDR);
552  if (highPt)
553  ME["pathDimuon_recoPtDRpos"]->Fill(globDimuonPt, globDimuonDRpos);
554  }
555  //trigger result
556  if (triggerFired) {
557  ME["resultDimuon_recoEtaPt"]->Fill(globDimuonEta, globDimuonPt);
558  ME["resultDimuon_recoRapPt"]->Fill(globDimuonRap, globDimuonPt);
559  if (highPt)
560  ME["resultDimuon_recoPtDR"]->Fill(globDimuonPt, globDimuonDR);
561  if (highPt)
562  ME["resultDimuon_recoPtDRpos"]->Fill(globDimuonPt, globDimuonDRpos);
563  }
564  }
565  }
566 }
567 
569  const Candidate *mother = p->mother();
570  if (mother) {
571  if (mother->pdgId() == p->pdgId()) {
572  return getMotherId(mother);
573  } else {
574  return mother->pdgId();
575  }
576  } else {
577  return 0;
578  }
579 }
580 
582  vector<LeafCandidate> &from,
583  vector<LeafCandidate> &to,
584  double dRMatchingCut,
585  vector<int> &map) {
586  vector<double> dR(from.size());
587  for (size_t i = 0; i < from.size(); i++) {
588  map[i] = -1;
589  dR[i] = 10.;
590  //find closest
591  for (size_t j = 0; j < to.size(); j++) {
592  double dRtmp = deltaR<double>(from[i].eta(), from[i].phi(), to[j].eta(), to[j].phi());
593  if (dRtmp < dR[i]) {
594  dR[i] = dRtmp;
595  map[i] = j;
596  }
597  }
598  //fill matching histo
599  if (map[i] != -1) {
600  me->Fill(to[map[i]].eta() - from[i].eta(), deltaPhi<double>(to[map[i]].phi(), from[i].phi()));
601  }
602  //apply matching cut
603  if (dR[i] > dRMatchingCut) {
604  map[i] = -1;
605  }
606  //remove duplication
607  if (map[i] != -1) {
608  for (size_t k = 0; k < i; k++) {
609  if (map[k] != -1 && map[i] == map[k]) {
610  if (dR[i] < dR[k]) {
611  map[k] = -1;
612  } else {
613  map[i] = -1;
614  }
615  break;
616  }
617  }
618  }
619  }
620 }
621 
623  TString name,
624  vector<double> &ptBins,
625  TString ptLabel,
626  vector<double> &etaBins,
627  TString etaLabel,
628  TString title) {
629  // dqmStore->setCurrentFolder(dqmFolder+"/"+folder);
630  int ptN = ptBins.size() == 3 ? (int)ptBins[0] + 1 : ptBins.size();
631  Double_t *pt = new Double_t[ptN];
632  for (int i = 0; i < ptN; i++) {
633  pt[i] = ptBins.size() == 3 ? ptBins[1] + i * (ptBins[2] - ptBins[1]) / ptBins[0] : ptBins[i];
634  }
635  int etaN = etaBins.size() == 3 ? (int)etaBins[0] + 1 : etaBins.size();
636  Double_t *eta = new Double_t[etaN];
637  for (int i = 0; i < etaN; i++) {
638  eta[i] = etaBins.size() == 3 ? etaBins[1] + i * (etaBins[2] - etaBins[1]) / etaBins[0] : etaBins[i];
639  }
640  TH2F *h = new TH2F(name, name, ptN - 1, pt, etaN - 1, eta);
641  h->SetXTitle(ptLabel);
642  h->SetYTitle(etaLabel);
643  h->SetTitle(title);
644  ME[name] = ibooker.book2D(name.Data(), h);
645  delete h;
646 }
647 
649  TString name,
650  vector<double> &ptBins,
651  TString ptLabel,
652  vector<double> &etaBins,
653  TString etaLabel,
654  TString title) {
655  // dqmStore->setCurrentFolder(dqmFolder+"/"+folder);
656  int ptN = ptBins.size() == 3 ? (int)ptBins[0] + 1 : ptBins.size();
657  Double_t *pt = new Double_t[ptN];
658  for (int i = 0; i < ptN; i++) {
659  pt[i] = ptBins.size() == 3 ? ptBins[1] + i * (ptBins[2] - ptBins[1]) / ptBins[0] : ptBins[i];
660  }
661  int etaN = etaBins.size() == 3 ? (int)etaBins[0] + 1 : etaBins.size();
662  Double_t *eta = new Double_t[etaN];
663  for (int i = 0; i < etaN; i++) {
664  eta[i] = etaBins.size() == 3 ? etaBins[1] + i * (etaBins[2] - etaBins[1]) / etaBins[0] : etaBins[i];
665  }
666  TProfile2D *h = new TProfile2D(name, name, ptN - 1, pt, etaN - 1, eta);
667  h->SetXTitle(ptLabel);
668  h->SetYTitle(etaLabel);
669  h->SetTitle(title);
670  ME[name] = ibooker.bookProfile2D(name.Data(), h);
671  delete h;
672 }
673 
675  DQMStore::IBooker &ibooker, TString name, vector<double> &bins, TString label, TString title) {
676  // dqmStore->setCurrentFolder(dqmFolder+"/"+folder);
677  int binsN = bins.size() == 3 ? (int)bins[0] + 1 : bins.size();
678  Double_t *myBins = new Double_t[binsN];
679  for (int i = 0; i < binsN; i++) {
680  myBins[i] = bins.size() == 3 ? bins[1] + i * (bins[2] - bins[1]) / bins[0] : bins[i];
681  }
682  TH1F *h = new TH1F(name, name, binsN - 1, myBins);
683  h->SetXTitle(label);
684  h->SetTitle(title);
685  ME[name] = ibooker.book1D(name.Data(), h);
686  delete h;
687 }
688 
690  // helper lambda to check if a string contains a substring
691  const auto contains = [](const std::string &s, const std::string &sub) -> bool {
692  return s.find(sub) != std::string::npos;
693  };
694 
695  // helper lambda to check if a string contains any of a list of substrings
696  const auto containsAny = [](const std::string &s, const std::vector<std::string> &subs) -> bool {
697  for (const auto &sub : subs) {
698  if (s.find(sub) != std::string::npos)
699  return true;
700  }
701  return false;
702  };
703 
704  // helper lambda to check if string s is any of the strings in vector ms
705  const auto isAnyOf = [](const std::string &s, const std::vector<std::string> &ms) -> bool {
706  for (const auto &m : ms) {
707  if (s == m)
708  return true;
709  }
710  return false;
711  };
712 
713  // tmadlener, 20.08.2017:
714  // define the valid module names for the different "levels", to add a little bit more stability
715  // to the checking compared to just doing some name matching.
716  // Note, that the name matching is not completely remved, since at level 4 and 5 some of the
717  // valid modules are the same, so that the name matching is still needed.
718  // With the current definition this yields the exact same levels as before, but weeds out some
719  // of the "false" positives at level 3 (naming matches also to some HLTMuonL1TFilter modules due to
720  // the 'forIterL3' in the name)
721  const std::string l1Filter = "HLTMuonL1TFilter";
722  const std::string l2Filter = "HLTMuonL2FromL1TPreFilter";
723  const std::vector<std::string> l3Filters = {"HLTMuonDimuonL3Filter", "HLTMuonL3PreFilter"};
724  const std::vector<std::string> l4Filters = {
725  "HLTDisplacedmumuFilter", "HLTDiMuonGlbTrkFilter", "HLTMuonTrackMassFilter"};
726  const std::vector<std::string> l5Filters = {"HLTmumutkFilter", "HLT2MuonMuonDZ", "HLTDisplacedmumuFilter"};
727 
728  if (contains(moduleName, "Filter") && hltConfig.moduleEDMType(moduleName) == "EDFilter") {
729  if (contains(moduleName, "L1") && !contains(moduleName, "ForIterL3") &&
730  hltConfig.moduleType(moduleName) == l1Filter) {
731  return 1;
732  }
733  if (contains(moduleName, "L2") && hltConfig.moduleType(moduleName) == l2Filter) {
734  return 2;
735  }
736  if (contains(moduleName, "L3") && isAnyOf(hltConfig.moduleType(moduleName), l3Filters)) {
737  return 3;
738  }
739  if (containsAny(moduleName, {"DisplacedmumuFilter", "DiMuon", "MuonL3Filtered", "TrackMassFiltered"}) &&
740  isAnyOf(hltConfig.moduleType(moduleName), l4Filters)) {
741  return 4;
742  }
743  if (containsAny(moduleName, {"Vertex", "Dz"}) && isAnyOf(hltConfig.moduleType(moduleName), l5Filters)) {
744  return 5;
745  }
746  }
747 
748  return -1;
749 }
750 
752 
753 //define this as a plug-in
size
Write out results.
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:118
MonitorElement * bookProfile2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:476
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:37
void myBook2D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString xLabel, vector< double > &yBins, TString yLabel, TString title)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void analyze(const edm::Event &, const edm::EventSetup &) override
enum start value shifted to 81 so as to avoid clashes with PDG codes
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:146
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const edm::InputTag filterTag(trigger::size_type index) const
Definition: TriggerEvent.h:108
std::vector< TPRegexp > filters
Definition: eve_filter.cc:22
int getFilterLevel(const std::string &moduleName, const HLTConfigProvider &hltConfig)
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
EDGetTokenT< TriggerEvent > triggerSummaryAODTag
example_stream void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
U second(std::pair< T, U > const &p)
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
Definition: ME.h:11
void myBookProfile2D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString xLabel, vector< double > &yBins, TString yLabel, TString title)
char const * label
int getMotherId(const Candidate *p)
int iEvent
Definition: GenABIO.cc:224
size_type filterIndex(const edm::InputTag &filterTag) const
index from tag
void match(MonitorElement *me, vector< LeafCandidate > &from, vector< LeafCandidate > &to, double deltaRMatchingCut, vector< int > &map)
EDGetTokenT< TriggerEventWithRefs > triggerSummaryRAWTag
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:101
void myBook1D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString label, TString title)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static std::string const triggerResults
Definition: EdmProvDump.cc:47
HeavyFlavorValidation(const edm::ParameterSet &)
virtual int pdgId() const =0
PDG identifier.
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
void myBook2D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString xLabel, vector< double > &yBins, TString yLabel)
EDGetTokenT< MuonCollection > recoMuonsToken
std::vector< size_type > Keys
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
bool isValid() const
Definition: HandleBase.h:70
EDGetTokenT< GenParticleCollection > genParticlesToken
fixed size matrix
HLT enums.
void myBookProfile2D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString xLabel, vector< double > &yBins, TString yLabel)
void myBook1D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString label)
EDGetTokenT< TriggerResults > triggerResultsToken
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
map< TString, MonitorElement * > ME
vector< pair< string, int > > filterNamesLevels
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
#define str(s)
Definition: Run.h:45
void getObjects(size_type filter, Vids &ids, VRphoton &photons) const
extract Ref<C>s for a specific filter and of specific physics type
#define LogDebug(id)