ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
TileCalorimeter
TilePulseSimulator
src
TilePulseShape.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
#include "
TilePulseSimulator/TilePulseShape.h
"
7
8
#include "TMath.h"
9
#include "TGraph.h"
10
#include "TSpline.h"
11
#include "TF1.h"
12
13
#include <iostream>
14
15
#include "GaudiKernel/IMessageSvc.h"
16
#include "GaudiKernel/GaudiException.h"
17
18
//_________________________________________________________________________
19
TilePulseShape::TilePulseShape
(IMessageSvc* msgSvc,
const
std::string& name)
20
:
AthMessaging
(msgSvc, name)
21
{
22
}
23
24
//_________________________________________________________________________
25
TilePulseShape::TilePulseShape
(IMessageSvc* msgSvc,
const
std::string& name,
const
TString& fileName)
26
:
AthMessaging
(msgSvc, name)
27
{
28
loadPulseShape
(fileName);
29
}
30
31
//________________________________________________________________________
32
TilePulseShape::TilePulseShape
(IMessageSvc* msgSvc,
const
std::string& name,
const
std::vector<double>& shapevec)
33
:
AthMessaging
(msgSvc, name)
34
{
35
setPulseShape
(shapevec);
36
}
37
38
//_________________________________________________________________________
39
TilePulseShape::~TilePulseShape
()
40
{
41
resetDeformation
();
42
if
(
m_pulseShape
)
delete
m_pulseShape
;
43
if
(
m_deformedSpline
)
delete
m_deformedSpline
;
44
}
45
46
//_________________________________________________________________________
47
void
TilePulseShape::loadPulseShape
(
const
TString& fileName)
48
{
49
resetDeformation
();
50
if
(
m_pulseShape
)
delete
m_pulseShape
;
51
m_pulseShape
=
new
TGraph(fileName.Data());
52
if
(
m_pulseShape
->IsZombie()) {
53
throw
GaudiException(std::string(
"could not load pulseshape from file: "
) + fileName.Data(),
54
"TilePulseShape"
, StatusCode::FAILURE);
55
}
else
ATH_MSG_INFO
(
"Loaded pulseshape from file: "
<< fileName);
56
resetDeformation
();
57
}
58
59
//_________________________________________________________________________
60
void
TilePulseShape::setPulseShape
(
const
std::vector<double>& shapevec)
61
{
62
resetDeformation
();
63
if
(
m_pulseShape
)
delete
m_pulseShape
;
64
m_pulseShape
=
new
TGraph(shapevec.size());
65
for
(std::vector<double>::size_type i = 0; i != shapevec.size(); i++) {
66
m_pulseShape
->SetPoint(i, -75.5+i*0.5, shapevec.at(i));
67
}
68
resetDeformation
();
69
}
70
71
//_________________________________________________________________________
72
void
TilePulseShape::setUndershootParameters
(
double
amplitude,
double
decayTime)
73
{
74
m_undershootAmplitude
= amplitude;
75
m_undershootDecayTime
= decayTime;
76
m_useConfiguredUndershoot
=
true
;
77
}
78
79
//_________________________________________________________________________
80
double
TilePulseShape::effectiveStartTime
()
const
81
{
82
return
m_deformedShape
->GetX()[0];
83
}
84
85
//_________________________________________________________________________
86
double
TilePulseShape::effectiveEndTime
()
const
87
{
88
return
m_deformedShape
->GetX()[
m_deformedShape
->GetN() - 1];
89
}
90
91
92
//
93
//_________________________________________________________________________
94
// This function gives a pulse shaper for the FEB
95
double
TilePulseShape::eval
(
double
x
,
bool
useSpline,
bool
useUndershoot)
96
{
97
98
//=== make sure pulseshape is available
99
if
(!
m_deformedShape
){
100
ATH_MSG_ERROR
(
"No pulseshape loaded!"
);
101
return
0.;
102
}
103
104
//=== interpolate pulseShape value, TMath::BinarySearch returns
105
//=== index of value smaller or equal to the search value.
106
//=== -> Need to catch boundary values
107
double
y
(0.);
108
int
n(
m_deformedShape
->GetN());
109
int
idx = TMath::BinarySearch(n,
m_deformedShape
->GetX(),
x
);
110
if
(idx<0){
111
//=== left out of bounds, return leftmost value
112
// y = (_deformedShape->GetY())[0];
113
y
= 0;
114
ATH_MSG_DEBUG
(
"Left out of bounds. Replacing y = "
<< (
m_deformedShape
->GetY())[0] <<
" with y = 0. (idx = "
<< idx <<
", x = "
<<
x
<<
")"
);
115
}
116
else
if
(idx>=n-1){
117
//=== right out of bounds, return rightmost value
118
// y = (_deformedShape->GetY())[n-1];
119
if
(useUndershoot){
120
if
(
m_useConfiguredUndershoot
) {
121
y
=
m_undershootAmplitude
* exp(-
x
/
m_undershootDecayTime
);
122
}
else
{
123
y
= 0.00196 * (1 - exp(-
x
/ 20664.59) ) - 0.00217;
124
}
125
}
126
else
{
127
y
= 0;
128
ATH_MSG_DEBUG
(
"Right out of bounds. Replacing y = "
<< (
m_deformedShape
->GetY())[0] <<
" with y = 0. (idx = "
<< idx <<
", x = "
<<
x
<<
")"
);
129
}
130
}
131
else
{
132
//=== linear interpolation
133
double
xLo = (
m_deformedShape
->GetX())[idx ];
134
double
xHi = (
m_deformedShape
->GetX())[idx+1];
135
double
yLo = (
m_deformedShape
->GetY())[idx ];
136
double
yHi = (
m_deformedShape
->GetY())[idx+1];
137
double
yLinear = yLo + (yHi-yLo)/(xHi-xLo) * (
x
-xLo);
138
//=== spline interpolation
139
double
ySpline =
m_deformedSpline
->Eval(
x
);
140
141
if
(useSpline)
y
= ySpline;
142
else
y
= yLinear;
143
}
144
145
return
y
;
146
}
147
148
//
149
//_______________________________________________________________________
150
void
TilePulseShape::resetDeformation
()
151
{
152
if
(
m_deformedShape
==
m_pulseShape
)
return
;
153
154
delete
m_deformedShape
;
155
delete
m_deformedSpline
;
156
m_deformedShape
=
m_pulseShape
;
157
m_deformedSpline
=
new
TSpline3(
"deformedSpline"
,
m_deformedShape
);
158
}
159
160
//
161
//_______________________________________________________________________
162
int
TilePulseShape::scalePulse
(
double
leftSF,
double
rightSF)
163
{
164
165
resetDeformation
();
166
if
(!
m_pulseShape
) {
167
ATH_MSG_WARNING
(
"Attempted pulse shape scaling before loading pulse shape"
);
168
return
1;
169
}
else
{
170
m_deformedShape
= (TGraph*)
m_pulseShape
->Clone();
171
172
for
(
int
i=0; i<
m_deformedShape
->GetN(); ++i){
173
double
x
,
y
;
174
m_deformedShape
->GetPoint(i,
x
,
y
);
175
if
(
x
<0.)
x
*= leftSF;
176
else
if
(
x
>0.)
x
*=rightSF;
177
m_deformedShape
->SetPoint(i,
x
,
y
);
178
}
179
180
delete
m_deformedSpline
;
181
m_deformedSpline
=
new
TSpline3(
"deformedSpline"
,
m_deformedShape
);
182
return
0;
183
}
184
185
}
186
187
//
188
//_______________________________________________________________________
189
TGraph*
TilePulseShape::getGraph
(
double
t0
,
double
ped,
double
amp)
190
{
191
TGraph*
gr
= (TGraph*)
m_deformedShape
->Clone();
192
for
(
int
i=0; i<
gr
->GetN(); i++){
193
double
x
,
y
;
194
gr
->GetPoint(i,
x
,
y
);
195
y
*=amp;
196
y
+=ped;
197
x
+=
t0
;
198
gr
->SetPoint(i,
x
,
y
);
199
}
200
return
gr
;
201
}
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x,...)
Definition
AthMsgStreamMacros.h:46
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
gr
#define gr
t0
static Double_t t0
Definition
LArPhysWaveHECTool.cxx:38
TilePulseShape.h
y
#define y
x
#define x
AthMessaging::AthMessaging
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
Definition
AthMessaging.cxx:13
TilePulseShape::eval
double eval(double x, bool useSpline=true, bool useUndershoot=false)
Definition
TilePulseShape.cxx:95
TilePulseShape::setPulseShape
void setPulseShape(const std::vector< double > &shapevec)
Definition
TilePulseShape.cxx:60
TilePulseShape::getGraph
TGraph * getGraph(double t0=0., double ped=0., double amp=1.)
Definition
TilePulseShape.cxx:189
TilePulseShape::~TilePulseShape
virtual ~TilePulseShape()
Definition
TilePulseShape.cxx:39
TilePulseShape::m_undershootAmplitude
double m_undershootAmplitude
Definition
TilePulseShape.h:44
TilePulseShape::effectiveStartTime
double effectiveStartTime() const
Definition
TilePulseShape.cxx:80
TilePulseShape::m_undershootDecayTime
double m_undershootDecayTime
Definition
TilePulseShape.h:45
TilePulseShape::m_pulseShape
TGraph * m_pulseShape
Definition
TilePulseShape.h:40
TilePulseShape::m_deformedSpline
TSpline * m_deformedSpline
Definition
TilePulseShape.h:42
TilePulseShape::effectiveEndTime
double effectiveEndTime() const
Definition
TilePulseShape.cxx:86
TilePulseShape::resetDeformation
void resetDeformation()
Definition
TilePulseShape.cxx:150
TilePulseShape::scalePulse
int scalePulse(double leftSF=1., double rightSF=1.)
Definition
TilePulseShape.cxx:162
TilePulseShape::setUndershootParameters
void setUndershootParameters(double amplitude, double decayTime)
Definition
TilePulseShape.cxx:72
TilePulseShape::loadPulseShape
void loadPulseShape(const TString &fileName)
Definition
TilePulseShape.cxx:47
TilePulseShape::m_deformedShape
TGraph * m_deformedShape
Definition
TilePulseShape.h:41
TilePulseShape::TilePulseShape
TilePulseShape(IMessageSvc *msgSvc, const std::string &name)
Definition
TilePulseShape.cxx:19
TilePulseShape::m_useConfiguredUndershoot
bool m_useConfiguredUndershoot
Definition
TilePulseShape.h:43
Generated on
for ATLAS Offline Software by
1.17.0