1 #include <utl/config.h>
6 #include <adst/RecEvent.h>
7 #include <adst/DetectorGeometry.h>
8 #include <adst/FileInfo.h>
9 #include <adst/GenShower.h>
10 #include <adst/GenParticle.h>
12 #include <det/Detector.h>
14 #include <sdet/SDetector.h>
16 #include <fdet/FDetector.h>
17 #include <fdet/Pixel.h>
19 #include <fdet/Camera.h>
20 #include <fdet/Telescope.h>
22 #include <atm/Atmosphere.h>
23 #include <atm/InclinedAtmosphericProfile.h>
24 #include <atm/ProfileResult.h>
25 #include <atm/GOESDB.h>
27 #include <evt/Event.h>
28 #include <evt/ShowerSimData.h>
29 #include <evt/GenParticle.h>
30 #include <evt/RadioSimulation.h>
31 #include <fevt/FEvent.h>
33 #include <fevt/Telescope.h>
35 #include <fwk/CentralConfig.h>
36 #include <fwk/CoordinateSystemRegistry.h>
38 #include <utl/Branch.h>
39 #include <utl/ErrorLogger.h>
40 #include <utl/UTCDateTime.h>
41 #include <utl/TimeStamp.h>
42 #include <utl/ModifiedJulianDate.h>
43 #include <utl/MathConstants.h>
44 #include <utl/ReferenceEllipsoid.h>
45 #include <utl/AugerUnits.h>
46 #include <utl/Point.h>
47 #include <utl/Vector.h>
48 #include <utl/UTMPoint.h>
49 #include <utl/Transformation.h>
50 #include <utl/Trace.h>
51 #include <utl/AugerUnits.h>
52 #include <utl/MathConstants.h>
53 #include <utl/PhysicalConstants.h>
54 #include <utl/PhysicalFunctions.h>
55 #include <evt/VGaisserHillasParameter.h>
56 #include <utl/config.h>
57 #include <utl/Particle.h>
58 #include <utl/CoordinateSystemPtr.h>
70 #include <mdet/MDetector.h>
71 #include <mdet/Counter.h>
74 #include <adst/RdEvent.h>
75 #include <adst/RdTrace.h>
76 #include <evt/ShowerRecData.h>
92 const auto& fDet = det::Detector::GetInstance().GetFDetector();
93 const bool hasFdConfig = (fDet.EyesBegin() != fDet.EyesEnd());
95 recEvent = RecEvent();
117 bool saveProfiles =
true;
119 saveProfiles = recEvent.GetNEyes() > 0 || recEvent.GetSDEvent().GetRecLevel() > 0;
120 FillSim(event, recEvent.GetGenShower(), saveProfiles);
124 recEvent.GetNEyes() > 0 ||
125 recEvent.GetSDEvent().GetRecLevel() > 0) {
126 INFO(
"Convert Detector");
145 if (storeRadioLevel < 0)
150 const bool storeStationTraces = storeRadioLevel >= 1;
151 const bool storeChannelTraces = storeRadioLevel >= 2;
154 const auto& rev =
event.GetREvent();
157 rfiller.
AddRadioDetector(det::Detector::GetInstance(), recEvent.GetDetector());
159 if (event.
HasRecShower() &&
event.GetRecShower().HasRRecShower())
177 info.SetHasSdAllTraces();
180 info.SetHasVEMTraces();
187 info.SetLDFType(eTabulated);
194 info.SetHasFdSpotRecTraces();
197 info.SetHasFdTraces();
203 const unsigned int hostLen = 80;
204 char host[hostLen+1] = {
'\0' };
205 gethostname(host, hostLen);
207 info.SetOfflineVersion(OFFLINE_PACKAGE_VERSION);
210 info.SetUser(getenv(
"USER") ? getenv(
"USER") :
"unknown");
213 info.SetOfflineConfiguration(cc->
GetConfig());
215 ostringstream recEventVersion;
216 recEventVersion << RecEvent::GetReleaseName() <<
' ' << RecEvent::GetVersion()
217 <<
" (SVN: " << RecEvent::GetSVNVersion() <<
" rev "<< RecEvent::GetSVNRevision() <<
')';
218 info.SetRecEventVersion(recEventVersion.str());
222 const CoordinateSystemPtr referenceCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
224 const sdet::SDetector& sdDetector = det::Detector::GetInstance().GetSDetector();
225 const DetectorGeometry::StationPosMap& adstStations =
fDetectorGeometry.GetStations();
227 for (
const auto& station : sdDetector.AllStationsRange()) {
229 if (station.IsDense())
232 const int id = station.GetId();
238 if (adstStations.find(
id) != adstStations.end())
246 WARNING(
"Station position information cannot be read from SDetector. "
247 "Probably this station is handled by the EventStationPositionsManager"
248 "that is already shut down at this stage ... "
249 "Station position will be set to 0,0,0.");
252 const int partners = station.GetNumberOfPartners();
255 if (station.IsInGrid())
256 gridType |= eRegularArray;
258 gridType |= eDoublet;
260 gridType |= eTriplet;
264 TString name =
"unknown";
266 name = station.GetName();
268 WARNING(
"Station name information cannot be read from SDetector. "
269 "Probably this station is handled by the EventStationPositionsManager"
270 "that is already shut down at this stage ... "
271 "Station name will be set to \"unknown\".");
285 const auto& ts =
event.GetHeader().GetTime();
288 recEvent.SetYYMMDD(yymmdd);
289 recEvent.SetHHMMSS(hhmmss);
297 const auto referenceCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
298 const auto& fdDetector = det::Detector::GetInstance().GetFDetector();
303 const auto& eyeCS = eyeiter->GetEyeCoordinateSystem();
304 const auto eyeId = eyeiter->GetId();
307 const auto pos =
ToTVector3(eyeiter->GetPosition(), referenceCS,
meter);
308 const Vector vertEye(0,0,1, eyeCS);
309 const double phiEye = vertEye.GetPhi(referenceCS);
310 const double thetaEye = vertEye.GetTheta(referenceCS);
311 const Vector backVec(1,0,0, eyeCS);
312 double backwallAngle = atan2(backVec.
GetY(referenceCS), backVec.
GetX(referenceCS));
313 if (backwallAngle >
kTwoPi)
315 if (backwallAngle < 0)
319 pos.X()/
m, pos.Y()/
m, pos.Z()/
m,
323 eyeiter->GetNameAbbr());
327 for (
auto teliter = eyeiter->TelescopesBegin(), end = eyeiter->TelescopesEnd();
328 teliter != end; ++teliter) {
329 const int telId = teliter->GetId();
331 if (!eyeGeo.HasTelescope(telId)) {
333 map<TString, Double_t> adstTelPPhi;
334 map<TString, Double_t> adstTelPElevation;
335 map<TString, TelescopeGeometry::PixelList_t> pixelPhi;
336 map<TString, TelescopeGeometry::PixelList_t> pixelOmega;
338 adstTelPPhi, adstTelPElevation,
339 teliter->GetCamera().GetFADCTraceLength(),
340 teliter->GetCamera().GetFADCBinSize(),
341 pixelPhi, pixelOmega);
344 const unsigned int firstpixelid = teliter->GetFirstPixelId();
345 const unsigned int lastpixelid = teliter->GetLastPixelId();
347 const TString curPointingId = TString(teliter->GetTelescopePointingId());
348 auto& telGeo = eyeGeo.GetTelescope(telId);
349 auto& solidAngles = telGeo.GetSolidAngles();
350 if (solidAngles.empty())
351 for (
unsigned int i = firstpixelid; i <= lastpixelid; ++i)
352 solidAngles.push_back(teliter->GetPixel(i).GetSolidAngle());
354 if (!telGeo.HasPointing(curPointingId)) {
356 const Double_t elevation =
kPi/2 - teliter->GetAxis().GetTheta(eyeCS);
357 const Double_t azimuth = teliter->GetAxis().GetPhi(eyeCS);
358 TelescopeGeometry::PixelList_t pixelPhi(lastpixelid - firstpixelid + 1);
359 TelescopeGeometry::PixelList_t pixelOmega(lastpixelid - firstpixelid + 1);
360 for (
unsigned int i = firstpixelid; i <= lastpixelid; ++i) {
361 const auto& detpixel = teliter->GetPixel(i);
362 const auto& dir = detpixel.GetDirection();
363 const double theta = dir.GetTheta(eyeCS) /
utl::degree;
369 pixelOmega[i-1] = 90 - theta;
372 telGeo.AddPointing(curPointingId, azimuth, elevation, pixelPhi, pixelOmega);
381 INFO(
"Updating SD stations");
383 const auto& sdDetector = det::Detector::GetInstance().GetSDetector();
387 for (
const auto& station : sdDetector.AllStationsRange()) {
389 if (station.IsDense())
392 const int id = station.GetId();
398 if (adstStations.find(
id) != adstStations.end())
403 const auto pos =
ToTVector3(station.GetPosition(), referenceCS,
meter);
405 const int partners = station.GetNumberOfPartners();
408 if (station.IsInGrid())
409 gridType |= eRegularArray;
411 gridType |= eDoublet;
413 gridType |= eTriplet;
418 WARNING(
"Station position information cannot be read from SDetector.");
422 const auto name = station.GetName();
425 WARNING(
"Station name information cannot be read from SDetector.");
429 const double gpsSecond = station.GetCommissionTime().GetGPSSecond();
432 WARNING(
"Station commission time information cannot be read from SDetector.");
439 if (cloudPixCenters.empty()) {
441 const auto& atm = det::Detector::GetInstance().GetAtmosphere();
442 const auto& goesDB = atm.GetGOESDB();
444 goesDB.GetPixelWidthNorthing());
445 for (
unsigned int iPix = 0; iPix < goesDB.GetNumberOfPixels(); ++iPix) {
446 const auto center =
ToTVector3(goesDB.GetPixelCenter(iPix).GetPoint(referenceCS), referenceCS);
447 cloudPixCenters.push_back(center);
462 const auto& simEvent=
event.GetSimShower();
463 const auto& referenceCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
465 gen.SetEnergy(simEvent.GetEnergy()/
eV);
466 gen.SetMuonNumber(simEvent.GetMuonNumber());
467 gen.SetMuonWeightScale(simEvent.GetMuonWeightScale());
468 gen.SetCalorimetricEnergy(simEvent.GetCalorimetricEnergy() /
eV);
469 gen.SetElectromagneticEnergy(simEvent.GetElectromagneticEnergy() /
eV);
470 gen.SetNmu(simEvent.GetNmu());
471 gen.SetXmaxMu(simEvent.GetXmaxMu() / (
g/
cm2));
474 if (simEvent.HasRadioSimulation()) {
475 const auto& radiosim = simEvent.GetRadioSimulation();
476 gen.SetRadiationEnergy(radiosim.GetRadiationEnergy());
479 if (simEvent.HasGeometry()) {
480 const auto& core = simEvent.GetPosition();
487 const utl::UTMPoint utm(core, ReferenceEllipsoid::GetWGS84());
492 ERROR(
"UTMZoneException: sd rec shower invalid");
495 ERROR(
"UTMException: sd rec shower invalid");
498 gen.SetCoreUTMCS(TVector3(easting, northing, altitude));
500 if (simEvent.HasGeometry()) {
502 const auto& axis = -simEvent.GetDirection();
503 const auto& localCS = simEvent.GetLocalCoordinateSystem();
505 gen.SetAxisSiteCS(
ToTVector3(axis, referenceCS));
507 gen.SetPrimary(simEvent.GetPrimaryParticle());
509 gen.SetCoreTime(simEvent.GetTimeStamp().GetGPSSecond(),
510 simEvent.GetTimeStamp().GetGPSNanoSecond());
515 const auto& coreTime = simEvent.GetTimeStamp();
516 const vector<double> inp({
522 axis.GetTheta(localCS),
526 const auto equOut = equCalc(inp);
527 gen.SetRightAscension(equOut[0]);
528 gen.SetDeclination(equOut[1]);
532 const auto galOut = galCalc(inp);
533 gen.SetGalacticLongitude(galOut[0]);
534 gen.SetGalacticLatitude(galOut[1]);
539 if (!simEvent.HasLongitudinalProfile())
544 if (!simEvent.HasdEdX())
548 unsigned int size = electronTrace.
GetNPoints();
549 vector<double> depth(size);
551 vector<double> dEdX(size);
553 for (
unsigned int i = 0; i < size; ++i) {
554 depth[i] = dEdXTrace[i].X() / (
g/
cm2);
555 dEdX[i] = dEdXTrace[i].
Y() / (
PeV/(
g/
cm2));
556 electrons[i] = electronTrace[i].
Y();
560 const double distanceOfShowerMaximum = simEvent.GetDistanceOfShowerMaximum();
563 gen.SetDistanceOfShowerMaximum(distanceOfShowerMaximum /
cm);
565 gen.SetMagneticFieldStrength(simEvent.GetMagneticFieldStrength());
566 gen.SetMagneticFieldInclination(simEvent.GetMagneticFieldInclination());
567 gen.SetMagneticFieldDeclination(simEvent.GetMagneticFieldDeclination());
570 if (simEvent.HasGHParameters()) {
571 gen.SetXmaxGaisserHillas(simEvent.GetGHParameters().GetXMax() / (
g/
cm2));
572 gen.SetNmaxGaisserHillas(simEvent.GetGHParameters().GetNMax() / (
g/
cm2));
576 double xMaxConex = 0;
577 double xMaxConexdEdX = 0;
579 gen.SetXmaxInterpolated(xMaxConex);
580 gen.SetdEdXmaxInterpolated(xMaxConexdEdX);
584 const double X1 = simEvent.GetXFirst();
585 gen.SetX1(X1 / (
g/
cm2));
586 const double X0 = simEvent.GetXInject();
587 gen.SetX0(X0 / (
g/
cm2));
589 if (simEvent.HasGeometry()) {
591 const double depthStepSize = 5*
g/
cm2;
592 const auto& atmo = det::Detector::GetInstance().GetAtmosphere();
593 atmo.InitSlantProfileModel(simEvent.GetPosition(), -simEvent.GetDirection(), depthStepSize);
595 gen.SetD1(distanceVsSlantDepth.
Y(X1));
596 gen.SetD0(distanceVsSlantDepth.
Y(X0));
598 WARNING(
"Can't load profile model. Core-to-depth distances not filled.");
606 gen.SetElectrons(electrons);
607 gen.SetEnergyDeposit(dEdX);
610 auto& adstGenP = gen.GetParticleTree();
611 const auto& partTree = simEvent.GetParticleTree();
629 adstGP.AddNDaughters(numberOfDaughterParticles);
630 for (
unsigned i = 0; i < numberOfDaughterParticles; ++i) {
double ModifiedJulianDate(const time_t unixSecond)
unsigned int GetNPoints() const
void FillGlobalInfo(const evt::Event &event, RecEvent &recEvent)
DetectorGeometry fDetectorGeometry
bool AddRadioDetector(const det::Detector &offlineDet, Detector &adstDet)
int StoreRadioLevel() const
void SetIsMCEvent(bool ismc)
Base class for all exceptions used in the auger offline code.
evt::Header & GetHeader()
bool FillRadioChannels(const revt::REvent &therev, const bool saveTrace=false, const bool storeExcludedStations=true)
Converts an Offline event to ADST FDEvent.
void FinishDetectorAndFileInfo()
void FillRadio(const evt::Event &event, RecEvent &recEvent)
Fills the per-event radio part of the event, EventInfo, and DetectorGeometry.
bool HasRecShower() const
bool FillRadioEventInfo(const revt::REvent &therev)
Class to hold and convert a point in geodetic coordinates.
Class to hold collection (x,y) points and provide interpolation between them.
void Convert(const evt::Event &event, RecEvent &recEvent)
bool HasSimShower() const
std::string GetConfig()
Get configuration in a string.
bool DropUntriggeredMCProfiles() const
#define INFO(message)
Macro for logging informational messages.
Base class for exceptions trying to access non-existing components.
bool IsMCEvent() const
Remember whether the current event is a MC.
unsigned int TimeStamp2HHMMSS(const utl::TimeStamp ×t)
Convert a TimeStamp into an integer representing the time as HHMMSS.
void Convert(const evt::Event &event, RecEvent &recEvent) const
double GetNorthing() const
Get the northing.
Report attempts to use invalid UTM zone.
void FillSim(const evt::Event &event, GenShower &gen, bool saveProfiles)
double Y(const double x) const
Get the Y value (coordinate) for given X (ordinate)
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
bool FillRadioShower(const evt::Event &theev)
Status
Return code for seek operation.
double GetHeight() const
Get the height.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Class describing the Atmospheric profile.
bool DropUntriggeredDetector() const
const otoa::Config & Config() const
Fetch the converter configuration.
bool Convert(const evt::Event &event, RecEvent &recEvent)
Converts an Offline event to ADST.
double GetEasting() const
Get the easting.
void Convert(const evt::Event &inEvent, RecEvent &outEvent) const
unsigned int TimeStamp2YYMMDD(const utl::TimeStamp ×t)
Convert a TimeStamp into an integer representing the date as YYMMDD.
double GetParentEnergy() const
#define WARNING(message)
Macro for logging warning messages.
void FillDetectorGeometryIncremental()
int StoreSDTraces() const
std::vector< GenParticle > & GetDaughterParticles()
double GetEnergyCM() const
bool FillSimRadioStations(const evt::Event &theev)
bool StoreExcludedRdStations() const
double GetY(const CoordinateSystemPtr &coordinateSystem) const
static bool AddRadioDetectorGeometry(const det::Detector &offlineDet, DetectorGeometry *const adstGeo)
void ConvertGenParticle(GenParticle &adstGP, const evt::GenParticle &evtGP)
Converts an Offline event to ADST SDEvent.
Report problems in UTM handling.
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
double TimeStamp2GMST(const utl::TimeStamp &ts)
Convert a TimeStamp to GMST.
Detector description interface for SDetector-related data.
Main configuration utility.
void Convert(const evt::Event &event, RecEvent &recEvent)
TVector3 ToTVector3(const T &v, const utl::CoordinateSystemPtr &cs, const double unit=1)
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
int GetTargetMass() const
#define ERROR(message)
Macro for logging error messages.
bool FillRadioStations(const evt::Event &theev, const bool saveTrace=true, const bool storeExcludedStations=true)
int StoreFDTraces() const
const std::string & GetMessage() const
Retrieve the message from the exception.
const FileInfo & GetFileInfo() const
static bool AddRadioInfo(FileInfo *const info, const int radioSaveLevel)
bool QuadraticMaximumInterpolation(const std::vector< double > &x, const std::vector< double > &y, double &xMax, double &yMax)
int GetMultiplicity() const