CMS 3D CMS Logo

EGMSeedGainProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: EGMSeedGainProducer
5 //
12 // system include files
13 #include <memory>
14 
15 // user include files
18 
21 
24 
27 
29 
30 //
31 // class declaration
32 //
33 
34 template <typename T>
36 public:
37  explicit EGMSeedGainProducer(const edm::ParameterSet& iConfig)
38  : src_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("src"))),
39  recHitsEB_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsEB"))),
40  recHitsEE_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsEE"))) {
41  produces<edm::ValueMap<int>>();
42  }
43  ~EGMSeedGainProducer() override{};
44 
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
46 
47 private:
48  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
49 
50  // ----------member data ---------------------------
51 
55 };
56 
57 //
58 // constants, enums and typedefs
59 //
60 
61 //
62 // static data member definitions
63 //
64 
65 //
66 // member functions
67 //
68 
69 // ------------ method called to produce the data ------------
70 template <typename T>
72  auto src = iEvent.getHandle(src_);
73  const auto& recHitsEBProd = iEvent.get(recHitsEB_);
74  const auto& recHitsEEProd = iEvent.get(recHitsEE_);
75 
76  unsigned nSrc = src->size();
77  std::vector<int> gainSeed(nSrc, 12);
78 
79  // determine gain of seed crystal as in RecoEgamma/EgammaTools/src/PhotonEnergyCalibrator.cc
80  for (unsigned i = 0; i < nSrc; i++) {
81  auto obj = src->ptrAt(i);
82  auto detid = obj->superCluster()->seed()->seed();
83  const auto& coll = obj->isEB() ? recHitsEBProd : recHitsEEProd;
84  auto seed = coll.find(detid);
85  if (seed != coll.end()) {
86  if (seed->checkFlag(EcalRecHit::kHasSwitchToGain6))
87  gainSeed[i] = 6;
88  if (seed->checkFlag(EcalRecHit::kHasSwitchToGain1))
89  gainSeed[i] = 1;
90  }
91  }
92 
93  std::unique_ptr<edm::ValueMap<int>> gainSeedV(new edm::ValueMap<int>());
94  edm::ValueMap<int>::Filler fillerCorr(*gainSeedV);
95  fillerCorr.insert(src, gainSeed.begin(), gainSeed.end());
96  fillerCorr.fill();
97  iEvent.put(std::move(gainSeedV));
98 }
99 
100 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
101 template <typename T>
104  desc.add<edm::InputTag>("src")->setComment("input physics object collection");
105  desc.add<edm::InputTag>("recHitsEB", edm::InputTag("reducedEgamma", "reducedEBRecHits"))
106  ->setComment("EB rechit collection");
107  desc.add<edm::InputTag>("recHitsEE", edm::InputTag("reducedEgamma", "reducedEERecHits"))
108  ->setComment("EE rechit collection");
109  descriptions.addDefault(desc);
110 }
111 
114 
115 //define this as a plug-in
edm::EDGetTokenT< EcalRecHitCollection > recHitsEE_
edm::EDGetTokenT< edm::View< T > > src_
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< EcalRecHitCollection > recHitsEB_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
EGMSeedGainProducer< pat::Electron > ElectronSeedGainProducer
HLT enums.
long double T
EGMSeedGainProducer(const edm::ParameterSet &iConfig)
def move(src, dest)
Definition: eostools.py:511
EGMSeedGainProducer< pat::Photon > PhotonSeedGainProducer