Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:55

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