47#include "TRestGeant4QuenchingProcess.h"
120 TiXmlElement* volumeElement =
GetElement(
"volume");
121 while (volumeElement) {
122 const string volumeName =
GetParameter(
"name", volumeElement,
"");
123 if (volumeName.empty()) {
124 cerr <<
"TRestGeant4QuenchingProcess: No volume expression specified" << endl;
127 fUserVolumeExpressions.insert(volumeName);
137 cerr <<
"TRestGeant4QuenchingProcess: No TRestGeant4Metadata found" << endl;
143 for (
const auto& userVolume : fUserVolumeExpressions) {
144 set<string> physicalVolumes = {};
145 for (
const auto& volume : geometryInfo.GetAllPhysicalVolumesMatchingExpression(userVolume)) {
146 physicalVolumes.insert(volume.Data());
148 if (!physicalVolumes.empty()) {
152 for (
const auto& logicalVolume : geometryInfo.GetAllLogicalVolumesMatchingExpression(userVolume)) {
153 for (
const auto& volume : geometryInfo.GetAllPhysicalVolumesFromLogical(logicalVolume.Data())) {
154 physicalVolumes.insert(volume.Data());
158 if (physicalVolumes.empty()) {
159 RESTWarning <<
"TRestGeant4QuenchingProcess: No volume found matching expression: " << userVolume
163 for (
const auto& physicalVolume : physicalVolumes) {
164 const auto volumeName = geometryInfo.GetAlternativeNameFromGeant4PhysicalName(physicalVolume);
165 fVolumes.insert(volumeName.Data());
169 RESTDebug <<
"TRestGeant4QuenchingProcess initialized with volumes" <<
RESTendl;
170 for (
const auto& volume : fVolumes) {
171 RESTDebug <<
" " << volume <<
RESTendl;
175double QuenchingFactor(
double recoilEnergy,
int A,
int Z) {
177 double gamma = 11.5 * recoilEnergy * TMath::Power(Z, -7.0 / 3.0);
178 double g = 3 * TMath::Power(gamma, 0.15) + 0.7 * TMath::Power(gamma, 0.6) + gamma;
179 double k = 0.133 * TMath::Power(Z, 2.0 / 3.0) * TMath::Power(A, -1.0 / 2.0);
180 return k * g / (1 + k * g);
189 const double sensitiveVolumeEnergyBefore =
fOutputG4Event->GetSensitiveVolumeEnergy();
195 for (
int trackIndex = 0; trackIndex < int(
fOutputG4Event->GetNumberOfTracks()); trackIndex++) {
198 const auto& particleName = track->GetParticleName();
200 auto hits = track->GetHitsPointer();
201 if (!hits->GetHadronicOk()) {
202 cerr <<
"TRestGeant4QuenchingProcess: Hadronic information not available. Use the "
203 "'storeHadronicTargetInfo' parameter in the restG4 configuration"
207 auto& energy = hits->GetEnergyRef();
208 for (
int hitIndex = 0; hitIndex < int(hits->GetNumberOfHits()); hitIndex++) {
209 const auto& volumeName = hits->GetVolumeName(hitIndex);
211 const string isotopeName = hits->GetHadronicTargetIsotopeName(hitIndex);
212 const int isotopeA = hits->GetHadronicTargetIsotopeA(hitIndex);
213 const int isotopeZ = hits->GetHadronicTargetIsotopeZ(hitIndex);
215 double recoilEnergy = hits->GetEnergy(hitIndex);
217 double quenchingFactor = 1.0;
218 if (fVolumes.count(volumeName.Data()) && recoilEnergy > 0 && !isotopeName.empty()) {
219 quenchingFactor = QuenchingFactor(recoilEnergy, isotopeA, isotopeZ);
222 const auto processName = hits->GetProcessName(hitIndex);
224 if (energy[hitIndex] > 0) {
225 fOutputG4Event->fEnergyInVolumePerParticlePerProcess[volumeName.Data()][particleName.Data()]
226 [processName.Data()] +=
227 energy[hitIndex] * quenchingFactor;
232 const double sensitiveVolumeEnergyAfter =
235 bool sensitiveQuenched = TMath::Abs(sensitiveVolumeEnergyAfter - sensitiveVolumeEnergyBefore) > 1e-2;
247 for (
auto const& volume : fVolumes) {
248 RESTMetadata <<
"Volume: " << volume <<
RESTendl;
253std::set<std::string> TRestGeant4QuenchingProcess::GetVolumes()
const {
return fVolumes; }
255std::set<std::string> TRestGeant4QuenchingProcess::GetUserVolumeExpressions()
const {
256 return fUserVolumeExpressions;
TRestRun * GetRunInfo() const
Return the pointer of the hosting TRestRun object.
void BeginPrintProcess()
[name, cut range]
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
A base class for any REST event.
An event class to store geant4 generated event information.
void InitializeReferences(TRestRun *run) override
Initialize dynamical references when loading the event from a root file.
Recomputes the energy of every hit based on quenching factor for each particle and volume.
TRestGeant4Event * fOutputG4Event
A pointer to the specific TRestGeant4Event output.
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
TRestGeant4Metadata * fGeant4Metadata
A pointer to the simulation metadata information accessible to TRestRun.
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
TRestGeant4Event * fInputG4Event
A pointer to the specific TRestGeant4Event input.
void EndProcess() override
To be executed at the end of the run (outside event loop)
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
TRestGeant4QuenchingProcess()
Default constructor.
void Initialize() override
Function to initialize input/output event members and define the section name.
~TRestGeant4QuenchingProcess() override
Default destructor.
void InitProcess() override
Process initialization. User volume expressions are matched to physical volumes.