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