REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestGeant4PhysicsLists.cxx
1
18
19#include "TRestGeant4PhysicsLists.h"
20
21#include <TRestTools.h>
22
23using namespace std;
24
26
27TRestGeant4PhysicsLists::TRestGeant4PhysicsLists() : TRestMetadata() { Initialize(); }
28
29TRestGeant4PhysicsLists::TRestGeant4PhysicsLists(const char* configFilename, string name)
30 : TRestMetadata(configFilename) {
31 Initialize();
32 LoadConfigFromFile(fConfigFileName, name);
33}
34
35TRestGeant4PhysicsLists::~TRestGeant4PhysicsLists() = default;
36
38 SetSectionName(this->ClassName());
39 SetLibraryVersion(LIBRARY_VERSION);
40}
41
43 this->Initialize();
44
45 fIonLimitStepList = Split(GetParameter("ionLimitStepList", ""), ",");
46
47 fCutForGamma = GetDblParameterWithUnits("cutForGamma", 0.01);
48 fCutForElectron = GetDblParameterWithUnits("cutForElectron", 1);
49 fCutForPositron = GetDblParameterWithUnits("cutForPositron", 1);
50 fCutForMuon = GetDblParameterWithUnits("cutForMuon", 1);
51 fCutForNeutron = GetDblParameterWithUnits("cutForNeutron", 1);
52 fMinEnergyRangeProductionCuts = GetDblParameterWithUnits("minEnergyRangeProductionCuts", 1);
53 fMaxEnergyRangeProductionCuts = GetDblParameterWithUnits("maxEnergyRangeProductionCuts", 1e6);
54
55 TiXmlElement* physicsListDefinition = GetElement("physicsList");
56 while (physicsListDefinition) {
57 // PhysicsList name
58 TString physicsListName = GetFieldValue("name", physicsListDefinition);
59
60 if (!PhysicsListExists(physicsListName)) {
61 cerr << "TRestPhysicsList: Physics list: '" << physicsListName
62 << "' not found among valid options" << endl;
63 exit(1);
64 }
65
66 TString optionString = "";
67 TiXmlElement* optionDefinition = GetElement("option", physicsListDefinition);
68 while (optionDefinition) {
69 TString optionName = GetFieldValue("name", optionDefinition);
70 TString optionValue = GetFieldValue("value", optionDefinition);
71
72 if (optionString != "") {
73 optionString += ":";
74 }
75 optionString += optionName + ":" + optionValue;
76
77 optionDefinition = GetNextElement(optionDefinition);
78 }
79
80 fPhysicsLists.push_back(physicsListName);
81 fPhysicsListOptions.push_back(optionString);
82 physicsListDefinition = GetNextElement(physicsListDefinition);
83 }
84}
85
86Int_t TRestGeant4PhysicsLists::FindPhysicsList(const TString& physicsListName) const {
87 if (!PhysicsListExists(physicsListName)) return -1;
88
89 for (unsigned int n = 0; n < fPhysicsLists.size(); n++) {
90 if (fPhysicsLists[n] == physicsListName) {
91 return (Int_t)n;
92 }
93 }
94
95 return -1;
96}
97
98TString TRestGeant4PhysicsLists::GetPhysicsListOptionString(const TString& physicsListName) const {
99 Int_t index = FindPhysicsList(physicsListName);
100
101 if (index == -1) {
102 return "";
103 }
104
105 return fPhysicsListOptions[index];
106}
107
108TString TRestGeant4PhysicsLists::GetPhysicsListOptionValue(const TString& physicsListName,
109 const TString& option,
110 const TString& defaultValue) const {
111 vector<string> optList = TRestTools::GetOptions((string)GetPhysicsListOptionString(physicsListName));
112
113 for (unsigned int n = 0; n < optList.size(); n = n + 2) {
114 if (optList[n] == option) {
115 return optList[n + 1];
116 }
117 }
118
119 return defaultValue;
120}
121
122Bool_t TRestGeant4PhysicsLists::PhysicsListExists(const TString& physicsListName) const {
123 const set<TString> validPhysicsLists = {"G4DecayPhysics",
124 "G4RadioactiveDecayPhysics",
125 "G4RadioactiveDecay",
126 "G4RadioactiveDecayBase",
127 "G4Radioactivation",
128 "G4EmLivermorePhysics",
129 "G4EmPenelopePhysics",
130 "G4EmStandardPhysics_option3",
131 "G4EmStandardPhysics_option4",
132 "G4HadronElasticPhysicsHP",
133 "G4IonBinaryCascadePhysics",
134 "G4HadronPhysicsQGSP_BIC_HP",
135 "G4NeutronTrackingCut",
136 "G4EmExtraPhysics"};
137
138 return validPhysicsLists.count(physicsListName) > 0;
139}
140
143
144 RESTMetadata << "Cut for electrons : " << fCutForElectron << " mm" << RESTendl;
145 RESTMetadata << "Cut for positrons : " << fCutForPositron << " mm" << RESTendl;
146 RESTMetadata << "Cut for gammas : " << fCutForGamma << " mm" << RESTendl;
147 RESTMetadata << "Cut for muons : " << fCutForMuon << " mm" << RESTendl;
148 RESTMetadata << "Cut for neutrons : " << fCutForNeutron << " mm" << RESTendl;
149 RESTMetadata << "Min Energy for particle production: " << fMinEnergyRangeProductionCuts << " keV"
150 << RESTendl;
151 RESTMetadata << "Max Energy for particle production: " << fMaxEnergyRangeProductionCuts << " keV"
152 << RESTendl;
153 RESTMetadata << "---------------------------------------" << RESTendl;
154 for (unsigned int n = 0; n < fPhysicsLists.size(); n++) {
155 RESTMetadata << "Physics list " << n << " : " << fPhysicsLists[n] << RESTendl;
156 vector<string> optList = TRestTools::GetOptions((string)fPhysicsListOptions[n]);
157 for (unsigned int m = 0; m < optList.size(); m = m + 2)
158 RESTMetadata << " - Option " << m / 2 << " : " << optList[m] << " = " << optList[m + 1]
159 << RESTendl;
160 }
161 if (!fIonLimitStepList.empty()) {
162 RESTMetadata << "List of ions affected by step limit" << RESTendl;
163 for (const auto& ion : fIonLimitStepList) {
164 RESTMetadata << " - " << ion << RESTendl;
165 }
166 }
167
168 RESTMetadata << "******************************************" << RESTendl;
169 RESTMetadata << RESTendl;
170 RESTMetadata << RESTendl;
171}
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
void Initialize() override
Making default settings.
A base class for any REST metadata class.
Definition: TRestMetadata.h:70
virtual void PrintMetadata()
Implemented it in the derived metadata class to print out specific metadata information.
endl_t RESTendl
Termination flag object for TRestStringOutput.
TiXmlElement * GetElement(std::string eleDeclare, TiXmlElement *e=nullptr)
Get an xml element from a given parent element, according to its declaration.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
std::string GetFieldValue(std::string parName, TiXmlElement *e)
Returns the field value of an xml element which has the specified name.
void SetSectionName(std::string sName)
set the section name, clear the section content
TiXmlElement * GetNextElement(TiXmlElement *e)
Get the next sibling xml element of this element, with same eleDeclare.
std::string GetParameter(std::string parName, TiXmlElement *e, TString defaultValue=PARAMETER_NOT_FOUND_STR)
Returns the value for the parameter named parName in the given section.
static std::vector< std::string > GetOptions(std::string optionsStr)
Returns all the options in an option string.
Definition: TRestTools.cxx:86
std::vector< std::string > Split(std::string in, std::string separator, bool allowBlankString=false, bool removeWhiteSpaces=false, int startPos=-1)
Split the input string according to the given separator. Returning a vector of fragments.