CMS 3D CMS Logo

EcalRecalibRecHitProducer.cc
Go to the documentation of this file.
1 
29 
30 #include <cmath>
31 #include <iostream>
32 #include <vector>
33 
35 public:
36  explicit EcalRecalibRecHitProducer(const edm::ParameterSet& ps);
37  void produce(edm::StreamID sid, edm::Event& evt, const edm::EventSetup& es) const override;
38 
39 private:
44 
45  const std::string EBRecalibRecHitCollection_; // secondary name to be given to EB collection of hits
46  const std::string EERecalibRecHitCollection_; // secondary name to be given to EE collection of hits
47 
48  const bool doEnergyScale_;
49  const bool doIntercalib_;
50  const bool doLaserCorrections_;
54 
58 };
59 
61  : EBRecHitCollection_(ps.getParameter<edm::InputTag>("EBRecHitCollection")),
62  EERecHitCollection_(ps.getParameter<edm::InputTag>("EERecHitCollection")),
63  EBRecHitToken_((not EBRecHitCollection_.label().empty()) ? consumes<EBRecHitCollection>(EBRecHitCollection_)
64  : edm::EDGetTokenT<EBRecHitCollection>()),
65  EERecHitToken_((not EERecHitCollection_.label().empty()) ? consumes<EERecHitCollection>(EERecHitCollection_)
66  : edm::EDGetTokenT<EERecHitCollection>()),
67  EBRecalibRecHitCollection_(ps.getParameter<std::string>("EBRecalibRecHitCollection")),
68  EERecalibRecHitCollection_(ps.getParameter<std::string>("EERecalibRecHitCollection")),
69  doEnergyScale_(ps.getParameter<bool>("doEnergyScale")),
70  doIntercalib_(ps.getParameter<bool>("doIntercalib")),
71  doLaserCorrections_(ps.getParameter<bool>("doLaserCorrections")),
72 
73  doEnergyScaleInverse_(ps.getParameter<bool>("doEnergyScaleInverse")),
74  doIntercalibInverse_(ps.getParameter<bool>("doIntercalibInverse")),
75  doLaserCorrectionsInverse_(ps.getParameter<bool>("doLaserCorrectionsInverse")),
76  ecalLaserDBServiceToken_(esConsumes<EcalLaserDbService, EcalLaserDbRecord>()) {
77  if (doEnergyScale_) {
78  ecalADCToGeVConstantToken_ = esConsumes<EcalADCToGeVConstant, EcalADCToGeVConstantRcd>();
79  }
80  if (doIntercalib_) {
81  ecalIntercalibConstantsToken_ = esConsumes<EcalIntercalibConstants, EcalIntercalibConstantsRcd>();
82  }
83  produces<EBRecHitCollection>(EBRecalibRecHitCollection_);
84  produces<EERecHitCollection>(EERecalibRecHitCollection_);
85 }
86 
88  using namespace edm;
89  Handle<EBRecHitCollection> pEBRecHits;
90  Handle<EERecHitCollection> pEERecHits;
91 
92  const EBRecHitCollection* EBRecHits = nullptr;
93  const EERecHitCollection* EERecHits = nullptr;
94 
95  if (not EBRecHitCollection_.label().empty()) {
96  evt.getByToken(EBRecHitToken_, pEBRecHits);
97  EBRecHits = pEBRecHits.product(); // get a ptr to the product
98  }
99  if (not EERecHitCollection_.label().empty()) {
100  evt.getByToken(EERecHitToken_, pEERecHits);
101  EERecHits = pEERecHits.product(); // get a ptr to the product
102  }
103 
104  // collection of rechits to put in the event
105  auto EBRecalibRecHits = std::make_unique<EBRecHitCollection>();
106  auto EERecalibRecHits = std::make_unique<EERecHitCollection>();
107 
108  // now fetch all conditions we need to make rechits
109  // ADC to GeV constant
111  const EcalADCToGeVConstant* agc = nullptr;
112  float agc_eb = 1.;
113  float agc_ee = 1.;
114  if (doEnergyScale_) {
116  agc = pAgc.product();
117  // use this value in the algorithm
118  agc_eb = float(agc->getEBValue());
119  agc_ee = float(agc->getEEValue());
120  }
121  // Intercalib constants
123  const EcalIntercalibConstants* ical = nullptr;
124  if (doIntercalib_) {
126  ical = pIcal.product();
127  }
128  // Laser corrections
130 
131  if (doEnergyScaleInverse_) {
132  agc_eb = 1.0 / agc_eb;
133  agc_ee = 1.0 / agc_ee;
134  }
135 
136  if (EBRecHits) {
137  // loop over uncalibrated rechits to make calibrated ones
138  for (EBRecHitCollection::const_iterator it = EBRecHits->begin(); it != EBRecHits->end(); ++it) {
139  EcalIntercalibConstant icalconst = 1.;
140  if (doIntercalib_) {
141  // find intercalib constant for this xtal
142  const EcalIntercalibConstantMap& icalMap = ical->getMap();
143  EcalIntercalibConstantMap::const_iterator icalit = icalMap.find(it->id());
144  if (icalit != icalMap.end()) {
145  icalconst = (*icalit);
146  } else {
147  edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EBDetId(it->id())
148  << "! something wrong with EcalIntercalibConstants in your DB? ";
149  }
150  }
151  // get laser coefficient
152  float lasercalib = 1;
153  if (doLaserCorrections_) {
154  lasercalib = pLaser->getLaserCorrection(EBDetId(it->id()), evt.time());
155  }
156 
157  // make the rechit and put in the output collection
158  // must implement op= for EcalRecHit
159 
160  if (doIntercalibInverse_) {
161  icalconst = 1.0 / icalconst;
162  }
164  lasercalib = 1.0 / lasercalib;
165  }
166 
167  EcalRecHit aHit((*it).id(), (*it).energy() * agc_eb * icalconst * lasercalib, (*it).time());
168  EBRecalibRecHits->push_back(aHit);
169  }
170  }
171 
172  if (EERecHits) {
173  // loop over uncalibrated rechits to make calibrated ones
174  for (EERecHitCollection::const_iterator it = EERecHits->begin(); it != EERecHits->end(); ++it) {
175  // find intercalib constant for this xtal
176  EcalIntercalibConstant icalconst = 1.;
177  if (doIntercalib_) {
178  const EcalIntercalibConstantMap& icalMap = ical->getMap();
179  EcalIntercalibConstantMap::const_iterator icalit = icalMap.find(it->id());
180  if (icalit != icalMap.end()) {
181  icalconst = (*icalit);
182  } else {
183  edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EEDetId(it->id())
184  << "! something wrong with EcalIntercalibConstants in your DB? ";
185  }
186  }
187  // get laser coefficient
188  float lasercalib = 1;
189  if (doLaserCorrections_) {
190  lasercalib = pLaser->getLaserCorrection(EEDetId(it->id()), evt.time());
191  }
192 
193  if (doIntercalibInverse_) {
194  icalconst = 1.0 / icalconst;
195  }
197  lasercalib = 1.0 / lasercalib;
198  }
199 
200  // make the rechit and put in the output collection
201  EcalRecHit aHit((*it).id(), (*it).energy() * agc_ee * icalconst * lasercalib, (*it).time());
202  EERecalibRecHits->push_back(aHit);
203  }
204  }
205  // put the collection of recunstructed hits in the event
206  LogInfo("EcalRecalibRecHitInfo") << "total # EB re-calibrated rechits: " << EBRecalibRecHits->size();
207  LogInfo("EcalRecalibRecHitInfo") << "total # EE re-calibrated rechits: " << EERecalibRecHits->size();
208 
209  evt.put(std::move(EBRecalibRecHits), EBRecalibRecHitCollection_);
210  evt.put(std::move(EERecalibRecHits), EERecalibRecHitCollection_);
211 }
212 
edm::ESGetToken< EcalADCToGeVConstant, EcalADCToGeVConstantRcd > ecalADCToGeVConstantToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
T const * product() const
Definition: Handle.h:70
std::vector< EcalRecHit >::const_iterator const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:540
edm::ESGetToken< EcalIntercalibConstants, EcalIntercalibConstantsRcd > ecalIntercalibConstantsToken_
std::string const & label() const
Definition: InputTag.h:36
edm::ESGetToken< EcalLaserDbService, EcalLaserDbRecord > ecalLaserDBServiceToken_
Log< level::Error, false > LogError
char const * label
void produce(edm::StreamID sid, edm::Event &evt, const edm::EventSetup &es) const override
T const * product() const
Definition: ESHandle.h:86
edm::Timestamp time() const
Definition: EventBase.h:64
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
float getLaserCorrection(DetId const &xid, edm::Timestamp const &iTime) const
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
const_iterator find(uint32_t rawId) const
Log< level::Info, false > LogInfo
EcalRecalibRecHitProducer(const edm::ParameterSet &ps)
std::vector< Item >::const_iterator const_iterator
const edm::EDGetTokenT< EERecHitCollection > EERecHitToken_
const std::string EERecalibRecHitCollection_
const edm::EDGetTokenT< EBRecHitCollection > EBRecHitToken_
HLT enums.
const_iterator end() const
const std::string EBRecalibRecHitCollection_
def move(src, dest)
Definition: eostools.py:511
float EcalIntercalibConstant