CMS 3D CMS Logo

SiStripGain.cc
Go to the documentation of this file.
1  // -*- C++ -*-
2 //
3 // Package: SiStripObjects
4 // Class : SiStripGain
5 // Implementation:
6 // <Notes on implementation>
7 // Original Author: gbruno
8 // Created: Wed Mar 22 12:24:33 CET 2006
9 
15 #include <sstream>
16 
17 void SiStripGain::multiply(const SiStripApvGain & apvgain, const double & factor,
18  const std::pair<std::string, std::string> & recordLabelPair)
19 {
20  // When inserting the first ApvGain
21  if( apvgain_ == 0 ) {
22  if( (factor != 1) && (factor != 0) ) {
23  fillNewGain( &apvgain, factor );
24  }
25  else {
26  // If the normalization factor is one, no need to create a new SiStripApvGain
27  apvgain_ = &apvgain;
28  }
29  }
30  else {
31  // There is already an ApvGain inside the SiStripGain. Multiply it by the new one and save the new pointer.
32  fillNewGain( apvgain_, 1., &apvgain, factor );
33  }
34  recordLabelPair_.push_back(recordLabelPair);
35  apvgainVector_.push_back(&apvgain);
36  normVector_.push_back(factor);
37 }
38 
39 void SiStripGain::fillNewGain(const SiStripApvGain * apvgain, const double & factor,
40  const SiStripApvGain * apvgain2, const double & factor2)
41 {
42  SiStripApvGain * newApvGain = new SiStripApvGain;
43  edm::FileInPath fp("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat");
45  const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo> DetInfos = reader.getAllData();
46 
47  // Loop on the apvgain in input and fill the newApvGain with the values/factor.
48  std::vector<uint32_t> detIds;
49  apvgain->getDetIds(detIds);
50  std::vector<uint32_t>::const_iterator it = detIds.begin();
51  for( ; it != detIds.end(); ++it ) {
52 
53  std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator detInfoIt = DetInfos.find(*it);
54  if( detInfoIt != DetInfos.end() ) {
55 
56  std::vector<float> theSiStripVector;
57 
58  // Loop on all the apvs and then on the strips
59  SiStripApvGain::Range range = apvgain->getRange(*it);
60 
61  SiStripApvGain::Range range2;
62  if( apvgain2 != 0 ) {
63  range2 = apvgain2->getRange(*it);
64  }
65 
66  for( int apv = 0; apv < detInfoIt->second.nApvs; ++apv ) {
67  float apvGainValue = apvgain->getApvGain( apv, range )/factor;
68 
69  if( (apvgain2 != 0) && (factor2 != 0.) ) {
70  apvGainValue *= apvgain2->getApvGain( apv, range2 )/factor2;
71  }
72 
73  theSiStripVector.push_back(apvGainValue);
74  }
75  SiStripApvGain::Range inputRange(theSiStripVector.begin(), theSiStripVector.end());
76  if( ! newApvGain->put(*it, inputRange) ) {
77  edm::LogError("SiStripGain") << "detid already exists" << std::endl;
78  }
79  }
80  }
81  apvgain_ = newApvGain;
82  // Deletes the managed object and replaces it with the new one
83  apvgainAutoPtr_.reset(newApvGain);
84 }
85 
86 
87 
88 float SiStripGain::getStripGain(const uint16_t& strip, const SiStripApvGain::Range& range, const uint32_t index) const
89 {
90  if( !(apvgainVector_.empty()) ) {
91  return( apvgainVector_[index]->getStripGain(strip, range) );
92  }
93  edm::LogError("SiStripGain::getStripGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
94  return 1.;
95 }
96 
97 
98 
99 float SiStripGain::getApvGain(const uint16_t& apv, const SiStripApvGain::Range& range, const uint32_t index) const
100 {
101  if( !(apvgainVector_.empty()) ) {
102  return (apvgainVector_[index]->getApvGain(apv, range))/(normVector_[index]);
103  }
104  edm::LogError("SiStripGain::getApvGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
105  return 1.;
106 }
107 
108 void SiStripGain::getDetIds(std::vector<uint32_t>& DetIds_) const
109 {
110  // ATTENTION: we assume the detIds are the same as those from the first gain
111  return apvgain_->getDetIds(DetIds_);
112 }
113 
114 
115 const SiStripApvGain::Range SiStripGain::getRange(const uint32_t& DetId, const uint32_t index) const
116 {
117  return apvgainVector_[index]->getRange(DetId);
118 }
119 
120 void SiStripGain::printDebug(std::stringstream & ss) const
121 {
122  std::vector<unsigned int> detIds;
123  getDetIds(detIds);
124  std::vector<unsigned int>::const_iterator detid = detIds.begin();
125  ss << "Number of detids " << detIds.size() << std::endl;
126 
127  for( ; detid != detIds.end(); ++detid ) {
128  SiStripApvGain::Range range = getRange(*detid);
129  int apv=0;
130  for( int it=0; it < range.second - range.first; ++it ) {
131  ss << "detid " << *detid << " \t"
132  << " apv " << apv++ << " \t"
133  << getApvGain(it,range) << " \t"
134  << std::endl;
135  }
136  }
137 }
138 
139 void SiStripGain::printSummary(std::stringstream& ss) const
140 {
141  SiStripDetSummary summaryGain;
142 
143  std::vector<unsigned int> detIds;
144  getDetIds(detIds);
145  std::vector<uint32_t>::const_iterator detid = detIds.begin();
146  for( ; detid != detIds.end(); ++detid ) {
147  SiStripApvGain::Range range = getRange(*detid);
148  for( int it=0; it < range.second - range.first; ++it ) {
149  summaryGain.add(*detid, getApvGain(it, range));
150  }
151  }
152  ss << "Summary of gain values:" << std::endl;
153  summaryGain.print(ss, true);
154 }
void multiply(const SiStripApvGain &apvgain, const double &factor, const std::pair< std::string, std::string > &recordLabelPair)
Used to input additional gain values that will be multiplied to the first one.
Definition: SiStripGain.cc:17
void printDebug(std::stringstream &ss) const
Definition: SiStripGain.cc:120
static float getApvGain(uint16_t apv, const Range &range)
std::vector< const SiStripApvGain * > apvgainVector_
Definition: SiStripGain.h:116
std::unique_ptr< SiStripApvGain > apvgainAutoPtr_
Definition: SiStripGain.h:119
std::vector< double > normVector_
Definition: SiStripGain.h:117
std::vector< std::pair< std::string, std::string > > recordLabelPair_
Definition: SiStripGain.h:120
void getDetIds(std::vector< uint32_t > &DetIds_) const
const SiStripApvGain * apvgain_
Definition: SiStripGain.h:118
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:69
bool put(const uint32_t &detID, Range input)
static float getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:68
std::pair< ContainerIterator, ContainerIterator > Range
void getDetIds(std::vector< uint32_t > &DetIds_) const
ATTENTION: we assume the detIds are the same as those from the first gain.
Definition: SiStripGain.cc:108
void print(std::stringstream &ss, const bool mean=true) const
Definition: DetId.h:18
void printSummary(std::stringstream &ss) const
Definition: SiStripGain.cc:139
void fillNewGain(const SiStripApvGain *apvgain, const double &factor, const SiStripApvGain *apvgain2=0, const double &factor2=1.)
Definition: SiStripGain.cc:39
inputRange
Get input source.
std::string fullPath() const
Definition: FileInPath.cc:184
const Range getRange(const uint32_t detID) const
void add(const DetId &detid, const float &value)
Used to compute the mean value of the value variable divided by subdetector, layer and mono/stereo...
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:66