Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-29 23:10:47

0001 
0002 /** \file HLTExoticaSubAnalysis.cc
0003  */
0004 
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "FWCore/Framework/interface/ConsumesCollector.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/Utilities/interface/TypeID.h"
0009 
0010 #include "CommonTools/Utils/interface/PtComparator.h"
0011 #include "DataFormats/Math/interface/LorentzVector.h"
0012 #include "HLTriggerOffline/Exotica/interface/HLTExoticaSubAnalysis.h"
0013 #include "HLTriggerOffline/Exotica/src/EVTColContainer.cc"
0014 
0015 #include "TPRegexp.h"
0016 #include "TString.h"
0017 
0018 #include "DataFormats/Common/interface/TriggerResults.h"
0019 #include "FWCore/Common/interface/TriggerNames.h"
0020 
0021 #include <algorithm>
0022 #include <set>
0023 
0024 static constexpr int verbose = 0;
0025 
0026 /// Constructor
0027 HLTExoticaSubAnalysis::HLTExoticaSubAnalysis(const edm::ParameterSet &pset,
0028                                              const std::string &analysisname,
0029                                              edm::ConsumesCollector &&consCollector)
0030     : _pset(pset),
0031       _analysisname(analysisname),
0032       _minCandidates(0),
0033       _hltProcessName(pset.getParameter<std::string>("hltProcessName")),
0034       _genParticleLabel(pset.getParameter<std::string>("genParticleLabel")),
0035       _trigResultsLabel("TriggerResults", "", _hltProcessName),
0036       _beamSpotLabel(pset.getParameter<std::string>("beamSpotLabel")),
0037       _parametersEta(pset.getParameter<std::vector<double>>("parametersEta")),
0038       _parametersPhi(pset.getParameter<std::vector<double>>("parametersPhi")),
0039       _parametersTurnOn(pset.getParameter<std::vector<double>>("parametersTurnOn")),
0040       _parametersTurnOnSumEt(pset.getParameter<std::vector<double>>("parametersTurnOnSumEt")),
0041       _parametersDxy(pset.getParameter<std::vector<double>>("parametersDxy")),
0042       _drop_pt2(false),
0043       _drop_pt3(false),
0044       _recMuonSelector(nullptr),
0045       _recMuonTrkSelector(nullptr),
0046       _recTrackSelector(nullptr),
0047       _recElecSelector(nullptr),
0048       _recMETSelector(nullptr),
0049       _recPFMETSelector(nullptr),
0050       _recPFMHTSelector(nullptr),
0051       _genMETSelector(nullptr),
0052       _recCaloMETSelector(nullptr),
0053       _recCaloMHTSelector(nullptr),
0054       _recPFTauSelector(nullptr),
0055       _recPhotonSelector(nullptr),
0056       _recPFJetSelector(nullptr),
0057       _recCaloJetSelector(nullptr) {
0058   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::constructor()";
0059 
0060   // Specific parameters for this analysis
0061   edm::ParameterSet anpset = pset.getParameter<edm::ParameterSet>(analysisname);
0062 
0063   // If this analysis has a particular set of binnings, use it.
0064   // (Taken from the analysis-specific parameter set, of course)
0065   // The "true" in the beginning of _pset.insert() means
0066   // "overwrite the parameter if need be".
0067   if (anpset.exists("parametersTurnOn")) {
0068     _parametersTurnOn = anpset.getParameter<std::vector<double>>("parametersTurnOn");
0069     _pset.insert(true, "parametersTurnOn", anpset.retrieve("parametersTurnOn"));
0070   }
0071   if (anpset.exists("parametersEta")) {
0072     _parametersEta = anpset.getParameter<std::vector<double>>("parametersEta");
0073     _pset.insert(true, "parametersEta", anpset.retrieve("parametersEta"));
0074   }
0075   if (anpset.exists("parametersPhi")) {
0076     _parametersPhi = anpset.getParameter<std::vector<double>>("parametersPhi");
0077     _pset.insert(true, "parametersPhi", anpset.retrieve("parametersPhi"));
0078   }
0079   if (anpset.exists("parametersDxy")) {
0080     _parametersDxy = anpset.getParameter<std::vector<double>>("parametersDxy");
0081     _pset.insert(true, "parametersDxy", anpset.retrieve("parametersDxy"));
0082   }
0083   if (anpset.exists("parametersTurnOnSumEt")) {
0084     _parametersTurnOnSumEt = anpset.getParameter<std::vector<double>>("parametersTurnOnSumEt");
0085     _pset.insert(true, "parametersTurnOnSumEt", anpset.retrieve("parametersTurnOnSumEt"));
0086   }
0087   if (anpset.exists("dropPt2")) {
0088     _drop_pt2 = anpset.getParameter<bool>("dropPt2");
0089     _pset.insert(true, "dropPt2", anpset.retrieve("dropPt2"));
0090   }
0091   if (anpset.exists("dropPt3")) {
0092     _drop_pt3 = anpset.getParameter<bool>("dropPt3");
0093     _pset.insert(true, "dropPt3", anpset.retrieve("dropPt3"));
0094   }
0095 
0096   // Get names of objects that we may want to get from the event.
0097   // Notice that genParticles are dealt with separately.
0098   this->getNamesOfObjects(anpset);
0099 
0100   // Since now we have the names, we should register the consumption
0101   // of objects.
0102   this->registerConsumes(consCollector);
0103 
0104   // Generic objects: Initialization of basic phase space cuts.
0105   for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0106     const std::string objStr = EVTColContainer::getTypeString(it->first);
0107     _genCut[it->first] = pset.getParameter<std::string>(objStr + "_genCut");
0108     _recCut[it->first] = pset.getParameter<std::string>(objStr + "_recCut");
0109     auto const genCutParam = objStr + "_genCut_leading";
0110     if (pset.exists(genCutParam)) {
0111       _genCut_leading[it->first] = pset.getParameter<std::string>(genCutParam);
0112     } else {
0113       _genCut_leading[it->first] = "pt>0";  // no cut
0114     }
0115     auto const recCutParam = objStr + "_recCut_leading";
0116     if (pset.exists(recCutParam)) {
0117       _recCut_leading[it->first] = pset.getParameter<std::string>(recCutParam);
0118     } else {
0119       _recCut_leading[it->first] = "pt>0";  // no cut
0120     }
0121   }
0122 
0123   //--- Updating parameters if has to be modified for this particular specific
0124   // analysis
0125   for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0126     const std::string objStr = EVTColContainer::getTypeString(it->first);
0127 
0128     auto const genCutParam = objStr + "_genCut";
0129     if (anpset.existsAs<std::string>(genCutParam, false)) {
0130       _genCut[it->first] = anpset.getUntrackedParameter<std::string>(genCutParam);
0131     }
0132 
0133     auto const recCutParam = objStr + "_recCut";
0134     if (anpset.existsAs<std::string>(recCutParam, false)) {
0135       _recCut[it->first] = anpset.getUntrackedParameter<std::string>(recCutParam);
0136     }
0137   }
0138 
0139   /// Get the vector of paths to check, for this particular analysis.
0140   _hltPathsToCheck = anpset.getParameter<std::vector<std::string>>("hltPathsToCheck");
0141   /// Get the minimum candidates, for this particular analysis.
0142   _minCandidates = anpset.getParameter<unsigned int>("minCandidates");
0143 
0144 }  /// End Constructor
0145 
0146 HLTExoticaSubAnalysis::~HLTExoticaSubAnalysis() {
0147   for (std::map<unsigned int, StringCutObjectSelector<reco::GenParticle> *>::iterator it = _genSelectorMap.begin();
0148        it != _genSelectorMap.end();
0149        ++it) {
0150     delete it->second;
0151     it->second = nullptr;
0152   }
0153   delete _recMuonSelector;
0154   _recMuonSelector = nullptr;
0155   delete _recMuonTrkSelector;
0156   _recMuonTrkSelector = nullptr;
0157   delete _recTrackSelector;
0158   _recTrackSelector = nullptr;
0159   delete _recElecSelector;
0160   _recElecSelector = nullptr;
0161   delete _recPhotonSelector;
0162   _recPhotonSelector = nullptr;
0163   delete _recMETSelector;
0164   _recMETSelector = nullptr;
0165   delete _recPFMETSelector;
0166   _recPFMETSelector = nullptr;
0167   delete _recPFMHTSelector;
0168   _recPFMHTSelector = nullptr;
0169   delete _genMETSelector;
0170   _genMETSelector = nullptr;
0171   delete _recCaloMETSelector;
0172   _recCaloMETSelector = nullptr;
0173   delete _recCaloMHTSelector;
0174   _recCaloMHTSelector = nullptr;
0175   delete _recPFTauSelector;
0176   _recPFTauSelector = nullptr;
0177   delete _recPFJetSelector;
0178   _recPFJetSelector = nullptr;
0179   delete _recCaloJetSelector;
0180   _recCaloJetSelector = nullptr;
0181 }
0182 
0183 void HLTExoticaSubAnalysis::beginJob() {}
0184 
0185 // 2014-02-03 -- Thiago
0186 // Due to the fact that the DQM has to be thread safe now, we have to do things
0187 // differently: 1) Implement the bookHistograms() method in the container class
0188 // 2) Make the iBooker from above be known to this class
0189 // 3) Separate all booking histograms routines in this and any auxiliary classe
0190 // to be called from bookHistograms() in the container class
0191 void HLTExoticaSubAnalysis::subAnalysisBookHistos(DQMStore::IBooker &iBooker,
0192                                                   const edm::Run &iRun,
0193                                                   const edm::EventSetup &iSetup) {
0194   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::subAnalysisBookHistos()";
0195 
0196   // Create the folder structure inside HLT/Exotica
0197   std::string baseDir = "HLT/Exotica/" + _analysisname + "/";
0198   iBooker.setCurrentFolder(baseDir);
0199 
0200   // Book the gen/reco analysis-dependent histograms (denominators)
0201   for (std::map<unsigned int, edm::InputTag>::const_iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0202     const std::string objStr = EVTColContainer::getTypeString(it->first);
0203     std::vector<std::string> sources(2);
0204     sources[0] = "gen";
0205     sources[1] = "rec";
0206 
0207     for (size_t i = 0; i < sources.size(); i++) {
0208       std::string source = sources[i];
0209 
0210       if (source == "gen") {
0211         if (TString(objStr).Contains("MET") || TString(objStr).Contains("MHT") || TString(objStr).Contains("Jet")) {
0212           continue;
0213         } else {
0214           bookHist(iBooker, source, objStr, "MaxPt1");
0215           if (!_drop_pt2)
0216             bookHist(iBooker, source, objStr, "MaxPt2");
0217           if (!_drop_pt3)
0218             bookHist(iBooker, source, objStr, "MaxPt3");
0219           bookHist(iBooker, source, objStr, "Eta");
0220           bookHist(iBooker, source, objStr, "Phi");
0221 
0222           // If the target is electron or muon,
0223           // we will add Dxy plots.
0224           if (it->first == EVTColContainer::ELEC || it->first == EVTColContainer::MUON ||
0225               it->first == EVTColContainer::MUTRK) {
0226             bookHist(iBooker, source, objStr, "Dxy");
0227           }
0228         }
0229       } else {  // reco
0230         if (TString(objStr).Contains("MET") || TString(objStr).Contains("MHT")) {
0231           bookHist(iBooker, source, objStr, "MaxPt1");
0232           bookHist(iBooker, source, objStr, "SumEt");
0233         } else {
0234           bookHist(iBooker, source, objStr, "MaxPt1");
0235           if (!_drop_pt2)
0236             bookHist(iBooker, source, objStr, "MaxPt2");
0237           if (!_drop_pt3)
0238             bookHist(iBooker, source, objStr, "MaxPt3");
0239           bookHist(iBooker, source, objStr, "Eta");
0240           bookHist(iBooker, source, objStr, "Phi");
0241 
0242           // If the target is electron or muon,
0243           // we will add Dxy plots.
0244           if (it->first == EVTColContainer::ELEC || it->first == EVTColContainer::MUON ||
0245               it->first == EVTColContainer::MUTRK) {
0246             bookHist(iBooker, source, objStr, "Dxy");
0247           }
0248         }
0249       }
0250     }
0251   }  // closes loop in _recLabels
0252 
0253   // Call the plotterBookHistos() (which books all the path dependent
0254   // histograms)
0255   LogDebug("ExoticaValidation") << "                        number of plotters = " << _plotters.size();
0256   for (std::vector<HLTExoticaPlotter>::iterator it = _plotters.begin(); it != _plotters.end(); ++it) {
0257     it->plotterBookHistos(iBooker, iRun, iSetup);
0258   }
0259 }
0260 
0261 void HLTExoticaSubAnalysis::beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
0262   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::beginRun()";
0263 
0264   /// Construct the plotters right here.
0265   /// For that we need to create the _hltPaths vector.
0266 
0267   // Initialize the HLT config.
0268   bool changedConfig(true);
0269   if (!_hltConfig.init(iRun, iSetup, _hltProcessName, changedConfig)) {
0270     edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::constructor(): "
0271                                        << "Initialization of HLTConfigProvider failed!";
0272   }
0273 
0274   // Parse the input paths to get them if they are in the table and associate
0275   // them to the last filter of the path (in order to extract the objects).
0276   _hltPaths.clear();
0277   for (size_t i = 0; i < _hltPathsToCheck.size(); ++i) {
0278     bool found = false;
0279     TPRegexp pattern(_hltPathsToCheck[i]);
0280 
0281     // Loop over triggerNames from _hltConfig
0282     for (size_t j = 0; j < _hltConfig.triggerNames().size(); ++j) {
0283       std::string thetriggername = _hltConfig.triggerNames()[j];
0284       if (TString(thetriggername).Contains(pattern)) {
0285         _hltPaths.insert(thetriggername);
0286         found = true;
0287       }
0288       if (verbose > 2 && i == 0)
0289         LogDebug("ExoticaValidation") << "--- TRIGGER PATH : " << thetriggername;
0290     }
0291 
0292     // Oh dear, the path we wanted seems to not be available
0293     if (!found && verbose > 2) {
0294       edm::LogWarning("ExoticaValidation") << "HLTExoticaSubAnalysis::constructor(): In " << _analysisname
0295                                            << " subfolder NOT found the path: '" << _hltPathsToCheck[i] << "*'";
0296     }
0297   }  // Close loop over paths to check.
0298 
0299   // At this point, _hltpaths contains the names of the paths to check
0300   // that were found. Let's log it at trace level.
0301   LogTrace("ExoticaValidation") << "SubAnalysis: " << _analysisname << "\nHLT Trigger Paths found >>>";
0302   for (std::set<std::string>::const_iterator iter = _hltPaths.begin(); iter != _hltPaths.end(); ++iter) {
0303     LogTrace("ExoticaValidation") << (*iter) << "\n";
0304   }
0305 
0306   // Initialize the plotters (analysers for each trigger path)
0307   _plotters.clear();
0308   for (std::set<std::string>::iterator iPath = _hltPaths.begin(); iPath != _hltPaths.end(); ++iPath) {
0309     // Avoiding the dependence of the version number for the trigger paths
0310     std::string path = *iPath;
0311     std::string shortpath = path;
0312     if (path.rfind("_v") < path.length()) {
0313       shortpath = path.substr(0, path.rfind("_v"));
0314     }
0315     _shortpath2long[shortpath] = path;
0316 
0317     // Objects needed by the HLT path
0318     // Thiago: instead of trying to decode the objects from the path,
0319     // put the burden on the user to tell us which objects are needed.
0320     // const std::vector<unsigned int> objsNeedHLT =
0321     // this->getObjectsType(shortpath);
0322     std::vector<unsigned int> objsNeedHLT;
0323     for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0324       objsNeedHLT.push_back(it->first);
0325     }
0326 
0327     /*std::vector<unsigned int> userInstantiate;
0328     // Sanity check: the object needed by a trigger path should be
0329     // introduced by the user via config python (_recLabels datamember)
0330     for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin()
0331     ; it != _recLabels.end(); ++it) { userInstantiate.push_back(it->first);
0332     }
0333     for (std::vector<unsigned int>::const_iterator it = objsNeedHLT.begin(); it
0334     != objsNeedHLT.end();
0335          ++it) {
0336         if (std::find(userInstantiate.begin(), userInstantiate.end(), *it) ==
0337             userInstantiate.end()) {
0338             edm::LogError("ExoticaValidation") << "In
0339     HLTExoticaSubAnalysis::beginRun, "
0340                                                << "Incoherence found in the
0341     python configuration file!!\nThe SubAnalysis '"
0342                                                << _analysisname << "' has been
0343     asked to evaluate the trigger path '"
0344                                                << shortpath << "' (found it in
0345     'hltPathsToCheck') BUT this path"
0346                                                << " needs a '" <<
0347     EVTColContainer::getTypeString(*it)
0348                                                << "' which has not been
0349     instantiated ('recVariableLabels'"
0350                                                << ")" ;
0351             exit(-1); // This should probably throw an exception...
0352         }
0353     }
0354     */
0355     LogTrace("ExoticaValidation") << " --- " << shortpath;
0356 
0357     // The hlt path, the objects (electrons, muons, photons, ...)
0358     // needed to evaluate the path are the argumens of the plotter
0359     HLTExoticaPlotter analyzer(_pset, shortpath, objsNeedHLT);
0360     _plotters.push_back(analyzer);
0361     // counting HLT passed events for debug
0362     _triggerCounter.insert(std::map<std::string, int>::value_type(shortpath, 0));
0363   }  // Okay, at this point we have prepared all the plotters.
0364 }
0365 
0366 void HLTExoticaSubAnalysis::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup, EVTColContainer *cols) {
0367   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::analyze()";
0368 
0369   // Loop over _recLabels to make sure everything is alright.
0370   /*
0371   std::cout << "Now printing the _recLabels" << std::endl;
0372   for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin();
0373        it != _recLabels.end(); ++it) {
0374       std::cout <<  "Number: " << it->first << "\t" << "Label: " <<
0375   it->second.label() << std::endl;
0376   }
0377   */
0378 
0379   // Initialize the collection (the ones which have not been initialiazed yet)
0380   // std::cout << "Setting handles to objects..." << std::endl;
0381   this->getHandlesToObjects(iEvent, cols);
0382 
0383   // Utility map, mapping kinds of objects (GEN, RECO) to strings ("gen","rec")
0384   // std::map<Level, std::string> u2str;
0385   // u2str[Level::GEN] = "gen";
0386   // u2str[Level::RECO] = "rec";
0387 
0388   // Extract the match structure containing the gen/reco candidates (electron,
0389   // muons,...). This part is common to all the SubAnalyses
0390   std::vector<reco::LeafCandidate> matchesGen;
0391   matchesGen.clear();
0392   std::vector<reco::LeafCandidate> matchesReco;
0393   matchesReco.clear();
0394   std::map<int, double> theSumEt;  // map< pdgId ; SumEt > in order to keep track of the MET type
0395   std::map<int, std::vector<const reco::Track *>> trkObjs;
0396 
0397   // --- deal with GEN objects first.
0398   // Make each good GEN object into the base cand for a MatchStruct
0399   // Our definition of "good" is "passes the selector" defined in the config.py
0400   // Save all the MatchStructs in the "matchesGen" vector.
0401 
0402   for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0403     // Here we are filling the vector of
0404     // StringCutObjectSelector<reco::GenParticle> with objects constructed from
0405     // the strings saved in _genCut. Initialize selectors when first event
0406 
0407     // std::cout << "Loop over the kinds of objects: objects of kind " <<
0408     // it->first << std::endl;
0409 
0410     if (!_genSelectorMap[it->first]) {
0411       _genSelectorMap[it->first] = new StringCutObjectSelector<reco::GenParticle>(_genCut[it->first]);
0412     }
0413 
0414     const std::string objTypeStr = EVTColContainer::getTypeString(it->first);
0415     // genAnyMET doesn't make sense. No need their matchesGens
0416     if (TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT") ||
0417         TString(objTypeStr).Contains("Jet"))
0418       continue;
0419 
0420     // Now loop over the genParticles, and apply the operator() over each of
0421     // them. Fancy syntax: for objects X and Y, X.operator()(Y) is the same as
0422     // X(Y).
0423     for (size_t i = 0; i < cols->genParticles->size(); ++i) {
0424       // std::cout << "Now matchesGen.size() is " << matchesGen.size() <<
0425       // std::endl;
0426       if (_genSelectorMap[it->first]->operator()(cols->genParticles->at(i))) {
0427         const reco::Candidate *cand = &(cols->genParticles->at(i));
0428         // std::cout << "Found good cand: cand->pt() = " << cand->pt() <<
0429         // std::endl; matchesGen.push_back(MatchStruct(cand, it->first));
0430         /// We are going to make a fake reco::LeafCandidate, with our
0431         /// particleType as the pdgId. This is an alternative to the older
0432         /// implementation with MatchStruct.
0433         reco::LeafCandidate v(0, cand->p4(), cand->vertex(), it->first, 0, true);
0434 
0435         matchesGen.push_back(v);
0436       }
0437     }
0438   }
0439 
0440   // Sort the matches by pT for later filling of turn-on curve
0441   // std::cout << "Before sorting: matchesGen.size() = " << matchesGen.size() <<
0442   // std::endl;
0443 
0444   // GreaterByPt<reco::LeafCandidate> comparator;
0445   // std::sort(matchesGen.begin(),
0446   //          matchesGen.end(),
0447   //          comparator);
0448 
0449   // --- same for RECO objects
0450   // Extraction of the objects candidates
0451   if (verbose > 0)
0452     LogDebug("ExoticaValidation") << "-- enter loop over recLabels";
0453   for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0454     // std::cout << "Filling RECO \"matchesReco\" vector for particle kind
0455     // it->first = "
0456     //    << it->first << ", which means " << it->second.label() << std::endl;
0457     // Reco selectors (the function takes into account if it was instantiated
0458     // before or not) ### Thiago ---> Then why don't we put it in the
0459     // beginRun???
0460     this->initSelector(it->first);
0461     // -- Storing the matchesReco
0462     this->insertCandidates(it->first, cols, &matchesReco, theSumEt, trkObjs);
0463     if (verbose > 0)
0464       LogDebug("ExoticaValidation") << "--- " << EVTColContainer::getTypeString(it->first)
0465                                     << " sumEt=" << theSumEt[it->first];
0466   }
0467 
0468   // std::sort(matchesReco.begin(),
0469   //          matchesReco.end(),
0470   //          comparator);
0471 
0472   // -- Trigger Results
0473   const edm::TriggerNames &trigNames = iEvent.triggerNames(*(cols->triggerResults));
0474 
0475   // counting HLT passed events for debugging
0476   for (std::vector<HLTExoticaPlotter>::iterator an = _plotters.begin(); an != _plotters.end(); ++an) {
0477     const std::string hltPath = _shortpath2long[an->gethltpath()];
0478     const bool ispassTrigger = cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
0479     if (ispassTrigger)
0480       _triggerCounter.find(an->gethltpath())->second++;
0481   }
0482 
0483   /// Filling the histograms if pass the minimum amount of candidates needed by
0484   /// the analysis:
0485 
0486   // for (std::map<unsigned int, std::vector<MatchStruct> >::iterator it =
0487   // sourceMatchMap.begin(); it != sourceMatchMap.end(); ++it) {
0488   // it->first: gen/reco   it->second: HLT matches (std::vector<MatchStruct>)
0489 
0490   // if (it->second.size() < _minCandidates) {  // FIXME: A bug is potentially
0491   // here: what about the mixed channels? continue;
0492   //}
0493 
0494   ////////////////
0495   /// GEN CASE ///
0496   ////////////////
0497   if (matchesGen.size() >= _minCandidates) {  // FIXME: A bug is potentially here: what about the
0498                                               // mixed channels?
0499     // Okay, there are enough candidates. Move on!
0500 
0501     // Filling the gen/reco objects (eff-denominators):
0502     // Just the first two different ones, if there are more
0503     // The countobjects maps uints (object types, really) --> integers.
0504     // Example:
0505     // | uint | int |
0506     // |  0   |  1  | --> 1 muon used
0507     // |  1   |  2  | --> 2 electrons used
0508 
0509     // Initializing the count of the used objects.
0510     std::map<unsigned int, int> countobjects;
0511     for (std::map<unsigned int, edm::InputTag>::iterator co = _recLabels.begin(); co != _recLabels.end(); ++co) {
0512       // countobjects->insert(std::pair<unsigned int, int>(co->first, 0));
0513       countobjects.insert(std::pair<unsigned int, int>(co->first, 0));
0514     }
0515 
0516     int counttotal = 0;
0517 
0518     // 3 : pt1, pt2, pt3
0519     int totalobjectssize = 1;
0520     if (!_drop_pt2)
0521       totalobjectssize++;
0522     if (!_drop_pt3)
0523       totalobjectssize++;
0524     totalobjectssize *= countobjects.size();
0525 
0526     bool isPassedLeadingCut = true;
0527     // We will proceed only when cuts for the pt-leading are satisified.
0528     for (size_t j = 0; j != matchesGen.size(); ++j) {
0529       const unsigned int objType = matchesGen[j].pdgId();
0530       // Cut for the pt-leading object
0531       StringCutObjectSelector<reco::LeafCandidate> select(_genCut_leading[objType]);
0532       if (!select(matchesGen[j])) {  // No interest case
0533         isPassedLeadingCut = false;  // Will skip the following matchesGen loop
0534         matchesGen.clear();
0535         break;
0536       }
0537     }
0538 
0539     std::vector<float> dxys;
0540     dxys.clear();
0541 
0542     for (size_t j = 0; (j != matchesGen.size()) && isPassedLeadingCut; ++j) {
0543       const unsigned int objType = matchesGen[j].pdgId();
0544       // std::cout << "(4) Gonna call with " << objType << std::endl;
0545       const std::string objTypeStr = EVTColContainer::getTypeString(objType);
0546 
0547       float pt = matchesGen[j].pt();
0548 
0549       if (countobjects[objType] == 0) {
0550         this->fillHist("gen", objTypeStr, "MaxPt1", pt);
0551         ++(countobjects[objType]);
0552         ++counttotal;
0553       } else if (countobjects[objType] == 1 && !_drop_pt2) {
0554         this->fillHist("gen", objTypeStr, "MaxPt2", pt);
0555         ++(countobjects[objType]);
0556         ++counttotal;
0557       } else if (countobjects[objType] == 2 && !_drop_pt3) {
0558         this->fillHist("gen", objTypeStr, "MaxPt3", pt);
0559         ++(countobjects[objType]);
0560         ++counttotal;
0561       } else {
0562         // Already the minimum three objects has been filled, get out...
0563         if (counttotal == totalobjectssize) {
0564           size_t max_size = matchesGen.size();
0565           for (size_t jj = j; jj < max_size; jj++) {
0566             matchesGen.erase(matchesGen.end());
0567           }
0568           break;
0569         }
0570       }
0571 
0572       float eta = matchesGen[j].eta();
0573       float phi = matchesGen[j].phi();
0574 
0575       this->fillHist("gen", objTypeStr, "Eta", eta);
0576       this->fillHist("gen", objTypeStr, "Phi", phi);
0577 
0578       // If the target is electron or muon,
0579 
0580       if (objType == EVTColContainer::MUON || objType == EVTColContainer::MUTRK || objType == EVTColContainer::ELEC) {
0581         const math::XYZPoint &vtx = matchesGen[j].vertex();
0582         float momphi = matchesGen[j].momentum().phi();
0583         float dxyGen = (-(vtx.x() - cols->bs->x0()) * sin(momphi) + (vtx.y() - cols->bs->y0()) * cos(momphi));
0584         dxys.push_back(dxyGen);
0585         this->fillHist("gen", objTypeStr, "Dxy", dxyGen);
0586       }
0587 
0588     }  // Closes loop in gen
0589 
0590     // Calling to the plotters analysis (where the evaluation of the different
0591     // trigger paths are done)
0592     // const std::string source = "gen";
0593     for (std::vector<HLTExoticaPlotter>::iterator an = _plotters.begin(); an != _plotters.end(); ++an) {
0594       const std::string hltPath = _shortpath2long[an->gethltpath()];
0595       const bool ispassTrigger = cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
0596       LogDebug("ExoticaValidation") << "                        preparing to call the plotters analysis";
0597       an->analyze(ispassTrigger, "gen", matchesGen, theSumEt, dxys);
0598       LogDebug("ExoticaValidation") << "                        called the plotter";
0599     }
0600   }  /// Close GEN case
0601 
0602   /////////////////
0603   /// RECO CASE ///
0604   /////////////////
0605 
0606   {
0607     if (matchesReco.size() < _minCandidates)
0608       return;  // FIXME: A bug is potentially here: what about the mixed
0609                // channels?
0610 
0611     // Okay, there are enough candidates. Move on!
0612 
0613     // Filling the gen/reco objects (eff-denominators):
0614     // Just the first two different ones, if there are more
0615     // The countobjects maps uints (object types, really) --> integers.
0616     // Example:
0617     // | uint | int |
0618     // |  0   |  1  | --> 1 muon used
0619     // |  1   |  2  | --> 2 electrons used
0620     // Initializing the count of the used objects.
0621     // std::map<unsigned int, int> * countobjects = new std::map<unsigned int,
0622     // int>;
0623     std::map<unsigned int, int> countobjects;
0624     for (std::map<unsigned int, edm::InputTag>::iterator co = _recLabels.begin(); co != _recLabels.end(); ++co) {
0625       countobjects.insert(std::pair<unsigned int, int>(co->first, 0));
0626     }
0627 
0628     int counttotal = 0;
0629 
0630     // 3 : pt1, pt2, pt3
0631     int totalobjectssize = 1;
0632     if (!_drop_pt2)
0633       totalobjectssize++;
0634     if (!_drop_pt3)
0635       totalobjectssize++;
0636     totalobjectssize *= countobjects.size();
0637 
0638     /// Debugging.
0639     // std::cout << "Our RECO vector has matchesReco.size() = " <<
0640     // matchesReco.size() << std::endl;
0641 
0642     std::vector<float> dxys;
0643     dxys.clear();
0644 
0645     bool isPassedLeadingCut = true;
0646     // We will proceed only when cuts for the pt-leading are satisified.
0647     for (size_t j = 0; j != matchesReco.size(); ++j) {
0648       const unsigned int objType = matchesReco[j].pdgId();
0649       // Cut for the pt-leading object
0650       StringCutObjectSelector<reco::LeafCandidate> select(_recCut_leading[objType]);
0651       if (!select(matchesReco[j])) {  // No interest case
0652         isPassedLeadingCut = false;   // Will skip the following matchesReco loop
0653         matchesReco.clear();
0654         break;
0655       }
0656     }
0657 
0658     int jel = 0;
0659     int jmu = 0;
0660     int jmutrk = 0;
0661 
0662     // jel, jmu and jmutrk are being used as a dedicated counters to avoid getting
0663     // non-existent elements inside trkObjs[11], trkObjs[13] and trkObjs[130], respectively
0664     // more information in the issue https://github.com/cms-sw/cmssw/issues/32550
0665 
0666     for (size_t j = 0; (j != matchesReco.size()) && isPassedLeadingCut; ++j) {
0667       const unsigned int objType = matchesReco[j].pdgId();
0668       //std::cout << "(4) Gonna call with " << objType << std::endl;
0669 
0670       const std::string objTypeStr = EVTColContainer::getTypeString(objType);
0671 
0672       float pt = matchesReco[j].pt();
0673 
0674       if (countobjects[objType] == 0) {
0675         this->fillHist("rec", objTypeStr, "MaxPt1", pt);
0676         ++(countobjects[objType]);
0677         ++counttotal;
0678       } else if (countobjects[objType] == 1 && !_drop_pt2) {
0679         if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
0680           this->fillHist("rec", objTypeStr, "MaxPt2", pt);
0681         }
0682         ++(countobjects[objType]);
0683         ++counttotal;
0684       } else if (countobjects[objType] == 2 && !_drop_pt3) {
0685         if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
0686           this->fillHist("rec", objTypeStr, "MaxPt3", pt);
0687         }
0688         ++(countobjects[objType]);
0689         ++counttotal;
0690       } else {
0691         // Already the minimum three objects has been filled, get out...
0692         if (counttotal == totalobjectssize) {
0693           size_t max_size = matchesReco.size();
0694           for (size_t jj = j; jj < max_size; jj++) {
0695             matchesReco.erase(matchesReco.end());
0696           }
0697           break;
0698         }
0699       }
0700 
0701       float eta = matchesReco[j].eta();
0702       float phi = matchesReco[j].phi();
0703 
0704       if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
0705         this->fillHist("rec", objTypeStr, "Eta", eta);
0706         this->fillHist("rec", objTypeStr, "Phi", phi);
0707       } else {
0708         this->fillHist("rec", objTypeStr, "SumEt", theSumEt[objType]);
0709       }
0710 
0711       if (objType == 11) {
0712         float dxyRec = trkObjs[objType].at(jel)->dxy(cols->bs->position());
0713         this->fillHist("rec", objTypeStr, "Dxy", dxyRec);
0714         dxys.push_back(dxyRec);
0715         ++jel;
0716       }
0717 
0718       if (objType == 13) {
0719         float dxyRec = trkObjs[objType].at(jmu)->dxy(cols->bs->position());
0720         this->fillHist("rec", objTypeStr, "Dxy", dxyRec);
0721         dxys.push_back(dxyRec);
0722         ++jmu;
0723       }
0724 
0725       if (objType == 130) {
0726         float dxyRec = trkObjs[objType].at(jmutrk)->dxy(cols->bs->position());
0727         this->fillHist("rec", objTypeStr, "Dxy", dxyRec);
0728         dxys.push_back(dxyRec);
0729         ++jmutrk;
0730       }
0731 
0732     }  // Closes loop in reco
0733 
0734     // LogDebug("ExoticaValidation") << "                        deleting
0735     // countobjects"; delete countobjects;
0736 
0737     // Calling to the plotters analysis (where the evaluation of the different
0738     // trigger paths are done)
0739     // const std::string source = "reco";
0740     for (std::vector<HLTExoticaPlotter>::iterator an = _plotters.begin(); an != _plotters.end(); ++an) {
0741       const std::string hltPath = _shortpath2long[an->gethltpath()];
0742       const bool ispassTrigger = cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
0743       LogDebug("ExoticaValidation") << "                        preparing to call the plotters analysis";
0744       an->analyze(ispassTrigger, "rec", matchesReco, theSumEt, dxys);
0745       LogDebug("ExoticaValidation") << "                        called the plotter";
0746     }
0747   }  /// Close RECO case
0748 
0749 }  /// closes analyze method
0750 
0751 // Return the objects (muons,electrons,photons,...) needed by a hlt path.
0752 const std::vector<unsigned int> HLTExoticaSubAnalysis::getObjectsType(const std::string &hltPath) const {
0753   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getObjectsType()";
0754 
0755   static const unsigned int objSize = 15;
0756   static const unsigned int objtriggernames[] = {EVTColContainer::MUON,
0757                                                  EVTColContainer::MUTRK,
0758                                                  EVTColContainer::TRACK,
0759                                                  EVTColContainer::ELEC,
0760                                                  EVTColContainer::PHOTON,
0761                                                  EVTColContainer::MET,
0762                                                  EVTColContainer::PFMET,
0763                                                  EVTColContainer::PFMHT,
0764                                                  EVTColContainer::GENMET,
0765                                                  EVTColContainer::CALOMET,
0766                                                  EVTColContainer::CALOMHT,
0767                                                  EVTColContainer::PFTAU,
0768                                                  EVTColContainer::PFJET,
0769                                                  EVTColContainer::CALOJET};
0770 
0771   std::set<unsigned int> objsType;
0772   // The object to deal has to be entered via the config .py
0773   for (unsigned int i = 0; i < objSize; ++i) {
0774     // std::cout << "(5) Gonna call with " << objtriggernames[i] << std::endl;
0775     std::string objTypeStr = EVTColContainer::getTypeString(objtriggernames[i]);
0776     // Check if it is needed this object for this trigger
0777     if (!TString(hltPath).Contains(objTypeStr)) {
0778       continue;
0779     }
0780 
0781     objsType.insert(objtriggernames[i]);
0782   }
0783 
0784   return std::vector<unsigned int>(objsType.begin(), objsType.end());
0785 }
0786 
0787 // Booking the maps: recLabels and genParticle selectors
0788 void HLTExoticaSubAnalysis::getNamesOfObjects(const edm::ParameterSet &anpset) {
0789   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getNamesOfObjects()";
0790 
0791   if (anpset.exists("recMuonLabel")) {
0792     _recLabels[EVTColContainer::MUON] = anpset.getParameter<edm::InputTag>("recMuonLabel");
0793     _genSelectorMap[EVTColContainer::MUON] = nullptr;
0794   }
0795   if (anpset.exists("recMuonTrkLabel")) {
0796     _recLabels[EVTColContainer::MUTRK] = anpset.getParameter<edm::InputTag>("recMuonTrkLabel");
0797     _genSelectorMap[EVTColContainer::MUTRK] = nullptr;
0798   }
0799   if (anpset.exists("recTrackLabel")) {
0800     _recLabels[EVTColContainer::TRACK] = anpset.getParameter<edm::InputTag>("recTrackLabel");
0801     _genSelectorMap[EVTColContainer::TRACK] = nullptr;
0802   }
0803   if (anpset.exists("recElecLabel")) {
0804     _recLabels[EVTColContainer::ELEC] = anpset.getParameter<edm::InputTag>("recElecLabel");
0805     _genSelectorMap[EVTColContainer::ELEC] = nullptr;
0806   }
0807   if (anpset.exists("recPhotonLabel")) {
0808     _recLabels[EVTColContainer::PHOTON] = anpset.getParameter<edm::InputTag>("recPhotonLabel");
0809     _genSelectorMap[EVTColContainer::PHOTON] = nullptr;
0810   }
0811   if (anpset.exists("recMETLabel")) {
0812     _recLabels[EVTColContainer::MET] = anpset.getParameter<edm::InputTag>("recMETLabel");
0813     _genSelectorMap[EVTColContainer::MET] = nullptr;
0814   }
0815   if (anpset.exists("recPFMETLabel")) {
0816     _recLabels[EVTColContainer::PFMET] = anpset.getParameter<edm::InputTag>("recPFMETLabel");
0817     _genSelectorMap[EVTColContainer::PFMET] = nullptr;
0818   }
0819   if (anpset.exists("recPFMHTLabel")) {
0820     _recLabels[EVTColContainer::PFMHT] = anpset.getParameter<edm::InputTag>("recPFMHTLabel");
0821     _genSelectorMap[EVTColContainer::PFMHT] = nullptr;
0822   }
0823   if (anpset.exists("genMETLabel")) {
0824     _recLabels[EVTColContainer::GENMET] = anpset.getParameter<edm::InputTag>("genMETLabel");
0825     _genSelectorMap[EVTColContainer::GENMET] = nullptr;
0826   }
0827   if (anpset.exists("recCaloMETLabel")) {
0828     _recLabels[EVTColContainer::CALOMET] = anpset.getParameter<edm::InputTag>("recCaloMETLabel");
0829     _genSelectorMap[EVTColContainer::CALOMET] = nullptr;
0830   }
0831   if (anpset.exists("recCaloMHTLabel")) {
0832     _recLabels[EVTColContainer::CALOMHT] = anpset.getParameter<edm::InputTag>("recCaloMHTLabel");
0833     _genSelectorMap[EVTColContainer::CALOMHT] = nullptr;
0834   }
0835   if (anpset.exists("hltMETLabel")) {
0836     _recLabels[EVTColContainer::CALOMET] = anpset.getParameter<edm::InputTag>("hltMETLabel");
0837     _genSelectorMap[EVTColContainer::CALOMET] = nullptr;
0838   }
0839   if (anpset.exists("recPFTauLabel")) {
0840     _recLabels[EVTColContainer::PFTAU] = anpset.getParameter<edm::InputTag>("recPFTauLabel");
0841     _genSelectorMap[EVTColContainer::PFTAU] = nullptr;
0842   }
0843   if (anpset.exists("recPFJetLabel")) {
0844     _recLabels[EVTColContainer::PFJET] = anpset.getParameter<edm::InputTag>("recPFJetLabel");
0845     _genSelectorMap[EVTColContainer::PFJET] = nullptr;
0846   }
0847   if (anpset.exists("recCaloJetLabel")) {
0848     _recLabels[EVTColContainer::CALOJET] = anpset.getParameter<edm::InputTag>("recCaloJetLabel");
0849     _genSelectorMap[EVTColContainer::CALOJET] = nullptr;
0850   }
0851 
0852   if (_recLabels.empty()) {
0853     edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::getNamesOfObjects, "
0854                                        << "Not included any object (recMuonLabel, recElecLabel, ...)  "
0855                                        << "in the analysis " << _analysisname;
0856     return;
0857   }
0858 }
0859 
0860 // Register consumption of objects.
0861 // I have chosen to centralize all consumes() calls here.
0862 void HLTExoticaSubAnalysis::registerConsumes(edm::ConsumesCollector &iC) {
0863   // Register that we are getting genParticles
0864   _genParticleToken = iC.consumes<reco::GenParticleCollection>(_genParticleLabel);
0865 
0866   // Register that we are getting the trigger results
0867   _trigResultsToken = iC.consumes<edm::TriggerResults>(_trigResultsLabel);
0868 
0869   // Register beamspot
0870   _bsToken = iC.consumes<reco::BeamSpot>(_beamSpotLabel);
0871 
0872   // Loop over _recLabels, see what we need, and register.
0873   // Then save the registered token in _tokens.
0874   // Remember: _recLabels is a map<uint, edm::InputTag>
0875   // Remember: _tokens    is a map<uint, edm::EDGetToken>
0876   LogDebug("ExoticaValidation") << "We have got " << _recLabels.size() << "recLabels";
0877   for (std::map<unsigned int, edm::InputTag>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0878     if (it->first == EVTColContainer::MUON) {
0879       edm::EDGetTokenT<reco::MuonCollection> particularToken = iC.consumes<reco::MuonCollection>(it->second);
0880       edm::EDGetToken token(particularToken);
0881       _tokens[it->first] = token;
0882     } else if (it->first == EVTColContainer::MUTRK) {
0883       edm::EDGetTokenT<reco::TrackCollection> particularToken = iC.consumes<reco::TrackCollection>(it->second);
0884       edm::EDGetToken token(particularToken);
0885       _tokens[it->first] = token;
0886     } else if (it->first == EVTColContainer::TRACK) {
0887       edm::EDGetTokenT<reco::TrackCollection> particularToken = iC.consumes<reco::TrackCollection>(it->second);
0888       edm::EDGetToken token(particularToken);
0889       _tokens[it->first] = token;
0890     } else if (it->first == EVTColContainer::ELEC) {
0891       edm::EDGetTokenT<reco::GsfElectronCollection> particularToken =
0892           iC.consumes<reco::GsfElectronCollection>(it->second);
0893       edm::EDGetToken token(particularToken);
0894       _tokens[it->first] = token;
0895     } else if (it->first == EVTColContainer::PHOTON) {
0896       edm::EDGetTokenT<reco::PhotonCollection> particularToken = iC.consumes<reco::PhotonCollection>(it->second);
0897       edm::EDGetToken token(particularToken);
0898       _tokens[it->first] = token;
0899     } else if (it->first == EVTColContainer::MET) {
0900       edm::EDGetTokenT<reco::METCollection> particularToken = iC.consumes<reco::METCollection>(it->second);
0901       edm::EDGetToken token(particularToken);
0902       _tokens[it->first] = token;
0903     } else if (it->first == EVTColContainer::PFMET) {
0904       edm::EDGetTokenT<reco::PFMETCollection> particularToken = iC.consumes<reco::PFMETCollection>(it->second);
0905       edm::EDGetToken token(particularToken);
0906       _tokens[it->first] = token;
0907     } else if (it->first == EVTColContainer::PFMHT) {
0908       edm::EDGetTokenT<reco::PFMETCollection> particularToken = iC.consumes<reco::PFMETCollection>(it->second);
0909       edm::EDGetToken token(particularToken);
0910       _tokens[it->first] = token;
0911     } else if (it->first == EVTColContainer::GENMET) {
0912       edm::EDGetTokenT<reco::GenMETCollection> particularToken = iC.consumes<reco::GenMETCollection>(it->second);
0913       edm::EDGetToken token(particularToken);
0914       _tokens[it->first] = token;
0915     } else if (it->first == EVTColContainer::CALOMET) {
0916       edm::EDGetTokenT<reco::CaloMETCollection> particularToken = iC.consumes<reco::CaloMETCollection>(it->second);
0917       edm::EDGetToken token(particularToken);
0918       _tokens[it->first] = token;
0919     } else if (it->first == EVTColContainer::CALOMHT) {
0920       edm::EDGetTokenT<reco::CaloMETCollection> particularToken = iC.consumes<reco::CaloMETCollection>(it->second);
0921       edm::EDGetToken token(particularToken);
0922       _tokens[it->first] = token;
0923     } else if (it->first == EVTColContainer::PFTAU) {
0924       edm::EDGetTokenT<reco::PFTauCollection> particularToken = iC.consumes<reco::PFTauCollection>(it->second);
0925       edm::EDGetToken token(particularToken);
0926       _tokens[it->first] = token;
0927     } else if (it->first == EVTColContainer::PFJET) {
0928       edm::EDGetTokenT<reco::PFJetCollection> particularToken = iC.consumes<reco::PFJetCollection>(it->second);
0929       edm::EDGetToken token(particularToken);
0930       _tokens[it->first] = token;
0931     } else if (it->first == EVTColContainer::CALOJET) {
0932       edm::EDGetTokenT<reco::CaloJetCollection> particularToken = iC.consumes<reco::CaloJetCollection>(it->second);
0933       edm::EDGetToken token(particularToken);
0934       _tokens[it->first] = token;
0935     } else {
0936       edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::registerConsumes"
0937                                          << " NOT IMPLEMENTED (yet) ERROR: '" << it->second.label() << "'";
0938     }
0939   }
0940 }
0941 
0942 // Setting the collections of objects in EVTColContainer
0943 void HLTExoticaSubAnalysis::getHandlesToObjects(const edm::Event &iEvent, EVTColContainer *col) {
0944   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::getHandlesToObjects()";
0945 
0946   if (!col->isCommonInit()) {
0947     // Extract the trigger results (path info, pass,...)
0948     edm::Handle<edm::TriggerResults> trigResults;
0949     iEvent.getByToken(_trigResultsToken, trigResults);
0950     if (trigResults.isValid()) {
0951       col->triggerResults = trigResults.product();
0952       LogDebug("ExoticaValidation") << "Added handle to triggerResults";
0953     }
0954 
0955     // Extract the genParticles
0956     edm::Handle<reco::GenParticleCollection> genPart;
0957     iEvent.getByToken(_genParticleToken, genPart);
0958     if (genPart.isValid()) {
0959       col->genParticles = genPart.product();
0960       LogDebug("ExoticaValidation") << "Added handle to genParticles";
0961     }
0962 
0963     // BeamSpot for dxy
0964     edm::Handle<reco::BeamSpot> bsHandle;
0965     iEvent.getByToken(_bsToken, bsHandle);
0966     if (bsHandle.isValid()) {
0967       col->bs = bsHandle.product();
0968     }
0969   }
0970 
0971   // Loop over the tokens and extract all other objects
0972   LogDebug("ExoticaValidation") << "We have got " << _tokens.size() << "tokens";
0973   for (std::map<unsigned int, edm::EDGetToken>::iterator it = _tokens.begin(); it != _tokens.end(); ++it) {
0974     if (it->first == EVTColContainer::MUON) {
0975       edm::Handle<reco::MuonCollection> theHandle;
0976       iEvent.getByToken(it->second, theHandle);
0977       if (theHandle.isValid())
0978         col->set(theHandle.product());
0979     } else if (it->first == EVTColContainer::MUTRK) {
0980       edm::Handle<reco::TrackCollection> theHandle;
0981       iEvent.getByToken(it->second, theHandle);
0982       if (theHandle.isValid())
0983         col->set(theHandle.product());
0984     } else if (it->first == EVTColContainer::TRACK) {
0985       edm::Handle<reco::TrackCollection> theHandle;
0986       iEvent.getByToken(it->second, theHandle);
0987       if (theHandle.isValid())
0988         col->set(theHandle.product());
0989     } else if (it->first == EVTColContainer::ELEC) {
0990       edm::Handle<reco::GsfElectronCollection> theHandle;
0991       iEvent.getByToken(it->second, theHandle);
0992       if (theHandle.isValid())
0993         col->set(theHandle.product());
0994     } else if (it->first == EVTColContainer::PHOTON) {
0995       edm::Handle<reco::PhotonCollection> theHandle;
0996       iEvent.getByToken(it->second, theHandle);
0997       if (theHandle.isValid())
0998         col->set(theHandle.product());
0999     } else if (it->first == EVTColContainer::MET) {
1000       edm::Handle<reco::METCollection> theHandle;
1001       iEvent.getByToken(it->second, theHandle);
1002       if (theHandle.isValid())
1003         col->set(theHandle.product());
1004     } else if (it->first == EVTColContainer::PFMET) {
1005       edm::Handle<reco::PFMETCollection> theHandle;
1006       iEvent.getByToken(it->second, theHandle);
1007       if (theHandle.isValid())
1008         col->set(theHandle.product());
1009     } else if (it->first == EVTColContainer::PFMHT) {
1010       edm::Handle<reco::PFMETCollection> theHandle;
1011       iEvent.getByToken(it->second, theHandle);
1012       if (theHandle.isValid())
1013         col->setPFMHT(theHandle.product());
1014     } else if (it->first == EVTColContainer::GENMET) {
1015       edm::Handle<reco::GenMETCollection> theHandle;
1016       iEvent.getByToken(it->second, theHandle);
1017       if (theHandle.isValid())
1018         col->set(theHandle.product());
1019     } else if (it->first == EVTColContainer::CALOMET) {
1020       edm::Handle<reco::CaloMETCollection> theHandle;
1021       iEvent.getByToken(it->second, theHandle);
1022       if (theHandle.isValid())
1023         col->set(theHandle.product());
1024     } else if (it->first == EVTColContainer::CALOMHT) {
1025       edm::Handle<reco::CaloMETCollection> theHandle;
1026       iEvent.getByToken(it->second, theHandle);
1027       if (theHandle.isValid())
1028         col->setCaloMHT(theHandle.product());
1029     } else if (it->first == EVTColContainer::PFTAU) {
1030       edm::Handle<reco::PFTauCollection> theHandle;
1031       iEvent.getByToken(it->second, theHandle);
1032       if (theHandle.isValid())
1033         col->set(theHandle.product());
1034     } else if (it->first == EVTColContainer::PFJET) {
1035       edm::Handle<reco::PFJetCollection> theHandle;
1036       iEvent.getByToken(it->second, theHandle);
1037       if (theHandle.isValid())
1038         col->set(theHandle.product());
1039     } else if (it->first == EVTColContainer::CALOJET) {
1040       edm::Handle<reco::CaloJetCollection> theHandle;
1041       iEvent.getByToken(it->second, theHandle);
1042       if (theHandle.isValid())
1043         col->set(theHandle.product());
1044     } else {
1045       edm::LogError("ExoticaValidation") << "HLTExoticaSubAnalysis::getHandlesToObjects "
1046                                          << " NOT IMPLEMENTED (yet) ERROR: '" << it->first << "'";
1047     }
1048   }
1049 }
1050 
1051 // Booking the histograms, and putting them in DQM
1052 void HLTExoticaSubAnalysis::bookHist(DQMStore::IBooker &iBooker,
1053                                      const std::string &source,
1054                                      const std::string &objType,
1055                                      const std::string &variable) {
1056   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::bookHist()";
1057   std::string sourceUpper = source;
1058   sourceUpper[0] = std::toupper(sourceUpper[0]);
1059   std::string name = source + objType + variable;
1060   TH1F *h = nullptr;
1061 
1062   if (variable.find("SumEt") != std::string::npos) {
1063     std::string title = "Sum ET of " + sourceUpper + " " + objType;
1064     const size_t nBins = _parametersTurnOnSumEt.size() - 1;
1065     float *edges = new float[nBins + 1];
1066     for (size_t i = 0; i < nBins + 1; i++) {
1067       edges[i] = _parametersTurnOnSumEt[i];
1068     }
1069     h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
1070     delete[] edges;
1071   }
1072 
1073   else if (variable.find("Dxy") != std::string::npos) {
1074     std::string title = "Dxy " + sourceUpper + " " + objType;
1075     int nBins = _parametersDxy[0];
1076     double min = _parametersDxy[1];
1077     double max = _parametersDxy[2];
1078     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
1079   }
1080 
1081   else if (variable.find("MaxPt") != std::string::npos) {
1082     std::string desc = (variable == "MaxPt1") ? "Leading" : "Next-to-Leading";
1083     std::string title = "pT of " + desc + " " + sourceUpper + " " + objType;
1084     const size_t nBins = _parametersTurnOn.size() - 1;
1085     float *edges = new float[nBins + 1];
1086     for (size_t i = 0; i < nBins + 1; i++) {
1087       edges[i] = _parametersTurnOn[i];
1088     }
1089     h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
1090     delete[] edges;
1091   }
1092 
1093   else {
1094     std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
1095     std::string title = symbol + " of " + sourceUpper + " " + objType;
1096     std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
1097     int nBins = (int)params[0];
1098     double min = params[1];
1099     double max = params[2];
1100     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
1101   }
1102 
1103   h->Sumw2();
1104   // This is the trick, that takes a normal TH1F and puts it in in the DQM
1105   // machinery. Seems to be easy!
1106   // Updated to use the new iBooker machinery.
1107   _elements[name] = iBooker.book1D(name, h);
1108   delete h;
1109 }
1110 
1111 // Fill the histograms
1112 void HLTExoticaSubAnalysis::fillHist(const std::string &source,
1113                                      const std::string &objType,
1114                                      const std::string &variable,
1115                                      const float &value) {
1116   std::string sourceUpper = source;
1117   sourceUpper[0] = toupper(sourceUpper[0]);
1118   std::string name = source + objType + variable;
1119 
1120   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::fillHist() " << name << " " << value;
1121   _elements[name]->Fill(value);
1122   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::fillHist() " << name << " worked";
1123 }
1124 
1125 // Initialize the selectors
1126 void HLTExoticaSubAnalysis::initSelector(const unsigned int &objtype) {
1127   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::initSelector()";
1128 
1129   if (objtype == EVTColContainer::MUON && _recMuonSelector == nullptr) {
1130     _recMuonSelector = new StringCutObjectSelector<reco::Muon>(_recCut[objtype]);
1131   } else if (objtype == EVTColContainer::MUTRK && _recMuonTrkSelector == nullptr) {
1132     _recMuonTrkSelector = new StringCutObjectSelector<reco::Track>(_recCut[objtype]);
1133   } else if (objtype == EVTColContainer::TRACK && _recTrackSelector == nullptr) {
1134     _recTrackSelector = new StringCutObjectSelector<reco::Track>(_recCut[objtype]);
1135   } else if (objtype == EVTColContainer::ELEC && _recElecSelector == nullptr) {
1136     _recElecSelector = new StringCutObjectSelector<reco::GsfElectron>(_recCut[objtype]);
1137   } else if (objtype == EVTColContainer::PHOTON && _recPhotonSelector == nullptr) {
1138     _recPhotonSelector = new StringCutObjectSelector<reco::Photon>(_recCut[objtype]);
1139   } else if (objtype == EVTColContainer::MET && _recMETSelector == nullptr) {
1140     _recMETSelector = new StringCutObjectSelector<reco::MET>(_recCut[objtype]);
1141   } else if (objtype == EVTColContainer::PFMET && _recPFMETSelector == nullptr) {
1142     _recPFMETSelector = new StringCutObjectSelector<reco::PFMET>(_recCut[objtype]);
1143   } else if (objtype == EVTColContainer::PFMHT && _recPFMHTSelector == nullptr) {
1144     _recPFMHTSelector = new StringCutObjectSelector<reco::PFMET>(_recCut[objtype]);
1145   } else if (objtype == EVTColContainer::GENMET && _genMETSelector == nullptr) {
1146     _genMETSelector = new StringCutObjectSelector<reco::GenMET>(_recCut[objtype]);
1147   } else if (objtype == EVTColContainer::CALOMET && _recCaloMETSelector == nullptr) {
1148     _recCaloMETSelector = new StringCutObjectSelector<reco::CaloMET>(_recCut[objtype]);
1149   } else if (objtype == EVTColContainer::CALOMHT && _recCaloMHTSelector == nullptr) {
1150     _recCaloMHTSelector = new StringCutObjectSelector<reco::CaloMET>(_recCut[objtype]);
1151   } else if (objtype == EVTColContainer::PFTAU && _recPFTauSelector == nullptr) {
1152     _recPFTauSelector = new StringCutObjectSelector<reco::PFTau>(_recCut[objtype]);
1153   } else if (objtype == EVTColContainer::PFJET && _recPFJetSelector == nullptr) {
1154     _recPFJetSelector = new StringCutObjectSelector<reco::PFJet>(_recCut[objtype]);
1155   } else if (objtype == EVTColContainer::CALOJET && _recCaloJetSelector == nullptr) {
1156     _recCaloJetSelector = new StringCutObjectSelector<reco::CaloJet>(_recCut[objtype]);
1157   }
1158   /* else
1159   {
1160   FIXME: ERROR NOT IMPLEMENTED
1161   }*/
1162 }
1163 
1164 // Insert the HLT candidates
1165 void HLTExoticaSubAnalysis::insertCandidates(const unsigned int &objType,
1166                                              const EVTColContainer *cols,
1167                                              std::vector<reco::LeafCandidate> *matches,
1168                                              std::map<int, double> &theSumEt,
1169                                              std::map<int, std::vector<const reco::Track *>> &trkObjs) {
1170   LogDebug("ExoticaValidation") << "In HLTExoticaSubAnalysis::insertCandidates()";
1171 
1172   theSumEt[objType] = -1;
1173 
1174   if (objType == EVTColContainer::MUON) {
1175     for (size_t i = 0; i < cols->muons->size(); i++) {
1176       LogDebug("ExoticaValidation") << "Inserting muon " << i;
1177       if (_recMuonSelector->operator()(cols->muons->at(i))) {
1178         reco::LeafCandidate m(0, cols->muons->at(i).p4(), cols->muons->at(i).vertex(), objType, 0, true);
1179         matches->push_back(m);
1180 
1181         // for making dxy plots
1182         trkObjs[objType].push_back(cols->muons->at(i).bestTrack());
1183       }
1184     }
1185   } else if (objType == EVTColContainer::MUTRK) {
1186     for (size_t i = 0; i < cols->tracks->size(); i++) {
1187       LogDebug("ExoticaValidation") << "Inserting muonTrack " << i;
1188       if (_recMuonTrkSelector->operator()(cols->tracks->at(i))) {
1189         ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>> mom4;
1190         ROOT::Math::XYZVector mom3 = cols->tracks->at(i).momentum();
1191         mom4.SetXYZT(mom3.x(), mom3.y(), mom3.z(), mom3.r());
1192         reco::LeafCandidate m(0, mom4, cols->tracks->at(i).vertex(), objType, 0, true);
1193         matches->push_back(m);
1194 
1195         // for making dxy plots
1196         trkObjs[objType].push_back(&cols->tracks->at(i));
1197       }
1198     }
1199   } else if (objType == EVTColContainer::TRACK) {
1200     for (size_t i = 0; i < cols->tracks->size(); i++) {
1201       LogDebug("ExoticaValidation") << "Inserting Track " << i;
1202       if (_recTrackSelector->operator()(cols->tracks->at(i))) {
1203         ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double>> mom4;
1204         ROOT::Math::XYZVector mom3 = cols->tracks->at(i).momentum();
1205         mom4.SetXYZT(mom3.x(), mom3.y(), mom3.z(), mom3.r());
1206         reco::LeafCandidate m(0, mom4, cols->tracks->at(i).vertex(), objType, 0, true);
1207         matches->push_back(m);
1208       }
1209     }
1210   } else if (objType == EVTColContainer::ELEC) {
1211     for (size_t i = 0; i < cols->electrons->size(); i++) {
1212       LogDebug("ExoticaValidation") << "Inserting electron " << i;
1213       if (_recElecSelector->operator()(cols->electrons->at(i))) {
1214         reco::LeafCandidate m(0, cols->electrons->at(i).p4(), cols->electrons->at(i).vertex(), objType, 0, true);
1215         matches->push_back(m);
1216 
1217         // for making dxy plots
1218         trkObjs[objType].push_back(cols->electrons->at(i).bestTrack());
1219       }
1220     }
1221   } else if (objType == EVTColContainer::PHOTON) {
1222     for (size_t i = 0; i < cols->photons->size(); i++) {
1223       LogDebug("ExoticaValidation") << "Inserting photon " << i;
1224       if (_recPhotonSelector->operator()(cols->photons->at(i))) {
1225         reco::LeafCandidate m(0, cols->photons->at(i).p4(), cols->photons->at(i).vertex(), objType, 0, true);
1226         matches->push_back(m);
1227       }
1228     }
1229   } else if (objType == EVTColContainer::PFMET) {
1230     /// This is a special case. Passing a PFMET* to the constructor of
1231     /// MatchStruct will trigger the usage of the special constructor which
1232     /// also sets the sumEt member.
1233     for (size_t i = 0; i < cols->pfMETs->size(); i++) {
1234       LogDebug("ExoticaValidation") << "Inserting PFMET " << i;
1235       if (_recPFMETSelector->operator()(cols->pfMETs->at(i))) {
1236         reco::LeafCandidate m(0, cols->pfMETs->at(i).p4(), cols->pfMETs->at(i).vertex(), objType, 0, true);
1237         matches->push_back(m);
1238         if (i == 0)
1239           theSumEt[objType] = cols->pfMETs->at(i).sumEt();
1240       }
1241     }
1242   } else if (objType == EVTColContainer::PFMHT) {
1243     for (size_t i = 0; i < cols->pfMHTs->size(); i++) {
1244       LogDebug("ExoticaValidation") << "Inserting PFMHT " << i;
1245       if (_recPFMHTSelector->operator()(cols->pfMHTs->at(i))) {
1246         reco::LeafCandidate m(0, cols->pfMHTs->at(i).p4(), cols->pfMHTs->at(i).vertex(), objType, 0, true);
1247         matches->push_back(m);
1248         if (i == 0)
1249           theSumEt[objType] = cols->pfMHTs->at(i).sumEt();
1250       }
1251     }
1252   } else if (objType == EVTColContainer::GENMET) {
1253     for (size_t i = 0; i < cols->genMETs->size(); i++) {
1254       LogDebug("ExoticaValidation") << "Inserting GENMET " << i;
1255       if (_genMETSelector->operator()(cols->genMETs->at(i))) {
1256         reco::LeafCandidate m(0, cols->genMETs->at(i).p4(), cols->genMETs->at(i).vertex(), objType, 0, true);
1257         matches->push_back(m);
1258         if (i == 0)
1259           theSumEt[objType] = cols->genMETs->at(i).sumEt();
1260       }
1261     }
1262   } else if (objType == EVTColContainer::CALOMET) {
1263     for (size_t i = 0; i < cols->caloMETs->size(); i++) {
1264       LogDebug("ExoticaValidation") << "Inserting CALOMET " << i;
1265       if (_recCaloMETSelector->operator()(cols->caloMETs->at(i))) {
1266         reco::LeafCandidate m(0, cols->caloMETs->at(i).p4(), cols->caloMETs->at(i).vertex(), objType, 0, true);
1267         matches->push_back(m);
1268         if (i == 0)
1269           theSumEt[objType] = cols->caloMETs->at(i).sumEt();
1270       }
1271     }
1272   } else if (objType == EVTColContainer::CALOMHT) {
1273     for (size_t i = 0; i < cols->caloMHTs->size(); i++) {
1274       LogDebug("ExoticaValidation") << "Inserting CaloMHT " << i;
1275       if (_recCaloMHTSelector->operator()(cols->caloMHTs->at(i))) {
1276         reco::LeafCandidate m(0, cols->caloMHTs->at(i).p4(), cols->caloMHTs->at(i).vertex(), objType, 0, true);
1277         matches->push_back(m);
1278         if (i == 0)
1279           theSumEt[objType] = cols->caloMHTs->at(i).sumEt();
1280       }
1281     }
1282   } else if (objType == EVTColContainer::PFTAU) {
1283     for (size_t i = 0; i < cols->pfTaus->size(); i++) {
1284       LogDebug("ExoticaValidation") << "Inserting PFtau " << i;
1285       if (_recPFTauSelector->operator()(cols->pfTaus->at(i))) {
1286         reco::LeafCandidate m(0, cols->pfTaus->at(i).p4(), cols->pfTaus->at(i).vertex(), objType, 0, true);
1287         matches->push_back(m);
1288       }
1289     }
1290   } else if (objType == EVTColContainer::PFJET) {
1291     for (size_t i = 0; i < cols->pfJets->size(); i++) {
1292       LogDebug("ExoticaValidation") << "Inserting jet " << i;
1293       if (_recPFJetSelector->operator()(cols->pfJets->at(i))) {
1294         reco::LeafCandidate m(0, cols->pfJets->at(i).p4(), cols->pfJets->at(i).vertex(), objType, 0, true);
1295         matches->push_back(m);
1296       }
1297     }
1298   } else if (objType == EVTColContainer::CALOJET) {
1299     for (size_t i = 0; i < cols->caloJets->size(); i++) {
1300       LogDebug("ExoticaValidation") << "Inserting jet " << i;
1301       if (_recCaloJetSelector->operator()(cols->caloJets->at(i))) {
1302         reco::LeafCandidate m(0, cols->caloJets->at(i).p4(), cols->caloJets->at(i).vertex(), objType, 0, true);
1303         matches->push_back(m);
1304       }
1305     }
1306   }
1307 
1308   /* else
1309   {
1310   FIXME: ERROR NOT IMPLEMENTED
1311   }*/
1312 }
1313 
1314 void HLTExoticaSubAnalysis::endRun() {
1315   // Dump trigger results
1316   std::stringstream log;
1317   log << std::endl;
1318   log << "====================================================================="
1319          "======"
1320       << std::endl;
1321   log << "          Trigger Results ( " << _analysisname << " )                      " << std::endl;
1322   log << "====================================================================="
1323          "======"
1324       << std::endl;
1325   log << std::setw(18) << "# of passed events : HLT path names" << std::endl;
1326   log << "-------------------:-------------------------------------------------"
1327          "------"
1328       << std::endl;
1329   for (std::map<std::string, int>::iterator it = _triggerCounter.begin(); it != _triggerCounter.end(); ++it) {
1330     log << std::setw(18) << it->second << " : " << it->first << std::endl;
1331   }
1332   log << "====================================================================="
1333          "======"
1334       << std::endl;
1335   LogDebug("ExoticaValidation") << log.str().data();
1336 }