CMS 3D CMS Logo

HLTExoticaSubAnalysis.cc
Go to the documentation of this file.
1 
9 
14 
15 #include "TPRegexp.h"
16 #include "TString.h"
17 
20 
21 #include <algorithm>
22 #include <set>
23 
24 static constexpr int verbose = 0;
25 
28  const std::string &analysisname,
29  edm::ConsumesCollector &&consCollector)
30  : _pset(pset),
31  _analysisname(analysisname),
32  _minCandidates(0),
33  _hltProcessName(pset.getParameter<std::string>("hltProcessName")),
34  _genParticleLabel(pset.getParameter<std::string>("genParticleLabel")),
35  _trigResultsLabel("TriggerResults", "", _hltProcessName),
36  _beamSpotLabel(pset.getParameter<std::string>("beamSpotLabel")),
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  _parametersTurnOnSumEt(pset.getParameter<std::vector<double>>("parametersTurnOnSumEt")),
41  _parametersDxy(pset.getParameter<std::vector<double>>("parametersDxy")),
42  _drop_pt2(false),
43  _drop_pt3(false),
44  _recMuonSelector(nullptr),
45  _recMuonTrkSelector(nullptr),
46  _recTrackSelector(nullptr),
47  _recElecSelector(nullptr),
48  _recMETSelector(nullptr),
49  _recPFMETSelector(nullptr),
50  _recPFMHTSelector(nullptr),
51  _genMETSelector(nullptr),
52  _recCaloMETSelector(nullptr),
53  _recCaloMHTSelector(nullptr),
54  _recPFTauSelector(nullptr),
55  _recPhotonSelector(nullptr),
56  _recPFJetSelector(nullptr),
57  _recCaloJetSelector(nullptr) {
58  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::constructor()";
59 
60  // Specific parameters for this analysis
61  edm::ParameterSet anpset = pset.getParameter<edm::ParameterSet>(analysisname);
62 
63  // If this analysis has a particular set of binnings, use it.
64  // (Taken from the analysis-specific parameter set, of course)
65  // The "true" in the beginning of _pset.insert() means
66  // "overwrite the parameter if need be".
67  if (anpset.exists("parametersTurnOn")) {
68  _parametersTurnOn = anpset.getParameter<std::vector<double>>("parametersTurnOn");
69  _pset.insert(true, "parametersTurnOn", anpset.retrieve("parametersTurnOn"));
70  }
71  if (anpset.exists("parametersEta")) {
72  _parametersEta = anpset.getParameter<std::vector<double>>("parametersEta");
73  _pset.insert(true, "parametersEta", anpset.retrieve("parametersEta"));
74  }
75  if (anpset.exists("parametersPhi")) {
76  _parametersPhi = anpset.getParameter<std::vector<double>>("parametersPhi");
77  _pset.insert(true, "parametersPhi", anpset.retrieve("parametersPhi"));
78  }
79  if (anpset.exists("parametersDxy")) {
80  _parametersDxy = anpset.getParameter<std::vector<double>>("parametersDxy");
81  _pset.insert(true, "parametersDxy", anpset.retrieve("parametersDxy"));
82  }
83  if (anpset.exists("parametersTurnOnSumEt")) {
84  _parametersTurnOnSumEt = anpset.getParameter<std::vector<double>>("parametersTurnOnSumEt");
85  _pset.insert(true, "parametersTurnOnSumEt", anpset.retrieve("parametersTurnOnSumEt"));
86  }
87  if (anpset.exists("dropPt2")) {
88  _drop_pt2 = anpset.getParameter<bool>("dropPt2");
89  _pset.insert(true, "dropPt2", anpset.retrieve("dropPt2"));
90  }
91  if (anpset.exists("dropPt3")) {
92  _drop_pt3 = anpset.getParameter<bool>("dropPt3");
93  _pset.insert(true, "dropPt3", anpset.retrieve("dropPt3"));
94  }
95 
96  // Get names of objects that we may want to get from the event.
97  // Notice that genParticles are dealt with separately.
98  this->getNamesOfObjects(anpset);
99 
100  // Since now we have the names, we should register the consumption
101  // of objects.
102  this->registerConsumes(consCollector);
103 
104  // Generic objects: Initialization of basic phase space cuts.
105  for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
106  const std::string objStr = EVTColContainer::getTypeString(it->first);
107  _genCut[it->first] = pset.getParameter<std::string>(objStr + "_genCut");
108  _recCut[it->first] = pset.getParameter<std::string>(objStr + "_recCut");
109  auto const genCutParam = objStr + "_genCut_leading";
110  if (pset.exists(genCutParam)) {
111  _genCut_leading[it->first] = pset.getParameter<std::string>(genCutParam);
112  } else {
113  _genCut_leading[it->first] = "pt>0"; // no cut
114  }
115  auto const recCutParam = objStr + "_recCut_leading";
116  if (pset.exists(recCutParam)) {
117  _recCut_leading[it->first] = pset.getParameter<std::string>(recCutParam);
118  } else {
119  _recCut_leading[it->first] = "pt>0"; // no cut
120  }
121  }
122 
123  //--- Updating parameters if has to be modified for this particular specific
124  // analysis
125  for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
126  const std::string objStr = EVTColContainer::getTypeString(it->first);
127 
128  auto const genCutParam = objStr + "_genCut";
129  if (anpset.existsAs<std::string>(genCutParam, false)) {
130  _genCut[it->first] = anpset.getUntrackedParameter<std::string>(genCutParam);
131  }
132 
133  auto const recCutParam = objStr + "_recCut";
134  if (anpset.existsAs<std::string>(recCutParam, false)) {
135  _recCut[it->first] = anpset.getUntrackedParameter<std::string>(recCutParam);
136  }
137  }
138 
140  _hltPathsToCheck = anpset.getParameter<std::vector<std::string>>("hltPathsToCheck");
142  _minCandidates = anpset.getParameter<unsigned int>("minCandidates");
143 
144 }
145 
147  for (std::map<unsigned int, StringCutObjectSelector<reco::GenParticle> *>::iterator it = _genSelectorMap.begin();
148  it != _genSelectorMap.end();
149  ++it) {
150  delete it->second;
151  it->second = nullptr;
152  }
153  delete _recMuonSelector;
154  _recMuonSelector = nullptr;
155  delete _recMuonTrkSelector;
156  _recMuonTrkSelector = nullptr;
157  delete _recTrackSelector;
158  _recTrackSelector = nullptr;
159  delete _recElecSelector;
160  _recElecSelector = nullptr;
161  delete _recPhotonSelector;
162  _recPhotonSelector = nullptr;
163  delete _recMETSelector;
164  _recMETSelector = nullptr;
165  delete _recPFMETSelector;
166  _recPFMETSelector = nullptr;
167  delete _recPFMHTSelector;
168  _recPFMHTSelector = nullptr;
169  delete _genMETSelector;
170  _genMETSelector = nullptr;
171  delete _recCaloMETSelector;
172  _recCaloMETSelector = nullptr;
173  delete _recCaloMHTSelector;
174  _recCaloMHTSelector = nullptr;
175  delete _recPFTauSelector;
176  _recPFTauSelector = nullptr;
177  delete _recPFJetSelector;
178  _recPFJetSelector = nullptr;
179  delete _recCaloJetSelector;
180  _recCaloJetSelector = nullptr;
181 }
182 
184 
185 // 2014-02-03 -- Thiago
186 // Due to the fact that the DQM has to be thread safe now, we have to do things
187 // differently: 1) Implement the bookHistograms() method in the container class
188 // 2) Make the iBooker from above be known to this class
189 // 3) Separate all booking histograms routines in this and any auxiliary classe
190 // to be called from bookHistograms() in the container class
192  const edm::Run &iRun,
193  const edm::EventSetup &iSetup) {
194  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::subAnalysisBookHistos()";
195 
196  // Create the folder structure inside HLT/Exotica
197  std::string baseDir = "HLT/Exotica/" + _analysisname + "/";
198  iBooker.setCurrentFolder(baseDir);
199 
200  // Book the gen/reco analysis-dependent histograms (denominators)
201  for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
202  const std::string objStr = EVTColContainer::getTypeString(it->first);
203  std::vector<std::string> sources(2);
204  sources[0] = "gen";
205  sources[1] = "rec";
206 
207  for (size_t i = 0; i < sources.size(); i++) {
209 
210  if (source == "gen") {
211  if (TString(objStr).Contains("MET") || TString(objStr).Contains("MHT") || TString(objStr).Contains("Jet")) {
212  continue;
213  } else {
214  bookHist(iBooker, source, objStr, "MaxPt1");
215  if (!_drop_pt2)
216  bookHist(iBooker, source, objStr, "MaxPt2");
217  if (!_drop_pt3)
218  bookHist(iBooker, source, objStr, "MaxPt3");
219  bookHist(iBooker, source, objStr, "Eta");
220  bookHist(iBooker, source, objStr, "Phi");
221 
222  // If the target is electron or muon,
223  // we will add Dxy plots.
224  if (it->first == EVTColContainer::ELEC || it->first == EVTColContainer::MUON ||
225  it->first == EVTColContainer::MUTRK) {
226  bookHist(iBooker, source, objStr, "Dxy");
227  }
228  }
229  } else { // reco
230  if (TString(objStr).Contains("MET") || TString(objStr).Contains("MHT")) {
231  bookHist(iBooker, source, objStr, "MaxPt1");
232  bookHist(iBooker, source, objStr, "SumEt");
233  } else {
234  bookHist(iBooker, source, objStr, "MaxPt1");
235  if (!_drop_pt2)
236  bookHist(iBooker, source, objStr, "MaxPt2");
237  if (!_drop_pt3)
238  bookHist(iBooker, source, objStr, "MaxPt3");
239  bookHist(iBooker, source, objStr, "Eta");
240  bookHist(iBooker, source, objStr, "Phi");
241 
242  // If the target is electron or muon,
243  // we will add Dxy plots.
244  if (it->first == EVTColContainer::ELEC || it->first == EVTColContainer::MUON ||
245  it->first == EVTColContainer::MUTRK) {
246  bookHist(iBooker, source, objStr, "Dxy");
247  }
248  }
249  }
250  }
251  } // closes loop in _recLabels
252 
253  // Call the plotterBookHistos() (which books all the path dependent
254  // histograms)
255  LogDebug("ExoticaValidation") << " number of plotters = " << _plotters.size();
256  for (std::vector<HLTExoticaPlotter>::iterator it = _plotters.begin(); it != _plotters.end(); ++it) {
257  it->plotterBookHistos(iBooker, iRun, iSetup);
258  }
259 }
260 
261 void HLTExoticaSubAnalysis::beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
262  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::beginRun()";
263 
266 
267  // Initialize the HLT config.
268  bool changedConfig(true);
269  if (!_hltConfig.init(iRun, iSetup, _hltProcessName, changedConfig)) {
270  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::constructor(): "
271  << "Initialization of HLTConfigProvider failed!";
272  }
273 
274  // Parse the input paths to get them if they are in the table and associate
275  // them to the last filter of the path (in order to extract the objects).
276  _hltPaths.clear();
277  for (size_t i = 0; i < _hltPathsToCheck.size(); ++i) {
278  bool found = false;
279  TPRegexp pattern(_hltPathsToCheck[i]);
280 
281  // Loop over triggerNames from _hltConfig
282  for (size_t j = 0; j < _hltConfig.triggerNames().size(); ++j) {
283  std::string thetriggername = _hltConfig.triggerNames()[j];
284  if (TString(thetriggername).Contains(pattern)) {
285  _hltPaths.insert(thetriggername);
286  found = true;
287  }
288  if (verbose > 2 && i == 0)
289  LogDebug("ExoticaValidation") << "--- TRIGGER PATH : " << thetriggername;
290  }
291 
292  // Oh dear, the path we wanted seems to not be available
293  if (!found && verbose > 2) {
294  edm::LogWarning("ExoticaValidation") << "HLTExoticaSubAnalysis::constructor(): In " << _analysisname
295  << " subfolder NOT found the path: '" << _hltPathsToCheck[i] << "*'";
296  }
297  } // Close loop over paths to check.
298 
299  // At this point, _hltpaths contains the names of the paths to check
300  // that were found. Let's log it at trace level.
301  LogTrace("ExoticaValidation") << "SubAnalysis: " << _analysisname << "\nHLT Trigger Paths found >>>";
302  for (std::set<std::string>::const_iterator iter = _hltPaths.begin(); iter != _hltPaths.end(); ++iter) {
303  LogTrace("ExoticaValidation") << (*iter) << "\n";
304  }
305 
306  // Initialize the plotters (analysers for each trigger path)
307  _plotters.clear();
308  for (std::set<std::string>::iterator iPath = _hltPaths.begin(); iPath != _hltPaths.end(); ++iPath) {
309  // Avoiding the dependence of the version number for the trigger paths
310  const std::string &path = *iPath;
311  std::string shortpath = path;
312  if (path.rfind("_v") < path.length()) {
313  shortpath = path.substr(0, path.rfind("_v"));
314  }
315  _shortpath2long[shortpath] = path;
316 
317  // Objects needed by the HLT path
318  // Thiago: instead of trying to decode the objects from the path,
319  // put the burden on the user to tell us which objects are needed.
320  // const std::vector<unsigned int> objsNeedHLT =
321  // this->getObjectsType(shortpath);
322  std::vector<unsigned int> objsNeedHLT;
323  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
324  objsNeedHLT.push_back(it->first);
325  }
326 
327  /*std::vector<unsigned int> userInstantiate;
328  // Sanity check: the object needed by a trigger path should be
329  // introduced by the user via config python (_recLabels datamember)
330  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin()
331  ; it != _recLabels.end(); ++it) { userInstantiate.push_back(it->first);
332  }
333  for (std::vector<unsigned int>::const_iterator it = objsNeedHLT.begin(); it
334  != objsNeedHLT.end();
335  ++it) {
336  if (std::find(userInstantiate.begin(), userInstantiate.end(), *it) ==
337  userInstantiate.end()) {
338  edm::LogError("ExoticaValidation") << "In
339  HLTExoticaSubAnalysis::beginRun, "
340  << "Incoherence found in the
341  python configuration file!!\nThe SubAnalysis '"
342  << _analysisname << "' has been
343  asked to evaluate the trigger path '"
344  << shortpath << "' (found it in
345  'hltPathsToCheck') BUT this path"
346  << " needs a '" <<
347  EVTColContainer::getTypeString(*it)
348  << "' which has not been
349  instantiated ('recVariableLabels'"
350  << ")" ;
351  exit(-1); // This should probably throw an exception...
352  }
353  }
354  */
355  LogTrace("ExoticaValidation") << " --- " << shortpath;
356 
357  // The hlt path, the objects (electrons, muons, photons, ...)
358  // needed to evaluate the path are the argumens of the plotter
359  HLTExoticaPlotter analyzer(_pset, shortpath, objsNeedHLT);
360  _plotters.push_back(analyzer);
361  // counting HLT passed events for debug
363  } // Okay, at this point we have prepared all the plotters.
364 }
365 
367  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::analyze()";
368 
369  // Loop over _recLabels to make sure everything is alright.
370  /*
371  std::cout << "Now printing the _recLabels" << std::endl;
372  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin();
373  it != _recLabels.end(); ++it) {
374  std::cout << "Number: " << it->first << "\t" << "Label: " <<
375  it->second.label() << std::endl;
376  }
377  */
378 
379  // Initialize the collection (the ones which have not been initialiazed yet)
380  // std::cout << "Setting handles to objects..." << std::endl;
381  this->getHandlesToObjects(iEvent, cols);
382 
383  // Utility map, mapping kinds of objects (GEN, RECO) to strings ("gen","rec")
384  // std::map<Level, std::string> u2str;
385  // u2str[Level::GEN] = "gen";
386  // u2str[Level::RECO] = "rec";
387 
388  // Extract the match structure containing the gen/reco candidates (electron,
389  // muons,...). This part is common to all the SubAnalyses
390  std::vector<reco::LeafCandidate> matchesGen;
391  matchesGen.clear();
392  std::vector<reco::LeafCandidate> matchesReco;
393  matchesReco.clear();
394  std::map<int, double> theSumEt; // map< pdgId ; SumEt > in order to keep track of the MET type
395  std::map<int, std::vector<const reco::Track *>> trkObjs;
396 
397  // --- deal with GEN objects first.
398  // Make each good GEN object into the base cand for a MatchStruct
399  // Our definition of "good" is "passes the selector" defined in the config.py
400  // Save all the MatchStructs in the "matchesGen" vector.
401 
402  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
403  // Here we are filling the vector of
404  // StringCutObjectSelector<reco::GenParticle> with objects constructed from
405  // the strings saved in _genCut. Initialize selectors when first event
406 
407  // std::cout << "Loop over the kinds of objects: objects of kind " <<
408  // it->first << std::endl;
409 
410  if (!_genSelectorMap[it->first]) {
412  }
413 
414  const std::string objTypeStr = EVTColContainer::getTypeString(it->first);
415  // genAnyMET doesn't make sense. No need their matchesGens
416  if (TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT") ||
417  TString(objTypeStr).Contains("Jet"))
418  continue;
419 
420  // Now loop over the genParticles, and apply the operator() over each of
421  // them. Fancy syntax: for objects X and Y, X.operator()(Y) is the same as
422  // X(Y).
423  for (size_t i = 0; i < cols->genParticles->size(); ++i) {
424  // std::cout << "Now matchesGen.size() is " << matchesGen.size() <<
425  // std::endl;
426  if (_genSelectorMap[it->first]->operator()(cols->genParticles->at(i))) {
427  const reco::Candidate *cand = &(cols->genParticles->at(i));
428  // std::cout << "Found good cand: cand->pt() = " << cand->pt() <<
429  // std::endl; matchesGen.push_back(MatchStruct(cand, it->first));
433  reco::LeafCandidate v(0, cand->p4(), cand->vertex(), it->first, 0, true);
434 
435  matchesGen.push_back(v);
436  }
437  }
438  }
439 
440  // Sort the matches by pT for later filling of turn-on curve
441  // std::cout << "Before sorting: matchesGen.size() = " << matchesGen.size() <<
442  // std::endl;
443 
444  // GreaterByPt<reco::LeafCandidate> comparator;
445  // std::sort(matchesGen.begin(),
446  // matchesGen.end(),
447  // comparator);
448 
449  // --- same for RECO objects
450  // Extraction of the objects candidates
451  if (verbose > 0)
452  LogDebug("ExoticaValidation") << "-- enter loop over recLabels";
453  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
454  // std::cout << "Filling RECO \"matchesReco\" vector for particle kind
455  // it->first = "
456  // << it->first << ", which means " << it->second.label() << std::endl;
457  // Reco selectors (the function takes into account if it was instantiated
458  // before or not) ### Thiago ---> Then why don't we put it in the
459  // beginRun???
460  this->initSelector(it->first);
461  // -- Storing the matchesReco
462  this->insertCandidates(it->first, cols, &matchesReco, theSumEt, trkObjs);
463  if (verbose > 0)
464  LogDebug("ExoticaValidation") << "--- " << EVTColContainer::getTypeString(it->first)
465  << " sumEt=" << theSumEt[it->first];
466  }
467 
468  // std::sort(matchesReco.begin(),
469  // matchesReco.end(),
470  // comparator);
471 
472  // -- Trigger Results
473  const edm::TriggerNames &trigNames = iEvent.triggerNames(*(cols->triggerResults));
474 
475  // counting HLT passed events for debugging
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  if (ispassTrigger)
480  _triggerCounter.find(an->gethltpath())->second++;
481  }
482 
485 
486  // for (std::map<unsigned int, std::vector<MatchStruct> >::iterator it =
487  // sourceMatchMap.begin(); it != sourceMatchMap.end(); ++it) {
488  // it->first: gen/reco it->second: HLT matches (std::vector<MatchStruct>)
489 
490  // if (it->second.size() < _minCandidates) { // FIXME: A bug is potentially
491  // here: what about the mixed channels? continue;
492  //}
493 
497  if (matchesGen.size() >= _minCandidates) { // FIXME: A bug is potentially here: what about the
498  // mixed channels?
499  // Okay, there are enough candidates. Move on!
500 
501  // Filling the gen/reco objects (eff-denominators):
502  // Just the first two different ones, if there are more
503  // The countobjects maps uints (object types, really) --> integers.
504  // Example:
505  // | uint | int |
506  // | 0 | 1 | --> 1 muon used
507  // | 1 | 2 | --> 2 electrons used
508 
509  // Initializing the count of the used objects.
510  std::map<unsigned int, int> countobjects;
511  for (std::map<unsigned int, edm::InputTag>::iterator co = _recLabels.begin(); co != _recLabels.end(); ++co) {
512  // countobjects->insert(std::pair<unsigned int, int>(co->first, 0));
513  countobjects.insert(std::pair<unsigned int, int>(co->first, 0));
514  }
515 
516  int counttotal = 0;
517 
518  // 3 : pt1, pt2, pt3
519  int totalobjectssize = 1;
520  if (!_drop_pt2)
521  totalobjectssize++;
522  if (!_drop_pt3)
523  totalobjectssize++;
524  totalobjectssize *= countobjects.size();
525 
526  bool isPassedLeadingCut = true;
527  // We will proceed only when cuts for the pt-leading are satisified.
528  for (size_t j = 0; j != matchesGen.size(); ++j) {
529  const unsigned int objType = matchesGen[j].pdgId();
530  // Cut for the pt-leading object
532  if (!select(matchesGen[j])) { // No interest case
533  isPassedLeadingCut = false; // Will skip the following matchesGen loop
534  matchesGen.clear();
535  break;
536  }
537  }
538 
539  std::vector<float> dxys;
540  dxys.clear();
541 
542  for (size_t j = 0; (j != matchesGen.size()) && isPassedLeadingCut; ++j) {
543  const unsigned int objType = matchesGen[j].pdgId();
544  // std::cout << "(4) Gonna call with " << objType << std::endl;
546 
547  float pt = matchesGen[j].pt();
548 
549  if (countobjects[objType] == 0) {
550  this->fillHist("gen", objTypeStr, "MaxPt1", pt);
551  ++(countobjects[objType]);
552  ++counttotal;
553  } else if (countobjects[objType] == 1 && !_drop_pt2) {
554  this->fillHist("gen", objTypeStr, "MaxPt2", pt);
555  ++(countobjects[objType]);
556  ++counttotal;
557  } else if (countobjects[objType] == 2 && !_drop_pt3) {
558  this->fillHist("gen", objTypeStr, "MaxPt3", pt);
559  ++(countobjects[objType]);
560  ++counttotal;
561  } else {
562  // Already the minimum three objects has been filled, get out...
563  if (counttotal == totalobjectssize) {
564  size_t max_size = matchesGen.size();
565  for (size_t jj = j; jj < max_size; jj++) {
566  matchesGen.erase(matchesGen.end());
567  }
568  break;
569  }
570  }
571 
572  float eta = matchesGen[j].eta();
573  float phi = matchesGen[j].phi();
574 
575  this->fillHist("gen", objTypeStr, "Eta", eta);
576  this->fillHist("gen", objTypeStr, "Phi", phi);
577 
578  // If the target is electron or muon,
579 
581  const math::XYZPoint &vtx = matchesGen[j].vertex();
582  float momphi = matchesGen[j].momentum().phi();
583  float dxyGen = (-(vtx.x() - cols->bs->x0()) * sin(momphi) + (vtx.y() - cols->bs->y0()) * cos(momphi));
584  dxys.push_back(dxyGen);
585  this->fillHist("gen", objTypeStr, "Dxy", dxyGen);
586  }
587 
588  } // Closes loop in gen
589 
590  // Calling to the plotters analysis (where the evaluation of the different
591  // trigger paths are done)
592  // const std::string source = "gen";
593  for (std::vector<HLTExoticaPlotter>::iterator an = _plotters.begin(); an != _plotters.end(); ++an) {
594  const std::string hltPath = _shortpath2long[an->gethltpath()];
595  const bool ispassTrigger = cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
596  LogDebug("ExoticaValidation") << " preparing to call the plotters analysis";
597  an->analyze(ispassTrigger, "gen", matchesGen, theSumEt, dxys);
598  LogDebug("ExoticaValidation") << " called the plotter";
599  }
600  }
601 
605 
606  {
607  if (matchesReco.size() < _minCandidates)
608  return; // FIXME: A bug is potentially here: what about the mixed
609  // channels?
610 
611  // Okay, there are enough candidates. Move on!
612 
613  // Filling the gen/reco objects (eff-denominators):
614  // Just the first two different ones, if there are more
615  // The countobjects maps uints (object types, really) --> integers.
616  // Example:
617  // | uint | int |
618  // | 0 | 1 | --> 1 muon used
619  // | 1 | 2 | --> 2 electrons used
620  // Initializing the count of the used objects.
621  // std::map<unsigned int, int> * countobjects = new std::map<unsigned int,
622  // int>;
623  std::map<unsigned int, int> countobjects;
624  for (std::map<unsigned int, edm::InputTag>::iterator co = _recLabels.begin(); co != _recLabels.end(); ++co) {
625  countobjects.insert(std::pair<unsigned int, int>(co->first, 0));
626  }
627 
628  int counttotal = 0;
629 
630  // 3 : pt1, pt2, pt3
631  int totalobjectssize = 1;
632  if (!_drop_pt2)
633  totalobjectssize++;
634  if (!_drop_pt3)
635  totalobjectssize++;
636  totalobjectssize *= countobjects.size();
637 
639  // std::cout << "Our RECO vector has matchesReco.size() = " <<
640  // matchesReco.size() << std::endl;
641 
642  std::vector<float> dxys;
643  dxys.clear();
644 
645  bool isPassedLeadingCut = true;
646  // We will proceed only when cuts for the pt-leading are satisified.
647  for (size_t j = 0; j != matchesReco.size(); ++j) {
648  const unsigned int objType = matchesReco[j].pdgId();
649  // Cut for the pt-leading object
651  if (!select(matchesReco[j])) { // No interest case
652  isPassedLeadingCut = false; // Will skip the following matchesReco loop
653  matchesReco.clear();
654  break;
655  }
656  }
657 
658  int jel = 0;
659  int jmu = 0;
660  int jmutrk = 0;
661 
662  // jel, jmu and jmutrk are being used as a dedicated counters to avoid getting
663  // non-existent elements inside trkObjs[11], trkObjs[13] and trkObjs[130], respectively
664  // more information in the issue https://github.com/cms-sw/cmssw/issues/32550
665 
666  for (size_t j = 0; (j != matchesReco.size()) && isPassedLeadingCut; ++j) {
667  const unsigned int objType = matchesReco[j].pdgId();
668  //std::cout << "(4) Gonna call with " << objType << std::endl;
669 
671 
672  float pt = matchesReco[j].pt();
673 
674  if (countobjects[objType] == 0) {
675  this->fillHist("rec", objTypeStr, "MaxPt1", pt);
676  ++(countobjects[objType]);
677  ++counttotal;
678  } else if (countobjects[objType] == 1 && !_drop_pt2) {
679  if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
680  this->fillHist("rec", objTypeStr, "MaxPt2", pt);
681  }
682  ++(countobjects[objType]);
683  ++counttotal;
684  } else if (countobjects[objType] == 2 && !_drop_pt3) {
685  if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
686  this->fillHist("rec", objTypeStr, "MaxPt3", pt);
687  }
688  ++(countobjects[objType]);
689  ++counttotal;
690  } else {
691  // Already the minimum three objects has been filled, get out...
692  if (counttotal == totalobjectssize) {
693  size_t max_size = matchesReco.size();
694  for (size_t jj = j; jj < max_size; jj++) {
695  matchesReco.erase(matchesReco.end());
696  }
697  break;
698  }
699  }
700 
701  float eta = matchesReco[j].eta();
702  float phi = matchesReco[j].phi();
703 
704  if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
705  this->fillHist("rec", objTypeStr, "Eta", eta);
706  this->fillHist("rec", objTypeStr, "Phi", phi);
707  } else {
708  this->fillHist("rec", objTypeStr, "SumEt", theSumEt[objType]);
709  }
710 
711  if (objType == 11) {
712  float dxyRec = trkObjs[objType].at(jel)->dxy(cols->bs->position());
713  this->fillHist("rec", objTypeStr, "Dxy", dxyRec);
714  dxys.push_back(dxyRec);
715  ++jel;
716  }
717 
718  if (objType == 13) {
719  float dxyRec = trkObjs[objType].at(jmu)->dxy(cols->bs->position());
720  this->fillHist("rec", objTypeStr, "Dxy", dxyRec);
721  dxys.push_back(dxyRec);
722  ++jmu;
723  }
724 
725  if (objType == 130) {
726  float dxyRec = trkObjs[objType].at(jmutrk)->dxy(cols->bs->position());
727  this->fillHist("rec", objTypeStr, "Dxy", dxyRec);
728  dxys.push_back(dxyRec);
729  ++jmutrk;
730  }
731 
732  } // Closes loop in reco
733 
734  // LogDebug("ExoticaValidation") << " deleting
735  // countobjects"; delete countobjects;
736 
737  // Calling to the plotters analysis (where the evaluation of the different
738  // trigger paths are done)
739  // const std::string source = "reco";
740  for (std::vector<HLTExoticaPlotter>::iterator an = _plotters.begin(); an != _plotters.end(); ++an) {
741  const std::string hltPath = _shortpath2long[an->gethltpath()];
742  const bool ispassTrigger = cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
743  LogDebug("ExoticaValidation") << " preparing to call the plotters analysis";
744  an->analyze(ispassTrigger, "rec", matchesReco, theSumEt, dxys);
745  LogDebug("ExoticaValidation") << " called the plotter";
746  }
747  }
748 
749 }
750 
751 // Return the objects (muons,electrons,photons,...) needed by a hlt path.
752 const std::vector<unsigned int> HLTExoticaSubAnalysis::getObjectsType(const std::string &hltPath) const {
753  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getObjectsType()";
754 
755  static const unsigned int objSize = 15;
756  static const unsigned int objtriggernames[] = {EVTColContainer::MUON,
770 
771  std::set<unsigned int> objsType;
772  // The object to deal has to be entered via the config .py
773  for (unsigned int i = 0; i < objSize; ++i) {
774  // std::cout << "(5) Gonna call with " << objtriggernames[i] << std::endl;
775  std::string objTypeStr = EVTColContainer::getTypeString(objtriggernames[i]);
776  // Check if it is needed this object for this trigger
777  if (!TString(hltPath).Contains(objTypeStr)) {
778  continue;
779  }
780 
781  objsType.insert(objtriggernames[i]);
782  }
783 
784  return std::vector<unsigned int>(objsType.begin(), objsType.end());
785 }
786 
787 // Booking the maps: recLabels and genParticle selectors
789  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getNamesOfObjects()";
790 
791  if (anpset.exists("recMuonLabel")) {
792  _recLabels[EVTColContainer::MUON] = anpset.getParameter<edm::InputTag>("recMuonLabel");
794  }
795  if (anpset.exists("recMuonTrkLabel")) {
796  _recLabels[EVTColContainer::MUTRK] = anpset.getParameter<edm::InputTag>("recMuonTrkLabel");
798  }
799  if (anpset.exists("recTrackLabel")) {
800  _recLabels[EVTColContainer::TRACK] = anpset.getParameter<edm::InputTag>("recTrackLabel");
802  }
803  if (anpset.exists("recElecLabel")) {
804  _recLabels[EVTColContainer::ELEC] = anpset.getParameter<edm::InputTag>("recElecLabel");
806  }
807  if (anpset.exists("recPhotonLabel")) {
808  _recLabels[EVTColContainer::PHOTON] = anpset.getParameter<edm::InputTag>("recPhotonLabel");
810  }
811  if (anpset.exists("recMETLabel")) {
812  _recLabels[EVTColContainer::MET] = anpset.getParameter<edm::InputTag>("recMETLabel");
814  }
815  if (anpset.exists("recPFMETLabel")) {
816  _recLabels[EVTColContainer::PFMET] = anpset.getParameter<edm::InputTag>("recPFMETLabel");
818  }
819  if (anpset.exists("recPFMHTLabel")) {
820  _recLabels[EVTColContainer::PFMHT] = anpset.getParameter<edm::InputTag>("recPFMHTLabel");
822  }
823  if (anpset.exists("genMETLabel")) {
826  }
827  if (anpset.exists("recCaloMETLabel")) {
828  _recLabels[EVTColContainer::CALOMET] = anpset.getParameter<edm::InputTag>("recCaloMETLabel");
830  }
831  if (anpset.exists("recCaloMHTLabel")) {
832  _recLabels[EVTColContainer::CALOMHT] = anpset.getParameter<edm::InputTag>("recCaloMHTLabel");
834  }
835  if (anpset.exists("hltMETLabel")) {
838  }
839  if (anpset.exists("recPFTauLabel")) {
840  _recLabels[EVTColContainer::PFTAU] = anpset.getParameter<edm::InputTag>("recPFTauLabel");
842  }
843  if (anpset.exists("recPFJetLabel")) {
844  _recLabels[EVTColContainer::PFJET] = anpset.getParameter<edm::InputTag>("recPFJetLabel");
846  }
847  if (anpset.exists("recCaloJetLabel")) {
848  _recLabels[EVTColContainer::CALOJET] = anpset.getParameter<edm::InputTag>("recCaloJetLabel");
850  }
851 
852  if (_recLabels.empty()) {
853  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::getNamesOfObjects, "
854  << "Not included any object (recMuonLabel, recElecLabel, ...) "
855  << "in the analysis " << _analysisname;
856  return;
857  }
858 }
859 
860 // Register consumption of objects.
861 // I have chosen to centralize all consumes() calls here.
863  // Register that we are getting genParticles
865 
866  // Register that we are getting the trigger results
868 
869  // Register beamspot
871 
872  // Loop over _recLabels, see what we need, and register.
873  // Then save the registered token in _tokens.
874  // Remember: _recLabels is a map<uint, edm::InputTag>
875  // Remember: _tokens is a map<uint, edm::EDGetToken>
876  LogDebug("ExoticaValidation") << "We have got " << _recLabels.size() << "recLabels";
877  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
878  if (it->first == EVTColContainer::MUON) {
879  edm::EDGetTokenT<reco::MuonCollection> particularToken = iC.consumes<reco::MuonCollection>(it->second);
880  edm::EDGetToken token(particularToken);
881  _tokens[it->first] = token;
882  } else if (it->first == EVTColContainer::MUTRK) {
884  edm::EDGetToken token(particularToken);
885  _tokens[it->first] = token;
886  } else if (it->first == EVTColContainer::TRACK) {
888  edm::EDGetToken token(particularToken);
889  _tokens[it->first] = token;
890  } else if (it->first == EVTColContainer::ELEC) {
892  iC.consumes<reco::GsfElectronCollection>(it->second);
893  edm::EDGetToken token(particularToken);
894  _tokens[it->first] = token;
895  } else if (it->first == EVTColContainer::PHOTON) {
897  edm::EDGetToken token(particularToken);
898  _tokens[it->first] = token;
899  } else if (it->first == EVTColContainer::MET) {
900  edm::EDGetTokenT<reco::METCollection> particularToken = iC.consumes<reco::METCollection>(it->second);
901  edm::EDGetToken token(particularToken);
902  _tokens[it->first] = token;
903  } else if (it->first == EVTColContainer::PFMET) {
905  edm::EDGetToken token(particularToken);
906  _tokens[it->first] = token;
907  } else if (it->first == EVTColContainer::PFMHT) {
909  edm::EDGetToken token(particularToken);
910  _tokens[it->first] = token;
911  } else if (it->first == EVTColContainer::GENMET) {
913  edm::EDGetToken token(particularToken);
914  _tokens[it->first] = token;
915  } else if (it->first == EVTColContainer::CALOMET) {
917  edm::EDGetToken token(particularToken);
918  _tokens[it->first] = token;
919  } else if (it->first == EVTColContainer::CALOMHT) {
921  edm::EDGetToken token(particularToken);
922  _tokens[it->first] = token;
923  } else if (it->first == EVTColContainer::PFTAU) {
925  edm::EDGetToken token(particularToken);
926  _tokens[it->first] = token;
927  } else if (it->first == EVTColContainer::PFJET) {
929  edm::EDGetToken token(particularToken);
930  _tokens[it->first] = token;
931  } else if (it->first == EVTColContainer::CALOJET) {
933  edm::EDGetToken token(particularToken);
934  _tokens[it->first] = token;
935  } else {
936  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::registerConsumes"
937  << " NOT IMPLEMENTED (yet) ERROR: '" << it->second.label() << "'";
938  }
939  }
940 }
941 
942 // Setting the collections of objects in EVTColContainer
944  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getHandlesToObjects()";
945 
946  if (!col->isCommonInit()) {
947  // Extract the trigger results (path info, pass,...)
949  iEvent.getByToken(_trigResultsToken, trigResults);
950  if (trigResults.isValid()) {
951  col->triggerResults = trigResults.product();
952  LogDebug("ExoticaValidation") << "Added handle to triggerResults";
953  }
954 
955  // Extract the genParticles
957  iEvent.getByToken(_genParticleToken, genPart);
958  if (genPart.isValid()) {
959  col->genParticles = genPart.product();
960  LogDebug("ExoticaValidation") << "Added handle to genParticles";
961  }
962 
963  // BeamSpot for dxy
965  iEvent.getByToken(_bsToken, bsHandle);
966  if (bsHandle.isValid()) {
967  col->bs = bsHandle.product();
968  }
969  }
970 
971  // Loop over the tokens and extract all other objects
972  LogDebug("ExoticaValidation") << "We have got " << _tokens.size() << "tokens";
973  for (std::map<unsigned int, edm::EDGetToken>::iterator it = _tokens.begin(); it != _tokens.end(); ++it) {
974  if (it->first == EVTColContainer::MUON) {
976  iEvent.getByToken(it->second, theHandle);
977  if (theHandle.isValid())
978  col->set(theHandle.product());
979  } else if (it->first == EVTColContainer::MUTRK) {
981  iEvent.getByToken(it->second, theHandle);
982  if (theHandle.isValid())
983  col->set(theHandle.product());
984  } else if (it->first == EVTColContainer::TRACK) {
986  iEvent.getByToken(it->second, theHandle);
987  if (theHandle.isValid())
988  col->set(theHandle.product());
989  } else if (it->first == EVTColContainer::ELEC) {
991  iEvent.getByToken(it->second, theHandle);
992  if (theHandle.isValid())
993  col->set(theHandle.product());
994  } else if (it->first == EVTColContainer::PHOTON) {
996  iEvent.getByToken(it->second, theHandle);
997  if (theHandle.isValid())
998  col->set(theHandle.product());
999  } else if (it->first == EVTColContainer::MET) {
1001  iEvent.getByToken(it->second, theHandle);
1002  if (theHandle.isValid())
1003  col->set(theHandle.product());
1004  } else if (it->first == EVTColContainer::PFMET) {
1006  iEvent.getByToken(it->second, theHandle);
1007  if (theHandle.isValid())
1008  col->set(theHandle.product());
1009  } else if (it->first == EVTColContainer::PFMHT) {
1011  iEvent.getByToken(it->second, theHandle);
1012  if (theHandle.isValid())
1013  col->setPFMHT(theHandle.product());
1014  } else if (it->first == EVTColContainer::GENMET) {
1016  iEvent.getByToken(it->second, theHandle);
1017  if (theHandle.isValid())
1018  col->set(theHandle.product());
1019  } else if (it->first == EVTColContainer::CALOMET) {
1021  iEvent.getByToken(it->second, theHandle);
1022  if (theHandle.isValid())
1023  col->set(theHandle.product());
1024  } else if (it->first == EVTColContainer::CALOMHT) {
1026  iEvent.getByToken(it->second, theHandle);
1027  if (theHandle.isValid())
1028  col->setCaloMHT(theHandle.product());
1029  } else if (it->first == EVTColContainer::PFTAU) {
1031  iEvent.getByToken(it->second, theHandle);
1032  if (theHandle.isValid())
1033  col->set(theHandle.product());
1034  } else if (it->first == EVTColContainer::PFJET) {
1036  iEvent.getByToken(it->second, theHandle);
1037  if (theHandle.isValid())
1038  col->set(theHandle.product());
1039  } else if (it->first == EVTColContainer::CALOJET) {
1041  iEvent.getByToken(it->second, theHandle);
1042  if (theHandle.isValid())
1043  col->set(theHandle.product());
1044  } else {
1045  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::getHandlesToObjects "
1046  << " NOT IMPLEMENTED (yet) ERROR: '" << it->first << "'";
1047  }
1048  }
1049 }
1050 
1051 // Booking the histograms, and putting them in DQM
1053  const std::string &source,
1054  const std::string &objType,
1055  const std::string &variable) {
1056  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::bookHist()";
1057  std::string sourceUpper = source;
1058  sourceUpper[0] = std::toupper(sourceUpper[0]);
1060  TH1F *h = nullptr;
1061 
1062  if (variable.find("SumEt") != std::string::npos) {
1063  std::string title = "Sum ET of " + sourceUpper + " " + objType;
1064  const size_t nBins = _parametersTurnOnSumEt.size() - 1;
1065  float *edges = new float[nBins + 1];
1066  for (size_t i = 0; i < nBins + 1; i++) {
1068  }
1069  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
1070  delete[] edges;
1071  }
1072 
1073  else if (variable.find("Dxy") != std::string::npos) {
1074  std::string title = "Dxy " + sourceUpper + " " + objType;
1075  int nBins = _parametersDxy[0];
1076  double min = _parametersDxy[1];
1077  double max = _parametersDxy[2];
1078  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
1079  }
1080 
1081  else if (variable.find("MaxPt") != std::string::npos) {
1082  std::string desc = (variable == "MaxPt1") ? "Leading" : "Next-to-Leading";
1083  std::string title = "pT of " + desc + " " + sourceUpper + " " + objType;
1084  const size_t nBins = _parametersTurnOn.size() - 1;
1085  float *edges = new float[nBins + 1];
1086  for (size_t i = 0; i < nBins + 1; i++) {
1087  edges[i] = _parametersTurnOn[i];
1088  }
1089  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
1090  delete[] edges;
1091  }
1092 
1093  else {
1094  std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
1095  std::string title = symbol + " of " + sourceUpper + " " + objType;
1096  std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
1097  int nBins = (int)params[0];
1098  double min = params[1];
1099  double max = params[2];
1100  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
1101  }
1102 
1103  h->Sumw2();
1104  // This is the trick, that takes a normal TH1F and puts it in in the DQM
1105  // machinery. Seems to be easy!
1106  // Updated to use the new iBooker machinery.
1107 
1108  if (source == "gen") {
1109  if (objType != "refittedStandAloneMuons") {
1110  _elements[name] = iBooker.book1D(name, h);
1111  }
1112  } else {
1113  _elements[name] = iBooker.book1D(name, h);
1114  }
1115 
1116  delete h;
1117 }
1118 
1119 // Fill the histograms
1121  const std::string &objType,
1122  const std::string &variable,
1123  const float &value) {
1124  std::string sourceUpper = source;
1125  sourceUpper[0] = toupper(sourceUpper[0]);
1127 
1128  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::fillHist() " << name << " " << value;
1129 
1130  if (source == "gen") {
1131  if (objType != "refittedStandAloneMuons") {
1132  _elements[name]->Fill(value);
1133  }
1134  } else {
1135  _elements[name]->Fill(value);
1136  }
1137 
1138  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::fillHist() " << name << " worked";
1139 }
1140 
1141 // Initialize the selectors
1142 void HLTExoticaSubAnalysis::initSelector(const unsigned int &objtype) {
1143  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::initSelector()";
1144 
1145  if (objtype == EVTColContainer::MUON && _recMuonSelector == nullptr) {
1147  } else if (objtype == EVTColContainer::MUTRK && _recMuonTrkSelector == nullptr) {
1149  } else if (objtype == EVTColContainer::TRACK && _recTrackSelector == nullptr) {
1151  } else if (objtype == EVTColContainer::ELEC && _recElecSelector == nullptr) {
1153  } else if (objtype == EVTColContainer::PHOTON && _recPhotonSelector == nullptr) {
1155  } else if (objtype == EVTColContainer::MET && _recMETSelector == nullptr) {
1157  } else if (objtype == EVTColContainer::PFMET && _recPFMETSelector == nullptr) {
1159  } else if (objtype == EVTColContainer::PFMHT && _recPFMHTSelector == nullptr) {
1161  } else if (objtype == EVTColContainer::GENMET && _genMETSelector == nullptr) {
1163  } else if (objtype == EVTColContainer::CALOMET && _recCaloMETSelector == nullptr) {
1165  } else if (objtype == EVTColContainer::CALOMHT && _recCaloMHTSelector == nullptr) {
1167  } else if (objtype == EVTColContainer::PFTAU && _recPFTauSelector == nullptr) {
1169  } else if (objtype == EVTColContainer::PFJET && _recPFJetSelector == nullptr) {
1171  } else if (objtype == EVTColContainer::CALOJET && _recCaloJetSelector == nullptr) {
1173  }
1174  /* else
1175  {
1176  FIXME: ERROR NOT IMPLEMENTED
1177  }*/
1178 }
1179 
1180 // Insert the HLT candidates
1182  const EVTColContainer *cols,
1183  std::vector<reco::LeafCandidate> *matches,
1184  std::map<int, double> &theSumEt,
1185  std::map<int, std::vector<const reco::Track *>> &trkObjs) {
1186  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::insertCandidates()";
1187 
1188  theSumEt[objType] = -1;
1189 
1190  if (objType == EVTColContainer::MUON) {
1191  for (size_t i = 0; i < cols->muons->size(); i++) {
1192  LogDebug("ExoticaValidation") << "Inserting muon " << i;
1193  if (_recMuonSelector->operator()(cols->muons->at(i))) {
1194  reco::LeafCandidate m(0, cols->muons->at(i).p4(), cols->muons->at(i).vertex(), objType, 0, true);
1195  matches->push_back(m);
1196 
1197  // for making dxy plots
1198  trkObjs[objType].push_back(cols->muons->at(i).bestTrack());
1199  }
1200  }
1201  } else if (objType == EVTColContainer::MUTRK) {
1202  for (size_t i = 0; i < cols->tracks->size(); i++) {
1203  LogDebug("ExoticaValidation") << "Inserting muonTrack " << i;
1204  if (_recMuonTrkSelector->operator()(cols->tracks->at(i))) {
1205  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>> mom4;
1206  ROOT::Math::XYZVector mom3 = cols->tracks->at(i).momentum();
1207  mom4.SetXYZT(mom3.x(), mom3.y(), mom3.z(), mom3.r());
1208  reco::LeafCandidate m(0, mom4, cols->tracks->at(i).vertex(), objType, 0, true);
1209  matches->push_back(m);
1210 
1211  // for making dxy plots
1212  trkObjs[objType].push_back(&cols->tracks->at(i));
1213  }
1214  }
1215  } else if (objType == EVTColContainer::TRACK) {
1216  for (size_t i = 0; i < cols->tracks->size(); i++) {
1217  LogDebug("ExoticaValidation") << "Inserting Track " << i;
1218  if (_recTrackSelector->operator()(cols->tracks->at(i))) {
1219  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>> mom4;
1220  ROOT::Math::XYZVector mom3 = cols->tracks->at(i).momentum();
1221  mom4.SetXYZT(mom3.x(), mom3.y(), mom3.z(), mom3.r());
1222  reco::LeafCandidate m(0, mom4, cols->tracks->at(i).vertex(), objType, 0, true);
1223  matches->push_back(m);
1224  }
1225  }
1226  } else if (objType == EVTColContainer::ELEC) {
1227  for (size_t i = 0; i < cols->electrons->size(); i++) {
1228  LogDebug("ExoticaValidation") << "Inserting electron " << i;
1229  if (_recElecSelector->operator()(cols->electrons->at(i))) {
1230  reco::LeafCandidate m(0, cols->electrons->at(i).p4(), cols->electrons->at(i).vertex(), objType, 0, true);
1231  matches->push_back(m);
1232 
1233  // for making dxy plots
1234  trkObjs[objType].push_back(cols->electrons->at(i).bestTrack());
1235  }
1236  }
1237  } else if (objType == EVTColContainer::PHOTON) {
1238  for (size_t i = 0; i < cols->photons->size(); i++) {
1239  LogDebug("ExoticaValidation") << "Inserting photon " << i;
1240  if (_recPhotonSelector->operator()(cols->photons->at(i))) {
1241  reco::LeafCandidate m(0, cols->photons->at(i).p4(), cols->photons->at(i).vertex(), objType, 0, true);
1242  matches->push_back(m);
1243  }
1244  }
1245  } else if (objType == EVTColContainer::PFMET) {
1249  for (size_t i = 0; i < cols->pfMETs->size(); i++) {
1250  LogDebug("ExoticaValidation") << "Inserting PFMET " << i;
1251  if (_recPFMETSelector->operator()(cols->pfMETs->at(i))) {
1252  reco::LeafCandidate m(0, cols->pfMETs->at(i).p4(), cols->pfMETs->at(i).vertex(), objType, 0, true);
1253  matches->push_back(m);
1254  if (i == 0)
1255  theSumEt[objType] = cols->pfMETs->at(i).sumEt();
1256  }
1257  }
1258  } else if (objType == EVTColContainer::PFMHT) {
1259  for (size_t i = 0; i < cols->pfMHTs->size(); i++) {
1260  LogDebug("ExoticaValidation") << "Inserting PFMHT " << i;
1261  if (_recPFMHTSelector->operator()(cols->pfMHTs->at(i))) {
1262  reco::LeafCandidate m(0, cols->pfMHTs->at(i).p4(), cols->pfMHTs->at(i).vertex(), objType, 0, true);
1263  matches->push_back(m);
1264  if (i == 0)
1265  theSumEt[objType] = cols->pfMHTs->at(i).sumEt();
1266  }
1267  }
1268  } else if (objType == EVTColContainer::GENMET) {
1269  for (size_t i = 0; i < cols->genMETs->size(); i++) {
1270  LogDebug("ExoticaValidation") << "Inserting GENMET " << i;
1271  if (_genMETSelector->operator()(cols->genMETs->at(i))) {
1272  reco::LeafCandidate m(0, cols->genMETs->at(i).p4(), cols->genMETs->at(i).vertex(), objType, 0, true);
1273  matches->push_back(m);
1274  if (i == 0)
1275  theSumEt[objType] = cols->genMETs->at(i).sumEt();
1276  }
1277  }
1278  } else if (objType == EVTColContainer::CALOMET) {
1279  for (size_t i = 0; i < cols->caloMETs->size(); i++) {
1280  LogDebug("ExoticaValidation") << "Inserting CALOMET " << i;
1281  if (_recCaloMETSelector->operator()(cols->caloMETs->at(i))) {
1282  reco::LeafCandidate m(0, cols->caloMETs->at(i).p4(), cols->caloMETs->at(i).vertex(), objType, 0, true);
1283  matches->push_back(m);
1284  if (i == 0)
1285  theSumEt[objType] = cols->caloMETs->at(i).sumEt();
1286  }
1287  }
1288  } else if (objType == EVTColContainer::CALOMHT) {
1289  for (size_t i = 0; i < cols->caloMHTs->size(); i++) {
1290  LogDebug("ExoticaValidation") << "Inserting CaloMHT " << i;
1291  if (_recCaloMHTSelector->operator()(cols->caloMHTs->at(i))) {
1292  reco::LeafCandidate m(0, cols->caloMHTs->at(i).p4(), cols->caloMHTs->at(i).vertex(), objType, 0, true);
1293  matches->push_back(m);
1294  if (i == 0)
1295  theSumEt[objType] = cols->caloMHTs->at(i).sumEt();
1296  }
1297  }
1298  } else if (objType == EVTColContainer::PFTAU) {
1299  for (size_t i = 0; i < cols->pfTaus->size(); i++) {
1300  LogDebug("ExoticaValidation") << "Inserting PFtau " << i;
1301  if (_recPFTauSelector->operator()(cols->pfTaus->at(i))) {
1302  reco::LeafCandidate m(0, cols->pfTaus->at(i).p4(), cols->pfTaus->at(i).vertex(), objType, 0, true);
1303  matches->push_back(m);
1304  }
1305  }
1306  } else if (objType == EVTColContainer::PFJET) {
1307  for (size_t i = 0; i < cols->pfJets->size(); i++) {
1308  LogDebug("ExoticaValidation") << "Inserting jet " << i;
1309  if (_recPFJetSelector->operator()(cols->pfJets->at(i))) {
1310  reco::LeafCandidate m(0, cols->pfJets->at(i).p4(), cols->pfJets->at(i).vertex(), objType, 0, true);
1311  matches->push_back(m);
1312  }
1313  }
1314  } else if (objType == EVTColContainer::CALOJET) {
1315  for (size_t i = 0; i < cols->caloJets->size(); i++) {
1316  LogDebug("ExoticaValidation") << "Inserting jet " << i;
1317  if (_recCaloJetSelector->operator()(cols->caloJets->at(i))) {
1318  reco::LeafCandidate m(0, cols->caloJets->at(i).p4(), cols->caloJets->at(i).vertex(), objType, 0, true);
1319  matches->push_back(m);
1320  }
1321  }
1322  }
1323 
1324  /* else
1325  {
1326  FIXME: ERROR NOT IMPLEMENTED
1327  }*/
1328 }
1329 
1331  // Dump trigger results
1332  std::stringstream log;
1333  log << std::endl;
1334  log << "====================================================================="
1335  "======"
1336  << std::endl;
1337  log << " Trigger Results ( " << _analysisname << " ) " << std::endl;
1338  log << "====================================================================="
1339  "======"
1340  << std::endl;
1341  log << std::setw(18) << "# of passed events : HLT path names" << std::endl;
1342  log << "-------------------:-------------------------------------------------"
1343  "------"
1344  << std::endl;
1345  for (std::map<std::string, int>::iterator it = _triggerCounter.begin(); it != _triggerCounter.end(); ++it) {
1346  log << std::setw(18) << it->second << " : " << it->first << std::endl;
1347  }
1348  log << "====================================================================="
1349  "======"
1350  << std::endl;
1351  LogDebug("ExoticaValidation") << log.str().data();
1352 }
const std::vector< reco::Muon > * muons
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
bool accept() const
Has at least one path accepted the event?
StringCutObjectSelector< reco::Track > * _recMuonTrkSelector
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
const std::vector< unsigned int > getObjectsType(const std::string &hltpath) const
closes analyze method
unsigned int _minCandidates
The minimum number of reco/gen candidates needed by the analysis.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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 Point & position() const
position
Definition: BeamSpot.h:59
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
const std::vector< reco::CaloMET > * caloMETs
std::vector< reco::GenMET > GenMETCollection
collection of GenMET objects
std::map< unsigned int, std::string > _genCut
gen/rec objects cuts
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool exists(std::string const &parameterName) const
checks if a parameter exists
T const * product() const
Definition: Handle.h:70
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< HLTExoticaPlotter > _plotters
The plotters: managers of each hlt path where the plots are done.
StringCutObjectSelector< reco::CaloJet > * _recCaloJetSelector
StringCutObjectSelector< reco::GenMET > * _genMETSelector
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
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
void analyze(const edm::Event &iEvent, const edm::EventSetup &iEventSetup, EVTColContainer *cols)
Log< level::Error, false > LogError
StringCutObjectSelector< reco::MET > * _recMETSelector
edm::EDGetTokenT< edm::TriggerResults > _trigResultsToken
__host__ __device__ VT * co
Definition: prefixScan.h:47
std::vector< reco::MET > METCollection
collection of MET objects
Definition: METCollection.h:22
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
#define LogTrace(id)
std::map< unsigned int, std::string > _genCut_leading
gen/rec pt-leading objects cuts
StringCutObjectSelector< reco::PFJet > * _recPFJetSelector
T getUntrackedParameter(std::string const &, T const &) const
U second(std::pair< T, U > const &p)
double x0() const
x coordinate
Definition: BeamSpot.h:61
std::map< std::string, int > _triggerCounter
counting HLT passed events
std::map< unsigned int, edm::InputTag > _recLabels
StringCutObjectSelector< reco::GsfElectron > * _recElecSelector
std::map< unsigned int, std::string > _recCut_leading
const std::vector< reco::PFMET > * pfMHTs
int iEvent
Definition: GenABIO.cc:224
void insertCandidates(const unsigned int &objtype, const EVTColContainer *col, std::vector< reco::LeafCandidate > *matches, std::map< int, double > &theSumEt, std::map< int, std::vector< const reco::Track *>> &trkObjs)
StringCutObjectSelector< reco::Muon > * _recMuonSelector
static constexpr int verbose
const std::vector< reco::GenMET > * genMETs
edm::ParameterSet _pset
Internal, working copy of the PSet passed from above.
const reco::BeamSpot * bs
void subAnalysisBookHistos(DQMStore::IBooker &iBooker, const edm::Run &iRun, const edm::EventSetup &iSetup)
Entry const & retrieve(char const *) const
std::vector< double > _parametersEta
Some kinematical parameters.
std::map< unsigned int, std::string > _recCut
std::vector< double > _parametersDxy
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
StringCutObjectSelector< reco::Track > * _recTrackSelector
const std::vector< reco::PFJet > * pfJets
HLTConfigProvider _hltConfig
Interface to the HLT information.
const std::vector< reco::Track > * tracks
const std::vector< reco::Photon > * photons
~HLTExoticaSubAnalysis()
End Constructor.
Definition: value.py:1
double y0() const
y coordinate
Definition: BeamSpot.h:63
std::vector< std::string > _hltPathsToCheck
The hlt paths to check for.
StringCutObjectSelector< reco::CaloMET > * _recCaloMHTSelector
std::string _hltProcessName
The labels of the object collections to be used in this analysis.
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:57
Transform3DPJ::Vector XYZVector
std::vector< reco::CaloMET > CaloMETCollection
collection of CaloMET objects
void registerConsumes(edm::ConsumesCollector &consCollector)
Registers consumption of objects.
void getHandlesToObjects(const edm::Event &iEvent, EVTColContainer *col)
Gets the collections themselves.
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
StringCutObjectSelector< reco::PFMET > * _recPFMETSelector
std::string _analysisname
The name of this sub-analysis.
StringCutObjectSelector< reco::Photon > * _recPhotonSelector
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
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)
const std::vector< reco::GsfElectron > * electrons
const std::vector< std::string > & triggerNames() const
names of trigger paths
std::vector< double > _parametersTurnOn
bool isValid() const
Definition: HandleBase.h:70
std::map< unsigned int, edm::EDGetToken > _tokens
std::map< std::string, MonitorElement * > _elements
Structure of the MonitorElements.
StringCutObjectSelector< reco::CaloMET > * _recCaloMETSelector
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
col
Definition: cuy.py:1009
const std::vector< reco::CaloMET > * caloMHTs
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.
Log< level::Warning, false > LogWarning
std::vector< double > _parametersTurnOnSumEt
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
const std::vector< reco::PFMET > * pfMETs
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::set< std::string > _hltPaths
The hlt paths found in the hltConfig.
static const std::string getTypeString(const unsigned int &objtype)
Tranform types into strings.
const edm::TriggerResults * triggerResults
StringCutObjectSelector< reco::PFMET > * _recPFMHTSelector
static std::string const source
Definition: EdmProvDump.cc:49
edm::EDGetTokenT< reco::BeamSpot > _bsToken
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:45
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.
#define LogDebug(id)