CMS 3D CMS Logo

SiStripNoiseNormalizedWithApvGainBuilder.cc
Go to the documentation of this file.
8 #include <iostream>
9 #include <fstream>
10 #include <vector>
11 #include <algorithm>
12 
14  printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug",1)),
15  pset_(iConfig),
16  electronsPerADC_(0.),
17  minimumPosValue_(0.),
18  stripLengthMode_(true),
19  printDebug_(0)
20 {}
21 
23 {
24  //Retrieve tracker topology from geometry
26  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
27  const TrackerTopology* const tTopo = tTopoHandle.product();
28 
29  // Read the gain from the given tag
30  edm::ESHandle<SiStripApvGain> inputApvGain;
31  iSetup.get<SiStripApvGainRcd>().get( inputApvGain );
32  std::vector<uint32_t> inputDetIds;
33  inputApvGain->getDetIds(inputDetIds);
34 
35  // Prepare the new object
37 
38 
39  stripLengthMode_ = pset_.getParameter<bool>("StripLengthMode");
40 
41  //parameters for random noise generation. not used if Strip length mode is chosen
42  SiStripFakeAPVParameters meanNoise{pset_, "MeanNoise"};
43  SiStripFakeAPVParameters sigmaNoise{pset_, "SigmaNoise"};
44  minimumPosValue_ = pset_.getParameter<double>("MinPositiveNoise");
45 
46  //parameters for strip length proportional noise generation. not used if random mode is chosen
47  SiStripFakeAPVParameters noiseStripLengthLinearSlope{pset_, "NoiseStripLengthSlope"};
48  SiStripFakeAPVParameters noiseStripLengthLinearQuote{pset_, "NoiseStripLengthQuote"};
49  electronsPerADC_ = pset_.getParameter<double>("electronPerAdc");
50 
51  printDebug_ = pset_.getUntrackedParameter<uint32_t>("printDebug", 5);
52 
54  unsigned int count = 0;
55  const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >& DetInfos = reader->getAllData();
56  for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++) {
57 
58  // Find if this DetId is in the input tag and if so how many are the Apvs for which it contains information
59  SiStripApvGain::Range inputRange(inputApvGain->getRange(it->first));
60 
61  //Generate Noises for det detid
62  SiStripNoises::InputVector theSiStripVector;
63  float noise = 0.;
64  uint32_t detId = it->first;
66  unsigned short nApvs = it->second.nApvs;
67 
68  if(stripLengthMode_) {
69  // Use strip length
70  double linearSlope = noiseStripLengthLinearSlope.get(sl);
71  double linearQuote = noiseStripLengthLinearQuote.get(sl);
72  double stripLength = it->second.stripLength;
73  for( unsigned short j=0; j<nApvs; ++j ) {
74 
75  double gain = inputApvGain->getApvGain(j, inputRange);
76 
77  for( unsigned short stripId = 0; stripId < 128; ++stripId ) {
78  noise = ( ( linearSlope*stripLength + linearQuote) / electronsPerADC_ ) * gain;
79  if( count<printDebug_ ) printLog(detId, stripId+128*j, noise);
80  obj->setData(noise, theSiStripVector);
81  }
82  }
83  }
84  else {
85  // Use random generator
86  double meanN = meanNoise.get(sl);
87  double sigmaN = sigmaNoise.get(sl);
88  for( unsigned short j=0; j<nApvs; ++j ) {
89 
90  double gain = inputApvGain->getApvGain(j, inputRange);
91 
92  for( unsigned short stripId = 0; stripId < 128; ++stripId ) {
93  noise = ( CLHEP::RandGauss::shoot(meanN, sigmaN) ) * gain;
94  if( noise<=minimumPosValue_ ) noise = minimumPosValue_;
95  if( count<printDebug_ ) printLog(detId, stripId+128*j, noise);
96  obj->setData(noise, theSiStripVector);
97  }
98  }
99  }
100  ++count;
101 
102  if ( ! obj->put(it->first,theSiStripVector) ) {
103  edm::LogError("SiStripNoisesFakeESSource::produce ")<<" detid already exists"<<std::endl;
104  }
105  }
106 
107  //End now write data in DB
109 
110  if( mydbservice.isAvailable() ){
111  if( mydbservice->isNewTagRequest("SiStripNoisesRcd") ){
112  mydbservice->createNewIOV<SiStripNoises>(obj,mydbservice->beginOfTime(),mydbservice->endOfTime(),"SiStripNoisesRcd");
113  }
114  else {
115  mydbservice->appendSinceTime<SiStripNoises>(obj,mydbservice->currentTime(),"SiStripNoisesRcd");
116  }
117  }
118  else {
119  edm::LogError("SiStripNoiseNormalizedWithApvGainBuilder")<<"Service is unavailable"<<std::endl;
120  }
121 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
static float getApvGain(uint16_t apv, const Range &range)
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:53
SiStripNoiseNormalizedWithApvGainBuilder(const edm::ParameterSet &iConfig)
static index getIndex(const TrackerTopology *tTopo, DetId id)
void getDetIds(std::vector< uint32_t > &DetIds_) const
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:40
std::pair< ContainerIterator, ContainerIterator > Range
void printLog(const uint32_t detId, const unsigned short strip, const double &noise) const
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
bool put(const uint32_t &detID, const InputVector &input)
inputRange
Get input source.
T get() const
Definition: EventSetup.h:71
const Range getRange(const uint32_t detID) const
T const * product() const
Definition: ESHandle.h:86
void setData(float noise_, InputVector &vped)
void analyze(const edm::Event &, const edm::EventSetup &) override