127 const int pdgId = truth->
pdgid();
131 const float Ekin = truth->
Ekin();
133 Einit = simulstate.
E();
139 if (!
m_slice->IsGanCorrectlyLoaded()) {
147 m_slice->GetNetworkOutputs(truth, extrapol, simulstate);
151 const auto ganVersion =
m_param.GetGANVersion();
157 double totalEnergy = 0;
158 for (
const auto & output : outputs) {
159 totalEnergy += output.second;
161 if (totalEnergy < 0) {
171 for (
const auto &[layer,
h] : binsInLayers) {
174 if (*
reinterpret_cast<void*
const*
>(&
h) ==
nullptr ||
h.IsZombie() ||
h.IsOnHeap() ||
dynamic_cast<const TH2D*
>(&
h) ==
nullptr) {
177 "See ATLASSIM-7031.");
179 std::ostringstream
ss;
180 ss <<
"Node dump:\n";
186 ss <<
"First node:\n";
187 auto it = binsInLayers.begin();
191 " on heap: " <<
h.IsOnHeap());
209 const int xBinNum =
h.GetNbinsX();
210 const int yBinNum =
h.GetNbinsY();
211 const TAxis *
x =
h.GetXaxis();
217 <<
" has only one bin in r, this means is it not used, "
218 "skipping (this is needed to keep correct "
219 "syncronisation of voxel and layers)");
227 for (
int ix = 1; ix <= xBinNum; ++ix) {
229 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
230 const double energyInVoxel = outputs.at(std::to_string(vox));
232 <<
" binx " << ix <<
" biny " << iy);
234 if (energyInVoxel <= 0) {
239 simulstate.
add_E(layer, Einit * energyInVoxel);
245 for (
unsigned int ichain =
m_bin_start.back(); ichain <
size(); ++ichain) {
254 for (
const auto &[layer,
h] : binsInLayers) {
255 const int xBinNum =
h.GetNbinsX();
256 const int yBinNum =
h.GetNbinsY();
257 const TAxis *
x =
h.GetXaxis();
258 const TAxis *
y =
h.GetYaxis();
260 simulstate.
setAuxInfo<
int>(
"GANlayer"_FCShash, layer);
267 <<
" has only one bin in r, this means is it not used, "
268 "skipping (this is needed to keep correct "
269 "syncronisation of voxel and layers)");
275 const int bin =
get_bin(simulstate, truth, extrapol);
283 <<
chain()[ichain]->GetName());
284 if (
chain()[ichain]->InheritsFrom(
285 TFCSLateralShapeParametrizationHitBase::Class())) {
288 if (sim->
simulate_hit(hit, simulstate, truth, extrapol) !=
293 <<
chain()[ichain]->GetName());
300 <<
chain()[ichain]->GetName()
301 <<
" does not inherit from "
302 "TFCSLateralShapeParametrizationHitBase");
313 int binResolution = 5;
314 if (layer == 1 || layer == 5) {
319 const double center_phi = hit.center_phi();
320 const double center_r = hit.center_r();
321 const double center_z = hit.center_z();
324 <<
" phi " << center_phi <<
" R " << center_r);
326 const float dist000 =
327 TMath::Sqrt(center_r * center_r + center_z * center_z);
328 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
329 (1.0 + TMath::Exp(-2 * center_eta)));
335 for (
int ix = 1; ix <= xBinNum; ++ix) {
339 const int binsToMerge = yBinNum == 32 ? 32 / binsInAlphaInRBin : 1;
340 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
341 const double energyInVoxel = outputs.at(std::to_string(vox));
342 const int lowEdgeIndex = (iy - 1) * binsToMerge + 1;
345 <<
" binx " << ix <<
" biny " << iy);
347 if (energyInVoxel <= 0) {
352 if (std::abs(pdgId) == 22 || std::abs(pdgId) == 11) {
354 int maxHitsInVoxel = energyInVoxel * truth->
Ekin() / 10;
355 if (maxHitsInVoxel < 1)
357 nHitsAlpha = std::sqrt(maxHitsInVoxel);
358 nHitsR = std::sqrt(maxHitsInVoxel);
361 nHitsR =
x->GetBinUpEdge(ix) -
x->GetBinLowEdge(ix);
364 const double r =
x->GetBinUpEdge(ix);
365 nHitsAlpha = ceil(2 * TMath::Pi() *
r / binResolution);
369 const double angle =
y->GetBinUpEdge(iy) -
y->GetBinLowEdge(iy);
370 const double r =
x->GetBinUpEdge(ix);
371 const double d = 2 *
r * sin(
angle / 2 *
r);
372 nHitsAlpha = ceil(d / binResolution);
375 if (layer != 1 && layer != 5) {
379 const int maxNhits = 10;
380 nHitsAlpha = std::min(maxNhits, std::max(1, nHitsAlpha));
381 nHitsR = std::min(maxNhits, std::max(1, nHitsR));
385 for (
int ir = 0;
ir < nHitsR; ++
ir) {
387 x->GetBinLowEdge(ix) +
x->GetBinWidth(ix) / (nHitsR + 1) *
ir;
389 for (
int ialpha = 1; ialpha <= nHitsAlpha; ++ialpha) {
390 if (ganVersion > 1) {
391 if (fitResults.at(layer)[ix - 1] != 0) {
394 x->GetBinLowEdge(ix),
395 x->GetBinUpEdge(ix));
397 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
398 fitResults.at(layer)[ix - 1];
399 while ((rand_r < x->GetBinLowEdge(ix) ||
400 rand_r >
x->GetBinUpEdge(ix)) &&
403 x->GetBinLowEdge(ix),
404 x->GetBinUpEdge(ix));
406 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
407 fitResults.at(layer)[ix - 1];
412 <<
x->GetBinLowEdge(ix) <<
"-"
413 <<
x->GetBinUpEdge(ix) <<
"] having slope "
414 << fitResults.at(layer)[ix - 1]
415 <<
" will use grid (old method)");
423 if (binsInAlphaInRBin == 1) {
424 alpha = CLHEP::RandFlat::shoot(simulstate.
randomEngine(),
425 -TMath::Pi(), TMath::Pi());
428 y->GetBinLowEdge(lowEdgeIndex) +
429 y->GetBinWidth(iy) * binsToMerge / (nHitsAlpha + 1) * ialpha;
431 if (
m_param.IsSymmetrisedAlpha()) {
433 -TMath::Pi(), TMath::Pi()) < 0) {
440 hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
443 float delta_eta_mm =
r * cos(alpha);
444 float delta_phi_mm =
r * sin(alpha);
454 delta_eta_mm = -delta_eta_mm;
459 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
460 delta_phi_mm = -delta_phi_mm;
462 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
463 const float delta_phi = delta_phi_mm / center_r;
465 hit.eta() = center_eta + delta_eta;
466 hit.phi() = TVector2::Phi_mpi_pi(center_phi + delta_phi);
469 <<
" layer " << layer);
471 const float hit_r =
r * cos(alpha) + center_r;
472 float delta_phi =
r * sin(alpha) / center_r;
477 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
478 delta_phi = -delta_phi;
479 const float hit_phi =
480 TVector2::Phi_mpi_pi(center_phi + delta_phi);
481 hit.x() = hit_r * cos(hit_phi);
482 hit.y() = hit_r * sin(hit_phi);
485 <<
" layer " << layer);
489 const int bin =
get_bin(simulstate, truth, extrapol);
491 for (
unsigned int ichain =
497 <<
chain()[ichain]->GetName());
498 if (
chain()[ichain]->InheritsFrom(
499 TFCSLateralShapeParametrizationHitBase::Class())) {
503 if (sim->
simulate_hit(hit, simulstate, truth, extrapol) !=
509 <<
chain()[ichain]->GetName());
516 <<
chain()[ichain]->GetName()
517 <<
" does not inherit from "
518 "TFCSLateralShapeParametrizationHitBase");
541 if (simulstate.
E() > std::numeric_limits<double>::epsilon()) {
543 simulstate.
set_Efrac(ilayer, simulstate.
E(ilayer) / simulstate.
E());
A number of constexpr particle constants to avoid hardcoding them directly in various places.