5#include "CLHEP/Random/RandFlat.h"
6#include "CLHEP/Random/RandPoisson.h"
17#include "HepPDT/ParticleData.hh"
18#include "HepPDT/ParticleDataTable.hh"
27 const char *name,
const char *title)
41 if (!
m_hist.get_HistoContents().empty()) {
42 int first_fix_bin = -1;
43 for (
int i = (
int)(
m_hist.get_HistoContents().size() - 1); i >= 0; --i) {
44 if (std::isnan(
m_hist.get_HistoContents()[i])) {
46 << GetTitle() <<
", bin[" << i
47 <<
"]=" <<
m_hist.get_HistoContents()[i] <<
" -> 1");
48 m_hist.get_HistoContents()[i] = 1;
52 if (first_fix_bin < 0)
55 if (first_fix_bin == 0) {
58 <<
" for all bins. Fixed to probability 1 causing hits "
59 "to be deposited in the shower center");
61 int last_fix_bin = -1;
62 for (
size_t i = 0; i <
m_hist.get_HistoContents().
size(); ++i) {
63 if (std::isnan(
m_hist.get_HistoContents()[i])) {
65 << GetTitle() <<
", bin[" << i
66 <<
"]=" <<
m_hist.get_HistoContents()[i] <<
" -> 0");
67 m_hist.get_HistoContents()[i] = 0;
72 << GetTitle() <<
". Fixed up to bin " << last_fix_bin
73 <<
" with probability 0 and beyond bin " << first_fix_bin
74 <<
" with probability 1.");
109 const int pdgId = truth->
pdgid();
110 const double charge = HepPDT::ParticleID(pdgId).charge();
115 const double center_r = hit.
center_r();
116 const double center_z = hit.
center_z();
118 if (TMath::IsNaN(center_r) or TMath::IsNaN(center_z) or
119 TMath::IsNaN(center_eta) or
120 TMath::IsNaN(center_phi)) {
124 float alpha,
r, rnd1, rnd2;
125 rnd1 = CLHEP::RandFlat::shoot(simulstate.
randomEngine());
126 rnd2 = CLHEP::RandFlat::shoot(simulstate.
randomEngine());
131 m_hist.rnd_to_fct(alpha,
r, rnd1, rnd2);
135 m_hist.rnd_to_fct(alpha,
r, rnd1, rnd2);
138 m_hist.rnd_to_fct(alpha,
r, rnd1, rnd2);
140 if (TMath::IsNaN(alpha) || TMath::IsNaN(
r)) {
142 <<
m_hist.get_HistoBordersx().size() - 1 <<
"*"
143 <<
m_hist.get_HistoBordersy().size() - 1
144 <<
" bins, #hits=" <<
m_nhits <<
" alpha=" << alpha
145 <<
" r=" <<
r <<
" rnd1=" << rnd1 <<
" rnd2=" << rnd2);
158 float delta_eta_mm =
r * cos(alpha);
159 float delta_phi_mm =
r * sin(alpha);
164 delta_eta_mm = -delta_eta_mm;
168 if ((
charge < 0. && pdgId!=11) || pdgId==-11)
169 delta_phi_mm = -delta_phi_mm;
171 const float dist000 = TMath::Sqrt(center_r * center_r + center_z * center_z);
172 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
173 (1.0 + TMath::Exp(-2 * center_eta)));
175 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
176 const float delta_phi = delta_phi_mm / center_r;
178 hit.
setEtaPhiZE(center_eta + delta_eta, center_phi + delta_phi, center_z,
182 <<
" phi=" << hit.
phi() <<
" z=" << hit.
z()
183 <<
" r=" <<
r <<
" alpha=" << alpha);
192 if (
m_hist.get_HistoContents().empty())
201 const char *histname) {
203 std::unique_ptr<TFile> inputfile(TFile::Open(filepath,
"READ"));
204 if (inputfile ==
nullptr)
208 TH2 *inputShape = (TH2 *)inputfile->Get(histname);
209 if (inputShape ==
nullptr)
221 bool shortprint = opt.Index(
"short") >= 0;
222 bool longprint =
msgLvl(MSG::DEBUG) || (
msgLvl(MSG::INFO) && !shortprint);
223 TString optprint = opt;
224 optprint.ReplaceAll(
"short",
"");
230 <<
" Histo: " <<
m_hist.get_HistoBordersx().size() - 1
231 <<
"*" <<
m_hist.get_HistoBordersy().size() - 1
233 <<
", r offset=" <<
m_r_offset <<
"mm (phi symmetric)");
236 <<
" Histo: " <<
m_hist.get_HistoBordersx().size() - 1
237 <<
"*" <<
m_hist.get_HistoBordersy().size() - 1
239 <<
", r offset=" <<
m_r_offset <<
"mm (not phi symmetric)");
245void TFCSHistoLateralShapeParametrization::LoadHistFuncs() {
251 FH2D fh = {0, 0, 0, 0, 0};
261 m_LdFH->set_hf2d(&fh);
#define ATH_MSG_WARNING(x)
double charge(const T &p)
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.
virtual unsigned int size() const
Some derived classes have daughter instances of TFCSParametrizationBase objects The size() and operat...
CLHEP::HepRandomEngine * randomEngine()