Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:34:01

0001 // -*- C++ -*-
0002 //
0003 // Package:    TauValidationMiniAOD
0004 // Class:      TauValidationMiniAOD
0005 //
0006 /**\class TauValidationMiniAOD TauValidationMiniAOD.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Class used to do the Validation of the Tau in miniAOD
0011 
0012  Implementation:
0013  <Notes on implementation>
0014  */
0015 //
0016 // Original Author:  Aniello Spiezia
0017 //         Created:  August 13, 2019
0018 
0019 #include "Validation/RecoTau/interface/TauValidationMiniAOD.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 
0022 using namespace edm;
0023 using namespace std;
0024 using namespace reco;
0025 
0026 TauValidationMiniAOD::TauValidationMiniAOD(const edm::ParameterSet& iConfig) {
0027   tauCollection_ = consumes<pat::TauCollection>(iConfig.getParameter<InputTag>("tauCollection"));
0028   refCollectionInputTagToken_ = consumes<edm::View<reco::Candidate> >(iConfig.getParameter<InputTag>("RefCollection"));
0029   extensionName_ = iConfig.getParameter<string>("ExtensionName");
0030   discriminators_ = iConfig.getParameter<std::vector<edm::ParameterSet> >("discriminators");
0031 }
0032 
0033 TauValidationMiniAOD::~TauValidationMiniAOD() {}
0034 
0035 void TauValidationMiniAOD::bookHistograms(DQMStore::IBooker& ibooker,
0036                                           edm::Run const& iRun,
0037                                           edm::EventSetup const& /* iSetup */) {
0038   MonitorElement *ptTemp, *etaTemp, *phiTemp, *massTemp, *decayModeFindingTemp, *decayModeTemp,
0039       *byDeepTau2017v2p1VSerawTemp, *byDeepTau2017v2p1VSjetrawTemp, *byDeepTau2017v2p1VSmurawTemp, *summaryTemp;
0040   ibooker.setCurrentFolder("RecoTauV/miniAODValidation" + extensionName_);
0041 
0042   //summary plots
0043   histoInfo summaryHinfo = (histoSettings_.exists("summary"))
0044                                ? histoInfo(histoSettings_.getParameter<edm::ParameterSet>("summary"))
0045                                : histoInfo(21, -0.5, 20.5);
0046   summaryTemp =
0047       ibooker.book1D("summaryPlotNum", "summaryPlotNum", summaryHinfo.nbins, summaryHinfo.min, summaryHinfo.max);
0048   summaryMap.insert(std::make_pair("Num", summaryTemp));
0049   summaryTemp =
0050       ibooker.book1D("summaryPlotDen", "summaryPlotDen", summaryHinfo.nbins, summaryHinfo.min, summaryHinfo.max);
0051   summaryMap.insert(std::make_pair("Den", summaryTemp));
0052   summaryTemp = ibooker.book1D("summaryPlot", "summaryPlot", summaryHinfo.nbins, summaryHinfo.min, summaryHinfo.max);
0053   summaryMap.insert(std::make_pair("", summaryTemp));
0054 
0055   int j = 0;
0056   for (const auto& it : discriminators_) {
0057     string DiscriminatorLabel = it.getParameter<string>("discriminator");
0058     summaryMap.find("Den")->second->setBinLabel(j + 1, DiscriminatorLabel);
0059     summaryMap.find("Num")->second->setBinLabel(j + 1, DiscriminatorLabel);
0060     summaryMap.find("")->second->setBinLabel(j + 1, DiscriminatorLabel);
0061     j = j + 1;
0062   }
0063 
0064   //other plots
0065   histoInfo ptHinfo = (histoSettings_.exists("pt")) ? histoInfo(histoSettings_.getParameter<edm::ParameterSet>("pt"))
0066                                                     : histoInfo(200, 0., 1000.);
0067   histoInfo etaHinfo = (histoSettings_.exists("eta")) ? histoInfo(histoSettings_.getParameter<edm::ParameterSet>("eta"))
0068                                                       : histoInfo(200, -3, 3.);
0069   histoInfo phiHinfo = (histoSettings_.exists("phi")) ? histoInfo(histoSettings_.getParameter<edm::ParameterSet>("phi"))
0070                                                       : histoInfo(200, -3, 3.);
0071   histoInfo massHinfo = (histoSettings_.exists("mass"))
0072                             ? histoInfo(histoSettings_.getParameter<edm::ParameterSet>("mass"))
0073                             : histoInfo(200, 0, 10.);
0074   histoInfo decayModeFindingHinfo = (histoSettings_.exists("decayModeFinding"))
0075                                         ? histoInfo(histoSettings_.getParameter<edm::ParameterSet>("decayModeFinding"))
0076                                         : histoInfo(2, -0.5, 1.5);
0077   histoInfo decayModeHinfo = (histoSettings_.exists("decayMode"))
0078                                  ? histoInfo(histoSettings_.getParameter<edm::ParameterSet>("decayMode"))
0079                                  : histoInfo(11, -0.5, 10.5);
0080   histoInfo byDeepTau2017v2p1VSerawHinfo =
0081       (histoSettings_.exists("byDeepTau2017v2p1VSeraw"))
0082           ? histoInfo(histoSettings_.getParameter<edm::ParameterSet>("byDeepTau2017v2p1VSeraw"))
0083           : histoInfo(200, 0., 1.);
0084   histoInfo byDeepTau2017v2p1VSjetrawHinfo =
0085       (histoSettings_.exists("byDeepTau2017v2p1VSjetraw"))
0086           ? histoInfo(histoSettings_.getParameter<edm::ParameterSet>("byDeepTau2017v2p1VSjetraw"))
0087           : histoInfo(200, 0., 1.);
0088   histoInfo byDeepTau2017v2p1VSmurawHinfo =
0089       (histoSettings_.exists("byDeepTau2017v2p1VSmuraw"))
0090           ? histoInfo(histoSettings_.getParameter<edm::ParameterSet>("byDeepTau2017v2p1VSmuraw"))
0091           : histoInfo(200, 0., 1.);
0092   ptTemp = ibooker.book1D("tau_pt", "tau_pt", ptHinfo.nbins, ptHinfo.min, ptHinfo.max);
0093   etaTemp = ibooker.book1D("tau_eta", "tau_eta", etaHinfo.nbins, etaHinfo.min, etaHinfo.max);
0094   phiTemp = ibooker.book1D("tau_phi", "tau_phi", phiHinfo.nbins, phiHinfo.min, phiHinfo.max);
0095   massTemp = ibooker.book1D("tau_mass", "tau_mass", massHinfo.nbins, massHinfo.min, massHinfo.max);
0096   decayModeFindingTemp = ibooker.book1D("tau_decayModeFinding",
0097                                         "tau_decayModeFinding",
0098                                         decayModeFindingHinfo.nbins,
0099                                         decayModeFindingHinfo.min,
0100                                         decayModeFindingHinfo.max);
0101   decayModeTemp =
0102       ibooker.book1D("tau_decayMode", "tau_decayMode", decayModeHinfo.nbins, decayModeHinfo.min, decayModeHinfo.max);
0103   byDeepTau2017v2p1VSerawTemp = ibooker.book1D("tau_byDeepTau2017v2p1VSeraw",
0104                                                "tau_byDeepTau2017v2p1VSeraw",
0105                                                byDeepTau2017v2p1VSerawHinfo.nbins,
0106                                                byDeepTau2017v2p1VSerawHinfo.min,
0107                                                byDeepTau2017v2p1VSerawHinfo.max);
0108   byDeepTau2017v2p1VSjetrawTemp = ibooker.book1D("tau_byDeepTau2017v2p1VSjetraw",
0109                                                  "tau_byDeepTau2017v2p1VSjetraw",
0110                                                  byDeepTau2017v2p1VSjetrawHinfo.nbins,
0111                                                  byDeepTau2017v2p1VSjetrawHinfo.min,
0112                                                  byDeepTau2017v2p1VSjetrawHinfo.max);
0113   byDeepTau2017v2p1VSmurawTemp = ibooker.book1D("tau_byDeepTau2017v2p1VSmuraw",
0114                                                 "tau_byDeepTau2017v2p1VSmuraw",
0115                                                 byDeepTau2017v2p1VSmurawHinfo.nbins,
0116                                                 byDeepTau2017v2p1VSmurawHinfo.min,
0117                                                 byDeepTau2017v2p1VSmurawHinfo.max);
0118   ptMap.insert(std::make_pair("", ptTemp));
0119   etaMap.insert(std::make_pair("", etaTemp));
0120   phiMap.insert(std::make_pair("", phiTemp));
0121   massMap.insert(std::make_pair("", massTemp));
0122   decayModeFindingMap.insert(std::make_pair("", decayModeFindingTemp));
0123   decayModeMap.insert(std::make_pair("", decayModeTemp));
0124   byDeepTau2017v2p1VSerawMap.insert(std::make_pair("", byDeepTau2017v2p1VSerawTemp));
0125   byDeepTau2017v2p1VSjetrawMap.insert(std::make_pair("", byDeepTau2017v2p1VSjetrawTemp));
0126   byDeepTau2017v2p1VSmurawMap.insert(std::make_pair("", byDeepTau2017v2p1VSmurawTemp));
0127 }
0128 
0129 void TauValidationMiniAOD::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0130   edm::Handle<pat::TauCollection> taus;
0131   bool isTau = iEvent.getByToken(tauCollection_, taus);
0132   if (!isTau) {
0133     edm::LogWarning("TauValidationMiniAOD") << " Tau collection not found while running TauValidationMiniAOD.cc ";
0134     return;
0135   }
0136   typedef edm::View<reco::Candidate> refCandidateCollection;
0137   Handle<refCandidateCollection> ReferenceCollection;
0138   bool isRef = iEvent.getByToken(refCollectionInputTagToken_, ReferenceCollection);
0139   if (!isRef) {
0140     edm::LogWarning("TauValidationMiniAOD") << " Reference collection not found while running TauValidationMiniAOD.cc ";
0141     return;
0142   }
0143   for (refCandidateCollection::const_iterator RefJet = ReferenceCollection->begin();
0144        RefJet != ReferenceCollection->end();
0145        RefJet++) {
0146     float dRmin = 0.15;
0147     unsigned matchedTauIndex = -99;
0148     for (unsigned iTau = 0; iTau < taus->size(); iTau++) {
0149       pat::TauRef tau(taus, iTau);
0150       //for (pat::TauCollection::const_iterator tau = taus->begin(); tau != taus->end(); tau++) {
0151       //pat::TauRef matchedTau(*tau);
0152       float dR = deltaR(tau->eta(), tau->phi(), RefJet->eta(), RefJet->phi());
0153       if (dR < dRmin) {
0154         dRmin = dR;
0155         matchedTauIndex = iTau;
0156       }
0157     }
0158     if (dRmin < 0.15) {
0159       pat::TauRef matchedTau(taus, matchedTauIndex);
0160       ptMap.find("")->second->Fill(matchedTau->pt());
0161       etaMap.find("")->second->Fill(matchedTau->eta());
0162       phiMap.find("")->second->Fill(matchedTau->phi());
0163       massMap.find("")->second->Fill(matchedTau->mass());
0164       decayModeMap.find("")->second->Fill(matchedTau->decayMode());
0165       if (matchedTau->isTauIDAvailable("decayModeFinding"))
0166         decayModeFindingMap.find("")->second->Fill(matchedTau->tauID("decayModeFinding"));
0167       if (matchedTau->isTauIDAvailable("byDeepTau2017v2p1VSeraw"))
0168         byDeepTau2017v2p1VSerawMap.find("")->second->Fill(matchedTau->tauID("byDeepTau2017v2p1VSeraw"));
0169       if (matchedTau->isTauIDAvailable("byDeepTau2017v2p1VSjetraw"))
0170         byDeepTau2017v2p1VSjetrawMap.find("")->second->Fill(matchedTau->tauID("byDeepTau2017v2p1VSjetraw"));
0171       if (matchedTau->isTauIDAvailable("byDeepTau2017v2p1VSmuraw"))
0172         byDeepTau2017v2p1VSmurawMap.find("")->second->Fill(matchedTau->tauID("byDeepTau2017v2p1VSmuraw"));
0173       int j = 0;
0174       for (const auto& it : discriminators_) {
0175         string currentDiscriminator = it.getParameter<string>("discriminator");
0176         double selectionCut = it.getParameter<double>("selectionCut");
0177         summaryMap.find("Den")->second->Fill(j);
0178         if (matchedTau->tauID(currentDiscriminator) >= selectionCut)
0179           summaryMap.find("Num")->second->Fill(j);
0180         j = j + 1;
0181       }
0182     }
0183   }
0184 }