CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
InterpolatedPulse< MaxLen > Class Template Reference

#include <InterpolatedPulse.h>

Public Types

enum  { maxlen = MaxLen }
 

Public Member Functions

double derivative (const double t) const
 
double getIntegral () const
 
unsigned getLength () const
 
double getPeakValue () const
 
const double * getPulse () const
 
double getPulseWidth () const
 
double getStartTime () const
 
double getStopTime () const
 
double getTimeStep () const
 
 InterpolatedPulse ()
 
 InterpolatedPulse (const unsigned len)
 
 InterpolatedPulse (const double tmin, const double tmax, const unsigned len)
 
template<typename Real >
 InterpolatedPulse (const double tmin, const double tmax, const Real *values, const unsigned len)
 
 InterpolatedPulse (const InterpolatedPulse &r)
 
template<unsigned Len2>
 InterpolatedPulse (const InterpolatedPulse< Len2 > &r)
 
template<unsigned Len2>
bool operator!= (const InterpolatedPulse< Len2 > &r) const
 
double operator() (const double t) const
 
InterpolatedPulseoperator*= (const double scale)
 
template<unsigned Len2>
InterpolatedPulseoperator+= (const InterpolatedPulse< Len2 > &r)
 
InterpolatedPulseoperator= (const InterpolatedPulse &r)
 
template<unsigned Len2>
InterpolatedPulseoperator= (const InterpolatedPulse< Len2 > &r)
 
template<unsigned Len2>
bool operator== (const InterpolatedPulse< Len2 > &r) const
 
double secondDerivative (const double t) const
 
void setIntegral (const double newValue)
 
void setPeakValue (const double newValue)
 
void setPulseWidth (const double newWidth)
 
template<typename Real >
void setShape (const Real *values, const unsigned len)
 
void setStartTime (const double newStartTime)
 
void zeroOut ()
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar, unsigned)
 

Private Attributes

unsigned length_
 
double pulse_ [MaxLen]
 
double tmin_
 
double width_
 

Friends

class boost::serialization::access
 
template<unsigned Len2>
class InterpolatedPulse
 

Detailed Description

template<unsigned MaxLen>
class InterpolatedPulse< MaxLen >

Definition at line 11 of file InterpolatedPulse.h.

Member Enumeration Documentation

template<unsigned MaxLen>
anonymous enum
Enumerator
maxlen 

Definition at line 17 of file InterpolatedPulse.h.

Constructor & Destructor Documentation

template<unsigned MaxLen>
InterpolatedPulse< MaxLen >::InterpolatedPulse ( )
inline
template<unsigned MaxLen>
InterpolatedPulse< MaxLen >::InterpolatedPulse ( const unsigned  len)
inlineexplicit

Definition at line 24 of file InterpolatedPulse.h.

24  : tmin_(0.0), width_(1.0), length_(len) {
25  if (length_ < 2 || length_ > MaxLen)
26  throw cms::Exception("In InterpolatedPulse constructor: invalid length");
27  zeroOut();
28  }
template<unsigned MaxLen>
InterpolatedPulse< MaxLen >::InterpolatedPulse ( const double  tmin,
const double  tmax,
const unsigned  len 
)
inline

Definition at line 30 of file InterpolatedPulse.h.

31  : tmin_(tmin), width_(tmax - tmin), length_(len) {
32  if (length_ < 2 || length_ > MaxLen)
33  throw cms::Exception("In InterpolatedPulse constructor: invalid length");
34  if (width_ <= 0.0)
35  throw cms::Exception("In InterpolatedPulse constructor: invalid pulse width");
36  zeroOut();
37  }
static const double tmax[3]
template<unsigned MaxLen>
template<typename Real >
InterpolatedPulse< MaxLen >::InterpolatedPulse ( const double  tmin,
const double  tmax,
const Real *  values,
const unsigned  len 
)
inline

Definition at line 40 of file InterpolatedPulse.h.

41  : tmin_(tmin), width_(tmax - tmin) {
42  if (width_ <= 0.0)
43  throw cms::Exception("In InterpolatedPulse constructor: invalid pulse width");
44  setShape(values, len);
45  }
void setShape(const Real *values, const unsigned len)
static const double tmax[3]
template<unsigned MaxLen>
InterpolatedPulse< MaxLen >::InterpolatedPulse ( const InterpolatedPulse< MaxLen > &  r)
inline

Definition at line 48 of file InterpolatedPulse.h.

