9 #include <io/CorsikaShowerFile.h>
10 #include <io/EVAFile.h>
11 #include <io/EVAIOException.h>
13 #include <evt/Event.h>
14 #include <evt/ShowerSimData.h>
15 #include <evt/SimRadioPulse.h>
16 #include <evt/RadioSimulation.h>
17 #include <evt/DefaultShowerGeometryProducer.h>
19 #include <utl/ErrorLogger.h>
20 #include <utl/AugerUnits.h>
21 #include <utl/PhysicalConstants.h>
22 #include <utl/Vector.h>
34 using std::ostringstream;
47 Open(filename, filemode, b);
55 const size_t ext_size = extension.size();
56 return filename.substr(filename.size() - ext_size, ext_size) == extension;
64 if (filemode !=
eRead) {
66 msg <<
"Cannot open file " << filename
67 <<
" - EVA files are read-only";
80 msg <<
"Cannot open file " << filename
91 const string header_name = ReadQuantity<string>();
92 const string header_start_MGMR = header_name.substr(0, 10);
93 const string header_start_EVA = header_name.substr(0, 9);
94 if (header_name !=
"MGMR-File" && header_start_MGMR !=
"MGMR-File-" &&
95 header_name !=
"MGRM-File" && header_start_EVA !=
"EVA-File-") {
97 msg <<
"Can't recognize the header of the file '" << header_name
98 <<
"' as a known version of an EVA or MGMR file.";
101 if (header_name ==
"MGRM-File" || header_name ==
"MGMR-File") {
104 }
else if (header_start_EVA ==
"EVA-File-") {
111 const bool is_mgmr =
filetype ==
"mgmr";
112 const bool is_eva =
filetype ==
"eva";
117 msg <<
"The file extension and the specified file-type in the file do not match.";
121 const string header_filename = ReadQuantity<string>();
127 detector_level = ReadQuantity<double>(
"detector_level_(a.s.l.)",
"m",
false, is_eva, -1) *
meter;
130 core_position[1] = ReadQuantity<double>(
"shower_core_y",
"m") *
meter;
131 core_position[2] = ReadQuantity<double>(
"shower_core_z",
"m") *
meter;
136 ReadQuantity<double>(
"trace_length",
"us",
false, is_mgmr &&
version_string ==
"0.0");
148 event_id = ReadQuantity<int>(
"event_id",
"",
true);
149 gps_time_seconds = ReadQuantity<int>(
"gps_time_seconds",
"s",
true, is_mgmr);
152 gps_time_seconds = ReadQuantity<int>(
"gpssec",
"",
false, is_eva,
gps_time_seconds);
153 gps_time_nanoseconds = ReadQuantity<double>(
"gpsnsec",
"",
false, is_eva,
gps_time_nanoseconds);
154 refcoord[0] = ReadQuantity<double>(
"refcoordx",
"",
false, is_eva, 0.0) *
meter;
155 refcoord[1] = ReadQuantity<double>(
"refcoordy",
"",
false, is_eva, 0.0) *
meter;
156 refcoord[2] = ReadQuantity<double>(
"refcoordz",
"",
false, is_eva, 0.0) *
meter;
166 while (header.find(
"#") == string::npos)
170 const bool is_eva = (
filetype ==
"eva");
176 input_file >> sub_fname >> rel_pos[0] >> rel_pos[1] >> rel_pos[2];
180 double dummy_trace_length;
183 double time_binning_EVA = -1;
185 int dummy_atmospheric_model;
186 input_file >> time_binning_EVA >> dummy_atmospheric_model;
197 "Error while reading the table containing the information about the secondary '.trace' files. "
198 "Arrived at the end of the file but expecting more data.";
218 msg <<
"Cannot open file " << filename
219 <<
" - filename does not end on .mgmr, .mgrm or .eva";
242 msg <<
"Invalid position " << fpos <<
". This file contains only one event.";
254 ERROR(
"Event not cleared - has SimShower. Cannot read EVA.");
269 ostringstream header_id;
275 event.GetHeader().SetId(header_id.str());
293 getline(sub_file, header);
303 if (!sub_file.eof()) {
304 const streampos fpos = sub_file.tellg();
305 sub_file >> time_bin >> e_field[0] >> e_field[1] >> e_field[2];
311 if (fpos == sub_file.tellg()) {
313 "Error while reading values from .trace file. (Maybe it contains NaNs?)";
329 WARNING(
"Event not cleared - has RadioSimulation");
342 const bool is_mgmr =
filetype ==
"mgmr";
344 for (vector<SubfileInfo>::const_iterator it =
sub_file_list.begin();
347 const string& full_filename = it->filestring;
349 ifstream sub_file(full_filename.c_str());
352 ERROR (
"Could not read header from " + full_filename +
".");
357 double e_field[3] = { 0 };
360 ERROR(
"Could not read line from " + full_filename +
361 ". The file must contain at least one sample.");
365 const double xdist = it->position[0];
366 const double ydist = it->position[1];
367 const double zdist = it->position[2];
375 const double time_binning_EVA = it->binning_EVA;
399 string msg(
"Cannot read from a closed file.");
417 const string msg =
"Cannot write to EVA/MGMR-File - read-only file";
426 const string msg =
"Not implemented. There is only one event per file.";
virtual void Open(const std::string &filename, const io::Mode filemode=eRead, utl::Branch *const b=nullptr)
void SetStartTime(const double starttime)
std::string primary_particle_str
void MakeRadioSimulation()
Make the RadioSimulation.
std::vector< SubfileInfo > sub_file_list
Data structure for simulated Radio pulses.
bool HasSimShower() const
Data structure for a radio simulation (including several SimRadioPulses)
bool ReadShowerData(evt::Event &)
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)...
void CheckFileReadability(const std::string &filename, const Mode filemode) const
bool HasRadioSimulation() const
Check initialization of the RadioSimulation.
utl::SVector< 3, double > Vector3D
A TimeStamp holds GPS second and nanosecond for some event.
void SetEventNumber(const int eventnum)
Set the event number of the RadioSimulation.
Interface class to access Shower Simulated parameters.
bool ReadSubfileHeader(std::ifstream &)
bool corsika_pancakefile_included
Class representing a document branch.
Status
Return code for seek operation.
bool corsika_longfile_included
Base for exceptions in the EVA reader.
void SetEventTime(const utl::TimeStamp &t)
Set the event time of the RadioSimulation.
bool CheckFileExtension(const std::string &filename, const std::string &extension) const
RadioSimulation & GetRadioSimulation()
Get the radio simulation data.
void SetCoreCoordinates(const double x, const double y, const double z)
Set the core position coordinates of the RadioSimulation.
std::string version_string
void SetEnergy(const double theEnergy)
Set the energy of the shower primary particle.
std::string file_extension
void ReadBaseFileQuantities()
#define WARNING(message)
Macro for logging warning messages.
void AddSimRadioPulse(const SimRadioPulse &rp)
Add a radio pulse to the RadioSimulation.
double magnetic_field_zenith
void OpenFile(const std::string &filename)
void SetPrimaryParticle(const int type)
Set the type of the shower primary particle.
virtual Status Read(evt::Event &event)
read current event advance cursor by 1
double magnetic_field_azimuth
void SetGroundParticleCoordinateSystemZenith(const double zenith)
Set the zenith angle of the shower. Room angle between z-axis and direction from where the shower is ...
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)
bool ReadRadioSimData(evt::Event &)
virtual Status FindEvent(const unsigned int eventId)
seek Event id set cursor there
utl::Vector3D core_position
void PushBack(const T &value)
Insert a single value at the end.
unsigned int events_remaining
#define ERROR(message)
Macro for logging error messages.
virtual void Write(const evt::Event &event)
bool ReadSubfileLine(std::ifstream &, double &, double *const)
const utl::TraceV3D & GetEfieldTimeSeries() const
Get the Trace of the simulated electric field.
bool askaryan_effect_included
double gps_time_nanoseconds
constexpr double electronvolt
virtual io::Status GotoPosition(const unsigned int pos)
goto by position in the file