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 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) {
184 ATH_MSG_ERROR(
"Histogram pointer for layer " << layer <<
" is broken");
188 const int xBinNum =
h.GetNbinsX();
189 const int yBinNum =
h.GetNbinsY();
190 const TAxis *
x =
h.GetXaxis();
196 <<
" has only one bin in r, this means is it not used, "
197 "skipping (this is needed to keep correct "
198 "syncronisation of voxel and layers)");
206 for (
int ix = 1; ix <= xBinNum; ++ix) {
208 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
209 const double energyInVoxel = outputs.at(std::to_string(vox));
211 <<
" binx " << ix <<
" biny " << iy);
213 if (energyInVoxel <= 0) {
218 simulstate.
add_E(layer, Einit * energyInVoxel);
224 for (
unsigned int ichain =
m_bin_start.back(); ichain <
size(); ++ichain) {
233 for (
const auto &[layer,
h] : binsInLayers) {
234 const int xBinNum =
h.GetNbinsX();
235 const int yBinNum =
h.GetNbinsY();
236 const TAxis *
x =
h.GetXaxis();
237 const TAxis *
y =
h.GetYaxis();
239 simulstate.
setAuxInfo<
int>(
"GANlayer"_FCShash, layer);
246 <<
" has only one bin in r, this means is it not used, "
247 "skipping (this is needed to keep correct "
248 "syncronisation of voxel and layers)");
254 const int bin =
get_bin(simulstate, truth, extrapol);
262 <<
chain()[ichain]->GetName());
263 if (
chain()[ichain]->InheritsFrom(
264 TFCSLateralShapeParametrizationHitBase::Class())) {
267 if (sim->
simulate_hit(hit, simulstate, truth, extrapol) !=
272 <<
chain()[ichain]->GetName());
279 <<
chain()[ichain]->GetName()
280 <<
" does not inherit from "
281 "TFCSLateralShapeParametrizationHitBase");
292 int binResolution = 5;
293 if (layer == 1 || layer == 5) {
298 const double center_phi = hit.center_phi();
299 const double center_r = hit.center_r();
300 const double center_z = hit.center_z();
303 <<
" phi " << center_phi <<
" R " << center_r);
305 const float dist000 =
306 TMath::Sqrt(center_r * center_r + center_z * center_z);
307 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
308 (1.0 + TMath::Exp(-2 * center_eta)));
314 for (
int ix = 1; ix <= xBinNum; ++ix) {
318 const int binsToMerge = yBinNum == 32 ? 32 / binsInAlphaInRBin : 1;
319 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
320 const double energyInVoxel = outputs.at(std::to_string(vox));
321 const int lowEdgeIndex = (iy - 1) * binsToMerge + 1;
324 <<
" binx " << ix <<
" biny " << iy);
326 if (energyInVoxel <= 0) {
331 if (std::abs(pdgId) == 22 || std::abs(pdgId) == 11) {
333 int maxHitsInVoxel = energyInVoxel * truth->
Ekin() / 10;
334 if (maxHitsInVoxel < 1)
336 nHitsAlpha = std::sqrt(maxHitsInVoxel);
337 nHitsR = std::sqrt(maxHitsInVoxel);
340 nHitsR =
x->GetBinUpEdge(ix) -
x->GetBinLowEdge(ix);
343 const double r =
x->GetBinUpEdge(ix);
344 nHitsAlpha = ceil(2 * TMath::Pi() *
r / binResolution);
348 const double angle =
y->GetBinUpEdge(iy) -
y->GetBinLowEdge(iy);
349 const double r =
x->GetBinUpEdge(ix);
350 const double d = 2 *
r * sin(
angle / 2 *
r);
351 nHitsAlpha = ceil(d / binResolution);
354 if (layer != 1 && layer != 5) {
358 const int maxNhits = 10;
359 nHitsAlpha = std::min(maxNhits, std::max(1, nHitsAlpha));
360 nHitsR = std::min(maxNhits, std::max(1, nHitsR));
364 for (
int ir = 0;
ir < nHitsR; ++
ir) {
366 x->GetBinLowEdge(ix) +
x->GetBinWidth(ix) / (nHitsR + 1) *
ir;
368 for (
int ialpha = 1; ialpha <= nHitsAlpha; ++ialpha) {
369 if (ganVersion > 1) {
370 if (fitResults.at(layer)[ix - 1] != 0) {
373 x->GetBinLowEdge(ix),
374 x->GetBinUpEdge(ix));
376 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
377 fitResults.at(layer)[ix - 1];
378 while ((rand_r < x->GetBinLowEdge(ix) ||
379 rand_r >
x->GetBinUpEdge(ix)) &&
382 x->GetBinLowEdge(ix),
383 x->GetBinUpEdge(ix));
385 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
386 fitResults.at(layer)[ix - 1];
391 <<
x->GetBinLowEdge(ix) <<
"-"
392 <<
x->GetBinUpEdge(ix) <<
"] having slope "
393 << fitResults.at(layer)[ix - 1]
394 <<
" will use grid (old method)");
402 if (binsInAlphaInRBin == 1) {
403 alpha = CLHEP::RandFlat::shoot(simulstate.
randomEngine(),
404 -TMath::Pi(), TMath::Pi());
407 y->GetBinLowEdge(lowEdgeIndex) +
408 y->GetBinWidth(iy) * binsToMerge / (nHitsAlpha + 1) * ialpha;
410 if (
m_param.IsSymmetrisedAlpha()) {
412 -TMath::Pi(), TMath::Pi()) < 0) {
419 hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
422 float delta_eta_mm =
r * cos(alpha);
423 float delta_phi_mm =
r * sin(alpha);
433 delta_eta_mm = -delta_eta_mm;
438 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
439 delta_phi_mm = -delta_phi_mm;
441 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
442 const float delta_phi = delta_phi_mm / center_r;
444 hit.eta() = center_eta + delta_eta;
445 hit.phi() = TVector2::Phi_mpi_pi(center_phi + delta_phi);
448 <<
" layer " << layer);
450 const float hit_r =
r * cos(alpha) + center_r;
451 float delta_phi =
r * sin(alpha) / center_r;
456 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
457 delta_phi = -delta_phi;
458 const float hit_phi =
459 TVector2::Phi_mpi_pi(center_phi + delta_phi);
460 hit.x() = hit_r * cos(hit_phi);
461 hit.y() = hit_r * sin(hit_phi);
464 <<
" layer " << layer);
468 const int bin =
get_bin(simulstate, truth, extrapol);
470 for (
unsigned int ichain =
476 <<
chain()[ichain]->GetName());
477 if (
chain()[ichain]->InheritsFrom(
478 TFCSLateralShapeParametrizationHitBase::Class())) {
482 if (sim->
simulate_hit(hit, simulstate, truth, extrapol) !=
488 <<
chain()[ichain]->GetName());
495 <<
chain()[ichain]->GetName()
496 <<
" does not inherit from "
497 "TFCSLateralShapeParametrizationHitBase");
520 if (simulstate.
E() > std::numeric_limits<double>::epsilon()) {
522 simulstate.
set_Efrac(ilayer, simulstate.
E(ilayer) / simulstate.
E());
A number of constexpr particle constants to avoid hardcoding them directly in various places.