REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestGeant4ParticleSource.h
1
16
17#ifndef RestCore_TRestGeant4ParticleSource
18#define RestCore_TRestGeant4ParticleSource
19
20#include <TF1.h>
21#include <TF2.h>
22#include <TRestMetadata.h>
23#include <TString.h>
24#include <TVector2.h>
25#include <TVector3.h>
26
27#include <iostream>
28
29#include "TRestGeant4Particle.h"
30#include "TRestGeant4PrimaryGeneratorInfo.h"
31
33 private:
34 void ReadEventDataFile(TString fName);
35 bool ReadNewDecay0File(TString fileName);
36 bool ReadOldDecay0File(TString fileName);
37
38 protected:
39 TString fAngularDistributionType = "Flux";
40 TString fAngularDistributionFilename;
41 TString fAngularDistributionNameInFile;
42 size_t fAngularDistributionFormulaNPoints = 500;
43 TF1* fAngularDistributionFunction = nullptr;
44 TVector2 fAngularDistributionRange;
45 double fAngularDistributionIsotropicConeHalfAngle = 0;
46
47 TString fEnergyDistributionType = "Mono";
48 TString fEnergyDistributionFilename;
49 TString fEnergyDistributionNameInFile;
50 size_t fEnergyDistributionFormulaNPoints = 5000;
51 TF1* fEnergyDistributionFunction = nullptr;
52 TVector2 fEnergyDistributionRange;
53
54 TF2* fEnergyAndAngularDistributionFunction = nullptr;
55
56 TString fGenFilename;
57 // store a set of generated particles
58 std::vector<TRestGeant4Particle> fParticles;
59 // store a list of particle set templates that could be used to generate fParticles
60 std::vector<std::vector<TRestGeant4Particle>> fParticlesTemplate;
61 // the random method to generate 0~1 equally distributed numbers
62 double (*fRandomMethod)();
63
64 public:
65 virtual void Update();
66 virtual void InitFromConfigFile() override;
67 static TRestGeant4ParticleSource* instantiate(std::string model = "");
68
69 TVector3 GetDirection() const;
70
71 inline TString GetEnergyDistributionType() const { return fEnergyDistributionType; }
72 inline TVector2 GetEnergyDistributionRange() const { return fEnergyDistributionRange; }
73 inline Double_t GetEnergyDistributionRangeMin() const { return fEnergyDistributionRange.X(); }
74 inline Double_t GetEnergyDistributionRangeMax() const { return fEnergyDistributionRange.Y(); }
75 inline size_t GetEnergyDistributionFormulaNPoints() const { return fEnergyDistributionFormulaNPoints; }
76 inline TString GetEnergyDistributionFilename() const { return fEnergyDistributionFilename; }
77 inline TString GetEnergyDistributionNameInFile() const { return fEnergyDistributionNameInFile; }
78 inline const TF1* GetEnergyDistributionFunction() const { return fEnergyDistributionFunction; }
79
80 inline TString GetAngularDistributionType() const { return fAngularDistributionType; }
81 inline TVector2 GetAngularDistributionRange() const { return fAngularDistributionRange; }
82 inline Double_t GetAngularDistributionRangeMin() const { return fAngularDistributionRange.X(); }
83 inline Double_t GetAngularDistributionRangeMax() const { return fAngularDistributionRange.Y(); }
84 inline size_t GetAngularDistributionFormulaNPoints() const { return fAngularDistributionFormulaNPoints; }
85 inline TString GetAngularDistributionFilename() const { return fAngularDistributionFilename; }
86 inline TString GetAngularDistributionNameInFile() const { return fAngularDistributionNameInFile; }
87 inline const TF1* GetAngularDistributionFunction() const { return fAngularDistributionFunction; }
88 inline double GetAngularDistributionIsotropicConeHalfAngle() const {
89 return fAngularDistributionIsotropicConeHalfAngle;
90 }
91
92 inline const TF2* GetEnergyAndAngularDistributionFunction() const {
93 return fEnergyAndAngularDistributionFunction;
94 }
95
96 inline TString GetGenFilename() const { return fGenFilename; }
97
98 inline std::vector<TRestGeant4Particle> GetParticles() const { return fParticles; }
99
100 inline void SetAngularDistributionIsotropicConeHalfAngle(double angle) {
101 if (angle < 0 || angle > TMath::Pi()) {
102 std::cerr << "TRestGeant4ParticleSource::SetAngularDistributionIsotropicConeHalfAngle: "
103 "angle must be between 0 and Pi radians"
104 << std::endl;
105 exit(1);
106 }
107 fAngularDistributionIsotropicConeHalfAngle = angle;
108 }
109
110 inline void SetAngularDistributionType(const TString& type) {
111 fAngularDistributionType = TRestGeant4PrimaryGeneratorTypes::AngularDistributionTypesToString(
112 TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionTypes(type.Data()));
113 }
114 inline void SetAngularDistributionRange(const TVector2& range) {
115 fAngularDistributionRange = range;
116 if (fAngularDistributionRange.X() < 0) {
117 fAngularDistributionRange.Set(0, fAngularDistributionRange.Y());
118 }
119 if (fAngularDistributionRange.Y() < 0) {
120 fAngularDistributionRange.Set(fAngularDistributionRange.X(), 0);
121 }
122 if (fAngularDistributionRange.Y() > TMath::Pi()) {
123 fAngularDistributionRange.Set(fAngularDistributionRange.X(), TMath::Pi());
124 }
125 if (fAngularDistributionRange.X() > fAngularDistributionRange.Y()) {
126 fAngularDistributionRange.Set(fAngularDistributionRange.Y(), fAngularDistributionRange.X());
127 }
128 }
129 inline void SetAngularDistributionFormulaNPoints(size_t nPoints) {
130 const auto nPointsMax = 10000;
131 if (nPoints > nPointsMax) {
132 nPoints = nPointsMax;
133 }
134 fAngularDistributionFormulaNPoints = nPoints;
135 }
136 inline void SetAngularDistributionFilename(const TString& filename) {
137 fAngularDistributionFilename = filename;
138 }
139 inline void SetAngularDistributionNameInFile(const TString& name) {
140 fAngularDistributionNameInFile = name;
141 }
142 inline void SetAngularDistributionFormula(const TString& formula) {
143 fAngularDistributionFunction =
144 (TF1*)TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToRootFormula(
145 TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionFormulas(formula.Data()))
146 .Clone();
147 }
148
149 inline void SetEnergyDistributionType(const TString& type) {
150 fEnergyDistributionType = TRestGeant4PrimaryGeneratorTypes::EnergyDistributionTypesToString(
151 TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionTypes(type.Data()));
152 }
153 inline void SetEnergyDistributionRange(const TVector2& range) {
154 fEnergyDistributionRange = range;
155 if (fEnergyDistributionRange.X() < 0) {
156 fEnergyDistributionRange.Set(0, fEnergyDistributionRange.Y());
157 }
158 if (fEnergyDistributionRange.Y() < 0) {
159 fEnergyDistributionRange.Set(fEnergyDistributionRange.X(), 0);
160 }
161 if (fEnergyDistributionRange.X() > fEnergyDistributionRange.Y()) {
162 fEnergyDistributionRange.Set(fEnergyDistributionRange.Y(), fEnergyDistributionRange.X());
163 }
164 }
165 inline void SetEnergyDistributionFormulaNPoints(size_t nPoints) {
166 const auto nPointsMax = 10000;
167 if (nPoints > nPointsMax) {
168 nPoints = nPointsMax;
169 }
170 fEnergyDistributionFormulaNPoints = nPoints;
171 }
172 inline void SetEnergyDistributionFilename(const TString& filename) {
173 fEnergyDistributionFilename = filename;
174 }
175 inline void SetEnergyDistributionNameInFile(const TString& name) { fEnergyDistributionNameInFile = name; }
176 inline void SetEnergyDistributionFormula(const TString& formula) {
177 fEnergyDistributionFunction =
178 (TF1*)TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToRootFormula(
179 TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionFormulas(formula.Data()))
180 .Clone();
181 }
182
183 inline void SetEnergyAndAngularDistributionFormula(const TString& formula) {
184 fEnergyAndAngularDistributionFunction =
185 (TF2*)TRestGeant4PrimaryGeneratorTypes::EnergyAndAngularDistributionFormulasToRootFormula(
186 TRestGeant4PrimaryGeneratorTypes::StringToEnergyAndAngularDistributionFormulas(
187 formula.Data()))
188 .Clone();
189 }
190
191 inline void SetGenFilename(const TString& name) { fGenFilename = name; }
192
193 inline void SetRandomMethod(double (*method)()) { fRandomMethod = method; }
194
195 inline void AddParticle(const TRestGeant4Particle& particle) { fParticles.push_back(particle); }
196
197 inline void RemoveParticles() { fParticles.clear(); }
198 inline void RemoveTemplates() { fParticlesTemplate.clear(); }
199 inline void FlushParticlesTemplate() {
200 fParticlesTemplate.push_back(fParticles);
201 fParticles.clear();
202 }
203
204 virtual void PrintMetadata() override;
205
206 // Constructor
208 // Destructor
210
211 ClassDefOverride(TRestGeant4ParticleSource, 6);
212};
213#endif
void ReadEventDataFile(TString fName)
Reads an input file produced by Decay0.
virtual void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
virtual void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
bool ReadOldDecay0File(TString fileName)
Reads particle information using the file format from older Decay0 versions.
bool ReadNewDecay0File(TString fileName)
Reads particle information using the file format from newer Decay0 versions.
A class used to store particle properties.
A base class for any REST metadata class.
Definition: TRestMetadata.h:74