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>
11 #include <atm/ProfileResult.h>
12 #include <atm/InclinedAtmosphericProfile.h>
14 #include <det/Detector.h>
15 #include <rdet/RDetector.h>
17 #include <sdet/SDetector.h>
18 #include <sdet/SDetectorConstants.h>
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>
26 #include <revt/REvent.h>
27 #include <revt/Header.h>
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>
38 #include <utl/GeometryUtilities.h>
39 #include <utl/RadioGeometryUtilities.h>
40 #include <utl/System.h>
41 #include <utl/RandomEngine.h>
43 #include <CLHEP/Random/RandFlat.h>
55 #include <boost/algorithm/string.hpp>
56 #include <boost/tokenizer.hpp>
66 using std::stringstream;
67 using std::ostringstream;
74 using CLHEP::RandFlat;
85 fLogfile.open(
"RdZHAireSSimPreparator.log");
86 cout <<
"Opening Log File..." << endl;
89 Branch topBranch = CentralConfig::GetInstance()->
GetTopBranch(
"RdZHAireSSimPreparator");
106 if (currentSet.GetName() ==
"simulation_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));
114 topBranch.
GetChild(
"GenerateCardsWithoutEvent").
GetData(fGenerateCardsWithoutEvent);
116 if (fGenerateCardsWithoutEvent) {
117 Branch branch = topBranch.
GetChild(
"GenerateCardsWithoutEventParameter");
129 const string distancetowhat = topBranch.
GetChild(
"DistTo").
Get<
string>();
130 fUseCoreDist = (distancetowhat ==
"core");
133 info <<
"\n-------RdZHAireSSimPreparator::Init\n"
134 " WorkingDir : "<< fWorkingDir <<
"\n"
135 " RUNNumber " << fStartRunNumber <<
"\n"
136 " MaxAntennaDistance : " << fMaxDistance;
139 fRandomEngine = &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector);
146 RdZHAireSSimPreparator::Run(
Event& event)
148 INFO(
"ZhairesSimPreparator::Run()");
157 if (fGenerateCardsWithoutEvent) {
158 cout <<
"[INFO] Generationg sim cards without event." << endl;
159 time = fTimeGeneratedEvent;
160 Detector& det = Detector::GetInstance();
164 GenerateCoreAroundRandomSDStation(core);
169 const double azi = RandFlat::shoot(&fRandomEngine->GetEngine(), fAzimuthLowGeneratedEvent, fAzimuthHighGeneratedEvent);
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)));
177 if (fEnergyLowGeneratedEvent == fEnergyHighGeneratedEvent) {
178 energy = fEnergyLowGeneratedEvent;
180 energy = PowerLaw(fEnergyLowGeneratedEvent /
utl::eV, fEnergyHighGeneratedEvent /
utl::eV, fEnergySlopeGeneratedEvent) *
utl::eV;
189 cout <<
"[INFO] Generationg sim cards from an event." << endl;
192 const Header& head =
event.GetHeader();
194 fEventHeader = head.
GetId();
196 eventId = head.
GetId();
197 rEventId = rHead.
GetId();
201 if (fUseGeometry ==
"SD") {
204 }
else if (fUseGeometry ==
"RD") {
211 if (fUseEnergy ==
"SD")
213 else if (fUseEnergy ==
"RD")
219 if (fModelMagField) {
224 fMagFieldX =
sqrt(
Sqr(magFieldVector.
GetX(coreCS)) +
Sqr(magFieldVector.
GetY(coreCS)));
225 fMagFieldY = -magFieldVector.
GetZ(coreCS);
229 for (
const auto& set : fSimulationSets) {
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);
246 RdZHAireSSimPreparator::GenerateCoreAroundRandomSDStation(
utl::Point& core)
249 const sdet::SDetector& det = det::Detector::GetInstance().GetSDetector();
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());
257 if (stationList.empty())
258 throw utl::AugerException(
"Asked to simulate around a random station but I get an empty list of stations.");
261 const int stationPos = int(RandFlat::shoot(&fRandomEngine->GetEngine(), 0, 1) * stationList.size());
262 const int stationId = stationList[stationPos];
266 std::vector<utl::Point> crownStations;
268 for (
const auto&
s : stations)
272 GenerateCoreAroundStation(center, crownStations, core);
278 RdZHAireSSimPreparator::GenerateCoreAroundStation(
const utl::Point& center,
const std::vector<utl::Point>& crownStations,
285 double eastingCore = 0;
286 double northingCore = 0;
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;
296 for (
auto const& stPoint : crownStations) {
297 const Vector crownStationVector = stPoint - center;
298 in = in && (crownStationVector * randomVector < 0.5*(crownStationVector*crownStationVector));
303 core = newPosition.GetPoint();
309 RdZHAireSSimPreparator::PowerLaw(
const double min,
const double max,
const double index)
314 if (min > 0 && max > 0) {
315 const double randNo = RandFlat::shoot(&fRandomEngine->GetEngine(), 0, 1);
317 x =
pow(
pow(min, index + 1) + randNo * (
pow(max, index + 1) -
pow(min, index + 1)),
320 x = min*
pow(max/min, randNo);
323 INFO(
"Impossible to dice!");
337 const std::string& runNumber,
338 const std::string& primaryType)
341 const double BIntensity = 0.23*
gauss;
342 const double MagInclination = -37.0*
deg;
343 const double MagDeclination = 4.233*
deg;
345 fMagDeclination = MagDeclination;
346 fMagInclination = MagInclination;
347 fBIntensity = BIntensity;
349 fLogfile <<
"fMagDeclination/deg=" << fMagDeclination/
deg <<
" deg\n"
350 <<
"fMagInclination/deg=" << fMagInclination/
deg <<
" deg\n"
351 <<
"fBIntensity/gauss=" << fBIntensity/
gauss <<
" Gauss\n";
353 const double rotationAngle = 90*
deg - fMagDeclination;
354 cout <<
"RotationAngle=" << rotationAngle/
deg <<
" deg" << endl;
356 fLogfile <<
"RotationAngle=" << rotationAngle/
deg <<
" deg\n";
365 vector<double> xantaires;
366 vector<double> yantaires;
367 vector<double> zantaires;
369 UTMPoint utmcore(core, ReferenceEllipsoid::GetWGS84());
372 Detector& det = Detector::GetInstance();
381 const double corealtitude = utmcore.
GetHeight();
382 fLogfile <<
"corealtitude=" << corealtitude/
m <<
" m\n";
384 cout <<
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"
385 "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
388 const double energyev = energy;
393 const double azimuthdeg = AugerAzimuthToZHAireS(axis.
GetPhi(coreCS), fMagDeclination)/
degree;
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";
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"
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"
424 ostringstream airesfilename;
425 airesfilename <<
"event" << rEventId <<
"-run" << runNumber <<
".inp";
427 ostringstream deffilename;
428 deffilename <<
"event" << rEventId <<
"-run" << runNumber <<
".def";
431 int antennaInFile = 0;
440 for (
const auto&
s : sdetector.StationsRange()) {
447 const Vector vecAntenna = position - core;
448 if (vecAntenna.
GetR(coreCS) > fMaxDistance )
451 const double axisDist =
452 RadioGeometryUtilities::GetDistanceToAxis(axis, core, position);
453 if (axisDist > fMaxDistance)
458 const double xcorecs = position.
GetX(coreCS)/
m;
459 const double ycorecs = position.
GetY(coreCS)/
m;
460 const double zcorecs = position.
GetZ(coreCS)/
m;
462 const double vcorecs[] = { xcorecs, ycorecs, zcorecs };
464 cout <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
465 " ANTENNA ACCEPTED!!!" << endl;
468 fLogfile <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
469 <<
" ANTENNA ACCEPTED!!!\n";
479 double vaires[3] = { 0 };
480 Rotatez(-rotationAngle, vcorecs, vaires);
485 xantaires.push_back(vaires[0]);
486 yantaires.push_back(vaires[1]);
487 zantaires.push_back(vaires[2]);
489 cout <<
"CoreCS: x=" << xcorecs <<
" y=" << ycorecs <<
" z=" << zcorecs <<
"\n"
490 <<
"AiresCS: x=" << xantaires[antennaInFile] <<
" y=" << yantaires[antennaInFile] <<
" z=" << zantaires[antennaInFile] << endl;
493 fLogfile <<
"CoreCS: x=" << xcorecs <<
" y=" << ycorecs <<
" z=" << zcorecs <<
"\n"
494 "AiresCS: x=" << xantaires[antennaInFile] <<
" y=" << yantaires[antennaInFile] <<
" z=" << zantaires[antennaInFile] << endl;
501 cout <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
502 "AntennaInFile :" << antennaInFile <<
"\n"
503 "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"
504 "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
507 fLogfile <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
508 "AntennaInFile :" << antennaInFile <<
"\n"
509 "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"
510 "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n";
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"
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"
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"
532 "Event# \t" << rEventId <<
"\n"
533 "RunNumber\t" << runId <<
'\n';
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';
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"
548 "PrimaryParticle " << primaryType <<
"\n"
549 "PrimaryEnergy " << energyev <<
" eV\n"
550 "PrimaryZenAngle " << zenithdeg <<
" deg\n"
551 "PrimaryAzimAngle " << azimuthdeg <<
" deg Magnetic\n"
554 "GeomagneticField " << fBIntensity/
gauss <<
" Gs " << fMagInclination/
degree <<
" deg " << fMagDeclination/
degree <<
" deg\n"
556 "GroundAltitude " << corealtitude/
m <<
" m\n"
558 "RunsPerProcess Infinite\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"
566 "InjectionAltitude 100 km\n";
567 if(fNewZhaires) airesfile <<
"ForceModelName SYBILL231\n";
569 "ThinningEnergy " << fThinEnergy <<
" Relative\n"
570 "ThinningWFactor " << fThinWFactor <<
"\n"
573 "ObservingLevels 510\n"
574 "PerShowerData Full\n"
575 "SaveNotInFile lgtpcles All\n"
576 "SaveNotInFile grdpcles All\n"
582 "TimeDomainBin 0.3 ns\n"
584 for (
int i = 0; i < antennaInFile; ++i)
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';
594 RdZHAireSSimPreparator::Finish()
603 RdZHAireSSimPreparator::GetEventNumber(
const std::string& eventId)
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;
612 RdZHAireSSimPreparator::AddZero(
const int runID,
const int numberofdigit)
614 const string pad =
"%0" + to_string(numberofdigit) +
"i";
615 return (boost::format(pad) % runID).str();
Branch GetTopBranch() const
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.
const StationIdCollection & GetCrown(const int level) const
Returns a list of station id's in the crown. If the argument is 0, it returns the station id...
utl::Vector GetAxis() const
Returns vector of the shower axis.
constexpr T Sqr(const T &x)
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
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.
Interface class to access to the Radio part of an event.
double GetR(const CoordinateSystemPtr &coordinateSystem) const
radius r in spherical coordinates coordinates (distance to origin)
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Class to hold and convert a point in geodetic coordinates.
CoordinateSystemPtr GetCoordinateSystem() const
Get the coordinate system of the current internal representation.
int GetZone() const
Get the zone.
#define INFO(message)
Macro for logging informational messages.
char GetBand() const
Get the band.
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.
double pow(const double x, const unsigned int i)
double GetNorthing() const
Get the northing.
ShowerRRecData & GetRRecShower()
ShowerSRecData & GetSRecShower()
A TimeStamp holds GPS second and nanosecond for some event.
utl::Point GetPosition() const
Tank position.
Branch GetNextSibling() const
Get next sibling of this branch.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
Reference ellipsoids for UTM transformations.
double GetHeight() const
Get the height.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
std::vector< int > StationIdCollection
static MagneticFieldModel & instance()
Header & GetHeader()
access to REvent Header
Top of the hierarchy of the detector description interface.
const sdet::SDetector & GetSDetector() const
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.
const utl::Vector & GetAxis() const
static const CSpherical kSpherical
void GetData(bool &b) const
Overloads of the GetData member template function.
double GetY(const CoordinateSystemPtr &coordinateSystem) const
ResultFlag
Flag returned by module methods to the RunController.
unsigned long GetGPSSecond() const
GPS second.
double GetGPSNanoSecond() const
GPS nanosecond.
utl::CoordinateSystemPtr GetReferenceCoordinateSystem() const
Get the reference coordinate system used for analysis (usually PampaAmarilla for Auger) ...
Detector description interface for SDetector-related data.
const utl::Point & GetCorePosition() const
utl::Point GetCorePosition() const
returns pointer of the position vector of the core in the reference coor system
double GetParameter(const Parameter i) const
Branch GetFirstChild() const
Get first child of this Branch.
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
const Station & GetStation(const int stationId) const
Get station by Station Id.
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.