Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:44

0001 // -*- C++ -*-
0002 //
0003 // Package:    PhysicsTools/NanoAOD
0004 // Class:      EGMSeedGainProducer
0005 //
0006 /**\class EGMSeedGainProducer EGMSeedGainProducer.cc PhysicsTools/NanoAOD/plugins/EGMSeedGainProducer.cc
0007  Description: [one line class summary]
0008  Implementation:
0009      [Notes on implementation]
0010 */
0011 
0012 // system include files
0013 #include <memory>
0014 
0015 // user include files
0016 #include "FWCore/Framework/interface/Frameworkfwd.h"
0017 #include "FWCore/Framework/interface/global/EDProducer.h"
0018 
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021 
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/Utilities/interface/StreamID.h"
0024 
0025 #include "DataFormats/PatCandidates/interface/Electron.h"
0026 #include "DataFormats/PatCandidates/interface/Photon.h"
0027 
0028 #include "DataFormats/Common/interface/View.h"
0029 
0030 //
0031 // class declaration
0032 //
0033 
0034 template <typename T>
0035 class EGMSeedGainProducer : public edm::global::EDProducer<> {
0036 public:
0037   explicit EGMSeedGainProducer(const edm::ParameterSet& iConfig)
0038       : src_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("src"))),
0039         recHitsEB_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsEB"))),
0040         recHitsEE_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsEE"))) {
0041     produces<edm::ValueMap<int>>();
0042   }
0043   ~EGMSeedGainProducer() override{};
0044 
0045   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0046 
0047 private:
0048   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0049 
0050   // ----------member data ---------------------------
0051 
0052   edm::EDGetTokenT<edm::View<T>> src_;
0053   edm::EDGetTokenT<EcalRecHitCollection> recHitsEB_;
0054   edm::EDGetTokenT<EcalRecHitCollection> recHitsEE_;
0055 };
0056 
0057 //
0058 // constants, enums and typedefs
0059 //
0060 
0061 //
0062 // static data member definitions
0063 //
0064 
0065 //
0066 // member functions
0067 //
0068 
0069 // ------------ method called to produce the data  ------------
0070 template <typename T>
0071 void EGMSeedGainProducer<T>::produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0072   edm::Handle<edm::View<T>> src;
0073   iEvent.getByToken(src_, src);
0074   edm::Handle<EcalRecHitCollection> recHitsEB;
0075   iEvent.getByToken(recHitsEB_, recHitsEB);
0076   edm::Handle<EcalRecHitCollection> recHitsEE;
0077   iEvent.getByToken(recHitsEE_, recHitsEE);
0078 
0079   unsigned nSrc = src->size();
0080   std::vector<int> gainSeed(nSrc, 12);
0081 
0082   // determine gain of seed crystal as in RecoEgamma/EgammaTools/src/PhotonEnergyCalibrator.cc
0083   for (unsigned i = 0; i < nSrc; i++) {
0084     auto obj = src->ptrAt(i);
0085     auto detid = obj->superCluster()->seed()->seed();
0086     auto coll = obj->isEB() ? recHitsEB.product() : recHitsEE.product();
0087     auto seed = coll->find(detid);
0088     if (seed != coll->end()) {
0089       if (seed->checkFlag(EcalRecHit::kHasSwitchToGain6))
0090         gainSeed[i] = 6;
0091       if (seed->checkFlag(EcalRecHit::kHasSwitchToGain1))
0092         gainSeed[i] = 1;
0093     }
0094   }
0095 
0096   std::unique_ptr<edm::ValueMap<int>> gainSeedV(new edm::ValueMap<int>());
0097   edm::ValueMap<int>::Filler fillerCorr(*gainSeedV);
0098   fillerCorr.insert(src, gainSeed.begin(), gainSeed.end());
0099   fillerCorr.fill();
0100   iEvent.put(std::move(gainSeedV));
0101 }
0102 
0103 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0104 template <typename T>
0105 void EGMSeedGainProducer<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0106   edm::ParameterSetDescription desc;
0107   desc.add<edm::InputTag>("src")->setComment("input physics object collection");
0108   desc.add<edm::InputTag>("recHitsEB", edm::InputTag("reducedEgamma", "reducedEBRecHits"))
0109       ->setComment("EB rechit collection");
0110   desc.add<edm::InputTag>("recHitsEE", edm::InputTag("reducedEgamma", "reducedEERecHits"))
0111       ->setComment("EE rechit collection");
0112   descriptions.addDefault(desc);
0113 }
0114 
0115 typedef EGMSeedGainProducer<pat::Electron> ElectronSeedGainProducer;
0116 typedef EGMSeedGainProducer<pat::Photon> PhotonSeedGainProducer;
0117 
0118 //define this as a plug-in
0119 DEFINE_FWK_MODULE(ElectronSeedGainProducer);
0120 DEFINE_FWK_MODULE(PhotonSeedGainProducer);