2 #include <utl/ErrorLogger.h>
5 #include <evt/ShowerSRecData.h>
6 #include <evt/ShowerRecData.h>
7 #include <sevt/EventTrigger.h>
8 #include <sevt/SEvent.h>
9 #include <sevt/Station.h>
10 #include <sevt/StationConstants.h>
11 #include <sevt/SortCriteria.h>
13 #include <fwk/CentralConfig.h>
14 #include <det/Detector.h>
15 #include <sdet/Station.h>
16 #include <sdet/SDetector.h>
17 #include <utl/CoordinateSystemPtr.h>
18 #include <utl/Branch.h>
20 #include <TCdasUtil.h>
28 using namespace TopDownSelectorNS;
34 TopDownSelector::TopDownSelector() :
37 fRejectNonT4Events(false),
45 fNMaxRemovedStations(4)
52 INFO(
"TopDownSelector::Init()");
81 INFO(
"TopDownSelector::Run()");
84 INFO(
"TopDownSelector::Run() => Event has not SEvent");
91 const bool isSdT4 =
Select();
100 (isSdT4 * ShowerSRecData::eT4_4C1));
103 INFO(
"Event was not selected.");
113 INFO(
"TopDownSelector::Finish()");
136 cout <<
" Event Accepted with all stations. Theta ~ "
143 for (
unsigned int i = 1; i <= k; ++i) {
148 cout <<
" Select: Trying with " << i <<
" less stations over "<< ns << endl;
149 for (
unsigned int ik = 0; ik < i; ++ik)
150 cout <<
" Select: fIndexes[" << ik <<
"] = "<<
fIndexes[ik] << endl;
153 for (
unsigned int j = 0; j <
fStations.size(); ++j) {
158 cout <<
" Event accepted with " << i <<
" rejected. Theta ~ "
166 for (
unsigned int i = 1; i <= k; ++i) {
171 cout <<
" Select: Trying with " << i <<
" less stations over "<< ns << endl;
172 for (
unsigned int ik = 0; ik < i; ++ik)
173 cout <<
" Select: fIndexes[" << ik <<
"] = "<<
fIndexes[ik] << endl;
176 for (
unsigned int j = 0; j <
fStations.size(); ++j) {
181 cout <<
" Event accepted with " << i <<
" rejected. Theta ~ "
200 const sdet::SDetector& sdetector = det::Detector::GetInstance().GetSDetector();
206 stationPair.
event = &(*sIt);
218 if (sIt->GetId() < 100) {
231 const sdet::SDetector& sdetector = det::Detector::GetInstance().GetSDetector();
246 const sdet::SDetector& sdetector = det::Detector::GetInstance().GetSDetector();
253 TimeStamp t1 = sIt_1->GetRecData().GetSignalStartTime();
257 if (sIt_1->GetId() == sIt_2->GetId())
261 const double d = ( fStPoint1 - fStPoint2 ).GetMag();
262 const TimeStamp t2 = sIt_2->GetRecData().GetSignalStartTime();
263 const double dt = fabs((t1-t2).GetInterval());
363 det::Detector::GetInstance().GetSiteCoordinateSystem();
364 const sdet::SDetector& sdetector = det::Detector::GetInstance().GetSDetector();
370 const Point siteOrigin(0,0,0, siteCS);
374 cout <<
" Estimating core..." << endl;
378 for (
unsigned int is = 0;
is < size; ++
is) {
392 cout <<
" ...FAILED." << endl;
403 cout <<
" ... Core(X,Y,Z,t): ("
417 det::Detector::GetInstance().GetSiteCoordinateSystem();
428 det::Detector::GetInstance().GetSiteCoordinateSystem();
430 const double dx =
fStations[
is].detector->GetPosition().GetX(siteCS);
431 const double dy =
fStations[
is].detector->GetPosition().GetY(siteCS);
432 const double d2 = dx*dx + dy*dy -
pow(
fU*dx + fV*dy, 2);
434 const double curv =
kCurv0 * costh;
443 det::Detector::GetInstance().GetSiteCoordinateSystem();
444 unsigned int is,
ns = 0;
445 double wgt, dx, dy, dt, sumw, sumx, sumy, sumx2, sumy2, sumxy, sumt, sumxt, sumyt;
446 double rxx, ryy, rxy, rx, ry, rr, deter;
449 cout <<
" Checking for Good Time Configuration. Correction Type: " << correctionType <<
" ..." << endl;
453 sumw = sumx = sumy = sumx2 = sumy2 = sumxy = sumt = sumxt = sumyt = 0;
454 for (is = 0; is < size; ++
is) {
469 INFO(
"Timing Correction Type not recognized. No correction done.");
472 (eventTime-
fStations[
is].event->GetRecData().GetSignalStartTime()).GetInterval() -
478 sumx2 += wgt * dx*dx;
479 sumy2 += wgt * dy*dy;
480 sumxy += wgt * dx * dy;
482 sumxt += wgt * dt * dx;
483 sumyt += wgt * dt * dy;
487 rxx = sumw * sumy2 - sumy*sumy;
488 ryy = sumw * sumx2 - sumx*sumx;
489 rxy = sumx * sumy - sumw * sumxy;
490 rx = sumxy * sumy - sumx * sumy2;
491 ry = sumxy * sumx - sumy * sumx2;
492 rr = sumx2 * sumy2 - sumxy*sumxy;
493 deter = sumx2 * rxx + sumxy * rxy + sumx * rx;
495 if (deter == 0 || std::isnan(deter))
497 fU = (rxx * sumxt + rxy * sumyt + rx * sumt) / deter;
498 fV = (rxy * sumxt + ryy * sumyt + ry * sumt) / deter;
499 fT0 = (rx * sumxt + ry * sumyt + rr * sumt) / deter;
515 cout <<
" Weight sum: " << sumw
516 <<
"\t Residual Max: " << (ns-2)*
kTolResM*
max(costh, 0.2) << endl;
519 for (is = 0; is < size; ++
is) {
525 (eventTime-
fStations[
is].event->GetRecData().GetSignalStartTime()).GetInterval() -
526 fBaryTime - (
fT0 -
fU*dx/kCdasUtil::CSPEED - fV*dy/kCdasUtil::CSPEED);
531 <<
"\tResidual: " << dt <<
" --> ";
535 cout <<
" Pattern REJECTED." << endl;
540 cout <<
" St. ACCEPTED." << endl;
546 cout <<
" REJECTED by tolerance on mean RMS of residuals" << endl;
550 double sin2th =
fU*
fU + fV*
fV;
553 cout <<
" REJECTED (firstIt && sin2th > 1)" << endl;
569 det::Detector::GetInstance().GetSiteCoordinateSystem();
571 double dist2_max_proj =
pow(1300., 2.) * (ns - 2);
574 cout <<
" Checking Space Configuration..." << endl;
577 cout <<
" Maximum Proj. Dist squared: " << dist2_max_proj << endl;
579 for (
int i = ns-1; i >= 0; --i) {
582 const double dx =
fStations[i].detector->GetPosition().GetX(siteCS) -
fXCore;
583 const double dy =
fStations[i].detector->GetPosition().GetY(siteCS) -
fYCore;
584 const double dist2 =
pow(dx, 2.) +
pow(dy, 2.) -
pow(
fU*dx +
fV*dy, 2.);
586 cout <<
" St: " <<
fStations[i].event->GetId()
587 <<
"\tDist square: " << dist2 <<
" --> ";
589 if (dist2 > dist2_max_proj) {
591 cout <<
" Pattern REJECTED." << endl;
595 cout <<
" St. ACCEPTED." << endl;
605 det::Detector::GetInstance().GetSiteCoordinateSystem();
607 double xmean = 0, ymean = 0;
608 for (
unsigned int is = 0;
is <
ns; ++
is) {
611 xmean +=
fStations[
is].detector->GetPosition().GetX(siteCS) / double(ns);
612 ymean +=
fStations[
is].detector->GetPosition().GetY(siteCS) / double(ns);
614 vector<double> dx(ns);
615 vector<double> dy(ns);
616 for (
unsigned int is = 0;
is <
ns; ++
is) {
619 dx[
is] =
fStations[
is].detector->GetPosition().GetX(siteCS) - xmean;
620 dy[
is] =
fStations[
is].detector->GetPosition().GetY(siteCS) - ymean;
622 double ixx = 0, ixy = 0, iyy = 0;
623 for (
unsigned int is = 0;
is <
ns; ++
is) {
626 ixx += dx[
is]*dx[
is];
627 iyy += dy[
is]*dy[
is];
628 ixy += dx[
is]*dy[
is];
630 const double zeta = 0.5*atan2(2*ixy, ixx - iyy);
631 vector<double> lg(ns);
632 vector<double> tr(ns);
633 for (
unsigned int is = 0;
is <
ns; ++
is) {
636 lg[
is] = dx[
is]*cos(zeta) + dy[
is]*sin(zeta);
637 tr[
is] = dx[
is]*sin(zeta) - dy[
is]*cos(zeta);
639 double longi = 0, trans = 0;
640 for (
unsigned int is = 0;
is <
ns; ++
is) {
643 longi += lg[
is]*lg[
is];
644 trans += tr[
is]*tr[
is];
672 return atan2(
fV,
fU);
680 det::Detector::GetInstance().GetSiteCoordinateSystem();
681 const sdet::SDetector& sdetector = det::Detector::GetInstance().GetSDetector();
685 for (
unsigned int i = 0, j = 0; i <
ns; ++i) {
701 st1X * st2Y - st1Y * st2X +
702 st2X * st3Y - st2Y * st3X +
703 st3X * st1Y - st3Y * st1X;
704 double dist2 =
pow(st1X - st2X, 2.) +
pow(st1Y - st2Y, 2.);
705 dist2 =
max(dist2,
pow(st2X - st3X, 2.) +
pow(st2Y - st3Y, 2.));
706 dist2 =
max(dist2,
pow(st3X - st1X, 2.) +
pow(st3Y - st1Y, 2.));
718 double dt1 = (
fStations[index[1]].event->GetRecData().GetSignalStartTime() -
719 fStations[index[0]].event->GetRecData().GetSignalStartTime()).GetInterval();
720 double dt2 = (
fStations[index[2]].event->GetRecData().GetSignalStartTime() -
721 fStations[index[0]].event->GetRecData().GetSignalStartTime()).GetInterval();
734 double sin2th =
fU*
fU + fV*
fV;
Branch GetTopBranch() const
unsigned int fNMaxRemovedStations
void RemoveIsolatedStations()
Detector description interface for Station-related data.
Report success to RunController.
Interface class to access to the SD Reconstruction of a Shower.
bool TryRemovingStations(int)
std::vector< unsigned int > fIndexes
bool HasRecShower() const
Skip remaining modules in the current loop and continue with next iteration of the loop...
ShowerRecData & GetRecShower()
bool is(const double a, const double b)
EventTrigger & GetTrigger()
Get the object with central trigger data, throw if n.a.
sevt::StationRecData & GetRecData()
Get station level reconstructed data.
double CorrectTimeAltitudeCurv(int)
double EstimatedAzimuth(const std::string &s)
#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.
boost::filter_iterator< CandidateStationFilter, StationIterator > CandidateStationIterator
Iterator over candidate stations.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
double pow(const double x, const unsigned int i)
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
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.
double EstimatedZenith(const std::string &s)
utl::Point GetPosition() const
Tank position.
Criterion to sort stations by increasing signal.
CandidateStationIterator CandidateStationsBegin()
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
class to hold data at Station level
utl::TimeStamp GetSignalStartTime() const
Start time of the signal.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
bool fIsLastTimingIteration
bool IsGoodTimeConfig(TimeCorrectionType correctionType)
double GetTotalSignal() const
Total integrated signal in VEM unit, averaged over pmts.
unsigned int fNMinStations
void GetData(bool &b) const
Overloads of the GetData member template function.
std::vector< double > fResiduals
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
double GetY(const CoordinateSystemPtr &coordinateSystem) const
constexpr double kSpeedOfLight
static bool bFirstIteration
utl::TimeStamp GetTime() const
Get time of the trigger.
ResultFlag
Flag returned by module methods to the RunController.
double CorrectTimeAltitude(int)
Detector description interface for SDetector-related data.
std::vector< StationPairStatus > fStations
CandidateStationIterator CandidateStationsEnd()
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
const sdet::Station * detector
void SetT4Trigger(const int t4)
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
const Station & GetStation(const int stationId) const
Get station by Station Id.
bool HasSRecShower() const