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