ATLAS Offline Software
Loading...
Searching...
No Matches
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
12
13#include "TFile.h"
14#include "TMath.h"
15#include "TH2.h"
16
18
19//=============================================
20//======= TFCS2DFunctionLateralShapeParametrization =========
21//=============================================
22
30
37
39 TFCSSimulationState & /*simulstate*/, const TFCSTruthState * /*truth*/,
40 const TFCSExtrapolationState * /*extrapol*/) const {
41 return 1.0 / m_nhits;
42}
43
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
58
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
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
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", "");
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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
ATLAS-specific HepMC functions.
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
Definition MLogging.h:222
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...
virtual void Print(Option_t *option="") const override
bool Initialize(TFCS2DFunction *func, float nhits=-1)
Init from function.
TFCS2DFunction * m_function
Histogram to be used for the shape simulation.
TFCS2DFunctionLateralShapeParametrization(const char *name=nullptr, const char *title=nullptr)
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...
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
void set_number_of_hits(float nhits)
set the desired number of hits
void setEtaPhiZE(float eta, float phi, float z, float E)
TFCSLateralShapeParametrizationHitBase(const char *name=nullptr, const char *title=nullptr)
void Print(Option_t *option="") const override
CLHEP::HepRandomEngine * randomEngine()
int pdgid() const
int r
Definition globals.cxx:22
double charge(const T &p)