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 
25 int verbose=0;
26 
29  const std::string & analysisname,
30  edm::ConsumesCollector && consCollector) :
31  _pset(pset),
32  _analysisname(analysisname),
33  _minCandidates(0),
34  _hltProcessName(pset.getParameter<std::string>("hltProcessName")),
35  _genParticleLabel(pset.getParameter<std::string>("genParticleLabel")),
36  _trigResultsLabel("TriggerResults", "", _hltProcessName),
37  _parametersEta(pset.getParameter<std::vector<double> >("parametersEta")),
38  _parametersPhi(pset.getParameter<std::vector<double> >("parametersPhi")),
39  _parametersTurnOn(pset.getParameter<std::vector<double> >("parametersTurnOn")),
40  _recMuonSelector(0),
41  _recMuonTrkSelector(0),
42  _recElecSelector(0),
43  _recPFMETSelector(0),
44  _recPFTauSelector(0),
45  _recPhotonSelector(0),
46  _recPFJetSelector(0),
47  _recCaloJetSelector(0)
48 {
49 
50  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::constructor()";
51 
52  // Specific parameters for this analysis
53  edm::ParameterSet anpset = pset.getParameter<edm::ParameterSet>(analysisname);
54 
55  // If this analysis has a particular set of binnings, use it.
56  // (Taken from the analysis-specific parameter set, of course)
57  // The "true" in the beginning of _pset.insert() means
58  // "overwrite the parameter if need be".
59  if (anpset.exists("parametersTurnOn")) {
60  _parametersTurnOn = anpset.getParameter<std::vector<double> >("parametersTurnOn");
61  _pset.insert(true, "parametersTurnOn", anpset.retrieve("parametersTurnOn"));
62  }
63  if (anpset.exists("parametersEta")) {
64  _parametersEta = anpset.getParameter<std::vector<double> >("parametersEta");
65  _pset.insert(true, "parametersEta", anpset.retrieve("parametersEta"));
66  }
67  if (anpset.exists("parametersPhi")) {
68  _parametersPhi = anpset.getParameter<std::vector<double> >("parametersPhi");
69  _pset.insert(true, "parametersPhi", anpset.retrieve("parametersPhi"));
70  }
71 
72  // Get names of objects that we may want to get from the event.
73  // Notice that genParticles are dealt with separately.
74  this->getNamesOfObjects(anpset);
75 
76  // Since now we have the names, we should register the consumption
77  // of objects.
78  this->registerConsumes(consCollector);
79 
80  // Generic objects: Initialization of basic phase space cuts.
81  for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin();
82  it != _recLabels.end(); ++it) {
83  const std::string objStr = EVTColContainer::getTypeString(it->first);
84  _genCut[it->first] = pset.getParameter<std::string>(std::string(objStr + "_genCut").c_str());
85  _recCut[it->first] = pset.getParameter<std::string>(std::string(objStr + "_recCut").c_str());
86  if (pset.exists(std::string(objStr + "_genCut_leading"))) {
87  _genCut_leading[it->first] = pset.getParameter<std::string>(std::string(objStr + "_genCut_leading").c_str());
88  }
89  if (pset.exists(std::string(objStr + "_recCut_leading"))) {
90  _recCut_leading[it->first] = pset.getParameter<std::string>(std::string(objStr + "_recCut_leading").c_str());
91  }
92  }
93 
94  //--- Updating parameters if has to be modified for this particular specific analysis
95  for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin();
96  it != _recLabels.end(); ++it) {
97  const std::string objStr = EVTColContainer::getTypeString(it->first);
98 
99  try {
100  _genCut[it->first] = anpset.getUntrackedParameter<std::string>(std::string(objStr + "_genCut").c_str());
101  } catch (edm::Exception) {}
102 
103  try {
104  _recCut[it->first] = anpset.getUntrackedParameter<std::string>(std::string(objStr + "_recCut").c_str());
105  } catch (edm::Exception) {}
106 
107  }
108 
110  _hltPathsToCheck = anpset.getParameter<std::vector<std::string> >("hltPathsToCheck");
112  _minCandidates = anpset.getParameter<unsigned int>("minCandidates");
113 
114 }
115 
117 {
118  for (std::map<unsigned int, StringCutObjectSelector<reco::GenParticle>* >::iterator it = _genSelectorMap.begin();
119  it != _genSelectorMap.end(); ++it) {
120  delete it->second;
121  it->second = 0;
122  }
123  delete _recMuonSelector;
124  _recMuonSelector = 0;
125  delete _recMuonTrkSelector;
127  delete _recElecSelector;
128  _recElecSelector = 0;
129  delete _recPhotonSelector;
130  _recPhotonSelector = 0;
131  delete _recPFMETSelector;
132  _recPFMETSelector = 0;
133  delete _recPFTauSelector;
134  _recPFTauSelector = 0;
135  delete _recPFJetSelector;
136  _recPFJetSelector = 0;
137  delete _recCaloJetSelector;
139 }
140 
141 
143 {
144 }
145 
146 
147 // 2014-02-03 -- Thiago
148 // Due to the fact that the DQM has to be thread safe now, we have to do things differently:
149 // 1) Implement the bookHistograms() method in the container class
150 // 2) Make the iBooker from above be known to this class
151 // 3) Separate all booking histograms routines in this and any auxiliary classe to be called
152 // from bookHistograms() in the container class
154  const edm::Run & iRun,
155  const edm::EventSetup & iSetup)
156 {
157 
158  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::subAnalysisBookHistos()";
159 
160  // Create the folder structure inside HLT/Exotica
161  std::string baseDir = "HLT/Exotica/" + _analysisname + "/";
162  iBooker.setCurrentFolder(baseDir);
163 
164  // Book the gen/reco analysis-dependent histograms (denominators)
165  for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin();
166  it != _recLabels.end(); ++it) {
167  const std::string objStr = EVTColContainer::getTypeString(it->first);
168  std::vector<std::string> sources(2);
169  sources[0] = "gen";
170  sources[1] = "rec";
171 
172  for (size_t i = 0; i < sources.size(); i++) {
173  std::string source = sources[i];
174  bookHist(iBooker, source, objStr, "Eta");
175  bookHist(iBooker, source, objStr, "Phi");
176  bookHist(iBooker, source, objStr, "MaxPt1");
177  bookHist(iBooker, source, objStr, "MaxPt2");
178  bookHist(iBooker, source, objStr, "SumEt");
179  }
180  } // closes loop in _recLabels
181 
182  // Call the plotterBookHistos() (which books all the path dependent histograms)
183  LogDebug("ExoticaValidation") << " number of plotters = " << _plotters.size();
184  for (std::vector<HLTExoticaPlotter>::iterator it = _plotters.begin();
185  it != _plotters.end(); ++it) {
186  it->plotterBookHistos(iBooker, iRun, iSetup);
187  }
188 }
189 
190 void HLTExoticaSubAnalysis::beginRun(const edm::Run & iRun, const edm::EventSetup & iSetup)
191 {
192 
193  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::beginRun()";
194 
197 
198  // Initialize the HLT config.
199  bool changedConfig(true);
200  if (!_hltConfig.init(iRun, iSetup, _hltProcessName, changedConfig)) {
201  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::constructor(): "
202  << "Initialization of HLTConfigProvider failed!";
203  }
204 
205  // Parse the input paths to get them if they are in the table and associate
206  // them to the last filter of the path (in order to extract the objects).
207  _hltPaths.clear();
208  for (size_t i = 0; i < _hltPathsToCheck.size(); ++i) {
209  bool found = false;
210  TPRegexp pattern(_hltPathsToCheck[i]);
211 
212  // Loop over triggerNames from _hltConfig
213  for (size_t j = 0 ; j < _hltConfig.triggerNames().size(); ++j) {
214  std::string thetriggername = _hltConfig.triggerNames()[j];
215  if (TString(thetriggername).Contains(pattern)) {
216  _hltPaths.insert(thetriggername);
217  found = true;
218  }
219  if(verbose>2 && i==0)
220  std::cout << "--- TRIGGER PATH : " << thetriggername << std::endl;
221  }
222 
223  // Oh dear, the path we wanted seems to not be available
224  if (! found && verbose>2) {
225  edm::LogWarning("ExoticaValidation") << "HLTExoticaSubAnalysis::constructor(): In "
226  << _analysisname << " subfolder NOT found the path: '"
227  << _hltPathsToCheck[i] << "*'" ;
228  }
229  } // Close loop over paths to check.
230 
231  // At this point, _hltpaths contains the names of the paths to check
232  // that were found. Let's log it at trace level.
233  LogTrace("ExoticaValidation") << "SubAnalysis: " << _analysisname
234  << "\nHLT Trigger Paths found >>>";
235  for (std::set<std::string>::const_iterator iter = _hltPaths.begin();
236  iter != _hltPaths.end(); ++iter) {
237  LogTrace("ExoticaValidation") << (*iter) << "\n";
238  }
239 
240  // Initialize the plotters (analysers for each trigger path)
241  _plotters.clear();
242  for (std::set<std::string>::iterator iPath = _hltPaths.begin();
243  iPath != _hltPaths.end(); ++iPath) {
244  // Avoiding the dependence of the version number for the trigger paths
245  std::string path = * iPath;
246  std::string shortpath = path;
247  if (path.rfind("_v") < path.length()) {
248  shortpath = path.substr(0, path.rfind("_v"));
249  }
250  _shortpath2long[shortpath] = path;
251 
252  // Objects needed by the HLT path
253  // Thiago: instead of trying to decode the objects from the path,
254  // put the burden on the user to tell us which objects are needed.
255  //const std::vector<unsigned int> objsNeedHLT = this->getObjectsType(shortpath);
256  std::vector<unsigned int> objsNeedHLT;
257  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin() ;
258  it != _recLabels.end(); ++it) {
259  objsNeedHLT.push_back(it->first);
260  }
261 
262  /*std::vector<unsigned int> userInstantiate;
263  // Sanity check: the object needed by a trigger path should be
264  // introduced by the user via config python (_recLabels datamember)
265  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin() ;
266  it != _recLabels.end(); ++it) {
267  userInstantiate.push_back(it->first);
268  }
269  for (std::vector<unsigned int>::const_iterator it = objsNeedHLT.begin(); it != objsNeedHLT.end();
270  ++it) {
271  if (std::find(userInstantiate.begin(), userInstantiate.end(), *it) ==
272  userInstantiate.end()) {
273  edm::LogError("ExoticaValidation") << "In HLTExoticaSubAnalysis::beginRun, "
274  << "Incoherence found in the python configuration file!!\nThe SubAnalysis '"
275  << _analysisname << "' has been asked to evaluate the trigger path '"
276  << shortpath << "' (found it in 'hltPathsToCheck') BUT this path"
277  << " needs a '" << EVTColContainer::getTypeString(*it)
278  << "' which has not been instantiated ('recVariableLabels'"
279  << ")" ;
280  exit(-1); // This should probably throw an exception...
281  }
282  }
283  */
284  LogTrace("ExoticaValidation") << " --- " << shortpath;
285 
286  // The hlt path, the objects (electrons, muons, photons, ...)
287  // needed to evaluate the path are the argumens of the plotter
288  HLTExoticaPlotter analyzer(_pset, shortpath, objsNeedHLT);
289  _plotters.push_back(analyzer);
290  }// Okay, at this point we have prepared all the plotters.
291 
292 }
293 
294 
296 {
297  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::analyze()";
298 
299  // Loop over _recLabels to make sure everything is alright.
300  /*
301  std::cout << "Now printing the _recLabels" << std::endl;
302  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin();
303  it != _recLabels.end(); ++it) {
304  std::cout << "Number: " << it->first << "\t" << "Label: " << it->second.label() << std::endl;
305  }
306  */
307 
308  // Initialize the collection (the ones which have not been initialiazed yet)
309  //std::cout << "Setting handles to objects..." << std::endl;
310  this->getHandlesToObjects(iEvent, cols);
311 
312  // Utility map, mapping kinds of objects (GEN, RECO) to strings ("gen","rec")
313  //std::map<Level, std::string> u2str;
314  //u2str[Level::GEN] = "gen";
315  //u2str[Level::RECO] = "rec";
316 
317  // Extract the match structure containing the gen/reco candidates (electron, muons,...). This part is common to all the SubAnalyses
318 
319  //std::map<unsigned int, std::vector<MatchStruct> > sourceMatchMap;
320  //std::vector<MatchStruct> matchesGen; matchesGen.clear();
321  std::vector<reco::LeafCandidate> matchesGen; matchesGen.clear();
322  //std::vector<MatchStruct> matchesReco; matchesReco.clear();
323  std::vector<reco::LeafCandidate> matchesReco; matchesReco.clear();
324  //sourceMatchMap[98] = matchesGen;
325  //sourceMatchMap[99] = matchesReco;
326 
327  //std::cout << "In the beginning: matchesGen.size() = " << matchesGen.size() << std::endl;
328  //std::cout << "In the beginning: matchesReco.size() = " << matchesReco.size() << std::endl;
329 
330  // --- deal with GEN objects first.
331  // Make each good GEN object into the base cand for a MatchStruct
332  // Our definition of "good" is "passes the selector" defined in the config.py
333  // Save all the MatchStructs in the "matchesGen" vector.
334 
335  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin();
336  it != _recLabels.end(); ++it) {
337  // Here we are filling the vector of StringCutObjectSelector<reco::GenParticle>
338  // with objects constructed from the strings saved in _genCut.
339  // Initialize selectors when first event
340 
341  //std::cout << "Loop over the kinds of objects: objects of kind " << it->first << std::endl;
342 
343  if (!_genSelectorMap[it->first]) {
345  }
346 
347  // Now loop over the genParticles, and apply the operator() over each of them.
348  // Fancy syntax: for objects X and Y, X.operator()(Y) is the same as X(Y).
349  for (size_t i = 0; i < cols->genParticles->size(); ++i) {
350  //std::cout << "Now matchesGen.size() is " << matchesGen.size() << std::endl;
351  if (_genSelectorMap[it->first]->operator()(cols->genParticles->at(i))) {
352  const reco::Candidate* cand = &(cols->genParticles->at(i));
353  //std::cout << "Found good cand: cand->pt() = " << cand->pt() << std::endl;
354  //matchesGen.push_back(MatchStruct(cand, it->first));
357  reco::LeafCandidate v(0,cand->p4(),cand->vertex(),it->first,0,true);
358  matchesGen.push_back(v);
359  }
360  }
361  }
362 
363  // Sort the matches by pT for later filling of turn-on curve
364  //std::cout << "Before sorting: matchesGen.size() = " << matchesGen.size() << std::endl;
366  std::sort(matchesGen.begin(),
367  matchesGen.end(),
368  comparator);
369  //std::cout << "After sorting: matchesGen.size() = " << matchesGen.size() << std::endl;
370 
371  //std::cout << "Before adding RECO: sourceMatchMap[98].size() = " << sourceMatchMap[98].size() << std::endl;
372  //std::cout << "Before adding RECO: matchesGen.size() = " << matchesGen.size() << std::endl;
373 
374  // --- same for RECO objects
375  // Extraction of the objects candidates
376  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin();
377  it != _recLabels.end(); ++it) {
378  //std::cout << "Filling RECO \"matchesReco\" vector for particle kind it->first = "
379  // << it->first << ", which means " << it->second.label() << std::endl;
380  // Reco selectors (the function takes into account if it was instantiated
381  // before or not) ### Thiago ---> Then why don't we put it in the beginRun???
382  this->initSelector(it->first);
383  // -- Storing the matchesReco
384  this->insertCandidates(it->first, cols, &matchesReco);
385  }
386 
387  //std::cout << "After adding RECO: matchesGen.size() = " << matchesGen.size() << std::endl;
388  //std::cout << "After adding RECO: matchesReco.size() = " << matchesReco.size() << std::endl;
389 
390  std::sort(matchesReco.begin(),
391  matchesReco.end(),
392  comparator);
393 
394 
395  // --- All the objects are in place
396  //std::cout << "DEBUG(0)" << std::endl;
397 
398  // -- Trigger Results
399  const edm::TriggerNames trigNames = iEvent.triggerNames(*(cols->triggerResults));
400 
403 
404  //for (std::map<unsigned int, std::vector<MatchStruct> >::iterator it = sourceMatchMap.begin(); it != sourceMatchMap.end(); ++it) {
405  // it->first: gen/reco it->second: HLT matches (std::vector<MatchStruct>)
406 
407  //if (it->second.size() < _minCandidates) { // FIXME: A bug is potentially here: what about the mixed channels?
408  //continue;
409  //}
410 
414  {
415  if(matchesGen.size() < _minCandidates) return; // FIXME: A bug is potentially here: what about the mixed channels?
416  // Okay, there are enough candidates. Move on!
417 
418  // Filling the gen/reco objects (eff-denominators):
419  // Just the first two different ones, if there are more
420  // The countobjects maps uints (object types, really) --> integers.
421  // Example:
422  // | uint | int |
423  // | 0 | 1 | --> 1 muon used
424  // | 1 | 2 | --> 2 electrons used
425  // Initializing the count of the used objects.
426  std::map<unsigned int, int> countobjects;
427  for (std::map<unsigned int, edm::InputTag>::iterator co = _recLabels.begin();
428  co != _recLabels.end(); ++co) {
429  countobjects.insert(std::pair<unsigned int, int>(co->first, 0));
430  }
431 
432  int counttotal = 0;
433  int totalobjectssize2 = 2 * countobjects.size();
434 
435  for (size_t j = 0; j != matchesGen.size(); ++j) {
436  const unsigned int objType = matchesGen[j].pdgId();
437  //std::cout << "(4) Gonna call with " << objType << std::endl;
438  const std::string objTypeStr = EVTColContainer::getTypeString(objType);
439 
440  float pt = matchesGen[j].pt();
441 
442  if (countobjects[objType] == 0) {
443 
444  // Cut for the pt-leading object
446  if ( !select( matchesGen[j] ) ) break;
447 
448  this->fillHist("gen", objTypeStr, "MaxPt1", pt);
449  // Filled the high pt ...
450  ++countobjects[objType];
451  ++counttotal;
452  } else if (countobjects[objType] == 1) {
453  this->fillHist("gen", objTypeStr, "MaxPt2", pt);
454  // Filled the second high pt ...
455  ++countobjects[objType];
456  ++counttotal;
457  } else {
458  // Already the minimum two objects has been filled, get out...
459  if (counttotal == totalobjectssize2) {
460  break;
461  }
462  }
463 
464  float eta = matchesGen[j].eta();
465  float phi = matchesGen[j].phi();
466  float sumEt = 0;//matchesGen[j].sumEt;
467 
468  this->fillHist("gen", objTypeStr, "Eta", eta);
469  this->fillHist("gen", objTypeStr, "Phi", phi);
470  this->fillHist("gen", objTypeStr, "SumEt", sumEt);
471 
472  } // Closes loop in gen
473 
474  // Calling to the plotters analysis (where the evaluation of the different trigger paths are done)
475  //const std::string source = "gen";
476  for (std::vector<HLTExoticaPlotter>::iterator an = _plotters.begin(); an != _plotters.end(); ++an) {
477  const std::string hltPath = _shortpath2long[an->gethltpath()];
478  const bool ispassTrigger = cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
479  LogDebug("ExoticaValidation") << " preparing to call the plotters analysis";
480  an->analyze(ispassTrigger, "gen", matchesGen);
481  LogDebug("ExoticaValidation") << " called the plotter";
482  }
483  }
484 
485 
489  {
490  if(matchesReco.size() < _minCandidates) return; // FIXME: A bug is potentially here: what about the mixed channels?
491 
492  // Okay, there are enough candidates. Move on!
493 
494  // Filling the gen/reco objects (eff-denominators):
495  // Just the first two different ones, if there are more
496  // The countobjects maps uints (object types, really) --> integers.
497  // Example:
498  // | uint | int |
499  // | 0 | 1 | --> 1 muon used
500  // | 1 | 2 | --> 2 electrons used
501  // Initializing the count of the used objects.
502  std::map<unsigned int, int> countobjects;
503  for (std::map<unsigned int, edm::InputTag>::iterator co = _recLabels.begin();
504  co != _recLabels.end(); ++co) {
505  countobjects.insert(std::pair<unsigned int, int>(co->first, 0));
506  }
507 
508  int counttotal = 0;
509  int totalobjectssize2 = 2 * countobjects.size();
510 
512  //std::cout << "Our RECO vector has matchesReco.size() = " << matchesReco.size() << std::endl;
513 
514  for (size_t j = 0; j != matchesReco.size(); ++j) {
515  const unsigned int objType = matchesReco[j].pdgId();
516  //std::cout << "(4) Gonna call with " << objType << std::endl;
517  const std::string objTypeStr = EVTColContainer::getTypeString(objType);
518 
519  float pt = matchesReco[j].pt();
520 
521  if (countobjects[objType] == 0) {
522 
523  // Cut for the pt-leading object
525  if ( !select( matchesReco[j] ) ) break;
526 
527  this->fillHist("rec", objTypeStr, "MaxPt1", pt);
528  // Filled the high pt ...
529  ++countobjects[objType];
530  ++counttotal;
531  } else if (countobjects[objType] == 1) {
532  this->fillHist("rec", objTypeStr, "MaxPt2", pt);
533  // Filled the second high pt ...
534  ++countobjects[objType];
535  ++counttotal;
536  } else {
537  // Already the minimum two objects has been filled, get out...
538  if (counttotal == totalobjectssize2) {
539  break;
540  }
541  }
542 
543  float eta = matchesReco[j].eta();
544  float phi = matchesReco[j].phi();
545  float sumEt = 0;//matchesReco[j].sumEt;
546 
547  this->fillHist("rec", objTypeStr, "Eta", eta);
548  this->fillHist("rec", objTypeStr, "Phi", phi);
549  this->fillHist("rec", objTypeStr, "SumEt", sumEt);
550  } // Closes loop in reco
551 
552  // Calling to the plotters analysis (where the evaluation of the different trigger paths are done)
553  //const std::string source = "reco";
554  for (std::vector<HLTExoticaPlotter>::iterator an = _plotters.begin(); an != _plotters.end(); ++an) {
555  const std::string hltPath = _shortpath2long[an->gethltpath()];
556  const bool ispassTrigger = cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
557  LogDebug("ExoticaValidation") << " preparing to call the plotters analysis";
558  an->analyze(ispassTrigger, "rec", matchesReco);
559  LogDebug("ExoticaValidation") << " called the plotter";
560  }
561  }
562 
563 }
564 
565 
566 // Return the objects (muons,electrons,photons,...) needed by a hlt path.
567 const std::vector<unsigned int> HLTExoticaSubAnalysis::getObjectsType(const std::string & hltPath) const
568 {
569  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getObjectsType()";
570 
571  static const unsigned int objSize = 7;
572  static const unsigned int objtriggernames[] = {
581  };
582 
583  std::set<unsigned int> objsType;
584  // The object to deal has to be entered via the config .py
585  for (unsigned int i = 0; i < objSize; ++i) {
586  //std::cout << "(5) Gonna call with " << objtriggernames[i] << std::endl;
587  std::string objTypeStr = EVTColContainer::getTypeString(objtriggernames[i]);
588  // Check if it is needed this object for this trigger
589  if (! TString(hltPath).Contains(objTypeStr)) {
590  continue;
591  }
592 
593  objsType.insert(objtriggernames[i]);
594  }
595 
596  return std::vector<unsigned int>(objsType.begin(), objsType.end());
597 }
598 
599 // Booking the maps: recLabels and genParticle selectors
601 {
602  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getNamesOfObjects()";
603 
604  if (anpset.exists("recMuonLabel")) {
605  _recLabels[EVTColContainer::MUON] = anpset.getParameter<edm::InputTag>("recMuonLabel");
607  }
608  if (anpset.exists("recMuonTrkLabel")) {
609  _recLabels[EVTColContainer::MUONTRACK] = anpset.getParameter<edm::InputTag>("recMuonTrkLabel");
611  }
612  if (anpset.exists("recElecLabel")) {
613  _recLabels[EVTColContainer::ELEC] = anpset.getParameter<edm::InputTag>("recElecLabel");
615  }
616  if (anpset.exists("recPhotonLabel")) {
617  _recLabels[EVTColContainer::PHOTON] = anpset.getParameter<edm::InputTag>("recPhotonLabel");
619  }
620  if (anpset.exists("recPFMETLabel")) {
621  _recLabels[EVTColContainer::PFMET] = anpset.getParameter<edm::InputTag>("recPFMETLabel");
623  }
624  if (anpset.exists("recPFTauLabel")) {
625  _recLabels[EVTColContainer::PFTAU] = anpset.getParameter<edm::InputTag>("recPFTauLabel");
627  }
628  if (anpset.exists("recPFJetLabel")) {
629  _recLabels[EVTColContainer::PFJET] = anpset.getParameter<edm::InputTag>("recPFJetLabel");
631  }
632  if (anpset.exists("recCaloJetLabel")) {
633  _recLabels[EVTColContainer::CALOJET] = anpset.getParameter<edm::InputTag>("recCaloJetLabel");
635  }
636 
637  if (_recLabels.size() < 1) {
638  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::getNamesOfObjects, "
639  << "Not included any object (recMuonLabel, recElecLabel, ...) "
640  << "in the analysis " << _analysisname;
641  return;
642  }
643 }
644 
645 // Register consumption of objects.
646 // I have chosen to centralize all consumes() calls here.
648 {
649  // Register that we are getting genParticles
651 
652  // Register that we are getting the trigger results
654  // Loop over _recLabels, see what we need, and register.
655  // Then save the registered token in _tokens.
656  // Remember: _recLabels is a map<uint, edm::InputTag>
657  // Remember: _tokens is a map<uint, edm::EDGetToken>
658  LogDebug("ExoticaValidation") << "We have got " << _recLabels.size() << "recLabels";
659  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin();
660  it != _recLabels.end(); ++it) {
661  if (it->first == EVTColContainer::MUON) {
662  edm::EDGetTokenT<reco::MuonCollection> particularToken = iC.consumes<reco::MuonCollection>(it->second);
663  edm::EDGetToken token(particularToken);
664  _tokens[it->first] = token;
665  }
666  else if (it->first == EVTColContainer::MUONTRACK) {
668  edm::EDGetToken token(particularToken);
669  _tokens[it->first] = token;
670  }
671  else if (it->first == EVTColContainer::ELEC) {
673  edm::EDGetToken token(particularToken);
674  _tokens[it->first] = token;
675  }
676  else if (it->first == EVTColContainer::PHOTON) {
678  edm::EDGetToken token(particularToken);
679  _tokens[it->first] = token;
680  }
681  else if (it->first == EVTColContainer::PFMET) {
683  edm::EDGetToken token(particularToken);
684  _tokens[it->first] = token;
685  }
686  else if (it->first == EVTColContainer::PFTAU) {
688  edm::EDGetToken token(particularToken);
689  _tokens[it->first] = token;
690  }
691  else if (it->first == EVTColContainer::PFJET) {
693  edm::EDGetToken token(particularToken);
694  _tokens[it->first] = token;
695  }
696  else if (it->first == EVTColContainer::CALOJET) {
698  edm::EDGetToken token(particularToken);
699  _tokens[it->first] = token;
700  }
701  else {
702  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::registerConsumes"
703  << " NOT IMPLEMENTED (yet) ERROR: '" << it->second.label() << "'";
704  }
705  }
706 
707 }
708 
709 // Setting the collections of objects in EVTColContainer
711 {
712  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getHandlesToObjects()";
713 
714  if (! col->isCommonInit()) {
715  // Extract the trigger results (path info, pass,...)
717  iEvent.getByToken(_trigResultsToken, trigResults);
718  if (trigResults.isValid()) {
719  col->triggerResults = trigResults.product();
720  LogDebug("ExoticaValidation") << "Added handle to triggerResults";
721  }
722 
723  // Extract the genParticles
725  iEvent.getByToken(_genParticleToken, genPart);
726  if (genPart.isValid()) {
727  col->genParticles = genPart.product();
728  LogDebug("ExoticaValidation") << "Added handle to genParticles";
729  }
730  }
731 
732  // Loop over the tokens and extract all other objects
733  LogDebug("ExoticaValidation") << "We have got " << _tokens.size() << "tokens";
734  for (std::map<unsigned int, edm::EDGetToken>::iterator it = _tokens.begin();
735  it != _tokens.end(); ++it) {
736  if (it->first == EVTColContainer::MUON) {
738  iEvent.getByToken(it->second, theHandle);
739  col->set(theHandle.product());
740  }
741  else if (it->first == EVTColContainer::MUONTRACK) {
743  iEvent.getByToken(it->second, theHandle);
744  col->set(theHandle.product());
745  }
746  else if (it->first == EVTColContainer::ELEC) {
748  iEvent.getByToken(it->second, theHandle);
749  col->set(theHandle.product());
750  }
751  else if (it->first == EVTColContainer::PHOTON) {
753  iEvent.getByToken(it->second, theHandle);
754  col->set(theHandle.product());
755  }
756  else if (it->first == EVTColContainer::PFMET) {
758  iEvent.getByToken(it->second, theHandle);
759  col->set(theHandle.product());
760  }
761  else if (it->first == EVTColContainer::PFTAU) {
763  iEvent.getByToken(it->second, theHandle);
764  col->set(theHandle.product());
765  }
766  else if (it->first == EVTColContainer::PFJET) {
768  iEvent.getByToken(it->second, theHandle);
769  col->set(theHandle.product());
770  }
771  else if (it->first == EVTColContainer::CALOJET) {
773  iEvent.getByToken(it->second, theHandle);
774  col->set(theHandle.product());
775  }
776  else {
777  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::getHandlesToObjects "
778  << " NOT IMPLEMENTED (yet) ERROR: '" << it->first << "'";
779  }
780  }
781 }
782 
783 // Booking the histograms, and putting them in DQM
785  const std::string & source,
786  const std::string & objType,
787  const std::string & variable)
788 {
789  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::bookHist()";
790  std::string sourceUpper = source;
791  sourceUpper[0] = std::toupper(sourceUpper[0]);
792  std::string name = source + objType + variable ;
793  TH1F * h = 0;
794 
795  if (variable.find("SumEt") != std::string::npos) {
796  std::string title = "Sum ET of " + sourceUpper + " " + objType;
797  const size_t nBins = _parametersTurnOn.size() - 1;
798  float * edges = new float[nBins + 1];
799  for (size_t i = 0; i < nBins + 1; i++) {
800  edges[i] = _parametersTurnOn[i];
801  }
802  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
803  delete[] edges;
804  }
805  else if (variable.find("MaxPt") != std::string::npos) {
806  std::string desc = (variable == "MaxPt1") ? "Leading" : "Next-to-Leading";
807  std::string title = "pT of " + desc + " " + sourceUpper + " " + objType;
808  const size_t nBins = _parametersTurnOn.size() - 1;
809  float * edges = new float[nBins + 1];
810  for (size_t i = 0; i < nBins + 1; i++) {
811  edges[i] = _parametersTurnOn[i];
812  }
813  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
814  delete[] edges;
815  } else {
816  std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
817  std::string title = symbol + " of " + sourceUpper + " " + objType;
818  std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
819  int nBins = (int)params[0];
820  double min = params[1];
821  double max = params[2];
822  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
823  }
824 
825  h->Sumw2();
826  // This is the trick, that takes a normal TH1F and puts it in in the DQM
827  // machinery. Seems to be easy!
828  // Updated to use the new iBooker machinery.
829  _elements[name] = iBooker.book1D(name, h);
830  delete h;
831 }
832 
833 // Fill the histograms
835  const std::string & objType,
836  const std::string & variable,
837  const float & value)
838 {
839  std::string sourceUpper = source;
840  sourceUpper[0] = toupper(sourceUpper[0]);
841  std::string name = source + objType + variable ;
842 
843  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::fillHist() " << name << " " << value;
844  _elements[name]->Fill(value);
845  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::fillHist() " << name << " worked";
846 }
847 
848 // Initialize the selectors
849 void HLTExoticaSubAnalysis::initSelector(const unsigned int & objtype)
850 {
851 
852  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::initSelector()";
853 
854  if (objtype == EVTColContainer::MUON && _recMuonSelector == 0) {
856  } else if (objtype == EVTColContainer::MUONTRACK && _recMuonTrkSelector == 0) {
858  } else if (objtype == EVTColContainer::ELEC && _recElecSelector == 0) {
860  } else if (objtype == EVTColContainer::PHOTON && _recPhotonSelector == 0) {
862  } else if (objtype == EVTColContainer::PFMET && _recPFMETSelector == 0) {
864  } else if (objtype == EVTColContainer::PFTAU && _recPFTauSelector == 0) {
866  } else if (objtype == EVTColContainer::PFJET && _recPFJetSelector == 0) {
868  } else if (objtype == EVTColContainer::CALOJET && _recCaloJetSelector == 0) {
870  }
871  /* else
872  {
873  FIXME: ERROR NOT IMPLEMENTED
874  }*/
875 }
876 
877 // Insert the HLT candidates
878 void HLTExoticaSubAnalysis::insertCandidates(const unsigned int & objType, const EVTColContainer * cols, std::vector<reco::LeafCandidate> * matches)
879 {
880 
881  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::insertCandidates()";
882 
883  if (objType == EVTColContainer::MUON) {
884  for (size_t i = 0; i < cols->muons->size(); i++) {
885  LogDebug("ExoticaValidation") << "Inserting muon " << i ;
886  if (_recMuonSelector->operator()(cols->muons->at(i))) {
887  reco::LeafCandidate m(0, cols->muons->at(i).p4(), cols->muons->at(i).vertex(), objType, 0, true);
888  matches->push_back(m);
889  }
890  }
891  } else if (objType == EVTColContainer::MUONTRACK) {
892  for (size_t i = 0; i < cols->muonTracks->size(); i++) {
893  LogDebug("ExoticaValidation") << "Inserting muonTrack " << i ;
894  if (_recMuonTrkSelector->operator()(cols->muonTracks->at(i))) {
895  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>> mom4;
896  ROOT::Math::XYZVector mom3 = cols->muonTracks->at(i).innerMomentum();
897  mom4.SetXYZT(mom3.x(),mom3.y(),mom3.z(),mom3.r());
898  reco::LeafCandidate m(0, mom4, cols->muonTracks->at(i).vertex(), objType, 0, true);
899  matches->push_back(m);
900  }
901  }
902  } else if (objType == EVTColContainer::ELEC) {
903  for (size_t i = 0; i < cols->electrons->size(); i++) {
904  LogDebug("ExoticaValidation") << "Inserting electron " << i ;
905  if (_recElecSelector->operator()(cols->electrons->at(i))) {
906  reco::LeafCandidate m(0, cols->electrons->at(i).p4(), cols->electrons->at(i).vertex(), objType, 0, true);
907  matches->push_back(m);
908  }
909  }
910  } else if (objType == EVTColContainer::PHOTON) {
911  for (size_t i = 0; i < cols->photons->size(); i++) {
912  LogDebug("ExoticaValidation") << "Inserting photon " << i ;
913  if (_recPhotonSelector->operator()(cols->photons->at(i))) {
914  reco::LeafCandidate m(0, cols->photons->at(i).p4(), cols->photons->at(i).vertex(), objType, 0, true);
915  matches->push_back(m);
916  }
917  }
918  } else if (objType == EVTColContainer::PFMET) {
922  for (size_t i = 0; i < cols->pfMETs->size(); i++) {
923  LogDebug("ExoticaValidation") << "Inserting PFMET " << i ;
924  if (_recPFMETSelector->operator()(cols->pfMETs->at(i))) {
925  reco::LeafCandidate m(0, cols->pfMETs->at(i).p4(), cols->pfMETs->at(i).vertex(), objType, 0, true);
926  matches->push_back(m);
927  }
928  }
929  } else if (objType == EVTColContainer::PFTAU) {
930  for (size_t i = 0; i < cols->pfTaus->size(); i++) {
931  LogDebug("ExoticaValidation") << "Inserting PFtau " << i ;
932  if (_recPFTauSelector->operator()(cols->pfTaus->at(i))) {
933  reco::LeafCandidate m(0, cols->pfTaus->at(i).p4(), cols->pfTaus->at(i).vertex(), objType, 0, true);
934  matches->push_back(m);
935  }
936  }
937  } else if (objType == EVTColContainer::PFJET) {
938  for (size_t i = 0; i < cols->pfJets->size(); i++) {
939  LogDebug("ExoticaValidation") << "Inserting jet " << i ;
940  if (_recPFJetSelector->operator()(cols->pfJets->at(i))) {
941  reco::LeafCandidate m(0, cols->pfJets->at(i).p4(), cols->pfJets->at(i).vertex(), objType, 0, true);
942  matches->push_back(m);
943  }
944  }
945  } else if (objType == EVTColContainer::CALOJET) {
946  for (size_t i = 0; i < cols->caloJets->size(); i++) {
947  LogDebug("ExoticaValidation") << "Inserting jet " << i ;
948  if (_recCaloJetSelector->operator()(cols->caloJets->at(i))) {
949  reco::LeafCandidate m(0, cols->caloJets->at(i).p4(), cols->caloJets->at(i).vertex(), objType, 0, true);
950  matches->push_back(m);
951  }
952  }
953  }
954 
955  /* else
956  {
957  FIXME: ERROR NOT IMPLEMENTED
958  }*/
959 }
#define LogDebug(id)
const std::vector< reco::Muon > * muons
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
StringCutObjectSelector< reco::Track > * _recMuonTrkSelector
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:199
void getNamesOfObjects(const edm::ParameterSet &anpset)
Creates the maps that map which collection should come from which label.
const std::vector< reco::PFJet > * pfJets
std::vector< PFTau > PFTauCollection
collection of PFTau objects
Definition: PFTauFwd.h:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
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< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
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
StringCutObjectSelector< reco::CaloJet > * _recCaloJetSelector
std::vector< double > _parametersPhi
const std::vector< reco::CaloJet > * caloJets
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, std::string > _genCut_leading
gen/rec pt-leading objects cuts
StringCutObjectSelector< reco::PFJet > * _recPFJetSelector
std::map< unsigned int, edm::InputTag > _recLabels
StringCutObjectSelector< reco::GsfElectron > * _recElecSelector
void set(const reco::MuonCollection *v)
Setter: multiple overloaded function.
std::map< unsigned int, std::string > _recCut_leading
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.
const T & max(const T &a, const T &b)
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:115
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.
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
const std::vector< reco::Track > * muonTracks
Transform3DPJ::Vector XYZVector
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
void registerConsumes(edm::ConsumesCollector &consCollector)
Registers consumption of objects.
T const * product() const
Definition: Handle.h:81
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
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
edm::EDGetTokenT< reco::GenParticleCollection > _genParticleToken
And also the tokens to get the object collections.
tuple cout
Definition: gather_cfg.py:121
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::vector< CaloJet > CaloJetCollection
collection of CaloJet objects
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