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;
45  uint32_t m_printDebug;
46 };
47 
52 
53 #include "CLHEP/Random/RandGauss.h"
54 
55 namespace { // helper methods
56  inline void printLog(const uint32_t detId, const unsigned short strip, const double & noise)
57  {
58  edm::LogInfo("SiStripNoisesDummyCalculator") << "detid: " << detId << " strip: " << strip << " noise: " << noise;
59  }
60 }
61 
63 {
64  setWhatProduced(this);
65  findingRecord<SiStripNoisesRcd>();
66 
67  m_stripLengthMode = iConfig.getParameter<bool>("StripLengthMode");
68 
69  if ( ! m_stripLengthMode ) {
70  //parameters for random noise generation. not used if Strip length mode is chosen
71  m_noisePar0 = iConfig.getParameter<double>("MinPositiveNoise");
72  m_noisePar1 = SiStripFakeAPVParameters(iConfig, "MeanNoise");
73  m_noisePar2 = SiStripFakeAPVParameters(iConfig, "SigmaNoise");
74  } else {
75  //parameters for strip length proportional noise generation. not used if random mode is chosen
76  m_noisePar0 = iConfig.getParameter<double>("electronPerAdc");
77  m_noisePar1 = SiStripFakeAPVParameters(iConfig, "NoiseStripLengthSlope");
78  m_noisePar2 = SiStripFakeAPVParameters(iConfig, "NoiseStripLengthQuote");
79  }
80 
81  m_file = iConfig.getParameter<edm::FileInPath>("file");
82  m_printDebug = iConfig.getUntrackedParameter<uint32_t>("printDebug", 5);
83 }
84 
86 
88 {
89  iValidity = edm::ValidityInterval{iov.beginOfTime(), iov.endOfTime()};
90 }
91 
92 // ------------ method called to produce the data ------------
95 {
96  using namespace edm::es;
97 
99  iRecord.getRecord<TrackerTopologyRcd>().get(tTopo);
100 
101  auto noises = std::make_unique<SiStripNoises>();
102 
104 
105  uint32_t count{0};
106  for ( const auto& elm : reader.getAllData() ) {
107  //Generate Noises for det detid
108  SiStripNoises::InputVector theSiStripVector;
110 
111  if ( m_stripLengthMode ) {
112  // Use strip length
113  const double linearSlope{m_noisePar1.get(sl)};
114  const double linearQuote{m_noisePar2.get(sl)};
115  const double stripLength{elm.second.stripLength};
116  for ( unsigned short j{0}; j < 128*elm.second.nApvs; ++j ) {
117  const float noise = (linearSlope*stripLength + linearQuote) / m_noisePar0;
118  if ( count < m_printDebug ) 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 ) 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
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
std::string fullPath() const
Definition: FileInPath.cc:197
SiStripFakeAPVParameters m_noisePar2
T const * product() const
Definition: ESHandle.h:86