Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //*****************************************************************************
0002 // File:      EgammaEcalPFClusterIsolationProducer.cc
0003 // ----------------------------------------------------------------------------
0004 // OrigAuth:  Matteo Sani
0005 // Institute: UCSD
0006 //*****************************************************************************
0007 
0008 #include "DataFormats/Candidate/interface/CandAssociation.h"
0009 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0010 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0011 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
0012 #include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "FWCore/Framework/interface/global/EDProducer.h"
0017 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0020 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0021 #include "RecoEgamma/EgammaIsolationAlgos/interface/EcalPFClusterIsolation.h"
0022 
0023 template <typename T1>
0024 class EgammaEcalPFClusterIsolationProducer : public edm::global::EDProducer<> {
0025 public:
0026   typedef std::vector<T1> T1Collection;
0027   typedef edm::Ref<T1Collection> T1Ref;
0028   explicit EgammaEcalPFClusterIsolationProducer(const edm::ParameterSet&);
0029   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0030 
0031   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0032 
0033 private:
0034   const edm::EDGetTokenT<T1Collection> emObjectProducer_;
0035   const edm::EDGetTokenT<reco::PFClusterCollection> pfClusterProducer_;
0036 
0037   const double drMax_;
0038   const double drVetoBarrel_;
0039   const double drVetoEndcap_;
0040   const double etaStripBarrel_;
0041   const double etaStripEndcap_;
0042   const double energyBarrel_;
0043   const double energyEndcap_;
0044 };
0045 
0046 template <typename T1>
0047 EgammaEcalPFClusterIsolationProducer<T1>::EgammaEcalPFClusterIsolationProducer(const edm::ParameterSet& config)
0048     :
0049 
0050       emObjectProducer_(consumes<T1Collection>(config.getParameter<edm::InputTag>("candidateProducer"))),
0051       pfClusterProducer_(consumes<reco::PFClusterCollection>(config.getParameter<edm::InputTag>("pfClusterProducer"))),
0052       drMax_(config.getParameter<double>("drMax")),
0053       drVetoBarrel_(config.getParameter<double>("drVetoBarrel")),
0054       drVetoEndcap_(config.getParameter<double>("drVetoEndcap")),
0055       etaStripBarrel_(config.getParameter<double>("etaStripBarrel")),
0056       etaStripEndcap_(config.getParameter<double>("etaStripEndcap")),
0057       energyBarrel_(config.getParameter<double>("energyBarrel")),
0058       energyEndcap_(config.getParameter<double>("energyEndcap")) {
0059   produces<edm::ValueMap<float>>();
0060 }
0061 
0062 template <typename T1>
0063 void EgammaEcalPFClusterIsolationProducer<T1>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0064   edm::ParameterSetDescription desc;
0065   desc.add<edm::InputTag>("candidateProducer", edm::InputTag("gedGsfElectrons"));
0066   desc.add<edm::InputTag>("pfClusterProducer", edm::InputTag("particleFlowClusterECAL"));
0067   desc.add<double>("drMax", 0.3);
0068   desc.add<double>("drVetoBarrel", 0.0);
0069   desc.add<double>("drVetoEndcap", 0.0);
0070   desc.add<double>("etaStripBarrel", 0.0);
0071   desc.add<double>("etaStripEndcap", 0.0);
0072   desc.add<double>("energyBarrel", 0.0);
0073   desc.add<double>("energyEndcap", 0.0);
0074   descriptions.add(defaultModuleLabel<EgammaEcalPFClusterIsolationProducer<T1>>(), desc);
0075 }
0076 
0077 template <typename T1>
0078 void EgammaEcalPFClusterIsolationProducer<T1>::produce(edm::StreamID,
0079                                                        edm::Event& iEvent,
0080                                                        const edm::EventSetup&) const {
0081   auto emObjectHandle = iEvent.getHandle(emObjectProducer_);
0082 
0083   auto isoMap = std::make_unique<edm::ValueMap<float>>();
0084   edm::ValueMap<float>::Filler filler(*isoMap);
0085   std::vector<float> retV(emObjectHandle->size(), 0);
0086 
0087   auto clusterHandle = iEvent.getHandle(pfClusterProducer_);
0088 
0089   EcalPFClusterIsolation<T1> isoAlgo(
0090       drMax_, drVetoBarrel_, drVetoEndcap_, etaStripBarrel_, etaStripEndcap_, energyBarrel_, energyEndcap_);
0091 
0092   for (unsigned int iReco = 0; iReco < emObjectHandle->size(); iReco++) {
0093     T1Ref candRef(emObjectHandle, iReco);
0094     retV[iReco] = isoAlgo.getSum(candRef, clusterHandle);
0095   }
0096 
0097   filler.insert(emObjectHandle, retV.begin(), retV.end());
0098   filler.fill();
0099 
0100   iEvent.put(std::move(isoMap));
0101 }
0102 
0103 typedef EgammaEcalPFClusterIsolationProducer<reco::GsfElectron> ElectronEcalPFClusterIsolationProducer;
0104 typedef EgammaEcalPFClusterIsolationProducer<reco::Photon> PhotonEcalPFClusterIsolationProducer;
0105 
0106 DEFINE_FWK_MODULE(ElectronEcalPFClusterIsolationProducer);
0107 DEFINE_FWK_MODULE(PhotonEcalPFClusterIsolationProducer);