23#include "HepPDT/ParticleData.hh"
36 m_number_of_hits_simul(nullptr) {}
57 TString(
"hit chain for ") +
73 const Chain_t::value_type &value) {
75 chain().push_back(value);
78 chain().insert(it, value);
108 if (param !=
nullptr) {
109 if (!param->InheritsFrom(TFCSLateralShapeParametrizationHitBase::Class())) {
110 ATH_MSG_ERROR(
"Wrong class type " << param->IsA()->GetName());
119 m_chain.at(ind - 1) = param_typed;
137 int n = hitsim->get_number_of_hits(simulstate, truth, extrapol);
146 float weight = hitsim->getMinWeight();
155 float weight = hitsim->getMaxWeight();
169 simulstate.
setAuxInfo<
int>(
"FCSHitChainNHits"_FCShash, nhits);
175 return simulstate.
E(sample);
176 const float maxWeight =
180 return simulstate.
E(sample) /
184 return simulstate.
E(sample) /
193 simulstate, truth, extrapol);
198 double sigma2 = hitsim->get_sigma2_fluctuation(simulstate, truth, extrapol);
207 MSG::Level
level)
const {
209 reset->setLevel(
level);
222 for (
auto hititr =
m_chain.begin(); hititr != initloopend; ++hititr) {
229 ATH_MSG_ERROR(
"TFCSLateralShapeParametrizationHitChain::simulate(): "
230 "simulate_hit init call failed");
241 MSG::Level old_level =
level();
256 const float Elayer = simulstate.
E(cs);
261 const float Ehit =
get_E_hit(simulstate, truth, extrapol);
262 if (Ehit * Elayer <= 0) {
263 ATH_MSG_ERROR(
"TFCSLateralShapeParametrizationHitChain::simulate(): Ehit "
264 "and Elayer have different sign! Ehit="
265 << Ehit <<
" Elayer=" << Elayer);
272 int nhit_signed = TMath::Nint(Elayer / Ehit);
275 unsigned int nhit = (
unsigned int)nhit_signed;
281 ATH_MSG_DEBUG(
"E(" << cs <<
")=" << simulstate.
E(cs) <<
" #hits~" << nhit);
289 bool our_chainA =
false;
290 if (cs > 0 && cs < 8 && cs != 4)
292 if (nhit >
MIN_GPU_HITS && our_chainA && simulstate.get_geold() !=
nullptr) {
294 "running FastCaloSim in GPU, nhits = " << nhit <<
" ; Ehit = " << Ehit);
300 args.extrapol_eta_ent = extrapol->eta(cs,
SUBPOS_ENT);
301 args.extrapol_eta_ext = extrapol->eta(cs,
SUBPOS_EXT);
302 args.extrapol_phi_ent = extrapol->phi(cs,
SUBPOS_ENT);
303 args.extrapol_phi_ext = extrapol->phi(cs,
SUBPOS_EXT);
304 args.extrapol_r_ent = extrapol->r(cs,
SUBPOS_ENT);
305 args.extrapol_r_ext = extrapol->r(cs,
SUBPOS_EXT);
306 args.extrapol_z_ent = extrapol->z(cs,
SUBPOS_ENT);
307 args.extrapol_z_ext = extrapol->z(cs,
SUBPOS_EXT);
308 args.pdgId = truth->
pdgid();
309 args.charge = HepPDT::ParticleID(args.pdgId).charge();
313 args.rd4h = simulstate.get_gpu_rand();
317 bool reweight =
false;
327 ->is_phi_symmetric();
333 if (ichn == 2 &&
m_chain.size() == 4) {
340 if ((ichn == 2 &&
m_chain.size() == 3) ||
341 (ichn == 3 &&
m_chain.size() == 4)) {
355 for (
unsigned int ii = 0; ii < args.ct; ++ii) {
358 gld->
index2cell(args.hitcells_E_h[ii].cellid);
360 m_geo->getDDE(cs, cellele->
eta(), cellele->
phi());
361 sumEhit += args.hitcells_E_h[ii].energy;
363 if (std::abs(sumEhit) > std::abs(Elayer))
364 simulstate.
deposit(cell_h, args.hitcells_E_h[ii].energy);
375 int retry_warning = 1;
389 for (
auto hititr = hitloopstart; hititr !=
m_chain.end(); ++hititr) {
406 retry_warning = retry >> 1;
407 if (retry_warning < 1)
417 if (((hit.
idx() == 20 * nhit) || (hit.
idx() == 100 * nhit)) && hit.
idx() >= 100) {
419 "TFCSLateralShapeParametrizationHitChain::simulate(): Iterated "
420 << hit.
idx() <<
" times, expected " << nhit <<
" times. Deposited E("
421 << cs <<
")=" << sumEhit <<
" expected E=" << Elayer);
423 if (hit.
idx() >= 1000 * nhit && hit.
idx() >= 1000) {
424 ATH_MSG_DEBUG(
"TFCSLateralShapeParametrizationHitChain::simulate():"
425 " Aborting hit chain, iterated "
426 << hit.
idx() <<
" times, expected " << nhit
427 <<
" times. Deposited E(" << cs <<
")=" << sumEhit
428 <<
" expected E=" << Elayer <<
", caused by:");
433 if (ifail >= retry) {
434 ATH_MSG_ERROR(
"TFCSLateralShapeParametrizationHitChain::simulate(): "
435 "simulate_hit call failed after "
436 << ifail <<
"/" << retry
437 <<
"retries, total fails=" << itotalfail);
442 if (ifail >= retry_warning) {
444 " retry simulate_hit calls "
445 << ifail <<
"/" << retry
446 <<
", total fails=" << itotalfail);
471 if (simulstate.
hasAuxInfo(
"FCSHitChainEnergySum"_FCShash) && hit.
idx() > 1) {
472 sumEhit = simulstate.
getAuxInfo<
float>(
"FCSHitChainEnergySum"_FCShash);
477 simulstate.
setAuxInfo<
float>(
"FCSHitChainEnergySum"_FCShash, sumEhit);
480 return (std::abs(sumEhit) >= std::abs(Elayer));
486 bool shortprint = opt.Index(
"short") >= 0;
487 bool longprint =
msgLvl(MSG::DEBUG) || (
msgLvl(MSG::INFO) && !shortprint);
488 TString optprint = opt;
489 optprint.ReplaceAll(
"short",
"");
493 ATH_MSG_INFO(optprint <<
"#:Number of hits simulation:");
499 for (
auto hititr =
m_chain.begin(); hititr != hitloopstart; ++hititr) {
501 hitsim->
Print(opt +
"> ");
506 for (
auto hititr = hitloopstart; hititr !=
m_chain.end(); ++hititr) {
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
FCSReturnCode
Base class for all FastCaloSim parametrizations Functionality in derivde classes is provided through ...
CUDA_HOSTDEV float phi() const
cell phi
CUDA_HOSTDEV float eta() const
cell eta
This class groups all DetDescr information related to a CaloCell.
unsigned long get_ncells() const
GeoGpu * get_geoPtr() const
const CaloDetDescrElement_Gpu * index2cell(unsigned long index)
bool msgLvl(const MSG::Level lvl) const
Check whether the logging system is active at the provided verbosity level.
MSG::Level level() const
Retrieve output level.
long unsigned int & idx()
virtual FCSReturnCode simulate_hit(Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol)
simulated one hit position with some energy.
virtual float get_sigma2_fluctuation(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
Give the effective size sigma^2 of the fluctuations that should be generated.
const Chain_t & chain() const
virtual float getMaxWeight() const
void push_back_init(const Chain_t::value_type &value)
virtual const TFCSParametrizationBase * operator[](unsigned int ind) const override
Some derived classes have daughter instances of TFCSParametrizationBase objects The size() and operat...
TFCSLateralShapeParametrizationHitChain(const char *name=nullptr, const char *title=nullptr)
virtual FCSReturnCode simulate(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const override
Method in all derived classes to do some simulation.
virtual unsigned int size() const override
Some derived classes have daughter instances of TFCSParametrizationBase objects The size() and operat...
unsigned int get_nr_of_init() const
virtual bool check_all_hits_simulated(TFCSLateralShapeParametrizationHitBase::Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol, bool success) const
void Print(Option_t *option="") const override
Do not persistify!
virtual float getMinWeight() const
Get minimum and maximum value of weight for hit energy reweighting.
TFCSLateralShapeParametrizationHitBase * m_number_of_hits_simul
virtual void set_daughter(unsigned int ind, TFCSParametrizationBase *param) override
Some derived classes have daughter instances of TFCSParametrizationBase objects The set_daughter meth...
virtual FCSReturnCode init_hit(TFCSLateralShapeParametrizationHitBase::Hit &hit, TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
static constexpr float s_max_sigma2_fluctuation
virtual float get_E_hit(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
Get hit energy from layer energy and number of hits.
void PropagateMSGLevel(MSG::Level level) const
virtual int get_number_of_hits(TFCSSimulationState &simulstate, const TFCSTruthState *truth, const TFCSExtrapolationState *extrapol) const
Call get_number_of_hits() only once, as it could contain a random number.
void Print(Option_t *option="") const override
TFCSLateralShapeParametrization(const char *name=nullptr, const char *title=nullptr)
virtual void set_pdgid_Ekin_eta_Ekin_bin_calosample(const TFCSLateralShapeParametrization &ref)
virtual void set_geometry(ICaloGeometry *geo)
Method to set the geometry access pointer.
TFCSParametrizationBase(const char *name=nullptr, const char *title=nullptr)
bool hasAuxInfo(std::uint32_t index) const
const T getAuxInfo(std::uint32_t index) const
void deposit(const CaloDetDescrElement *cellele, float E)
void setAuxInfo(std::uint32_t index, const T &val)
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
void simulate_hits(float, int, Chain0_Args &, bool)