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_
AbsElectronicODERHS::allSet_
bool allSet_
Definition: AbsElectronicODERHS.h:119
mps_fire.i
i
Definition: mps_fire.py:355
funct::false
false
Definition: Factorize.h:34
AbsElectronicODERHS::inputPulse
HcalInterpolatedPulse & inputPulse()
Definition: AbsElectronicODERHS.h:28
min
T min(T a, T b)
Definition: MathUtil.h:58
AbsElectronicODERHS::controlNode
virtual unsigned controlNode() const
Definition: AbsElectronicODERHS.h:46
AbsElectronicODERHS::getAllParameters
const std::vector< double > & getAllParameters() const
Definition: AbsElectronicODERHS.h:85
AbsElectronicODERHS::AbsElectronicODERHS
AbsElectronicODERHS()
Definition: AbsElectronicODERHS.h:20
pulse
double pulse(double x, double y, double z, double t)
Definition: SiStripPulseShape.cc:49
cms::cuda::assert
assert(be >=bs)
AbsElectronicODERHS::setParameter
void setParameter(const unsigned which, const double value)
Definition: AbsElectronicODERHS.h:70
AbsElectronicODERHS::initialized_
bool initialized_
Definition: AbsElectronicODERHS.h:118
AbsElectronicODERHS::params_
std::vector< double > params_
Definition: AbsElectronicODERHS.h:114
AbsElectronicODERHS::AbsElectronicODERHS
AbsElectronicODERHS(const HcalInterpolatedPulse &pulse)
Definition: AbsElectronicODERHS.h:22
AbsElectronicODERHS::outputNode
virtual unsigned outputNode() const =0
AbsElectronicODERHS
Definition: AbsElectronicODERHS.h:16
AbsODERHS.h
AbsElectronicODERHS::setInputPulse
void setInputPulse(const Pulse &pulse)
Definition: AbsElectronicODERHS.h:31
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
AbsElectronicODERHS::initialize
void initialize()
Definition: AbsElectronicODERHS.h:121
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
AbsODERHS
Definition: AbsODERHS.h:7
AbsElectronicODERHS::nParameters
virtual unsigned nParameters() const =0
AbsElectronicODERHS::numberOfNodes
virtual unsigned numberOfNodes() const =0
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
AbsElectronicODERHS::paramMask_
std::vector< unsigned char > paramMask_
Definition: AbsElectronicODERHS.h:117
value
Definition: value.py:1
AbsElectronicODERHS::allParametersSet
bool allParametersSet() const
Definition: AbsElectronicODERHS.h:52
HcalInterpolatedPulse.h
InterpolatedPulse< 1500U >
relativeConstraints.value
value
Definition: relativeConstraints.py:53
Exception
Definition: hltDiff.cc:246
AbsElectronicODERHS::setLeadingParameters
void setLeadingParameters(const std::vector< double > &values)
Definition: AbsElectronicODERHS.h:107
AbsElectronicODERHS::inputPulse_
HcalInterpolatedPulse inputPulse_
Definition: AbsElectronicODERHS.h:113
cms::Exception
Definition: Exception.h:70
AbsElectronicODERHS::inputPulse
const HcalInterpolatedPulse & inputPulse() const
Definition: AbsElectronicODERHS.h:26
AbsElectronicODERHS::getParameter
double getParameter(const unsigned which) const
Definition: AbsElectronicODERHS.h:77
eostools.which
def which(cmd)
Definition: eostools.py:336
AbsElectronicODERHS::~AbsElectronicODERHS
~AbsElectronicODERHS() override
Definition: AbsElectronicODERHS.h:24
AbsElectronicODERHS::setLeadingParameters
void setLeadingParameters(const double *values, const unsigned len)
Definition: AbsElectronicODERHS.h:93
AbsElectronicODERHS::invalidNode
static const unsigned invalidNode
Definition: AbsElectronicODERHS.h:18