CMS 3D CMS Logo

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