ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
ISF
ISF_FastCaloSim
ISF_FastCaloSimParametrization
Root
TFCSSimpleLateralShapeParametrization.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 "CLHEP/Random/RandGaussZiggurat.h"
6
7
#include "
ISF_FastCaloSimParametrization/TFCSSimpleLateralShapeParametrization.h
"
8
#include "
ISF_FastCaloSimEvent/TFCSExtrapolationState.h
"
9
#include "
ISF_FastCaloSimEvent/TFCSSimulationState.h
"
10
#include "
ISF_FastCaloSimEvent/FastCaloSim_CaloCell_ID.h
"
11
12
#include "TMath.h"
13
14
//=============================================
15
//======= TFCSLateralShapeParametrization =========
16
//=============================================
17
18
TFCSSimpleLateralShapeParametrization::TFCSSimpleLateralShapeParametrization
(
const
char
* name,
const
char
* title) :
19
TFCSLateralShapeParametrizationHitBase
(name,title)
20
{
21
m_sigmaX
= 0;
22
m_sigmaY
= 0;
23
}
24
25
26
FCSReturnCode
TFCSSimpleLateralShapeParametrization::simulate_hit
(
Hit
&
hit
,
TFCSSimulationState
&simulstate,
const
TFCSTruthState
*
/*truth*/
,
const
TFCSExtrapolationState
* extrapol)
27
{
28
if
(!simulstate.
randomEngine
()) {
29
return
FCSFatal
;
30
}
31
32
int
cs=
calosample
();
33
hit
.eta()=0.5*( extrapol->
eta
(cs,
CaloSubPos::SUBPOS_ENT
) + extrapol->
eta
(cs,
CaloSubPos::SUBPOS_EXT
) );
34
hit
.phi()=0.5*( extrapol->
phi
(cs,
CaloSubPos::SUBPOS_ENT
) + extrapol->
phi
(cs,
CaloSubPos::SUBPOS_EXT
) );
35
hit
.E()*=1;
36
37
double
x
,
y
;
38
getHitXY
(simulstate.
randomEngine
(),
x
,
y
);
39
40
// delta_eta and delta_phi;
41
double
delta_eta =
x
;
42
double
delta_phi =
y
;
43
44
hit
.eta() += delta_eta;
45
hit
.phi() += delta_phi;
46
47
return
FCSSuccess
;
48
}
49
50
51
bool
TFCSSimpleLateralShapeParametrization::Initialize
(
float
input_sigma_x,
float
input_sigma_y)
52
{
53
m_sigmaX
= input_sigma_x;
54
m_sigmaY
= input_sigma_y;
55
return
true
;
56
}
57
58
bool
TFCSSimpleLateralShapeParametrization::Initialize
(
const
char
* filepath,
const
char
* histname)
59
{
60
// input file with histogram to fit
61
TFile *f =
new
TFile(filepath);
62
if
(f ==
nullptr
)
return
false
;
63
64
// histogram with hit pattern
65
TH2D *inputShape = (TH2D*)f->Get(histname);
66
if
(inputShape ==
nullptr
)
return
false
;
67
68
// Function to fit with
69
double
hiEdge = inputShape->GetYaxis()->GetBinLowEdge( inputShape->GetNbinsY() );
70
TF1 *x_func =
new
TF1(
"fx"
,
"gaus"
,-hiEdge,hiEdge);
71
TF1 *y_func =
new
TF1(
"fy"
,
"gaus"
,-hiEdge,hiEdge);
72
73
// Project into x and y histograms
74
TH1F *h_xrms =
new
TH1F(
"h_xrms"
,
"h_xrms"
,100,-hiEdge,hiEdge);
75
TH1F *h_yrms =
new
TH1F(
"h_yrms"
,
"h_yrms"
,100,-hiEdge,hiEdge);
76
77
double
val = 0;
// bin content
78
double
r
= 0;
// radius
79
double
a
= 0;
// angle
80
double
ypos= 0;
81
double
xpos= 0;
82
83
// Loop over to project along axes, takes bin center as position
84
for
(
int
xbin = 1; xbin < inputShape->GetNbinsX() + 1; xbin++)
85
{
86
a
= inputShape->GetXaxis()->GetBinCenter(xbin);
87
88
for
(
int
ybin = 1; ybin < inputShape->GetNbinsY() + 1; ybin++)
89
{
90
val = inputShape->GetBinContent(xbin,ybin);
91
92
r
= inputShape->GetYaxis()->GetBinCenter(ybin);
93
94
ypos =
r
* TMath::Sin(
a
);
95
xpos =
r
* TMath::Cos(
a
);
96
97
h_xrms->Fill( xpos, val);
98
h_yrms->Fill( ypos, val);
99
100
}
101
}
102
103
h_xrms->Fit(x_func,
"0"
);
104
TF1 *fitx = h_xrms->GetFunction(
"fx"
);
105
// posibly center
106
107
h_yrms->Fit(y_func,
"0"
);
108
TF1 *fity = h_yrms->GetFunction(
"fy"
);
109
// posibly center
110
111
// Finally set sigma
112
m_sigmaX
= fitx->GetParameter(2);
113
m_sigmaY
= fity->GetParameter(2);
114
115
116
// clean up
117
delete
x_func;
118
delete
y_func;
119
120
delete
h_xrms;
121
delete
h_yrms;
122
f->Close();
123
124
return
true
;
125
}
126
127
void
TFCSSimpleLateralShapeParametrization::getHitXY
(CLHEP::HepRandomEngine *engine,
double
&
x
,
double
&
y
)
const
128
{
129
x
= CLHEP::RandGaussZiggurat::shoot(engine, 0,
m_sigmaX
);
130
y
= CLHEP::RandGaussZiggurat::shoot(engine, 0,
m_sigmaY
);
131
}
FastCaloSim_CaloCell_ID.h
SUBPOS_ENT
@ SUBPOS_ENT
Definition
FastCaloSim_CaloCell_ID.h:12
SUBPOS_EXT
@ SUBPOS_EXT
Definition
FastCaloSim_CaloCell_ID.h:13
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
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
TFCSSimpleLateralShapeParametrization.h
TFCSSimulationState.h
y
#define y
x
#define x
TFCSExtrapolationState
Definition
TFCSExtrapolationState.h:13
TFCSExtrapolationState::phi
double phi(int layer, int subpos) const
Definition
TFCSExtrapolationState.h:55
TFCSExtrapolationState::eta
double eta(int layer, int subpos) const
Definition
TFCSExtrapolationState.h:54
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
TFCSSimpleLateralShapeParametrization::TFCSSimpleLateralShapeParametrization
TFCSSimpleLateralShapeParametrization(const char *name=nullptr, const char *title=nullptr)
Definition
TFCSSimpleLateralShapeParametrization.cxx:18
TFCSSimpleLateralShapeParametrization::getHitXY
void getHitXY(CLHEP::HepRandomEngine *engine, double &x, double &y) const
Definition
TFCSSimpleLateralShapeParametrization.cxx:127
TFCSSimpleLateralShapeParametrization::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
TFCSSimpleLateralShapeParametrization.cxx:26
TFCSSimpleLateralShapeParametrization::m_sigmaY
float m_sigmaY
Definition
TFCSSimpleLateralShapeParametrization.h:40
TFCSSimpleLateralShapeParametrization::m_sigmaX
float m_sigmaX
Definition
TFCSSimpleLateralShapeParametrization.h:39
TFCSSimpleLateralShapeParametrization::Initialize
bool Initialize(const char *filepath, const char *histname)
Definition
TFCSSimpleLateralShapeParametrization.cxx:58
TFCSSimulationState
Definition
TFCSSimulationState.h:32
TFCSSimulationState::randomEngine
CLHEP::HepRandomEngine * randomEngine()
Definition
TFCSSimulationState.h:36
TFCSTruthState
Definition
TFCSTruthState.h:13
r
int r
Definition
globals.cxx:22
Generated on
for ATLAS Offline Software by
1.17.0