CMS 3D CMS Logo

HLTObjectsMonitor.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <sys/time.h>
4 #include <cstdlib>
5 #include <unordered_map>
6 
7 // user include files
12 
21 
23 
24 //for collections
26 
35 
38 
39 #include "TLorentzVector.h"
40 
41 
42 
43 struct hltPlot {
44 
45  std::pair<MonitorElement*,bool> nME;
46  std::pair<MonitorElement*,bool> etaME;
47  std::pair<MonitorElement*,bool> phiME;
48  std::pair<MonitorElement*,bool> ptME;
49  std::pair<MonitorElement*,bool> massME;
50  std::pair<MonitorElement*,bool> energyME;
51  std::pair<MonitorElement*,bool> csvME;
52  std::pair<MonitorElement*,bool> etaVSphiME;
53  std::pair<MonitorElement*,bool> ptMEhep17;
54  std::pair<MonitorElement*,bool> ptMEhem17; // in harvesting step ratio
55  std::pair<MonitorElement*,bool> mrME;
56  std::pair<MonitorElement*,bool> rsqME;
57  std::pair<MonitorElement*,bool> dxyME;
58  std::pair<MonitorElement*,bool> dzME;
59  std::pair<MonitorElement*,bool> dimassME;
60  std::pair<MonitorElement*,bool> dRME;
61  std::pair<MonitorElement*,bool> dRetaVSphiME;
62  std::pair<MonitorElement*,bool> q1q2ME;
63 
66  int pathIDX;
68 
70  std::vector<double> etaBINNING;
71  std::vector<double> ptBINNING;
72  std::vector<double> phiBINNING;
73  std::vector<double> massBINNING;
74  std::vector<double> dxyBINNING;
75  std::vector<double> dzBINNING;
76  std::vector<double> dimassBINNING;
77 
78  bool doPlot2D;
79  bool doPlotETA;
80  bool doPlotMASS;
83  bool doPlotCSV;
84  bool doCALO;
85  bool doPF;
87  bool doPlotDXY;
88  bool doPlotDZ;
90 };
91 //
92 // class declaration
93 //
94 
95 //using namespace edm;
96 using std::unordered_map;
97 
99 
100  public:
101  explicit HLTObjectsMonitor(const edm::ParameterSet&);
102  ~HLTObjectsMonitor() override = default;
103 
104  // static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
105 
106 
107  private:
108  void analyze(const edm::Event&, const edm::EventSetup&) override;
109  void bookHistograms(DQMStore::IBooker &i, edm::Run const&, edm::EventSetup const&) override;
110  void dqmBeginRun(edm::Run const&, edm::EventSetup const&) override;
111 
112  static hltPlot getPlotPSet(edm::ParameterSet pset);
113  void getPSet();
114  bool isHEP17(double eta, double phi);
115  bool isHEM17(double eta, double phi);
116 
117  double dxyFinder(double, double, edm::Handle<reco::RecoChargedCandidateCollection>, edm::Handle<reco::BeamSpot>, double);
118  double dzFinder(double, double, double, double, edm::Handle<reco::RecoChargedCandidateCollection>, double);
119  // ----------member data ---------------------------
120 
124  std::vector<edm::ParameterSet> plotPSETS_;
125 
127 
129  std::vector<hltPlot> hltPlots_;
130  std::unordered_map<std::string, int> plotNamesToBins_;
131 
132  bool debug_;
133 
136 
137 
140 
143 
146 
151 
152  const double MASS_MU = .105658;
153 
154 
155 struct MEbinning {
156  int nbins;
157  double xmin;
158  double xmax;
159 };
160 
161 
162 double MAX_PHI = 3.2;
163 int N_PHI = 64;
164 const MEbinning phi_binning_{
165  N_PHI, -MAX_PHI, MAX_PHI
166 };
167 
168 double MAX_CSV = 1.;
169 int N_CSV = 20;
170 const MEbinning csv_binning_{
171  N_CSV, -MAX_CSV, MAX_CSV
172 };
173 
174 std::vector<double> phi_variable_binning_;
175 
176 /*
177  HEP17 covers
178  - phi between 310° and 330° (-50° to -30°, or -0.87 t.52 rad)
179  - eta between +1.3 and +3.0 (positive side only)
180 */
181 double MAX_PHI_HEP17 = -0.52;
182 double MIN_PHI_HEP17 = -0.87;
183 int N_PHI_HEP17 = 7;
184 const MEbinning phi_binning_hep17_{
185  N_PHI_HEP17, MIN_PHI_HEP17, MAX_PHI_HEP17
186 };
187 double MAX_ETA_HEP17 = 3.0;
188 double MIN_ETA_HEP17 = 1.3;
189 int N_ETA_HEP17 = 6;
190 const MEbinning eta_binning_hep17_{
191  N_ETA_HEP17, MIN_ETA_HEP17, MAX_ETA_HEP17
192 };
193 
194 const MEbinning eta_binning_hem17_{
195  N_ETA_HEP17, -MAX_ETA_HEP17, MIN_ETA_HEP17
196 };
197 
198 };
199 
200 //
201 // constants, enums and typedefs
202 //
203 
204 //
205 // static data member definitions
206 //
207 hltPlot
209 
210  return hltPlot{
211  std::make_pair<MonitorElement*,bool>(nullptr,false),
212  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_eta") ),
213  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_phi") ),
214  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_pt") ),
215  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_mass") ),
216  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_energy") ),
217  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_csv") ),
218  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_etaVSphi") ),
219  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_pt_HEP17") ),
220  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_pt_HEM17") ),
221  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_MR") ),
222  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_RSQ") ),
223  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_dxy") ),
224  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_dz") ),
225  std::make_pair<MonitorElement*,bool>(nullptr,pset.getParameter<bool>("displayInPrimary_dimass") ),
226  std::make_pair<MonitorElement*,bool>(nullptr,false),
227  std::make_pair<MonitorElement*,bool>(nullptr,false),
228  std::make_pair<MonitorElement*,bool>(nullptr,false),
229  pset.getParameter<std::string>("label" ),
230  pset.getParameter<std::string>("pathNAME" ),
231  -1,
232  pset.getParameter<std::string>("moduleNAME"),
233  pset.getParameter<std::string>("xTITLE" ),
234  pset.getParameter<std::vector<double> >("etaBINNING" ),
235  pset.getParameter<std::vector<double> >("ptBINNING" ),
236  pset.getParameter<std::vector<double> >("phiBINNING" ),
237  pset.getParameter<std::vector<double> >("massBINNING" ),
238  pset.getParameter<std::vector<double> >("dxyBINNING" ),
239  pset.getParameter<std::vector<double> >("dzBINNING" ),
240  pset.getParameter<std::vector<double> >("dimassBINNING" ),
241  pset.getUntrackedParameter<bool>("doPlot2D", false ),
242  pset.getUntrackedParameter<bool>("doPlotETA", true ),
243  pset.getUntrackedParameter<bool>("doPlotMASS", false ),
244  pset.getUntrackedParameter<bool>("doPlotENERGY", false ),
245  pset.getUntrackedParameter<bool>("doPlotHEP17", true ),
246  pset.getUntrackedParameter<bool>("doPlotCSV", false ),
247  pset.getUntrackedParameter<bool>("doCALO", false ),
248  pset.getUntrackedParameter<bool>("doPF", false ),
249  pset.getUntrackedParameter<bool>("doPlotRazor", false ),
250  pset.getUntrackedParameter<bool>("doPlotDXY", false ),
251  pset.getUntrackedParameter<bool>("doPlotDZ", false ),
252  pset.getUntrackedParameter<bool>("doPlotDiMass", false )
253  };
254 
255 }
256 
257 void
259 
260  for ( const auto & pset : plotPSETS_ )
261  hltPlots_.push_back( getPlotPSet(pset) );
262 }
263 
264 bool HLTObjectsMonitor::isHEP17(double eta, double phi) {
265  if ( (eta >= MIN_ETA_HEP17 && eta <= MAX_ETA_HEP17) &&
266  (phi >= MIN_PHI_HEP17 && phi <= MAX_PHI_HEP17) ) return true;
267  else
268  return false;
269 }
270 bool HLTObjectsMonitor::isHEM17(double eta, double phi) {
271  if ( (eta >= -MAX_ETA_HEP17 && eta <= -MIN_ETA_HEP17) &&
272  (phi >= MIN_PHI_HEP17 && phi <= MAX_PHI_HEP17) ) return true;
273  else
274  return false;
275 }
276 //
277 // constructors and destructor
278 //
280  : TopFolder_ ( iConfig.getParameter<std::string>("TopFolder") )
281  , label_ ( iConfig.getParameter<std::string>("label") )
282  , processName_ ( iConfig.getParameter<std::string>("processName") )
283  , plotPSETS_ ( iConfig.getParameter<std::vector<edm::ParameterSet> >("plots") )
284  , debug_ ( iConfig.getUntrackedParameter<bool>("debug",false) )
285  , triggerResultsToken_ ( consumes<edm::TriggerResults> (iConfig.getParameter<edm::InputTag>("TriggerResults") ) )
286  , triggerEventToken_ ( consumes<trigger::TriggerEvent>(iConfig.getParameter<edm::InputTag>("TriggerSummary") ) )
287  , beamSpot_ ( iConfig.getParameter<edm::InputTag>("beamspot") )
288  , beamSpotToken_ ( consumes<reco::BeamSpot>(beamSpot_) )
289  , caloJetBTagsToken_ ( consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("caloJetBTags") ) )
290  , pfJetBTagsToken_ ( consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("pfJetBTags") ) )
291  , muCandidates_ ( iConfig.getParameter<edm::InputTag>("muCandidates") )
292  , muCandidatesToken_ ( consumes<std::vector<reco::RecoChargedCandidate> >(muCandidates_) )
293  , eleCandidates_ ( iConfig.getParameter<edm::InputTag>("eleCandidates") )
294  , eleCandidatesToken_ ( consumes<std::vector<reco::RecoChargedCandidate> >(eleCandidates_) )
295 {
296  getPSet();
297 
298  //now do what ever initialization is needed
299  mainFolder_ = TopFolder_+"/MainShifter";
300  backupFolder_ = TopFolder_+"/Backup";
301 
302  //set Token(s)
303 
304 
305  double step = 2*MAX_PHI/double(N_PHI);
306  for ( int i=0; i<=N_PHI; i++)
307  phi_variable_binning_.push_back(-MAX_PHI + step*i);
308 
309 }
310 
311 
312 //
313 // member functions
314 //
315 
316 // ------------ method called for each event ------------
317 void
319 {
320  // if ( debug_ )
321  // std::cout << "[HLTObjectsMonitor::analyze]" << std::endl;
322 
323  // access trigger results
325  iEvent.getByToken(triggerResultsToken_, triggerResults);
326  if (!triggerResults.isValid()) return;
327 
329  iEvent.getByToken(triggerEventToken_, triggerEvent);
330  if (!triggerEvent.isValid()) return;
331 
333  iEvent.getByToken(caloJetBTagsToken_, caloJetBTags);
334 
336  iEvent.getByToken(pfJetBTagsToken_, pfJetBTags);
337 
339  iEvent.getByToken(muCandidatesToken_, muCandidates);
340 
342  iEvent.getByToken(eleCandidatesToken_, eleCandidates);
343 
345  iEvent.getByToken(beamSpotToken_, beamspot);
346 
347  // loop over path
348  int ibin = -1;
349  std::vector<bool> plottedPathIndices(plotNamesToBins_.size(),false);
350  for (auto & plot : hltPlots_) {
351  ibin++;
352  if ( plot.pathIDX <= 0 ) continue;
353 
354  if ( triggerResults->accept(plot.pathIDX) ) {
355  //We only want to fill this once per pathNAME per event
356  auto index = plotNamesToBins_[plot.pathNAME];
357  if(not plottedPathIndices[index]) {
358  plottedPathIndices[index] = true;
359  if ( debug_ )
360  std::cout << plot.pathNAME << " --> bin: " << ibin << std::endl;
361  eventsPlot_->Fill(index);
362  }
363  const trigger::TriggerObjectCollection objects = triggerEvent->getObjects();
364  if ( hltConfig_.saveTags(plot.moduleNAME) ) {
365  if ( debug_ )
366  std::cout << "objects: " << objects.size() << std::endl;
367 
368  bool moduleFOUND = false;
369  std::vector<std::string> moduleNames = hltConfig_.moduleLabels(plot.pathIDX);
370  for ( const auto & module : moduleNames ) {
371  if ( module == plot.moduleNAME) moduleFOUND = true;
372  }
373  if ( debug_ )
374  std::cout << plot.moduleNAME << (moduleFOUND ? "" : "NOT" ) << " found in the list of modules" << std::endl;
375 
376  if (debug_)
377  for ( const auto & module : moduleNames ) {
378  unsigned int idx = triggerEvent->filterIndex(edm::InputTag(module,"",processName_));
379  std::cout << "module: " << module;
380  if ( idx < triggerEvent->sizeFilters() )
381  std::cout << " --> " << idx;
382  std::cout << std::endl;
383  }
384  //
385  // trigger accepted and collection w/ objects is available
387  unsigned int moduleIDX = triggerEvent->filterIndex(moduleName);
388  if (debug_)
389  std::cout << "moduleNAME: " << plot.moduleNAME << " --> " << moduleIDX << std::endl;
390 
391  if ( moduleIDX >= triggerEvent->sizeFilters() ) {
392  LogDebug ("HLTObjectsMonitor") << plot.pathNAME << " " << plot.moduleNAME << " is not available ! please, fix update DQM/HLTEvF/python/HLTObjectsMonitor_cfi.py";
393  return;
394  }
395 
396  const trigger::Keys &keys = triggerEvent->filterKeys( moduleIDX );
397  if ( debug_ )
398  std::cout << "keys: " << keys.size() << std::endl;
399 
400  plot.nME.first->Fill(keys.size());
401 
402  double MR = 0.;
403  double RSQ = 0.;
404  for ( const auto & key : keys ) {
405 
406  double pt = objects[key].pt();
407  double eta = objects[key].eta();
408  double phi = objects[key].phi();
409  double mass = objects[key].mass();
410  double energy = objects[key].energy();
411  int id = objects[key].id();
412  if ( debug_ )
413  std::cout << "object ID " << id << " mass: " << mass << std::endl;
414 
415  // single-object plots
416  plot.ptME.first->Fill(pt);
417  if ( plot.doPlotETA ) plot.etaME.first->Fill(eta);
418  plot.phiME.first->Fill(phi);
419 
420  if ( plot.doPlotCSV ) {
421 
422  if ( plot.doCALO ) {
423  if ( !caloJetBTags.isValid() ) plot.csvME.first->Fill(-10.);
424  else {
425  for ( auto it = caloJetBTags->begin();
426  it != caloJetBTags->end(); ++it ) {
427  double dR = deltaR(eta,phi,it->first->eta(),it->first->phi());
428  if ( debug_ )
429  std::cout << "[HLTObjectsMonitor::analyze] deltaR: " << dR << " matched ? " << ( dR <= 0.4 ? "YEAP" : "NOPE" ) << std::endl;
430  plot.csvME.first->Fill(it->second);
431  }
432  }
433 
434  } else if ( plot.doPF ) {
435  if ( !pfJetBTags.isValid() ) plot.csvME.first->Fill(-10.);
436  else {
437  for ( auto it = pfJetBTags->begin();
438  it != pfJetBTags->end(); ++it ) {
439  double dR = deltaR(eta,phi,it->first->eta(),it->first->phi());
440  if ( debug_ )
441  std::cout << "[HLTObjectsMonitor::analyze] deltaR: " << dR << " matched ? " << ( dR <= 0.4 ? "YEAP" : "NOPE" ) << std::endl;
442  plot.csvME.first->Fill(it->second);
443  }
444  }
445  }
446  }
447  if ( plot.doPlotMASS ) plot.massME.first->Fill(mass);
448  if ( plot.doPlotENERGY ) plot.energyME.first->Fill(energy);
449  if ( plot.doPlot2D ) plot.etaVSphiME.first->Fill(eta,phi);
450  if ( plot.doPlotHEP17 ) {
451  if ( isHEP17(eta,phi) ) plot.ptMEhep17.first->Fill(pt);
452  if ( isHEM17(eta,phi) ) plot.ptMEhem17.first->Fill(pt);
453  }
454 
455  if(id == 0){ //the MET object containing MR and Rsq will show up with ID = 0
456  MR = objects[key].px(); //razor variables stored in dummy reco::MET objects
457  RSQ = objects[key].py();
458  }
459 
460  if ( plot.doPlotDXY ) {
461  double dxy = -99.;
462  if ( abs(id) == 13 )
463  dxy = dxyFinder(eta,phi,muCandidates, beamspot, 0.1); // dRcut = 0.1
464  else
465  dxy = dxyFinder(eta,phi,eleCandidates, beamspot, 0.1); // dRcut = 0.1
466  plot.dxyME.first->Fill(dxy);
467  }
468  } // end loop on keys
469  if ( plot.doPlotRazor ) {
470  plot.mrME.first->Fill(MR);
471  plot.rsqME.first->Fill(RSQ);
472  }
473 
474  if ( keys.size() < 2 ) {
475  if ( plot.doPlotDiMass || plot.doPlotDZ )
476  LogDebug ("HLTObjectsMonitor") << plot.pathNAME << " " << plot.moduleNAME << " # objects is (" << keys.size() << ") less than 2 ! you probably want to either change the moduleNAME or switch off di-object system plots (doPlotDZ: " << plot.doPlotDZ << " doPlotDiMass: " << plot.doPlotDiMass << ") in DQM/HLTEvF/python/HLTObjectsMonitor_cfi.py)";
477  } else {
478  for ( const auto & key : keys ) {
479  double pt = objects[key].pt();
480  double eta = objects[key].eta();
481  double phi = objects[key].phi();
482  int id = objects[key].id();
483 
484  unsigned int kCnt0 = 0;
485 
486  TLorentzVector v1;
487  if ( abs(id) == 13 ) // check if it is a muon
488  v1.SetPtEtaPhiM(pt,eta,phi,MASS_MU);
489  else
490  v1.SetPtEtaPhiM(pt,eta,phi,0);
491 
492  unsigned int kCnt1 = 0;
493  for ( const auto & key1: keys ) {
494 
495  if (key != key1 && kCnt1 > kCnt0) { // avoid filling hists with same objs && avoid double counting separate objs
496 
497  double pt2 = objects[key1].phi();
498  double eta2 = objects[key1].eta();
499  double phi2 = objects[key1].phi();
500  int id2 = objects[key1].id();
501 
502  double dR = deltaR( eta, phi, eta2, phi2);
503  plot.dRME.first->Fill(dR);
504  plot.dRetaVSphiME.first->Fill(eta,phi,dR);
505 
506  int q1 = ( id==0 ? 0 : id/abs(id) );
507  int q2 = ( id2==0 ? 0 : id2/abs(id2) );
508  int q1q2 = q1*q2;
509  plot.q1q2ME.first->Fill(q1q2);
510 
511  if ( abs(id) != abs(id2) )
512  edm::LogInfo ("HLTObjectsMonitor") << plot.pathNAME << " " << plot.moduleNAME << " objects have different ID !?!" << abs(id) << " and " << abs(id2);
513 
514  if( (id+id2 ) == 0 ) { // check di-object system charge and flavor
515 
516  TLorentzVector v2;
517  if ( abs( id2 ) == 13 ) // check if it is a muon
518  v2.SetPtEtaPhiM(pt2,eta2,phi2, MASS_MU);
519  else
520  v2.SetPtEtaPhiM(pt2,eta2,phi2, 0);
521 
522  if ( plot.doPlotDiMass ) {
523  TLorentzVector v = v1+v2;
524  plot.dimassME.first->Fill(v.M());
525  }
526 
527  if ( plot.doPlotDZ ) {
528  double dz = -99.;
529  if ( abs(id) == 13 )
530  dz = dzFinder(eta,phi,eta2,phi2,muCandidates, 0.1); // dRcut = 0.1
531  else
532  dz = dzFinder(eta,phi,eta2,phi2,eleCandidates, 0.1); // dRcut = 0.1
533  plot.dzME.first->Fill(dz);
534  }
535  }
536 
537  }
538  kCnt1++;
539  }
540  kCnt0++;
541  }
542 
543  }
544  }
545  }
546  }
547 
548 }
549 
550 // ------------ method called when starting to processes a run ------------
551 void
553 {
554  bool changed = true;
555  if (hltConfig_.init(iRun, iSetup, processName_, changed))
556  if (debug_) std::cout << "[HLTObjectsMonitor::dqmBeginRun] extracting HLTconfig" << std::endl;
557 
558  //get path indicies from menu
559  std::string pathName_noVersion;
560  std::vector<std::string> triggerPaths = hltConfig_.triggerNames();
561 
562  if ( debug_ )
563  std::cout << "[HLTObjectsMonitor::dqmBeginRun] triggerPaths: " << triggerPaths.size() << " <--> " << hltPlots_.size() << std::endl;
564 
565  for (const auto & pathName : triggerPaths) {
566 
567  if ( debug_ )
568  std::cout << "[HLTObjectsMonitor::dqmBeginRun] " << pathName << std::endl;
569 
570  pathName_noVersion = hltConfig_.removeVersion(pathName);
571  // std::cout << "pathName: " << pathName << " --> " << pathName_noVersion << std::endl;
572  for (auto & plot : hltPlots_) {
573  if (plot.pathNAME == pathName_noVersion) {
574  plot.pathIDX = hltConfig_.triggerIndex(pathName);
575  // check that the index makes sense, otherwise force pathIDX = -1
576  if ( plot.pathIDX <= 0 || plot.pathIDX == int(triggerPaths.size()) )
577  plot.pathIDX = -1;
578  }
579  }
580  }
581 
582  if ( debug_ ) {
583  for (const auto & plot : hltPlots_)
584  std::cout << "plot: " << plot.pathNAME << " --> pathIDX: " << plot.pathIDX << std::endl;
585  std::cout << "[HLTObjectsMonitor::dqmBeginRun] DONE" << std::endl;
586  }
587 
588 }
589 
591 {
592 
593  if ( debug_ )
594  std::cout << "[HLTObjectsMonitor::bookHistograms]" << std::endl;
595 
596  ibooker.setCurrentFolder(TopFolder_);
597 
598  std::string name = "eventsPerPath_"+label_;
599  std::string title = " events per path";
600 
601  //We must avoid repeating the same pathNAME
602  {
603  std::unordered_map<std::string,int> uniqueNames;
604  for(auto const& p: hltPlots_) {
605  plotNamesToBins_[p.pathNAME] = -1;
606  }
607  int nbins = plotNamesToBins_.size();
608  eventsPlot_ = ibooker.book1D(name,title,nbins,-0.5,double(nbins)-0.5);
609  eventsPlot_->setAxisTitle("HLT path");
610  int i=0;
611  //keep the bin order the same as hltPlots_
612  for (auto const& p : hltPlots_) {
613  //only add a bin if this is the first time we've seen the name
614  if( -1 == plotNamesToBins_[p.pathNAME]) {
615  plotNamesToBins_[p.pathNAME] = ++i;
616  eventsPlot_->setBinLabel(i,p.pathNAME);
617  if ( debug_ )
618  std::cout << p.pathNAME << " --> bin: " << i << std::endl;
619  }
620  }
621  }
622 
623  for (auto & plot : hltPlots_) {
624 
625  if ( debug_ )
626  std::cout << "booking plots for " << plot.label << std::endl;
627 
628  if ( plot.pathIDX <= 0 ) {
629  LogDebug ("HLTObjectsMonitor") << plot.pathNAME << " is not available in the HLT menu ! no plots are going to be booked for it (update DQM/HLTEvF/python/HLTObjectsMonitor_cfi.py)";
630  continue;
631  }
632  if ( debug_ )
633  std::cout << "booking histograms for " << plot.pathNAME << std::endl;
634 
635  {
636  if ( plot.nME.second )
637  ibooker.setCurrentFolder(mainFolder_);
638  else
640 
641  name = plot.label+"_nobjects";
642  title = plot.pathNAME+" # objects";
643  plot.nME.first = ibooker.book1D(name,title,20,-0.5,19.5);
644  plot.nME.first->setAxisTitle(plot.xTITLE+" # objects");
645  }
646 
647  if ( plot.ptME.second )
648  ibooker.setCurrentFolder(mainFolder_);
649  else
651 
652  name = plot.label+"_pt";
653  title = plot.pathNAME+" p_T";
654  int nbins = (plot.ptBINNING).size()-1;
655  std::vector<float> fbinning((plot.ptBINNING).begin(),(plot.ptBINNING).end());
656  float* arr = &fbinning[0];
657  plot.ptME.first = ibooker.book1D(name,title,nbins,arr);
658  plot.ptME.first->setAxisTitle(plot.xTITLE+" p_{T} [GeV]");
659 
660 
661  {
662  if ( plot.phiME.second )
663  ibooker.setCurrentFolder(mainFolder_);
664  else
666 
667  name = plot.label+"_phi";
668  title = plot.pathNAME+" #phi";
669  int nbins = (plot.phiBINNING).size()-1;
670  std::vector<float> fbinning((plot.phiBINNING).begin(),(plot.phiBINNING).end());
671  float* arr = &fbinning[0];
672  plot.phiME.first = ibooker.book1D(name,title,nbins,arr);
673  plot.phiME.first->setAxisTitle(plot.xTITLE+" #phi [rad]");
674  }
675 
676  if ( plot.doPlotETA ) {
677  if ( plot.etaME.second )
678  ibooker.setCurrentFolder(mainFolder_);
679  else
681 
682  name = plot.label+"_eta";
683  title = plot.pathNAME+" #eta";
684  int nbins = (plot.etaBINNING).size()-1;
685  std::vector<float> fbinning((plot.etaBINNING).begin(),(plot.etaBINNING).end());
686  float* arr = &fbinning[0];
687 
688  plot.etaME.first = ibooker.book1D(name,title,nbins,arr);
689  plot.etaME.first->setAxisTitle(plot.xTITLE+" #eta");
690  }
691 
692  if ( plot.doPlotMASS ) {
693  if ( plot.massME.second )
694  ibooker.setCurrentFolder(mainFolder_);
695  else
697 
698  name = plot.label+"_mass";
699  title = plot.pathNAME+" mass";
700  int nbins = (plot.massBINNING).size()-1;
701  std::vector<float> fbinning((plot.massBINNING).begin(),(plot.massBINNING).end());
702  float* arr = &fbinning[0];
703 
704  plot.massME.first = ibooker.book1D(name,title,nbins,arr);
705  plot.massME.first->setAxisTitle(plot.xTITLE+" mass [GeV]");
706  }
707 
708  if ( plot.doPlotENERGY ) {
709  if ( plot.energyME.second )
710  ibooker.setCurrentFolder(mainFolder_);
711  else
713 
714  name = plot.label+"_energy";
715  title = plot.pathNAME+" energy";
716  int nbins = (plot.ptBINNING).size()-1;
717  std::vector<float> fbinning((plot.ptBINNING).begin(),(plot.ptBINNING).end());
718  float* arr = &fbinning[0];
719 
720  plot.energyME.first = ibooker.book1D(name,title,nbins,arr);
721  plot.energyME.first->setAxisTitle(plot.xTITLE+" energy [GeV]");
722  }
723 
724  if ( plot.doPlotCSV ) {
725  if ( plot.csvME.second )
726  ibooker.setCurrentFolder(mainFolder_);
727  else
729 
730  name = plot.label+"_csv";
731  title = plot.pathNAME+" CSV";
732 
733  plot.csvME.first = ibooker.book1D(name,title,csv_binning_.nbins,csv_binning_.xmin,csv_binning_.xmax);
734  plot.csvME.first->setAxisTitle(plot.xTITLE+" CSV discriminator");
735  }
736 
737  if ( plot.doPlot2D ) {
738  if ( plot.etaVSphiME.second )
739  ibooker.setCurrentFolder(mainFolder_);
740  else
742 
743  name = plot.label+"_etaVSphi";
744  title = plot.pathNAME+" #eta vs #phi";
745  int nbinsX = (plot.etaBINNING).size()-1;
746  std::vector<float> fbinningX((plot.etaBINNING).begin(),(plot.etaBINNING).end());
747  float* arrX = &fbinningX[0];
748  int nbinsY = (plot.phiBINNING).size()-1;;
749  std::vector<float> fbinningY((plot.phiBINNING).begin(),(plot.phiBINNING).end());
750  float* arrY = &fbinningY[0];
751  plot.etaVSphiME.first = ibooker.book2D(name,title,nbinsX,arrX,nbinsY,arrY);
752  plot.etaVSphiME.first->setAxisTitle(plot.xTITLE+" #eta",1);
753  plot.etaVSphiME.first->setAxisTitle(plot.xTITLE+" #phi",2);
754  }
755 
756  if ( plot.doPlotHEP17 ) {
757 
758  if ( plot.ptMEhep17.second )
759  ibooker.setCurrentFolder(mainFolder_);
760  else
762 
763  int nbins = (plot.ptBINNING).size()-1;
764  std::vector<float> fbinning((plot.ptBINNING).begin(),(plot.ptBINNING).end());
765  float* arr = &fbinning[0];
766 
767  name = plot.label+"_pt_HEP17";
768  title = plot.pathNAME+" p_{T} HEP17";
769  plot.ptMEhep17.first = ibooker.book1D(name,title,nbins,arr);
770  plot.ptMEhep17.first->setAxisTitle(plot.xTITLE+" p_{T} [GeV]",1);
771 
772  if ( plot.ptMEhem17.second )
773  ibooker.setCurrentFolder(mainFolder_);
774  else
776 
777  name = plot.label+"_pt_HEM17";
778  title = plot.pathNAME+" p_{T} HEM17";
779  plot.ptMEhem17.first = ibooker.book1D(name,title,nbins,arr);
780  plot.ptMEhem17.first->setAxisTitle(plot.xTITLE+" p_{T} [GeV]",1);
781  }
782 
783  if ( plot.doPlotRazor ) {
784  if ( plot.mrME.second )
785  ibooker.setCurrentFolder(mainFolder_);
786  else
788 
789  name = plot.label+"_mr";
790  title = plot.pathNAME+" M_{R}";
791  plot.mrME.first = ibooker.book1D(name,title,100,0.,100.);
792  plot.mrME.first->setAxisTitle(plot.xTITLE+" M_{R} [GeV]",1);
793 
794  if ( plot.rsqME.second )
795  ibooker.setCurrentFolder(mainFolder_);
796  else
798 
799  name = plot.label+"_rsq";
800  title = plot.pathNAME+" RSQ";
801  plot.rsqME.first = ibooker.book1D(name,title,100,0.,100.);
802  plot.rsqME.first->setAxisTitle(plot.xTITLE+" RSQ [GeV]",1);
803 
804  }
805 
806  if ( plot.doPlotDXY ) {
807 
808  if ( plot.dxyME.second )
809  ibooker.setCurrentFolder(mainFolder_);
810  else
812 
813  name = plot.label+"_dxy";
814  title = plot.pathNAME+" d_{xy}";
815  int nbins = (plot.dxyBINNING).size()-1;
816  std::vector<float> fbinning((plot.dxyBINNING).begin(),(plot.dxyBINNING).end());
817  float* arr = &fbinning[0];
818  plot.dxyME.first = ibooker.book1D(name,title,nbins,arr);
819  plot.dxyME.first->setAxisTitle(plot.xTITLE+" d_{xy} [cm]");
820 
821  }
822 
823  if ( plot.doPlotDZ ) {
824 
825  if ( plot.dzME.second )
826  ibooker.setCurrentFolder(mainFolder_);
827  else
829 
830  name = plot.label+"_dz";
831  title = plot.pathNAME+" d_{z}";
832  int nbins = (plot.dzBINNING).size()-1;
833  std::vector<float> fbinning((plot.dzBINNING).begin(),(plot.dzBINNING).end());
834  float* arr = &fbinning[0];
835  plot.dzME.first = ibooker.book1D(name,title,nbins,arr);
836  plot.dzME.first->setAxisTitle(plot.xTITLE+" d_{z} [cm]");
837 
838  }
839 
840  if ( plot.dRME.second )
841  ibooker.setCurrentFolder(mainFolder_);
842  else
844 
845  name = plot.label+"_dR";
846  title = plot.pathNAME+" di-object dR";
847  plot.dRME.first = ibooker.book1D(name,title,50,0.,5.);
848  plot.dRME.first->setAxisTitle(plot.xTITLE+" dR_{obj,obj}");
849 
850  if ( plot.dRetaVSphiME.second )
851  ibooker.setCurrentFolder(mainFolder_);
852  else
854 
855  name = plot.label+"_dR_etaVSphi";
856  title = plot.pathNAME+" di-object dR in the #eta-#phi plane (of 1st obj)";
857  plot.dRetaVSphiME.first = ibooker.bookProfile2D(name,title,60,-3.,3.,64,-3.2,3.2,0.,5.);
858  plot.dRetaVSphiME.first->setAxisTitle(plot.xTITLE+" #eta",1);
859  plot.dRetaVSphiME.first->setAxisTitle(plot.xTITLE+" #phi",2);
860  plot.dRetaVSphiME.first->setAxisTitle(plot.xTITLE+" dR_{obj,obj}",3);
861 
862  if ( plot.q1q2ME.second )
863  ibooker.setCurrentFolder(mainFolder_);
864  else
866 
867  name = plot.label+"_q1q2";
868  title = plot.pathNAME+" di-object q1xq2";
869  plot.q1q2ME.first = ibooker.book1D(name,title,3,-1.,1.);
870  plot.q1q2ME.first->setAxisTitle(plot.xTITLE+" q_{obj1} x q_{obj2}");
871 
872  if ( plot.doPlotDiMass ) {
873 
874  if ( plot.dimassME.second )
875  ibooker.setCurrentFolder(mainFolder_);
876  else
878 
879  name = plot.label+"_dimass";
880  title = plot.pathNAME+" di-object mass";
881  int nbins = (plot.dimassBINNING).size()-1;
882  std::vector<float> fbinning((plot.dimassBINNING).begin(),(plot.dimassBINNING).end());
883  float* arr = &fbinning[0];
884  plot.dimassME.first = ibooker.book1D(name,title,nbins,arr);
885  plot.dimassME.first->setAxisTitle(plot.xTITLE+" m_{obj,obj} [GeV]");
886 
887  }
888  }
889 
890  if ( debug_ )
891  std::cout << "[HLTObjectsMonitor::bookHistograms] DONE" << std::endl;
892 
893 }
894 
895 double
897 {
898  double dxy = -99.;
899  if ( !candidates.isValid() ) {
900  LogDebug ("HLTObjectsMonitor") << "either " << muCandidates_ << " or " << eleCandidates_ << " is not valid ! please, update DQM/HLTEvF/python/HLTObjectsMonitor_cfi.py"
901  << " by switching OFF doPlotDXY or updating the InputTag collection";
902  return dxy;
903  }
904  if ( !beamspot.isValid() ) {
905  LogDebug ("HLTObjectsMonitor") << beamSpot_ << " is not valid ! please, update DQM/HLTEvF/python/HLTObjectsMonitor_cfi.py"
906  << " by switching OFF doPlotDXY or updating the InputTag collection";
907  return dxy;
908  }
909 
910  bool matched = false;
911  for (reco::RecoChargedCandidateCollection::const_iterator candidate = candidates->begin();
912  candidate != candidates->end(); ++candidate) {
913 
914  if ( deltaR( eta,phi,candidate->eta(),candidate->phi() ) < dRcut ) {
915  matched = true;
916  dxy = (-(candidate->vx()-beamspot->x0()) * candidate->py() + (candidate->vy()-beamspot->y0()) * candidate->px())/candidate->pt();
917  break;
918  }
919  }
920  if (!matched)
921  edm::LogWarning ("HLTObjectsMonitor") << "trigger object does not match ( dR > " << dRcut << ") to any of the candidates in either "
922  << muCandidates_ << " or " << eleCandidates_;
923 
924  return dxy;
925 }
926 
927 double
928 HLTObjectsMonitor::dzFinder(double eta1, double phi1, double eta2, double phi2, edm::Handle<reco::RecoChargedCandidateCollection> candidates, double dRcut = 0.1)
929 {
930  double dz = -99.;
931  if ( !candidates.isValid() ) {
932  LogDebug ("HLTObjectsMonitor") << "either " << muCandidates_ << " or " << eleCandidates_ << " is not valid ! please, update DQM/HLTEvF/python/HLTObjectsMonitor_cfi.py"
933  << " by switching OFF doPlotDZ or updating the InputTag collection";
934  return dz;
935  }
936 
937  const reco::RecoChargedCandidate* cand1;
938  const reco::RecoChargedCandidate* cand2;
939  bool matched1 = false;
940  bool matched2 = false;
941  for (reco::RecoChargedCandidateCollection::const_iterator candidate = candidates->begin();
942  candidate != candidates->end(); ++candidate) {
943 
944  if ( deltaR( eta1,phi1,candidate->eta(),candidate->phi() ) < dRcut ) {
945  matched1 = true;
946  cand1 = &*candidate;
947  if ( debug_ )
948  std::cout << "cand1: " << cand1->pt() << " " << cand1->eta() << " " << cand1->phi() << std::endl;
949  break;
950  }
951  }
952  if (!matched1) {
953  LogDebug ("HLTObjectsMonitor") << "trigger object1 does not match ( dR > " << dRcut << ") to any of the candidates in either "
954  << muCandidates_ << " or " << eleCandidates_;
955  return dz;
956  }
957 
958  for (reco::RecoChargedCandidateCollection::const_iterator candidate = candidates->begin();
959  candidate != candidates->end(); ++candidate) {
960  if ( debug_ ) {
961  std::cout << "candidate: " << candidate->pt() << " cand1: " << cand1->pt() << std::endl;
962  std::cout << "candidate: " << candidate->eta() << " cand1: " << cand1->eta() << std::endl;
963  std::cout << "candidate: " << candidate->phi() << " cand1: " << cand1->phi() << std::endl;
964  }
965  if (&*candidate == cand1) continue;
966 
967  if ( deltaR( eta2,phi2,candidate->eta(),candidate->phi() ) < dRcut ) {
968  matched2 = true;
969  cand2 = &*candidate;
970  if ( debug_ )
971  std::cout << "cand2: " << cand2->pt() << " " << cand2->eta() << " " << cand2->phi() << std::endl;
972  break;
973  }
974  }
975  if (!matched2) {
976  LogDebug ("HLTObjectsMonitor") << "trigger object2 does not match ( dR > " << dRcut << ") to any of the candidates in either "
977  << muCandidates_ << " or " << eleCandidates_;
978  return dz;
979  }
980 
981  dz = cand1->vz() - cand2->vz();
982  return dz;
983 }
984 
985 //define this as a plug-in
#define LogDebug(id)
size
Write out results.
edm::EDGetTokenT< reco::JetTagCollection > pfJetBTagsToken_
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double > phiBINNING
bool saveTags(const std::string &module) const
Is module an L3 filter (ie, tracked saveTags=true)
std::pair< MonitorElement *, bool > dzME
std::vector< hltPlot > hltPlots_
std::string pathNAME
std::pair< MonitorElement *, bool > dimassME
std::pair< MonitorElement *, bool > csvME
double eta() const final
momentum pseudorapidity
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
std::unordered_map< std::string, int > plotNamesToBins_
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:135
const MEbinning csv_binning_
std::pair< MonitorElement *, bool > massME
edm::InputTag muCandidates_
edm::EDGetTokenT< reco::JetTagCollection > caloJetBTagsToken_
std::pair< MonitorElement *, bool > energyME
std::vector< double > etaBINNING
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< double > dimassBINNING
static hltPlot getPlotPSet(edm::ParameterSet pset)
std::string moduleNAME
std::pair< MonitorElement *, bool > etaVSphiME
std::pair< MonitorElement *, bool > dRetaVSphiME
bool accept() const
Has at least one path accepted the event?
const std::vector< std::string > & triggerNames() const
names of trigger paths
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:111
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:123
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
const_iterator end() const
double pt() const final
transverse momentum
std::pair< MonitorElement *, bool > ptMEhem17
JetFloatAssociation::Container JetTagCollection
Definition: JetTag.h:18
std::pair< MonitorElement *, bool > q1q2ME
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
double q2[4]
Definition: TauolaWrapper.h:88
static const std::string removeVersion(const std::string &trigger)
edm::InputTag beamSpot_
void Fill(long long x)
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< std::vector< reco::RecoChargedCandidate > > eleCandidatesToken_
bool isHEP17(double eta, double phi)
std::pair< MonitorElement *, bool > etaME
std::pair< MonitorElement *, bool > phiME
int iEvent
Definition: GenABIO.cc:224
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::pair< MonitorElement *, bool > dxyME
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
HLTObjectsMonitor(const edm::ParameterSet &)
edm::InputTag eleCandidates_
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:98
MonitorElement * bookProfile2D(Args &&...args)
Definition: DQMStore.h:114
double dxyFinder(double, double, edm::Handle< reco::RecoChargedCandidateCollection >, edm::Handle< reco::BeamSpot >, double)
std::pair< MonitorElement *, bool > mrME
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define end
Definition: vmac.h:39
static std::string const triggerResults
Definition: EdmProvDump.cc:45
bool isValid() const
Definition: HandleBase.h:74
std::vector< double > massBINNING
std::pair< MonitorElement *, bool > rsqME
double vz() const override
z coordinate of vertex position
std::pair< MonitorElement *, bool > ptME
std::string label
std::vector< double > dzBINNING
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:81
std::pair< MonitorElement *, bool > nME
std::pair< MonitorElement *, bool > dRME
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
double q1[4]
Definition: TauolaWrapper.h:87
std::vector< size_type > Keys
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
HLTConfigProvider hltConfig_
example_stream void bookHistograms(DQMStore::IBooker &,@example_stream edm::Run const &,@example_stream edm::EventSetup const &) override
std::pair< MonitorElement *, bool > ptMEhep17
edm::EDGetTokenT< std::vector< reco::RecoChargedCandidate > > muCandidatesToken_
bool isHEM17(double eta, double phi)
fixed size matrix
std::vector< double > phi_variable_binning_
HLT enums.
MonitorElement * eventsPlot_
std::vector< edm::ParameterSet > plotPSETS_
void analyze(const edm::Event &, const edm::EventSetup &) override
double y0() const
y coordinate
Definition: BeamSpot.h:66
double dzFinder(double, double, double, double, edm::Handle< reco::RecoChargedCandidateCollection >, double)
step
Definition: StallMonitor.cc:94
static std::string const triggerPaths
Definition: EdmProvDump.cc:46
double phi() const final
momentum azimuthal angle
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
const_iterator begin() const
std::vector< double > dxyBINNING
Definition: vlib.h:208
edm::EDGetTokenT< trigger::TriggerEvent > triggerEventToken_
std::string xTITLE
std::vector< double > ptBINNING
Definition: Run.h:45
double x0() const
x coordinate
Definition: BeamSpot.h:64