CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

Definition at line 20 of file InterpolatedPulse.h.

21  : tmin_(0.0), width_(1.0), length_(2U)
22  {
23  zeroOut();
24  }
template<unsigned MaxLen>
InterpolatedPulse< MaxLen >::InterpolatedPulse ( const unsigned  len)
inlineexplicit

Definition at line 28 of file InterpolatedPulse.h.

29  : tmin_(0.0), width_(1.0), length_(len)
30  {
31  if (length_ < 2 || length_ > MaxLen) throw cms::Exception(
32  "In InterpolatedPulse constructor: invalid length");
33  zeroOut();
34  }
template<unsigned MaxLen>
InterpolatedPulse< MaxLen >::InterpolatedPulse ( const double  tmin,
const double  tmax,
const unsigned  len 
)
inline

Definition at line 36 of file InterpolatedPulse.h.

38  : tmin_(tmin), width_(tmax - tmin), length_(len)
39  {
40  if (length_ < 2 || length_ > MaxLen) throw cms::Exception(
41  "In InterpolatedPulse constructor: invalid length");
42  if (width_ <= 0.0) throw cms::Exception(
43  "In InterpolatedPulse constructor: invalid pulse width");
44  zeroOut();
45  }
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 48 of file InterpolatedPulse.h.

50  : tmin_(tmin), width_(tmax - tmin)
51  {
52  if (width_ <= 0.0) throw cms::Exception(
53  "In InterpolatedPulse constructor: invalid pulse width");
54  setShape(values, len);
55  }
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 58 of file InterpolatedPulse.h.

59  : tmin_(r.tmin_), width_(r.width_), length_(r.length_)
60  {
61  double* buf = &pulse_[0];
62  const double* rbuf = &r.pulse_[0];
63  for (unsigned i=0; i<length_; ++i)
64  *buf++ = *rbuf++;
65  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]
template<unsigned MaxLen>
template<unsigned Len2>
InterpolatedPulse< MaxLen >::InterpolatedPulse ( const InterpolatedPulse< Len2 > &  r)
inline

Definition at line 69 of file InterpolatedPulse.h.

70  : tmin_(r.tmin_), width_(r.width_), length_(r.length_)
71  {
72  if (length_ > MaxLen) throw cms::Exception(
73  "In InterpolatedPulse copy constructor: buffer is not long enough");
74  double* buf = &pulse_[0];
75  const double* rbuf = &r.pulse_[0];
76  for (unsigned i=0; i<length_; ++i)
77  *buf++ = *rbuf++;
78  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]

Member Function Documentation

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

Definition at line 170 of file InterpolatedPulse.h.

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

171  {
172  const volatile double tmax = tmin_ + width_;
173  if (t < tmin_ || t > tmax)
174  return 0.0;
175  const unsigned lm1 = length_ - 1U;
176  const double step = width_/lm1;
177  const double nSteps = (t - tmin_)/step;
178  unsigned nbelow = nSteps;
179  unsigned nabove = nbelow + 1;
180  if (nabove > lm1)
181  {
182  nabove = lm1;
183  nbelow = nabove - 1U;
184  }
185  const double delta = nSteps - nbelow;
186  if ((nbelow == 0U && delta <= 0.5) || (nabove == lm1 && delta >= 0.5))
187  return (pulse_[nabove] - pulse_[nbelow])/step;
188  else if (delta >= 0.5)
189  {
190  const double lower = pulse_[nabove] - pulse_[nbelow];
191  const double upper = pulse_[nabove+1U] - pulse_[nabove];
192  return (upper*(delta - 0.5) + lower*(1.5 - delta))/step;
193  }
194  else
195  {
196  const double lower = pulse_[nbelow] - pulse_[nbelow-1U];
197  const double upper = pulse_[nabove] - pulse_[nbelow];
198  return (lower*(0.5 - delta) + upper*(0.5 + delta))/step;
199  }
200  }
dbl * delta
Definition: mlp_gen.cc:36
double pulse_[MaxLen]
static const double tmax[3]
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::getIntegral ( ) const
inline

Definition at line 280 of file InterpolatedPulse.h.

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

281  {
282  const double* buf = &pulse_[0];
283  long double sum = buf[0]/2.0;
284  const unsigned nIntervals = length_ - 1U;
285  for (unsigned i=1U; i<nIntervals; ++i)
286  sum += buf[i];
287  sum += buf[nIntervals]/2.0;
288  return sum*width_/nIntervals;
289  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]
template<unsigned MaxLen>
unsigned InterpolatedPulse< MaxLen >::getLength ( ) const
inline

