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 public:
32  ~SiStripNoisesFakeESSource() override;
33 
35 
36  typedef std::unique_ptr<SiStripNoises> ReturnType;
37  ReturnType produce(const SiStripNoisesRcd&);
38 
39 private:
41  double m_noisePar0;
44  uint32_t m_printDebug;
45 };
46 
51 
52 #include "CLHEP/Random/RandGauss.h"
53 
54 namespace { // helper methods
55  inline void printLog(const uint32_t detId, const unsigned short strip, const double & noise)
56  {
57  edm::LogInfo("SiStripNoisesDummyCalculator") << "detid: " << detId << " strip: " << strip << " noise: " << noise;
58  }
59 }
60 
62 {
63  setWhatProduced(this);
64  findingRecord<SiStripNoisesRcd>();
65 
66  m_stripLengthMode = iConfig.getParameter<bool>("StripLengthMode");
67 
68  if ( ! m_stripLengthMode ) {
69  //parameters for random noise generation. not used if Strip length mode is chosen
70  m_noisePar0 = iConfig.getParameter<double>("MinPositiveNoise");
71  m_noisePar1 = SiStripFakeAPVParameters(iConfig, "MeanNoise");
72  m_noisePar2 = SiStripFakeAPVParameters(iConfig, "SigmaNoise");
73  } else {
74  //parameters for strip length proportional noise generation. not used if random mode is chosen
75  m_noisePar0 = iConfig.getParameter<double>("electronPerAdc");
76  m_noisePar1 = SiStripFakeAPVParameters(iConfig, "NoiseStripLengthSlope");
77  m_noisePar2 = SiStripFakeAPVParameters(iConfig, "NoiseStripLengthQuote");
78  }
79 
80  m_printDebug = iConfig.getUntrackedParameter<uint32_t>("printDebug", 5);
81 }
82 
84 
86 {
87  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
88 }
89 
90 // ------------ method called to produce the data ------------
93 {
94  using namespace edm::es;
95 
97  iRecord.getRecord<TrackerTopologyRcd>().get(tTopo);
98 
99  auto noises = std::make_unique<SiStripNoises>();
100 
102  uint32_t count{0};
103  for ( const auto& elm : reader->getAllData() ) {
104  //Generate Noises for det detid
105  SiStripNoises::InputVector theSiStripVector;
107 
108  if ( m_stripLengthMode ) {
109  // Use strip length
110  const double linearSlope{m_noisePar1.get(sl)};
111  const double linearQuote{m_noisePar2.get(sl)};
112  const double stripLength{elm.second.stripLength};
113  for ( unsigned short j{0}; j < 128*elm.second.nApvs; ++j ) {
114  const float noise = (linearSlope*stripLength + linearQuote) / m_noisePar0;
115  if ( count < m_printDebug ) printLog(elm.first, j, noise);
116  noises->setData(noise, theSiStripVector);
117  }
118  } else {
119  // Use random generator
120  const double meanN {m_noisePar1.get(sl)};
121  const double sigmaN{m_noisePar2.get(sl)};
122  for ( unsigned short j{0}; j < 128*elm.second.nApvs; ++j ) {
123  const float noise = std::max(CLHEP::RandGauss::shoot(meanN, sigmaN), m_noisePar0);
124  if ( count < m_printDebug ) printLog(elm.first, j, noise);
125  noises->setData(noise, theSiStripVector);
126  }
127  }
128  ++count;
129 
130  if ( ! noises->put(elm.first, theSiStripVector) ) {
131  edm::LogError("SiStripNoisesFakeESSource::produce ") << " detid already exists";
132  }
133  }
134 
135  return noises;
136 }
137 
138 //define this as a plug-in
T getParameter(std::string const &) const
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:53
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
static index getIndex(const TrackerTopology *tTopo, DetId id)
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
std::unique_ptr< SiStripNoises > ReturnType
static const IOVSyncValue & beginOfTime()
double get(const index &idx) const
SiStripNoisesFakeESSource(const edm::ParameterSet &)
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
ReturnType produce(const SiStripNoisesRcd &)
SiStripFakeAPVParameters m_noisePar1
SiStripFakeAPVParameters m_noisePar2
T const * product() const
Definition: ESHandle.h:86