CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BTVHLTOfflineSource.cc
Go to the documentation of this file.
1 /*
2  BTVHLTOffline DQM code
3 */
4 //
5 // Originally created by: Anne-Catherine Le Bihan
6 // June 2015
7 // John Alison <johnalison@cmu.edu>
8 // June 2020
9 // Following the structure used in JetMetHLTOfflineSource
10 
11 // system include files
12 #include <fstream>
13 #include <iostream>
14 #include <memory>
15 #include <sstream>
16 #include <string>
17 #include <utility>
18 #include <vector>
19 #include <unistd.h>
20 #include <cmath>
21 #include <iostream>
22 
23 // user include files
44 
45 #include "TMath.h"
46 #include "TPRegexp.h"
47 
48 class BTVHLTOfflineSource : public DQMEDAnalyzer {
49 public:
50  explicit BTVHLTOfflineSource(const edm::ParameterSet&);
51  ~BTVHLTOfflineSource() override;
52 
53 private:
54  void analyze(const edm::Event&, const edm::EventSetup&) override;
55 
56  std::vector<const reco::Track*> getOfflineBTagTracks(float hltJetEta,
57  float hltJetPhi,
58  edm::Handle<edm::View<reco::BaseTagInfo>> offlineIPTagHandle,
59  std::vector<float>& offlineIP3D,
60  std::vector<float>& offlineIP3DSig);
61 
63 
64  template <class Base>
65  std::vector<const reco::Track*> getOnlineBTagTracks(float hltJetEta,
66  float hltJetPhi,
67  edm::Handle<std::vector<Base>> jetSVTagsColl,
68  std::vector<float>& onlineIP3D,
69  std::vector<float>& onlineIP3DSig);
70 
71  void bookHistograms(DQMStore::IBooker&, edm::Run const& run, edm::EventSetup const& c) override;
72 
73  void dqmBeginRun(edm::Run const& run, edm::EventSetup const& c) override;
74 
77  bool verbose_;
78 
79  std::vector<std::pair<std::string, std::string>> custompathnamepairs_;
80 
83 
87 
91 
96 
101 
104 
107 
112 
118 
120 
121  class PathInfo : public TriggerDQMBase {
122  public:
124  : prescaleUsed_(-1),
125  pathName_("unset"),
126  filterName_("unset"),
127  processName_("unset"),
128  objectType_(-1),
129  triggerType_("unset") {}
130 
131  ~PathInfo() override = default;
132 
133  PathInfo(const int prescaleUsed,
134  const std::string& pathName,
135  const std::string& filterName,
136  const std::string& processName,
137  const int type,
138  const std::string& triggerType)
139  : prescaleUsed_(prescaleUsed),
140  pathName_(pathName),
141  filterName_(filterName),
142  processName_(processName),
143  objectType_(type),
144  triggerType_(triggerType) {}
145 
146  const std::string getLabel() const { return filterName_; }
147  void setLabel(std::string labelName) { filterName_ = std::move(labelName); }
148  const std::string getPath() const { return pathName_; }
149  const int getprescaleUsed() const { return prescaleUsed_; }
150  const std::string getProcess() const { return processName_; }
151  const int getObjectType() const { return objectType_; }
152  const std::string getTriggerType() const { return triggerType_; }
154  const bool operator==(const std::string& v) const { return v == pathName_; }
155 
156  MonitorElement* Discr = nullptr;
157  MonitorElement* Pt = nullptr;
158  MonitorElement* Eta = nullptr;
164  MonitorElement* PVz = nullptr;
168  MonitorElement* n_vtx = nullptr;
183  // MonitorElement* n_pixel_hits_;
184  // MonitorElement* n_total_hits_;
185 
186  private:
193  };
194 
195  class PathInfoCollection : public std::vector<PathInfo> {
196  public:
198  std::vector<PathInfo>::iterator find(const std::string& pathName) { return std::find(begin(), end(), pathName); }
199  };
200 
202 };
203 
204 using namespace edm;
205 using namespace reco;
206 using namespace std;
207 using namespace trigger;
208 
210  : dirname_(iConfig.getUntrackedParameter("dirname", std::string("HLT/BTV/"))),
211  processname_(iConfig.getParameter<std::string>("processname")),
212  verbose_(iConfig.getUntrackedParameter<bool>("verbose", false)),
213  triggerSummaryLabel_(iConfig.getParameter<edm::InputTag>("triggerSummaryLabel")),
214  triggerResultsLabel_(iConfig.getParameter<edm::InputTag>("triggerResultsLabel")),
215  turnon_threshold_loose_(iConfig.getParameter<double>("turnon_threshold_loose")),
216  turnon_threshold_medium_(iConfig.getParameter<double>("turnon_threshold_medium")),
217  turnon_threshold_tight_(iConfig.getParameter<double>("turnon_threshold_tight")),
218  offlineDiscrTokenb_(consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("offlineDiscrLabelb"))),
219  offlineDiscrTokenbb_(
220  consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("offlineDiscrLabelbb"))),
221  offlineIPToken_(consumes<View<BaseTagInfo>>(iConfig.getParameter<edm::InputTag>("offlineIPLabel"))),
222 
223  hltFastPVToken_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("hltFastPVLabel"))),
224  hltPFPVToken_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("hltPFPVLabel"))),
225  hltCaloPVToken_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("hltCaloPVLabel"))),
226  offlinePVToken_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("offlinePVLabel"))),
227  triggerResultsToken(consumes<edm::TriggerResults>(triggerResultsLabel_)),
228  triggerResultsFUToken(consumes<edm::TriggerResults>(
229  edm::InputTag(triggerResultsLabel_.label(), triggerResultsLabel_.instance(), std::string("FU")))),
230  triggerSummaryToken(consumes<trigger::TriggerEvent>(triggerSummaryLabel_)),
231  triggerSummaryFUToken(consumes<trigger::TriggerEvent>(
232  edm::InputTag(triggerSummaryLabel_.label(), triggerSummaryLabel_.instance(), std::string("FU")))),
233  shallowTagInfosTokenCalo_(
234  consumes<vector<reco::ShallowTagInfo>>(edm::InputTag("hltDeepCombinedSecondaryVertexBJetTagsInfosCalo"))),
235  shallowTagInfosTokenPf_(
236  consumes<vector<reco::ShallowTagInfo>>(edm::InputTag("hltDeepCombinedSecondaryVertexBJetTagsInfos"))),
237  SVTagInfosTokenCalo_(consumes<std::vector<reco::SecondaryVertexTagInfo>>(
238  edm::InputTag("hltInclusiveSecondaryVertexFinderTagInfos"))),
239  SVTagInfosTokenPf_(consumes<std::vector<SVTagInfo>>(edm::InputTag("hltDeepSecondaryVertexTagInfosPF"))),
240  caloTagsToken_(consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("onlineDiscrLabelCalo"))),
241  pfTagsToken_(consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("onlineDiscrLabelPF"))),
242  minDecayLength_(iConfig.getParameter<double>("minDecayLength")),
243  maxDecayLength_(iConfig.getParameter<double>("maxDecayLength")),
244  minJetDistance_(iConfig.getParameter<double>("minJetDistance")),
245  maxJetDistance_(iConfig.getParameter<double>("maxJetDistance")),
246  dRTrackMatch_(iConfig.getParameter<double>("dRTrackMatch")) {
247  std::vector<edm::ParameterSet> paths = iConfig.getParameter<std::vector<edm::ParameterSet>>("pathPairs");
248  for (const auto& path : paths) {
249  custompathnamepairs_.push_back(
250  make_pair(path.getParameter<std::string>("pathname"), path.getParameter<std::string>("pathtype")));
251  }
252 }
253 
255 
257  bool changed = true;
258  if (!hltConfig_.init(run, c, processname_, changed)) {
259  LogDebug("BTVHLTOfflineSource") << "HLTConfigProvider failed to initialize.";
260  }
261 
262  for (unsigned int idx = 0; idx != hltConfig_.size(); ++idx) {
263  const auto& pathname = hltConfig_.triggerName(idx);
264 
265  for (const auto& custompathnamepair : custompathnamepairs_) {
266  if (pathname.find(custompathnamepair.first) != std::string::npos) {
267  hltPathsAll_.push_back(PathInfo(1, pathname, "dummy", processname_, 0, custompathnamepair.second));
268  }
269  }
270  }
271 }
272 
275  iEvent.getByToken(triggerResultsToken, triggerResults);
276  if (!triggerResults.isValid()) {
277  iEvent.getByToken(triggerResultsFUToken, triggerResults);
278  if (!triggerResults.isValid()) {
279  edm::LogInfo("BTVHLTOfflineSource") << "TriggerResults not found, skipping event";
280  return;
281  }
282  }
283 
284  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
285 
287  iEvent.getByToken(triggerSummaryToken, triggerObj);
288  if (!triggerObj.isValid()) {
289  iEvent.getByToken(triggerSummaryFUToken, triggerObj);
290  if (!triggerObj.isValid()) {
291  edm::LogInfo("BTVHLTOfflineSource") << "TriggerEvent not found, skipping event";
292  return;
293  }
294  }
295 
297  iEvent.getByToken(caloTagsToken_, caloTags);
298 
300  iEvent.getByToken(pfTagsToken_, pfTags);
301 
302  Handle<reco::VertexCollection> VertexHandler;
303 
304  Handle<reco::JetTagCollection> offlineJetTagHandlerb;
305  iEvent.getByToken(offlineDiscrTokenb_, offlineJetTagHandlerb);
306 
307  Handle<reco::JetTagCollection> offlineJetTagHandlerbb;
308  iEvent.getByToken(offlineDiscrTokenbb_, offlineJetTagHandlerbb);
309 
310  Handle<View<BaseTagInfo>> offlineIPTagHandle;
311  iEvent.getByToken(offlineIPToken_, offlineIPTagHandle);
312 
313  Handle<reco::VertexCollection> offlineVertexHandler;
314  iEvent.getByToken(offlinePVToken_, offlineVertexHandler);
315 
316  if (verbose_ && iEvent.id().event() % 10000 == 0)
317  cout << "Run = " << iEvent.id().run() << ", LS = " << iEvent.luminosityBlock()
318  << ", Event = " << iEvent.id().event() << endl;
319 
320  if (!triggerResults.isValid())
321  return;
322 
323  edm::Handle<std::vector<SVTagInfo>> jetSVTagsCollPF;
325 
326  for (auto& v : hltPathsAll_) {
327  unsigned index = triggerNames.triggerIndex(v.getPath());
328  if (!(index < triggerNames.size())) {
329  edm::LogInfo("BTVHLTOfflineSource") << "Path " << v.getPath() << " not in menu, skipping event";
330  continue;
331  }
332 
333  if (!triggerResults->accept(index)) {
334  edm::LogInfo("BTVHLTOfflineSource") << "Path " << v.getPath() << " not accepted, skipping event";
335  continue;
336  }
337 
338  if (v.getTriggerType() == "PF") {
339  iEvent.getByToken(SVTagInfosTokenPf_, jetSVTagsCollPF);
340  } else {
341  iEvent.getByToken(SVTagInfosTokenCalo_, jetSVTagsCollCalo);
342  }
343 
344  // PF and Calo btagging
345  if ((v.getTriggerType() == "PF" && pfTags.isValid()) ||
346  (v.getTriggerType() == "Calo" && caloTags.isValid() && !caloTags->empty())) {
347  const auto& iter = (v.getTriggerType() == "PF") ? pfTags->begin() : caloTags->begin();
348 
349  float Discr_online = iter->second;
350  if (Discr_online < 0)
351  Discr_online = -0.05;
352 
353  v.Discr->Fill(Discr_online);
354  v.Pt->Fill(iter->first->pt());
355  v.Eta->Fill(iter->first->eta());
356 
357  if (offlineJetTagHandlerb.isValid()) {
358  for (auto const& iterOffb : *offlineJetTagHandlerb) {
359  float DR = reco::deltaR(iterOffb.first->eta(), iterOffb.first->phi(), iter->first->eta(), iter->first->phi());
360  if (DR < 0.3) {
361  float Discr_offline = iterOffb.second;
362 
363  // offline probb and probbb must be added (if probbb isn't specified, it'll just use probb)
364  if (offlineJetTagHandlerbb.isValid()) {
365  for (auto const& iterOffbb : *offlineJetTagHandlerbb) {
366  DR = reco::deltaR(
367  iterOffbb.first->eta(), iterOffbb.first->phi(), iter->first->eta(), iter->first->phi());
368  if (DR < 0.3) {
369  Discr_offline += iterOffbb.second;
370  break;
371  }
372  }
373  }
374 
375  if (Discr_offline < 0)
376  Discr_offline = -0.05;
377  v.Discr_HLTvsRECO->Fill(Discr_online, Discr_offline);
378  v.Discr_HLTMinusRECO->Fill(Discr_online - Discr_offline);
379 
380  v.Discr_turnon_loose.denominator->Fill(Discr_offline);
381  v.Discr_turnon_medium.denominator->Fill(Discr_offline);
382  v.Discr_turnon_tight.denominator->Fill(Discr_offline);
383 
384  if (Discr_online > turnon_threshold_loose_)
385  v.Discr_turnon_loose.numerator->Fill(Discr_offline);
386  if (Discr_online > turnon_threshold_medium_)
387  v.Discr_turnon_medium.numerator->Fill(Discr_offline);
388  if (Discr_online > turnon_threshold_tight_)
389  v.Discr_turnon_tight.numerator->Fill(Discr_offline);
390 
391  break;
392  }
393  }
394  }
395 
396  bool pfSVTagCollValid = (v.getTriggerType() == "PF" && jetSVTagsCollPF.isValid());
397  bool caloSVTagCollValid = (v.getTriggerType() == "Calo" && jetSVTagsCollCalo.isValid());
398  if (offlineIPTagHandle.isValid() && (pfSVTagCollValid || caloSVTagCollValid)) {
399  std::vector<float> offlineIP3D;
400  std::vector<float> offlineIP3DSig;
401  std::vector<const reco::Track*> offlineTracks = getOfflineBTagTracks(
402  iter->first->eta(), iter->first->phi(), offlineIPTagHandle, offlineIP3D, offlineIP3DSig);
403  std::vector<const reco::Track*> onlineTracks;
404  std::vector<float> onlineIP3D;
405  std::vector<float> onlineIP3DSig;
406  if (pfSVTagCollValid)
407  onlineTracks = getOnlineBTagTracks<SVTagInfo>(
408  iter->first->eta(), iter->first->phi(), jetSVTagsCollPF, onlineIP3D, onlineIP3DSig);
409  if (caloSVTagCollValid)
410  onlineTracks = getOnlineBTagTracks<reco::SecondaryVertexTagInfo>(
411  iter->first->eta(), iter->first->phi(), jetSVTagsCollCalo, onlineIP3D, onlineIP3DSig);
412 
413  for (unsigned int iOffTrk = 0; iOffTrk < offlineTracks.size(); ++iOffTrk) {
414  const reco::Track* offTrk = offlineTracks.at(iOffTrk);
415  bool hasMatch = false;
416  float offTrkEta = offTrk->eta();
417  float offTrkPhi = offTrk->phi();
418 
419  for (const reco::Track* onTrk : onlineTracks) {
420  float DR = reco::deltaR(offTrkEta, offTrkPhi, onTrk->eta(), onTrk->phi());
421  if (DR < dRTrackMatch_) {
422  hasMatch = true;
423  }
424  }
425 
426  float offTrkPt = offTrk->pt();
427  v.OnlineTrkEff_Pt.denominator->Fill(offTrkPt);
428  if (hasMatch)
429  v.OnlineTrkEff_Pt.numerator->Fill(offTrkPt);
430 
431  v.OnlineTrkEff_Eta.denominator->Fill(offTrkEta);
432  if (hasMatch)
433  v.OnlineTrkEff_Eta.numerator->Fill(offTrkEta);
434 
435  v.OnlineTrkEff_3d_ip_distance.denominator->Fill(offlineIP3D.at(iOffTrk));
436  if (hasMatch)
437  v.OnlineTrkEff_3d_ip_distance.numerator->Fill(offlineIP3D.at(iOffTrk));
438 
439  v.OnlineTrkEff_3d_ip_sig.denominator->Fill(offlineIP3DSig.at(iOffTrk));
440  if (hasMatch)
441  v.OnlineTrkEff_3d_ip_sig.numerator->Fill(offlineIP3DSig.at(iOffTrk));
442  }
443 
444  for (unsigned int iOnTrk = 0; iOnTrk < onlineTracks.size(); ++iOnTrk) {
445  const reco::Track* onTrk = onlineTracks.at(iOnTrk);
446  bool hasMatch = false;
447  float onTrkEta = onTrk->eta();
448  float onTrkPhi = onTrk->phi();
449 
450  for (const reco::Track* offTrk : offlineTracks) {
451  float DR = reco::deltaR(onTrkEta, onTrkPhi, offTrk->eta(), offTrk->phi());
452  if (DR < dRTrackMatch_) {
453  hasMatch = true;
454  }
455  }
456 
457  float onTrkPt = onTrk->pt();
458  v.OnlineTrkFake_Pt.denominator->Fill(onTrkPt);
459  if (!hasMatch)
460  v.OnlineTrkFake_Pt.numerator->Fill(onTrkPt);
461 
462  v.OnlineTrkFake_Eta.denominator->Fill(onTrkEta);
463  if (!hasMatch)
464  v.OnlineTrkFake_Eta.numerator->Fill(onTrkEta);
465 
466  v.OnlineTrkFake_3d_ip_distance.denominator->Fill(onlineIP3D.at(iOnTrk));
467  if (!hasMatch)
468  v.OnlineTrkFake_3d_ip_distance.numerator->Fill(onlineIP3D.at(iOnTrk));
469 
470  v.OnlineTrkFake_3d_ip_sig.denominator->Fill(onlineIP3DSig.at(iOnTrk));
471  if (!hasMatch)
472  v.OnlineTrkFake_3d_ip_sig.numerator->Fill(onlineIP3DSig.at(iOnTrk));
473  }
474  }
475 
476  if (v.getTriggerType() == "PF") {
477  iEvent.getByToken(hltPFPVToken_, VertexHandler);
478  } else {
479  iEvent.getByToken(hltFastPVToken_, VertexHandler);
480  }
481  if (VertexHandler.isValid()) {
482  v.PVz->Fill(VertexHandler->begin()->z());
483  if (offlineVertexHandler.isValid()) {
484  v.PVz_HLTMinusRECO->Fill(VertexHandler->begin()->z() - offlineVertexHandler->begin()->z());
485  }
486  }
487  } // caloTagsValid
488 
489  // specific to Calo b-tagging
490  if (caloTags.isValid() && v.getTriggerType() == "Calo" && !caloTags->empty()) {
491  iEvent.getByToken(hltCaloPVToken_, VertexHandler);
492  if (VertexHandler.isValid()) {
493  v.fastPVz->Fill(VertexHandler->begin()->z());
494  if (offlineVertexHandler.isValid()) {
495  v.fastPVz_HLTMinusRECO->Fill(VertexHandler->begin()->z() - offlineVertexHandler->begin()->z());
496  }
497  }
498  }
499 
500  // additional plots from tag info collections
502 
504  iEvent.getByToken(shallowTagInfosTokenCalo_, shallowTagInfosCalo);
505 
507  iEvent.getByToken(shallowTagInfosTokenPf_, shallowTagInfosPf);
508 
509  // edm::Handle<std::vector<reco::TemplatedSecondaryVertexTagInfo<reco::IPTagInfo<edm::RefVector<std::vector<reco::Track>, reco::Track, edm::refhelper::FindUsingAdvance<std::vector<reco::Track>, reco::Track> >, reco::JTATagInfo>, reco::Vertex> > > caloTagInfos;
510  // iEvent.getByToken(caloTagInfosToken_, caloTagInfos);
511 
512  // edm::Handle<std::vector<reco::TemplatedSecondaryVertexTagInfo<reco::IPTagInfo<edm::RefVector<std::vector<reco::Track>, reco::Track, edm::refhelper::FindUsingAdvance<std::vector<reco::Track>, reco::Track> >, reco::JTATagInfo>, reco::Vertex> > > pfTagInfos;
513  // iEvent.getByToken(pfTagInfosToken_, pfTagInfos);
514 
515  // first try to get info from shallowTagInfos ...
516  if ((v.getTriggerType() == "PF" && shallowTagInfosPf.isValid()) ||
517  (v.getTriggerType() == "Calo" && shallowTagInfosCalo.isValid())) {
518  const auto& shallowTagInfoCollection = (v.getTriggerType() == "PF") ? shallowTagInfosPf : shallowTagInfosCalo;
519  for (const auto& shallowTagInfo : *shallowTagInfoCollection) {
520  const auto& tagVars = shallowTagInfo.taggingVariables();
521 
522  // n secondary vertices and n selected tracks
523  for (const auto& tagVar : tagVars.getList(reco::btau::jetNSecondaryVertices, false)) {
524  v.n_vtx->Fill(tagVar);
525  }
526  for (const auto& tagVar : tagVars.getList(reco::btau::jetNSelectedTracks, false)) {
527  v.n_sel_tracks->Fill(tagVar);
528  }
529 
530  // impact parameter
531  const auto& trackSip3dVal = tagVars.getList(reco::btau::trackSip3dVal, false);
532  const auto& trackSip3dSig = tagVars.getList(reco::btau::trackSip3dSig, false);
533  for (unsigned i_trk = 0; i_trk < trackSip3dVal.size(); i_trk++) {
534  float val = trackSip3dVal[i_trk];
535  float sig = trackSip3dSig[i_trk];
536  v.h_3d_ip_distance->Fill(val);
537  v.h_3d_ip_error->Fill(val / sig);
538  v.h_3d_ip_sig->Fill(sig);
539  }
540 
541  // vertex mass and tracks per vertex
542  for (const auto& tagVar : tagVars.getList(reco::btau::vertexMass, false)) {
543  v.vtx_mass->Fill(tagVar);
544  }
545  for (const auto& tagVar : tagVars.getList(reco::btau::vertexNTracks, false)) {
546  v.n_vtx_trks->Fill(tagVar);
547  }
548 
549  // // track N total/pixel hits
550  // for (const auto & tagVar : tagVars.getList(reco::btau::trackNPixelHits, false)) {
551  // v.n_pixel_hits->Fill(tagVar);}
552  // for (const auto & tagVar : tagVars.getList(reco::btau::trackNTotalHits, false)) {
553  // v.n_total_hits->Fill(tagVar);}
554  }
555  }
556 
557  // ... otherwise from usual tag infos.
558  // else
559  // if ( (v.getTriggerType() == "PF" && pfTagInfos.isValid())
560  // || (v.getTriggerType() == "Calo" && caloTagInfos.isValid()) )
561  // {
562  // const auto & DiscrTagInfoCollection = (v.getTriggerType() == "PF") ? pfTagInfos : caloTagInfos;
563 
564  // // loop over secondary vertex tag infos
565  // for (const auto & DiscrTagInfo : *DiscrTagInfoCollection) {
566  // v.n_vtx->Fill(DiscrTagInfo.nVertexCandidates());
567  // v.n_sel_tracks->Fill(DiscrTagInfo.nSelectedTracks());
568 
569  // // loop over selected tracks in each tag info
570  // for (unsigned i_trk=0; i_trk < DiscrTagInfo.nSelectedTracks(); i_trk++) {
571  // const auto & ip3d = DiscrTagInfo.trackIPData(i_trk).ip3d;
572  // v.h_3d_ip_distance->Fill(ip3d.value());
573  // v.h_3d_ip_error->Fill(ip3d.error());
574  // v.h_3d_ip_sig->Fill(ip3d.significance());
575  // }
576 
577  // // loop over vertex candidates in each tag info
578  // for (unsigned i_sv=0; i_sv < DiscrTagInfo.nVertexCandidates(); i_sv++) {
579  // const auto & sv = DiscrTagInfo.secondaryVertex(i_sv);
580  // v.vtx_mass->Fill(sv.p4().mass());
581  // v.n_vtx_trks->Fill(sv.nTracks());
582 
583  // // loop over tracks for number of pixel and total hits
584  // const auto & trkIPTagInfo = DiscrTagInfo.trackIPTagInfoRef().get();
585  // for (const auto & trk : trkIPTagInfo->selectedTracks()) {
586  // v.n_pixel_hits->Fill(trk.get()->hitPattern().numberOfValidPixelHits());
587  // v.n_total_hits->Fill(trk.get()->hitPattern().numberOfValidHits());
588  // }
589  // }
590  // }
591  // }
592  }
593 }
594 
595 std::vector<const reco::Track*> BTVHLTOfflineSource::getOfflineBTagTracks(float hltJetEta,
596  float hltJetPhi,
597  Handle<View<BaseTagInfo>> offlineIPTagHandle,
598  std::vector<float>& offlineIP3D,
599  std::vector<float>& offlineIP3DSig) {
600  std::vector<const reco::Track*> offlineTracks;
601 
602  for (auto const& iterOffIP : *offlineIPTagHandle) {
603  float DR = reco::deltaR(iterOffIP.jet()->eta(), iterOffIP.jet()->phi(), hltJetEta, hltJetPhi);
604 
605  if (DR > 0.3)
606  continue;
607 
609  dynamic_cast<const reco::IPTagInfo<vector<reco::CandidatePtr>, reco::JetTagInfo>*>(&iterOffIP);
610 
611  if (!tagInfo) {
612  throw cms::Exception("Configuration")
613  << "BTagPerformanceAnalyzer: Extended TagInfo not of type TrackIPTagInfo. " << std::endl;
614  }
615 
616  const GlobalPoint pv(tagInfo->primaryVertex()->position().x(),
617  tagInfo->primaryVertex()->position().y(),
618  tagInfo->primaryVertex()->position().z());
619 
620  const std::vector<reco::btag::TrackIPData>& ip = tagInfo->impactParameterData();
621 
622  std::vector<std::size_t> sortedIndices = tagInfo->sortedIndexes(reco::btag::IP2DSig);
623  std::vector<reco::CandidatePtr> sortedTracks = tagInfo->sortedTracks(sortedIndices);
624  std::vector<std::size_t> selectedIndices;
625  vector<reco::CandidatePtr> selectedTracks;
626  for (unsigned int n = 0; n != sortedIndices.size(); ++n) {
627  double decayLength = (ip[sortedIndices[n]].closestToJetAxis - pv).mag();
628  double jetDistance = ip[sortedIndices[n]].distanceToJetAxis.value();
629  if (decayLength > minDecayLength_ && decayLength < maxDecayLength_ && fabs(jetDistance) >= minJetDistance_ &&
630  fabs(jetDistance) < maxJetDistance_) {
631  selectedIndices.push_back(sortedIndices[n]);
632  selectedTracks.push_back(sortedTracks[n]);
633  }
634  }
635 
636  for (unsigned int n = 0; n != selectedIndices.size(); ++n) {
637  const reco::Track* track = reco::btag::toTrack(selectedTracks[n]);
638  offlineTracks.push_back(track);
639  offlineIP3D.push_back(ip[n].ip3d.value());
640  offlineIP3DSig.push_back(ip[n].ip3d.significance());
641  }
642  }
643  return offlineTracks;
644 }
645 
646 template <class Base>
647 std::vector<const reco::Track*> BTVHLTOfflineSource::getOnlineBTagTracks(float hltJetEta,
648  float hltJetPhi,
649  edm::Handle<std::vector<Base>> jetSVTagsColl,
650  std::vector<float>& onlineIP3D,
651  std::vector<float>& onlineIP3DSig) {
652  std::vector<const reco::Track*> onlineTracks;
653 
654  for (auto iterTI = jetSVTagsColl->begin(); iterTI != jetSVTagsColl->end(); ++iterTI) {
655  float DR = reco::deltaR(iterTI->jet()->eta(), iterTI->jet()->phi(), hltJetEta, hltJetPhi);
656  if (DR > 0.3)
657  continue;
658 
659  const auto& ipInfo = *(iterTI->trackIPTagInfoRef().get());
660  const std::vector<reco::btag::TrackIPData>& ip = ipInfo.impactParameterData();
661 
662  unsigned int trackSize = ipInfo.selectedTracks().size();
663  for (unsigned int itt = 0; itt < trackSize; ++itt) {
664  const auto ptrackRef = (ipInfo.selectedTracks()[itt]); //TrackRef or
665  const reco::Track* ptrackPtr = reco::btag::toTrack(ptrackRef);
666  onlineTracks.push_back(ptrackPtr);
667  onlineIP3D.push_back(ip[itt].ip3d.value());
668  onlineIP3DSig.push_back(ip[itt].ip3d.significance());
669  }
670  }
671  return onlineTracks;
672 }
673 
675  iBooker.setCurrentFolder(dirname_);
676  for (auto& v : hltPathsAll_) {
677  std::string trgPathName = HLTConfigProvider::removeVersion(v.getPath());
678  std::string subdirName = dirname_ + "/" + trgPathName + v.getTriggerType();
679  std::string trigPath = "(" + trgPathName + ")";
680  iBooker.setCurrentFolder(subdirName);
681 
682  std::string labelname("HLT");
683  std::string histoname(labelname + "");
684  std::string title(labelname + "");
685 
686  histoname = labelname + "_Discr";
687  title = labelname + "_Discr " + trigPath;
688  v.Discr = iBooker.book1D(histoname.c_str(), title.c_str(), 110, -0.1, 1);
689 
690  histoname = labelname + "_Pt";
691  title = labelname + "_Pt " + trigPath;
692  v.Pt = iBooker.book1D(histoname.c_str(), title.c_str(), 100, 0, 400);
693 
694  histoname = labelname + "_Eta";
695  title = labelname + "_Eta " + trigPath;
696  v.Eta = iBooker.book1D(histoname.c_str(), title.c_str(), 60, -3.0, 3.0);
697 
698  histoname = "HLTvsRECO_Discr";
699  title = "online discr vs offline discr " + trigPath;
700  v.Discr_HLTvsRECO = iBooker.book2D(histoname.c_str(), title.c_str(), 110, -0.1, 1, 110, -0.1, 1);
701 
702  histoname = "HLTMinusRECO_Discr";
703  title = "online discr minus offline discr " + trigPath;
704  v.Discr_HLTMinusRECO = iBooker.book1D(histoname.c_str(), title.c_str(), 100, -1, 1);
705 
706  histoname = "Turnon_loose_Discr";
707  title = "turn-on with loose threshold " + trigPath;
708  v.bookME(iBooker, v.Discr_turnon_loose, histoname, title, 22, -0.1, 1.);
709 
710  histoname = "Turnon_medium_Discr";
711  title = "turn-on with medium threshold " + trigPath;
712  v.bookME(iBooker, v.Discr_turnon_medium, histoname, title, 22, -0.1, 1.);
713 
714  histoname = "Turnon_tight_Discr";
715  title = "turn-on with tight threshold " + trigPath;
716  v.bookME(iBooker, v.Discr_turnon_tight, histoname, title, 22, -0.1, 1.);
717 
718  histoname = labelname + "_PVz";
719  title = "online z(PV) " + trigPath;
720  v.PVz = iBooker.book1D(histoname.c_str(), title.c_str(), 80, -20, 20);
721 
722  histoname = labelname + "_fastPVz";
723  title = "online z(fastPV) " + trigPath;
724  v.fastPVz = iBooker.book1D(histoname.c_str(), title.c_str(), 80, -20, 20);
725 
726  histoname = "HLTMinusRECO_PVz";
727  title = "online z(PV) - offline z(PV) " + trigPath;
728  v.PVz_HLTMinusRECO = iBooker.book1D(histoname.c_str(), title.c_str(), 200, -0.5, 0.5);
729 
730  histoname = "HLTMinusRECO_fastPVz";
731  title = "online z(fastPV) - offline z(PV) " + trigPath;
732  v.fastPVz_HLTMinusRECO = iBooker.book1D(histoname.c_str(), title.c_str(), 100, -2, 2);
733 
734  histoname = "n_vtx";
735  title = "N vertex candidates " + trigPath;
736  v.n_vtx = iBooker.book1D(histoname.c_str(), title.c_str(), 10, -0.5, 9.5);
737 
738  histoname = "vtx_mass";
739  title = "secondary vertex mass (GeV)" + trigPath;
740  v.vtx_mass = iBooker.book1D(histoname.c_str(), title.c_str(), 20, 0, 10);
741 
742  histoname = "n_vtx_trks";
743  title = "N tracks associated to secondary vertex" + trigPath;
744  v.n_vtx_trks = iBooker.book1D(histoname.c_str(), title.c_str(), 20, -0.5, 19.5);
745 
746  histoname = "n_sel_tracks";
747  title = "N selected tracks" + trigPath;
748  v.n_sel_tracks = iBooker.book1D(histoname.c_str(), title.c_str(), 25, -0.5, 24.5);
749 
750  histoname = "3d_ip_distance";
751  title = "3D IP distance of tracks (cm)" + trigPath;
752  v.h_3d_ip_distance = iBooker.book1D(histoname.c_str(), title.c_str(), 40, -0.1, 0.1);
753 
754  histoname = "3d_ip_error";
755  title = "3D IP error of tracks (cm)" + trigPath;
756  v.h_3d_ip_error = iBooker.book1D(histoname.c_str(), title.c_str(), 40, 0., 0.1);
757 
758  histoname = "3d_ip_sig";
759  title = "3D IP significance of tracks (cm)" + trigPath;
760  v.h_3d_ip_sig = iBooker.book1D(histoname.c_str(), title.c_str(), 40, -40, 40);
761 
762  histoname = "OnlineTrkEff_Pt";
763  title = "Relative Online Trk Efficiency vs Pt " + trigPath;
764  v.bookME(iBooker, v.OnlineTrkEff_Pt, histoname, title, 50, -0.5, 20.);
765 
766  histoname = "OnlineTrkEff_Eta";
767  title = "Relative Online Trk Efficiency vs Eta " + trigPath;
768  v.bookME(iBooker, v.OnlineTrkEff_Eta, histoname, title, 60, -3.0, 3.0);
769 
770  histoname = "OnlineTrkEff_3d_ip_distance";
771  title = "Relative Online Trk Efficiency vs IP3D " + trigPath;
772  v.bookME(iBooker, v.OnlineTrkEff_3d_ip_distance, histoname, title, 40, -0.1, 0.1);
773 
774  histoname = "OnlineTrkEff_3d_ip_sig";
775  title = "Relative Online Trk Efficiency vs IP3D significance " + trigPath;
776  v.bookME(iBooker, v.OnlineTrkEff_3d_ip_sig, histoname, title, 40, -40, 40);
777 
778  histoname = "OnlineTrkFake_Pt";
779  title = "Relative Online Trk Fake Rate vs Pt " + trigPath;
780  v.bookME(iBooker, v.OnlineTrkFake_Pt, histoname, title, 50, -0.5, 20.);
781 
782  histoname = "OnlineTrkFake_Eta";
783  title = "Relative Online Trk Fake Rate vs Eta " + trigPath;
784  v.bookME(iBooker, v.OnlineTrkFake_Eta, histoname, title, 60, -3.0, 3.0);
785 
786  histoname = "OnlineTrkFake_3d_ip_distance";
787  title = "Relative Online Trk Fake Rate vs IP3D " + trigPath;
788  v.bookME(iBooker, v.OnlineTrkFake_3d_ip_distance, histoname, title, 40, -0.1, 0.1);
789 
790  histoname = "OnlineTrkFake_3d_ip_sig";
791  title = "Relative Online Trk Fake Rate vs IP3D significance " + trigPath;
792  v.bookME(iBooker, v.OnlineTrkFake_3d_ip_sig, histoname, title, 40, -40, 40);
793 
794  // histoname = "n_pixel_hits";
795  // title = "N pixel hits"+trigPath;
796  // v.n_pixel_hits = iBooker.book1D(histoname.c_str(), title.c_str(), 16, -0.5, 15.5);
797 
798  // histoname = "n_total_hits";
799  // title = "N hits"+trigPath;
800  // v.n_total_hits = iBooker.book1D(histoname.c_str(), title.c_str(), 40, -0.5, 39.5);
801  }
802 }
803 
804 // Define this as a plug-in
std::size_t size() const
Definition: TriggerNames.cc:59
void analyze(const edm::Event &, const edm::EventSetup &) override
RunNumber_t run() const
Definition: EventID.h:38
unsigned int size() const
number of trigger paths in trigger table
BTVHLTOfflineSource(const edm::ParameterSet &)
const std::string getPath() const
EventNumber_t event() const
Definition: EventID.h:40
tuple decayLength
Definition: listHistos.py:101
const edm::EventSetup & c
edm::EDGetTokenT< std::vector< SVTagInfo > > SVTagInfosTokenPf_
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
const std::string & triggerName(unsigned int triggerIndex) const
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
static PFTauRenderPlugin instance
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
const std::string getLabel() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< std::vector< reco::ShallowTagInfo > > shallowTagInfosTokenCalo_
edm::EDGetTokenT< reco::JetTagCollection > pfTagsToken_
const bool operator==(const std::string &v) const
edm::EDGetTokenT< reco::JetTagCollection > offlineDiscrTokenb_
unsigned int triggerIndex(std::string_view name) const
Definition: TriggerNames.cc:52
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
void setLabel(std::string labelName)
edm::EDGetTokenT< std::vector< reco::Vertex > > hltCaloPVToken_
reco::TemplatedSecondaryVertexTagInfo< reco::CandIPTagInfo, reco::VertexCompositePtrCandidate > SVTagInfo
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const reco::Track * toTrack(const reco::TrackBaseRef &t)
Definition: IPTagInfo.h:24
edm::EDGetTokenT< std::vector< reco::SecondaryVertexTagInfo > > SVTagInfosTokenCalo_
static const std::string removeVersion(const std::string &trigger)
const edm::Ref< VertexCollection > & primaryVertex() const
Definition: IPTagInfo.h:133
edm::EDGetTokenT< std::vector< reco::Vertex > > offlinePVToken_
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:275
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryFUToken
char const * label
std::vector< PathInfo >::iterator find(const std::string &pathName)
int iEvent
Definition: GenABIO.cc:224
edm::InputTag triggerResultsLabel_
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
edm::Handle< reco::JetTagCollection > pfTags
edm::InputTag triggerSummaryLabel_
double pt() const
track transverse momentum
Definition: TrackBase.h:637
def move
Definition: eostools.py:511
~PathInfo() override=default
const std::string getProcess() const
PathInfo(const int prescaleUsed, const std::string &pathName, const std::string &filterName, const std::string &processName, const int type, const std::string &triggerType)
PathInfoCollection hltPathsAll_
const edm::InputTag getTag() const
~BTVHLTOfflineSource() override
static std::string const triggerResults
Definition: EdmProvDump.cc:44
std::vector< size_t > sortedIndexes(btag::SortCriteria mode=reco::btag::IP3DSig) const
Definition: IPTagInfo.h:231
bool isValid() const
Definition: HandleBase.h:70
HLTConfigProvider hltConfig_
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
const std::vector< btag::TrackIPData > & impactParameterData() const
Definition: IPTagInfo.h:90
edm::EDGetTokenT< reco::JetTagCollection > offlineDiscrTokenbb_
edm::EDGetTokenT< std::vector< reco::Vertex > > hltFastPVToken_
Log< level::Info, false > LogInfo
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken
const std::string getTriggerType() const
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
edm::EDGetTokenT< std::vector< reco::Vertex > > hltPFPVToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void dqmBeginRun(edm::Run const &run, edm::EventSetup const &c) override
std::vector< const reco::Track * > getOfflineBTagTracks(float hltJetEta, float hltJetPhi, edm::Handle< edm::View< reco::BaseTagInfo >> offlineIPTagHandle, std::vector< float > &offlineIP3D, std::vector< float > &offlineIP3DSig)
std::vector< std::pair< std::string, std::string > > custompathnamepairs_
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryToken
edm::EventID id() const
Definition: EventBase.h:59
edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > offlineIPToken_
edm::EDGetTokenT< std::vector< reco::ShallowTagInfo > > shallowTagInfosTokenPf_
string end
Definition: dataset.py:937
tuple cout
Definition: gather_cfg.py:144
edm::Handle< reco::JetTagCollection > caloTags
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Container sortedTracks(const std::vector< size_t > &indexes) const
Definition: IPTagInfo.h:129
void bookHistograms(DQMStore::IBooker &, edm::Run const &run, edm::EventSetup const &c) override
edm::EDGetTokenT< reco::JetTagCollection > caloTagsToken_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsFUToken
std::vector< const reco::Track * > getOnlineBTagTracks(float hltJetEta, float hltJetPhi, edm::Handle< std::vector< Base >> jetSVTagsColl, std::vector< float > &onlineIP3D, std::vector< float > &onlineIP3DSig)
Definition: Run.h:45
#define LogDebug(id)