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 {
18 public:
19  static const unsigned invalidNode = UINT_MAX - 1U;
20 
22 
24  : inputPulse_(pulse) {}
25 
26  inline ~AbsElectronicODERHS() override {}
27 
28  inline const HcalInterpolatedPulse& inputPulse() const {return inputPulse_;}
29 
31 
32  template<class Pulse>
33  inline void setInputPulse(const Pulse& pulse) {inputPulse_ = pulse;}
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  {
54  // Raise "allSet_" flag if all parameters have been set
55  if (!allSet_)
56  {
57  const unsigned nExpected = this->nParameters();
58  if (nExpected)
59  {
60  if (paramMask_.size() != nExpected)
61  return false;
62  unsigned count = 0;
63  const unsigned char* mask = &paramMask_[0];
64  for (unsigned i=0; i<nExpected; ++i)
65  count += mask[i];
66  allSet_ = count == nExpected;
67  }
68  else
69  allSet_ = true;
70  }
71  return allSet_;
72  }
73 
74  inline void setParameter(const unsigned which, const double value)
75  {
76  if (!initialized_)
77  initialize();
78  paramMask_.at(which) = 1;
79  params_[which] = value;
80  }
81 
82  inline double getParameter(const unsigned which) const
83  {
84  if (!paramMask_.at(which)) throw cms::Exception(
85  "In AbsElectronicODERHS::getParameter: no such parameter or "
86  "parameter value is not established yet");
87  return params_[which];
88  }
89 
90  inline const std::vector<double>& getAllParameters() const
91  {
92  if (!allParametersSet()) throw cms::Exception(
93  "In AbsElectronicODERHS::getAllParameters: "
94  "some parameter values were not established yet");
95  return params_;
96  }
97 
98  inline void setLeadingParameters(const double* values, const unsigned len)
99  {
100  if (len)
101  {
102  assert(values);
103  if (!initialized_)
104  initialize();
105  const unsigned sz = params_.size();
106  const unsigned imax = std::min(sz, len);
107  for (unsigned i=0; i<imax; ++i)
108  {
109  params_[i] = values[i];
110  paramMask_[i] = 1;
111  }
112  }
113  }
114 
115  inline void setLeadingParameters(const std::vector<double>& values)
116  {
117  if (!values.empty())
118  setLeadingParameters(&values[0], values.size());
119  }
120 
121 protected:
123  std::vector<double> params_;
124 
125 private:
126  std::vector<unsigned char> paramMask_;
128  mutable bool allSet_;
129 
130  inline void initialize()
131  {
132  const unsigned nExpected = this->nParameters();
133  if (nExpected)
134  {
135  params_.resize(nExpected);
136  paramMask_.resize(nExpected);
137  for (unsigned i=0; i<nExpected; ++i)
138  paramMask_[i] = 0;
139  }
140  initialized_ = true;
141  }
142 };
143 
144 #endif // CalibCalorimetry_HcalAlgos_AbsElectronicODERHS_h_
virtual unsigned numberOfNodes() const =0
static const unsigned invalidNode
virtual unsigned nParameters() const =0
std::vector< double > params_
HcalInterpolatedPulse & inputPulse()
virtual unsigned outputNode() const =0
const HcalInterpolatedPulse & inputPulse() const
virtual unsigned controlNode() const
double getParameter(const unsigned which) const
AbsElectronicODERHS(const HcalInterpolatedPulse &pulse)
void setLeadingParameters(const double *values, const unsigned len)
Definition: value.py:1
T min(T a, T b)
Definition: MathUtil.h:58
void setParameter(const unsigned which, const double value)
const std::vector< double > & getAllParameters() const
double pulse(double x, double y, double z, double t)
void setInputPulse(const Pulse &pulse)
std::vector< unsigned char > paramMask_
HcalInterpolatedPulse inputPulse_
bool allParametersSet() const
def which(cmd)
Definition: eostools.py:335
void setLeadingParameters(const std::vector< double > &values)