CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EmDQMReco.cc
Go to the documentation of this file.
1 // Header file for this //
5 
7 // Collaborating Class Header //
15 //#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
16 //#include "DataFormats/EgammaCandidates/interface/Photon.h"
19 //#include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
23 
27 //#include "PhysicsTools/UtilAlgos/interface/TFileService.h"
33 #include <boost/format.hpp>
35 // Root include files //
37 #include "TFile.h"
38 #include "TDirectory.h"
39 #include "TH1F.h"
40 #include <iostream>
41 #include <string>
42 #include <Math/VectorUtil.h>
43 using namespace ROOT::Math::VectorUtil ;
44 
45 //----------------------------------------------------------------------
46 // class EmDQMReco::FourVectorMonitorElements
47 //----------------------------------------------------------------------
49  const std::string &histogramNameTemplate,
50  const std::string &histogramTitleTemplate
51  ) :
52  parent(_parent)
53 {
54  // introducing variables for better code readability later on
55  std::string histName;
56  std::string histTitle;
57 
58  // et
59  histName = boost::str(boost::format(histogramNameTemplate) % "et");
60  histTitle = boost::str(boost::format(histogramTitleTemplate) % "E_{T}");
61  etMonitorElement = parent->dbe->book1D(histName.c_str(),
62  histTitle.c_str(),
65  parent->plotPtMax);
66 
67  // eta
68  histName = boost::str(boost::format(histogramNameTemplate) % "eta");
69  histTitle= boost::str(boost::format(histogramTitleTemplate) % "#eta");
70  etaMonitorElement = parent->dbe->book1D(histName.c_str(),
71  histTitle.c_str(),
73  - parent->plotEtaMax,
75 
76  // phi
77  histName = boost::str(boost::format(histogramNameTemplate) % "phi");
78  histTitle= boost::str(boost::format(histogramTitleTemplate) % "#phi");
79  phiMonitorElement = parent->dbe->book1D(histName.c_str(),
80  histTitle.c_str(),
82  - parent->plotPhiMax,
84 }
85 
86 //----------------------------------------------------------------------
87 
88 void
90 {
91  etMonitorElement->Fill(momentum.Et());
92  etaMonitorElement->Fill(momentum.eta() );
93  phiMonitorElement->Fill(momentum.phi() );
94 }
95 
96 //----------------------------------------------------------------------
97 
99 // Constructor //
102 {
103 
105  dbe->setVerbose(0);
106 
107 
109  // Read from configuration file //
111  dirname_="HLT/HLTEgammaValidation/"+pset.getParameter<std::string>("@module_label");
113 
114  // parameters for generator study
115  reqNum = pset.getParameter<unsigned int>("reqNum");
116  pdgGen = pset.getParameter<int>("pdgGen");
117  recoEtaAcc = pset.getParameter<double>("genEtaAcc");
118  recoEtAcc = pset.getParameter<double>("genEtAcc");
119  // plotting parameters (untracked because they don't affect the physics)
120  plotPtMin = pset.getUntrackedParameter<double>("PtMin",0.);
121  plotPtMax = pset.getUntrackedParameter<double>("PtMax",1000.);
122  plotEtaMax = pset.getUntrackedParameter<double>("EtaMax", 2.7);
123  plotPhiMax = pset.getUntrackedParameter<double>("PhiMax", 3.15);
124  plotBins = pset.getUntrackedParameter<unsigned int>("Nbins",50);
125  useHumanReadableHistTitles = pset.getUntrackedParameter<bool>("useHumanReadableHistTitles", false);
126 
127  triggerNameRecoMonPath = pset.getUntrackedParameter<std::string>("triggerNameRecoMonPath","HLT_MinBias");
128  processNameRecoMonPath = pset.getUntrackedParameter<std::string>("processNameRecoMonPath","HLT");
129 
130  recoElectronsInput = consumes<reco::GsfElectronCollection>(pset.getUntrackedParameter<edm::InputTag>("recoElectrons",edm::InputTag("gsfElectrons")));
131  recoObjectsEBT = consumes<std::vector<reco::SuperCluster>>(edm::InputTag("correctedHybridSuperClusters"));
132  recoObjectsEET = consumes<std::vector<reco::SuperCluster>>(edm::InputTag("correctedMulti5x5SuperClustersWithPreshower"));
133  hltResultsT = consumes<edm::TriggerResults>(edm::InputTag("TriggerResults","",processNameRecoMonPath));
134  triggerObjT = consumes<trigger::TriggerEventWithRefs>(edm::InputTag("hltTriggerSummaryRAW"));
135 
136  // preselction cuts
137  // recocutCollection_= pset.getParameter<edm::InputTag>("cutcollection");
138  recocut_ = pset.getParameter<int>("cutnum");
139 
140  // prescale = 10;
141  eventnum = 0;
142 
143  // just init
144  isHltConfigInitialized_ = false;
145 
147  // Read in the Vector of Parameter Sets. //
148  // Information for each filter-step //
150  std::vector<edm::ParameterSet> filters =
151  pset.getParameter<std::vector<edm::ParameterSet> >("filters");
152 
153  int i = 0;
154  for(std::vector<edm::ParameterSet>::iterator filterconf = filters.begin() ; filterconf != filters.end() ; filterconf++)
155  {
156 
157  theHLTCollectionLabels.push_back(filterconf->getParameter<edm::InputTag>("HLTCollectionLabels"));
158  theHLTOutputTypes.push_back(filterconf->getParameter<int>("theHLTOutputTypes"));
159  // Grab the human-readable name, if it is not specified, use the Collection Label
160  theHLTCollectionHumanNames.push_back(filterconf->getUntrackedParameter<std::string>("HLTCollectionHumanName",theHLTCollectionLabels[i].label()));
161 
162  std::vector<double> bounds = filterconf->getParameter<std::vector<double> >("PlotBounds");
163  // If the size of plot "bounds" vector != 2, abort
164  assert(bounds.size() == 2);
165  plotBounds.push_back(std::pair<double,double>(bounds[0],bounds[1]));
166  isoNames.push_back(filterconf->getParameter<std::vector<edm::InputTag> >("IsoCollections"));
167 
168  for (unsigned int i=0; i<isoNames.back().size(); i++) {
169  switch(theHLTOutputTypes.back()) {
172  break;
173  case trigger::TriggerL1IsoEG: // Isolated Level 1
175  break;
176  case trigger::TriggerPhoton: // Photon
178  break;
179  case trigger::TriggerElectron: // Electron
181  break;
182  case trigger::TriggerCluster: // TriggerCluster
184  break;
185  default:
186  throw(cms::Exception("Release Validation Error") << "HLT output type not implemented: theHLTOutputTypes[n]" );
187  }
188  }
189 
190  // If the size of the isoNames vector is not greater than zero, abort
191  assert(isoNames.back().size()>0);
192  if (isoNames.back().at(0).label()=="none") {
193  plotiso.push_back(false);
194  } else {
195  plotiso.push_back(true);
196  }
197  i++;
198  } // END of loop over parameter sets
199 
200  // Record number of HLTCollectionLabels
202 
203 }
204 
205 
206 
210 void EmDQMReco::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup ) {
211 
212  bool isHltConfigChanged = false; // change of cfg at run boundaries?
213  isHltConfigInitialized_ = hltConfig_.init( iRun, iSetup, "HLT", isHltConfigChanged );
214 
215 }
216 
217 
218 
219 
220 
222 // method called once each job just before starting event loop //
224 void
226 {
227  //edm::Service<TFileService> fs;
229 
231  // Set up Histogram of Effiency vs Step. //
232  // theHLTCollectionLabels is a vector of InputTags //
233  // from the configuration file. //
235 
236  std::string histName="total_eff";
237  std::string histTitle = "total events passing";
238  // This plot will have bins equal to 2+(number of
239  // HLTCollectionLabels in the config file)
240  totalreco = dbe->book1D(histName.c_str(),histTitle.c_str(),numOfHLTCollectionLabels+2,0,numOfHLTCollectionLabels+2);
243  for (unsigned int u=0; u<numOfHLTCollectionLabels; u++){totalreco->setBinLabel(u+1,theHLTCollectionLabels[u].label().c_str());}
244 
245  histName="total_eff_RECO_matched";
246  histTitle="total events passing (Reco matched)";
247  totalmatchreco = dbe->book1D(histName.c_str(),histTitle.c_str(),numOfHLTCollectionLabels+2,0,numOfHLTCollectionLabels+2);
248  totalmatchreco->setBinLabel(numOfHLTCollectionLabels+1,"Total");
249  totalmatchreco->setBinLabel(numOfHLTCollectionLabels+2,"Reco");
250  for (unsigned int u=0; u<numOfHLTCollectionLabels; u++){totalmatchreco->setBinLabel(u+1,theHLTCollectionLabels[u].label().c_str());}
251 
252  // MonitorElement* tmphisto;
253  MonitorElement* tmpiso;
254 
256  // Set up generator-level histograms //
258  std::string pdgIdString;
259  switch(pdgGen) {
260  case 11:
261  pdgIdString="Electron";break;
262  case 22:
263  pdgIdString="Photon";break;
264  default:
265  pdgIdString="Particle";
266  }
267 
268  //--------------------
269 
270  // reco
271  // (note that reset(..) must be used to set the value of the scoped_ptr...)
272  histReco.reset(
273  new FourVectorMonitorElements(this,
274  "reco_%s", // pattern for histogram name
275  "%s of " + pdgIdString + "s"
276  ));
277 
278  //--------------------
279 
280  // monpath
281  histRecoMonpath.reset(
282  new FourVectorMonitorElements(this,
283  "reco_%s_monpath", // pattern for histogram name
284  "%s of " + pdgIdString + "s monpath"
285  )
286  );
287 
288  //--------------------
289 
290  // TODO: WHAT ARE THESE HISTOGRAMS FOR ? THEY SEEM NEVER REFERENCED ANYWHERE IN THIS FILE...
291  // final X monpath
292  histMonpath.reset(
293  new FourVectorMonitorElements(this,
294  "final_%s_monpath", // pattern for histogram name
295  "Final %s Monpath"
296  )
297  );
298 
299  //--------------------
300 
302  // Set up histograms of HLT objects //
304 
305  // Determine what strings to use for histogram titles
306  std::vector<std::string> HltHistTitle;
307  if ( theHLTCollectionHumanNames.size() == numOfHLTCollectionLabels && useHumanReadableHistTitles ) {
308  HltHistTitle = theHLTCollectionHumanNames;
309  } else {
310  for (unsigned int i =0; i < numOfHLTCollectionLabels; i++) {
311  HltHistTitle.push_back(theHLTCollectionLabels[i].label());
312  }
313  }
314 
315  for(unsigned int i = 0; i< numOfHLTCollectionLabels ; i++){
316  //--------------------
317  // distributions of HLT objects passing filter i
318  //--------------------
319 
320 // // Et
321 // histName = theHLTCollectionLabels[i].label()+"et_all";
322 // histTitle = HltHistTitle[i]+" Et (ALL)";
323 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
324 // ethist.push_back(tmphisto);
325 //
326 // // Eta
327 // histName = theHLTCollectionLabels[i].label()+"eta_all";
328 // histTitle = HltHistTitle[i]+" #eta (ALL)";
329 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
330 // etahist.push_back(tmphisto);
331 //
332 // // phi
333 // histName = theHLTCollectionLabels[i].label()+"phi_all";
334 // histTitle = HltHistTitle[i]+" #phi (ALL)";
335 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
336 // phiHist.push_back(tmphisto);
337 
338  standardHist.push_back(new FourVectorMonitorElements(this,
339  theHLTCollectionLabels[i].label()+"%s_all", // histogram name
340  HltHistTitle[i]+" %s (ALL)" // histogram title
341  ));
342 
343  //--------------------
344  // distributions of reco object matching HLT object passing filter i
345  //--------------------
346 
347  // Et
348 // histName = theHLTCollectionLabels[i].label()+"et_RECO_matched";
349 // histTitle = HltHistTitle[i]+" Et (RECO matched)";
350 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
351 // ethistmatchreco.push_back(tmphisto);
352 
353 // // Eta
354 // histName = theHLTCollectionLabels[i].label()+"eta_RECO_matched";
355 // histTitle = HltHistTitle[i]+" #eta (RECO matched)";
356 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
357 // etahistmatchreco.push_back(tmphisto);
358 //
359 // // phi
360 // histName = theHLTCollectionLabels[i].label()+"phi_RECO_matched";
361 // histTitle = HltHistTitle[i]+" #phi (RECO matched)";
362 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
363 // phiHistMatchReco.push_back(tmphisto);
364  histMatchReco.push_back(new FourVectorMonitorElements(this,
365  theHLTCollectionLabels[i].label()+"%s_RECO_matched", // histogram name
366  HltHistTitle[i]+" %s (RECO matched)" // histogram title
367  ));
368 
369  //--------------------
370  // distributions of reco object matching HLT object passing filter i
371  //--------------------
372 
373 // // Et
374 // histName = theHLTCollectionLabels[i].label()+"et_RECO_matched_monpath";
375 // histTitle = HltHistTitle[i]+" Et (RECO matched, monpath)";
376 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
377 // ethistmatchrecomonpath.push_back(tmphisto);
378 //
379 // // Eta
380 // histName = theHLTCollectionLabels[i].label()+"eta_RECO_matched_monpath";
381 // histTitle = HltHistTitle[i]+" #eta (RECO matched, monpath)";
382 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
383 // etahistmatchrecomonpath.push_back(tmphisto);
384 //
385 // // phi
386 // histName = theHLTCollectionLabels[i].label()+"phi_RECO_matched_monpath";
387 // histTitle = HltHistTitle[i]+" #phi (RECO matched, monpath)";
388 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
389 // phiHistMatchRecoMonPath.push_back(tmphisto);
390 
392  theHLTCollectionLabels[i].label()+"%s_RECO_matched_monpath", // histogram name
393  HltHistTitle[i]+" %s (RECO matched, monpath)" // histogram title
394  ));
395  //--------------------
396  // distributions of HLT object that is closest delta-R match to sorted reco particle(s)
397  //--------------------
398 
399  // Et
400 // histName = theHLTCollectionLabels[i].label()+"et_reco";
401 // histTitle = HltHistTitle[i]+" Et (reco)";
402 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
403 // histEtOfHltObjMatchToReco.push_back(tmphisto);
404 //
405 // // eta
406 // histName = theHLTCollectionLabels[i].label()+"eta_reco";
407 // histTitle = HltHistTitle[i]+" eta (reco)";
408 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
409 // histEtaOfHltObjMatchToReco.push_back(tmphisto);
410 //
411 // // phi
412 // histName = theHLTCollectionLabels[i].label()+"phi_reco";
413 // histTitle = HltHistTitle[i]+" phi (reco)";
414 // tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
415 // histPhiOfHltObjMatchToReco.push_back(tmphisto);
416 
418  theHLTCollectionLabels[i].label()+"%s_reco", // histogram name
419  HltHistTitle[i]+" %s (reco)" // histogram title
420  ));
421 
422  //--------------------
423 
424  if (!plotiso[i]) {
425  tmpiso = NULL;
426  etahistiso.push_back(tmpiso);
427  ethistiso.push_back(tmpiso);
428  phiHistIso.push_back(tmpiso);
429 
430  etahistisomatchreco.push_back(tmpiso);
431  ethistisomatchreco.push_back(tmpiso);
432  phiHistIsoMatchReco.push_back(tmpiso);
433 
434  histEtaIsoOfHltObjMatchToReco.push_back(tmpiso);
435  histEtIsoOfHltObjMatchToReco.push_back(tmpiso);
436  histPhiIsoOfHltObjMatchToReco.push_back(tmpiso);
437 
438  } else {
439 
440  //--------------------
441  // 2D plot: Isolation values vs X for all objects
442  //--------------------
443 
444  // X = eta
445  histName = theHLTCollectionLabels[i].label()+"eta_isolation_all";
446  histTitle = HltHistTitle[i]+" isolation vs #eta (all)";
447  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[i].first,plotBounds[i].second);
448  etahistiso.push_back(tmpiso);
449 
450  // X = et
451  histName = theHLTCollectionLabels[i].label()+"et_isolation_all";
452  histTitle = HltHistTitle[i]+" isolation vs Et (all)";
453  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[i].first,plotBounds[i].second);
454  ethistiso.push_back(tmpiso);
455 
456  // X = phi
457  histName = theHLTCollectionLabels[i].label()+"phi_isolation_all";
458  histTitle = HltHistTitle[i]+" isolation vs #phi (all)";
459  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[i].first,plotBounds[i].second);
460  phiHistIso.push_back(tmpiso);
461 
462  //--------------------
463  // 2D plot: Isolation values vs X for reco matched objects
464  //--------------------
465 
466  // X = eta
467  histName = theHLTCollectionLabels[i].label()+"eta_isolation_RECO_matched";
468  histTitle = HltHistTitle[i]+" isolation vs #eta (reco matched)";
469  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[i].first,plotBounds[i].second);
470  etahistisomatchreco.push_back(tmpiso);
471 
472  // X = et
473  histName = theHLTCollectionLabels[i].label()+"et_isolation_RECO_matched";
474  histTitle = HltHistTitle[i]+" isolation vs Et (reco matched)";
475  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[i].first,plotBounds[i].second);
476  ethistisomatchreco.push_back(tmpiso);
477 
478  // X = eta
479  histName = theHLTCollectionLabels[i].label()+"phi_isolation_RECO_matched";
480  histTitle = HltHistTitle[i]+" isolation vs #phi (reco matched)";
481  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[i].first,plotBounds[i].second);
482  phiHistIsoMatchReco.push_back(tmpiso);
483 
484  //--------------------
485  // 2D plot: Isolation values vs X for HLT object that
486  // is closest delta-R match to sorted reco particle(s)
487  //--------------------
488 
489  // X = eta
490  histName = theHLTCollectionLabels[i].label()+"eta_isolation_reco";
491  histTitle = HltHistTitle[i]+" isolation vs #eta (reco)";
492  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[i].first,plotBounds[i].second);
493  histEtaIsoOfHltObjMatchToReco.push_back(tmpiso);
494 
495  // X = et
496  histName = theHLTCollectionLabels[i].label()+"et_isolation_reco";
497  histTitle = HltHistTitle[i]+" isolation vs Et (reco)";
498  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[i].first,plotBounds[i].second);
499  histEtIsoOfHltObjMatchToReco.push_back(tmpiso);
500 
501  // X = phi
502  histName = theHLTCollectionLabels[i].label()+"phi_isolation_reco";
503  histTitle = HltHistTitle[i]+" isolation vs #phi (reco)";
504  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[i].first,plotBounds[i].second);
505  histPhiIsoOfHltObjMatchToReco.push_back(tmpiso);
506  //--------------------
507 
508  } // END of HLT histograms
509 
510  }
511 }
512 
513 
515 // Destructor //
518 }
519 
520 
522 // method called to for each event //
524 void
526 {
527 
528  // protect from hlt config failure
529  if( !isHltConfigInitialized_ ) return;
530 
531  eventnum++;
532  bool plotMonpath = false;
533  bool plotReco = true;
534 
538 
539  if (pdgGen == 11) {
540 
541  event.getByToken(recoElectronsInput, recoObjects);
542 
543  if (recoObjects->size() < (unsigned int)recocut_) {
544  // edm::LogWarning("EmDQMReco") << "Less than "<< recocut_ <<" Reco particles with pdgId=" << pdgGen << ". Only " << cutRecoCounter->size() << " particles.";
545  return;
546  }
547  } else if (pdgGen == 22) {
548 
549  event.getByToken(recoObjectsEBT, recoObjectsEB);
550  event.getByToken(recoObjectsEET, recoObjectsEE);
551 
552  if (recoObjectsEB->size() + recoObjectsEE->size() < (unsigned int)recocut_) {
553  // edm::LogWarning("EmDQMReco") << "Less than "<< recocut_ <<" Reco particles with pdgId=" << pdgGen << ". Only " << cutRecoCounter.size() << " particles.";
554  return;
555  }
556  }
557 
559  event.getByToken(hltResultsT, HLTR);
560 
565 
566  /* if (theHLTCollectionHumanNames[0] == "hltL1sRelaxedSingleEgammaEt8"){
567  triggerIndex = hltConfig.triggerIndex("HLT_L1SingleEG8");
568  } else if (theHLTCollectionHumanNames[0] == "hltL1sRelaxedSingleEgammaEt5") {
569  triggerIndex = hltConfig.triggerIndex("HLT_L1SingleEG5");
570  } else if (theHLTCollectionHumanNames[0] == "hltL1sRelaxedDoubleEgammaEt5") {
571  triggerIndex = hltConfig.triggerIndex("HLT_L1DoubleEG5");
572  } else {
573  triggerIndex = hltConfig.triggerIndex("");
574  } */
575 
576  unsigned int triggerIndex;
578 
579  //triggerIndex must be less than the size of HLTR or you get a CMSException
580  bool isFired = false;
581  if (triggerIndex < HLTR->size()){
582  isFired = HLTR->accept(triggerIndex);
583  }
584 
585  // fill L1 and HLT info
586  // get objects possed by each filter
588  event.getByToken(triggerObjT, triggerObj);
589 
590  if(!triggerObj.isValid()) {
591  edm::LogWarning("EmDQMReco") << "RAW-type HLT results not found, skipping event";
592  return;
593  }
594 
596  // Fill the bin labeled "Total" //
597  // This will be the number of events looked at. //
601 
602  /* edm::Handle< edm::View<reco::GsfElectron> > recoParticles;
603  event.getByLabel("gsfElectrons", recoParticles);
604 
605  std::vector<reco::GsfElectron> allSortedRecoParticles;
606 
607  for(edm::View<reco::GsfElectron>::const_iterator currentRecoParticle = recoParticles->begin(); currentRecoParticle != recoParticles->end(); currentRecoParticle++){
608  if ( !((*currentRecoParticle).et() > 2.0) ) continue;
609  reco::GsfElectron tmpcand( *(currentRecoParticle) );
610  allSortedRecoParticles.push_back(tmpcand);
611  }
612 
613  std::sort(allSortedRecoParticles.begin(), allSortedRecoParticles.end(),pTRecoComparator_);*/
614 
615  // Were enough high energy gen particles found?
616  // It was an event worth keeping. Continue.
617 
619  // Fill the bin labeled "Total" //
620  // This will be the number of events looked at. //
622  //total->Fill(numOfHLTCollectionLabels+0.5);
623  //totalmatch->Fill(numOfHLTCollectionLabels+0.5);
624 
625 
627  // Fill reconstruction info //
629  // the recocut_ highest Et generator objects of the preselected type are our matches
630 
631  std::vector<reco::Particle> sortedReco;
632  if (plotReco == true) {
633  if (pdgGen == 11) {
634  for(edm::View<reco::Candidate>::const_iterator recopart = recoObjects->begin(); recopart != recoObjects->end();recopart++){
635  reco::Particle tmpcand( recopart->charge(), recopart->p4(), recopart->vertex(),recopart->pdgId(),recopart->status() );
636  sortedReco.push_back(tmpcand);
637  }
638  }
639  else if (pdgGen == 22) {
640  for(std::vector<reco::SuperCluster>::const_iterator recopart2 = recoObjectsEB->begin(); recopart2 != recoObjectsEB->end();recopart2++){
641  float en = recopart2->energy();
642  float er = sqrt(pow(recopart2->x(),2) + pow(recopart2->y(),2) + pow(recopart2->z(),2) );
643  float px = recopart2->energy()*recopart2->x()/er;
644  float py = recopart2->energy()*recopart2->y()/er;
645  float pz = recopart2->energy()*recopart2->z()/er;
646  reco::Candidate::LorentzVector thisLV(px,py,pz,en);
647  reco::Particle tmpcand( 0, thisLV, math::XYZPoint(0.,0.,0.), 22, 1 );
648  sortedReco.push_back(tmpcand);
649  }
650  for(std::vector<reco::SuperCluster>::const_iterator recopart2 = recoObjectsEE->begin(); recopart2 != recoObjectsEE->end();recopart2++){
651  float en = recopart2->energy();
652  float er = sqrt(pow(recopart2->x(),2) + pow(recopart2->y(),2) + pow(recopart2->z(),2) );
653  float px = recopart2->energy()*recopart2->x()/er;
654  float py = recopart2->energy()*recopart2->y()/er;
655  float pz = recopart2->energy()*recopart2->z()/er;
656  reco::Candidate::LorentzVector thisLV(px,py,pz,en);
657  reco::Particle tmpcand( 0, thisLV, math::XYZPoint(0.,0.,0.), 22, 1 );
658  sortedReco.push_back(tmpcand);
659  }
660  }
661 
662  std::sort(sortedReco.begin(),sortedReco.end(),pTComparator_ );
663 
664  // Now the collection of gen particles is sorted by pt.
665  // So, remove all particles from the collection so that we
666  // only have the top "1 thru recocut_" particles in it
667 
668  sortedReco.erase(sortedReco.begin()+recocut_,sortedReco.end());
669 
670  for (unsigned int i = 0 ; i < recocut_ ; i++ ) {
671  //validity has been implicitily checked by the cut on recocut_ above
672  histReco->fill(sortedReco[i].p4());
673 
674 // etreco ->Fill( sortedReco[i].et() );
675 // etareco->Fill( sortedReco[i].eta() );
676 // phiReco->Fill( sortedReco[i].phi() );
677 
678  if (isFired) {
679  histRecoMonpath->fill(sortedReco[i].p4());
680  plotMonpath = true;
681  }
682 
683  } // END of loop over Reconstructed particles
684 
685  if (recocut_ >= reqNum) totalreco->Fill(numOfHLTCollectionLabels+1.5); // this isn't really needed anymore keep for backward comp.
686  if (recocut_ >= reqNum) totalmatchreco->Fill(numOfHLTCollectionLabels+1.5); // this isn't really needed anymore keep for backward comp.
687 
688  }
689 
690 
691 
692 
694  // Loop over filter modules //
696  for(unsigned int n=0; n < numOfHLTCollectionLabels ; n++) {
697  // These numbers are from the Parameter Set, such as:
698  // theHLTOutputTypes = cms.uint32(100)
699  switch(theHLTOutputTypes[n])
700  {
701  case trigger::TriggerL1NoIsoEG: // Non-isolated Level 1
702  histoFillerL1NonIso->fillHistos(triggerObj,event,n, sortedReco, plotReco, plotMonpath);
703  break;
704  case trigger::TriggerL1IsoEG: // Isolated Level 1
705  histoFillerL1Iso->fillHistos(triggerObj,event,n, sortedReco, plotReco, plotMonpath);
706  break;
707  case trigger::TriggerPhoton: // Photon
708  histoFillerPho->fillHistos(triggerObj,event,n, sortedReco, plotReco, plotMonpath);
709  break;
710  case trigger::TriggerElectron: // Electron
711  histoFillerEle->fillHistos(triggerObj,event,n, sortedReco, plotReco, plotMonpath);
712  break;
713  case trigger::TriggerCluster: // TriggerCluster
714  histoFillerClu->fillHistos(triggerObj,event,n, sortedReco, plotReco, plotMonpath);
715  break;
716  default:
717  throw(cms::Exception("Release Validation Error") << "HLT output type not implemented: theHLTOutputTypes[n]" );
718  }
719  } // END of loop over filter modules
720 }
721 
722 
724 // fillHistos //
725 // Called by analyze method. //
727 template <class T> void HistoFillerReco<T>::fillHistos(edm::Handle<trigger::TriggerEventWithRefs>& triggerObj,const edm::Event& iEvent ,unsigned int n, std::vector<reco::Particle>& sortedReco, bool plotReco, bool plotMonpath)
728 {
729  std::vector<edm::Ref<T> > recoecalcands;
730  if ( ( triggerObj->filterIndex(dqm->theHLTCollectionLabels[n])>=triggerObj->size() )){ // only process if available
731  return;
732  }
733 
735  // Retrieve saved filter objects //
737  triggerObj->getObjects(triggerObj->filterIndex(dqm->theHLTCollectionLabels[n]),dqm->theHLTOutputTypes[n],recoecalcands);
738  //Danger: special case, L1 non-isolated
739  // needs to be merged with L1 iso
741  std::vector<edm::Ref<T> > isocands;
742  triggerObj->getObjects(triggerObj->filterIndex(dqm->theHLTCollectionLabels[n]),trigger::TriggerL1IsoEG,isocands);
743  if (isocands.size()>0)
744  {
745  for (unsigned int i=0; i < isocands.size(); i++)
746  recoecalcands.push_back(isocands[i]);
747  }
748  } // END of if theHLTOutputTypes == 82
749 
750 
751  if (recoecalcands.size() < 1){ // stop if no object passed the previous filter
752  return;
753  }
754 
755 
756  if (recoecalcands.size() >= dqm->reqNum )
757  dqm->totalreco->Fill(n+0.5);
758 
759 
761  // check for validity //
762  // prevents crash in CMSSW_3_1_0_pre6 //
764  for (unsigned int j=0; j<recoecalcands.size(); j++){
765  if(!( recoecalcands.at(j).isAvailable())){
766  edm::LogError("EmDQMReco") << "Event content inconsistent: TriggerEventWithRefs contains invalid Refs" << std::endl << "invalid refs for: " << dqm->theHLTCollectionLabels[n].label();
767  return;
768  }
769  }
770 
772  // Loop over all HLT objects in this filter step, and //
773  // fill histograms. //
775  // bool foundAllMatches = false;
776  // unsigned int numOfHLTobjectsMatched = 0;
777  for (unsigned int i=0; i<recoecalcands.size(); i++) {
778 
779  dqm->standardHist[n].fill(recoecalcands[i]->p4());
780 
782  // Plot isolation variables (show the not-yet-cut //
783  // isolation, i.e. associated to next filter) //
785  if ( n+1 < dqm->numOfHLTCollectionLabels ) { // can't plot beyond last
786  if (dqm->plotiso[n+1]) {
787  for (unsigned int j = 0 ; j < isoNameTokens_.size() ;j++ ){
789  iEvent.getByToken(isoNameTokens_.at(j),depMap);
790  if (depMap.isValid()){ //Map may not exist if only one candidate passes a double filter
791  typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(recoecalcands[i]);
792  if (mapi!=depMap->end()){ // found candidate in isolation map!
793  dqm->etahistiso[n+1]->Fill(recoecalcands[i]->eta(),mapi->val);
794  dqm->ethistiso[n+1]->Fill(recoecalcands[i]->et() ,mapi->val);
795  dqm->phiHistIso[n+1]->Fill(recoecalcands[i]->phi(),mapi->val);
796  }
797  }
798  }
799  }
800  } // END of if n+1 < then the number of hlt collections
801  }
802 
804  // Loop over the Reconstructed Particles, and find the //
805  // closest HLT object match. //
807  if (plotReco == true) {
808  for (unsigned int i=0; i < dqm->recocut_; i++) {
809  math::XYZVector currentRecoParticleMomentum = sortedReco[i].momentum();
810 
811  // float closestRecoDeltaR = 0.5;
812  float closestRecoDeltaR = 1000.;
813  int closestRecoEcalCandIndex = -1;
814  for (unsigned int j=0; j<recoecalcands.size(); j++) {
815  float deltaR = DeltaR(recoecalcands[j]->momentum(),currentRecoParticleMomentum);
816 
817  if (deltaR < closestRecoDeltaR) {
818  closestRecoDeltaR = deltaR;
819  closestRecoEcalCandIndex = j;
820  }
821  }
822 
823  // If an HLT object was found within some delta-R
824  // of this reco particle, store it in a histogram
825  if ( closestRecoEcalCandIndex >= 0 ) {
826 // histEtOfHltObjMatchToReco[n] ->Fill( recoecalcands[closestRecoEcalCandIndex]->et() );
827 // histEtaOfHltObjMatchToReco[n]->Fill( recoecalcands[closestRecoEcalCandIndex]->eta() );
828 // histPhiOfHltObjMatchToReco[n]->Fill( recoecalcands[closestRecoEcalCandIndex]->phi() );
829 
830  dqm->histHltObjMatchToReco[n].fill(recoecalcands[closestRecoEcalCandIndex]->p4());
831 
832  // Also store isolation info
833  if (n+1 < dqm->numOfHLTCollectionLabels){ // can't plot beyond last
834  if (dqm->plotiso[n+1] ){ // only plot if requested in config
835  for (unsigned int j = 0 ; j < isoNameTokens_.size() ;j++ ){
837  iEvent.getByToken(isoNameTokens_.at(j),depMap);
838  if (depMap.isValid()){ //Map may not exist if only one candidate passes a double filter
839  typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(recoecalcands[closestRecoEcalCandIndex]);
840  if (mapi!=depMap->end()) { // found candidate in isolation map!
841  dqm->histEtaIsoOfHltObjMatchToReco[n+1]->Fill( recoecalcands[closestRecoEcalCandIndex]->eta(),mapi->val);
842  dqm->histEtIsoOfHltObjMatchToReco[n+1] ->Fill( recoecalcands[closestRecoEcalCandIndex]->et(), mapi->val);
843  dqm->histPhiIsoOfHltObjMatchToReco[n+1] ->Fill( recoecalcands[closestRecoEcalCandIndex]->phi(), mapi->val);
844  }
845  }
846  }
847  }
848  }
849  } // END of if closestEcalCandIndex >= 0
850  }
851 
853  // Fill reco matched objects into histograms //
855  unsigned int mtachedRecoParts = 0;
856  float minrecodist=0.3;
857  if(n==0) minrecodist=0.5; //low L1-resolution => allow wider matching
858  for(unsigned int i =0; i < dqm->recocut_; i++){
859  //match generator candidate
860  bool matchThis= false;
861  math::XYZVector candDir=sortedReco[i].momentum();
862  unsigned int closest = 0;
863  double closestDr = 1000.;
864  for(unsigned int trigOb = 0 ; trigOb < recoecalcands.size(); trigOb++){
865  double dr = DeltaR(recoecalcands[trigOb]->momentum(),candDir);
866  if (dr < closestDr) {
867  closestDr = dr;
868  closest = trigOb;
869  }
870  if (closestDr > minrecodist) { // it's not really a "match" if it's that far away
871  closest = -1;
872  } else {
873  mtachedRecoParts++;
874  matchThis = true;
875  }
876  }
877  if ( !matchThis ) continue; // only plot matched candidates
878  // fill coordinates of mc particle matching trigger object
879 // ethistmatchreco[n] ->Fill( sortedReco[i].et() );
880 // etahistmatchreco[n]->Fill( sortedReco[i].eta() );
881 // phiHistMatchReco[n]->Fill( sortedReco[i].phi() );
882  dqm->histMatchReco[n].fill(sortedReco[i].p4());
883 
884  if (plotMonpath) {
885 // ethistmatchrecomonpath[n]->Fill( sortedReco[i].et() );
886 // etahistmatchrecomonpath[n]->Fill( sortedReco[i].eta() );
887 // phiHistMatchRecoMonPath[n]->Fill( sortedReco[i].phi() );
888  dqm->histMatchRecoMonPath[n].fill(sortedReco[i].p4());
889 
890  }
892  // Plot isolation variables (show the not-yet-cut //
893  // isolation, i.e. associated to next filter) //
895  if (n+1 < dqm->numOfHLTCollectionLabels){ // can't plot beyond last
896  if (dqm->plotiso[n+1] ){ // only plot if requested in config
897  for (unsigned int j = 0 ; j < isoNameTokens_.size() ;j++ ){
899  iEvent.getByToken(isoNameTokens_.at(j),depMapReco);
900  if (depMapReco.isValid()){ //Map may not exist if only one candidate passes a double filter
901  typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMapReco->find(recoecalcands[closest]);
902  if (mapi!=depMapReco->end()){ // found candidate in isolation map!
903  dqm->etahistisomatchreco[n+1]->Fill(sortedReco[i].eta(),mapi->val);
904  dqm->ethistisomatchreco[n+1]->Fill(sortedReco[i].et(),mapi->val);
905  dqm->phiHistIsoMatchReco[n+1]->Fill(sortedReco[i].eta(),mapi->val);
906  }
907  }
908  }
909  }
910  } // END of if n+1 < then the number of hlt collections
911  }
912  // fill total reco matched efficiency
913  if (mtachedRecoParts >= dqm->reqNum )
914  dqm-> totalmatchreco->Fill(n+0.5);
915  }
916 
917 }
918 
919 
921 // method called once each job just after ending the event loop //
924 
925 }
926 
int pdgGen
Definition: EmDQMReco.h:120
void fill(const math::XYZTLorentzVector &momentum)
Definition: EmDQMReco.cc:89
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
boost::ptr_vector< FourVectorMonitorElements > standardHist
Definition: EmDQMReco.h:163
std::vector< std::vector< edm::InputTag > > isoNames
Definition: EmDQMReco.h:109
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
void analyze(const edm::Event &event, const edm::EventSetup &)
Definition: EmDQMReco.cc:525
double energy() const
energy
Definition: Particle.cc:112
HistoFillerReco< reco::RecoEcalCandidateCollection > * histoFillerPho
Definition: EmDQMReco.h:231
list parent
Definition: dbtoconf.py:74
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
HistoFillerReco< reco::ElectronCollection > * histoFillerEle
Definition: EmDQMReco.h:228
std::string dirname_
Definition: EmDQMReco.h:226
Definition: deltaR.h:79
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
boost::ptr_vector< FourVectorMonitorElements > histMatchReco
Definition: EmDQMReco.h:168
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int eventnum
Definition: EmDQMReco.h:221
void endJob()
Definition: EmDQMReco.cc:923
std::vector< MonitorElement * > histEtIsoOfHltObjMatchToReco
Definition: EmDQMReco.h:193
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)
EmDQMReco(const edm::ParameterSet &pset)
Constructor.
Definition: EmDQMReco.cc:101
#define NULL
Definition: scimark2.h:8
std::vector< int > theHLTOutputTypes
Definition: EmDQMReco.h:107
void fillHistos(edm::Handle< trigger::TriggerEventWithRefs > &triggerObj, const edm::Event &iEvent, unsigned int n, std::vector< reco::Particle > &sortedReco, bool plotReco, bool plotMonpath)
Definition: EmDQMReco.cc:727
string format
Some error handling for the usage.
T eta() const
edm::EDGetTokenT< std::vector< reco::SuperCluster > > recoObjectsEET
Definition: EmDQMReco.h:150
std::vector< MonitorElement * > phiHistIso
Definition: EmDQMReco.h:187
unsigned int plotBins
Definition: EmDQMReco.h:130
std::vector< MonitorElement * > histEtaIsoOfHltObjMatchToReco
Definition: EmDQMReco.h:194
std::vector< TPRegexp > filters
Definition: eve_filter.cc:25
bool isHltConfigInitialized_
Definition: EmDQMReco.h:113
double recoEtaAcc
Definition: EmDQMReco.h:121
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void Fill(long long x)
HLTConfigProvider hltConfig_
Definition: EmDQMReco.h:112
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: EmDQMReco.cc:210
boost::ptr_vector< FourVectorMonitorElements > histMatchRecoMonPath
Definition: EmDQMReco.h:173
double recoEtAcc
Definition: EmDQMReco.h:122
GreaterByPt< reco::Particle > pTComparator_
Definition: EmDQMReco.h:235
int iEvent
Definition: GenABIO.cc:243
std::vector< std::string > theHLTCollectionHumanNames
Definition: EmDQMReco.h:105
unsigned int numOfHLTCollectionLabels
Definition: EmDQMReco.h:102
HistoFillerReco< l1extra::L1EmParticleCollection > * histoFillerL1Iso
Definition: EmDQMReco.h:232
~EmDQMReco()
Destructor.
Definition: EmDQMReco.cc:517
T sqrt(T t)
Definition: SSEVec.h:48
double p4[4]
Definition: TauolaWrapper.h:92
MonitorElement * totalreco
Definition: EmDQMReco.h:200
EmDQMReco * dqm
Definition: EmDQMReco.h:39
MonitorElement * etaMonitorElement
Definition: EmDQMReco.h:71
edm::EDGetTokenT< std::vector< reco::SuperCluster > > recoObjectsEBT
Definition: EmDQMReco.h:149
int j
Definition: DBlmapReader.cc:9
MonitorElement * totalmatchreco
Definition: EmDQMReco.h:201
FourVectorMonitorElements(EmDQMReco *_parent, const std::string &histogramNameTemplate, const std::string &histogramTitleTemplate)
Definition: EmDQMReco.cc:48
void setVerbose(unsigned level)
Definition: DQMStore.cc:548
DQMStore * dbe
Definition: EmDQMReco.h:225
unsigned int recocut_
Definition: EmDQMReco.h:134
std::vector< MonitorElement * > ethistisomatchreco
Definition: EmDQMReco.h:190
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:76
std::string triggerNameRecoMonPath
Definition: EmDQMReco.h:138
std::vector< bool > plotiso
Definition: EmDQMReco.h:108
edm::EDGetTokenT< reco::GsfElectronCollection > recoElectronsInput
Definition: EmDQMReco.h:148
bool useHumanReadableHistTitles
Definition: EmDQMReco.h:104
double plotPhiMax
Definition: EmDQMReco.h:127
edm::EDGetTokenT< trigger::TriggerEventWithRefs > triggerObjT
Definition: EmDQMReco.h:152
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
HistoFillerReco< l1extra::L1EmParticleCollection > * histoFillerL1NonIso
Definition: EmDQMReco.h:230
MonitorElement * phiMonitorElement
Definition: EmDQMReco.h:72
unsigned int reqNum
Definition: EmDQMReco.h:119
boost::scoped_ptr< FourVectorMonitorElements > histRecoMonpath
Definition: EmDQMReco.h:213
std::vector< MonitorElement * > etahistiso
Definition: EmDQMReco.h:185
boost::scoped_ptr< FourVectorMonitorElements > histMonpath
Definition: EmDQMReco.h:218
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< MonitorElement * > etahistisomatchreco
Definition: EmDQMReco.h:189
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::vector< std::pair< double, double > > plotBounds
Definition: EmDQMReco.h:110
std::vector< edm::EDGetTokenT< edm::AssociationMap< edm::OneToValue< T, float > > > > isoNameTokens_
Definition: EmDQMReco.h:36
std::vector< edm::InputTag > theHLTCollectionLabels
Definition: EmDQMReco.h:100
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
edm::EDGetTokenT< edm::TriggerResults > hltResultsT
Definition: EmDQMReco.h:151
double plotPtMin
Definition: EmDQMReco.h:125
double plotPtMax
Definition: EmDQMReco.h:126
boost::ptr_vector< FourVectorMonitorElements > histHltObjMatchToReco
Definition: EmDQMReco.h:179
double plotEtaMax
Definition: EmDQMReco.h:124
std::vector< MonitorElement * > ethistiso
Definition: EmDQMReco.h:186
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1000
std::string processNameRecoMonPath
Definition: EmDQMReco.h:143
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
boost::scoped_ptr< FourVectorMonitorElements > histReco
Definition: EmDQMReco.h:208
tuple size
Write out results.
std::vector< MonitorElement * > phiHistIsoMatchReco
Definition: EmDQMReco.h:191
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
void beginJob()
Definition: EmDQMReco.cc:225
Definition: Run.h:41
std::vector< MonitorElement * > histPhiIsoOfHltObjMatchToReco
Definition: EmDQMReco.h:195
Definition: DDAxes.h:10
HistoFillerReco< reco::RecoEcalCandidateCollection > * histoFillerClu
Definition: EmDQMReco.h:229