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 {
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  return obj;
95 }
96 
97 std::pair<int, int> SiStripNoisesGenerator::subDetAndLayer( const uint32_t detId ) const
98 {
99  int layerId = 0;
100 
101  StripSubdetector subid(detId);
102  int subId = subid.subdetId();
103 
104  if( subId == int(StripSubdetector::TIB)) {
105  TIBDetId theTIBDetId(detId);
106  layerId = theTIBDetId.layer() - 1;
107  }
108  else if(subId == int(StripSubdetector::TOB)) {
109  TOBDetId theTOBDetId(detId);
110  layerId = theTOBDetId.layer() - 1;
111  }
112  else if(subId == int(StripSubdetector::TID)) {
113  TIDDetId theTIDDetId(detId);
114  layerId = theTIDDetId.ring() - 1;
115  }
116  if(subId == int(StripSubdetector::TEC)) {
117  TECDetId theTECDetId = TECDetId(detId);
118  layerId = theTECDetId.ring() - 1;
119  }
120  return std::make_pair(subId, layerId);
121 }
122 
123 void SiStripNoisesGenerator::fillParameters(std::map<int, std::vector<double> > & mapToFill, const std::string & parameterName) const
124 {
125  int layersTIB = 4;
126  int ringsTID = 3;
127  int layersTOB = 6;
128  int ringsTEC = 7;
129 
130  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TIB"), int(StripSubdetector::TIB), layersTIB );
131  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TID"), int(StripSubdetector::TID), ringsTID );
132  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TOB"), int(StripSubdetector::TOB), layersTOB );
133  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TEC"), int(StripSubdetector::TEC), ringsTEC );
134 }
135 
136 void SiStripNoisesGenerator::fillSubDetParameter(std::map<int, std::vector<double> > & mapToFill, const std::vector<double> & v, const int subDet, const unsigned short layers) const
137 {
138  if( v.size() == layers ) {
139  mapToFill.insert(std::make_pair( subDet, v ));
140  }
141  else if( v.size() == 1 ) {
142  std::vector<double> parV(layers, v[0]);
143  mapToFill.insert(std::make_pair( subDet, parV ));
144  }
145  else {
146  throw cms::Exception("Configuration") << "ERROR: number of parameters for subDet " << subDet << " are " << v.size() << ". They must be either 1 or " << layers << std::endl;
147  }
148 }
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.
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
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:51
SiStripNoisesGenerator(const edm::ParameterSet &, const edm::ActivityRegistry &)
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:37
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:165
void setData(float noise_, InputVector &vped)