Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:31:47

0001 // -*- C++ -*-
0002 //
0003 // Package:    TauTagValidation
0004 // Class:      TauTagValidation
0005 //
0006 /**\class TauTagValidation TauTagValidation.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Class used to do the Validation of the TauTag
0011 
0012  Implementation:
0013  <Notes on implementation>
0014  */
0015 //
0016 // Original Author:  Ricardo Vasquez Sierra
0017 //         Created:  October 8, 2008
0018 //
0019 //Modified by: Atanu Modak to include extra plots
0020 // user include files
0021 
0022 #include "Validation/RecoTau/interface/TauTagValidation.h"
0023 #include "FWCore/Version/interface/GetReleaseVersion.h"
0024 #include <DataFormats/VertexReco/interface/Vertex.h>
0025 #include <DataFormats/VertexReco/interface/VertexFwd.h>
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 
0028 #include "PhysicsTools/JetMCUtils/interface/JetMCTag.h"
0029 #include "DataFormats/JetReco/interface/GenJet.h"
0030 #include "DataFormats/TauReco/interface/PFTauFwd.h"
0031 #include "DataFormats/TauReco/interface/PFTau.h"
0032 
0033 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0034 #include "RecoTauTag/RecoTau/interface/PFTauDecayModeTools.h"
0035 
0036 using namespace edm;
0037 using namespace std;
0038 using namespace reco;
0039 
0040 TauTagValidation::TauTagValidation(const edm::ParameterSet& iConfig)
0041     : moduleLabel_(iConfig.getParameter<std::string>("@module_label")),
0042       // What do we want to use as source Leptons or Jets (the only difference is the matching criteria)
0043       dataType_(iConfig.getParameter<string>("DataType")),
0044       // We need different matching criteria if we talk about leptons or jets
0045       matchDeltaR_Leptons_(iConfig.getParameter<double>("MatchDeltaR_Leptons")),
0046       matchDeltaR_Jets_(iConfig.getParameter<double>("MatchDeltaR_Jets")),
0047       TauPtCut_(iConfig.getParameter<double>("TauPtCut")),
0048       //flexible cut interface to filter reco and gen collection. use an empty string to select all.
0049       recoCuts_(iConfig.getParameter<std::string>("recoCuts")),
0050       genCuts_(iConfig.getParameter<std::string>("genCuts")),
0051       // The output histograms can be stored or not
0052       saveoutputhistograms_(iConfig.getParameter<bool>("SaveOutputHistograms")),
0053       // Here it can be pretty much anything either a lepton or a jet
0054       refCollectionInputTag_(iConfig.getParameter<InputTag>("RefCollection")),
0055       // The extension name has information about the Reference collection used
0056       extensionName_(iConfig.getParameter<string>("ExtensionName")),
0057       // Here is the reconstructed product of interest.
0058       TauProducerInputTag_(iConfig.getParameter<InputTag>("TauProducer")),
0059       // Get the discriminators and their cuts
0060       discriminators_(iConfig.getParameter<std::vector<edm::ParameterSet>>("discriminators")) {
0061   turnOnTrigger_ = iConfig.exists("turnOnTrigger") && iConfig.getParameter<bool>("turnOnTrigger");
0062   genericTriggerEventFlag_ =
0063       (iConfig.exists("GenericTriggerSelection") && turnOnTrigger_)
0064           ? new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("GenericTriggerSelection"),
0065                                         consumesCollector(),
0066                                         *this,
0067                                         l1t::UseEventSetupIn::Run)
0068           : nullptr;
0069   if (genericTriggerEventFlag_ != nullptr)
0070     LogDebug(moduleLabel_) << "--> GenericTriggerSelection parameters found in " << moduleLabel_ << "."
0071                            << std::endl;  //move to LogDebug
0072   else
0073     LogDebug(moduleLabel_) << "--> GenericTriggerSelection not found in " << moduleLabel_ << "."
0074                            << std::endl;  //move to LogDebug to keep track of modules that fail and pass
0075 
0076   //InputTag to strings
0077   refCollection_ = refCollectionInputTag_.label();
0078   TauProducer_ = TauProducerInputTag_.label();
0079 
0080   histoSettings_ = (iConfig.exists("histoSettings")) ? iConfig.getParameter<edm::ParameterSet>("histoSettings")
0081                                                      : edm::ParameterSet();
0082   edm::InputTag PrimaryVertexCollection_ = (iConfig.exists("PrimaryVertexCollection"))
0083                                                ? iConfig.getParameter<InputTag>("PrimaryVertexCollection")
0084                                                : edm::InputTag("offlinePrimaryVertices");  //TO-DO
0085 
0086   refCollectionInputTagToken_ = consumes<edm::View<reco::Candidate>>(iConfig.getParameter<InputTag>("RefCollection"));
0087   primaryVertexCollectionToken_ = consumes<VertexCollection>(PrimaryVertexCollection_);  //TO-DO
0088   tauProducerInputTagToken_ = consumes<reco::PFTauCollection>(iConfig.getParameter<InputTag>("TauProducer"));
0089   std::vector<edm::ParameterSet> temp_plainDiscriminators;
0090   std::vector<edm::ParameterSet> temp_discriminatorContainers;
0091   for (std::vector<edm::ParameterSet>::iterator it = discriminators_.begin(); it != discriminators_.end(); ++it) {
0092     if (it->getParameter<string>("container").empty()) {
0093       temp_plainDiscriminators.push_back(*it);
0094       currentDiscriminatorToken_.push_back(
0095           consumes<reco::PFTauDiscriminator>(edm::InputTag(it->getParameter<string>("discriminator"))));
0096     } else {
0097       temp_discriminatorContainers.push_back(*it);
0098       currentDiscriminatorContainerToken_.push_back(std::pair<edm::EDGetTokenT<reco::TauDiscriminatorContainer>, int>(
0099           consumes<reco::TauDiscriminatorContainer>(edm::InputTag(it->getParameter<string>("container"))), -99));
0100       auto const prov_cfg_label = it->getParameter<std::string>("provenanceConfigLabel");
0101       if (prov_cfg_label != "rawValues" && prov_cfg_label != "workingPoints" && prov_cfg_label != "IDdefinitions" &&
0102           prov_cfg_label != "IDWPdefinitions" && prov_cfg_label != "direct_rawValues" &&
0103           prov_cfg_label != "direct_workingPoints")
0104         throw cms::Exception("Configuration")
0105             << "TauTagValidation: Parameter 'provenanceConfigLabel' does only accept 'rawValues', 'workingPoints', "
0106                "'IDdefinitions', 'IDWPdefinitions', 'direct_rawValues', 'direct_workingPoints'\n";
0107       currentDiscriminatorContainerIdName_.push_back({prov_cfg_label, it->getParameter<std::string>("idLabel")});
0108     }
0109   }
0110   //sort discriminators_: first of type PFTauDiscriminator then TauDiscriminatorContainer
0111   discriminators_ = temp_plainDiscriminators;
0112   discriminators_.insert(
0113       discriminators_.end(), temp_discriminatorContainers.begin(), temp_discriminatorContainers.end());
0114 
0115   tversion = edm::getReleaseVersion();
0116 
0117   if (!saveoutputhistograms_) {
0118     LogInfo("OutputInfo") << " TauVisible histograms will NOT be saved";
0119   } else {
0120     outPutFile_ = TauProducer_;
0121     outPutFile_.append("_");
0122     tversion.erase(0, 1);
0123     tversion.erase(tversion.size() - 1, 1);
0124     outPutFile_.append(tversion);
0125     outPutFile_.append("_" + refCollection_);
0126     if (!extensionName_.empty()) {
0127       outPutFile_.append("_" + extensionName_);
0128     }
0129     outPutFile_.append(".root");
0130 
0131     LogInfo("OutputInfo") << " TauVisiblehistograms will be saved to file:" << outPutFile_;
0132   }
0133 
0134   //---- book-keeping information ---
0135   numEvents_ = 0;
0136 
0137   // Check if we want to "chain" the discriminator requirements (i.e. all
0138   // prveious discriminators must pass)
0139   chainCuts_ = iConfig.exists("chainCuts") ? iConfig.getParameter<bool>("chainCuts") : true;
0140 }
0141 
0142 TauTagValidation::~TauTagValidation() {
0143   if (genericTriggerEventFlag_)
0144     delete genericTriggerEventFlag_;
0145 }
0146 
0147 void TauTagValidation::bookHistograms(DQMStore::IBooker& ibooker,
0148                                       edm::Run const& iRun,
0149                                       edm::EventSetup const& /* iSetup */) {
0150   MonitorElement *ptTemp, *etaTemp, *phiTemp, *pileupTemp, *tmpME, *summaryTemp;
0151 
0152   ibooker.setCurrentFolder("RecoTauV/" + TauProducer_ + extensionName_ + "_Summary");
0153   auto n_disc = !discriminators_.empty() ? discriminators_.size() : 21;
0154   hinfo summaryHinfo = (histoSettings_.exists("summary"))
0155                            ? hinfo(histoSettings_.getParameter<edm::ParameterSet>("summary"))
0156                            : hinfo(n_disc, -0.5, n_disc - 0.5);
0157   summaryTemp =
0158       ibooker.book1D("summaryPlotNum", "summaryPlotNum", summaryHinfo.nbins, summaryHinfo.min, summaryHinfo.max);
0159   summaryMap.insert(std::make_pair(refCollection_ + "Num", summaryTemp));
0160   summaryTemp =
0161       ibooker.book1D("summaryPlotDen", "summaryPlotDen", summaryHinfo.nbins, summaryHinfo.min, summaryHinfo.max);
0162   summaryMap.insert(std::make_pair(refCollection_ + "Den", summaryTemp));
0163   summaryTemp = ibooker.book1D("summaryPlot", "summaryPlot", summaryHinfo.nbins, summaryHinfo.min, summaryHinfo.max);
0164   summaryMap.insert(std::make_pair(refCollection_, summaryTemp));
0165 
0166   ibooker.setCurrentFolder("RecoTauV/" + TauProducer_ + extensionName_ + "_ReferenceCollection");
0167 
0168   //Histograms settings
0169   hinfo ptHinfo = (histoSettings_.exists("pt")) ? hinfo(histoSettings_.getParameter<edm::ParameterSet>("pt"))
0170                                                 : hinfo(500, 0., 1000.);
0171   hinfo etaHinfo = (histoSettings_.exists("eta")) ? hinfo(histoSettings_.getParameter<edm::ParameterSet>("eta"))
0172                                                   : hinfo(60, -3.0, 3.0);
0173   hinfo phiHinfo = (histoSettings_.exists("phi")) ? hinfo(histoSettings_.getParameter<edm::ParameterSet>("phi"))
0174                                                   : hinfo(40, -200., 200.);
0175   hinfo pileupHinfo = (histoSettings_.exists("pileup"))
0176                           ? hinfo(histoSettings_.getParameter<edm::ParameterSet>("pileup"))
0177                           : hinfo(100, 0., 100.);
0178   //hinfo dRHinfo = (histoSettings_.exists("deltaR")) ? hinfo(histoSettings_.getParameter<edm::ParameterSet>("deltaR")) : hinfo(10, 0., 0.5);
0179 
0180   // What kind of Taus do we originally have!
0181 
0182   ptTemp =
0183       ibooker.book1D("nRef_Taus_vs_ptTauVisible", "nRef_Taus_vs_ptTauVisible", ptHinfo.nbins, ptHinfo.min, ptHinfo.max);
0184   etaTemp = ibooker.book1D(
0185       "nRef_Taus_vs_etaTauVisible", "nRef_Taus_vs_etaTauVisible", etaHinfo.nbins, etaHinfo.min, etaHinfo.max);
0186   phiTemp = ibooker.book1D(
0187       "nRef_Taus_vs_phiTauVisible", "nRef_Taus_vs_phiTauVisible", phiHinfo.nbins, phiHinfo.min, phiHinfo.max);
0188   pileupTemp = ibooker.book1D("nRef_Taus_vs_pileupTauVisible",
0189                               "nRef_Taus_vs_pileupTauVisible",
0190                               pileupHinfo.nbins,
0191                               pileupHinfo.min,
0192                               pileupHinfo.max);
0193 
0194   ptTauVisibleMap.insert(std::make_pair(refCollection_, ptTemp));
0195   etaTauVisibleMap.insert(std::make_pair(refCollection_, etaTemp));
0196   phiTauVisibleMap.insert(std::make_pair(refCollection_, phiTemp));
0197   pileupTauVisibleMap.insert(std::make_pair(refCollection_, pileupTemp));
0198 
0199   // Number of Tau Candidates matched to MC Taus
0200 
0201   ibooker.setCurrentFolder("RecoTauV/" + TauProducer_ + extensionName_ + "_Matched");
0202 
0203   ptTemp = ibooker.book1D(TauProducer_ + "Matched_vs_ptTauVisible",
0204                           TauProducer_ + "Matched_vs_ptTauVisible",
0205                           ptHinfo.nbins,
0206                           ptHinfo.min,
0207                           ptHinfo.max);
0208   etaTemp = ibooker.book1D(TauProducer_ + "Matched_vs_etaTauVisible",
0209                            TauProducer_ + "Matched_vs_etaTauVisible",
0210                            etaHinfo.nbins,
0211                            etaHinfo.min,
0212                            etaHinfo.max);
0213   phiTemp = ibooker.book1D(TauProducer_ + "Matched_vs_phiTauVisible",
0214                            TauProducer_ + "Matched_vs_phiTauVisible",
0215                            phiHinfo.nbins,
0216                            phiHinfo.min,
0217                            phiHinfo.max);
0218   pileupTemp = ibooker.book1D(TauProducer_ + "Matched_vs_pileupTauVisible",
0219                               TauProducer_ + "Matched_vs_pileupTauVisible",
0220                               pileupHinfo.nbins,
0221                               pileupHinfo.min,
0222                               pileupHinfo.max);
0223 
0224   ptTauVisibleMap.insert(std::make_pair(TauProducer_ + "Matched", ptTemp));
0225   etaTauVisibleMap.insert(std::make_pair(TauProducer_ + "Matched", etaTemp));
0226   phiTauVisibleMap.insert(std::make_pair(TauProducer_ + "Matched", phiTemp));
0227   pileupTauVisibleMap.insert(std::make_pair(TauProducer_ + "Matched", pileupTemp));
0228 
0229   int j = 0;
0230   for (const auto& it : discriminators_) {
0231     string DiscriminatorLabel = it.getParameter<string>("discriminator");
0232     std::string histogramName;
0233     stripDiscriminatorLabel(DiscriminatorLabel, histogramName);
0234 
0235     //Summary plots
0236     string DiscriminatorLabelReduced = it.getParameter<string>("discriminator");
0237     DiscriminatorLabelReduced.erase(0, 24);
0238     summaryMap.find(refCollection_ + "Den")->second->setBinLabel(j + 1, DiscriminatorLabelReduced);
0239     summaryMap.find(refCollection_ + "Num")->second->setBinLabel(j + 1, DiscriminatorLabelReduced);
0240     summaryMap.find(refCollection_)->second->setBinLabel(j + 1, DiscriminatorLabelReduced);
0241 
0242     ibooker.setCurrentFolder("RecoTauV/" + TauProducer_ + extensionName_ + "_" + DiscriminatorLabel);
0243 
0244     ptTemp = ibooker.book1D(DiscriminatorLabel + "_vs_ptTauVisible",
0245                             histogramName + "_vs_ptTauVisible",
0246                             ptHinfo.nbins,
0247                             ptHinfo.min,
0248                             ptHinfo.max);
0249     etaTemp = ibooker.book1D(DiscriminatorLabel + "_vs_etaTauVisible",
0250                              histogramName + "_vs_etaTauVisible",
0251                              etaHinfo.nbins,
0252                              etaHinfo.min,
0253                              etaHinfo.max);
0254     phiTemp = ibooker.book1D(DiscriminatorLabel + "_vs_phiTauVisible",
0255                              histogramName + "_vs_phiTauVisible",
0256                              phiHinfo.nbins,
0257                              phiHinfo.min,
0258                              phiHinfo.max);
0259     pileupTemp = ibooker.book1D(DiscriminatorLabel + "_vs_pileupTauVisible",
0260                                 histogramName + "_vs_pileupTauVisible",
0261                                 pileupHinfo.nbins,
0262                                 pileupHinfo.min,
0263                                 pileupHinfo.max);
0264 
0265     ptTauVisibleMap.insert(std::make_pair(DiscriminatorLabel, ptTemp));
0266     etaTauVisibleMap.insert(std::make_pair(DiscriminatorLabel, etaTemp));
0267     phiTauVisibleMap.insert(std::make_pair(DiscriminatorLabel, phiTemp));
0268     pileupTauVisibleMap.insert(std::make_pair(DiscriminatorLabel, pileupTemp));
0269 
0270     tmpME = ibooker.book1D(
0271         DiscriminatorLabel + "_TauCandMass", histogramName + "_TauCandMass" + ";Cand Mass" + ";Frequency", 30, 0., 2.0);
0272     plotMap_.insert(std::make_pair(DiscriminatorLabel + "_TauCandMass", tmpME));
0273 
0274     // momentum resolution for several decay modes
0275 
0276     std::string plotType = "_pTRatio_";  //use underscores (this allows to parse plot type in later stages)
0277     std::string xaxisLabel = ";p_{T}^{reco}/p_{T}^{gen}";
0278     std::string yaxislabel = ";Frequency";
0279     std::string plotName = plotType + "allHadronic";
0280     int bins = 40;
0281     tmpME =
0282         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0283     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0284     plotName = plotType + "oneProng0Pi0";
0285     tmpME =
0286         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0287     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0288     plotName = plotType + "oneProng1Pi0";
0289     tmpME =
0290         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0291     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0292     plotName = plotType + "oneProng2Pi0";
0293     tmpME =
0294         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0295     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0296 
0297     plotName = plotType + "twoProng0Pi0";
0298     tmpME =
0299         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0300     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0301     plotName = plotType + "twoProng1Pi0";
0302     tmpME =
0303         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0304     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0305     plotName = plotType + "twoProng2Pi0";
0306     tmpME =
0307         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0308     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0309 
0310     plotName = plotType + "threeProng0Pi0";
0311     tmpME =
0312         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0313     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0314     plotName = plotType + "threeProng1Pi0";
0315     tmpME =
0316         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0317     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0318 
0319     // Tau Multiplicity for several decay modes
0320 
0321     plotType = "_nTaus_";  //use underscores (this allows to parse plot type in later stages)
0322     xaxisLabel = ";Tau Multiplicity";
0323     yaxislabel = ";Frequency";
0324     plotName = plotType + "allHadronic";
0325     bins = 50;
0326     tmpME = ibooker.book1D(
0327         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0328     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0329     plotName = plotType + "oneProng0Pi0";
0330     tmpME = ibooker.book1D(
0331         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0332     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0333     plotName = plotType + "oneProng1Pi0";
0334     tmpME = ibooker.book1D(
0335         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0336     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0337     plotName = plotType + "oneProng2Pi0";
0338     tmpME = ibooker.book1D(
0339         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0340     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0341     plotName = plotType + "twoProng0Pi0";
0342     tmpME = ibooker.book1D(
0343         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0344     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0345     plotName = plotType + "twoProng1Pi0";
0346     tmpME = ibooker.book1D(
0347         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0348     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0349     plotName = plotType + "twoProng2Pi0";
0350     tmpME = ibooker.book1D(
0351         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0352     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0353     plotName = plotType + "threeProng0Pi0";
0354     tmpME = ibooker.book1D(
0355         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0356     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0357     plotName = plotType + "threeProng1Pi0";
0358     tmpME = ibooker.book1D(
0359         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0360     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0361 
0362     //size and sumPt within tau isolation
0363 
0364     plotType = "_Size_";
0365     xaxisLabel = ";size";
0366     yaxislabel = ";Frequency";
0367     bins = 20;
0368     plotName = plotType + "signalCands";
0369     tmpME = ibooker.book1D(
0370         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0371     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0372     plotName = plotType + "signalChargedHadrCands";
0373     tmpME = ibooker.book1D(
0374         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0375     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0376     plotName = plotType + "signalNeutrHadrCands";
0377     tmpME = ibooker.book1D(
0378         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0379     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0380 
0381     plotName = plotType + "isolationCands";
0382     tmpME = ibooker.book1D(
0383         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0384     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0385     plotName = plotType + "isolationChargedHadrCands";
0386     bins = 10;
0387     tmpME = ibooker.book1D(
0388         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0389     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0390     plotName = plotType + "isolationNeutrHadrCands";
0391     tmpME = ibooker.book1D(
0392         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0393     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0394     plotName = plotType + "isolationGammaCands";
0395     tmpME = ibooker.book1D(
0396         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0397     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0398 
0399     plotType = "_SumPt_";
0400     xaxisLabel = ";p_{T}^{sum}/ GeV";
0401     yaxislabel = ";Frequency";
0402     bins = 20;
0403     plotName = plotType + "signalCands";
0404     tmpME = ibooker.book1D(
0405         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0406     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0407     plotName = plotType + "signalChargedHadrCands";
0408     tmpME = ibooker.book1D(
0409         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0410     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0411     plotName = plotType + "signalNeutrHadrCands";
0412     tmpME = ibooker.book1D(
0413         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0414     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0415     plotName = plotType + "isolationCands";
0416     tmpME = ibooker.book1D(
0417         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0418     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0419     plotName = plotType + "isolationChargedHadrCands";
0420     tmpME = ibooker.book1D(
0421         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 10.);
0422     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0423     plotName = plotType + "isolationNeutrHadrCands";
0424     tmpME = ibooker.book1D(
0425         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 30.);
0426     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0427     plotName = plotType + "isolationGammaCands";
0428     tmpME = ibooker.book1D(
0429         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 20.);
0430     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0431 
0432     //deprecated!
0433 
0434     if (DiscriminatorLabel.find("LeadingTrackPtCut") != string::npos) {
0435       if (TauProducer_.find("PFTau") != string::npos) {
0436         nPFJet_LeadingChargedHadron_ChargedHadronsSignal_ = ibooker.book1D(
0437             DiscriminatorLabel + "_ChargedHadronsSignal", DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);
0438         nPFJet_LeadingChargedHadron_ChargedHadronsIsolAnnulus_ =
0439             ibooker.book1D(DiscriminatorLabel + "_ChargedHadronsIsolAnnulus",
0440                            DiscriminatorLabel + "_ChargedHadronsIsolAnnulus",
0441                            21,
0442                            -0.5,
0443                            20.5);
0444         nPFJet_LeadingChargedHadron_GammasSignal_ =
0445             ibooker.book1D(DiscriminatorLabel + "_GammasSignal", DiscriminatorLabel + "_GammasSignal", 21, -0.5, 20.5);
0446         nPFJet_LeadingChargedHadron_GammasIsolAnnulus_ = ibooker.book1D(
0447             DiscriminatorLabel + "_GammasIsolAnnulus", DiscriminatorLabel + "_GammasIsolAnnulus", 21, -0.5, 20.5);
0448         nPFJet_LeadingChargedHadron_NeutralHadronsSignal_ = ibooker.book1D(
0449             DiscriminatorLabel + "_NeutralHadronsSignal", DiscriminatorLabel + "_NeutralHadronsSignal", 21, -0.5, 20.5);
0450         nPFJet_LeadingChargedHadron_NeutralHadronsIsolAnnulus_ =
0451             ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0452                            DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0453                            21,
0454                            -0.5,
0455                            20.5);
0456       }
0457     }
0458 
0459     if (DiscriminatorLabel.find("ByIsolationLater") != string::npos) {
0460       if (TauProducer_.find("PFTau") != string::npos) {
0461         nIsolated_NoChargedHadrons_ChargedHadronsSignal_ = ibooker.book1D(
0462             DiscriminatorLabel + "_ChargedHadronsSignal", DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);
0463         nIsolated_NoChargedHadrons_GammasSignal_ =
0464             ibooker.book1D(DiscriminatorLabel + "_GammasSignal", DiscriminatorLabel + "_GammasSignal", 21, -0.5, 20.5);
0465         nIsolated_NoChargedHadrons_GammasIsolAnnulus_ = ibooker.book1D(
0466             DiscriminatorLabel + "_GammasIsolAnnulus", DiscriminatorLabel + "_GammasIsolAnnulus", 21, -0.5, 20.5);
0467         nIsolated_NoChargedHadrons_NeutralHadronsSignal_ = ibooker.book1D(
0468             DiscriminatorLabel + "_NeutralHadronsSignal", DiscriminatorLabel + "_NeutralHadronsSignal", 21, -0.5, 20.5);
0469         nIsolated_NoChargedHadrons_NeutralHadronsIsolAnnulus_ =
0470             ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0471                            DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0472                            21,
0473                            -0.5,
0474                            20.5);
0475       }
0476     }
0477 
0478     if (DiscriminatorLabel.find("ByIsolation") != string::npos) {
0479       if (TauProducer_.find("PFTau") != string::npos) {
0480         nIsolated_NoChargedNoGammas_ChargedHadronsSignal_ = ibooker.book1D(
0481             DiscriminatorLabel + "_ChargedHadronsSignal", DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);
0482         nIsolated_NoChargedNoGammas_GammasSignal_ =
0483             ibooker.book1D(DiscriminatorLabel + "_GammasSignal", DiscriminatorLabel + "_GammasSignal", 21, -0.5, 20.5);
0484         nIsolated_NoChargedNoGammas_NeutralHadronsSignal_ = ibooker.book1D(
0485             DiscriminatorLabel + "_NeutralHadronsSignal", DiscriminatorLabel + "_NeutralHadronsSignal", 21, -0.5, 20.5);
0486         nIsolated_NoChargedNoGammas_NeutralHadronsIsolAnnulus_ =
0487             ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0488                            DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0489                            21,
0490                            -0.5,
0491                            20.5);
0492       }
0493     }
0494     j++;
0495   }
0496 }
0497 
0498 void TauTagValidation::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0499   if (genericTriggerEventFlag_) {
0500     if (genericTriggerEventFlag_->on()) {
0501       genericTriggerEventFlag_->initRun(iRun, iSetup);
0502     }
0503   }
0504 }
0505 
0506 void TauTagValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0507   if (genericTriggerEventFlag_) {
0508     if (!genericTriggerEventFlag_->on())
0509       std::cout << "TauTagValidation::analyze: No working genericTriggerEventFlag. Did you specify a valid globaltag?"
0510                 << std::endl;  //move to LogDebug?
0511   }
0512 
0513   numEvents_++;
0514   double matching_criteria = -1.0;
0515 
0516   //Initialize the Tau Multiplicity Counter
0517   for (const auto& it : discriminators_) {
0518     string DiscriminatorLabel = it.getParameter<string>("discriminator");
0519     tauDecayCountMap_["allHadronic" + DiscriminatorLabel] = 0;
0520     tauDecayCountMap_["oneProng0Pi0" + DiscriminatorLabel] = 0;
0521     tauDecayCountMap_["oneProng1Pi0" + DiscriminatorLabel] = 0;
0522     tauDecayCountMap_["oneProng2Pi0" + DiscriminatorLabel] = 0;
0523     tauDecayCountMap_["twoProng0Pi0" + DiscriminatorLabel] = 0;
0524     tauDecayCountMap_["twoProng1Pi0" + DiscriminatorLabel] = 0;
0525     tauDecayCountMap_["twoProng2Pi0" + DiscriminatorLabel] = 0;
0526     tauDecayCountMap_["threeProng0Pi0" + DiscriminatorLabel] = 0;
0527     tauDecayCountMap_["threeProng1Pi0" + DiscriminatorLabel] = 0;
0528   }
0529 
0530   typedef edm::View<reco::Candidate> genCandidateCollection;
0531 
0532   // ----------------------- Reference product -----------------------------------------------------------------------
0533 
0534   Handle<genCandidateCollection> ReferenceCollection;
0535   bool isGen = iEvent.getByToken(refCollectionInputTagToken_, ReferenceCollection);
0536 
0537   Handle<VertexCollection> pvHandle;
0538   iEvent.getByToken(primaryVertexCollectionToken_, pvHandle);  //TO-DO
0539 
0540   if (!isGen) {
0541     std::cerr << " Reference collection: " << refCollection_ << " not found while running TauTagValidation.cc "
0542               << std::endl;
0543     return;
0544   }
0545 
0546   if (dataType_ == "Leptons") {
0547     matching_criteria = matchDeltaR_Leptons_;
0548   } else {
0549     matching_criteria = matchDeltaR_Jets_;
0550   }
0551 
0552   // ------------------------------ PFTauCollection Matched and other discriminators ---------------------------------------------------------
0553 
0554   if (TauProducer_.find("PFTau") != string::npos || TauProducer_.find("hpsTancTaus") != string::npos) {
0555     // Retrieve ID container indices if config history changes, in particular for the first event.
0556     if (phID_ != iEvent.processHistoryID()) {
0557       phID_ = iEvent.processHistoryID();
0558       for (size_t idx = 0; idx < currentDiscriminatorContainerToken_.size(); ++idx) {
0559         const edm::Provenance* prov = iEvent.getHandle(currentDiscriminatorContainerToken_[idx].first).provenance();
0560         string prov_cfg_label = currentDiscriminatorContainerIdName_[idx].first;
0561         string prov_ID_label = currentDiscriminatorContainerIdName_[idx].second;
0562         bool found = false;
0563         if (prov_cfg_label == "rawValues" || prov_cfg_label == "workingPoints") {
0564           const std::vector<string> psetsFromProvenance = edm::parameterSet(prov->stable(), iEvent.processHistory())
0565                                                               .getParameter<std::vector<string>>(prov_cfg_label);
0566           for (size_t i = 0; i < psetsFromProvenance.size(); ++i) {
0567             if (psetsFromProvenance[i] == prov_ID_label) {
0568               // using negative indices for raw values
0569               if (prov_cfg_label == "rawValues")
0570                 currentDiscriminatorContainerToken_[idx].second = -1 - i;
0571               else
0572                 currentDiscriminatorContainerToken_[idx].second = i;
0573               found = true;
0574             }
0575           }
0576         } else if (prov_cfg_label == "IDdefinitions" || prov_cfg_label == "IDWPdefinitions") {
0577           const std::vector<edm::ParameterSet> psetsFromProvenance =
0578               edm::parameterSet(prov->stable(), iEvent.processHistory())
0579                   .getParameter<std::vector<edm::ParameterSet>>(prov_cfg_label);
0580           for (size_t i = 0; i < psetsFromProvenance.size(); ++i) {
0581             if (psetsFromProvenance[i].getParameter<string>("IDname") == prov_ID_label) {
0582               // using negative indices for raw values
0583               if (prov_cfg_label == "IDdefinitions")
0584                 currentDiscriminatorContainerToken_[idx].second = -1 - i;
0585               else
0586                 currentDiscriminatorContainerToken_[idx].second = i;
0587               found = true;
0588             }
0589           }
0590         } else {
0591           // checked prov_cfg_label before, so it must be a direct access via indices
0592           try {
0593             int i = std::stoi(prov_ID_label);
0594             if (prov_cfg_label == "direct_rawValues")
0595               currentDiscriminatorContainerToken_[idx].second = -1 - i;
0596             else
0597               currentDiscriminatorContainerToken_[idx].second = i;
0598             found = true;
0599           } catch (std::invalid_argument const& e) {
0600             throw cms::Exception("Configuration") << "TauTagValidation: Direct access to ID container requested, so "
0601                                                      "argument of 'idLabel' must be convertable to int!\n";
0602           }
0603         }
0604         if (!found) {
0605           throw cms::Exception("Configuration")
0606               << "TauTagValidation: Requested working point '" << prov_ID_label << "' for ID '"
0607               << discriminators_.at(idx - currentDiscriminatorToken_.size()).getParameter<string>("discriminator")
0608               << "' not found!\n";
0609         }
0610       }
0611     }
0612 
0613     Handle<PFTauCollection> thePFTauHandle;
0614     iEvent.getByToken(tauProducerInputTagToken_, thePFTauHandle);
0615 
0616     const PFTauCollection* pfTauProduct;
0617     pfTauProduct = thePFTauHandle.product();
0618 
0619     PFTauCollection::size_type thePFTauClosest;
0620 
0621     std::map<std::string, MonitorElement*>::const_iterator element = plotMap_.end();
0622 
0623     //Run the Reference Collection
0624     for (genCandidateCollection::const_iterator RefJet = ReferenceCollection->begin();
0625          RefJet != ReferenceCollection->end();
0626          RefJet++) {
0627       ptTauVisibleMap.find(refCollection_)->second->Fill(RefJet->pt());
0628       etaTauVisibleMap.find(refCollection_)->second->Fill(RefJet->eta());
0629       phiTauVisibleMap.find(refCollection_)->second->Fill(RefJet->phi() * 180.0 / TMath::Pi());
0630       pileupTauVisibleMap.find(refCollection_)->second->Fill(pvHandle->size());
0631 
0632       const reco::Candidate* gen_particle = &(*RefJet);
0633 
0634       double delta = TMath::Pi();
0635 
0636       thePFTauClosest = pfTauProduct->size();
0637 
0638       for (PFTauCollection::size_type iPFTau = 0; iPFTau < pfTauProduct->size(); iPFTau++) {
0639         if (algo_->deltaR(gen_particle, &pfTauProduct->at(iPFTau)) < delta) {
0640           delta = algo_->deltaR(gen_particle, &pfTauProduct->at(iPFTau));
0641           thePFTauClosest = iPFTau;
0642         }
0643       }
0644 
0645       // Skip if there is no reconstructed Tau matching the Reference
0646       if (thePFTauClosest == pfTauProduct->size())
0647         continue;
0648 
0649       double deltaR = algo_->deltaR(gen_particle, &pfTauProduct->at(thePFTauClosest));
0650 
0651       // Skip if the delta R difference is larger than the required criteria
0652       if (deltaR > matching_criteria && matching_criteria != -1.0)
0653         continue;
0654 
0655       ptTauVisibleMap.find(TauProducer_ + "Matched")->second->Fill(RefJet->pt());
0656       etaTauVisibleMap.find(TauProducer_ + "Matched")->second->Fill(RefJet->eta());
0657       phiTauVisibleMap.find(TauProducer_ + "Matched")->second->Fill(RefJet->phi() * 180.0 / TMath::Pi());
0658       pileupTauVisibleMap.find(TauProducer_ + "Matched")->second->Fill(pvHandle->size());
0659 
0660       PFTauRef thePFTau(thePFTauHandle, thePFTauClosest);
0661 
0662       Handle<PFTauDiscriminator> currentDiscriminator;
0663       Handle<TauDiscriminatorContainer> currentDiscriminatorContainer;
0664 
0665       //filter the candidates
0666       if (thePFTau->pt() < TauPtCut_)
0667         continue;  //almost deprecated, since recoCuts_ provides more flexibility
0668                    //reco
0669       StringCutObjectSelector<PFTauRef> selectReco(recoCuts_);
0670       bool pass = selectReco(thePFTau);
0671       if (!pass)
0672         continue;
0673       //gen
0674       StringCutObjectSelector<reco::Candidate> selectGen(genCuts_);
0675       pass = selectGen(*gen_particle);
0676       if (!pass)
0677         continue;
0678 
0679       for (unsigned j = 0; j < discriminators_.size(); j++) {
0680         string currentDiscriminatorLabel = discriminators_.at(j).getParameter<string>("discriminator");
0681         summaryMap.find(refCollection_ + "Den")->second->Fill(j);
0682 
0683         bool passesID;
0684         if (j < currentDiscriminatorToken_.size()) {
0685           iEvent.getByToken(currentDiscriminatorToken_[j], currentDiscriminator);
0686           passesID = ((*currentDiscriminator)[thePFTau] >= discriminators_.at(j).getParameter<double>("selectionCut"));
0687         } else {
0688           iEvent.getByToken(currentDiscriminatorContainerToken_[j - currentDiscriminatorToken_.size()].first,
0689                             currentDiscriminatorContainer);
0690           if (currentDiscriminatorContainerToken_[j - currentDiscriminatorToken_.size()].second < 0) {
0691             if ((*currentDiscriminatorContainer)[thePFTau].rawValues.size() == 1)
0692               passesID = false;  //in case of prediscriminant fail at reco level
0693             else
0694               passesID = ((*currentDiscriminatorContainer)[thePFTau].rawValues.at(
0695                               -1 - currentDiscriminatorContainerToken_[j - currentDiscriminatorToken_.size()].second) >=
0696                           discriminators_.at(j).getParameter<double>("selectionCut"));
0697           } else {
0698             if ((*currentDiscriminatorContainer)[thePFTau].workingPoints.empty())
0699               passesID = false;  //in case of prediscriminant fail at reco level
0700             else
0701               passesID = (*currentDiscriminatorContainer)[thePFTau].workingPoints.at(
0702                   currentDiscriminatorContainerToken_[j - currentDiscriminatorToken_.size()].second);
0703           }
0704         }
0705         if (passesID) {
0706           ptTauVisibleMap.find(currentDiscriminatorLabel)->second->Fill(RefJet->pt());
0707           etaTauVisibleMap.find(currentDiscriminatorLabel)->second->Fill(RefJet->eta());
0708           phiTauVisibleMap.find(currentDiscriminatorLabel)->second->Fill(RefJet->phi() * 180.0 / TMath::Pi());
0709           pileupTauVisibleMap.find(currentDiscriminatorLabel)->second->Fill(pvHandle->size());
0710           summaryMap.find(refCollection_ + "Num")->second->Fill(j);
0711 
0712           //fill the momentum resolution plots
0713           double tauPtRes = thePFTau->pt() / gen_particle->pt();  //WARNING: use only the visible parts!
0714           plotMap_.find(currentDiscriminatorLabel + "_pTRatio_allHadronic")->second->Fill(tauPtRes);
0715 
0716           //Fill Tau Cand Mass
0717           TLorentzVector TAU;
0718           TAU.SetPtEtaPhiE(thePFTau->pt(), thePFTau->eta(), thePFTau->phi(), thePFTau->energy());
0719           plotMap_.find(currentDiscriminatorLabel + "_TauCandMass")->second->Fill(TAU.M());
0720 
0721           //Tau Counter, allHadronic mode
0722           tauDecayCountMap_.find("allHadronic" + currentDiscriminatorLabel)->second++;
0723 
0724           /*
0725           //is there a better way than casting the candidate?
0726           const reco::GenJet *tauGenJet = dynamic_cast<const reco::GenJet*>(gen_particle);
0727           if(tauGenJet){
0728             std::string genTauDecayMode =  JetMCTagUtils::genTauDecayMode(*tauGenJet); // gen_particle is the tauGenJet matched to the reconstructed tau
0729             element = plotMap_.find( currentDiscriminatorLabel + "_pTRatio_" + genTauDecayMode );
0730             if( element != plotMap_.end() ) element->second->Fill(tauPtRes);
0731             tauDecayCountMap_.find( genTauDecayMode + currentDiscriminatorLabel)->second++;
0732           }else{
0733             LogInfo("TauTagValidation") << " Failed to cast the MC candidate.";
0734       }*/
0735 
0736           if (thePFTau->decayMode() == reco::PFTau::kOneProng0PiZero) {
0737             tauDecayCountMap_.find("oneProng0Pi0" + currentDiscriminatorLabel)->second++;
0738             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "oneProng0Pi0")->second->Fill(tauPtRes);
0739           } else if (thePFTau->decayMode() == reco::PFTau::kOneProng1PiZero) {
0740             tauDecayCountMap_.find("oneProng1Pi0" + currentDiscriminatorLabel)->second++;
0741             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "oneProng1Pi0")->second->Fill(tauPtRes);
0742           } else if (thePFTau->decayMode() == reco::PFTau::kOneProng2PiZero) {
0743             tauDecayCountMap_.find("oneProng2Pi0" + currentDiscriminatorLabel)->second++;
0744             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "oneProng2Pi0")->second->Fill(tauPtRes);
0745           } else if (thePFTau->decayMode() == reco::PFTau::kTwoProng0PiZero) {
0746             tauDecayCountMap_.find("twoProng0Pi0" + currentDiscriminatorLabel)->second++;
0747             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "twoProng0Pi0")->second->Fill(tauPtRes);
0748           } else if (thePFTau->decayMode() == reco::PFTau::kTwoProng1PiZero) {
0749             tauDecayCountMap_.find("twoProng1Pi0" + currentDiscriminatorLabel)->second++;
0750             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "twoProng1Pi0")->second->Fill(tauPtRes);
0751           } else if (thePFTau->decayMode() == reco::PFTau::kTwoProng2PiZero) {
0752             tauDecayCountMap_.find("twoProng2Pi0" + currentDiscriminatorLabel)->second++;
0753             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "twoProng2Pi0")->second->Fill(tauPtRes);
0754           } else if (thePFTau->decayMode() == reco::PFTau::kThreeProng0PiZero) {
0755             tauDecayCountMap_.find("threeProng0Pi0" + currentDiscriminatorLabel)->second++;
0756             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "threeProng0Pi0")->second->Fill(tauPtRes);
0757           } else if (thePFTau->decayMode() == reco::PFTau::kThreeProng1PiZero) {
0758             tauDecayCountMap_.find("threeProng1Pi0" + currentDiscriminatorLabel)->second++;
0759             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "threeProng1Pi0")->second->Fill(tauPtRes);
0760           }
0761           //fill: size and sumPt within tau isolation
0762           std::string plotType = "_Size_";
0763           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalCands");
0764           if (element != plotMap_.end())
0765             element->second->Fill(thePFTau->signalCands().size());
0766           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalChargedHadrCands");
0767           if (element != plotMap_.end())
0768             element->second->Fill(thePFTau->signalChargedHadrCands().size());
0769           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalNeutrHadrCands");
0770           if (element != plotMap_.end())
0771             element->second->Fill(thePFTau->signalNeutrHadrCands().size());
0772           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationCands");
0773           if (element != plotMap_.end())
0774             element->second->Fill(thePFTau->isolationCands().size());
0775           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationChargedHadrCands");
0776           if (element != plotMap_.end())
0777             element->second->Fill(thePFTau->isolationChargedHadrCands().size());
0778           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationNeutrHadrCands");
0779           if (element != plotMap_.end())
0780             element->second->Fill(thePFTau->isolationNeutrHadrCands().size());
0781           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationGammaCands");
0782           if (element != plotMap_.end())
0783             element->second->Fill(thePFTau->isolationGammaCands().size());
0784 
0785           plotType = "_SumPt_";
0786           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalCands");
0787           if (element != plotMap_.end())
0788             element->second->Fill(getSumPt(thePFTau->signalCands()));
0789           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalChargedHadrCands");
0790           if (element != plotMap_.end())
0791             element->second->Fill(getSumPt(thePFTau->signalChargedHadrCands()));
0792           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalNeutrHadrCands");
0793           if (element != plotMap_.end())
0794             element->second->Fill(getSumPt(thePFTau->signalNeutrHadrCands()));
0795           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationCands");
0796           if (element != plotMap_.end())
0797             element->second->Fill(getSumPt(thePFTau->isolationCands()));
0798           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationChargedHadrCands");
0799           if (element != plotMap_.end())
0800             element->second->Fill(getSumPt(thePFTau->isolationChargedHadrCands()));
0801           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationNeutrHadrCands");
0802           if (element != plotMap_.end())
0803             element->second->Fill(getSumPt(thePFTau->isolationNeutrHadrCands()));
0804           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationGammaCands");
0805           if (element != plotMap_.end())
0806             element->second->Fill(getSumPt(thePFTau->isolationGammaCands()));
0807 
0808           //deprecated
0809 
0810           if (TauProducer_.find("PFTau") != string::npos) {
0811             if (currentDiscriminatorLabel.find("LeadingTrackPtCut") != string::npos) {
0812               nPFJet_LeadingChargedHadron_ChargedHadronsSignal_->Fill((*thePFTau).signalChargedHadrCands().size());
0813               nPFJet_LeadingChargedHadron_ChargedHadronsIsolAnnulus_->Fill(
0814                   (*thePFTau).isolationChargedHadrCands().size());
0815               nPFJet_LeadingChargedHadron_GammasSignal_->Fill((*thePFTau).signalGammaCands().size());
0816               nPFJet_LeadingChargedHadron_GammasIsolAnnulus_->Fill((*thePFTau).isolationGammaCands().size());
0817               nPFJet_LeadingChargedHadron_NeutralHadronsSignal_->Fill((*thePFTau).signalNeutrHadrCands().size());
0818               nPFJet_LeadingChargedHadron_NeutralHadronsIsolAnnulus_->Fill(
0819                   (*thePFTau).isolationNeutrHadrCands().size());
0820             } else if (currentDiscriminatorLabel.find("ByIsolation") != string::npos) {
0821               nIsolated_NoChargedNoGammas_ChargedHadronsSignal_->Fill((*thePFTau).signalChargedHadrCands().size());
0822               nIsolated_NoChargedNoGammas_GammasSignal_->Fill((*thePFTau).signalGammaCands().size());
0823               nIsolated_NoChargedNoGammas_NeutralHadronsSignal_->Fill((*thePFTau).signalNeutrHadrCands().size());
0824               nIsolated_NoChargedNoGammas_NeutralHadronsIsolAnnulus_->Fill(
0825                   (*thePFTau).isolationNeutrHadrCands().size());
0826             }
0827           }
0828         } else {
0829           if (chainCuts_)
0830             break;
0831         }
0832       }
0833     }  //End of Reference Collection Loop
0834 
0835     //Fill the Tau Multiplicity Histograms
0836     for (const auto& it : discriminators_) {
0837       string currentDiscriminatorLabel = it.getParameter<string>("discriminator");
0838       plotMap_.find(currentDiscriminatorLabel + "_nTaus_allHadronic")
0839           ->second->Fill(tauDecayCountMap_.find("allHadronic" + currentDiscriminatorLabel)->second);
0840       plotMap_.find(currentDiscriminatorLabel + "_nTaus_oneProng0Pi0")
0841           ->second->Fill(tauDecayCountMap_.find("oneProng0Pi0" + currentDiscriminatorLabel)->second);
0842       plotMap_.find(currentDiscriminatorLabel + "_nTaus_oneProng1Pi0")
0843           ->second->Fill(tauDecayCountMap_.find("oneProng1Pi0" + currentDiscriminatorLabel)->second);
0844       plotMap_.find(currentDiscriminatorLabel + "_nTaus_oneProng2Pi0")
0845           ->second->Fill(tauDecayCountMap_.find("oneProng2Pi0" + currentDiscriminatorLabel)->second);
0846       plotMap_.find(currentDiscriminatorLabel + "_nTaus_twoProng0Pi0")
0847           ->second->Fill(tauDecayCountMap_.find("twoProng0Pi0" + currentDiscriminatorLabel)->second);
0848       plotMap_.find(currentDiscriminatorLabel + "_nTaus_twoProng1Pi0")
0849           ->second->Fill(tauDecayCountMap_.find("twoProng1Pi0" + currentDiscriminatorLabel)->second);
0850       plotMap_.find(currentDiscriminatorLabel + "_nTaus_twoProng2Pi0")
0851           ->second->Fill(tauDecayCountMap_.find("twoProng2Pi0" + currentDiscriminatorLabel)->second);
0852       plotMap_.find(currentDiscriminatorLabel + "_nTaus_threeProng0Pi0")
0853           ->second->Fill(tauDecayCountMap_.find("threeProng0Pi0" + currentDiscriminatorLabel)->second);
0854       plotMap_.find(currentDiscriminatorLabel + "_nTaus_threeProng1Pi0")
0855           ->second->Fill(tauDecayCountMap_.find("threeProng1Pi0" + currentDiscriminatorLabel)->second);
0856     }
0857 
0858   }  //End of PFTau Collection If Loop
0859 }
0860 
0861 double TauTagValidation::getSumPt(const std::vector<edm::Ptr<reco::Candidate>>& candidates) {
0862   double sumPt = 0.;
0863   for (std::vector<edm::Ptr<reco::Candidate>>::const_iterator candidate = candidates.begin();
0864        candidate != candidates.end();
0865        ++candidate) {
0866     sumPt += (*candidate)->pt();
0867   }
0868   return sumPt;
0869 }
0870 
0871 bool TauTagValidation::stripDiscriminatorLabel(const std::string& discriminatorLabel, std::string& newLabel) {
0872   std::string separatorString = "DiscriminationBy";
0873   std::string::size_type separator = discriminatorLabel.find(separatorString);
0874   if (separator == std::string::npos) {
0875     separatorString = "Discrimination";  //DiscriminationAgainst, keep the 'against' here
0876     separator = discriminatorLabel.find(separatorString);
0877     if (separator == std::string::npos) {
0878       return false;
0879     }
0880   }
0881   std::string prefix = discriminatorLabel.substr(0, separator);
0882   std::string postfix = discriminatorLabel.substr(separator + separatorString.size());
0883   newLabel = prefix + postfix;
0884   return true;
0885 }