Definition at line 133 of file InterpolatedPulse.h.

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

Definition at line 299 of file InterpolatedPulse.h.

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

300  {
301  const double* buf = &pulse_[0];
302  double peak = buf[0];
303  for (unsigned i=1U; i<length_; ++i)
304  if (buf[i] > peak)
305  peak = buf[i];
306  return peak;
307  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]
template<unsigned MaxLen>
const double* InterpolatedPulse< MaxLen >::getPulse ( ) const
inline

Definition at line 132 of file InterpolatedPulse.h.

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

Definition at line 136 of file InterpolatedPulse.h.

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

Definition at line 134 of file InterpolatedPulse.h.

Referenced by QIE8Simulator::getInputStartTime().

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

Definition at line 135 of file InterpolatedPulse.h.

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

Definition at line 137 of file InterpolatedPulse.h.

137 {return width_/(length_ - 1U);}
template<unsigned MaxLen>
template<unsigned Len2>
bool InterpolatedPulse< MaxLen >::operator!= ( const InterpolatedPulse< Len2 > &  r) const
inline

Definition at line 276 of file InterpolatedPulse.h.

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

Definition at line 151 of file InterpolatedPulse.h.

152  {
153  const volatile double tmax = tmin_ + width_;
154  if (t < tmin_ || t > tmax)
155  return 0.0;
156  const unsigned lm1 = length_ - 1U;
157  const double step = width_/lm1;
158  const double nSteps = (t - tmin_)/step;
159  unsigned nbelow = nSteps;
160  unsigned nabove = nbelow + 1;
161  if (nabove > lm1)
162  {
163  nabove = lm1;
164  nbelow = nabove - 1U;
165  }
166  const double delta = nSteps - nbelow;
167  return pulse_[nbelow]*(1.0 - delta) + pulse_[nabove]*delta;
168  }
dbl * delta
Definition: mlp_gen.cc:36
double pulse_[MaxLen]
static const double tmax[3]
template<unsigned MaxLen>
InterpolatedPulse& InterpolatedPulse< MaxLen >::operator*= ( const double  scale)
inline

Definition at line 239 of file InterpolatedPulse.h.

240  {
241  if (scale != 1.0)
242  {
243  double* buf = &pulse_[0];
244  for (unsigned i=0; i<length_; ++i)
245  *buf++ *= scale;
246  }
247  return *this;
248  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]
template<unsigned MaxLen>
template<unsigned Len2>
InterpolatedPulse& InterpolatedPulse< MaxLen >::operator+= ( const InterpolatedPulse< Len2 > &  r)
inline

Definition at line 254 of file InterpolatedPulse.h.

255  {
256  const double step = width_/(length_ - 1U);
257  for (unsigned i=0; i<length_; ++i)
258  pulse_[i] += r(tmin_ + i*step);
259  return *this;
260  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]
template<unsigned MaxLen>
InterpolatedPulse& InterpolatedPulse< MaxLen >::operator= ( const InterpolatedPulse< MaxLen > &  r)
inline

Definition at line 81 of file InterpolatedPulse.h.

82  {
83  if (this != &r)
84  {
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  }
93  return *this;
94  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]
template<unsigned MaxLen>
template<unsigned Len2>
InterpolatedPulse& InterpolatedPulse< MaxLen >::operator= ( const InterpolatedPulse< Len2 > &  r)
inline

Definition at line 98 of file InterpolatedPulse.h.

99  {
100  if (r.length_ > MaxLen) throw cms::Exception(
101  "In InterpolatedPulse::operator=: buffer is not long enough");
102  tmin_ = r.tmin_;
103  width_ = r.width_;
104  length_ = r.length_;
105  double* buf = &pulse_[0];
106  const double* rbuf = &r.pulse_[0];
107  for (unsigned i=0; i<length_; ++i)
108  *buf++ = *rbuf++;
109  return *this;
110  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]
template<unsigned MaxLen>
template<unsigned Len2>
bool InterpolatedPulse< MaxLen >::operator== ( const InterpolatedPulse< Len2 > &  r) const
inline

Definition at line 263 of file InterpolatedPulse.h.

264  {
265  if (!(tmin_ == r.tmin_ && width_ == r.width_ && length_ == r.length_))
266  return false;
267  const double* buf = &pulse_[0];
268  const double* rbuf = &r.pulse_[0];
269  for (unsigned i=0; i<length_; ++i)
270  if (*buf++ != *rbuf++)
271  return false;
272  return true;
273  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]
template<unsigned MaxLen>
double InterpolatedPulse< MaxLen >::secondDerivative ( const double  t) const
inline

