RdZHAireSSimPreparator.cc
Go to the documentation of this file.
2 
3 // OffLine
4 #include <fwk/CentralConfig.h>
5 #include <fwk/LocalCoordinateSystem.h>
6 #include <fwk/CoordinateSystemRegistry.h>
7 #include <fwk/MagneticFieldModel.h>
8 #include <fwk/RandomEngineRegistry.h>
9 
10 // Atmosphere
11 #include <atm/ProfileResult.h>
12 #include <atm/InclinedAtmosphericProfile.h>
13 
14 #include <det/Detector.h>
15 #include <rdet/RDetector.h>
16 
17 #include <sdet/SDetector.h>
18 #include <sdet/SDetectorConstants.h>
19 
20 #include <evt/Event.h>
21 #include <evt/ShowerRecData.h>
22 #include <evt/ShowerSRecData.h>
23 #include <evt/ShowerRRecData.h>
24 #include <evt/Header.h>
25 
26 #include <revt/REvent.h>
27 #include <revt/Header.h>
28 
29 #include <utl/AugerCoordinateSystem.h>
30 #include <utl/Point.h>
31 #include <utl/UTMPoint.h>
32 #include <utl/ReferenceEllipsoid.h>
33 #include <utl/AugerUnits.h>
34 #include <utl/Reader.h>
35 #include <utl/TimeStamp.h>
36 #include <utl/UTCDateTime.h>
37 #include <utl/Line.h>
38 #include <utl/GeometryUtilities.h>
39 #include <utl/RadioGeometryUtilities.h>
40 #include <utl/System.h>
41 #include <utl/RandomEngine.h>
42 
43 #include <CLHEP/Random/RandFlat.h>
44 
45 //Root
46 #include <TFile.h>
47 #include <TTree.h>
48 
49 // C++
50 #include <fstream>
51 #include <sstream>
52 #include <ios>
53 #include <cmath>
54 #include <vector>
55 #include <boost/algorithm/string.hpp>
56 #include <boost/tokenizer.hpp>
57 #include <iomanip>
58 
59 using namespace evt;
60 using namespace fwk;
61 using namespace utl;
62 using namespace det;
63 using namespace std;
64 using std::string;
65 using std::vector;
66 using std::stringstream;
67 using std::ostringstream;
68 using std::ofstream;
69 using std::cout;
70 using std::setw;
71 using std::endl;
72 using std::ios_base;
73 
74 using CLHEP::RandFlat;
75 
76 
77 
78 
80 
83  {
84  // TEST log
85  fLogfile.open("RdZHAireSSimPreparator.log");
86  cout << "Opening Log File..." << endl;
87 
88  ostringstream info;
89  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdZHAireSSimPreparator");
90  topBranch.GetChild("WorkingDir").GetData(fWorkingDir);
91  topBranch.GetChild("StartRunNumber").GetData(fStartRunNumber);
92 
93  topBranch.GetChild("ModelMagField").GetData(fModelMagField);
94  topBranch.GetChild("MagFieldDec").GetData(fMagFieldDec);
95  topBranch.GetChild("MagFieldX").GetData(fMagFieldX);
96  topBranch.GetChild("MagFieldY").GetData(fMagFieldY);
97 
98  topBranch.GetChild("UseGeometry").GetData(fUseGeometry);
99  topBranch.GetChild("UseEnergy").GetData(fUseEnergy);
100  topBranch.GetChild("ThinningEnergy").GetData(fThinEnergy);
101  topBranch.GetChild("ThinningWFactor").GetData(fThinWFactor);
102 
103  // Fetching list of option sets
104  Branch simSets = topBranch.GetChild("SimulationSets");
105  for (Branch currentSet = simSets.GetFirstChild(); currentSet; currentSet = currentSet.GetNextSibling()) {
106  if (currentSet.GetName() == "simulation_set") {
107  Set set;
108  set.fNumberOfCards = VManager::FindComponent<int>("number_of_cards", currentSet.GetAttributes());
109  set.fPrimary = VManager::FindComponent<string>("primary", currentSet.GetAttributes());
110  fSimulationSets.push_back(std::move(set));
111  }
112  }
113 
114  topBranch.GetChild("GenerateCardsWithoutEvent").GetData(fGenerateCardsWithoutEvent);
115  topBranch.GetChild("NewZhaires").GetData(fNewZhaires);
116  if (fGenerateCardsWithoutEvent) {
117  Branch branch = topBranch.GetChild("GenerateCardsWithoutEventParameter");
118  branch.GetChild("eventTime").GetData(fTimeGeneratedEvent);
119  branch.GetChild("zenithLow").GetData(fZenithLowGeneratedEvent);
120  branch.GetChild("zenithHigh").GetData(fZenithHighGeneratedEvent);
121  branch.GetChild("azimuthLow").GetData(fAzimuthLowGeneratedEvent);
122  branch.GetChild("azimuthHigh").GetData(fAzimuthHighGeneratedEvent);
123  branch.GetChild("energyLow").GetData(fEnergyLowGeneratedEvent);
124  branch.GetChild("energyHigh").GetData(fEnergyHighGeneratedEvent);
125  branch.GetChild("energySlope").GetData(fEnergySlopeGeneratedEvent);
126  }
127 
128  topBranch.GetChild("MaxAntennaDistance").GetData(fMaxDistance);
129  const string distancetowhat = topBranch.GetChild("DistTo").Get<string>();
130  fUseCoreDist = (distancetowhat == "core");
131 
132  info.str("");
133  info << "\n-------RdZHAireSSimPreparator::Init\n"
134  " WorkingDir : "<< fWorkingDir << "\n"
135  " RUNNumber " << fStartRunNumber << "\n"
136  " MaxAntennaDistance : " << fMaxDistance;
137  INFO(info);
138 
139  fRandomEngine = &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector);
140 
141  return VModule::eSuccess;
142  }
143 
144 
146  RdZHAireSSimPreparator::Run(Event& event)
147  {
148  INFO("ZhairesSimPreparator::Run()");
149  TimeStamp time;
150  utl::Point core;
151  utl::Vector axis;
152  float energy = 0;
153  std::string eventId;
154  int rEventId = 0;
155  int runId = 0;
156 
157  if (fGenerateCardsWithoutEvent) {
158  cout << "[INFO] Generationg sim cards without event." << endl;
159  time = fTimeGeneratedEvent;
160  Detector& det = Detector::GetInstance();
161  det.Update(time); // In this mode detector is not yet updated
162 
163  // Get random core around a random stations
164  GenerateCoreAroundRandomSDStation(core);
165  const CoordinateSystemPtr coreCS = LocalCoordinateSystem::Create(core);
166 
167  // get random axis (arrival direction)
168  // draw azimuth uniformly
169  const double azi = RandFlat::shoot(&fRandomEngine->GetEngine(), fAzimuthLowGeneratedEvent, fAzimuthHighGeneratedEvent);
170  // draw zenith uniformly in sin(zenith) ** 2
171  const double low = Sqr(sin(fZenithLowGeneratedEvent));
172  const double high = Sqr(sin(fZenithHighGeneratedEvent));
173  const double zen = asin(sqrt(RandFlat::shoot(&fRandomEngine->GetEngine(), low, high)));
174  axis = utl::Vector(1, zen, azi, coreCS, utl::Vector::kSpherical);
175 
176  // draw energy from powerlay
177  if (fEnergyLowGeneratedEvent == fEnergyHighGeneratedEvent) {
178  energy = fEnergyLowGeneratedEvent;
179  } else {
180  energy = PowerLaw(fEnergyLowGeneratedEvent / utl::eV, fEnergyHighGeneratedEvent / utl::eV, fEnergySlopeGeneratedEvent) * utl::eV;
181  }
182 
183  // dummy data
184  eventId = "1";
185  rEventId = 1;
186  runId = 1;
187 
188  } else {
189  cout << "[INFO] Generationg sim cards from an event." << endl;
190  const revt::REvent& rEvent = event.GetREvent();
191  const revt::Header& rHead = rEvent.GetHeader();
192  const Header& head = event.GetHeader();
193 
194  fEventHeader = head.GetId();
195  time = head.GetTime();
196  eventId = head.GetId();
197  rEventId = rHead.GetId();
198  runId = rHead.GetRunNumber();
199 
200  const evt::ShowerRecData& shower = event.GetRecShower();
201  if (fUseGeometry == "SD") {
202  core = shower.GetSRecShower().GetCorePosition();
203  axis = shower.GetSRecShower().GetAxis();
204  } else if (fUseGeometry == "RD") {
205  core = shower.GetRRecShower().GetCorePosition();
206  axis = shower.GetRRecShower().GetAxis();
207  } else {
208  throw utl::AugerException("fUseGeometry has invalid value.");
209  }
210 
211  if (fUseEnergy == "SD")
212  energy = shower.GetSRecShower().GetEnergy();
213  else if (fUseEnergy == "RD")
214  energy = shower.GetRRecShower().GetParameter(revt::eCosmicRayEnergy);
215  else
216  throw utl::AugerException("fUseEnergy has invalid value.");
217  }
218 
219  if (fModelMagField) {
220  fMagFieldDec = fwk::MagneticFieldModel::instance().GetDeclination(core, time);
221  const Vector magFieldVector = fwk::MagneticFieldModel::instance().GetMagneticFieldVector(core, time);
223 
224  fMagFieldX = sqrt(Sqr(magFieldVector.GetX(coreCS)) + Sqr(magFieldVector.GetY(coreCS)));
225  fMagFieldY = -magFieldVector.GetZ(coreCS);
226  }
227 
228  string runNumber;
229  for (const auto& set : fSimulationSets) {
230 
231  const int numberOfCards = set.fNumberOfCards;
232  cout << "numberOfCards: " << numberOfCards << '\n' << set.fPrimary << endl;
233  for (int cardNumber = 0; cardNumber < numberOfCards; ++cardNumber) {
234  runNumber = AddZero(fStartRunNumber, 6);
235  CreateFiles(axis, energy, core, time, eventId, rEventId, runId, runNumber, set.fPrimary);
236  ++fStartRunNumber;
237  }
238  }
239 
240  return VModule::eSuccess;
241  }
242 
243 
244  // copied from reas
245  void
246  RdZHAireSSimPreparator::GenerateCoreAroundRandomSDStation(utl::Point& core)
247  {
248  // Draw core around random station in array. Station needs to have 6 neighbours
249  const sdet::SDetector& det = det::Detector::GetInstance().GetSDetector();
250  // get list of stations with full crown around
251  std::vector<int> stationList;
252  for (const auto& s : det.StationsRange()) {
253  if (s.IsInGrid() && s.GetCrown(1).size() == 6)
254  stationList.push_back(s.GetId());
255  }
256 
257  if (stationList.empty())
258  throw utl::AugerException("Asked to simulate around a random station but I get an empty list of stations.");
259 
260  // pick a random station
261  const int stationPos = int(RandFlat::shoot(&fRandomEngine->GetEngine(), 0, 1) * stationList.size());
262  const int stationId = stationList[stationPos];
263  const sdet::Station& stat = det.GetStation(stationId);
264  const utl::Point& center = stat.GetPosition();
265 
266  std::vector<utl::Point> crownStations;
267  const sdet::Station::StationIdCollection& stations = stat.GetCrown(1);
268  for (const auto& s : stations)
269  crownStations.push_back(det.GetStation(s).GetPosition());
270 
271  // Get random core around the picked stations
272  GenerateCoreAroundStation(center, crownStations, core);
273  }
274 
275 
276  // copied from reas
277  void
278  RdZHAireSSimPreparator::GenerateCoreAroundStation(const utl::Point& center, const std::vector<utl::Point>& crownStations,
279  utl::Point& core)
280  {
281  const ReferenceEllipsoid& e = ReferenceEllipsoid::GetWGS84();
282 
283  const UTMPoint utmPoint = UTMPoint(center, e);
284 
285  double eastingCore = 0;
286  double northingCore = 0;
287  bool in = false;
288  do {
289  eastingCore = utmPoint.GetEasting() + RandFlat::shoot(&fRandomEngine->GetEngine(), -0.5, 0.5) * 2000*meter;
290  northingCore = utmPoint.GetNorthing() + RandFlat::shoot(&fRandomEngine->GetEngine(), -0.5, 0.5) * 2000*meter;
291 
292  const UTMPoint utmPosition(northingCore, eastingCore, utmPoint.GetHeight(), utmPoint.GetZone(), utmPoint.GetBand(), e);
293  const Vector randomVector = utmPosition.GetPoint(center.GetCoordinateSystem()) - center;
294 
295  in = true;
296  for (auto const& stPoint : crownStations) {
297  const Vector crownStationVector = stPoint - center;
298  in = in && (crownStationVector * randomVector < 0.5*(crownStationVector*crownStationVector));
299  }
300  } while (!in);
301 
302  const UTMPoint newPosition(northingCore, eastingCore, utmPoint.GetHeight(), utmPoint.GetZone(), utmPoint.GetBand(), e);
303  core = newPosition.GetPoint();
304  }
305 
306 
307  // copied from Modules/FdSimulation/ProfileSimulatorOG/ProfileSimulator.cc
308  double
309  RdZHAireSSimPreparator::PowerLaw(const double min, const double max, const double index)
310  const
311  {
312  double x = 0;
313 
314  if (min > 0 && max > 0) {
315  const double randNo = RandFlat::shoot(&fRandomEngine->GetEngine(), 0, 1);
316  if (index != -1) {
317  x = pow(pow(min, index + 1) + randNo * (pow(max, index + 1) - pow(min, index + 1)),
318  1 / (index + 1));
319  } else {
320  x = min*pow(max/min, randNo);
321  }
322  } else
323  INFO("Impossible to dice!");
324 
325  return x;
326  }
327 
328 
329  void
330  RdZHAireSSimPreparator::CreateFiles(const utl::Vector& axis,
331  const float energy,
332  const utl::Point& core,
333  const TimeStamp time,
334  const std::string& /*eventId*/,
335  const int rEventId,
336  const int runId,
337  const std::string& runNumber,
338  const std::string& primaryType)
339  {
340  //Magnetic Field Parameters (SHOULD BE in CONFIGURATION XSD)
341  const double BIntensity = 0.23*gauss; //Gauss
342  const double MagInclination = -37.0*deg; //degrees
343  const double MagDeclination = 4.233*deg; //degrees
344 
345  fMagDeclination = MagDeclination;
346  fMagInclination = MagInclination;
347  fBIntensity = BIntensity;
348 
349  fLogfile << "fMagDeclination/deg=" << fMagDeclination/deg << " deg\n"
350  << "fMagInclination/deg=" << fMagInclination/deg << " deg\n"
351  << "fBIntensity/gauss=" << fBIntensity/gauss << " Gauss\n";
352 
353  const double rotationAngle = 90*deg - fMagDeclination;
354  cout << "RotationAngle=" << rotationAngle/deg << " deg" << endl;
355  // TEST logfile
356  fLogfile << "RotationAngle=" << rotationAngle/deg << " deg\n";
357  //
358 
359  // Station coordinates (CoreCS transformed to Aires system):
360  // The transformation is just a rotation around the z-axis of
361  // an angle 90deg-magdeclination=85.767deg.
362  // (The old transformation just disregarded the magnetic declination)
363  // Z transformation is valid for input (fieldtool.inp) only!!!
364  //**double xantaires[maxnantennas],yantaires[maxnantennas],zantaires[maxnantennas];
365  vector<double> xantaires;
366  vector<double> yantaires;
367  vector<double> zantaires;
368 
369  UTMPoint utmcore(core, ReferenceEllipsoid::GetWGS84());
370 
371  //Get detector
372  Detector& det = Detector::GetInstance();
373 
374  // Coordinate systems
376  // get reference coordinate system of detector (usually PampaAmarilla)
377  const CoordinateSystemPtr& referenceCS = det.GetReferenceCoordinateSystem();
378  //const ReferenceEllipsoid& elliposewgs84 = ReferenceEllipsoid::GetWGS84();
379 
380  // Simulation Ground altitude is set to core altitude
381  const double corealtitude = utmcore.GetHeight();
382  fLogfile << "corealtitude=" << corealtitude/m << " m\n";
383 
384  cout << "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"
385  "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
386 
387  // inputs
388  const double energyev = energy; // input from function
389  // Get reconstructed zenith and azimuth angles
390  //const utl::Vector axis = axis;
391  const double zenithdeg = axis.GetTheta(coreCS)/degree;
392  // Azimuthal angle in AIRES coordinate system (Azim_Auger-90deg+Magdeclination)
393  const double azimuthdeg = AugerAzimuthToZHAireS(axis.GetPhi(coreCS), fMagDeclination)/degree;
394 
395  // TEST log
396  fLogfile << "Xcore(m) \t" << core.GetX(referenceCS)/m << "\n"
397  "Ycore(m) \t" << core.GetY(referenceCS)/m << "\n"
398  "Zcore(m) \t" << core.GetZ(referenceCS)/m << "\n"
399  "Event# \t" << rEventId << "\n"
400  "RunNumber \t" << runId << "\n"
401  "E0 \t" << energyev << " eV" << "\n"
402  "Zenith \t" << zenithdeg << " deg" << "\n"
403  "azimuth \t" << azimuthdeg << " deg" << "\n"
404  "########################\n"
405  "Auger Azimuth: " << axis.GetPhi(coreCS)/degree << " deg, Aires Azimuth: " << azimuthdeg << " deg\n";
406  //
407 
408  // cout with data that goes into the .def file
409  // use also passed values from function
410  cout << "========= Info going into the .def file\n"
411  "Xcore(m) \t" << core.GetX(referenceCS)/m << "\n"
412  "Ycore(m) \t" << core.GetY(referenceCS)/m << "\n"
413  "Zcore(m) \t" << core.GetZ(referenceCS)/m << "\n"
414  "GPSsec \t" << int(time.GetGPSSecond()) << "\n"
415  "GPSns \t" << int(time.GetGPSNanoSecond()) << "\n"
416  "Event# \t" << rEventId << "\n"
417  "RunNumber\t" << runId << "\n"
418  "E0 \t" << energyev << " eV\n"
419  "Zenith \t" << zenithdeg << " deg\n"
420  "azimuth \t" << azimuthdeg << " deg\n"
421  "\n";
422 
423  // output files
424  ostringstream airesfilename;
425  airesfilename << "event" << rEventId << "-run" << runNumber << ".inp";
426 
427  ostringstream deffilename;
428  deffilename << "event" << rEventId << "-run" << runNumber << ".def";
429 
430  // Loop over radio stations
431  int antennaInFile = 0;
432 
433  const sdet::SDetector& sdetector = det.GetSDetector();
434 
435  /* only iterate over regular 1500 m grid array.
436  Use sdetector.StationsBegin()
437  and sdetector.StationsEnd() for all stations or set gridtype:
438  eAny, eStandard, eInfill750, eInfill433 */
439 
440  for (const auto& s : sdetector.StationsRange()) {
441 
442  // Get station position
443  const utl::Point& position = s.GetPosition();
444 
445  if (fUseCoreDist) {
446  // does the chosen coordinate system influence the result?
447  const Vector vecAntenna = position - core;
448  if (vecAntenna.GetR(coreCS) > fMaxDistance )
449  continue;
450  } else {
451  const double axisDist =
452  RadioGeometryUtilities::GetDistanceToAxis(axis, core, position);
453  if (axisDist > fMaxDistance)
454  continue;
455  }
456 
457  //Get station coordinates on coreCS system from RDetector position
458  const double xcorecs = position.GetX(coreCS)/m;
459  const double ycorecs = position.GetY(coreCS)/m;
460  const double zcorecs = position.GetZ(coreCS)/m;
461 
462  const double vcorecs[] = { xcorecs, ycorecs, zcorecs };
463 
464  cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
465  " ANTENNA ACCEPTED!!!" << endl;
466 
467  // TEST log
468  fLogfile << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
469  << " ANTENNA ACCEPTED!!!\n";
470  //
471 
472  // Station coordinates (CoreCS transformed to Aires system):
473  // The transformation is just a rotation around the z-axis of
474  // an angle of 90deg-magdeclination=85.767deg.
475  // (The old transformation just disregarded the magnetic declination)
476  // From CoreCS to AiresCS the rotation angle is negative
477  // From AiresCS to CoreCS the rotation angle is positive
478  // Z transformation is valid for input (fieldtool.inp) only!!!
479  double vaires[3] = { 0 };
480  Rotatez(-rotationAngle, vcorecs, vaires);
481 
482  //**xantaires[antennaInFile] = vaires[0];
483  //**yantaires[antennaInFile] = vaires[1];
484  //**zantaires[antennaInFile] = vaires[2]; // valid for fieldtool.inp only!!!
485  xantaires.push_back(vaires[0]);
486  yantaires.push_back(vaires[1]);
487  zantaires.push_back(vaires[2]);
488 
489  cout << "CoreCS: x=" << xcorecs << " y=" << ycorecs << " z=" << zcorecs << "\n"
490  << "AiresCS: x=" << xantaires[antennaInFile] << " y=" << yantaires[antennaInFile] << " z=" << zantaires[antennaInFile] << endl;
491 
492  // TEST log
493  fLogfile << "CoreCS: x=" << xcorecs << " y=" << ycorecs << " z=" << zcorecs << "\n"
494  "AiresCS: x=" << xantaires[antennaInFile] << " y=" << yantaires[antennaInFile] << " z=" << zantaires[antennaInFile] << endl;
495  //
496 
497  //cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
498  ++antennaInFile;
499  }
500 
501  cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
502  "AntennaInFile :" << antennaInFile << "\n"
503  "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"
504  "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
505 
506  // TEST log
507  fLogfile << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
508  "AntennaInFile :" << antennaInFile << "\n"
509  "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"
510  "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n";
511  //
512 
513 
514  {
515  // write .def file
516  ofstream deffile((fWorkingDir + deffilename.str()).c_str());
517  deffile << "# This File sets core position, evt# and GPS time for ZHAireS simulations.\n"
518  "# ZHAires simulations are independant of core X and Y coordinates and time,\n"
519  "# but depend on ground altitude.\n"
520  "# The core Z coordinate is read from the .sry file\n"
521  "#\n"
522  "# This file can be manually edited to set the desired core position and time\n"
523  "# Core X and Y should be in the PampaAmarilla coordinate system\n"
524  "# Generated by RdZhaireSSimPreparator\n"
525  "#\n"
526  // Core position is saved in Pampa Amarilla system
527  "Xcore(m) \t" << core.GetX(referenceCS)/m << "\n"
528  "Ycore(m) \t" << core.GetY(referenceCS)/m << "\n"
529  "Zcore(m) \t" << core.GetZ(referenceCS)/m << "\n"
530  "GPSsec \t" << int(time.GetGPSSecond()) << "\n"
531  "GPSns \t" << int(time.GetGPSNanoSecond()) << "\n"
532  "Event# \t" << rEventId << "\n"
533  "RunNumber\t" << runId << '\n';
534  }
535 
536  fLogfile << " zeCore.GetX(referenceCS)=" << core.GetX(referenceCS) << " in m: "<< core.GetX(referenceCS)/m << "\n"
537  " zeCore.GetY(referenceCS)=" << core.GetY(referenceCS) << " in m: "<< core.GetY(referenceCS)/m << "\n"
538  " zeCore.GetZ(referenceCS)=" << core.GetZ(referenceCS) << " in m: "<< core.GetZ(referenceCS)/m << '\n';
539 
540  {
541  // write Aires .inp file
542  const int seed = (unsigned int)(RandFlat::shoot(&fRandomEngine->GetEngine(), 0, 1) * 999999);
543  ofstream airesfile((fWorkingDir + airesfilename.str()).c_str());
544  airesfile << "TaskName event" << rEventId << "-run" << runNumber << "\n"
545  "\n"
546  // Fixing proton as primary for now
547  // use passed "Primary" here
548  "PrimaryParticle " << primaryType << "\n"
549  "PrimaryEnergy " << energyev << " eV\n"
550  "PrimaryZenAngle " << zenithdeg << " deg\n"
551  "PrimaryAzimAngle " << azimuthdeg << " deg Magnetic\n"
552  "\n"
553  // Geomagnetic Field
554  "GeomagneticField " << fBIntensity/gauss << " Gs " << fMagInclination/degree << " deg " << fMagDeclination/degree << " deg\n"
555  "\n"
556  "GroundAltitude " << corealtitude/m << " m\n"
557  "TotalShowers 1\n"
558  "RunsPerProcess Infinite\n"
559  "ShowersPerRun 1\n"
560  "RandomSeed 0." << seed << "\n"
561  "ElectronCutEnergy 80 keV\n"
562  "ElectronRoughCut 80 keV\n"
563  "GammaCutEnergy 80 keV\n"
564  "GammaRoughCut 80 keV\n"
565  "\n"
566  "InjectionAltitude 100 km\n";
567  if(fNewZhaires) airesfile << "ForceModelName SYBILL231\n";
568  airesfile << "\n"
569  "ThinningEnergy " << fThinEnergy << " Relative\n"
570  "ThinningWFactor " << fThinWFactor << "\n"
571  "\n"
572  "#Output Handling\n"
573  "ObservingLevels 510\n"
574  "PerShowerData Full\n"
575  "SaveNotInFile lgtpcles All\n"
576  "SaveNotInFile grdpcles All\n"
577  "ExportPerShower\n"
578  "\n"
579  "#ZHAireS\n"
580  "ZHAireS On\n"
581  "FresnelTime On\n"
582  "TimeDomainBin 0.3 ns\n"
583  "\n";
584  for (int i = 0; i < antennaInFile; ++i)
585  {
586  if(fNewZhaires) airesfile << "AddAntenna\t" << i+1 << " " << xantaires[i] << " " << yantaires[i] << " " << zantaires[i] << '\n';
587  else airesfile << "AddAntenna\t" << xantaires[i] << " " << yantaires[i] << " " << zantaires[i] << '\n';
588  }
589  }
590  }
591 
592 
594  RdZHAireSSimPreparator::Finish()
595  {
596  fLogfile.close();
597  return VModule::eSuccess;
598  }
599 
600 
601  // Extract Event Number from the Event ID string
602  string
603  RdZHAireSSimPreparator::GetEventNumber(const std::string& eventId)
604  {
605  boost::tokenizer<boost::char_separator<char>> tok(eventId, boost::char_separator<char>("_"));
606  const vector<string> zetokens(tok.begin(), tok.end());
607  return (zetokens.size() > 1) ? zetokens[3] : eventId;
608  }
609 
610 
611  string
612  RdZHAireSSimPreparator::AddZero(const int runID, const int numberofdigit)
613  {
614  const string pad = "%0" + to_string(numberofdigit) + "i";
615  return (boost::format(pad) % runID).str();
616  }
617 
618 }
Branch GetTopBranch() const
Definition: Branch.cc:63
void Update(const utl::TimeStamp &time, const bool invData=true, const bool invComp=true, const bool forceRadio=false)
Update detector: deletes currently constructed stations and sets new time.
Definition: Detector.cc:179
constexpr double eV
Definition: AugerUnits.h:185
const StationIdCollection & GetCrown(const int level) const
Returns a list of station id&#39;s in the crown. If the argument is 0, it returns the station id...
utl::Vector GetAxis() const
Returns vector of the shower axis.
const double degree
constexpr T Sqr(const T &x)
Point object.
Definition: Point.h:32
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
Definition: BasicVector.h:254
Detector description interface for Station-related data.
Base class for all exceptions used in the auger offline code.
Interface class to access Shower Reconstructed parameters.
Definition: ShowerRecData.h:33
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
double GetR(const CoordinateSystemPtr &coordinateSystem) const
radius r in spherical coordinates coordinates (distance to origin)
Definition: BasicVector.h:257
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Definition: BasicVector.h:248
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
CoordinateSystemPtr GetCoordinateSystem() const
Get the coordinate system of the current internal representation.
Definition: BasicVector.h:234
int GetZone() const
Get the zone.
Definition: UTMPoint.h:215
const double meter
Definition: GalacticUnits.h:29
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
char GetBand() const
Get the band.
Definition: UTMPoint.h:218
static double GetDeclination(const utl::Point &position, const utl::TimeStamp &time)
returns declination in radians
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)
double GetNorthing() const
Get the northing.
Definition: UTMPoint.h:206
ShowerRRecData & GetRRecShower()
ShowerSRecData & GetSRecShower()
const double high[npar]
Definition: UnivRec.h:78
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
const utl::TimeStamp & GetTime() const
Definition: Event/Header.h:33
utl::Point GetPosition() const
Tank position.
constexpr double deg
Definition: AugerUnits.h:140
T Get() const
Definition: Branch.h:271
Branch GetNextSibling() const
Get next sibling of this branch.
Definition: Branch.cc:284
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
#define max(a, b)
Class representing a document branch.
Definition: Branch.h:107
const double gauss
Definition: GalacticUnits.h:41
constexpr double s
Definition: AugerUnits.h:163
Reference ellipsoids for UTM transformations.
double GetHeight() const
Get the height.
Definition: UTMPoint.h:212
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
std::vector< int > StationIdCollection
static MagneticFieldModel & instance()
Header & GetHeader()
access to REvent Header
Definition: REvent.h:239
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
const sdet::SDetector & GetSDetector() const
Definition: Detector.cc:119
static utl::Vector GetMagneticFieldVector(const utl::Point &position, const utl::TimeStamp &time)
returns the magnetic field at a specific place at a specific time
double GetEasting() const
Get the easting.
Definition: UTMPoint.h:209
const utl::Vector & GetAxis() const
static const CSpherical kSpherical
Definition: BasicVector.h:335
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
double GetEnergy() const
const std::string & GetId() const
Get the event identifier.
Definition: Event/Header.h:31
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
const double low[npar]
Definition: UnivRec.h:77
int GetRunNumber() const
Event id in the run (Start at zero at the beginning of each run) /provided by the daq...
Definition: REvent/Header.h:22
unsigned long GetGPSSecond() const
GPS second.
Definition: TimeStamp.h:124
double GetGPSNanoSecond() const
GPS nanosecond.
Definition: TimeStamp.h:127
Header file holding the RD Event Trigger class definition (based on SD)
Definition: REvent/Header.h:14
utl::CoordinateSystemPtr GetReferenceCoordinateSystem() const
Get the reference coordinate system used for analysis (usually PampaAmarilla for Auger) ...
Definition: Detector.h:141
Vector object.
Definition: Vector.h:30
Detector description interface for SDetector-related data.
Definition: SDetector.h:42
const utl::Point & GetCorePosition() const
utl::Point GetCorePosition() const
returns pointer of the position vector of the core in the reference coor system
std::string fPrimary
double GetParameter(const Parameter i) const
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: SDetector.cc:192
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
constexpr double m
Definition: AugerUnits.h:121
int GetId() const
Definition: REvent/Header.h:21
Global event header.
Definition: Event/Header.h:27

, generated on Tue Sep 26 2023.