CMS 3D CMS Logo

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  for (size_t j = 0; (j != matchesReco.size()) && isPassedLeadingCut; ++j) {
663  const unsigned int objType = matchesReco[j].pdgId();
664  // std::cout << "(4) Gonna call with " << objType << std::endl;
665  const std::string objTypeStr = EVTColContainer::getTypeString(objType);
666 
667  float pt = matchesReco[j].pt();
668 
669  if (countobjects[objType] == 0) {
670  this->fillHist("rec", objTypeStr, "MaxPt1", pt);
671  ++(countobjects[objType]);
672  ++counttotal;
673  } else if (countobjects[objType] == 1 && !_drop_pt2) {
674  if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
675  this->fillHist("rec", objTypeStr, "MaxPt2", pt);
676  }
677  ++(countobjects[objType]);
678  ++counttotal;
679  } else if (countobjects[objType] == 2 && !_drop_pt3) {
680  if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
681  this->fillHist("rec", objTypeStr, "MaxPt3", pt);
682  }
683  ++(countobjects[objType]);
684  ++counttotal;
685  } else {
686  // Already the minimum three objects has been filled, get out...
687  if (counttotal == totalobjectssize) {
688  size_t max_size = matchesReco.size();
689  for (size_t jj = j; jj < max_size; jj++) {
690  matchesReco.erase(matchesReco.end());
691  }
692  break;
693  }
694  }
695 
696  float eta = matchesReco[j].eta();
697  float phi = matchesReco[j].phi();
698 
699  if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
700  this->fillHist("rec", objTypeStr, "Eta", eta);
701  this->fillHist("rec", objTypeStr, "Phi", phi);
702  } else {
703  this->fillHist("rec", objTypeStr, "SumEt", theSumEt[objType]);
704  }
705 
706  if (trkObjs[objType].size() >= j + 1) {
707  float dxyRec = trkObjs[objType].at(j)->dxy(cols->bs->position());
708  this->fillHist("rec", objTypeStr, "Dxy", dxyRec);
709  dxys.push_back(dxyRec);
710  }
711 
712  } // Closes loop in reco
713 
714  // LogDebug("ExoticaValidation") << " deleting
715  // countobjects"; delete countobjects;
716 
717  // Calling to the plotters analysis (where the evaluation of the different
718  // trigger paths are done)
719  // const std::string source = "reco";
720  for (std::vector<HLTExoticaPlotter>::iterator an = _plotters.begin(); an != _plotters.end(); ++an) {
721  const std::string hltPath = _shortpath2long[an->gethltpath()];
722  const bool ispassTrigger = cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
723  LogDebug("ExoticaValidation") << " preparing to call the plotters analysis";
724  an->analyze(ispassTrigger, "rec", matchesReco, theSumEt, dxys);
725  LogDebug("ExoticaValidation") << " called the plotter";
726  }
727  }
728 
729 }
730 
731 // Return the objects (muons,electrons,photons,...) needed by a hlt path.
732 const std::vector<unsigned int> HLTExoticaSubAnalysis::getObjectsType(const std::string &hltPath) const {
733  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getObjectsType()";
734 
735  static const unsigned int objSize = 15;
736  static const unsigned int objtriggernames[] = {EVTColContainer::MUON,
751 
752  std::set<unsigned int> objsType;
753  // The object to deal has to be entered via the config .py
754  for (unsigned int i = 0; i < objSize; ++i) {
755  // std::cout << "(5) Gonna call with " << objtriggernames[i] << std::endl;
756  std::string objTypeStr = EVTColContainer::getTypeString(objtriggernames[i]);
757  // Check if it is needed this object for this trigger
758  if (!TString(hltPath).Contains(objTypeStr)) {
759  continue;
760  }
761 
762  objsType.insert(objtriggernames[i]);
763  }
764 
765  return std::vector<unsigned int>(objsType.begin(), objsType.end());
766 }
767 
768 // Booking the maps: recLabels and genParticle selectors
770  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getNamesOfObjects()";
771 
772  if (anpset.exists("recMuonLabel")) {
773  _recLabels[EVTColContainer::MUON] = anpset.getParameter<edm::InputTag>("recMuonLabel");
775  }
776  if (anpset.exists("recMuonTrkLabel")) {
777  _recLabels[EVTColContainer::MUTRK] = anpset.getParameter<edm::InputTag>("recMuonTrkLabel");
779  }
780  if (anpset.exists("recTrackLabel")) {
781  _recLabels[EVTColContainer::TRACK] = anpset.getParameter<edm::InputTag>("recTrackLabel");
783  }
784  if (anpset.exists("recElecLabel")) {
785  _recLabels[EVTColContainer::ELEC] = anpset.getParameter<edm::InputTag>("recElecLabel");
787  }
788  if (anpset.exists("recPhotonLabel")) {
789  _recLabels[EVTColContainer::PHOTON] = anpset.getParameter<edm::InputTag>("recPhotonLabel");
791  }
792  if (anpset.exists("recMETLabel")) {
793  _recLabels[EVTColContainer::MET] = anpset.getParameter<edm::InputTag>("recMETLabel");
795  }
796  if (anpset.exists("recPFMETLabel")) {
797  _recLabels[EVTColContainer::PFMET] = anpset.getParameter<edm::InputTag>("recPFMETLabel");
799  }
800  if (anpset.exists("recPFMHTLabel")) {
801  _recLabels[EVTColContainer::PFMHT] = anpset.getParameter<edm::InputTag>("recPFMHTLabel");
803  }
804  if (anpset.exists("genMETLabel")) {
807  }
808  if (anpset.exists("recCaloMETLabel")) {
809  _recLabels[EVTColContainer::CALOMET] = anpset.getParameter<edm::InputTag>("recCaloMETLabel");
811  }
812  if (anpset.exists("recCaloMHTLabel")) {
813  _recLabels[EVTColContainer::CALOMHT] = anpset.getParameter<edm::InputTag>("recCaloMHTLabel");
815  }
816  if (anpset.exists("hltMETLabel")) {
819  }
820  if (anpset.exists("l1METLabel")) {
823  }
824  if (anpset.exists("recPFTauLabel")) {
825  _recLabels[EVTColContainer::PFTAU] = anpset.getParameter<edm::InputTag>("recPFTauLabel");
827  }
828  if (anpset.exists("recPFJetLabel")) {
829  _recLabels[EVTColContainer::PFJET] = anpset.getParameter<edm::InputTag>("recPFJetLabel");
831  }
832  if (anpset.exists("recCaloJetLabel")) {
833  _recLabels[EVTColContainer::CALOJET] = anpset.getParameter<edm::InputTag>("recCaloJetLabel");
835  }
836 
837  if (_recLabels.empty()) {
838  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::getNamesOfObjects, "
839  << "Not included any object (recMuonLabel, recElecLabel, ...) "
840  << "in the analysis " << _analysisname;
841  return;
842  }
843 }
844 
845 // Register consumption of objects.
846 // I have chosen to centralize all consumes() calls here.
848  // Register that we are getting genParticles
850 
851  // Register that we are getting the trigger results
853 
854  // Register beamspot
856 
857  // Loop over _recLabels, see what we need, and register.
858  // Then save the registered token in _tokens.
859  // Remember: _recLabels is a map<uint, edm::InputTag>
860  // Remember: _tokens is a map<uint, edm::EDGetToken>
861  LogDebug("ExoticaValidation") << "We have got " << _recLabels.size() << "recLabels";
862  for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
863  if (it->first == EVTColContainer::MUON) {
864  edm::EDGetTokenT<reco::MuonCollection> particularToken = iC.consumes<reco::MuonCollection>(it->second);
865  edm::EDGetToken token(particularToken);
866  _tokens[it->first] = token;
867  } else if (it->first == EVTColContainer::MUTRK) {
869  edm::EDGetToken token(particularToken);
870  _tokens[it->first] = token;
871  } else if (it->first == EVTColContainer::TRACK) {
873  edm::EDGetToken token(particularToken);
874  _tokens[it->first] = token;
875  } else if (it->first == EVTColContainer::ELEC) {
877  iC.consumes<reco::GsfElectronCollection>(it->second);
878  edm::EDGetToken token(particularToken);
879  _tokens[it->first] = token;
880  } else if (it->first == EVTColContainer::PHOTON) {
882  edm::EDGetToken token(particularToken);
883  _tokens[it->first] = token;
884  } else if (it->first == EVTColContainer::MET) {
885  edm::EDGetTokenT<reco::METCollection> particularToken = iC.consumes<reco::METCollection>(it->second);
886  edm::EDGetToken token(particularToken);
887  _tokens[it->first] = token;
888  } else if (it->first == EVTColContainer::PFMET) {
890  edm::EDGetToken token(particularToken);
891  _tokens[it->first] = token;
892  } else if (it->first == EVTColContainer::PFMHT) {
894  edm::EDGetToken token(particularToken);
895  _tokens[it->first] = token;
896  } else if (it->first == EVTColContainer::GENMET) {
898  edm::EDGetToken token(particularToken);
899  _tokens[it->first] = token;
900  } else if (it->first == EVTColContainer::CALOMET) {
902  edm::EDGetToken token(particularToken);
903  _tokens[it->first] = token;
904  } else if (it->first == EVTColContainer::CALOMHT) {
906  edm::EDGetToken token(particularToken);
907  _tokens[it->first] = token;
908  } else if (it->first == EVTColContainer::L1MET) {
911  edm::EDGetToken token(particularToken);
912  _tokens[it->first] = token;
913  } else if (it->first == EVTColContainer::PFTAU) {
915  edm::EDGetToken token(particularToken);
916  _tokens[it->first] = token;
917  } else if (it->first == EVTColContainer::PFJET) {
919  edm::EDGetToken token(particularToken);
920  _tokens[it->first] = token;
921  } else if (it->first == EVTColContainer::CALOJET) {
923  edm::EDGetToken token(particularToken);
924  _tokens[it->first] = token;
925  } else {
926  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::registerConsumes"
927  << " NOT IMPLEMENTED (yet) ERROR: '" << it->second.label() << "'";
928  }
929  }
930 }
931 
932 // Setting the collections of objects in EVTColContainer
934  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getHandlesToObjects()";
935 
936  if (!col->isCommonInit()) {
937  // Extract the trigger results (path info, pass,...)
939  iEvent.getByToken(_trigResultsToken, trigResults);
940  if (trigResults.isValid()) {
941  col->triggerResults = trigResults.product();
942  LogDebug("ExoticaValidation") << "Added handle to triggerResults";
943  }
944 
945  // Extract the genParticles
947  iEvent.getByToken(_genParticleToken, genPart);
948  if (genPart.isValid()) {
949  col->genParticles = genPart.product();
950  LogDebug("ExoticaValidation") << "Added handle to genParticles";
951  }
952 
953  // BeamSpot for dxy
955  iEvent.getByToken(_bsToken, bsHandle);
956  if (bsHandle.isValid()) {
957  col->bs = bsHandle.product();
958  }
959  }
960 
961  // Loop over the tokens and extract all other objects
962  LogDebug("ExoticaValidation") << "We have got " << _tokens.size() << "tokens";
963  for (std::map<unsigned int, edm::EDGetToken>::iterator it = _tokens.begin(); it != _tokens.end(); ++it) {
964  if (it->first == EVTColContainer::MUON) {
966  iEvent.getByToken(it->second, theHandle);
967  if (theHandle.isValid())
968  col->set(theHandle.product());
969  } else if (it->first == EVTColContainer::MUTRK) {
971  iEvent.getByToken(it->second, theHandle);
972  if (theHandle.isValid())
973  col->set(theHandle.product());
974  } else if (it->first == EVTColContainer::TRACK) {
976  iEvent.getByToken(it->second, theHandle);
977  if (theHandle.isValid())
978  col->set(theHandle.product());
979  } else if (it->first == EVTColContainer::ELEC) {
981  iEvent.getByToken(it->second, theHandle);
982  if (theHandle.isValid())
983  col->set(theHandle.product());
984  } else if (it->first == EVTColContainer::PHOTON) {
986  iEvent.getByToken(it->second, theHandle);
987  if (theHandle.isValid())
988  col->set(theHandle.product());
989  } else if (it->first == EVTColContainer::MET) {
991  iEvent.getByToken(it->second, theHandle);
992  if (theHandle.isValid())
993  col->set(theHandle.product());
994  } else if (it->first == EVTColContainer::PFMET) {
996  iEvent.getByToken(it->second, theHandle);
997  if (theHandle.isValid())
998  col->set(theHandle.product());
999  } else if (it->first == EVTColContainer::PFMHT) {
1001  iEvent.getByToken(it->second, theHandle);
1002  if (theHandle.isValid())
1003  col->setPFMHT(theHandle.product());
1004  } else if (it->first == EVTColContainer::GENMET) {
1006  iEvent.getByToken(it->second, theHandle);
1007  if (theHandle.isValid())
1008  col->set(theHandle.product());
1009  } else if (it->first == EVTColContainer::CALOMET) {
1011  iEvent.getByToken(it->second, theHandle);
1012  if (theHandle.isValid())
1013  col->set(theHandle.product());
1014  } else if (it->first == EVTColContainer::CALOMHT) {
1016  iEvent.getByToken(it->second, theHandle);
1017  if (theHandle.isValid())
1018  col->setCaloMHT(theHandle.product());
1019  } else if (it->first == EVTColContainer::L1MET) {
1021  iEvent.getByToken(it->second, theHandle);
1022  if (theHandle.isValid())
1023  col->set(theHandle.product());
1024  } else if (it->first == EVTColContainer::PFTAU) {
1026  iEvent.getByToken(it->second, theHandle);
1027  if (theHandle.isValid())
1028  col->set(theHandle.product());
1029  } else if (it->first == EVTColContainer::PFJET) {
1031  iEvent.getByToken(it->second, theHandle);
1032  if (theHandle.isValid())
1033  col->set(theHandle.product());
1034  } else if (it->first == EVTColContainer::CALOJET) {
1036  iEvent.getByToken(it->second, theHandle);
1037  if (theHandle.isValid())
1038  col->set(theHandle.product());
1039  } else {
1040  edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::getHandlesToObjects "
1041  << " NOT IMPLEMENTED (yet) ERROR: '" << it->first << "'";
1042  }
1043  }
1044 }
1045 
1046 // Booking the histograms, and putting them in DQM
1048  const std::string &source,
1049  const std::string &objType,
1050  const std::string &variable) {
1051  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::bookHist()";
1052  std::string sourceUpper = source;
1053  sourceUpper[0] = std::toupper(sourceUpper[0]);
1054  std::string name = source + objType + variable;
1055  TH1F *h = nullptr;
1056 
1057  if (variable.find("SumEt") != std::string::npos) {
1058  std::string title = "Sum ET of " + sourceUpper + " " + objType;
1059  const size_t nBins = _parametersTurnOnSumEt.size() - 1;
1060  float *edges = new float[nBins + 1];
1061  for (size_t i = 0; i < nBins + 1; i++) {
1062  edges[i] = _parametersTurnOnSumEt[i];
1063  }
1064  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
1065  delete[] edges;
1066  }
1067 
1068  else if (variable.find("Dxy") != std::string::npos) {
1069  std::string title = "Dxy " + sourceUpper + " " + objType;
1070  int nBins = _parametersDxy[0];
1071  double min = _parametersDxy[1];
1072  double max = _parametersDxy[2];
1073  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
1074  }
1075 
1076  else if (variable.find("MaxPt") != std::string::npos) {
1077  std::string desc = (variable == "MaxPt1") ? "Leading" : "Next-to-Leading";
1078  std::string title = "pT of " + desc + " " + sourceUpper + " " + objType;
1079  const size_t nBins = _parametersTurnOn.size() - 1;
1080  float *edges = new float[nBins + 1];
1081  for (size_t i = 0; i < nBins + 1; i++) {
1082  edges[i] = _parametersTurnOn[i];
1083  }
1084  h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
1085  delete[] edges;
1086  }
1087 
1088  else {
1089  std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
1090  std::string title = symbol + " of " + sourceUpper + " " + objType;
1091  std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
1092  int nBins = (int)params[0];
1093  double min = params[1];
1094  double max = params[2];
1095  h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
1096  }
1097 
1098  h->Sumw2();
1099  // This is the trick, that takes a normal TH1F and puts it in in the DQM
1100  // machinery. Seems to be easy!
1101  // Updated to use the new iBooker machinery.
1102  _elements[name] = iBooker.book1D(name, h);
1103  delete h;
1104 }
1105 
1106 // Fill the histograms
1108  const std::string &objType,
1109  const std::string &variable,
1110  const float &value) {
1111  std::string sourceUpper = source;
1112  sourceUpper[0] = toupper(sourceUpper[0]);
1113  std::string name = source + objType + variable;
1114 
1115  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::fillHist() " << name << " " << value;
1116  _elements[name]->Fill(value);
1117  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::fillHist() " << name << " worked";
1118 }
1119 
1120 // Initialize the selectors
1121 void HLTExoticaSubAnalysis::initSelector(const unsigned int &objtype) {
1122  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::initSelector()";
1123 
1124  if (objtype == EVTColContainer::MUON && _recMuonSelector == nullptr) {
1126  } else if (objtype == EVTColContainer::MUTRK && _recMuonTrkSelector == nullptr) {
1128  } else if (objtype == EVTColContainer::TRACK && _recTrackSelector == nullptr) {
1130  } else if (objtype == EVTColContainer::ELEC && _recElecSelector == nullptr) {
1132  } else if (objtype == EVTColContainer::PHOTON && _recPhotonSelector == nullptr) {
1134  } else if (objtype == EVTColContainer::MET && _recMETSelector == nullptr) {
1136  } else if (objtype == EVTColContainer::PFMET && _recPFMETSelector == nullptr) {
1138  } else if (objtype == EVTColContainer::PFMHT && _recPFMHTSelector == nullptr) {
1140  } else if (objtype == EVTColContainer::GENMET && _genMETSelector == nullptr) {
1142  } else if (objtype == EVTColContainer::CALOMET && _recCaloMETSelector == nullptr) {
1144  } else if (objtype == EVTColContainer::CALOMHT && _recCaloMHTSelector == nullptr) {
1146  } else if (objtype == EVTColContainer::L1MET && _l1METSelector == nullptr) {
1148  } else if (objtype == EVTColContainer::PFTAU && _recPFTauSelector == nullptr) {
1150  } else if (objtype == EVTColContainer::PFJET && _recPFJetSelector == nullptr) {
1152  } else if (objtype == EVTColContainer::CALOJET && _recCaloJetSelector == nullptr) {
1154  }
1155  /* else
1156  {
1157  FIXME: ERROR NOT IMPLEMENTED
1158  }*/
1159 }
1160 
1161 // Insert the HLT candidates
1163  const EVTColContainer *cols,
1164  std::vector<reco::LeafCandidate> *matches,
1165  std::map<int, double> &theSumEt,
1166  std::map<int, std::vector<const reco::Track *>> &trkObjs) {
1167  LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::insertCandidates()";
1168 
1169  theSumEt[objType] = -1;
1170 
1171  if (objType == EVTColContainer::MUON) {
1172  for (size_t i = 0; i < cols->muons->size(); i++) {
1173  LogDebug("ExoticaValidation") << "Inserting muon " << i;
1174  if (_recMuonSelector->operator()(cols->muons->at(i))) {
1175  reco::LeafCandidate m(0, cols->muons->at(i).p4(), cols->muons->at(i).vertex(), objType, 0, true);
1176  matches->push_back(m);
1177 
1178  // for making dxy plots
1179  trkObjs[objType].push_back(cols->muons->at(i).bestTrack());
1180  }
1181  }
1182  } else if (objType == EVTColContainer::MUTRK) {
1183  for (size_t i = 0; i < cols->tracks->size(); i++) {
1184  LogDebug("ExoticaValidation") << "Inserting muonTrack " << i;
1185  if (_recMuonTrkSelector->operator()(cols->tracks->at(i))) {
1186  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>> mom4;
1187  ROOT::Math::XYZVector mom3 = cols->tracks->at(i).momentum();
1188  mom4.SetXYZT(mom3.x(), mom3.y(), mom3.z(), mom3.r());
1189  reco::LeafCandidate m(0, mom4, cols->tracks->at(i).vertex(), objType, 0, true);
1190  matches->push_back(m);
1191 
1192  // for making dxy plots
1193  trkObjs[objType].push_back(&cols->tracks->at(i));
1194  }
1195  }
1196  } else if (objType == EVTColContainer::TRACK) {
1197  for (size_t i = 0; i < cols->tracks->size(); i++) {
1198  LogDebug("ExoticaValidation") << "Inserting Track " << i;
1199  if (_recTrackSelector->operator()(cols->tracks->at(i))) {
1200  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>> mom4;
1201  ROOT::Math::XYZVector mom3 = cols->tracks->at(i).momentum();
1202  mom4.SetXYZT(mom3.x(), mom3.y(), mom3.z(), mom3.r());
1203  reco::LeafCandidate m(0, mom4, cols->tracks->at(i).vertex(), objType, 0, true);
1204  matches->push_back(m);
1205  }
1206  }
1207  } else if (objType == EVTColContainer::ELEC) {
1208  for (size_t i = 0; i < cols->electrons->size(); i++) {
1209  LogDebug("ExoticaValidation") << "Inserting electron " << i;
1210  if (_recElecSelector->operator()(cols->electrons->at(i))) {
1211  reco::LeafCandidate m(0, cols->electrons->at(i).p4(), cols->electrons->at(i).vertex(), objType, 0, true);
1212  matches->push_back(m);
1213 
1214  // for making dxy plots
1215  trkObjs[objType].push_back(cols->electrons->at(i).bestTrack());
1216  }
1217  }
1218  } else if (objType == EVTColContainer::PHOTON) {
1219  for (size_t i = 0; i < cols->photons->size(); i++) {
1220  LogDebug("ExoticaValidation") << "Inserting photon " << i;
1221  if (_recPhotonSelector->operator()(cols->photons->at(i))) {
1222  reco::LeafCandidate m(0, cols->photons->at(i).p4(), cols->photons->at(i).vertex(), objType, 0, true);
1223  matches->push_back(m);
1224  }
1225  }
1226  } else if (objType == EVTColContainer::PFMET) {
1230  for (size_t i = 0; i < cols->pfMETs->size(); i++) {
1231  LogDebug("ExoticaValidation") << "Inserting PFMET " << i;
1232  if (_recPFMETSelector->operator()(cols->pfMETs->at(i))) {
1233  reco::LeafCandidate m(0, cols->pfMETs->at(i).p4(), cols->pfMETs->at(i).vertex(), objType, 0, true);
1234  matches->push_back(m);
1235  if (i == 0)
1236  theSumEt[objType] = cols->pfMETs->at(i).sumEt();
1237  }
1238  }
1239  } else if (objType == EVTColContainer::PFMHT) {
1240  for (size_t i = 0; i < cols->pfMHTs->size(); i++) {
1241  LogDebug("ExoticaValidation") << "Inserting PFMHT " << i;
1242  if (_recPFMHTSelector->operator()(cols->pfMHTs->at(i))) {
1243  reco::LeafCandidate m(0, cols->pfMHTs->at(i).p4(), cols->pfMHTs->at(i).vertex(), objType, 0, true);
1244  matches->push_back(m);
1245  if (i == 0)
1246  theSumEt[objType] = cols->pfMHTs->at(i).sumEt();
1247  }
1248  }
1249  } else if (objType == EVTColContainer::GENMET) {
1250  for (size_t i = 0; i < cols->genMETs->size(); i++) {
1251  LogDebug("ExoticaValidation") << "Inserting GENMET " << i;
1252  if (_genMETSelector->operator()(cols->genMETs->at(i))) {
1253  reco::LeafCandidate m(0, cols->genMETs->at(i).p4(), cols->genMETs->at(i).vertex(), objType, 0, true);
1254  matches->push_back(m);
1255  if (i == 0)
1256  theSumEt[objType] = cols->genMETs->at(i).sumEt();
1257  }
1258  }
1259  } else if (objType == EVTColContainer::CALOMET) {
1260  for (size_t i = 0; i < cols->caloMETs->size(); i++) {
1261  LogDebug("ExoticaValidation") << "Inserting CALOMET " << i;
1262  if (_recCaloMETSelector->operator()(cols->caloMETs->at(i))) {
1263  reco::LeafCandidate m(0, cols->caloMETs->at(i).p4(), cols->caloMETs->at(i).vertex(), objType, 0, true);
1264  matches->push_back(m);
1265  if (i == 0)
1266  theSumEt[objType] = cols->caloMETs->at(i).sumEt();
1267  }
1268  }
1269  } else if (objType == EVTColContainer::CALOMHT) {
1270  for (size_t i = 0; i < cols->caloMHTs->size(); i++) {
1271  LogDebug("ExoticaValidation") << "Inserting CaloMHT " << i;
1272  if (_recCaloMHTSelector->operator()(cols->caloMHTs->at(i))) {
1273  reco::LeafCandidate m(0, cols->caloMHTs->at(i).p4(), cols->caloMHTs->at(i).vertex(), objType, 0, true);
1274  matches->push_back(m);
1275  if (i == 0)
1276  theSumEt[objType] = cols->caloMHTs->at(i).sumEt();
1277  }
1278  }
1279  } else if (objType == EVTColContainer::L1MET) {
1280  for (size_t i = 0; i < cols->l1METs->size(); i++) {
1281  LogDebug("ExoticaValidation") << "Inserting L1MET " << i;
1282  if (_l1METSelector->operator()(cols->l1METs->at(i))) {
1283  reco::LeafCandidate m(0, cols->l1METs->at(i).p4(), cols->l1METs->at(i).vertex(), objType, 0, true);
1284  matches->push_back(m);
1285  if (i == 0)
1286  theSumEt[objType] = cols->l1METs->at(i).etTotal();
1287  }
1288  }
1289  } else if (objType == EVTColContainer::PFTAU) {
1290  for (size_t i = 0; i < cols->pfTaus->size(); i++) {
1291  LogDebug("ExoticaValidation") << "Inserting PFtau " << i;
1292  if (_recPFTauSelector->operator()(cols->pfTaus->at(i))) {
1293  reco::LeafCandidate m(0, cols->pfTaus->at(i).p4(), cols->pfTaus->at(i).vertex(), objType, 0, true);
1294  matches->push_back(m);
1295  }
1296  }
1297  } else if (objType == EVTColContainer::PFJET) {
1298  for (size_t i = 0; i < cols->pfJets->size(); i++) {
1299  LogDebug("ExoticaValidation") << "Inserting jet " << i;
1300  if (_recPFJetSelector->operator()(cols->pfJets->at(i))) {
1301  reco::LeafCandidate m(0, cols->pfJets->at(i).p4(), cols->pfJets->at(i).vertex(), objType, 0, true);
1302  matches->push_back(m);
1303  }
1304  }
1305  } else if (objType == EVTColContainer::CALOJET) {
1306  for (size_t i = 0; i < cols->caloJets->size(); i++) {
1307  LogDebug("ExoticaValidation") << "Inserting jet " << i;
1308  if (_recCaloJetSelector->operator()(cols->caloJets->at(i))) {
1309  reco::LeafCandidate m(0, cols->caloJets->at(i).p4(), cols->caloJets->at(i).vertex(), objType, 0, true);
1310  matches->push_back(m);
1311  }
1312  }
1313  }
1314 
1315  /* else
1316  {
1317  FIXME: ERROR NOT IMPLEMENTED
1318  }*/
1319 }
1320 
1322  // Dump trigger results
1323  std::stringstream log;
1324  log << std::endl;
1325  log << "====================================================================="
1326  "======"
1327  << std::endl;
1328  log << " Trigger Results ( " << _analysisname << " ) " << std::endl;
1329  log << "====================================================================="
1330  "======"
1331  << std::endl;
1332  log << std::setw(18) << "# of passed events : HLT path names" << std::endl;
1333  log << "-------------------:-------------------------------------------------"
1334  "------"
1335  << std::endl;
1336  for (std::map<std::string, int>::iterator it = _triggerCounter.begin(); it != _triggerCounter.end(); ++it) {
1337  log << std::setw(18) << it->second << " : " << it->first << std::endl;
1338  }
1339  log << "====================================================================="
1340  "======"
1341  << std::endl;
1342  LogDebug("ExoticaValidation") << log.str().data();
1343 }
#define LogDebug(id)
size
Write out results.
const std::vector< reco::Muon > * muons
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
StringCutObjectSelector< reco::Track > * _recMuonTrkSelector
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
unsigned int _minCandidates
The minimum number of reco/gen candidates needed by the analysis.
Entry const & retrieve(char const *) const
T getUntrackedParameter(std::string const &, T const &) const
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
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:161
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
const std::vector< reco::CaloMET > * caloMETs
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
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
#define nullptr
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
std::vector< HLTExoticaPlotter > _plotters
The plotters: managers of each hlt path where the plots are done.
bool exists(std::string const &parameterName) const
checks if a parameter exists
StringCutObjectSelector< reco::CaloJet > * _recCaloJetSelector
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)
StringCutObjectSelector< reco::MET > * _recMETSelector
edm::EDGetTokenT< edm::TriggerResults > _trigResultsToken
std::vector< reco::MET > METCollection
collection of MET objects
Definition: METCollection.h:23
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
const std::vector< reco::PFTau > * pfTaus
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::map< unsigned int, std::string > _genCut_leading
gen/rec pt-leading objects cuts
StringCutObjectSelector< reco::PFJet > * _recPFJetSelector
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
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:24
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)
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
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
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
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
T min(T a, T b)
Definition: MathUtil.h:58
bool isValid() const
Definition: HandleBase.h:74
std::vector< std::string > _hltPathsToCheck
The hlt paths to check for.
#define LogTrace(id)
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:74
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:74
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)
StringCutObjectSelector< l1extra::L1EtMissParticle > * _l1METSelector
const std::vector< reco::GsfElectron > * electrons
std::vector< double > _parametersTurnOn
std::map< unsigned int, edm::EDGetToken > _tokens
std::map< std::string, MonitorElement * > _elements
Structure of the MonitorElements.
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:1010
double y0() const
y coordinate
Definition: BeamSpot.h:66
const std::vector< reco::CaloMET > * caloMHTs
edm::EDGetTokenT< reco::GenParticleCollection > _genParticleToken
And also the tokens to get the object collections.
virtual const Point & vertex() const =0
vertex position
const Point & position() const
position
Definition: BeamSpot.h:62
void initSelector(const unsigned int &objtype)
Initializes the selectors of the objects based on which object it is.
std::vector< L1EtMissParticle > L1EtMissParticleCollection
std::vector< double > _parametersTurnOnSumEt
const std::vector< reco::PFMET > * pfMETs
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:47
edm::EDGetTokenT< reco::BeamSpot > _bsToken
StringCutObjectSelector< reco::PFTau > * _recPFTauSelector
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:256
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.
#define constexpr
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.
double x0() const
x coordinate
Definition: BeamSpot.h:64