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;
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  : m_tTopoToken(setWhatProduced(this).consumes()) {
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 }
86 
88 
90  const edm::IOVSyncValue& iov,
91  edm::ValidityInterval& iValidity) {
92  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
93 }
94 
95 // ------------ method called to produce the data ------------
97  using namespace edm::es;
98 
99  const auto& tTopo = iRecord.get(m_tTopoToken);
100 
101  auto noises = std::make_unique<SiStripNoises>();
102 
103  uint32_t count{0};
104  for (const auto& elm : m_detInfo.getAllData()) {
105  //Generate Noises for det detid
106  SiStripNoises::InputVector theSiStripVector;
108 
109  if (m_stripLengthMode) {
110  // Use strip length
111  const double linearSlope{m_noisePar1.get(sl)};
112  const double linearQuote{m_noisePar2.get(sl)};
113  const double stripLength{elm.second.stripLength};
114  for (unsigned short j{0}; j < 128 * elm.second.nApvs; ++j) {
115  const float noise = (linearSlope * stripLength + linearQuote) / m_noisePar0;
116  if (count < m_printDebug)
117  printLog(elm.first, j, noise);
118  noises->setData(noise, theSiStripVector);
119  }
120  } else {
121  // Use random generator
122  const double meanN{m_noisePar1.get(sl)};
123  const double sigmaN{m_noisePar2.get(sl)};
124  for (unsigned short j{0}; j < 128 * elm.second.nApvs; ++j) {
125  const float noise = std::max(CLHEP::RandGauss::shoot(meanN, sigmaN), m_noisePar0);
126  if (count < m_printDebug)
127  printLog(elm.first, j, noise);
128  noises->setData(noise, theSiStripVector);
129  }
130  }
131  ++count;
132 
133  if (!noises->put(elm.first, theSiStripVector)) {
134  edm::LogError("SiStripNoisesFakeESSource::produce ") << " detid already exists";
135  }
136  }
137 
138  return noises;
139 }
140 
141 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
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
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > m_tTopoToken
static index getIndex(const TrackerTopology *tTopo, DetId id)
Log< level::Error, false > LogError
T getUntrackedParameter(std::string const &, T const &) const
std::unique_ptr< SiStripNoises > ReturnType
double get(const index &idx) const
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
SiStripDetInfo read(std::string filePath)
SiStripNoisesFakeESSource(const edm::ParameterSet &)
Log< level::Info, false > LogInfo
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
ReturnType produce(const SiStripNoisesRcd &)
const std::map< uint32_t, DetInfo > & getAllData() const noexcept
SiStripFakeAPVParameters m_noisePar1
const std::string & fullPath() const
Definition: FileInPath.cc:144
SiStripFakeAPVParameters m_noisePar2
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const