Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-05 04:09:22

0001 // system include files
0002 #include <memory>
0003 #include <utility>
0004 
0005 // user include files
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 class SiStripGainSimESProducer : public edm::ESProducer {
0021 public:
0022   SiStripGainSimESProducer(const edm::ParameterSet&);
0023   ~SiStripGainSimESProducer() override{};
0024 
0025   std::unique_ptr<SiStripGain> produce(const SiStripGainSimRcd&);
0026 
0027 private:
0028   struct TokenLabel {
0029     TokenLabel(edm::ESConsumesCollector& cc, std::string record, std::string label)
0030         : token_{cc.consumesFrom<SiStripApvGain, SiStripApvGainSimRcd>(edm::ESInputTag{"", label})},
0031           recordLabel_{std::move(record), std::move(label)} {}
0032     edm::ESGetToken<SiStripApvGain, SiStripApvGainSimRcd> token_;
0033     std::pair<std::string, std::string> recordLabel_;
0034   };
0035 
0036   std::vector<TokenLabel> tokenLabels_;
0037   SiStripGainFactor factor_;
0038 };
0039 
0040 SiStripGainSimESProducer::SiStripGainSimESProducer(const edm::ParameterSet& iConfig) : factor_{iConfig} {
0041   auto cc = setWhatProduced(this);
0042 
0043   auto apvGainLabels = iConfig.getParameter<std::vector<edm::ParameterSet> >("APVGain");
0044   if (apvGainLabels.empty()) {
0045     throw cms::Exception("Configuration") << "Got empty APVGain vector, but need at least one entry";
0046   }
0047 
0048   // Fill the vector of apv labels
0049   for (const auto& gainPSet : apvGainLabels) {
0050     // Shouldn't all these parameters be tracked?
0051     tokenLabels_.emplace_back(
0052         cc, gainPSet.getParameter<std::string>("Record"), gainPSet.getUntrackedParameter<std::string>("Label", ""));
0053     factor_.push_back_norm(gainPSet.getUntrackedParameter<double>("NormalizationFactor", 1.));
0054   }
0055 
0056   factor_.resetIfBadNorm();
0057 }
0058 
0059 std::unique_ptr<SiStripGain> SiStripGainSimESProducer::produce(const SiStripGainSimRcd& iRecord) {
0060   const auto detInfo =
0061       SiStripDetInfoFileReader::read(edm::FileInPath{SiStripDetInfoFileReader::kDefaultFile}.fullPath());
0062 
0063   const auto& apvGain = iRecord.get(tokenLabels_[0].token_);
0064   auto gain = std::make_unique<SiStripGain>(apvGain, factor_.get(apvGain, 0), tokenLabels_[0].recordLabel_, detInfo);
0065 
0066   for (unsigned int i = 1; i < tokenLabels_.size(); ++i) {
0067     const auto& apvGain = iRecord.get(tokenLabels_[i].token_);
0068     gain->multiply(apvGain, factor_.get(apvGain, i), tokenLabels_[i].recordLabel_, detInfo);
0069   }
0070   return gain;
0071 }
0072 
0073 #include "FWCore/Framework/interface/ModuleFactory.h"
0074 
0075 DEFINE_FWK_EVENTSETUP_MODULE(SiStripGainSimESProducer);