126 const int pdgId = truth->
pdgid();
127 const float charge = HepPDT::ParticleID(pdgId).charge();
130 const float Ekin = truth->
Ekin();
132 Einit = simulstate.
E();
138 if (!
m_slice->IsGanCorrectlyLoaded()) {
144 std::scoped_lock lock(
m_mutex);
146 m_slice->GetNetworkOutputs(truth, extrapol, simulstate);
150 const auto ganVersion =
m_param.GetGANVersion();
156 double totalEnergy = 0;
157 for (
const auto & output : outputs) {
158 totalEnergy += output.second;
160 if (totalEnergy < 0) {
170 for (
const auto &[layer,
h] : binsInLayers) {
186 ATH_MSG_ERROR(
"Histogram pointer for layer " << layer <<
" is broken");
190 const int xBinNum =
h.GetNbinsX();
191 const int yBinNum =
h.GetNbinsY();
192 const TAxis *
x =
h.GetXaxis();
198 <<
" has only one bin in r, this means is it not used, "
199 "skipping (this is needed to keep correct "
200 "syncronisation of voxel and layers)");
208 for (
int ix = 1; ix <= xBinNum; ++ix) {
210 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
211 const double energyInVoxel = outputs.at(std::to_string(vox));
213 <<
" binx " << ix <<
" biny " << iy);
215 if (energyInVoxel <= 0) {
220 simulstate.
add_E(layer, Einit * energyInVoxel);
226 for (
unsigned int ichain =
m_bin_start.back(); ichain <
size(); ++ichain) {
235 for (
const auto &[layer,
h] : binsInLayers) {
236 const int xBinNum =
h.GetNbinsX();
237 const int yBinNum =
h.GetNbinsY();
238 const TAxis *
x =
h.GetXaxis();
239 const TAxis *
y =
h.GetYaxis();
241 simulstate.
setAuxInfo<
int>(
"GANlayer"_FCShash, layer);
248 <<
" has only one bin in r, this means is it not used, "
249 "skipping (this is needed to keep correct "
250 "syncronisation of voxel and layers)");
256 const int bin =
get_bin(simulstate, truth, extrapol);
264 <<
chain()[ichain]->GetName());
265 if (
chain()[ichain]->InheritsFrom(
266 TFCSLateralShapeParametrizationHitBase::Class())) {
269 if (sim->
simulate_hit(hit, simulstate, truth, extrapol) !=
274 <<
chain()[ichain]->GetName());
281 <<
chain()[ichain]->GetName()
282 <<
" does not inherit from "
283 "TFCSLateralShapeParametrizationHitBase");
294 int binResolution = 5;
295 if (layer == 1 || layer == 5) {
300 const double center_phi = hit.center_phi();
301 const double center_r = hit.center_r();
302 const double center_z = hit.center_z();
305 <<
" phi " << center_phi <<
" R " << center_r);
307 const float dist000 =
308 TMath::Sqrt(center_r * center_r + center_z * center_z);
309 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
310 (1.0 + TMath::Exp(-2 * center_eta)));
316 for (
int ix = 1; ix <= xBinNum; ++ix) {
320 const int binsToMerge = yBinNum == 32 ? 32 / binsInAlphaInRBin : 1;
321 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
322 const double energyInVoxel = outputs.at(std::to_string(vox));
323 const int lowEdgeIndex = (iy - 1) * binsToMerge + 1;
326 <<
" binx " << ix <<
" biny " << iy);
328 if (energyInVoxel <= 0) {
333 if (std::abs(pdgId) == 22 || std::abs(pdgId) == 11) {
335 int maxHitsInVoxel = energyInVoxel * truth->
Ekin() / 10;
336 if (maxHitsInVoxel < 1)
338 nHitsAlpha = std::sqrt(maxHitsInVoxel);
339 nHitsR = std::sqrt(maxHitsInVoxel);
342 nHitsR =
x->GetBinUpEdge(ix) -
x->GetBinLowEdge(ix);
345 const double r =
x->GetBinUpEdge(ix);
346 nHitsAlpha = ceil(2 * TMath::Pi() *
r / binResolution);
350 const double angle =
y->GetBinUpEdge(iy) -
y->GetBinLowEdge(iy);
351 const double r =
x->GetBinUpEdge(ix);
352 const double d = 2 *
r * sin(
angle / 2 *
r);
353 nHitsAlpha = ceil(d / binResolution);
356 if (layer != 1 && layer != 5) {
360 const int maxNhits = 10;
361 nHitsAlpha = std::min(maxNhits, std::max(1, nHitsAlpha));
362 nHitsR = std::min(maxNhits, std::max(1, nHitsR));
366 for (
int ir = 0;
ir < nHitsR; ++
ir) {
368 x->GetBinLowEdge(ix) +
x->GetBinWidth(ix) / (nHitsR + 1) *
ir;
370 for (
int ialpha = 1; ialpha <= nHitsAlpha; ++ialpha) {
371 if (ganVersion > 1) {
372 if (fitResults.at(layer)[ix - 1] != 0) {
375 x->GetBinLowEdge(ix),
376 x->GetBinUpEdge(ix));
378 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
379 fitResults.at(layer)[ix - 1];
380 while ((rand_r < x->GetBinLowEdge(ix) ||
381 rand_r >
x->GetBinUpEdge(ix)) &&
384 x->GetBinLowEdge(ix),
385 x->GetBinUpEdge(ix));
387 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
388 fitResults.at(layer)[ix - 1];
393 <<
x->GetBinLowEdge(ix) <<
"-"
394 <<
x->GetBinUpEdge(ix) <<
"] having slope "
395 << fitResults.at(layer)[ix - 1]
396 <<
" will use grid (old method)");
404 if (binsInAlphaInRBin == 1) {
405 alpha = CLHEP::RandFlat::shoot(simulstate.
randomEngine(),
406 -TMath::Pi(), TMath::Pi());
409 y->GetBinLowEdge(lowEdgeIndex) +
410 y->GetBinWidth(iy) * binsToMerge / (nHitsAlpha + 1) * ialpha;
412 if (
m_param.IsSymmetrisedAlpha()) {
414 -TMath::Pi(), TMath::Pi()) < 0) {
421 hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
424 float delta_eta_mm =
r * cos(alpha);
425 float delta_phi_mm =
r * sin(alpha);
435 delta_eta_mm = -delta_eta_mm;
440 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
441 delta_phi_mm = -delta_phi_mm;
443 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
444 const float delta_phi = delta_phi_mm / center_r;
446 hit.eta() = center_eta + delta_eta;
447 hit.phi() = TVector2::Phi_mpi_pi(center_phi + delta_phi);
450 <<
" layer " << layer);
452 const float hit_r =
r * cos(alpha) + center_r;
453 float delta_phi =
r * sin(alpha) / center_r;
458 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
459 delta_phi = -delta_phi;
460 const float hit_phi =
461 TVector2::Phi_mpi_pi(center_phi + delta_phi);
462 hit.x() = hit_r * cos(hit_phi);
463 hit.y() = hit_r * sin(hit_phi);
466 <<
" layer " << layer);
470 const int bin =
get_bin(simulstate, truth, extrapol);
472 for (
unsigned int ichain =
478 <<
chain()[ichain]->GetName());
479 if (
chain()[ichain]->InheritsFrom(
480 TFCSLateralShapeParametrizationHitBase::Class())) {
484 if (sim->
simulate_hit(hit, simulstate, truth, extrapol) !=
490 <<
chain()[ichain]->GetName());
497 <<
chain()[ichain]->GetName()
498 <<
" does not inherit from "
499 "TFCSLateralShapeParametrizationHitBase");
522 if (simulstate.
E() > std::numeric_limits<double>::epsilon()) {
524 simulstate.
set_Efrac(ilayer, simulstate.
E(ilayer) / simulstate.
E());
A number of constexpr particle constants to avoid hardcoding them directly in various places.