ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
ISF
ISF_FastCaloSim
ISF_FastCaloSimEvent
src
TFCSLateralShapeTuning.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
#include "
ISF_FastCaloSimEvent/TFCSLateralShapeTuning.h
"
6
#include "
ISF_FastCaloSimEvent/TFCSSimulationState.h
"
7
#include "
TruthUtils/HepMCHelpers.h
"
8
9
//=============================================
10
//======= TFCSLateralShapeTuning ==============
11
//=============================================
12
13
TFCSLateralShapeTuning::TFCSLateralShapeTuning
(
const
char
*name,
14
const
char
*title)
15
:
TFCSLateralShapeParametrizationHitBase
(name, title) {}
16
17
TFCSLateralShapeTuning::~TFCSLateralShapeTuning
() {
18
// clear parameter interpolation map and free memory
19
for
(
auto
&p :
m_parameterInterpol
) {
20
delete
p.second;
21
}
22
m_parameterInterpol
.clear();
23
}
24
25
FCSReturnCode
TFCSLateralShapeTuning::initFromModelFile
(
26
const
std::string &pathToModelParameters,
int
intMinEta,
int
intMaxEta) {
27
// get current calo layer
28
int
layer =
TFCSLateralShapeParametrization::calosample
();
29
30
// load file containing model parameters
31
std::unique_ptr<TFile> modelParametersFile (TFile::Open(pathToModelParameters.c_str(),
"READ"
));
32
modelParametersFile->cd();
33
34
// set parameter model names depending on layer
35
std::vector<std::string> parameterModelNames;
36
if
(layer == 1 || layer == 5)
37
parameterModelNames = {
"a0"
,
"a1"
,
"a2"
,
"a3"
};
38
else
if
(layer == 2 || layer == 6)
39
parameterModelNames = {
"eta_s"
,
"phi_s"
};
40
41
for
(
auto
¶meterName : parameterModelNames) {
42
43
// interpolate the model parameters
44
TFCSEnergyInterpolationPiecewiseLinear
*linModelInterpol =
45
new
TFCSEnergyInterpolationPiecewiseLinear
(
""
,
""
);
46
47
TGraph *modelParameterGraph = (TGraph *)gDirectory->Get(
48
Form(
"photons/layer%d/m%d_m%d_%d_%d/%s"
, layer, intMaxEta, intMinEta,
49
intMinEta, intMaxEta, parameterName.c_str()));
50
if
(modelParameterGraph) {
51
// initialize the model interpolation and save in interpolation map
52
linModelInterpol->
InitFromArrayInEkin
(modelParameterGraph->GetN(),
53
modelParameterGraph->GetX(),
54
modelParameterGraph->GetY());
55
m_parameterInterpol
.insert(
56
std::make_pair(parameterName, linModelInterpol));
57
}
else
{
58
ATH_MSG_DEBUG
(
"[TFCSLateralShapeTuning] Could not find model parameter "
59
"graph for layer="
60
<< layer <<
" minEta="
<< intMinEta
61
<<
" maxEta="
<< intMaxEta);
62
return
FCSSuccess
;
63
}
64
}
65
modelParametersFile->Close();
66
67
return
FCSSuccess
;
68
}
69
70
FCSReturnCode
71
TFCSLateralShapeTuning::initFromMap
(
const
interpolationMap
&
interpolationMap
) {
72
ATH_MSG_DEBUG
(
"[TFCSLateralShapeTuning] Initializing data tuning model from "
73
"interpolation map."
);
74
m_parameterInterpol
=
interpolationMap
;
75
return
FCSSuccess
;
76
}
77
78
FCSReturnCode
79
TFCSLateralShapeTuning::simulate_hit
(
Hit
&
hit
,
TFCSSimulationState
&,
80
const
TFCSTruthState
*truth,
81
const
TFCSExtrapolationState
*) {
82
83
// do not do anything if the parameter interpolation map is empty
84
// this means we are in an pseudorapidity region, where no tuning to data is
85
// available
86
if
(
m_parameterInterpol
.empty())
87
return
FCSSuccess
;
88
89
// set maximum scaling factor
90
float
maxScaling = 500;
91
92
// retrieve particle data
93
const
int
pdgId = truth->
pdgid
();
94
const
double
charge
=
MC::charge
(pdgId);
95
96
// retreive hit information
97
const
double
centerEta =
hit
.center_eta();
98
const
double
centerPhi =
hit
.center_phi();
99
const
double
centerZ =
hit
.center_z();
100
// retrieve truth kinetic energy for interpolation
101
const
float
Ekin = truth->
Ekin
();
102
// retrieve calo sample
103
int
layer =
TFCSLateralShapeParametrization::calosample
();
104
105
ATH_MSG_DEBUG
(
"[TFCSLateralShapeTuning] Initializing with pdgId="
106
<< pdgId <<
", charge="
<<
charge
<<
", Ekin="
<< Ekin
107
<<
", caloSample="
<< layer);
108
109
ATH_MSG_DEBUG
(
"[TFCSLateralShapeTuning] Got hit position: "
110
<<
" hit.eta="
<<
hit
.eta() <<
", hit.phi="
<<
hit
.phi()
111
<<
", hit.r="
<<
hit
.r());
112
113
// compute deltaEta and deltaPhi
114
const
double
deltaEta =
hit
.eta() - centerEta;
115
const
double
deltaPhi
=
hit
.phi() - centerPhi;
116
117
if
(layer == 2 || layer == 6) {
118
119
double
etaScaleFactor =
m_parameterInterpol
[
"eta_s"
]->evaluate(Ekin);
120
double
phiScaleFactor =
m_parameterInterpol
[
"phi_s"
]->evaluate(Ekin);
121
122
// add a maximum scaling threshold to prevent unreasonable scalings
123
etaScaleFactor =
124
std::abs(etaScaleFactor) < maxScaling ? etaScaleFactor : maxScaling;
125
phiScaleFactor =
126
std::abs(phiScaleFactor) < maxScaling ? phiScaleFactor : maxScaling;
127
128
ATH_MSG_DEBUG
(
"[TFCSLateralShapeTuning] Applying 2D eta_s - eta_phi "
129
"scaling model with eta_s="
130
<< etaScaleFactor <<
" and phi_s="
<< phiScaleFactor);
131
132
double
deltaEtaCorr = etaScaleFactor * deltaEta;
133
double
deltaPhiCorr = phiScaleFactor *
deltaPhi
;
134
135
hit
.setEtaPhiZE(centerEta + deltaEtaCorr, centerPhi + deltaPhiCorr, centerZ,
136
hit
.E());
137
138
}
139
140
else
if
(layer == 1 || layer == 5) {
141
142
double
etaScaleFactor =
getSeriesScalingFactor
(
143
m_parameterInterpol
[
"a0"
]->evaluate(Ekin),
144
m_parameterInterpol
[
"a1"
]->evaluate(Ekin),
145
m_parameterInterpol
[
"a2"
]->evaluate(Ekin),
146
m_parameterInterpol
[
"a3"
]->evaluate(Ekin), std::abs(deltaEta));
147
148
// add a maximum scaling threshold to prevent unreasonable scalings
149
etaScaleFactor =
150
std::abs(etaScaleFactor) < maxScaling ? etaScaleFactor : maxScaling;
151
152
ATH_MSG_DEBUG
(
"[TFCSLateralShapeTuning] Applying eta_s series expansion "
153
"model with eta_s="
154
<< etaScaleFactor);
155
156
double
deltaEtaCorr = etaScaleFactor * deltaEta;
157
158
hit
.setEtaPhiZE(centerEta + deltaEtaCorr, centerPhi +
deltaPhi
, centerZ,
159
hit
.E());
160
}
161
162
return
FCSSuccess
;
163
}
164
165
double
TFCSLateralShapeTuning::getSeriesScalingFactor
(
166
double
a0
,
double
a1,
double
a2,
double
a3,
double
distToShowerCenter) {
167
168
double
meanDistToShowerCentre = 0.0039;
169
double
scaleFactor =
170
1 +
a0
+ a1 * distToShowerCenter / meanDistToShowerCentre +
171
a2 * std::pow(distToShowerCenter / meanDistToShowerCentre, 2) +
172
a3 * std::pow(distToShowerCenter / meanDistToShowerCentre, 3);
173
174
return
scaleFactor;
175
}
deltaPhi
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
Definition
AmgMatrixBasePlugin.h:112
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
charge
double charge(const T &p)
Definition
AtlasPID.h:1003
HepMCHelpers.h
ATLAS-specific HepMC functions.
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
TFCSLateralShapeTuning.h
FCSReturnCode
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
Definition
TFCSParametrizationBase.h:41
FCSSuccess
@ FCSSuccess
Definition
TFCSParametrizationBase.h:41
TFCSSimulationState.h
TFCSEnergyInterpolationPiecewiseLinear
Definition
TFCSEnergyInterpolationPiecewiseLinear.h:19
TFCSEnergyInterpolationPiecewiseLinear::InitFromArrayInEkin
void InitFromArrayInEkin(Int_t np, const Double_t Ekin[], const Double_t response[])
Definition
TFCSEnergyInterpolationPiecewiseLinear.cxx:43
TFCSExtrapolationState
Definition
TFCSExtrapolationState.h:13
TFCSLateralShapeParametrizationHitBase::Hit
Definition
TFCSLateralShapeParametrizationHitBase.h:42
TFCSLateralShapeParametrizationHitBase::TFCSLateralShapeParametrizationHitBase
TFCSLateralShapeParametrizationHitBase(const char *name=nullptr, const char *title=nullptr)
Definition
TFCSLateralShapeParametrizationHitBase.cxx:15
TFCSLateralShapeParametrization::calosample
int calosample() const
Definition
TFCSLateralShapeParametrization.h:34
TFCSLateralShapeTuning::simulate_hit
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) override
simulated one hit position with some energy.
Definition
TFCSLateralShapeTuning.cxx:79
TFCSLateralShapeTuning::interpolationMap
std::map< std::string, TFCSEnergyInterpolationPiecewiseLinear * > interpolationMap
Definition
TFCSLateralShapeTuning.h:20
TFCSLateralShapeTuning::initFromModelFile
FCSReturnCode initFromModelFile(const std::string &pathToModelParameters, int intMinEta, int intMaxEta)
Definition
TFCSLateralShapeTuning.cxx:25
TFCSLateralShapeTuning::m_parameterInterpol
interpolationMap m_parameterInterpol
Definition
TFCSLateralShapeTuning.h:45
TFCSLateralShapeTuning::TFCSLateralShapeTuning
TFCSLateralShapeTuning(const char *name=nullptr, const char *title=nullptr)
Constructor.
Definition
TFCSLateralShapeTuning.cxx:13
TFCSLateralShapeTuning::~TFCSLateralShapeTuning
~TFCSLateralShapeTuning()
Definition
TFCSLateralShapeTuning.cxx:17
TFCSLateralShapeTuning::getSeriesScalingFactor
static double getSeriesScalingFactor(double a0, double a1, double a2, double a3, double distToShowerCenter)
Definition
TFCSLateralShapeTuning.cxx:165
TFCSLateralShapeTuning::initFromMap
FCSReturnCode initFromMap(const interpolationMap &)
Definition
TFCSLateralShapeTuning.cxx:71
TFCSSimulationState
Definition
TFCSSimulationState.h:32
TFCSTruthState
Definition
TFCSTruthState.h:13
TFCSTruthState::pdgid
int pdgid() const
Definition
TFCSTruthState.h:25
TFCSTruthState::Ekin
double Ekin() const
Definition
TFCSTruthState.h:26
a0
double a0
Definition
globals.cxx:27
MC::charge
double charge(const T &p)
Definition
HepMCHelpers.h:1004
Generated on
for ATLAS Offline Software by
1.17.0