CMS 3D CMS Logo

MTDShapeBase.cc
Go to the documentation of this file.
3 
5 
7  : qNSecPerBin_(1. / kNBinsPerNSec),
8  indexOfMax_(0),
9  timeOfMax_(0.),
10  fallTime_(0.),
11  shape_(DVec(k1NSecBinsTotal, 0.0)) {}
12 
13 std::array<float, 3> MTDShapeBase::timeAtThr(const float scale, const float threshold1, const float threshold2) const {
14  std::array<float, 3> times_tmp = {{0., 0., 0.}};
15 
16  // --- Check if the pulse amplitude is greater than threshold 2
17  if (shape_[indexOfMax_] * scale < threshold2)
18  return times_tmp;
19 
20  // --- Find the times corresponding to thresholds 1 and 2 on the pulse leading edge
21  // NB: To speed up the search we loop only on the rising edge
22  unsigned int index_LT1 = 0;
23  unsigned int index_LT2 = 0;
24 
25  for (unsigned int i = 0; i < indexOfMax_; ++i) {
26  float amplitude = shape_[i] * scale;
27 
28  if (amplitude > threshold1 && index_LT1 == 0)
29  index_LT1 = i;
30 
31  if (amplitude > threshold2 && index_LT2 == 0) {
32  index_LT2 = i;
33  break;
34  }
35  }
36 
37  // --- Find the time corresponding to thresholds 1 on the pulse falling edge
38  unsigned int index_FT1 = 0;
39 
40  for (unsigned int i = shape_.size() - 1; i > indexOfMax_; i--) {
41  float amplitude = shape_[i] * scale;
42 
43  if (amplitude > threshold1 && index_FT1 == 0) {
44  index_FT1 = i + 1;
45  break;
46  }
47  }
48 
49  if (index_LT1 != 0)
50  times_tmp[0] = linear_interpolation(threshold1,
51  (index_LT1 - 1) * qNSecPerBin_,
52  index_LT1 * qNSecPerBin_,
53  shape_[index_LT1 - 1] * scale,
54  shape_[index_LT1] * scale);
55 
56  if (index_LT2 != 0)
57  times_tmp[1] = linear_interpolation(threshold2,
58  (index_LT2 - 1) * qNSecPerBin_,
59  index_LT2 * qNSecPerBin_,
60  shape_[index_LT2 - 1] * scale,
61  shape_[index_LT2] * scale);
62 
63  if (index_FT1 != 0)
64  times_tmp[2] = linear_interpolation(threshold1,
65  (index_FT1 - 1) * qNSecPerBin_,
66  index_FT1 * qNSecPerBin_,
67  shape_[index_FT1 - 1] * scale,
68  shape_[index_FT1] * scale);
69 
70  return times_tmp;
71 }
72 
73 unsigned int MTDShapeBase::indexOfMax() const { return indexOfMax_; }
74 
75 double MTDShapeBase::timeOfMax() const { return timeOfMax_; }
76 
77 float MTDShapeBase::maximum() const { return shape_[indexOfMax_]; }
78 
79 float MTDShapeBase::fallTime() const { return fallTime_; }
80 
82  // --- Fill the vector with the pulse shape
84 
85  // --- Find the index of maximum
86  for (unsigned int i = 0; i < shape_.size(); ++i) {
87  if (shape_[indexOfMax_] < shape_[i])
88  indexOfMax_ = i;
89  }
90 
91  for (unsigned int i = indexOfMax_; i < shape_.size(); ++i) {
92  if (shape_[indexOfMax_] * 0.01 > shape_[i]) {
94  break;
95  }
96  }
97 
98  if (indexOfMax_ != 0)
100 }
101 
102 unsigned int MTDShapeBase::timeIndex(double aTime) const {
103  const unsigned int index = aTime * kNBinsPerNSec;
104 
105  const bool bad = (k1NSecBinsTotal <= index);
106 
107  if (bad)
108  LogDebug("MTDShapeBase") << " MTD pulse shape requested for out of range time " << aTime;
109 
110  return (bad ? k1NSecBinsTotal : index);
111 }
112 
113 double MTDShapeBase::operator()(double aTime) const {
114  // return pulse amplitude for request time in ns
115  const unsigned int index(timeIndex(aTime));
116  return (k1NSecBinsTotal == index ? 0 : shape_[index]);
117 }
118 
120  const double& y, const double& x1, const double& x2, const double& y1, const double& y2) const {
121  if (x1 == x2)
122  throw cms::Exception("BadValue") << " MTDShapeBase: Trying to interpolate two points with the same x coordinate!";
123 
124  double a = (y2 - y1) / (x2 - x1);
125  double b = y1 - a * x1;
126 
127  return (y - b) / a;
128 }
std::array< float, 3 > timeAtThr(const float scale, const float threshold1, const float threshold2) const
Definition: MTDShapeBase.cc:13
virtual void fillShape(DVec &aVec) const =0
~MTDShapeBase() override
Definition: MTDShapeBase.cc:4
const double qNSecPerBin_
Definition: MTDShapeBase.h:42
void buildMe()
Definition: MTDShapeBase.cc:81
float fallTime() const
Definition: MTDShapeBase.cc:79
static constexpr unsigned int kNBinsPerNSec
Definition: MTDShapeBase.h:28
double linear_interpolation(const double &y, const double &x1, const double &x2, const double &y1, const double &y2) const
static constexpr unsigned int k1NSecBinsTotal
Definition: MTDShapeBase.h:29
double operator()(double aTime) const override
double timeOfMax_
Definition: MTDShapeBase.h:44
float maximum() const
Definition: MTDShapeBase.cc:77
double timeOfMax() const
Definition: MTDShapeBase.cc:75
double b
Definition: hdecay.h:120
unsigned int indexOfMax_
Definition: MTDShapeBase.h:43
double a
Definition: hdecay.h:121
unsigned int indexOfMax() const
Definition: MTDShapeBase.cc:73
unsigned int timeIndex(double aTime) const
std::vector< double > DVec
Definition: MTDShapeBase.h:11
float fallTime_
Definition: MTDShapeBase.h:45
#define LogDebug(id)