CMS 3D CMS Logo

L1TMuonDQMOffline.cc
Go to the documentation of this file.
1 
14 
15 #include <array>
16 
17 using namespace reco;
18 using namespace trigger;
19 using namespace edm;
20 using namespace std;
21 using namespace l1t;
22 
23 //__________RECO-GMT Muon Pair Helper Class____________________________
24 
25 MuonGmtPair::MuonGmtPair(const reco::Muon *muon, const l1t::Muon *regMu, bool useAtVtxCoord) :
26  m_muon(muon), m_regMu(regMu), m_eta(999.), m_phi_bar(999.), m_phi_end(999.)
27 {
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 };
41 
43  m_muon = muonGmtPair.m_muon;
44  m_regMu = muonGmtPair.m_regMu;
45 
46  m_gmtEta = muonGmtPair.m_gmtEta;
47  m_gmtPhi = muonGmtPair.m_gmtPhi;
48 
49  m_eta = muonGmtPair.m_eta;
50  m_phi_bar = muonGmtPair.m_phi_bar;
51  m_phi_end = muonGmtPair.m_phi_end;
52 }
53 
54 double MuonGmtPair::dR() {
55  float dEta = m_regMu ? (m_gmtEta - eta()) : 999.;
56  float dPhi = m_regMu ? reco::deltaPhi(m_gmtPhi, phi()) : 999.;
57  return sqrt(dEta*dEta + dPhi*dPhi);
58 }
59 
63  m_BField = bField;
66  TrackRef standaloneMuon = m_muon->outerTrack();
67  TrajectoryStateOnSurface trajectory;
68  trajectory = cylExtrapTrkSam(standaloneMuon, 500); // track at MB2 radius - extrapolation
69  if (trajectory.isValid()) {
70  m_eta = trajectory.globalPosition().eta();
71  m_phi_bar = trajectory.globalPosition().phi();
72  }
73  trajectory = surfExtrapTrkSam(standaloneMuon, 790); // track at ME2+ plane - extrapolation
74  if (trajectory.isValid()) {
75  m_eta = trajectory.globalPosition().eta();
76  m_phi_end = trajectory.globalPosition().phi();
77  }
78  trajectory = surfExtrapTrkSam(standaloneMuon, -790); // track at ME2- disk - extrapolation
79  if (trajectory.isValid()) {
80  m_eta = trajectory.globalPosition().eta();
81  m_phi_end = trajectory.globalPosition().phi();
82  }
83 }
84 
86  if (std::abs(eta()) < 0.83) return L1TMuonDQMOffline::kEtaRegionBmtf;
87  if (std::abs(eta()) < 1.24) return L1TMuonDQMOffline::kEtaRegionOmtf;
88  if (std::abs(eta()) < 2.4) return L1TMuonDQMOffline::kEtaRegionEmtf;
90 }
91 
93  if (type == L1TMuonDQMOffline::kResPt) return (gmtPt() - pt()) / pt();
94  if (type == L1TMuonDQMOffline::kRes1OverPt) return (pt() - gmtPt()) / gmtPt(); // (1/gmtPt - 1/pt) / (1/pt)
95  if (type == L1TMuonDQMOffline::kResQOverPt) return (gmtCharge()*charge()*pt() - gmtPt()) / gmtPt(); // (gmtCharge/gmtPt - charge/pt) / (charge/pt) with gmtCharge/charge = gmtCharge*charge
96  if (type == L1TMuonDQMOffline::kResPhi) return reco::deltaPhi(gmtPhi(), phi());
97  if (type == L1TMuonDQMOffline::kResEta) return gmtEta() - eta();
98  if (type == L1TMuonDQMOffline::kResCh) return gmtCharge() - charge();
99  return -999.;
100 }
101 
103  if (type == L1TMuonDQMOffline::kEffPt) return pt();
104  if (type == L1TMuonDQMOffline::kEffPhi) return phi();
105  if (type == L1TMuonDQMOffline::kEffEta) return eta();
106  return -999.;
107 }
108 
110 {
111  Cylinder::PositionType pos(0, 0, 0);
113  Cylinder::CylinderPointer myCylinder = Cylinder::build(pos, rot, rho);
114 
115  FreeTrajectoryState recoStart = freeTrajStateMuon(track);
116  TrajectoryStateOnSurface recoProp;
117  recoProp = m_propagatorAlong->propagate(recoStart, *myCylinder);
118  if (!recoProp.isValid()) {
119  recoProp = m_propagatorOpposite->propagate(recoStart, *myCylinder);
120  }
121  return recoProp;
122 }
123 
125 {
126  Plane::PositionType pos(0, 0, z);
128  Plane::PlanePointer myPlane = Plane::build(pos, rot);
129 
130  FreeTrajectoryState recoStart = freeTrajStateMuon(track);
131  TrajectoryStateOnSurface recoProp;
132  recoProp = m_propagatorAlong->propagate(recoStart, *myPlane);
133  if (!recoProp.isValid()) {
134  recoProp = m_propagatorOpposite->propagate(recoStart, *myPlane);
135  }
136  return recoProp;
137 }
138 
140 {
141  GlobalPoint innerPoint(track->innerPosition().x(), track->innerPosition().y(), track->innerPosition().z());
142  GlobalVector innerVec (track->innerMomentum().x(), track->innerMomentum().y(), track->innerMomentum().z());
143  FreeTrajectoryState recoStart(innerPoint, innerVec, track->charge(), &*m_BField);
144  return recoStart;
145 }
146 
147 //__________DQM_base_class_______________________________________________
149  m_effTypes({kEffPt, kEffPhi, kEffEta, kEffVtx}),
153  m_effStrings({ {kEffPt, "pt"}, {kEffPhi, "phi"}, {kEffEta, "eta"}, {kEffVtx, "vtx"} }),
154  m_effLabelStrings({ {kEffPt, "p_{T} (GeV)"}, {kEffPhi, "#phi"}, {kEffEta, "#eta"}, {kEffVtx, "# vertices"} }),
155  m_resStrings({ {kResPt, "pt"}, {kRes1OverPt, "1overpt"}, {kResQOverPt, "qoverpt"}, {kResPhi, "phi"}, {kResEta, "eta"}, {kResCh, "charge"} }),
156  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}"} }),
157  m_etaStrings({ {kEtaRegionAll, "etaMin0_etaMax2p4"}, {kEtaRegionBmtf, "etaMin0_etaMax0p83"}, {kEtaRegionOmtf, "etaMin0p83_etaMax1p24"}, {kEtaRegionEmtf, "etaMin1p24_etaMax2p4"} }),
158  m_qualStrings({ {kQualAll, "qualAll"}, {kQualOpen, "qualOpen"}, {kQualDouble, "qualDouble"}, {kQualSingle, "qualSingle"} }),
159  m_verbose(ps.getUntrackedParameter<bool>("verbose")),
160  m_HistFolder(ps.getUntrackedParameter<string>("histFolder")),
161  m_TagPtCut(ps.getUntrackedParameter<double>("tagPtCut")),
162  m_recoToL1PtCutFactor(ps.getUntrackedParameter<double>("recoToL1PtCutFactor")),
163  m_cutsVPSet(ps.getUntrackedParameter<std::vector<edm::ParameterSet>>("cuts")),
164  m_MuonInputTag(consumes<reco::MuonCollection>(ps.getUntrackedParameter<InputTag>("muonInputTag"))),
165  m_GmtInputTag(consumes<l1t::MuonBxCollection>(ps.getUntrackedParameter<InputTag>("gmtInputTag"))),
166  m_VtxInputTag(consumes<VertexCollection>(ps.getUntrackedParameter<InputTag>("vtxInputTag"))),
167  m_BsInputTag(consumes<BeamSpot>(ps.getUntrackedParameter<InputTag>("bsInputTag"))),
168  m_trigInputTag(consumes<trigger::TriggerEvent>(ps.getUntrackedParameter<InputTag>("trigInputTag"))),
169  m_trigProcess(ps.getUntrackedParameter<string>("trigProcess")),
170  m_trigProcess_token(consumes<edm::TriggerResults>(ps.getUntrackedParameter<InputTag>("trigProcess_token"))),
171  m_trigNames(ps.getUntrackedParameter<vector<string> >("triggerNames")),
172  m_effVsPtBins(ps.getUntrackedParameter<std::vector<double>>("efficiencyVsPtBins")),
173  m_effVsPhiBins(ps.getUntrackedParameter<std::vector<double>>("efficiencyVsPhiBins")),
174  m_effVsEtaBins(ps.getUntrackedParameter<std::vector<double>>("efficiencyVsEtaBins")),
175  m_effVsVtxBins(ps.getUntrackedParameter<std::vector<double>>("efficiencyVsVtxBins")),
176  m_useAtVtxCoord(ps.getUntrackedParameter<bool>("useL1AtVtxCoord")),
177  m_maxGmtMuonDR(0.3),
178  m_minTagProbeDR(0.5),
179  m_maxHltMuonDR(0.1)
180 {
181  if (m_verbose) cout << "[L1TMuonDQMOffline:] ____________ Storage initialization ____________ " << endl;
182 
183  for (const auto cutsPSet : m_cutsVPSet) {
184  const auto qCut = cutsPSet.getUntrackedParameter<int>("qualCut");
185  QualLevel qLevel = kQualAll;
186  if (qCut > 11) {
187  qLevel = kQualSingle;
188  } else if (qCut > 7) {
189  qLevel = kQualDouble;
190  } else if (qCut > 3) {
191  qLevel = kQualOpen;
192  }
193  m_cuts.emplace_back(std::make_pair(cutsPSet.getUntrackedParameter<int>("ptCut"), qLevel));
194  }
195 }
196 
197 //_____________________________________________________________________
199 //----------------------------------------------------------------------
201  if (m_verbose) cout << "[L1TMuonDQMOffline:] Called beginRun." << endl;
202  bool changed = true;
203  m_hltConfig.init(run,iSetup,m_trigProcess,changed);
204 }
205 
206 //_____________________________________________________________________
208  //book histos
209  bookControlHistos(ibooker);
210  bookEfficiencyHistos(ibooker);
211  bookResolutionHistos(ibooker);
212 
213  vector<string>::const_iterator trigNamesIt = m_trigNames.begin();
214  vector<string>::const_iterator trigNamesEnd = m_trigNames.end();
215 
216  for (; trigNamesIt!=trigNamesEnd; ++trigNamesIt) {
217  TString tNameTmp = TString(*trigNamesIt); // use TString as it handles regex
218  TRegexp tNamePattern = TRegexp(tNameTmp,true);
219  int tIndex = -1;
220 
221  for (unsigned ipath = 0; ipath < m_hltConfig.size(); ++ipath) {
222  TString tmpName = TString(m_hltConfig.triggerName(ipath));
223  if (tmpName.Contains(tNamePattern)) {
224  tIndex = int(ipath);
225  m_trigIndices.push_back(tIndex);
226  }
227  }
228  if (tIndex < 0 && m_verbose) cout << "[L1TMuonDQMOffline:] Warning: Could not find trigger " << (*trigNamesIt) << endl;
229  }
230 }
231 
232 //_____________________________________________________________________
234  if(m_verbose) cout << "[L1TMuonDQMOffline:] Called beginLuminosityBlock at LS=" << lumiBlock.id().luminosityBlock() << endl;
235 }
236 
237 //_____________________________________________________________________
239  if(m_verbose) cout << "[L1TMuonDQMOffline:] Called endLuminosityBlock at LS=" << lumiBlock.id().luminosityBlock() << endl;
240 }
241 
242 //_____________________________________________________________________
243 void L1TMuonDQMOffline::analyze(const Event & iEvent, const EventSetup & eventSetup){
244 
246  iEvent.getByToken(m_MuonInputTag, muons);
248  iEvent.getByToken(m_BsInputTag, beamSpot);
250  iEvent.getByToken(m_VtxInputTag, vertex);
252  iEvent.getByToken(m_GmtInputTag,gmtCands);
253  Handle<edm::TriggerResults> trigResults;
254  iEvent.getByToken(m_trigProcess_token,trigResults);
256  iEvent.getByToken(m_trigInputTag,trigEvent);
257 
258  eventSetup.get<IdealMagneticFieldRecord>().get(m_BField);
259  eventSetup.get<TrackingComponentsRecord>().get("PropagatorWithMaterial",m_propagatorAlong);
260  eventSetup.get<TrackingComponentsRecord>().get("PropagatorWithMaterialOpposite",m_propagatorOpposite);
261 
262  const auto nVtx = getNVertices(vertex);
263  const Vertex primaryVertex = getPrimaryVertex(vertex,beamSpot);
264 
265  getTightMuons(muons,primaryVertex);
266  getProbeMuons(trigResults,trigEvent); // CB add flag to run on orthogonal datasets (no T&P)
267 
268  getMuonGmtPairs(gmtCands);
269 
270  if (m_verbose) cout << "[L1TMuonDQMOffline:] Computing efficiencies" << endl;
271 
272  vector<MuonGmtPair>::const_iterator muonGmtPairsIt = m_MuonGmtPairs.begin();
273  vector<MuonGmtPair>::const_iterator muonGmtPairsEnd = m_MuonGmtPairs.end();
274 
275  // To fill once for global eta and once for TF eta region of the L1T muon.
276  // The second entry is a placeholder and will be replaced by the TF eta region of the L1T muon.
277  std::array<EtaRegion, 2> regsToFill { {kEtaRegionAll, kEtaRegionAll} };
278 
279  for(; muonGmtPairsIt!=muonGmtPairsEnd; ++muonGmtPairsIt) {
280  // Fill the resolution histograms
281  if( (muonGmtPairsIt->etaRegion() != kEtaRegionOut) && (muonGmtPairsIt->gmtPt() > 0) ){
282  regsToFill[1] = muonGmtPairsIt->etaRegion();
284  for (const auto var : m_resTypes) {
285  const auto varToFill = muonGmtPairsIt->getDeltaVar(var);
286  std::get<0>(histoKeyRes) = var;
287  // Fill for the global eta and for TF eta region that the probe muon is in
288  for (const auto regToFill : regsToFill) {
289  std::get<1>(histoKeyRes) = regToFill;
290  for (const auto qualLevel : m_qualLevelsRes) {
291  // This assumes that the qualLevel enum has increasing qualities
292  // HW quality levels can be 0, 4, 8, or 12
293  int qualCut = qualLevel * 4;
294  if (muonGmtPairsIt->gmtQual() >= qualCut) {
295  std::get<2>(histoKeyRes) = qualLevel;
296  m_ResolutionHistos[histoKeyRes]->Fill(varToFill);
297  }
298  }
299  }
300  }
301  }
302 
303  // Fill the efficiency numerator and denominator histograms
304  if (muonGmtPairsIt->etaRegion() != kEtaRegionOut) {
305  unsigned int cutsCounter = 0;
306  for (const auto cut : m_cuts) {
307  const auto gmtPtCut = cut.first;
308  const auto qualLevel = cut.second;
309  const bool gmtAboveCut = (muonGmtPairsIt->gmtPt() > gmtPtCut);
310 
311  // default keys
312  m_histoKeyEffDenVarType histoKeyEffDenVar = {kEffPt, gmtPtCut, kEtaRegionAll};
313  m_histoKeyEffNumVarType histoKeyEffNumVar = {kEffPt, gmtPtCut, kEtaRegionAll, qualLevel};
314 
315  regsToFill[1] = muonGmtPairsIt->etaRegion();
316  for(const auto var : m_effTypes) {
317  if(var != kEffPt){
318  if (muonGmtPairsIt->pt() < m_recoToL1PtCutFactor * gmtPtCut) break; // efficiency at plateau
319  }
320  double varToFill;
321  if (var == kEffVtx) {
322  varToFill = static_cast<double>(nVtx);
323  } else {
324  varToFill = muonGmtPairsIt->getVar(var);
325  }
326  // Fill denominators
327  if (var == kEffEta) {
328  m_EfficiencyDenEtaHistos[gmtPtCut]->Fill(varToFill);
329  } else {
330  std::get<0>(histoKeyEffDenVar) = var;
331  // Fill for the global eta and for TF eta region that the probe muon is in
332  for (const auto regToFill : regsToFill) {
333  if (var == kEffPt) {
334  if (cutsCounter == 0) {
335  m_EfficiencyDenPtHistos[regToFill]->Fill(varToFill);
336  }
337  } else {
338  std::get<2>(histoKeyEffDenVar) = regToFill;
339  m_EfficiencyDenVarHistos[histoKeyEffDenVar]->Fill(varToFill);
340  }
341  }
342  }
343  // Fill numerators
344  std::get<0>(histoKeyEffNumVar) = var;
345  // This assumes that the qualLevel enum has increasing qualities
346  if (gmtAboveCut && muonGmtPairsIt->gmtQual() >= qualLevel * 4) {
347  if (var == kEffEta) {
348  m_histoKeyEffNumEtaType histoKeyEffNumEta = {gmtPtCut, qualLevel};
349  m_EfficiencyNumEtaHistos[histoKeyEffNumEta]->Fill(varToFill);
350  } else {
351  std::get<3>(histoKeyEffNumVar) = qualLevel;
352  // Fill for the global eta and for TF eta region that the probe muon is in
353  for (const auto regToFill : regsToFill) {
354  std::get<2>(histoKeyEffNumVar) = regToFill;
355  m_EfficiencyNumVarHistos[histoKeyEffNumVar]->Fill(varToFill);
356  }
357  }
358  }
359  }
360  ++cutsCounter;
361  }
362  }
363  }
364 
365  if (m_verbose) cout << "[L1TMuonDQMOffline:] Computation finished" << endl;
366 }
367 
368 //_____________________________________________________________________
370  if(m_verbose) cout << "[L1TMuonDQMOffline:] Booking Control Plot Histos" << endl;
371 
372  ibooker.setCurrentFolder(m_HistFolder+"/control_variables");
373 
374  m_ControlHistos[kCtrlMuonGmtDeltaR] = ibooker.book1D("MuonGmtDeltaR", "MuonGmtDeltaR; #DeltaR", 50, 0., 0.5);
375  m_ControlHistos[kCtrlNTightVsAll] = ibooker.book2D("NTightVsAll", "NTightVsAll; # muons; # tight muons", 20, -0.5, 19.5, 16, -0.5, 15.5);
376  m_ControlHistos[kCtrlNProbesVsTight] = ibooker.book2D("NProbesVsTight", "NProbesVsTight; # tight muons; # probe muons", 8, -0.5, 7.5, 8, -0.5, 7.5);
377 
378  m_ControlHistos[kCtrlTagPt] = ibooker.book1D("TagMuonPt", "TagMuonPt; p_{T}", 50, 0., 100.);
379  m_ControlHistos[kCtrlTagPhi] = ibooker.book1D("TagMuonPhi", "TagMuonPhi; #phi", 66, -3.3, 3.3);
380  m_ControlHistos[kCtrlTagEta] = ibooker.book1D("TagMuonEta", "TagMuonEta; #eta", 50, -2.5, 2.5);
381 
382  m_ControlHistos[kCtrlProbePt] = ibooker.book1D("ProbeMuonPt", "ProbeMuonPt; p_{T}", 50, 0., 100.);
383  m_ControlHistos[kCtrlProbePhi] = ibooker.book1D("ProbeMuonPhi", "ProbeMuonPhi; #phi", 66, -3.3, 3.3);
384  m_ControlHistos[kCtrlProbeEta] = ibooker.book1D("ProbeMuonEta", "ProbeMuonEta; #eta", 50, -2.5, 2.5);
385 
386  m_ControlHistos[kCtrlTagProbeDr] = ibooker.book1D("TagMuonProbeMuonDeltaR", "TagMuonProbeMuonDeltaR; #DeltaR", 50, 0.,5.0);
387  m_ControlHistos[kCtrlTagHltDr] = ibooker.book1D("TagMuonHltDeltaR", "TagMuonHltDeltaR;#DeltaR", 55, 0., 0.11);
388 }
389 
390 //_____________________________________________________________________
392  ibooker.setCurrentFolder(m_HistFolder+"/numerators_and_denominators");
393 
394  for(const auto var : m_effTypes) {
395  auto histBins = getHistBinsEff(var);
396  // histograms for eta variable get a special treatment
397  if (var == kEffEta) {
398  for (const auto cut : m_cuts) {
399  const auto gmtPtCut = cut.first;
400  const auto qualLevel = cut.second;
401  std::string name = "effDen_"+m_effStrings[var]+"_"+std::to_string(gmtPtCut);
402  m_EfficiencyDenEtaHistos[gmtPtCut] = ibooker.book1D(name, name+";"+m_effLabelStrings[var], histBins.size()-1, &histBins[0]);
403  name = "effNum_"+m_effStrings[var]+"_"+std::to_string(gmtPtCut)+"_"+m_qualStrings[qualLevel];
404  m_histoKeyEffNumEtaType histoKeyEffNumEta = {gmtPtCut, qualLevel};
405  m_EfficiencyNumEtaHistos[histoKeyEffNumEta] = ibooker.book1D(name, name+";"+m_effLabelStrings[var], histBins.size()-1, &histBins[0]);
406  }
407  } else {
408  for (const auto etaReg : m_etaRegions) {
409  // denominator histograms for pt variable get a special treatment
410  if (var == kEffPt) {
411  std::string name = "effDen_"+m_effStrings[var]+"_"+m_etaStrings[etaReg];
412  m_EfficiencyDenPtHistos[etaReg] = ibooker.book1D(name, name+";"+m_effLabelStrings[var], histBins.size()-1, &histBins[0]);
413  } else {
414  for (const auto cut : m_cuts) {
415  const int gmtPtCut = cut.first;
416  std::string name = "effDen_"+m_effStrings[var]+"_"+std::to_string(gmtPtCut)+"_"+m_etaStrings[etaReg];
417  m_histoKeyEffDenVarType histoKeyEffDenVar = {var, gmtPtCut, etaReg};
418  m_EfficiencyDenVarHistos[histoKeyEffDenVar] = ibooker.book1D(name, name+";"+m_effLabelStrings[var], histBins.size()-1, &histBins[0]);
419  }
420  }
421  for (const auto cut : m_cuts) {
422  const auto gmtPtCut = cut.first;
423  const auto qualLevel = cut.second;
424  std::string name = "effNum_"+m_effStrings[var]+"_"+std::to_string(gmtPtCut)+"_"+m_etaStrings[etaReg]+"_"+m_qualStrings[qualLevel];
425  m_histoKeyEffNumVarType histoKeyEffNum = {var, gmtPtCut, etaReg, qualLevel};
426  m_EfficiencyNumVarHistos[histoKeyEffNum] = ibooker.book1D(name, name+";"+m_effLabelStrings[var], histBins.size()-1, &histBins[0]);
427  }
428  }
429  }
430  }
431 }
432 
434  if(m_verbose) cout << "[L1TMuonOffline:] Booking Resolution Plot Histos" << endl;
435  ibooker.setCurrentFolder(m_HistFolder+"/resolution");
436 
437  for (const auto var : m_resTypes) {
438  auto nbins = std::get<0>(getHistBinsRes(var));
439  auto xmin = std::get<1>(getHistBinsRes(var));
440  auto xmax = std::get<2>(getHistBinsRes(var));
441  for (const auto etaReg : m_etaRegions) {
442  for (const auto qualLevel : m_qualLevelsRes) {
443  m_histoKeyResType histoKeyRes = {var, etaReg, qualLevel};
444  std::string name = "resolution_"+m_resStrings[var]+"_"+m_etaStrings[etaReg]+"_"+m_qualStrings[qualLevel];
445  m_ResolutionHistos[histoKeyRes] = ibooker.book1D(name, name+";"+m_resLabelStrings[var], nbins, xmin, xmax);
446  }
447  }
448  }
449 }
450 
451 //_____________________________________________________________________
453  unsigned int nVtx = 0;
454 
455  if (vertex.isValid()) {
456  for (const auto vertexIt : *vertex) {
457  if (vertexIt.isValid() && !vertexIt.isFake()) {
458  ++nVtx;
459  }
460  }
461  }
462  return nVtx;
463 }
464 
465 //_____________________________________________________________________
468  Vertex::Point posVtx;
469  Vertex::Error errVtx;
470 
471  bool hasPrimaryVertex = false;
472 
473  if (vertex.isValid()) {
474  vector<Vertex>::const_iterator vertexIt = vertex->begin();
475  vector<Vertex>::const_iterator vertexEnd = vertex->end();
476 
477  for (;vertexIt!=vertexEnd;++vertexIt) {
478  if (vertexIt->isValid() && !vertexIt->isFake()) {
479  posVtx = vertexIt->position();
480  errVtx = vertexIt->error();
481  hasPrimaryVertex = true;
482  break;
483  }
484  }
485  }
486 
487  if ( !hasPrimaryVertex ) {
488  posVtx = beamSpot->position();
489  errVtx(0,0) = beamSpot->BeamWidthX();
490  errVtx(1,1) = beamSpot->BeamWidthY();
491  errVtx(2,2) = beamSpot->sigmaZ();
492  }
493  const Vertex primaryVertex(posVtx,errVtx);
494  return primaryVertex;
495 }
496 
497 //_____________________________________________________________________
499 
500  if (m_verbose) cout << "[L1TMuonDQMOffline:] Getting tight muons" << endl;
501  m_TightMuons.clear();
502  MuonCollection::const_iterator muonIt = muons->begin();
503  MuonCollection::const_iterator muonEnd = muons->end();
504 
505  for(; muonIt!=muonEnd; ++muonIt) {
506  if (muon::isTightMuon((*muonIt), vertex)) {
507  m_TightMuons.push_back(&(*muonIt));
508  }
509  }
510  m_ControlHistos[kCtrlNTightVsAll]->Fill(muons->size(), m_TightMuons.size());
511 }
512 
513 //_____________________________________________________________________
516 
517  if (m_verbose) cout << "[L1TMuonDQMOffline:] getting probe muons" << endl;
518  m_ProbeMuons.clear();
519  std::vector<const reco::Muon*> tagMuonsInHist;
520 
521  tagMuonsInHist.clear();
522 
523  vector<const reco::Muon*>::const_iterator probeCandIt = m_TightMuons.begin();
524  vector<const reco::Muon*>::const_iterator tightMuonsEnd = m_TightMuons.end();
525 
526  for (; probeCandIt!=tightMuonsEnd; ++probeCandIt) {
527  bool isProbe = false;
528  vector<const reco::Muon*>::const_iterator tagCandIt = m_TightMuons.begin();
529  float deltar = 0.;
530 
531  for (; tagCandIt!=tightMuonsEnd; ++tagCandIt) {
532  bool tagMuonAlreadyInHist = false;
533  bool tagHasTrig = false;
534  float eta = (*tagCandIt)->eta();
535  float phi = (*tagCandIt)->phi();
536  float pt = (*tagCandIt)->pt();
537  float dEta = eta - (*probeCandIt)->eta();
538  float dPhi = phi - (*probeCandIt)->phi();
539  deltar = sqrt(dEta*dEta + dPhi*dPhi);
540 
541  if ( (*tagCandIt) == (*probeCandIt) || deltar<m_minTagProbeDR ) continue; // CB has a little bias for closed-by muons
542  auto matchHltDeltaR = matchHlt(trigEvent,(*tagCandIt));
543  tagHasTrig = (matchHltDeltaR < m_maxHltMuonDR) && (pt > m_TagPtCut);
544  isProbe |= tagHasTrig;
545  if (tagHasTrig) {
546  if (std::distance(m_TightMuons.begin(), m_TightMuons.end()) > 2 ) {
547  for (vector<const reco::Muon*>::const_iterator tagMuonsInHistIt = tagMuonsInHist.begin(); tagMuonsInHistIt!=tagMuonsInHist.end(); ++tagMuonsInHistIt) {
548  if ( (*tagCandIt) == (*tagMuonsInHistIt) ) {
549  tagMuonAlreadyInHist = true;
550  break;
551  }
552  }
553  if (tagMuonAlreadyInHist == false) tagMuonsInHist.push_back((*tagCandIt));
554  }
555  if (tagMuonAlreadyInHist == false) {
556  m_ControlHistos[kCtrlTagEta]->Fill(eta);
557  m_ControlHistos[kCtrlTagPhi]->Fill(phi);
558  m_ControlHistos[kCtrlTagPt]->Fill(pt);
559  m_ControlHistos[kCtrlTagProbeDr]->Fill(deltar);
560  m_ControlHistos[kCtrlTagHltDr]->Fill(matchHltDeltaR);
561  }
562  }
563  }
564  if (isProbe) m_ProbeMuons.push_back((*probeCandIt));
565  }
567 }
568 
569 //_____________________________________________________________________
571 
572  m_MuonGmtPairs.clear();
573  if (m_verbose) cout << "[L1TMuonDQMOffline:] Getting muon GMT pairs" << endl;
574 
575  vector<const reco::Muon*>::const_iterator probeMuIt = m_ProbeMuons.begin();
576  vector<const reco::Muon*>::const_iterator probeMuEnd = m_ProbeMuons.end();
577 
579  l1t::MuonBxCollection::const_iterator gmtEnd = gmtCands->end(0);
580 
581  for (; probeMuIt!=probeMuEnd; ++probeMuIt) {
582  m_ControlHistos[kCtrlProbeEta]->Fill((*probeMuIt)->eta());
583  m_ControlHistos[kCtrlProbePhi]->Fill((*probeMuIt)->phi());
584  m_ControlHistos[kCtrlProbePt]->Fill((*probeMuIt)->pt());
585 
586  MuonGmtPair pairBestCand((*probeMuIt), nullptr, m_useAtVtxCoord);
587 // pairBestCand.propagate(m_BField,m_propagatorAlong,m_propagatorOpposite);
588  gmtIt = gmtCands->begin(0); // use only on L1T muons from BX 0
589 
590  for(; gmtIt!=gmtEnd; ++gmtIt) {
591  MuonGmtPair pairTmpCand((*probeMuIt),&(*gmtIt), m_useAtVtxCoord);
592 // pairTmpCand.propagate(m_BField,m_propagatorAlong,m_propagatorOpposite);
593 
594  if ( (pairTmpCand.dR() < m_maxGmtMuonDR) && (pairTmpCand.dR() < pairBestCand.dR() ) ) {
595  pairBestCand = pairTmpCand;
596  }
597 
598  }
599  m_MuonGmtPairs.push_back(pairBestCand);
600  m_ControlHistos[kCtrlMuonGmtDeltaR]->Fill(pairBestCand.dR());
601  }
602 }
603 
604 //_____________________________________________________________________
606 
607  double matchDeltaR = 9999;
608 
609  TriggerObjectCollection trigObjs = triggerEvent->getObjects();
610 
611  vector<int>::const_iterator trigIndexIt = m_trigIndices.begin();
612  vector<int>::const_iterator trigIndexEnd = m_trigIndices.end();
613 
614  for(; trigIndexIt!=trigIndexEnd; ++trigIndexIt) {
615  const vector<string> moduleLabels(m_hltConfig.moduleLabels(*trigIndexIt));
616  const unsigned moduleIndex = m_hltConfig.size((*trigIndexIt))-2;
617  const unsigned hltFilterIndex = triggerEvent->filterIndex(InputTag(moduleLabels[moduleIndex],"",m_trigProcess));
618 
619  if (hltFilterIndex < triggerEvent->sizeFilters()) {
620  const Keys triggerKeys(triggerEvent->filterKeys(hltFilterIndex));
621  const Vids triggerVids(triggerEvent->filterIds(hltFilterIndex));
622  const unsigned nTriggers = triggerVids.size();
623  for (size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
624  const TriggerObject trigObject = trigObjs[triggerKeys[iTrig]];
625  double dRtmp = deltaR((*mu),trigObject);
626  if (dRtmp < matchDeltaR) matchDeltaR = dRtmp;
627  }
628  }
629  }
630  return matchDeltaR;
631 }
632 
634  if (eff == kEffPt) {
635  std::vector<float> effVsPtBins(m_effVsPtBins.begin(), m_effVsPtBins.end());
636  return effVsPtBins;
637  }
638  if (eff == kEffPhi) {
639  std::vector<float> effVsPhiBins(m_effVsPhiBins.begin(), m_effVsPhiBins.end());
640  return effVsPhiBins;
641  }
642  if (eff == kEffEta) {
643  std::vector<float> effVsEtaBins(m_effVsEtaBins.begin(), m_effVsEtaBins.end());
644  return effVsEtaBins;
645  }
646  if (eff == kEffVtx) {
647  std::vector<float> effVsVtxBins(m_effVsVtxBins.begin(), m_effVsVtxBins.end());
648  return effVsVtxBins;
649  }
650  return {0., 1.};
651 }
652 
653 std::tuple<int, double, double> L1TMuonDQMOffline::getHistBinsRes(ResType res){
654  if (res == kResPt) return {50, -2., 2.};
655  if (res == kRes1OverPt) return {50, -2., 2.};
656  if (res == kResQOverPt) return {50, -2., 2.};
657  if (res == kResPhi) return {96, -0.2, 0.2};
658  if (res == kResEta) return {100, -0.1, 0.1};
659  if (res == kResCh) return {5, -2, 3};
660  return {1, 0, 1};
661 }
662 
663 //define this as a plug-in
std::map< EffType, std::string > m_effStrings
unsigned int size() const
number of trigger paths in trigger table
LuminosityBlockID id() const
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
const_iterator end(int bx) const
type
Definition: HCALResponse.h:21
edm::ESHandle< Propagator > m_propagatorOpposite
edm::EDGetTokenT< reco::BeamSpot > m_BsInputTag
MuonGmtPair(const reco::Muon *muon, const l1t::Muon *regMu, bool useAtVtxCoord)
double eta() const final
momentum pseudorapidity
edm::ESHandle< Propagator > m_propagatorOpposite
edm::ESHandle< Propagator > m_propagatorAlong
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
std::map< EtaRegion, std::string > m_etaStrings
edm::EDGetTokenT< edm::TriggerResults > m_trigProcess_token
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
void beginLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c) override
double gmtPt() const
void analyze(const edm::Event &e, const edm::EventSetup &c) override
double getDeltaVar(const L1TMuonDQMOffline::ResType) const
std::map< std::tuple< ResType, EtaRegion, QualLevel >, MonitorElement * > m_ResolutionHistos
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const std::vector< EtaRegion > m_etaRegions
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:111
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
virtual void dqmEndLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:123
std::vector< double > m_effVsPhiBins
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
GlobalPoint globalPosition() const
double getVar(const L1TMuonDQMOffline::EffType) const
std::map< EtaRegion, MonitorElement * > m_EfficiencyDenPtHistos
std::tuple< EffType, int, EtaRegion, QualLevel > m_histoKeyEffNumVarType
delete x;
Definition: CaloConfig.h:22
std::string m_HistFolder
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
virtual void bookControlHistos(DQMStore::IBooker &)
edm::ESHandle< MagneticField > m_BField
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
static CylinderPointer build(const PositionType &pos, const RotationType &rot, Scalar radius, Bounds *bounds=0)
Definition: Cylinder.h:51
const l1t::Muon * m_regMu
const Vids & filterIds(trigger::size_type index) const
Definition: TriggerEvent.h:110
std::vector< edm::ParameterSet > m_cutsVPSet
int iEvent
Definition: GenABIO.cc:230
std::map< EffType, std::string > m_effLabelStrings
std::tuple< int, double, double > getHistBinsRes(ResType res)
edm::EDGetTokenT< l1t::MuonBxCollection > m_GmtInputTag
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:98
double phi() const
std::vector< double > m_effVsPtBins
void bookHistograms(DQMStore::IBooker &ibooker, const edm::Run &run, const edm::EventSetup &iSetup) override
double gmtPhi() const
T sqrt(T t)
Definition: SSEVec.h:18
std::tuple< EffType, int, EtaRegion > m_histoKeyEffDenVarType
std::map< std::pair< int, QualLevel >, MonitorElement * > m_EfficiencyNumEtaHistos
static PlanePointer build(Args &&...args)
Definition: Plane.h:33
TrajectoryStateOnSurface cylExtrapTrkSam(reco::TrackRef track, double rho)
const reco::Muon * m_muon
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
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:39
double etaAtVtx() const
Definition: Muon.h:94
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
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:74
std::map< std::tuple< EffType, int, EtaRegion >, MonitorElement * > m_EfficiencyDenVarHistos
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
Definition: Muon.h:21
edm::ESHandle< MagneticField > m_BField
edm::ESHandle< Propagator > m_propagatorAlong
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
L1TMuonDQMOffline(const edm::ParameterSet &ps)
FreeTrajectoryState freeTrajStateMuon(reco::TrackRef track)
double eta() const
void getMuonGmtPairs(edm::Handle< l1t::MuonBxCollection > &gmtCands)
std::map< ResType, std::string > m_resStrings
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
Definition: deltar.py:1
void propagate(edm::ESHandle< MagneticField > bField, edm::ESHandle< Propagator > propagatorAlong, edm::ESHandle< Propagator > propagatorOpposite)
std::vector< size_type > Keys
TrajectoryStateOnSurface surfExtrapTrkSam(reco::TrackRef track, double z)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:88
virtual void bookResolutionHistos(DQMStore::IBooker &ibooker)
HLTConfigProvider m_hltConfig
LuminosityBlockNumber_t luminosityBlock() const
const reco::Vertex getPrimaryVertex(edm::Handle< reco::VertexCollection > &vertex, edm::Handle< reco::BeamSpot > &beamSpot)
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
double pt() const
std::vector< double > m_effVsEtaBins
std::vector< const reco::Muon * > m_TightMuons
T eta() const
Definition: PV3DBase.h:76
fixed size matrix
HLT enums.
const std::vector< ResType > m_resTypes
T get() const
Definition: EventSetup.h:63
void dqmBeginRun(const edm::Run &run, const edm::EventSetup &iSetup) override
edm::EDGetTokenT< reco::VertexCollection > m_VtxInputTag
double gmtEta() const
edm::EDGetTokenT< trigger::TriggerEvent > m_trigInputTag
const Point & position() const
position
Definition: BeamSpot.h:62
std::map< std::tuple< EffType, int, EtaRegion, QualLevel >, MonitorElement * > m_EfficiencyNumVarHistos
double phiAtVtx() const
Definition: Muon.h:95
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
L1TMuonDQMOffline::EtaRegion etaRegion() const
const_iterator begin(int bx) const
double phi() const final
momentum azimuthal angle
std::map< Control, MonitorElement * > m_ControlHistos
std::vector< int > Vids
std::vector< int > m_trigIndices
Definition: Run.h:44
virtual void bookEfficiencyHistos(DQMStore::IBooker &ibooker)
std::vector< Muon >::const_iterator const_iterator
Definition: BXVector.h:20
void getTightMuons(edm::Handle< reco::MuonCollection > &muons, const reco::Vertex &vertex)