48  : tmin_(r.tmin_), width_(r.width_), length_(r.length_) {
49  double* buf = &pulse_[0];
50  const double* rbuf = &r.pulse_[0];
51  for (unsigned i = 0; i < length_; ++i)
52  *buf++ = *rbuf++;
53  }
double pulse_[MaxLen]
template<unsigned MaxLen>
template<unsigned Len2>
InterpolatedPulse< MaxLen >::InterpolatedPulse ( const InterpolatedPulse< Len2 > &  r)
inline

Definition at line 57 of file InterpolatedPulse.h.

57  : tmin_(r.tmin_), width_(r.width_), length_(r.length_) {
58  if (length_ > MaxLen)
59  throw cms::Exception("In InterpolatedPulse copy constructor: buffer is not long enough");
60  double* buf = &pulse_[0];
61  const double* rbuf = &r.pulse_[0];
62  for (unsigned i = 0; i < length_; ++i)
63  *buf++ = *rbuf++;
64  }
double pulse_[MaxLen]

Member Function Documentation

template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::derivative ( const double  t) const
inline

Definition at line 147 of file InterpolatedPulse.h.

Referenced by DoublePadeDelay< ODE1, ODE2, DelayTimeModel1, DelayTimeModel2 >::calc().

147  {
148  const volatile double tmax = tmin_ + width_;
149  if (t < tmin_ || t > tmax)
150  return 0.0;
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;
156  if (nabove > lm1) {
157  nabove = lm1;
158  nbelow = nabove - 1U;
159  }
160  const double delta = nSteps - nbelow;
161  if ((nbelow == 0U && delta <= 0.5) || (nabove == lm1 && delta >= 0.5))
162  return (pulse_[nabove] - pulse_[nbelow]) / step;
163  else if (delta >= 0.5) {
164  const double lower = pulse_[nabove] - pulse_[nbelow];
165  const double upper = pulse_[nabove + 1U] - pulse_[nabove];
166  return (upper * (delta - 0.5) + lower * (1.5 - delta)) / step;
167  } else {
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;
171  }
172  }
double pulse_[MaxLen]
static const double tmax[3]
step
Definition: StallMonitor.cc:94
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::getIntegral ( ) const
inline

Definition at line 242 of file InterpolatedPulse.h.

Referenced by QIE8Simulator::getInputIntegral(), and InterpolatedPulse< 1500U >::setIntegral().

242  {
243  const double* buf = &pulse_[0];
244  long double sum = buf[0] / 2.0;
245  const unsigned nIntervals = length_ - 1U;
246  for (unsigned i = 1U; i < nIntervals; ++i)
247  sum += buf[i];
248  sum += buf[nIntervals] / 2.0;
249  return sum * width_ / nIntervals;
250  }
double pulse_[MaxLen]
template<unsigned MaxLen>
unsigned InterpolatedPulse< MaxLen >::getLength ( ) const
inline

Definition at line 114 of file InterpolatedPulse.h.

114 { return length_; }
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::getPeakValue ( ) const
inline

Definition at line 259 of file InterpolatedPulse.h.

Referenced by QIE8Simulator::getInputAmplitude(), and InterpolatedPulse< 1500U >::setPeakValue().

259  {
260  const double* buf = &pulse_[0];
261  double peak = buf[0];
262  for (unsigned i = 1U; i < length_; ++i)
263  if (buf[i] > peak)
264  peak = buf[i];
265  return peak;
266  }
double pulse_[MaxLen]
template<unsigned MaxLen>
const double* InterpolatedPulse< MaxLen >::getPulse ( ) const
inline

Definition at line 113 of file InterpolatedPulse.h.

113 { return &pulse_[0]; }
double pulse_[MaxLen]
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::getPulseWidth ( ) const
inline

Definition at line 117 of file InterpolatedPulse.h.

117 { return width_; }
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::getStartTime ( ) const
inline

Definition at line 115 of file InterpolatedPulse.h.

Referenced by QIE8Simulator::getInputStartTime().

115 { return tmin_; }
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::getStopTime ( ) const
inline

Definition at line 116 of file InterpolatedPulse.h.

116 { return tmin_ + width_; }
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::getTimeStep ( ) const
inline

Definition at line 118 of file InterpolatedPulse.h.

template<unsigned MaxLen>
template<unsigned Len2>
bool InterpolatedPulse< MaxLen >::operator!= ( const InterpolatedPulse< Len2 > &  r) const
inline

