4 #include <utl/Vector.h>
5 #include <utl/CoordinateSystemPtr.h>
6 #include <utl/Transformation.h>
7 #include <utl/UTMPoint.h>
8 #include <fwk/LocalCoordinateSystem.h>
10 #include <utl/PhysicalConstants.h>
11 #include <utl/PhysicalFunctions.h>
12 #include <fevt/Pixel.h>
13 #include <fevt/PixelRecData.h>
14 #include <fevt/Telescope.h>
15 #include <fevt/TelescopeRecData.h>
18 #include <det/Detector.h>
19 #include <fdet/FDetector.h>
21 #include <fdet/Telescope.h>
22 #include <fdet/Pixel.h>
23 #include <utl/CoordinateSystemPtr.h>
24 #include <fdet/FTimeFitModel.h>
25 #include <atm/Atmosphere.h>
26 #include <atm/InclinedAtmosphericProfile.h>
27 #include <atm/ProfileResult.h>
28 #include <utl/ReferenceEllipsoid.h>
34 #include "../../General/RecDataWriterNG/ConversionUtil.h"
36 namespace FdProfileConstrainedGeometryFitPG {
65 const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
66 const unsigned int lastTel = detFD.
GetEye(eyeRec.GetEyeId()).GetLastTelescopeId();
67 std::vector<unsigned int> nPix(lastTel, 0);
70 end = eyeRec.TimeFitPixelsEnd(); pix != end; ++pix) {
71 nPix[pix->GetTelescopeId()-1]++;
73 unsigned int maxPix = 0;
74 for (
unsigned int i=0; i<nPix.size(); i++) {
75 if (nPix[i] > maxPix) {
81 fEyeId = eyeRec.GetEyeId();
90 end = eyeRec.TimeFitPixelsEnd(); pix != end; ++pix) {
95 tels.push_back(pix->GetTelescopeId());
96 pixids.push_back(pix->GetId());
117 std::vector<double> xs;
118 std::vector<double> ys;
119 std::vector<double> yerrs;
123 for (
unsigned int i = 0, n =
chii.size(); i < n; ++i) {
125 xs.push_back(tan(0.5*(chi0 -
chii[i])));
126 ys.push_back(
times[i]);
148 double& rp,
double &rpErr,
149 double& t0,
double &t0Err,
153 std::vector<double> xs;
154 std::vector<double> ys;
155 std::vector<double> yerrs;
157 for (
unsigned int i = 0, n =
chii.size(); i < n; ++i) {
159 xs.push_back(tan(0.5*(chi0 -
chii[i])));
160 ys.push_back(
times[i]);
179 const double dirErr = 0.35*
deg;
181 double& Chi0 = par[0];
186 const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
191 const Vector vertical(0,0,1, telCS);
194 const Transformation rot = Transformation::Rotation(-Chi0, sdp, telCS);
197 const double coreDistance = Rp / sin(Chi0);
198 const Vector coreTelVec = coreDistance * horizontalInSDP;
199 const Point core = telPos + coreTelVec;
204 const atm::Atmosphere& atmo = det::Detector::GetInstance().GetAtmosphere();
211 double logLikeSum = 0.;
212 double logLikeSumSDP = 0.;
213 for (
int i = 0, n =
chii.size(); i < n; ++i) {
219 const Point core_in_curtel = core-axis*core.
GetZ(curtelCS)/cos(axis.GetTheta(curtelCS));
221 const Vector curtel_to_core = core_in_curtel-curtelPos;
222 double chi0_in_curtel =
Angle(curtel_to_core, axis);
223 if (axis.GetTheta(curtelCS) >
kPi/2.) {
224 chi0_in_curtel = -(
kPi-chi0_in_curtel);
226 double rp_in_curtel = curtel_to_core.GetMag()*sin(chi0_in_curtel);
227 if (axis.GetTheta(curtelCS) >
kPi/2.) {
233 const Vector Pt_to_Pct = P_in_curtel - P_in_tel;
234 const double t0_in_curtel = T0 + ((Pt_to_Pct*axis > 0.) ? -1. : 1.)*Pt_to_Pct.
GetMag()/
kSpeedOfLight;
236 const Vector vertical_in_curtel(0,0,1, curtelCS);
240 const Vector pixelDirInSDP = pixelDirection - (SDP_in_curtel * pixelDirection)*SDP_in_curtel;
241 const double pixelChi =
Angle(pixelDirInSDP, horizontalInSDP_in_curtel);
243 const double angleWithSDP =
abs(
kPiOnTwo -
Angle(SDP_in_curtel, pixelDirection));
245 const Point PointOnShower = P_in_curtel+axis*rp_in_curtel/tan(chi0_in_curtel-pixelChi);
246 const double cosLocalZenith =
249 const double pressure = pressureProfile.
Y(height);
250 const double temperature = tempProfile.
Y(height);
251 const double rMoliere =
MoliereRadius(temperature, pressure, cosLocalZenith);
252 const Vector core_to_PoS = PointOnShower-core;
253 const double age =
ShowerAge(slantDepthProfile.
Y( ((core_to_PoS*axis > 0.) ? -1. : 1.) * core_to_PoS.
GetMag() ),
fXmax);
256 const double rMcor = rMoliere*rcorr;
259 double ti_exp = timeFitModel.GetTimeAtAperture(t0_in_curtel, rp_in_curtel, chi0_in_curtel, pixelChi,
263 logLikeSumSDP += (-0.5*(2*
kPi) - log(dirErr) - 0.5*
pow(angleWithSDP/dirErr, 2));
265 logLikeSum += logLikeSumSDP;
266 if (logLikeSum != 0) {
269 f = std::numeric_limits<double>::infinity();
272 }
catch (
const std::exception&) {
273 f = std::numeric_limits<double>::infinity();
280 double& T0,
double& T0err,
281 double& Rp,
double& Rperr,
285 TMinuit theMinuit(npar);
286 theMinuit.SetPrintLevel(-1);
288 double arglist[
npar];
292 theMinuit.mnexcm(
"SET ERR", arglist,1,ierflag);
293 if (ierflag)
ERROR(
"Minuit SET ERR failed");
294 static double vstart[
npar];
295 static double step[
npar];
302 theMinuit.mnparm(0,
"Chi0", vstart[0], step[0], 0,0,ierflag);
303 theMinuit.FixParameter(0);
304 theMinuit.mnparm(1,
"T0", vstart[1], step[1], vstart[1]-300, vstart[1]+300.,ierflag);
305 theMinuit.mnparm(2,
"Rp", vstart[2], step[2], vstart[2]-300., vstart[2]+300.,ierflag);
308 theMinuit.mnexcm(
"MIGRAD", arglist, 2, ierflag);
310 ERROR(
"Minuit MIGRAD failed");
312 theMinuit.GetParameter(1, T0, T0err);
313 theMinuit.GetParameter(2, Rp, Rperr);
314 chi2 = theMinuit.fAmin;
319 const std::vector<double>& y,
320 const std::vector<double>& ey,
321 double& a0,
double& a0err,
322 double& a1,
double& a1err,
332 for (
unsigned int i = 0; i<x.size(); ++i) {
334 const double wi = 1.0 / (ey[i]*ey[i]);
337 sxx += wi * x[i] * x[i];
339 sxy += wi * x[i] * y[i];
340 syy += wi * y[i] * y[i];
344 const double dinv = 1.0/(sw*sxx - sx*sx);
346 a0 = (sxx*sy - sx * sxy) * dinv;
347 a1 = (-sx*sy + sw * sxy) * dinv;
348 a0err =
sqrt (sxx * dinv);
349 a1err =
sqrt (sw * dinv);
352 chi2 = syy - a0*sy - a1*sxy;
354 double logLikeSum = 0;
355 for (
unsigned int i = 0; i<x.size(); ++i) {
356 logLikeSum += (-0.5*log(ey[i]*ey[i]) - 0.5*
pow( (y[i]-(a0+a1*x[i]))/ey[i] , 2));
358 chi2 = -2.*logLikeSum;
Telescope & GetTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Telescope by Id, throw exception if not existent.
AxialVector Cross(const Vector &l, const Vector &r)
const utl::Vector & GetDirection() const
pointing direction of this pixel
Top of the interface to Atmosphere information.
double InverseGoraCDF(const double fraction, const double age)
static std::vector< double > times
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
Fluorescence Detector Eye Event.
unsigned int PrepParams(const fevt::Eye &eye)
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Class to hold and convert a point in geodetic coordinates.
const atm::ProfileResult & EvaluatePressureVsHeight() const
Tabulated function giving Y=air pressure as a function of X=height.
static std::vector< double > chii
void LinearFitErrors(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &ey, double &a0, double &a0err, double &a1, double &a1err, double &chi2) const
const Eye & GetEye(const unsigned int eyeId) const
Find eye by numerical Id.
fevt::TelescopeRecData & GetRecData()
Reconstructed data for this telescope.
static std::vector< int > pixids
double pow(const double x, const unsigned int i)
void SetRealAtm(bool realAtm, bool deex, bool emissionPointCorrection)
Detector description interface for FDetector-related data.
double Y(const double x) const
Get the Y value (coordinate) for given X (ordinate)
boost::indirect_iterator< ConstInternalPixelIterator, const Pixel & > ConstPixelIterator
Const iterator over pixels used in reconstruction.
const Pixel & GetPixel(const unsigned int pixelId) const
Get Pixel by id, throw utl::NonExistentComponentException if n.a.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Reference ellipsoids for UTM transformations.
double MoliereRadius(double temperature, double pressure, const double cosTheta)
The Moliere Radius (2 radiation length above obs-level, GAP-1998-002)
Class describing the Atmospheric profile.
utl::TimeInterval GetT_i() const
double abs(const SVector< n, T > &v)
Triple PointToLatitudeLongitudeHeight(const Point &thePoint) const
Convert Point to Lat/Long/Height.
constexpr double kPiOnTwo
static std::vector< double > timeErrs
static std::vector< int > tels
Eye-specific shower reconstruction data.
AxialVector Normalized(const AxialVector &v)
double GetInterval() const
Get the time interval as a double (in Auger base units)
void MinuitFitErrors(const double Chi0, double &T0, double &T0err, double &Rp, double &Rperr, double &chi2) const
constexpr double kSpeedOfLight
Detector description interface for Telescope-related data.
static bool fEmissionPointCorrection
double ShowerAge(const double slantDepth, const double showerMax)
General definition of shower age.
static void MinuitFitFunc(int &npar, double *gin, double &f, double *par, int iflag)
bool HasTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData) const
Check if the telescope is in the event.
utl::Point GetPosition() const
utl::TimeInterval GetT_iError() const
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
void LinearFit(const vector< double > &x, const vector< double > &y, const vector< double > &ey, double &a0, double &a1, double &chi2)
Do a linear fit and return coefficients and chi2.
double GetNanoSecond() const
Get integer number of nanoseconds past seconds boundary.
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
const utl::AxialVector & GetSDP() const
const atm::ProfileResult & EvaluateSlantDepthVsDistance() const
#define ERROR(message)
Macro for logging error messages.
Fluorescence Detector Pixel Reconstructed Data.
void operator()(const double chi0, double &chi2, double &rp, double &t0, double Xmax=600 *utl::g/utl::cm2) const
const atm::ProfileResult & EvaluateTemperatureVsHeight() const
Tabulated function giving Y=temperature as a function of X=height.
fevt::EyeRecData & GetRecData()
Reconstructed data for this eye.