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 
28 public:
30  ~SiStripApvGainFakeESSource() override;
31 
33  const edm::IOVSyncValue& iov,
34  edm::ValidityInterval& iValidity) override;
35 
36  typedef std::unique_ptr<SiStripApvGain> ReturnType;
38 
39 private:
41  double m_meanGain;
42  double m_sigmaGain;
44  uint32_t m_printDebug;
46 };
47 
49 #include "CLHEP/Random/RandGauss.h"
50 
52  setWhatProduced(this);
53  findingRecord<SiStripApvGainRcd>();
54 
55  m_genMode = iConfig.getParameter<std::string>("genMode");
56  m_meanGain = iConfig.getParameter<double>("MeanGain");
57  m_sigmaGain = iConfig.getParameter<double>("SigmaGain");
58  m_minimumPosValue = iConfig.getParameter<double>("MinPositiveGain");
59  m_printDebug = iConfig.getUntrackedParameter<uint32_t>("printDebug", 5);
61 }
62 
64 
66  const edm::IOVSyncValue& iov,
67  edm::ValidityInterval& iValidity) {
68  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
69 }
70 
71 // ------------ method called to produce the data ------------
73  using namespace edm::es;
74 
75  auto apvGain = std::make_unique<SiStripApvGain>();
76 
77  uint32_t count{0};
78  for (const auto& elm : m_detInfo.getAllData()) {
79  std::vector<float> theSiStripVector;
80  for (unsigned short j = 0; j < elm.second.nApvs; ++j) {
81  float gainValue;
82  if (m_genMode == "default") {
83  gainValue = m_meanGain;
84  } else if (m_genMode == "gaussian") {
85  gainValue = CLHEP::RandGauss::shoot(m_meanGain, m_sigmaGain);
86  if (gainValue <= m_minimumPosValue) {
87  gainValue = m_minimumPosValue;
88  }
89  } else {
90  LogDebug("SiStripApvGain") << "ERROR: wrong genMode specifier : " << m_genMode
91  << ", 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
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::string fullPath() const
Definition: FileInPath.cc:161
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
Log< level::Error, false > LogError
T getUntrackedParameter(std::string const &, T const &) const
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &iov, edm::ValidityInterval &iValidity) override
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
std::pair< ContainerIterator, ContainerIterator > Range
SiStripDetInfo read(std::string filePath)
Log< level::Info, false > LogInfo
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
const std::map< uint32_t, DetInfo > & getAllData() const noexcept
std::unique_ptr< SiStripApvGain > ReturnType
ReturnType produce(const SiStripApvGainRcd &)
SiStripApvGainFakeESSource(const edm::ParameterSet &)
#define LogDebug(id)
def exit(msg="")