Definition at line 237 of file InterpolatedPulse.h.

237  {
238  return !(*this == r);
239  }
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::operator() ( const double  t) const
inline

Definition at line 130 of file InterpolatedPulse.h.

130  {
131  const volatile double tmax = tmin_ + width_;
132  if (t < tmin_ || t > tmax)
133  return 0.0;
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;
139  if (nabove > lm1) {
140  nabove = lm1;
141  nbelow = nabove - 1U;
142  }
143  const double delta = nSteps - nbelow;
144  return pulse_[nbelow] * (1.0 - delta) + pulse_[nabove] * delta;
145  }
double pulse_[MaxLen]
static const double tmax[3]
step
Definition: StallMonitor.cc:94
template<unsigned MaxLen>
InterpolatedPulse& InterpolatedPulse< MaxLen >::operator*= ( const double  scale)
inline

Definition at line 204 of file InterpolatedPulse.h.

204  {
205  if (scale != 1.0) {
206  double* buf = &pulse_[0];
207  for (unsigned i = 0; i < length_; ++i)
208  *buf++ *= scale;
209  }
210  return *this;
211  }
double pulse_[MaxLen]
template<unsigned MaxLen>
template<unsigned Len2>
InterpolatedPulse& InterpolatedPulse< MaxLen >::operator+= ( const InterpolatedPulse< Len2 > &  r)
inline

Definition at line 217 of file InterpolatedPulse.h.

217  {
218  const double step = width_ / (length_ - 1U);
219  for (unsigned i = 0; i < length_; ++i)
220  pulse_[i] += r(tmin_ + i * step);
221  return *this;
222  }
double pulse_[MaxLen]
step
Definition: StallMonitor.cc:94
template<unsigned MaxLen>
InterpolatedPulse& InterpolatedPulse< MaxLen >::operator= ( const InterpolatedPulse< MaxLen > &  r)
inline

Definition at line 67 of file InterpolatedPulse.h.

67  {
68  if (this != &r) {
69  tmin_ = r.tmin_;
70  width_ = r.width_;
71  length_ = r.length_;
72  double* buf = &pulse_[0];
73  const double* rbuf = &r.pulse_[0];
74  for (unsigned i = 0; i < length_; ++i)
75  *buf++ = *rbuf++;
76  }
77  return *this;
78  }
double pulse_[MaxLen]
template<unsigned MaxLen>
template<unsigned Len2>
InterpolatedPulse& InterpolatedPulse< MaxLen >::operator= ( const InterpolatedPulse< Len2 > &  r)
inline

Definition at line 82 of file InterpolatedPulse.h.

82  {
83  if (r.length_ > MaxLen)
84  throw cms::Exception("In InterpolatedPulse::operator=: buffer is not long enough");
85  tmin_ = r.tmin_;
86  width_ = r.width_;
87  length_ = r.length_;
88  double* buf = &pulse_[0];
89  const double* rbuf = &r.pulse_[0];
90  for (unsigned i = 0; i < length_; ++i)
91  *buf++ = *rbuf++;
92  return *this;
93  }
double pulse_[MaxLen]
template<unsigned MaxLen>
template<unsigned Len2>
bool InterpolatedPulse< MaxLen >::operator== ( const InterpolatedPulse< Len2 > &  r) const
inline

Definition at line 225 of file InterpolatedPulse.h.

225  {
226  if (!(tmin_ == r.tmin_ && width_ == r.width_ && length_ == r.length_))
227  return false;
228  const double* buf = &pulse_[0];
229  const double* rbuf = &r.pulse_[0];
230  for (unsigned i = 0; i < length_; ++i)
231  if (*buf++ != *rbuf++)
232  return false;
233  return true;
234  }
double pulse_[MaxLen]
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::secondDerivative ( const double  t) const
inline

Definition at line 174 of file InterpolatedPulse.h.

Referenced by DoublePadeDelay< ODE1, ODE2, DelayTimeModel1, DelayTimeModel2 >::calc().

