5 #include <utl/ErrorLogger.h>
6 #include <utl/Branch.h>
9 #include <fwk/CentralConfig.h>
10 #include <fwk/LocalCoordinateSystem.h>
12 #include <evt/Event.h>
13 #include <evt/ShowerRecData.h>
14 #include <evt/ShowerSRecData.h>
16 #include <sevt/StationTriggerData.h>
17 #include <sevt/EventTrigger.h>
18 #include <sevt/SortCriteria.h>
20 #include <sdet/SDetector.h>
22 #include <TCdasUtil.h>
35 Point SdTopDownSignalSelectorUGR::fBarycenter;
36 TimeStamp SdTopDownSignalSelectorUGR::fBaryTime;
42 fRejectNonT4Events(false),
50 fNMaxRemovedStations(4)
58 INFO(
"SdTopDownSignalSelectorUGR::Init: INFO:");
61 CentralConfig::GetInstance()->
GetTopBranch(
"SdTopDownSignalSelectorUGR");
70 cerr <<
"WARNING! You specified a non valid Nmin (" <<
fMinSlots <<
"). Should be at least 1. Setting it to default (10 Slots)" << endl;
76 cerr <<
"WARNING! You specified a non valid Smin (" <<
fMinSignal <<
"). Should be bigger than 0. Setting it to default (1 VEMs)" << endl;
82 cerr <<
"WARNING! You specified a negative N0 (" <<
fMingap <<
"). Setting it to 0 slots." << endl;
90 cerr <<
"WARNING! You specified a non valid MinStationSignal (" <<
fMinStSignal <<
"). Should be at least 0. Setting it to 0." << endl;
96 cerr <<
"WARNING! You specified a non valid MinNumberOfStationForSignalCut (" <<
fMinNumberStSignalCut <<
"). Should be at least 0. Setting it to 0." << endl;
102 cerr <<
"WARNING! You specified a non valid AnodeSignalFactor (" <<
fLowFactor <<
"). Should be bigger than 0. Setting it to 1." << endl;
112 cerr <<
"WARNING! You specified a non valid Nmin (" <<
fPreMinSlots <<
"). Should be at least 1. Setting it to default (3 Slots)" << endl;
118 cerr <<
"WARNING! You specified a non valid GAP (" <<
fPreMingap <<
"). Should be at least 0. Setting it to default (3 Slots)" << endl;
124 cerr <<
"WARNING! You specified a non valid PreSmin (" <<
fPreMinSignal <<
"). Should be bigger than 0. Setting it to default (0.8 VEMs)" << endl;
149 CentralConfig::GetInstance()->
GetTopBranch(
"SdCalibrator");
158 ERROR(
"Rise/fall time fractions must be within [0, 1]");
166 ERROR(
"Rise/fall time definition is not in the ascending order");
170 WARNING(
"Rise/Fall Time Fractions can not be readed. Did you use the SdTraceCalibratorOG?\n Using default values");
178 cout <<
" Accidental Signal Rejector parameters: (See GAP 2005-074)\n"
179 "\t Verbosity: " <<
fVerbose <<
"\n"
181 "\t Min Slots (Nmin): " <<
fMinSlots <<
"\n"
182 "\t Min. Signal (Smin): " <<
fMinSignal <<
"\n"
183 "\t Min. GAP (N0): " <<
fMingap <<
"\n"
185 "\tAnode Signal factor: " <<
fLowFactor << endl;
188 cout <<
"\t Reject St. below: " <<
fMinStSignal <<
" VEMs\n"
201 "\t Time Residual Tol.: " <<
kTolRes <<
"\n"
202 "\t M. Time Res. Tol.: " <<
kTolResM <<
"\n"
203 "\t Isolated Dist. 1: " <<
kIsoDist1 <<
"\n"
204 "\t Isolated Dist. 2: " <<
kIsoDist2 <<
"\n"
205 "\t Curvature 0: " <<
kCurv0 <<
"\n"
206 "\t Area Min.: " <<
kAreaMin <<
"\n"
207 "\t Area Max.: " <<
kAreaMax <<
"\n"
209 "\t Dist. Max.: " <<
kDistMax <<
"\n"
210 "\t Isolated Time 1: " <<
kIsoTime1 <<
"\n"
211 "\t Isolated Time 2: " <<
kIsoTime2 << endl;
222 INFO(
"SdTopDownSignalSelectorUGR::Run");
225 INFO(
"Event has not SEvent");
232 cout <<
" Removing non grid stations." << endl;
243 cout <<
" Sorted Stations by signal:" << endl;
246 cout <<
" St: " << sIt->GetId() <<
"\t Signal: " << sIt->GetRecData().GetTotalSignal() <<
" VEMs" << endl;
249 int candidateStations = 0;
252 cout <<
" Station pre-processing... " << endl;
260 if (!sIt->HasTriggerData()) {
262 cout <<
" St: " << sIt->GetId() <<
" -> Skipped. No Trigger Data." << endl;
269 cout <<
" St: " << sIt->GetId() <<
" -> Skipped. Error by code:" << trig.
GetErrorCode() << endl;
275 cout <<
" St: " << sIt->GetId() <<
" -> Skipped. Random Trigger." << endl;
279 if (!sIt->HasCalibData()) {
281 cout <<
" St: " << sIt->GetId() <<
" -> Skipped. No Calib Data." << endl;
286 if (sIt->GetCalibData().GetVersion() > 32000) {
288 cout <<
" St: " << sIt->GetId() <<
" -> Skipped. Calib vervison > 32000." << endl;
292 if (!sIt->HasGPSData()) {
294 cout <<
" St: " << sIt->GetId() <<
" -> Skipped. No GPS Data." << endl;
298 if (!sIt->HasVEMTrace()) {
300 cout <<
" St: " << sIt->GetId() <<
" -> Skipped. No VEM signal." << endl;
308 cout <<
" Event with " << candidateStations <<
" candidate stations" << endl;
312 INFO(
"Event was not selected.");
317 cout <<
" Station processing... " << endl;
324 cout <<
"\n Processing station: " << sIt->GetId() << endl;
328 cout <<
" Rejected. Signal " << sIt->GetRecData().GetTotalSignal() <<
" VEMs below the minimun " <<
fMinStSignal <<
" VEMs" << endl;
338 if (segments.size() < 1) {
341 cout <<
" Station " << sIt->GetId() <<
" rejected. No valid segments. Flagged as random." << endl;
348 const int start = segments[0].fStart;
349 const int stop = segments[0].fStop + 1;
351 cout <<
" Selected Segment [StartBin, StopBin): [" << start <<
" , " << stop <<
")" << endl;
355 cout <<
" Segment Stored for Top Down selection " << endl;
357 if (!sIt->HasRecData())
362 for (
unsigned int seg = 0; seg < BasicSegments.size(); ++seg)
372 cout <<
" Using Top Down signal selector...";
374 cout <<
" ...for the segments:\n"
375 " (StId, Start, Stop, Time, Signal)" << endl;
376 for (
unsigned int seg = 0; seg <
fAllSegments.size(); ++seg)
377 cout <<
" (" <<
fAllSegments[seg].fStEvt->GetId() <<
" , "
380 <<
fAllSegments[seg].fStartTime.GetGPSNanoSecond() <<
" , "
388 INFO(
"Event was not selected.");
393 const bool isSdT4 =
Select();
432 INFO(
"Event was not selected.");
442 SdTopDownSignalSelectorUGR::Finish()
447 INFO(
"SdTopDownSignalSelectorUGR::Finish");
458 SdTopDownSignalSelectorUGR::Select()
467 cout <<
" Debuged info: Number of segments: " << ns <<
"\n"
470 " Index k: " << k << endl;
475 cout <<
" Event Accepted with all stations. Theta ~ "
482 for (
int i = 1; i <= k; ++i) {
487 cout <<
" Select: Trying with " << i <<
" less stations over " << ns << endl;
488 for (
int ik = 0; ik < i; ++ik)
489 cout <<
" Select: fIndexes[" << ik <<
"] = " <<
fIndexes[ik] << endl;
495 cout <<
" Selected segments:\n"
496 " (StId, Start, Stop, Time, Signal)" << endl;
497 for (
unsigned int seg = 0; seg <
fAllSegments.size(); ++seg) {
500 cout <<
" (" <<
fAllSegments[seg].fStEvt->GetId() <<
" , "
503 <<
fAllSegments[seg].fStartTime.GetGPSNanoSecond() <<
" , "
509 cout <<
" Event accepted with " << i <<
" rejected. Theta ~ "
517 for (
int i = 1; i <= k; ++i) {
522 cout <<
" Select: Trying with " << i <<
" less stations over " << ns << endl;
523 for (
int ik = 0; ik < i; ++ik)
524 cout <<
" Select: fIndexes[" << ik <<
"] = " <<
fIndexes[ik] << endl;
530 cout <<
" Selected segments:\n"
531 " (StId, Start, Stop, Time, Signal)" << endl;
532 for (
unsigned int seg = 0; seg <
fAllSegments.size(); ++seg) {
535 cout <<
" (" <<
fAllSegments[seg].fStEvt->GetId() <<
" , "
538 <<
fAllSegments[seg].fStartTime.GetGPSNanoSecond() <<
" , "
544 cout <<
" Event accepted with " << i <<
" rejected. Theta ~ "
556 SdTopDownSignalSelectorUGR::RemoveEA()
560 if (sIt->GetId() < 100)
570 SdTopDownSignalSelectorUGR::RemoveDoublets()
572 const sdet::SDetector& sdetector = det::Detector::GetInstance().GetSDetector();
584 SdTopDownSignalSelectorUGR::RemoveIsolatedStations()
586 const sdet::SDetector& sdetector = det::Detector::GetInstance().GetSDetector();
593 const TimeStamp t1 = sIt_1->GetRecData().GetSignalStartTime();
597 if (sIt_1->GetId() == sIt_2->GetId())
601 const double d = (fStPoint1 - fStPoint2).GetMag();
602 const TimeStamp t2 = sIt_2->GetRecData().GetSignalStartTime();
603 const double dt = fabs((t1 - t2).GetInterval());
625 SdTopDownSignalSelectorUGR::PatternRecovering()
655 SdTopDownSignalSelectorUGR::TryRemovingStations(
const int n)
667 fIndexes[n - 2] =
is;
678 SdTopDownSignalSelectorUGR::EstimateCore()
681 det::Detector::GetInstance().GetSiteCoordinateSystem();
682 const sdet::SDetector& sdetector = det::Detector::GetInstance().GetSDetector();
684 Vector barySum(0, 0, 0, siteCS);
688 const Point siteOrigin(0, 0, 0, siteCS);
692 cout <<
" Estimating core..." << endl;
696 for (
unsigned int is = 0;
is < size; ++
is) {
710 cout <<
" ...FAILED." << endl;
719 fTCore = timeSum.GetInterval();
720 fXCore = barySum.GetX(siteCS);
721 fYCore = barySum.GetY(siteCS);
722 fZCore = barySum.GetZ(siteCS);
725 cout <<
" ... Core(X,Y,Z,t): ("
736 SdTopDownSignalSelectorUGR::CorrectTimeAltitude(
const int is)
739 det::Detector::GetInstance().GetSiteCoordinateSystem();
746 SdTopDownSignalSelectorUGR::CorrectTimeAltitudeCurv(
const int is)
750 det::Detector::GetInstance().GetSiteCoordinateSystem();
752 const double dx =
fAllSegments[
is].fStDet->GetPosition().GetX(siteCS);
753 const double dy =
fAllSegments[
is].fStDet->GetPosition().GetY(siteCS);
754 const double d2 = dx * dx + dy * dy -
pow(
fU * dx + fV * dy, 2);
756 const double curv =
kCurv0 * costh;
765 det::Detector::GetInstance().GetSiteCoordinateSystem();
769 cout <<
" Checking for Good Time Configuration. Correction Type: " << correctionType <<
" ..." << endl;
782 for (
unsigned int is = 0;
is < size; ++
is) {
790 if (correctionType == SdTopDownSignalSelectorUGR::eAltitude)
792 else if (correctionType == SdTopDownSignalSelectorUGR::eAltitudeCurved)
798 INFO(
"Timing Correction Type not recognized. No correction done.");
801 const double wgt = 1;
805 sumx2 += wgt * dx * dx;
806 sumy2 += wgt * dy * dy;
807 sumxy += wgt * dx * dy;
809 sumxt += wgt * dt * dx;
810 sumyt += wgt * dt * dy;
814 const double rxx = sumw * sumy2 - sumy * sumy;
815 const double ryy = sumw * sumx2 - sumx * sumx;
816 const double rxy = sumx * sumy - sumw * sumxy;
817 const double rx = sumxy * sumy - sumx * sumy2;
818 const double ry = sumxy * sumx - sumy * sumx2;
819 const double rr = sumx2 * sumy2 - sumxy * sumxy;
820 const double deter = sumx2 * rxx + sumxy * rxy + sumx * rx;
822 if (deter == 0 || std::isnan(deter))
824 fU = (rxx * sumxt + rxy * sumyt + rx * sumt) / deter;
825 fV = (rxy * sumxt + ryy * sumyt + ry * sumt) / deter;
826 fT0 = (rx * sumxt + ry * sumyt + rr * sumt) / deter;
842 cout <<
" Weight sum: " << sumw
843 <<
"\t Residual Max: " << (ns - 2)*
kTolResM*
max(costh, 0.2) << endl;
846 for (
unsigned int is = 0;
is < size; ++
is) {
857 <<
"\tResidual: " << dt <<
" fabs: " << fabs(dt) <<
"\tLimit: " << (ns - 2)*
kTolResM*
max(costh, 0.2) <<
" --> ";
859 if (fabs(dt) > (ns - 2)*
kTolResM *
max(costh, 0.2)) {
861 cout <<
" Pattern REJECTED." << endl;
866 cout <<
" Segment ACCEPTED." << endl;
871 if (
sqrt(sumdt2 / (ns - 3)) > (ns - 2)*
kTolRes *
max(costh, 0.2)) {
873 cout <<
" Mean RMS: " <<
sqrt(sumdt2 / (ns - 3)) <<
"\tMaxValue: " << (ns - 2)*
kTolRes*
max(costh, 0.2) <<
" --> REJECTED " << endl;
877 const double sin2th =
fU *
fU + fV *
fV;
880 cout <<
" REJECTED (firstIt && sin2th>1.)" << endl;
893 SdTopDownSignalSelectorUGR::IsGoodSpaceConfig()
896 det::Detector::GetInstance().GetSiteCoordinateSystem();
898 const double dist2_max_proj =
pow(1300., 2) * (ns - 2);
901 cout <<
" Checking Space Configuration..." << endl;
904 cout <<
" Maximum Proj. Dist squared: " << dist2_max_proj << endl;
906 for (
int i = ns - 1; i >= 0; --i) {
911 const double dist2 =
pow(dx, 2) +
pow(dy, 2) -
pow(
fU * dx +
fV * dy, 2);
914 <<
"\tDist square: " << dist2 <<
" --> ";
916 if (dist2 > dist2_max_proj) {
918 cout <<
" Pattern REJECTED." << endl;
922 cout <<
" St. ACCEPTED." << endl;
929 SdTopDownSignalSelectorUGR::IsAligned()
932 det::Detector::GetInstance().GetSiteCoordinateSystem();
936 for (
unsigned int is = 0;
is <
ns; ++
is) {
944 vector<double> dx(ns);
945 vector<double> dy(ns);
946 for (
unsigned int is = 0;
is <
ns; ++
is) {
955 for (
unsigned int is = 0;
is <
ns; ++
is) {
958 ixx += dx[
is] * dx[
is];
959 iyy += dy[
is] * dy[
is];
960 ixy += dx[
is] * dy[
is];
962 double zeta = 0.5 * atan2(2 * ixy, ixx - iyy);
963 vector<double> lg(ns);
964 vector<double> tr(ns);
965 for (
unsigned int is = 0;
is <
ns; ++
is) {
968 lg[
is] = dx[
is] * cos(zeta) + dy[
is] * sin(zeta);
969 tr[
is] = dx[
is] * sin(zeta) - dy[
is] * cos(zeta);
973 for (
unsigned int is = 0;
is <
ns; ++
is) {
976 longi += lg[
is] * lg[
is];
977 trans += tr[
is] * tr[
is];
992 SdTopDownSignalSelectorUGR::EstimatedZenith(
const string&
s)
996 return asin(
sqrt(
fU *
fU + fV * fV));
1001 SdTopDownSignalSelectorUGR::EstimatedAzimuth(
const string&
s)
1005 return atan2(
fV,
fU);
1010 SdTopDownSignalSelectorUGR::Recover3Stations()
1013 det::Detector::GetInstance().GetSiteCoordinateSystem();
1014 const sdet::SDetector& sdetector = det::Detector::GetInstance().GetSDetector();
1018 for (
unsigned int i = 0, j = 0; i <
ns; ++i) {
1033 const double deter =
1034 st1X * st2Y - st1Y * st2X +
1035 st2X * st3Y - st2Y * st3X +
1036 st3X * st1Y - st3Y * st1X;
1037 double dist2 =
pow(st1X - st2X, 2) +
pow(st1Y - st2Y, 2);
1038 dist2 =
max(dist2,
pow(st2X - st3X, 2) +
pow(st2Y - st3Y, 2));
1039 dist2 =
max(dist2,
pow(st3X - st1X, 2) +
pow(st3Y - st1Y, 2));
1049 const double dt1 = (
fAllSegments[index[1]].fStartTime -
1051 const double dt2 = (
fAllSegments[index[2]].fStartTime -
1054 fU =
kSpeedOfLight * ((st1Y - st3Y) * dt1 - (st1Y - st2Y) * dt2) / deter;
1055 fV =
kSpeedOfLight * ((st3X - st1X) * dt1 - (st2X - st1X) * dt2) / deter;
1064 const double sin2th =
fU *
fU + fV *
fV;
1081 det::Detector::GetInstance().GetSDetector().GetStation(st);
1096 GeoSegment subsegment(0, 0, 0, 0., 0., 0., traceTime, &st, &dStation,
true);
1098 double lowFactor = 1;
1102 cout <<
" Station with High gain trace saturated. Using factor " << lowFactor <<
" for signal threshold." << endl;
1106 cout <<
"\n\t\t Scaning for segments..." << endl;
1115 cout <<
"\t\t\t Bin: " << bin
1116 <<
"\t Value: " << vemPeakTrace[bin]
1117 <<
" VEM Peak\t Value: " << vemChargeTrace[bin] <<
" VEM Charge" << endl;
1122 cout <<
"\t\t Adding new subsegment (start, stop, charge, bins): ("
1123 << subsegment.
fStart <<
" , "
1124 << subsegment.
fStop <<
" , "
1125 << subsegment.
fCharge <<
" , "
1126 << subsegment.
fAoP <<
" , "
1130 segments.push_back(subsegment);
1134 subsegment.
fAoP = 0;
1137 subsegment.
fStop = 0;
1141 subsegment.
fStop = bin;
1142 subsegment.
fCharge += vemChargeTrace[bin];
1143 subsegment.
fSignal += vemPeakTrace[bin];
1147 cout <<
"\t\t\t New segment starting: "
1148 << subsegment.
fStart <<
" , "
1149 << subsegment.
fStop <<
" , "
1150 << subsegment.
fCharge <<
" , "
1153 subsegment.
fStop = bin;
1154 subsegment.
fCharge += vemChargeTrace[bin];
1156 subsegment.
fSignal += vemPeakTrace[bin];
1158 cout <<
"\t\t\t Updating segment: "
1159 << subsegment.
fStart <<
" , "
1160 << subsegment.
fStop <<
" , "
1161 << subsegment.
fCharge <<
" , "
1166 if (segments.size() <= 1)
1170 cout <<
"\n\t\t Merging subsegments..." << endl;
1172 cout <<
"\t\t\t(Start, Stop, Charge, BinsOverThreshold)" << endl;
1175 for (
unsigned int seg = 0; seg < segments.size() - 1; ++seg) {
1177 if ((segments[seg].fStop +
fMingap + segments[seg].fBinsOverThresh) > segments[seg + 1].fStart) {
1179 cout <<
"\t\t\t Merging: ("
1180 << segments[seg].fStart <<
" , "
1181 << segments[seg].fStop <<
" , "
1182 << segments[seg].fCharge <<
" , "
1183 << segments[seg].fBinsOverThresh <<
") + ("
1184 << segments[seg + 1].fStart <<
" , "
1185 << segments[seg + 1].fStop <<
" , "
1186 << segments[seg + 1].fCharge <<
" , "
1187 << segments[seg + 1].fBinsOverThresh <<
") = (";
1189 segments[seg].fStop = segments[seg + 1].fStop;
1190 segments[seg].fBinsOverThresh += segments[seg + 1].fBinsOverThresh;
1191 segments[seg].fCharge += segments[seg + 1].fCharge;
1192 segments[seg].fSignal += segments[seg + 1].fSignal;
1195 cout << segments[seg].fStart <<
" , "
1196 << segments[seg].fStop <<
" , "
1197 << segments[seg].fCharge <<
" , "
1198 << segments[seg].fBinsOverThresh <<
")" << endl;
1200 segments.erase(segments.begin() + seg + 1);
1206 cout <<
"\n\t\t Deleting segments below threshold... " << endl;
1208 cout <<
"\t\t\t(Start, Stop, Charge, BinsOverThreshold)" << endl;
1210 for (
unsigned int seg = 0; seg < segments.size(); ++seg) {
1214 for (
int bin = segments[seg].fStart; bin <= segments[seg].fStop; ++bin)
1215 peak = vemPeakTrace[bin] > peak ? vemPeakTrace[bin] : peak;
1216 segments[seg].fAoP = segments[seg].fCharge / peak;
1221 cout <<
"\t\t\t Deleting segment: ("
1222 << segments[seg].
fStart <<
" , "
1223 << segments[seg].fStop <<
" , "
1224 << segments[seg].fCharge <<
" , "
1225 << segments[seg].fBinsOverThresh <<
")" << endl;
1227 segments.erase(segments.begin() + seg);
1232 cout <<
"\n\t Selected segments: (Start, Stop, VEMCharge, AoP, VEMPeakSignal, BinsOverTh, SignalStartTime)" << endl;
1233 for (
unsigned int seg = 0; seg < segments.size(); ++seg) {
1235 << segments[seg].fStart <<
" , "
1236 << segments[seg].fStop <<
" , "
1237 << segments[seg].fCharge <<
" , "
1238 << segments[seg].fAoP <<
" , "
1239 << segments[seg].fSignal <<
" , "
1240 << segments[seg].fBinsOverThresh <<
" , "
1241 << segments[seg].fStartTime.GetGPSNanoSecond() <<
")" << endl;
1303 cout <<
"\n Sorted segments by ";
1311 cout <<
"Signal quality";
1319 cout <<
"AoP quality";
1323 cout <<
"Signal quality (default for Top Down)";
1327 cout <<
" Unrecognized Rejection Procedure. Setting to default: Signal Quality";
1334 cout <<
": " << endl;
1335 for (
unsigned int seg = 0; seg < segments.size(); ++seg) {
1337 << segments[seg].fStart <<
" , "
1338 << segments[seg].fStop <<
" , "
1339 << segments[seg].fCharge <<
" , "
1340 << segments[seg].fAoP <<
" , "
1341 << segments[seg].fBinsOverThresh <<
")" << endl;
1349 SdTopDownSignalSelectorUGR::UpdateStations()
1353 cout <<
" Will check duplicity of stations for the candidates out of the following segments\n"
1354 "\t (StId, Start, Stop, Charge, AoP, Cand, BinsOverThreshold, TimeResidual)" << endl;
1355 for (
unsigned int i = 0; i <
fAllSegments.size(); ++i) {
1368 for (
unsigned int i = 0; i <
fAllSegments.size(); ++i) {
1371 for (
unsigned int j = i + 1; j <
fAllSegments.size(); ++j) {
1377 cout <<
" Duplicate segment with bigger residual time rejected. Station " <<
fAllSegments[j].fStEvt->GetId() << endl;
1381 cout <<
" Duplicate segment with bigger residual time rejected. Station " <<
fAllSegments[i].fStEvt->GetId() << endl;
1390 cout <<
" Duplicate candidate segments checked and cleared (only one candidate per station)\n"
1391 "\t (StId, Start, Stop, Charge, AoP, Cand, BinsOverThreshold, TimeResidual)" << endl;
1392 for (
unsigned int i = 0; i <
fAllSegments.size(); ++i) {
1407 for (
unsigned int seg = 0; seg <
fAllSegments.size(); ++seg) {
1417 for (
unsigned int r = 0; r < rejectedSegments.size(); ++r) {
1418 bool rejectCurrSt =
true;
1419 for (
unsigned int seg = 0; seg <
fAllSegments.size() && rejectCurrSt; ++seg) {
1420 if (rejectedSegments[r].fStEvt ==
fAllSegments[seg].fStEvt)
1421 rejectCurrSt =
false;
1428 cout <<
" Duplicate segments deleted. Final segments to update\n"
1429 "\t (StId, Start, Stop, Charge, AoP, Cand, BinsOverThreshold, TimeResidual)" << endl;
1430 for (
unsigned int i = 0; i <
fAllSegments.size(); ++i) {
1444 for (
unsigned int seg = 0; seg <
fAllSegments.size(); ++seg) {
1453 cout <<
" updated segments:\n"
1454 "\t (StId, Start, Stop, Charge, AoP, Cand, BinsOverThreshold, TimeResidual)" << endl;
1455 for (
unsigned int i = 0; i <
fAllSegments.size(); ++i) {
1471 SdTopDownSignalSelectorUGR::UpdateStationValues(
sevt::Station& st,
const int start,
const int stop)
1480 for (
int i = start; i < stop; ++i) {
1481 const double val = vemTrace[i];
1489 det::Detector::GetInstance().GetSDetector().GetStation(st);
1494 double totalCharge = 0;
1499 for (Station::PMTIterator pmtIt = st.
PMTsBegin();
1500 pmtIt != st.
PMTsEnd(); ++pmtIt) {
1501 if (pmtIt->HasCalibData() && pmtIt->GetCalibData().IsTubeOk()) {
1510 for (
int i = start; i < stop; ++i)
1511 charge += vemTrace[i];
1515 totalCharge += charge;
1519 t50Stat(pmtRec.
GetT50());
1526 totalCharge /= nPMTs;
1546 const TimeStamp signalTime = traceTime +
1557 SdTopDownSignalSelectorUGR::ComputeShapeRiseFallPeak(
PMTRecData& pmtRec,
1558 const double binSize,
1559 const unsigned int startBin,
1560 const unsigned int startIntegration,
1561 const unsigned int endIntegration,
1562 const double traceIntegral)
1568 if (traceIntegral <= 0)
1575 const double binTiming = binSize;
1576 const unsigned int shapeSentry =
1577 startIntegration + (
unsigned int)(600 *
nanosecond / binTiming);
1578 const double t50Sentry = 0.5 * traceIntegral;
1579 double riseStartBin = 0;
1580 double riseEndBin = 0;
1581 double fallStartBin = 0;
1582 double fallEndBin = 0;
1584 double sumEarly = 0;
1586 double peakAmplitude = 0;
1587 double runningSum = 0;
1592 for (
unsigned int i = startIntegration; i < endIntegration; ++i) {
1594 const double binValue = trace[i];
1595 runningSum += binValue;
1597 if (peakAmplitude < binValue)
1598 peakAmplitude = binValue;
1600 if (!sumEarly && i >= shapeSentry)
1603 if (!riseStartBin && runningSum > riseStartSentry)
1604 riseStartBin = i - (runningSum - riseStartSentry) / (runningSum - oldSum);
1606 if (!riseEndBin && runningSum > riseEndSentry)
1607 riseEndBin = i - (runningSum - riseEndSentry) / (runningSum - oldSum);
1609 if (!fallStartBin && runningSum > fallStartSentry)
1610 fallStartBin = i - (runningSum - fallStartSentry) / (runningSum - oldSum);
1612 if (!fallEndBin && runningSum > fallEndSentry)
1613 fallEndBin = i - (runningSum - fallEndSentry) / (runningSum - oldSum);
1615 if (!t50Bin && runningSum > t50Sentry)
1616 t50Bin = i - (runningSum - t50Sentry) / (runningSum - oldSum);
1618 oldSum = runningSum;
1623 pmtRec.
SetRiseTime(binTiming * (riseEndBin - riseStartBin), 0);
1624 pmtRec.
SetFallTime(binTiming * (fallEndBin - fallStartBin), 0);
1625 pmtRec.
SetT50(binTiming * (t50Bin - startBin));
1626 const double sumLate = runningSum - sumEarly;
1627 if (shapeSentry < endIntegration && sumLate > 0)
1638 det::Detector::GetInstance().GetSDetector().GetStation(station);
1640 vector<const PMT*> validPMTs;
1645 const int traceLength = vemTrace.
GetSize();
1646 for (
int i = 0; i < traceLength; ++i)
1649 for (Station::ConstPMTIterator pmtIt = station.
PMTsBegin();
1650 pmtIt != station.
PMTsEnd(); ++pmtIt)
1651 if (pmtIt->HasCalibData() && pmtIt->GetCalibData().IsTubeOk() &&
1652 pmtIt->HasRecData() && pmtIt->GetRecData().HasVEMTrace())
1653 validPMTs.push_back(&(*pmtIt));
1655 if (!validPMTs.empty()) {
1656 const int nPMTs = validPMTs.size();
1657 for (vector<const PMT*>::const_iterator pmtIt = validPMTs.begin();
1658 pmtIt != validPMTs.end(); ++pmtIt) {
1659 const PMTRecData& pmtRec = (*pmtIt)->GetRecData();
1662 for (
int i = 0; i < traceLength; ++i)
1663 vemTrace[i] += (pmtTrace[i] * peakChargeFactor) / nPMTs;
1676 det::Detector::GetInstance().GetSDetector().GetStation(st);
1691 GeoSegment subsegment(0, 0, 0, 0., 0., 0., traceTime, &st, &dStation,
true);
1693 double lowFactor = 1;
1697 cout <<
" Station with High gain trace saturated. Using factor " << lowFactor <<
" for signal threshold." << endl;
1701 cout <<
"\n\t\t Scaning for segments..." << endl;
1706 cout <<
"\t\t\t Bin: " << bin
1707 <<
"\t Value: " << vemPeakTrace[bin]
1708 <<
" VEM Peak\t Value: " << vemChargeTrace[bin] <<
" VEM Charge" << endl;
1713 cout <<
"\t\t Adding new subsegment (start, stop, charge, bins): ("
1714 << subsegment.
fStart <<
" , "
1715 << subsegment.
fStop <<
" , "
1716 << subsegment.
fCharge <<
" , "
1717 << subsegment.
fAoP <<
" , "
1721 segments.push_back(subsegment);
1725 subsegment.
fAoP = 0;
1728 subsegment.
fStop = 0;
1732 subsegment.
fStop = bin;
1733 subsegment.
fCharge += vemChargeTrace[bin];
1734 subsegment.
fSignal += vemPeakTrace[bin];
1738 cout <<
"\t\t\t New segment starting: "
1739 << subsegment.
fStart <<
" , "
1740 << subsegment.
fStop <<
" , "
1741 << subsegment.
fCharge <<
" , "
1744 subsegment.
fStop = bin;
1745 subsegment.
fCharge += vemChargeTrace[bin];
1747 subsegment.
fSignal += vemPeakTrace[bin];
1749 cout <<
"\t\t\t Updating segment: "
1750 << subsegment.
fStart <<
" , "
1751 << subsegment.
fStop <<
" , "
1752 << subsegment.
fCharge <<
" , "
1757 if (segments.size() <= 1)
1761 cout <<
"\n\t\t Merging subsegments..." << endl;
1763 cout <<
"\t\t\t(Start, Stop, Charge, BinsOverThreshold)" << endl;
1766 for (
unsigned int seg = 0; seg < segments.size() - 1; ++seg) {
1768 if ((segments[seg].fStop +
fPreMingap + segments[seg].fBinsOverThresh) > segments[seg + 1].fStart) {
1770 cout <<
"\t\t\t Merging: ("
1771 << segments[seg].fStart <<
" , "
1772 << segments[seg].fStop <<
" , "
1773 << segments[seg].fCharge <<
" , "
1774 << segments[seg].fBinsOverThresh <<
") + ("
1775 << segments[seg + 1].fStart <<
" , "
1776 << segments[seg + 1].fStop <<
" , "
1777 << segments[seg + 1].fCharge <<
" , "
1778 << segments[seg + 1].fBinsOverThresh <<
") = (";
1780 segments[seg].fStop = segments[seg + 1].fStop;
1781 segments[seg].fBinsOverThresh += segments[seg + 1].fBinsOverThresh;
1782 segments[seg].fCharge += segments[seg + 1].fCharge;
1783 segments[seg].fSignal += segments[seg + 1].fSignal;
1786 cout << segments[seg].fStart <<
" , "
1787 << segments[seg].fStop <<
" , "
1788 << segments[seg].fCharge <<
" , "
1789 << segments[seg].fBinsOverThresh <<
")" << endl;
1791 segments.erase(segments.begin() + seg + 1);
1797 cout <<
"\n\t\t Deleting Pre segments below threshold... " << endl;
1799 cout <<
"\t\t\t(Start, Stop, Charge, BinsOverThreshold)" << endl;
1801 for (
unsigned int seg = 0; seg < segments.size(); ++seg) {
1805 for (
int bin = segments[seg].fStart; bin <= segments[seg].fStop; ++bin)
1806 peak = vemPeakTrace[bin] > peak ? vemPeakTrace[bin] : peak;
1807 segments[seg].fAoP = segments[seg].fCharge / peak;
1812 cout <<
"\t\t\t Deleting segment: ("
1813 << segments[seg].
fStart <<
" , "
1814 << segments[seg].fStop <<
" , "
1815 << segments[seg].fCharge <<
" , "
1816 << segments[seg].fBinsOverThresh <<
")" << endl;
1818 segments.erase(segments.begin() + seg);
1823 cout <<
"\n\t Selected segments: (Start, Stop, VEMCharge, AoP, VEMPeakSignal, BinsOverTh, SignalStartTime)" << endl;
1824 for (
unsigned int seg = 0; seg < segments.size(); ++seg) {
1826 << segments[seg].fStart <<
" , "
1827 << segments[seg].fStop <<
" , "
1828 << segments[seg].fCharge <<
" , "
1829 << segments[seg].fAoP <<
" , "
1830 << segments[seg].fSignal <<
" , "
1831 << segments[seg].fBinsOverThresh <<
" , "
1832 << segments[seg].fStartTime.GetGPSNanoSecond() <<
")" << endl;
1841 SdTopDownSignalSelectorUGR::UpdateSegmentValues(
const int seg)
1846 cout <<
"\n\t\t Updating segment for station: " << st.
GetId()
1847 <<
"\n\t\t (Start, Stop): (" <<
fAllSegments[seg].fStart
1856 GeoSegment subsegment(0, 0, 0, 0., 0., 0., 0, NULL, NULL,
true);
1858 double lowFactor = 1;
1861 cout <<
" Station with High gain trace saturated. Using factor " << lowFactor <<
" for signal threshold." << endl;
1866 cout <<
"\n\t\t Scaning for segments..." << endl;
1872 !segments.size() && !subsegment.
fStart) {
1874 cout <<
"\t\tNo more segments found " << endl;
1879 cout <<
"\t\t\t Bin: " << bin
1880 <<
"\t Value: " << vemPeakTrace[bin]
1881 <<
" VEM Peak\t Value: " << vemChargeTrace[bin] <<
" VEM Charge" << endl;
1886 cout <<
"\t\t Adding new subsegment (start, stop, charge, bins): ("
1887 << subsegment.
fStart <<
" , "
1888 << subsegment.
fStop <<
" , "
1889 << subsegment.
fCharge <<
" , "
1890 << subsegment.
fAoP <<
" , "
1893 segments.push_back(subsegment);
1897 subsegment.
fAoP = 0;
1900 subsegment.
fStop = 0;
1904 subsegment.
fStop = bin;
1905 subsegment.
fCharge += vemChargeTrace[bin];
1906 subsegment.
fSignal += vemPeakTrace[bin];
1912 cout <<
"\t\tNo more segments found " << endl;
1917 cout <<
"\t\t\t New segment starting: "
1918 << subsegment.
fStart <<
" , "
1919 << subsegment.
fStop <<
" , "
1920 << subsegment.
fCharge <<
" , "
1923 subsegment.
fStop = bin;
1924 subsegment.
fCharge += vemChargeTrace[bin];
1926 subsegment.
fSignal += vemPeakTrace[bin];
1928 cout <<
"\t\t\t Updating segment: "
1929 << subsegment.
fStart <<
" , "
1930 << subsegment.
fStop <<
" , "
1931 << subsegment.
fCharge <<
" , "
1937 for (
unsigned int i = 0; i < segments.size(); ++i) {
1940 cout <<
"\t\t\t Merging: ("
1945 << segments[i].fStart <<
" , "
1946 << segments[i].fStop <<
" , "
1947 << segments[i].fCharge <<
" , "
1948 << segments[i].fBinsOverThresh <<
") = (";
1951 fAllSegments[seg].fBinsOverThresh += segments[i].fBinsOverThresh;
1967 peak = vemPeakTrace[bin] > peak ? vemPeakTrace[bin] : peak;
1972 cout <<
"\t\t\t Merging done! " << endl;
double GetVEMCharge() const
bool SelectMainSegment(GeoSegmentCollection &segments)
Branch GetTopBranch() const
Class to access station level reconstructed data.
static bool bFirstIteration
void SetCurvature(const double curvature, const double error)
gaussian curvature = 1 / Rc
utl::TraceD & GetVEMTrace(const StationConstants::SignalComponent source=StationConstants::eTotal)
Traces calibrated in VEM Peak.
void SetTotalSignal(const double signal, const double sErr=0)
Total integrated signal in VEM unit, averaged over pmts.
double EstimatedZenith(const std::string &s)
int GetId() const
Get the station Id.
std::vector< GeoSegment > GeoSegmentCollection
void SetBarycenter(const utl::Point &bary)
Detector description interface for Station-related data.
Report success to RunController.
void SetSignalStartSlot(const unsigned int slot)
Start time of the signal in time slots from beginning of trace.
bool operator()(const GeoSegment &i, const GeoSegment &j) const
double GetRiseTime() const
Average rise time from the PMTs.
Interface class to access to the SD Reconstruction of a Shower.
void RemoveIsolatedStations()
double fPreSignalThreshold
SizeType GetStop() const
Get valid data stop bin.
bool HasRecShower() const
PMTIterator PMTsBegin(const sdet::PMTConstants::PMTType type=sdet::PMTConstants::eWaterCherenkovLarge)
begin PMT iterator for read/write
void SetShapeParameter(const double shape)
void SetAreaOverPeak(const double areaOverPeak)
Skip remaining modules in the current loop and continue with next iteration of the loop...
double GetFallTime() const
Average fall time from the PMTs.
ShowerRecData & GetRecShower()
void SetPeakAmplitude(const double peak)
Amplitude of signal Peak in VEM-Peak unit,averaged over pmts.
bool is(const double a, const double b)
EventTrigger & GetTrigger()
Get the object with central trigger data, throw if n.a.
unsigned int GetSecond() const
Get end of traces raw time.
void SetFallTime(const double fallTime, const double rms)
sevt::StationRecData & GetRecData()
Get station level reconstructed data.
std::vector< unsigned int > fIndexes
#define INFO(message)
Macro for logging informational messages.
bool IsInGrid(const SDetectorConstants::GridIndex index=SDetectorConstants::eStandard) const
Tells whether the station is in the regular triangular grid.
void SetTraceStartTime(const utl::TimeStamp &Time)
Set absolute start time of the VEM trace.
boost::filter_iterator< CandidateStationFilter, StationIterator > CandidateStationIterator
Iterator over candidate stations.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
double pow(const double x, const unsigned int i)
bool IsHighGainSaturation() const
void SortStations(const OrderingCriterion ord) const
Sort the list of stations by the criterion specified in an OrderingCriterion object.
A TimeStamp holds GPS second and nanosecond for some event.
utl::TraceD & GetVEMTrace(const StationConstants::SignalComponent source=StationConstants::eTotal)
signal trace calibrated in [VEM charge]
utl::Point GetPosition() const
Tank position.
Criterion to sort stations by increasing signal.
CandidateStationIterator CandidateStationsBegin()
void SetPeakAmplitude(const double peak)
std::pair< double, double > fRiseTimeFractions
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
class to hold data at Station level
GeoSegmentCollection fAllSegments
class to hold reconstructed data at PMT level
double GetX(const CoordinateSystemPtr &coordinateSystem) const
std::vector< double >::size_type SizeType
utl::TimeStamp fStartTime
constexpr double nanosecond
double abs(const SVector< n, T > &v)
void SetAxis(const utl::Vector &axis)
bool TryRemovingStations(int)
bool operator()(const GeoSegment &i, const GeoSegment &j) const
bool IsGoodTimeConfig(const TimeCorrectionType correctionType)
PMTIterator PMTsEnd(const sdet::PMTConstants::PMTType type=sdet::PMTConstants::eWaterCherenkovLarge)
end PMT iterator for read/write
utl::TraceD GetVEMChargeTrace(const sevt::Station &st) const
unsigned int GetCorrectedNanosecond() const
Get corrected trigger nanosecond.
sevt::StationGPSData & GetGPSData()
Get GPS data for the station.
double GetShapeParameter() const
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
void SetCoreTime(const utl::TimeStamp &coreTime, const utl::TimeInterval &coreTimeErr)
void SetTotalCharge(const double totalCharge, const double chErr=0)
bool operator()(const GeoSegment &i, const GeoSegment &j) const
std::vector< GeoSegment > FoundSegments(sevt::Station &st)
void ComputeShapeRiseFallPeak(sevt::PMTRecData &pmtRecData, const double binSize, const unsigned int startBin, const unsigned int startIntegration, const unsigned int endIntegration, const double traceIntegral) const
static utl::Point fBarycenter
unsigned int fRejectionProcedure
void SetSignalStartTime(const utl::TimeStamp time)
Start time of the signal.
double CorrectTimeAltitude(const int)
bool operator()(const GeoSegment &i, const GeoSegment &j) const
double CorrectTimeAltitudeCurv(const int)
double GetY(const CoordinateSystemPtr &coordinateSystem) const
constexpr double kSpeedOfLight
A TimeInterval is used to represent time elapsed between two events.
utl::TimeStamp GetTime() const
Get time of the trigger.
ResultFlag
Flag returned by module methods to the RunController.
bool UpdateStationValues(sevt::Station &st, const int start, const int stop)
double GetFADCBinSize() const
Station Trigger Data description
SizeType GetStart() const
Get valid data start bin.
std::pair< double, double > fFallTimeFractions
Detector description interface for SDetector-related data.
void SetT50(const double t50)
Report failure to RunController, causing RunController to terminate execution.
void SetCorePosition(const utl::Point &core)
void UpdateSegmentValues(const int seg)
unsigned int GetFADCTraceLength() const
CandidateStationIterator CandidateStationsEnd()
void SetT4Trigger(const int t4)
void SetRiseTime(const double riseTime, const double rms)
const Station & GetStation(const int stationId) const
Get station by Station Id.
std::vector< double > fResiduals
double GetPeakAmplitude() const
Peak Amplitude.
#define ERROR(message)
Macro for logging error messages.
std::vector< GeoSegment > FoundBasicSegments(sevt::Station &st)
double GetVEMPeak() const
bool HasSRecShower() const
static utl::TimeStamp fBaryTime
bool fIsLastTimingIteration
int fMinNumberStSignalCut
bool operator()(const GeoSegment &i, const GeoSegment &j) const
void SetSignalEndSlot(const unsigned int slot)
End time of the signal in time slots from beginning of trace.