2 #include <evt/ShowerSimData.h>
3 #include <evt/SimRadioPulse.h>
4 #include <evt/RadioSimulation.h>
5 #include <evt/DefaultShowerGeometryProducer.h>
7 #include <fwk/CentralConfig.h>
8 #include <fwk/LocalCoordinateSystem.h>
9 #include <fwk/CoordinateSystemRegistry.h>
11 #include <utl/AugerCoordinateSystem.h>
13 #include <io/ZHAireSFile.h>
14 #include <io/ZHAireSIOException.h>
16 #include <utl/AugerUnits.h>
17 #include <utl/ErrorLogger.h>
18 #include <utl/PhysicalConstants.h>
19 #include <utl/TimeStamp.h>
20 #include <utl/config.h>
21 #include <utl/Particle.h>
23 #include <utl/CoordinateSystem.h>
24 #include <utl/Point.h>
25 #include <utl/ReferenceEllipsoid.h>
26 #include <utl/UTMPoint.h>
27 #include <utl/System.h>
29 #include <det/Detector.h>
39 #include <boost/filesystem/path.hpp>
42 # include <io/AiresUtilities.h>
43 # include <io/AiresShowerFile.h>
51 namespace fs = boost::filesystem;
56 ZHAireSFile::~ZHAireSFile()
62 delete fAiresShowerFile;
67 ZHAireSFile::ZHAireSFile(
const std::string& fileName,
const Mode mode,
utl::Branch*
const b) :
71 logfile.open(
"ZHAireSFile.log");
72 cout <<
"Opening Log File..." << endl;
74 Open(fileName, mode, b);
82 std::string ourFileName = fileName;
85 char tmpHostNameString[256] = {
'\0' };
86 gethostname(tmpHostNameString, 256);
89 if (fileName.size() < 8 ||
90 (fileName.substr(fileName.size() - 8, 8) !=
".zhaires" &&
91 fileName.substr(fileName.size() - 7, 7) !=
".tar.gz")) {
93 msg <<
"Cannot open file " << fileName <<
" - file name does not end on .zhaires";
100 msg <<
"Cannot open file " << fileName <<
" - ZHAireS files are read-only";
105 stringstream directory;
107 if (fileName.substr(fileName.size() - 7, 7) ==
".tar.gz") {
111 stringstream command;
112 command <<
"rm -rf " << directory.str();
116 msg <<
"Extracting " << fileName <<
" to directory " << directory.str() <<
" ...";
119 command <<
"mkdir 2>/dev/null ./TempExtractionDir";
122 command <<
"mkdir 2>/dev/null " << directory.str();
127 string flag = (fileName.substr(fileName.size() - 7, 7) ==
".tar.gz") ?
"xfz":
"xfj";
129 command <<
"tar " << flag <<
" " << fileName <<
" -C " << directory.str();
133 string entryname = fileName;
135 while ((pos = entryname.find(
"/")) != std::string::npos) {
136 entryname.erase(0, pos + 1);
138 ourFileName = directory.str() +
"/" + entryname.substr(0,entryname.size()-7) +
".zhaires";
142 fZHAireSin =
new ifstream(ourFileName.c_str());
145 msg <<
"Cannot open file " << ourFileName <<
" - ERROR";
151 info <<
"ZHAireS simulation " << ourFileName <<
'\n';
154 logfile <<
"ZHAireS simulation " << ourFileName <<
'\n';
156 const string basename = ourFileName.substr(0, ourFileName.size() - 8);
157 const size_t pathlength = ourFileName.find_last_of(
"/");
161 if (pathlength >= ourFileName.size()) {
165 pathname = ourFileName.substr(0, pathlength) +
"/";
166 simname = basename.substr(pathname.size(),basename.size()-pathlength);
169 const string sryFileName = basename +
".sry";
170 const string alternative_sryFileName = directory.str() +
"/" + basename.substr(2, basename.size()+1) +
".sry";
171 fsry =
new ifstream(sryFileName.c_str());
173 fsry =
new ifstream(alternative_sryFileName.c_str());
175 msg <<
"Cannot open Aires summary file " << sryFileName
176 <<
"\tLooking for .sry file in " << alternative_sryFileName;
180 msg <<
"No .sry file found in " << alternative_sryFileName;
186 const string defFileName = basename +
".def";
187 const string alternative_defFileName = directory.str() +
"/" + basename.substr(2, basename.size()+1) +
".def";
188 fdef =
new ifstream(defFileName.c_str());
190 fdef =
new ifstream(alternative_defFileName.c_str());
192 msg <<
"Cannot open event auger definitions file (.def) " << defFileName
193 <<
"\tLooking for .def file in " << alternative_defFileName;
197 msg <<
"No .def file found in " << alternative_defFileName;
216 if (fAiresShowerFile) {
217 fAiresShowerFile->Close();
218 delete fAiresShowerFile;
219 fAiresShowerFile =
nullptr;
224 stringstream command;
237 INFO(
"Reading ZHAireSFile");
240 ERROR(
"Event not cleared - has SimShower. Cannot read ZHAireSFile.");
244 double xcorepampa = 0;
245 double ycorepampa = 0;
246 double zcorepampa = 0;
249 double corealtitude = 0;
250 double primaryenergy = 0;
251 double showerzenith = 0;
254 double showerazimuthaires = 0;
255 double showerazimuthauger = 0;
257 string airesfilepath;
258 string airesparamfile;
259 int eventnumber = -1;
269 while (
fdef->peek() ==
'#')
270 fdef->getline(lineBuf, 1024);
291 cout <<
"===========================================\n"
292 "Data read from .def file:\n"
293 "xcorepampa(m): " << xcorepampa <<
" "
294 "ycorepampa(m): " << ycorepampa <<
" "
295 "zcorepampa(m): " << zcorepampa <<
" "
296 "GPSs: " << gpssecs <<
" GPSns: " << gpsnanosecs <<
" "
297 "evt#: " << eventnumber <<
" "
298 "runnumber: " << runnumber << endl;
302 logfile <<
"===========================================\n"
303 <<
"Data read from .def file:\n"
304 "xcorepampa(m): " << xcorepampa <<
" "
305 "ycorepampa(m): " << ycorepampa <<
" "
306 "zcorepampa(m): " << zcorepampa <<
" "
307 "GPSs: " << gpssecs <<
" GPSns: " << gpsnanosecs <<
" "
308 "evt#: " << eventnumber <<
" "
309 "runnumber: " << runnumber << endl;
312 const long sec = gpssecs;
313 const long nsec = gpsnanosecs;
316 logfile <<
"long sec:" << sec <<
" long nsec:" << nsec <<
"\n"
317 " Reading TimeStamp....\n"
325 int Nlines = 0, NlinesE = 0, Nlinesalt = 0, NlinesBdeclination = 0, NlinesXmax = 0;
327 char teststringangle[] =
"angle:", teststringenergy[] =
"energy:";
328 char teststringalt[] =
"altitude:", ReadString[80], testBdeclination[] =
"D:";
329 char teststringXmax[] =
"(g/cm2):";
331 while (
fsry->good() && (Nlines != 2 || NlinesE != 1 || Nlinesalt != 2 || NlinesXmax != 2)) {
335 if (strcmp(teststringangle, ReadString) == 0) {
339 showerzenith = value*
deg;
341 logfile <<
"showerzenith=" << showerzenith <<
" rad=" << showerzenith/deg <<
" deg" << endl;
342 }
else if (Nlines == 2) {
343 showerazimuthaires = value*
deg;
345 logfile <<
"showerazimuthaires=" << showerazimuthaires <<
" rad=" << showerazimuthaires/deg <<
" deg" << endl;
348 if (strcmp(teststringenergy, ReadString) == 0) {
354 if (strcmp(ReadString,
"eV") == 0)
355 primaryenergy = value*
eV;
356 else if (strcmp(ReadString,
"keV") == 0)
357 primaryenergy = value*
keV;
358 else if (strcmp(ReadString,
"MeV") == 0)
359 primaryenergy = value*
MeV;
360 else if (strcmp(ReadString,
"GeV") == 0)
361 primaryenergy = value*
GeV;
362 else if (strcmp(ReadString,
"TeV") == 0)
363 primaryenergy = value*
TeV;
364 else if (strcmp(ReadString,
"PeV") == 0)
365 primaryenergy = value*
PeV;
366 else if (strcmp(ReadString,
"EeV") == 0)
367 primaryenergy = value*
EeV;
370 msg <<
"Unrecognized unit:" << ReadString <<
" in sry file - ERROR";
375 logfile <<
"primaryenergy=" << primaryenergy/
eV <<
" eV" << endl;
379 if (strcmp(teststringalt, ReadString) == 0) {
381 if (Nlinesalt == 2) {
385 if (strcmp(ReadString,
"km") == 0)
386 corealtitude = value*
km;
387 else if (strcmp(ReadString,
"m") == 0)
388 corealtitude = value*
m;
389 else if (strcmp(ReadString,
"cm") == 0)
390 corealtitude = value*
cm;
393 msg <<
"Unrecognized unit:" << ReadString <<
" in sry file - ERROR";
398 logfile <<
"corealtitude=" << corealtitude/
m <<
" m" << endl;
401 if (strcmp(testBdeclination, ReadString) == 0) {
402 ++NlinesBdeclination;
404 if (NlinesBdeclination == 1) {
411 if (strcmp(teststringXmax, ReadString) == 0) {
413 if (NlinesXmax == 2) {
419 cout <<
"===========================================\n"
420 "Data read from .sry file:\n"
421 "Zenith: " << showerzenith/
deg <<
" deg, "
422 "Aires Azimuth: " << showerazimuthaires/
deg <<
" deg, "
423 "E0: " << primaryenergy/
eV <<
" eV, "
424 "Ground Altitude: " << corealtitude/
m <<
" m, "
426 "Xmax: " << Xmax/
g*
cm2 <<
" g/cm2" << endl;
430 logfile <<
"===========================================\n"
431 "Data read from .sry file:\n"
432 "Zenith: " << showerzenith/
deg <<
" deg, "
433 "Aires Azimuth: " << showerazimuthaires/
deg <<
" deg, "
434 "E0: " << primaryenergy/
eV <<
" eV, "
435 "Ground Altitude: " << corealtitude/
m <<
" m, "
437 "Xmax: " << Xmax/
g*
cm2 <<
" g/cm2" << endl;
442 #warning RU: this is inconsistent with how this is handled in corsika
445 const double RotationAngle = 90*
deg - MagDeclination;
448 logfile <<
"MagDeclination=" << MagDeclination <<
" rad=" << MagDeclination/
deg <<
" deg\n"
449 "RotationAngle=" << RotationAngle <<
" rad=" << RotationAngle/
deg <<
" deg" << endl;
454 WARNING (
"Event not cleared - has RadioSimulation");
473 cout <<
"Azimuth angle: Aires: " << showerazimuthaires/
deg <<
" deg "
474 "Auger: " << showerazimuthauger/
deg <<
" deg" << endl;
476 logfile <<
"((((((((((((((((((\n"
477 "Azimuth angle: Aires: " << showerazimuthaires/
deg <<
" deg "
478 "Auger: " << showerazimuthauger/
deg <<
" deg\n"
479 "Reading ShowerSimData...\n"
489 "((((((((((((((((((" << endl;
505 ostringstream tmpout;
506 tmpout <<
"ZHAireS_r" << runnumber <<
"_e" << eventnumber;
507 event.GetHeader().SetId(tmpout.str());
511 const Point core(xcorepampa, ycorepampa, zcorepampa, referenceCS);
515 cout <<
"===========================================\n"
516 "CORE altitude: utmcore.GetHeight()=" << utmcore.
GetHeight() <<
" "
517 "corealtitude (from aires .sry file)=" << corealtitude/
m << endl;
520 logfile <<
"===========================================\n"
521 "CORE altitude: utmcore.GetHeight()=" << utmcore.
GetHeight() <<
" "
522 "corealtitude (from aires .sry file)=" << corealtitude/
m << endl;
527 cout <<
"===========================================\n"
528 "Core coords (Pampa) sent to radiosim.SetCoreCoordinates: "
529 << xcorepampa <<
", " << ycorepampa <<
", " << zcorepampa << endl;
532 logfile <<
"===========================================\n"
533 "Core coords (Pampa) sent to radiosim.SetCoreCoordinates (m): "
534 << xcorepampa/
m <<
", " << ycorepampa/
m <<
", " << zcorepampa/
m << endl;
555 int showern, antn, lastant;
557 double antxaires, antyaires, antzINJ;
558 double antxcorecs, antycorecs, antzcorecs;
562 double exvmzhaires, eyvmzhaires, ezvmzhaires, exvmcorecs, eyvmcorecs, ezvmcorecs;
572 msg <<
"Cannot read from ZHAireS File";
604 exvmzhaires *= (
V/
m);
605 eyvmzhaires *= (
V/
m);
606 ezvmzhaires *= (
V/
m);
608 double firsttime = time, secondtime;
609 bool readsecondtime =
false;
626 double vantaires[3] = { antxaires, antyaires, antzINJ };
627 double vantcorecs[3];
628 Rotatez(RotationAngle, vantaires, vantcorecs);
629 antxcorecs = vantcorecs[0];
630 antycorecs = vantcorecs[1];
634 #warning readZHAireS assumes injection altitude of 100km (should be read from.sry later).
635 antalt = (100000 - antzINJ)*
m;
637 antzcorecs = antalt - corealtitude;
640 cout <<
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n"
641 "Antenna " << antn <<
" "
642 "position in zhairesCS (m): x=" << antxaires/
m <<
" y=" << antyaires/
m <<
" z=" << antzINJ/
m <<
" "
643 "(antalt=" << antalt/
m <<
")\n"
644 "Antenna " << antn <<
" "
645 "position in CoreCS (m): x=" << antxcorecs/
m <<
" y=" << antycorecs/
m <<
" z=" << antzcorecs/
m << endl;
649 logfile <<
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n"
650 "Antenna " << antn <<
" "
651 "position in zhairesCS (m): x=" << antxaires/
m <<
" y=" << antyaires/
m <<
" z=" << antzINJ/
m <<
" "
652 "(antalt=" << antalt/
m <<
")\n"
653 "Antenna " << antn <<
" "
654 "position in CoreCS (m): x=" << antxcorecs/
m <<
" y=" << antycorecs/
m <<
" z=" << antzcorecs/
m << endl;
664 #warning RU: this must be checked:
667 while (lastant == antn &&
fZHAireSin->good()) {
672 cout <<
"StartTime:" << time/
nanosecond <<
" ns" << endl;
679 double veaires[3] = { exvmzhaires, eyvmzhaires, ezvmzhaires};
681 Rotatez(RotationAngle, veaires, vecorecs);
682 exvmcorecs = vecorecs[0];
683 eyvmcorecs = vecorecs[1];
685 ezvmcorecs = -vecorecs[2];
688 efield[0] = exvmcorecs;
689 efield[1] = eyvmcorecs;
690 efield[2] = ezvmcorecs;
695 logfile <<
"First time bin ZHAireSCS E (V/m): ("
696 << exvmzhaires/(
V/
m) <<
"," << eyvmzhaires/(
V/
m) <<
"," << ezvmzhaires/(
V/
m) <<
")\n"
697 "First time bin CoreCS E (V/m): ("
698 << exvmcorecs/(
V/
m) <<
"," << eyvmcorecs/(
V/
m) <<
"," << ezvmcorecs/(
V/
m) <<
")" << endl;
703 double veaires[3] = { exvmzhaires, eyvmzhaires, ezvmzhaires};
705 Rotatez(RotationAngle, veaires, vecorecs);
712 efield[0] = exvmcorecs;
713 efield[1] = eyvmcorecs;
714 efield[2] = ezvmcorecs;
738 exvmzhaires *= (
V/
m);
739 eyvmzhaires *= (
V/
m);
740 ezvmzhaires *= (
V/
m);
742 if (!readsecondtime) {
744 binning = secondtime - firsttime;
745 readsecondtime =
true;
747 if (!first && (lastant != antn || !
fZHAireSin->good())) {
750 double veaires[3] = { exvmzhaires, eyvmzhaires, ezvmzhaires };
752 Rotatez(RotationAngle, veaires, vecorecs);
757 exvmcorecs = vecorecs[0];
758 eyvmcorecs = vecorecs[1];
760 ezvmcorecs = -vecorecs[2];
763 efield[0] = exvmcorecs;
764 efield[1] = eyvmcorecs;
765 efield[2] = ezvmcorecs;
784 logfile <<
"((((((((((((((((((\n"
785 "Azimuth angle: Aires: " << showerazimuthaires/
deg <<
" deg "
786 "Auger: " << showerazimuthauger/
deg <<
" deg\n"
787 "Reading ShowerSimData...\n"
797 "((((((((((((((((((\n"
799 "Reading RadioSimulation....\n"
808 "((((((((((((((((((\n"
810 "Reading RadioSimulation pulses...." << endl;
815 logfile <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
816 "pulse #" << i <<
"\n"
825 "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
836 const string msg =
"Cannot write to ZHAireS File - read-only file";
int GetPrimaryParticle() const
Get the type of the shower primary particle.
double GetBinning() const
Get the sampling time scale.
void SetStartTime(const double starttime)
const SimRadioPulse & GetSimPulseByIndex(const int index)
void System(const char *const command, const bool throwOnError, const bool notify)
int GetEventNumber() const
Get the event number of the RadioSimulation.
void MakeRadioSimulation()
Make the RadioSimulation.
Class to hold and convert a point in geodetic coordinates.
Data structure for simulated Radio pulses.
bool HasSimShower() const
Data structure for a radio simulation (including several SimRadioPulses)
void SetBinning(const double samplingtime)
Mode
Available open modes.
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.
bool HasRadioSimulation() const
Check initialization of the RadioSimulation.
utl::SVector< 3, double > Vector3D
double ZHAireSAzimuthToAuger(const double airesAzimuth)
Returns the azimuth rotated from AIRES's system to Auger standard.
utl::Point GetLocation() const
void SetRunNumber(const int runnum)
Set the run number of the RadioSimulation.
A TimeStamp holds GPS second and nanosecond for some event.
void SetEventNumber(const int eventnum)
Set the event number of the RadioSimulation.
void SetLocalCoordinateSystem(utl::CoordinateSystemPtr localCS) const
Interface class to access Shower Simulated parameters.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
int GetShowerNumber() const
Get the number of the shower in the file.
Class representing a document branch.
Status
Return code for seek operation.
double GetMagneticFieldStrength() const
Get the absolute strength of the Earth's magnetic field used in CORSIKA/REAS simulation.
static void Rotatez(const double theta, const double vi[], double vf[])
utl::Point GetCorePosition() const
Get the core position of the RadioSimulation as a utl::Point.
double GetHeight() const
Get the height.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
void SetEventTime(const utl::TimeStamp &t)
Set the event time of the RadioSimulation.
bool HasCorePosition() const
RadioSimulation & GetRadioSimulation()
Get the radio simulation data.
constexpr double nanosecond
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
get local coordinate system anchored at the core position
void SetCoreCoordinates(const double x, const double y, const double z)
Set the core position coordinates of the RadioSimulation.
static const ReferenceEllipsoid & GetWGS84()
Get the auger standard ellipsoid: wgs84.
void SetEnergy(const double theEnergy)
Set the energy of the shower primary particle.
double GetEnergy() const
Get the energy of the shower primary particle.
#define WARNING(message)
Macro for logging warning messages.
void AddSimRadioPulse(const SimRadioPulse &rp)
Add a radio pulse to the RadioSimulation.
int GetNEvents() override
const utl::TimeStamp & GetEventTime() const
Get the event time of the RadioSimulation.
double GetY(const CoordinateSystemPtr &coordinateSystem) const
void SetPrimaryParticle(const int type)
Set the type of the shower primary particle.
double GetMagneticFieldDeclination() const
Get the declination of the Earth's magnetic field used in CORSIKA/REAS simulation.
unsigned long GetGPSSecond() const
GPS second.
void SetGroundParticleCoordinateSystemZenith(const double zenith)
Set the zenith angle of the shower. Room angle between z-axis and direction from where the shower is ...
double GetGPSNanoSecond() const
GPS nanosecond.
double GetMagneticFieldInclination() const
Get the inclination of the Earth's magnetic field used in CORSIKA/REAS simulation.
std::string GetShowerRunId() const
Get the run id for the shower.
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
void SetRelativeCoordinates(double northing, double easting, double height)
void SetShowerNumber(const int sid)
void MakeTimeStamp(const utl::TimeStamp &ts)
Make the TimeStamp of the shower.
int GetRunNumber() const
Get the run number of the RadioSimulation.
Base for exceptions in the ZHAireS reader.
Status GotoPosition(const unsigned int position) override
goto by position in the file
Status FindEvent(const unsigned int eventId) override
seek Event id set cursor there
long GetNumPulses() const
Get the number of radio pulses contained in the RadioSimulation.
Status Read(evt::Event &event) override
read current event advance cursor by 1
void Write(const evt::Event &event) override
double GetGroundParticleCoordinateSystemZenith() const
Get the zenith angle of the shower. Room angle between z-axis and direction from where the shower is ...
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
void SetShowerRunId(const std::string srid)
void PushBack(const T &value)
Insert a single value at the end.
#define ERROR(message)
Macro for logging error messages.
double GetGroundParticleCoordinateSystemAzimuth() const
Get the azimuth angle of the shower. Angle in x-y plane wrt. to the x axis (0 is from east)...
const utl::TraceV3D & GetEfieldTimeSeries() const
Get the Trace of the simulated electric field.
void Open(const std::string &fileName, const Mode mode=eRead, utl::Branch *const b=nullptr) override
unsigned int fCurrentPosition
double GetStartTime() const
Get the timestamp of the first sample.
std::ifstream * fZHAireSin