Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    CalibTracker/SiStripESProducers
0004 // Class:      SiStripApvGainFakeESSource
0005 //
0006 /**\class SiStripApvGainFakeESSource SiStripApvGainFakeESSource.h CalibTracker/SiStripESProducers/plugins/SiStripApvGainFakeESSource.cc
0007 
0008  Description: "fake" SiStripApvGain ESProducer - fixed (or gaussian-generated) value from configuration for all gains
0009 
0010  Implementation:
0011      Port of SiStripApvGainGenerator and templated fake ESSource to an edm::ESProducer
0012 */
0013 
0014 // system include files
0015 #include <memory>
0016 
0017 // user include files
0018 #include "FWCore/Framework/interface/ESProducer.h"
0019 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0020 
0021 #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
0022 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 
0025 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0026 
0027 class SiStripApvGainFakeESSource : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0028 public:
0029   SiStripApvGainFakeESSource(const edm::ParameterSet&);
0030   ~SiStripApvGainFakeESSource() override;
0031 
0032   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0033                       const edm::IOVSyncValue& iov,
0034                       edm::ValidityInterval& iValidity) override;
0035 
0036   typedef std::unique_ptr<SiStripApvGain> ReturnType;
0037   ReturnType produce(const SiStripApvGainRcd&);
0038 
0039 private:
0040   std::string m_genMode;
0041   double m_meanGain;
0042   double m_sigmaGain;
0043   double m_minimumPosValue;
0044   uint32_t m_printDebug;
0045   SiStripDetInfo m_detInfo;
0046 };
0047 
0048 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0049 #include "CLHEP/Random/RandGauss.h"
0050 
0051 SiStripApvGainFakeESSource::SiStripApvGainFakeESSource(const edm::ParameterSet& iConfig) {
0052   setWhatProduced(this);
0053   findingRecord<SiStripApvGainRcd>();
0054 
0055   m_genMode = iConfig.getParameter<std::string>("genMode");
0056   m_meanGain = iConfig.getParameter<double>("MeanGain");
0057   m_sigmaGain = iConfig.getParameter<double>("SigmaGain");
0058   m_minimumPosValue = iConfig.getParameter<double>("MinPositiveGain");
0059   m_printDebug = iConfig.getUntrackedParameter<uint32_t>("printDebug", 5);
0060   m_detInfo = SiStripDetInfoFileReader::read(iConfig.getParameter<edm::FileInPath>("SiStripDetInfoFile").fullPath());
0061 }
0062 
0063 SiStripApvGainFakeESSource::~SiStripApvGainFakeESSource() {}
0064 
0065 void SiStripApvGainFakeESSource::setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0066                                                 const edm::IOVSyncValue& iov,
0067                                                 edm::ValidityInterval& iValidity) {
0068   iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
0069 }
0070 
0071 // ------------ method called to produce the data  ------------
0072 SiStripApvGainFakeESSource::ReturnType SiStripApvGainFakeESSource::produce(const SiStripApvGainRcd& iRecord) {
0073   using namespace edm::es;
0074 
0075   auto apvGain = std::make_unique<SiStripApvGain>();
0076 
0077   uint32_t count{0};
0078   for (const auto& elm : m_detInfo.getAllData()) {
0079     std::vector<float> theSiStripVector;
0080     for (unsigned short j = 0; j < elm.second.nApvs; ++j) {
0081       float gainValue;
0082       if (m_genMode == "default") {
0083         gainValue = m_meanGain;
0084       } else if (m_genMode == "gaussian") {
0085         gainValue = CLHEP::RandGauss::shoot(m_meanGain, m_sigmaGain);
0086         if (gainValue <= m_minimumPosValue) {
0087           gainValue = m_minimumPosValue;
0088         }
0089       } else {
0090         LogDebug("SiStripApvGain") << "ERROR: wrong genMode specifier : " << m_genMode
0091                                    << ", please select one of \"default\" or \"gaussian\"";
0092         exit(1);
0093       }
0094 
0095       if (count < m_printDebug) {
0096         edm::LogInfo("SiStripApvGainGenerator") << "detid: " << elm.first << " Apv: " << j << " gain: " << gainValue;
0097       }
0098       theSiStripVector.push_back(gainValue);
0099     }
0100     ++count;
0101 
0102     if (!apvGain->put(elm.first, SiStripApvGain::Range{theSiStripVector.begin(), theSiStripVector.end()})) {
0103       edm::LogError("SiStripApvGainGenerator") << " detid already exists";
0104     }
0105   }
0106 
0107   return apvGain;
0108 }
0109 
0110 //define this as a plug-in
0111 #include "FWCore/Framework/interface/SourceFactory.h"
0112 DEFINE_FWK_EVENTSETUP_SOURCE(SiStripApvGainFakeESSource);