CMS 3D CMS Logo

EcalRecalibRecHitProducer.cc
Go to the documentation of this file.
1 
10 
13 
15 
16 #include <iostream>
17 #include <cmath>
18 #include <vector>
19 
24 
26  : EBRecHitCollection_(ps.getParameter<edm::InputTag>("EBRecHitCollection")),
27  EERecHitCollection_(ps.getParameter<edm::InputTag>("EERecHitCollection")),
28  EBRecHitToken_((not EBRecHitCollection_.label().empty()) ? consumes<EBRecHitCollection>(EBRecHitCollection_)
29  : edm::EDGetTokenT<EBRecHitCollection>()),
30  EERecHitToken_((not EERecHitCollection_.label().empty()) ? consumes<EERecHitCollection>(EERecHitCollection_)
31  : edm::EDGetTokenT<EERecHitCollection>()),
32  EBRecalibRecHitCollection_(ps.getParameter<std::string>("EBRecalibRecHitCollection")),
33  EERecalibRecHitCollection_(ps.getParameter<std::string>("EERecalibRecHitCollection")),
34  doEnergyScale_(ps.getParameter<bool>("doEnergyScale")),
35  doIntercalib_(ps.getParameter<bool>("doIntercalib")),
36  doLaserCorrections_(ps.getParameter<bool>("doLaserCorrections")),
37 
38  doEnergyScaleInverse_(ps.getParameter<bool>("doEnergyScaleInverse")),
39  doIntercalibInverse_(ps.getParameter<bool>("doIntercalibInverse")),
40  doLaserCorrectionsInverse_(ps.getParameter<bool>("doLaserCorrectionsInverse")),
41  ecalLaserDBServiceToken_(esConsumes<EcalLaserDbService, EcalLaserDbRecord>()) {
42  if (doEnergyScale_) {
43  ecalADCToGeVConstantToken_ = esConsumes<EcalADCToGeVConstant, EcalADCToGeVConstantRcd>();
44  }
45  if (doIntercalib_) {
46  ecalIntercalibConstantsToken_ = esConsumes<EcalIntercalibConstants, EcalIntercalibConstantsRcd>();
47  }
48  produces<EBRecHitCollection>(EBRecalibRecHitCollection_);
49  produces<EERecHitCollection>(EERecalibRecHitCollection_);
50 }
51 
53  using namespace edm;
54  Handle<EBRecHitCollection> pEBRecHits;
55  Handle<EERecHitCollection> pEERecHits;
56 
57  const EBRecHitCollection* EBRecHits = nullptr;
58  const EERecHitCollection* EERecHits = nullptr;
59 
60  if (not EBRecHitCollection_.label().empty()) {
61  evt.getByToken(EBRecHitToken_, pEBRecHits);
62  EBRecHits = pEBRecHits.product(); // get a ptr to the product
63  }
64  if (not EERecHitCollection_.label().empty()) {
65  evt.getByToken(EERecHitToken_, pEERecHits);
66  EERecHits = pEERecHits.product(); // get a ptr to the product
67  }
68 
69  // collection of rechits to put in the event
70  auto EBRecalibRecHits = std::make_unique<EBRecHitCollection>();
71  auto EERecalibRecHits = std::make_unique<EERecHitCollection>();
72 
73  // now fetch all conditions we need to make rechits
74  // ADC to GeV constant
76  const EcalADCToGeVConstant* agc = nullptr;
77  float agc_eb = 1.;
78  float agc_ee = 1.;
79  if (doEnergyScale_) {
81  agc = pAgc.product();
82  // use this value in the algorithm
83  agc_eb = float(agc->getEBValue());
84  agc_ee = float(agc->getEEValue());
85  }
86  // Intercalib constants
88  const EcalIntercalibConstants* ical = nullptr;
89  if (doIntercalib_) {
91  ical = pIcal.product();
92  }
93  // Laser corrections
95 
97  agc_eb = 1.0 / agc_eb;
98  agc_ee = 1.0 / agc_ee;
99  }
100 
101  if (EBRecHits) {
102  // loop over uncalibrated rechits to make calibrated ones
103  for (EBRecHitCollection::const_iterator it = EBRecHits->begin(); it != EBRecHits->end(); ++it) {
104  EcalIntercalibConstant icalconst = 1.;
105  if (doIntercalib_) {
106  // find intercalib constant for this xtal
107  const EcalIntercalibConstantMap& icalMap = ical->getMap();
108  EcalIntercalibConstantMap::const_iterator icalit = icalMap.find(it->id());
109  if (icalit != icalMap.end()) {
110  icalconst = (*icalit);
111  } else {
112  edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EBDetId(it->id())
113  << "! something wrong with EcalIntercalibConstants in your DB? ";
114  }
115  }
116  // get laser coefficient
117  float lasercalib = 1;
118  if (doLaserCorrections_) {
119  lasercalib = pLaser->getLaserCorrection(EBDetId(it->id()), evt.time());
120  }
121 
122  // make the rechit and put in the output collection
123  // must implement op= for EcalRecHit
124 
125  if (doIntercalibInverse_) {
126  icalconst = 1.0 / icalconst;
127  }
129  lasercalib = 1.0 / lasercalib;
130  }
131 
132  EcalRecHit aHit((*it).id(), (*it).energy() * agc_eb * icalconst * lasercalib, (*it).time());
133  EBRecalibRecHits->push_back(aHit);
134  }
135  }
136 
137  if (EERecHits) {
138  // loop over uncalibrated rechits to make calibrated ones
139  for (EERecHitCollection::const_iterator it = EERecHits->begin(); it != EERecHits->end(); ++it) {
140  // find intercalib constant for this xtal
141  EcalIntercalibConstant icalconst = 1.;
142  if (doIntercalib_) {
143  const EcalIntercalibConstantMap& icalMap = ical->getMap();
144  EcalIntercalibConstantMap::const_iterator icalit = icalMap.find(it->id());
145  if (icalit != icalMap.end()) {
146  icalconst = (*icalit);
147  } else {
148  edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EEDetId(it->id())
149  << "! something wrong with EcalIntercalibConstants in your DB? ";
150  }
151  }
152  // get laser coefficient
153  float lasercalib = 1;
154  if (doLaserCorrections_) {
155  lasercalib = pLaser->getLaserCorrection(EEDetId(it->id()), evt.time());
156  }
157 
158  if (doIntercalibInverse_) {
159  icalconst = 1.0 / icalconst;
160  }
162  lasercalib = 1.0 / lasercalib;
163  }
164 
165  // make the rechit and put in the output collection
166  EcalRecHit aHit((*it).id(), (*it).energy() * agc_ee * icalconst * lasercalib, (*it).time());
167  EERecalibRecHits->push_back(aHit);
168  }
169  }
170  // put the collection of recunstructed hits in the event
171  LogInfo("EcalRecalibRecHitInfo") << "total # EB re-calibrated rechits: " << EBRecalibRecHits->size();
172  LogInfo("EcalRecalibRecHitInfo") << "total # EE re-calibrated rechits: " << EERecalibRecHits->size();
173 
174  evt.put(std::move(EBRecalibRecHits), EBRecalibRecHitCollection_);
175  evt.put(std::move(EERecalibRecHits), EERecalibRecHitCollection_);
176 }
177 
EcalCondObjectContainer::getMap
const self & getMap() const
Definition: EcalCondObjectContainer.h:78
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EcalCondObjectContainer::end
const_iterator end() const
Definition: EcalCondObjectContainer.h:74
edm::StreamID
Definition: StreamID.h:30
EcalRecHit
Definition: EcalRecHit.h:15
Handle.h
EcalRecHitSimpleAlgo.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
MessageLogger.h
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
EcalRecalibRecHitProducer::doIntercalib_
const bool doIntercalib_
Definition: EcalRecalibRecHitProducer.h:40
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
EBDetId
Definition: EBDetId.h:17
edm
HLT enums.
Definition: AlignableModifier.h:19
EBDetId.h
EEDetId.h
EcalRecalibRecHitProducer
Definition: EcalRecalibRecHitProducer.h:25
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
EcalRecalibRecHitProducer::doIntercalibInverse_
const bool doIntercalibInverse_
Definition: EcalRecalibRecHitProducer.h:43
edm::SortedCollection< EcalRecHit >
EcalADCToGeVConstant
Definition: EcalADCToGeVConstant.h:13
EcalRecalibRecHitProducer::ecalLaserDBServiceToken_
edm::ESGetToken< EcalLaserDbService, EcalLaserDbRecord > ecalLaserDBServiceToken_
Definition: EcalRecalibRecHitProducer.h:48
EcalRecalibRecHitProducer::ecalADCToGeVConstantToken_
edm::ESGetToken< EcalADCToGeVConstant, EcalADCToGeVConstantRcd > ecalADCToGeVConstantToken_
Definition: EcalRecalibRecHitProducer.h:46
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::EventBase::time
edm::Timestamp time() const
Definition: EventBase.h:60
EcalCondObjectContainer
Definition: EcalCondObjectContainer.h:13
edm::Handle
Definition: AssociativeIterator.h:50
filterRecHits_cfi.EERecHits
EERecHits
Definition: filterRecHits_cfi.py:9
EcalIntercalibConstant
float EcalIntercalibConstant
Definition: EcalIntercalibConstants.h:10
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
MakerMacros.h
EcalRecalibRecHitProducer::EBRecHitCollection_
const edm::InputTag EBRecHitCollection_
Definition: EcalRecalibRecHitProducer.h:31
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
EcalRecalibRecHitProducer::EBRecalibRecHitCollection_
const std::string EBRecalibRecHitCollection_
Definition: EcalRecalibRecHitProducer.h:36
EcalLaserDbService
Definition: EcalLaserDbService.h:25
EcalRecalibRecHitProducer::doLaserCorrectionsInverse_
const bool doLaserCorrectionsInverse_
Definition: EcalRecalibRecHitProducer.h:44
edm::ESHandle< EcalADCToGeVConstant >
EcalRecalibRecHitProducer::EcalRecalibRecHitProducer
EcalRecalibRecHitProducer(const edm::ParameterSet &ps)
Definition: EcalRecalibRecHitProducer.cc:25
EcalRecalibRecHitProducer::EERecalibRecHitCollection_
const std::string EERecalibRecHitCollection_
Definition: EcalRecalibRecHitProducer.h:37
EcalCondObjectContainer::find
const_iterator find(uint32_t rawId) const
Definition: EcalCondObjectContainer.h:53
EcalRecHit.h
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
EcalUncalibratedRecHit.h
EcalLaserDbRecord
Definition: EcalLaserDbRecord.h:19
EEDetId
Definition: EEDetId.h:14
EcalRecalibRecHitProducer::doLaserCorrections_
const bool doLaserCorrections_
Definition: EcalRecalibRecHitProducer.h:41
EcalRecalibRecHitProducer::EBRecHitToken_
const edm::EDGetTokenT< EBRecHitCollection > EBRecHitToken_
Definition: EcalRecalibRecHitProducer.h:33
edm::ParameterSet
Definition: ParameterSet.h:47
EcalADCToGeVConstant::getEEValue
float getEEValue() const
Definition: EcalADCToGeVConstant.h:21
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
edm::EventSetup
Definition: EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalLaserDbService::getLaserCorrection
float getLaserCorrection(DetId const &xid, edm::Timestamp const &iTime) const
Definition: EcalLaserDbService.cc:30
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
EcalRecalibRecHitProducer::EERecHitCollection_
const edm::InputTag EERecHitCollection_
Definition: EcalRecalibRecHitProducer.h:32
EcalRecalibRecHitProducer::doEnergyScaleInverse_
const bool doEnergyScaleInverse_
Definition: EcalRecalibRecHitProducer.h:42
EcalRecalibRecHitProducer::ecalIntercalibConstantsToken_
edm::ESGetToken< EcalIntercalibConstants, EcalIntercalibConstantsRcd > ecalIntercalibConstantsToken_
Definition: EcalRecalibRecHitProducer.h:47
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
EcalRecalibRecHitProducer::produce
void produce(edm::StreamID sid, edm::Event &evt, const edm::EventSetup &es) const override
Definition: EcalRecalibRecHitProducer.cc:52
EcalRecalibRecHitProducer.h
EcalCondObjectContainer::const_iterator
std::vector< Item >::const_iterator const_iterator
Definition: EcalCondObjectContainer.h:19
EcalRecalibRecHitProducer::EERecHitToken_
const edm::EDGetTokenT< EERecHitCollection > EERecHitToken_
Definition: EcalRecalibRecHitProducer.h:34
EcalRecalibRecHitProducer::doEnergyScale_
const bool doEnergyScale_
Definition: EcalRecalibRecHitProducer.h:39
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
EcalADCToGeVConstant::getEBValue
float getEBValue() const
Definition: EcalADCToGeVConstant.h:20
label
const char * label
Definition: PFTauDecayModeTools.cc:11
filterRecHits_cfi.EBRecHits
EBRecHits
Definition: filterRecHits_cfi.py:8