11 #include <evt/Event.h>
12 #include <evt/ShowerSimData.h>
13 #include <evt/SimRadioPulse.h>
14 #include <evt/RadioSimulation.h>
16 #include <fwk/CoordinateSystemRegistry.h>
18 #include <io/CorsikaUtilities.h>
19 #include <io/CorsikaShowerFile.h>
20 #include <io/REASH5File.h>
21 #include <io/REASIOException.h>
23 #include <utl/AugerUnits.h>
24 #include <utl/ErrorLogger.h>
25 #include <utl/PhysicalConstants.h>
26 #include <utl/TimeStamp.h>
27 #include <utl/CoordinateSystem.h>
28 #include <utl/Point.h>
29 #include <utl/ReferenceEllipsoid.h>
30 #include <utl/UTMPoint.h>
31 #include <utl/UTCDateTime.h>
32 #include <utl/System.h>
35 #include <det/Detector.h>
37 #include <boost/lexical_cast.hpp>
59 using std::stringstream;
60 using std::ostringstream;
61 using std::istringstream;
79 REASH5File::AddObserver(hid_t loc_id,
const char*
const name,
void*
const operator_data)
87 H5Gget_objinfo(loc_id, name,
false, &statbuf);
88 if (statbuf.type == H5G_DATASET) {
89 hid_t dataset_id = H5Dopen1(loc_id, name);
90 DataSet dataset(dataset_id);
91 Attribute position = dataset.openAttribute(
"position");
92 DataType type = position.getDataType();
93 double tmp[3] = { 0 };
94 position.read(type, &tmp);
100 double zpos = tmp[2];
106 DataSpace dataspace = dataset.getSpace();
110 hsize_t dims_out[2] = { 0 };
111 dataspace.getSimpleExtentDims(dims_out,
nullptr);
112 double data_out[dims_out[0]][dims_out[1]];
114 dataset.read(data_out, PredType::NATIVE_DOUBLE, H5S_ALL, H5S_ALL);
116 const double timestamp = data_out[0][0];
121 double finalefield[3];
122 for (
unsigned int j = 0; j < dims_out[0]; ++j) {
125 efield[0] = data_out[j][1] * conv;
126 efield[1] = data_out[j][2] * conv;
127 efield[2] = data_out[j][3] * conv;
132 rotefield[2] = efield[2];
135 finalefield[0] = -rotefield[1];
136 finalefield[1] = rotefield[0];
137 finalefield[2] = rotefield[2];
143 (data_out[dims_out[0] - 1][0] * second - currpulse.
GetStartTime()) /
144 double(currtimeseries.
GetSize() - 1)
153 REASH5File::REASH5File(
const std::string& fileName,
const Mode mode,
utl::Branch*
const b) :
156 Open(fileName, mode, b);
171 const std::string ourFileName = fileName;
175 msg <<
"Cannot open file " << fileName <<
" - REAS-H5 files are read-only";
180 fReasH5 = H5File(ourFileName.c_str(), H5F_ACC_RDONLY);
189 info <<
"(Co)REAS simulation " << ourFileName <<
'\n';
192 const string basename = ourFileName.substr(0, ourFileName.size() - 5);
193 const size_t pathlength = ourFileName.find_last_of(
"/");
197 if (pathlength >= ourFileName.size()) {
201 pathname = ourFileName.substr(0, pathlength) +
"/";
202 simname = basename.substr(pathname.size(), basename.size() - pathlength);
206 const unsigned int bufsize = 1024;
207 char dirbuf[bufsize];
208 if (!getcwd(dirbuf, bufsize)) {
210 msg <<
"Buffer too small for reading out path.";
250 INFO(
"Reading in CoREASH5File");
253 ERROR(
"Event not cleared - has SimShower. Cannot read REASFile.");
257 long selectedcorsikashower = 1;
262 H5::Group group_coreas(
fReasH5.openGroup(
"/CoREAS"));
264 double corecoordinateverticalinreassim = ReadAttribute<double>(group_coreas,
"CoreCoordinateVertical");
265 corecoordinateverticalinreassim *=
utl::cm;
266 double corecoordinatenorthinreassim = ReadAttribute<double>(group_coreas,
"CoreCoordinateNorth");
267 corecoordinatenorthinreassim *=
utl::cm;
268 double corecoordinatewestinreassim = ReadAttribute<double>(group_coreas,
"CoreCoordinateWest");
269 corecoordinatewestinreassim *=
utl::cm;
271 const string corsikafilepath = ReadAttribute<const char*>(group_coreas,
"CorsikaFilePath");
272 const string corsikaparamfile = ReadAttribute<const char*>(group_coreas,
"CorsikaParameterFile");
274 const int runnumber = ReadAttribute<int>(group_coreas,
"RunNumber");
275 const int eventnumber = ReadAttribute<int>(group_coreas,
"EventNumber");
277 unsigned int gpssecs = ReadAttribute<int>(group_coreas,
"GPSSecs");
278 unsigned int gpsnanosecs = ReadAttribute<int>(group_coreas,
"GPSNanoSecs");
280 double corecoordinateeastinaugercs = ReadAttribute<double>(group_coreas,
"CoreEastingOffline");
282 double corecoordinatenorthinaugercs = ReadAttribute<double>(group_coreas,
"CoreNorthingOffline");
284 double corecoordinateverticalinaugercs = ReadAttribute<double>(group_coreas,
"CoreVerticalOffline");
285 corecoordinateverticalinaugercs *=
utl::meter;
288 if (corecoordinatenorthinreassim || corecoordinatewestinreassim) {
289 const string msg =
"(Co)REAS local coordinate system has to be anchored at (0,0,z) "
290 "but the x and/or y coordinate is not 0";
295 double magneticfielddeclination = ReadAttribute<double>(group_coreas,
"RotationAngleForMagfieldDeclination");
296 magneticfielddeclination *=
degree;
298 double distanceofshowermax = ReadAttribute<double>(group_coreas,
"DistanceOfShowerMaximum");
299 distanceofshowermax *=
utl::cm;
302 ostringstream tmpout;
303 tmpout <<
"(Co)REAS_r" << runnumber <<
"_e" << eventnumber;
304 event.GetHeader().SetId(tmpout.str());
306 string offlineCoordinateSystem(
"Reference");
307 if (group_coreas.attrExists(
"OfflineCoordinateSystem")) {
308 offlineCoordinateSystem = ReadAttribute<const char*>(group_coreas,
"OfflineCoordinateSystem");
311 det::Detector::GetInstance().GetReferenceCoordinateSystem() :
314 const Point core(corecoordinateeastinaugercs, corecoordinatenorthinaugercs,
315 corecoordinateverticalinaugercs, cs);
332 bool corsikaazimuth =
true;
336 if (!corsikaazimuth) {
337 const string msg =
"REAS simulations with particle file must not have azimuth override set";
341 #warning RU: the following check is logical not 100% identical to before
342 if (selectedcorsikashower != 1) {
344 "(Co)REAS simulations without particle file must not have "
345 "multiple CORSIKA simulations in one CORSIKA run";
352 "(Co)REAS simulations could not initialize sim shower. No CORSIKA files found";
366 WARNING(
"Event not cleared - has RadioSimulation");
380 if (gpssecs || gpsnanosecs)
387 H5Giterate(
fReasH5.getId(),
"/CoREAS/observers/",
nullptr,
AddObserver, (
void*)&oooptdata);
405 const string msg =
"Cannot write to REASH5File - read-only file";
Status Read(evt::Event &event) override
read current event advance cursor by 1
Status Read(evt::Event &event) override
read current event advance cursor by 1
void SetCorePosition(const utl::Point &core)
Set the core position of the RadioSimulation using an utl::Point.
void SetMagneticFieldDeclination(const double magneticFieldDeclination)
Set the declination of the Earth's magnetic field used in CORSIKA/REAS simulation.
double magneticfielddeclination
static herr_t AddObserver(hid_t loc_id, const char *const name, void *const operator_data)
void SetStartTime(const double starttime)
void MakeRadioSimulation()
Make the RadioSimulation.
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.
#define INFO(message)
Macro for logging informational messages.
bool HasRadioSimulation() const
Check initialization of the RadioSimulation.
utl::SVector< 3, double > Vector3D
void SetRunNumber(const int runnum)
Set the run number of the RadioSimulation.
unsigned int fCurrentPosition
Status GotoPosition(const unsigned int position) override
goto by position in the file
CorsikaShowerFile * fCorsikaShowerFile
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.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
Status
Return code for seek operation.
void SetMagneticFieldDeclination(const double d)
void SetEventTime(const utl::TimeStamp &t)
Set the event time of the RadioSimulation.
RadioSimulation & GetRadioSimulation()
Get the radio simulation data.
Base for exceptions in the REAS reader.
Read data from the output of CORSIKA.
double corecoordinateverticalinreassim
#define WARNING(message)
Macro for logging warning messages.
void AddSimRadioPulse(const SimRadioPulse &rp)
Add a radio pulse to the RadioSimulation.
std::string fReasDirectory
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 SetDistanceOfShowerMaximum(const double parDistance)
Set the geometrical distance of the shower maximum from the core.
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
RadioSimulation * radiosim
void Write(const evt::Event &event) override
void PushBack(const T &value)
Insert a single value at the end.
#define ERROR(message)
Macro for logging error messages.
const utl::TraceV3D & GetEfieldTimeSeries() const
Get the Trace of the simulated electric field.
int GetNEvents() override
Status FindEvent(const unsigned int eventId) override
seek Event id set cursor there
double GetStartTime() const
Get the timestamp of the first sample.
void Open(const std::string &fileName, const Mode mode=eRead, utl::Branch *const b=nullptr) override
Status GotoPosition(const unsigned int position) override
goto by position in the file
std::string fOrigDirectory