40 double timeWindow = 10;
41 double gridStartTime = 0;
42 auto hitBitSet = HitBitSet(
"000001");
45 readoutSpecs = std::make_shared<GReadoutSpecs>(timeWindow, gridStartTime, hitBitSet, log);
69 GIdentifier identity = ghit->getGID().front();
72 auto gdata = std::make_unique<GDigitizedData>(
gopts, ghit);
75 gdata->includeVariable(identity.getName(), identity.getValue());
76 gdata->includeVariable(
"hitn",
static_cast<int>(hitn));
77 gdata->includeVariable(
"eTot", ghit->getTotalEnergyDeposited());
78 gdata->includeVariable(
"time", ghit->getAverageTime());
81 auto pids = ghit->getPids();
82 auto pEnergies = ghit->getEs();
84 double nielWeight = 0;
86 for (
size_t stepIndex = 0; stepIndex < pids.size(); stepIndex++) {
88 int pid = std::abs(pids[stepIndex]);
91 if (pid == 11 || pid == 211 || pid == 2212 || pid == 2112) {
93 double E = pEnergies[stepIndex] - pMassMeV[pid];
95 nielWeight += getNielFactorForParticleAtEnergy(pid, E);
100 gdata->includeVariable(
"nielWeight", nielWeight);
119 std::map<int, std::string> nielDataFiles;
120 nielDataFiles[11] =
"niel_electron.txt";
121 nielDataFiles[211] =
"niel_pion.txt";
122 nielDataFiles[2112] =
"niel_neutron.txt";
123 nielDataFiles[2212] =
"niel_proton.txt";
126 std::filesystem::path gemcRoot = gutilities::gemc_root();
127 std::string pluginPath = gemcRoot.string() +
"/dosimeterData/";
130 for (
const auto& [pid, filename] : nielDataFiles) {
131 std::string dataFileWithPath = pluginPath +
"/dosimeterData/Niel/" + filename;
133 std::ifstream inputfile(dataFileWithPath);
134 if (!inputfile) { log->error(EC__FILENOTFOUND,
"Error loading dosimeter data for pid <", pid,
"> from file ", dataFileWithPath); }
136 log->info(0,
" Loading dosimeter data for pid <", pid,
"> from file ", dataFileWithPath);
140 while (inputfile >> p0 >> p1) {
141 nielfactorMap[pid].push_back(p0);
142 E_nielfactorMap[pid].push_back(p1);
148 pMassMeV[11] = 0.510;
149 pMassMeV[211] = 139.570;
150 pMassMeV[2112] = 939.565;
151 pMassMeV[2212] = 938.272;
168double GDosimeterDigitization::getNielFactorForParticleAtEnergy(
int pid,
double energyMeV) {
170 auto niel_N = nielfactorMap[pid].size();
174 for (
size_t i = 0; i < niel_N; i++) {
175 if (energyMeV < E_nielfactorMap[pid][i]) {
182 if (j > 0 && j < niel_N) {
184 auto nielfactor_low = nielfactorMap[pid][j - 1];
185 auto nielfactor_high = nielfactorMap[pid][j];
186 auto energy_low = E_nielfactorMap[pid][j - 1];
187 auto energy_high = E_nielfactorMap[pid][j];
188 value = nielfactor_low + (nielfactor_high - nielfactor_low) / (energy_high - energy_low) * (energyMeV - energy_low);
192 value = nielfactorMap[pid].front();
196 value = nielfactorMap[pid].back();
199 log->debug(NORMAL,
" pid: ", pid,
", j: ", j,
", value: ", value,
", energy: ", energyMeV);
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
Optional pointer to GOptions.
void check_if_log_defined() const
Checks that all required loggers and options are defined.
std::shared_ptr< const GReadoutSpecs > readoutSpecs
After init, we never mutate these:
Declares internal digitization classes for various detector types.