CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  std::map<int, std::vector<double> > meanNoise;
47  fillParameters(meanNoise, "MeanNoise");
48  std::map<int, std::vector<double> > sigmaNoise;
49  fillParameters(sigmaNoise, "SigmaNoise");
50  minimumPosValue_ = pset_.getParameter<double>("MinPositiveNoise");
51 
52  //parameters for strip length proportional noise generation. not used if random mode is chosen
53  std::map<int, std::vector<double> > noiseStripLengthLinearSlope;
54  fillParameters(noiseStripLengthLinearSlope, "NoiseStripLengthSlope");
55  std::map<int, std::vector<double> > noiseStripLengthLinearQuote;
56  fillParameters(noiseStripLengthLinearQuote, "NoiseStripLengthQuote");
57  electronsPerADC_ = pset_.getParameter<double>("electronPerAdc");
58 
59  printDebug_ = pset_.getUntrackedParameter<uint32_t>("printDebug", 5);
60 
61  unsigned int count = 0;
62  const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > DetInfos = reader.getAllData();
63  for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++) {
64 
65  // Find if this DetId is in the input tag and if so how many are the Apvs for which it contains information
66  SiStripApvGain::Range inputRange(inputApvGain->getRange(it->first));
67 
68  //Generate Noises for det detid
69  SiStripNoises::InputVector theSiStripVector;
70  float noise = 0.;
71  uint32_t detId = it->first;
72  std::pair<int, int> sl = subDetAndLayer(detId, tTopo);
73  unsigned short nApvs = it->second.nApvs;
74 
75  if(stripLengthMode_) {
76  // Use strip length
77  double linearSlope = noiseStripLengthLinearSlope[sl.first][sl.second];
78  double linearQuote = noiseStripLengthLinearQuote[sl.first][sl.second];
79  double stripLength = it->second.stripLength;
80  for( unsigned short j=0; j<nApvs; ++j ) {
81 
82  double gain = inputApvGain->getApvGain(j, inputRange);
83 
84  for( unsigned short stripId = 0; stripId < 128; ++stripId ) {
85  noise = ( ( linearSlope*stripLength + linearQuote) / electronsPerADC_ ) * gain;
86  if( count<printDebug_ ) printLog(detId, stripId+128*j, noise);
87  obj->setData(noise, theSiStripVector);
88  }
89  }
90  }
91  else {
92  // Use random generator
93  double meanN = meanNoise[sl.first][sl.second];
94  double sigmaN = sigmaNoise[sl.first][sl.second];
95  for( unsigned short j=0; j<nApvs; ++j ) {
96 
97  double gain = inputApvGain->getApvGain(j, inputRange);
98 
99  for( unsigned short stripId = 0; stripId < 128; ++stripId ) {
100  noise = ( CLHEP::RandGauss::shoot(meanN, sigmaN) ) * gain;
101  if( noise<=minimumPosValue_ ) noise = minimumPosValue_;
102  if( count<printDebug_ ) printLog(detId, stripId+128*j, noise);
103  obj->setData(noise, theSiStripVector);
104  }
105  }
106  }
107  ++count;
108 
109  if ( ! obj->put(it->first,theSiStripVector) ) {
110  edm::LogError("SiStripNoisesFakeESSource::produce ")<<" detid already exists"<<std::endl;
111  }
112  }
113 
114  //End now write data in DB
116 
117  if( mydbservice.isAvailable() ){
118  if( mydbservice->isNewTagRequest("SiStripNoisesRcd") ){
119  mydbservice->createNewIOV<SiStripNoises>(obj,mydbservice->beginOfTime(),mydbservice->endOfTime(),"SiStripNoisesRcd");
120  }
121  else {
122  mydbservice->appendSinceTime<SiStripNoises>(obj,mydbservice->currentTime(),"SiStripNoisesRcd");
123  }
124  }
125  else {
126  edm::LogError("SiStripNoiseNormalizedWithApvGainBuilder")<<"Service is unavailable"<<std::endl;
127  }
128 }
129 
130 std::pair<int, int> SiStripNoiseNormalizedWithApvGainBuilder::subDetAndLayer(const uint32_t detId, const TrackerTopology* tTopo) const
131 {
132  int layerId = 0;
133 
134  StripSubdetector subid(detId);
135  int subId = subid.subdetId();
136 
137  if( subId == int(StripSubdetector::TIB)) {
138  layerId = tTopo->tibLayer(detId) - 1;
139  }
140  else if(subId == int(StripSubdetector::TOB)) {
141  layerId = tTopo->tobLayer(detId) - 1;
142  }
143  else if(subId == int(StripSubdetector::TID)) {
144  layerId = tTopo->tidRing(detId) - 1;
145  }
146  if(subId == int(StripSubdetector::TEC)) {
147  layerId = tTopo->tecRing(detId) - 1;
148  }
149  return std::make_pair(subId, layerId);
150 }
151 
152 void SiStripNoiseNormalizedWithApvGainBuilder::fillParameters(std::map<int, std::vector<double> > & mapToFill, const std::string & parameterName) const
153 {
154  int layersTIB = 4;
155  int ringsTID = 3;
156  int layersTOB = 6;
157  int ringsTEC = 7;
158 
159  fillSubDetParameter( mapToFill, pset_.getParameter<std::vector<double> >(parameterName+"TIB"), int(StripSubdetector::TIB), layersTIB );
160  fillSubDetParameter( mapToFill, pset_.getParameter<std::vector<double> >(parameterName+"TID"), int(StripSubdetector::TID), ringsTID );
161  fillSubDetParameter( mapToFill, pset_.getParameter<std::vector<double> >(parameterName+"TOB"), int(StripSubdetector::TOB), layersTOB );
162  fillSubDetParameter( mapToFill, pset_.getParameter<std::vector<double> >(parameterName+"TEC"), int(StripSubdetector::TEC), ringsTEC );
163 }
164 
165 void SiStripNoiseNormalizedWithApvGainBuilder::fillSubDetParameter(std::map<int, std::vector<double> > & mapToFill, const std::vector<double> & v, const int subDet, const unsigned short layers) const
166 {
167  if( v.size() == layers ) {
168  mapToFill.insert(std::make_pair( subDet, v ));
169  }
170  else if( v.size() == 1 ) {
171  std::vector<double> parV(layers, v[0]);
172  mapToFill.insert(std::make_pair( subDet, parV ));
173  }
174  else {
175  throw cms::Exception("Configuration") << "ERROR: number of parameters for subDet " << subDet << " are " << v.size() << ". They must be either 1 or " << layers << std::endl;
176  }
177 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
inputRange
Get input source.
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
unsigned int tibLayer(const DetId &id) const
unsigned int tidRing(const DetId &id) const
unsigned int tecRing(const DetId &id) const
ring id
std::pair< int, int > subDetAndLayer(const uint32_t detit, const TrackerTopology *tTopo) const
Given the map and the detid it returns the corresponding layer/ring.
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:51
SiStripNoiseNormalizedWithApvGainBuilder(const edm::ParameterSet &iConfig)
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
int j
Definition: DBlmapReader.cc:9
void fillParameters(std::map< int, std::vector< double > > &mapToFill, const std::string &parameterName) const
Fills the parameters read from cfg and matching the name in the given map.
void printLog(const uint32_t detId, const unsigned short strip, const double &noise) const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
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)
void fillSubDetParameter(std::map< int, std::vector< double > > &mapToFill, const std::vector< double > &v, const int subDet, const unsigned short layers) const
virtual void analyze(const edm::Event &, const edm::EventSetup &)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
std::string fullPath() const
Definition: FileInPath.cc:165
void setData(float noise_, InputVector &vped)
unsigned int tobLayer(const DetId &id) const