Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-26 02:43:45

0001 #include "L1Trigger/Phase2L1Taus/interface/L1HPSPFTauQualityCut.h"
0002 #include "FWCore/Utilities/interface/Exception.h"  // cms::Exception
0003 
0004 L1HPSPFTauQualityCut::L1HPSPFTauQualityCut(const edm::ParameterSet& cfg)
0005     : debug_(cfg.getUntrackedParameter<bool>("debug", false)) {
0006   std::string pfCandTypeString = cfg.getParameter<std::string>("pfCandType");
0007   if (pfCandTypeString == "chargedHadron")
0008     pfCandType_ = l1t::PFCandidate::ChargedHadron;
0009   else if (pfCandTypeString == "electron")
0010     pfCandType_ = l1t::PFCandidate::Electron;
0011   else if (pfCandTypeString == "muon")
0012     pfCandType_ = l1t::PFCandidate::Muon;
0013   else if (pfCandTypeString == "neutralHadron")
0014     pfCandType_ = l1t::PFCandidate::NeutralHadron;
0015   else if (pfCandTypeString == "photon")
0016     pfCandType_ = l1t::PFCandidate::Photon;
0017   else
0018     throw cms::Exception("L1HPSPFTauQualityCut")
0019         << "Invalid Configuration parameter 'pfCandType' = '" << pfCandTypeString << "' !!\n";
0020 
0021   std::string dzCutString = cfg.getParameter<std::string>("dzCut");
0022   if (dzCutString == "disabled")
0023     dzCut_ = kDisabled;
0024   else if (dzCutString == "enabled_primary")
0025     dzCut_ = kEnabledPrimary;
0026   else if (dzCutString == "enabled_pileup")
0027     dzCut_ = kEnabledPileup;
0028   else
0029     throw cms::Exception("L1HPSPFTauQualityCut")
0030         << "Invalid Configuration parameter 'dzCut' = '" << dzCutString << "' !!\n";
0031 
0032   minPt_ = cfg.getParameter<double>("minPt");
0033   maxDz_ = (cfg.exists("maxDz")) ? cfg.getParameter<double>("maxDz") : 1.e+3;
0034 }
0035 
0036 bool L1HPSPFTauQualityCut::operator()(const l1t::PFCandidate& pfCand, float_t primaryVertex_z) const {
0037   if (pfCand.id() == pfCandType_) {
0038     if (pfCand.pt() < minPt_) {
0039       return false;
0040     }
0041 
0042     if (pfCand.charge() != 0) {
0043       if (dzCut_ == kEnabledPrimary || dzCut_ == kEnabledPileup) {
0044         const l1t::PFTrackRef& pfCand_track = pfCand.pfTrack();
0045         double dz = std::abs(pfCand_track->vertex().z() - primaryVertex_z);
0046         if (dzCut_ == kEnabledPrimary && dz > maxDz_)
0047           return false;
0048         if (dzCut_ == kEnabledPileup && dz <= maxDz_)
0049           return false;
0050       }
0051     } else if (dzCut_ == kEnabledPileup) {
0052       return false;  // CV: only consider charged PFCands as originating from pileup
0053     }
0054   }
0055   return true;
0056 }
0057 
0058 l1t::PFCandidate::ParticleType L1HPSPFTauQualityCut::pfCandType() const { return pfCandType_; }
0059 
0060 int L1HPSPFTauQualityCut::dzCut() const { return dzCut_; }
0061 
0062 float_t L1HPSPFTauQualityCut::minPt() const { return minPt_; }
0063 
0064 float_t L1HPSPFTauQualityCut::maxDz() const { return maxDz_; }
0065 
0066 L1HPSPFTauQualityCut readL1PFTauQualityCut(const edm::ParameterSet& cfg,
0067                                            const std::string& pfCandType,
0068                                            const std::string& dzCut,
0069                                            bool debug) {
0070   edm::ParameterSet cfg_pfCandType = cfg.getParameter<edm::ParameterSet>(pfCandType);
0071   cfg_pfCandType.addParameter<std::string>("pfCandType", pfCandType);
0072   cfg_pfCandType.addParameter<std::string>("dzCut", dzCut);
0073   cfg_pfCandType.addUntrackedParameter<bool>("debug", debug);
0074   L1HPSPFTauQualityCut qualityCut(cfg_pfCandType);
0075   return qualityCut;
0076 }
0077 
0078 std::vector<L1HPSPFTauQualityCut> readL1PFTauQualityCuts(const edm::ParameterSet& cfg,
0079                                                          const std::string& dzCut,
0080                                                          bool debug) {
0081   std::vector<L1HPSPFTauQualityCut> qualityCuts;
0082   qualityCuts.push_back(readL1PFTauQualityCut(cfg, "chargedHadron", dzCut, debug));
0083   qualityCuts.push_back(readL1PFTauQualityCut(cfg, "electron", dzCut, debug));
0084   qualityCuts.push_back(readL1PFTauQualityCut(cfg, "muon", dzCut, debug));
0085   qualityCuts.push_back(readL1PFTauQualityCut(cfg, "photon", dzCut, debug));
0086   qualityCuts.push_back(readL1PFTauQualityCut(cfg, "neutralHadron", dzCut, debug));
0087   return qualityCuts;
0088 }
0089 
0090 bool isSelected(const std::vector<L1HPSPFTauQualityCut>& qualityCuts,
0091                 const l1t::PFCandidate& pfCand,
0092                 float_t primaryVertex_z) {
0093   for (auto qualityCut : qualityCuts) {
0094     if (!qualityCut(pfCand, primaryVertex_z))
0095       return false;
0096   }
0097   return true;
0098 }