Definition at line 202 of file InterpolatedPulse.h.

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

203  {
204  const volatile double tmax = tmin_ + width_;
205  if (t < tmin_ || t > tmax || length_ < 3U)
206  return 0.0;
207  const unsigned lm1 = length_ - 1U;
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;
213  if (nabove > lm1)
214  {
215  nabove = lm1;
216  nbelow = nabove - 1U;
217  }
218 
219  if (nbelow == 0U)
220  {
221  // The first interval
222  return (pulse_[2] - 2.0*pulse_[1] + pulse_[0])/stepSq;
223  }
224  else if (nabove == lm1)
225  {
226  // The last interval
227  return (pulse_[lm1] - 2.0*pulse_[lm1-1U] + pulse_[lm1-2U])/stepSq;
228  }
229  else
230  {
231  // One of the middle intervals
232  const double lower = pulse_[nbelow-1U] - 2.0*pulse_[nbelow] + pulse_[nabove];
233  const double upper = pulse_[nbelow] - 2.0*pulse_[nabove] + pulse_[nabove+1U];
234  const double delta = nSteps - nbelow;
235  return (lower*(1.0 - delta) + upper*delta)/stepSq;
236  }
237  }
dbl * delta
Definition: mlp_gen.cc:36
double pulse_[MaxLen]
static const double tmax[3]
template<unsigned MaxLen>
template<class Archive >
void InterpolatedPulse< MaxLen >::serialize ( Archive &  ar,
unsigned   
)
inlineprivate

Definition at line 326 of file InterpolatedPulse.h.

327  {
328  ar & tmin_ & width_ & length_;
329 
330  // In case we are reading, it may be useful to verify
331  // that the length is reasonable
332  if (length_ > MaxLen) throw cms::Exception(
333  "In InterpolatedPulse::serialize: buffer is not long enough");
334 
335  for (unsigned i=0; i<length_; ++i)
336  ar & pulse_[i];
337  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]
template<unsigned MaxLen>
void InterpolatedPulse< MaxLen >::setIntegral ( const double  newValue)
inline

Definition at line 291 of file InterpolatedPulse.h.

Referenced by QIE8Simulator::setInputIntegral().

292  {
293  const double integ = this->getIntegral();
294  if (integ == 0.0) throw cms::Exception(
295  "In InterpolatedPulse::setIntegral division by zero");
296  *this *= (newValue/integ);
297  }
double getIntegral() const
template<unsigned MaxLen>
void InterpolatedPulse< MaxLen >::setPeakValue ( const double  newValue)
inline

Definition at line 309 of file InterpolatedPulse.h.

Referenced by QIE8Simulator::setInputAmplitude().

310  {
311  const double peak = this->getPeakValue();
312  if (peak == 0.0) throw cms::Exception(
313  "In InterpolatedPulse::setPeakValue: division by zero");
314  *this *= (newValue/peak);
315  }
double getPeakValue() const
template<unsigned MaxLen>
void InterpolatedPulse< MaxLen >::setPulseWidth ( const double  newWidth)
inline

Definition at line 143 of file InterpolatedPulse.h.

144  {
145  if (newWidth <= 0.0) throw cms::Exception(
146  "In InterpolatedPulse::setPulseWidth: invalid pulse width");
147  width_ = newWidth;
148  }
template<unsigned MaxLen>
template<typename Real >
void InterpolatedPulse< MaxLen >::setShape ( const Real *  values,
const unsigned  len 
)
inline

Definition at line 113 of file InterpolatedPulse.h.

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

114  {
115  if (len < 2 || len > MaxLen) throw cms::Exception(
116  "In InterpolatedPulse::setShape: invalid length");
117  assert(values);
118  length_ = len;
119  double* buf = &pulse_[0];
120  for (unsigned i=0; i<len; ++i)
121  *buf++ = *values++;
122  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]
assert(m_qm.get())
template<unsigned MaxLen>
void InterpolatedPulse< MaxLen >::setStartTime ( const double  newStartTime)
inline

Definition at line 140 of file InterpolatedPulse.h.

Referenced by QIE8Simulator::setInputStartTime().

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

Definition at line 125 of file InterpolatedPulse.h.

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

126  {
127  for (unsigned i=0; i<length_; ++i)
128  pulse_[i] = 0.0;
129  }
int i
Definition: DBlmapReader.cc:9
double pulse_[MaxLen]

Friends And Related Function Documentation

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

Definition at line 323 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