3 #include <fwk/CentralConfig.h>
4 #include <fwk/RunController.h>
6 #include <det/Detector.h>
8 #include <sdet/SDetector.h>
9 #include <sdet/Station.h>
11 #include <evt/Event.h>
12 #include <evt/ShowerRecData.h>
13 #include <evt/ShowerSRecData.h>
15 #include <sevt/SEvent.h>
16 #include <sevt/SEventConstants.h>
17 #include <sevt/Header.h>
18 #include <sevt/EventTrigger.h>
19 #include <sevt/Station.h>
20 #include <sevt/StationTriggerData.h>
21 #include <sevt/StationRecData.h>
22 #include <sevt/SortCriteria.h>
24 #include <utl/Vector.h>
25 #include <utl/AxialVector.h>
26 #include <utl/GeometryUtilities.h>
27 #include <utl/ErrorLogger.h>
28 #include <utl/Reader.h>
30 #include <utl/String.h>
32 #include <boost/range/iterator_range.hpp>
41 namespace SdEventPosteriorSelectorOG {
58 return core + ((n*(a - core)) / (n*axis)) * axis;
74 pair<vector<int>,
unsigned int>
75 SdEventPosteriorSelector::CalculateT5PosteriorTrigger(
const Event& event)
78 const auto& sEvent =
event.GetSEvent();
79 const auto& shRec =
event.GetRecShower();
80 if (!shRec.HasSRecShower() || sEvent.CandidateStationsBegin() == sEvent.CandidateStationsEnd())
82 const auto& shSRec = shRec.GetSRecShower();
84 const Station* hottestStation =
nullptr;
85 if (
const unsigned int id = shSRec.GetT5HottestStation())
86 hottestStation = &sEvent.GetStation(
id);
89 hottestStation = &*sEvent.CandidateStationsBegin();
92 const auto& sDet = det::Detector::GetInstance().GetSDetector();
93 const auto& hotPos = sDet.GetStation(*hottestStation).GetPosition();
95 const auto& core = shSRec.GetCorePosition();
100 vector<Point> neighborPos;
101 pair<vector<int>,
unsigned int>
result;
103 auto& neighbors = result.first;
104 for (
const auto&
s : sEvent.StationsRange()) {
105 if (
s.IsRejected() && (
s.GetRejectionStatus() & badBits))
107 const auto& pos = sDet.GetStation(
s).GetPosition();
108 const double dist =
Distance(hotPos, pos);
109 if (fFirstCrownDistanceRange[0] < dist && dist < fFirstCrownDistanceRange[1]) {
110 neighbors.push_back(
s.GetId());
111 neighborPos.push_back(pos);
115 if (neighbors.size() > 6) {
116 const string msg =
"Number of C1 stations should not be larger than 6!";
117 if (fRejectNonT5PosteriorEvents) {
124 if (neighborPos.size() < 2)
127 const auto& axis = shSRec.GetAxis();
129 unsigned int nTriangles[2] = { 0, 0 };
130 bool isCoreClosestToHottest =
false;
131 bool isCoreInHottestVoronoi =
false;
132 const int n = neighborPos.size();
133 for (
int i = 0, n1 = n - 1; i < n1; ++i) {
134 for (
int j = i+1; j < n; ++j) {
135 const auto& ci = neighborPos[i];
136 const auto& cj = neighborPos[j];
137 const double dij =
Distance(ci, cj);
139 if (dij > fSkewMaximumDistance)
144 const bool isIsosceles = (dij > fFirstCrownDistanceRange[1]);
145 ++nTriangles[isIsosceles];
147 const double dh = (pc - hotPos).GetMag2();
148 if (dh < (pc - ci).GetMag2() && dh < (pc - cj).GetMag2())
149 isCoreClosestToHottest =
true;
152 const Line shower(pc, axis);
153 const double dh =
Distance(shower, hotPos);
155 isCoreInHottestVoronoi =
true;
173 topB.
GetChild(
"RejectNonT5PosteriorEvents").
GetData(fRejectNonT5PosteriorEvents);
174 topB.
GetChild(
"MinNumberOfActiveStationsPosterior").
GetData(fMinNumberOfActiveStationsPosterior);
175 topB.
GetChild(
"FirstCrownDistanceRange").
GetData(fFirstCrownDistanceRange);
185 return eContinueLoop;
186 const auto& sEvent =
event.GetSEvent();
189 return eContinueLoop;
190 auto& shRec =
event.GetRecShower();
192 if (!shRec.HasSRecShower())
193 return eContinueLoop;
194 auto& shSRec = shRec.GetSRecShower();
196 if (fEnableT5Trigger) {
197 const auto t5NeighborsTriangle = CalculateT5PosteriorTrigger(event);
198 const int nActive = t5NeighborsTriangle.first.size();
199 const unsigned int triangleType = t5NeighborsTriangle.second;
200 const bool t5Posterior = (nActive >= fMinNumberOfActiveStationsPosterior && triangleType);
203 info <<
"T5Posterior = " << (t5Posterior ?
"true" :
"false") <<
", "
204 "NT5 = " << nActive <<
", "
205 "type = " << triangleType <<
':'
212 "station ids = " << shSRec.GetT5HottestStation() <<
"(hottest)";
213 for (
const auto id : t5NeighborsTriangle.first) {
214 const auto&
s = sEvent.GetStation(
id);
215 info <<
' ' <<
id <<
'('
216 << (
s.IsCandidate() ?
226 ++RunController::GetInstance().GetRunData().GetNamedCounters()[
"SdEventPosteriorSelector/T5Post"];
228 if (fRejectNonT5PosteriorEvents && !t5Posterior)
229 return eContinueLoop;
231 int t5Trigger = shSRec.GetT5Trigger();
233 info <<
"t5trigger " << t5Trigger <<
" -> ";
234 AsBitArray(t5Trigger).Mask(ShowerSRecData::eT5_Posterior, t5Posterior);
235 shSRec.SetT5Trigger(t5Trigger);
239 shSRec.SetT5PosteriorActiveNeighbors(t5NeighborsTriangle.first);
240 shSRec.SetT5PosteriorCoreTriangle(triangleType);
AxialVector Cross(const Vector &l, const Vector &r)
bool HasRecShower() const
Bit::Array< T > AsBitArray(T &target)
#define INFO(message)
Macro for logging informational messages.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Exception for reporting variable out of valid range.
Criterion to sort stations by decreasing signal.
Class representing a document branch.
class to hold data at Station level
std::string AsBinary(const T &number, const int maxBits=8 *sizeof(T), const char separator= ' ', const int stride=4)
converts integer-type numbers into a string of binary representation
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
bool IsAlongside(const Vector &p1, const Vector &p2, const Vector &p3)
bool IsInsideTriangle(const Point &p, const Point &a, const Point &b, const Point &c)
iff core is within triangle(a, b, c) return vector (a - projected core)
double Distance(const Point &p, const sdet::Station &s)
ResultFlag
Flag returned by module methods to the RunController.
Point ProjectPointAlongAxisToTriangle(const Point &core, const Vector &axis, const Point &a, const Point &b, const Point &c)
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
#define ERROR(message)
Macro for logging error messages.
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)