CMS 3D CMS Logo

SiStripApvGainFakeESSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CalibTracker/SiStripESProducers
4 // Class: SiStripApvGainFakeESSource
5 //
14 // system include files
15 #include <memory>
16 
17 // user include files
20 
24 
26 public:
28  ~SiStripApvGainFakeESSource() override;
29 
31 
32  typedef std::unique_ptr<SiStripApvGain> ReturnType;
33  ReturnType produce(const SiStripApvGainRcd&);
34 
35 private:
37  double m_meanGain;
38  double m_sigmaGain;
40  uint32_t m_printDebug;
41 };
42 
45 #include "CLHEP/Random/RandGauss.h"
46 
48 {
49  setWhatProduced(this);
50  findingRecord<SiStripApvGainRcd>();
51 
52  m_genMode = iConfig.getParameter<std::string>("genMode");
53  m_meanGain = iConfig.getParameter<double>("MeanGain");
54  m_sigmaGain = iConfig.getParameter<double>("SigmaGain");
55  m_minimumPosValue = iConfig.getParameter<double>("MinPositiveGain");
56  m_printDebug = iConfig.getUntrackedParameter<uint32_t>("printDebug", 5);
57 }
58 
60 
62 {
63  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
64 }
65 
66 // ------------ method called to produce the data ------------
69 {
70  using namespace edm::es;
71 
72  auto apvGain = std::make_unique<SiStripApvGain>();
73 
75  uint32_t count{0};
76  for ( const auto& elm : reader->getAllData() ) {
77  std::vector<float> theSiStripVector;
78  for ( unsigned short j=0; j < elm.second.nApvs; ++j ){
79  float gainValue;
80  if ( m_genMode == "default" ) {
81  gainValue = m_meanGain;
82  } else if ( m_genMode == "gaussian" ) {
83  gainValue = CLHEP::RandGauss::shoot(m_meanGain, m_sigmaGain);
84  if ( gainValue <= m_minimumPosValue ) {
85  gainValue = m_minimumPosValue;
86  }
87  } else {
88  LogDebug("SiStripApvGain") << "ERROR: wrong genMode specifier : " << m_genMode << ", please select one of \"default\" or \"gaussian\"";
89  exit(1);
90  }
91 
92  if ( count < m_printDebug ) {
93  edm::LogInfo("SiStripApvGainGenerator") << "detid: " << elm.first << " Apv: " << j << " gain: " << gainValue;
94  }
95  theSiStripVector.push_back(gainValue);
96  }
97  ++count;
98 
99  if ( ! apvGain->put(elm.first, SiStripApvGain::Range{theSiStripVector.begin(),theSiStripVector.end()}) ) {
100  edm::LogError("SiStripApvGainGenerator") << " detid already exists";
101  }
102  }
103 
104  return apvGain;
105 }
106 
107 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &iov, edm::ValidityInterval &iValidity) override
static const IOVSyncValue & beginOfTime()
std::pair< ContainerIterator, ContainerIterator > Range
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
std::unique_ptr< SiStripApvGain > ReturnType
ReturnType produce(const SiStripApvGainRcd &)
SiStripApvGainFakeESSource(const edm::ParameterSet &)