CMS 3D CMS Logo

L1TMuonDQMOffline.cc
Go to the documentation of this file.
1 
12 
13 #include <array>
14 
15 using namespace reco;
16 using namespace trigger;
17 using namespace edm;
18 using namespace std;
19 using namespace l1t;
20 
21 //__________RECO-GMT Muon Pair Helper Class____________________________
22 
24  const l1t::Muon* regMu,
26  bool useAtVtxCoord)
27  : m_muon(muon), m_regMu(regMu) {
28  if (m_regMu) {
29  if (useAtVtxCoord) {
32  } else {
33  m_gmtEta = m_regMu->eta();
34  m_gmtPhi = m_regMu->phi();
35  }
36  } else {
37  m_gmtEta = -5.;
38  m_gmtPhi = -5.;
39  }
40  if (m_muon) {
41  TrajectoryStateOnSurface trajectory = propagator.extrapolate(*m_muon);
42  if (trajectory.isValid()) {
43  m_eta = trajectory.globalPosition().eta();
44  m_phi = trajectory.globalPosition().phi();
45  } else {
46  m_eta = 999.;
47  m_phi = 999.;
48  }
49  } else {
50  m_eta = 999.;
51  m_phi = 999.;
52  }
53 };
54 
56  m_muon = muonGmtPair.m_muon;
57  m_regMu = muonGmtPair.m_regMu;
58 
59  m_gmtEta = muonGmtPair.m_gmtEta;
60  m_gmtPhi = muonGmtPair.m_gmtPhi;
61 
62  m_eta = muonGmtPair.m_eta;
63  m_phi = muonGmtPair.m_phi;
64 }
65 
66 double MuonGmtPair::dR() {
67  float dEta = m_regMu ? (m_gmtEta - m_eta) : 999.;
68  float dPhi = m_regMu ? reco::deltaPhi(m_gmtPhi, m_phi) : 999.;
69  return sqrt(dEta * dEta + dPhi * dPhi);
70 }
71 
73  if (std::abs(m_eta) < 0.83)
75  if (std::abs(m_eta) < 1.24)
77  if (std::abs(m_eta) < 2.4)
80 }
81 
84  return (gmtPt() - pt()) / pt();
86  return (pt() - gmtPt()) / gmtPt(); // (1/gmtPt - 1/pt) / (1/pt)
88  return (gmtCharge() * charge() * pt() - gmtPt()) /
89  gmtPt(); // (gmtCharge/gmtPt - charge/pt) / (charge/pt) with gmtCharge/charge = gmtCharge*charge
91  return reco::deltaPhi(gmtPhi(), m_phi);
93  return gmtEta() - m_eta;
95  return gmtCharge() - charge();
96  return -999.;
97 }
98 
101  return pt();
103  return m_phi;
105  return m_eta;
106  return -999.;
107 }
108 
109 //__________DQM_base_class_______________________________________________
111  : m_propagatorSetup(ps.getParameter<edm::ParameterSet>("muProp"), consumesCollector()),
112  m_effTypes({kEffPt, kEffPhi, kEffEta, kEffVtx}),
113  m_resTypes({kResPt, kResQOverPt, kResPhi, kResEta}),
114  m_etaRegions({kEtaRegionAll, kEtaRegionBmtf, kEtaRegionOmtf, kEtaRegionEmtf}),
115  m_qualLevelsRes({kQualAll}),
116  m_effStrings({{kEffPt, "pt"}, {kEffPhi, "phi"}, {kEffEta, "eta"}, {kEffVtx, "vtx"}}),
117  m_effLabelStrings({{kEffPt, "p_{T} (GeV)"}, {kEffPhi, "#phi"}, {kEffEta, "#eta"}, {kEffVtx, "# vertices"}}),
118  m_resStrings({{kResPt, "pt"},
119  {kRes1OverPt, "1overpt"},
120  {kResQOverPt, "qoverpt"},
121  {kResPhi, "phi"},
122  {kResEta, "eta"},
123  {kResCh, "charge"}}),
124  m_resLabelStrings({{kResPt, "(p_{T}^{L1} - p_{T}^{reco})/p_{T}^{reco}"},
125  {kRes1OverPt, "(p_{T}^{reco} - p_{T}^{L1})/p_{T}^{L1}"},
126  {kResQOverPt, "(q^{L1}*q^{reco}*p_{T}^{reco} - p_{T}^{L1})/p_{T}^{L1}"},
127  {kResPhi, "#phi_{L1} - #phi_{reco}"},
128  {kResEta, "#eta_{L1} - #eta_{reco}"},
129  {kResCh, "charge^{L1} - charge^{reco}"}}),
130  m_etaStrings({{kEtaRegionAll, "etaMin0_etaMax2p4"},
131  {kEtaRegionBmtf, "etaMin0_etaMax0p83"},
132  {kEtaRegionOmtf, "etaMin0p83_etaMax1p24"},
133  {kEtaRegionEmtf, "etaMin1p24_etaMax2p4"}}),
134  m_qualStrings(
135  {{kQualAll, "qualAll"}, {kQualOpen, "qualOpen"}, {kQualDouble, "qualDouble"}, {kQualSingle, "qualSingle"}}),
136  m_verbose(ps.getUntrackedParameter<bool>("verbose")),
137  m_HistFolder(ps.getUntrackedParameter<string>("histFolder")),
138  m_TagPtCut(ps.getUntrackedParameter<double>("tagPtCut")),
139  m_recoToL1PtCutFactor(ps.getUntrackedParameter<double>("recoToL1PtCutFactor")),
140  m_cutsVPSet(ps.getUntrackedParameter<std::vector<edm::ParameterSet>>("cuts")),
141  m_MuonInputTag(consumes<reco::MuonCollection>(ps.getUntrackedParameter<InputTag>("muonInputTag"))),
142  m_GmtInputTag(consumes<l1t::MuonBxCollection>(ps.getUntrackedParameter<InputTag>("gmtInputTag"))),
143  m_VtxInputTag(consumes<VertexCollection>(ps.getUntrackedParameter<InputTag>("vtxInputTag"))),
144  m_BsInputTag(consumes<BeamSpot>(ps.getUntrackedParameter<InputTag>("bsInputTag"))),
145  m_trigInputTag(consumes<trigger::TriggerEvent>(ps.getUntrackedParameter<InputTag>("trigInputTag"))),
146  m_trigProcess(ps.getUntrackedParameter<string>("trigProcess")),
147  m_trigProcess_token(consumes<edm::TriggerResults>(ps.getUntrackedParameter<InputTag>("trigProcess_token"))),
148  m_trigNames(ps.getUntrackedParameter<vector<string>>("triggerNames")),
149  m_effVsPtBins(ps.getUntrackedParameter<std::vector<double>>("efficiencyVsPtBins")),
150  m_effVsPhiBins(ps.getUntrackedParameter<std::vector<double>>("efficiencyVsPhiBins")),
151  m_effVsEtaBins(ps.getUntrackedParameter<std::vector<double>>("efficiencyVsEtaBins")),
152  m_effVsVtxBins(ps.getUntrackedParameter<std::vector<double>>("efficiencyVsVtxBins")),
153  m_useAtVtxCoord(ps.getUntrackedParameter<bool>("useL1AtVtxCoord")),
154  m_maxGmtMuonDR(0.3),
155  m_minTagProbeDR(0.5),
156  m_maxHltMuonDR(0.1) {
157  if (m_verbose)
158  edm::LogInfo("L1TMuonDQMOffline") << "____________ Storage initialization ____________ " << endl;
159 
160  for (const auto& cutsPSet : m_cutsVPSet) {
161  const auto qCut = cutsPSet.getUntrackedParameter<int>("qualCut");
162  QualLevel qLevel = kQualAll;
163  if (qCut > 11) {
164  qLevel = kQualSingle;
165  } else if (qCut > 7) {
166  qLevel = kQualDouble;
167  } else if (qCut > 3) {
168  qLevel = kQualOpen;
169  }
170  m_cuts.emplace_back(std::make_pair(cutsPSet.getUntrackedParameter<int>("ptCut"), qLevel));
171  }
172 }
173 
174 //_____________________________________________________________________
176 //----------------------------------------------------------------------
178  if (m_verbose)
179  edm::LogInfo("L1TMuonDQMOffline") << "Called beginRun." << endl;
180  bool changed = true;
181  m_hltConfig.init(run, iSetup, m_trigProcess, changed);
182 }
183 
184 //_____________________________________________________________________
186  //book histos
187  bookControlHistos(ibooker);
188  bookEfficiencyHistos(ibooker);
189  bookResolutionHistos(ibooker);
190 
191  vector<string>::const_iterator trigNamesIt = m_trigNames.begin();
192  vector<string>::const_iterator trigNamesEnd = m_trigNames.end();
193 
194  for (; trigNamesIt != trigNamesEnd; ++trigNamesIt) {
195  TString tNameTmp = TString(*trigNamesIt); // use TString as it handles regex
196  TRegexp tNamePattern = TRegexp(tNameTmp, true);
197  int tIndex = -1;
198 
199  for (unsigned ipath = 0; ipath < m_hltConfig.size(); ++ipath) {
200  TString tmpName = TString(m_hltConfig.triggerName(ipath));
201  if (tmpName.Contains(tNamePattern)) {
202  tIndex = int(ipath);
203  m_trigIndices.push_back(tIndex);
204  if (m_verbose)
205  edm::LogInfo("L1TMuonDQMOffline") << "Found trigger " << tmpName << " with index " << tIndex << endl;
206  }
207  }
208  if (tIndex < 0 && m_verbose)
209  edm::LogInfo("L1TMuonDQMOffline") << "Warning: Could not find trigger " << (*trigNamesIt) << endl;
210  }
211 }
212 
213 //_____________________________________________________________________
215  if (m_verbose)
216  edm::LogInfo("L1TMuonDQMOffline") << "\nProcessing new event in analyze" << endl;
217 
218  auto const propagator = m_propagatorSetup.init(eventSetup);
219 
221  iEvent.getByToken(m_MuonInputTag, muons);
223  iEvent.getByToken(m_BsInputTag, beamSpot);
225  iEvent.getByToken(m_VtxInputTag, vertex);
227  iEvent.getByToken(m_GmtInputTag, gmtCands);
228  Handle<edm::TriggerResults> trigResults;
229  iEvent.getByToken(m_trigProcess_token, trigResults);
231  iEvent.getByToken(m_trigInputTag, trigEvent);
232 
233  // Only process event if at least one trigger fired
234  bool pass_HLT = false;
235  for (const auto& tIndex : m_trigIndices) {
236  if (trigResults->accept(tIndex)) {
237  if (m_verbose)
238  edm::LogInfo("L1TMuonDQMOffline") << "Fired trigger " << m_hltConfig.triggerName(tIndex) << endl;
239  pass_HLT = true;
240  break;
241  }
242  }
243  if (not pass_HLT) {
244  if (m_verbose)
245  edm::LogInfo("L1TMuonDQMOffline") << "Did not fire any triggers - quitting" << endl;
246  return;
247  }
248 
249  const auto nVtx = getNVertices(vertex);
251 
253  getProbeMuons(trigResults, trigEvent); // CB add flag to run on orthogonal datasets (no T&P)
254 
255  getMuonGmtPairs(gmtCands, propagator);
256 
257  if (m_verbose)
258  edm::LogInfo("L1TMuonDQMOffline") << "Computing efficiencies with " << m_MuonGmtPairs.size() << " muonGmtPairs, "
259  << m_TightMuons.size() << " tight muons, " << m_ProbeMuons.size()
260  << " probe muons" << endl;
261 
262  vector<MuonGmtPair>::const_iterator muonGmtPairsIt = m_MuonGmtPairs.begin();
263  vector<MuonGmtPair>::const_iterator muonGmtPairsEnd = m_MuonGmtPairs.end();
264 
265  // To fill once for global eta and once for TF eta region of the L1T muon.
266  // The second entry is a placeholder and will be replaced by the TF eta region of the L1T muon.
267  std::array<EtaRegion, 2> regsToFill{{kEtaRegionAll, kEtaRegionAll}};
268 
269  for (; muonGmtPairsIt != muonGmtPairsEnd; ++muonGmtPairsIt) {
270  // Fill the resolution histograms
271  if ((muonGmtPairsIt->etaRegion() != kEtaRegionOut) && (muonGmtPairsIt->gmtPt() > 0)) {
272  regsToFill[1] = muonGmtPairsIt->etaRegion();
274  for (const auto var : m_resTypes) {
275  const auto varToFill = muonGmtPairsIt->getDeltaVar(var);
276  std::get<0>(histoKeyRes) = var;
277  // Fill for the global eta and for TF eta region that the probe muon is in
278  for (const auto regToFill : regsToFill) {
279  std::get<1>(histoKeyRes) = regToFill;
280  for (const auto qualLevel : m_qualLevelsRes) {
281  // This assumes that the qualLevel enum has increasing qualities
282  // HW quality levels can be 0, 4, 8, or 12
283  int qualCut = qualLevel * 4;
284  if (muonGmtPairsIt->gmtQual() >= qualCut) {
285  std::get<2>(histoKeyRes) = qualLevel;
286  m_ResolutionHistos[histoKeyRes]->Fill(varToFill);
287  if (m_verbose)
288  edm::LogInfo("L1TMuonDQMOffline")
289  << "Filled resolution histo[" << std::get<0>(histoKeyRes) << ", " << std::get<1>(histoKeyRes)
290  << ", " << std::get<2>(histoKeyRes) << "] with " << varToFill << endl;
291  }
292  }
293  }
294  }
295  }
296 
297  // Fill the efficiency numerator and denominator histograms
298  if (muonGmtPairsIt->etaRegion() != kEtaRegionOut) {
299  unsigned int cutsCounter = 0;
300  for (const auto& cut : m_cuts) {
301  const auto gmtPtCut = cut.first;
302  const auto qualLevel = cut.second;
303  const bool gmtAboveCut = (muonGmtPairsIt->gmtPt() > gmtPtCut);
304 
305  // default keys
306  m_histoKeyEffDenVarType histoKeyEffDenVar = {kEffPt, gmtPtCut, kEtaRegionAll};
307  m_histoKeyEffNumVarType histoKeyEffNumVar = {kEffPt, gmtPtCut, kEtaRegionAll, qualLevel};
308 
309  regsToFill[1] = muonGmtPairsIt->etaRegion();
310  for (const auto var : m_effTypes) {
311  if (var != kEffPt) {
312  if (muonGmtPairsIt->pt() < m_recoToL1PtCutFactor * gmtPtCut)
313  break; // efficiency at plateau
314  }
315  double varToFill;
316  if (var == kEffVtx) {
317  varToFill = static_cast<double>(nVtx);
318  } else {
319  varToFill = muonGmtPairsIt->getVar(var);
320  }
321  // Fill denominators
322  if (var == kEffEta) {
323  m_EfficiencyDenEtaHistos[gmtPtCut]->Fill(varToFill);
324  if (m_verbose)
325  edm::LogInfo("L1TMuonDQMOffline")
326  << "Filled eff denom eta histo[" << gmtPtCut << "] with " << varToFill << endl;
327  } else {
328  std::get<0>(histoKeyEffDenVar) = var;
329  // Fill for the global eta and for TF eta region that the probe muon is in
330  for (const auto regToFill : regsToFill) {
331  if (var == kEffPt) {
332  if (cutsCounter == 0) {
333  m_EfficiencyDenPtHistos[regToFill]->Fill(varToFill);
334  if (m_verbose)
335  edm::LogInfo("L1TMuonDQMOffline")
336  << "Filled eff denom pT histo[" << regToFill << "] with " << varToFill << endl;
337  }
338  } else {
339  std::get<2>(histoKeyEffDenVar) = regToFill;
340  m_EfficiencyDenVarHistos[histoKeyEffDenVar]->Fill(varToFill);
341  if (m_verbose)
342  edm::LogInfo("L1TMuonDQMOffline") << "Filled eff denom histo[" << std::get<0>(histoKeyEffDenVar)
343  << ", " << std::get<1>(histoKeyEffDenVar) << ", "
344  << std::get<2>(histoKeyEffDenVar) << "] with " << varToFill << endl;
345  }
346  }
347  }
348  // Fill numerators
349  std::get<0>(histoKeyEffNumVar) = var;
350  // This assumes that the qualLevel enum has increasing qualities
351  if (gmtAboveCut && muonGmtPairsIt->gmtQual() >= qualLevel * 4) {
352  if (var == kEffEta) {
353  m_histoKeyEffNumEtaType histoKeyEffNumEta = {gmtPtCut, qualLevel};
354  m_EfficiencyNumEtaHistos[histoKeyEffNumEta]->Fill(varToFill);
355  if (m_verbose)
356  edm::LogInfo("L1TMuonDQMOffline")
357  << "Filled eff num eta histo[" << std::get<0>(histoKeyEffNumEta) << ", "
358  << std::get<1>(histoKeyEffNumEta) << "] with " << varToFill << endl;
359  } else {
360  std::get<3>(histoKeyEffNumVar) = qualLevel;
361  // Fill for the global eta and for TF eta region that the probe muon is in
362  for (const auto regToFill : regsToFill) {
363  std::get<2>(histoKeyEffNumVar) = regToFill;
364  m_EfficiencyNumVarHistos[histoKeyEffNumVar]->Fill(varToFill);
365  if (m_verbose)
366  edm::LogInfo("L1TMuonDQMOffline")
367  << "Filled eff num histo[" << std::get<0>(histoKeyEffNumVar) << ", "
368  << std::get<1>(histoKeyEffNumVar) << ", " << std::get<2>(histoKeyEffNumVar) << ", "
369  << std::get<3>(histoKeyEffNumVar) << "] with " << varToFill << endl;
370  }
371  }
372  }
373  }
374  ++cutsCounter;
375  }
376  }
377  }
378 
379  if (m_verbose)
380  edm::LogInfo("L1TMuonDQMOffline") << "Computation finished" << endl;
381 }
382 
383 //_____________________________________________________________________
385  if (m_verbose)
386  edm::LogInfo("L1TMuonDQMOffline") << "Booking Control Plot Histos" << endl;
387 
388  ibooker.setCurrentFolder(m_HistFolder + "/control_variables");
389 
390  m_ControlHistos[kCtrlMuonGmtDeltaR] = ibooker.book1D("MuonGmtDeltaR", "MuonGmtDeltaR; #DeltaR", 50, 0., 0.5);
392  ibooker.book2D("NTightVsAll", "NTightVsAll; # muons; # tight muons", 20, -0.5, 19.5, 16, -0.5, 15.5);
394  ibooker.book2D("NProbesVsTight", "NProbesVsTight; # tight muons; # probe muons", 8, -0.5, 7.5, 8, -0.5, 7.5);
395 
396  m_ControlHistos[kCtrlTagPt] = ibooker.book1D("TagMuonPt", "TagMuonPt; p_{T}", 50, 0., 100.);
397  m_ControlHistos[kCtrlTagPhi] = ibooker.book1D("TagMuonPhi", "TagMuonPhi; #phi", 66, -3.3, 3.3);
398  m_ControlHistos[kCtrlTagEta] = ibooker.book1D("TagMuonEta", "TagMuonEta; #eta", 50, -2.5, 2.5);
399 
400  m_ControlHistos[kCtrlProbePt] = ibooker.book1D("ProbeMuonPt", "ProbeMuonPt; p_{T}", 50, 0., 100.);
401  m_ControlHistos[kCtrlProbePhi] = ibooker.book1D("ProbeMuonPhi", "ProbeMuonPhi; #phi", 66, -3.3, 3.3);
402  m_ControlHistos[kCtrlProbeEta] = ibooker.book1D("ProbeMuonEta", "ProbeMuonEta; #eta", 50, -2.5, 2.5);
403 
405  ibooker.book1D("TagMuonProbeMuonDeltaR", "TagMuonProbeMuonDeltaR; #DeltaR", 50, 0., 5.0);
406  m_ControlHistos[kCtrlTagHltDr] = ibooker.book1D("TagMuonHltDeltaR", "TagMuonHltDeltaR;#DeltaR", 55, 0., 0.11);
407 }
408 
409 //_____________________________________________________________________
411  ibooker.setCurrentFolder(m_HistFolder + "/numerators_and_denominators");
412 
413  for (const auto var : m_effTypes) {
414  auto histBins = getHistBinsEff(var);
415  // histograms for eta variable get a special treatment
416  if (var == kEffEta) {
417  for (const auto& cut : m_cuts) {
418  const auto gmtPtCut = cut.first;
419  const auto qualLevel = cut.second;
420  std::string name = "effDen_" + m_effStrings[var] + "_" + std::to_string(gmtPtCut);
421  m_EfficiencyDenEtaHistos[gmtPtCut] =
422  ibooker.book1D(name, name + ";" + m_effLabelStrings[var], histBins.size() - 1, &histBins[0]);
423  name = "effNum_" + m_effStrings[var] + "_" + std::to_string(gmtPtCut) + "_" + m_qualStrings[qualLevel];
424  m_histoKeyEffNumEtaType histoKeyEffNumEta = {gmtPtCut, qualLevel};
425  m_EfficiencyNumEtaHistos[histoKeyEffNumEta] =
426  ibooker.book1D(name, name + ";" + m_effLabelStrings[var], histBins.size() - 1, &histBins[0]);
427  }
428  } else {
429  for (const auto etaReg : m_etaRegions) {
430  // denominator histograms for pt variable get a special treatment
431  if (var == kEffPt) {
432  std::string name = "effDen_" + m_effStrings[var] + "_" + m_etaStrings[etaReg];
433  m_EfficiencyDenPtHistos[etaReg] =
434  ibooker.book1D(name, name + ";" + m_effLabelStrings[var], histBins.size() - 1, &histBins[0]);
435  } else {
436  for (const auto& cut : m_cuts) {
437  const int gmtPtCut = cut.first;
438  std::string name =
439  "effDen_" + m_effStrings[var] + "_" + std::to_string(gmtPtCut) + "_" + m_etaStrings[etaReg];
440  m_histoKeyEffDenVarType histoKeyEffDenVar = {var, gmtPtCut, etaReg};
441  m_EfficiencyDenVarHistos[histoKeyEffDenVar] =
442  ibooker.book1D(name, name + ";" + m_effLabelStrings[var], histBins.size() - 1, &histBins[0]);
443  }
444  }
445  for (const auto& cut : m_cuts) {
446  const auto gmtPtCut = cut.first;
447  const auto qualLevel = cut.second;
448  std::string name = "effNum_" + m_effStrings[var] + "_" + std::to_string(gmtPtCut) + "_" +
449  m_etaStrings[etaReg] + "_" + m_qualStrings[qualLevel];
450  m_histoKeyEffNumVarType histoKeyEffNum = {var, gmtPtCut, etaReg, qualLevel};
451  m_EfficiencyNumVarHistos[histoKeyEffNum] =
452  ibooker.book1D(name, name + ";" + m_effLabelStrings[var], histBins.size() - 1, &histBins[0]);
453  }
454  }
455  }
456  }
457 }
458 
460  if (m_verbose)
461  edm::LogInfo("L1TMuonDQMOffline") << "Booking Resolution Plot Histos" << endl;
462  ibooker.setCurrentFolder(m_HistFolder + "/resolution");
463 
464  for (const auto var : m_resTypes) {
465  auto nbins = std::get<0>(getHistBinsRes(var));
466  auto xmin = std::get<1>(getHistBinsRes(var));
467  auto xmax = std::get<2>(getHistBinsRes(var));
468  for (const auto etaReg : m_etaRegions) {
469  for (const auto qualLevel : m_qualLevelsRes) {
470  m_histoKeyResType histoKeyRes = {var, etaReg, qualLevel};
471  std::string name =
472  "resolution_" + m_resStrings[var] + "_" + m_etaStrings[etaReg] + "_" + m_qualStrings[qualLevel];
473  m_ResolutionHistos[histoKeyRes] = ibooker.book1D(name, name + ";" + m_resLabelStrings[var], nbins, xmin, xmax);
474  }
475  }
476  }
477 }
478 
479 //_____________________________________________________________________
481  unsigned int nVtx = 0;
482 
483  if (vertex.isValid()) {
484  for (const auto& vertexIt : *vertex) {
485  if (vertexIt.isValid() && !vertexIt.isFake()) {
486  ++nVtx;
487  }
488  }
489  }
490  return nVtx;
491 }
492 
493 //_____________________________________________________________________
495  Vertex::Point posVtx;
496  Vertex::Error errVtx;
497 
498  bool hasPrimaryVertex = false;
499 
500  if (vertex.isValid()) {
501  vector<Vertex>::const_iterator vertexIt = vertex->begin();
502  vector<Vertex>::const_iterator vertexEnd = vertex->end();
503 
504  for (; vertexIt != vertexEnd; ++vertexIt) {
505  if (vertexIt->isValid() && !vertexIt->isFake()) {
506  posVtx = vertexIt->position();
507  errVtx = vertexIt->error();
508  hasPrimaryVertex = true;
509  break;
510  }
511  }
512  }
513 
514  if (!hasPrimaryVertex) {
515  posVtx = beamSpot->position();
516  errVtx(0, 0) = beamSpot->BeamWidthX();
517  errVtx(1, 1) = beamSpot->BeamWidthY();
518  errVtx(2, 2) = beamSpot->sigmaZ();
519  }
520  const Vertex primaryVertex(posVtx, errVtx);
521  return primaryVertex;
522 }
523 
524 //_____________________________________________________________________
526  if (m_verbose)
527  edm::LogInfo("L1TMuonDQMOffline") << "Getting tight muons" << endl;
528  m_TightMuons.clear();
529  MuonCollection::const_iterator muonIt = muons->begin();
530  MuonCollection::const_iterator muonEnd = muons->end();
531 
532  for (; muonIt != muonEnd; ++muonIt) {
533  if (muon::isTightMuon((*muonIt), vertex)) {
534  m_TightMuons.push_back(&(*muonIt));
535  }
536  }
537  m_ControlHistos[kCtrlNTightVsAll]->Fill(muons->size(), m_TightMuons.size());
538 }
539 
540 //_____________________________________________________________________
543  if (m_verbose)
544  edm::LogInfo("L1TMuonDQMOffline") << "getting probe muons" << endl;
545  m_ProbeMuons.clear();
546  std::vector<const reco::Muon*> tagMuonsInHist;
547 
548  tagMuonsInHist.clear();
549 
550  vector<const reco::Muon*>::const_iterator probeCandIt = m_TightMuons.begin();
551  vector<const reco::Muon*>::const_iterator tightMuonsEnd = m_TightMuons.end();
552 
553  for (; probeCandIt != tightMuonsEnd; ++probeCandIt) {
554  bool isProbe = false;
555  vector<const reco::Muon*>::const_iterator tagCandIt = m_TightMuons.begin();
556  float deltar = 0.;
557 
558  for (; tagCandIt != tightMuonsEnd; ++tagCandIt) {
559  bool tagMuonAlreadyInHist = false;
560  bool tagHasTrig = false;
561  float eta = (*tagCandIt)->eta();
562  float phi = (*tagCandIt)->phi();
563  float pt = (*tagCandIt)->pt();
564  float dEta = eta - (*probeCandIt)->eta();
565  float dPhi = phi - (*probeCandIt)->phi();
566  deltar = sqrt(dEta * dEta + dPhi * dPhi);
567 
568  if ((*tagCandIt) == (*probeCandIt) || deltar < m_minTagProbeDR)
569  continue; // CB has a little bias for closed-by muons
570  auto matchHltDeltaR = matchHlt(trigEvent, (*tagCandIt));
571  tagHasTrig = (matchHltDeltaR < m_maxHltMuonDR) && (pt > m_TagPtCut);
572  isProbe |= tagHasTrig;
573  if (tagHasTrig) {
574  if (std::distance(m_TightMuons.begin(), m_TightMuons.end()) > 2) {
575  for (vector<const reco::Muon*>::const_iterator tagMuonsInHistIt = tagMuonsInHist.begin();
576  tagMuonsInHistIt != tagMuonsInHist.end();
577  ++tagMuonsInHistIt) {
578  if ((*tagCandIt) == (*tagMuonsInHistIt)) {
579  tagMuonAlreadyInHist = true;
580  break;
581  }
582  }
583  if (tagMuonAlreadyInHist == false)
584  tagMuonsInHist.push_back((*tagCandIt));
585  }
586  if (tagMuonAlreadyInHist == false) {
589  m_ControlHistos[kCtrlTagPt]->Fill(pt);
591  m_ControlHistos[kCtrlTagHltDr]->Fill(matchHltDeltaR);
592  }
593  }
594  }
595  if (isProbe)
596  m_ProbeMuons.push_back((*probeCandIt));
597  }
599 }
600 
601 //_____________________________________________________________________
603  PropagateToMuon const& propagator) {
604  m_MuonGmtPairs.clear();
605  if (m_verbose)
606  edm::LogInfo("L1TMuonDQMOffline") << "Getting muon GMT pairs" << endl;
607 
608  vector<const reco::Muon*>::const_iterator probeMuIt = m_ProbeMuons.begin();
609  vector<const reco::Muon*>::const_iterator probeMuEnd = m_ProbeMuons.end();
610 
612  l1t::MuonBxCollection::const_iterator gmtEnd = gmtCands->end(0);
613 
614  for (; probeMuIt != probeMuEnd; ++probeMuIt) {
615  MuonGmtPair pairBestCand((*probeMuIt), nullptr, propagator, m_useAtVtxCoord);
616 
617  // Fill the control histograms with the probe muon kinematic variables used
621 
622  gmtIt = gmtCands->begin(0); // use only on L1T muons from BX 0
623 
624  for (; gmtIt != gmtEnd; ++gmtIt) {
625  MuonGmtPair pairTmpCand((*probeMuIt), &(*gmtIt), propagator, m_useAtVtxCoord);
626 
627  if ((pairTmpCand.dR() < m_maxGmtMuonDR) && (pairTmpCand.dR() < pairBestCand.dR())) {
628  pairBestCand = pairTmpCand;
629  }
630  }
631  m_MuonGmtPairs.push_back(pairBestCand);
632  m_ControlHistos[kCtrlMuonGmtDeltaR]->Fill(pairBestCand.dR());
633  }
634 }
635 
636 //_____________________________________________________________________
638  double matchDeltaR = 9999;
639 
641 
642  vector<int>::const_iterator trigIndexIt = m_trigIndices.begin();
643  vector<int>::const_iterator trigIndexEnd = m_trigIndices.end();
644 
645  for (; trigIndexIt != trigIndexEnd; ++trigIndexIt) {
646  const vector<string> moduleLabels(m_hltConfig.moduleLabels(*trigIndexIt));
647  // For some reason various modules now come *after* "hltBoolEnd"
648  // Really just want module one index before "hltBoolEnd" - AWB 2022.09.28
649  // const unsigned moduleIndex = m_hltConfig.size((*trigIndexIt)) - 2;
650  unsigned int moduleIndex = 999999;
651  for (int ii = 0; ii < int(moduleLabels.size()); ii++) {
652  if (moduleLabels[ii] == "hltBoolEnd") {
653  moduleIndex = ii - 1;
654  break;
655  }
656  }
657  if (moduleIndex == 999999) {
658  edm::LogError("L1TMuonDQMOffline") << "Found no module label in trigger " << (*trigIndexIt) << endl;
659  continue;
660  }
661 
662  const unsigned hltFilterIndex = triggerEvent->filterIndex(InputTag(moduleLabels[moduleIndex], "", m_trigProcess));
663 
664  if (hltFilterIndex < triggerEvent->sizeFilters()) {
665  const Keys triggerKeys(triggerEvent->filterKeys(hltFilterIndex));
666  const Vids triggerVids(triggerEvent->filterIds(hltFilterIndex));
667  const unsigned nTriggers = triggerVids.size();
668 
669  for (size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
670  const TriggerObject trigObject = trigObjs[triggerKeys[iTrig]];
671  if (m_verbose)
672  edm::LogInfo("L1TMuonDQMOffline") << "Found trigObject with pt = " << trigObject.pt()
673  << ", eta = " << trigObject.eta() << ", phi = " << trigObject.phi() << endl;
674  if (m_verbose)
675  edm::LogInfo("L1TMuonDQMOffline") << "Compare to muon with pt = " << (*mu).pt() << ", eta = " << (*mu).eta()
676  << ", phi = " << (*mu).phi() << endl;
677  double dRtmp = deltaR((*mu), trigObject);
678  if (dRtmp < matchDeltaR)
679  matchDeltaR = dRtmp;
680  }
681  }
682  }
683  return matchDeltaR;
684 }
685 
687  if (eff == kEffPt) {
688  std::vector<float> effVsPtBins(m_effVsPtBins.begin(), m_effVsPtBins.end());
689  return effVsPtBins;
690  }
691  if (eff == kEffPhi) {
692  std::vector<float> effVsPhiBins(m_effVsPhiBins.begin(), m_effVsPhiBins.end());
693  return effVsPhiBins;
694  }
695  if (eff == kEffEta) {
696  std::vector<float> effVsEtaBins(m_effVsEtaBins.begin(), m_effVsEtaBins.end());
697  return effVsEtaBins;
698  }
699  if (eff == kEffVtx) {
700  std::vector<float> effVsVtxBins(m_effVsVtxBins.begin(), m_effVsVtxBins.end());
701  return effVsVtxBins;
702  }
703  return {0., 1.};
704 }
705 
706 std::tuple<int, double, double> L1TMuonDQMOffline::getHistBinsRes(ResType res) {
707  if (res == kResPt)
708  return {50, -2., 2.};
709  if (res == kRes1OverPt)
710  return {50, -2., 2.};
711  if (res == kResQOverPt)
712  return {50, -2., 2.};
713  if (res == kResPhi)
714  return {96, -0.2, 0.2};
715  if (res == kResEta)
716  return {100, -0.1, 0.1};
717  if (res == kResCh)
718  return {5, -2, 3};
719  return {1, 0, 1};
720 }
721 
722 //define this as a plug-in
std::map< EffType, std::string > m_effStrings
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
bool accept() const
Has at least one path accepted the event?
const std::string & triggerName(unsigned int triggerIndex) const
edm::EDGetTokenT< reco::BeamSpot > m_BsInputTag
edm::EDGetTokenT< reco::MuonCollection > m_MuonInputTag
std::vector< double > m_effVsVtxBins
std::map< ResType, std::string > m_resLabelStrings
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
std::map< EtaRegion, std::string > m_etaStrings
edm::EDGetTokenT< edm::TriggerResults > m_trigProcess_token
void analyze(const edm::Event &e, const edm::EventSetup &c) override
std::map< std::tuple< ResType, EtaRegion, QualLevel >, MonitorElement * > m_ResolutionHistos
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
const std::vector< EtaRegion > m_etaRegions
T eta() const
Definition: PV3DBase.h:73
std::vector< double > m_effVsPhiBins
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
std::string to_string(const V &value)
Definition: OMSAccess.h:77
std::map< EtaRegion, MonitorElement * > m_EfficiencyDenPtHistos
std::tuple< EffType, int, EtaRegion, QualLevel > m_histoKeyEffNumVarType
delete x;
Definition: CaloConfig.h:22
double getDeltaVar(const L1TMuonDQMOffline::ResType) const
std::string m_HistFolder
Log< level::Error, false > LogError
std::pair< int, QualLevel > m_histoKeyEffNumEtaType
Definition: Electron.h:6
std::tuple< ResType, EtaRegion, QualLevel > m_histoKeyResType
std::vector< const reco::Muon * > m_ProbeMuons
std::vector< float > getHistBinsEff(EffType eff)
void getProbeMuons(edm::Handle< edm::TriggerResults > &trigResults, edm::Handle< trigger::TriggerEvent > &trigEvent)
const unsigned int getNVertices(edm::Handle< reco::VertexCollection > &vertex)
~L1TMuonDQMOffline() override
std::vector< std::string > m_trigNames
const_iterator begin(int bx) const
virtual void bookControlHistos(DQMStore::IBooker &)
std::map< QualLevel, std::string > m_qualStrings
double matchHlt(edm::Handle< trigger::TriggerEvent > &triggerEvent, const reco::Muon *mu)
std::string m_trigProcess
double phiAtVtx() const
Definition: Muon.h:104
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:18
const l1t::Muon * m_regMu
int iEvent
Definition: GenABIO.cc:224
Propagate an object (usually a track) to the second (default) or first muon station.
std::map< EffType, std::string > m_effLabelStrings
GlobalPoint globalPosition() const
std::tuple< int, double, double > getHistBinsRes(ResType res)
unsigned int size() const
number of trigger paths in trigger table
edm::EDGetTokenT< l1t::MuonBxCollection > m_GmtInputTag
std::vector< double > m_effVsPtBins
void bookHistograms(DQMStore::IBooker &ibooker, const edm::Run &run, const edm::EventSetup &iSetup) override
T sqrt(T t)
Definition: SSEVec.h:19
std::tuple< EffType, int, EtaRegion > m_histoKeyEffDenVarType
std::map< std::pair< int, QualLevel >, MonitorElement * > m_EfficiencyNumEtaHistos
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
double pt() const
L1TMuonDQMOffline::EtaRegion etaRegion() const
double gmtPt() const
const reco::Muon * m_muon
PropagateToMuonSetup const m_propagatorSetup
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::map< int, MonitorElement * > m_EfficiencyDenEtaHistos
std::vector< std::pair< int, QualLevel > > m_cuts
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const std::vector< EffType > m_effTypes
const std::vector< QualLevel > m_qualLevelsRes
std::vector< MuonGmtPair > m_MuonGmtPairs
std::map< std::tuple< EffType, int, EtaRegion >, MonitorElement * > m_EfficiencyDenVarHistos
double gmtPhi() const
ii
Definition: cuy.py:589
Definition: Muon.h:21
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
Log< level::Info, false > LogInfo
L1TMuonDQMOffline(const edm::ParameterSet &ps)
std::map< ResType, std::string > m_resStrings
Definition: deltar.py:1
std::vector< size_type > Keys
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
double getVar(const L1TMuonDQMOffline::EffType) const
double gmtEta() const
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
virtual void bookResolutionHistos(DQMStore::IBooker &ibooker)
HLTConfigProvider m_hltConfig
const reco::Vertex getPrimaryVertex(edm::Handle< reco::VertexCollection > &vertex, edm::Handle< reco::BeamSpot > &beamSpot)
std::vector< double > m_effVsEtaBins
double etaAtVtx() const
Definition: Muon.h:103
std::vector< const reco::Muon * > m_TightMuons
const_iterator end(int bx) const
fixed size matrix
HLT enums.
const std::vector< ResType > m_resTypes
void dqmBeginRun(const edm::Run &run, const edm::EventSetup &iSetup) override
edm::EDGetTokenT< reco::VertexCollection > m_VtxInputTag
edm::EDGetTokenT< trigger::TriggerEvent > m_trigInputTag
std::map< std::tuple< EffType, int, EtaRegion, QualLevel >, MonitorElement * > m_EfficiencyNumVarHistos
int charge() const
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
double phi() const final
momentum azimuthal angle
primaryVertex
hltOfflineBeamSpot for HLTMON
MuonGmtPair(const reco::Muon *muon, const l1t::Muon *regMu, const PropagateToMuon &propagator, bool useAtVtxCoord)
std::map< Control, MonitorElement * > m_ControlHistos
void getMuonGmtPairs(edm::Handle< l1t::MuonBxCollection > &gmtCands, PropagateToMuon const &propagator)
std::vector< int > Vids
std::vector< int > m_trigIndices
int gmtCharge() const
Definition: Run.h:45
virtual void bookEfficiencyHistos(DQMStore::IBooker &ibooker)
void getTightMuons(edm::Handle< reco::MuonCollection > &muons, const reco::Vertex &vertex)
double eta() const final
momentum pseudorapidity