Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    EgammaIsoHcalDetIdCollectionProducer
0004 // Class:      EgammaIsoHcalDetIdCollectionProducer
0005 //
0006 /**\class EgammaIsoHcalDetIdCollectionProducer 
0007 Original author: Sam Harper (RAL)
0008  
0009 Make a collection of detids to be kept tipically in a AOD rechit collection
0010 Modified from the ECAL version "InterestingDetIdCollectionProducer" to be HCAL
0011 
0012 */
0013 
0014 #include "DataFormats/DetId/interface/DetIdCollection.h"
0015 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0016 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0017 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0018 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
0019 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0020 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
0021 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0022 #include "FWCore/Framework/interface/ESHandle.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Framework/interface/EventSetup.h"
0025 #include "FWCore/Framework/interface/stream/EDProducer.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0028 #include "RecoEgamma/EgammaIsolationAlgos/interface/EGHcalRecHitSelector.h"
0029 
0030 class EgammaIsoHcalDetIdCollectionProducer : public edm::stream::EDProducer<> {
0031 public:
0032   explicit EgammaIsoHcalDetIdCollectionProducer(const edm::ParameterSet&);
0033   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0034 
0035   void beginRun(edm::Run const&, const edm::EventSetup&) final;
0036   void produce(edm::Event&, const edm::EventSetup&) override;
0037 
0038 private:
0039   // ----------member data ---------------------------
0040   const edm::EDGetTokenT<HBHERecHitCollection> recHitsToken_;
0041   const edm::EDGetTokenT<reco::SuperClusterCollection> superClustersToken_;
0042   const edm::EDGetTokenT<reco::GsfElectronCollection> elesToken_;
0043   const edm::EDGetTokenT<reco::PhotonCollection> phosToken_;
0044 
0045   std::string interestingDetIdCollection_;
0046 
0047   float minSCEt_;
0048   float minEleEt_;
0049   float minPhoEt_;
0050 
0051   EGHcalRecHitSelector hcalHitSelector_;
0052 };
0053 
0054 #include "FWCore/Framework/interface/MakerMacros.h"
0055 DEFINE_FWK_MODULE(EgammaIsoHcalDetIdCollectionProducer);
0056 
0057 EgammaIsoHcalDetIdCollectionProducer::EgammaIsoHcalDetIdCollectionProducer(const edm::ParameterSet& iConfig)
0058     : recHitsToken_{consumes(iConfig.getParameter<edm::InputTag>("recHitsLabel"))},
0059       superClustersToken_{consumes(iConfig.getParameter<edm::InputTag>("superClustersLabel"))},
0060       elesToken_{consumes(iConfig.getParameter<edm::InputTag>("elesLabel"))},
0061       phosToken_{consumes(iConfig.getParameter<edm::InputTag>("phosLabel"))},
0062       hcalHitSelector_(iConfig.getParameter<edm::ParameterSet>("hitSelection"), consumesCollector()) {
0063   minSCEt_ = iConfig.getParameter<double>("minSCEt");
0064   minEleEt_ = iConfig.getParameter<double>("minEleEt");
0065   minPhoEt_ = iConfig.getParameter<double>("minPhoEt");
0066 
0067   interestingDetIdCollection_ = iConfig.getParameter<std::string>("interestingDetIdCollection");
0068 
0069   //register your products
0070   produces<DetIdCollection>(interestingDetIdCollection_);
0071 }
0072 
0073 void EgammaIsoHcalDetIdCollectionProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0074   edm::ParameterSetDescription desc;
0075   desc.add<edm::InputTag>("recHitsLabel", edm::InputTag("hbhereco"));
0076   desc.add<edm::InputTag>("elesLabel", edm::InputTag("gedGsfElectrons"));
0077   desc.add<edm::InputTag>("phosLabel", edm::InputTag("gedPhotons"));
0078   desc.add<edm::InputTag>("superClustersLabel", edm::InputTag("particleFlowEGamma"));
0079   desc.add<double>("minSCEt", 20);
0080   desc.add<double>("minEleEt", 20);
0081   desc.add<double>("minPhoEt", 20);
0082   desc.add<std::string>("interestingDetIdCollection", "");
0083   desc.add<edm::ParameterSetDescription>("hitSelection", EGHcalRecHitSelector::makePSetDescription());
0084   descriptions.add(("interestingGedEgammaIsoHCALDetId"), desc);
0085 }
0086 
0087 void EgammaIsoHcalDetIdCollectionProducer::beginRun(edm::Run const& run, const edm::EventSetup& iSetup) {
0088   hcalHitSelector_.setup(iSetup);
0089 }
0090 
0091 // ------------ method called to produce the data  ------------
0092 void EgammaIsoHcalDetIdCollectionProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0093   auto superClusters = iEvent.getHandle(superClustersToken_);
0094   auto eles = iEvent.getHandle(elesToken_);
0095   auto phos = iEvent.getHandle(phosToken_);
0096   auto recHits = iEvent.getHandle(recHitsToken_);
0097 
0098   std::vector<DetId> indexToStore;
0099   indexToStore.reserve(100);
0100 
0101   if (eles.isValid() && recHits.isValid()) {
0102     for (auto& ele : *eles) {
0103       float scEt = ele.superCluster()->energy() * std::sin(ele.superCluster()->position().theta());
0104       if (scEt > minEleEt_ || ele.et() > minEleEt_) {
0105         hcalHitSelector_.addDetIds(*ele.superCluster(), *recHits, indexToStore);
0106       }
0107     }
0108   }
0109   if (phos.isValid() && recHits.isValid()) {
0110     for (auto& pho : *phos) {
0111       float scEt = pho.superCluster()->energy() * std::sin(pho.superCluster()->position().theta());
0112       if (scEt > minPhoEt_ || pho.et() > minPhoEt_) {
0113         hcalHitSelector_.addDetIds(*pho.superCluster(), *recHits, indexToStore);
0114       }
0115     }
0116   }
0117   if (superClusters.isValid() && recHits.isValid()) {
0118     for (auto& sc : *superClusters) {
0119       float scEt = sc.energy() * std::sin(sc.position().theta());
0120       if (scEt > minSCEt_) {
0121         hcalHitSelector_.addDetIds(sc, *recHits, indexToStore);
0122       }
0123     }
0124   }
0125 
0126   //unify the vector
0127   std::sort(indexToStore.begin(), indexToStore.end());
0128   std::unique(indexToStore.begin(), indexToStore.end());
0129 
0130   auto detIdCollection = std::make_unique<DetIdCollection>(indexToStore);
0131 
0132   iEvent.put(std::move(detIdCollection), interestingDetIdCollection_);
0133 }