CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTExoticaSubAnalysis.cc
Go to the documentation of this file.
1 
10 
15 
16 #include "TPRegexp.h"
17 #include "TString.h"
18 
21 
22 #include <set>
23 #include <algorithm>
24 
27  const std::string & analysisname,
28  edm::ConsumesCollector && consCollector) :
29  _pset(pset),
30  _analysisname(analysisname),
31  _minCandidates(0),
32  _hltProcessName(pset.getParameter<std::string>("hltProcessName")),
33  _genParticleLabel(pset.getParameter<std::string>("genParticleLabel")),
34  _trigResultsLabel("TriggerResults", "", _hltProcessName),
35  _parametersEta(pset.getParameter<std::vector<double> >("parametersEta")),
36  _parametersPhi(pset.getParameter<std::vector<double> >("parametersPhi")),
37  _parametersTurnOn(pset.getParameter<std::vector<double> >("parametersTurnOn")),
38  _recMuonSelector(0),
39  _recElecSelector(0),
40  _recPFMETSelector(0),
41  _recPFTauSelector(0),
42  _recPhotonSelector(0),
43  _recJetSelector(0)
44 {
45 
46  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::constructor()";
47 
48  // Specific parameters for this analysis
49  edm::ParameterSet anpset = pset.getParameter<edm::ParameterSet>(analysisname);
50 
51  // If this analysis has a particular set of binnings, use it.
52  // (Taken from the analysis-specific parameter set, of course)
53  // The "true" in the beginning of _pset.insert() means
54  // "overwrite the parameter if need be".
55  if (anpset.exists("parametersTurnOn")) {
56  _parametersTurnOn = anpset.getParameter<std::vector<double> >("parametersTurnOn");
57  _pset.insert(true, "parametersTurnOn", anpset.retrieve("parametersTurnOn"));
58  }
59  if (anpset.exists("parametersEta")) {
60  _parametersEta = anpset.getParameter<std::vector<double> >("parametersEta");
61  _pset.insert(true, "parametersEta", anpset.retrieve("parametersEta"));
62  }
63  if (anpset.exists("parametersPhi")) {
64  _parametersPhi = anpset.getParameter<std::vector<double> >("parametersPhi");
65  _pset.insert(true, "parametersPhi", anpset.retrieve("parametersPhi"));
66  }
67 
68  // Get names of objects that we may want to get from the event.
69  // Notice that genParticles are dealt with separately.
70  this->getNamesOfObjects(anpset);
71 
72  // Since now we have the names, we should register the consumption
73  // of objects.
74  this->registerConsumes(consCollector);
75 
76  // Generic objects: Initialization of basic phase space cuts.
77  for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin();
78  it != _recLabels.end(); ++it) {
79  const std::string objStr = EVTColContainer::getTypeString(it->first);
80  _genCut[it->first] = pset.getParameter<std::string>(std::string(objStr + "_genCut").c_str());
81  _recCut[it->first] = pset.getParameter<std::string>(std::string(objStr + "_recCut").c_str());
82  }
83 
84  //--- Updating parameters if has to be modified for this particular specific analysis
85  for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin();
86  it != _recLabels.end(); ++it) {
87  const std::string objStr = EVTColContainer::getTypeString(it->first);
88 
89  try {
90  _genCut[it->first] = anpset.getUntrackedParameter<std::string>(std::string(objStr + "_genCut").c_str());
91  } catch (edm::Exception) {}
92 
93  try {
94  _recCut[it->first] = anpset.getUntrackedParameter<std::string>(std::string(objStr + "_recCut").c_str());
95  } catch (edm::Exception) {}
96 
97  }
98 
100  _hltPathsToCheck = anpset.getParameter<std::vector<std::string> >("hltPathsToCheck");
102  _minCandidates = anpset.getParameter<unsigned int>("minCandidates");
103 
104 }
105 
107 {
108  for (std::map<unsigned int, StringCutObjectSelector<reco::GenParticle>* >::iterator it = _genSelectorMap.begin();
109  it != _genSelectorMap.end(); ++it) {
110  delete it->second;
111  it->second = 0;
112  }
113  delete _recMuonSelector;
114  _recMuonSelector = 0;
115  delete _recElecSelector;
116  _recElecSelector = 0;
117  delete _recPhotonSelector;
118  _recPhotonSelector = 0;
119  delete _recPFMETSelector;
120  _recPFMETSelector = 0;
121  delete _recPFTauSelector;
122  _recPFTauSelector = 0;
123  delete _recJetSelector;
124  _recJetSelector = 0;
125 }
126 
127 
129 {
130 }
131 
132 
133 // 2014-02-03 -- Thiago
134 // Due to the fact that the DQM has to be thread safe now, we have to do things differently:
135 // 1) Implement the bookHistograms() method in the container class
136 // 2) Make the iBooker from above be known to this class
137 // 3) Separate all booking histograms routines in this and any auxiliary classe to be called
138 // from bookHistograms() in the container class
140  const edm::Run & iRun,
141  const edm::EventSetup & iSetup)
142 {
143 
144  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::subAnalysisBookHistos()";
145 
146  // Create the folder structure inside HLT/Exotica
147  std::string baseDir = "HLT/Exotica/" + _analysisname + "/";
148  iBooker.setCurrentFolder(baseDir);
149 
150  // Book the gen/reco analysis-dependent histograms (denominators)
151  for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin();
152  it != _recLabels.end(); ++it) {
153  const std::string objStr = EVTColContainer::getTypeString(it->first);
154  std::vector<std::string> sources(2);
155  sources[0] = "gen";
156  sources[1] = "rec";
157 
158  for (size_t i = 0; i < sources.size(); i++) {
159  std::string source = sources[i];
160  bookHist(iBooker, source, objStr, "Eta");
161  bookHist(iBooker, source, objStr, "Phi");
162  bookHist(iBooker, source, objStr, "MaxPt1");
163  bookHist(iBooker, source, objStr, "MaxPt2");
164  bookHist(iBooker, source, objStr, "SumEt");
165  }
166  } // closes loop in _recLabels
167 
168  // Call the plotterBookHistos() (which books all the path dependent histograms)
169  LogDebug("ExoticaValidation") << " number of plotters = " << _plotters.size();
170  for (std::vector<HLTExoticaPlotter>::iterator it = _plotters.begin();
171  it != _plotters.end(); ++it) {
172  it->plotterBookHistos(iBooker, iRun, iSetup);
173  }
174 }
175 
176 void HLTExoticaSubAnalysis::beginRun(const edm::Run & iRun, const edm::EventSetup & iSetup)
177 {
178 
179  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::beginRun()";
180 
183 
184  // Initialize the HLT config.
185  bool changedConfig(true);
186  if (!_hltConfig.init(iRun, iSetup, _hltProcessName, changedConfig)) {
187  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::constructor(): "
188  << "Initialization of HLTConfigProvider failed!";
189  }
190 
191  // Parse the input paths to get them if they are in the table and associate
192  // them to the last filter of the path (in order to extract the objects).
193  _hltPaths.clear();
194  for (size_t i = 0; i < _hltPathsToCheck.size(); ++i) {
195  bool found = false;
196  TPRegexp pattern(_hltPathsToCheck[i]);
197 
198  // Loop over triggerNames from _hltConfig
199  for (size_t j = 0 ; j < _hltConfig.triggerNames().size(); ++j) {
200  std::string thetriggername = _hltConfig.triggerNames()[j];
201  if (TString(thetriggername).Contains(pattern)) {
202  _hltPaths.insert(thetriggername);
203  found = true;
204  }
205  }
206 
207  // Oh dear, the path we wanted seems to not be available
208  if (! found) {
209  edm::LogWarning("ExoticaValidation") << "HLTExoticaSubAnalysis::constructor(): In "
210  << _analysisname << " subfolder NOT found the path: '"
211  << _hltPathsToCheck[i] << "*'" ;
212  }
213  } // Close loop over paths to check.
214 
215  // At this point, _hltpaths contains the names of the paths to check
216  // that were found. Let's log it at trace level.
217  LogTrace("ExoticaValidation") << "SubAnalysis: " << _analysisname
218  << "\nHLT Trigger Paths found >>>";
219  for (std::set<std::string>::const_iterator iter = _hltPaths.begin();
220  iter != _hltPaths.end(); ++iter) {
221  LogTrace("ExoticaValidation") << (*iter) << "\n";
222  }
223 
224  // Initialize the plotters (analysers for each trigger path)
225  _plotters.clear();
226  for (std::set<std::string>::iterator iPath = _hltPaths.begin();
227  iPath != _hltPaths.end(); ++iPath) {
228  // Avoiding the dependence of the version number for the trigger paths
229  std::string path = * iPath;
230  std::string shortpath = path;
231  if (path.rfind("_v") < path.length()) {
232  shortpath = path.substr(0, path.rfind("_v"));
233  }
234  _shortpath2long[shortpath] = path;
235 
236  // Objects needed by the HLT path
237  // Thiago: instead of trying to decode the objects from the path,
238  // put the burden on the user to tell us which objects are needed.
239  //const std::vector<unsigned int> objsNeedHLT = this->getObjectsType(shortpath);
240  std::vector<unsigned int> objsNeedHLT;
241  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin() ;
242  it != _recLabels.end(); ++it) {
243  objsNeedHLT.push_back(it->first);
244  }
245 
246  /*std::vector<unsigned int> userInstantiate;
247  // Sanity check: the object needed by a trigger path should be
248  // introduced by the user via config python (_recLabels datamember)
249  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin() ;
250  it != _recLabels.end(); ++it) {
251  userInstantiate.push_back(it->first);
252  }
253  for (std::vector<unsigned int>::const_iterator it = objsNeedHLT.begin(); it != objsNeedHLT.end();
254  ++it) {
255  if (std::find(userInstantiate.begin(), userInstantiate.end(), *it) ==
256  userInstantiate.end()) {
257  edm::LogError("ExoticaValidation") << "In HLTExoticaSubAnalysis::beginRun, "
258  << "Incoherence found in the python configuration file!!\nThe SubAnalysis '"
259  << _analysisname << "' has been asked to evaluate the trigger path '"
260  << shortpath << "' (found it in 'hltPathsToCheck') BUT this path"
261  << " needs a '" << EVTColContainer::getTypeString(*it)
262  << "' which has not been instantiated ('recVariableLabels'"
263  << ")" ;
264  exit(-1); // This should probably throw an exception...
265  }
266  }
267  */
268  LogTrace("ExoticaValidation") << " --- " << shortpath;
269 
270  // The hlt path, the objects (electrons, muons, photons, ...)
271  // needed to evaluate the path are the argumens of the plotter
272  HLTExoticaPlotter analyzer(_pset, shortpath, objsNeedHLT);
273  _plotters.push_back(analyzer);
274  }// Okay, at this point we have prepared all the plotters.
275 
276 }
277 
278 
280 {
281  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::analyze()";
282 
283  // Loop over _recLabels to make sure everything is alright.
284  /*
285  std::cout << "Now printing the _recLabels" << std::endl;
286  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin();
287  it != _recLabels.end(); ++it) {
288  std::cout << "Number: " << it->first << "\t" << "Label: " << it->second.label() << std::endl;
289  }
290  */
291 
292  // Initialize the collection (the ones which have not been initialiazed yet)
293  //std::cout << "Setting handles to objects..." << std::endl;
294  this->getHandlesToObjects(iEvent, cols);
295 
296  // Utility map, mapping kinds of objects (GEN, RECO) to strings ("gen","rec")
297  //std::map<Level, std::string> u2str;
298  //u2str[Level::GEN] = "gen";
299  //u2str[Level::RECO] = "rec";
300 
301  // Extract the match structure containing the gen/reco candidates (electron, muons,...). This part is common to all the SubAnalyses
302 
303  //std::map<unsigned int, std::vector<MatchStruct> > sourceMatchMap;
304  //std::vector<MatchStruct> matchesGen; matchesGen.clear();
305  std::vector<reco::LeafCandidate> matchesGen; matchesGen.clear();
306  //std::vector<MatchStruct> matchesReco; matchesReco.clear();
307  std::vector<reco::LeafCandidate> matchesReco; matchesReco.clear();
308  //sourceMatchMap[98] = matchesGen;
309  //sourceMatchMap[99] = matchesReco;
310 
311  //std::cout << "In the beginning: matchesGen.size() = " << matchesGen.size() << std::endl;
312  //std::cout << "In the beginning: matchesReco.size() = " << matchesReco.size() << std::endl;
313 
314  // --- deal with GEN objects first.
315  // Make each good GEN object into the base cand for a MatchStruct
316  // Our definition of "good" is "passes the selector" defined in the config.py
317  // Save all the MatchStructs in the "matchesGen" vector.
318 
319  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin();
320  it != _recLabels.end(); ++it) {
321  // Here we are filling the vector of StringCutObjectSelector<reco::GenParticle>
322  // with objects constructed from the strings saved in _genCut.
323  // Initialize selectors when first event
324 
325  //std::cout << "Loop over the kinds of objects: objects of kind " << it->first << std::endl;
326 
327  if (!_genSelectorMap[it->first]) {
329  }
330 
331  // Now loop over the genParticles, and apply the operator() over each of them.
332  // Fancy syntax: for objects X and Y, X.operator()(Y) is the same as X(Y).
333  for (size_t i = 0; i < cols->genParticles->size(); ++i) {
334  //std::cout << "Now matchesGen.size() is " << matchesGen.size() << std::endl;
335  if (_genSelectorMap[it->first]->operator()(cols->genParticles->at(i))) {
336  const reco::Candidate* cand = &(cols->genParticles->at(i));
337  //std::cout << "Found good cand: cand->pt() = " << cand->pt() << std::endl;
338  //matchesGen.push_back(MatchStruct(cand, it->first));
341  reco::LeafCandidate v(0,cand->p4(),cand->vertex(),it->first,0,true);
342  matchesGen.push_back(v);
343  }
344  }
345  }
346 
347  // Sort the matches by pT for later filling of turn-on curve
348  //std::cout << "Before sorting: matchesGen.size() = " << matchesGen.size() << std::endl;
350  std::sort(matchesGen.begin(),
351  matchesGen.end(),
352  comparator);
353  //std::cout << "After sorting: matchesGen.size() = " << matchesGen.size() << std::endl;
354 
355  //std::cout << "Before adding RECO: sourceMatchMap[98].size() = " << sourceMatchMap[98].size() << std::endl;
356  //std::cout << "Before adding RECO: matchesGen.size() = " << matchesGen.size() << std::endl;
357 
358  // --- same for RECO objects
359  // Extraction of the objects candidates
360  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin();
361  it != _recLabels.end(); ++it) {
362  //std::cout << "Filling RECO \"matchesReco\" vector for particle kind it->first = "
363  // << it->first << ", which means " << it->second.label() << std::endl;
364  // Reco selectors (the function takes into account if it was instantiated
365  // before or not) ### Thiago ---> Then why don't we put it in the beginRun???
366  this->initSelector(it->first);
367  // -- Storing the matchesReco
368  this->insertCandidates(it->first, cols, &matchesReco);
369  }
370 
371  //std::cout << "After adding RECO: matchesGen.size() = " << matchesGen.size() << std::endl;
372  //std::cout << "After adding RECO: matchesReco.size() = " << matchesReco.size() << std::endl;
373 
374  std::sort(matchesReco.begin(),
375  matchesReco.end(),
376  comparator);
377 
378  // --- All the objects are in place
379  //std::cout << "DEBUG(0)" << std::endl;
380 
381  // -- Trigger Results
382  const edm::TriggerNames trigNames = iEvent.triggerNames(*(cols->triggerResults));
383 
386 
387  //for (std::map<unsigned int, std::vector<MatchStruct> >::iterator it = sourceMatchMap.begin(); it != sourceMatchMap.end(); ++it) {
388  // it->first: gen/reco it->second: HLT matches (std::vector<MatchStruct>)
389 
390  //if (it->second.size() < _minCandidates) { // FIXME: A bug is potentially here: what about the mixed channels?
391  //continue;
392  //}
393 
397  {
398  if(matchesGen.size() < _minCandidates) return; // FIXME: A bug is potentially here: what about the mixed channels?
399 
400  // Okay, there are enough candidates. Move on!
401 
402  // Filling the gen/reco objects (eff-denominators):
403  // Just the first two different ones, if there are more
404  // The countobjects maps uints (object types, really) --> integers.
405  // Example:
406  // | uint | int |
407  // | 0 | 1 | --> 1 muon used
408  // | 1 | 2 | --> 2 electrons used
409  // Initializing the count of the used objects.
410  std::map<unsigned int, int> * countobjects = new std::map<unsigned int, int>;
411  for (std::map<unsigned int, edm::InputTag>::iterator co = _recLabels.begin();
412  co != _recLabels.end(); ++co) {
413  countobjects->insert(std::pair<unsigned int, int>(co->first, 0));
414  }
415 
416  int counttotal = 0;
417  int totalobjectssize2 = 2 * countobjects->size();
418 
419  for (size_t j = 0; j != matchesGen.size(); ++j) {
420  const unsigned int objType = matchesGen[j].pdgId();
421  //std::cout << "(4) Gonna call with " << objType << std::endl;
422  const std::string objTypeStr = EVTColContainer::getTypeString(objType);
423 
424  float pt = matchesGen[j].pt();
425  float eta = matchesGen[j].eta();
426  float phi = matchesGen[j].phi();
427  float sumEt = 0;//matchesGen[j].sumEt;
428 
429  this->fillHist("gen", objTypeStr, "Eta", eta);
430  this->fillHist("gen", objTypeStr, "Phi", phi);
431  this->fillHist("gen", objTypeStr, "SumEt", sumEt);
432 
433  if ((*countobjects)[objType] == 0) {
434  this->fillHist("gen", objTypeStr, "MaxPt1", pt);
435  // Filled the high pt ...
436  ++((*countobjects)[objType]);
437  ++counttotal;
438  } else if ((*countobjects)[objType] == 1) {
439  this->fillHist("gen", objTypeStr, "MaxPt2", pt);
440  // Filled the second high pt ...
441  ++((*countobjects)[objType]);
442  ++counttotal;
443  } else {
444  // Already the minimum two objects has been filled, get out...
445  if (counttotal == totalobjectssize2) {
446  break;
447  }
448  }
449  } // Closes loop in gen
450 
451  LogDebug("ExoticaValidation") << " deleting countobjects";
452  //delete countobjects;
453 
454  // Calling to the plotters analysis (where the evaluation of the different trigger paths are done)
455  //const std::string source = "gen";
456  for (std::vector<HLTExoticaPlotter>::iterator an = _plotters.begin(); an != _plotters.end(); ++an) {
457  const std::string hltPath = _shortpath2long[an->gethltpath()];
458  const bool ispassTrigger = cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
459  LogDebug("ExoticaValidation") << " preparing to call the plotters analysis";
460  an->analyze(ispassTrigger, "gen", matchesGen);
461  LogDebug("ExoticaValidation") << " called the plotter";
462  }
463  }
464 
465 
469  {
470  if(matchesReco.size() < _minCandidates) return; // FIXME: A bug is potentially here: what about the mixed channels?
471 
472  // Okay, there are enough candidates. Move on!
473 
474  // Filling the gen/reco objects (eff-denominators):
475  // Just the first two different ones, if there are more
476  // The countobjects maps uints (object types, really) --> integers.
477  // Example:
478  // | uint | int |
479  // | 0 | 1 | --> 1 muon used
480  // | 1 | 2 | --> 2 electrons used
481  // Initializing the count of the used objects.
482  std::map<unsigned int, int> * countobjects = new std::map<unsigned int, int>;
483  for (std::map<unsigned int, edm::InputTag>::iterator co = _recLabels.begin();
484  co != _recLabels.end(); ++co) {
485  countobjects->insert(std::pair<unsigned int, int>(co->first, 0));
486  }
487 
488  int counttotal = 0;
489  int totalobjectssize2 = 2 * countobjects->size();
490 
492  //std::cout << "Our RECO vector has matchesReco.size() = " << matchesReco.size() << std::endl;
493 
494  for (size_t j = 0; j != matchesReco.size(); ++j) {
495  const unsigned int objType = matchesReco[j].pdgId();
496  //std::cout << "(4) Gonna call with " << objType << std::endl;
497  const std::string objTypeStr = EVTColContainer::getTypeString(objType);
498 
499  float pt = matchesReco[j].pt();
500  float eta = matchesReco[j].eta();
501  float phi = matchesReco[j].phi();
502  float sumEt = 0;//matchesReco[j].sumEt;
503 
504  this->fillHist("rec", objTypeStr, "Eta", eta);
505  this->fillHist("rec", objTypeStr, "Phi", phi);
506  this->fillHist("rec", objTypeStr, "SumEt", sumEt);
507 
508  if ((*countobjects)[objType] == 0) {
509  this->fillHist("rec", objTypeStr, "MaxPt1", pt);
510  // Filled the high pt ...
511  ++((*countobjects)[objType]);
512  ++counttotal;
513  } else if ((*countobjects)[objType] == 1) {
514  this->fillHist("rec", objTypeStr, "MaxPt2", pt);
515  // Filled the second high pt ...
516  ++((*countobjects)[objType]);
517  ++counttotal;
518  } else {
519  // Already the minimum two objects has been filled, get out...
520  if (counttotal == totalobjectssize2) {
521  break;
522  }
523  }
524  } // Closes loop in reco
525 
526  LogDebug("ExoticaValidation") << " deleting countobjects";
527  //delete countobjects;
528 
529  // Calling to the plotters analysis (where the evaluation of the different trigger paths are done)
530  //const std::string source = "reco";
531  for (std::vector<HLTExoticaPlotter>::iterator an = _plotters.begin(); an != _plotters.end(); ++an) {
532  const std::string hltPath = _shortpath2long[an->gethltpath()];
533  const bool ispassTrigger = cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
534  LogDebug("ExoticaValidation") << " preparing to call the plotters analysis";
535  an->analyze(ispassTrigger, "rec", matchesReco);
536  LogDebug("ExoticaValidation") << " called the plotter";
537  }
538  }
539 
540 }
541 
542 
543 // Return the objects (muons,electrons,photons,...) needed by a hlt path.
544 const std::vector<unsigned int> HLTExoticaSubAnalysis::getObjectsType(const std::string & hltPath) const
545 {
546  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getObjectsType()";
547 
548  static const unsigned int objSize = 6;
549  static const unsigned int objtriggernames[] = {
556  };
557 
558  std::set<unsigned int> objsType;
559  // The object to deal has to be entered via the config .py
560  for (unsigned int i = 0; i < objSize; ++i) {
561  //std::cout << "(5) Gonna call with " << objtriggernames[i] << std::endl;
562  std::string objTypeStr = EVTColContainer::getTypeString(objtriggernames[i]);
563  // Check if it is needed this object for this trigger
564  if (! TString(hltPath).Contains(objTypeStr)) {
565  continue;
566  }
567 
568  objsType.insert(objtriggernames[i]);
569  }
570 
571  return std::vector<unsigned int>(objsType.begin(), objsType.end());
572 }
573 
574 // Booking the maps: recLabels and genParticle selectors
576 {
577  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getNamesOfObjects()";
578 
579  if (anpset.exists("recMuonLabel")) {
580  _recLabels[EVTColContainer::MUON] = anpset.getParameter<edm::InputTag>("recMuonLabel");
582  }
583  if (anpset.exists("recElecLabel")) {
584  _recLabels[EVTColContainer::ELEC] = anpset.getParameter<edm::InputTag>("recElecLabel");
586  }
587  if (anpset.exists("recPhotonLabel")) {
588  _recLabels[EVTColContainer::PHOTON] = anpset.getParameter<edm::InputTag>("recPhotonLabel");
590  }
591  if (anpset.exists("recPFMETLabel")) {
592  _recLabels[EVTColContainer::PFMET] = anpset.getParameter<edm::InputTag>("recPFMETLabel");
594  }
595  if (anpset.exists("recPFTauLabel")) {
596  _recLabels[EVTColContainer::PFTAU] = anpset.getParameter<edm::InputTag>("recPFTauLabel");
598  }
599  if (anpset.exists("recJetLabel")) {
600  _recLabels[EVTColContainer::JET] = anpset.getParameter<edm::InputTag>("recJetLabel");
602  }
603 
604  if (_recLabels.size() < 1) {
605  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::getNamesOfObjects, "
606  << "Not included any object (recMuonLabel, recElecLabel, ...) "
607  << "in the analysis " << _analysisname;
608  return;
609  }
610 }
611 
612 // Register consumption of objects.
613 // I have chosen to centralize all consumes() calls here.
615 {
616  // Register that we are getting genParticles
618 
619  // Register that we are getting the trigger results
621  // Loop over _recLabels, see what we need, and register.
622  // Then save the registered token in _tokens.
623  // Remember: _recLabels is a map<uint, edm::InputTag>
624  // Remember: _tokens is a map<uint, edm::EDGetToken>
625  LogDebug("ExoticaValidation") << "We have got " << _recLabels.size() << "recLabels";
626  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin();
627  it != _recLabels.end(); ++it) {
628  if (it->first == EVTColContainer::MUON) {
629  edm::EDGetTokenT<reco::MuonCollection> particularToken = iC.consumes<reco::MuonCollection>(it->second);
630  edm::EDGetToken token(particularToken);
631  _tokens[it->first] = token;
632  }
633  else if (it->first == EVTColContainer::ELEC) {
635  edm::EDGetToken token(particularToken);
636  _tokens[it->first] = token;
637  }
638  else if (it->first == EVTColContainer::PHOTON) {
640  edm::EDGetToken token(particularToken);
641  _tokens[it->first] = token;
642  }
643  else if (it->first == EVTColContainer::PFMET) {
645  edm::EDGetToken token(particularToken);
646  _tokens[it->first] = token;
647  }
648  else if (it->first == EVTColContainer::PFTAU) {
650  edm::EDGetToken token(particularToken);
651  _tokens[it->first] = token;
652  }
653  else if (it->first == EVTColContainer::JET) {
655  edm::EDGetToken token(particularToken);
656  _tokens[it->first] = token;
657  }
658  else {
659  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::registerConsumes"
660  << " NOT IMPLEMENTED (yet) ERROR: '" << it->second.label() << "'";
661  }
662  }
663 
664 }
665 
666 // Setting the collections of objects in EVTColContainer
668 {
669  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getHandlesToObjects()";
670 
671  if (! col->isCommonInit()) {
672  // Extract the trigger results (path info, pass,...)
674  iEvent.getByToken(_trigResultsToken, trigResults);
675  if (trigResults.isValid()) {
676  col->triggerResults = trigResults.product();
677  LogDebug("ExoticaValidation") << "Added handle to triggerResults";
678  }
679 
680  // Extract the genParticles
682  iEvent.getByToken(_genParticleToken, genPart);
683  if (genPart.isValid()) {
684  col->genParticles = genPart.product();
685  LogDebug("ExoticaValidation") << "Added handle to genParticles";
686  }
687  }
688 
689  // Loop over the tokens and extract all other objects
690  LogDebug("ExoticaValidation") << "We have got " << _tokens.size() << "tokens";
691  for (std::map<unsigned int, edm::EDGetToken>::iterator it = _tokens.begin();
692  it != _tokens.end(); ++it) {
693  if (it->first == EVTColContainer::MUON) {
695  iEvent.getByToken(it->second, theHandle);
696  col->set(theHandle.product());
697  }
698  else if (it->first == EVTColContainer::ELEC) {
700  iEvent.getByToken(it->second, theHandle);
701  col->set(theHandle.product());
702  }
703  else if (it->first == EVTColContainer::PHOTON) {
705  iEvent.getByToken(it->second, theHandle);
706  col->set(theHandle.product());
707  }
708  else if (it->first == EVTColContainer::PFMET) {
710  iEvent.getByToken(it->second, theHandle);
711  col->set(theHandle.product());
712  }
713  else if (it->first == EVTColContainer::PFTAU) {
715  iEvent.getByToken(it->second, theHandle);
716  col->set(theHandle.product());
717  }
718  else if (it->first == EVTColContainer::JET) {
720  iEvent.getByToken(it->second, theHandle);
721  col->set(theHandle.product());
722  }
723  else {
724  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::getHandlesToObjects "
725  << " NOT IMPLEMENTED (yet) ERROR: '" << it->first << "'";
726  }
727  }
728 }
729 
730 // Booking the histograms, and putting them in DQM
732  const std::string & source,
733  const std::string & objType,
734  const std::string & variable)
735 {
736  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::bookHist()";
737  std::string sourceUpper = source;
738  sourceUpper[0] = std::toupper(sourceUpper[0]);
739  std::string name = source + objType + variable ;
740  TH1F * h = 0;
741 
742  if (variable.find("SumEt") != std::string::npos) {
743  std::string title = "Sum ET of " + sourceUpper + " " + objType;
744  const size_t nBins = _parametersTurnOn.size() - 1;
745  float * edges = new float[nBins + 1];
746  for (size_t i = 0; i < nBins + 1; i++) {
747  edges[i] = _parametersTurnOn[i];
748  }
749  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
750  delete[] edges;
751  }
752  else if (variable.find("MaxPt") != std::string::npos) {
753  std::string desc = (variable == "MaxPt1") ? "Leading" : "Next-to-Leading";
754  std::string title = "pT of " + desc + " " + sourceUpper + " " + objType;
755  const size_t nBins = _parametersTurnOn.size() - 1;
756  float * edges = new float[nBins + 1];
757  for (size_t i = 0; i < nBins + 1; i++) {
758  edges[i] = _parametersTurnOn[i];
759  }
760  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
761  delete[] edges;
762  } else {
763  std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
764  std::string title = symbol + " of " + sourceUpper + " " + objType;
765  std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
766  int nBins = (int)params[0];
767  double min = params[1];
768  double max = params[2];
769  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
770  }
771 
772  h->Sumw2();
773  // This is the trick, that takes a normal TH1F and puts it in in the DQM
774  // machinery. Seems to be easy!
775  // Updated to use the new iBooker machinery.
776  _elements[name] = iBooker.book1D(name, h);
777  delete h;
778 }
779 
780 // Fill the histograms
782  const std::string & objType,
783  const std::string & variable,
784  const float & value)
785 {
786  std::string sourceUpper = source;
787  sourceUpper[0] = toupper(sourceUpper[0]);
788  std::string name = source + objType + variable ;
789 
790  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::fillHist() " << name << " " << value;
791  _elements[name]->Fill(value);
792  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::fillHist() " << name << " worked";
793 }
794 
795 // Initialize the selectors
796 void HLTExoticaSubAnalysis::initSelector(const unsigned int & objtype)
797 {
798 
799  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::initSelector()";
800 
801  if (objtype == EVTColContainer::MUON && _recMuonSelector == 0) {
803  } else if (objtype == EVTColContainer::ELEC && _recElecSelector == 0) {
805  } else if (objtype == EVTColContainer::PHOTON && _recPhotonSelector == 0) {
807  } else if (objtype == EVTColContainer::PFMET && _recPFMETSelector == 0) {
809  } else if (objtype == EVTColContainer::PFTAU && _recPFTauSelector == 0) {
811  } else if (objtype == EVTColContainer::JET && _recJetSelector == 0) {
813  }
814  /* else
815  {
816  FIXME: ERROR NOT IMPLEMENTED
817  }*/
818 }
819 
820 // Insert the HLT candidates
821 void HLTExoticaSubAnalysis::insertCandidates(const unsigned int & objType, const EVTColContainer * cols, std::vector<reco::LeafCandidate> * matches)
822 {
823 
824  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::insertCandidates()";
825 
826  if (objType == EVTColContainer::MUON) {
827  for (size_t i = 0; i < cols->muons->size(); i++) {
828  LogDebug("ExoticaValidation") << "Inserting muon " << i ;
829  if (_recMuonSelector->operator()(cols->muons->at(i))) {
830  reco::LeafCandidate m(0, cols->muons->at(i).p4(), cols->muons->at(i).vertex(), objType, 0, true);
831  matches->push_back(m);
832  }
833  }
834  } else if (objType == EVTColContainer::ELEC) {
835  for (size_t i = 0; i < cols->electrons->size(); i++) {
836  LogDebug("ExoticaValidation") << "Inserting electron " << i ;
837  if (_recElecSelector->operator()(cols->electrons->at(i))) {
838  reco::LeafCandidate m(0, cols->electrons->at(i).p4(), cols->electrons->at(i).vertex(), objType, 0, true);
839  matches->push_back(m);
840  }
841  }
842  } else if (objType == EVTColContainer::PHOTON) {
843  for (size_t i = 0; i < cols->photons->size(); i++) {
844  LogDebug("ExoticaValidation") << "Inserting photon " << i ;
845  if (_recPhotonSelector->operator()(cols->photons->at(i))) {
846  reco::LeafCandidate m(0, cols->photons->at(i).p4(), cols->photons->at(i).vertex(), objType, 0, true);
847  matches->push_back(m);
848  }
849  }
850  } else if (objType == EVTColContainer::PFMET) {
854  for (size_t i = 0; i < cols->pfMETs->size(); i++) {
855  LogDebug("ExoticaValidation") << "Inserting PFMET " << i ;
856  if (_recPFMETSelector->operator()(cols->pfMETs->at(i))) {
857  reco::LeafCandidate m(0, cols->pfMETs->at(i).p4(), cols->pfMETs->at(i).vertex(), objType, 0, true);
858  matches->push_back(m);
859  }
860  }
861  } else if (objType == EVTColContainer::PFTAU) {
862  for (size_t i = 0; i < cols->pfTaus->size(); i++) {
863  LogDebug("ExoticaValidation") << "Inserting PFtau " << i ;
864  if (_recPFTauSelector->operator()(cols->pfTaus->at(i))) {
865  reco::LeafCandidate m(0, cols->pfTaus->at(i).p4(), cols->pfTaus->at(i).vertex(), objType, 0, true);
866  matches->push_back(m);
867  }
868  }
869  } else if (objType == EVTColContainer::JET) {
870  for (size_t i = 0; i < cols->jets->size(); i++) {
871  LogDebug("ExoticaValidation") << "Inserting jet " << i ;
872  if (_recJetSelector->operator()(cols->jets->at(i))) {
873  reco::LeafCandidate m(0, cols->jets->at(i).p4(), cols->jets->at(i).vertex(), objType, 0, true);
874  matches->push_back(m);
875  }
876  }
877  }
878 
879  /* else
880  {
881  FIXME: ERROR NOT IMPLEMENTED
882  }*/
883 }
#define LogDebug(id)
const std::vector< reco::Muon > * muons
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
unsigned int _minCandidates
The minimum number of reco/gen candidates needed by the analysis.
Entry const & retrieve(char const *) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:204
void getNamesOfObjects(const edm::ParameterSet &anpset)
Creates the maps that map which collection should come from which label.
std::vector< PFTau > PFTauCollection
collection of PFTau objects
Definition: PFTauFwd.h:9
const std::vector< reco::PFJet > * jets
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::map< unsigned int, std::string > _genCut
gen/rec objects cuts
bool accept() const
Has at least one path accepted the event?
const std::vector< std::string > & triggerNames() const
names of trigger paths
std::vector< HLTExoticaPlotter > _plotters
The plotters: managers of each hlt path where the plots are done.
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< double > _parametersPhi
void insert(bool ok_to_replace, char const *, Entry const &)
void fillHist(const std::string &source, const std::string &objType, const std::string &variable, const float &value)
const reco::GenParticleCollection * genParticles
container with all the objects needed
Strings::size_type size() const
Definition: TriggerNames.cc:39
void analyze(const edm::Event &iEvent, const edm::EventSetup &iEventSetup, EVTColContainer *cols)
T eta() const
edm::EDGetTokenT< edm::TriggerResults > _trigResultsToken
dictionary edges
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
const std::vector< reco::PFTau > * pfTaus
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::map< unsigned int, edm::InputTag > _recLabels
StringCutObjectSelector< reco::GsfElectron > * _recElecSelector
void set(const reco::MuonCollection *v)
Setter: multiple overloaded function.
int iEvent
Definition: GenABIO.cc:230
StringCutObjectSelector< reco::Muon > * _recMuonSelector
tuple path
else: Piece not in the list, fine.
edm::ParameterSet _pset
Internal, working copy of the PSet passed from above.
void subAnalysisBookHistos(DQMStore::IBooker &iBooker, const edm::Run &iRun, const edm::EventSetup &iSetup)
std::vector< double > _parametersEta
Some kinematical parameters.
std::map< unsigned int, std::string > _recCut
const std::vector< unsigned int > getObjectsType(const std::string &hltpath) const
closes analyze method
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:113
int j
Definition: DBlmapReader.cc:9
HLTConfigProvider _hltConfig
Interface to the HLT information.
const std::vector< reco::Photon > * photons
virtual const Point & vertex() const =0
vertex position
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
~HLTExoticaSubAnalysis()
End Constructor.
T min(T a, T b)
Definition: MathUtil.h:58
bool isValid() const
Definition: HandleBase.h:76
std::vector< std::string > _hltPathsToCheck
The hlt paths to check for.
#define LogTrace(id)
std::string _hltProcessName
The labels of the object collections to be used in this analysis.
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:74
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
void registerConsumes(edm::ConsumesCollector &consCollector)
Registers consumption of objects.
void getHandlesToObjects(const edm::Event &iEvent, EVTColContainer *col)
Gets the collections themselves.
StringCutObjectSelector< reco::PFMET > * _recPFMETSelector
std::string _analysisname
The name of this sub-analysis.
StringCutObjectSelector< reco::Photon > * _recPhotonSelector
std::map< unsigned int, StringCutObjectSelector< reco::GenParticle > * > _genSelectorMap
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
void beginRun(const edm::Run &iRun, const edm::EventSetup &iEventSetup)
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
T const * product() const
Definition: Handle.h:81
const std::vector< reco::GsfElectron > * electrons
std::vector< double > _parametersTurnOn
std::map< unsigned int, edm::EDGetToken > _tokens
std::map< std::string, MonitorElement * > _elements
Structure of the MonitorElements.
std::vector< PFJet > PFJetCollection
collection of PFJet objects
HLTExoticaSubAnalysis(const edm::ParameterSet &pset, const std::string &analysisname, edm::ConsumesCollector &&consCollector)
Constructor.
std::vector< reco::PFMET > PFMETCollection
collection of PFMET objects
StringCutObjectSelector< reco::PFJet > * _recJetSelector
edm::EDGetTokenT< reco::GenParticleCollection > _genParticleToken
And also the tokens to get the object collections.
void initSelector(const unsigned int &objtype)
Initializes the selectors of the objects based on which object it is.
int col
Definition: cuy.py:1008
std::set< std::string > _hltPaths
The hlt paths found in the hltConfig.
const std::vector< reco::PFMET > * pfMETs
static const std::string getTypeString(const unsigned int &objtype)
Tranform types into strings.
void insertCandidates(const unsigned int &objtype, const EVTColContainer *col, std::vector< reco::LeafCandidate > *matches)
const edm::TriggerResults * triggerResults
static std::string const source
Definition: EdmProvDump.cc:43
StringCutObjectSelector< reco::PFTau > * _recPFTauSelector
void bookHist(DQMStore::IBooker &iBooker, const std::string &source, const std::string &objType, const std::string &variable)
The internal functions to book and fill histograms.
Definition: Run.h:41
std::map< std::string, std::string > _shortpath2long
Relation between the short and long versions of the path.
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
Definition: DDAxes.h:10