Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 /** \file HLTHiggsSubAnalysis.cc
0003 */
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "DataFormats/Common/interface/Handle.h"
0008 
0009 #include "HLTHiggsSubAnalysis.h"
0010 #include "EVTColContainer.h"
0011 #include "MatchStruct.h"
0012 
0013 #include "FWCore/Common/interface/TriggerNames.h"
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 "TPRegexp.h"
0022 #include "TRegexp.h"
0023 #include "TString.h"
0024 
0025 #include <set>
0026 #include <algorithm>
0027 
0028 HLTHiggsSubAnalysis::HLTHiggsSubAnalysis(const edm::ParameterSet& pset,
0029                                          const std::string& analysisname,
0030                                          edm::ConsumesCollector&& iC)
0031     : _pset(pset),
0032       _analysisname(analysisname),
0033       _minCandidates(0),
0034       _HtJetPtMin(0),
0035       _HtJetEtaMax(0),
0036       _hltProcessName(pset.getParameter<std::string>("hltProcessName")),
0037       _histDirectory(pset.getParameter<std::string>("histDirectory")),
0038       _genParticleLabel(iC.consumes<reco::GenParticleCollection>(pset.getParameter<std::string>("genParticleLabel"))),
0039       _genJetLabel(iC.consumes<reco::GenJetCollection>(pset.getParameter<std::string>("genJetLabel"))),
0040       _recoHtJetLabel(iC.consumes<reco::PFJetCollection>(
0041           pset.getUntrackedParameter<std::string>("recoHtJetLabel", "ak4PFJetsCHS"))),
0042       _parametersEta(pset.getParameter<std::vector<double>>("parametersEta")),
0043       _parametersPhi(pset.getParameter<std::vector<double>>("parametersPhi")),
0044       _parametersPu(pset.getParameter<std::vector<double>>("parametersPu")),
0045       _parametersHt(0),
0046       _parametersTurnOn(pset.getParameter<std::vector<double>>("parametersTurnOn")),
0047       _trigResultsTag(iC.consumes<edm::TriggerResults>(edm::InputTag("TriggerResults", "", _hltProcessName))),
0048       _genJetSelector(nullptr),
0049       _recMuonSelector(nullptr),
0050       _recElecSelector(nullptr),
0051       _recCaloMETSelector(nullptr),
0052       _recPFMETSelector(nullptr),
0053       _recPFTauSelector(nullptr),
0054       _recPhotonSelector(nullptr),
0055       _recPFJetSelector(nullptr),
0056       _recTrackSelector(nullptr),
0057       _NminOneCuts(0),
0058       _useNminOneCuts(false) {
0059   // Specific parameters for this analysis
0060   edm::ParameterSet anpset = pset.getParameter<edm::ParameterSet>(analysisname);
0061   // Collections labels (but genparticles already initialized)
0062   // initializing _recLabels data member)
0063   if (anpset.exists("parametersTurnOn")) {
0064     _parametersTurnOn = anpset.getParameter<std::vector<double>>("parametersTurnOn");
0065     _pset.addParameter("parametersTurnOn", _parametersTurnOn);
0066   }
0067   this->bookobjects(anpset, iC);
0068   // Generic objects: Initialization of cuts
0069   for (std::map<unsigned int, std::string>::const_iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0070     const std::string objStr = EVTColContainer::getTypeString(it->first);
0071     _genCut[it->first] = pset.getParameter<std::string>(objStr + "_genCut");
0072     _recCut[it->first] = pset.getParameter<std::string>(objStr + "_recCut");
0073     _cutMinPt[it->first] = pset.getParameter<double>(objStr + "_cutMinPt");
0074     _cutMaxEta[it->first] = pset.getParameter<double>(objStr + "_cutMaxEta");
0075   }
0076   //--- Updating parameters if has to be modified for this particular specific analysis
0077   for (std::map<unsigned int, std::string>::const_iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0078     const std::string objStr = EVTColContainer::getTypeString(it->first);
0079     if (anpset.existsAs<std::string>(objStr + "_genCut", false)) {
0080       _genCut[it->first] = anpset.getUntrackedParameter<std::string>(objStr + "_genCut");
0081     }
0082     if (anpset.existsAs<std::string>(objStr + "_recCut", false)) {
0083       _recCut[it->first] = anpset.getUntrackedParameter<std::string>(objStr + "_recCut");
0084     }
0085     if (anpset.existsAs<double>(objStr + "_cutMinPt", false)) {
0086       _cutMinPt[it->first] = anpset.getUntrackedParameter<double>(objStr + "_cutMinPt");
0087     }
0088     if (anpset.existsAs<double>(objStr + "_cutMaxEta", false)) {
0089       _cutMaxEta[it->first] = anpset.getUntrackedParameter<double>(objStr + "_cutMaxEta");
0090     }
0091   }
0092   _hltPathsToCheck = anpset.getParameter<std::vector<std::string>>("hltPathsToCheck");
0093   _minCandidates = anpset.getParameter<unsigned int>("minCandidates");
0094 
0095   std::vector<double> default_parametersHt;
0096   default_parametersHt.push_back(100);
0097   default_parametersHt.push_back(0);
0098   default_parametersHt.push_back(1000);
0099   _parametersHt = pset.getUntrackedParameter<std::vector<double>>("parametersHt", default_parametersHt);
0100 
0101   _HtJetPtMin = anpset.getUntrackedParameter<double>("HtJetPtMin", -1);
0102   _HtJetEtaMax = anpset.getUntrackedParameter<double>("HtJetEtaMax", -1);
0103 
0104   if (_HtJetPtMin > 0 && _HtJetEtaMax > 0)
0105     _bookHtPlots = true;
0106   else
0107     _bookHtPlots = false;
0108 
0109   if (pset.exists("pileUpInfoLabel")) {
0110     _puSummaryInfo = iC.consumes<std::vector<PileupSummaryInfo>>(pset.getParameter<std::string>("pileUpInfoLabel"));
0111   }
0112 
0113   if (anpset.existsAs<std::vector<double>>("NminOneCuts", false)) {
0114     _NminOneCuts = anpset.getUntrackedParameter<std::vector<double>>("NminOneCuts");
0115     if (_NminOneCuts.size() < 9 + _minCandidates) {
0116       edm::LogError("HiggsValidation") << "In HLTHiggsSubAnalysis::HLTHiggsSubAnalysis, "
0117                                        << "Incoherence found in the python configuration file!!\nThe SubAnalysis '"
0118                                        << _analysisname << "' has a vector NminOneCuts with size "
0119                                        << _NminOneCuts.size() << ", while it needs to be at least of size "
0120                                        << (9 + _minCandidates) << ".";
0121       exit(-1);
0122     }
0123     if ((_NminOneCuts[0] || _NminOneCuts[1]) && _minCandidates < 4) {
0124       edm::LogError("HiggsValidation") << "In HLTHiggsSubAnalysis::HLTHiggsSubAnalysis, "
0125                                        << "Incoherence found in the python configuration file!!\nThe SubAnalysis '"
0126                                        << _analysisname
0127                                        << "' has a vector NminOneCuts with a dEtaqq of mqq cut on the least b-tagged "
0128                                           "jets of the first 4 jets while only requiring "
0129                                        << _minCandidates << " jets.";
0130       exit(-1);
0131     }
0132     if (_NminOneCuts[5] && _minCandidates < 3) {
0133       edm::LogError("HiggsValidation") << "In HLTHiggsSubAnalysis::HLTHiggsSubAnalysis, "
0134                                        << "Incoherence found in the python configuration file!!\nThe SubAnalysis '"
0135                                        << _analysisname
0136                                        << "' has a vector NminOneCuts with a CSV3 cut while only requiring "
0137                                        << _minCandidates << " jets.";
0138       exit(-1);
0139     }
0140     if ((_NminOneCuts[2] || _NminOneCuts[4]) && _minCandidates < 2) {
0141       edm::LogError("HiggsValidation") << "In HLTHiggsSubAnalysis::HLTHiggsSubAnalysis, "
0142                                        << "Incoherence found in the python configuration file!!\nThe SubAnalysis '"
0143                                        << _analysisname
0144                                        << "' has a vector NminOneCuts with a dPhibb or CSV2 cut using the second most "
0145                                           "b-tagged jet while only requiring "
0146                                        << _minCandidates << " jet.";
0147       exit(-1);
0148     }
0149     for (std::vector<double>::const_iterator it = _NminOneCuts.begin(); it != _NminOneCuts.end(); ++it) {
0150       if (*it) {
0151         _useNminOneCuts = true;
0152         break;
0153       }
0154     }
0155   }
0156   //    NptPlots = ( _useNminOneCuts ? _minCandidates : 2 );
0157   NptPlots = _minCandidates;
0158 }
0159 
0160 HLTHiggsSubAnalysis::~HLTHiggsSubAnalysis() {
0161   for (std::map<unsigned int, StringCutObjectSelector<reco::GenParticle>*>::iterator it = _genSelectorMap.begin();
0162        it != _genSelectorMap.end();
0163        ++it) {
0164     delete it->second;
0165     it->second = nullptr;
0166   }
0167   delete _genJetSelector;
0168   _genJetSelector = nullptr;
0169   delete _recMuonSelector;
0170   _recMuonSelector = nullptr;
0171   delete _recElecSelector;
0172   _recElecSelector = nullptr;
0173   delete _recPhotonSelector;
0174   _recPhotonSelector = nullptr;
0175   delete _recCaloMETSelector;
0176   _recCaloMETSelector = nullptr;
0177   delete _recPFMETSelector;
0178   _recPFMETSelector = nullptr;
0179   delete _recPFTauSelector;
0180   _recPFTauSelector = nullptr;
0181   delete _recPFJetSelector;
0182   _recPFJetSelector = nullptr;
0183   delete _recTrackSelector;
0184   _recTrackSelector = nullptr;
0185 }
0186 
0187 void HLTHiggsSubAnalysis::beginJob() {}
0188 
0189 void HLTHiggsSubAnalysis::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0190   // Initialize the confighlt
0191   bool changedConfig;
0192   if (!_hltConfig.init(iRun, iSetup, _hltProcessName, changedConfig)) {
0193     edm::LogError("HiggsValidations") << "HLTHiggsSubAnalysis::beginRun: "
0194                                       << "Initializtion of HLTConfigProvider failed!!";
0195   }
0196 
0197   // Parse the input paths to get them if there are in the table
0198   // and associate them the last filter of the path (in order to extract the
0199   _hltPaths.clear();
0200   for (size_t i = 0; i < _hltPathsToCheck.size(); ++i) {
0201     bool found = false;
0202     TPRegexp pattern(_hltPathsToCheck[i]);
0203     for (size_t j = 0; j < _hltConfig.triggerNames().size(); ++j) {
0204       std::string thetriggername = _hltConfig.triggerNames()[j];
0205       if (TString(thetriggername).Contains(pattern)) {
0206         _hltPaths.insert(thetriggername);
0207         found = true;
0208       }
0209     }
0210     if (!found) {
0211       LogDebug("HiggsValidations") << "HLTHiggsSubAnalysis::beginRun, In " << _analysisname
0212                                    << " subfolder NOT found the path: '" << _hltPathsToCheck[i] << "*'";
0213     }
0214   }
0215 
0216   LogTrace("HiggsValidation") << "SubAnalysis: " << _analysisname << "\nHLT Trigger Paths found >>>";
0217   // Initialize the plotters (analysers for each trigger path)
0218   _analyzers.clear();
0219   for (std::set<std::string>::iterator iPath = _hltPaths.begin(); iPath != _hltPaths.end(); ++iPath) {
0220     // Avoiding the dependence of the version number for
0221     // the trigger paths
0222     std::string path = *iPath;
0223     std::string shortpath = path;
0224     if (path.rfind("_v") < path.length()) {
0225       shortpath = path.substr(0, path.rfind("_v"));
0226     }
0227     _shortpath2long[shortpath] = path;
0228 
0229     // Objects needed by the HLT path
0230     const std::vector<unsigned int> objsNeedHLT = this->getObjectsType(shortpath);
0231     // Sanity check: the object needed by a trigger path should be
0232     // introduced by the user via config python (_recLabels datamember)
0233     std::vector<unsigned int> userInstantiate;
0234     for (std::map<unsigned int, std::string>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0235       userInstantiate.push_back(it->first);
0236     }
0237     for (std::vector<unsigned int>::const_iterator it = objsNeedHLT.begin(); it != objsNeedHLT.end(); ++it) {
0238       if (std::find(userInstantiate.begin(), userInstantiate.end(), *it) == userInstantiate.end()) {
0239         edm::LogError("HiggsValidation") << "In HLTHiggsSubAnalysis::beginRun, "
0240                                          << "Incoherence found in the python configuration file!!\nThe SubAnalysis '"
0241                                          << _analysisname << "' has been asked to evaluate the trigger path '"
0242                                          << shortpath << "' (found it in 'hltPathsToCheck') BUT this path"
0243                                          << " needs a '" << EVTColContainer::getTypeString(*it)
0244                                          << "' which has not been instantiate ('recVariableLabels'"
0245                                          << ")";
0246         exit(-1);
0247       }
0248     }
0249     LogTrace("HiggsValidation") << " --- " << shortpath;
0250 
0251     // the hlt path, the objects (elec,muons,photons,...)
0252     // needed to evaluate the path are the argumens of the plotter
0253     HLTHiggsPlotter analyzer(_pset, shortpath, objsNeedHLT, NptPlots, _NminOneCuts);
0254     _analyzers.push_back(analyzer);
0255   }
0256 }
0257 
0258 void HLTHiggsSubAnalysis::bookHistograms(DQMStore::IBooker& ibooker) {
0259   std::string baseDir = _histDirectory + "/" + _analysisname + "/";
0260   ibooker.setCurrentFolder(baseDir);
0261   // Book the gen/reco analysis-dependent histograms (denominators)
0262   std::vector<std::string> sources(2);
0263   sources[0] = "gen";
0264   sources[1] = "rec";
0265 
0266   for (std::map<unsigned int, std::string>::const_iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0267     const std::string objStr = EVTColContainer::getTypeString(it->first);
0268     TString maxPt;
0269 
0270     for (size_t i = 0; i < sources.size(); i++) {
0271       std::string source = sources[i];
0272       if (_useNminOneCuts && it->first == EVTColContainer::PFJET) {
0273         if (source == "gen")
0274           continue;
0275         else {
0276           // N-1 jet plots (dEtaqq, mqq, dPhibb, CSV1, maxCSV_jets, maxCSV_E, PFMET, pt1, pt2, pt3, pt4)
0277           if (_NminOneCuts[0])
0278             bookHist(source, objStr, "dEtaqq", ibooker);
0279           if (_NminOneCuts[1])
0280             bookHist(source, objStr, "mqq", ibooker);
0281           if (_NminOneCuts[2])
0282             bookHist(source, objStr, "dPhibb", ibooker);
0283           if (_NminOneCuts[3]) {
0284             if (_NminOneCuts[6])
0285               bookHist(source, objStr, "maxCSV", ibooker);
0286             else
0287               bookHist(source, objStr, "CSV1", ibooker);
0288           }
0289           if (_NminOneCuts[4])
0290             bookHist(source, objStr, "CSV2", ibooker);
0291           if (_NminOneCuts[5])
0292             bookHist(source, objStr, "CSV3", ibooker);
0293         }
0294       }
0295 
0296       bookHist(source, objStr, "Eta", ibooker);
0297       bookHist(source, objStr, "Phi", ibooker);
0298       for (unsigned int i = 0; i < NptPlots; i++) {
0299         maxPt = "MaxPt";
0300         maxPt += i + 1;
0301         bookHist(source, objStr, maxPt.Data(), ibooker);
0302       }
0303     }
0304   }
0305 
0306   // Call the bookHistograms (which books all the path dependent histograms)
0307   for (std::vector<HLTHiggsPlotter>::iterator it = _analyzers.begin(); it != _analyzers.end(); ++it) {
0308     it->bookHistograms(ibooker, _useNminOneCuts);
0309   }
0310   //booking the histograms for overall trigger efficiencies
0311   for (size_t i = 0; i < sources.size(); i++) {
0312     std::string nameGlobalEfficiency = "SummaryPaths_" + _analysisname + "_" + sources[i];
0313 
0314     _elements[nameGlobalEfficiency] = ibooker.book1D(
0315         nameGlobalEfficiency.c_str(), nameGlobalEfficiency.c_str(), _hltPathsToCheck.size(), 0, _hltPathsToCheck.size());
0316 
0317     std::string nameGlobalEfficiencyPassing = nameGlobalEfficiency + "_passingHLT";
0318     _elements[nameGlobalEfficiencyPassing] = ibooker.book1D(nameGlobalEfficiencyPassing.c_str(),
0319                                                             nameGlobalEfficiencyPassing.c_str(),
0320                                                             _hltPathsToCheck.size(),
0321                                                             0,
0322                                                             _hltPathsToCheck.size());
0323 
0324     std::string titlePu = "nb of interations in the event";
0325     std::string nameVtxPlot = "trueVtxDist_" + _analysisname + "_" + sources[i];
0326     std::vector<double> paramsPu = _parametersPu;
0327     int nBinsPu = (int)paramsPu[0];
0328     double minPu = paramsPu[1];
0329     double maxPu = paramsPu[2];
0330 
0331     std::string titleHt = "sum of jet pT in the event";
0332     std::string nameHtPlot = "HtDist_" + _analysisname + "_" + sources[i];
0333     std::vector<double> paramsHt = _parametersHt;
0334     int nBinsHt = (int)paramsHt[0];
0335     double minHt = paramsHt[1];
0336     double maxHt = paramsHt[2];
0337 
0338     if ((!_useNminOneCuts) || sources[i] == "rec")
0339       _elements[nameVtxPlot] = ibooker.book1D(nameVtxPlot.c_str(), titlePu.c_str(), nBinsPu, minPu, maxPu);
0340     if (_bookHtPlots)
0341       _elements[nameHtPlot] = ibooker.book1D(nameHtPlot.c_str(), titleHt.c_str(), nBinsHt, minHt, maxHt);
0342     for (size_t j = 0; j < _hltPathsToCheck.size(); j++) {
0343       //declare the efficiency vs interaction plots
0344       std::string path = _hltPathsToCheck[j];
0345       std::string shortpath = path;
0346       if (path.rfind("_v") < path.length()) {
0347         shortpath = path.substr(0, path.rfind("_v"));
0348       }
0349       std::string titlePassingPu = "nb of interations in the event passing path " + shortpath;
0350       if ((!_useNminOneCuts) || sources[i] == "rec")
0351         _elements[nameVtxPlot + "_" + shortpath] =
0352             ibooker.book1D(nameVtxPlot + "_" + shortpath, titlePassingPu.c_str(), nBinsPu, minPu, maxPu);
0353 
0354       std::string titlePassingHt = "sum of jet pT in the event passing path " + shortpath;
0355       if (_bookHtPlots)
0356         _elements[nameHtPlot + "_" + shortpath] =
0357             ibooker.book1D(nameHtPlot + "_" + shortpath, titlePassingHt.c_str(), nBinsHt, minHt, maxHt);
0358 
0359       //fill the bin labels of the summary plot
0360       _elements[nameGlobalEfficiency]->setBinLabel(j + 1, shortpath);
0361       _elements[nameGlobalEfficiencyPassing]->setBinLabel(j + 1, shortpath);
0362     }
0363   }
0364 }
0365 
0366 void HLTHiggsSubAnalysis::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup, EVTColContainer* cols) {
0367   // Initialize the collection (the ones which hasn't been initialiazed yet)
0368   this->initobjects(iEvent, cols);
0369   // utility map
0370   std::map<unsigned int, std::string> u2str;
0371   u2str[GEN] = "gen";
0372   u2str[RECO] = "rec";
0373 
0374   std::map<unsigned int, double> Htmap;
0375   Htmap[GEN] = 0.;
0376   Htmap[RECO] = 0.;
0377 
0378   edm::Handle<std::vector<PileupSummaryInfo>> puInfo;
0379   iEvent.getByToken(_puSummaryInfo, puInfo);
0380   int nbMCvtx = -1;
0381   if (puInfo.isValid()) {
0382     std::vector<PileupSummaryInfo>::const_iterator PVI;
0383     for (PVI = puInfo->begin(); PVI != puInfo->end(); ++PVI) {
0384       if (PVI->getBunchCrossing() == 0) {
0385         nbMCvtx = PVI->getPU_NumInteractions();
0386         break;
0387       }
0388     }
0389   }
0390 
0391   // Extract the match structure containing the gen/reco candidates (electron, muons,...)
0392   // common to all the SubAnalysis
0393   //---- Generation
0394   // Make each good gen object into the base cand for a MatchStruct
0395   std::vector<MatchStruct>* matches = new std::vector<MatchStruct>;
0396   //  bool alreadyMu = false;
0397   for (std::map<unsigned int, std::string>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0398     // Use genJets for jet matchstructs
0399     if (it->first == EVTColContainer::PFJET) {
0400       // Skip genJets for N-1 plots
0401       if (!_useNminOneCuts) {
0402         // Initialize selectors when first event
0403         if (!_genJetSelector) {
0404           _genJetSelector = new StringCutObjectSelector<reco::GenJet>(_genCut[it->first]);
0405         }
0406         for (size_t i = 0; i < cols->genJets->size(); ++i) {
0407           if (_genJetSelector->operator()(cols->genJets->at(i))) {
0408             matches->push_back(MatchStruct(&cols->genJets->at(i), it->first));
0409           }
0410         }
0411       }
0412     }
0413     // Use genParticles
0414     else {
0415       // Avoiding the TkMu and Mu case
0416       /*      if( alreadyMu )
0417         {
0418             continue;
0419         }*/
0420       // Initialize selectors when first event
0421       if (!_genSelectorMap[it->first]) {
0422         _genSelectorMap[it->first] = new StringCutObjectSelector<reco::GenParticle>(_genCut[it->first]);
0423       }
0424 
0425       for (size_t i = 0; i < cols->genParticles->size(); ++i) {
0426         if (_genSelectorMap[it->first]->operator()(cols->genParticles->at(i))) {
0427           matches->push_back(MatchStruct(&cols->genParticles->at(i), it->first));
0428         }
0429       }
0430       /*      if( it->first == EVTColContainer::MUON || it->first == EVTColContainer::TRACK )
0431         {
0432             alreadyMu = true;
0433         }*/
0434     }
0435   }
0436   // Sort the MatchStructs by pT for later filling of turn-on curve
0437   std::sort(matches->begin(), matches->end(), matchesByDescendingPt());
0438 
0439   // Map to reference the source (gen/reco) with the recoCandidates
0440   std::map<unsigned int, std::vector<MatchStruct>> sourceMatchMap;  // To be a pointer to delete
0441   // --- Storing the generating candidates
0442   sourceMatchMap[GEN] = *matches;
0443 
0444   // Reuse the vector
0445   matches->clear();
0446   // --- same for RECO objects
0447 
0448   // Different treatment for jets (b-tag)
0449   std::map<std::string, bool> nMinOne;
0450   std::map<std::string, bool> jetCutResult;
0451   float dEtaqq;
0452   float mqq;
0453   float dPhibb;
0454   float CSV1;
0455   float CSV2;
0456   float CSV3;
0457   bool passAllCuts = false;
0458   if (_recLabels.find(EVTColContainer::PFJET) != _recLabels.end()) {
0459     // Initialize jet selector
0460     this->InitSelector(EVTColContainer::PFJET);
0461     // Initialize and insert pfJets
0462     this->initAndInsertJets(iEvent, cols, matches);
0463     // Make sure to skip events that don't have enough jets
0464     if (matches->size() < NptPlots) {
0465       delete matches;
0466       return;
0467     }
0468     // Cuts on multiple jet events (RECO)
0469     if (_useNminOneCuts) {
0470       this->passJetCuts(matches, jetCutResult, dEtaqq, mqq, dPhibb, CSV1, CSV2, CSV3);
0471     }
0472   }
0473   // Extraction of the objects candidates
0474   for (std::map<unsigned int, std::string>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0475     // Reco selectors (the function takes into account if it was instantiated
0476     // before or not
0477     this->InitSelector(it->first);
0478     // -- Storing the matches
0479     this->insertcandidates(it->first, cols, matches);
0480   }
0481 
0482   // Sort the MatchStructs by pT for later filling of turn-on curve
0483   std::sort(matches->begin(), matches->end(), matchesByDescendingPt());
0484 
0485   if (_useNminOneCuts) {
0486     // Check non-jet N-1 Cuts
0487     this->passOtherCuts(*matches, jetCutResult);
0488 
0489     // Make N-1 booleans from jetCutResults
0490     for (std::map<std::string, bool>::const_iterator it = jetCutResult.begin(); it != jetCutResult.end(); ++it) {
0491       nMinOne[it->first] = true;
0492       for (std::map<std::string, bool>::const_iterator it2 = jetCutResult.begin(); it2 != jetCutResult.end(); ++it2) {
0493         //ignore CSV2,CSV3 cut plotting CSV1
0494         if (it->first == "CSV1" && it2->first == "CSV3")
0495           continue;
0496         if (it->first == "CSV1" && it2->first == "CSV2")
0497           continue;
0498 
0499         //ignore CSV3 plotting cut CSV2
0500         if (it->first == "CSV2" && it2->first == "CSV3")
0501           continue;
0502 
0503         if (it->first != it2->first && !(it2->second)) {
0504           nMinOne[it->first] = false;
0505           break;
0506         }
0507       }
0508     }
0509     bool temp = false;
0510     for (std::map<std::string, bool>::const_iterator it = nMinOne.begin(); it != nMinOne.end(); ++it) {
0511       if (temp && it->second) {
0512         passAllCuts = true;
0513         break;
0514       }
0515       if (it->second)
0516         temp = true;
0517     }
0518   }
0519 
0520   // --- Storing the reco candidates
0521   sourceMatchMap[RECO] = *matches;
0522   // --- All the objects are in place
0523   delete matches;
0524 
0525   // -- Trigger Results
0526   const edm::TriggerNames& trigNames = iEvent.triggerNames(*(cols->triggerResults));
0527 
0528   if (_bookHtPlots) {
0529     edm::Handle<reco::PFJetCollection> recoJet;
0530     iEvent.getByToken(_recoHtJetLabel, recoJet);
0531     if (recoJet.isValid()) {
0532       for (reco::PFJetCollection::const_iterator iJet = recoJet->begin(); iJet != recoJet->end(); iJet++) {
0533         double pt = iJet->pt();
0534         double eta = iJet->eta();
0535         if (pt > _HtJetPtMin && fabs(eta) < _HtJetEtaMax) {
0536           Htmap[RECO] += pt;
0537         }
0538       }
0539     }
0540 
0541     edm::Handle<reco::GenJetCollection> genJet;
0542     iEvent.getByToken(_genJetLabel, genJet);
0543     if (genJet.isValid()) {
0544       for (reco::GenJetCollection::const_iterator iJet = genJet->begin(); iJet != genJet->end(); iJet++) {
0545         double pt = iJet->pt();
0546         double eta = iJet->eta();
0547         if (pt > _HtJetPtMin && fabs(eta) < _HtJetEtaMax) {
0548           Htmap[GEN] += pt;
0549         }
0550       }
0551     }
0552   }
0553 
0554   // Filling the histograms if pass the minimum amount of candidates needed by the analysis:
0555   // GEN + RECO CASE in the same loop
0556   for (std::map<unsigned int, std::vector<MatchStruct>>::iterator it = sourceMatchMap.begin();
0557        it != sourceMatchMap.end();
0558        ++it) {
0559     // it->first: gen/reco   it->second: matches (std::vector<MatchStruc>)
0560     if (it->second.size() < _minCandidates)  // FIXME: A bug is potentially here: what about the mixed channels?
0561     {
0562       continue;
0563     }
0564 
0565     // Filling the gen/reco objects (eff-denominators):
0566     // Just the first two different ones, if there are more
0567     std::map<unsigned int, int>* countobjects = new std::map<unsigned int, int>;
0568     // Initializing the count of the used object
0569     for (std::map<unsigned int, std::string>::iterator co = _recLabels.begin(); co != _recLabels.end(); ++co) {
0570       if (!(_useNminOneCuts && co->first == EVTColContainer::PFJET && it->first == GEN))  // genJets are not there
0571         countobjects->insert(std::pair<unsigned int, int>(co->first, 0));
0572     }
0573     int counttotal = 0;
0574     const int totalobjectssize2 = NptPlots * countobjects->size();
0575     for (size_t j = 0; j < it->second.size(); ++j) {
0576       const unsigned int objType = it->second[j].objType;
0577       const std::string objTypeStr = EVTColContainer::getTypeString(objType);
0578 
0579       float pt = (it->second)[j].pt;
0580       float eta = (it->second)[j].eta;
0581       float phi = (it->second)[j].phi;
0582 
0583       // PFMET N-1 cut
0584       if (_useNminOneCuts && objType == EVTColContainer::PFMET && _NminOneCuts[8] && !nMinOne["PFMET"]) {
0585         continue;
0586       }
0587 
0588       TString maxPt;
0589       if ((unsigned)(*countobjects)[objType] < NptPlots) {
0590         maxPt = "MaxPt";
0591         maxPt += (*countobjects)[objType] + 1;
0592         if (_useNminOneCuts && objType == EVTColContainer::PFJET) {
0593           if (nMinOne[maxPt.Data()]) {
0594             this->fillHist(u2str[it->first], objTypeStr, maxPt.Data(), pt);
0595           }
0596         } else {
0597           this->fillHist(u2str[it->first], objTypeStr, maxPt.Data(), pt);
0598         }
0599         // Filled the high pt ...
0600         ++((*countobjects)[objType]);
0601         ++counttotal;
0602       } else {
0603         if ((unsigned)(*countobjects)[objType] < _minCandidates) {  // To get correct results for HZZ
0604           ++((*countobjects)[objType]);
0605           ++counttotal;
0606         } else
0607           continue;  //   Otherwise too many entries in Eta and Phi distributions
0608       }
0609 
0610       // Jet N-1 Cuts
0611       if (_useNminOneCuts && objType == EVTColContainer::PFJET) {
0612         if (passAllCuts) {
0613           this->fillHist(u2str[it->first], objTypeStr, "Eta", eta);
0614           this->fillHist(u2str[it->first], objTypeStr, "Phi", phi);
0615         }
0616       } else {
0617         this->fillHist(u2str[it->first], objTypeStr, "Eta", eta);
0618         this->fillHist(u2str[it->first], objTypeStr, "Phi", phi);
0619       }
0620 
0621       // Already the minimum two objects has been filled, get out...
0622       if (counttotal == totalobjectssize2) {
0623         break;
0624       }
0625     }
0626     delete countobjects;
0627 
0628     if (_useNminOneCuts && it->first == RECO) {
0629       if (_NminOneCuts[0] && nMinOne["dEtaqq"]) {
0630         this->fillHist(u2str[it->first], EVTColContainer::getTypeString(EVTColContainer::PFJET), "dEtaqq", dEtaqq);
0631       }
0632       if (_NminOneCuts[1] && nMinOne["mqq"]) {
0633         this->fillHist(u2str[it->first], EVTColContainer::getTypeString(EVTColContainer::PFJET), "mqq", mqq);
0634       }
0635       if (_NminOneCuts[2] && nMinOne["dPhibb"]) {
0636         this->fillHist(u2str[it->first], EVTColContainer::getTypeString(EVTColContainer::PFJET), "dPhibb", dPhibb);
0637       }
0638       if (_NminOneCuts[3]) {
0639         std::string nameCSVplot = "CSV1";
0640         if (_NminOneCuts[6])
0641           nameCSVplot = "maxCSV";
0642         if (nMinOne[nameCSVplot])
0643           this->fillHist(u2str[it->first], EVTColContainer::getTypeString(EVTColContainer::PFJET), nameCSVplot, CSV1);
0644       }
0645       if (_NminOneCuts[4] && nMinOne["CSV2"]) {
0646         this->fillHist(u2str[it->first], EVTColContainer::getTypeString(EVTColContainer::PFJET), "CSV2", CSV2);
0647       }
0648       if (_NminOneCuts[5] && nMinOne["CSV3"]) {
0649         this->fillHist(u2str[it->first], EVTColContainer::getTypeString(EVTColContainer::PFJET), "CSV3", CSV3);
0650       }
0651     }
0652 
0653     //fill the efficiency vs nb of interactions
0654     std::string nameVtxPlot = "trueVtxDist_" + _analysisname + "_" + u2str[it->first];
0655     if ((!_useNminOneCuts) || it->first == RECO)
0656       _elements[nameVtxPlot]->Fill(nbMCvtx);
0657 
0658     //fill the efficiency vs sum pT of jets
0659     std::string nameHtPlot = "HtDist_" + _analysisname + "_" + u2str[it->first];
0660     if (_bookHtPlots)
0661       _elements[nameHtPlot]->Fill(Htmap[it->first]);
0662 
0663     // Calling to the plotters analysis (where the evaluation of the different trigger paths are done)
0664     std::string SummaryName = "SummaryPaths_" + _analysisname + "_" + u2str[it->first];
0665     const std::string source = u2str[it->first];
0666     for (std::vector<HLTHiggsPlotter>::iterator an = _analyzers.begin(); an != _analyzers.end(); ++an) {
0667       const std::string hltPath = _shortpath2long[an->gethltpath()];
0668       const std::string fillShortPath = an->gethltpath();
0669       const bool ispassTrigger = cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
0670 
0671       if (_useNminOneCuts) {
0672         an->analyze(ispassTrigger, source, it->second, nMinOne, dEtaqq, mqq, dPhibb, CSV1, CSV2, CSV3, passAllCuts);
0673       } else {
0674         an->analyze(ispassTrigger, source, it->second, _minCandidates);
0675       }
0676 
0677       int refOfThePath = -1;
0678       for (size_t itePath = 0; itePath < _hltPathsToCheck.size(); itePath++) {
0679         refOfThePath++;
0680         if (TString(hltPath).Contains(_hltPathsToCheck[itePath]))
0681           break;
0682       }
0683       _elements[SummaryName]->Fill(refOfThePath);
0684       if (ispassTrigger) {
0685         _elements[SummaryName + "_passingHLT"]->Fill(refOfThePath, 1);
0686         if ((!_useNminOneCuts) || it->first == RECO)
0687           _elements[nameVtxPlot + "_" + fillShortPath]->Fill(nbMCvtx);
0688         if (_bookHtPlots)
0689           _elements[nameHtPlot + "_" + fillShortPath]->Fill(Htmap[it->first]);
0690       } else {
0691         _elements[SummaryName + "_passingHLT"]->Fill(refOfThePath, 0);
0692       }
0693     }
0694   }
0695 }
0696 
0697 // Return the objects (muons,electrons,photons,...) needed by a hlt path.
0698 const std::vector<unsigned int> HLTHiggsSubAnalysis::getObjectsType(const std::string& hltPath) const {
0699   static const unsigned int objSize = 7;
0700   static const unsigned int objtriggernames[] = {EVTColContainer::MUON,
0701                                                  EVTColContainer::ELEC,
0702                                                  EVTColContainer::PHOTON,
0703                                                  //      EVTColContainer::TRACK,  // Note is tracker muon
0704                                                  EVTColContainer::PFTAU,
0705                                                  EVTColContainer::PFJET,
0706                                                  EVTColContainer::CALOMET,
0707                                                  EVTColContainer::PFMET};
0708 
0709   std::set<unsigned int> objsType;
0710   // The object to deal has to be entered via the config .py
0711   for (unsigned int i = 0; i < objSize; ++i) {
0712     std::string objTypeStr = EVTColContainer::getTypeString(objtriggernames[i]);
0713     // Check if it is needed this object for this trigger
0714     if (!TString(hltPath).Contains(objTypeStr)) {
0715       if ((objtriggernames[i] == EVTColContainer::PFJET &&
0716            TString(hltPath).Contains("WHbbBoost")) ||  // fix for HLT_Ele27_WPLoose_Gsf_WHbbBoost_v
0717           (objtriggernames[i] == EVTColContainer::PFJET && TString(hltPath).Contains("CSV")) ||  // fix for ZnnHbb PFJET
0718           (objtriggernames[i] == EVTColContainer::PFMET && TString(hltPath).Contains("MHT")) ||  // fix for ZnnHbb PFMET
0719           (objtriggernames[i] == EVTColContainer::PHOTON && TString(hltPath).Contains("Diphoton"))) {
0720         objsType.insert(objtriggernames[i]);  //case of the New Diphoton paths
0721       }
0722       continue;
0723     }
0724     if ((objtriggernames[i] == EVTColContainer::CALOMET &&
0725          (TString(hltPath).Contains("PFMET") || TString(hltPath).Contains("MHT"))) ||  // fix for PFMET
0726         (objtriggernames[i] == EVTColContainer::PFJET && TString(hltPath).Contains("JetIdCleaned") &&
0727          !TString(hltPath).Contains(TRegexp("Jet[^I]"))) ||                                     // fix for Htaunu
0728         (objtriggernames[i] == EVTColContainer::MUON && TString(hltPath).Contains("METNoMu")))  // fix for VBFHToInv
0729     {
0730       continue;
0731     }
0732 
0733     objsType.insert(objtriggernames[i]);
0734   }
0735 
0736   return std::vector<unsigned int>(objsType.begin(), objsType.end());
0737 }
0738 
0739 // Booking the maps: recLabels and genParticle selectors
0740 void HLTHiggsSubAnalysis::bookobjects(const edm::ParameterSet& anpset, edm::ConsumesCollector& iC) {
0741   if (anpset.exists("recMuonLabel")) {
0742     _recLabels[EVTColContainer::MUON] = anpset.getParameter<std::string>("recMuonLabel");
0743     _recLabelsMuon = iC.consumes<reco::MuonCollection>(anpset.getParameter<std::string>("recMuonLabel"));
0744     _genSelectorMap[EVTColContainer::MUON] = nullptr;
0745   }
0746   if (anpset.exists("recElecLabel")) {
0747     _recLabels[EVTColContainer::ELEC] = anpset.getParameter<std::string>("recElecLabel");
0748     _recLabelsElec = iC.consumes<reco::GsfElectronCollection>(anpset.getParameter<std::string>("recElecLabel"));
0749     _genSelectorMap[EVTColContainer::ELEC] = nullptr;
0750   }
0751   if (anpset.exists("recPhotonLabel")) {
0752     _recLabels[EVTColContainer::PHOTON] = anpset.getParameter<std::string>("recPhotonLabel");
0753     _recLabelsPhoton = iC.consumes<reco::PhotonCollection>(anpset.getParameter<std::string>("recPhotonLabel"));
0754     _genSelectorMap[EVTColContainer::PHOTON] = nullptr;
0755   }
0756   if (anpset.exists("recCaloMETLabel")) {
0757     _recLabels[EVTColContainer::CALOMET] = anpset.getParameter<std::string>("recCaloMETLabel");
0758     _recLabelsCaloMET = iC.consumes<reco::CaloMETCollection>(anpset.getParameter<std::string>("recCaloMETLabel"));
0759     _genSelectorMap[EVTColContainer::CALOMET] = nullptr;
0760   }
0761   if (anpset.exists("recPFMETLabel")) {
0762     _recLabels[EVTColContainer::PFMET] = anpset.getParameter<std::string>("recPFMETLabel");
0763     _recLabelsPFMET = iC.consumes<reco::PFMETCollection>(anpset.getParameter<std::string>("recPFMETLabel"));
0764     _genSelectorMap[EVTColContainer::PFMET] = nullptr;
0765   }
0766   if (anpset.exists("recPFTauLabel")) {
0767     _recLabels[EVTColContainer::PFTAU] = anpset.getParameter<std::string>("recPFTauLabel");
0768     _recLabelsPFTau = iC.consumes<reco::PFTauCollection>(anpset.getParameter<std::string>("recPFTauLabel"));
0769     _genSelectorMap[EVTColContainer::PFTAU] = nullptr;
0770   }
0771   if (anpset.exists("recJetLabel")) {
0772     _recLabels[EVTColContainer::PFJET] = anpset.getParameter<std::string>("recJetLabel");
0773     _recLabelsPFJet = iC.consumes<reco::PFJetCollection>(anpset.getParameter<std::string>("recJetLabel"));
0774     if (anpset.exists("jetTagLabel"))
0775       _recTagPFJet = iC.consumes<reco::JetTagCollection>(anpset.getParameter<std::string>("jetTagLabel"));
0776     _genJetSelector = nullptr;
0777   }
0778   /*if( anpset.exists("recTrackLabel") )
0779     {
0780         _recLabels[EVTColContainer::TRACK] = anpset.getParameter<std::string>("recTrackLabel");
0781         _genSelectorMap[EVTColContainer::TRACK] = 0 ;
0782     }*/
0783 
0784   if (_recLabels.empty()) {
0785     edm::LogError("HiggsValidation") << "HLTHiggsSubAnalysis::bookobjects, "
0786                                      << "Not included any object (recMuonLabel, recElecLabel, ...)  "
0787                                      << "in the analysis " << _analysisname;
0788     return;
0789   }
0790 }
0791 
0792 void HLTHiggsSubAnalysis::initobjects(const edm::Event& iEvent, EVTColContainer* col) {
0793   /*if( col != 0 && col->isAllInit() )
0794     {
0795         // Already init, not needed to do nothing
0796         return;
0797     }*/
0798   if (!col->isCommonInit()) {
0799     // extract the trigger results (path info, pass,...)
0800     edm::Handle<edm::TriggerResults> trigResults;
0801     iEvent.getByToken(_trigResultsTag, trigResults);
0802     if (trigResults.isValid()) {
0803       col->triggerResults = trigResults.product();
0804     }
0805 
0806     // GenParticle collection if is there (genJets only if there need to be jets)
0807     edm::Handle<reco::GenParticleCollection> genPart;
0808     iEvent.getByToken(_genParticleLabel, genPart);
0809     if (genPart.isValid()) {
0810       col->genParticles = genPart.product();
0811     }
0812   }
0813 
0814   for (std::map<unsigned int, std::string>::iterator it = _recLabels.begin(); it != _recLabels.end(); ++it) {
0815     if (it->first == EVTColContainer::MUON) {
0816       edm::Handle<reco::MuonCollection> theHandle;
0817       iEvent.getByToken(_recLabelsMuon, theHandle);
0818       col->set(theHandle.product());
0819     } else if (it->first == EVTColContainer::ELEC) {
0820       edm::Handle<reco::GsfElectronCollection> theHandle;
0821       iEvent.getByToken(_recLabelsElec, theHandle);
0822       col->set(theHandle.product());
0823     } else if (it->first == EVTColContainer::PHOTON) {
0824       edm::Handle<reco::PhotonCollection> theHandle;
0825       iEvent.getByToken(_recLabelsPhoton, theHandle);
0826       col->set(theHandle.product());
0827     } else if (it->first == EVTColContainer::CALOMET) {
0828       edm::Handle<reco::CaloMETCollection> theHandle;
0829       iEvent.getByToken(_recLabelsCaloMET, theHandle);
0830       col->set(theHandle.product());
0831     } else if (it->first == EVTColContainer::PFMET) {
0832       edm::Handle<reco::PFMETCollection> theHandle;
0833       iEvent.getByToken(_recLabelsPFMET, theHandle);
0834       col->set(theHandle.product());
0835     } else if (it->first == EVTColContainer::PFTAU) {
0836       edm::Handle<reco::PFTauCollection> theHandle;
0837       iEvent.getByToken(_recLabelsPFTau, theHandle);
0838       col->set(theHandle.product());
0839     }
0840     // PFJets loaded in seperate function initAndInsertJets because they need to be combined with the btags using the Handle (not the product) and for ordering them seperately in the MatchStruct's
0841     else if (it->first == EVTColContainer::PFJET) {
0842       if (!_useNminOneCuts) {
0843         // GenJet collection
0844         edm::Handle<reco::GenJetCollection> genJet;
0845         iEvent.getByToken(_genJetLabel, genJet);
0846         if (genJet.isValid()) {
0847           col->genJets = genJet.product();
0848         }
0849       }
0850     } else {
0851       edm::LogError("HiggsValidation") << "HLTHiggsSubAnalysis::initobjects "
0852                                        << " NOT IMPLEMENTED (yet) ERROR: '" << it->second << "'";
0853       //return; ??
0854     }
0855   }
0856 }
0857 
0858 void HLTHiggsSubAnalysis::bookHist(const std::string& source,
0859                                    const std::string& objType,
0860                                    const std::string& variable,
0861                                    DQMStore::IBooker& ibooker) {
0862   std::string sourceUpper = source;
0863   sourceUpper[0] = std::toupper(sourceUpper[0]);
0864   std::string name = source + objType + variable;
0865   TH1F* h = nullptr;
0866 
0867   if (variable.find("MaxPt") != std::string::npos) {
0868     std::string desc;
0869     if (variable == "MaxPt1")
0870       desc = "Leading";
0871     else if (variable == "MaxPt2")
0872       desc = "Next-to-Leading";
0873     else
0874       desc = variable.substr(5, 6) + "th Leading";
0875     std::string title = "pT of " + desc + " " + sourceUpper + " " + objType;
0876     const size_t nBinsStandard = _parametersTurnOn.size() - 1;
0877     size_t nBins = nBinsStandard;
0878     float* edges = new float[nBinsStandard + 1];
0879     for (size_t i = 0; i < nBinsStandard + 1; i++) {
0880       edges[i] = _parametersTurnOn[i];
0881     }
0882 
0883     std::string jetObj = EVTColContainer::getTypeString(EVTColContainer::PFJET);
0884     if (objType == jetObj) {
0885       const size_t nBinsJets = 25;
0886       nBins = nBinsJets;
0887       delete[] edges;
0888       edges = new float[nBinsJets + 1];
0889       for (size_t i = 0; i < nBinsJets + 1; i++) {
0890         edges[i] = i * 10;
0891       }
0892     }
0893     if (objType == EVTColContainer::getTypeString(EVTColContainer::PFMET)) {
0894       const size_t nBinsJets = 30;
0895       nBins = nBinsJets;
0896       delete[] edges;
0897       edges = new float[nBinsJets + 1];
0898       for (size_t i = 0; i < nBinsJets + 1; i++) {
0899         edges[i] = i * 10;
0900       }
0901     }
0902     h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
0903     delete[] edges;
0904   } else if (variable == "dEtaqq") {
0905     std::string title = "#Delta #eta_{qq} of " + sourceUpper + " " + objType;
0906     int nBins = 20;
0907     double min = 0;
0908     double max = 4.8;
0909     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
0910   } else if (variable == "mqq") {
0911     std::string title = "m_{qq} of " + sourceUpper + " " + objType;
0912     int nBins = 20;
0913     double min = 0;
0914     double max = 1000;
0915     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
0916   } else if (variable == "dPhibb") {
0917     std::string title = "#Delta #phi_{bb} of " + sourceUpper + " " + objType;
0918     int nBins = 10;
0919     double min = 0;
0920     double max = 3.1416;
0921     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
0922   } else if (variable == "CSV1") {
0923     std::string title = "CSV1 of " + sourceUpper + " " + objType;
0924     int nBins = 20;
0925     double min = 0;
0926     double max = 1;
0927     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
0928   } else if (variable == "CSV2") {
0929     std::string title = "CSV2 of " + sourceUpper + " " + objType;
0930     int nBins = 20;
0931     double min = 0;
0932     double max = 1;
0933     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
0934   } else if (variable == "CSV3") {
0935     std::string title = "CSV3 of " + sourceUpper + " " + objType;
0936     int nBins = 20;
0937     double min = 0;
0938     double max = 1;
0939     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
0940   } else if (variable == "maxCSV") {
0941     std::string title = "max CSV of " + sourceUpper + " " + objType;
0942     int nBins = 20;
0943     double min = 0;
0944     double max = 1;
0945     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
0946   } else {
0947     std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
0948     std::string title = symbol + " of " + sourceUpper + " " + objType;
0949     std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
0950 
0951     int nBins = (int)params[0];
0952     double min = params[1];
0953     double max = params[2];
0954     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
0955   }
0956   h->Sumw2();
0957   _elements[name] = ibooker.book1D(name, h);
0958   delete h;
0959 }
0960 
0961 void HLTHiggsSubAnalysis::fillHist(const std::string& source,
0962                                    const std::string& objType,
0963                                    const std::string& variable,
0964                                    const float& value) {
0965   std::string sourceUpper = source;
0966   sourceUpper[0] = toupper(sourceUpper[0]);
0967   std::string name = source + objType + variable;
0968 
0969   _elements[name]->Fill(value);
0970 }
0971 
0972 // Initialize the selectors
0973 void HLTHiggsSubAnalysis::InitSelector(const unsigned int& objtype) {
0974   if (objtype == EVTColContainer::MUON && _recMuonSelector == nullptr) {
0975     _recMuonSelector = new StringCutObjectSelector<reco::Muon>(_recCut[objtype]);
0976   } else if (objtype == EVTColContainer::ELEC && _recElecSelector == nullptr) {
0977     _recElecSelector = new StringCutObjectSelector<reco::GsfElectron>(_recCut[objtype]);
0978   } else if (objtype == EVTColContainer::PHOTON && _recPhotonSelector == nullptr) {
0979     _recPhotonSelector = new StringCutObjectSelector<reco::Photon>(_recCut[objtype]);
0980   } else if (objtype == EVTColContainer::CALOMET && _recCaloMETSelector == nullptr) {
0981     _recCaloMETSelector = new StringCutObjectSelector<reco::CaloMET>(_recCut[objtype]);
0982   } else if (objtype == EVTColContainer::PFMET && _recPFMETSelector == nullptr) {
0983     _recPFMETSelector = new StringCutObjectSelector<reco::PFMET>(_recCut[objtype]);
0984   } else if (objtype == EVTColContainer::PFTAU && _recPFTauSelector == nullptr) {
0985     _recPFTauSelector = new StringCutObjectSelector<reco::PFTau>(_recCut[objtype]);
0986   } else if (objtype == EVTColContainer::PFJET && _recPFJetSelector == nullptr) {
0987     _recPFJetSelector = new StringCutObjectSelector<reco::PFJet>(_recCut[objtype]);
0988   }
0989   /*else if( objtype == EVTColContainer::TRACK && _recTrackSelector == 0)
0990     {
0991         _recTrackSelector = new StringCutObjectSelector<reco::Track>(_recCut[objtype]);
0992     }*/
0993   /*  else
0994     {
0995 FIXME: ERROR NO IMPLEMENTADO
0996     }*/
0997 }
0998 
0999 void HLTHiggsSubAnalysis::initAndInsertJets(const edm::Event& iEvent,
1000                                             EVTColContainer* cols,
1001                                             std::vector<MatchStruct>* matches) {
1002   edm::Handle<reco::PFJetCollection> PFJetHandle;
1003   iEvent.getByToken(_recLabelsPFJet, PFJetHandle);
1004   cols->set(PFJetHandle.product());
1005 
1006   edm::Handle<reco::JetTagCollection> JetTagHandle;
1007   if (_useNminOneCuts) {
1008     iEvent.getByToken(_recTagPFJet, JetTagHandle);
1009   }
1010 
1011   for (reco::PFJetCollection::const_iterator it = PFJetHandle->begin(); it != PFJetHandle->end(); ++it) {
1012     reco::PFJetRef jetRef(PFJetHandle, it - PFJetHandle->begin());
1013     reco::JetBaseRef jetBaseRef(jetRef);
1014 
1015     if (_recPFJetSelector->operator()(*it)) {
1016       if (_useNminOneCuts) {
1017         float bTag = (*(JetTagHandle.product()))[jetBaseRef];
1018         matches->push_back(MatchStruct(&*it, EVTColContainer::PFJET, bTag));
1019       } else {
1020         matches->push_back(MatchStruct(&*it, EVTColContainer::PFJET));
1021       }
1022     }
1023   }
1024 }
1025 
1026 void HLTHiggsSubAnalysis::passJetCuts(
1027     std::vector<MatchStruct>* matches,
1028     std::map<std::string, bool>& jetCutResult,
1029     float& dEtaqq,
1030     float& mqq,
1031     float& dPhibb,
1032     float& CSV1,
1033     float& CSV2,
1034     float& CSV3) {  //dEtaqq, mqq, dPhibb, CSV1, CSV2, CSV3, maxCSV_jets, maxCSV_E, PFMET, pt1, pt2, pt3, pt4
1035 
1036   // Perform pt cuts
1037   std::sort(matches->begin(), matches->end(), matchesByDescendingPt());
1038   TString maxPt;
1039   for (unsigned int i = 0; i < NptPlots; i++) {
1040     maxPt = "MaxPt";
1041     maxPt += i + 1;
1042     if ((*matches)[i].pt > _NminOneCuts[9 + i])
1043       jetCutResult[maxPt.Data()] = true;
1044     else
1045       jetCutResult[maxPt.Data()] = false;
1046   }
1047 
1048   unsigned int NbTag = ((_NminOneCuts[0] || _NminOneCuts[1]) ? 4 : 8);
1049   if (matches->size() < NbTag)
1050     NbTag = matches->size();
1051   // Perform b-tag ordered cuts
1052   std::sort(matches->begin(), matches->begin() + NbTag, matchesByDescendingBtag());
1053 
1054   if (_NminOneCuts[0]) {
1055     jetCutResult["dEtaqq"] = false;
1056     if (matches->size() > 2) {
1057       dEtaqq = fabs((*matches)[2].eta - (*matches)[3].eta);
1058       if (dEtaqq > _NminOneCuts[0])
1059         jetCutResult["dEtaqq"] = true;
1060     }
1061   }
1062 
1063   if (_NminOneCuts[1]) {
1064     jetCutResult["mqq"] = false;
1065     if (matches->size() > 2) {
1066       mqq = ((*matches)[2].lorentzVector + (*matches)[3].lorentzVector).M();
1067       if (mqq > _NminOneCuts[1])
1068         jetCutResult["mqq"] = true;
1069     }
1070   }
1071 
1072   if (_NminOneCuts[2]) {
1073     jetCutResult["dPhibb"] = false;
1074     if (matches->size() > 1) {
1075       dPhibb = fmod(fabs((*matches)[0].phi - (*matches)[1].phi), 3.1416);
1076       if (dPhibb < _NminOneCuts[2])
1077         jetCutResult["dPhibb"] = true;
1078     }
1079   }
1080 
1081   if (_NminOneCuts[4]) {
1082     std::string nameCSV2plot = "CSV2";
1083     jetCutResult[nameCSV2plot] = false;
1084     if (matches->size() > 1) {
1085       CSV2 = (*matches)[1].bTag;
1086       if (CSV2 > _NminOneCuts[4])
1087         jetCutResult[nameCSV2plot] = true;
1088     }
1089   }
1090 
1091   if (_NminOneCuts[5]) {
1092     std::string nameCSV3plot = "CSV3";
1093     jetCutResult[nameCSV3plot] = false;
1094     if (matches->size() > 2) {
1095       CSV3 = (*matches)[2].bTag;
1096       if (CSV3 > _NminOneCuts[5])
1097         jetCutResult[nameCSV3plot] = true;
1098     }
1099   }
1100 
1101   if (_NminOneCuts[3]) {
1102     CSV1 = (*matches)[0].bTag;
1103     std::string nameCSVplot = "CSV1";
1104     if (_NminOneCuts[6])
1105       nameCSVplot = "maxCSV";
1106 
1107     if (CSV1 > _NminOneCuts[3])
1108       jetCutResult[nameCSVplot] = true;
1109     else
1110       jetCutResult[nameCSVplot] = false;
1111 
1112     // max(CSV)
1113     if (_NminOneCuts[6]) {
1114       std::sort(matches->begin(), matches->end(), matchesByDescendingPt());
1115       CSV1 = (*matches)[0].bTag;
1116       unsigned int Njets = (unsigned int)_NminOneCuts[6];
1117       if (_NminOneCuts[6] > matches->size())
1118         Njets = matches->size();
1119       for (unsigned int i = 1; i < (unsigned int)Njets; ++i) {
1120         if ((*matches)[i].bTag > CSV1 && (*matches)[i].pt > _NminOneCuts[7])
1121           CSV1 = (*matches)[i].bTag;
1122       }
1123     }
1124   }
1125 }
1126 
1127 void HLTHiggsSubAnalysis::passOtherCuts(const std::vector<MatchStruct>& matches,
1128                                         std::map<std::string, bool>& jetCutResult) {
1129   if (_NminOneCuts[8]) {
1130     jetCutResult["PFMET"] = false;
1131     for (std::vector<MatchStruct>::const_iterator it = matches.begin(); it != matches.end(); ++it) {
1132       if (it->objType == EVTColContainer::PFMET) {
1133         if (it->pt > _NminOneCuts[8])
1134           jetCutResult["PFMET"] = true;
1135         break;
1136       }
1137     }
1138   }
1139 }
1140 
1141 void HLTHiggsSubAnalysis::insertcandidates(const unsigned int& objType,
1142                                            const EVTColContainer* cols,
1143                                            std::vector<MatchStruct>* matches) {
1144   if (objType == EVTColContainer::MUON) {
1145     for (size_t i = 0; i < cols->muons->size(); i++) {
1146       if (_recMuonSelector->operator()(cols->muons->at(i))) {
1147         matches->push_back(MatchStruct(&cols->muons->at(i), objType));
1148       }
1149     }
1150   } else if (objType == EVTColContainer::ELEC) {
1151     for (size_t i = 0; i < cols->electrons->size(); i++) {
1152       if (_recElecSelector->operator()(cols->electrons->at(i))) {
1153         matches->push_back(MatchStruct(&cols->electrons->at(i), objType));
1154       }
1155     }
1156   } else if (objType == EVTColContainer::PHOTON) {
1157     for (size_t i = 0; i < cols->photons->size(); i++) {
1158       if (_recPhotonSelector->operator()(cols->photons->at(i))) {
1159         matches->push_back(MatchStruct(&cols->photons->at(i), objType));
1160       }
1161     }
1162   } else if (objType == EVTColContainer::CALOMET) {
1163     for (size_t i = 0; i < cols->caloMETs->size(); i++) {
1164       if (_recCaloMETSelector->operator()(cols->caloMETs->at(i))) {
1165         matches->push_back(MatchStruct(&cols->caloMETs->at(i), objType));
1166       }
1167     }
1168   } else if (objType == EVTColContainer::PFMET) {
1169     for (size_t i = 0; i < cols->pfMETs->size(); i++) {
1170       if (_recPFMETSelector->operator()(cols->pfMETs->at(i))) {
1171         matches->push_back(MatchStruct(&cols->pfMETs->at(i), objType));
1172       }
1173     }
1174   } else if (objType == EVTColContainer::PFTAU) {
1175     for (size_t i = 0; i < cols->pfTaus->size(); i++) {
1176       if (_recPFTauSelector->operator()(cols->pfTaus->at(i))) {
1177         matches->push_back(MatchStruct(&cols->pfTaus->at(i), objType));
1178       }
1179     }
1180   }
1181   //  else if( objType == EVTColContainer::PFJET )
1182   //  {
1183   //  already inserted
1184   //  }
1185   /*else if( objType == EVTColContainer::TRACK )
1186     {
1187         for(size_t i = 0; i < cols->tracks->size(); i++)
1188         {
1189             if(_recTrackSelector->operator()(cols->tracks->at(i)))
1190             {
1191                 matches->push_back(MatchStruct(&cols->tracks->at(i),objType));
1192             }
1193         }
1194     }*/
1195   /*
1196     else FIXME: Control errores
1197     {
1198     }
1199     */
1200 }