CMS 3D CMS Logo

AbsElectronicODERHS.h
Go to the documentation of this file.
1 #ifndef CalibCalorimetry_HcalAlgos_AbsElectronicODERHS_h_
2 #define CalibCalorimetry_HcalAlgos_AbsElectronicODERHS_h_
3 
4 #include <vector>
5 #include <climits>
6 #include <algorithm>
7 
10 
11 //
12 // Modeling of electronic circuits always involves an input pulse that
13 // determines the circuit output. This class adds an input pulse to
14 // AbsODERHS and establishes a uniform interface to circuit parameters.
15 //
17 public:
18  static const unsigned invalidNode = UINT_MAX - 1U;
19 
21 
23 
24  inline ~AbsElectronicODERHS() override {}
25 
26  inline const HcalInterpolatedPulse& inputPulse() const { return inputPulse_; }
27 
29 
30  template <class Pulse>
31  inline void setInputPulse(const Pulse& pulse) {
33  }
34 
35  // The following methods must be overriden by derived classes.
36  // Total number of nodes included in the simulation:
37  virtual unsigned numberOfNodes() const = 0;
38 
39  // The node which counts as "output" (preamp output in case
40  // of QIE8, which is not necessarily the node which accumulates
41  // the charge):
42  virtual unsigned outputNode() const = 0;
43 
44  // The node which counts as "control". If this method returns
45  // "invalidNode" then there is no such node in the circuit.
46  virtual unsigned controlNode() const { return invalidNode; }
47 
48  // The number of simulation parameters:
49  virtual unsigned nParameters() const = 0;
50 
51  // Check if all parameters have been set
52  inline bool allParametersSet() const {
53  // Raise "allSet_" flag if all parameters have been set
54  if (!allSet_) {
55  const unsigned nExpected = this->nParameters();
56  if (nExpected) {
57  if (paramMask_.size() != nExpected)
58  return false;
59  unsigned count = 0;
60  const unsigned char* mask = &paramMask_[0];
61  for (unsigned i = 0; i < nExpected; ++i)
62  count += mask[i];
63  allSet_ = count == nExpected;
64  } else
65  allSet_ = true;
66  }
67  return allSet_;
68  }
69 
70  inline void setParameter(const unsigned which, const double value) {
71  if (!initialized_)
72  initialize();
73  paramMask_.at(which) = 1;
74  params_[which] = value;
75  }
76 
77  inline double getParameter(const unsigned which) const {
78  if (!paramMask_.at(which))
79  throw cms::Exception(
80  "In AbsElectronicODERHS::getParameter: no such parameter or "
81  "parameter value is not established yet");
82  return params_[which];
83  }
84 
85  inline const std::vector<double>& getAllParameters() const {
86  if (!allParametersSet())
87  throw cms::Exception(
88  "In AbsElectronicODERHS::getAllParameters: "
89  "some parameter values were not established yet");
90  return params_;
91  }
92 
93  inline void setLeadingParameters(const double* values, const unsigned len) {
94  if (len) {
95  assert(values);
96  if (!initialized_)
97  initialize();
98  const unsigned sz = params_.size();
99  const unsigned imax = std::min(sz, len);
100  for (unsigned i = 0; i < imax; ++i) {
101  params_[i] = values[i];
102  paramMask_[i] = 1;
103  }
104  }
105  }
106 
107  inline void setLeadingParameters(const std::vector<double>& values) {
108  if (!values.empty())
109  setLeadingParameters(&values[0], values.size());
110  }
111 
112 protected:
114  std::vector<double> params_;
115 
116 private:
117  std::vector<unsigned char> paramMask_;
119  mutable bool allSet_;
120 
121  inline void initialize() {
122  const unsigned nExpected = this->nParameters();
123  if (nExpected) {
124  params_.resize(nExpected);
125  paramMask_.resize(nExpected);
126  for (unsigned i = 0; i < nExpected; ++i)
127  paramMask_[i] = 0;
128  }
129  initialized_ = true;
130  }
131 };
132 
133 #endif // CalibCalorimetry_HcalAlgos_AbsElectronicODERHS_h_
static const unsigned invalidNode
virtual unsigned numberOfNodes() const =0
double getParameter(const unsigned which) const
std::vector< double > params_
virtual unsigned outputNode() const =0
HcalInterpolatedPulse & inputPulse()
const std::vector< double > & getAllParameters() const
assert(be >=bs)
const HcalInterpolatedPulse & inputPulse() const
AbsElectronicODERHS(const HcalInterpolatedPulse &pulse)
void setLeadingParameters(const double *values, const unsigned len)
Definition: value.py:1
void setParameter(const unsigned which, const double value)
double pulse(double x, double y, double z, double t)
void setInputPulse(const Pulse &pulse)
std::vector< unsigned char > paramMask_
HcalInterpolatedPulse inputPulse_
virtual unsigned controlNode() const
virtual unsigned nParameters() const =0
def which(cmd)
Definition: eostools.py:336
void setLeadingParameters(const std::vector< double > &values)
bool allParametersSet() const