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->createNewIOV<SiStripNoises>(
109  obj, mydbservice->beginOfTime(), mydbservice->endOfTime(), "SiStripNoisesRcd");
110  } else {
111  mydbservice->appendSinceTime<SiStripNoises>(obj, mydbservice->currentTime(), "SiStripNoisesRcd");
112  }
113  } else {
114  edm::LogError("SiStripNoiseNormalizedWithApvGainBuilder") << "Service is unavailable" << std::endl;
115  }
116 }
SiStripFakeAPVParameters::getIndex
static index getIndex(const TrackerTopology *tTopo, DetId id)
Definition: SiStripFakeAPVParameters.h:34
SiStripNoiseNormalizedWithApvGainBuilder::electronsPerADC_
double electronsPerADC_
Definition: SiStripNoiseNormalizedWithApvGainBuilder.h:63
StripGeomDetUnit.h
TrackerGeometry.h
SiStripFakeAPVParameters
Definition: SiStripFakeAPVParameters.h:9
cond::service::PoolDBOutputService::beginOfTime
cond::Time_t beginOfTime() const
Definition: PoolDBOutputService.cc:215
SiStripNoises
Definition: SiStripNoises.h:25
cond::service::PoolDBOutputService::appendSinceTime
void appendSinceTime(const T *payloadObj, cond::Time_t sinceTime, const std::string &recordName)
Definition: PoolDBOutputService.h:141
SiStripFakeAPVParameters.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
pileupCalc.inputRange
inputRange
Definition: pileupCalc.py:217
DetId
Definition: DetId.h:17
TrackerTopology.h
cond::service::PoolDBOutputService::createNewIOV
void createNewIOV(const T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t, const std::string &recordName)
Definition: PoolDBOutputService.h:116
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
SiStripFakeAPVParameters::index
std::pair< int, int > index
Definition: SiStripFakeAPVParameters.h:11
funct::true
true
Definition: Factorize.h:173
GeomDet::geographicalId
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
StripTopology::stripLength
virtual float stripLength() const =0
edm::ParameterSet
Definition: ParameterSet.h:47
SiStripNoiseNormalizedWithApvGainBuilder::SiStripNoiseNormalizedWithApvGainBuilder
SiStripNoiseNormalizedWithApvGainBuilder(const edm::ParameterSet &iConfig)
Definition: SiStripNoiseNormalizedWithApvGainBuilder.cc:12
edm::Service< cond::service::PoolDBOutputService >
SiStripNoiseNormalizedWithApvGainBuilder::inputApvGainToken_
edm::ESGetToken< SiStripApvGain, SiStripApvGainRcd > inputApvGainToken_
Definition: SiStripNoiseNormalizedWithApvGainBuilder.h:70
SiStripNoiseNormalizedWithApvGainBuilder::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: SiStripNoiseNormalizedWithApvGainBuilder.cc:24
edm::EventSetup
Definition: EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
gpuVertexFinder::noise
__shared__ int noise
Definition: gpuFitVertices.h:50
SiStripNoiseNormalizedWithApvGainBuilder::stripLengthMode_
bool stripLengthMode_
Definition: SiStripNoiseNormalizedWithApvGainBuilder.h:65
StripTopology::nstrips
virtual int nstrips() const =0
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
SiStripNoiseNormalizedWithApvGainBuilder.h
PedestalClient_cfi.gain
gain
Definition: PedestalClient_cfi.py:37
cond::service::PoolDBOutputService::endOfTime
cond::Time_t endOfTime() const
Definition: PoolDBOutputService.cc:213
SiStripNoiseNormalizedWithApvGainBuilder::tTopoToken_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
Definition: SiStripNoiseNormalizedWithApvGainBuilder.h:68
SiStripNoiseNormalizedWithApvGainBuilder::printLog
void printLog(const uint32_t detId, const unsigned short strip, const double &noise) const
Definition: SiStripNoiseNormalizedWithApvGainBuilder.h:54
SiStripApvGain::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripApvGain.h:28
EventSetup.h
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:128
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
StripGeomDetUnit::specificTopology
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
Definition: StripGeomDetUnit.cc:17
SiStripNoises::InputVector
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:50
SiStripNoiseNormalizedWithApvGainBuilder::minimumPosValue_
double minimumPosValue_
Definition: SiStripNoiseNormalizedWithApvGainBuilder.h:64
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
SiStripNoiseNormalizedWithApvGainBuilder::tGeomToken_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tGeomToken_
Definition: SiStripNoiseNormalizedWithApvGainBuilder.h:69
cond::service::PoolDBOutputService::currentTime
cond::Time_t currentTime() const
Definition: PoolDBOutputService.cc:217
SiStripNoiseNormalizedWithApvGainBuilder::pset_
edm::ParameterSet pset_
Definition: SiStripNoiseNormalizedWithApvGainBuilder.h:61
StripGeomDetUnit
Definition: StripGeomDetUnit.h:15
SiStripNoiseNormalizedWithApvGainBuilder::printDebug_
uint32_t printDebug_
Definition: SiStripNoiseNormalizedWithApvGainBuilder.h:66