Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:29

0001 /*
0002  * ChargedHadronPFTrackIsolationProducer
0003  *
0004  * Author: Andreas Hinzmann
0005  *
0006  * Associates PF isolation flag to charged hadron candidates
0007  *
0008  */
0009 
0010 #include "FWCore/Framework/interface/global/EDProducer.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0016 
0017 #include "FWCore/Utilities/interface/Exception.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 
0020 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0021 #include "DataFormats/Common/interface/ValueMap.h"
0022 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
0023 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
0024 
0025 class ChargedHadronPFTrackIsolationProducer : public edm::global::EDProducer<> {
0026 public:
0027   explicit ChargedHadronPFTrackIsolationProducer(const edm::ParameterSet& cfg);
0028   ~ChargedHadronPFTrackIsolationProducer() override {}
0029   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0030   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0031 
0032 private:
0033   // input collection
0034   edm::InputTag srccandidates_;
0035   edm::EDGetTokenT<edm::View<reco::PFCandidate> > candidatesToken_;
0036   double minTrackPt_;
0037   double minRawCaloEnergy_;
0038 };
0039 
0040 ChargedHadronPFTrackIsolationProducer::ChargedHadronPFTrackIsolationProducer(const edm::ParameterSet& cfg) {
0041   srccandidates_ = cfg.getParameter<edm::InputTag>("src");
0042   candidatesToken_ = consumes<edm::View<reco::PFCandidate> >(srccandidates_);
0043   minTrackPt_ = cfg.getParameter<double>("minTrackPt");
0044   minRawCaloEnergy_ = cfg.getParameter<double>("minRawCaloEnergy");
0045 
0046   produces<edm::ValueMap<bool> >();
0047 }
0048 
0049 void ChargedHadronPFTrackIsolationProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const {
0050   // get a view of our candidates via the base candidates
0051   auto candidates = evt.getHandle(candidatesToken_);
0052 
0053   std::vector<bool> values;
0054 
0055   for (auto const& c : *candidates) {
0056     // Check that there is only one track in the block.
0057     unsigned int nTracks = 0;
0058     if ((c.particleId() == 1) && (c.pt() > minTrackPt_) &&
0059         ((c.rawEcalEnergy() + c.rawHcalEnergy()) > minRawCaloEnergy_)) {
0060       const reco::PFCandidate::ElementsInBlocks& theElements = c.elementsInBlocks();
0061       if (theElements.empty())
0062         nTracks = 1;  // the PFBlockElements is empty for pfTICL charged candidates
0063       // because they don't go through PFBlocks machanism. We consider each charged candidate to be well isolated for now.
0064       else {
0065         const reco::PFBlockRef blockRef = theElements[0].first;
0066         const edm::OwnVector<reco::PFBlockElement>& elements = blockRef->elements();
0067         // Find the tracks in the block
0068         for (auto const& ele : elements) {
0069           reco::PFBlockElement::Type type = ele.type();
0070           if (type == reco::PFBlockElement::TRACK)
0071             nTracks++;
0072         }
0073       }
0074     }
0075     values.push_back((nTracks == 1));
0076   }
0077 
0078   std::unique_ptr<edm::ValueMap<bool> > out(new edm::ValueMap<bool>());
0079   edm::ValueMap<bool>::Filler filler(*out);
0080   filler.insert(candidates, values.begin(), values.end());
0081   filler.fill();
0082   evt.put(std::move(out));
0083 }
0084 
0085 void ChargedHadronPFTrackIsolationProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0086   edm::ParameterSetDescription desc;
0087   desc.add<edm::InputTag>("src", edm::InputTag("particleFlow"));
0088   desc.add<double>("minTrackPt", 1);
0089   desc.add<double>("minRawCaloEnergy", 0.5);
0090   descriptions.add("chargedHadronPFTrackIsolation", desc);
0091 }
0092 
0093 #include "FWCore/Framework/interface/MakerMacros.h"
0094 
0095 DEFINE_FWK_MODULE(ChargedHadronPFTrackIsolationProducer);