REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestGeant4ParticleSourceDecay0.cxx
1#include "TRestGeant4ParticleSourceDecay0.h"
2
3using namespace std;
4
6
7TRestGeant4ParticleSourceDecay0::TRestGeant4ParticleSourceDecay0()
8/* : generator((uintptr_t)this), prng(generator)*/ {
9 fDecay0Model = new bxdecay0::decay0_generator();
10}
11
13 RESTMetadata << "---------------------------------------" << RESTendl;
14 if (!fParticleName.empty() && fParticleName != "NO_SUCH_PARA")
15 RESTMetadata << "Particle Source Name: " << fParticleName << RESTendl;
16 RESTMetadata << "Parent Nuclide: " << fParentName << RESTendl;
17 RESTMetadata << "Decay Mode: " << fDecayType << RESTendl;
18 RESTMetadata << "Daughter Level: " << fDaughterLevel << RESTendl;
19 RESTMetadata << "Seed: " << fSeed << RESTendl;
20}
21
23 // unsigned int seed = (uintptr_t)this;
24 // std::default_random_engine generator(seed);
25 // prng = bxdecay0::std_random(generator);
26 fParticleName = ((TRestMetadata*)this)->ClassName();
27 fParentName = GetParameter("particle");
28 fDecayType = GetParameter("decayMode");
29 fDaughterLevel = StringToInteger(GetParameter("daughterLevel"));
30 fSeed = StringToInteger(GetParameter("seed", "0"));
31 if (fSeed != 0) {
32 } else {
33 fSeed = (uintptr_t)this;
34 }
35 generator = new std::default_random_engine(fSeed);
36 prng = new bxdecay0::std_random(*generator);
37
38 fDecay0Model->set_decay_category(bxdecay0::decay0_generator::DECAY_CATEGORY_DBD);
39
40 if (fParentName != "Xe136") {
41 ferr << "Only Xe136 double beta decay is supported by restDecay0" << endl;
42 exit(1);
43 }
44 if (fDaughterLevel < 0 || fDaughterLevel > 3) {
45 ferr << "Supported Ba136 excitation level: 0, 1, 2, 3" << endl;
46 exit(1);
47 }
48
49 fDecay0Model->set_decay_isotope(fParentName);
50
51 fDecay0Model->set_decay_dbd_level(fDaughterLevel);
52
53 if (fDecayType == "2vbb") {
54 if (fDaughterLevel == 0 || fDaughterLevel == 3) {
55 fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_2NUBB_0_2N);
56 } else if (fDaughterLevel == 1 || fDaughterLevel == 2) {
57 fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_2NUBB_2_2N);
58 }
59 } else if (fDecayType == "0vbb") {
60 if (fDaughterLevel == 0 || fDaughterLevel == 3) {
61 fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_0NUBB_MN_0_2N);
62 } else if (fDaughterLevel == 1 || fDaughterLevel == 2) {
63 fDecay0Model->set_decay_dbd_mode(bxdecay0::DBDMODE_0NUBB_RHC_LAMBDA_2_2N);
64 }
65 }
66
67 fDecay0Model->initialize(*prng);
68
69 Update();
70}
71
72void TRestGeant4ParticleSourceDecay0::Update() {
73 RemoveParticles();
74
75 bxdecay0::event gendecay;
76 fDecay0Model->shoot(*prng, gendecay);
77
78 auto ps = gendecay.get_particles();
79 for (auto p : ps) {
80 TRestGeant4Particle particle;
81 double mass;
82 double energy;
83
84 double momx = p.get_px();
85 double momy = p.get_py();
86 double momz = p.get_pz();
87 double momentum2 = p.get_p() * p.get_p();
88 int pID = p.get_code();
89
90 /*
91 0, ///< Invalid particle code
92 1, ///< Gamma
93 2, ///< Positron
94 3, ///< Electron
95 13, ///< Neutron
96 14, ///< Proton
97 47 ///< Alpha
98 */
99
100 if (pID == 1) {
101 energy = TMath::Sqrt(momentum2);
102 particle.SetParticleName("gamma");
103 particle.SetParticleCharge(0);
104 particle.SetExcitationLevel(0);
105 } else if (pID == 2) {
106 mass = 0.511;
107 energy = TMath::Sqrt(momentum2);
108 particle.SetParticleName("positron");
109 particle.SetParticleCharge(1);
110 particle.SetExcitationLevel(0);
111 } else if (pID == 3) {
112 mass = 0.511;
113 energy = TMath::Sqrt(momentum2 + mass * mass) - mass;
114 particle.SetParticleName("e-");
115 particle.SetParticleCharge(-1);
116 particle.SetExcitationLevel(0);
117 } else if (pID == 13) {
118 mass = 939.6;
119 energy = TMath::Sqrt(momentum2);
120 particle.SetParticleName("neutron");
121 particle.SetParticleCharge(0);
122 particle.SetExcitationLevel(0);
123 } else if (pID == 14) {
124 mass = 938.3;
125 energy = TMath::Sqrt(momentum2);
126 particle.SetParticleName("proton");
127 particle.SetParticleCharge(1);
128 particle.SetExcitationLevel(0);
129 } else if (pID == 47) {
130 mass = 3727;
131 energy = TMath::Sqrt(momentum2);
132 particle.SetParticleName("alpha");
133 particle.SetParticleCharge(2);
134 particle.SetExcitationLevel(0);
135 }
136
137 TVector3 momDirection(momx, momy, momz);
138 momDirection = momDirection.Unit();
139
140 particle.SetEnergy(1000. * energy);
141 particle.SetDirection(momDirection);
142
143 // cout << energy * 1000 << " ";
144
145 AddParticle(particle);
146 }
147
148 // cout << endl;
149}
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.
A class used to store particle properties.
A base class for any REST metadata class.
Definition: TRestMetadata.h:74
endl_t RESTendl
Termination flag object for TRestStringOutput.
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.
Int_t StringToInteger(std::string in)
Gets an integer from a string.