CMS 3D CMS Logo

EGMSeedGainProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: EGMSeedGainProducer
5 //
13 // system include files
14 #include <memory>
15 
16 // user include files
19 
22 
25 
28 
30 
31 
32 //
33 // class declaration
34 //
35 
36 template <typename T>
38 public:
39  explicit EGMSeedGainProducer(const edm::ParameterSet &iConfig):
40  src_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("src"))),
41  recHitsEB_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsEB"))),
42  recHitsEE_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsEE")))
43  {
44  produces<edm::ValueMap<int>>();
45  }
46  ~EGMSeedGainProducer() override {};
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50 private:
51  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
52 
53  // ----------member data ---------------------------
54 
58 };
59 
60 //
61 // constants, enums and typedefs
62 //
63 
64 
65 //
66 // static data member definitions
67 //
68 
69 //
70 // member functions
71 //
72 
73 // ------------ method called to produce the data ------------
74 template <typename T>
75 void
77 {
79  iEvent.getByToken(src_, src);
81  iEvent.getByToken(recHitsEB_, recHitsEB);
83  iEvent.getByToken(recHitsEB_, recHitsEE);
84 
85  unsigned nSrc = src->size();
86  std::vector<int> gainSeed(nSrc,12);
87 
88  // determine gain of seed crystal as in RecoEgamma/EgammaTools/src/PhotonEnergyCalibrator.cc
89  for (unsigned i = 0; i<nSrc; i++){
90  auto obj = src->ptrAt(i);
91  auto detid = obj->superCluster()->seed()->seed();
92  auto coll = obj->isEB() ? recHitsEB.product() : recHitsEE.product();
93  auto seed = coll->find(detid);
94  if (seed != coll->end()) {
95  if (seed->checkFlag(EcalRecHit::kHasSwitchToGain6)) gainSeed[i]=6;
96  if (seed->checkFlag(EcalRecHit::kHasSwitchToGain1)) gainSeed[i]=1;
97  }
98  }
99 
100  std::unique_ptr<edm::ValueMap<int>> gainSeedV(new edm::ValueMap<int>());
101  edm::ValueMap<int>::Filler fillerCorr(*gainSeedV);
102  fillerCorr.insert(src,gainSeed.begin(),gainSeed.end());
103  fillerCorr.fill();
104  iEvent.put(std::move(gainSeedV));
105 
106 }
107 
108 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
109 template <typename T>
110 void
113  desc.add<edm::InputTag>("src")->setComment("input physics object collection");
114  desc.add<edm::InputTag>("recHitsEB",edm::InputTag("reducedEgamma","reducedEBRecHits"))->setComment("EB rechit collection");
115  desc.add<edm::InputTag>("recHitsEE",edm::InputTag("reducedEgamma","reducedEERecHits"))->setComment("EE rechit collection");
116  descriptions.addDefault(desc);
117 }
118 
121 
122 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
edm::EDGetTokenT< EcalRecHitCollection > recHitsEE_
edm::EDGetTokenT< edm::View< T > > src_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:230
void addDefault(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< EcalRecHitCollection > recHitsEB_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
JetCorrectorParametersCollection coll
Definition: classes.h:10
T const * product() const
Definition: Handle.h:81
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
EGMSeedGainProducer< pat::Electron > ElectronSeedGainProducer
HLT enums.
long double T
EGMSeedGainProducer(const edm::ParameterSet &iConfig)
def move(src, dest)
Definition: eostools.py:510
EGMSeedGainProducer< pat::Photon > PhotonSeedGainProducer
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override