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"
67 using namespace std;
68 
70 
75 
80 
85  SetSectionName(this->ClassName());
86  SetLibraryVersion(LIBRARY_VERSION);
87 
88  fOutputAxionEvent = new TRestAxionEvent();
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) {
108  fAxionFlux->Initialize();
109 
110  fTotalFlux = fAxionFlux->IntegrateFluxInRange(fEnergyRange);
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;
127  fOutputAxionEvent->SetID(fCounter);
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") {
147  p = fAxionFlux->GetRandomEnergyAndRadius(fEnergyRange);
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 
193  if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug)
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)
TRestAxionGeneratorProcess()
Default constructor.
void PrintMetadata() override
Prints out relevant metadata members.
void Initialize() override
Function to initialize input/output event members and define the section name.
void InitProcess() override
Process initialization. Data members that require initialization just before start processing should ...
TRestEvent * ProcessEvent(TRestEvent *eventInput) override
The main processing event function.
~TRestAxionGeneratorProcess()
Default destructor.
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.
@ REST_Debug
+show the defined debug messages
constexpr double AU
Average Sun-Earth distance in m.
Definition: TRestPhysics.h:61