ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
ISF
ISF_FastCaloSim
ISF_FastCaloSimEvent
src
TFCS2DFunctionLateralShapeParametrization.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "CLHEP/Random/RandFlat.h"
6
#include "CLHEP/Random/RandPoisson.h"
7
8
#include "
ISF_FastCaloSimEvent/TFCS2DFunctionLateralShapeParametrization.h
"
9
#include "
ISF_FastCaloSimEvent/FastCaloSim_CaloCell_ID.h
"
10
#include "
ISF_FastCaloSimEvent/TFCSSimulationState.h
"
11
#include "
ISF_FastCaloSimEvent/TFCSExtrapolationState.h
"
12
13
#include "TFile.h"
14
#include "TMath.h"
15
#include "TH2.h"
16
17
#include "
TruthUtils/HepMCHelpers.h
"
18
19
//=============================================
20
//======= TFCS2DFunctionLateralShapeParametrization =========
21
//=============================================
22
23
TFCS2DFunctionLateralShapeParametrization::
24
TFCS2DFunctionLateralShapeParametrization
(
const
char
*name,
25
const
char
*title)
26
:
TFCSLateralShapeParametrizationHitBase
(name, title),
m_function
(nullptr),
27
m_nhits
(0) {
28
TFCS2DFunctionLateralShapeParametrization::reset_phi_symmetric
();
29
}
30
31
TFCS2DFunctionLateralShapeParametrization::
32
~TFCS2DFunctionLateralShapeParametrization
() {
33
if
(
m_function
)
34
delete
m_function
;
35
m_function
=
nullptr
;
36
}
37
38
double
TFCS2DFunctionLateralShapeParametrization::get_sigma2_fluctuation
(
39
TFCSSimulationState
&
/*simulstate*/
,
const
TFCSTruthState
*
/*truth*/
,
40
const
TFCSExtrapolationState
*
/*extrapol*/
)
const
{
41
return
1.0 /
m_nhits
;
42
}
43
44
int
TFCS2DFunctionLateralShapeParametrization::get_number_of_hits
(
45
TFCSSimulationState
&simulstate,
const
TFCSTruthState
*
/*truth*/
,
46
const
TFCSExtrapolationState
*
/*extrapol*/
)
const
{
47
if
(!simulstate.
randomEngine
()) {
48
return
-1;
49
}
50
51
return
CLHEP::RandPoisson::shoot(simulstate.
randomEngine
(),
m_nhits
);
52
}
53
54
void
TFCS2DFunctionLateralShapeParametrization::set_number_of_hits
(
55
float
nhits) {
56
m_nhits
= nhits;
57
}
58
59
FCSReturnCode
TFCS2DFunctionLateralShapeParametrization::simulate_hit
(
60
Hit
&
hit
,
TFCSSimulationState
&simulstate,
const
TFCSTruthState
*truth,
61
const
TFCSExtrapolationState
*
/*extrapol*/
) {
62
if
(!simulstate.
randomEngine
()) {
63
return
FCSFatal
;
64
}
65
if
(!
m_function
) {
66
return
FCSFatal
;
67
}
68
69
const
int
pdgId = truth->
pdgid
();
70
const
double
charge
=
MC::charge
(pdgId);
71
72
const
int
cs =
calosample
();
73
const
double
center_eta =
hit
.center_eta();
74
const
double
center_phi =
hit
.center_phi();
75
const
double
center_r =
hit
.center_r();
76
const
double
center_z =
hit
.center_z();
77
78
if
(TMath::IsNaN(center_r) or TMath::IsNaN(center_z) or
79
TMath::IsNaN(center_eta) or
80
TMath::IsNaN(center_phi)) {
// Check if extrapolation fails
81
return
FCSFatal
;
82
}
83
84
float
alpha,
r
, rnd1, rnd2;
85
rnd1 = CLHEP::RandFlat::shoot(simulstate.
randomEngine
());
86
rnd2 = CLHEP::RandFlat::shoot(simulstate.
randomEngine
());
87
if
(
is_phi_symmetric
()) {
88
if
(rnd2 >= 0.5) {
// Fill negative phi half of shape
89
rnd2 -= 0.5;
90
rnd2 *= 2;
91
m_function
->rnd_to_fct(alpha,
r
, rnd1, rnd2);
92
alpha = -alpha;
93
}
else
{
// Fill positive phi half of shape
94
rnd2 *= 2;
95
m_function
->rnd_to_fct(alpha,
r
, rnd1, rnd2);
96
}
97
}
else
{
98
m_function
->rnd_to_fct(alpha,
r
, rnd1, rnd2);
99
}
100
if
(TMath::IsNaN(alpha) || TMath::IsNaN(
r
)) {
101
ATH_MSG_ERROR
(
" 2D function, #hits="
<<
m_nhits
<<
" alpha="
<< alpha
102
<<
" r="
<<
r
<<
" rnd1="
<< rnd1
103
<<
" rnd2="
<< rnd2);
104
alpha = 0;
105
r
= 0.001;
106
107
ATH_MSG_ERROR
(
" This error could probably be retried"
);
108
return
FCSFatal
;
109
}
110
111
float
delta_eta_mm =
r
* cos(alpha);
112
float
delta_phi_mm =
r
* sin(alpha);
113
114
// Particles with negative eta are expected to have the same shape as those
115
// with positive eta after transformation: delta_eta --> -delta_eta
116
if
(center_eta < 0.)
117
delta_eta_mm = -delta_eta_mm;
118
// We derive the shower shapes for electrons and positively charged hadrons.
119
// Particle with the opposite charge are expected to have the same shower shape
120
// after the transformation: delta_phi --> -delta_phi
121
if
((
charge
< 0. && pdgId!=11) || pdgId==-11)
122
delta_phi_mm = -delta_phi_mm;
123
124
const
float
dist000 = TMath::Sqrt(center_r * center_r + center_z * center_z);
125
const
float
eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
126
(1.0 + TMath::Exp(-2 * center_eta)));
127
128
const
float
delta_eta = delta_eta_mm / eta_jakobi / dist000;
129
const
float
delta_phi = delta_phi_mm / center_r;
130
131
hit
.setEtaPhiZE(center_eta + delta_eta, center_phi + delta_phi, center_z,
132
hit
.E());
133
134
ATH_MSG_DEBUG
(
"HIT: E="
<<
hit
.E() <<
" cs="
<< cs <<
" eta="
<<
hit
.eta()
135
<<
" phi="
<<
hit
.phi() <<
" z="
<<
hit
.z()
136
<<
" r="
<<
r
<<
" alpha="
<< alpha);
137
138
return
FCSSuccess
;
139
}
140
141
bool
TFCS2DFunctionLateralShapeParametrization::Initialize
(
TFCS2DFunction
*func,
142
float
nhits) {
143
if
(!func)
144
return
false
;
145
if
(
m_function
)
146
delete
m_function
;
147
m_function
= func;
148
149
if
(nhits > 0)
150
set_number_of_hits
(nhits);
151
152
return
true
;
153
}
154
155
void
TFCS2DFunctionLateralShapeParametrization::Print
(Option_t *option)
const
{
156
TString opt(option);
157
bool
shortprint = opt.Index(
"short"
) >= 0;
158
bool
longprint =
msgLvl
(MSG::DEBUG) || (
msgLvl
(MSG::INFO) && !shortprint);
159
TString optprint = opt;
160
optprint.ReplaceAll(
"short"
,
""
);
161
TFCSLateralShapeParametrizationHitBase::Print
(option);
162
163
if
(longprint) {
164
if
(
is_phi_symmetric
()) {
165
ATH_MSG_INFO
(optprint <<
" 2D function, #hits="
<<
m_nhits
166
<<
" (phi symmetric)"
);
167
}
else
{
168
ATH_MSG_INFO
(optprint <<
" 2D function, #hits="
<<
m_nhits
169
<<
" (not phi symmetric)"
);
170
}
171
}
172
}
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
charge
double charge(const T &p)
Definition
AtlasPID.h:1003
FastCaloSim_CaloCell_ID.h
HepMCHelpers.h
ATLAS-specific HepMC functions.
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
TFCS2DFunctionLateralShapeParametrization.h
TFCSExtrapolationState.h
FCSReturnCode
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
Definition
TFCSParametrizationBase.h:41
FCSFatal
@ FCSFatal
Definition
TFCSParametrizationBase.h:41
FCSSuccess
@ FCSSuccess
Definition
TFCSParametrizationBase.h:41
TFCSSimulationState.h
ISF_FCS::MLogging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
Definition
MLogging.h:222
TFCS2DFunctionLateralShapeParametrization::get_sigma2_fluctuation
virtual double get_sigma2_fluctuation(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
default for this class is to simulate get_number_of_expected_hits() hits, which gives fluctuations si...
Definition
TFCS2DFunctionLateralShapeParametrization.cxx:38
TFCS2DFunctionLateralShapeParametrization::Print
virtual void Print(Option_t *option="") const override
Definition
TFCS2DFunctionLateralShapeParametrization.cxx:155
TFCS2DFunctionLateralShapeParametrization::Initialize
bool Initialize(TFCS2DFunction *func, float nhits=-1)
Init from function.
Definition
TFCS2DFunctionLateralShapeParametrization.cxx:141
TFCS2DFunctionLateralShapeParametrization::is_phi_symmetric
bool is_phi_symmetric() const
Definition
TFCS2DFunctionLateralShapeParametrization.h:27
TFCS2DFunctionLateralShapeParametrization::m_function
TFCS2DFunction * m_function
Histogram to be used for the shape simulation.
Definition
TFCS2DFunctionLateralShapeParametrization.h:67
TFCS2DFunctionLateralShapeParametrization::TFCS2DFunctionLateralShapeParametrization
TFCS2DFunctionLateralShapeParametrization(const char *name=nullptr, const char *title=nullptr)
Definition
TFCS2DFunctionLateralShapeParametrization.cxx:24
TFCS2DFunctionLateralShapeParametrization::~TFCS2DFunctionLateralShapeParametrization
~TFCS2DFunctionLateralShapeParametrization()
Definition
TFCS2DFunctionLateralShapeParametrization.cxx:32
TFCS2DFunctionLateralShapeParametrization::reset_phi_symmetric
virtual void reset_phi_symmetric()
Definition
TFCS2DFunctionLateralShapeParametrization.h:29
TFCS2DFunctionLateralShapeParametrization::simulate_hit
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) override
simulated one hit position with weight that should be put into simulstate sometime later all hit weig...
Definition
TFCS2DFunctionLateralShapeParametrization.cxx:59
TFCS2DFunctionLateralShapeParametrization::m_nhits
float m_nhits
Definition
TFCS2DFunctionLateralShapeParametrization.h:68
TFCS2DFunctionLateralShapeParametrization::get_number_of_hits
virtual int get_number_of_hits(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
default for this class is to simulate get_number_of_expected_hits() hits
Definition
TFCS2DFunctionLateralShapeParametrization.cxx:44
TFCS2DFunctionLateralShapeParametrization::set_number_of_hits
void set_number_of_hits(float nhits)
set the desired number of hits
Definition
TFCS2DFunctionLateralShapeParametrization.cxx:54
TFCS2DFunction
Definition
TFCS2DFunction.h:15
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::Print
void Print(Option_t *option="") const override
Definition
TFCSLateralShapeParametrization.cxx:53
TFCSLateralShapeParametrization::calosample
int calosample() const
Definition
TFCSLateralShapeParametrization.h:34
TFCSSimulationState
Definition
TFCSSimulationState.h:32
TFCSSimulationState::randomEngine
CLHEP::HepRandomEngine * randomEngine()
Definition
TFCSSimulationState.h:36
TFCSTruthState
Definition
TFCSTruthState.h:13
TFCSTruthState::pdgid
int pdgid() const
Definition
TFCSTruthState.h:25
r
int r
Definition
globals.cxx:22
MC::charge
double charge(const T &p)
Definition
HepMCHelpers.h:1004
Generated on
for ATLAS Offline Software by
1.17.0