CMS 3D CMS Logo

SiStripNoisesFakeESSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CalibTracker/SiStripESProducers
4 // Class: SiStripNoisesFakeESSource
5 //
16 // system include files
17 #include <memory>
18 
19 // user include files
22 
26 
28 
30 
32 public:
34  ~SiStripNoisesFakeESSource() override;
35 
37  const edm::IOVSyncValue& iov,
38  edm::ValidityInterval& iValidity) override;
39 
40  typedef std::unique_ptr<SiStripNoises> ReturnType;
41  ReturnType produce(const SiStripNoisesRcd&);
42 
43 private:
46  double m_noisePar0;
49  uint32_t m_printDebug;
51 };
52 
55 
56 #include "CLHEP/Random/RandGauss.h"
57 
58 namespace { // helper methods
59  inline void printLog(const uint32_t detId, const unsigned short strip, const double& noise) {
60  edm::LogInfo("SiStripNoisesDummyCalculator") << "detid: " << detId << " strip: " << strip << " noise: " << noise;
61  }
62 } // namespace
63 
65  setWhatProduced(this).setConsumes(m_tTopoToken);
66  findingRecord<SiStripNoisesRcd>();
67 
68  m_stripLengthMode = iConfig.getParameter<bool>("StripLengthMode");
69 
70  if (!m_stripLengthMode) {
71  //parameters for random noise generation. not used if Strip length mode is chosen
72  m_noisePar0 = iConfig.getParameter<double>("MinPositiveNoise");
73  m_noisePar1 = SiStripFakeAPVParameters(iConfig, "MeanNoise");
74  m_noisePar2 = SiStripFakeAPVParameters(iConfig, "SigmaNoise");
75  } else {
76  //parameters for strip length proportional noise generation. not used if random mode is chosen
77  m_noisePar0 = iConfig.getParameter<double>("electronPerAdc");
78  m_noisePar1 = SiStripFakeAPVParameters(iConfig, "NoiseStripLengthSlope");
79  m_noisePar2 = SiStripFakeAPVParameters(iConfig, "NoiseStripLengthQuote");
80  }
81 
82  m_printDebug = iConfig.getUntrackedParameter<uint32_t>("printDebug", 5);
83 
85  SiStripDetInfoFileReader{iConfig.getParameter<edm::FileInPath>("SiStripDetInfoFile").fullPath()};
86 }
87 
89 
91  const edm::IOVSyncValue& iov,
92  edm::ValidityInterval& iValidity) {
93  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
94 }
95 
96 // ------------ method called to produce the data ------------
98  using namespace edm::es;
99 
100  const auto& tTopo = iRecord.get(m_tTopoToken);
101 
102  auto noises = std::make_unique<SiStripNoises>();
103 
104  uint32_t count{0};
105  for (const auto& elm : m_detInfoFileReader.getAllData()) {
106  //Generate Noises for det detid
107  SiStripNoises::InputVector theSiStripVector;
109 
110  if (m_stripLengthMode) {
111  // Use strip length
112  const double linearSlope{m_noisePar1.get(sl)};
113  const double linearQuote{m_noisePar2.get(sl)};
114  const double stripLength{elm.second.stripLength};
115  for (unsigned short j{0}; j < 128 * elm.second.nApvs; ++j) {
116  const float noise = (linearSlope * stripLength + linearQuote) / m_noisePar0;
117  if (count < m_printDebug)
118  printLog(elm.first, j, noise);
119  noises->setData(noise, theSiStripVector);
120  }
121  } else {
122  // Use random generator
123  const double meanN{m_noisePar1.get(sl)};
124  const double sigmaN{m_noisePar2.get(sl)};
125  for (unsigned short j{0}; j < 128 * elm.second.nApvs; ++j) {
126  const float noise = std::max(CLHEP::RandGauss::shoot(meanN, sigmaN), m_noisePar0);
127  if (count < m_printDebug)
128  printLog(elm.first, j, noise);
129  noises->setData(noise, theSiStripVector);
130  }
131  }
132  ++count;
133 
134  if (!noises->put(elm.first, theSiStripVector)) {
135  edm::LogError("SiStripNoisesFakeESSource::produce ") << " detid already exists";
136  }
137  }
138 
139  return noises;
140 }
141 
142 //define this as a plug-in
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
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &iov, edm::ValidityInterval &iValidity) override
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:50
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
SiStripDetInfoFileReader m_detInfoFileReader
static index getIndex(const TrackerTopology *tTopo, DetId id)
std::unique_ptr< SiStripNoises > ReturnType
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > m_tTopoToken
double get(const index &idx) const
SiStripNoisesFakeESSource(const edm::ParameterSet &)
ReturnType produce(const SiStripNoisesRcd &)
SiStripFakeAPVParameters m_noisePar1
const std::map< uint32_t, DetInfo > & getAllData() const
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
SiStripFakeAPVParameters m_noisePar2