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>
32 "In InterpolatedPulse constructor: invalid length");
41 "In InterpolatedPulse constructor: invalid length");
43 "In InterpolatedPulse constructor: invalid pulse width");
47 template <
typename Real>
53 "In InterpolatedPulse constructor: invalid pulse width");
62 const double* rbuf = &r.
pulse_[0];
68 template <
unsigned Len2>
73 "In InterpolatedPulse copy constructor: buffer is not long enough");
75 const double* rbuf = &r.
pulse_[0];
89 const double* rbuf = &r.
pulse_[0];
97 template <
unsigned Len2>
101 "In InterpolatedPulse::operator=: buffer is not long enough");
106 const double* rbuf = &r.
pulse_[0];
112 template <
typename Real>
116 "In InterpolatedPulse::setShape: invalid length");
120 for (
unsigned i=0;
i<len; ++
i)
141 {
tmin_ = newStartTime;}
146 "In InterpolatedPulse::setPulseWidth: invalid pulse width");
154 if (t < tmin_ || t > tmax)
157 const double step = width_/lm1;
158 const double nSteps = (t -
tmin_)/step;
159 unsigned nbelow = nSteps;
160 unsigned nabove = nbelow + 1;
164 nbelow = nabove - 1
U;
166 const double delta = nSteps - nbelow;
173 if (t < tmin_ || t > tmax)
176 const double step = width_/lm1;
177 const double nSteps = (t -
tmin_)/step;
178 unsigned nbelow = nSteps;
179 unsigned nabove = nbelow + 1;
183 nbelow = nabove - 1
U;
185 const double delta = nSteps - nbelow;
186 if ((nbelow == 0U && delta <= 0.5) || (nabove == lm1 && delta >= 0.5))
188 else if (delta >= 0.5)
191 const double upper = pulse_[nabove+1
U] - pulse_[nabove];
192 return (upper*(delta - 0.5) + lower*(1.5 -
delta))/
step;
197 const double upper = pulse_[nabove] - pulse_[nbelow];
198 return (lower*(0.5 - delta) + upper*(0.5 +
delta))/
step;
205 if (t < tmin_ || t > tmax ||
length_ < 3
U)
208 const double step = width_/lm1;
209 const double stepSq = step*
step;
210 const double nSteps = (t -
tmin_)/step;
211 unsigned nbelow = nSteps;
212 unsigned nabove = nbelow + 1;
216 nbelow = nabove - 1
U;
224 else if (nabove == lm1)
233 const double upper = pulse_[nbelow] - 2.0*pulse_[nabove] + pulse_[nabove+1
U];
234 const double delta = nSteps - nbelow;
235 return (lower*(1.0 - delta) + upper*
delta)/stepSq;
253 template <
unsigned Len2>
262 template <
unsigned Len2>
267 const double* buf = &
pulse_[0];
268 const double* rbuf = &r.
pulse_[0];
270 if (*buf++ != *rbuf++)
275 template <
unsigned Len2>
277 {
return !(*
this ==
r);}
282 const double* buf = &
pulse_[0];
283 long double sum = buf[0]/2.0;
284 const unsigned nIntervals =
length_ - 1
U;
285 for (
unsigned i=1U;
i<nIntervals; ++
i)
287 sum += buf[nIntervals]/2.0;
288 return sum*
width_/nIntervals;
295 "In InterpolatedPulse::setIntegral division by zero");
296 *
this *= (newValue/integ);
301 const double* buf = &
pulse_[0];
302 double peak = buf[0];
313 "In InterpolatedPulse::setPeakValue: division by zero");
314 *
this *= (newValue/peak);
323 friend class boost::serialization::access;
325 template<
class Archive>
333 "In InterpolatedPulse::serialize: buffer is not long enough");
342 namespace serialization {
343 template<
unsigned MaxLen>
346 BOOST_STATIC_CONSTANT(
int,
value = 1);
351 #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)