127 const int pdgId = truth->
pdgid();
131 const float Ekin = truth->
Ekin();
133 Einit = simulstate.
E();
139 if (!
m_slice->IsGanCorrectlyLoaded()) {
144 m_slice->GetNetworkOutputs(truth, extrapol, simulstate);
148 const auto ganVersion =
m_param.GetGANVersion();
154 double totalEnergy = 0;
155 for (
const auto & output : outputs) {
156 totalEnergy += output.second;
158 if (totalEnergy < 0) {
168 for (
const auto &[layer,
h] : binsInLayers) {
169 const int xBinNum =
h.GetNbinsX();
170 const int yBinNum =
h.GetNbinsY();
171 const TAxis *
x =
h.GetXaxis();
177 <<
" has only one bin in r, this means is it not used, "
178 "skipping (this is needed to keep correct "
179 "syncronisation of voxel and layers)");
187 for (
int ix = 1; ix <= xBinNum; ++ix) {
189 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
190 const double energyInVoxel = outputs.at(std::to_string(vox));
192 <<
" binx " << ix <<
" biny " << iy);
194 if (energyInVoxel <= 0) {
199 simulstate.
add_E(layer, Einit * energyInVoxel);
205 for (
unsigned int ichain =
m_bin_start.back(); ichain <
size(); ++ichain) {
214 for (
const auto &[layer,
h] : binsInLayers) {
215 const int xBinNum =
h.GetNbinsX();
216 const int yBinNum =
h.GetNbinsY();
217 const TAxis *
x =
h.GetXaxis();
218 const TAxis *
y =
h.GetYaxis();
220 simulstate.
setAuxInfo<
int>(
"GANlayer"_FCShash, layer);
227 <<
" has only one bin in r, this means is it not used, "
228 "skipping (this is needed to keep correct "
229 "syncronisation of voxel and layers)");
235 const int bin =
get_bin(simulstate, truth, extrapol);
243 <<
chain()[ichain]->GetName());
244 if (
chain()[ichain]->InheritsFrom(
245 TFCSLateralShapeParametrizationHitBase::Class())) {
253 <<
chain()[ichain]->GetName());
260 <<
chain()[ichain]->GetName()
261 <<
" does not inherit from "
262 "TFCSLateralShapeParametrizationHitBase");
273 int binResolution = 5;
274 if (layer == 1 || layer == 5) {
278 const double center_eta =
hit.center_eta();
279 const double center_phi =
hit.center_phi();
280 const double center_r =
hit.center_r();
281 const double center_z =
hit.center_z();
284 <<
" phi " << center_phi <<
" R " << center_r);
286 const float dist000 =
287 TMath::Sqrt(center_r * center_r + center_z * center_z);
288 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
289 (1.0 + TMath::Exp(-2 * center_eta)));
295 for (
int ix = 1; ix <= xBinNum; ++ix) {
299 const int binsToMerge = yBinNum == 32 ? 32 / binsInAlphaInRBin : 1;
300 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
301 const double energyInVoxel = outputs.at(std::to_string(vox));
302 const int lowEdgeIndex = (iy - 1) * binsToMerge + 1;
305 <<
" binx " << ix <<
" biny " << iy);
307 if (energyInVoxel <= 0) {
312 if (std::abs(pdgId) == 22 || std::abs(pdgId) == 11) {
314 int maxHitsInVoxel = energyInVoxel * truth->
Ekin() / 10;
315 if (maxHitsInVoxel < 1)
317 nHitsAlpha = std::sqrt(maxHitsInVoxel);
318 nHitsR = std::sqrt(maxHitsInVoxel);
321 nHitsR =
x->GetBinUpEdge(ix) -
x->GetBinLowEdge(ix);
324 const double r =
x->GetBinUpEdge(ix);
325 nHitsAlpha = ceil(2 * TMath::Pi() *
r / binResolution);
329 const double angle =
y->GetBinUpEdge(iy) -
y->GetBinLowEdge(iy);
330 const double r =
x->GetBinUpEdge(ix);
331 const double d = 2 *
r * sin(
angle / 2 *
r);
332 nHitsAlpha = ceil(d / binResolution);
335 if (layer != 1 && layer != 5) {
339 const int maxNhits = 10;
340 nHitsAlpha = std::min(maxNhits, std::max(1, nHitsAlpha));
341 nHitsR = std::min(maxNhits, std::max(1, nHitsR));
345 for (
int ir = 0;
ir < nHitsR; ++
ir) {
347 x->GetBinLowEdge(ix) +
x->GetBinWidth(ix) / (nHitsR + 1) *
ir;
349 for (
int ialpha = 1; ialpha <= nHitsAlpha; ++ialpha) {
350 if (ganVersion > 1) {
351 if (fitResults.at(layer)[ix - 1] != 0) {
354 x->GetBinLowEdge(ix),
355 x->GetBinUpEdge(ix));
357 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
358 fitResults.at(layer)[ix - 1];
359 while ((rand_r < x->GetBinLowEdge(ix) ||
360 rand_r >
x->GetBinUpEdge(ix)) &&
363 x->GetBinLowEdge(ix),
364 x->GetBinUpEdge(ix));
366 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
367 fitResults.at(layer)[ix - 1];
372 <<
x->GetBinLowEdge(ix) <<
"-"
373 <<
x->GetBinUpEdge(ix) <<
"] having slope "
374 << fitResults.at(layer)[ix - 1]
375 <<
" will use grid (old method)");
383 if (binsInAlphaInRBin == 1) {
384 alpha = CLHEP::RandFlat::shoot(simulstate.
randomEngine(),
385 -TMath::Pi(), TMath::Pi());
388 y->GetBinLowEdge(lowEdgeIndex) +
389 y->GetBinWidth(iy) * binsToMerge / (nHitsAlpha + 1) * ialpha;
391 if (
m_param.IsSymmetrisedAlpha()) {
393 -TMath::Pi(), TMath::Pi()) < 0) {
400 hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
403 float delta_eta_mm =
r * cos(alpha);
404 float delta_phi_mm =
r * sin(alpha);
414 delta_eta_mm = -delta_eta_mm;
419 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
420 delta_phi_mm = -delta_phi_mm;
422 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
423 const float delta_phi = delta_phi_mm / center_r;
425 hit.eta() = center_eta + delta_eta;
426 hit.phi() = TVector2::Phi_mpi_pi(center_phi + delta_phi);
429 <<
" layer " << layer);
431 const float hit_r =
r * cos(alpha) + center_r;
432 float delta_phi =
r * sin(alpha) / center_r;
437 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
438 delta_phi = -delta_phi;
439 const float hit_phi =
440 TVector2::Phi_mpi_pi(center_phi + delta_phi);
441 hit.x() = hit_r * cos(hit_phi);
442 hit.y() = hit_r * sin(hit_phi);
445 <<
" layer " << layer);
449 const int bin =
get_bin(simulstate, truth, extrapol);
451 for (
unsigned int ichain =
457 <<
chain()[ichain]->GetName());
458 if (
chain()[ichain]->InheritsFrom(
459 TFCSLateralShapeParametrizationHitBase::Class())) {
469 <<
chain()[ichain]->GetName());
476 <<
chain()[ichain]->GetName()
477 <<
" does not inherit from "
478 "TFCSLateralShapeParametrizationHitBase");
501 if (simulstate.
E() > std::numeric_limits<double>::epsilon()) {
503 simulstate.
set_Efrac(ilayer, simulstate.
E(ilayer) / simulstate.
E());
A number of constexpr particle constants to avoid hardcoding them directly in various places.
constexpr double chargedPionMassInMeV
the mass of the charged pion (in MeV)