74 template <
typename HandleType,
typename ValType>
77 const std::vector<ValType>& vals,
79 auto valMap = std::make_unique<edm::ValueMap<ValType>>();
81 filler.insert(objHandle, vals.begin(), vals.end());
89 : electronToken_(consumes(conf.getParameter<edm::
InputTag>(
"src"))),
90 epCombinationTool_{conf.
getParameterSet(
"epCombConfig"), consumesCollector()},
91 energyCorrector_(epCombinationTool_, conf.getParameter<
std::string>(
"correctionFile")),
92 recHitCollectionEBToken_(consumes(conf.getParameter<
edm::InputTag>(
"recHitCollectionEB"))),
93 recHitCollectionEEToken_(consumes(conf.getParameter<
edm::InputTag>(
"recHitCollectionEE"))),
94 produceCalibratedObjs_(conf.getParameter<
bool>(
"produceCalibratedObjs")) {
95 energyCorrector_.setMinEt(conf.getParameter<
double>(
"minEtToCalibrate"));
97 if (conf.getParameter<
bool>(
"semiDeterministic")) {
98 semiDeterministicRng_ = std::make_unique<TRandom2>();
99 energyCorrector_.initPrivateRng(semiDeterministicRng_.get());
102 if (produceCalibratedObjs_)
103 produces<std::vector<T>>();
105 for (
const auto& toStore : valMapsToStore_) {
110 template <
typename T>
118 desc.
add<
double>(
"minEtToCalibrate", 5.0);
119 desc.
add<
bool>(
"produceCalibratedObjs",
true);
120 desc.
add<
bool>(
"semiDeterministic",
true);
121 std::vector<std::string> valMapsProduced;
122 valMapsProduced.reserve(valMapsToStore_.size());
123 for (
auto varToStore : valMapsToStore_)
125 desc.
add<std::vector<std::string>>(
"valueMapsStored", valMapsProduced)
127 "provides to python configs the list of valuemaps stored, can not be overriden in the python config");
131 template <
typename T>
133 epCombinationTool_.setEventContent(iSetup);
135 auto inHandle = iEvent.
getHandle(electronToken_);
137 auto recHitCollectionEBHandle = iEvent.
getHandle(recHitCollectionEBToken_);
138 auto recHitCollectionEEHandle = iEvent.
getHandle(recHitCollectionEEToken_);
140 std::unique_ptr<std::vector<T>>
out = std::make_unique<std::vector<T>>();
142 size_t nrObj = inHandle->size();
144 for (
auto& res : results)
150 for (
const auto& ele : *inHandle) {
153 if (semiDeterministicRng_)
154 setSemiDetRandomSeed(iEvent, ele, nrObj, out->
size());
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);
162 results[
index].push_back(uncertainties[
index]);
166 auto fillAndStore = [&](
auto handle) {
167 for (
const auto& mapToStore : valMapsToStore_) {
172 if (produceCalibratedObjs_) {
175 fillAndStore(inHandle);
179 template <
typename T>
184 if (obj.superCluster().isNonnull()) {
CalibratedElectronProducerT(const edm::ParameterSet &)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
~CalibratedElectronProducerT() override
static const std::string & name(size_t index)
#define DEFINE_FWK_MODULE(type)
ElectronEnergyCalibrator energyCorrector_
bool produceCalibratedObjs_
EpCombinationTool epCombinationTool_
edm::EDGetTokenT< edm::View< T > > electronToken_
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
edm::EDGetTokenT< EcalRecHitCollection > recHitCollectionEBToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static constexpr size_t kNrSysErrs
uint32_t getRandomSeedFromObj(const edm::Event &iEvent, const T &obj, size_t nrObjs, size_t objNr)
void produce(edm::Event &, const edm::EventSetup &) override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void setSemiDetRandomSeed(const edm::Event &iEvent, const T &obj, size_t nrObjs, size_t objNr)
ParameterSet const & getParameterSet(std::string const &) const
std::unique_ptr< TRandom > semiDeterministicRng_
edm::EDGetTokenT< EcalRecHitCollection > recHitCollectionEEToken_
uint32_t getRandomSeedFromSC(const edm::Event &iEvent, const reco::SuperClusterRef scRef)
static const std::vector< int > valMapsToStore_
StreamID streamID() const