REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestAxionGeneratorProcess.cxx
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
66#include "TRestAxionGeneratorProcess.h"
67using namespace std;
68
70
75
80
85 SetSectionName(this->ClassName());
86 SetLibraryVersion(LIBRARY_VERSION);
87
89
90 fIsExternal = true;
91 fSingleThreadOnly = true;
92}
93
99 RESTDebug << "Entering ... TRestAxionGeneratorProcess::InitProcess" << RESTendl;
100
101 fAxionFlux = GetMetadata<TRestAxionSolarFlux>();
102
103 if (fGeneratorType == "solarFlux" && fAxionFlux == nullptr) {
104 if (!this->GetError()) this->SetError("The solar flux definition was not found.");
105 }
106
107 if (fAxionFlux) {
109
111 }
112
113 if (!fRandom) {
114 delete fRandom;
115 fRandom = nullptr;
116 }
117
118 fRandom = new TRandom3(fSeed);
119 fSeed = fRandom->TRandom::GetSeed();
120}
121
126 RESTDebug << "TRestAxionGeneratorProcess::ProcessEvent : " << fCounter << RESTendl;
128 fCounter++;
129
130 TVector3 axionPosition = TVector3(0, 0, -REST_Physics::AU);
131 TVector3 axionDirection = TVector3(0, 0, 1);
132 Double_t energy = 1;
133
134 // Random unit position
135 // We avoid the use of expensive trigonometric functions
136 Double_t x, y, r;
137 do {
138 x = 2 * (fRandom->Rndm() - 0.5);
139 y = 2 * (fRandom->Rndm() - 0.5);
140 r = x * x + y * y;
141 } while (r > 1 || r == 0);
142
143 r = TMath::Sqrt(r);
144
145 std::pair<Double_t, Double_t> p;
146 if (fGeneratorType == "solarFlux") {
148 energy = p.first;
149 Double_t radius = p.second;
150
151 axionPosition = TVector3(REST_Physics::solarRadius * radius * x / r,
152 REST_Physics::solarRadius * radius * y / r, -REST_Physics::AU);
153
154 axionDirection = -axionPosition.Unit();
155 }
156
157 if (fGeneratorType == "flat" || fGeneratorType == "plain") {
158 if (fEnergyRange.X() > 0 && fEnergyRange.Y() > 0)
159 energy = fRandom->Rndm() * (fEnergyRange.Y() - fEnergyRange.X()) + fEnergyRange.X();
160 else if (fEnergyRange.X() > 0)
161 energy = (1. - fEnergyRange.X()) * fRandom->Rndm() + fEnergyRange.X();
162 else {
163 RESTWarning << "Not a valid energy range was defined!" << RESTendl;
164 }
165 }
166
176 do {
177 x = 2 * (fRandom->Rndm() - 0.5);
178 y = 2 * (fRandom->Rndm() - 0.5);
179 r = x * x + y * y;
180 } while (r > 1 || r == 0);
181
182 r = TMath::Sqrt(r);
183
184 axionPosition = axionPosition + TVector3(fTargetRadius * x, fTargetRadius * y, 0) + fTargetPosition;
185
186 Double_t mass = fRandom->Uniform(fAxionMassRange.X(), fAxionMassRange.Y());
187
188 fOutputAxionEvent->SetEnergy(energy);
189 fOutputAxionEvent->SetPosition(axionPosition);
190 fOutputAxionEvent->SetDirection(axionDirection);
191 fOutputAxionEvent->SetMass(mass);
192
194 fOutputAxionEvent->PrintEvent();
195
196 return fOutputAxionEvent;
197}
198
204
205 RESTMetadata << "Generator type: " << fGeneratorType << RESTendl;
206 RESTMetadata << "Axion mass range: (" << fAxionMassRange.X() * units("eV") << ", "
207 << fAxionMassRange.Y() * units("eV") << ") eV" << RESTendl;
208 RESTMetadata << "Target radius: " << fTargetRadius * units("cm") << " cm" << RESTendl;
209 RESTMetadata << "Random seed: " << (UInt_t)fSeed << RESTendl;
210 RESTMetadata << "Energy range: (" << fEnergyRange.X() << ", " << fEnergyRange.Y() << ") keV" << RESTendl;
211 RESTMetadata << "Total flux: " << fTotalFlux << " cm-2 s-1" << RESTendl;
212
213 RESTMetadata << "+++++++++++++++++++++++++++++++++++++++++++++++++" << RESTendl;
214}
An event data class to define the parameters related to an axion particle.
A process to initialize the axion event (mainly through TRestAxionSolarFlux)
TVector3 fTargetPosition
The target position in mm with regards to the sun at (0,0,-AU).
TRestAxionGeneratorProcess()
Default constructor.
TRandom3 * fRandom
Internal process random generator.
Double_t fTotalFlux
Absolute solar flux (cm-2 s-1). Required for future calculations.
TVector2 fAxionMassRange
The axion mass range in keV.
void PrintMetadata() override
Prints out relevant metadata members.
void Initialize() override
Function to initialize input/output event members and define the section name.
Int_t fSeed
Seed used in random generator.
Double_t fTargetRadius
The target size in mm (or generator source extension) for the generator.
void InitProcess() override
Process initialization. Data members that require initialization just before start processing should ...
TVector2 fEnergyRange
It defines the energy range for the axion event generator. Default between 50eV and 10keV.
TRestAxionEvent * fOutputAxionEvent
A pointer to the specific TRestAxionEvent output.
Int_t fCounter
Used internally to define the event id.
TString fGeneratorType
The generator type (solarFlux/flat)
TRestAxionSolarFlux * fAxionFlux
A pointer to the TRestAxionSolarFlux metadata description.
TRestEvent * ProcessEvent(TRestEvent *eventInput) override
The main processing event function.
~TRestAxionGeneratorProcess()
Default destructor.
void Initialize()
It is required in order to load solar flux tables into memory.
virtual std::pair< Double_t, Double_t > GetRandomEnergyAndRadius(TVector2 eRange=TVector2(-1, -1), Double_t mass=0)=0
It defines how to generate Monte Carlo energy and radius values to reproduce the flux.
virtual Double_t IntegrateFluxInRange(TVector2 eRange=TVector2(-1, -1), Double_t mass=0)=0
It returns the integrated flux at earth in cm-2 s-1 for the given energy range.
bool fIsExternal
It defines if the process reads event data from an external source.
A base class for any REST event.
Definition: TRestEvent.h:38
virtual void PrintMetadata()
Implemented it in the derived metadata class to print out specific metadata information.
endl_t RESTendl
Termination flag object for TRestStringOutput.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
TRestStringOutput::REST_Verbose_Level GetVerboseLevel()
returns the verboselevel in type of REST_Verbose_Level enumerator
Bool_t GetError() const
It returns true if an error was identified by a derived metadata class.
void SetSectionName(std::string sName)
set the section name, clear the section content
void SetError(std::string message="", bool print=true, int maxPrint=5)
A metadata class may use this method to signal that something went wrong.
@ REST_Debug
+show the defined debug messages
constexpr double AU
Average Sun-Earth distance in m.
Definition: TRestPhysics.h:61