CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: SiStripGain.cc,v 1.13 2010/04/27 08:06:06 demattia Exp $
10 
16 #include <sstream>
17 
18 void SiStripGain::multiply(const SiStripApvGain & apvgain, const double & factor,
19  const std::pair<std::string, std::string> & recordLabelPair)
20 {
21  // When inserting the first ApvGain
22  if( apvgain_ == 0 ) {
23  if( (factor != 1) && (factor != 0) ) {
24  fillNewGain( &apvgain, factor );
25  }
26  else {
27  // If the normalization factor is one, no need to create a new SiStripApvGain
28  apvgain_ = &apvgain;
29  }
30  }
31  else {
32  // There is already an ApvGain inside the SiStripGain. Multiply it by the new one and save the new pointer.
33  fillNewGain( apvgain_, 1., &apvgain, factor );
34  }
35  recordLabelPair_.push_back(recordLabelPair);
36  apvgainVector_.push_back(&apvgain);
37  normVector_.push_back(factor);
38 }
39 
40 void SiStripGain::fillNewGain(const SiStripApvGain * apvgain, const double & factor,
41  const SiStripApvGain * apvgain2, const double & factor2)
42 {
43  SiStripApvGain * newApvGain = new SiStripApvGain;
44  edm::FileInPath fp("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat");
46  const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo> DetInfos = reader.getAllData();
47 
48  // Loop on the apvgain in input and fill the newApvGain with the values/factor.
49  std::vector<uint32_t> detIds;
50  apvgain->getDetIds(detIds);
51  std::vector<uint32_t>::const_iterator it = detIds.begin();
52  for( ; it != detIds.end(); ++it ) {
53 
54  std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator detInfoIt = DetInfos.find(*it);
55  if( detInfoIt != DetInfos.end() ) {
56 
57  std::vector<float> theSiStripVector;
58 
59  // Loop on all the apvs and then on the strips
60  SiStripApvGain::Range range = apvgain->getRange(*it);
61 
62  SiStripApvGain::Range range2;
63  if( apvgain2 != 0 ) {
64  range2 = apvgain2->getRange(*it);
65  }
66 
67  for( int apv = 0; apv < detInfoIt->second.nApvs; ++apv ) {
68  float apvGainValue = apvgain->getApvGain( apv, range )/factor;
69 
70  if( (apvgain2 != 0) && (factor2 != 0.) ) {
71  apvGainValue *= apvgain2->getApvGain( apv, range2 )/factor2;
72  }
73 
74  theSiStripVector.push_back(apvGainValue);
75  }
76  SiStripApvGain::Range inputRange(theSiStripVector.begin(), theSiStripVector.end());
77  if( ! newApvGain->put(*it, inputRange) ) {
78  edm::LogError("SiStripGain") << "detid already exists" << std::endl;
79  }
80  }
81  }
82  apvgain_ = newApvGain;
83  // Deletes the managed object and replaces it with the new one
84  apvgainAutoPtr_.reset(newApvGain);
85 }
86 
87 float SiStripGain::getStripGain(const uint16_t& strip, const SiStripApvGain::Range& range) const
88 {
89  if( apvgain_ == 0 ) {
90  edm::LogError("SiStripGain::getStripGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
91  return 1.;
92  }
93  return( apvgain_->getStripGain(strip, range) );
94 }
95 
96 float SiStripGain::getStripGain(const uint16_t& strip, const SiStripApvGain::Range& range, const uint32_t index) const
97 {
98  if( !(apvgainVector_.empty()) ) {
99  return( apvgainVector_[index]->getStripGain(strip, range) );
100  }
101  edm::LogError("SiStripGain::getStripGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
102  return 1.;
103 }
104 
105 float SiStripGain::getApvGain(const uint16_t& apv, const SiStripApvGain::Range& range) const
106 {
107  if( apvgain_ == 0 ) {
108  edm::LogError("SiStripGain::getApvGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
109  return 1.;
110  }
111  return( apvgain_->getApvGain(apv, range) );
112 }
113 
114 float SiStripGain::getApvGain(const uint16_t& apv, const SiStripApvGain::Range& range, const uint32_t index) const
115 {
116  if( !(apvgainVector_.empty()) ) {
117  return (apvgainVector_[index]->getApvGain(apv, range))/(normVector_[index]);
118  }
119  edm::LogError("SiStripGain::getApvGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
120  return 1.;
121 }
122 
123 void SiStripGain::getDetIds(std::vector<uint32_t>& DetIds_) const
124 {
125  // ATTENTION: we assume the detIds are the same as those from the first gain
126  return apvgain_->getDetIds(DetIds_);
127 }
128 
130 {
131  return apvgain_->getRange(DetId);
132 }
133 
134 const SiStripApvGain::Range SiStripGain::getRange(const uint32_t& DetId, const uint32_t index) const
135 {
136  return apvgainVector_[index]->getRange(DetId);
137 }
138 
139 void SiStripGain::printDebug(std::stringstream & ss) const
140 {
141  std::vector<unsigned int> detIds;
142  getDetIds(detIds);
143  std::vector<unsigned int>::const_iterator detid = detIds.begin();
144  ss << "Number of detids " << detIds.size() << std::endl;
145 
146  for( ; detid != detIds.end(); ++detid ) {
147  SiStripApvGain::Range range = getRange(*detid);
148  int apv=0;
149  for( int it=0; it < range.second - range.first; ++it ) {
150  ss << "detid " << *detid << " \t"
151  << " apv " << apv++ << " \t"
152  << getApvGain(it,range) << " \t"
153  << std::endl;
154  }
155  }
156 }
157 
158 void SiStripGain::printSummary(std::stringstream& ss) const
159 {
160  SiStripDetSummary summaryGain;
161 
162  std::vector<unsigned int> detIds;
163  getDetIds(detIds);
164  std::vector<uint32_t>::const_iterator detid = detIds.begin();
165  for( ; detid != detIds.end(); ++detid ) {
166  SiStripApvGain::Range range = getRange(*detid);
167  for( int it=0; it < range.second - range.first; ++it ) {
168  summaryGain.add(*detid, getApvGain(it, range));
169  }
170  }
171  ss << "Summary of gain values:" << std::endl;
172  summaryGain.print(ss, true);
173 }
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:18
void printDebug(std::stringstream &ss) const
Definition: SiStripGain.cc:139
inputRange
Get input source.
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
std::vector< const SiStripApvGain * > apvgainVector_
Definition: SiStripGain.h:116
float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range) const
Definition: SiStripGain.cc:105
std::auto_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
float getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range) const
Definition: SiStripGain.cc:87
const SiStripApvGain * apvgain_
Definition: SiStripGain.h:118
bool put(const uint32_t &detID, Range input)
float getStripGain(const uint16_t &strip, const Range &range) const
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:123
void print(std::stringstream &ss, const bool mean=true) const
Definition: DetId.h:20
void printSummary(std::stringstream &ss) const
Definition: SiStripGain.cc:158
void fillNewGain(const SiStripApvGain *apvgain, const double &factor, const SiStripApvGain *apvgain2=0, const double &factor2=1.)
Definition: SiStripGain.cc:40
const Range getRange(const uint32_t &detID) const
const SiStripApvGain::Range getRange(const uint32_t &detID) const
Definition: SiStripGain.cc:129
std::string fullPath() const
Definition: FileInPath.cc:171
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...
float getApvGain(const uint16_t &apv, const Range &range) const