1 #ifndef CondFormats_HcalObjects_InterpolatedPulse_h_ 2 #define CondFormats_HcalObjects_InterpolatedPulse_h_ 7 #include "boost/serialization/access.hpp" 8 #include "boost/serialization/version.hpp" 10 template <
unsigned MaxLen>
12 template <
unsigned Len2>
25 if (length_ < 2 || length_ > MaxLen)
26 throw cms::Exception(
"In InterpolatedPulse constructor: invalid length");
32 if (length_ < 2 || length_ > MaxLen)
33 throw cms::Exception(
"In InterpolatedPulse constructor: invalid length");
35 throw cms::Exception(
"In InterpolatedPulse constructor: invalid pulse width");
39 template <
typename Real>
43 throw cms::Exception(
"In InterpolatedPulse constructor: invalid pulse width");
50 const double* rbuf = &
r.pulse_[0];
56 template <
unsigned Len2>
59 throw cms::Exception(
"In InterpolatedPulse copy constructor: buffer is not long enough");
61 const double* rbuf = &
r.pulse_[0];
73 const double* rbuf = &
r.pulse_[0];
81 template <
unsigned Len2>
83 if (
r.length_ > MaxLen)
84 throw cms::Exception(
"In InterpolatedPulse::operator=: buffer is not long enough");
89 const double* rbuf = &
r.pulse_[0];
95 template <
typename Real>
97 if (len < 2 || len > MaxLen)
98 throw cms::Exception(
"In InterpolatedPulse::setShape: invalid length");
102 for (
unsigned i = 0;
i < len; ++
i)
125 throw cms::Exception(
"In InterpolatedPulse::setPulseWidth: invalid pulse width");
132 if (t < tmin_ || t >
tmax)
137 unsigned nbelow = nSteps;
138 unsigned nabove = nbelow + 1;
141 nbelow = nabove - 1
U;
143 const double delta = nSteps - nbelow;
149 if (t < tmin_ || t >
tmax)
154 unsigned nbelow = nSteps;
155 unsigned nabove = nbelow + 1;
158 nbelow = nabove - 1
U;
160 const double delta = nSteps - nbelow;
161 if ((nbelow == 0
U &&
delta <= 0.5) || (nabove == lm1 &&
delta >= 0.5))
163 else if (
delta >= 0.5) {
182 unsigned nbelow = nSteps;
183 unsigned nabove = nbelow + 1;
186 nbelow = nabove - 1
U;
192 }
else if (nabove == lm1) {
199 const double delta = nSteps - nbelow;
200 return (lower * (1.0 -
delta) + upper *
delta) / stepSq;
216 template <
unsigned Len2>
224 template <
unsigned Len2>
229 const double* rbuf = &
r.pulse_[0];
231 if (*
buf++ != *rbuf++)
236 template <
unsigned Len2>
238 return !(*
this ==
r);
244 long double sum =
buf[0] / 2.0;
245 const unsigned nIntervals =
length_ - 1
U;
246 for (
unsigned i = 1
U;
i < nIntervals; ++
i)
248 sum +=
buf[nIntervals] / 2.0;
249 return sum *
width_ / nIntervals;
255 throw cms::Exception(
"In InterpolatedPulse::setIntegral division by zero");
256 *
this *= (newValue / integ);
261 double peak =
buf[0];
271 throw cms::Exception(
"In InterpolatedPulse::setPeakValue: division by zero");
272 *
this *= (newValue / peak);
281 friend class boost::serialization::access;
283 template <
class Archive>
290 throw cms::Exception(
"In InterpolatedPulse::serialize: buffer is not long enough");
299 namespace serialization {
300 template <
unsigned MaxLen>
302 BOOST_STATIC_CONSTANT(
int,
value = 1);
307 #endif // CondFormats_HcalObjects_InterpolatedPulse_h_
void setStartTime(const double newStartTime)
void serialize(Archive &ar, unsigned)
bool operator==(const InterpolatedPulse< Len2 > &r) const
double getStartTime() const
InterpolatedPulse & operator+=(const InterpolatedPulse< Len2 > &r)
void setShape(const Real *values, const unsigned len)
double getIntegral() const
double getTimeStep() const
InterpolatedPulse(const double tmin, const double tmax, const unsigned len)
double getPulseWidth() const
InterpolatedPulse(const double tmin, const double tmax, const Real *values, const unsigned len)
InterpolatedPulse & operator=(const InterpolatedPulse< Len2 > &r)
const double * getPulse() const
double operator()(const double t) const
InterpolatedPulse(const InterpolatedPulse< Len2 > &r)
static const double tmax[3]
double secondDerivative(const double t) const
InterpolatedPulse & operator=(const InterpolatedPulse &r)
double getPeakValue() const
InterpolatedPulse(const InterpolatedPulse &r)
InterpolatedPulse & operator*=(const double scale)
void setPeakValue(const double newValue)
bool operator!=(const InterpolatedPulse< Len2 > &r) const
double getStopTime() const
double derivative(const double t) const
void setPulseWidth(const double newWidth)
void setIntegral(const double newValue)
unsigned getLength() const
InterpolatedPulse(const unsigned len)