CMS 3D CMS Logo

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