CMS 3D CMS Logo

LowPassFilterTiming.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include <cassert>
4 
6 
7 #define NPARAMETERS 6U
8 
9 //
10 // The formula below join_location - h is aleft*(x_in - join_location) + bleft.
11 // The formula above join_location + h is aright*(x_in - join_location) + bright.
12 // Smooth cubic interpolation is performed within +-h of join_location.
13 //
14 static double two_joined_lines(const double x_in, const double aleft,
15  const double bleft, const double aright,
16  const double bright, const double join_location,
17  const double h)
18 {
19  assert(h >= 0.0);
20  const double x = x_in - join_location;
21  if (x <= -h)
22  return aleft*x + bleft;
23  else if (x >= h)
24  return aright*x + bright;
25  else
26  {
27  const double vleft = -h*aleft + bleft;
28  const double vright = aright*h + bright;
29  const double b = (aright - aleft)/4.0/h;
30  const double d = (vright + vleft - 2*b*h*h)/2.0;
31  const double a = (d + aright*h - b*h*h - vright)/(2.0*h*h*h);
32  const double c = -(3*d + aright*h + b*h*h - 3*vright)/(2.0*h);
33  return ((a*x + b)*x + c)*x + d;
34  }
35 }
36 
38 {
39  return NPARAMETERS;
40 }
41 
42 //
43 // The time constant decreases linearly in the space of log(V + Vbias),
44 // from tauMin+tauDelta when V = 0 to tauMin when V = V1.
45 // Around log(V1 + Vbias), the curve is joined by a third order polynomial.
46 // The width of the join is dLogV on both sides of log(V1 + Vbias).
47 //
48 // Value "tauDelta" = 0 can be used to create a constant time filter.
49 //
50 double LowPassFilterTiming::operator()(const double v,
51  const double* pars,
52  const unsigned nParams) const
53 {
54  assert(nParams == NPARAMETERS);
55  assert(pars);
56  unsigned ipar = 0;
57  const double logVbias = pars[ipar++];
58  const double logTauMin = pars[ipar++];
59 
60  // The middle of the join region. Not a log actually,
61  // it is simple in the log space.
62  const double logV0 = pars[ipar++];
63 
64  // Log of the width of the join region
65  const double logDelta = pars[ipar++];
66 
67  // Log of the minus negative slope
68  const double slopeLog = pars[ipar++];
69 
70  // Log of the maximum delay time (cutoff)
71  const double tauMax = pars[ipar++];
72  assert(ipar == NPARAMETERS);
73 
74  // What happens for large (in magnitude) negative voltage inputs?
75  const double Vbias = exp(logVbias);
76  const double shiftedV = v + Vbias;
77  if (shiftedV <= 0.0)
78  return tauMax;
79 
80  const double lg = log(shiftedV);
81  const double delta = exp(logDelta);
82  const double tauMin = exp(logTauMin);
83  double result = two_joined_lines(lg, -exp(slopeLog), tauMin,
84  0.0, tauMin, logV0, delta);
85  if (result > tauMax)
86  result = tauMax;
87  return result;
88 }
dbl * delta
Definition: mlp_gen.cc:36
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static double two_joined_lines(const double x_in, const double aleft, const double bleft, const double aright, const double bright, const double join_location, const double h)
unsigned nParameters() const
#define NPARAMETERS
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
double operator()(double currentIn, const double *params, unsigned nParams) const