Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:33:19

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/standardValidation/" + 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/standardValidation/" + 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/standardValidation/" + 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::cout << "Current discriminator: \n";
0233     //std::cout << DiscriminatorLabel;
0234     std::string histogramName;
0235     stripDiscriminatorLabel(DiscriminatorLabel, histogramName);
0236 
0237     //Summary plots
0238     string DiscriminatorLabelReduced = it.getParameter<string>("discriminator");
0239     DiscriminatorLabelReduced.erase(0, 24);
0240     summaryMap.find(refCollection_ + "Den")->second->setBinLabel(j + 1, DiscriminatorLabelReduced);
0241     summaryMap.find(refCollection_ + "Num")->second->setBinLabel(j + 1, DiscriminatorLabelReduced);
0242     summaryMap.find(refCollection_)->second->setBinLabel(j + 1, DiscriminatorLabelReduced);
0243 
0244     ibooker.setCurrentFolder("RecoTauV/standardValidation/" + TauProducer_ + extensionName_ + "_" + DiscriminatorLabel);
0245 
0246     ptTemp = ibooker.book1D(DiscriminatorLabel + "_vs_ptTauVisible",
0247                             histogramName + "_vs_ptTauVisible",
0248                             ptHinfo.nbins,
0249                             ptHinfo.min,
0250                             ptHinfo.max);
0251     etaTemp = ibooker.book1D(DiscriminatorLabel + "_vs_etaTauVisible",
0252                              histogramName + "_vs_etaTauVisible",
0253                              etaHinfo.nbins,
0254                              etaHinfo.min,
0255                              etaHinfo.max);
0256     phiTemp = ibooker.book1D(DiscriminatorLabel + "_vs_phiTauVisible",
0257                              histogramName + "_vs_phiTauVisible",
0258                              phiHinfo.nbins,
0259                              phiHinfo.min,
0260                              phiHinfo.max);
0261     pileupTemp = ibooker.book1D(DiscriminatorLabel + "_vs_pileupTauVisible",
0262                                 histogramName + "_vs_pileupTauVisible",
0263                                 pileupHinfo.nbins,
0264                                 pileupHinfo.min,
0265                                 pileupHinfo.max);
0266 
0267     ptTauVisibleMap.insert(std::make_pair(DiscriminatorLabel, ptTemp));
0268     etaTauVisibleMap.insert(std::make_pair(DiscriminatorLabel, etaTemp));
0269     phiTauVisibleMap.insert(std::make_pair(DiscriminatorLabel, phiTemp));
0270     pileupTauVisibleMap.insert(std::make_pair(DiscriminatorLabel, pileupTemp));
0271 
0272     tmpME = ibooker.book1D(
0273         DiscriminatorLabel + "_TauCandMass", histogramName + "_TauCandMass" + ";Cand Mass" + ";Frequency", 30, 0., 2.0);
0274     plotMap_.insert(std::make_pair(DiscriminatorLabel + "_TauCandMass", tmpME));
0275 
0276     // momentum resolution for several decay modes
0277 
0278     std::string plotType = "_pTRatio_";  //use underscores (this allows to parse plot type in later stages)
0279     std::string xaxisLabel = ";p_{T}^{reco}/p_{T}^{gen}";
0280     std::string yaxislabel = ";Frequency";
0281     std::string plotName = plotType + "allHadronic";
0282     int bins = 40;
0283     tmpME =
0284         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0285     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0286     plotName = plotType + "oneProng0Pi0";
0287     tmpME =
0288         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0289     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0290     plotName = plotType + "oneProng1Pi0";
0291     tmpME =
0292         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0293     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0294     plotName = plotType + "oneProng2Pi0";
0295     tmpME =
0296         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0297     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0298 
0299     plotName = plotType + "twoProng0Pi0";
0300     tmpME =
0301         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0302     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0303     plotName = plotType + "twoProng1Pi0";
0304     tmpME =
0305         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0306     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0307     plotName = plotType + "twoProng2Pi0";
0308     tmpME =
0309         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0310     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0311 
0312     plotName = plotType + "threeProng0Pi0";
0313     tmpME =
0314         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0315     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0316     plotName = plotType + "threeProng1Pi0";
0317     tmpME =
0318         ibooker.book1D(DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 2.);
0319     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0320 
0321     // Tau Multiplicity for several decay modes
0322 
0323     plotType = "_nTaus_";  //use underscores (this allows to parse plot type in later stages)
0324     xaxisLabel = ";Tau Multiplicity";
0325     yaxislabel = ";Frequency";
0326     plotName = plotType + "allHadronic";
0327     bins = 50;
0328     tmpME = ibooker.book1D(
0329         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0330     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0331     plotName = plotType + "oneProng0Pi0";
0332     tmpME = ibooker.book1D(
0333         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0334     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0335     plotName = plotType + "oneProng1Pi0";
0336     tmpME = ibooker.book1D(
0337         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0338     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0339     plotName = plotType + "oneProng2Pi0";
0340     tmpME = ibooker.book1D(
0341         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0342     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0343     plotName = plotType + "twoProng0Pi0";
0344     tmpME = ibooker.book1D(
0345         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0346     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0347     plotName = plotType + "twoProng1Pi0";
0348     tmpME = ibooker.book1D(
0349         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0350     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0351     plotName = plotType + "twoProng2Pi0";
0352     tmpME = ibooker.book1D(
0353         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0354     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0355     plotName = plotType + "threeProng0Pi0";
0356     tmpME = ibooker.book1D(
0357         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0358     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0359     plotName = plotType + "threeProng1Pi0";
0360     tmpME = ibooker.book1D(
0361         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0362     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0363 
0364     //size and sumPt within tau isolation
0365 
0366     plotType = "_Size_";
0367     xaxisLabel = ";size";
0368     yaxislabel = ";Frequency";
0369     bins = 20;
0370     plotName = plotType + "signalCands";
0371     tmpME = ibooker.book1D(
0372         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0373     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0374     plotName = plotType + "signalChargedHadrCands";
0375     tmpME = ibooker.book1D(
0376         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0377     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0378     plotName = plotType + "signalNeutrHadrCands";
0379     tmpME = ibooker.book1D(
0380         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0381     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0382 
0383     plotName = plotType + "isolationCands";
0384     tmpME = ibooker.book1D(
0385         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0386     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0387     plotName = plotType + "isolationChargedHadrCands";
0388     bins = 10;
0389     tmpME = ibooker.book1D(
0390         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0391     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0392     plotName = plotType + "isolationNeutrHadrCands";
0393     tmpME = ibooker.book1D(
0394         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0395     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0396     plotName = plotType + "isolationGammaCands";
0397     tmpME = ibooker.book1D(
0398         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, -0.5, bins - 0.5);
0399     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0400 
0401     plotType = "_SumPt_";
0402     xaxisLabel = ";p_{T}^{sum}/ GeV";
0403     yaxislabel = ";Frequency";
0404     bins = 20;
0405     plotName = plotType + "signalCands";
0406     tmpME = ibooker.book1D(
0407         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0408     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0409     plotName = plotType + "signalChargedHadrCands";
0410     tmpME = ibooker.book1D(
0411         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0412     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0413     plotName = plotType + "signalNeutrHadrCands";
0414     tmpME = ibooker.book1D(
0415         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0416     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0417     plotName = plotType + "isolationCands";
0418     tmpME = ibooker.book1D(
0419         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 50.);
0420     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0421     plotName = plotType + "isolationChargedHadrCands";
0422     tmpME = ibooker.book1D(
0423         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 10.);
0424     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0425     plotName = plotType + "isolationNeutrHadrCands";
0426     tmpME = ibooker.book1D(
0427         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 30.);
0428     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0429     plotName = plotType + "isolationGammaCands";
0430     tmpME = ibooker.book1D(
0431         DiscriminatorLabel + plotName, histogramName + plotName + xaxisLabel + yaxislabel, bins, 0., 20.);
0432     plotMap_.insert(std::make_pair(DiscriminatorLabel + plotName, tmpME));
0433 
0434     //deprecated!
0435 
0436     if (DiscriminatorLabel.find("LeadingTrackPtCut") != string::npos) {
0437       if (TauProducer_.find("PFTau") != string::npos) {
0438         nPFJet_LeadingChargedHadron_ChargedHadronsSignal_ = ibooker.book1D(
0439             DiscriminatorLabel + "_ChargedHadronsSignal", DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);
0440         nPFJet_LeadingChargedHadron_ChargedHadronsIsolAnnulus_ =
0441             ibooker.book1D(DiscriminatorLabel + "_ChargedHadronsIsolAnnulus",
0442                            DiscriminatorLabel + "_ChargedHadronsIsolAnnulus",
0443                            21,
0444                            -0.5,
0445                            20.5);
0446         nPFJet_LeadingChargedHadron_GammasSignal_ =
0447             ibooker.book1D(DiscriminatorLabel + "_GammasSignal", DiscriminatorLabel + "_GammasSignal", 21, -0.5, 20.5);
0448         nPFJet_LeadingChargedHadron_GammasIsolAnnulus_ = ibooker.book1D(
0449             DiscriminatorLabel + "_GammasIsolAnnulus", DiscriminatorLabel + "_GammasIsolAnnulus", 21, -0.5, 20.5);
0450         nPFJet_LeadingChargedHadron_NeutralHadronsSignal_ = ibooker.book1D(
0451             DiscriminatorLabel + "_NeutralHadronsSignal", DiscriminatorLabel + "_NeutralHadronsSignal", 21, -0.5, 20.5);
0452         nPFJet_LeadingChargedHadron_NeutralHadronsIsolAnnulus_ =
0453             ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0454                            DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0455                            21,
0456                            -0.5,
0457                            20.5);
0458       }
0459     }
0460 
0461     if (DiscriminatorLabel.find("ByIsolationLater") != string::npos) {
0462       if (TauProducer_.find("PFTau") != string::npos) {
0463         nIsolated_NoChargedHadrons_ChargedHadronsSignal_ = ibooker.book1D(
0464             DiscriminatorLabel + "_ChargedHadronsSignal", DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);
0465         nIsolated_NoChargedHadrons_GammasSignal_ =
0466             ibooker.book1D(DiscriminatorLabel + "_GammasSignal", DiscriminatorLabel + "_GammasSignal", 21, -0.5, 20.5);
0467         nIsolated_NoChargedHadrons_GammasIsolAnnulus_ = ibooker.book1D(
0468             DiscriminatorLabel + "_GammasIsolAnnulus", DiscriminatorLabel + "_GammasIsolAnnulus", 21, -0.5, 20.5);
0469         nIsolated_NoChargedHadrons_NeutralHadronsSignal_ = ibooker.book1D(
0470             DiscriminatorLabel + "_NeutralHadronsSignal", DiscriminatorLabel + "_NeutralHadronsSignal", 21, -0.5, 20.5);
0471         nIsolated_NoChargedHadrons_NeutralHadronsIsolAnnulus_ =
0472             ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0473                            DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0474                            21,
0475                            -0.5,
0476                            20.5);
0477       }
0478     }
0479 
0480     if (DiscriminatorLabel.find("ByIsolation") != string::npos) {
0481       if (TauProducer_.find("PFTau") != string::npos) {
0482         nIsolated_NoChargedNoGammas_ChargedHadronsSignal_ = ibooker.book1D(
0483             DiscriminatorLabel + "_ChargedHadronsSignal", DiscriminatorLabel + "_ChargedHadronsSignal", 21, -0.5, 20.5);
0484         nIsolated_NoChargedNoGammas_GammasSignal_ =
0485             ibooker.book1D(DiscriminatorLabel + "_GammasSignal", DiscriminatorLabel + "_GammasSignal", 21, -0.5, 20.5);
0486         nIsolated_NoChargedNoGammas_NeutralHadronsSignal_ = ibooker.book1D(
0487             DiscriminatorLabel + "_NeutralHadronsSignal", DiscriminatorLabel + "_NeutralHadronsSignal", 21, -0.5, 20.5);
0488         nIsolated_NoChargedNoGammas_NeutralHadronsIsolAnnulus_ =
0489             ibooker.book1D(DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0490                            DiscriminatorLabel + "_NeutralHadronsIsolAnnulus",
0491                            21,
0492                            -0.5,
0493                            20.5);
0494       }
0495     }
0496     j++;
0497   }
0498 }
0499 
0500 void TauTagValidation::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0501   if (genericTriggerEventFlag_) {
0502     if (genericTriggerEventFlag_->on()) {
0503       genericTriggerEventFlag_->initRun(iRun, iSetup);
0504     }
0505   }
0506 }
0507 
0508 void TauTagValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0509   if (genericTriggerEventFlag_) {
0510     if (!genericTriggerEventFlag_->on())
0511       std::cout << "TauTagValidation::analyze: No working genericTriggerEventFlag. Did you specify a valid globaltag?"
0512                 << std::endl;  //move to LogDebug?
0513   }
0514 
0515   numEvents_++;
0516   double matching_criteria = -1.0;
0517 
0518   //Initialize the Tau Multiplicity Counter
0519   for (const auto& it : discriminators_) {
0520     string DiscriminatorLabel = it.getParameter<string>("discriminator");
0521     tauDecayCountMap_["allHadronic" + DiscriminatorLabel] = 0;
0522     tauDecayCountMap_["oneProng0Pi0" + DiscriminatorLabel] = 0;
0523     tauDecayCountMap_["oneProng1Pi0" + DiscriminatorLabel] = 0;
0524     tauDecayCountMap_["oneProng2Pi0" + DiscriminatorLabel] = 0;
0525     tauDecayCountMap_["twoProng0Pi0" + DiscriminatorLabel] = 0;
0526     tauDecayCountMap_["twoProng1Pi0" + DiscriminatorLabel] = 0;
0527     tauDecayCountMap_["twoProng2Pi0" + DiscriminatorLabel] = 0;
0528     tauDecayCountMap_["threeProng0Pi0" + DiscriminatorLabel] = 0;
0529     tauDecayCountMap_["threeProng1Pi0" + DiscriminatorLabel] = 0;
0530   }
0531 
0532   typedef edm::View<reco::Candidate> genCandidateCollection;
0533 
0534   // ----------------------- Reference product -----------------------------------------------------------------------
0535 
0536   Handle<genCandidateCollection> ReferenceCollection;
0537   bool isGen = iEvent.getByToken(refCollectionInputTagToken_, ReferenceCollection);
0538 
0539   Handle<VertexCollection> pvHandle;
0540   iEvent.getByToken(primaryVertexCollectionToken_, pvHandle);  //TO-DO
0541 
0542   if (!isGen) {
0543     std::cerr << " Reference collection: " << refCollection_ << " not found while running TauTagValidation.cc "
0544               << std::endl;
0545     return;
0546   }
0547 
0548   if (dataType_ == "Leptons") {
0549     matching_criteria = matchDeltaR_Leptons_;
0550   } else {
0551     matching_criteria = matchDeltaR_Jets_;
0552   }
0553 
0554   // ------------------------------ PFTauCollection Matched and other discriminators ---------------------------------------------------------
0555 
0556   if (TauProducer_.find("PFTau") != string::npos || TauProducer_.find("hpsTancTaus") != string::npos) {
0557     // Retrieve ID container indices if config history changes, in particular for the first event.
0558     if (phID_ != iEvent.processHistoryID()) {
0559       phID_ = iEvent.processHistoryID();
0560       for (size_t idx = 0; idx < currentDiscriminatorContainerToken_.size(); ++idx) {
0561         const edm::Provenance* prov = iEvent.getHandle(currentDiscriminatorContainerToken_[idx].first).provenance();
0562         string prov_cfg_label = currentDiscriminatorContainerIdName_[idx].first;
0563         string prov_ID_label = currentDiscriminatorContainerIdName_[idx].second;
0564         bool found = false;
0565         if (prov_cfg_label == "rawValues" || prov_cfg_label == "workingPoints") {
0566           const std::vector<string> psetsFromProvenance = edm::parameterSet(prov->stable(), iEvent.processHistory())
0567                                                               .getParameter<std::vector<string>>(prov_cfg_label);
0568           for (size_t i = 0; i < psetsFromProvenance.size(); ++i) {
0569             if (psetsFromProvenance[i] == prov_ID_label) {
0570               // using negative indices for raw values
0571               if (prov_cfg_label == "rawValues")
0572                 currentDiscriminatorContainerToken_[idx].second = -1 - i;
0573               else
0574                 currentDiscriminatorContainerToken_[idx].second = i;
0575               found = true;
0576             }
0577           }
0578         } else if (prov_cfg_label == "IDdefinitions" || prov_cfg_label == "IDWPdefinitions") {
0579           const std::vector<edm::ParameterSet> psetsFromProvenance =
0580               edm::parameterSet(prov->stable(), iEvent.processHistory())
0581                   .getParameter<std::vector<edm::ParameterSet>>(prov_cfg_label);
0582           for (size_t i = 0; i < psetsFromProvenance.size(); ++i) {
0583             if (psetsFromProvenance[i].getParameter<string>("IDname") == prov_ID_label) {
0584               // using negative indices for raw values
0585               if (prov_cfg_label == "IDdefinitions")
0586                 currentDiscriminatorContainerToken_[idx].second = -1 - i;
0587               else
0588                 currentDiscriminatorContainerToken_[idx].second = i;
0589               found = true;
0590             }
0591           }
0592         } else {
0593           // checked prov_cfg_label before, so it must be a direct access via indices
0594           try {
0595             int i = std::stoi(prov_ID_label);
0596             if (prov_cfg_label == "direct_rawValues")
0597               currentDiscriminatorContainerToken_[idx].second = -1 - i;
0598             else
0599               currentDiscriminatorContainerToken_[idx].second = i;
0600             found = true;
0601           } catch (std::invalid_argument const& e) {
0602             throw cms::Exception("Configuration") << "TauTagValidation: Direct access to ID container requested, so "
0603                                                      "argument of 'idLabel' must be convertable to int!\n";
0604           }
0605         }
0606         if (!found) {
0607           throw cms::Exception("Configuration")
0608               << "TauTagValidation: Requested working point '" << prov_ID_label << "' for ID '"
0609               << discriminators_.at(idx - currentDiscriminatorToken_.size()).getParameter<string>("discriminator")
0610               << "' not found!\n";
0611         }
0612       }
0613     }
0614 
0615     Handle<PFTauCollection> thePFTauHandle;
0616     iEvent.getByToken(tauProducerInputTagToken_, thePFTauHandle);
0617 
0618     const PFTauCollection* pfTauProduct;
0619     pfTauProduct = thePFTauHandle.product();
0620 
0621     PFTauCollection::size_type thePFTauClosest;
0622 
0623     std::map<std::string, MonitorElement*>::const_iterator element = plotMap_.end();
0624 
0625     //Run the Reference Collection
0626     for (genCandidateCollection::const_iterator RefJet = ReferenceCollection->begin();
0627          RefJet != ReferenceCollection->end();
0628          RefJet++) {
0629       ptTauVisibleMap.find(refCollection_)->second->Fill(RefJet->pt());
0630       etaTauVisibleMap.find(refCollection_)->second->Fill(RefJet->eta());
0631       phiTauVisibleMap.find(refCollection_)->second->Fill(RefJet->phi() * 180.0 / TMath::Pi());
0632       pileupTauVisibleMap.find(refCollection_)->second->Fill(pvHandle->size());
0633 
0634       const reco::Candidate* gen_particle = &(*RefJet);
0635 
0636       double delta = TMath::Pi();
0637 
0638       thePFTauClosest = pfTauProduct->size();
0639 
0640       for (PFTauCollection::size_type iPFTau = 0; iPFTau < pfTauProduct->size(); iPFTau++) {
0641         if (algo_->deltaR(gen_particle, &pfTauProduct->at(iPFTau)) < delta) {
0642           delta = algo_->deltaR(gen_particle, &pfTauProduct->at(iPFTau));
0643           thePFTauClosest = iPFTau;
0644         }
0645       }
0646 
0647       // Skip if there is no reconstructed Tau matching the Reference
0648       if (thePFTauClosest == pfTauProduct->size())
0649         continue;
0650 
0651       double deltaR = algo_->deltaR(gen_particle, &pfTauProduct->at(thePFTauClosest));
0652 
0653       // Skip if the delta R difference is larger than the required criteria
0654       if (deltaR > matching_criteria && matching_criteria != -1.0)
0655         continue;
0656 
0657       ptTauVisibleMap.find(TauProducer_ + "Matched")->second->Fill(RefJet->pt());
0658       etaTauVisibleMap.find(TauProducer_ + "Matched")->second->Fill(RefJet->eta());
0659       phiTauVisibleMap.find(TauProducer_ + "Matched")->second->Fill(RefJet->phi() * 180.0 / TMath::Pi());
0660       pileupTauVisibleMap.find(TauProducer_ + "Matched")->second->Fill(pvHandle->size());
0661 
0662       PFTauRef thePFTau(thePFTauHandle, thePFTauClosest);
0663 
0664       Handle<PFTauDiscriminator> currentDiscriminator;
0665       Handle<TauDiscriminatorContainer> currentDiscriminatorContainer;
0666 
0667       //filter the candidates
0668       if (thePFTau->pt() < TauPtCut_)
0669         continue;  //almost deprecated, since recoCuts_ provides more flexibility
0670                    //reco
0671       StringCutObjectSelector<PFTauRef> selectReco(recoCuts_);
0672       bool pass = selectReco(thePFTau);
0673       if (!pass)
0674         continue;
0675       //gen
0676       StringCutObjectSelector<reco::Candidate> selectGen(genCuts_);
0677       pass = selectGen(*gen_particle);
0678       if (!pass)
0679         continue;
0680 
0681       for (unsigned j = 0; j < discriminators_.size(); j++) {
0682         string currentDiscriminatorLabel = discriminators_.at(j).getParameter<string>("discriminator");
0683         summaryMap.find(refCollection_ + "Den")->second->Fill(j);
0684 
0685         bool passesID;
0686         if (j < currentDiscriminatorToken_.size()) {
0687           iEvent.getByToken(currentDiscriminatorToken_[j], currentDiscriminator);
0688           passesID = ((*currentDiscriminator)[thePFTau] >= discriminators_.at(j).getParameter<double>("selectionCut"));
0689         } else {
0690           iEvent.getByToken(currentDiscriminatorContainerToken_[j - currentDiscriminatorToken_.size()].first,
0691                             currentDiscriminatorContainer);
0692           if (currentDiscriminatorContainerToken_[j - currentDiscriminatorToken_.size()].second < 0) {
0693             if ((*currentDiscriminatorContainer)[thePFTau].rawValues.size() == 1)
0694               passesID = false;  //in case of prediscriminant fail at reco level
0695             else
0696               passesID = ((*currentDiscriminatorContainer)[thePFTau].rawValues.at(
0697                               -1 - currentDiscriminatorContainerToken_[j - currentDiscriminatorToken_.size()].second) >=
0698                           discriminators_.at(j).getParameter<double>("selectionCut"));
0699           } else {
0700             if ((*currentDiscriminatorContainer)[thePFTau].workingPoints.empty())
0701               passesID = false;  //in case of prediscriminant fail at reco level
0702             else
0703               passesID = (*currentDiscriminatorContainer)[thePFTau].workingPoints.at(
0704                   currentDiscriminatorContainerToken_[j - currentDiscriminatorToken_.size()].second);
0705           }
0706         }
0707         if (passesID) {
0708           ptTauVisibleMap.find(currentDiscriminatorLabel)->second->Fill(RefJet->pt());
0709           etaTauVisibleMap.find(currentDiscriminatorLabel)->second->Fill(RefJet->eta());
0710           phiTauVisibleMap.find(currentDiscriminatorLabel)->second->Fill(RefJet->phi() * 180.0 / TMath::Pi());
0711           pileupTauVisibleMap.find(currentDiscriminatorLabel)->second->Fill(pvHandle->size());
0712           summaryMap.find(refCollection_ + "Num")->second->Fill(j);
0713 
0714           //fill the momentum resolution plots
0715           double tauPtRes = thePFTau->pt() / gen_particle->pt();  //WARNING: use only the visible parts!
0716           plotMap_.find(currentDiscriminatorLabel + "_pTRatio_allHadronic")->second->Fill(tauPtRes);
0717 
0718           //Fill Tau Cand Mass
0719           TLorentzVector TAU;
0720           TAU.SetPtEtaPhiE(thePFTau->pt(), thePFTau->eta(), thePFTau->phi(), thePFTau->energy());
0721           plotMap_.find(currentDiscriminatorLabel + "_TauCandMass")->second->Fill(TAU.M());
0722 
0723           //Tau Counter, allHadronic mode
0724           tauDecayCountMap_.find("allHadronic" + currentDiscriminatorLabel)->second++;
0725 
0726           /*
0727           //is there a better way than casting the candidate?
0728           const reco::GenJet *tauGenJet = dynamic_cast<const reco::GenJet*>(gen_particle);
0729           if(tauGenJet){
0730             std::string genTauDecayMode =  JetMCTagUtils::genTauDecayMode(*tauGenJet); // gen_particle is the tauGenJet matched to the reconstructed tau
0731             element = plotMap_.find( currentDiscriminatorLabel + "_pTRatio_" + genTauDecayMode );
0732             if( element != plotMap_.end() ) element->second->Fill(tauPtRes);
0733             tauDecayCountMap_.find( genTauDecayMode + currentDiscriminatorLabel)->second++;
0734           }else{
0735             LogInfo("TauTagValidation") << " Failed to cast the MC candidate.";
0736       }*/
0737 
0738           if (thePFTau->decayMode() == reco::PFTau::kOneProng0PiZero) {
0739             tauDecayCountMap_.find("oneProng0Pi0" + currentDiscriminatorLabel)->second++;
0740             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "oneProng0Pi0")->second->Fill(tauPtRes);
0741           } else if (thePFTau->decayMode() == reco::PFTau::kOneProng1PiZero) {
0742             tauDecayCountMap_.find("oneProng1Pi0" + currentDiscriminatorLabel)->second++;
0743             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "oneProng1Pi0")->second->Fill(tauPtRes);
0744           } else if (thePFTau->decayMode() == reco::PFTau::kOneProng2PiZero) {
0745             tauDecayCountMap_.find("oneProng2Pi0" + currentDiscriminatorLabel)->second++;
0746             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "oneProng2Pi0")->second->Fill(tauPtRes);
0747           } else if (thePFTau->decayMode() == reco::PFTau::kTwoProng0PiZero) {
0748             tauDecayCountMap_.find("twoProng0Pi0" + currentDiscriminatorLabel)->second++;
0749             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "twoProng0Pi0")->second->Fill(tauPtRes);
0750           } else if (thePFTau->decayMode() == reco::PFTau::kTwoProng1PiZero) {
0751             tauDecayCountMap_.find("twoProng1Pi0" + currentDiscriminatorLabel)->second++;
0752             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "twoProng1Pi0")->second->Fill(tauPtRes);
0753           } else if (thePFTau->decayMode() == reco::PFTau::kTwoProng2PiZero) {
0754             tauDecayCountMap_.find("twoProng2Pi0" + currentDiscriminatorLabel)->second++;
0755             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "twoProng2Pi0")->second->Fill(tauPtRes);
0756           } else if (thePFTau->decayMode() == reco::PFTau::kThreeProng0PiZero) {
0757             tauDecayCountMap_.find("threeProng0Pi0" + currentDiscriminatorLabel)->second++;
0758             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "threeProng0Pi0")->second->Fill(tauPtRes);
0759           } else if (thePFTau->decayMode() == reco::PFTau::kThreeProng1PiZero) {
0760             tauDecayCountMap_.find("threeProng1Pi0" + currentDiscriminatorLabel)->second++;
0761             plotMap_.find(currentDiscriminatorLabel + "_pTRatio_" + "threeProng1Pi0")->second->Fill(tauPtRes);
0762           }
0763           //fill: size and sumPt within tau isolation
0764           std::string plotType = "_Size_";
0765           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalCands");
0766           if (element != plotMap_.end())
0767             element->second->Fill(thePFTau->signalCands().size());
0768           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalChargedHadrCands");
0769           if (element != plotMap_.end())
0770             element->second->Fill(thePFTau->signalChargedHadrCands().size());
0771           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalNeutrHadrCands");
0772           if (element != plotMap_.end())
0773             element->second->Fill(thePFTau->signalNeutrHadrCands().size());
0774           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationCands");
0775           if (element != plotMap_.end())
0776             element->second->Fill(thePFTau->isolationCands().size());
0777           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationChargedHadrCands");
0778           if (element != plotMap_.end())
0779             element->second->Fill(thePFTau->isolationChargedHadrCands().size());
0780           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationNeutrHadrCands");
0781           if (element != plotMap_.end())
0782             element->second->Fill(thePFTau->isolationNeutrHadrCands().size());
0783           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationGammaCands");
0784           if (element != plotMap_.end())
0785             element->second->Fill(thePFTau->isolationGammaCands().size());
0786 
0787           plotType = "_SumPt_";
0788           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalCands");
0789           if (element != plotMap_.end())
0790             element->second->Fill(getSumPt(thePFTau->signalCands()));
0791           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalChargedHadrCands");
0792           if (element != plotMap_.end())
0793             element->second->Fill(getSumPt(thePFTau->signalChargedHadrCands()));
0794           element = plotMap_.find(currentDiscriminatorLabel + plotType + "signalNeutrHadrCands");
0795           if (element != plotMap_.end())
0796             element->second->Fill(getSumPt(thePFTau->signalNeutrHadrCands()));
0797           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationCands");
0798           if (element != plotMap_.end())
0799             element->second->Fill(getSumPt(thePFTau->isolationCands()));
0800           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationChargedHadrCands");
0801           if (element != plotMap_.end())
0802             element->second->Fill(getSumPt(thePFTau->isolationChargedHadrCands()));
0803           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationNeutrHadrCands");
0804           if (element != plotMap_.end())
0805             element->second->Fill(getSumPt(thePFTau->isolationNeutrHadrCands()));
0806           element = plotMap_.find(currentDiscriminatorLabel + plotType + "isolationGammaCands");
0807           if (element != plotMap_.end())
0808             element->second->Fill(getSumPt(thePFTau->isolationGammaCands()));
0809 
0810           //deprecated
0811 
0812           if (TauProducer_.find("PFTau") != string::npos) {
0813             if (currentDiscriminatorLabel.find("LeadingTrackPtCut") != string::npos) {
0814               nPFJet_LeadingChargedHadron_ChargedHadronsSignal_->Fill((*thePFTau).signalChargedHadrCands().size());
0815               nPFJet_LeadingChargedHadron_ChargedHadronsIsolAnnulus_->Fill(
0816                   (*thePFTau).isolationChargedHadrCands().size());
0817               nPFJet_LeadingChargedHadron_GammasSignal_->Fill((*thePFTau).signalGammaCands().size());
0818               nPFJet_LeadingChargedHadron_GammasIsolAnnulus_->Fill((*thePFTau).isolationGammaCands().size());
0819               nPFJet_LeadingChargedHadron_NeutralHadronsSignal_->Fill((*thePFTau).signalNeutrHadrCands().size());
0820               nPFJet_LeadingChargedHadron_NeutralHadronsIsolAnnulus_->Fill(
0821                   (*thePFTau).isolationNeutrHadrCands().size());
0822             } else if (currentDiscriminatorLabel.find("ByIsolation") != string::npos) {
0823               nIsolated_NoChargedNoGammas_ChargedHadronsSignal_->Fill((*thePFTau).signalChargedHadrCands().size());
0824               nIsolated_NoChargedNoGammas_GammasSignal_->Fill((*thePFTau).signalGammaCands().size());
0825               nIsolated_NoChargedNoGammas_NeutralHadronsSignal_->Fill((*thePFTau).signalNeutrHadrCands().size());
0826               nIsolated_NoChargedNoGammas_NeutralHadronsIsolAnnulus_->Fill(
0827                   (*thePFTau).isolationNeutrHadrCands().size());
0828             }
0829           }
0830         } else {
0831           if (chainCuts_)
0832             break;
0833         }
0834       }
0835     }  //End of Reference Collection Loop
0836 
0837     //Fill the Tau Multiplicity Histograms
0838     for (const auto& it : discriminators_) {
0839       string currentDiscriminatorLabel = it.getParameter<string>("discriminator");
0840       plotMap_.find(currentDiscriminatorLabel + "_nTaus_allHadronic")
0841           ->second->Fill(tauDecayCountMap_.find("allHadronic" + currentDiscriminatorLabel)->second);
0842       plotMap_.find(currentDiscriminatorLabel + "_nTaus_oneProng0Pi0")
0843           ->second->Fill(tauDecayCountMap_.find("oneProng0Pi0" + currentDiscriminatorLabel)->second);
0844       plotMap_.find(currentDiscriminatorLabel + "_nTaus_oneProng1Pi0")
0845           ->second->Fill(tauDecayCountMap_.find("oneProng1Pi0" + currentDiscriminatorLabel)->second);
0846       plotMap_.find(currentDiscriminatorLabel + "_nTaus_oneProng2Pi0")
0847           ->second->Fill(tauDecayCountMap_.find("oneProng2Pi0" + currentDiscriminatorLabel)->second);
0848       plotMap_.find(currentDiscriminatorLabel + "_nTaus_twoProng0Pi0")
0849           ->second->Fill(tauDecayCountMap_.find("twoProng0Pi0" + currentDiscriminatorLabel)->second);
0850       plotMap_.find(currentDiscriminatorLabel + "_nTaus_twoProng1Pi0")
0851           ->second->Fill(tauDecayCountMap_.find("twoProng1Pi0" + currentDiscriminatorLabel)->second);
0852       plotMap_.find(currentDiscriminatorLabel + "_nTaus_twoProng2Pi0")
0853           ->second->Fill(tauDecayCountMap_.find("twoProng2Pi0" + currentDiscriminatorLabel)->second);
0854       plotMap_.find(currentDiscriminatorLabel + "_nTaus_threeProng0Pi0")
0855           ->second->Fill(tauDecayCountMap_.find("threeProng0Pi0" + currentDiscriminatorLabel)->second);
0856       plotMap_.find(currentDiscriminatorLabel + "_nTaus_threeProng1Pi0")
0857           ->second->Fill(tauDecayCountMap_.find("threeProng1Pi0" + currentDiscriminatorLabel)->second);
0858     }
0859 
0860   }  //End of PFTau Collection If Loop
0861 }
0862 
0863 double TauTagValidation::getSumPt(const std::vector<edm::Ptr<reco::Candidate>>& candidates) {
0864   double sumPt = 0.;
0865   for (std::vector<edm::Ptr<reco::Candidate>>::const_iterator candidate = candidates.begin();
0866        candidate != candidates.end();
0867        ++candidate) {
0868     sumPt += (*candidate)->pt();
0869   }
0870   return sumPt;
0871 }
0872 
0873 bool TauTagValidation::stripDiscriminatorLabel(const std::string& discriminatorLabel, std::string& newLabel) {
0874   std::string separatorString = "DiscriminationBy";
0875   std::string::size_type separator = discriminatorLabel.find(separatorString);
0876   if (separator == std::string::npos) {
0877     separatorString = "Discrimination";  //DiscriminationAgainst, keep the 'against' here
0878     separator = discriminatorLabel.find(separatorString);
0879     if (separator == std::string::npos) {
0880       return false;
0881     }
0882   }
0883   std::string prefix = discriminatorLabel.substr(0, separator);
0884   std::string postfix = discriminatorLabel.substr(separator + separatorString.size());
0885   newLabel = prefix + postfix;
0886   return true;
0887 }