File indexing completed on 2024-09-07 04:35:09
0001
0002 #include <memory>
0003 #include <utility>
0004
0005
0006 #include "FWCore/Framework/interface/ModuleFactory.h"
0007 #include "FWCore/Framework/interface/ESProducer.h"
0008
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011
0012 #include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
0013 #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
0014 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0015 #include "CalibTracker/Records/interface/SiStripDependentRecords.h"
0016 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0017
0018 #include "SiStripGainFactor.h"
0019
0020
0021
0022
0023 class SiStripGainESProducer : public edm::ESProducer {
0024 public:
0025 SiStripGainESProducer(const edm::ParameterSet&);
0026 ~SiStripGainESProducer() override {}
0027
0028 std::unique_ptr<SiStripGain> produce(const SiStripGainRcd&);
0029
0030 private:
0031 class GainGetter {
0032 public:
0033 GainGetter(std::string record, std::string label) : recordLabel_{std::move(record), std::move(label)} {}
0034 virtual ~GainGetter() = default;
0035 virtual const SiStripApvGain& gain(const SiStripGainRcd& rcd) const = 0;
0036
0037 const auto& recordLabel() const { return recordLabel_; }
0038
0039 private:
0040 std::pair<std::string, std::string> recordLabel_;
0041 };
0042
0043 template <typename Record>
0044 class GainGetterT : public GainGetter {
0045 public:
0046 GainGetterT(edm::ESConsumesCollector& cc, std::string record, std::string label)
0047 : GainGetter(std::move(record), std::move(label)),
0048 token_{cc.consumesFrom<SiStripApvGain, Record>(edm::ESInputTag{"", recordLabel().second})} {}
0049
0050 const SiStripApvGain& gain(const SiStripGainRcd& rcd) const override { return rcd.get(token_); }
0051
0052 private:
0053 edm::ESGetToken<SiStripApvGain, Record> token_;
0054 };
0055
0056 template <typename Record>
0057 auto make_GainGetter(edm::ESConsumesCollector& cc, std::string record, std::string label) {
0058 return std::make_unique<GainGetterT<Record>>(cc, std::move(record), std::move(label));
0059 }
0060
0061 std::vector<std::unique_ptr<GainGetter>> gainGetters_;
0062
0063 SiStripGainFactor factor_;
0064 };
0065
0066 SiStripGainESProducer::SiStripGainESProducer(const edm::ParameterSet& iConfig) : factor_{iConfig} {
0067 auto cc = setWhatProduced(this);
0068
0069 auto apvGainLabels = iConfig.getParameter<std::vector<edm::ParameterSet>>("APVGain");
0070 if (apvGainLabels.empty()) {
0071 throw cms::Exception("Configuration") << "Got empty APVGain vector, but need at least one entry";
0072 }
0073
0074
0075 for (const auto& gainPSet : apvGainLabels) {
0076
0077 auto record = gainPSet.getParameter<std::string>("Record");
0078 auto label = gainPSet.getUntrackedParameter<std::string>("Label", "");
0079 if (record == "SiStripApvGainRcd")
0080 gainGetters_.emplace_back(make_GainGetter<SiStripApvGainRcd>(cc, record, label));
0081 else if (record == "SiStripApvGain2Rcd")
0082 gainGetters_.emplace_back(make_GainGetter<SiStripApvGain2Rcd>(cc, record, label));
0083 else if (record == "SiStripApvGain3Rcd")
0084 gainGetters_.emplace_back(make_GainGetter<SiStripApvGain3Rcd>(cc, record, label));
0085 else
0086 throw cms::Exception("Configuration")
0087 << "SiStripGainESProducer::ctor ERROR: unrecognized record name " << record << std::endl
0088 << "please specify one of: SiStripApvGainRcd, SiStripApvGain2Rcd, SiStripApvGain3Rcd";
0089 factor_.push_back_norm(gainPSet.getUntrackedParameter<double>("NormalizationFactor", 1.));
0090 }
0091 factor_.resetIfBadNorm();
0092 }
0093
0094 std::unique_ptr<SiStripGain> SiStripGainESProducer::produce(const SiStripGainRcd& iRecord) {
0095 const auto detInfo =
0096 SiStripDetInfoFileReader::read(edm::FileInPath{SiStripDetInfoFileReader::kDefaultFile}.fullPath());
0097
0098 const auto& apvGain = gainGetters_[0]->gain(iRecord);
0099
0100 auto gain = std::make_unique<SiStripGain>(apvGain, factor_.get(apvGain, 0), gainGetters_[0]->recordLabel(), detInfo);
0101
0102 for (unsigned int i = 1; i < gainGetters_.size(); ++i) {
0103 const auto& apvGain = gainGetters_[i]->gain(iRecord);
0104
0105 gain->multiply(apvGain, factor_.get(apvGain, i), gainGetters_[i]->recordLabel(), detInfo);
0106 }
0107
0108 return gain;
0109 }
0110
0111 #include "FWCore/Framework/interface/ModuleFactory.h"
0112
0113 DEFINE_FWK_EVENTSETUP_MODULE(SiStripGainESProducer);