|
ATLAS Offline Software
|
Go to the documentation of this file.
16 #include "HepPDT/ParticleData.hh"
17 #include "HepPDT/ParticleDataTable.hh"
19 #include "CLHEP/Random/RandGauss.h"
20 #include "CLHEP/Random/RandFlat.h"
22 #if defined(__FastCaloSimStandAlone__)
23 #include "CLHEP/Random/TRandomEngine.h"
25 #include <CLHEP/Random/RanluxEngine.h>
74 const std::string &FastCaloGANInputFolderName) {
80 "Using FastCaloGANInputFolderName: " << FastCaloGANInputFolderName);
95 if (
pid != 22 &&
pid != 11) {
112 Form(
"layer=%d", simulstate.
getAuxInfo<
int>(
"GANlayer"_FCShash)));
132 const float Ekin = truth->
Ekin();
134 Einit = simulstate.
E();
156 double totalEnergy = 0;
158 totalEnergy +=
output.second;
160 if (totalEnergy < 0) {
170 for (
const auto &element : binsInLayers) {
171 const int layer = element.first;
172 const TH2D *
h = &element.second;
174 const int xBinNum =
h->GetNbinsX();
175 const int yBinNum =
h->GetNbinsY();
176 const TAxis *
x =
h->GetXaxis();
182 <<
" has only one bin in r, this means is it not used, "
183 "skipping (this is needed to keep correct "
184 "syncronisation of voxel and layers)");
192 for (
int ix = 1; ix <= xBinNum; ++ix) {
194 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
197 <<
" binx " << ix <<
" biny " << iy);
199 if (energyInVoxel <= 0) {
204 simulstate.
add_E(
layer, Einit * energyInVoxel);
210 for (
unsigned int ichain =
m_bin_start.back(); ichain <
size(); ++ichain) {
219 for (
const auto &element : binsInLayers) {
220 const int layer = element.first;
221 const TH2D *
h = &element.second;
222 const int xBinNum =
h->GetNbinsX();
223 const int yBinNum =
h->GetNbinsY();
224 const TAxis *
x =
h->GetXaxis();
225 const TAxis *
y =
h->GetYaxis();
234 <<
" has only one bin in r, this means is it not used, "
235 "skipping (this is needed to keep correct "
236 "syncronisation of voxel and layers)");
250 <<
chain()[ichain]->GetName());
251 if (
chain()[ichain]->InheritsFrom(
252 TFCSLateralShapeParametrizationHitBase::Class())) {
260 <<
chain()[ichain]->GetName());
267 <<
chain()[ichain]->GetName()
268 <<
" does not inherit from "
269 "TFCSLateralShapeParametrizationHitBase");
280 int binResolution = 5;
285 const double center_eta = hit.center_eta();
286 const double center_phi = hit.center_phi();
287 const double center_r = hit.center_r();
288 const double center_z = hit.center_z();
291 <<
" phi " << center_phi <<
" R " << center_r);
293 const float dist000 =
294 TMath::Sqrt(center_r * center_r + center_z * center_z);
295 const float eta_jakobi = TMath::Abs(2.0 * TMath::Exp(-center_eta) /
296 (1.0 + TMath::Exp(-2 * center_eta)));
302 for (
int ix = 1; ix <= xBinNum; ++ix) {
306 const int binsToMerge = yBinNum == 32 ? 32 / binsInAlphaInRBin : 1;
307 for (
int iy = 1; iy <= binsInAlphaInRBin; ++iy) {
309 const int lowEdgeIndex = (iy - 1) * binsToMerge + 1;
312 <<
" binx " << ix <<
" biny " << iy);
314 if (energyInVoxel <= 0) {
319 if (std::abs(
pdgId) == 22 || std::abs(
pdgId) == 11) {
321 int maxHitsInVoxel = energyInVoxel * truth->
Ekin() / 10;
322 if (maxHitsInVoxel < 1)
324 nHitsAlpha = std::sqrt(maxHitsInVoxel);
325 nHitsR = std::sqrt(maxHitsInVoxel);
328 nHitsR =
x->GetBinUpEdge(ix) -
x->GetBinLowEdge(ix);
331 const double r =
x->GetBinUpEdge(ix);
332 nHitsAlpha = ceil(2 * TMath::Pi() *
r / binResolution);
336 const TAxis *
y =
h->GetYaxis();
337 const double angle =
y->GetBinUpEdge(iy) -
y->GetBinLowEdge(iy);
338 const double r =
x->GetBinUpEdge(ix);
340 nHitsAlpha = ceil(
d / binResolution);
347 const int maxNhits = 10;
353 for (
int ir = 0;
ir < nHitsR; ++
ir) {
355 x->GetBinLowEdge(ix) +
x->GetBinWidth(ix) / (nHitsR + 1) *
ir;
357 for (
int ialpha = 1; ialpha <= nHitsAlpha; ++ialpha) {
358 if (ganVersion > 1) {
359 if (fitResults.at(
layer)[ix - 1] != 0) {
362 x->GetBinLowEdge(ix),
363 x->GetBinUpEdge(ix));
365 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
366 fitResults.at(
layer)[ix - 1];
367 while ((rand_r < x->GetBinLowEdge(ix) ||
368 rand_r >
x->GetBinUpEdge(ix)) &&
371 x->GetBinLowEdge(ix),
372 x->GetBinUpEdge(ix));
374 log((
a -
x->GetBinLowEdge(ix)) / (
x->GetBinWidth(ix))) /
375 fitResults.at(
layer)[ix - 1];
380 <<
x->GetBinLowEdge(ix) <<
"-"
381 <<
x->GetBinUpEdge(ix) <<
"] having slope "
382 << fitResults.at(
layer)[ix - 1]
383 <<
" will use grid (old method)");
391 if (binsInAlphaInRBin == 1) {
392 alpha = CLHEP::RandFlat::shoot(simulstate.
randomEngine(),
393 -TMath::Pi(), TMath::Pi());
396 y->GetBinLowEdge(lowEdgeIndex) +
397 y->GetBinWidth(iy) * binsToMerge / (nHitsAlpha + 1) * ialpha;
401 -TMath::Pi(), TMath::Pi()) < 0) {
408 hit.E() = Einit * energyInVoxel / (nHitsAlpha * nHitsR);
411 float delta_eta_mm =
r *
cos(alpha);
412 float delta_phi_mm =
r *
sin(alpha);
422 delta_eta_mm = -delta_eta_mm;
427 delta_phi_mm = -delta_phi_mm;
429 const float delta_eta = delta_eta_mm / eta_jakobi / dist000;
430 const float delta_phi = delta_phi_mm / center_r;
432 hit.eta() = center_eta + delta_eta;
436 <<
" layer " <<
layer);
438 const float hit_r =
r *
cos(alpha) + center_r;
445 const float hit_phi =
447 hit.x() = hit_r *
cos(hit_phi);
448 hit.y() = hit_r *
sin(hit_phi);
451 <<
" layer " <<
layer);
457 for (
unsigned int ichain =
463 <<
chain()[ichain]->GetName());
464 if (
chain()[ichain]->InheritsFrom(
465 TFCSLateralShapeParametrizationHitBase::Class())) {
475 <<
chain()[ichain]->GetName());
482 <<
chain()[ichain]->GetName()
483 <<
" does not inherit from "
484 "TFCSLateralShapeParametrizationHitBase");
507 if (simulstate.
E() > std::numeric_limits<double>::epsilon()) {
509 simulstate.
set_Efrac(ilayer, simulstate.
E(ilayer) / simulstate.
E());
521 for (
unsigned int ichain = 0; ichain <
m_bin_start[0]; ++ichain) {
542 const bool shortprint =
opt.Index(
"short") >= 0;
543 const bool longprint =
545 TString optprint =
opt;
546 optprint.ReplaceAll(
"short",
"");
549 for (
unsigned int ichain = 0; ichain <
size(); ++ichain) {
550 if (ichain == 0 && ichain !=
m_bin_start.front()) {
560 prefix = Form(
"%-2d", ibin);
579 std::string
path =
"/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
580 "InputsToBigParamFiles/FastCaloGANWeightsVer02/";
584 path =
"/eos/atlas/atlascerngroupdisk/proj-simul/AF3_Run3/"
585 "InputsToBigParamFiles/FastCaloGANWeightsONNXVer08/";
594 const std::string& outputname,
int pid) {
599 #if defined(__FastCaloSimStandAlone__)
608 t->SetPtEtaPhiM(65536, 0, 0, 139.6);
614 e->set_IDCaloBoundary_eta(truth->Eta());
615 for (
int i = 0;
i < 24; ++
i) {
638 for (
int i = 0;
i < 24; ++
i)
641 Form(
"center%d",
i), Form(
"center layer %d",
i));
642 c->set_calosample(
i);
643 c->setExtrapWeight(0.5);
644 c->setLevel(MSG::INFO);
650 c->set_eta_min(
etaMin / 100.0);
651 c->set_eta_max(
etaMax / 100.0);
661 const std::string
outname =
"FCSGANtest_" + outputname +
".root";
662 TFile *fGAN = TFile::Open(
outname.c_str(),
"recreate");
665 fGAN->WriteObjectAny(&GAN,
"TFCSEnergyAndHitGANV2",
"GAN");
671 fGAN = TFile::Open(
outname.c_str());
694 double binsInAlphaInRBin = yBinNum;
697 const double widthX =
x->GetBinWidth(ix);
698 const double radious =
x->GetBinCenter(ix);
699 double circumference = radious * 2 * TMath::Pi();
701 circumference = radious * TMath::Pi();
704 const double bins = circumference / widthX;
706 ATH_MSG_DEBUG(
"Bin in alpha: " << binsInAlphaInRBin <<
" for r bin: " << ix
707 <<
" (" <<
x->GetBinLowEdge(ix) <<
"-"
708 <<
x->GetBinUpEdge(ix) <<
")");
710 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)
__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
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
FitResultsPerLayer GetFitResults() 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...