CMS 3D CMS Logo

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