10 #include <io/CDASToOfflineEventConverter.h>
12 #include <det/Detector.h>
13 #include <sdet/SDetector.h>
14 #include <sdet/Station.h>
16 #include <sdet/PMTConstants.h>
18 #include <evt/Event.h>
19 #include <evt/ShowerRecData.h>
20 #include <evt/ShowerSRecData.h>
21 #include <evt/ShowerFRecData.h>
22 #include <evt/VGaisserHillasParameter.h>
23 #include <evt/GaisserHillas2Parameter.h>
25 #include <sevt/EventTrigger.h>
26 #include <sevt/Header.h>
27 #include <sevt/SEvent.h>
28 #include <sevt/Station.h>
29 #include <sevt/StationCalibData.h>
30 #include <sevt/StationRecData.h>
31 #include <sevt/StationGPSData.h>
32 #include <sevt/StationTriggerData.h>
34 #include <sevt/PMTCalibData.h>
35 #include <sevt/PMTRecData.h>
36 #include <sevt/Meteo.h>
38 #include <fwk/LocalCoordinateSystem.h>
39 #include <fwk/CoordinateSystemRegistry.h>
42 #include <utl/MathConstants.h>
43 #include <utl/CoordinateSystemPtr.h>
44 #include <utl/Point.h>
45 #include <utl/AugerCoordinateSystem.h>
46 #include <utl/ErrorLogger.h>
47 #include <utl/TimeStamp.h>
48 #include <utl/UTCDateTime.h>
49 #include <utl/Trace.h>
50 #include <utl/TraceAlgorithm.h>
51 #include <utl/UTMPoint.h>
52 #include <utl/String.h>
64 #include <mdet/MDetector.h>
65 #include <mdet/Counter.h>
66 #include <mdet/Module.h>
67 #include <mdet/FrontEnd.h>
69 #include <mevt/MEvent.h>
70 #include <mevt/Counter.h>
71 #include <mevt/Module.h>
72 #include <mevt/Channel.h>
74 #include <rdet/RDetector.h>
75 #include <rdet/Station.h>
76 #include <rdet/Channel.h>
78 #include <revt/REvent.h>
79 #include <revt/Station.h>
80 #include <revt/Channel.h>
81 #include <revt/Header.h>
82 #include <revt/StationTriggerData.h>
83 #include <revt/StationGPSData.h>
84 #include <revt/EventTrigger.h>
85 #include <revt/StationHeader.h>
86 #include <revt/StationConstants.h>
113 template<
typename T1,
typename T2>
116 T2*
const dst,
const unsigned int dstSize,
119 static bool beenHere =
false;
120 const unsigned int srcSize = src.size();
121 if (!beenHere && srcSize != dstSize) {
123 warn << what <<
" size mismatch: source " << srcSize <<
", "
124 "destination " << dstSize <<
'.';
128 const unsigned int n = min(srcSize, dstSize);
130 for (i = 0; i < n; ++i)
132 for (; i < dstSize; ++i)
140 const auto& managerRRegister = det::Detector::GetInstance().GetRManagerRegister();
143 if (managerRRegister.ManagersBegin() == managerRRegister.ManagersEnd()) {
145 INFO(
"No RDetector is configured. No read-in of RD data possible!");
155 const auto& managerMRegister = det::Detector::GetInstance().GetMManagerRegister();
158 if (managerMRegister.ManagersBegin() == managerMRegister.ManagersEnd()) {
160 INFO(
"No MDetector is configured. No read-in of UMD data possible!");
201 return station.Error & 0xff;
205 static const std::set<int>
gCycloneStations({600, 610, 620, 627, 630, 648});
206 static const std::set<int>
gCycloneYears({2007, 2008, 2009});
212 DEBUGRAW(
" PullEventRaw - IoSdEvent " << endl);
219 if (!oSEvent.HasTrigger())
222 oSEvent.SetNErrorZeroStations(rEvent.NumberOfErrorZeroStation);
225 auto& osHeader = oSEvent.GetHeader();
226 osHeader.SetId(rEvent.Id);
228 const auto& rTrigger = rEvent.Trigger;
229 const TimeStamp currentTime(rTrigger.Second, rTrigger.MicroSecond * 1000);
230 osHeader.SetTime(currentTime);
238 if (!oHeader.GetId().empty())
239 idos << oHeader.GetId() <<
"__";
240 idos <<
"sd_" << rEvent.Id;
241 const auto&
id = idos.str();
247 auto& oTrigger = oSEvent.GetTrigger();
249 oTrigger.SetId(rTrigger.Id);
250 oTrigger.SetPreviousId(rTrigger.PreviousId);
251 oTrigger.SetTime(currentTime);
252 oTrigger.SetSender(rTrigger.Sender);
253 oTrigger.SetAlgorithm(rTrigger.Algo);
254 oTrigger.SetSDPAngle(rTrigger.SDPAngle);
256 const auto& detector = det::Detector::GetInstance();
257 const auto& rDetector = detector.GetRDetector();
267 const bool readInRdData =
277 if (!rdEvent.HasTrigger())
278 rdEvent.MakeTrigger();
279 rdEvent.GetTrigger().SetSDTrigger(
true);
282 if (!rdHeader.GetId()) {
283 rdHeader.
SetId(rEvent.Id);
284 rdHeader.SetTime(currentTime);
289 if (!oSEvent.HasMeteo())
292 if (rEvent.MeteoFlag) {
294 const auto& rMeteo = rEvent.meteo();
296 auto& oMeteo = oSEvent.GetMeteo();
297 float pressures[kIoSd::N_WEATHER_STATIONS];
298 float dailyPressures[kIoSd::N_WEATHER_STATIONS];
300 for (
unsigned int k = 0; k < kIoSd::N_WEATHER_STATIONS; ++k) {
301 pressures[k] = rMeteo.Pressure[k]*
hPa;
302 dailyPressures[k] = rMeteo.DayPressure[k]*
hPa;
305 oMeteo.SetPressures(pressures, kIoSd::N_WEATHER_STATIONS);
306 oMeteo.SetTemperatures(rMeteo.Temperature, kIoSd::N_WEATHER_STATIONS);
307 oMeteo.SetHumidities(rMeteo.Humidity, kIoSd::N_WEATHER_STATIONS);
308 oMeteo.SetDayPressures(dailyPressures, kIoSd::N_WEATHER_STATIONS);
309 oMeteo.SetDayTemperatures(rMeteo.DayTemperature, kIoSd::N_WEATHER_STATIONS);
310 oMeteo.SetDayHumidities(rMeteo.DayHumidity, kIoSd::N_WEATHER_STATIONS);
314 const auto& rStations = rEvent.Stations;
316 set<int> zeroErrorStations;
317 for (
const auto&
s : rStations) {
320 zeroErrorStations.emplace(
s.Id);
323 const auto& sDetector = detector.GetSDetector();
324 set<int> missingDStations;
326 set<int> copiedStations;
327 ostringstream discardedStations;
328 for (
const auto& rStation : rStations) {
330 const int id = rStation.Id;
332 if (
Is(
id).In(copiedStations) ||
333 (
Is(
id).In(zeroErrorStations) &&
HasError(rStation))) {
335 discardedStations <<
' ' <<
id <<
'(' << rStation.Error <<
')';
340 sDetector.GetStation(
id);
342 missingDStations.insert(
id);
345 auto& dStation = sDetector.GetStation(
id);
347 copiedStations.emplace(
id);
364 const bool isUUB = rStation.IsUUB;
365 const int hasSSD =
const_cast<IoSdStation&
>(rStation).HasSSD();
366 const bool noError = !
HasError(rStation);
370 if (dStation.IsUUB() != isUUB)
396 if (hasSSD || isUUB) {
397 if (!dStation.HasScintillator())
399 }
else if (dStation.HasScintillator() && !oEvent.
HasSimShower())
404 if (!dStation.HasSmallPMT())
406 }
else if (dStation.HasSmallPMT())
411 if (!oSEvent.HasStation(
id))
412 oSEvent.MakeStation(
id);
413 auto& oStation = oSEvent.GetStation(
id);
423 if (!oStation.HasTriggerData())
424 oStation.MakeTriggerData();
426 auto& oStationTrigger = oStation.GetTriggerData();
427 oStationTrigger.SetErrorCode(rStation.Error);
429 const auto& rStationTrigger = rStation.Trigger;
430 oStationTrigger.SetWindowMicroSecond(rStationTrigger.Window);
431 oStationTrigger.SetOffsetMicroSecond(rStationTrigger.Offset);
433 oStationTrigger.SetPLDTrigger(rStationTrigger.Type);
443 oStationTrigger.SetPLDTrigger(pld);
447 if (rStation.T2Life > -1 && rStation.T2Life120 > -1)
448 oStation.SetT2Life(
bool(rStation.T2Life) +
bool(rStation.T2Life120));
450 oStation.SetT2Life(2);
462 const auto*
const rGPS = rStation.Gps;
467 if (!oStation.HasGPSData())
468 oStation.MakeGPSData();
470 auto& oGPS = oStation.GetGPSData();
472 oGPS.SetSecond(rGPS->Second);
473 oGPS.SetTick(rGPS->Tick);
474 oGPS.SetCurrent100(rGPS->Current100);
475 oGPS.SetNext100(rGPS->Next100);
476 oGPS.SetCurrent40(rGPS->Current40);
477 oGPS.SetNext40(rGPS->Next40);
478 oGPS.SetPreviousST(rGPS->PreviousST);
479 oGPS.SetCurrentST(rGPS->CurrentST);
480 oGPS.SetNextST(rGPS->NextST);
481 oGPS.SetOffset(rGPS->Offset);
494 oStation.SetIsCyclone();
497 const auto*
const rCalib = rStation.Calib;
502 <<
"v" << rCalib->Version <<
")"
505 if (!oStation.HasCalibData())
506 oStation.MakeCalibData();
507 auto& oStationCalib = oStation.GetCalibData();
509 const auto& calibVersion = rCalib->Version;
510 oStationCalib.SetVersion(calibVersion);
512 if (rGPS && calibVersion > 12)
513 oStation.GetGPSData().SetTickFall(rGPS->TickFall);
516 oStation.GetGPSData().SetTickFall(rGPS->Tick ? 0 : 1);
523 oStationCalib.SetStartSecond(rCalib->StartSecond);
524 oStationCalib.SetEndSecond(rCalib->EndSecond);
525 oStationCalib.SetNT1(rCalib->NbT1);
526 oStationCalib.SetNT2(rCalib->NbT2);
527 oStationCalib.SetNTot(rCalib->NbTOT);
529 const unsigned int tubeMask = rCalib->TubeMask;
551 int i = oPMT.GetId() - 1;
555 else if (i == hasSSD - 1)
559 if (!oPMT.HasCalibData())
560 oPMT.MakeCalibData();
562 auto& oPMTCalib = oPMT.GetCalibData();
564 if (tubeMask & (1u << i)) {
566 oPMTCalib.SetIsTubeOk(
true);
567 oPMTCalib.SetIsLowGainOk(
true);
576 if (isUUB && calibVersion < 262) {
578 oPMTCalib.SetIsTubeOk(
true);
579 oPMTCalib.SetIsLowGainOk(
true);
581 warn <<
"station " << oStation.GetId() <<
" has calibration version " << calibVersion <<
"; "
582 "PMT id " << oPMT.GetId() <<
" had flag IsTubeOK overwritten with \"true\"";
594 262 <= calibVersion && calibVersion <= 268) {
596 oPMTCalib.SetIsTubeOk(
true);
597 oPMTCalib.SetIsLowGainOk(
true);
599 warn <<
"station " << oStation.GetId() <<
" has calibration version " << calibVersion <<
"; "
600 "SSD PMT flag IsTubeOK was overwritten with \"true\"";
604 warn <<
"station " << oStation.GetId() <<
" has calibration version " << calibVersion <<
"; "
605 "if SSD PMT trace is absent, its IsTubeOK flag is possibly set to \"false\" by CDAS";
615 auto& dPmt = dStation.GetPMT(oPMT.GetId());
617 oPMTCalib.SetGainRatio(dPmt.GetGainRatio(), 0);
618 oPMTCalib.SetOnlinePeak(dPmt.GetNominalVEMPeak());
619 oPMTCalib.SetOnlineCharge(dPmt.GetNominalVEMCharge());
629 if (i >=
int(kIoSd::NPMT))
633 oPMTCalib.SetNumberTDA(rCalib->NbTDA[i]);
634 oPMTCalib.SetEvolution(rCalib->Evolution[i]);
635 oPMTCalib.SetRate(rCalib->Rate[i]);
652 if (rCalib->DA[i] > 0)
653 oPMTCalib.SetGainRatio(rCalib->DA[i], rCalib->SigmaDA[i]);
655 oPMTCalib.SetGainRatio(dPmt.GetGainRatio(), 0);
656 oPMTCalib.SetOnlinePeak(
657 (rCalib->VemPeak[i] > 0) ? rCalib->VemPeak[i] : dPmt.GetNominalVEMPeak()
659 oPMTCalib.SetOnlineCharge(
660 (rCalib->VemCharge[i] > 0) ? rCalib->VemCharge[i] : dPmt.GetNominalVEMCharge()
672 oPMTCalib.SetIsTubeOk(
true);
673 oPMTCalib.SetIsLowGainOk(
true);
674 oPMTCalib.SetOnlinePeak(dPmt.GetNominalVEMPeak());
675 oPMTCalib.SetOnlineCharge(dPmt.GetNominalVEMCharge());
678 warn <<
"PPA station " << oStation.GetId() <<
" had its SSD PMT "
679 "flag IsTubeOK overridden with \"true\" and its online MIP peak and charge "
680 "set to nominal values " << oPMTCalib.GetOnlinePeak() <<
" adc and "
681 << oPMTCalib.GetOnlineCharge() <<
" adct, respectively";
687 if (calibVersion > 12) {
688 oPMTCalib.SetHighGainDelay(rCalib->DADt[i], rCalib->SigmaDADt[i]);
689 oPMTCalib.SetHighGainDelayChi2(rCalib->DAChi2[i]);
691 oPMTCalib.SetHighGainDelay(0, 0);
692 oPMTCalib.SetHighGainDelayChi2(0);
696 oStationCalib.SetNTubesOk(nTubesOK);
700 const IoSdPMQuality*
const rPMQuality = rStation.pmquality();
702 const auto& version = rPMQuality->Version;
703 const auto& tube = rPMQuality->TubeMask;
704 const auto& anode = rPMQuality->AnodeMask;
705 const auto& raining = rPMQuality->RainingMask;
708 int i = oPMT.GetId() - 1;
712 else if (i == hasSSD - 1)
715 if (!oPMT.HasQuality())
717 auto& oPMTQuality = oPMT.GetQuality();
718 oPMTQuality.SetVersion(version);
719 const auto pmtMask = 1 << i;
720 oPMTQuality.SetIsTubeOk(tube & pmtMask);
721 oPMTQuality.SetHasAnode(anode & pmtMask);
722 oPMTQuality.SetIsRaining(~raining & pmtMask);
727 const IoSdHisto*
const rHisto = rStation.Histo;
733 if (!oStation.HasCalibData())
734 oStation.MakeCalibData();
736 auto& oStationCalib = oStation.GetCalibData();
738 const int calibVersion = oStationCalib.GetVersion();
739 if (calibVersion > 8) {
741 vector<int> mch(rHisto->Charge[3], rHisto->Charge[3] + 600);
742 oStationCalib.SetMuonChargeHisto(mch, rHisto->Offset[9]);
751 int i = oPMT.GetId() - 1;
755 else if (i == hasSSD - 1)
759 if (!oPMT.HasCalibData())
760 oPMT.MakeCalibData();
761 auto& oPMTCalib = oPMT.GetCalibData();
768 const vector<int> base(rHisto->Base[i], rHisto->Base[i] + 20);
769 oPMTCalib.SetMuonBaseHisto(base, rHisto->Offset[i]);
771 const vector<int> shape(rHisto->UShape[i], rHisto->UShape[i] + 70);
772 oPMTCalib.SetMuonShapeHisto(shape);
774 const vector<int> peak(rHisto->Peak[i], rHisto->Peak[i] + 150);
775 oPMTCalib.SetMuonPeakHisto(peak, rHisto->Offset[i+3]);
777 const vector<int> charge(rHisto->Charge[i], rHisto->Charge[i] + 600);
778 oPMTCalib.SetMuonChargeHisto(charge, rHisto->Offset[i+6]);
782 const vector<int> base(rHisto->Base3, rHisto->Base3 + 20);
783 oPMTCalib.SetMuonBaseHisto(base, rHisto->Offset3[0]);
785 const vector<int> shape(rHisto->UShape[3], rHisto->UShape[3] + 70);
786 oPMTCalib.SetMuonShapeHisto(shape);
788 const vector<int> peak(rHisto->Peak3, rHisto->Peak3 + 150);
789 oPMTCalib.SetMuonPeakHisto(peak, rHisto->Offset3[1]);
791 const vector<int> charge(rHisto->Charge[3], rHisto->Charge[3] + 600);
792 oPMTCalib.SetMuonChargeHisto(charge, rHisto->Offset3[2]);
795 const vector<int> base(rHisto->Base[i], rHisto->Base[i] + 20);
796 oPMTCalib.SetMuonBaseHisto(base, rHisto->Offset[i]);
798 const unsigned int shapeN = (calibVersion == 13) ? 19 : 20;
799 const vector<int> shape(rHisto->Shape[i], rHisto->Shape[i] + shapeN);
800 oPMTCalib.SetMuonShapeHisto(shape);
802 const vector<int> peak(rHisto->Peak[i], rHisto->Peak[i] + 150);
803 oPMTCalib.SetMuonPeakHisto(peak, rHisto->Offset[i+3]);
805 const vector<int> charge(rHisto->Charge[i], rHisto->Charge[i] + 600);
806 oPMTCalib.SetMuonChargeHisto(charge, rHisto->Offset[i+6]);
814 const IoSdFadc*
const rFADC = rStation.Fadc;
822 int i = oPMT.GetId() - 1;
826 else if (i == hasSSD - 1)
829 const auto& trace = rFADC->Trace[i];
831 if (!oPMT.HasFADCTrace()) {
832 oPMT.MakeFADCTrace();
842 if (rStation.UFadc) {
844 const int nSample = rStation.UFadc->NSample;
845 DEBUGRAW(
" upgraded station has-FADC " << flush);
847 int i = oPMT.GetId() - 1;
848 if (!oPMT.HasFADCTrace())
849 oPMT.MakeFADCTrace();
850 for (
int j = 0; j < nGain; ++j) {
851 unsigned short trace[nSample];
852 for (
int k = 0; k < nSample; ++k) {
853 trace[k] = rStation.UFadc->GetValue(i, j, k);
857 ).Adopt(trace, nSample);
868 if (readInRdData && rStation.UFadc->Traces.size() > 20480) {
871 const int nSample = rStation.UFadc->NSample;
872 unsigned int totalParity = 0;
873 for (
int i = 0; i < nSample; ++i) {
874 totalParity += rStation.UFadc->GetValueParity(5, 0, i);
875 totalParity += rStation.UFadc->GetValueParity(5, 1, i);
877 const bool parityOkay = (totalParity == 4096);
882 const unsigned int rdId = rDetector.GetRdSdStationIdLink() + id;
885 if (!rdEvent.HasStation(rdId))
888 auto& rdStation = rdEvent.GetStation(rdId);
889 if (!rdStation.HasTriggerData())
890 rdStation.MakeTriggerData();
892 if (!rdStation.HasGPSData())
893 rdStation.MakeGPSData();
896 auto& gps = rdStation.GetGPSData();
897 gps.SetSecond(rGPS->Second);
898 gps.SetCorrectedNanosecond(oStation.GetGPSData().GetCorrectedNanosecond());
900 const utl::TimeStamp ts(gps.GetSecond(), gps.GetCorrectedNanosecond());
902 const double fadcBinSize = dStation.GetFADCBinSize();
904 const auto& rdetStation = rDetector.GetStation(rdStation);
911 for (
int chId = 0; chId < rdetStation.GetNChannels(); ++chId) {
912 auto& chan = rdStation.GetChannel(chId);
914 auto& trace = chan.GetChannelADCTimeSeries();
916 const auto& rdetChannel = rdetStation.GetChannel(chId);
917 const double samplingfreq = rdetChannel.GetSamplingFrequency();
918 trace.SetBinning(1 / samplingfreq);
920 unsigned int parityChannel = 0;
921 for (
int i = 0; i < nSample; ++i) {
922 const double val = rStation.UFadc->GetValueRd(5, chId, i);
924 parityChannel += rStation.UFadc->GetValueParity(5, chId, i);
926 chan.SetParity(parityChannel);
929 rdStation.SetRawTraceStartTime(traceTime);
934 err <<
"Wrong parity count for traces of RD station " << rdId
935 <<
". Excluded it from reconstruction.";
945 const auto dis = discardedStations.str();
947 discardedStations.str(
"");
948 discardedStations <<
"Discarded duplicated stations:" << dis;
949 INFO(discardedStations);
953 if (!missingDStations.empty()) {
957 <<
" missing from the SD detector description, not including.";
961 oTrigger.SetNStations(copiedStations.size());
963 DEBUGRAW(
" PullEventRaw - IoSdEvent (END) " << endl);
978 DEBUGRAW(
" PushEventRaw - IoSdEvent " << endl);
981 ERROR(
"Non-existent evt::SEvent class object.");
988 ERROR(
"Non-existent central trigger in event.");
995 rawSEvent.Id = header.
GetId();
998 IoSdT3Trigger& reTrigger = rawSEvent.Trigger;
1000 reTrigger.Id = trigger.
GetId();
1013 const sdet::SDetector& theSDetector = det::Detector::GetInstance().GetSDetector();
1017 csIt != stationsEnd; ++csIt) {
1019 const int sdId = csIt->GetId();
1020 const bool isUUB = csIt->IsUUB();
1022 IoSdStation rawStation;
1023 rawStation.Id = sdId;
1024 rawStation.IsUUB = isUUB;
1028 rawStation.Name = theSDetector.
GetStation(csIt->GetId()).GetName();
1032 boost::tie(rawStation.Northing, rawStation.Easting, rawStation.Altitude) =
1039 DEBUGRAW(
" raw-station: " << setw(4) << rawStation.Id
1040 <<
" is not available in Offline. ... " << endl);
1044 rawStation.Name =
"unkown by Offline";
1045 rawStation.Northing = 0;
1046 rawStation.Easting = 0;
1047 rawStation.Altitude = 0;
1051 DEBUGRAW(
" raw-station: " << setw(4) << rawStation.Id
1052 <<
" " << setw (20) << left << rawStation.Name);
1054 if (csIt->HasTriggerData()) {
1056 DEBUGRAW(
" has-trig-data " << flush);
1060 IoSdT2Trigger& rTrigger = rawStation.Trigger;
1068 DEBUGRAW(
" Ecode " << rawStation.Error << flush);
1072 IoSdFadc*
const rfadc = rawStation.Fadc =
new IoSdFadc;
1074 rfadc->NSample = theSDetector.
GetStation(csIt->GetId()).GetFADCTraceLength();
1076 for (
unsigned int i = 0; i < 3; ++i) {
1078 const PMT& pmt = csIt->GetPMT(i+1);
1083 Short_t*
const rTraceHigh = rfadc->Trace[i][IoSdEvent::eHigh];
1088 hIt != traceHighEnd && j < kIoSd::MAXSAMPLE; ++hIt, ++j)
1089 rTraceHigh[j] = Short_t(*hIt);
1092 Short_t*
const rTraceLow = rfadc->Trace[i][IoSdEvent::eLow];
1097 lIt != traceLowEnd && j < kIoSd::MAXSAMPLE; ++lIt, ++j)
1098 rTraceLow[j] = Short_t(*lIt);
1107 if (csIt->HasGPSData()) {
1109 DEBUGRAW(
" has-gps-data " << flush);
1111 IoSdGps*
const rgps = rawStation.Gps =
new IoSdGps;
1131 if (csIt->HasCalibData()) {
1133 DEBUGRAW(
" has-cal-data " << flush);
1137 IoSdCalib*
const rcalib = rawStation.Calib =
new IoSdCalib;
1144 rcalib->NbT1 = calib.
GetNT1();
1145 rcalib->NbT2 = calib.
GetNT2();
1146 rcalib->NbTOT = calib.
GetNTot();
1147 rcalib->TubeMask = 0;
1149 for (
unsigned int i = 0; i < kIoSd::NPMT; ++i) {
1152 const PMT& pmt = csIt->GetPMT(i+1);
1158 if (pmtCalib.IsTubeOk())
1159 rcalib->TubeMask |= (1
U << i);
1161 rcalib->NbTDA[i] = UShort_t(pmtCalib.GetNumberTDA());
1163 rcalib->Rate[i] = pmtCalib.GetRate();
1164 rcalib->VemCharge[i] = pmtCalib.GetOnlineCharge();
1165 rcalib->VemPeak[i] = pmtCalib.GetOnlinePeak();
1166 rcalib->Base[i] = pmtCalib.GetBaseline();
1168 rcalib->SigmaBase[i] = pmtCalib.GetBaselineRMS();
1170 rcalib->DA[i] = pmtCalib.GetGainRatio();
1171 rcalib->SigmaDA[i] = pmtCalib.GetGainRatioRMS();
1174 rcalib->DADt[i] = pmtCalib.GetHighGainDelay();
1175 rcalib->SigmaDADt[i] = pmtCalib.GetHighGainDelayRMS();
1176 rcalib->DAChi2[i] = pmtCalib.GetHighGainDelayChi2();
1179 rcalib->DADt[i] = 0;
1180 rcalib->SigmaDADt[i] = 0;
1181 rcalib->DAChi2[i] = 0;
1185 rcalib->TubeOk[i] = bool(rawStation.calib()->TubeMask & (1
U << i));
1192 rcalib->NTubesOk = rcalib->TubeOk[0] + rcalib->TubeOk[1] + rcalib->TubeOk[2];
1198 IoSdHisto*
const rhisto = rawStation.Histo =
new IoSdHisto;
1202 "Muon charge (sum)");
1210 for (
unsigned int i = 0; i < kIoSd::NPMT; ++i) {
1212 const PMT& pmt = csIt->GetPMT(i+1);
1223 ConditionalCopy(shape, rhisto->Shape[i], kIoSd::SINGLE_MUON_SIZE,
"Muon shape histogram");
1230 ConditionalCopy(mch, rhisto->Charge[i], 600,
"Muon charge histogram");
1239 const PMT& pmt = csIt->GetScintillatorPMT();
1250 ConditionalCopy(shape, rhisto->UShape[3], 70,
"Muon shape histogram");
1257 ConditionalCopy(mch, rhisto->Charge[3], 600,
"Muon charge histogram");
1267 rawSEvent.Stations.push_back(rawStation);
1275 DEBUGRAW(
" PushEventRaw - IoSdEvent (DONE)" << endl);
1284 DEBUGEC(
" PushEventEc - TEcEvent" << endl);
1287 event >> (IoSdEvent&)ec;
1296 ERROR (
"Non-existent evt::SEvent class object.");
1308 const Point refPoint(0,0,0, pampaCS);
1309 const UTMPoint refPointUTM(refPoint, wgs84);
1312 theEc.fRefEasting = refPointUTM.
GetEasting();
1314 DEBUGEC(
" Reference Point: northing " << theEc.fRefNorthing
1315 <<
" easting " << theEc.fRefEasting << endl);
1320 csIt != stationsEnd; ++csIt) {
1322 const unsigned int stationID = csIt->GetId();
1325 det::Detector::GetInstance().GetSDetector().GetStation(stationID);
1327 DEBUGEC(
" cal-station: " << setw(4) << stationID);
1329 vector<IoSdStation>& rStations = theEc.Stations;
1331 vector<IoSdStation>::const_iterator iRawStation = rStations.begin();
1332 for ( ; iRawStation != rStations.end(); ++iRawStation)
1333 if (iRawStation->Id == stationID)
1336 if (iRawStation == rStations.end()) {
1338 err <<
"Raw station " << stationID <<
" not found in raw event!"
1339 " DPA->CDAS conversion not possible!";
1344 if (!csIt->HasCalibData() || !csIt->HasRecData()) {
1348 if (!iRawStation->Error) {
1350 warn <<
"Raw station " << stationID <<
" has error-code "
1351 << iRawStation->Error <<
" but is not calibrated!"
1352 " (HasCalibData: " << csIt->HasCalibData() <<
")"
1353 " (HasRecData: " << csIt->HasRecData() <<
')'
1357 theEc.fCalibStations.push_back(*iRawStation);
1359 DEBUGEC(
"NO-cal-data. SKIP" << endl);
1365 const auto& stationCalib = csIt->GetCalibData();
1366 const auto& stationRec = csIt->GetRecData();
1369 TCalibStation cdasCal(*iRawStation);
1371 DEBUGEC(
"pos: north " << cdasCal.Northing/
m
1372 <<
" east " << cdasCal.Easting/
m
1373 <<
" alti " << cdasCal.Altitude/
m << endl);
1377 const UTMPoint stationPosUTM(cdasCal.Northing,
1384 cdasCal.fRefSecond = theEc.Trigger.Second;
1385 cdasCal.fX = stationPos.
GetX(refCS)/
m;
1386 cdasCal.fY = stationPos.
GetY(refCS)/
m;
1387 cdasCal.fZ = stationPos.
GetZ(refCS)/
m;
1390 cdasCal.fLatitude = latLonH.get<0>()/
deg;
1391 cdasCal.fLongitude = latLonH.get<1>()/
deg;
1393 int nSaturatedPMTs = 0;
1394 for (
unsigned int iPMT = 0; iPMT < kIoSd::NPMT; ++iPMT) {
1396 if (!csIt->HasPMT(iPMT+1)) {
1398 err <<
"Raw station " << stationID <<
" has no PMT #" << iPMT+1 <<
"!"
1399 " CDAS event might be currupted!";
1404 const PMT& pmt = csIt->GetPMT(iPMT+1);
1407 err <<
"Raw station " << stationID <<
" PMT #" << iPMT+1
1408 <<
" has no calib/rec data!" ;
1416 TCalibSdPmt& pmti = cdasCal.fPmt[iPMT];
1420 int nBinsSaturatedHighGain = 0;
1421 int nBinsSaturatedLowGain = 0;
1428 const unsigned int vemTraceSize = vemTrace.
GetSize();
1430 for (
unsigned int iTraceBin = 0; iTraceBin < kIoSd::MAXSAMPLE; ++iTraceBin) {
1432 pmti.fTrace[iTraceBin] = (iTraceBin < vemTraceSize) ? vemTrace[iTraceBin] : 0;
1434 if (lowTrace[iTraceBin] >=
int(saturationValue))
1435 ++nBinsSaturatedLowGain;
1437 if (highTrace[iTraceBin] >=
int(saturationValue))
1438 ++nBinsSaturatedHighGain;
1444 const int start = stationRec.GetSignalStartSlot();
1445 const int end = stationRec.GetSignalEndSlot();
1446 pmti.fT90 = TraceAlgorithm::TimeAtRelativeSignalX(vemTrace, start, end, 90)/
ns;
1447 pmti.fT70 = TraceAlgorithm::TimeAtRelativeSignalX(vemTrace, start, end, 70)/
ns;
1448 pmti.fT50 = TraceAlgorithm::TimeAtRelativeSignalX(vemTrace, start, end, 50)/
ns;
1449 pmti.fT10 = TraceAlgorithm::TimeAtRelativeSignalX(vemTrace, start, end, 10)/
ns;
1452 pmti.fStartIntegration = start;
1453 pmti.fEndIntegration = end;
1458 pmti.fHighGainSat = nBinsSaturatedHighGain;
1459 pmti.fLowGainSat = nBinsSaturatedLowGain;
1462 pmti.fCalibratedState = 3;
1477 pmti.fPmtBaselineSigma = 0;
1490 if (csIt->HasVEMTrace()) {
1492 const int start = stationRec.GetSignalStartSlot();
1493 const int end = stationRec.GetSignalEndSlot();
1494 const TraceD& vemTrace = csIt->GetVEMTrace();
1496 cdasCal.fT90 = TraceAlgorithm::TimeAtRelativeSignalX(vemTrace, start, end, 90)/
ns;
1497 cdasCal.fT70 = TraceAlgorithm::TimeAtRelativeSignalX(vemTrace, start, end, 70)/
ns;
1498 cdasCal.fT50 = TraceAlgorithm::TimeAtRelativeSignalX(vemTrace, start, end, 50)/
ns;
1499 cdasCal.fT10 = TraceAlgorithm::TimeAtRelativeSignalX(vemTrace, start, end, 10)/
ns;
1501 cdasCal.fSigInVEM = stationRec.GetTotalSignal();
1502 cdasCal.fPeakInVEM = stationRec.GetPeakAmplitude();
1504 cdasCal.fStartIntegration = start;
1505 cdasCal.fEndIntegration = end;
1522 cdasCal.fPmTStatus = stationCalib.GetNTubesOk();
1523 cdasCal.fSat = nSaturatedPMTs;
1526 cdasCal.fStartBin = cdasCal.fStartIntegration;
1528 cdasCal.fSeveralSignals = 0;
1538 theEc.fCalibStations.push_back(cdasCal);
1542 theEc.fNCalibStations = theEc.fCalibStations.size();
1544 DEBUGEC(
" PushEventEc - TEcEvent (DONE) " << endl);
1552 DEBUGEC(
" PullEventEc - TEcEvent " << endl);
1555 event << (IoSdEvent&)ec;
1563 auto& oSEvent =
event.GetSEvent();
1568 const Point refPoint(0,0,0, pampaCS);
1569 const double refHeight = wgs84.PointToLatitudeLongitudeHeight(refPoint).get<2>();
1570 const UTMPoint cdasRefPointUTM(ec.fRefNorthing, ec.fRefEasting, refHeight, 19,
'H', wgs84);
1572 const auto& cdasRefCS = LocalCoordinateSystem::Create(cdasRefPointUTM);
1574 DEBUGEC(
" Reference Point: north/east/alt " << ec.fRefNorthing <<
'/'
1575 << ec.fRefEasting <<
'/' << refHeight << endl);
1577 bool firstMsg =
true;
1579 for (
auto iCDASCalStation = ec.fCalibStations.begin(); iCDASCalStation != ec.fCalibStations.end(); ++iCDASCalStation) {
1581 const unsigned int stationID = iCDASCalStation->id();
1582 const int errorCode = iCDASCalStation->Error && 0xff;
1584 if (!oSEvent.HasStation(stationID)) {
1586 err <<
"Missing station " << stationID <<
" in event!";
1591 auto& oStation = oSEvent.GetStation(stationID);
1594 if (errorCode == 2 && iCDASCalStation->Trigger.Window) {
1595 oStation.SetSilent();
1599 if (!oStation.HasCalibData())
1600 oStation.MakeCalibData();
1602 auto& oStationCalib = oStation.GetCalibData();
1604 if (!oStation.HasGPSData()) {
1605 ERROR(
"Raw station with signal, but without GPS data !");
1606 oStation.MakeGPSData();
1608 auto& gpsData = oStation.GetGPSData();
1610 if (oStation.HasRecData() && firstMsg) {
1611 ERROR (
"The SEvent should be completely cleared before refilling!");
1614 oStation.MakeRecData();
1616 auto& oStationRec = oStation.GetRecData();
1618 DEBUGEC(
"cal-station: " << setw(4) << stationID);
1620 const auto& sDetector = det::Detector::GetInstance().GetSDetector();
1622 const unsigned int fadcTraceLength = sDetector.GetStation(stationID).GetFADCTraceLength();
1624 const double fadcBinSize = sDetector.GetStation(stationID).GetFADCBinSize();
1626 for (
unsigned int iPMT = 0; iPMT < kIoSd::NPMT; ++iPMT) {
1628 if (!oStation.HasPMT(iPMT+1)) {
1630 err <<
"PMT " << iPMT+1 <<
" missing in station " << stationID <<
"!";
1634 auto& oPMT = oStation.GetPMT(iPMT+1);
1636 if (!oPMT.HasRecData())
1638 auto& oPMTRec = oPMT.GetRecData();
1640 if (!oPMTRec.HasVEMTrace())
1641 oPMTRec.MakeVEMTrace();
1642 auto& oPMTRecTrace = oPMTRec.GetVEMTrace();
1644 const auto& pmt = iCDASCalStation->fPmt[iPMT];
1647 oPMTRecTrace =
TraceD(fadcTraceLength, fadcBinSize);
1649 for (
unsigned int iTraceBin = 0; iTraceBin < kIoSd::MAXSAMPLE; ++iTraceBin) {
1650 if (iTraceBin < fadcTraceLength)
1651 oPMTRecTrace[iTraceBin] = pmt.fTrace[iTraceBin];
1653 ERROR(
"Trace out of bounds!");
1657 oPMTRec.SetT50(pmt.T50()*
ns);
1662 oPMTRec.SetTotalCharge(pmt.fSigInVEM);
1663 oPMTRec.SetPeakAmplitude(pmt.fPeakInVEM);
1667 oStation.SetHighGainSaturation(pmt.fHighGainSat);
1668 oStation.SetLowGainSaturation(pmt.fLowGainSat);
1682 TraceD sumTrace(fadcTraceLength, fadcBinSize);
1684 for (
unsigned int iTraceBin = 0; iTraceBin < kIoSd::MAXSAMPLE; ++iTraceBin) {
1685 if (iTraceBin < fadcTraceLength) {
1686 sumTrace[iTraceBin] =
1687 iCDASCalStation->fPmt[0].fTrace[iTraceBin] +
1688 iCDASCalStation->fPmt[1].fTrace[iTraceBin] +
1689 iCDASCalStation->fPmt[2].fTrace[iTraceBin];
1691 ERROR(
"Trace out of bounds!");
1694 if (!oStation.HasVEMTrace())
1695 oStation.MakeVEMTrace();
1696 oStation.GetVEMTrace() = sumTrace;
1699 const TimeStamp gpsTime(gpsData.GetSecond(), gpsData.GetCorrectedNanosecond());
1701 DEBUGEC(
"bin: " << iCDASCalStation->fStartIntegration
1702 <<
" sec " << gpsTime.GetGPSSecond()
1703 <<
" nsec " << gpsTime.GetNanoSecond() << flush);
1708 oStation.SetTraceStartTime(traceTime);
1710 const TimeStamp signalTime = traceTime +
1711 TimeInterval((iCDASCalStation->fStartIntegration - 0.5) * fadcBinSize);
1713 oStationRec.SetSignalStartTime(signalTime);
1716 oStationRec.SetSignalStartSlot(iCDASCalStation->fStartIntegration);
1717 oStationRec.SetSignalEndSlot(iCDASCalStation->fEndIntegration);
1719 oStationRec.SetT50(iCDASCalStation->T50()*
ns, 0.);
1720 oStationRec.SetTotalSignal(iCDASCalStation->fSigInVEM);
1721 oStationRec.SetPeakAmplitude(iCDASCalStation->fPeakInVEM);
1723 oStationCalib.SetNTubesOk(iCDASCalStation->fPmTStatus);
1727 DEBUGEC(
"signal " << iCDASCalStation->fSigInVEM
1728 <<
" peak " << iCDASCalStation->fPeakInVEM
1729 <<
" t50 " << iCDASCalStation->T50()*
ns
1730 <<
" start " << iCDASCalStation->fStartIntegration
1731 <<
" end " << iCDASCalStation->fEndIntegration
1749 DEBUGEC(
" PullEventEc - TEcEvent (END) " << endl);
1757 DEBUGES(
" PushEventEs - TEsEvent " << endl);
1760 event >> (TEcEvent&)es;
1769 ERROR (
"Non-existent evt::SEvent class object.");
1772 const auto& oSEvent =
event.GetSEvent();
1774 auto& calStations = es.fCalibStations;
1775 auto& randomStations = es.fRandomStations;
1776 auto& selectedStations = es.fSelectedStations;
1777 auto& silentStations = es.fSilentStations;
1778 auto& badStations = es.fBadStations;
1780 for (
auto osIt = oSEvent.StationsBegin(), end = oSEvent.StationsEnd(); osIt != end; ++osIt) {
1782 const unsigned int stationID = osIt->GetId();
1784 DEBUGES(
"sel-station: " << setw(4) << stationID);
1787 auto csIt = calStations.begin();
1788 for ( ; csIt != calStations.end(); ++csIt)
1789 if (csIt->Id == stationID)
1792 if (csIt == calStations.end()) {
1794 err <<
"Raw station " << stationID <<
" "
1795 "not found in cdas event (accidental)! "
1796 "DPA->CDAS conversion may not be possible!";
1799 if (osIt->IsRejected()) {
1800 randomStations.push_back(&(*csIt));
1801 DEBUGES(
" accidental" << endl);
1802 }
else if (osIt->IsCandidate()) {
1803 selectedStations.push_back(&(*csIt));
1804 DEBUGES(
" candidate" << endl);
1805 }
else if (osIt->IsSilent()) {
1806 silentStations.push_back(&(*csIt));
1810 badStations.push_back(&(*csIt));
1818 if (!event.
HasRecShower() || !
event.GetRecShower().HasSRecShower()) {
1819 ERROR(
"No Seed triangle available!");
1823 const auto& showerRec =
event.GetRecShower();
1824 const auto& showerSRec = showerRec.GetSRecShower();
1825 const auto& seed = showerSRec.GetReconstructionSeed();
1827 DEBUGES(
"Mark SEED stations: ");
1829 for (
auto seedIt = seed.begin(); seedIt != seed.end(); ++seedIt) {
1832 auto sIt = calStations.begin();
1833 for ( ; sIt != calStations.end(); ++sIt)
1834 if (
int(sIt->Id) == *seedIt)
1837 if (sIt == calStations.end()) {
1839 err <<
"Calib station " << *seedIt
1840 <<
" not found in cdas event!"
1841 " DPA->CDAS conversion not possible!";
1846 sIt->Trigger.Type |= 0x400;
1867 const auto& axis = showerSRec.GetSeedAxis();
1868 const auto& core = showerSRec.GetSeedBarycenter();
1870 auto& estimated = es.fEstimated;
1872 estimated.fGPSSecond = es.Trigger.Second;
1873 estimated.fU = sin(axis.GetTheta(cdasRefCS)) * cos(axis.GetPhi(cdasRefCS));
1874 estimated.fV = sin(axis.GetTheta(cdasRefCS)) * sin(axis.GetPhi(cdasRefCS));
1875 estimated.fXCore = core.GetX(cdasRefCS)/
m;
1876 estimated.fYCore = core.GetY(cdasRefCS)/
m;
1877 estimated.fZCore = core.GetZ(cdasRefCS)/
m;
1879 DEBUGES(
" PushEventEs - TEsEvent (END) " << endl);
1887 DEBUGES(
"PullEventEs - TEsEvent" << endl);
1889 event << (TEcEvent&)es;
1897 auto& oSEvent =
event.GetSEvent();
1907 const auto& selectedStations = es.fSelectedStations;
1908 for (
auto sIt = selectedStations.begin(); sIt != selectedStations.end(); ++sIt) {
1910 const auto*
const cStat = *sIt;
1911 const unsigned int sId = cStat->id();
1913 DEBUGES(
"sel-station: " << setw (4) << sId);
1916 if (cStat->Trigger.Type & 0x400) {
1917 seed.push_back(sId);
1921 if (!oSEvent.HasStation(sId)) {
1922 ERROR(
"SelectedStations: Can't use Event Selection with DPA Event not completely set.");
1924 oSEvent.GetStation(sId).SetCandidate();
1925 DEBUGES(
" candidate" << endl);
1931 for (
const auto rs : es.fRandomStations) {
1933 const unsigned int sId = rs->id();
1935 DEBUGES(
"sel-station: " << setw (4) << sId);
1937 if (!oSEvent.HasStation(sId)) {
1938 ERROR(
"RandomStations: Can't use Event Selection with DPA Event not completely set.");
1941 DEBUGES(
" accidental" << endl);
1947 for (
const auto bs : es.fBadStations) {
1949 const unsigned int sId = bs->id();
1951 DEBUGES(
"sel-station: " << setw (4) << sId <<
" bad" << endl);
1953 if (oSEvent.HasStation(sId))
1954 oSEvent.GetStation(sId).SetSilent();
1959 for (
const auto ss : es.fSilentStations) {
1961 const unsigned int sId = ss->id();
1963 DEBUGES(
"sel-station: " << setw(4) << sId);
1965 if (!oSEvent.HasStation(sId)) {
1966 ERROR(
"SilentStations: Can't use Event Selection with DPA Event not completely set.");
1968 oSEvent.GetStation(sId).SetSilent();
1978 auto& showerRec =
event.GetRecShower();
1980 if (!showerRec.HasSRecShower())
1981 showerRec.MakeSRecShower();
1983 auto& srecData = showerRec.GetSRecShower();
1985 if (seed.size() != 3
U)
1987 srecData.SetReconstructionSeed(seed);
1989 srecData.SetT4Trigger(const_cast<TEsEvent&>(es).IsT4());
1990 srecData.SetT5Trigger(const_cast<TEsEvent&>(es).IsT5());
1995 const auto& estimated = es.fEstimated;
1997 const double u = estimated.fU;
1998 const double v = estimated.fV;
2001 const Point core(estimated.fXCore*
m,
2003 estimated.fZCore*
m, cdasRefCS);
2004 const Vector axis(u, v, w, cdasRefCS);
2006 srecData.SetSeedAxis(axis);
2007 srecData.SetSeedBarycenter(core);
2009 DEBUGES(
"PullEventEs - TEsEvent (END) " << endl);
2018 DEBUGER(
" PushEventEr - TErEvent " << endl);
2021 event >> (TEsEvent&)er;
2046 TShowerParams& cRec = theEr.fRec;
2049 cRec.fGPSSecond = time.GetGPSSecond();
2051 const auto& core = showerSRec.GetCorePosition();
2052 const auto& axis = showerSRec.GetAxis();
2053 const auto& localCS = LocalCoordinateSystem::Create(core);
2055 cRec.fU = axis.GetX(localCS);
2056 cRec.fV = axis.GetY(localCS);
2058 cRec.fXCore = core.GetX(siteCS)/
m;
2059 cRec.fYCore = core.GetY(siteCS)/
m;
2060 cRec.fZCore = core.GetZ(siteCS)/
m;
2062 cRec.fSRef = showerSRec.GetShowerSize();
2063 switch (showerSRec.GetShowerSizeType()) {
2065 cRec.fRefDist = 1000;
2068 cRec.fRefDist = 450;
2072 msg <<
"Could not determine the reference distance for shower size."
2073 "ShowerSizeType = " << showerSRec.GetShowerSizeType();
2080 double xMaxError = 0;
2081 if (showerRec.HasFRecShower() &&
2082 showerRec.GetFRecShower().HasGHParameters()) {
2088 cRec.fXmax = xMax/(
g/
cm2);
2090 const double curv = showerSRec.GetCurvature()*
m;
2091 cRec.fR = (curv ? 1/curv : 0);
2094 cRec.fChi2 = showerSRec.GetLDFChi2();
2095 cRec.frChi2 = showerSRec.GetLDFChi2()/showerSRec.GetLDFNdof();
2096 cRec.fddl = showerSRec.GetLDFNdof();
2099 cRec.fBeta = showerSRec.GetBeta();
2100 cRec.fGamma = showerSRec.GetGamma();
2103 cRec.fE = showerSRec.GetEnergy()/
EeV;
2104 cRec.fdE = showerSRec.GetEnergyError()/
EeV;
2107 for (
int i = 0; i < 8; ++i)
2108 for (
int j = 0; j < 8; ++j)
2109 cRec.fVarCov[i][j] = 0;
2111 const double theta = axis.GetTheta(localCS);
2112 const double sinTheta = sin(theta);
2113 const double cosTheta = cos(theta);
2114 const double phi = axis.GetPhi(localCS);
2115 const double sinPhi = sin(phi);
2116 const double cosPhi = cos(phi);
2118 cRec.fVarCov[0][0] =
Sqr(showerSRec.GetCoreTimeError().GetNanoSecond());
2119 cRec.fVarCov[1][1] =
Sqr(showerSRec.GetThetaError() * cosTheta * cosPhi) -
2120 Sqr(showerSRec.GetPhiError() * sinTheta * sinPhi);
2121 cRec.fVarCov[2][2] =
Sqr(showerSRec.GetThetaError() * cosTheta * sinPhi) +
2122 Sqr(showerSRec.GetPhiError() * sinTheta * cosPhi);
2123 cRec.fVarCov[3][3] =
Sqr(showerSRec.GetCoreError().GetX(localCS)/
m);
2124 cRec.fVarCov[4][4] =
Sqr(showerSRec.GetCoreError().GetY(localCS)/
m);
2125 cRec.fVarCov[5][5] =
Sqr(showerSRec.GetShowerSizeError());
2126 cRec.fVarCov[6][6] =
Sqr(xMaxError/(
g/
cm2));
2127 cRec.fVarCov[7][7] =
Sqr(showerSRec.GetCurvatureError()/
m);
2129 DEBUGER(
"PushEventEr - TErEvent (END) " << endl);
2137 DEBUGER(
" PullEventEr - TErEvent " << endl);
2139 event << (TEsEvent&)er;
2151 auto& recData =
event.GetRecShower();
2153 if (!recData.HasSRecShower())
2154 recData.MakeSRecShower();
2155 auto& srecData = recData.GetSRecShower();
2157 if (!recData.HasFRecShower())
2158 recData.MakeFRecShower();
2159 auto& frecData = recData.GetFRecShower();
2161 const auto& cRec = er.fRec;
2164 const double nsecError =
sqrt(cRec.fVarCov[0][0])*
ns;
2167 const double xError =
sqrt(cRec.fVarCov[3][3])*
m;
2168 const double yError =
sqrt(cRec.fVarCov[4][4])*
m;
2170 const double xMaxError =
sqrt(cRec.fVarCov[6][6])*
g/
cm2;
2171 const double rcError =
sqrt(cRec.fVarCov[7][7])*
m;
2175 if (!frecData.HasGHParameters())
2176 frecData.MakeGHParameters(gh2);
2178 frecData.GetGHParameters() = gh2;
2181 TimeStamp((
unsigned int)(cRec.fGPSSecond),
2182 (
unsigned int)(cRec.fT0));
2184 srecData.SetCoreTime(coreTime, coreTimeErr);
2186 const Point core(cRec.fXCore*
m,
2188 cRec.fZCore*
m, pampaCS);
2189 const Vector coreError(xError, yError, 0, pampaCS);
2190 const auto& localCS = LocalCoordinateSystem::Create(core);
2192 const double u = cRec.fU;
2193 const double v = cRec.fV;
2195 const Vector axis(u,v,w, localCS);
2198 const double thetaError = 0;
2199 const double phiError = 0;
2201 srecData.SetAxis(axis);
2202 srecData.SetCorePosition(core);
2203 srecData.SetCoreError(coreError);
2204 srecData.SetThetaError(thetaError);
2205 srecData.SetPhiError(phiError);
2207 srecData.SetShowerSize(cRec.fSRef, cRec.dSRef());
2214 msg <<
"Could not determine the ShowerSizeType "
2215 "CDAS fRefDist = " << cRec.fRefDist << endl;
2220 srecData.SetCurvature(1/(cRec.fR*
m), rcError);
2222 srecData.SetCurvature(0, 0);
2225 srecData.SetLDFChi2(cRec.fChi2, cRec.fddl);
2228 const double betaError = -1;
2229 const double gammaError = -1;
2230 srecData.SetBeta(cRec.fBeta, betaError);
2231 srecData.SetGamma(cRec.fGamma, gammaError);
2234 srecData.SetEnergy(cRec.fE*
EeV, cRec.fdE*
EeV);
2237 srecData.SetNumberOfActiveStations(
int(cRec.fddl));
2244 auto& sevent =
event.GetSEvent();
2247 const auto& calibStations = er.fCalibStations;
2248 for (
auto sIt = calibStations.begin(); sIt != calibStations.end(); ++sIt) {
2250 const unsigned int sId = sIt->id();
2252 if (!sevent.HasStation(sId)) {
2254 err <<
"Missing station " << sId <<
" in event!";
2259 auto& oStation = sevent.GetStation(sId);
2261 if (!oStation.HasRecData())
2262 oStation.MakeRecData();
2264 auto& oStationRec = oStation.GetRecData();
2266 oStationRec.SetSPDistance(sIt->fDist, 0);
2269 oStationRec.SetResidual(sIt->fDt);
2270 oStationRec.SetLDFResidual(sIt->fDt);
2276 DEBUGER(
"PullEventEr - TErEvent (END) " << endl);
2284 DEBUGRAW(
" PullEventRaw - md::Event " << endl);
2302 if (rEvent.HasCounters()) {
2304 msg <<
"Number of Counters: " << rEvent.CountersSize();
2310 const auto& rTrigger = rEvent.GetTrigger();
2311 const unsigned int t3Sec = rTrigger.GetT3Sec();
2312 const unsigned int t3NanoSec = int(rTrigger.GetT3Mic() * 1000);
2313 const auto mdId = rTrigger.GetId();
2314 const auto t3algorithm = rTrigger.GetT3Algorithm();
2316 const TimeStamp mdT3GPS(t3Sec, t3NanoSec);
2319 auto& omHeader = omEvent.GetHeader();
2320 omHeader.SetId(mdId);
2321 omHeader.SetTime(mdT3GPS);
2323 auto& omTrigger = omHeader.GetTrigger();
2324 omTrigger.SetAlgorithm(t3algorithm);
2329 if (!oHeader.GetId().empty())
2330 idss << oHeader.
GetId() <<
"__";
2331 idss <<
"md_" << mdId;
2333 oHeader.SetTime(mdT3GPS);
2334 oHeader.SetId(idss.str());
2336 const auto& mDetector = det::Detector::GetInstance().GetMDetector();
2339 for (
auto cIt = rEvent.CountersBegin(), end = rEvent.CountersEnd(); cIt != end; ++cIt) {
2341 const auto& mdCter = **cIt;
2342 const int cId = mdCter.GetId();
2343 const unsigned int t3delay = mdCter.GetT3Delay();
2344 const size_t mdWindow = mdCter.GetWindow();
2349 const auto& oSEvent = oEvent.
GetSEvent();
2350 if (oSEvent.HasStation(cId)) {
2352 const auto& oStation = oSEvent.
GetStation(cId);
2354 if (oStation.HasTriggerData()) {
2357 sdWindow = oStationTrigger.GetWindowMicroSecond();
2361 if (!omEvent.HasCounter(cId))
2362 omEvent.MakeCounter(cId);
2365 auto& oCounter = omEvent.GetCounter(cId);
2366 const auto& mdetCounter = mDetector.GetCounter(cId);
2368 for (
auto mIt = mdCter.ModulesBegin(), end = mdCter.ModulesEnd(); mIt != end; ++mIt) {
2370 const auto& mdMod = **mIt;
2371 const int mId = mdMod.GetId();
2373 if (!oCounter.HasModule(mId))
2374 oCounter.MakeModule(mId);
2377 auto& oModule = oCounter.GetModule(mId);
2380 const auto& mdetModule = mdetCounter.GetModule(mId);
2383 msg <<
"Counter " << oCounter.GetId() <<
" module " << oModule.GetId() <<
" is ";
2385 std::ostringstream errorFlag;
2386 errorFlag <<
"SDError:" << sdError <<
":SDWindow:"<< sdWindow <<
":MDWindow:" << mdWindow;
2388 if (t3delay == (
unsigned int)(-1)) {
2390 errorFlag <<
":T3NotFound";
2392 if (sdError == 2 && sdWindow != 0) {
2393 oModule.SetSilent();
2394 msg <<
"silent because \"" << errorFlag.str() <<
"\".";
2396 oModule.SetRejected(errorFlag.str());
2397 msg <<
"rejected because \"" << errorFlag.str() <<
"\".";
2401 }
else if (!mdMod.HasT1()) {
2402 errorFlag <<
":T1NotFound";
2403 oModule.SetRejected(errorFlag.str());
2404 msg <<
"rejected because \"" << errorFlag.str() <<
"\".";
2407 }
else if (sdError != 0 && sdError != 256) {
2408 errorFlag <<
":T1Found";
2409 oModule.SetRejected(errorFlag.str());
2410 msg <<
"rejected because \"" << errorFlag.str() <<
"\".";
2414 msg <<
"candidate.";
2415 oModule.SetCandidate();
2418 const auto mdmask = mdetModule.IsSiPM() ?
2419 mdetModule.GetFrontEndSiPM().GetMask() : mdetModule.GetFrontEnd().GetMask();
2421 const bitset<64> bit_mask = mdmask;
2422 oModule.SetChannelMask(bit_mask);
2424 const auto& dyn = (*mIt)->GetIntegrator();
2426 INFO(
"*** This module has dynode-integrated signal ***");
2427 if (!oModule.HasDynodeTrace())
2428 oModule.MakeDynodeTrace();
2429 auto& oDynodeTrace = oModule.GetDynodeTrace();
2430 oDynodeTrace.Assign(dyn.begin(), dyn.end());
2433 const auto& integratorA = (*mIt)->GetIntegratorA();
2434 if (!integratorA.empty()) {
2435 INFO(
"*** This module has dynode-integrated signal for SiPM electronics ***");
2436 if (!oModule.HasIntegratorATrace())
2437 oModule.MakeIntegratorATrace();
2438 auto& oIntegratorATrace = oModule.GetIntegratorATrace();
2439 oIntegratorATrace.Assign(integratorA.begin(), integratorA.end());
2441 if (!oModule.HasIntegratorBTrace())
2442 oModule.MakeIntegratorBTrace();
2443 auto& oIntegratorBTrace = oModule.GetIntegratorBTrace();
2444 const auto& integratorB = (*mIt)->GetIntegratorB();
2445 oIntegratorBTrace.Assign(integratorB.begin(), integratorB.end());
2449 for (
unsigned int bit = 0, chId = 1; bit < 64; ++bit, ++chId) {
2451 if (!oModule.HasChannel(chId))
2452 oModule.MakeChannel(chId);
2456 oChannel.
SetMask(bit_mask[chId-1]);
2467 const unsigned int numberOfSamples = mdetModule.IsSiPM() ?
2468 mdetModule.GetFrontEndSiPM().GetBufferLength() :
2469 mdetModule.GetFrontEnd().GetBufferLength();
2481 auto rawsigIt = mdMod.RawSignalBegin();
2482 for (
unsigned int nTimeBin = 0; nTimeBin < numberOfSamples; ++nTimeBin) {
2484 if (rawsigIt != mdMod.RawSignalEnd() && nTimeBin == (*rawsigIt)->GetTimeBin()) {
2486 const bitset<64> bc = (*rawsigIt)->GetSample();
2489 msg << setw(10) << setfill(
' ')
2492 " ==> (" << bc.count() <<
")\n";
2496 for (
unsigned int bit = 0, chId = 1, n = bc.size(); bit < n; ++bit, ++chId) {
2503 if (!trace.GetStart() && bc[bit])
2508 trace.SetStop(nTimeBin);
2511 trace.PushBack(
bool(bc[bit]));
2520 for (
unsigned int bit = 0, chId = 1; bit < 64; ++bit, ++chId) {
2577 const unsigned int tick = gpsData.
GetTick();
2582 const unsigned int tickFall = gpsData.
GetTickFall();
2586 (
unsigned int)((tick * (1e9 + nextST - currentST) / next100) + currentST +
2587 0.01 * short(offset & 0xffff)) - 100 * (tickFall == tick);
void operator>>(const Event &theEvent, IoSdEvent &rawSEvent)
void SetStop(const SizeType stop)
Set valid data stop bin.
StationIterator StationsEnd()
End of all stations.
utl::TraceD & GetVEMTrace(const StationConstants::SignalComponent source=StationConstants::eTotal)
Traces calibrated in VEM Peak.
double GetTotalCharge() const
Total charge.
bool HasRecData() const
Check for existenc of PMT reconstructed data object.
constexpr T Sqr(const T &x)
mevt::MEvent & GetMEvent()
class to hold data at PMT level
double GetBaselineRMS(const sdet::PMTConstants::PMTGain gain=sdet::PMTConstants::eHighGain) const
static const std::set< int > gCycloneYears({2007, 2008, 2009})
int GetOffsetMicroSecond() const
IsProxy< T > Is(const T &x)
Detector description interface for Station-related data.
evt::Header & GetHeader()
PMTCalibData & GetCalibData()
Get object containing PMT calibration data.
void ConvertEsToEvent(evt::Event &event, const TEsEvent &es)
int GetCurrent100() const
bool HasRecShower() const
Interface class to access to the SD part of an event.
const std::vector< int > & GetMuonChargeHisto() const
histogram of the sum of muon charges (not really used anywhere)
void ConvertIoSdToEvent(evt::Event &oEvent, const IoSdEvent &rEvent)
Class to hold and convert a point in geodetic coordinates.
int GetMuonPeakHistoOffset() const
x-axis offset of the muon peak histogram
unsigned int GetNT1() const
number of T1 received during calibration
PMTRecData & GetRecData()
Get object containing PMT reconstructed data.
ShowerRecData & GetRecShower()
bool HasCalibData() const
Check for existence of PMT calibration data object.
const std::vector< int > & GetMuonChargeHisto() const
Muon charge histogram.
bool HasSimShower() const
unsigned int GetId() const
Get Id of the trigger.
EventTrigger & GetTrigger()
Get the object with central trigger data, throw if n.a.
unsigned int GetSecond() const
Get end of traces raw time.
void ConvertEventToEc(const evt::Event &theEvent, TEcEvent &theEc)
void SetXMax(const double xMax, const double error)
#define INFO(message)
Macro for logging informational messages.
const std::vector< int > & GetMuonPeakHisto() const
Muon peak histogram.
unsigned int GetNT2() const
number of T2 received during calibration
void UpdateElectronics(const bool isUUB) const
revt::REvent & GetREvent()
Base class for exceptions trying to access non-existing components.
bool HasMDetectorConfig(const bool printMsg=false)
const std::string & GetAlgorithmName() const
const std::vector< int > & GetMuonShapeHisto() const
Average shape of a muon.
unsigned int GetPreviousId() const
Get Id of the FD trigger that contains data for this event.
double GetNorthing() const
Get the northing.
void ApplyTimeCorrection(StationGPSData &gpsData)
const std::vector< int > & GetMuonBaseHisto() const
Muon base histogram.
void FillMdTraces(const md::Module &mdMod, mevt::Module &oModule, unsigned int numberOfSamples)
ShowerSRecData & GetSRecShower()
std::vector< int >::const_iterator ConstIterator
double GetXMaxError() const
void MakeScintillator() const
A TimeStamp holds GPS second and nanosecond for some event.
const char * Plural(const T n)
unsigned int GetTick() const
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
bool HasFADCTrace(const StationConstants::SignalComponent source=StationConstants::eTotal) const
Check if a FADC trace exists. Trace source may be specified.
void ConvertEventToIoMd(const evt::Event &, md::Event &)
int GetMuonChargeHistoOffset() const
x axis offset of the combined charge histogram
Reference ellipsoids for UTM transformations.
class to hold reconstructed data at PMT level
void operator<<(Event &event, const IoSdEvent &rawEvent)
grabs the data of an IoSdEvent and stores it in evt::Event
int GetOffset() const
Get GPS offset compared to a reference.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
unsigned int GetSaturationValue() const
Interface class to access the Event Trigger (T3)
void MakeSmallPMT() const
constexpr double nanosecond
const utl::TimeStamp & GetCoreTime() const
time when shower front passes through the core point
#define DEBUGLOG(message)
Macro for logging debugging messages.
void ConditionalCopy(const T1 &src, T2 *const dst, const unsigned int dstSize, const string &what)
void ConvertEventToEs(const evt::Event &event, TEsEvent &es)
Header & GetHeader()
access to REvent Header
void SetStart(const SizeType start)
Set valid data start bin.
bool HasTrigger() const
check whether the central trigger object exists
void MakeTrigger()
Create the central trigger object.
Triple PointToLatitudeLongitudeHeight(const Point &thePoint) const
Convert Point to Lat/Long/Height.
Channel & GetChannel(const int cId)
void RemoveSmallPMT() const
double GetEasting() const
Get the easting.
void ConvertErToEvent(evt::Event &event, const TErEvent &er)
void ConvertEventToIoSd(const evt::Event &theEvent, IoSdEvent &rawSEvent)
unsigned int GetNTot() const
total number of triggers recevied during calibration
unsigned int GetCorrectedNanosecond() const
Get corrected trigger nanosecond.
boost::tuple< double, double, double > Triple
Coordinate triple.
int GetNErrorZeroStations() const
Get number of error zero stations (mapped over from IoSdEvent)
#define WARNING(message)
Macro for logging warning messages.
int GetWindowMicroSecond() const
Gaisser Hillas with 4 parameters.
utl::TraceI & GetFADCTrace(const sdet::PMTConstants::PMTGain gain=sdet::PMTConstants::eHighGain, const StationConstants::SignalComponent source=StationConstants::eTotal)
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
int GetPreviousST() const
double GetBaseline(const sdet::PMTConstants::PMTGain gain=sdet::PMTConstants::eHighGain) const
void RemoveScintillator() const
unsigned int GetNStations() const
Get number of stations in the trigger.
double GetY(const CoordinateSystemPtr &coordinateSystem) const
boost::tuple< double, double, double > GetCoordinates3() const
Get norting, easting, and height.
unsigned int GetStartSecond() const
GPS second of start of calibration.
A TimeInterval is used to represent time elapsed between two events.
utl::TimeStamp GetTime() const
Get time of the trigger.
unsigned long GetGPSSecond() const
GPS second.
Unlock(const sdet::Station &station)
double GetGPSNanoSecond() const
GPS nanosecond.
unsigned int GetEndSecond() const
GPS second of end of calibration.
int GetMuonBaseHistoOffset() const
x-axis offset of the muon base histogram
Station Trigger Data description
StationIterator StationsBegin()
Beginning of all stations.
bool HasRDetectorConfig(const bool printMsg=false)
Channel level event data.
Interface class for access to the Gaisser-Hillas parameters.
Detector description interface for SDetector-related data.
void SetCorrectedNanosecond(const unsigned int ns)
Set corrected trigger nanosecond.
int GetVersion() const
version of the onboard calibration
sevt::Header & GetHeader()
bool HasError(const IoSdStation &station)
std::string GetAlgorithm() const
Get algorithm of the trigger.
void ConvertEventToEr(const evt::Event &theEvent, TErEvent &theEr)
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
int GetMuonChargeHistoOffset() const
x-axis offset of the muon charge histogram
sevt::StationTriggerData & GetTriggerData()
Get Trigger data for the station.
const sdet::Station & fStation
string OfSortedIds(vector< int > ids)
double GetOnlineCharge() const
Online estimate of VEM_charge [adc*time_bin].
static const std::set< int > gCycloneStations({600, 610, 620, 627, 630, 648})
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
const Station & GetStation(const int stationId) const
Get station by Station Id.
void PushBack(const T &value)
Insert a single value at the end.
double GetPeakAmplitude() const
Peak Amplitude.
bool HasVEMTrace(const StationConstants::SignalComponent source=StationConstants::eTotal) const
boost::indirect_iterator< InternalConstStationIterator, const Station & > ConstStationIterator
Point GetPoint(const CoordinateSystemPtr &theCS=CoordinateSystemPtr()) const
Get a cartesian point from an UTMPoint.
#define ERROR(message)
Macro for logging error messages.
double GetOnlinePeak() const
Online estimate of VEM_peak [adc].
void ConvertIoMdToEvent(evt::Event &oEvent, const md::Event &rEvent)
void MakeStation(const int stationId)
make a station with specifying Id, throw if invalid stationId
unsigned int GetTickFall() const
bool HasSRecShower() const
sevt::SEvent & GetSEvent()
std::string GetSender() const
Get sender of the trigger.
void ConvertEcToEvent(evt::Event &event, const TEcEvent &ec)
PLDType GetPLDTrigger() const
double GetSDPAngle() const
Get SDPAngle of the trigger.
double GetGainRatio() const