18 double timeWindow = 10;
19 double gridStartTime = 0;
23 readoutSpecs = std::make_shared<GReadoutSpecs>(timeWindow, gridStartTime, hitBitSet,
log);
35 auto gdata = std::make_unique<GDigitizedData>(
gopts, ghit);
43 auto pEnergies = ghit->
getEs();
45 double nielWeight = 0;
49 for (
size_t stepIndex = 0; stepIndex < pids.size(); stepIndex++) {
51 int pid = std::abs(pids[stepIndex]);
54 if (pid == 11 || pid == 211 || pid == 2212 || pid == 2112) {
57 double E = pEnergies[stepIndex] - pMassMeV[pid];
58 nielWeight += getNielFactorForParticleAtEnergy(pid, E);
62 gdata->includeVariable(
"nielWeight", nielWeight);
69 [[maybe_unused]] std::string
const& variation) {
71 std::map<int, std::string> nielDataFiles;
72 nielDataFiles[11] =
"niel_electron.txt";
73 nielDataFiles[211] =
"niel_pion.txt";
74 nielDataFiles[2112] =
"niel_neutron.txt";
75 nielDataFiles[2212] =
"niel_proton.txt";
80 for (
const auto& [pid, filename] : nielDataFiles) {
81 std::string dataFileWithPath = gemcRoot.string() +
"/dosimeterData" +
"/Niel/" + filename;
83 std::ifstream inputfile(dataFileWithPath);
87 dataFileWithPath = gemcRoot.string() +
"/gdynamicDigitization/dosimeterData" +
"/Niel/" + filename;
88 inputfile.open(dataFileWithPath);
95 log->
info(0,
" Loading dosimeter data for pid <", pid,
"> from file ", dataFileWithPath);
99 while (inputfile >> p0 >> p1) {
100 nielfactorMap[pid].push_back(p0);
101 E_nielfactorMap[pid].push_back(p1);
107 pMassMeV[11] = 0.510;
108 pMassMeV[211] = 139.570;
109 pMassMeV[2112] = 939.565;
110 pMassMeV[2212] = 938.272;
116double GDosimeterDigitization::getNielFactorForParticleAtEnergy(
int pid,
double energyMeV) {
117 const auto niel_N = nielfactorMap[pid].size();
122 log->
error(EC__FILENOTFOUND,
"NIEL tables are empty for pid <", pid,
">. Did loadConstantsImpl fail?");
129 for (
size_t i = 0; i < niel_N; i++) {
130 if (energyMeV < E_nielfactorMap[pid][i]) {
138 if (j > 0 && j < niel_N) {
140 const auto nielfactor_low = nielfactorMap[pid][j - 1];
141 const auto nielfactor_high = nielfactorMap[pid][j];
142 const auto energy_low = E_nielfactorMap[pid][j - 1];
143 const auto energy_high = E_nielfactorMap[pid][j];
145 value = nielfactor_low +
146 (nielfactor_high - nielfactor_low) / (energy_high - energy_low) * (energyMeV - energy_low);
150 value = nielfactorMap[pid].front();
154 value = nielfactorMap[pid].back();
157 log->
debug(NORMAL,
" pid: ", pid,
", j: ", j,
", value: ", value,
", energy: ", energyMeV);
std::shared_ptr< GLogger > log
bool defineReadoutSpecsImpl() override
Defines readout specifications for dosimeter digitization.
std::unique_ptr< GDigitizedData > digitizeHitImpl(GHit *ghit, size_t hitn) override
Digitizes a hit for dosimeter detectors.
bool loadConstantsImpl(int runno, std::string const &variation) override
Loads digitization constants for dosimeter digitization.
std::shared_ptr< GOptions > gopts
Options used by the digitization plugin instance.
void check_if_log_defined() const
Ensures options/logging are configured before plugin methods run.
std::shared_ptr< const GReadoutSpecs > readoutSpecs
Readout specs are created during initialization and treated as immutable.
std::vector< int > getPids() const
std::vector< double > getEs() const
std::vector< GIdentifier > getGID() const
double getTotalEnergyDeposited()
void debug(debug_type type, Args &&... args) const
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
std::bitset< NHITBITS > HitBitSet
Internal digitization plugins shipped with the gdynamic digitization library.
std::filesystem::path gemc_root()
std::string getName() const