Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //*****************************************************************************
0002 // File:      EgammaTowerIsolationProducer.cc
0003 // ----------------------------------------------------------------------------
0004 // OrigAuth:  Matthias Mozer
0005 // Institute: IIHE-VUB
0006 //=============================================================================
0007 //*****************************************************************************
0008 
0009 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
0010 #include "DataFormats/Candidate/interface/CandAssociation.h"
0011 #include "DataFormats/Candidate/interface/Candidate.h"
0012 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/stream/EDProducer.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
0017 
0018 class EgammaTowerIsolationProducer : public edm::stream::EDProducer<> {
0019 public:
0020   explicit EgammaTowerIsolationProducer(const edm::ParameterSet&);
0021 
0022   void produce(edm::Event&, const edm::EventSetup&) override;
0023 
0024 private:
0025   // ----------member data ---------------------------
0026 
0027   const edm::EDGetTokenT<edm::View<reco::Candidate>> emObjectProducer_;
0028   const edm::EDGetTokenT<CaloTowerCollection> towerProducer_;
0029 
0030   const edm::EDPutTokenT<edm::ValueMap<double>> putToken_;
0031 
0032   const double egHcalIsoPtMin_;
0033   const double egHcalIsoConeSizeOut_;
0034   const double egHcalIsoConeSizeIn_;
0035   const signed int egHcalDepth_;
0036 };
0037 
0038 #include "FWCore/Framework/interface/MakerMacros.h"
0039 DEFINE_FWK_MODULE(EgammaTowerIsolationProducer);
0040 
0041 EgammaTowerIsolationProducer::EgammaTowerIsolationProducer(const edm::ParameterSet& config)
0042     : emObjectProducer_{consumes(config.getParameter<edm::InputTag>("emObjectProducer"))},
0043       towerProducer_{consumes(config.getParameter<edm::InputTag>("towerProducer"))},
0044       putToken_{produces<edm::ValueMap<double>>()},
0045       egHcalIsoPtMin_{config.getParameter<double>("etMin")},
0046       egHcalIsoConeSizeOut_{config.getParameter<double>("extRadius")},
0047       egHcalIsoConeSizeIn_{config.getParameter<double>("intRadius")},
0048       egHcalDepth_{config.getParameter<int>("Depth")} {}
0049 
0050 void EgammaTowerIsolationProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0051   // Get the  filtered objects
0052   auto emObjectHandle = iEvent.getHandle(emObjectProducer_);
0053 
0054   // Get the barrel hcal hits
0055   auto const& towers = iEvent.get(towerProducer_);
0056 
0057   edm::ValueMap<double> isoMap;
0058   edm::ValueMap<double>::Filler filler(isoMap);
0059   std::vector<double> retV(emObjectHandle->size(), 0);
0060 
0061   EgammaTowerIsolation myHadIsolation(
0062       egHcalIsoConeSizeOut_, egHcalIsoConeSizeIn_, egHcalIsoPtMin_, egHcalDepth_, &towers);
0063 
0064   for (size_t i = 0; i < emObjectHandle->size(); ++i) {
0065     double isoValue = myHadIsolation.getTowerEtSum(&(emObjectHandle->at(i)));
0066     retV[i] = isoValue;
0067   }
0068 
0069   filler.insert(emObjectHandle, retV.begin(), retV.end());
0070   filler.fill();
0071   iEvent.emplace(putToken_, std::move(isoMap));
0072 }