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::shared_ptr<SiStripApvGain> ReturnType;
33  ReturnType produce(const SiStripApvGainRcd&);
34 
35 private:
37  double m_meanGain;
38  double m_sigmaGain;
41  uint32_t m_printDebug;
42 };
43 
46 #include "CLHEP/Random/RandGauss.h"
47 
49 {
50  setWhatProduced(this);
51  findingRecord<SiStripApvGainRcd>();
52 
53  m_genMode = iConfig.getParameter<std::string>("genMode");
54  m_meanGain = iConfig.getParameter<double>("MeanGain");
55  m_sigmaGain = iConfig.getParameter<double>("SigmaGain");
56  m_minimumPosValue = iConfig.getParameter<double>("MinPositiveGain");
57  m_file = iConfig.getParameter<edm::FileInPath>("file");
58  m_printDebug = iConfig.getUntrackedParameter<uint32_t>("printDebug", 5);
59 }
60 
62 
64 {
65  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
66 }
67 
68 // ------------ method called to produce the data ------------
71 {
72  using namespace edm::es;
73 
74  std::shared_ptr<SiStripApvGain> apvGain{new SiStripApvGain};
75 
77 
78  uint32_t count{0};
79  for ( const auto& elm : reader.getAllData() ) {
80  std::vector<float> theSiStripVector;
81  for ( unsigned short j=0; j < elm.second.nApvs; ++j ){
82  float gainValue;
83  if ( m_genMode == "default" ) {
84  gainValue = m_meanGain;
85  } else if ( m_genMode == "gaussian" ) {
86  gainValue = CLHEP::RandGauss::shoot(m_meanGain, m_sigmaGain);
87  if ( gainValue <= m_minimumPosValue ) {
88  gainValue = m_minimumPosValue;
89  }
90  } else {
91  LogDebug("SiStripApvGain") << "ERROR: wrong genMode specifier : " << m_genMode << ", please select one of \"default\" or \"gaussian\"";
92  exit(1);
93  }
94 
95  if ( count < m_printDebug ) {
96  edm::LogInfo("SiStripApvGainGenerator") << "detid: " << elm.first << " Apv: " << j << " gain: " << gainValue;
97  }
98  theSiStripVector.push_back(gainValue);
99  }
100  ++count;
101 
102  if ( ! apvGain->put(elm.first, SiStripApvGain::Range{theSiStripVector.begin(),theSiStripVector.end()}) ) {
103  edm::LogError("SiStripApvGainGenerator") << " detid already exists";
104  }
105  }
106 
107  return apvGain;
108 }
109 
110 //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
ReturnType produce(const SiStripApvGainRcd &)
std::string fullPath() const
Definition: FileInPath.cc:197
std::shared_ptr< SiStripApvGain > ReturnType
SiStripApvGainFakeESSource(const edm::ParameterSet &)