1 #include <utl/config.h>
2 #include <adst/RecEvent.h>
6 #include <fwk/CentralConfig.h>
7 #include <fwk/CoordinateSystemRegistry.h>
9 #include <utl/Reader.h>
10 #include <utl/TimeStamp.h>
11 #include <utl/ErrorLogger.h>
12 #include <utl/MathConstants.h>
13 #include <utl/PhysicalConstants.h>
14 #include <utl/Transformation.h>
15 #include <utl/CoordinateSystemPtr.h>
16 #include <utl/Point.h>
17 #include <utl/Vector.h>
18 #include <utl/AxialVector.h>
19 #include <utl/UTMPoint.h>
20 #include <utl/ReferenceEllipsoid.h>
21 #include <utl/TabulatedFunction.h>
23 #include <det/Detector.h>
24 #include <fdet/FDetector.h>
25 #include <fdet/Pixel.h>
26 #include <fdet/Camera.h>
28 #include <fdet/Telescope.h>
30 #include <fevt/FEvent.h>
32 #include <fevt/Telescope.h>
34 #include <atm/ProfileResult.h>
35 #include <atm/InclinedAtmosphericProfile.h>
36 #include <atm/AttenuationResult.h>
52 FOVCalculator::FillFOVVariables(
const fevt::FEvent& fdEvent, RecEvent& theRecEvent)
54 CoordinateSystemPtr referenceCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
55 const Atmosphere& atm = det::Detector::GetInstance().GetAtmosphere();
56 const fdet::FDetector& fdDet = det::Detector::GetInstance().GetFDetector();
58 std::vector<FDEvent>& theFDEvents = theRecEvent.GetFDEvents();
59 for (
unsigned int i = 0; i < theFDEvents.size(); ++i) {
61 const unsigned int eyeID = theFDEvents[i].GetEyeId();
65 set<unsigned int> telescopesWithData;
66 set<unsigned int> telescopesInDAQ;
69 telescopesInDAQ.insert(telIter->GetId());
73 telescopesWithData.insert(telIter->GetId());
75 if (theFDEvents[i].GetRecLevel() >= eHasGHParameters) {
77 FdRecShower& theShower = theFDEvents[i].GetFdRecShower();
78 const double zeta = theFDEvents[i].GetFdRecApertureLight().GetZeta();
79 const TVector3& adstCore = theShower.GetCoreSiteCS();
80 const TVector3& adstAxis = theShower.GetAxisSiteCS();
82 const Vector axis(adstAxis.X(), adstAxis.Y(), adstAxis.Z(), referenceCS);
83 const Point core(adstCore.X(), adstCore.Y(), adstCore.Z(), referenceCS);
92 CalculateFOVBoundaries(core, axis, detEye,
97 theShower.SetXFOVMin(xLow);
98 theShower.SetXFOVMax(xUp);
106 CalculateXmaxErrors(theRecEvent);
111 FOVCalculator::CalculateXmaxErrors(RecEvent& theRecEvent)
113 fXmaxScanner.EstimateXmaxErrors(theRecEvent);
114 std::vector<FDEvent>& theFDEvents = theRecEvent.GetFDEvents();
115 const std::vector<LongitudinalScan> longScan =
116 fXmaxScanner.GetLongitudinalScan();
117 const std::vector<double> errAtXmaxVec =
118 fXmaxScanner.GetErrorAtXmax();
119 if (theFDEvents.size() != longScan.size() ||
120 theFDEvents.size() != errAtXmaxVec.size()) {
121 ERROR(
"size mismatch FDEvent vs. XmaxErrors!!");
122 cout << theFDEvents.size() <<
' '
123 << longScan.size() <<
' '
124 << errAtXmaxVec.size() << endl;
128 for (
unsigned int i = 0; i < theFDEvents.size(); ++i) {
129 FdRecShower& recShower = theFDEvents[i].GetFdRecShower();
130 vector<double>& zVec = recShower.GetZVector();
132 vector<double>& mvaVec = recShower.GetMinViewingAngles();
134 const vector<double>& xmaxErrors = longScan[i].GetXiXmaxVector();
135 const vector<double>& mvaValues = longScan[i].GetMinViewingAngleVector();
136 for (
unsigned int j = 0; j < xmaxErrors.size(); ++j) {
137 zVec.push_back(xmaxErrors[j]/
g*
cm2);
138 mvaVec.push_back(mvaValues[j]);
140 recShower.SetZXmax(errAtXmaxVec[i]/
g*
cm2);
146 FOVCalculator::CalculateFOVBoundaries(
const Point& core,
const Vector& axis,
148 const set<unsigned int>& telsInDAQ,
149 const set<unsigned int>& telsWithData,
151 double& xLow,
double& xUp)
153 const Atmosphere& atm = det::Detector::GetInstance().GetAtmosphere();
160 double xLowGeom = -1;
167 const double maxDistance = depthProfile.
MaxX();
168 const double minDistance = depthProfile.
MinX();
170 const utl::Vector vertical(0, 0, 1, CS, Vector::kCartesian);
172 const double cosZeta = cos(zeta);
177 const double Rp = sdp.
GetMag();
179 sdp.TransformTo(eyeCS);
183 const double chi0 =
Angle(horizontal, axis);
184 const Vector eyeCoreVec = Rp / sin(
kPi - chi0) * horizontal;
185 const double eyeCoreDistance = eyeCoreVec.
GetMag();
189 const unsigned int telID = telIter->GetId();
191 const bool telHasData = (telsWithData.find(telID) != telsWithData.end());
192 const bool telInDAQ = (telsInDAQ.find(telID)!= telsInDAQ.end());
194 bool goodTelescope =
false;
197 const bool telInAquisition = telInDAQ;
198 const double telUpTime = telIter->GetUpTimeFraction();
200 cout <<
" telId=" << telID <<
" upTime = " << telUpTime
201 <<
" isInAqu=" << telInAquisition
202 <<
" " << (telHasData ?
"[data]" :
" ")
204 goodTelescope = (telUpTime > 0 && telInDAQ);
207 cerr <<
" no FdUptime available!!\n"
208 << c.GetExceptionName() <<
"\n " << c.
GetMessage() <<
'\n';
210 goodTelescope =
true;
213 if (!goodTelescope && telHasData) {
214 cerr <<
" FOVCalculator::CalculateFOVBoundaries() -"
215 <<
" telescope out of DAQ with data!! eye="
216 << detEye.
GetId() <<
" tel=" << telIter->GetId() <<
'\n';
217 goodTelescope =
true;
223 vector<unsigned int> candidatePixelIds;
225 for (
unsigned int iP = telIter->GetFirstPixelId(); iP <= telIter->GetLastPixelId(); ++iP) {
227 const Vector& pixelDir = telIter->GetPixel(iP).GetDirection();
229 const double angle = fabs(0.5*
kPi -
Angle(sdp, pixelDir));
230 if (angle <= 0.75*
degree) {
231 candidatePixelIds.push_back(iP);
235 const unsigned int minSLTPixels = 4;
237 if (candidatePixelIds.size() >= minSLTPixels) {
239 for (
unsigned int iPix = 0; iPix < candidatePixelIds.size(); ++iPix) {
241 const unsigned int iP = candidatePixelIds[iPix];
242 const Vector& pixelDir = telIter->GetPixel(iP).GetDirection();
244 const Vector chi_i_vector = pixelDir - (sdp * pixelDir) * sdp;
246 const double nominalAngle =
Angle(chi_i_vector, horizontal);
247 if (nominalAngle < 0 || nominalAngle>chi0)
252 const double chi_i = nominalAngle + dChi;
254 double l = eyeCoreDistance * sin(chi_i) / sin(chi0 - chi_i);
257 double distance = -l;
258 if (distance < minDistance)
259 distance = minDistance;
260 else if (distance > maxDistance)
261 distance = maxDistance;
263 const Vector closestApproach = eyeCoreVec + l * axis;
264 closestApproach.TransformTo(eyeCS);
267 bool isNearBorder =
false;
269 for (
auto oobPixIter = telIter->OutOfBorderPixelsBegin(); oobPixIter!= telIter->OutOfBorderPixelsEnd(); ++oobPixIter) {
270 if (
CosAngle(closestApproach, *oobPixIter) > cosZeta) {
278 const Point pclosestApproach(closestApproach.
GetX(eyeCS),
279 closestApproach.
GetY(eyeCS),
280 closestApproach.
GetZ(eyeCS),
282 const double thePhi = pclosestApproach.
GetPhi(eyeCS)/
degree;
283 if (thePhi > -1 && thePhi < 181) {
285 const double depth = depthProfile.
Y(distance);
287 if (xUpGeom < 0 || depth > xUpGeom)
289 if (xLowGeom < 0 || depth < xLowGeom)
292 if (xUpDAQ < 0 || depth > xUpDAQ)
294 if (xLowDAQ < 0 || depth < xLowDAQ)
303 cout <<
" skipping mirror with less than "
305 <<
" pixels " << candidatePixelIds.size() << endl;
312 if (xUpGeom > 0 && xLowGeom > 0) {
317 if (xUpDAQ > 0 && xLowDAQ > 0) {
322 if (fVerbosity > -1) {
323 cout <<
"geom FOV boundaries: " << detEye.
GetId() <<
" "
324 << xUpGeom <<
" " << xLowGeom <<
"\n"
325 "DAQ FOV boundaries: " << detEye.
GetId() <<
" "
326 << xUpDAQ <<
" " << xLowDAQ << endl;
327 if (xUpGeom != xUpDAQ || xLowGeom != xLowDAQ)
328 cout <<
" ######### GEOM-FOV update! ##########" << endl;
329 if (fabs(xUp - xUpDAQ) > 10*
g/
cm2 || fabs(xLow - xLowDAQ) > 10*
g/
cm2)
330 cout <<
" ######### FOV update! ##########" << endl;
341 FOVCalculator::FdUpAndRunning()
344 bool oneIsUp =
false;
345 const fdet::FDetector& fdDet = det::Detector::GetInstance().GetFDetector();
349 for (
auto telIter = eyeIter->TelescopesBegin();
350 telIter != eyeIter->TelescopesEnd(); ++telIter) {
351 if (telIter->GetDAQStatus()) {
360 cerr <<
" no FdUptime available!!\n"
361 << c.GetExceptionName() <<
"\n " << c.
GetMessage() << endl;
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
The Auger coordinate system (x to east, z local verical) for this eye.
AxialVector Cross(const Vector &l, const Vector &r)
Top of the interface to Atmosphere information.
double Angle(const double theta1, const double phi1, const double theta2, const double phi2)
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
void InitSlantProfileModel(const utl::Point &core, const utl::Vector &dir, const double deltaX) const
Base class for all exceptions used in the auger offline code.
Fluorescence Detector Eye Event.
Base class for exceptions trying to access non-existing components.
const Eye & GetEye(const unsigned int eyeId) const
Find eye by numerical Id.
EyeIterator EyesBegin(const FDetComponentSelector::Type type=FDetComponentSelector::ePhysical) const
iterator pointing to first eye of given type (ePhysical, eVirtual, eAll)
Detector description interface for Eye-related data.
Detector description interface for FDetector-related data.
double Y(const double x) const
Get the Y value (coordinate) for given X (ordinate)
Exception for reporting variable out of valid range.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Reference ellipsoids for UTM transformations.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
utl::CoordinateSystemPtr GetEyeCoordinateSystem() const
Returns the Eye Coordinate system.
Class describing the Atmospheric profile.
TelescopeIterator TelescopesEnd()
first available tel of status eHasData (DEPRECATED)
TelescopeIterator TelescopesBegin() const
Beginning of the collection of telescopes.
unsigned int GetId() const
Eye numerical Id.
Top of Fluorescence Detector event hierarchy.
AxialVector Normalized(const AxialVector &v)
Eye & GetEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
return Eye by id
TelescopeIterator TelescopesBegin()
first available tel of status eHasData (DEPRECATED)
double GetY(const CoordinateSystemPtr &coordinateSystem) const
double MinX() const
Return the minimum value for X (ordinate) stored in the profile.
execption handling for calculation/access for inclined atmosphere model
double CosAngle(const Vector &l, const Vector &r)
TelescopeIterator TelescopesEnd() const
End of the collection of telescopes.
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
const atm::ProfileResult & EvaluateSlantDepthVsDistance() const
#define ERROR(message)
Macro for logging error messages.
const std::string & GetMessage() const
Retrieve the message from the exception.
utl::Point GetPosition() const
Eye position.
double MaxX() const
Return the maximum value for X (ordinate) stored in the profile.
EyeIterator EyesEnd(const FDetComponentSelector::Type type=FDetComponentSelector::ePhysical) const
iterator pointing to end of available eyes of given type (ePhysical, eVirtual, eAll) ...