CMS 3D CMS Logo

SiStripNoiseNormalizedWithApvGainBuilder.cc
Go to the documentation of this file.
7 #include <iostream>
8 #include <fstream>
9 #include <vector>
10 #include <algorithm>
11 
13  : printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)),
14  pset_(iConfig),
15  electronsPerADC_(0.),
16  minimumPosValue_(0.),
17  stripLengthMode_(true),
18  printDebug_(0) {
19  tTopoToken_ = esConsumes<TrackerTopology, TrackerTopologyRcd>();
20  tGeomToken_ = esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>();
21  inputApvGainToken_ = esConsumes<SiStripApvGain, SiStripApvGainRcd>();
22 }
23 
25  const auto& tTopo = iSetup.getData(tTopoToken_);
26  const auto& tGeom = iSetup.getData(tGeomToken_);
27  // Read the gain from the given tag
28  const auto& inputApvGain = iSetup.getData(inputApvGainToken_);
29  std::vector<uint32_t> inputDetIds;
30  inputApvGain.getDetIds(inputDetIds);
31 
32  // Prepare the new object
34 
35  stripLengthMode_ = pset_.getParameter<bool>("StripLengthMode");
36 
37  //parameters for random noise generation. not used if Strip length mode is chosen
38  SiStripFakeAPVParameters meanNoise{pset_, "MeanNoise"};
39  SiStripFakeAPVParameters sigmaNoise{pset_, "SigmaNoise"};
40  minimumPosValue_ = pset_.getParameter<double>("MinPositiveNoise");
41 
42  //parameters for strip length proportional noise generation. not used if random mode is chosen
43  SiStripFakeAPVParameters noiseStripLengthLinearSlope{pset_, "NoiseStripLengthSlope"};
44  SiStripFakeAPVParameters noiseStripLengthLinearQuote{pset_, "NoiseStripLengthQuote"};
45  electronsPerADC_ = pset_.getParameter<double>("electronPerAdc");
46 
47  printDebug_ = pset_.getUntrackedParameter<uint32_t>("printDebug", 5);
48 
49  unsigned int count = 0;
50  for (const auto det : tGeom.detUnits()) {
51  const StripGeomDetUnit* stripDet = dynamic_cast<const StripGeomDetUnit*>(det);
52  if (stripDet != nullptr) {
53  const DetId detId = stripDet->geographicalId();
54  // Find if this DetId is in the input tag and if so how many are the Apvs for which it contains information
55  SiStripApvGain::Range inputRange(inputApvGain.getRange(detId));
56 
57  //Generate Noises for det detid
58  SiStripNoises::InputVector theSiStripVector;
59  float noise = 0.;
61  unsigned short nApvs = stripDet->specificTopology().nstrips() / 128;
62 
63  if (stripLengthMode_) {
64  // Use strip length
65  double linearSlope = noiseStripLengthLinearSlope.get(sl);
66  double linearQuote = noiseStripLengthLinearQuote.get(sl);
67  double stripLength = stripDet->specificTopology().stripLength();
68  for (unsigned short j = 0; j < nApvs; ++j) {
69  double gain = inputApvGain.getApvGain(j, inputRange);
70 
71  for (unsigned short stripId = 0; stripId < 128; ++stripId) {
72  noise = ((linearSlope * stripLength + linearQuote) / electronsPerADC_) * gain;
73  if (count < printDebug_)
74  printLog(detId, stripId + 128 * j, noise);
75  obj.setData(noise, theSiStripVector);
76  }
77  }
78  } else {
79  // Use random generator
80  double meanN = meanNoise.get(sl);
81  double sigmaN = sigmaNoise.get(sl);
82  for (unsigned short j = 0; j < nApvs; ++j) {
83  double gain = inputApvGain.getApvGain(j, inputRange);
84 
85  for (unsigned short stripId = 0; stripId < 128; ++stripId) {
86  noise = (CLHEP::RandGauss::shoot(meanN, sigmaN)) * gain;
87  if (noise <= minimumPosValue_)
89  if (count < printDebug_)
90  printLog(detId, stripId + 128 * j, noise);
91  obj.setData(noise, theSiStripVector);
92  }
93  }
94  }
95  ++count;
96 
97  if (!obj.put(detId, theSiStripVector)) {
98  edm::LogError("SiStripNoisesFakeESSource::produce ") << " detid already exists" << std::endl;
99  }
100  }
101  }
102 
103  //End now write data in DB
105 
106  if (mydbservice.isAvailable()) {
107  if (mydbservice->isNewTagRequest("SiStripNoisesRcd")) {
108  mydbservice->createOneIOV<SiStripNoises>(obj, mydbservice->beginOfTime(), "SiStripNoisesRcd");
109  } else {
110  mydbservice->appendOneIOV<SiStripNoises>(obj, mydbservice->currentTime(), "SiStripNoisesRcd");
111  }
112  } else {
113  edm::LogError("SiStripNoiseNormalizedWithApvGainBuilder") << "Service is unavailable" << std::endl;
114  }
115 }
edm::ESGetToken< SiStripApvGain, SiStripApvGainRcd > inputApvGainToken_
virtual int nstrips() const =0
void printLog(const uint32_t detId, const unsigned short strip, const double &noise) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:50
SiStripNoiseNormalizedWithApvGainBuilder(const edm::ParameterSet &iConfig)
static index getIndex(const TrackerTopology *tTopo, DetId id)
Log< level::Error, false > LogError
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
T getUntrackedParameter(std::string const &, T const &) const
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
virtual float stripLength() const =0
bool isNewTagRequest(const std::string &recordName)
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
std::pair< ContainerIterator, ContainerIterator > Range
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
Definition: DetId.h:17
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tGeomToken_
bool isAvailable() const
Definition: Service.h:40
void analyze(const edm::Event &, const edm::EventSetup &) override