CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripGainFactor.h
Go to the documentation of this file.
1 #ifndef CalibTracker_SiStripESProducers_SiStripGainFactor_h
2 #define CalibTracker_SiStripESProducers_SiStripGainFactor_h
3 
6 
8 
10 public:
12  : automaticMode_{iConfig.getParameter<bool>("AutomaticNormalization")},
13  printdebug_{iConfig.getUntrackedParameter<bool>("printDebug", false)} {}
14 
15  void push_back_norm(double norm) { norm_.push_back(norm); }
16 
17  void resetIfBadNorm() {
18  bool badNorm = std::find_if(norm_.begin(), norm_.end(), [](double x) { return x <= 0.; }) != norm_.end();
19 
20  if (!automaticMode_ && badNorm) {
21  edm::LogError("SiStripGainESProducer") << "[SiStripGainESProducer] - ERROR: negative or zero Normalization "
22  "factor provided. Assuming 1 for such factor"
23  << std::endl;
24  norm_ = std::vector<double>(norm_.size(), 1.);
25  }
26  }
27 
28  double get(const SiStripApvGain& gain, const int apvGainIndex) const {
29  double NFactor = 0.;
30 
31  if (automaticMode_ || printdebug_) {
32  std::vector<uint32_t> DetIds;
33  gain.getDetIds(DetIds);
34 
35  double SumOfGains = 0.;
36  int NGains = 0;
37  for (uint32_t detid : DetIds) {
38  SiStripApvGain::Range detRange = gain.getRange(detid);
39 
40  int iComp = 0;
41  for (std::vector<float>::const_iterator apvit = detRange.first; apvit != detRange.second; apvit++) {
42  SumOfGains += (*apvit);
43  NGains++;
44  if (printdebug_)
45  edm::LogInfo("SiStripGainESProducer::produce()")
46  << "detid/component: " << detid << "/" << iComp << " gain factor " << *apvit;
47  iComp++;
48  }
49  }
50 
51  if (automaticMode_) {
52  if (SumOfGains > 0 && NGains > 0) {
53  NFactor = SumOfGains / NGains;
54  } else {
56  "SiStripGainESProducer::produce() - ERROR: empty set of gain values received. Cannot compute "
57  "normalization factor. Assuming 1 for such factor")
58  << std::endl;
59  NFactor = 1.;
60  }
61  }
62  }
63 
64  if (!automaticMode_) {
65  NFactor = norm_[apvGainIndex];
66  }
67 
68  if (printdebug_)
69  edm::LogInfo("SiStripGainESProducer")
70  << " putting A SiStrip Gain object in eventSetup with normalization factor " << NFactor;
71  return NFactor;
72  }
73 
74 private:
75  std::vector<double> norm_;
78 };
79 
80 #endif
T getUntrackedParameter(std::string const &, T const &) const
SiStripGainFactor(const edm::ParameterSet &iConfig)
Log< level::Error, false > LogError
void push_back_norm(double norm)
std::pair< ContainerIterator, ContainerIterator > Range
Log< level::Info, false > LogInfo
constexpr int NGains
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< double > norm_