Loading [MathJax]/jax/input/TeX/config.js
 |
ATLAS Offline Software
|
Go to the documentation of this file.
7 #include "CLHEP/Random/RandFlat.h"
8 #include "CLHEP/Random/RandGauss.h"
9 #include "HepPDT/ParticleData.hh"
10 #include "HepPDT/ParticleDataTable.hh"
20 #if defined(__FastCaloSimStandAlone__)
21 #include "CLHEP/Random/TRandomEngine.h"
23 #include <CLHEP/Random/RanluxEngine.h>
72 const std::string &FastCaloGANInputFolderName) {
78 "Using FastCaloGANInputFolderName: " << FastCaloGANInputFolderName);
93 if (
pid != 22 &&
pid != 11) {
109 Form(
"layer=%d", simulstate.
getAuxInfo<
int>(
"GANlayer"_FCShash)));
125 const int pdgId = truth->
pdgid();
129 const float Ekin = truth->
Ekin();
131 Einit = simulstate.
E();
153 double totalEnergy = 0;
155 totalEnergy +=
output.second;
157 if (totalEnergy < 0) {
167 for (
const auto &[
layer,
h] : binsInLayers) {
187 const int xBinNum =
h.GetNbinsX();
188 const int yBinNum =
h.GetNbinsY();
189 const TAxis *
x =
h.GetXaxis();
195 <<
" has only one bin in r, this means is it not used, "
196 "skipping (this is needed to keep correct "
197 "syncronisation of voxel and layers)");
205 for (
int ix = 1; ix <= xBinNum; ++ix) {
207 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
210 <<
" binx " << ix <<
" biny " << iy);
212 if (energyInVoxel <= 0) {
217 simulstate.
add_E(
layer, Einit * energyInVoxel);
223 for (
unsigned int ichain =
m_bin_start.back(); ichain <
size(); ++ichain) {
232 for (
const auto &[
layer,
h] : binsInLayers) {
233 const int xBinNum =
h.GetNbinsX();
234 const int yBinNum =
h.GetNbinsY();
235 const TAxis *
x =
h.GetXaxis();
236 const TAxis *
y =
h.GetYaxis();
245 <<
" has only one bin in r, this means is it not used, "
246 "skipping (this is needed to keep correct "
247 "syncronisation of voxel and layers)");
261 <<
chain()[ichain]->GetName());
262 if (
chain()[ichain]->InheritsFrom(
263 TFCSLateralShapeParametrizationHitBase::Class())) {
271 <<
chain()[ichain]->GetName());
278 <<
chain()[ichain]->GetName()
279 <<
" does not inherit from "
280 "TFCSLateralShapeParametrizationHitBase");
291 int binResolution = 5;
296 const double center_eta = hit.center_eta();
297 const double center_phi = hit.center_phi();
298 const double center_r = hit.center_r();
299 const double center_z = hit.center_z();
302 <<
" phi " << center_phi <<
" R " << center_r);
304 const float dist000 =
305 TMath::Sqrt(center_r * center_r + center_z * center_z);
306 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
307 (1.0 + TMath::Exp(-2 * center_eta)));
313 for (
int ix = 1; ix <= xBinNum; ++ix) {
317 const int binsToMerge = yBinNum == 32 ? 32 / binsInAlphaInRBin : 1;
318 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
320 const int lowEdgeIndex = (iy - 1) * binsToMerge + 1;
323 <<
" binx " << ix <<
" biny " << iy);
325 if (energyInVoxel <= 0) {
330 if (std::abs(pdgId) == 22 || std::abs(pdgId) == 11) {
332 int maxHitsInVoxel = energyInVoxel * truth->
Ekin() / 10;
333 if (maxHitsInVoxel < 1)
335 nHitsAlpha = std::sqrt(maxHitsInVoxel);
336 nHitsR = std::sqrt(maxHitsInVoxel);
339 nHitsR =
x->GetBinUpEdge(ix) -
x->GetBinLowEdge(ix);
342 const double r =
x->GetBinUpEdge(ix);
343 nHitsAlpha = ceil(2 * TMath::Pi() *
r / binResolution);
347 const double angle =
y->GetBinUpEdge(iy) -
y->GetBinLowEdge(iy);
348 const double r =
x->GetBinUpEdge(ix);
350 nHitsAlpha = ceil(
d / binResolution);
357 const int maxNhits = 10;
363 for (
int ir = 0;
ir < nHitsR; ++
ir) {
365 x->GetBinLowEdge(ix) +
x->GetBinWidth(ix) / (nHitsR + 1) *
ir;
367 for (
int ialpha = 1; ialpha <= nHitsAlpha; ++ialpha) {
368 if (ganVersion > 1) {
369 if (fitResults.at(
layer)[ix - 1] != 0) {
372 x->GetBinLowEdge(ix),
373 x->GetBinUpEdge(ix));
375 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
376 fitResults.at(
layer)[ix - 1];
377 while ((rand_r < x->GetBinLowEdge(ix) ||
378 rand_r >
x->GetBinUpEdge(ix)) &&
381 x->GetBinLowEdge(ix),
382 x->GetBinUpEdge(ix));
384 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
385 fitResults.at(
layer)[ix - 1];
390 <<
x->GetBinLowEdge(ix) <<
"-"
391 <<
x->GetBinUpEdge(ix) <<
"] having slope "
392 << fitResults.at(
layer)[ix - 1]
393 <<
" will use grid (old method)");
401 if (binsInAlphaInRBin == 1) {
403 -TMath::Pi(), TMath::Pi());
406 y->GetBinLowEdge(lowEdgeIndex) +
407 y->GetBinWidth(iy) * binsToMerge / (nHitsAlpha + 1) * ialpha;
411 -TMath::Pi(), TMath::Pi()) < 0) {
418 hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
432 delta_eta_mm = -delta_eta_mm;
437 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
438 delta_phi_mm = -delta_phi_mm;
440 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
441 const float delta_phi = delta_phi_mm / center_r;
443 hit.eta() = center_eta + delta_eta;
447 <<
" layer " <<
layer);
449 const float hit_r =
r *
cos(
alpha) + center_r;
455 if ((
charge < 0. && pdgId != 11) || pdgId == -11)
457 const float hit_phi =
459 hit.x() = hit_r *
cos(hit_phi);
460 hit.y() = hit_r *
sin(hit_phi);
463 <<
" layer " <<
layer);
469 for (
unsigned int ichain =
475 <<
chain()[ichain]->GetName());
476 if (
chain()[ichain]->InheritsFrom(
477 TFCSLateralShapeParametrizationHitBase::Class())) {
487 <<
chain()[ichain]->GetName());
494 <<
chain()[ichain]->GetName()
495 <<
" does not inherit from "
496 "TFCSLateralShapeParametrizationHitBase");
519 if (simulstate.
E() > std::numeric_limits<double>::epsilon()) {
521 simulstate.
set_Efrac(ilayer, simulstate.
E(ilayer) / simulstate.
E());
532 for (
unsigned int ichain = 0; ichain <
m_bin_start[0]; ++ichain) {
553 const bool shortprint =
opt.Index(
"short") >= 0;
554 const bool longprint =
556 TString optprint =
opt;
557 optprint.ReplaceAll(
"short",
"");
560 for (
unsigned int ichain = 0; ichain <
size(); ++ichain) {
561 if (ichain == 0 && ichain !=
m_bin_start.front()) {
571 prefix = Form(
"%-2d", ibin);
591 "/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
592 "InputsToBigParamFiles/FastCaloGANWeightsVer02/";
597 "/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
598 "InputsToBigParamFiles/FastCaloGANWeightsONNXVer08/";
607 const std::string &outputname,
int pid) {
612 #if defined(__FastCaloSimStandAlone__)
621 t->SetPtEtaPhiM(65536, 0, 0, 139.6);
627 e->set_IDCaloBoundary_eta(truth->Eta());
628 for (
int i = 0;
i < 24; ++
i) {
651 for (
int i = 0;
i < 24; ++
i)
654 Form(
"center%d",
i), Form(
"center layer %d",
i));
655 c->set_calosample(
i);
656 c->setExtrapWeight(0.5);
657 c->setLevel(MSG::INFO);
663 c->set_eta_min(
etaMin / 100.0);
664 c->set_eta_max(
etaMax / 100.0);
674 const std::string
outname =
"FCSGANtest_" + outputname +
".root";
675 TFile *fGAN = TFile::Open(
outname.c_str(),
"recreate");
678 fGAN->WriteObjectAny(&GAN,
"TFCSEnergyAndHitGANV2",
"GAN");
684 fGAN = TFile::Open(
outname.c_str());
707 double binsInAlphaInRBin = yBinNum;
710 const double widthX =
x->GetBinWidth(ix);
711 const double radious =
x->GetBinCenter(ix);
712 double circumference = radious * 2 * TMath::Pi();
714 circumference = radious * TMath::Pi();
717 const double bins = circumference / widthX;
719 ATH_MSG_DEBUG(
"Bin in alpha: " << binsInAlphaInRBin <<
" for r bin: " << ix
720 <<
" (" <<
x->GetBinLowEdge(ix) <<
"-"
721 <<
x->GetBinUpEdge(ix) <<
")");
723 return binsInAlphaInRBin;
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol)
simulated one hit position with some energy.
const T getAuxInfo(std::uint32_t index) const
virtual const std::string get_bin_text(int bin) const
print the range of a bin; for bin -1, print the allowed range
path
python interpreter configuration --------------------------------------—
std::string find(const std::string &s)
return a remapped string
const TFCSGANXMLParameters::Binning & get_Binning() const
bool initializeNetwork(int const &pid, int const &etaMin, const std::string &FastCaloGANInputFolderName)
void InitialiseFromXML(int pid, int etaMid, const std::string &FastCaloGANInputFolderName)
std::map< std::string, double > NetworkOutputs
virtual void add_pdgid(int id)
static int GetBinsInFours(double const &bins)
virtual void push_back_in_bin(TFCSParametrizationBase *param, unsigned int bin)
std::map< int, TH2D > Binning
bool OnlyScaleEnergy() const
CLHEP::HepRandomEngine * randomEngine()
void set_nr_of_init(unsigned int bin, unsigned int ninit)
#define ATH_MSG_VERBOSE(x)
void Print(Option_t *option="") const
__HOSTDEV__ double Phi_mpi_pi(double)
virtual void set_eta_max(double max)
virtual void set_pdgid(int id)
virtual unsigned int get_number_of_bins() const
void add_E(int sample, double Esample)
const Chain_t & chain() const
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
TFCSGANEtaSlice * m_slice
virtual ~TFCSEnergyAndHitGANV2()
int GetAlphaBinsForRBin(const TAxis *x, int ix, int yBinNum) const
void Print(Option_t *option="") const
Print object information.
std::map< int, std::vector< double > > FitResultsPerLayer
void Print(Option_t *option="") const
bool IsGanCorrectlyLoaded() const
const FitResultsPerLayer & GetFitResults() const
virtual void reset_match_all_pdgid()
virtual void set_eta_nominal(double min)
std::string to_string(const DetectorType &type)
virtual void setLevel(MSG::Level lvl)
Update outputlevel.
void setAuxInfo(std::uint32_t index, const T &val)
void set_E(int sample, double Esample)
double charge(const T &p)
static void unit_test(TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr)
int GetGANVersion() const
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
Method in all derived classes to do some simulation.
NetworkOutputs GetNetworkOutputs(const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol, TFCSSimulationState simulstate) const
void setRandomEngine(CLHEP::HepRandomEngine *engine)
std::vector< int > m_bin_ninit
int ir
counter of the current depth
TFCSGANXMLParameters m_param
#define ATH_MSG_NOCLASS(logger_name, x)
#define ATH_MSG_WARNING(x)
virtual bool is_match_calosample(int calosample) const override
virtual int get_bin(TFCSSimulationState &simulstate, const TFCSTruthState *, const TFCSExtrapolationState *) const override
use the layer to be done as binning of the GAN chain
def delta_phi(phi1, phi2)
FCSReturnCode simulate_and_retry(TFCSParametrizationBase *parametrization, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
virtual void set_eta_min(double min)
bool fillEnergy(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
unsigned int get_nr_of_init(unsigned int bin) const
TFCSEnergyAndHitGANV2(const char *name=nullptr, const char *title=nullptr)
static void test_path(const std::string &path, TFCSSimulationState *simulstate=nullptr, const TFCSTruthState *truth=nullptr, const TFCSExtrapolationState *extrapol=nullptr, const std::string &outputname="unnamed", int pid=211)
virtual void Print(Option_t *option="") const override
bool IsSymmetrisedAlpha() const
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
std::vector< unsigned int > m_bin_start
Contains the index where the TFCSParametrizationBase* instances to run for a given bin start.
const Binning & GetBinning() const
void set_Efrac(int sample, double Efracsample)
virtual const std::string get_variable_text(TFCSSimulationState &simulstate, const TFCSTruthState *, const TFCSExtrapolationState *) const override
virtual unsigned int size() const override
Some derived classes have daughter instances of TFCSParametrizationBase objects The size() and operat...