CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
15 #include <sstream>
16 
18  const double &factor,
19  const std::pair<std::string, std::string> &recordLabelPair,
20  const SiStripDetInfo &detInfo) {
21  // When inserting the first ApvGain
22  if (apvgain_ == nullptr) {
23  if ((factor != 1) && (factor != 0)) {
24  fillNewGain(&apvgain, factor, detInfo);
25  } else {
26  // If the normalization factor is one, no need to create a new
27  // SiStripApvGain
28  apvgain_ = &apvgain;
29  }
30  } else {
31  // There is already an ApvGain inside the SiStripGain. Multiply it by the
32  // new one and save the new pointer.
33  fillNewGain(apvgain_, 1., detInfo, &apvgain, factor);
34  }
35  recordLabelPair_.push_back(recordLabelPair);
36  apvgainVector_.push_back(&apvgain);
37  normVector_.push_back(factor);
38 }
39 
41  const double &factor,
42  const SiStripDetInfo &detInfo,
43  const SiStripApvGain *apvgain2,
44  const double &factor2) {
45  SiStripApvGain *newApvGain = new SiStripApvGain;
46  const auto &DetInfos = detInfo.getAllData();
47 
48  // Loop on the apvgain in input and fill the newApvGain with the
49  // values/factor.
50  std::vector<uint32_t> detIds;
51  apvgain->getDetIds(detIds);
52  std::vector<uint32_t>::const_iterator it = detIds.begin();
53  for (; it != detIds.end(); ++it) {
54  auto detInfoIt = DetInfos.find(*it);
55  if (detInfoIt != DetInfos.end()) {
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 != nullptr) {
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 != nullptr) && (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 float SiStripGain::getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range, const uint32_t index) const {
87  if (!(apvgainVector_.empty())) {
88  return (apvgainVector_[index]->getStripGain(strip, range));
89  }
90  edm::LogError("SiStripGain::getStripGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
91  return 1.;
92 }
93 
94 float SiStripGain::getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range, const uint32_t index) const {
95  if (!(apvgainVector_.empty())) {
96  return (apvgainVector_[index]->getApvGain(apv, range)) / (normVector_[index]);
97  }
98  edm::LogError("SiStripGain::getApvGain") << "ERROR: no gain available. Returning gain = 1." << std::endl;
99  return 1.;
100 }
101 
102 void SiStripGain::getDetIds(std::vector<uint32_t> &DetIds_) const {
103  // ATTENTION: we assume the detIds are the same as those from the first gain
104  return apvgain_->getDetIds(DetIds_);
105 }
106 
107 const SiStripApvGain::Range SiStripGain::getRange(const uint32_t &DetId, const uint32_t index) const {
108  return apvgainVector_[index]->getRange(DetId);
109 }
110 
111 void SiStripGain::printDebug(std::stringstream &ss, const TrackerTopology * /*trackerTopo*/) const {
112  std::vector<unsigned int> detIds;
113  getDetIds(detIds);
114  std::vector<unsigned int>::const_iterator detid = detIds.begin();
115  ss << "Number of detids " << detIds.size() << std::endl;
116 
117  for (; detid != detIds.end(); ++detid) {
119  int apv = 0;
120  for (int it = 0; it < range.second - range.first; ++it) {
121  ss << "detid " << *detid << " \t"
122  << " apv " << apv++ << " \t" << getApvGain(it, range) << " \t" << std::endl;
123  }
124  }
125 }
126 
127 void SiStripGain::printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const {
128  SiStripDetSummary summaryGain{trackerTopo};
129 
130  std::vector<unsigned int> detIds;
131  getDetIds(detIds);
132  std::vector<uint32_t>::const_iterator detid = detIds.begin();
133  for (; detid != detIds.end(); ++detid) {
135  for (int it = 0; it < range.second - range.first; ++it) {
136  summaryGain.add(*detid, getApvGain(it, range));
137  }
138  }
139  ss << "Summary of gain values:" << std::endl;
140  summaryGain.print(ss, true);
141 }
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
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Definition: SiStripGain.cc:111
std::vector< double > normVector_
Definition: SiStripGain.h:117
std::vector< std::pair< std::string, std::string > > recordLabelPair_
Definition: SiStripGain.h:120
Log< level::Error, false > LogError
void getDetIds(std::vector< uint32_t > &DetIds_) const
const SiStripApvGain * apvgain_
Definition: SiStripGain.h:118
const uint16_t range(const Frame &aFrame)
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:80
bool put(const uint32_t &detID, Range input)
void fillNewGain(const SiStripApvGain *apvgain, const double &factor, SiStripDetInfo const &detInfo, const SiStripApvGain *apvgain2=nullptr, const double &factor2=1.)
Definition: SiStripGain.cc:40
static float getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:77
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:102
Definition: DetId.h:17
tuple inputRange
Definition: pileupCalc.py:168
void printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Definition: SiStripGain.cc:127
void multiply(const SiStripApvGain &apvgain, const double &factor, const std::pair< std::string, std::string > &recordLabelPair, const SiStripDetInfo &detInfo)
Definition: SiStripGain.cc:17
const std::map< uint32_t, DetInfo > & getAllData() const noexcept
const Range getRange(const uint32_t detID) const
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:75