5 #include "CLHEP/Random/RandGaussZiggurat.h"
6 #include "CLHEP/Random/RandFlat.h"
18 #include "TMatrixDSymEigen.h"
35 if (Ekin_bin >= 1 && Ekin_bin <=
n_bins())
50 bool shortprint =
opt.Index(
"short") >= 0;
52 TString optprint =
opt;
53 optprint.ReplaceAll(
"short",
"");
75 if (x <= hist->GetBinCenter(1))
76 return hist->GetBinContent(1);
77 if (
x >=
hist->GetBinCenter(
hist->GetNbinsX()))
78 return hist->GetBinContent(
hist->GetNbinsX());
90 if (x <= hist->GetBinCenter(
bin)) {
112 int Ekin_bin)
const {
128 int pcabin = simulstate.
Ebin();
138 TMatrixD *EV =
m_EV[pcabin - 1];
143 std::vector<TFCS1DFunction *> cumulative =
m_cumulative[pcabin - 1];
147 double *vals_gauss_means = (
double *)Gauss_means->GetMatrixArray();
148 double *vals_gauss_rms = Gauss_rms->GetMatrixArray();
150 double *output_data =
new double[layerNr.size() + 1];
151 double *input_data =
new double[layerNr.size() + 1];
153 for (
unsigned int l = 0;
l <= layerNr.size();
l++) {
154 double mean = vals_gauss_means[
l];
155 double rms = vals_gauss_rms[
l];
158 input_data[
l] = gauszz;
161 P2X(SigmaValues, MeanValues, EV, layerNr.size() + 1, input_data,
162 output_data, layerNr.size() + 1);
164 double *simdata =
new double[layerNr.size() + 1];
165 double sum_fraction = 0.0;
166 for (
unsigned int l = 0;
l <= layerNr.size();
l++) {
167 double simdata_uniform =
168 (TMath::Erf(output_data[
l] / 1.414213562) + 1) / 2.
f;
170 simdata[
l] = cumulative[
l]->rnd_to_fct(simdata_uniform);
172 if (
l != layerNr.size())
173 sum_fraction += simdata[
l];
176 double scalefactor = 1.0 / sum_fraction;
182 int layerNrsize =
static_cast<int>(layerNr.size());
183 for (
int l = 0;
l < layerNrsize;
l++) {
184 simdata[
l] *= scalefactor;
191 if (h_totalE_ratio) {
192 float pass_probability = 0;
193 float Etot = simdata[layerNr.size()];
194 if (Etot > h_totalE_ratio->GetXaxis()->GetXmin() &&
195 Etot < h_totalE_ratio->GetXaxis()->GetXmax()) {
198 float random = CLHEP::RandFlat::shoot(simulstate.
randomEngine());
199 if (random > pass_probability) {
200 delete[] output_data;
208 double total_energy =
210 simulstate.
set_E(total_energy);
214 double energyfrac = 0.0;
215 for (
unsigned int l = 0;
l < layerNr.size();
l++) {
217 energyfrac = simdata[
l];
220 simulstate.
set_E(
s, energyfrac * total_energy);
221 simulstate.
set_SF(scalefactor);
224 delete[] output_data;
233 TVectorD *MeanValues, TMatrixD *EV,
234 int gNVariables,
const double *
p,
237 const double *gSigmaValues = SigmaValues->GetMatrixArray();
238 const double *gMeanValues = MeanValues->GetMatrixArray();
239 const double *gEigenVectors = EV->GetMatrixArray();
241 for (
int i = 0;
i < gNVariables;
i++) {
242 x[
i] = gMeanValues[
i];
243 for (
int j = 0; j < nTest; j++) {
245 p[j] * gSigmaValues[
i] * (
double)(gEigenVectors[
i * gNVariables + j]);
255 const std::string &
folder) {
276 file->cd(
x +
"1/pca");
278 if (RelevantLayers ==
nullptr) {
279 ATH_MSG_ERROR(
"TFCSPCAEnergyParametrization::m_RelevantLayers in first "
288 for (
int i = 0;
i < RelevantLayers->GetSize();
i++)
295 TMatrixDSym *symCov = (TMatrixDSym *)
gDirectory->Get(
"symCov");
296 TVectorD *MeanValues = (TVectorD *)
gDirectory->Get(
"MeanValues");
297 TVectorD *SigmaValues = (TVectorD *)
gDirectory->Get(
"SigmaValues");
298 TVectorD *Gauss_means = (TVectorD *)
gDirectory->Get(
"Gauss_means");
299 TVectorD *Gauss_rms = (TVectorD *)
gDirectory->Get(
"Gauss_rms");
301 if (symCov ==
nullptr) {
303 <<
bin <<
" is null!");
306 if (MeanValues ==
nullptr) {
308 <<
bin <<
" is null!");
311 if (SigmaValues ==
nullptr) {
313 <<
bin <<
" is null!");
316 if (Gauss_means ==
nullptr) {
318 <<
bin <<
" is null!");
321 if (Gauss_rms ==
nullptr) {
323 <<
bin <<
" is null!");
330 TMatrixDSymEigen cov_eigen(*symCov);
331 TMatrixD *EV =
new TMatrixD(cov_eigen.GetEigenVectors());
338 std::vector<std::string>
layer;
341 for (
unsigned int i = 0;
i < layerNr.size();
i++) {
342 layer.emplace_back(Form(
"layer%i", layerNr[
i]));
344 layer.emplace_back(
"totalE");
346 std::vector<TFCS1DFunction *> cumulative;
347 cumulative.reserve(
layer.size());
349 for (
unsigned int l = 0;
l <
layer.size();
l++) {
358 cumulative.push_back(
fct);
369 for (
unsigned int i = 0;
i <
m_EV.size();
i++)
373 void TFCSPCAEnergyParametrization::Streamer(TBuffer &R__b) {
376 if (R__b.IsReading()) {
378 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
379 R__b.SetBufferOffset(R__s);
381 R__b.ReadClassBuffer(TFCSPCAEnergyParametrization::Class(),
this);
395 R__b.WriteClassBuffer(TFCSPCAEnergyParametrization::Class(),
this);