Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-28 22:23:59

0001 #include "HPSPFTauProducer.h"
0002 #include "FWCore/Utilities/interface/InputTag.h"
0003 #include <cmath>  // std::fabs
0004 
0005 HPSPFTauProducer::HPSPFTauProducer(const edm::ParameterSet& cfg)
0006     : moduleLabel_(cfg.getParameter<std::string>("@module_label")),
0007       tauBuilder_(cfg),
0008       useChargedPFCandSeeds_(cfg.getParameter<bool>("useChargedPFCandSeeds")),
0009       minSeedChargedPFCandPt_(cfg.getParameter<double>("minSeedChargedPFCandPt")),
0010       maxSeedChargedPFCandEta_(cfg.getParameter<double>("maxSeedChargedPFCandEta")),
0011       maxSeedChargedPFCandDz_(cfg.getParameter<double>("maxSeedChargedPFCandDz")),
0012       useJetSeeds_(cfg.getParameter<bool>("useJetSeeds")),
0013       minSeedJetPt_(cfg.getParameter<double>("minSeedJetPt")),
0014       maxSeedJetEta_(cfg.getParameter<double>("maxSeedJetEta")),
0015       minPFTauPt_(cfg.getParameter<double>("minPFTauPt")),
0016       maxPFTauEta_(cfg.getParameter<double>("maxPFTauEta")),
0017       minLeadChargedPFCandPt_(cfg.getParameter<double>("minLeadChargedPFCandPt")),
0018       maxLeadChargedPFCandEta_(cfg.getParameter<double>("maxLeadChargedPFCandEta")),
0019       maxLeadChargedPFCandDz_(cfg.getParameter<double>("maxLeadChargedPFCandDz")),
0020       maxChargedIso_(cfg.getParameter<double>("maxChargedIso")),
0021       maxChargedRelIso_(cfg.getParameter<double>("maxChargedRelIso")),
0022       deltaRCleaning_(cfg.getParameter<double>("deltaRCleaning")),
0023       applyPreselection_(cfg.getParameter<bool>("applyPreselection")),
0024       debug_(cfg.getUntrackedParameter<bool>("debug", false)) {
0025   srcL1PFCands_ = cfg.getParameter<edm::InputTag>("srcL1PFCands");
0026   tokenL1PFCands_ = consumes<l1t::PFCandidateCollection>(srcL1PFCands_);
0027   srcL1Jets_ = cfg.getParameter<edm::InputTag>("srcL1Jets");
0028   if (useJetSeeds_) {
0029     tokenL1Jets_ = consumes<std::vector<reco::CaloJet>>(srcL1Jets_);
0030   }
0031   srcL1Vertices_ = cfg.getParameter<edm::InputTag>("srcL1Vertices");
0032   if (!srcL1Vertices_.label().empty()) {
0033     tokenL1Vertices_ = consumes<std::vector<l1t::TkPrimaryVertex>>(srcL1Vertices_);
0034   }
0035   deltaR2Cleaning_ = deltaRCleaning_ * deltaRCleaning_;
0036 
0037   edm::ParameterSet cfg_signalQualityCuts = cfg.getParameter<edm::ParameterSet>("signalQualityCuts");
0038   signalQualityCutsDzCutDisabled_ = readL1PFTauQualityCuts(cfg_signalQualityCuts, "disabled");
0039   edm::ParameterSet cfg_isolationQualityCuts = cfg.getParameter<edm::ParameterSet>("isolationQualityCuts");
0040   isolationQualityCutsDzCutDisabled_ = readL1PFTauQualityCuts(cfg_isolationQualityCuts, "disabled");
0041 
0042   produces<l1t::HPSPFTauCollection>();
0043 }
0044 
0045 namespace {
0046   bool isHigherPt_pfCandRef(const l1t::PFCandidateRef& l1PFCand1, const l1t::PFCandidateRef& l1PFCand2) {
0047     return l1PFCand1->pt() > l1PFCand2->pt();
0048   }
0049 
0050   bool isHigherPt_pfTau(const l1t::HPSPFTau& l1PFTau1, const l1t::HPSPFTau& l1PFTau2) {
0051     return l1PFTau1.pt() > l1PFTau2.pt();
0052   }
0053 }  // namespace
0054 
0055 void HPSPFTauProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
0056   std::unique_ptr<l1t::HPSPFTauCollection> l1PFTauCollectionCleaned(new l1t::HPSPFTauCollection());
0057 
0058   edm::Handle<l1t::PFCandidateCollection> l1PFCands;
0059   evt.getByToken(tokenL1PFCands_, l1PFCands);
0060 
0061   l1t::TkPrimaryVertexRef primaryVertex;
0062   float primaryVertex_z = 0.;
0063   if (!srcL1Vertices_.label().empty()) {
0064     edm::Handle<std::vector<l1t::TkPrimaryVertex>> vertices;
0065     evt.getByToken(tokenL1Vertices_, vertices);
0066     if (!vertices->empty()) {
0067       primaryVertex = l1t::TkPrimaryVertexRef(vertices, 0);
0068       primaryVertex_z = primaryVertex->zvertex();
0069     }
0070   }
0071 
0072   // build collection of selected PFCandidates
0073   std::vector<l1t::PFCandidateRef> selectedL1PFCandsSignalQualityCuts;
0074   std::vector<l1t::PFCandidateRef> selectedL1PFCandsSignalOrIsolationQualityCuts;
0075   size_t numL1PFCands = l1PFCands->size();
0076   for (size_t idxL1PFCand = 0; idxL1PFCand < numL1PFCands; ++idxL1PFCand) {
0077     l1t::PFCandidateRef l1PFCand(l1PFCands, idxL1PFCand);
0078     bool passesSignalQualityCuts = isSelected(signalQualityCutsDzCutDisabled_, *l1PFCand, primaryVertex_z);
0079     bool passesIsolationQualityCuts = isSelected(isolationQualityCutsDzCutDisabled_, *l1PFCand, primaryVertex_z);
0080     if (passesSignalQualityCuts) {
0081       selectedL1PFCandsSignalQualityCuts.push_back(l1PFCand);
0082     }
0083     if (passesSignalQualityCuts || passesIsolationQualityCuts) {
0084       selectedL1PFCandsSignalOrIsolationQualityCuts.push_back(l1PFCand);
0085     }
0086   }
0087 
0088   // sort PFCandidate collection by decreasing pT
0089   std::sort(selectedL1PFCandsSignalQualityCuts.begin(), selectedL1PFCandsSignalQualityCuts.end(), isHigherPt_pfCandRef);
0090   std::sort(selectedL1PFCandsSignalOrIsolationQualityCuts.begin(),
0091             selectedL1PFCandsSignalOrIsolationQualityCuts.end(),
0092             isHigherPt_pfCandRef);
0093 
0094   l1t::HPSPFTauCollection l1PFTauCollectionUncleaned;
0095 
0096   if (useChargedPFCandSeeds_) {
0097     for (const auto& l1PFCand : selectedL1PFCandsSignalQualityCuts) {
0098       if (l1PFCand->charge() != 0 && l1PFCand->pt() > minSeedChargedPFCandPt_ &&
0099           std::fabs(l1PFCand->eta()) < maxSeedChargedPFCandEta_) {
0100         bool isFromPrimaryVertex = false;
0101         if (primaryVertex.get()) {
0102           l1t::PFTrackRef l1PFTrack = l1PFCand->pfTrack();
0103           double dz = std::fabs(l1PFTrack->vertex().z() - primaryVertex_z);
0104           if (dz < maxSeedChargedPFCandDz_) {
0105             isFromPrimaryVertex = true;
0106           }
0107         } else {
0108           isFromPrimaryVertex = true;
0109         }
0110         if (isFromPrimaryVertex) {
0111           tauBuilder_.reset();
0112           tauBuilder_.setL1PFCandProductID(l1PFCands.id());
0113           tauBuilder_.setVertex(primaryVertex);
0114           tauBuilder_.setL1PFTauSeed(l1PFCand);
0115           tauBuilder_.addL1PFCandidates(selectedL1PFCandsSignalOrIsolationQualityCuts);
0116           tauBuilder_.buildL1PFTau();
0117           l1t::HPSPFTau l1PFTau = tauBuilder_.getL1PFTau();
0118           if (l1PFTau.pt() > isPFTauPt_)
0119             l1PFTauCollectionUncleaned.push_back(l1PFTau);
0120         }
0121       }
0122     }
0123   }
0124 
0125   if (useJetSeeds_) {
0126     edm::Handle<std::vector<reco::CaloJet>> l1Jets;
0127     evt.getByToken(tokenL1Jets_, l1Jets);
0128 
0129     size_t numL1Jets = l1Jets->size();
0130     for (size_t idxL1Jet = 0; idxL1Jet < numL1Jets; ++idxL1Jet) {
0131       reco::CaloJetRef l1Jet(l1Jets, idxL1Jet);
0132       if (l1Jet->pt() > minSeedJetPt_ && std::fabs(l1Jet->eta()) < maxSeedJetEta_) {
0133         tauBuilder_.reset();
0134         tauBuilder_.setL1PFCandProductID(l1PFCands.id());
0135         tauBuilder_.setVertex(primaryVertex);
0136         //tauBuilder_.setL1PFTauSeed(l1Jet);
0137         tauBuilder_.setL1PFTauSeed(l1Jet, selectedL1PFCandsSignalQualityCuts);
0138         tauBuilder_.addL1PFCandidates(selectedL1PFCandsSignalOrIsolationQualityCuts);
0139         tauBuilder_.buildL1PFTau();
0140         l1t::HPSPFTau l1PFTau = tauBuilder_.getL1PFTau();
0141         if (l1PFTau.pt() > isPFTauPt_)
0142           l1PFTauCollectionUncleaned.push_back(l1PFTau);
0143       }
0144     }
0145   }
0146 
0147   // sort PFTau candidate collection by decreasing pT
0148   std::sort(l1PFTauCollectionUncleaned.begin(), l1PFTauCollectionUncleaned.end(), isHigherPt_pfTau);
0149 
0150   for (const auto& l1PFTau : l1PFTauCollectionUncleaned) {
0151     if (applyPreselection_ &&
0152         !(l1PFTau.pt() > minPFTauPt_ && std::fabs(l1PFTau.eta()) < maxPFTauEta_ &&
0153           l1PFTau.leadChargedPFCand().isNonnull() && l1PFTau.leadChargedPFCand()->pt() > minLeadChargedPFCandPt_ &&
0154           std::fabs(l1PFTau.leadChargedPFCand()->eta()) < maxLeadChargedPFCandEta_ &&
0155           (srcL1Vertices_.label().empty() ||
0156            (primaryVertex.isNonnull() && l1PFTau.leadChargedPFCand()->pfTrack().isNonnull() &&
0157             std::fabs(l1PFTau.leadChargedPFCand()->pfTrack()->vertex().z() - primaryVertex->zvertex()) <
0158                 maxLeadChargedPFCandDz_)) &&
0159           l1PFTau.sumChargedIso() < maxChargedIso_ && l1PFTau.sumChargedIso() < maxChargedRelIso_ * l1PFTau.pt()))
0160       continue;
0161 
0162     bool isOverlap = false;
0163     for (const auto& l1PFTau2 : *l1PFTauCollectionCleaned) {
0164       double deltaEta = l1PFTau.eta() - l1PFTau2.eta();
0165       double deltaPhi = l1PFTau.phi() - l1PFTau2.phi();
0166       if ((deltaEta * deltaEta + deltaPhi * deltaPhi) < deltaR2Cleaning_) {
0167         isOverlap = true;
0168       }
0169     }
0170     if (!isOverlap) {
0171       l1PFTauCollectionCleaned->push_back(l1PFTau);
0172     }
0173   }
0174 
0175   evt.put(std::move(l1PFTauCollectionCleaned));
0176 }
0177 
0178 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0179 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0180 
0181 void HPSPFTauProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0182   // HPSPFTauProducerPF
0183   edm::ParameterSetDescription desc;
0184   desc.add<bool>("useJetSeeds", true);
0185   desc.add<double>("minPFTauPt", 20.0);
0186   desc.add<double>("minSignalConeSize", 0.05);
0187   {
0188     edm::ParameterSetDescription psd0;
0189     {
0190       edm::ParameterSetDescription psd1;
0191       psd1.add<double>("minPt", 0.0);
0192       psd0.add<edm::ParameterSetDescription>("neutralHadron", psd1);
0193     }
0194     {
0195       edm::ParameterSetDescription psd1;
0196       psd1.add<double>("maxDz", 0.4);
0197       psd1.add<double>("minPt", 0.0);
0198       psd0.add<edm::ParameterSetDescription>("muon", psd1);
0199     }
0200     {
0201       edm::ParameterSetDescription psd1;
0202       psd1.add<double>("maxDz", 0.4);
0203       psd1.add<double>("minPt", 0.0);
0204       psd0.add<edm::ParameterSetDescription>("electron", psd1);
0205     }
0206     {
0207       edm::ParameterSetDescription psd1;
0208       psd1.add<double>("minPt", 0.0);
0209       psd0.add<edm::ParameterSetDescription>("photon", psd1);
0210     }
0211     {
0212       edm::ParameterSetDescription psd1;
0213       psd1.add<double>("maxDz", 0.4);
0214       psd1.add<double>("minPt", 0.0);
0215       psd0.add<edm::ParameterSetDescription>("chargedHadron", psd1);
0216     }
0217     desc.add<edm::ParameterSetDescription>("isolationQualityCuts", psd0);
0218   }
0219   desc.add<double>("stripSizePhi", 0.2);
0220   desc.add<double>("minSeedJetPt", 30.0);
0221   desc.add<double>("maxChargedRelIso", 1.0);
0222   desc.add<double>("minSeedChargedPFCandPt", 5.0);
0223   desc.add<edm::InputTag>("srcL1PFCands", edm::InputTag("l1ctLayer1", "PF"));
0224   desc.add<double>("stripSizeEta", 0.05);
0225   desc.add<double>("maxLeadChargedPFCandEta", 2.4);
0226   desc.add<double>("deltaRCleaning", 0.4);
0227   desc.add<bool>("useStrips", true);
0228   desc.add<double>("maxSeedChargedPFCandDz", 1000.0);
0229   desc.add<double>("minLeadChargedPFCandPt", 1.0);
0230   desc.add<double>("maxSeedChargedPFCandEta", 2.4);
0231   desc.add<bool>("applyPreselection", false);
0232   desc.add<double>("isolationConeSize", 0.4);
0233   desc.add<edm::InputTag>("srcL1Vertices", edm::InputTag("L1TkPrimaryVertex"));
0234   desc.add<double>("maxChargedIso", 1000.0);
0235   {
0236     edm::ParameterSetDescription psd0;
0237     {
0238       edm::ParameterSetDescription psd1;
0239       psd1.add<double>("minPt", 0.0);
0240       psd0.add<edm::ParameterSetDescription>("neutralHadron", psd1);
0241     }
0242     {
0243       edm::ParameterSetDescription psd1;
0244       psd1.add<double>("maxDz", 0.4);
0245       psd1.add<double>("minPt", 0.0);
0246       psd0.add<edm::ParameterSetDescription>("muon", psd1);
0247     }
0248     {
0249       edm::ParameterSetDescription psd1;
0250       psd1.add<double>("maxDz", 0.4);
0251       psd1.add<double>("minPt", 0.0);
0252       psd0.add<edm::ParameterSetDescription>("electron", psd1);
0253     }
0254     {
0255       edm::ParameterSetDescription psd1;
0256       psd1.add<double>("minPt", 0.0);
0257       psd0.add<edm::ParameterSetDescription>("photon", psd1);
0258     }
0259     {
0260       edm::ParameterSetDescription psd1;
0261       psd1.add<double>("maxDz", 0.4);
0262       psd1.add<double>("minPt", 0.0);
0263       psd0.add<edm::ParameterSetDescription>("chargedHadron", psd1);
0264     }
0265     desc.add<edm::ParameterSetDescription>("signalQualityCuts", psd0);
0266   }
0267   desc.add<bool>("useChargedPFCandSeeds", true);
0268   desc.add<double>("maxLeadChargedPFCandDz", 1000.0);
0269   desc.add<double>("maxSeedJetEta", 2.4);
0270   desc.add<std::string>("signalConeSize", "2.8/max(1., pt)");
0271   desc.add<edm::InputTag>("srcL1Jets",
0272                           edm::InputTag("Phase1L1TJetProducer", "UncalibratedPhase1L1TJetFromPfCandidates"));
0273   desc.addUntracked<bool>("debug", false);
0274   desc.add<double>("maxPFTauEta", 2.4);
0275   desc.add<double>("maxSignalConeSize", 0.1);
0276   descriptions.addWithDefaultLabel(desc);
0277 }
0278 
0279 #include "FWCore/Framework/interface/MakerMacros.h"
0280 DEFINE_FWK_MODULE(HPSPFTauProducer);