5#include "CLHEP/Random/RandFlat.h"
6#include "CLHEP/Random/RandPoisson.h"
26 const char *name,
const char *title)
40 if (!
m_hist.get_HistoContents().empty()) {
41 int first_fix_bin = -1;
42 for (
int i = (
int)(
m_hist.get_HistoContents().size() - 1); i >= 0; --i) {
43 if (std::isnan(
m_hist.get_HistoContents()[i])) {
45 << GetTitle() <<
", bin[" << i
46 <<
"]=" <<
m_hist.get_HistoContents()[i] <<
" -> 1");
47 m_hist.get_HistoContents()[i] = 1;
51 if (first_fix_bin < 0)
54 if (first_fix_bin == 0) {
57 <<
" for all bins. Fixed to probability 1 causing hits "
58 "to be deposited in the shower center");
60 int last_fix_bin = -1;
61 for (
size_t i = 0; i <
m_hist.get_HistoContents().
size(); ++i) {
62 if (std::isnan(
m_hist.get_HistoContents()[i])) {
64 << GetTitle() <<
", bin[" << i
65 <<
"]=" <<
m_hist.get_HistoContents()[i] <<
" -> 0");
66 m_hist.get_HistoContents()[i] = 0;
71 << GetTitle() <<
". Fixed up to bin " << last_fix_bin
72 <<
" with probability 0 and beyond bin " << first_fix_bin
73 <<
" with probability 1.");
108 const int pdgId = truth->
pdgid();
114 const double center_r = hit.
center_r();
115 const double center_z = hit.
center_z();
117 if (TMath::IsNaN(center_r) or TMath::IsNaN(center_z) or
118 TMath::IsNaN(center_eta) or
119 TMath::IsNaN(center_phi)) {
123 float alpha,
r, rnd1, rnd2;
124 rnd1 = CLHEP::RandFlat::shoot(simulstate.
randomEngine());
125 rnd2 = CLHEP::RandFlat::shoot(simulstate.
randomEngine());
130 m_hist.rnd_to_fct(alpha,
r, rnd1, rnd2);
134 m_hist.rnd_to_fct(alpha,
r, rnd1, rnd2);
137 m_hist.rnd_to_fct(alpha,
r, rnd1, rnd2);
139 if (TMath::IsNaN(alpha) || TMath::IsNaN(
r)) {
141 <<
m_hist.get_HistoBordersx().size() - 1 <<
"*"
142 <<
m_hist.get_HistoBordersy().size() - 1
143 <<
" bins, #hits=" <<
m_nhits <<
" alpha=" << alpha
144 <<
" r=" <<
r <<
" rnd1=" << rnd1 <<
" rnd2=" << rnd2);
157 float delta_eta_mm =
r * cos(alpha);
158 float delta_phi_mm =
r * sin(alpha);
163 delta_eta_mm = -delta_eta_mm;
167 if ((
charge < 0. && pdgId!=11) || pdgId==-11)
168 delta_phi_mm = -delta_phi_mm;
170 const float dist000 = TMath::Sqrt(center_r * center_r + center_z * center_z);
171 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
172 (1.0 + TMath::Exp(-2 * center_eta)));
174 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
175 const float delta_phi = delta_phi_mm / center_r;
177 hit.
setEtaPhiZE(center_eta + delta_eta, center_phi + delta_phi, center_z,
181 <<
" phi=" << hit.
phi() <<
" z=" << hit.
z()
182 <<
" r=" <<
r <<
" alpha=" << alpha);
191 if (
m_hist.get_HistoContents().empty())
200 const char *histname) {
202 std::unique_ptr<TFile> inputfile(TFile::Open(filepath,
"READ"));
203 if (inputfile ==
nullptr)
207 TH2 *inputShape = (TH2 *)inputfile->Get(histname);
208 if (inputShape ==
nullptr)
220 bool shortprint = opt.Index(
"short") >= 0;
221 bool longprint =
msgLvl(MSG::DEBUG) || (
msgLvl(MSG::INFO) && !shortprint);
222 TString optprint = opt;
223 optprint.ReplaceAll(
"short",
"");
229 <<
" Histo: " <<
m_hist.get_HistoBordersx().size() - 1
230 <<
"*" <<
m_hist.get_HistoBordersy().size() - 1
232 <<
", r offset=" <<
m_r_offset <<
"mm (phi symmetric)");
235 <<
" Histo: " <<
m_hist.get_HistoBordersx().size() - 1
236 <<
"*" <<
m_hist.get_HistoBordersy().size() - 1
238 <<
", r offset=" <<
m_r_offset <<
"mm (not phi symmetric)");
244void TFCSHistoLateralShapeParametrization::LoadHistFuncs() {
250 FH2D fh = {0, 0, 0, 0, 0};
260 m_LdFH->set_hf2d(&fh);
#define ATH_MSG_WARNING(x)
double charge(const T &p)
ATLAS-specific HepMC functions.
size_t size() const
Number of registered mappings.
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.
virtual void set_geometry(ICaloGeometry *geo) override
will actually not store the geometry information, but rather used to check the validity of the 2D sha...
void Print(Option_t *option="") const override
bool is_phi_symmetric() const
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
virtual void reset_phi_symmetric()
bool Initialize(TH2 *hist)
Init from histogram.
~TFCSHistoLateralShapeParametrization()
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...
TFCS2DFunctionHistogram m_hist
Histogram to be used for the shape simulation.
TFCSHistoLateralShapeParametrization(const char *name=nullptr, const char *title=nullptr)
void set_number_of_hits(float nhits)
set the integral of the histogram to the desired number of hits
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...
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
virtual void set_geometry(ICaloGeometry *geo)
Method to set the geometry access pointer.
CLHEP::HepRandomEngine * randomEngine()
double charge(const T &p)