CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EmDQM.cc
Go to the documentation of this file.
1 // Header file for this //
5 
7 // Collaborating Class Header //
15 //#include "DataFormats/EgammaCandidates/interface/Photon.h"
18 //#include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
22 
28 #include <boost/foreach.hpp>
29 
31 // Root include files //
33 #include "TFile.h"
34 #include "TDirectory.h"
35 #include "TH1F.h"
36 #include <iostream>
37 #include <string>
38 #include <Math/VectorUtil.h>
39 using namespace ROOT::Math::VectorUtil ;
40 
41 
43 // Constructor //
46 {
47 
49  dbe->setVerbose(0);
50 
52  // Read from configuration file //
54  dirname_="HLT/HLTEgammaValidation/"+pset.getParameter<std::string>("@module_label");
55  dbe->setCurrentFolder(dirname_);
56 
57  triggerobjwithrefs = pset.getParameter<edm::InputTag>("triggerobject");
58  pathIndex = pset.getUntrackedParameter<unsigned int>("pathIndex", 0);
59  // parameters for generator study
60  reqNum = pset.getParameter<unsigned int>("reqNum");
61  pdgGen = pset.getParameter<int>("pdgGen");
62  genEtaAcc = pset.getParameter<double>("genEtaAcc");
63  genEtAcc = pset.getParameter<double>("genEtAcc");
64  // plotting parameters (untracked because they don't affect the physics)
65  plotEtMin = pset.getUntrackedParameter<double>("genEtMin",0.);
66  plotPtMin = pset.getUntrackedParameter<double>("PtMin",0.);
67  plotPtMax = pset.getUntrackedParameter<double>("PtMax",1000.);
68  plotEtaMax = pset.getUntrackedParameter<double>("EtaMax", 2.7);
69  plotPhiMax = pset.getUntrackedParameter<double>("PhiMax", 3.15);
70  plotBins = pset.getUntrackedParameter<unsigned int>("Nbins",40);
71  plotMinEtForEtaEffPlot = pset.getUntrackedParameter<unsigned int>("minEtForEtaEffPlot", 15);
72  useHumanReadableHistTitles = pset.getUntrackedParameter<bool>("useHumanReadableHistTitles", false);
73  mcMatchedOnly = pset.getUntrackedParameter<bool>("mcMatchedOnly", true);
74  noPhiPlots = pset.getUntrackedParameter<bool>("noPhiPlots", true);
75  noIsolationPlots = pset.getUntrackedParameter<bool>("noIsolationPlots", true);
76  verbosity = pset.getUntrackedParameter<unsigned int>("verbosity",0);
77 
78  //preselction cuts
79  gencutCollection_= pset.getParameter<edm::InputTag>("cutcollection");
80  gencut_ = pset.getParameter<int>("cutnum");
81 
83  // Read in the Vector of Parameter Sets. //
84  // Information for each filter-step //
86  std::vector<edm::ParameterSet> filters =
87  pset.getParameter<std::vector<edm::ParameterSet> >("filters");
88 
89  int i = 0;
90  for(std::vector<edm::ParameterSet>::iterator filterconf = filters.begin() ; filterconf != filters.end() ; filterconf++)
91  {
92 
93  theHLTCollectionLabels.push_back(filterconf->getParameter<edm::InputTag>("HLTCollectionLabels"));
94  theHLTOutputTypes.push_back(filterconf->getParameter<int>("theHLTOutputTypes"));
95  // Grab the human-readable name, if it is not specified, use the Collection Label
96  theHLTCollectionHumanNames.push_back(filterconf->getUntrackedParameter<std::string>("HLTCollectionHumanName",theHLTCollectionLabels[i].label()));
97 
98  std::vector<double> bounds = filterconf->getParameter<std::vector<double> >("PlotBounds");
99  // If the size of plot "bounds" vector != 2, abort
100  assert(bounds.size() == 2);
101  plotBounds.push_back(std::pair<double,double>(bounds[0],bounds[1]));
102  isoNames.push_back(filterconf->getParameter<std::vector<edm::InputTag> >("IsoCollections"));
103  // If the size of the isoNames vector is not greater than zero, abort
104  assert(isoNames.back().size()>0);
105  if (isoNames.back().at(0).label()=="none") {
106  plotiso.push_back(false);
107  } else {
108  if (!noIsolationPlots) plotiso.push_back(true);
109  else plotiso.push_back(false);
110  }
111  nCandCuts.push_back(filterconf->getParameter<int>("ncandcut"));
112  i++;
113  } // END of loop over parameter sets
114 
115  // Record number of HLTCollectionLabels
116  numOfHLTCollectionLabels = theHLTCollectionLabels.size();
117 
118 }
119 
120 
122 // method called once each job just before starting event loop //
124 void
126 {
127 
128 }
129 
130 void
131 EmDQM::beginRun(edm::Run const &iRun, edm::EventSetup const &iSetup)
132 {
133  bool changed(true);
134  if (hltConf_.init(iRun, iSetup, triggerobjwithrefs.process(), changed)) {
135 
136  // if init returns TRUE, initialisation has succeeded!
137 
138  //edm::Service<TFileService> fs;
139  dbe->setCurrentFolder(dirname_);
140 
142  // Set up Histogram of Effiency vs Step. //
143  // theHLTCollectionLabels is a vector of InputTags //
144  // from the configuration file. //
146 
147  std::string histName="total_eff";
148  std::string histTitle = "total events passing";
149  if (!mcMatchedOnly) {
150  // This plot will have bins equal to 2+(number of
151  // HLTCollectionLabels in the config file)
152  total = dbe->book1D(histName.c_str(),histTitle.c_str(),numOfHLTCollectionLabels+2,0,numOfHLTCollectionLabels+2);
153  total->setBinLabel(numOfHLTCollectionLabels+1,"Total");
154  total->setBinLabel(numOfHLTCollectionLabels+2,"Gen");
155  for (unsigned int u=0; u<numOfHLTCollectionLabels; u++){total->setBinLabel(u+1,theHLTCollectionLabels[u].label().c_str());}
156  }
157 
158  histName="total_eff_MC_matched";
159  histTitle="total events passing (mc matched)";
160  totalmatch = dbe->book1D(histName.c_str(),histTitle.c_str(),numOfHLTCollectionLabels+2,0,numOfHLTCollectionLabels+2);
161  totalmatch->setBinLabel(numOfHLTCollectionLabels+1,"Total");
162  totalmatch->setBinLabel(numOfHLTCollectionLabels+2,"Gen");
163  for (unsigned int u=0; u<numOfHLTCollectionLabels; u++){totalmatch->setBinLabel(u+1,theHLTCollectionLabels[u].label().c_str());}
164 
165  MonitorElement* tmphisto;
166  MonitorElement* tmpiso;
167 
169  // Set up generator-level histograms //
171  std::string pdgIdString;
172  switch(pdgGen) {
173  case 11:
174  pdgIdString="Electron";break;
175  case 22:
176  pdgIdString="Photon";break;
177  default:
178  pdgIdString="Particle";
179  }
180 
181  histName = "gen_et";
182  histTitle= "E_{T} of " + pdgIdString + "s" ;
183  etgen = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
184  histName = "gen_eta";
185  histTitle= "#eta of "+ pdgIdString +"s " ;
186  etagen = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
187  histName = "gen_phi";
188  histTitle= "#phi of "+ pdgIdString +"s " ;
189  if (!noPhiPlots) phigen = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
190 
191 
192 
194  // Set up histograms of HLT objects //
196 
197  // Determine what strings to use for histogram titles
198  std::vector<std::string> HltHistTitle;
199  if ( theHLTCollectionHumanNames.size() == numOfHLTCollectionLabels && useHumanReadableHistTitles ) {
200  HltHistTitle = theHLTCollectionHumanNames;
201  } else {
202  for (unsigned int i =0; i < numOfHLTCollectionLabels; i++) {
203  HltHistTitle.push_back(theHLTCollectionLabels[i].label());
204  }
205  }
206 
207  for(unsigned int i = 0; i< numOfHLTCollectionLabels ; i++){
208  if (!mcMatchedOnly) {
209  // Et distribution of HLT objects passing filter i
210  histName = theHLTCollectionLabels[i].label()+"et_all";
211  histTitle = HltHistTitle[i]+" Et (ALL)";
212  tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
213  ethist.push_back(tmphisto);
214 
215  // Eta distribution of HLT objects passing filter i
216  histName = theHLTCollectionLabels[i].label()+"eta_all";
217  histTitle = HltHistTitle[i]+" #eta (ALL)";
218  tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
219  etahist.push_back(tmphisto);
220 
221  if (!noPhiPlots) {
222  // Phi distribution of HLT objects passing filter i
223  histName = theHLTCollectionLabels[i].label()+"phi_all";
224  histTitle = HltHistTitle[i]+" #phi (ALL)";
225  tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
226  phihist.push_back(tmphisto);
227  }
228 
229 
230  // Et distribution of HLT object that is closest delta-R match to sorted gen particle(s)
231  histName = theHLTCollectionLabels[i].label()+"et";
232  histTitle = HltHistTitle[i]+" Et";
233  tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
234  histEtOfHltObjMatchToGen.push_back(tmphisto);
235 
236  // eta distribution of HLT object that is closest delta-R match to sorted gen particle(s)
237  histName = theHLTCollectionLabels[i].label()+"eta";
238  histTitle = HltHistTitle[i]+" eta";
239  tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
240  histEtaOfHltObjMatchToGen.push_back(tmphisto);
241 
242  if (!noPhiPlots) {
243  // phi distribution of HLT object that is closest delta-R match to sorted gen particle(s)
244  histName = theHLTCollectionLabels[i].label()+"phi";
245  histTitle = HltHistTitle[i]+" phi";
246  tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
247  histPhiOfHltObjMatchToGen.push_back(tmphisto);
248  }
249  }
250 
251  // Et distribution of gen object matching HLT object passing filter i
252  histName = theHLTCollectionLabels[i].label()+"et_MC_matched";
253  histTitle = HltHistTitle[i]+" Et (MC matched)";
254  tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax);
255  ethistmatch.push_back(tmphisto);
256 
257  // Eta distribution of gen object matching HLT object passing filter i
258  histName = theHLTCollectionLabels[i].label()+"eta_MC_matched";
259  histTitle = HltHistTitle[i]+" #eta (MC matched)";
260  tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax);
261  etahistmatch.push_back(tmphisto);
262 
263  if (!noPhiPlots) {
264  // Phi distribution of gen object matching HLT object passing filter i
265  histName = theHLTCollectionLabels[i].label()+"phi_MC_matched";
266  histTitle = HltHistTitle[i]+" #phi (MC matched)";
267  tmphisto = dbe->book1D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax);
268  phihistmatch.push_back(tmphisto);
269  }
270 
271 
272  if (!plotiso[i]) {
273  tmpiso = NULL;
274  if (!mcMatchedOnly) {
275  etahistiso.push_back(tmpiso);
276  phihistiso.push_back(tmpiso);
277  ethistiso.push_back(tmpiso);
278  histEtaIsoOfHltObjMatchToGen.push_back(tmpiso);
279  histPhiIsoOfHltObjMatchToGen.push_back(tmpiso);
280  histEtIsoOfHltObjMatchToGen.push_back(tmpiso);
281  }
282  etahistisomatch.push_back(tmpiso);
283  phihistisomatch.push_back(tmpiso);
284  ethistisomatch.push_back(tmpiso);
285  } else {
286  if (!mcMatchedOnly) {
287  // 2D plot: Isolation values vs eta for all objects
288  histName = theHLTCollectionLabels[i].label()+"eta_isolation_all";
289  histTitle = HltHistTitle[i]+" isolation vs #eta (all)";
290  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[i].first,plotBounds[i].second);
291  etahistiso.push_back(tmpiso);
292 
293  // 2D plot: Isolation values vs phi for all objects
294  histName = theHLTCollectionLabels[i].label()+"phi_isolation_all";
295  histTitle = HltHistTitle[i]+" isolation vs #phi (all)";
296  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[i].first,plotBounds[i].second);
297  phihistiso.push_back(tmpiso);
298 
299  // 2D plot: Isolation values vs et for all objects
300  histName = theHLTCollectionLabels[i].label()+"et_isolation_all";
301  histTitle = HltHistTitle[i]+" isolation vs Et (all)";
302  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[i].first,plotBounds[i].second);
303  ethistiso.push_back(tmpiso);
304 
305  // 2D plot: Isolation values vs eta for HLT object that
306  // is closest delta-R match to sorted gen particle(s)
307  histName = theHLTCollectionLabels[i].label()+"eta_isolation";
308  histTitle = HltHistTitle[i]+" isolation vs #eta";
309  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[i].first,plotBounds[i].second);
310  histEtaIsoOfHltObjMatchToGen.push_back(tmpiso);
311 
312  // 2D plot: Isolation values vs phi for HLT object that
313  // is closest delta-R match to sorted gen particle(s)
314  histName = theHLTCollectionLabels[i].label()+"phi_isolation";
315  histTitle = HltHistTitle[i]+" isolation vs #phi";
316  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[i].first,plotBounds[i].second);
317  histPhiIsoOfHltObjMatchToGen.push_back(tmpiso);
318 
319  // 2D plot: Isolation values vs et for HLT object that
320  // is closest delta-R match to sorted gen particle(s)
321  histName = theHLTCollectionLabels[i].label()+"et_isolation";
322  histTitle = HltHistTitle[i]+" isolation vs Et";
323  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[i].first,plotBounds[i].second);
324  histEtIsoOfHltObjMatchToGen.push_back(tmpiso);
325  }
326 
327  // 2D plot: Isolation values vs eta for matched objects
328  histName = theHLTCollectionLabels[i].label()+"eta_isolation_MC_matched";
329  histTitle = HltHistTitle[i]+" isolation vs #eta (mc matched)";
330  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotEtaMax,plotEtaMax,plotBins,plotBounds[i].first,plotBounds[i].second);
331  etahistisomatch.push_back(tmpiso);
332 
333  // 2D plot: Isolation values vs phi for matched objects
334  histName = theHLTCollectionLabels[i].label()+"phi_isolation_MC_matched";
335  histTitle = HltHistTitle[i]+" isolation vs #phi (mc matched)";
336  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,-plotPhiMax,plotPhiMax,plotBins,plotBounds[i].first,plotBounds[i].second);
337  phihistisomatch.push_back(tmpiso);
338 
339 
340  // 2D plot: Isolation values vs et for matched objects
341  histName = theHLTCollectionLabels[i].label()+"et_isolation_MC_matched";
342  histTitle = HltHistTitle[i]+" isolation vs Et (mc matched)";
343  tmpiso = dbe->book2D(histName.c_str(),histTitle.c_str(),plotBins,plotPtMin,plotPtMax,plotBins,plotBounds[i].first,plotBounds[i].second);
344  ethistisomatch.push_back(tmpiso);
345 
346  } // END of HLT histograms
347 
348  }
349 
350  if (changed) {
351  // The HLT config has actually changed wrt the previous Run, hence rebook your
352  // histograms or do anything else dependent on the revised HLT config
353  }
354  } else {
355  // if init returns FALSE, initialisation has NOT succeeded, which indicates a problem
356  // with the file and/or code and needs to be investigated!
357  if (verbosity >= OUTPUT_ERRORS)
358  edm::LogError("EmDQM") << " HLT config extraction failure with process name '" << triggerobjwithrefs.process() << "'.";
359  // In this case, all access methods will return empty values!
360  }
361 }
362 
364 // Destructor //
367 }
369 
371 {
373  // Decide if this was an event of interest. //
374  // Did the highest energy particles happen //
375  // to have |eta| < 2.5 ? Then continue. //
378  event.getByLabel("genParticles", genParticles);
379  if(!genParticles.isValid()) {
380  if (verbosity >= OUTPUT_WARNINGS)
381  edm::LogWarning("EmDQM") << "genParticles invalid.";
382  return false;
383  }
384 
385  std::vector<reco::LeafCandidate> allSortedGenParticles;
386 
387  for(edm::View<reco::Candidate>::const_iterator currentGenParticle = genParticles->begin(); currentGenParticle != genParticles->end(); currentGenParticle++){
388 
389  // TODO: do we need to check the states here again ?
390  // in principle, there should collections produced with the python configuration
391  // (other than 'genParticles') which fulfill these criteria
392  if ( !( abs((*currentGenParticle).pdgId())==pdgGen && (*currentGenParticle).status()==1 && (*currentGenParticle).et() > 2.0) ) continue;
393 
394  reco::LeafCandidate tmpcand( *(currentGenParticle) );
395 
396  if (tmpcand.et() < plotEtMin) continue;
397 
398  allSortedGenParticles.push_back(tmpcand);
399  }
400 
401  std::sort(allSortedGenParticles.begin(), allSortedGenParticles.end(),pTGenComparator_);
402 
403  // return false if not enough particles found
404  if (allSortedGenParticles.size() < gencut_)
405  return false;
406 
407  // additional check (this might be legacy code and we need to check
408  // whether this should not be removed ?)
409 
410  // We now have a sorted collection of all generated particles
411  // with pdgId = pdgGen.
412  // Loop over them to see if the top gen particles have eta within acceptance
413  // bool keepEvent = true;
414  for (unsigned int i = 0 ; i < gencut_ ; i++ ) {
415  bool inECALgap = fabs(allSortedGenParticles[i].eta()) > 1.4442 && fabs(allSortedGenParticles[i].eta()) < 1.556;
416  if ( (fabs(allSortedGenParticles[i].eta()) > genEtaAcc) || inECALgap ) {
417  //edm::LogWarning("EmDQM") << "Throwing event away. Gen particle with pdgId="<< allSortedGenParticles[i].pdgId() <<"; et="<< allSortedGenParticles[i].et() <<"; and eta="<< allSortedGenParticles[i].eta() <<" beyond acceptance.";
418  return false;
419  }
420  }
421 
422  // all tests passed
423  return true;
424 }
426 
428 {
429  // note that this code is very similar to the one in checkGeneratedParticlesRequirement(..)
430  // and hopefully can be merged with it at some point in the future
431 
432  edm::Handle< edm::View<reco::Candidate> > referenceParticles;
433  event.getByLabel(gencutCollection_,referenceParticles);
434  if(!referenceParticles.isValid()) {
435  if (verbosity >= OUTPUT_WARNINGS)
436  edm::LogWarning("EmDQM") << "referenceParticles invalid.";
437  return false;
438  }
439 
440  std::vector<const reco::Candidate *> allSortedReferenceParticles;
441 
442  for(edm::View<reco::Candidate>::const_iterator currentReferenceParticle = referenceParticles->begin();
443  currentReferenceParticle != referenceParticles->end();
444  currentReferenceParticle++)
445  {
446  if ( currentReferenceParticle->et() <= 2.0)
447  continue;
448 
449  // Note that for determining the overall efficiency,
450  // we should only allow
451  //
452  // HOWEVER: for turn-on curves, we need to let
453  // more electrons pass
454  if (currentReferenceParticle->et() < plotEtMin)
455  continue;
456 
457  // TODO: instead of filling a new vector we could simply count here...
458  allSortedReferenceParticles.push_back(&(*currentReferenceParticle));
459  }
460 
461  // std::sort(allSortedReferenceParticles.begin(), allSortedReferenceParticles.end(),pTComparator_);
462 
463  // return false if not enough particles found
464  return allSortedReferenceParticles.size() >= gencut_;
465 }
466 
467 
469 // method called to for each event //
471 void
473 {
475  // Check if there's enough gen particles //
476  // of interest //
479  event.getByLabel(gencutCollection_,cutCounter);
480  if (cutCounter->size() < (unsigned int)gencut_) {
481  //edm::LogWarning("EmDQM") << "Less than "<< gencut_ <<" gen particles with pdgId=" << pdgGen;
482  return;
483  }
484 
485 
486  // fill L1 and HLT info
487  // get objects possed by each filter
489  event.getByLabel(triggerobjwithrefs,triggerObj);
490  if(!triggerObj.isValid()) {
491  if (verbosity >= OUTPUT_WARNINGS)
492  edm::LogWarning("EmDQM") << "parameter triggerobject (" << triggerobjwithrefs << ") does not corresond to a valid TriggerEventWithRefs product. Please check especially the process name (e.g. when running over reprocessed datasets)";
493  return;
494  }
495 
496  // Were enough high energy gen particles found?
497  if (event.isRealData())
498  {
499  // running validation on data.
500  // TODO: we should check that the entire
501  // run is on the same type (all data or
502  // all MC). Otherwise one gets
503  // uninterpretable results...
504  if (!checkRecoParticlesRequirement(event))
505  return;
506  }
507  else
508  {
509  // MC
510  if (!checkGeneratedParticlesRequirement(event))
511  // if no, throw event away
512  return;
513  }
514 
515 
516  // It was an event worth keeping. Continue.
517 
519  // Fill the bin labeled "Total" //
520  // This will be the number of events looked at. //
522  if (!mcMatchedOnly) total->Fill(numOfHLTCollectionLabels+0.5);
523  totalmatch->Fill(numOfHLTCollectionLabels+0.5);
524 
525 
527  // Fill generator info //
529  // the gencut_ highest Et generator objects of the preselected type are our matches
530 
531  std::vector<reco::Particle> sortedGen;
532  for(edm::View<reco::Candidate>::const_iterator genpart = cutCounter->begin(); genpart != cutCounter->end();genpart++){
533  reco::Particle tmpcand( genpart->charge(), genpart->p4(), genpart->vertex(),genpart->pdgId(),genpart->status() );
534  if (tmpcand.et() >= plotEtMin) {
535  sortedGen.push_back(tmpcand);
536  }
537  }
538  std::sort(sortedGen.begin(),sortedGen.end(),pTComparator_ );
539 
540  // Now the collection of gen particles is sorted by pt.
541  // So, remove all particles from the collection so that we
542  // only have the top "1 thru gencut_" particles in it
543  if (sortedGen.size() < gencut_){
544  return;
545  }
546  sortedGen.erase(sortedGen.begin()+gencut_,sortedGen.end());
547 
548  for (unsigned int i = 0 ; i < gencut_ ; i++ ) {
549  etgen ->Fill( sortedGen[i].et() ); //validity has been implicitily checked by the cut on gencut_ above
550  if (sortedGen[i].et() > plotMinEtForEtaEffPlot) {
551  etagen->Fill( sortedGen[i].eta() );
552  if (!noPhiPlots) phigen->Fill( sortedGen[i].phi() );
553  }
554  } // END of loop over Generated particles
555  if (gencut_ >= reqNum && !mcMatchedOnly) total->Fill(numOfHLTCollectionLabels+1.5); // this isn't really needed anymore keep for backward comp.
556  if (gencut_ >= reqNum) totalmatch->Fill(numOfHLTCollectionLabels+1.5); // this isn't really needed anymore keep for backward comp.
557 
558  bool accepted = true; // flags that the event has been accepted by all filters before
560  event.getByLabel(edm::InputTag("TriggerResults","", triggerobjwithrefs.process()), hltResults);
562  // Loop over filter modules //
564  for(unsigned int n=0; n < numOfHLTCollectionLabels ; n++) {
565  // check that there are not less sortedGen particles than nCandCut requires for this filter
566  if (sortedGen.size() < nCandCuts.at(n)) {
567  if (verbosity >= OUTPUT_ERRORS)
568  edm::LogError("EmDQM") << "There are less generated particles than the module '" << theHLTCollectionLabels[n].label() << "' requires.";
569  continue;
570  }
571  std::vector<reco::Particle> sortedGenForFilter(sortedGen);
572  sortedGenForFilter.erase(sortedGenForFilter.begin() + nCandCuts.at(n), sortedGenForFilter.end());
573 
574  // Fill only if this filter was run.
575  if (pathIndex != 0 && hltConf_.moduleIndex(pathIndex, theHLTCollectionLabels[n].label()) > hltResults->index(pathIndex)) break;
576  // These numbers are from the Parameter Set, such as:
577  // theHLTOutputTypes = cms.uint32(100)
578  switch(theHLTOutputTypes[n])
579  {
580  case trigger::TriggerL1NoIsoEG: // Non-isolated Level 1
581  fillHistos<l1extra::L1EmParticleCollection>(triggerObj,event,n,sortedGenForFilter,accepted);break;
582  case trigger::TriggerL1IsoEG: // Isolated Level 1
583  fillHistos<l1extra::L1EmParticleCollection>(triggerObj,event,n,sortedGenForFilter,accepted);break;
584  case trigger::TriggerPhoton: // Photon
585  fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,event,n,sortedGenForFilter,accepted);break;
586  case trigger::TriggerElectron: // Electron
587  fillHistos<reco::ElectronCollection>(triggerObj,event,n,sortedGenForFilter,accepted);break;
588  case trigger::TriggerCluster: // TriggerCluster
589  fillHistos<reco::RecoEcalCandidateCollection>(triggerObj,event,n,sortedGenForFilter,accepted);break;
590  default:
591  throw(cms::Exception("Release Validation Error") << "HLT output type not implemented: theHLTOutputTypes[n]" );
592  }
593  } // END of loop over filter modules
594 }
595 
596 
598 // fillHistos //
599 // Called by analyze method. //
601 template <class T> void EmDQM::fillHistos(edm::Handle<trigger::TriggerEventWithRefs>& triggerObj,const edm::Event& iEvent ,unsigned int n,std::vector<reco::Particle>& sortedGen, bool &accepted)
602 {
603  std::vector<edm::Ref<T> > recoecalcands;
604  if ( ( triggerObj->filterIndex(theHLTCollectionLabels[n])>=triggerObj->size() )){ // only process if available
605  hltCollectionLabelsMissed.insert(theHLTCollectionLabels[n].encode());
606  accepted = false;
607  return;
608  }
609 
610  hltCollectionLabelsFound.insert(theHLTCollectionLabels[n].encode());
611 
613  // Retrieve saved filter objects //
615  triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),theHLTOutputTypes[n],recoecalcands);
616  //Danger: special case, L1 non-isolated
617  // needs to be merged with L1 iso
618  if (theHLTOutputTypes[n] == trigger::TriggerL1NoIsoEG){
619  std::vector<edm::Ref<T> > isocands;
620  triggerObj->getObjects(triggerObj->filterIndex(theHLTCollectionLabels[n]),trigger::TriggerL1IsoEG,isocands);
621  if (isocands.size()>0)
622  {
623  for (unsigned int i=0; i < isocands.size(); i++)
624  recoecalcands.push_back(isocands[i]);
625  }
626  } // END of if theHLTOutputTypes == 82
627 
628 
629  if (recoecalcands.size() < 1){ // stop if no object passed the previous filter
630  accepted = false;
631  return;
632  }
633 
634  //if (recoecalcands.size() >= reqNum )
635  if (recoecalcands.size() >= nCandCuts.at(n) && !mcMatchedOnly)
636  total->Fill(n+0.5);
637 
639  // check for validity //
640  // prevents crash in CMSSW_3_1_0_pre6 //
642  for (unsigned int j=0; j<recoecalcands.size(); j++){
643  if(!( recoecalcands.at(j).isAvailable())){
644  if (verbosity >= OUTPUT_ERRORS)
645  edm::LogError("EmDQMInvalidRefs") << "Event content inconsistent: TriggerEventWithRefs contains invalid Refs. Invalid refs for: " << theHLTCollectionLabels[n].label() << ". The collection that this module uses may has been dropped in the event.";
646  return;
647  }
648  }
649 
650  if (!mcMatchedOnly) {
652  // Loop over the Generated Particles, and find the //
653  // closest HLT object match. //
655  //for (unsigned int i=0; i < gencut_; i++) {
656  for (unsigned int i=0; i < nCandCuts.at(n); i++) {
657  math::XYZVector currentGenParticleMomentum = sortedGen[i].momentum();
658 
659  float closestDeltaR = 0.5;
660  int closestEcalCandIndex = -1;
661  for (unsigned int j=0; j<recoecalcands.size(); j++) {
662  float deltaR = DeltaR(recoecalcands[j]->momentum(),currentGenParticleMomentum);
663 
664  if (deltaR < closestDeltaR) {
665  closestDeltaR = deltaR;
666  closestEcalCandIndex = j;
667  }
668  }
669 
670  // If an HLT object was found within some delta-R
671  // of this gen particle, store it in a histogram
672  if ( closestEcalCandIndex >= 0 ) {
673  histEtOfHltObjMatchToGen[n] ->Fill( recoecalcands[closestEcalCandIndex]->et() );
674  histEtaOfHltObjMatchToGen[n]->Fill( recoecalcands[closestEcalCandIndex]->eta() );
675  if (!noPhiPlots) histPhiOfHltObjMatchToGen[n]->Fill( recoecalcands[closestEcalCandIndex]->phi() );
676 
677  // Also store isolation info
678  if (n+1 < numOfHLTCollectionLabels){ // can't plot beyond last
679  if (plotiso[n+1] ){ // only plot if requested in config
680  for (unsigned int j = 0 ; j < isoNames[n+1].size() ;j++ ){
682  iEvent.getByLabel(isoNames[n+1].at(j),depMap);
683  if (depMap.isValid()){ //Map may not exist if only one candidate passes a double filter
684  typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(recoecalcands[closestEcalCandIndex]);
685  if (mapi!=depMap->end()) { // found candidate in isolation map!
686  histEtaIsoOfHltObjMatchToGen[n+1]->Fill( recoecalcands[closestEcalCandIndex]->eta(),mapi->val);
687  histPhiIsoOfHltObjMatchToGen[n+1]->Fill( recoecalcands[closestEcalCandIndex]->phi(),mapi->val);
688  histEtIsoOfHltObjMatchToGen[n+1] ->Fill( recoecalcands[closestEcalCandIndex]->et(), mapi->val);
689  }
690  }
691  }
692  }
693  }
694  } // END of if closestEcalCandIndex >= 0
695  }
696 
698  // Loop over all HLT objects in this filter step, and //
699  // fill histograms. //
701  // bool foundAllMatches = false;
702  // unsigned int numOfHLTobjectsMatched = 0;
703  for (unsigned int i=0; i<recoecalcands.size(); i++) {
705  //float closestGenParticleDr = 99.0;
706  //for(unsigned int j =0; j < gencut_; j++) {
707  // math::XYZVector currentGenParticle = sortedGen[j].momentum();
708 
709  // double currentDeltaR = DeltaR(recoecalcands[i]->momentum(),currentGenParticle);
710  // if ( currentDeltaR < closestGenParticleDr ) {
711  // closestGenParticleDr = currentDeltaR;
712  // }
713  //}
715  //if ( !(fabs(closestGenParticleDr < 0.3)) ) continue;
716 
717  //numOfHLTobjectsMatched++;
718  //if (numOfHLTobjectsMatched >= gencut_) foundAllMatches=true;
719 
720  // Fill HLT object histograms
721  ethist[n] ->Fill(recoecalcands[i]->et() );
722  etahist[n]->Fill(recoecalcands[i]->eta() );
723  if (!noPhiPlots) phihist[n]->Fill(recoecalcands[i]->phi() );
724 
726  // Plot isolation variables (show the not-yet-cut //
727  // isolation, i.e. associated to next filter) //
729  if ( n+1 < numOfHLTCollectionLabels ) { // can't plot beyond last
730  if (plotiso[n+1]) {
731  for (unsigned int j = 0 ; j < isoNames[n+1].size() ;j++ ){
733  iEvent.getByLabel(isoNames[n+1].at(j),depMap);
734  if (depMap.isValid()){ //Map may not exist if only one candidate passes a double filter
735  typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(recoecalcands[i]);
736  if (mapi!=depMap->end()){ // found candidate in isolation map!
737  etahistiso[n+1]->Fill(recoecalcands[i]->eta(),mapi->val);
738  phihistiso[n+1]->Fill(recoecalcands[i]->phi(),mapi->val);
739  ethistiso[n+1]->Fill(recoecalcands[i]->et(),mapi->val);
740  }
741  }
742  }
743  }
744  } // END of if n+1 < then the number of hlt collections
745  }
746  }
747 
748 
750  // Fill mc matched objects into histograms //
752  unsigned int mtachedMcParts = 0;
753  float mindist=0.3;
754  if(n==0) mindist=0.5; //low L1-resolution => allow wider matching
755  for(unsigned int i =0; i < nCandCuts.at(n); ++i){
756  //match generator candidate
757  bool matchThis= false;
758  math::XYZVector candDir=sortedGen[i].momentum();
759  unsigned int closest = 0;
760  double closestDr = 1000.;
761  for(unsigned int trigOb = 0 ; trigOb < recoecalcands.size(); ++trigOb){
762  double dr = DeltaR(recoecalcands[trigOb]->momentum(),candDir);
763  if (dr < closestDr) {
764  closestDr = dr;
765  closest = trigOb;
766  }
767  if (closestDr > mindist) { // it's not really a "match" if it's that far away
768  closest = -1;
769  } else {
770  mtachedMcParts++;
771  matchThis = true;
772  }
773  }
774  if ( !matchThis ) {
775  accepted = false;
776  continue; // only plot matched candidates
777  }
778  // fill coordinates of mc particle matching trigger object
779  ethistmatch[n] ->Fill( sortedGen[i].et() );
780  if (sortedGen[i].et() > plotMinEtForEtaEffPlot) {
781  etahistmatch[n]->Fill( sortedGen[i].eta() );
782  if (!noPhiPlots) phihistmatch[n]->Fill( sortedGen[i].phi() );
783  }
785  // Plot isolation variables (show the not-yet-cut //
786  // isolation, i.e. associated to next filter) //
788  if (n+1 < numOfHLTCollectionLabels){ // can't plot beyond last
789  if (plotiso[n+1] ){ // only plot if requested in config
790  for (unsigned int j = 0 ; j < isoNames[n+1].size() ;j++ ){
792  iEvent.getByLabel(isoNames[n+1].at(j),depMap);
793  if (depMap.isValid()){ //Map may not exist if only one candidate passes a double filter
794  typename edm::AssociationMap<edm::OneToValue< T , float > >::const_iterator mapi = depMap->find(recoecalcands[closest]);
795  if (mapi!=depMap->end()){ // found candidate in isolation map!
796  // Only make efficiency plot using photons with some min Et
797  etahistisomatch[n+1]->Fill(sortedGen[i].eta(),mapi->val);
798  phihistisomatch[n+1]->Fill(sortedGen[i].phi(),mapi->val);
799  ethistisomatch[n+1]->Fill(sortedGen[i].et(),mapi->val);
800  }
801  }
802  }
803  }
804  } // END of if n+1 < then the number of hlt collections
805  }
806  // fill total mc matched efficiency
807 
808  if (mtachedMcParts >= nCandCuts.at(n) && accepted == true)
809  totalmatch->Fill(n+0.5);
810 }
811 
812 void
813 EmDQM::endRun(edm::Run const &iRun, edm::EventSetup const &iSetup)
814 {
815  // print information about hltCollectionLabels which were not found
816  // (but only those which were never found)
817 
818  // check which ones were never found
819  std::vector<std::string> labelsNeverFound;
820 
821 
822  // for (std::set<edm::InputTag>::const_iterator it = hltCollectionLabelsMissed.begin(); it != hltCollectionLabelsMissed.end(); ++it)
823  BOOST_FOREACH(const edm::InputTag &tag, hltCollectionLabelsMissed)
824  {
825  if (hltCollectionLabelsFound.count(tag.encode()) == 0)
826  // never found
827  labelsNeverFound.push_back(tag.encode());
828 
829  } // loop over all tags which were missed at least once
830 
831  if (labelsNeverFound.empty())
832  return;
833 
834  std::sort(labelsNeverFound.begin(), labelsNeverFound.end());
835 
836  // there was at least one label which was never found
837  // (note that this could also be because the corresponding
838  // trigger path slowly fades out to zero efficiency)
839  if (verbosity >= OUTPUT_WARNINGS)
840  edm::LogWarning("EmDQM") << "There were some HLTCollectionLabels which were never found:";
841 
842  BOOST_FOREACH(const edm::InputTag &tag, labelsNeverFound)
843  {
844  if (verbosity >= OUTPUT_ALL)
845  edm::LogPrint("EmDQM") << " " << tag;
846  }
847 }
848 
850 // method called once each job just after ending the event loop //
853 {
854 
855 }
856 
857 //----------------------------------------------------------------------
858 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
void beginJob()
Definition: EmDQM.cc:125
bool checkRecoParticlesRequirement(const edm::Event &event)
Definition: EmDQM.cc:427
~EmDQM()
Destructor.
Definition: EmDQM.cc:366
virtual double et() const
transverse energy
Definition: deltaR.h:51
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
#define abs(x)
Definition: mlp_lapack.h:159
#define NULL
Definition: scimark2.h:8
T eta() const
Definition: EmDQM.h:24
bool isRealData() const
Definition: EventBase.h:60
std::vector< TPRegexp > filters
Definition: eve_filter.cc:25
std::string encode() const
Definition: InputTag.cc:72
void beginRun(edm::Run const &, edm::EventSetup const &)
Definition: EmDQM.cc:131
int iEvent
Definition: GenABIO.cc:243
void endRun(edm::Run const &, edm::EventSetup const &)
Definition: EmDQM.cc:813
int j
Definition: DBlmapReader.cc:9
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
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
EmDQM(const edm::ParameterSet &pset)
Constructor.
Definition: EmDQM.cc:45
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
bool checkGeneratedParticlesRequirement(const edm::Event &event)
Definition: EmDQM.cc:370
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
void analyze(const edm::Event &event, const edm::EventSetup &)
Definition: EmDQM.cc:472
void fillHistos(edm::Handle< trigger::TriggerEventWithRefs > &, const edm::Event &, unsigned int, std::vector< reco::Particle > &, bool &)
Definition: EmDQM.cc:601
void endJob()
Definition: EmDQM.cc:852
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:33
list at
Definition: asciidump.py:428
Definition: DDAxes.h:10