Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //*****************************************************************************
0002 // File:      EgammaHcalPFClusterIsolationProducer.cc
0003 // ----------------------------------------------------------------------------
0004 // OrigAuth:  Matteo Sani
0005 // Institute: UCSD
0006 //*****************************************************************************
0007 
0008 #include "DataFormats/Candidate/interface/CandAssociation.h"
0009 #include "DataFormats/Common/interface/Handle.h"
0010 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0011 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0012 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
0013 #include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 #include "FWCore/Framework/interface/MakerMacros.h"
0017 #include "FWCore/Framework/interface/global/EDProducer.h"
0018 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0021 #include "FWCore/Utilities/interface/TypeID.h"
0022 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0023 #include "RecoEgamma/EgammaIsolationAlgos/interface/HcalPFClusterIsolation.h"
0024 
0025 #include <typeinfo>
0026 
0027 template <typename T1>
0028 class EgammaHcalPFClusterIsolationProducer : public edm::global::EDProducer<> {
0029 public:
0030   typedef std::vector<T1> T1Collection;
0031   typedef edm::Ref<T1Collection> T1Ref;
0032   explicit EgammaHcalPFClusterIsolationProducer(const edm::ParameterSet&);
0033   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0034 
0035   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0036 
0037 private:
0038   const edm::EDGetTokenT<T1Collection> emObjectProducer_;
0039   const edm::EDGetTokenT<reco::PFClusterCollection> pfClusterProducerHCAL_;
0040   const edm::EDGetTokenT<reco::PFClusterCollection> pfClusterProducerHFEM_;
0041   const edm::EDGetTokenT<reco::PFClusterCollection> pfClusterProducerHFHAD_;
0042 
0043   const bool useHF_;
0044   const double drMax_;
0045   const double drVetoBarrel_;
0046   const double drVetoEndcap_;
0047   const double etaStripBarrel_;
0048   const double etaStripEndcap_;
0049   const double energyBarrel_;
0050   const double energyEndcap_;
0051   const double useEt_;
0052 };
0053 
0054 template <typename T1>
0055 EgammaHcalPFClusterIsolationProducer<T1>::EgammaHcalPFClusterIsolationProducer(const edm::ParameterSet& config)
0056     :
0057 
0058       emObjectProducer_(consumes(config.getParameter<edm::InputTag>("candidateProducer"))),
0059       pfClusterProducerHCAL_(consumes(config.getParameter<edm::InputTag>("pfClusterProducerHCAL"))),
0060       pfClusterProducerHFEM_(consumes(config.getParameter<edm::InputTag>("pfClusterProducerHFEM"))),
0061       pfClusterProducerHFHAD_(consumes(config.getParameter<edm::InputTag>("pfClusterProducerHFHAD"))),
0062       useHF_(config.getParameter<bool>("useHF")),
0063       drMax_(config.getParameter<double>("drMax")),
0064       drVetoBarrel_(config.getParameter<double>("drVetoBarrel")),
0065       drVetoEndcap_(config.getParameter<double>("drVetoEndcap")),
0066       etaStripBarrel_(config.getParameter<double>("etaStripBarrel")),
0067       etaStripEndcap_(config.getParameter<double>("etaStripEndcap")),
0068       energyBarrel_(config.getParameter<double>("energyBarrel")),
0069       energyEndcap_(config.getParameter<double>("energyEndcap")),
0070       useEt_(config.getParameter<bool>("useEt")) {
0071   produces<edm::ValueMap<float>>();
0072 }
0073 
0074 template <typename T1>
0075 void EgammaHcalPFClusterIsolationProducer<T1>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0076   edm::ParameterSetDescription desc;
0077   desc.add<edm::InputTag>("candidateProducer", edm::InputTag("gedGsfElectrons"));
0078   desc.add<edm::InputTag>("pfClusterProducerHCAL", edm::InputTag("particleFlowClusterHCAL"));
0079   desc.ifValue(edm::ParameterDescription<bool>("useHF", false, true),
0080                true >> (edm::ParameterDescription<edm::InputTag>(
0081                             "pfClusterProducerHFEM", {"hltParticleFlowClusterHFEM"}, true) and
0082                         edm::ParameterDescription<edm::InputTag>(
0083                             "pfClusterProducerHFHAD", {"hltParticleFlowClusterHFHAD"}, true)) or
0084                    false >> (edm::ParameterDescription<edm::InputTag>("pfClusterProducerHFEM", {""}, true) and
0085                              edm::ParameterDescription<edm::InputTag>("pfClusterProducerHFHAD", {""}, true)));
0086   desc.add<double>("drMax", 0.3);
0087   desc.add<double>("drVetoBarrel", 0.0);
0088   desc.add<double>("drVetoEndcap", 0.0);
0089   desc.add<double>("etaStripBarrel", 0.0);
0090   desc.add<double>("etaStripEndcap", 0.0);
0091   desc.add<double>("energyBarrel", 0.0);
0092   desc.add<double>("energyEndcap", 0.0);
0093   desc.add<bool>("useEt", true);
0094   descriptions.add(defaultModuleLabel<EgammaHcalPFClusterIsolationProducer<T1>>(), desc);
0095 }
0096 
0097 template <typename T1>
0098 void EgammaHcalPFClusterIsolationProducer<T1>::produce(edm::StreamID,
0099                                                        edm::Event& iEvent,
0100                                                        const edm::EventSetup&) const {
0101   auto emObjectHandle = iEvent.getHandle(emObjectProducer_);
0102 
0103   auto isoMap = std::make_unique<edm::ValueMap<float>>();
0104   edm::ValueMap<float>::Filler filler(*isoMap);
0105   std::vector<float> retV(emObjectHandle->size(), 0);
0106 
0107   std::vector<edm::Handle<reco::PFClusterCollection>> clusterHandles{iEvent.getHandle(pfClusterProducerHCAL_)};
0108 
0109   if (useHF_) {
0110     clusterHandles.push_back(iEvent.getHandle(pfClusterProducerHFEM_));
0111     clusterHandles.push_back(iEvent.getHandle(pfClusterProducerHFHAD_));
0112   }
0113 
0114   HcalPFClusterIsolation<T1> isoAlgo(
0115       drMax_, drVetoBarrel_, drVetoEndcap_, etaStripBarrel_, etaStripEndcap_, energyBarrel_, energyEndcap_, useEt_);
0116 
0117   for (unsigned int iReco = 0; iReco < emObjectHandle->size(); iReco++) {
0118     T1Ref candRef(emObjectHandle, iReco);
0119     retV[iReco] = isoAlgo.getSum(candRef, clusterHandles);
0120   }
0121 
0122   filler.insert(emObjectHandle, retV.begin(), retV.end());
0123   filler.fill();
0124 
0125   iEvent.put(std::move(isoMap));
0126 }
0127 
0128 typedef EgammaHcalPFClusterIsolationProducer<reco::GsfElectron> ElectronHcalPFClusterIsolationProducer;
0129 typedef EgammaHcalPFClusterIsolationProducer<reco::Photon> PhotonHcalPFClusterIsolationProducer;
0130 
0131 DEFINE_FWK_MODULE(ElectronHcalPFClusterIsolationProducer);
0132 DEFINE_FWK_MODULE(PhotonHcalPFClusterIsolationProducer);