CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
83  if (type == L1TMuonDQMOffline::kResPt)
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
90  if (type == L1TMuonDQMOffline::kResPhi)
91  return reco::deltaPhi(gmtPhi(), m_phi);
92  if (type == L1TMuonDQMOffline::kResEta)
93  return gmtEta() - m_eta;
94  if (type == L1TMuonDQMOffline::kResCh)
95  return gmtCharge() - charge();
96  return -999.;
97 }
98 
100  if (type == L1TMuonDQMOffline::kEffPt)
101  return pt();
102  if (type == L1TMuonDQMOffline::kEffPhi)
103  return m_phi;
104  if (type == L1TMuonDQMOffline::kEffEta)
105  return m_eta;
106  return -999.;
107 }
108 
109 //__________DQM_base_class_______________________________________________
111  : m_propagator(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"}}),
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),
157  if (m_verbose)
158  cout << "[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  cout << "[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  }
205  }
206  if (tIndex < 0 && m_verbose)
207  cout << "[L1TMuonDQMOffline:] Warning: Could not find trigger " << (*trigNamesIt) << endl;
208  }
209 }
210 
211 //_____________________________________________________________________
212 void L1TMuonDQMOffline::analyze(const Event& iEvent, const EventSetup& eventSetup) {
213  m_propagator.init(eventSetup);
214 
216  iEvent.getByToken(m_MuonInputTag, muons);
218  iEvent.getByToken(m_BsInputTag, beamSpot);
220  iEvent.getByToken(m_VtxInputTag, vertex);
222  iEvent.getByToken(m_GmtInputTag, gmtCands);
223  Handle<edm::TriggerResults> trigResults;
224  iEvent.getByToken(m_trigProcess_token, trigResults);
226  iEvent.getByToken(m_trigInputTag, trigEvent);
227 
228  const auto nVtx = getNVertices(vertex);
229  const Vertex primaryVertex = getPrimaryVertex(vertex, beamSpot);
230 
231  getTightMuons(muons, primaryVertex);
232  getProbeMuons(trigResults, trigEvent); // CB add flag to run on orthogonal datasets (no T&P)
233 
234  getMuonGmtPairs(gmtCands);
235 
236  if (m_verbose)
237  cout << "[L1TMuonDQMOffline:] Computing efficiencies" << endl;
238 
239  vector<MuonGmtPair>::const_iterator muonGmtPairsIt = m_MuonGmtPairs.begin();
240  vector<MuonGmtPair>::const_iterator muonGmtPairsEnd = m_MuonGmtPairs.end();
241 
242  // To fill once for global eta and once for TF eta region of the L1T muon.
243  // The second entry is a placeholder and will be replaced by the TF eta region of the L1T muon.
244  std::array<EtaRegion, 2> regsToFill{{kEtaRegionAll, kEtaRegionAll}};
245 
246  for (; muonGmtPairsIt != muonGmtPairsEnd; ++muonGmtPairsIt) {
247  // Fill the resolution histograms
248  if ((muonGmtPairsIt->etaRegion() != kEtaRegionOut) && (muonGmtPairsIt->gmtPt() > 0)) {
249  regsToFill[1] = muonGmtPairsIt->etaRegion();
251  for (const auto var : m_resTypes) {
252  const auto varToFill = muonGmtPairsIt->getDeltaVar(var);
253  std::get<0>(histoKeyRes) = var;
254  // Fill for the global eta and for TF eta region that the probe muon is in
255  for (const auto regToFill : regsToFill) {
256  std::get<1>(histoKeyRes) = regToFill;
257  for (const auto qualLevel : m_qualLevelsRes) {
258  // This assumes that the qualLevel enum has increasing qualities
259  // HW quality levels can be 0, 4, 8, or 12
260  int qualCut = qualLevel * 4;
261  if (muonGmtPairsIt->gmtQual() >= qualCut) {
262  std::get<2>(histoKeyRes) = qualLevel;
263  m_ResolutionHistos[histoKeyRes]->Fill(varToFill);
264  }
265  }
266  }
267  }
268  }
269 
270  // Fill the efficiency numerator and denominator histograms
271  if (muonGmtPairsIt->etaRegion() != kEtaRegionOut) {
272  unsigned int cutsCounter = 0;
273  for (const auto& cut : m_cuts) {
274  const auto gmtPtCut = cut.first;
275  const auto qualLevel = cut.second;
276  const bool gmtAboveCut = (muonGmtPairsIt->gmtPt() > gmtPtCut);
277 
278  // default keys
279  m_histoKeyEffDenVarType histoKeyEffDenVar = {kEffPt, gmtPtCut, kEtaRegionAll};
280  m_histoKeyEffNumVarType histoKeyEffNumVar = {kEffPt, gmtPtCut, kEtaRegionAll, qualLevel};
281 
282  regsToFill[1] = muonGmtPairsIt->etaRegion();
283  for (const auto var : m_effTypes) {
284  if (var != kEffPt) {
285  if (muonGmtPairsIt->pt() < m_recoToL1PtCutFactor * gmtPtCut)
286  break; // efficiency at plateau
287  }
288  double varToFill;
289  if (var == kEffVtx) {
290  varToFill = static_cast<double>(nVtx);
291  } else {
292  varToFill = muonGmtPairsIt->getVar(var);
293  }
294  // Fill denominators
295  if (var == kEffEta) {
296  m_EfficiencyDenEtaHistos[gmtPtCut]->Fill(varToFill);
297  } else {
298  std::get<0>(histoKeyEffDenVar) = var;
299  // Fill for the global eta and for TF eta region that the probe muon is in
300  for (const auto regToFill : regsToFill) {
301  if (var == kEffPt) {
302  if (cutsCounter == 0) {
303  m_EfficiencyDenPtHistos[regToFill]->Fill(varToFill);
304  }
305  } else {
306  std::get<2>(histoKeyEffDenVar) = regToFill;
307  m_EfficiencyDenVarHistos[histoKeyEffDenVar]->Fill(varToFill);
308  }
309  }
310  }
311  // Fill numerators
312  std::get<0>(histoKeyEffNumVar) = var;
313  // This assumes that the qualLevel enum has increasing qualities
314  if (gmtAboveCut && muonGmtPairsIt->gmtQual() >= qualLevel * 4) {
315  if (var == kEffEta) {
316  m_histoKeyEffNumEtaType histoKeyEffNumEta = {gmtPtCut, qualLevel};
317  m_EfficiencyNumEtaHistos[histoKeyEffNumEta]->Fill(varToFill);
318  } else {
319  std::get<3>(histoKeyEffNumVar) = qualLevel;
320  // Fill for the global eta and for TF eta region that the probe muon is in
321  for (const auto regToFill : regsToFill) {
322  std::get<2>(histoKeyEffNumVar) = regToFill;
323  m_EfficiencyNumVarHistos[histoKeyEffNumVar]->Fill(varToFill);
324  }
325  }
326  }
327  }
328  ++cutsCounter;
329  }
330  }
331  }
332 
333  if (m_verbose)
334  cout << "[L1TMuonDQMOffline:] Computation finished" << endl;
335 }
336 
337 //_____________________________________________________________________
339  if (m_verbose)
340  cout << "[L1TMuonDQMOffline:] Booking Control Plot Histos" << endl;
341 
342  ibooker.setCurrentFolder(m_HistFolder + "/control_variables");
343 
344  m_ControlHistos[kCtrlMuonGmtDeltaR] = ibooker.book1D("MuonGmtDeltaR", "MuonGmtDeltaR; #DeltaR", 50, 0., 0.5);
346  ibooker.book2D("NTightVsAll", "NTightVsAll; # muons; # tight muons", 20, -0.5, 19.5, 16, -0.5, 15.5);
348  ibooker.book2D("NProbesVsTight", "NProbesVsTight; # tight muons; # probe muons", 8, -0.5, 7.5, 8, -0.5, 7.5);
349 
350  m_ControlHistos[kCtrlTagPt] = ibooker.book1D("TagMuonPt", "TagMuonPt; p_{T}", 50, 0., 100.);
351  m_ControlHistos[kCtrlTagPhi] = ibooker.book1D("TagMuonPhi", "TagMuonPhi; #phi", 66, -3.3, 3.3);
352  m_ControlHistos[kCtrlTagEta] = ibooker.book1D("TagMuonEta", "TagMuonEta; #eta", 50, -2.5, 2.5);
353 
354  m_ControlHistos[kCtrlProbePt] = ibooker.book1D("ProbeMuonPt", "ProbeMuonPt; p_{T}", 50, 0., 100.);
355  m_ControlHistos[kCtrlProbePhi] = ibooker.book1D("ProbeMuonPhi", "ProbeMuonPhi; #phi", 66, -3.3, 3.3);
356  m_ControlHistos[kCtrlProbeEta] = ibooker.book1D("ProbeMuonEta", "ProbeMuonEta; #eta", 50, -2.5, 2.5);
357 
359  ibooker.book1D("TagMuonProbeMuonDeltaR", "TagMuonProbeMuonDeltaR; #DeltaR", 50, 0., 5.0);
360  m_ControlHistos[kCtrlTagHltDr] = ibooker.book1D("TagMuonHltDeltaR", "TagMuonHltDeltaR;#DeltaR", 55, 0., 0.11);
361 }
362 
363 //_____________________________________________________________________
365  ibooker.setCurrentFolder(m_HistFolder + "/numerators_and_denominators");
366 
367  for (const auto var : m_effTypes) {
368  auto histBins = getHistBinsEff(var);
369  // histograms for eta variable get a special treatment
370  if (var == kEffEta) {
371  for (const auto& cut : m_cuts) {
372  const auto gmtPtCut = cut.first;
373  const auto qualLevel = cut.second;
374  std::string name = "effDen_" + m_effStrings[var] + "_" + std::to_string(gmtPtCut);
375  m_EfficiencyDenEtaHistos[gmtPtCut] =
376  ibooker.book1D(name, name + ";" + m_effLabelStrings[var], histBins.size() - 1, &histBins[0]);
377  name = "effNum_" + m_effStrings[var] + "_" + std::to_string(gmtPtCut) + "_" + m_qualStrings[qualLevel];
378  m_histoKeyEffNumEtaType histoKeyEffNumEta = {gmtPtCut, qualLevel};
379  m_EfficiencyNumEtaHistos[histoKeyEffNumEta] =
380  ibooker.book1D(name, name + ";" + m_effLabelStrings[var], histBins.size() - 1, &histBins[0]);
381  }
382  } else {
383  for (const auto etaReg : m_etaRegions) {
384  // denominator histograms for pt variable get a special treatment
385  if (var == kEffPt) {
386  std::string name = "effDen_" + m_effStrings[var] + "_" + m_etaStrings[etaReg];
387  m_EfficiencyDenPtHistos[etaReg] =
388  ibooker.book1D(name, name + ";" + m_effLabelStrings[var], histBins.size() - 1, &histBins[0]);
389  } else {
390  for (const auto& cut : m_cuts) {
391  const int gmtPtCut = cut.first;
392  std::string name =
393  "effDen_" + m_effStrings[var] + "_" + std::to_string(gmtPtCut) + "_" + m_etaStrings[etaReg];
394  m_histoKeyEffDenVarType histoKeyEffDenVar = {var, gmtPtCut, etaReg};
395  m_EfficiencyDenVarHistos[histoKeyEffDenVar] =
396  ibooker.book1D(name, name + ";" + m_effLabelStrings[var], histBins.size() - 1, &histBins[0]);
397  }
398  }
399  for (const auto& cut : m_cuts) {
400  const auto gmtPtCut = cut.first;
401  const auto qualLevel = cut.second;
402  std::string name = "effNum_" + m_effStrings[var] + "_" + std::to_string(gmtPtCut) + "_" +
403  m_etaStrings[etaReg] + "_" + m_qualStrings[qualLevel];
404  m_histoKeyEffNumVarType histoKeyEffNum = {var, gmtPtCut, etaReg, qualLevel};
405  m_EfficiencyNumVarHistos[histoKeyEffNum] =
406  ibooker.book1D(name, name + ";" + m_effLabelStrings[var], histBins.size() - 1, &histBins[0]);
407  }
408  }
409  }
410  }
411 }
412 
414  if (m_verbose)
415  cout << "[L1TMuonOffline:] Booking Resolution Plot Histos" << endl;
416  ibooker.setCurrentFolder(m_HistFolder + "/resolution");
417 
418  for (const auto var : m_resTypes) {
419  auto nbins = std::get<0>(getHistBinsRes(var));
420  auto xmin = std::get<1>(getHistBinsRes(var));
421  auto xmax = std::get<2>(getHistBinsRes(var));
422  for (const auto etaReg : m_etaRegions) {
423  for (const auto qualLevel : m_qualLevelsRes) {
424  m_histoKeyResType histoKeyRes = {var, etaReg, qualLevel};
425  std::string name =
426  "resolution_" + m_resStrings[var] + "_" + m_etaStrings[etaReg] + "_" + m_qualStrings[qualLevel];
427  m_ResolutionHistos[histoKeyRes] = ibooker.book1D(name, name + ";" + m_resLabelStrings[var], nbins, xmin, xmax);
428  }
429  }
430  }
431 }
432 
433 //_____________________________________________________________________
435  unsigned int nVtx = 0;
436 
437  if (vertex.isValid()) {
438  for (const auto& vertexIt : *vertex) {
439  if (vertexIt.isValid() && !vertexIt.isFake()) {
440  ++nVtx;
441  }
442  }
443  }
444  return nVtx;
445 }
446 
447 //_____________________________________________________________________
449  Vertex::Point posVtx;
450  Vertex::Error errVtx;
451 
452  bool hasPrimaryVertex = false;
453 
454  if (vertex.isValid()) {
455  vector<Vertex>::const_iterator vertexIt = vertex->begin();
456  vector<Vertex>::const_iterator vertexEnd = vertex->end();
457 
458  for (; vertexIt != vertexEnd; ++vertexIt) {
459  if (vertexIt->isValid() && !vertexIt->isFake()) {
460  posVtx = vertexIt->position();
461  errVtx = vertexIt->error();
462  hasPrimaryVertex = true;
463  break;
464  }
465  }
466  }
467 
468  if (!hasPrimaryVertex) {
469  posVtx = beamSpot->position();
470  errVtx(0, 0) = beamSpot->BeamWidthX();
471  errVtx(1, 1) = beamSpot->BeamWidthY();
472  errVtx(2, 2) = beamSpot->sigmaZ();
473  }
474  const Vertex primaryVertex(posVtx, errVtx);
475  return primaryVertex;
476 }
477 
478 //_____________________________________________________________________
480  if (m_verbose)
481  cout << "[L1TMuonDQMOffline:] Getting tight muons" << endl;
482  m_TightMuons.clear();
483  MuonCollection::const_iterator muonIt = muons->begin();
484  MuonCollection::const_iterator muonEnd = muons->end();
485 
486  for (; muonIt != muonEnd; ++muonIt) {
487  if (muon::isTightMuon((*muonIt), vertex)) {
488  m_TightMuons.push_back(&(*muonIt));
489  }
490  }
491  m_ControlHistos[kCtrlNTightVsAll]->Fill(muons->size(), m_TightMuons.size());
492 }
493 
494 //_____________________________________________________________________
497  if (m_verbose)
498  cout << "[L1TMuonDQMOffline:] getting probe muons" << endl;
499  m_ProbeMuons.clear();
500  std::vector<const reco::Muon*> tagMuonsInHist;
501 
502  tagMuonsInHist.clear();
503 
504  vector<const reco::Muon*>::const_iterator probeCandIt = m_TightMuons.begin();
505  vector<const reco::Muon*>::const_iterator tightMuonsEnd = m_TightMuons.end();
506 
507  for (; probeCandIt != tightMuonsEnd; ++probeCandIt) {
508  bool isProbe = false;
509  vector<const reco::Muon*>::const_iterator tagCandIt = m_TightMuons.begin();
510  float deltar = 0.;
511 
512  for (; tagCandIt != tightMuonsEnd; ++tagCandIt) {
513  bool tagMuonAlreadyInHist = false;
514  bool tagHasTrig = false;
515  float eta = (*tagCandIt)->eta();
516  float phi = (*tagCandIt)->phi();
517  float pt = (*tagCandIt)->pt();
518  float dEta = eta - (*probeCandIt)->eta();
519  float dPhi = phi - (*probeCandIt)->phi();
520  deltar = sqrt(dEta * dEta + dPhi * dPhi);
521 
522  if ((*tagCandIt) == (*probeCandIt) || deltar < m_minTagProbeDR)
523  continue; // CB has a little bias for closed-by muons
524  auto matchHltDeltaR = matchHlt(trigEvent, (*tagCandIt));
525  tagHasTrig = (matchHltDeltaR < m_maxHltMuonDR) && (pt > m_TagPtCut);
526  isProbe |= tagHasTrig;
527  if (tagHasTrig) {
528  if (std::distance(m_TightMuons.begin(), m_TightMuons.end()) > 2) {
529  for (vector<const reco::Muon*>::const_iterator tagMuonsInHistIt = tagMuonsInHist.begin();
530  tagMuonsInHistIt != tagMuonsInHist.end();
531  ++tagMuonsInHistIt) {
532  if ((*tagCandIt) == (*tagMuonsInHistIt)) {
533  tagMuonAlreadyInHist = true;
534  break;
535  }
536  }
537  if (tagMuonAlreadyInHist == false)
538  tagMuonsInHist.push_back((*tagCandIt));
539  }
540  if (tagMuonAlreadyInHist == false) {
541  m_ControlHistos[kCtrlTagEta]->Fill(eta);
542  m_ControlHistos[kCtrlTagPhi]->Fill(phi);
543  m_ControlHistos[kCtrlTagPt]->Fill(pt);
544  m_ControlHistos[kCtrlTagProbeDr]->Fill(deltar);
545  m_ControlHistos[kCtrlTagHltDr]->Fill(matchHltDeltaR);
546  }
547  }
548  }
549  if (isProbe)
550  m_ProbeMuons.push_back((*probeCandIt));
551  }
553 }
554 
555 //_____________________________________________________________________
557  m_MuonGmtPairs.clear();
558  if (m_verbose)
559  cout << "[L1TMuonDQMOffline:] Getting muon GMT pairs" << endl;
560 
561  vector<const reco::Muon*>::const_iterator probeMuIt = m_ProbeMuons.begin();
562  vector<const reco::Muon*>::const_iterator probeMuEnd = m_ProbeMuons.end();
563 
565  l1t::MuonBxCollection::const_iterator gmtEnd = gmtCands->end(0);
566 
567  for (; probeMuIt != probeMuEnd; ++probeMuIt) {
568  MuonGmtPair pairBestCand((*probeMuIt), nullptr, m_propagator, m_useAtVtxCoord);
569 
570  // Fill the control histograms with the probe muon kinematic variables used
574 
575  gmtIt = gmtCands->begin(0); // use only on L1T muons from BX 0
576 
577  for (; gmtIt != gmtEnd; ++gmtIt) {
578  MuonGmtPair pairTmpCand((*probeMuIt), &(*gmtIt), m_propagator, m_useAtVtxCoord);
579 
580  if ((pairTmpCand.dR() < m_maxGmtMuonDR) && (pairTmpCand.dR() < pairBestCand.dR())) {
581  pairBestCand = pairTmpCand;
582  }
583  }
584  m_MuonGmtPairs.push_back(pairBestCand);
585  m_ControlHistos[kCtrlMuonGmtDeltaR]->Fill(pairBestCand.dR());
586  }
587 }
588 
589 //_____________________________________________________________________
591  double matchDeltaR = 9999;
592 
593  TriggerObjectCollection trigObjs = triggerEvent->getObjects();
594 
595  vector<int>::const_iterator trigIndexIt = m_trigIndices.begin();
596  vector<int>::const_iterator trigIndexEnd = m_trigIndices.end();
597 
598  for (; trigIndexIt != trigIndexEnd; ++trigIndexIt) {
599  const vector<string> moduleLabels(m_hltConfig.moduleLabels(*trigIndexIt));
600  const unsigned moduleIndex = m_hltConfig.size((*trigIndexIt)) - 2;
601  const unsigned hltFilterIndex = triggerEvent->filterIndex(InputTag(moduleLabels[moduleIndex], "", m_trigProcess));
602 
603  if (hltFilterIndex < triggerEvent->sizeFilters()) {
604  const Keys triggerKeys(triggerEvent->filterKeys(hltFilterIndex));
605  const Vids triggerVids(triggerEvent->filterIds(hltFilterIndex));
606  const unsigned nTriggers = triggerVids.size();
607  for (size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
608  const TriggerObject trigObject = trigObjs[triggerKeys[iTrig]];
609  double dRtmp = deltaR((*mu), trigObject);
610  if (dRtmp < matchDeltaR)
611  matchDeltaR = dRtmp;
612  }
613  }
614  }
615  return matchDeltaR;
616 }
617 
619  if (eff == kEffPt) {
620  std::vector<float> effVsPtBins(m_effVsPtBins.begin(), m_effVsPtBins.end());
621  return effVsPtBins;
622  }
623  if (eff == kEffPhi) {
624  std::vector<float> effVsPhiBins(m_effVsPhiBins.begin(), m_effVsPhiBins.end());
625  return effVsPhiBins;
626  }
627  if (eff == kEffEta) {
628  std::vector<float> effVsEtaBins(m_effVsEtaBins.begin(), m_effVsEtaBins.end());
629  return effVsEtaBins;
630  }
631  if (eff == kEffVtx) {
632  std::vector<float> effVsVtxBins(m_effVsVtxBins.begin(), m_effVsVtxBins.end());
633  return effVsVtxBins;
634  }
635  return {0., 1.};
636 }
637 
638 std::tuple<int, double, double> L1TMuonDQMOffline::getHistBinsRes(ResType res) {
639  if (res == kResPt)
640  return {50, -2., 2.};
641  if (res == kRes1OverPt)
642  return {50, -2., 2.};
643  if (res == kResQOverPt)
644  return {50, -2., 2.};
645  if (res == kResPhi)
646  return {96, -0.2, 0.2};
647  if (res == kResEta)
648  return {100, -0.1, 0.1};
649  if (res == kResCh)
650  return {5, -2, 3};
651  return {1, 0, 1};
652 }
653 
654 //define this as a plug-in
std::map< EffType, std::string > m_effStrings
unsigned int size() const
number of trigger paths in trigger table
m_VtxInputTag(consumes< VertexCollection >(ps.getUntrackedParameter< InputTag >("vtxInputTag")))
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
tuple propagator
TrajectoryStateOnSurface extrapolate(const reco::Track &tk) const
Extrapolate reco::Track to the muon station 2, return an invalid TSOS if it fails.
edm::EDGetTokenT< reco::BeamSpot > m_BsInputTag
m_trigProcess(ps.getUntrackedParameter< string >("trigProcess"))
edm::EDGetTokenT< reco::MuonCollection > m_MuonInputTag
const std::string & triggerName(unsigned int triggerIndex) const
std::vector< double > m_effVsVtxBins
std::map< ResType, std::string > m_resLabelStrings
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
std::map< EtaRegion, std::string > m_etaStrings
edm::EDGetTokenT< edm::TriggerResults > m_trigProcess_token
m_qualLevelsRes({kQualAll})
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
double gmtPt() const
void analyze(const edm::Event &e, const edm::EventSetup &c) override
double getDeltaVar(const L1TMuonDQMOffline::ResType) const
m_verbose(ps.getUntrackedParameter< bool >("verbose"))
std::map< std::tuple< ResType, EtaRegion, QualLevel >, MonitorElement * > m_ResolutionHistos
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
m_minTagProbeDR(0.5)
const std::vector< EtaRegion > m_etaRegions
m_effVsVtxBins(ps.getUntrackedParameter< std::vector< double >>("efficiencyVsVtxBins"))
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
m_etaStrings({{kEtaRegionAll,"etaMin0_etaMax2p4"},{kEtaRegionBmtf,"etaMin0_etaMax0p83"},{kEtaRegionOmtf,"etaMin0p83_etaMax1p24"},{kEtaRegionEmtf,"etaMin1p24_etaMax2p4"}})
m_effStrings({{kEffPt,"pt"},{kEffPhi,"phi"},{kEffEta,"eta"},{kEffVtx,"vtx"}})
m_cutsVPSet(ps.getUntrackedParameter< std::vector< edm::ParameterSet >>("cuts"))
std::vector< double > m_effVsPhiBins
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
m_resStrings({{kResPt,"pt"},{kRes1OverPt,"1overpt"},{kResQOverPt,"qoverpt"},{kResPhi,"phi"},{kResEta,"eta"},{kResCh,"charge"}})
GlobalPoint globalPosition() const
double getVar(const L1TMuonDQMOffline::EffType) const
m_MuonInputTag(consumes< reco::MuonCollection >(ps.getUntrackedParameter< InputTag >("muonInputTag")))
std::map< EtaRegion, MonitorElement * > m_EfficiencyDenPtHistos
std::tuple< EffType, int, EtaRegion, QualLevel > m_histoKeyEffNumVarType
std::string m_HistFolder
std::pair< int, QualLevel > m_histoKeyEffNumEtaType
m_GmtInputTag(consumes< l1t::MuonBxCollection >(ps.getUntrackedParameter< InputTag >("gmtInputTag")))
std::tuple< ResType, EtaRegion, QualLevel > m_histoKeyResType
std::vector< const reco::Muon * > m_ProbeMuons
std::vector< float > getHistBinsEff(EffType eff)
m_trigNames(ps.getUntrackedParameter< vector< string >>("triggerNames"))
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
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
int gmtCharge() const
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:18
const l1t::Muon * m_regMu
m_resLabelStrings({{kResPt,"(p_{T}^{L1} - p_{T}^{reco})/p_{T}^{reco}"},{kRes1OverPt,"(p_{T}^{reco} - p_{T}^{L1})/p_{T}^{L1}"},{kResQOverPt,"(q^{L1}*q^{reco}*p_{T}^{reco} - p_{T}^{L1})/p_{T}^{L1}"},{kResPhi,"#phi_{L1} - #phi_{reco}"},{kResEta,"#eta_{L1} - #eta_{reco}"},{kResCh,"charge^{L1} - charge^{reco}"}})
int iEvent
Definition: GenABIO.cc:224
Propagate an object (usually a track) to the second muon station. Support for other muon stations wil...
std::map< EffType, std::string > m_effLabelStrings
std::tuple< int, double, double > getHistBinsRes(ResType res)
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
double gmtPhi() const
m_trigProcess_token(consumes< edm::TriggerResults >(ps.getUntrackedParameter< InputTag >("trigProcess_token")))
T sqrt(T t)
Definition: SSEVec.h:19
std::tuple< EffType, int, EtaRegion > m_histoKeyEffDenVarType
std::map< std::pair< int, QualLevel >, MonitorElement * > m_EfficiencyNumEtaHistos
list var
if using global norm cols_to_minmax = [&#39;t_delta&#39;, &#39;t_hmaxNearP&#39;,&#39;t_emaxNearP&#39;, &#39;t_hAnnular&#39;, &#39;t_eAnnular&#39;,&#39;t_pt&#39;,&#39;t_nVtx&#39;,&#39;t_ieta&#39;,&#39;t_eHcal10&#39;, &#39;t_eHcal30&#39;,&#39;t_rhoh&#39;,&#39;t_eHcal&#39;] df[cols_to_minmax] = df[cols_to_minmax].apply(lambda x: (x - x.min()) / (x.max() - x.min()) if (x.max() - x.min() &gt; 0) else 1.0/200.0)
m_HistFolder(ps.getUntrackedParameter< string >("histFolder"))
m_maxHltMuonDR(0.1)
const reco::Muon * m_muon
m_useAtVtxCoord(ps.getUntrackedParameter< bool >("useL1AtVtxCoord"))
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
double etaAtVtx() const
Definition: Muon.h:103
m_etaRegions({kEtaRegionAll, kEtaRegionBmtf, kEtaRegionOmtf, kEtaRegionEmtf})
m_effVsEtaBins(ps.getUntrackedParameter< std::vector< double >>("efficiencyVsEtaBins"))
const int mu
Definition: Constants.h:22
const std::vector< EffType > m_effTypes
int charge() const
const std::vector< QualLevel > m_qualLevelsRes
std::vector< MuonGmtPair > m_MuonGmtPairs
bool isValid() const
Definition: HandleBase.h:70
std::map< std::tuple< EffType, int, EtaRegion >, MonitorElement * > m_EfficiencyDenVarHistos
m_recoToL1PtCutFactor(ps.getUntrackedParameter< double >("recoToL1PtCutFactor"))
Definition: Muon.h:21
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
L1TMuonDQMOffline(const edm::ParameterSet &ps)
m_trigInputTag(consumes< trigger::TriggerEvent >(ps.getUntrackedParameter< InputTag >("trigInputTag")))
m_effVsPhiBins(ps.getUntrackedParameter< std::vector< double >>("efficiencyVsPhiBins"))
void getMuonGmtPairs(edm::Handle< l1t::MuonBxCollection > &gmtCands)
m_qualStrings({{kQualAll,"qualAll"},{kQualOpen,"qualOpen"},{kQualDouble,"qualDouble"},{kQualSingle,"qualSingle"}})
std::map< ResType, std::string > m_resStrings
m_BsInputTag(consumes< BeamSpot >(ps.getUntrackedParameter< InputTag >("bsInputTag")))
std::vector< size_type > Keys
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
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:177
virtual void bookResolutionHistos(DQMStore::IBooker &ibooker)
HLTConfigProvider m_hltConfig
const reco::Vertex getPrimaryVertex(edm::Handle< reco::VertexCollection > &vertex, edm::Handle< reco::BeamSpot > &beamSpot)
void init(const edm::EventSetup &iSetup)
Call this method at the beginning of each event, to initialize geometry, magnetic field and propagato...
double pt() const
m_TagPtCut(ps.getUntrackedParameter< double >("tagPtCut"))
std::vector< double > m_effVsEtaBins
m_resTypes({kResPt, kResQOverPt, kResPhi, kResEta})
std::vector< const reco::Muon * > m_TightMuons
T eta() const
Definition: PV3DBase.h:73
tuple muons
Definition: patZpeak.py:39
const std::vector< ResType > m_resTypes
m_effVsPtBins(ps.getUntrackedParameter< std::vector< double >>("efficiencyVsPtBins"))
void dqmBeginRun(const edm::Run &run, const edm::EventSetup &iSetup) override
edm::EDGetTokenT< reco::VertexCollection > m_VtxInputTag
m_maxGmtMuonDR(0.3)
double gmtEta() const
edm::EDGetTokenT< trigger::TriggerEvent > m_trigInputTag
tuple cout
Definition: gather_cfg.py:144
std::map< std::tuple< EffType, int, EtaRegion, QualLevel >, MonitorElement * > m_EfficiencyNumVarHistos
PropagateToMuon m_propagator
double phiAtVtx() const
Definition: Muon.h:104
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
L1TMuonDQMOffline::EtaRegion etaRegion() const
double phi() const final
momentum azimuthal angle
MuonGmtPair(const reco::Muon *muon, const l1t::Muon *regMu, const PropagateToMuon &propagator, bool useAtVtxCoord)
std::map< Control, MonitorElement * > m_ControlHistos
std::vector< int > Vids
std::vector< int > m_trigIndices
Definition: Run.h:45
virtual void bookEfficiencyHistos(DQMStore::IBooker &ibooker)
m_effLabelStrings({{kEffPt,"p_{T} (GeV)"},{kEffPhi,"#phi"},{kEffEta,"#eta"},{kEffVtx,"# vertices"}})
void getTightMuons(edm::Handle< reco::MuonCollection > &muons, const reco::Vertex &vertex)
double eta() const final
momentum pseudorapidity