CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripNoisesGenerator.cc
Go to the documentation of this file.
2 #include <boost/cstdint.hpp>
10 
11 #include "CLHEP/Random/RandFlat.h"
12 #include "CLHEP/Random/RandGauss.h"
13 
16  electronsPerADC_(0.),
17  minimumPosValue_(0.),
18  stripLengthMode_(true),
19  printDebug_(0)
20 {
21  edm::LogInfo("SiStripNoisesGenerator") << "[SiStripNoisesGenerator::SiStripNoisesGenerator]";
22 }
23 
25 {
26  edm::LogInfo("SiStripNoisesGenerator") << "[SiStripNoisesGenerator::~SiStripNoisesGenerator]";
27 }
28 
30 {
31  obj_ = new SiStripNoises();
32 
33  stripLengthMode_ = _pset.getParameter<bool>("StripLengthMode");
34 
35  //parameters for random noise generation. not used if Strip length mode is chosen
36  std::map<int, std::vector<double> > meanNoise;
37  fillParameters(meanNoise, "MeanNoise");
38  std::map<int, std::vector<double> > sigmaNoise;
39  fillParameters(sigmaNoise, "SigmaNoise");
40  minimumPosValue_ = _pset.getParameter<double>("MinPositiveNoise");
41 
42  //parameters for strip length proportional noise generation. not used if random mode is chosen
43  std::map<int, std::vector<double> > noiseStripLengthLinearSlope;
44  fillParameters(noiseStripLengthLinearSlope, "NoiseStripLengthSlope");
45  std::map<int, std::vector<double> > noiseStripLengthLinearQuote;
46  fillParameters(noiseStripLengthLinearQuote, "NoiseStripLengthQuote");
47  electronsPerADC_ = _pset.getParameter<double>("electronPerAdc");
48 
49  printDebug_ = _pset.getUntrackedParameter<uint32_t>("printDebug", 5);
50 
51  uint32_t count = 0;
54  const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > DetInfos = reader.getAllData();
55 
56  for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); ++it) {
57 
58  //Generate Noises for det detid
59  SiStripNoises::InputVector theSiStripVector;
60  float noise = 0.;
61  uint32_t detId = it->first;
62  std::pair<int, int> sl = subDetAndLayer(detId);
63  unsigned short nApvs = it->second.nApvs;
64 
65 
66  if(stripLengthMode_) {
67  // Use strip length
68  double linearSlope = noiseStripLengthLinearSlope[sl.first][sl.second];
69  double linearQuote = noiseStripLengthLinearQuote[sl.first][sl.second];
70  double stripLength = it->second.stripLength;
71  for( unsigned short j=0; j<128*nApvs; ++j ) {
72  noise = ( linearSlope*stripLength + linearQuote) / electronsPerADC_;
73  if( count<printDebug_ ) printLog(detId, j, noise);
74  obj_->setData(noise, theSiStripVector);
75  }
76  }
77  else {
78  // Use random generator
79  double meanN = meanNoise[sl.first][sl.second];
80  double sigmaN = sigmaNoise[sl.first][sl.second];
81  for( unsigned short j=0; j<128*nApvs; ++j ) {
82  noise = CLHEP::RandGauss::shoot(meanN, sigmaN);
83  if( noise<=minimumPosValue_ ) noise = minimumPosValue_;
84  if( count<printDebug_ ) printLog(detId, j, noise);
85  obj_->setData(noise, theSiStripVector);
86  }
87  }
88  ++count;
89 
90  if ( ! obj_->put(it->first,theSiStripVector) ) {
91  edm::LogError("SiStripNoisesFakeESSource::produce ")<<" detid already exists"<<std::endl;
92  }
93  }
94 }
95 
96 std::pair<int, int> SiStripNoisesGenerator::subDetAndLayer( const uint32_t detId ) const
97 {
98  int layerId = 0;
99 
100  StripSubdetector subid(detId);
101  int subId = subid.subdetId();
102 
103  if( subId == int(StripSubdetector::TIB)) {
104  TIBDetId theTIBDetId(detId);
105  layerId = theTIBDetId.layer() - 1;
106  }
107  else if(subId == int(StripSubdetector::TOB)) {
108  TOBDetId theTOBDetId(detId);
109  layerId = theTOBDetId.layer() - 1;
110  }
111  else if(subId == int(StripSubdetector::TID)) {
112  TIDDetId theTIDDetId(detId);
113  layerId = theTIDDetId.ring() - 1;
114  }
115  if(subId == int(StripSubdetector::TEC)) {
116  TECDetId theTECDetId = TECDetId(detId);
117  layerId = theTECDetId.ring() - 1;
118  }
119  return std::make_pair(subId, layerId);
120 }
121 
122 void SiStripNoisesGenerator::fillParameters(std::map<int, std::vector<double> > & mapToFill, const std::string & parameterName) const
123 {
124  int layersTIB = 4;
125  int ringsTID = 3;
126  int layersTOB = 6;
127  int ringsTEC = 7;
128 
129  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TIB"), int(StripSubdetector::TIB), layersTIB );
130  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TID"), int(StripSubdetector::TID), ringsTID );
131  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TOB"), int(StripSubdetector::TOB), layersTOB );
132  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TEC"), int(StripSubdetector::TEC), ringsTEC );
133 }
134 
135 void SiStripNoisesGenerator::fillSubDetParameter(std::map<int, std::vector<double> > & mapToFill, const std::vector<double> & v, const int subDet, const unsigned short layers) const
136 {
137  if( v.size() == layers ) {
138  mapToFill.insert(std::make_pair( subDet, v ));
139  }
140  else if( v.size() == 1 ) {
141  std::vector<double> parV(layers, v[0]);
142  mapToFill.insert(std::make_pair( subDet, parV ));
143  }
144  else {
145  throw cms::Exception("Configuration") << "ERROR: number of parameters for subDet " << subDet << " are " << v.size() << ". They must be either 1 or " << layers << std::endl;
146  }
147 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
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.
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
std::pair< int, int > subDetAndLayer(const uint32_t detit) const
Given the map and the detid it returns the corresponding layer/ring.
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:44
SiStripNoisesGenerator(const edm::ParameterSet &, const edm::ActivityRegistry &)
dictionary map
Definition: Association.py:196
void fillSubDetParameter(std::map< int, std::vector< double > > &mapToFill, const std::vector< double > &v, const int subDet, const unsigned short layers) const
unsigned int ring() const
ring id
Definition: TIDDetId.h:55
int j
Definition: DBlmapReader.cc:9
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool put(const uint32_t &detID, const InputVector &input)
void printLog(const uint32_t detId, const unsigned short strip, const double &noise) const
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
unsigned int ring() const
ring id
Definition: TECDetId.h:71
std::string fullPath() const
Definition: FileInPath.cc:171
mathSSE::Vec4< T > v
void setData(float noise_, InputVector &vped)