Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-10 22:24:50

0001 #include "FWCore/Framework/interface/global/EDProducer.h"
0002 #include "FWCore/Utilities/interface/InputTag.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "DataFormats/Common/interface/ValueMap.h"
0006 #include "DataFormats/Candidate/interface/Candidate.h"
0007 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0008 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
0009 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
0010 
0011 class IsolationProducerForTracks : public edm::global::EDProducer<> {
0012 public:
0013   IsolationProducerForTracks(const edm::ParameterSet&);
0014 
0015 private:
0016   void produce(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const override;
0017 
0018   const edm::EDGetTokenT<reco::CandidateView> tracksToken_;
0019   const edm::EDGetTokenT<reco::CandidateView> highPtTracksToken_;
0020   const edm::EDGetTokenT<reco::IsoDepositMap> isoDepsToken_;
0021   const double trackPtMin_;
0022   const double coneSize_;
0023 };
0024 
0025 #include "DataFormats/Common/interface/Handle.h"
0026 #include "DataFormats/Common/interface/Association.h"
0027 #include "DataFormats/Common/interface/Ref.h"
0028 #include "DataFormats/Candidate/interface/OverlapChecker.h"
0029 #include <iostream>
0030 #include <iterator>
0031 #include <vector>
0032 
0033 using namespace edm;
0034 using namespace reco;
0035 
0036 typedef edm::ValueMap<float> TkIsoMap;
0037 
0038 IsolationProducerForTracks::IsolationProducerForTracks(const ParameterSet& pset)
0039     : tracksToken_(consumes<CandidateView>(pset.getParameter<InputTag>("tracks"))),
0040       highPtTracksToken_(consumes<CandidateView>(pset.getParameter<InputTag>("highPtTracks"))),
0041       isoDepsToken_(consumes<IsoDepositMap>(pset.getParameter<InputTag>("isoDeps"))),
0042       trackPtMin_(pset.getParameter<double>("trackPtMin")),
0043       coneSize_(pset.getParameter<double>("coneSize")) {
0044   produces<TkIsoMap>();
0045 }
0046 
0047 void IsolationProducerForTracks::produce(edm::StreamID, Event& event, const EventSetup& setup) const {
0048   auto caloIsolations = std::make_unique<TkIsoMap>();
0049   TkIsoMap::Filler filler(*caloIsolations);
0050   {
0051     Handle<CandidateView> tracks;
0052     event.getByToken(tracksToken_, tracks);
0053 
0054     Handle<CandidateView> highPtTracks;
0055     event.getByToken(highPtTracksToken_, highPtTracks);
0056 
0057     Handle<IsoDepositMap> isoDeps;
0058     event.getByToken(isoDepsToken_, isoDeps);
0059 
0060     int nTracks = tracks->size();
0061     int nHighPtTracks = highPtTracks->size();
0062     std::vector<double> iso(nTracks);
0063 
0064     OverlapChecker overlap;
0065 
0066     for (int i = 0; i < nTracks; ++i) {
0067       const Candidate& tkCand = (*tracks)[i];
0068       double caloIso = -1.0;
0069       if (tkCand.pt() > trackPtMin_) {
0070         for (int j = 0; j < nHighPtTracks; ++j) {
0071           const Candidate& highPtTkCand = (*highPtTracks)[j];
0072           if (overlap(tkCand, highPtTkCand)) {
0073             CandidateBaseRef tkRef = highPtTracks->refAt(j);
0074             const IsoDeposit& isoDep = (*isoDeps)[tkRef];
0075             caloIso = isoDep.depositWithin(coneSize_);
0076             break;
0077           }
0078         }
0079       }
0080       iso[i] = caloIso;
0081     }
0082     filler.insert(tracks, iso.begin(), iso.end());
0083   }
0084 
0085   // really fill the association map
0086   filler.fill();
0087   event.put(std::move(caloIsolations));
0088 }
0089 
0090 #include "FWCore/Framework/interface/MakerMacros.h"
0091 
0092 DEFINE_FWK_MODULE(IsolationProducerForTracks);