SimFastTiming
FastTimingCommon
src
MTDShapeBase.cc
Go to the documentation of this file.
1
#include "
FWCore/MessageLogger/interface/MessageLogger.h
"
2
#include "
SimFastTiming/FastTimingCommon/interface/MTDShapeBase.h
"
3
4
MTDShapeBase::~MTDShapeBase
() {}
5
6
MTDShapeBase::MTDShapeBase
()
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
73
void
MTDShapeBase::buildMe
() {
74
// --- Fill the vector with the pulse shape
75
fillShape
(
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)
84
timeOfMax_
=
indexOfMax_
*
qNSecPerBin_
;
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
104
double
MTDShapeBase::linear_interpolation
(
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
}
DDAxes::y
MTDShapeBase::operator()
double operator()(double aTime) const override
Definition:
MTDShapeBase.cc:98
MTDShapeBase::qNSecPerBin_
const double qNSecPerBin_
Definition:
MTDShapeBase.h:40
mps_fire.i
i
Definition:
mps_fire.py:355
CustomPhysics_cfi.amplitude
amplitude
Definition:
CustomPhysics_cfi.py:12
MessageLogger.h
MTDShapeBase::fillShape
virtual void fillShape(DVec &aVec) const =0
MTDShapeBase::~MTDShapeBase
~MTDShapeBase() override
Definition:
MTDShapeBase.cc:4
MTDShapeBase::timeAtThr
std::array< float, 3 > timeAtThr(const float scale, const float threshold1, const float threshold2) const
Definition:
MTDShapeBase.cc:9
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition:
testProducerWithPsetDescEmpty_cfi.py:28
MTDShapeBase::indexOfMax
unsigned int indexOfMax() const
Definition:
MTDShapeBase.cc:69
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition:
testProducerWithPsetDescEmpty_cfi.py:33
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition:
testProducerWithPsetDescEmpty_cfi.py:29
MTDShapeBase::DVec
std::vector< double > DVec
Definition:
MTDShapeBase.h:11
MTDShapeBase::k1NSecBinsTotal
static constexpr unsigned int k1NSecBinsTotal
Definition:
MTDShapeBase.h:27
b
double b
Definition:
hdecay.h:118
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition:
testProducerWithPsetDescEmpty_cfi.py:30
MTDShapeBase::timeOfMax_
double timeOfMax_
Definition:
MTDShapeBase.h:42
Scenarios_cff.scale
scale
Definition:
Scenarios_cff.py:2186
LogDebug
#define LogDebug(id)
Definition:
MessageLogger.h:670
a
double a
Definition:
hdecay.h:119
MTDShapeBase::timeOfMax
double timeOfMax() const
Definition:
MTDShapeBase.cc:71
MTDShapeBase::MTDShapeBase
MTDShapeBase()
Definition:
MTDShapeBase.cc:6
MTDShapeBase::shape_
DVec shape_
Definition:
MTDShapeBase.h:43
MTDShapeBase::buildMe
void buildMe()
Definition:
MTDShapeBase.cc:73
MTDShapeBase.h
Exception
Definition:
hltDiff.cc:246
detailsBasic3DVector::y
float float y
Definition:
extBasic3DVector.h:14
AlignmentPI::index
index
Definition:
AlignmentPayloadInspectorHelper.h:46
MTDShapeBase::kNBinsPerNSec
static constexpr unsigned int kNBinsPerNSec
Definition:
MTDShapeBase.h:26
MTDShapeBase::indexOfMax_
unsigned int indexOfMax_
Definition:
MTDShapeBase.h:41
MTDShapeBase::linear_interpolation
double linear_interpolation(const double &y, const double &x1, const double &x2, const double &y1, const double &y2) const
Definition:
MTDShapeBase.cc:104
MTDShapeBase::timeIndex
unsigned int timeIndex(double aTime) const
Definition:
MTDShapeBase.cc:87
Generated for CMSSW Reference Manual by
1.8.16