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;
37  ReturnType produce(const SiStripApvGainRcd&);
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  SiStripDetInfoFileReader{iConfig.getParameter<edm::FileInPath>("SiStripDetInfoFile").fullPath()};
62 }
63 
65 
67  const edm::IOVSyncValue& iov,
68  edm::ValidityInterval& iValidity) {
69  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
70 }
71 
72 // ------------ method called to produce the data ------------
74  using namespace edm::es;
75 
76  auto apvGain = std::make_unique<SiStripApvGain>();
77 
78  uint32_t count{0};
79  for (const auto& elm : m_detInfoFileReader.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
92  << ", please select one of \"default\" or \"gaussian\"";
93  exit(1);
94  }
95 
96  if (count < m_printDebug) {
97  edm::LogInfo("SiStripApvGainGenerator") << "detid: " << elm.first << " Apv: " << j << " gain: " << gainValue;
98  }
99  theSiStripVector.push_back(gainValue);
100  }
101  ++count;
102 
103  if (!apvGain->put(elm.first, SiStripApvGain::Range{theSiStripVector.begin(), theSiStripVector.end()})) {
104  edm::LogError("SiStripApvGainGenerator") << " detid already exists";
105  }
106  }
107 
108  return apvGain;
109 }
110 
111 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
T getUntrackedParameter(std::string const &, T const &) const
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
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
SiStripDetInfoFileReader m_detInfoFileReader
std::unique_ptr< SiStripApvGain > ReturnType
ReturnType produce(const SiStripApvGainRcd &)
const std::map< uint32_t, DetInfo > & getAllData() const
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
SiStripApvGainFakeESSource(const edm::ParameterSet &)
def exit(msg="")