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>
5 
6 #include "CLHEP/Random/RandFlat.h"
7 #include "CLHEP/Random/RandGauss.h"
8 
11  electronsPerADC_(0.),
12  minimumPosValue_(0.),
13  stripLengthMode_(true),
14  printDebug_(0)
15 {
16  edm::LogInfo("SiStripNoisesGenerator") << "[SiStripNoisesGenerator::SiStripNoisesGenerator]";
17 }
18 
20 {
21  edm::LogInfo("SiStripNoisesGenerator") << "[SiStripNoisesGenerator::~SiStripNoisesGenerator]";
22 }
23 
25 {
27 
28  stripLengthMode_ = _pset.getParameter<bool>("StripLengthMode");
29 
30  //parameters for random noise generation. not used if Strip length mode is chosen
31  std::map<int, std::vector<double> > meanNoise;
32  fillParameters(meanNoise, "MeanNoise");
33  std::map<int, std::vector<double> > sigmaNoise;
34  fillParameters(sigmaNoise, "SigmaNoise");
35  minimumPosValue_ = _pset.getParameter<double>("MinPositiveNoise");
36 
37  //parameters for strip length proportional noise generation. not used if random mode is chosen
38  std::map<int, std::vector<double> > noiseStripLengthLinearSlope;
39  fillParameters(noiseStripLengthLinearSlope, "NoiseStripLengthSlope");
40  std::map<int, std::vector<double> > noiseStripLengthLinearQuote;
41  fillParameters(noiseStripLengthLinearQuote, "NoiseStripLengthQuote");
42  electronsPerADC_ = _pset.getParameter<double>("electronPerAdc");
43 
44  printDebug_ = _pset.getUntrackedParameter<uint32_t>("printDebug", 5);
45 
46  uint32_t count = 0;
49  const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > DetInfos = reader.getAllData();
50 
51  for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); ++it) {
52 
53  //Generate Noises for det detid
54  SiStripNoises::InputVector theSiStripVector;
55  float noise = 0.;
56  uint32_t detId = it->first;
57  std::pair<int, int> sl = subDetAndLayer(detId,tTopo);
58  unsigned short nApvs = it->second.nApvs;
59 
60 
61  if(stripLengthMode_) {
62  // Use strip length
63  double linearSlope = noiseStripLengthLinearSlope[sl.first][sl.second];
64  double linearQuote = noiseStripLengthLinearQuote[sl.first][sl.second];
65  double stripLength = it->second.stripLength;
66  for( unsigned short j=0; j<128*nApvs; ++j ) {
67  noise = ( linearSlope*stripLength + linearQuote) / electronsPerADC_;
68  if( count<printDebug_ ) printLog(detId, j, noise);
69  obj->setData(noise, theSiStripVector);
70  }
71  }
72  else {
73  // Use random generator
74  double meanN = meanNoise[sl.first][sl.second];
75  double sigmaN = sigmaNoise[sl.first][sl.second];
76  for( unsigned short j=0; j<128*nApvs; ++j ) {
77  noise = CLHEP::RandGauss::shoot(meanN, sigmaN);
78  if( noise<=minimumPosValue_ ) noise = minimumPosValue_;
79  if( count<printDebug_ ) printLog(detId, j, noise);
80  obj->setData(noise, theSiStripVector);
81  }
82  }
83  ++count;
84 
85  if ( ! obj->put(it->first,theSiStripVector) ) {
86  edm::LogError("SiStripNoisesFakeESSource::produce ")<<" detid already exists"<<std::endl;
87  }
88  }
89  return obj;
90 }
91 
92 std::pair<int, int> SiStripNoisesGenerator::subDetAndLayer( const uint32_t detId, const TrackerTopology* tTopo ) const
93 {
94  int layerId = 0;
95 
96  const DetId detectorId=DetId(detId);
97  const int subDet = detectorId.subdetId();
98 
99  if( subDet == int(StripSubdetector::TIB)) {
100  layerId = tTopo->tibLayer(detectorId) - 1;
101  }
102  else if(subDet == int(StripSubdetector::TOB)) {
103  layerId = tTopo->tobLayer(detectorId) - 1;
104  }
105  else if(subDet == int(StripSubdetector::TID)) {
106  layerId = tTopo->tidRing(detectorId) - 1;
107  }
108  if(subDet == int(StripSubdetector::TEC)) {
109  layerId = tTopo->tecRing(detectorId) - - 1;
110  }
111  return std::make_pair(subDet, layerId);
112 }
113 
114 void SiStripNoisesGenerator::fillParameters(std::map<int, std::vector<double> > & mapToFill, const std::string & parameterName) const
115 {
116  int layersTIB = 4;
117  int ringsTID = 3;
118  int layersTOB = 6;
119  int ringsTEC = 7;
120 
121  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TIB"), int(StripSubdetector::TIB), layersTIB );
122  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TID"), int(StripSubdetector::TID), ringsTID );
123  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TOB"), int(StripSubdetector::TOB), layersTOB );
124  fillSubDetParameter( mapToFill, _pset.getParameter<std::vector<double> >(parameterName+"TEC"), int(StripSubdetector::TEC), ringsTEC );
125 }
126 
127 void SiStripNoisesGenerator::fillSubDetParameter(std::map<int, std::vector<double> > & mapToFill, const std::vector<double> & v, const int subDet, const unsigned short layers) const
128 {
129  if( v.size() == layers ) {
130  mapToFill.insert(std::make_pair( subDet, v ));
131  }
132  else if( v.size() == 1 ) {
133  std::vector<double> parV(layers, v[0]);
134  mapToFill.insert(std::make_pair( subDet, parV ));
135  }
136  else {
137  throw cms::Exception("Configuration") << "ERROR: number of parameters for subDet " << subDet << " are " << v.size() << ". They must be either 1 or " << layers << std::endl;
138  }
139 }
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
SiStripNoises * createObject(const TrackerTopology *tTopo)
unsigned int tibLayer(const DetId &id) const
unsigned int tidRing(const DetId &id) const
unsigned int tecRing(const DetId &id) const
ring id
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
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)
Definition: DetId.h:18
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.
void printLog(const uint32_t detId, const unsigned short strip, const double &noise) const
std::string fullPath() const
Definition: FileInPath.cc:165
void setData(float noise_, InputVector &vped)
unsigned int tobLayer(const DetId &id) const