5#include "TRestGeant4PrimaryGeneratorInfo.h"
11#include <TRestStringOutput.h>
16using namespace TRestGeant4PrimaryGeneratorTypes;
18string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString(
const SpatialGeneratorTypes& type) {
20 case SpatialGeneratorTypes::CUSTOM:
22 case SpatialGeneratorTypes::VOLUME:
24 case SpatialGeneratorTypes::SURFACE:
26 case SpatialGeneratorTypes::POINT:
28 case SpatialGeneratorTypes::COSMIC:
30 case SpatialGeneratorTypes::SOURCE:
33 cout <<
"TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString - Error - Unknown "
34 "SpatialGeneratorTypes"
39SpatialGeneratorTypes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorTypes(
const string& type) {
40 if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::CUSTOM),
41 TString::ECaseCompare::kIgnoreCase)) {
42 return SpatialGeneratorTypes::CUSTOM;
43 }
else if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME),
44 TString::ECaseCompare::kIgnoreCase)) {
45 return SpatialGeneratorTypes::VOLUME;
46 }
else if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::SURFACE),
47 TString::ECaseCompare::kIgnoreCase)) {
48 return SpatialGeneratorTypes::SURFACE;
49 }
else if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::POINT),
50 TString::ECaseCompare::kIgnoreCase)) {
51 return SpatialGeneratorTypes::POINT;
52 }
else if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::COSMIC),
53 TString::ECaseCompare::kIgnoreCase)) {
54 return SpatialGeneratorTypes::COSMIC;
55 }
else if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::SOURCE),
56 TString::ECaseCompare::kIgnoreCase)) {
57 return SpatialGeneratorTypes::SOURCE;
59 cout <<
"TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorTypes - Error - Unknown "
60 "SpatialGeneratorTypes: "
66string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorShapesToString(
const SpatialGeneratorShapes& type) {
68 case SpatialGeneratorShapes::GDML:
70 case SpatialGeneratorShapes::WALL:
72 case SpatialGeneratorShapes::CIRCLE:
74 case SpatialGeneratorShapes::BOX:
76 case SpatialGeneratorShapes::SPHERE:
78 case SpatialGeneratorShapes::CYLINDER:
81 cout <<
"TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorShapesToString - Error - Unknown "
82 "SpatialGeneratorShapes"
87SpatialGeneratorShapes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorShapes(
const string& type) {
88 if (TString(type).EqualTo(SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML),
89 TString::ECaseCompare::kIgnoreCase)) {
90 return SpatialGeneratorShapes::GDML;
91 }
else if (TString(type).EqualTo(SpatialGeneratorShapesToString(SpatialGeneratorShapes::WALL),
92 TString::ECaseCompare::kIgnoreCase)) {
93 return SpatialGeneratorShapes::WALL;
94 }
else if (TString(type).EqualTo(SpatialGeneratorShapesToString(SpatialGeneratorShapes::CIRCLE),
95 TString::ECaseCompare::kIgnoreCase)) {
96 return SpatialGeneratorShapes::CIRCLE;
97 }
else if (TString(type).EqualTo(SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX),
98 TString::ECaseCompare::kIgnoreCase)) {
99 return SpatialGeneratorShapes::BOX;
100 }
else if (TString(type).EqualTo(SpatialGeneratorShapesToString(SpatialGeneratorShapes::SPHERE),
101 TString::ECaseCompare::kIgnoreCase)) {
102 return SpatialGeneratorShapes::SPHERE;
103 }
else if (TString(type).EqualTo(SpatialGeneratorShapesToString(SpatialGeneratorShapes::CYLINDER),
104 TString::ECaseCompare::kIgnoreCase)) {
105 return SpatialGeneratorShapes::CYLINDER;
108 cout <<
"TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorShapes - Error - Unknown "
109 "SpatialGeneratorShapes: "
115string TRestGeant4PrimaryGeneratorTypes::EnergyDistributionTypesToString(
116 const EnergyDistributionTypes& type) {
118 case EnergyDistributionTypes::TH1D:
120 case EnergyDistributionTypes::TH2D:
122 case EnergyDistributionTypes::FORMULA:
124 case EnergyDistributionTypes::FORMULA2:
126 case EnergyDistributionTypes::MONO:
128 case EnergyDistributionTypes::FLAT:
130 case EnergyDistributionTypes::LOG:
133 cout <<
"TRestGeant4PrimaryGeneratorTypes::EnergyDistributionTypesToString - Error - Unknown energy "
139EnergyDistributionTypes TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionTypes(
140 const string& type) {
141 if (TString(type).EqualTo(EnergyDistributionTypesToString(EnergyDistributionTypes::TH1D),
142 TString::ECaseCompare::kIgnoreCase)) {
143 return EnergyDistributionTypes::TH1D;
144 }
else if (TString(type).EqualTo(EnergyDistributionTypesToString(EnergyDistributionTypes::TH2D),
145 TString::ECaseCompare::kIgnoreCase)) {
146 return EnergyDistributionTypes::TH2D;
147 }
else if (TString(type).EqualTo(EnergyDistributionTypesToString(EnergyDistributionTypes::FORMULA),
148 TString::ECaseCompare::kIgnoreCase)) {
149 return EnergyDistributionTypes::FORMULA;
150 }
else if (TString(type).EqualTo(EnergyDistributionTypesToString(EnergyDistributionTypes::FORMULA2),
151 TString::ECaseCompare::kIgnoreCase)) {
152 return EnergyDistributionTypes::FORMULA2;
153 }
else if (TString(type).EqualTo(EnergyDistributionTypesToString(EnergyDistributionTypes::MONO),
154 TString::ECaseCompare::kIgnoreCase)) {
155 return EnergyDistributionTypes::MONO;
156 }
else if (TString(type).EqualTo(EnergyDistributionTypesToString(EnergyDistributionTypes::FLAT),
157 TString::ECaseCompare::kIgnoreCase)) {
158 return EnergyDistributionTypes::FLAT;
159 }
else if (TString(type).EqualTo(EnergyDistributionTypesToString(EnergyDistributionTypes::LOG),
160 TString::ECaseCompare::kIgnoreCase)) {
161 return EnergyDistributionTypes::LOG;
163 cout <<
"TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionTypes - Error - Unknown "
164 "EnergyDistributionTypes: "
170string TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToString(
171 const EnergyDistributionFormulas& type) {
173 case EnergyDistributionFormulas::COSMIC_NEUTRONS:
174 return "CosmicNeutrons";
175 case EnergyDistributionFormulas::COSMIC_GAMMAS:
176 return "CosmicGammas";
178 cout <<
"TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToString - Error - Unknown energy "
179 "distribution formula"
184EnergyDistributionFormulas TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionFormulas(
185 const string& type) {
186 if (TString(type).EqualTo(EnergyDistributionFormulasToString(EnergyDistributionFormulas::COSMIC_NEUTRONS),
187 TString::ECaseCompare::kIgnoreCase)) {
188 return EnergyDistributionFormulas::COSMIC_NEUTRONS;
189 }
else if (TString(type).EqualTo(
190 EnergyDistributionFormulasToString(EnergyDistributionFormulas::COSMIC_GAMMAS),
191 TString::ECaseCompare::kIgnoreCase)) {
192 return EnergyDistributionFormulas::COSMIC_GAMMAS;
194 cout <<
"TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionFormulas - Error - Unknown "
195 "energyDistributionFormulas: "
201TF1 TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToRootFormula(
202 const EnergyDistributionFormulas& type) {
204 case EnergyDistributionFormulas::COSMIC_NEUTRONS: {
206 const char* title =
"Cosmic Neutrons at Sea Level";
209 "1.006E-6 * TMath::Exp(-0.3500 * TMath::Power(TMath::Log(x * 1E-3), 2) + 2.1451 * "
210 "TMath::Log(x * 1E-3)) + "
211 "1.011E-3 * TMath::Exp(-0.4106 * TMath::Power(TMath::Log(x * 1E-3), 2) - 0.6670 * "
212 "TMath::Log(x * 1E-3))",
214 distribution.SetNormalized(
true);
215 distribution.SetTitle(title);
216 distribution.GetXaxis()->SetTitle(
"Energy (keV)");
219 case EnergyDistributionFormulas::COSMIC_GAMMAS:
222 cout <<
"TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToRootFormula - Error - Unknown "
223 "energy distribution formula"
228string TRestGeant4PrimaryGeneratorTypes::AngularDistributionTypesToString(
229 const AngularDistributionTypes& type) {
231 case AngularDistributionTypes::TH1D:
233 case AngularDistributionTypes::TH2D:
235 case AngularDistributionTypes::FORMULA:
237 case AngularDistributionTypes::FORMULA2:
239 case AngularDistributionTypes::ISOTROPIC:
241 case AngularDistributionTypes::FLUX:
243 case AngularDistributionTypes::BACK_TO_BACK:
244 return "Back to back";
246 cout <<
"TRestGeant4PrimaryGeneratorTypes::AngularDistributionTypesToString - Error - Unknown angular "
252AngularDistributionTypes TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionTypes(
253 const string& type) {
254 if (TString(type).EqualTo(AngularDistributionTypesToString(AngularDistributionTypes::TH1D),
255 TString::ECaseCompare::kIgnoreCase)) {
256 return AngularDistributionTypes::TH1D;
257 }
else if (TString(type).EqualTo(AngularDistributionTypesToString(AngularDistributionTypes::TH2D),
258 TString::ECaseCompare::kIgnoreCase)) {
259 return AngularDistributionTypes::TH2D;
260 }
else if (TString(type).EqualTo(AngularDistributionTypesToString(AngularDistributionTypes::FORMULA),
261 TString::ECaseCompare::kIgnoreCase)) {
262 return AngularDistributionTypes::FORMULA;
263 }
else if (TString(type).EqualTo(AngularDistributionTypesToString(AngularDistributionTypes::FORMULA2),
264 TString::ECaseCompare::kIgnoreCase)) {
265 return AngularDistributionTypes::FORMULA2;
266 }
else if (TString(type).EqualTo(AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC),
267 TString::ECaseCompare::kIgnoreCase)) {
268 return AngularDistributionTypes::ISOTROPIC;
269 }
else if (TString(type).EqualTo(AngularDistributionTypesToString(AngularDistributionTypes::FLUX),
270 TString::ECaseCompare::kIgnoreCase)) {
271 return AngularDistributionTypes::FLUX;
272 }
else if (TString(type).EqualTo(AngularDistributionTypesToString(AngularDistributionTypes::BACK_TO_BACK),
273 TString::ECaseCompare::kIgnoreCase)) {
274 return AngularDistributionTypes::BACK_TO_BACK;
276 cout <<
"TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionTypes - Error - Unknown "
277 "AngularDistributionTypes: "
283string TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToString(
284 const AngularDistributionFormulas& type) {
286 case AngularDistributionFormulas::COS2:
288 case AngularDistributionFormulas::COS3:
291 cout <<
"TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToString - Error - Unknown angular "
292 "distribution formula"
297AngularDistributionFormulas TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionFormulas(
298 const string& type) {
299 if (TString(type).EqualTo(AngularDistributionFormulasToString(AngularDistributionFormulas::COS2),
300 TString::ECaseCompare::kIgnoreCase)) {
301 return AngularDistributionFormulas::COS2;
302 }
else if (TString(type).EqualTo(AngularDistributionFormulasToString(AngularDistributionFormulas::COS3),
303 TString::ECaseCompare::kIgnoreCase)) {
304 return AngularDistributionFormulas::COS3;
306 cout <<
"TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionFormulas - Error - Unknown "
307 "AngularDistributionFormulas: "
313TF1 TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToRootFormula(
314 const AngularDistributionFormulas& type) {
316 case AngularDistributionFormulas::COS2: {
317 auto cos2 = [](
double* xs,
double* ps) {
318 if (xs[0] >= 0 && xs[0] <= TMath::Pi() / 2) {
319 return TMath::Power(TMath::Cos(xs[0]), 2);
323 const char* title =
"AngularDistribution: Cos2";
324 auto f = TF1(title, cos2, 0.0, TMath::Pi());
328 case AngularDistributionFormulas::COS3: {
329 auto cos3 = [](
double* xs,
double* ps) {
330 if (xs[0] >= 0 && xs[0] <= TMath::Pi() / 2) {
331 return TMath::Power(TMath::Cos(xs[0]), 3);
335 const char* title =
"AngularDistribution: Cos3";
336 auto f = TF1(title, cos3, 0.0, TMath::Pi());
341 cout <<
"TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToRootFormula - Error - Unknown "
342 "angular distribution formula"
347string TRestGeant4PrimaryGeneratorTypes::EnergyAndAngularDistributionFormulasToString(
348 const EnergyAndAngularDistributionFormulas& type) {
350 case EnergyAndAngularDistributionFormulas::COSMIC_MUONS:
351 return "CosmicMuons";
353 cout <<
"TRestGeant4PrimaryGeneratorTypes::EnergyAndAngularDistributionFormulasToString - Error - "
354 "Unknown energy/angular distribution formula"
359EnergyAndAngularDistributionFormulas
360TRestGeant4PrimaryGeneratorTypes::StringToEnergyAndAngularDistributionFormulas(
const string& type) {
361 if (TString(type).EqualTo(
362 EnergyAndAngularDistributionFormulasToString(EnergyAndAngularDistributionFormulas::COSMIC_MUONS),
363 TString::ECaseCompare::kIgnoreCase)) {
364 return EnergyAndAngularDistributionFormulas::COSMIC_MUONS;
366 cout <<
"TRestGeant4PrimaryGeneratorTypes::StringToEnergyAndAngularDistributionFormulas - Error - "
367 "Unknown AngularDistributionFormulas: "
373TF2 TRestGeant4PrimaryGeneratorTypes::EnergyAndAngularDistributionFormulasToRootFormula(
374 const EnergyAndAngularDistributionFormulas& type) {
376 case EnergyAndAngularDistributionFormulas::COSMIC_MUONS: {
381 const char* title =
"Cosmic Muons Energy and Angular";
384 "2*TMath::Pi()*1E-6*0.14*TMath::Power(x*1E-6*(1.+3.64/"
385 "(x*1E-6*TMath::Power(TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*"
386 "TMath::Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285)"
387 ")/(0.982960),0.5),1.29))),-2.7)*(1./"
388 "(1.+(1.1*x*1E-6*TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*TMath::"
389 "Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285))/"
390 "(0.982960),0.5))/115.)+0.054/"
391 "(1.+(1.1*x*1E-6*TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*TMath::"
392 "Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285))/"
393 "(0.982960),0.5))/850.))*(2.*TMath::Sin(y)*TMath::Pi())",
394 2.0E5, 5.0E9, 0, TMath::Pi() / 2.);
405 cout <<
"TRestGeant4PrimaryGeneratorTypes::EnergyAndAngularDistributionFormulasToRootFormula - Error - "
406 "Unknown energy and angular distribution formula"
411void TRestGeant4PrimaryGeneratorInfo::Print()
const {
413 RESTMetadata <<
"Generator type: " << SpatialGeneratorTypesToString(typeEnum) << RESTendl;
415 if (typeEnum != SpatialGeneratorTypes::POINT) {
417 RESTMetadata <<
"Generator shape: " << SpatialGeneratorShapesToString(shapeEnum);
418 if (shapeEnum == SpatialGeneratorShapes::GDML) {
421 if (shapeEnum == SpatialGeneratorShapes::BOX) {
422 RESTMetadata <<
", (length, width, height): ";
423 }
else if (shapeEnum == SpatialGeneratorShapes::SPHERE) {
424 RESTMetadata <<
", (radius, , ): ";
425 }
else if (shapeEnum == SpatialGeneratorShapes::WALL) {
426 RESTMetadata <<
", (length, width, ): ";
427 }
else if (shapeEnum == SpatialGeneratorShapes::CIRCLE) {
428 RESTMetadata <<
", (radius, , ): ";
429 }
else if (shapeEnum == SpatialGeneratorShapes::CYLINDER) {
430 RESTMetadata <<
", (radius, length, ): ";
TVector3 fSpatialGeneratorSize
The size of the generator. Stores up to three dimensions according to the shape box: length,...
TString fSpatialGeneratorFrom
The volume name where the events are generated, in case of volume or surface generator types.
Double_t fSpatialGeneratorRotationValue
degrees of rotation for generator virtual shape along the axis
TVector3 fSpatialGeneratorPosition
The position of the generator for virtual, and point, generator types.
TVector3 fSpatialGeneratorRotationAxis
A 3d-std::vector with the angles, measured in degrees, of a XYZ rotation applied to the virtual gener...
TString fSpatialGeneratorShape
Shape of spatial generator (wall, GDML, sphere, etc)
TString fSpatialGeneratorType
Type of spatial generator (point, surface, volume, custom)