Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:12

0001 //*****************************************************************************
0002 // File:      EgammaPhotonTkNumIsolationProducer.cc
0003 // ----------------------------------------------------------------------------
0004 // OrigAuth:  Matthias Mozer
0005 // Institute: IIHE-VUB
0006 //=============================================================================
0007 //*****************************************************************************
0008 
0009 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0010 #include "DataFormats/Candidate/interface/CandAssociation.h"
0011 #include "DataFormats/Candidate/interface/Candidate.h"
0012 #include "DataFormats/Common/interface/Handle.h"
0013 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/global/EDProducer.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "RecoEgamma/EgammaIsolationAlgos/interface/PhotonTkIsolation.h"
0018 
0019 class EgammaPhotonTkNumIsolationProducer : public edm::global::EDProducer<> {
0020 public:
0021   explicit EgammaPhotonTkNumIsolationProducer(const edm::ParameterSet&);
0022 
0023   void produce(edm::StreamID sid, edm::Event&, const edm::EventSetup&) const override;
0024 
0025 private:
0026   const edm::EDGetTokenT<edm::View<reco::Candidate>> photonProducer_;
0027   const edm::EDGetTokenT<reco::TrackCollection> trackProducer_;
0028   const edm::EDGetTokenT<reco::BeamSpot> beamspotProducer_;
0029 
0030   const double ptMin_;
0031   const double intRadiusBarrel_;
0032   const double intRadiusEndcap_;
0033   const double stripBarrel_;
0034   const double stripEndcap_;
0035   const double extRadius_;
0036   const double maxVtxDist_;
0037   const double drb_;
0038 };
0039 
0040 #include "FWCore/Framework/interface/MakerMacros.h"
0041 DEFINE_FWK_MODULE(EgammaPhotonTkNumIsolationProducer);
0042 
0043 EgammaPhotonTkNumIsolationProducer::EgammaPhotonTkNumIsolationProducer(const edm::ParameterSet& config)
0044     :
0045 
0046       photonProducer_{consumes(config.getParameter<edm::InputTag>("photonProducer"))},
0047 
0048       trackProducer_{consumes(config.getParameter<edm::InputTag>("trackProducer"))},
0049       beamspotProducer_{consumes(config.getParameter<edm::InputTag>("BeamspotProducer"))},
0050 
0051       ptMin_(config.getParameter<double>("ptMin")),
0052       intRadiusBarrel_(config.getParameter<double>("intRadiusBarrel")),
0053       intRadiusEndcap_(config.getParameter<double>("intRadiusEndcap")),
0054       stripBarrel_(config.getParameter<double>("stripBarrel")),
0055       stripEndcap_(config.getParameter<double>("stripEndcap")),
0056       extRadius_(config.getParameter<double>("extRadius")),
0057       maxVtxDist_(config.getParameter<double>("maxVtxDist")),
0058       drb_(config.getParameter<double>("maxVtxDistXY"))
0059 
0060 {
0061   //register your products
0062   produces<edm::ValueMap<int>>();
0063 }
0064 
0065 // ------------ method called to produce the data  ------------
0066 void EgammaPhotonTkNumIsolationProducer::produce(edm::StreamID sid,
0067                                                  edm::Event& iEvent,
0068                                                  const edm::EventSetup& iSetup) const {
0069   // Get the  filtered objects
0070   auto photonHandle = iEvent.getHandle(photonProducer_);
0071 
0072   //prepare product
0073   auto isoMap = std::make_unique<edm::ValueMap<int>>();
0074   edm::ValueMap<int>::Filler filler(*isoMap);
0075   std::vector<int> retV(photonHandle->size(), 0);
0076 
0077   PhotonTkIsolation myTkIsolation(extRadius_,
0078                                   intRadiusBarrel_,
0079                                   intRadiusEndcap_,
0080                                   stripBarrel_,
0081                                   stripEndcap_,
0082                                   ptMin_,
0083                                   maxVtxDist_,
0084                                   drb_,
0085                                   &iEvent.get(trackProducer_),
0086                                   iEvent.get(beamspotProducer_).position());
0087 
0088   for (unsigned int i = 0; i < photonHandle->size(); ++i) {
0089     int isoValue = myTkIsolation.getIso(&(photonHandle->at(i))).first;
0090     retV[i] = isoValue;
0091   }
0092 
0093   //fill and insert valuemap
0094   filler.insert(photonHandle, retV.begin(), retV.end());
0095   filler.fill();
0096   iEvent.put(std::move(isoMap));
0097 }