174  {
175  const volatile double tmax = tmin_ + width_;
176  if (t < tmin_ || t > tmax || length_ < 3U)
177  return 0.0;
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;
184  if (nabove > lm1) {
185  nabove = lm1;
186  nbelow = nabove - 1U;
187  }
188 
189  if (nbelow == 0U) {
190  // The first interval
191  return (pulse_[2] - 2.0 * pulse_[1] + pulse_[0]) / stepSq;
192  } else if (nabove == lm1) {
193  // The last interval
194  return (pulse_[lm1] - 2.0 * pulse_[lm1 - 1U] + pulse_[lm1 - 2U]) / stepSq;
195  } else {
196  // One of the middle intervals
197  const double lower = pulse_[nbelow - 1U] - 2.0 * pulse_[nbelow] + pulse_[nabove];
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;
201  }
202  }
double pulse_[MaxLen]
static const double tmax[3]
step
Definition: StallMonitor.cc:94
template<unsigned MaxLen>
template<class Archive >
void InterpolatedPulse< MaxLen >::serialize ( Archive &  ar,
unsigned   
)
inlineprivate

Definition at line 284 of file InterpolatedPulse.h.

284  {
285  ar& tmin_& width_& length_;
286 
287  // In case we are reading, it may be useful to verify
288  // that the length is reasonable
289  if (length_ > MaxLen)
290  throw cms::Exception("In InterpolatedPulse::serialize: buffer is not long enough");
291 
292  for (unsigned i = 0; i < length_; ++i)
293  ar& pulse_[i];
294  }
double pulse_[MaxLen]
template<unsigned MaxLen>
void InterpolatedPulse< MaxLen >::setIntegral ( const double  newValue)
inline

Definition at line 252 of file InterpolatedPulse.h.

Referenced by QIE8Simulator::setInputIntegral().

252  {
253  const double integ = this->getIntegral();
254  if (integ == 0.0)
255  throw cms::Exception("In InterpolatedPulse::setIntegral division by zero");
256  *this *= (newValue / integ);
257  }
double getIntegral() const
template<unsigned MaxLen>
void InterpolatedPulse< MaxLen >::setPeakValue ( const double  newValue)
inline

Definition at line 268 of file InterpolatedPulse.h.

Referenced by QIE8Simulator::setInputAmplitude().

268  {
269  const double peak = this->getPeakValue();
270  if (peak == 0.0)
271  throw cms::Exception("In InterpolatedPulse::setPeakValue: division by zero");
272  *this *= (newValue / peak);
273  }
double getPeakValue() const
template<unsigned MaxLen>
void InterpolatedPulse< MaxLen >::setPulseWidth ( const double  newWidth)
inline

Definition at line 123 of file InterpolatedPulse.h.

123  {
124  if (newWidth <= 0.0)
125  throw cms::Exception("In InterpolatedPulse::setPulseWidth: invalid pulse width");
126  width_ = newWidth;
127  }
template<unsigned MaxLen>
template<typename Real >
void InterpolatedPulse< MaxLen >::setShape ( const Real *  values,
const unsigned  len 
)
inline

Definition at line 96 of file InterpolatedPulse.h.

Referenced by InterpolatedPulse< 1500U >::InterpolatedPulse(), and QIE8Simulator::setInputShape().

96  {
97  if (len < 2 || len > MaxLen)
98  throw cms::Exception("In InterpolatedPulse::setShape: invalid length");
99  assert(values);
100  length_ = len;
101  double* buf = &pulse_[0];
102  for (unsigned i = 0; i < len; ++i)
103  *buf++ = *values++;
104  }
double pulse_[MaxLen]
template<unsigned MaxLen>
void InterpolatedPulse< MaxLen >::setStartTime ( const double  newStartTime)
inline

Definition at line 121 of file InterpolatedPulse.h.

Referenced by QIE8Simulator::setInputStartTime().

121 { tmin_ = newStartTime; }
template<unsigned MaxLen>
void InterpolatedPulse< MaxLen >::zeroOut ( )
inline

Definition at line 107 of file InterpolatedPulse.h.

Referenced by InterpolatedPulse< 1500U >::InterpolatedPulse().

107  {
108  for (unsigned i = 0; i < length_; ++i)
109  pulse_[i] = 0.0;
110  }
double pulse_[MaxLen]

Friends And Related Function Documentation

template<unsigned MaxLen>
friend class boost::serialization::access
friend

Definition at line 281 of file InterpolatedPulse.h.

template<unsigned MaxLen>
template<unsigned Len2>
friend class InterpolatedPulse
friend

Definition at line 13 of file InterpolatedPulse.h.

Member Data Documentation

template<unsigned MaxLen>
unsigned InterpolatedPulse< MaxLen >::length_
private
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::pulse_[MaxLen]
private
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::tmin_
private
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::width_
private