7#include "CLHEP/Random/RandFlat.h"
8#include "CLHEP/Random/RandGauss.h"
20#include "TMatrixDSym.h"
21#include "TMatrixDSymEigen.h"
30 "PreSamplerB"_FCShash,
"EMB1"_FCShash,
"EMB2"_FCShash,
31 "EMB3"_FCShash,
"PreSamplerE"_FCShash,
"EME1"_FCShash,
32 "EME2"_FCShash,
"EME3"_FCShash,
"HEC0"_FCShash,
33 "HEC1"_FCShash,
"HEC2"_FCShash,
"HEC3"_FCShash,
34 "TileBar0"_FCShash,
"TileBar1"_FCShash,
"TileBar2"_FCShash,
35 "TileGap1"_FCShash,
"TileGap2"_FCShash,
"TileGap3"_FCShash,
36 "TileExt0"_FCShash,
"TileExt1"_FCShash,
"TileExt2"_FCShash,
37 "FCAL0"_FCShash,
"FCAL1"_FCShash,
"FCAL2"_FCShash};
39const std::uint32_t TFCSVoxelHistoLateralCovarianceFluctuations::
41 "PreSamplerB_geo"_FCShash,
"EMB1_geo"_FCShash,
42 "EMB2_geo"_FCShash,
"EMB3_geo"_FCShash,
43 "PreSamplerE_geo"_FCShash,
"EME1_geo"_FCShash,
44 "EME2_geo"_FCShash,
"EME3_geo"_FCShash,
45 "HEC0_geo"_FCShash,
"HEC1_geo"_FCShash,
46 "HEC2_geo"_FCShash,
"HEC3_geo"_FCShash,
47 "TileBar0_geo"_FCShash,
"TileBar1_geo"_FCShash,
48 "TileBar2_geo"_FCShash,
"TileGap1_geo"_FCShash,
49 "TileGap2_geo"_FCShash,
"TileGap3_geo"_FCShash,
50 "TileExt0_geo"_FCShash,
"TileExt1_geo"_FCShash,
51 "TileExt2_geo"_FCShash,
"FCAL0_geo"_FCShash,
52 "FCAL1_geo"_FCShash,
"FCAL2_geo"_FCShash};
63 TFile *inputfile,
const std::string &folder) {
69 inputfile->cd(folder.c_str());
75 TH2 *temp =
dynamic_cast<TH2 *
>(
76 inputfile->Get(Form(
"voxel_template_cs%d_pca%d", cs,
bin)));
78 ATH_MSG_ERROR(
"Template hist not found for cs " + std::to_string(cs));
85 while (inputfile->Get(Form(
"parMeans_cs%d_pca%d", cs,
bin))) {
87 TMatrixD EigenVectors;
89 std::vector<std::vector<TFCS1DFunction *>> transform;
91 std::string
label = Form(
"_cs%d_pca%d", cs,
bin);
93 TObject *obj = inputfile->Get((
"parMeans" +
label).c_str());
103 parMeans = *
dynamic_cast<TVectorT<double> *
>(obj);
106 obj = inputfile->Get((
"covMatrix" +
label).c_str());
111 TMatrixTSym<double> covMatrix = *
dynamic_cast<TMatrixTSym<double> *
>(obj);
112 TMatrixDSymEigen eigenvariances = TMatrixDSymEigen(covMatrix);
113 EigenVectors.ResizeTo(eigenvariances.GetEigenVectors());
114 EigenVectors = eigenvariances.GetEigenVectors();
117 EigenValues.ResizeTo(eigenvariances.GetEigenValues());
118 EigenValues = eigenvariances.GetEigenValues();
123 eigenvariances.GetEigenValues().Print();
124 eigenvariances.GetEigenVectors().Print();
130 EigenVectors.Print();
138 std::string histname = Form(
"hist_%d_%d%s",
x,
y,
label.c_str());
139 TH1 *hist = (TH1 *)inputfile->Get(histname.c_str());
147 transform[
x][
y] = func;
161 int Ebin = simulstate.
Ebin();
164 genPars.ResizeTo(nPars);
167 for (
int iPar = 0; iPar < nPars; iPar++) {
172 <<
") on iPar = " << iPar);
175 genPars[iPar] = CLHEP::RandGauss::shoot(simulstate.
randomEngine(),
176 rotParMeans[iPar], sqrt(variance));
178 <<
" rotParMeans[iPar]=" << rotParMeans[iPar]
179 <<
" sqrt(variance)=" << sqrt(variance));
199 int Ebin = simulstate.
Ebin();
203 weightvec =
static_cast<weight_t *
>(
211 voxel_temp =
static_cast<TH2 *
>(
238 TVectorD genPars(
m_parMeans[Ebin - 1].GetNrows());
249 (TMath::Erf(genPars[
count] * 2.0 / TMath::Pi()) + 1) / 2.0;
252 double orig_val =
m_transform[Ebin - 1][
x][
y]->rnd_to_fct(cdf_val);
255 (*weightvec)[
x][
y] = orig_val;
259 <<
" orig_val=" << orig_val);
270 ATH_MSG_DEBUG(
"simulstate after storing weight " << weightvec
283 const double center_r = hit.
center_r();
284 const double center_z = hit.
center_z();
289 weightvec =
static_cast<weight_t *
>(
293 ATH_MSG_ERROR(
"Weights not stored in simulstate for calosample=" << cs);
297 TH2 *voxel_template =
nullptr;
301 if (!voxel_template) {
303 "Voxel geometry not stored in simulstate for calosample=" << cs);
337 float deta_hit_minus_extrapol = hit.
eta() - center_eta;
338 float dphi_hit_minus_extrapol = TVector2::Phi_mpi_pi(hit.
phi() - center_phi);
342 deta_hit_minus_extrapol = -deta_hit_minus_extrapol;
344 float phi_dist2r = 1.0;
345 float dist000 = TMath::Sqrt(center_r * center_r + center_z * center_z);
346 float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-hit.
eta()) /
347 (1.0 + TMath::Exp(-2 * hit.
eta())));
349 float deta_hit_minus_extrapol_mm =
350 deta_hit_minus_extrapol * eta_jakobi * dist000;
351 float dphi_hit_minus_extrapol_mm =
352 dphi_hit_minus_extrapol * center_r * phi_dist2r;
355 TMath::ATan2(dphi_hit_minus_extrapol_mm, deta_hit_minus_extrapol_mm);
357 TMath::Sqrt(dphi_hit_minus_extrapol_mm * dphi_hit_minus_extrapol_mm +
358 deta_hit_minus_extrapol_mm * deta_hit_minus_extrapol_mm);
361 int iy = voxel_template->GetYaxis()->FindBin(radius_mm) - 1;
368 ix = voxel_template->GetXaxis()->FindBin(2 * TMath::Pi() -
372 ix = voxel_template->GetXaxis()->FindBin(alpha_mm) - 1;
375 const int sizex = (*weightvec).size();
378 if (ix >= 0 && ix < sizex) {
379 const int sizey = (*weightvec)[ix].size();
380 if (iy >= 0 && iy < sizey) {
381 weight = (*weightvec)[ix][iy];
388 <<
", r = " << center_r <<
", ix = " << ix
389 <<
", iy = " << iy <<
", weight = " << weight);
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.
void Initialize(const TH1 *hist, bool doprint=true)
Initialize from root histogram.
TFCSLateralShapeParametrizationHitBase(const char *name=nullptr, const char *title=nullptr)
void Print(Option_t *option="") const
bool hasAuxInfo(std::uint32_t index) const
const T getAuxInfo(std::uint32_t index) const
void setAuxInfo(std::uint32_t index, const T &val)
CLHEP::HepRandomEngine * randomEngine()
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
create one fluctuated shape for a shower to be applied as scale factor to the average shape Store the...
virtual ~TFCSVoxelHistoLateralCovarianceFluctuations()
std::vector< std::vector< std::vector< TFCS1DFunction * > > > m_transform
static const std::uint32_t s_layer_hash[CaloCell_ID_FCS::MaxSample]
do not persistify
std::vector< TMatrixD > m_EigenVectors
void MultiGaus(TFCSSimulationState &simulstate, TVectorD &genPars) const
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) override
weight the energy of one hit by the fluctuation calculated in simulate(...)
std::vector< TVectorD > m_parMeans
bool initialize(TFile *inputfile, const std::string &folder)
TFCSVoxelHistoLateralCovarianceFluctuations(const char *name=nullptr, const char *title=nullptr)
std::vector< std::vector< float > > weight_t
do not persistify
std::vector< TVectorD > m_EigenValues
std::vector< TH2 * > m_voxel_template
static const std::uint32_t s_layer_hash_geo[CaloCell_ID_FCS::MaxSample]
do not persistify
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
std::string label(const std::string &format, int i)