Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:39

0001 #include "DQMOffline/Trigger/interface/HLTTauDQML1Plotter.h"
0002 
0003 #include "FWCore/Framework/interface/Event.h"
0004 
0005 #include <cstring>
0006 
0007 namespace {
0008   double getMaxEta(int binsEta, double widthEta) {
0009     if (widthEta <= 0.0) {
0010       edm::LogWarning("HLTTauDQMOffline") << "HLTTauDQML1Plotter::HLTTauDQML1Plotter: EtaHistoBinWidth = " << widthEta
0011                                           << " <= 0, using default value 0.348 instead";
0012       widthEta = 0.348;
0013     }
0014     return binsEta / 2 * widthEta;
0015   }
0016 }  // namespace
0017 
0018 HLTTauDQML1Plotter::HLTTauDQML1Plotter(const edm::ParameterSet& ps,
0019                                        edm::ConsumesCollector&& cc,
0020                                        int phibins,
0021                                        double maxpt,
0022                                        double maxhighpt,
0023                                        bool ref,
0024                                        double dr,
0025                                        const std::string& dqmBaseFolder)
0026     : HLTTauDQMPlotter(ps, dqmBaseFolder),
0027       doRefAnalysis_(ref),
0028       matchDeltaR_(dr),
0029       maxPt_(maxpt),
0030       maxHighPt_(maxhighpt),
0031       binsEt_(ps.getUntrackedParameter<int>("EtHistoBins", 25)),
0032       binsEta_(ps.getUntrackedParameter<int>("EtaHistoBins", 14)),
0033       binsPhi_(phibins),
0034       maxEta_(getMaxEta(binsEta_, ps.getUntrackedParameter<double>("EtaHistoBinWidth", 0.348))) {
0035   if (!configValid_)
0036     return;
0037 
0038   //Process PSet
0039   l1stage2Taus_ = ps.getUntrackedParameter<edm::InputTag>("L1Taus");
0040   l1stage2TausToken_ = cc.consumes<l1t::TauBxCollection>(l1stage2Taus_);
0041 
0042   l1stage2Sums_ = ps.getUntrackedParameter<edm::InputTag>("L1ETM");
0043   l1stage2SumsToken_ = cc.consumes<l1t::EtSumBxCollection>(l1stage2Sums_);
0044   l1ETMMin_ = ps.getUntrackedParameter<double>("L1ETMMin");
0045 
0046   configValid_ = true;
0047 }
0048 
0049 void HLTTauDQML1Plotter::bookHistograms(HistoWrapper& iWrapper, DQMStore::IBooker& iBooker) {
0050   if (!configValid_)
0051     return;
0052 
0053   // The L1 phi plot is asymmetric around 0 because of the discrete nature of L1 phi
0054   constexpr float pi = 3.1416f;
0055   constexpr float phiShift = pi / 18;  // half of 2pi/18 bin
0056   constexpr float minPhi = -pi + phiShift;
0057   constexpr float maxPhi = pi + phiShift;
0058 
0059   constexpr int BUFMAX = 256;
0060   char buffer[BUFMAX] = "";
0061 
0062   //Create the histograms
0063   iBooker.setCurrentFolder(triggerTag());
0064 
0065   l1tauEt_ = iWrapper.book1D(iBooker, "L1TauEt", "L1 #tau E_{T};L1 #tau E_{T};entries", binsEt_, 0, maxPt_, kVital);
0066   l1tauEta_ = iWrapper.book1D(iBooker, "L1TauEta", "L1 #tau #eta;L1 #tau #eta;entries", binsEta_, -maxEta_, maxEta_);
0067   l1tauPhi_ = iWrapper.book1D(iBooker, "L1TauPhi", "L1 #tau #phi;L1 #tau #phi;entries", binsPhi_, minPhi, maxPhi);
0068 
0069   l1isotauEt_ = iWrapper.book1D(
0070       iBooker, "L1IsoTauEt", "L1 isolated #tau E_{T};L1 #tau E_{T};entries", binsEt_, 0, maxPt_, kVital);
0071   l1isotauEta_ = iWrapper.book1D(
0072       iBooker, "L1IsoTauEta", "L1 isolated #tau #eta;L1 #tau #eta;entries", binsEta_, -maxEta_, maxEta_);
0073   l1isotauPhi_ =
0074       iWrapper.book1D(iBooker, "L1IsoTauPhi", "L1 isolated #tau #phi;L1 #tau #phi;entries", binsPhi_, minPhi, maxPhi);
0075 
0076   l1etmEt_ = iWrapper.book1D(iBooker, "L1ETM", "L1 ETM E_{T};L1 ETM E_{T};entries", binsEt_, 0, maxPt_, kVital);
0077   l1etmPhi_ = iWrapper.book1D(iBooker, "L1ETMPhi", "L1 ETM #phi;L1 ETM #phi;entries", binsPhi_, minPhi, maxPhi);
0078 
0079   snprintf(buffer, BUFMAX, "L1 leading #tau E_{T};L1 #tau E_{T};entries");
0080   firstTauEt_ = iWrapper.book1D(iBooker, "L1LeadTauEt", buffer, binsEt_, 0, maxPt_, kVital);
0081   snprintf(buffer, BUFMAX, "L1 leading #tau #eta;L1 #tau #eta;entries");
0082   firstTauEta_ = iWrapper.book1D(iBooker, "L1LeadTauEta", buffer, binsEta_, -maxEta_, maxEta_);
0083   snprintf(buffer, BUFMAX, "L1 leading #tau #phi;L1 #tau #phi;entries");
0084   firstTauPhi_ = iWrapper.book1D(iBooker, "L1LeadTauPhi", buffer, binsPhi_, minPhi, maxPhi);
0085 
0086   snprintf(buffer, BUFMAX, "L1 second-leading #tau E_{T};L1 #tau E_{T};entries");
0087   secondTauEt_ = iWrapper.book1D(iBooker, "L1SecondTauEt", buffer, binsEt_, 0, maxPt_, kVital);
0088   snprintf(buffer, BUFMAX, "L1 second-leading #tau #eta;L1 #tau #eta;entries");
0089   secondTauEta_ = iWrapper.book1D(iBooker, "L1SecondTauEta", buffer, binsEta_, -maxEta_, maxEta_);
0090   snprintf(buffer, BUFMAX, "L1 second-leading #tau #phi;L1 #tau #phi;entries");
0091   secondTauPhi_ = iWrapper.book1D(iBooker, "L1SecondTauPhi", buffer, binsPhi_, minPhi, maxPhi);
0092 
0093   snprintf(buffer, BUFMAX, "L1 leading isolated #tau E_{T};L1 #tau E_{T};entries");
0094   firstIsoTauEt_ = iWrapper.book1D(iBooker, "L1LeadIsoTauEt", buffer, binsEt_, 0, maxPt_, kVital);
0095   snprintf(buffer, BUFMAX, "L1 leading isolated #tau #eta;L1 #tau #eta;entries");
0096   firstIsoTauEta_ = iWrapper.book1D(iBooker, "L1LeadIsoTauEta", buffer, binsEta_, -maxEta_, maxEta_);
0097   snprintf(buffer, BUFMAX, "L1 leading isolated #tau #phi;L1 #tau #phi;entries");
0098   firstIsoTauPhi_ = iWrapper.book1D(iBooker, "L1LeadIsoTauPhi", buffer, binsPhi_, minPhi, maxPhi);
0099 
0100   snprintf(buffer, BUFMAX, "L1 second-leading isolated #tau E_{T};L1 #tau E_{T};entries");
0101   secondIsoTauEt_ = iWrapper.book1D(iBooker, "L1SecondIsoTauEt", buffer, binsEt_, 0, maxPt_, kVital);
0102   snprintf(buffer, BUFMAX, "L1 second-leading isolated #tau #eta;L1 #tau #eta;entries");
0103   secondIsoTauEta_ = iWrapper.book1D(iBooker, "L1SecondIsoTauEta", buffer, binsEta_, -maxEta_, maxEta_);
0104   snprintf(buffer, BUFMAX, "L1 second-leading isolated #tau #phi;L1 #tau #phi;entries");
0105   secondIsoTauPhi_ = iWrapper.book1D(iBooker, "L1SecondIsoTauPhi", buffer, binsPhi_, minPhi, maxPhi);
0106 
0107   if (doRefAnalysis_) {
0108     l1tauEtRes_ = iWrapper.book1D(iBooker,
0109                                   "L1TauEtResol",
0110                                   "L1 #tau E_{T} resolution;[L1 #tau E_{T}-Ref #tau E_{T}]/Ref #tau E_{T};entries",
0111                                   60,
0112                                   -1,
0113                                   4,
0114                                   kVital);
0115     l1isotauEtRes_ =
0116         iWrapper.book1D(iBooker,
0117                         "L1IsoTauEtResol",
0118                         "L1 isolated #tau E_{T} resolution;[L1 #tau E_{T}-Ref #tau E_{T}]/Ref #tau E_{T};entries",
0119                         60,
0120                         -1,
0121                         4,
0122                         kVital);
0123 
0124     iBooker.setCurrentFolder(triggerTag() + "/helpers");
0125 
0126     l1tauEtEffNum_ = iWrapper.book1D(
0127         iBooker, "L1TauEtEffNum", "L1 #tau E_{T} Efficiency;Ref #tau E_{T};entries", binsEt_, 0, maxPt_, kVital);
0128     l1tauHighEtEffNum_ = iWrapper.book1D(iBooker,
0129                                          "L1TauHighEtEffNum",
0130                                          "L1 #tau E_{T} Efficiency (high E_{T});Ref #tau E_{T};entries",
0131                                          binsEt_,
0132                                          0,
0133                                          maxHighPt_,
0134                                          kVital);
0135 
0136     l1tauEtEffDenom_ = iWrapper.book1D(
0137         iBooker, "L1TauEtEffDenom", "L1 #tau E_{T} Denominator;Ref #tau E_{T};entries", binsEt_, 0, maxPt_, kVital);
0138     l1tauHighEtEffDenom_ = iWrapper.book1D(iBooker,
0139                                            "L1TauHighEtEffDenom",
0140                                            "L1 #tau E_{T} Denominator (high E_{T});Ref #tau E_{T};Efficiency",
0141                                            binsEt_,
0142                                            0,
0143                                            maxHighPt_,
0144                                            kVital);
0145 
0146     l1tauEtaEffNum_ = iWrapper.book1D(
0147         iBooker, "L1TauEtaEffNum", "L1 #tau #eta Efficiency;Ref #tau #eta;entries", binsEta_, -maxEta_, maxEta_);
0148     l1tauEtaEffDenom_ = iWrapper.book1D(
0149         iBooker, "L1TauEtaEffDenom", "L1 #tau #eta Denominator;Ref #tau #eta;entries", binsEta_, -maxEta_, maxEta_);
0150 
0151     l1tauPhiEffNum_ = iWrapper.book1D(
0152         iBooker, "L1TauPhiEffNum", "L1 #tau #phi Efficiency;Ref #tau #phi;entries", binsPhi_, minPhi, maxPhi);
0153     l1tauPhiEffDenom_ = iWrapper.book1D(
0154         iBooker, "L1TauPhiEffDenom", "L1 #tau #phi Denominator;Ref #tau #phi;Efficiency", binsPhi_, minPhi, maxPhi);
0155 
0156     l1isotauEtEffNum_ = iWrapper.book1D(iBooker,
0157                                         "L1IsoTauEtEffNum",
0158                                         "L1 isolated #tau E_{T} Efficiency;Ref #tau E_{T};entries",
0159                                         binsEt_,
0160                                         0,
0161                                         maxPt_,
0162                                         kVital);
0163     l1isotauEtEffDenom_ = iWrapper.book1D(iBooker,
0164                                           "L1IsoTauEtEffDenom",
0165                                           "L1 isolated #tau E_{T} Denominator;Ref #tau E_{T};entries",
0166                                           binsEt_,
0167                                           0,
0168                                           maxPt_,
0169                                           kVital);
0170 
0171     l1isotauEtaEffNum_ = iWrapper.book1D(iBooker,
0172                                          "L1IsoTauEtaEffNum",
0173                                          "L1 isolated #tau #eta Efficiency;Ref #tau #eta;entries",
0174                                          binsEta_,
0175                                          -maxEta_,
0176                                          maxEta_);
0177     l1isotauEtaEffDenom_ = iWrapper.book1D(iBooker,
0178                                            "L1IsoTauEtaEffDenom",
0179                                            "L1 isolated #tau #eta Denominator;Ref #tau #eta;entries",
0180                                            binsEta_,
0181                                            -maxEta_,
0182                                            maxEta_);
0183 
0184     l1isotauPhiEffNum_ = iWrapper.book1D(iBooker,
0185                                          "L1IsoTauPhiEffNum",
0186                                          "L1 isolated #tau #phi Efficiency;Ref #tau #phi;entries",
0187                                          binsPhi_,
0188                                          minPhi,
0189                                          maxPhi);
0190     l1isotauPhiEffDenom_ = iWrapper.book1D(iBooker,
0191                                            "L1IsoTauPhiEffDenom",
0192                                            "L1 isolated #tau #phi Denominator;Ref #tau #phi;Efficiency",
0193                                            binsPhi_,
0194                                            minPhi,
0195                                            maxPhi);
0196 
0197     l1etmEtEffNum_ =
0198         iWrapper.book1D(iBooker, "L1ETMEtEffNum", "L1 ETM Efficiency;Ref MET;entries", binsEt_, 0, maxPt_, kVital);
0199     l1etmEtEffDenom_ =
0200         iWrapper.book1D(iBooker, "L1ETMEtEffDenom", "L1 ETM Denominator;Ref MET;entries", binsEt_, 0, maxPt_, kVital);
0201   }
0202 }
0203 
0204 HLTTauDQML1Plotter::~HLTTauDQML1Plotter() = default;
0205 
0206 //
0207 // member functions
0208 //
0209 
0210 void HLTTauDQML1Plotter::analyze(const edm::Event& iEvent,
0211                                  const edm::EventSetup& iSetup,
0212                                  const HLTTauDQMOfflineObjects& refC) {
0213   if (doRefAnalysis_) {
0214     //Tau reference
0215     for (auto const& tau : refC.taus) {
0216       if (l1tauEtEffDenom_)
0217         l1tauEtEffDenom_->Fill(tau.pt());
0218       if (l1tauHighEtEffDenom_)
0219         l1tauHighEtEffDenom_->Fill(tau.pt());
0220 
0221       if (l1tauEtaEffDenom_)
0222         l1tauEtaEffDenom_->Fill(tau.eta());
0223 
0224       if (l1tauPhiEffDenom_)
0225         l1tauPhiEffDenom_->Fill(tau.phi());
0226 
0227       if (l1isotauEtEffDenom_)
0228         l1isotauEtEffDenom_->Fill(tau.pt());
0229       if (l1isotauEtaEffDenom_)
0230         l1isotauEtaEffDenom_->Fill(tau.eta());
0231       if (l1isotauPhiEffDenom_)
0232         l1isotauPhiEffDenom_->Fill(tau.phi());
0233     }
0234     if (!refC.met.empty())
0235       if (l1etmEtEffDenom_)
0236         l1etmEtEffDenom_->Fill(refC.met[0].pt());
0237   }
0238 
0239   //Analyze L1 Objects (Tau+Jets)
0240   edm::Handle<l1t::TauBxCollection> taus;
0241   iEvent.getByToken(l1stage2TausToken_, taus);
0242 
0243   edm::Handle<l1t::EtSumBxCollection> sums;
0244   iEvent.getByToken(l1stage2SumsToken_, sums);
0245 
0246   LVColl pathTaus;
0247   LVColl pathIsoTaus;
0248 
0249   //Set Variables for the threshold plot
0250   LVColl l1taus;
0251   LVColl l1isotaus;
0252   LVColl l1met;
0253 
0254   if (taus.isValid()) {
0255     for (auto const& i : *taus) {
0256       l1taus.push_back(i.p4());
0257       if (i.hwIso() > 0)
0258         l1isotaus.push_back(i.p4());
0259       if (!doRefAnalysis_) {
0260         if (l1tauEt_)
0261           l1tauEt_->Fill(i.et());
0262         if (l1tauEta_)
0263           l1tauEta_->Fill(i.eta());
0264         if (l1tauPhi_)
0265           l1tauPhi_->Fill(i.phi());
0266         pathTaus.push_back(i.p4());
0267 
0268         if (l1isotauEt_)
0269           l1isotauEt_->Fill(i.et());
0270         if (l1isotauEta_)
0271           l1isotauEta_->Fill(i.eta());
0272         if (l1isotauPhi_)
0273           l1isotauPhi_->Fill(i.phi());
0274         if (i.hwIso() > 0)
0275           pathIsoTaus.push_back(i.p4());
0276       }
0277     }
0278   } else {
0279     edm::LogWarning("HLTTauDQMOffline") << "HLTTauDQML1Plotter::analyze: unable to read L1 tau collection "
0280                                         << l1stage2Taus_.encode();
0281   }
0282 
0283   if (sums.isValid() && sums.product()->size() > 0) {
0284     if (!doRefAnalysis_) {
0285       for (int ibx = sums->getFirstBX(); ibx <= sums->getLastBX(); ++ibx) {
0286         for (auto it = sums->begin(ibx); it != sums->end(ibx); it++) {
0287           auto type = static_cast<int>(it->getType());
0288           if (type == l1t::EtSum::EtSumType::kMissingEt)
0289             if (l1etmEt_)
0290               l1etmEt_->Fill(it->et());
0291         }
0292       }
0293     }
0294   } else {
0295     edm::LogWarning("HLTTauDQMOffline") << "HLTTauDQML1Plotter::analyze: unable to read L1 met collection "
0296                                         << l1stage2Sums_.encode();
0297   }
0298 
0299   //Now do the efficiency matching
0300   if (doRefAnalysis_) {
0301     for (auto const& tau : refC.taus) {
0302       std::pair<bool, LV> m = match(tau, l1taus, matchDeltaR_);
0303       if (m.first) {
0304         if (l1tauEt_)
0305           l1tauEt_->Fill(m.second.pt());
0306         if (l1tauEta_)
0307           l1tauEta_->Fill(m.second.eta());
0308         if (l1tauPhi_)
0309           l1tauPhi_->Fill(m.second.phi());
0310 
0311         if (l1tauEtEffNum_)
0312           l1tauEtEffNum_->Fill(tau.pt());
0313         if (l1tauHighEtEffNum_)
0314           l1tauHighEtEffNum_->Fill(tau.pt());
0315         if (l1tauEtaEffNum_)
0316           l1tauEtaEffNum_->Fill(tau.eta());
0317         if (l1tauPhiEffNum_)
0318           l1tauPhiEffNum_->Fill(tau.phi());
0319 
0320         if (l1tauEtRes_)
0321           l1tauEtRes_->Fill((m.second.pt() - tau.pt()) / tau.pt());
0322 
0323         pathTaus.push_back(m.second);
0324       }
0325       m = match(tau, l1isotaus, matchDeltaR_);
0326       if (m.first) {
0327         if (l1isotauEt_)
0328           l1isotauEt_->Fill(m.second.pt());
0329         if (l1isotauEta_)
0330           l1isotauEta_->Fill(m.second.eta());
0331         if (l1isotauPhi_)
0332           l1isotauPhi_->Fill(m.second.phi());
0333 
0334         if (l1isotauEtEffNum_)
0335           l1isotauEtEffNum_->Fill(tau.pt());
0336         if (l1isotauEtaEffNum_)
0337           l1isotauEtaEffNum_->Fill(tau.eta());
0338         if (l1isotauPhiEffNum_)
0339           l1isotauPhiEffNum_->Fill(tau.phi());
0340 
0341         if (l1isotauEtRes_)
0342           l1isotauEtRes_->Fill((m.second.pt() - tau.pt()) / tau.pt());
0343 
0344         pathIsoTaus.push_back(m.second);
0345       }
0346     }
0347 
0348     if (sums.isValid() && sums.product()->size() > 0) {
0349       for (int ibx = sums->getFirstBX(); ibx <= sums->getLastBX(); ++ibx) {
0350         for (auto it = sums->begin(ibx); it != sums->end(ibx); it++) {
0351           auto type = static_cast<int>(it->getType());
0352           if (type == l1t::EtSum::EtSumType::kMissingEt) {
0353             if (l1etmEt_)
0354               l1etmEt_->Fill(it->et());
0355             if (l1etmPhi_)
0356               l1etmPhi_->Fill(it->phi());
0357 
0358             if (it->et() > l1ETMMin_) {
0359               if (l1etmEtEffNum_)
0360                 l1etmEtEffNum_->Fill(it->et());
0361             }
0362           }
0363         }
0364       }
0365     }
0366   }
0367 
0368   //Fill the Threshold Monitoring
0369   if (pathTaus.size() > 1)
0370     std::sort(pathTaus.begin(), pathTaus.end(), [](const LV& a, const LV& b) { return a.pt() > b.pt(); });
0371   if (!pathTaus.empty()) {
0372     if (firstTauEt_)
0373       firstTauEt_->Fill(pathTaus[0].pt());
0374     if (firstTauEta_)
0375       firstTauEta_->Fill(pathTaus[0].eta());
0376     if (firstTauPhi_)
0377       firstTauPhi_->Fill(pathTaus[0].phi());
0378   }
0379   if (pathTaus.size() > 1) {
0380     if (secondTauEt_)
0381       secondTauEt_->Fill(pathTaus[1].pt());
0382     if (secondTauEta_)
0383       secondTauEta_->Fill(pathTaus[1].eta());
0384     if (secondTauPhi_)
0385       secondTauPhi_->Fill(pathTaus[1].phi());
0386   }
0387   if (pathIsoTaus.size() > 1)
0388     std::sort(pathIsoTaus.begin(), pathIsoTaus.end(), [](const LV& a, const LV& b) { return a.pt() > b.pt(); });
0389   if (!pathIsoTaus.empty()) {
0390     if (firstIsoTauEt_)
0391       firstIsoTauEt_->Fill(pathIsoTaus[0].pt());
0392     if (firstIsoTauEta_)
0393       firstIsoTauEta_->Fill(pathIsoTaus[0].eta());
0394     if (firstIsoTauPhi_)
0395       firstIsoTauPhi_->Fill(pathIsoTaus[0].phi());
0396   }
0397   if (pathIsoTaus.size() > 1) {
0398     if (secondIsoTauEt_)
0399       secondIsoTauEt_->Fill(pathIsoTaus[1].pt());
0400     if (secondIsoTauEta_)
0401       secondIsoTauEta_->Fill(pathIsoTaus[1].eta());
0402     if (secondIsoTauPhi_)
0403       secondIsoTauPhi_->Fill(pathIsoTaus[1].phi());
0404   }
0405 }