CMS 3D CMS Logo

CalibratedElectronProducers.cc
Go to the documentation of this file.
1 //author: Alan Smithee
2 //description:
3 // this class allows the residual scale and smearing to be applied to electrons
4 // the scale and smearing is on the ecal part of the energy
5 // hence the E/p combination needs to be re-don, hence the E/p Combination Tools
6 // it re-applies the regression with the new corrected ecal energy
7 // returns a vector of calibrated energies and correction data, indexed by EGEnergySysIndex
8 // a port of EgammaAnalysis/ElectronTools/CalibratedElectronProducerRun2
9 
19 
24 
31 
32 #include "TRandom2.h"
33 
34 #include <vector>
35 
36 template <typename T>
38 public:
41  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
42  void produce(edm::Event&, const edm::EventSetup&) override;
43 
44 private:
45  void setSemiDetRandomSeed(const edm::Event& iEvent, const T& obj, size_t nrObjs, size_t objNr);
46 
48 
51  std::unique_ptr<TRandom> semiDeterministicRng_;
55  static const std::vector<int> valMapsToStore_;
56 };
57 
58 template <typename T>
59 const std::vector<int> CalibratedElectronProducerT<T>::valMapsToStore_ = {
69 
70 namespace {
71  template <typename HandleType, typename ValType>
72  void fillAndStoreValueMap(edm::Event& iEvent,
73  HandleType objHandle,
74  const std::vector<ValType>& vals,
75  const std::string& name) {
76  auto valMap = std::make_unique<edm::ValueMap<ValType>>();
77  typename edm::ValueMap<ValType>::Filler filler(*valMap);
78  filler.insert(objHandle, vals.begin(), vals.end());
79  filler.fill();
80  iEvent.put(std::move(valMap), name);
81  }
82 } // namespace
83 
84 template <typename T>
86  : electronToken_(consumes<edm::View<T>>(conf.getParameter<edm::InputTag>("src"))),
87  epCombinationTool_(conf.getParameter<edm::ParameterSet>("epCombConfig")),
88  energyCorrector_(epCombinationTool_, conf.getParameter<std::string>("correctionFile")),
89  recHitCollectionEBToken_(consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("recHitCollectionEB"))),
90  recHitCollectionEEToken_(consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("recHitCollectionEE"))),
91  produceCalibratedObjs_(conf.getParameter<bool>("produceCalibratedObjs")) {
92  energyCorrector_.setMinEt(conf.getParameter<double>("minEtToCalibrate"));
93 
94  if (conf.getParameter<bool>("semiDeterministic")) {
95  semiDeterministicRng_.reset(new TRandom2());
97  }
98 
100  produces<std::vector<T>>();
101 
102  for (const auto& toStore : valMapsToStore_) {
103  produces<edm::ValueMap<float>>(EGEnergySysIndex::name(toStore));
104  }
105 }
106 
107 template <typename T>
110  desc.add<edm::InputTag>("src", edm::InputTag("gedPhotons"));
112  desc.add<edm::InputTag>("recHitCollectionEB", edm::InputTag("reducedEcalRecHitsEB"));
113  desc.add<edm::InputTag>("recHitCollectionEE", edm::InputTag("reducedEcalRecHitsEE"));
114  desc.add<std::string>("correctionFile", std::string());
115  desc.add<double>("minEtToCalibrate", 5.0);
116  desc.add<bool>("produceCalibratedObjs", true);
117  desc.add<bool>("semiDeterministic", true);
118  std::vector<std::string> valMapsProduced;
119  for (auto varToStore : valMapsToStore_)
120  valMapsProduced.push_back(EGEnergySysIndex::name(varToStore));
121  desc.add<std::vector<std::string>>("valueMapsStored", valMapsProduced)
122  ->setComment(
123  "provides to python configs the list of valuemaps stored, can not be overriden in the python config");
124  descriptions.addWithDefaultLabel(desc);
125 }
126 
127 template <typename T>
129  epCombinationTool_.setEventContent(iSetup);
130 
131  edm::Handle<edm::View<T>> inHandle;
132  iEvent.getByToken(electronToken_, inHandle);
133 
134  edm::Handle<EcalRecHitCollection> recHitCollectionEBHandle;
135  edm::Handle<EcalRecHitCollection> recHitCollectionEEHandle;
136 
137  iEvent.getByToken(recHitCollectionEBToken_, recHitCollectionEBHandle);
138  iEvent.getByToken(recHitCollectionEEToken_, recHitCollectionEEHandle);
139 
140  std::unique_ptr<std::vector<T>> out = std::make_unique<std::vector<T>>();
141 
142  size_t nrObj = inHandle->size();
143  std::array<std::vector<float>, EGEnergySysIndex::kNrSysErrs> results;
144  for (auto& res : results)
145  res.reserve(nrObj);
146 
149 
150  for (const auto& ele : *inHandle) {
151  out->push_back(ele);
152 
153  if (semiDeterministicRng_)
154  setSemiDetRandomSeed(iEvent, ele, nrObj, out->size());
155 
157  (ele.isEB()) ? recHitCollectionEBHandle.product() : recHitCollectionEEHandle.product();
158  std::array<float, EGEnergySysIndex::kNrSysErrs> uncertainties =
159  energyCorrector_.calibrate(out->back(), iEvent.id().run(), recHits, iEvent.streamID(), evtType);
160 
161  for (size_t index = 0; index < EGEnergySysIndex::kNrSysErrs; index++) {
162  results[index].push_back(uncertainties[index]);
163  }
164  }
165 
166  auto fillAndStore = [&](auto handle) {
167  for (const auto& mapToStore : valMapsToStore_) {
168  fillAndStoreValueMap(iEvent, handle, results[mapToStore], EGEnergySysIndex::name(mapToStore));
169  }
170  };
171 
172  if (produceCalibratedObjs_) {
173  fillAndStore(iEvent.put(std::move(out)));
174  } else {
175  fillAndStore(inHandle);
176  }
177 }
178 
179 template <typename T>
181  const T& obj,
182  size_t nrObjs,
183  size_t objNr) {
184  if (obj.superCluster().isNonnull()) {
185  semiDeterministicRng_->SetSeed(egamma::getRandomSeedFromSC(iEvent, obj.superCluster()));
186  } else {
187  semiDeterministicRng_->SetSeed(egamma::getRandomSeedFromObj(iEvent, obj, nrObjs, objNr));
188  }
189 }
190 
193 
195 
ConfigurationDescriptions.h
CalibratedElectronProducerT::setSemiDetRandomSeed
void setSemiDetRandomSeed(const edm::Event &iEvent, const T &obj, size_t nrObjs, size_t objNr)
Definition: CalibratedElectronProducers.cc:180
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
EGEnergySysIndex.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EpCombinationTool::makePSetDescription
static edm::ParameterSetDescription makePSetDescription()
Definition: EpCombinationTool.cc:22
CalibratedElectronProducerT::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CalibratedElectronProducers.cc:128
ESHandle.h
sistrip::View
View
Definition: ConstantsForView.h:26
EGEnergySysIndex::kEcalTrkPostCorr
Definition: EGEnergySysIndex.h:37
patZpeak.handle
handle
Definition: patZpeak.py:23
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EGEnergySysIndex::kSmearRhoDown
Definition: EGEnergySysIndex.h:21
CalibratedElectronProducerT::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: CalibratedElectronProducers.cc:108
CalibratedElectronProducerT::recHitCollectionEEToken_
edm::EDGetTokenT< EcalRecHitCollection > recHitCollectionEEToken_
Definition: CalibratedElectronProducers.cc:53
EDProducer.h
EGEnergySysIndex::kScaleGainUp
Definition: EGEnergySysIndex.h:18
edm::SortedCollection< EcalRecHit >
bookConverter.results
results
Definition: bookConverter.py:144
EGEnergySysIndex::kEcalErrPostCorr
Definition: EGEnergySysIndex.h:34
EGEnergySysIndex::kEcalTrkPreCorr
Definition: EGEnergySysIndex.h:35
EGEnergySysIndex::kSmearRhoUp
Definition: EGEnergySysIndex.h:20
edm::Handle
Definition: AssociativeIterator.h:50
EGEnergySysIndex::kScaleValue
Definition: EGEnergySysIndex.h:28
EGEnergySysIndex::kScaleStatDown
Definition: EGEnergySysIndex.h:15
EGEnergySysIndex::kNrSysErrs
static constexpr size_t kNrSysErrs
Definition: EGEnergySysIndex.h:40
EGEnergySysIndex::kSmearNrSigma
Definition: EGEnergySysIndex.h:30
EGEnergySysIndex::kScaleGainDown
Definition: EGEnergySysIndex.h:19
MakerMacros.h
EGEnergySysIndex::kScaleUp
Definition: EGEnergySysIndex.h:24
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
egamma::getRandomSeedFromObj
uint32_t getRandomSeedFromObj(const edm::Event &iEvent, const T &obj, size_t nrObjs, size_t objNr)
Definition: EgammaRandomSeeds.h:21
CalibratedElectronProducerT::epCombinationTool_
EpCombinationTool epCombinationTool_
Definition: CalibratedElectronProducers.cc:49
egamma::getRandomSeedFromSC
uint32_t getRandomSeedFromSC(const edm::Event &iEvent, const reco::SuperClusterRef scRef)
Definition: EgammaRandomSeeds.cc:5
EpCombinationTool.h
EGEnergySysIndex::kEcalErrPreCorr
Definition: EGEnergySysIndex.h:32
GBRDWrapperRcd.h
ElectronEnergyCalibrator::EventType::DATA
ParameterSetDescription.h
GsfElectron.h
EDGetToken.h
CalibratedElectronProducerT::energyCorrector_
ElectronEnergyCalibrator energyCorrector_
Definition: CalibratedElectronProducers.cc:50
ElectronEnergyCalibrator::EventType
EventType
Definition: ElectronEnergyCalibrator.h:26
GBRForestD.h
CalibratedElectronProducerT
Definition: CalibratedElectronProducers.cc:37
CalibratedElectronProducerT::produceCalibratedObjs_
bool produceCalibratedObjs_
Definition: CalibratedElectronProducers.cc:54
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
EGEnergySysIndex::kSmearDown
Definition: EGEnergySysIndex.h:27
EGEnergySysIndex::name
static const std::string & name(size_t index)
Definition: EGEnergySysIndex.h:42
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CalibratedElectronProducerT::valMapsToStore_
static const std::vector< int > valMapsToStore_
Definition: CalibratedElectronProducers.cc:55
EGEnergySysIndex::kEcalTrkErrPreCorr
Definition: EGEnergySysIndex.h:36
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
GsfElectronFwd.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
ElectronEnergyCalibrator::initPrivateRng
void initPrivateRng(TRandom *rnd)
Definition: ElectronEnergyCalibrator.cc:16
Event.h
ParameterSet
Definition: Functions.h:16
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
CalibratedElectronProducerT::electronToken_
edm::EDGetTokenT< edm::View< T > > electronToken_
Definition: CalibratedElectronProducers.cc:47
EGEnergySysIndex::kScaleDown
Definition: EGEnergySysIndex.h:25
edm::EventSetup
Definition: EventSetup.h:57
res
Definition: Electron.h:6
EGEnergySysIndex::kEcalPostCorr
Definition: EGEnergySysIndex.h:33
ValueMap.h
CalibratedElectronProducerT::recHitCollectionEBToken_
edm::EDGetTokenT< EcalRecHitCollection > recHitCollectionEBToken_
Definition: CalibratedElectronProducers.cc:52
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
EGEnergySysIndex::kEcalPreCorr
Definition: EGEnergySysIndex.h:31
EGEnergySysIndex::kSmearValue
Definition: EGEnergySysIndex.h:29
CalibratedElectronProducerT::~CalibratedElectronProducerT
~CalibratedElectronProducerT() override
Definition: CalibratedElectronProducers.cc:40
CalibratedElectronProducerT::CalibratedElectronProducerT
CalibratedElectronProducerT(const edm::ParameterSet &)
Definition: CalibratedElectronProducers.cc:85
T
long double T
Definition: Basic3DVectorLD.h:48
EGEnergySysIndex::kSmearUp
Definition: EGEnergySysIndex.h:26
EGEnergySysIndex::kSmearPhiDown
Definition: EGEnergySysIndex.h:23
EgammaRandomSeeds.h
EGEnergySysIndex::kScaleSystUp
Definition: EGEnergySysIndex.h:16
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
ElectronEnergyCalibrator
Definition: ElectronEnergyCalibrator.h:39
Electron.h
EGEnergySysIndex::kScaleSystDown
Definition: EGEnergySysIndex.h:17
CalibratedElectronProducerT::semiDeterministicRng_
std::unique_ptr< TRandom > semiDeterministicRng_
Definition: CalibratedElectronProducers.cc:51
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
EGEnergySysIndex::kScaleStatUp
Definition: EGEnergySysIndex.h:14
ElectronEnergyCalibrator::setMinEt
void setMinEt(float val)
Definition: ElectronEnergyCalibrator.h:40
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
EGEnergySysIndex::kEcalTrkErrPostCorr
Definition: EGEnergySysIndex.h:38
ElectronEnergyCalibrator::EventType::MC
edm::Event
Definition: Event.h:73
EGEnergySysIndex::kSmearPhiUp
Definition: EGEnergySysIndex.h:22
edm::InputTag
Definition: InputTag.h:15
ElectronEnergyCalibrator.h
EpCombinationTool
Definition: EpCombinationTool.h:10
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87