7 #include <fwk/CentralConfig.h>
8 #include <fwk/LocalCoordinateSystem.h>
9 #include <fwk/CoordinateSystemRegistry.h>
11 #include <det/Detector.h>
13 #include <fdet/FDetector.h>
14 #include <fdet/Pixel.h>
16 #include <fdet/Camera.h>
17 #include <fdet/Telescope.h>
19 #include <sdet/SDetector.h>
20 #include <sdet/Station.h>
22 #include <evt/Event.h>
23 #include <evt/ShowerRecData.h>
24 #include <evt/ShowerSimData.h>
25 #include <evt/ShowerFRecData.h>
26 #include <evt/ShowerSRecData.h>
27 #include <evt/VGaisserHillasParameter.h>
28 #include <evt/GaisserHillas4Parameter.h>
29 #include <evt/GaisserHillas6Parameter.h>
30 #include <evt/ShowerSimData.h>
32 #include <fevt/FEvent.h>
33 #include <fevt/Header.h>
35 #include <fevt/Telescope.h>
36 #include <fevt/EyeHeader.h>
37 #include <fevt/EyeRecData.h>
38 #include <fevt/TelescopeSimData.h>
39 #include <fevt/TelescopeRecData.h>
40 #include <fevt/Pixel.h>
41 #include <fevt/PixelRecData.h>
43 #include <sevt/SEvent.h>
44 #include <sevt/Station.h>
45 #include <sevt/Header.h>
46 #include <sevt/StationRecData.h>
47 #include <sevt/StationSimData.h>
48 #include <sevt/StationTriggerData.h>
49 #include <sevt/SortCriteria.h>
51 #include <sevt/PMTRecData.h>
52 #include <sevt/PMTCalibData.h>
53 #include <sevt/StationConstants.h>
55 #include <revt/REvent.h>
56 #include <revt/Station.h>
57 #include <revt/Channel.h>
58 #include <revt/EventTrigger.h>
59 #include <revt/Header.h>
60 #include <revt/StationGPSData.h>
61 #include <revt/StationRecData.h>
62 #include <revt/StationSimData.h>
63 #include <revt/StationTriggerData.h>
65 #include <rdet/RDetector.h>
67 #include <utl/Reader.h>
68 #include <utl/ErrorLogger.h>
69 #include <utl/TimeStamp.h>
70 #include <utl/ModifiedJulianDate.h>
71 #include <utl/UTCDateTime.h>
72 #include <utl/ReferenceEllipsoid.h>
73 #include <utl/AugerUnits.h>
74 #include <utl/Point.h>
75 #include <utl/Vector.h>
76 #include <utl/UTMPoint.h>
77 #include <utl/Transformation.h>
78 #include <utl/Trace.h>
79 #include <utl/AugerUnits.h>
80 #include <utl/MathConstants.h>
81 #include <utl/PhysicalConstants.h>
82 #include <utl/PhysicalFunctions.h>
83 #include <utl/config.h>
84 #include <utl/Particle.h>
85 #include <utl/CoordinateSystemPtr.h>
86 #include <utl/SaveCurrentTDirectory.h>
87 #include <utl/String.h>
89 #include <atm/ProfileResult.h>
90 #include <atm/MolecularDB.h>
91 #include <atm/MolecularZone.h>
92 #include <atm/Atmosphere.h>
93 #include <atm/LidarDB.h>
94 #include <atm/LidarZone.h>
97 # include <has/MuonProfile.h>
98 # include <has/VTankResponse.h>
99 # include <has/TankResponseFactory.h>
100 # include <has/EMComponent.h>
101 # include <has/HASUtilities.h>
104 #include <boost/tuple/tuple.hpp>
106 #include <adst/Detector.h>
107 #include <adst/FileInfo.h>
108 #include <adst/SDEvent.h>
109 #include <adst/FDEvent.h>
110 #include <adst/RecEvent.h>
111 #include <adst/FdRecApertureLight.h>
112 #include <adst/FdGenApertureLight.h>
113 #include <adst/FdRecPixel.h>
114 #include <adst/FdGenShower.h>
115 #include <adst/FdRecLevel.h>
116 #include <adst/SdRecLevel.h>
117 #include <adst/DetectorGeometry.h>
118 #include <adst/FdRecLevel.h>
119 #include <adst/FdLidarData.h>
120 #include <adst/FdAerosols.h>
121 #include <adst/Traces.h>
123 #include <adst/AsciiSDConverter.h>
124 #include <adst/AsciiHybridConverter.h>
125 #include <adst/AsciiHybridOnlineConverter.h>
127 #include <adst/RdEvent.h>
128 #include <adst/RdTrace.h>
137 using namespace otoa;
139 using namespace fdet;
140 using namespace sdet;
141 using namespace fevt;
142 using namespace sevt;
147 using namespace HASTools;
148 using namespace HASUtilities;
152 namespace RecDataWriterNG {
154 RecDataWriter::RecDataWriter() :
176 info <<
"Parameters:\n"
180 " save FD traces: " << cfg.StoreFDTraces() <<
"\n"
181 " save SD traces: " << cfg.StoreSDTraces() <<
"\n"
182 " save MC traces: " << cfg.StoreMCTraces() <<
"\n"
183 " use weather station: " << cfg.UseWeatherStations() <<
"\n"
184 " connect to databases: " << cfg.ConnectToDatabases() <<
"\n"
185 " store Lidar data: " << cfg.StoreLidarData() <<
"\n"
186 " store cloud camera data: " << cfg.StoreCloudCameraData() <<
"\n"
187 " store GOES cloud data: " << cfg.StoreGOESData() <<
"\n"
188 " store all pixels: " << cfg.StoreAllPixels() <<
"\n"
189 " untriggered MC profile: " << (cfg.DropUntriggeredMCProfiles() ?
"drop" :
"keep") <<
"\n"
190 " untriggered MC tels: " << (cfg.DropUntriggeredMCTelescopes() ?
"drop" :
"keep") <<
"\n"
191 " untriggered detector: " << (cfg.DropUntriggeredDetector() ?
"drop" :
"keep") <<
"\n"
192 " re-bin sim. tel traces: ";
193 if (cfg.GetRebinSimTelescopeTraces() > 0)
194 info << cfg.GetRebinSimTelescopeTraces()/
ns <<
" ns\n";
197 info <<
" store photoelectrons: " << cfg.StoreSDPETimeDistribution() <<
"\n"
198 " Mie att. prof. sampling: " << cfg.AerosolAttenuationLengthSampling()/
m <<
" m\n"
199 " Laser wavelength: " << cfg.LaserWavelength()/
nanometer <<
" nm\n"
200 " store particles: " << cfg.StoreSDParticles() <<
"\n"
201 " Radio Save level: " << cfg.StoreRadioLevel() <<
"\n"
202 " save MD traces (AMIGA): " << cfg.StoreMDTraces();
205 if (cfg.AerosolAttenuationLengthSampling() > 0 && cfg.AerosolAttenuationLengthSampling() != 200*
m) {
206 ERROR(
"Aerosol attenuation length sampling was not 200 m; this will invoke interpolation "
207 "which is not properly implemented, so the aerosol data stored in the ADST will not "
208 "be accurate. Please check your configuration and use 200 m!");
212 switch (cfg.StoreRadioLevel()) {
214 INFO(
"Radio will not be saved");
217 INFO(
"Only Radio shower and station information will be saved");
220 INFO(
"Radio data will be saved at the station level");
223 INFO(
"Radio data will be saved at the Channel level");
226 INFO(
"Correct Values for SaveRadio field are -1/0/1/2! "
227 "Defaulting to saving the radio at the shower level! "
228 "Check RecDataWriter.xml");
287 INFO(
"writing detector");
291 INFO(
"writing file info");
319 const auto cc = CentralConfig::GetInstance();
320 auto topB = cc->GetTopBranch(
"RecDataWriter");
323 ERROR(
"Could not find configuration branch RecDataWriter");
332 topB.GetChild(
"verbosity").GetData(
fVerbosity);
336 adstCfg.SetWriteFD(topB.GetChild(
"writeFD").Get<
bool>());
337 adstCfg.SetWriteSD(topB.GetChild(
"writeSD").Get<
bool>());
340 adstCfg.SetUseWeatherStations(topB.GetChild(
"useWeatherStations").Get<
bool>());
341 adstCfg.SetConnectToDatabases(topB.GetChild(
"connectToDatabases").Get<
bool>());
342 adstCfg.SetStoreLidarData(topB.GetChild(
"storeLidarData").Get<
bool>());
343 adstCfg.SetStoreCloudCameraData(topB.GetChild(
"storeCloudCameraData").Get<
int>());
344 adstCfg.SetStoreGOESData(topB.GetChild(
"storeGOESData").Get<
int>());
345 adstCfg.SetStoreAllPixels(topB.GetChild(
"storeAllPixels").Get<
bool>());
346 adstCfg.SetStoreFDTraces(topB.GetChild(
"saveFDTraces").Get<
int>());
347 adstCfg.SetStoreLCEfficiency(topB.GetChild(
"saveLCEfficiency").Get<
bool>());
348 adstCfg.SetVAODReferenceHeight(topB.GetChild(
"vaodReferenceHeight").Get<
double>());
349 adstCfg.SetFieldOfViewOption(topB.GetChild(
"calculateFOVs").Get<
int>());
350 adstCfg.SetAerosolAttenuationLengthSampling(topB.GetChild(
"aerosolAttenuationLengthSampling").Get<
double>());
351 adstCfg.SetLaserWavelength(topB.GetChild(
"laserWavelength").Get<
double>());
354 adstCfg.SetStoreSDTraces(topB.GetChild(
"saveSDTraces").Get<
int>());
355 adstCfg.SetStoreCalibHistos(topB.GetChild(
"storeCalibHistos").Get<
int>());
356 adstCfg.SetStoreSDTracesMinEnergy(topB.GetChild(
"minEnergyForTraces").Get<
double>());
357 adstCfg.SetStoreMPDsMinEnergy(topB.GetChild(
"minEnergyForStationsMPDs").Get<
double>());
358 adstCfg.SetStoreSDPETimeDistribution(topB.GetChild(
"savePETimeDistribution").Get<
bool>());
359 adstCfg.SetStoreMCTraces(topB.GetChild(
"saveMCTraces").Get<
bool>());
360 adstCfg.SetStoreSDParticles(topB.GetChild(
"saveParticles").Get<
bool>());
362 auto saveParticleTypesB = topB.GetChild(
"saveParticleTypes");
363 if (saveParticleTypesB) {
364 const auto p = topB.GetChild(
"saveParticleTypes").Get<vector<int>>();
365 adstCfg.SetStoreSDParticleTypes(std::set<int>(
p.begin(),
p.end()));
369 adstCfg.SetDropUntriggeredMCProfiles(topB.GetChild(
"dropUntriggeredMCProfiles").Get<
bool>());
371 adstCfg.SetDropUntriggeredMCTelescopes(topB.GetChild(
"dropUntriggeredMCTelescopes").Get<
bool>());
373 adstCfg.SetDropUntriggeredDetector(topB.GetChild(
"dropUntriggeredDetector").Get<
bool>());
375 adstCfg.SetRebinSimTelescopeTraces(topB.GetChild(
"rebinSimTelescopesTraces").Get<
double>());
378 adstCfg.SetStoreRadioLevel(topB.GetChild(
"SaveRadio").Get<
int>());
379 adstCfg.SetStoreExcludedRdStations(topB.GetChild(
"StoreExcludedRdStations").Get<
bool>());
382 adstCfg.SetStoreMDTraces(topB.GetChild(
"saveMDTraces").Get<
bool>());
383 adstCfg.SetStoreMDInjectedParticles(topB.GetChild(
"saveMDInjectedParticles").Get<
bool>());
384 auto saveMDParticleTypesB = topB.GetChild(
"saveMDParticleTypes");
385 if (saveMDParticleTypesB) {
386 const auto p = saveMDParticleTypesB.Get<vector<int>>();
387 adstCfg.SetStoreMDParticleTypes(std::set<int>(
p.begin(),
p.end()));
392 const auto hasB = cc->GetTopBranch(
"SdHorizontalReconstruction");
395 const auto muonProfile = hasB.GetChild(
"MuonProfile").Get<
string>();
396 auto muonMapBranch = cc->GetTopBranch(
"MuonProfile").GetChild(muonProfile);
397 fMuonProfile =
new HASTools::MuonProfile(muonMapBranch);
398 const string tmp =
"MuonProfile";
399 fMuonMapType = muonProfile.substr(0, muonProfile.length() - tmp.length());
401 const auto tankResponse = hasB.GetChild(
"TankResponse").Get<
string>();
402 auto tankResponseBranch = cc->GetTopBranch(
"TankResponse").GetChild(tankResponse);
403 fTankResponse = &HASTools::TankResponseFactory::GetInstance().GetTankResponse(tankResponseBranch);
405 const auto emComponent = hasB.GetChild(
"EMComponent").Get<
string>();
406 auto EMComponentBranch = cc->GetTopBranch(
"EMComponent").GetChild(emComponent);
407 fEMComponent =
new HASTools::EMComponent(EMComponentBranch);
409 const auto muonMapB = topB.GetChild(
"muonMap");
410 muonMapB.GetChild(
"nrOfPointsPerContour").GetData(fNoOfPoints);
411 muonMapB.GetChild(
"nrOfContours").GetData(fNoOfContours);
412 muonMapB.GetChild(
"contourSignalFactor").GetData(fContourSignalFactor);
414 INFO(
"Configuration for SdHorizontalReconstruction not found, no special treatment for horizontal events.");
424 auto outputB = topB.
GetChild(
"rootOutput");
429 const auto writeMode = outputB.GetChild(
"outputFileMode").Get<
string>();
430 if (writeMode ==
"eWrite") {
433 }
else if (writeMode ==
"eAppend") {
436 }
else if (writeMode ==
"eNone") {
441 err <<
"Unrecognized file mode \"" << writeMode <<
"\"";
453 auto aOutputB = topB.
GetChild(
"asciiOutput");
457 const auto aWriteMode = aOutputB.
GetChild(
"outputFileMode").
Get<
string>();
458 if (aWriteMode ==
"eWrite") {
461 }
else if (aWriteMode ==
"eAppend") {
464 }
else if (aWriteMode ==
"eNone") {
469 err <<
"Unrecognized ASCII file mode \"" << aWriteMode <<
"\"";
512 if (!asciiOut->is_open()) {
513 ERROR(
"Could not open ascii output file");
518 const auto cv =
new ADST::AsciiSDConverter(asciiOut);
522 const auto cv =
new ADST::AsciiHybridConverter(asciiOut);
526 const auto cv =
new ADST::AsciiHybridOnlineConverter(asciiOut);
bool PrepareRecEventAndRootFile()
RecEventFile::Mode fAsciiOutputFileMode
std::string fAsciiOutputFileName
fwk::VModule::ResultFlag Finish() override
Finish: invoked at end of the run (NOT end of the event)
Report success to RunController.
std::string fRootOutputFileName
void FinishDetectorAndFileInfo()
std::string fAsciiDataMode
#define INFO(message)
Macro for logging informational messages.
vector< t2list > out
output of the algorithm: a list of clusters
Base class for exceptions trying to access non-existing components.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
constexpr double nanometer
otoa::Offline2ADST * fADSTConverter
const char * Plural(const T n)
Class representing a document branch.
void SetVerbosity(const int v)
const otoa::Config & Config() const
Fetch the converter configuration.
bool Convert(const evt::Event &event, RecEvent &recEvent)
RecEventFile::Mode fRootOutputFileMode
RecEventFile * fRecEventFile
void GetData(bool &b) const
Overloads of the GetData member template function.
ADST::AsciiConverter * fAsciiConverter
ResultFlag
Flag returned by module methods to the RunController.
fwk::VModule::ResultFlag Run(evt::Event &event) override
Run: invoked once per event.
fwk::VModule::ResultFlag Init() override
Initialize: invoked at beginning of run (NOT beginning of event)
const DetectorGeometry & GetDetectorGeometry() const
Overwrite if exist and open for write.
Report failure to RunController, causing RunController to terminate execution.
bool ReadRootConfig(utl::Branch &topB)
#define ERROR(message)
Macro for logging error messages.
bool ReadAsciiConfig(utl::Branch &topB)
const FileInfo & GetFileInfo() const
Converts an Offline event to ADST.