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>
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)
134 const unsigned lm1 =
length_ - 1U;
135 const double step = width_ / lm1;
136 const double nSteps = (t -
tmin_) / step;
137 unsigned nbelow = nSteps;
138 unsigned nabove = nbelow + 1;
141 nbelow = nabove - 1U;
143 const double delta = nSteps - nbelow;
149 if (t < tmin_ || t > tmax)
151 const unsigned lm1 =
length_ - 1U;
152 const double step = width_ / lm1;
153 const double nSteps = (t -
tmin_) / step;
154 unsigned nbelow = nSteps;
155 unsigned nabove = nbelow + 1;
158 nbelow = nabove - 1U;
160 const double delta = nSteps - nbelow;
161 if ((nbelow == 0U && delta <= 0.5) || (nabove == lm1 && delta >= 0.5))
163 else if (delta >= 0.5) {
165 const double upper = pulse_[nabove + 1U] - pulse_[nabove];
166 return (upper * (delta - 0.5) + lower * (1.5 -
delta)) /
step;
168 const double lower =
pulse_[nbelow] -
pulse_[nbelow - 1U];
169 const double upper = pulse_[nabove] - pulse_[nbelow];
170 return (lower * (0.5 - delta) + upper * (0.5 +
delta)) /
step;
176 if (t < tmin_ || t > tmax ||
length_ < 3U)
178 const unsigned lm1 =
length_ - 1U;
179 const double step = width_ / lm1;
180 const double stepSq = step *
step;
181 const double nSteps = (t -
tmin_) / step;
182 unsigned nbelow = nSteps;
183 unsigned nabove = nbelow + 1;
186 nbelow = nabove - 1U;
192 }
else if (nabove == lm1) {
198 const double upper = pulse_[nbelow] - 2.0 * pulse_[nabove] + pulse_[nabove + 1U];
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_ - 1U;
246 for (
unsigned i = 1U;
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>
289 if (length_ > MaxLen)
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_
bool operator!=(const InterpolatedPulse< Len2 > &r) const
void setStartTime(const double newStartTime)
void serialize(Archive &ar, unsigned)
double getIntegral() const
double secondDerivative(const double t) const
InterpolatedPulse & operator+=(const InterpolatedPulse< Len2 > &r)
void setShape(const Real *values, const unsigned len)
InterpolatedPulse(const double tmin, const double tmax, const unsigned len)
InterpolatedPulse(const double tmin, const double tmax, const Real *values, const unsigned len)
const double * getPulse() const
double getPeakValue() const
InterpolatedPulse & operator=(const InterpolatedPulse< Len2 > &r)
double operator()(const double t) const
double getStartTime() const
InterpolatedPulse(const InterpolatedPulse< Len2 > &r)
double getStopTime() const
static const double tmax[3]
InterpolatedPulse & operator=(const InterpolatedPulse &r)
bool operator==(const InterpolatedPulse< Len2 > &r) const
double getTimeStep() const
double getPulseWidth() const
InterpolatedPulse(const InterpolatedPulse &r)
InterpolatedPulse & operator*=(const double scale)
unsigned getLength() const
void setPeakValue(const double newValue)
double derivative(const double t) const
void setPulseWidth(const double newWidth)
void setIntegral(const double newValue)
InterpolatedPulse(const unsigned len)