GeometryGenerator.cc
Go to the documentation of this file.
1 /*
2  GeometryGeneratorKG
3 
4  this is useful for CONEX profiles (maybe also for GH profile)
5  to set a shower axis (theta, phi)
6 */
7 
8 #include <utl/config.h>
9 
10 #include "GeometryGenerator.h"
11 
12 #include <fwk/CentralConfig.h>
13 #include <fwk/RandomEngineRegistry.h>
14 
15 #include <det/Detector.h>
16 
17 #include <evt/Event.h>
18 #include <evt/Header.h>
19 #include <evt/ShowerSimData.h>
20 
21 #include <sevt/SEvent.h>
22 #include <sevt/Header.h>
23 
24 #include <fevt/FEvent.h>
25 #include <fevt/Header.h>
26 #include <fevt/Eye.h>
27 #include <fevt/Telescope.h>
28 
29 #include <utl/AugerCoordinateSystem.h>
30 #include <utl/AugerUnits.h>
31 #include <utl/CoordinateSystem.h>
32 #include <utl/ErrorLogger.h>
33 #include <utl/RandomEngine.h>
34 #include <utl/Reader.h>
35 #include <utl/UTMPoint.h>
36 #include <utl/Vector.h>
37 #include <utl/Point.h>
38 
39 #include <sdet/SDetector.h>
40 
41 #include <fdet/FDetector.h>
42 #include <fdet/Eye.h>
43 #include <fdet/Telescope.h>
44 
45 #include <CLHEP/Random/RandFlat.h>
46 
47 #include <math.h>
48 #include <cstddef>
49 #include <iostream>
50 #include <string>
51 
52 using namespace utl;
53 using namespace fwk;
54 using namespace std;
55 using CLHEP::RandFlat;
56 
57 
59 
62  {
63  CentralConfig& cc = *CentralConfig::GetInstance();
64 
65  Branch topBranch = cc.GetTopBranch("GeometryGenerator");
66 
67  // check for azimuth sampling
68  // (CONEX profiles may be re-aligned in azimuth)
69  Branch bAzimuth = topBranch.GetChild("SampleAzimuth");
70  if (bAzimuth) {
71  fSampleAzimuth = true;
72  bAzimuth.GetChild("azimuthMin").GetData(fAzimuthMin);
73  bAzimuth.GetChild("azimuthMax").GetData(fAzimuthMax);
74  }
75 
76  // check for zenith sampling ------------------
77  Branch bZenith = topBranch.GetChild ("SampleZenith");
78  if (bZenith) {
79  fSampleZenith = true;
80  bZenith.GetChild("zenithMin").GetData(fZenithMin);
81  bZenith.GetChild("zenithMax").GetData(fZenithMax);
82  bZenith.GetChild("n_cos").GetData(fNcos);
83 
84  if (fZenithMin < 0 || fZenithMax < fZenithMin) {
85  ostringstream err;
86  err << "inconsistent zenith range: zenithMin = "
87  << fZenithMin / degree << ", zenithMax = " << fZenithMax / degree;
88  ERROR(err);
89  return eFailure;
90  }
91  if (fNcos != 0 && (fZenithMin <= 90*degree) != (fZenithMax <= 90*degree)) { // XOR
92  ostringstream err;
93  err << "Zenith range can be only down or up going in n_cos > 0: n_cos = " << fNcos << ", "
94  "zenithMin = " << fZenithMin / degree << ", zenithMax = " << fZenithMax / degree;
95  ERROR(err);
96  return eFailure;
97  }
98  if (fNcos != 0 && fNcos != 1 && fZenithMin > 90*degree) { // fNcos not 0 Nor 1 and upgoing
99  ostringstream err;
100  err << "n_cos must be 0 or 1 for up-going: n_cos = " << fNcos << ", "
101  "zenithMin = " << fZenithMin / degree << ", zenithMax = " << fZenithMax / degree;
102  ERROR(err);
103  return eFailure;
104  }
105  }
106 
107  fRandomEngine = &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector);
108 
109  return eSuccess;
110  }
111 
112 
114  GeometryGenerator::Run(evt::Event& event)
115  {
116  evt::ShowerSimData& shower = event.GetSimShower();
117 
118  if (shower.HasDirection()) {
119  ERROR("Nothing to do. Shower already has a direction. Check your ModuleSequence!");
120  return eFailure;
121  }
122 
123  ostringstream info;
124 
125  if (fSampleAzimuth) {
126  const double azimuth = GetPhi();
128  info << " set azimuth=" << azimuth/deg << " deg ";
129  }
130 
131  if (fSampleZenith) {
132  const double zenith = GetTheta();
134  info << " set zenith=" << zenith/deg << " deg ";
135  }
136 
137  INFO(info);
138  return eSuccess;
139  }
140 
141 
143  GeometryGenerator::Finish()
144  {
145  return eSuccess;
146  }
147 
148 
149  // GetTheta(): dice a zenith angle from isotropic flux on flat surface:
150  // dN/dcos(theta) ~ cos(theta)
151 
152  double
153  GeometryGenerator::GetTheta()
154  {
155  if (fZenithMin == fZenithMax)
156  return fZenithMax;
157 
158  const auto n1 = fNcos + 1;
159  const double t1 = pow(cos(fZenithMax), n1);
160  const double t2 = pow(cos(fZenithMin), n1);
161 
162  const double c = RandFlat::shoot(&fRandomEngine->GetEngine(), t1, t2);
163 
164  double theta;
165  if (fNcos == 0)
166  theta = acos(c);
167  else if (fNcos == 1) {
168  if (fZenithMin > 90*degree)
169  theta = acos(-sqrt(c));
170  else
171  theta = acos(sqrt(c));
172  } else
173  theta = acos(exp(log(c) / n1));
174 
175  return theta;
176  }
177 
178 
179  // GetPhi(): dice an azimuth angle
180 
181  double
182  GeometryGenerator::GetPhi()
183  {
184  if (fAzimuthMax == fAzimuthMin)
185  return fAzimuthMin;
186 
187  return RandFlat::shoot(&fRandomEngine->GetEngine(), fAzimuthMin, fAzimuthMax);
188  }
189 
190 }
bool HasDirection() const
Check initialization of shower geometry.
void SetGroundParticleCoordinateSystemAzimuth(const double azimuth)
Set the azimuth angle of the shower. Angle in x-y plane wrt. to the x axis (0 is from east)...
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
double pow(const double x, const unsigned int i)
Simple event generator.
constexpr double deg
Definition: AugerUnits.h:140
Interface class to access Shower Simulated parameters.
Definition: ShowerSimData.h:49
Class representing a document branch.
Definition: Branch.h:107
constexpr double degree
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
a second level trigger
Definition: XbT2.h:8
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
void SetGroundParticleCoordinateSystemZenith(const double zenith)
Set the zenith angle of the shower. Room angle between z-axis and direction from where the shower is ...
Main configuration utility.
Definition: CentralConfig.h:51
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.