RdPlaneFit.cc
Go to the documentation of this file.
1 #include "RdPlaneFit.h"
2 
3 #include <fwk/CentralConfig.h>
4 #include <fwk/LocalCoordinateSystem.h>
5 #include <fwk/CoordinateSystemRegistry.h>
6 
7 #include <det/Detector.h>
8 #include <rdet/RDetector.h>
9 
10 #include <utl/ErrorLogger.h>
11 #include <utl/Reader.h>
12 #include <utl/config.h>
13 #include <utl/PhysicalConstants.h>
14 #include <utl/AxialVector.h>
15 #include <utl/Math.h>
16 #include <utl/ErrorLogger.h>
17 #include <utl/AnalyticCoordinateTransformator.h>
18 
19 #include <evt/Event.h>
20 #include <evt/ShowerRecData.h>
21 #include <evt/ShowerRRecData.h>
22 #include <evt/ShowerRRecDataQuantities.h>
23 
24 #include <revt/REvent.h>
25 #include <revt/Station.h>
26 #include <revt/Header.h>
27 #include <revt/StationRecData.h>
28 
29 #include <CLHEP/Matrix/Matrix.h>
30 #include <CLHEP/Matrix/Vector.h>
31 
32 #include <TMinuit.h>
33 
34 #include <cmath>
35 
36 using namespace std;
37 using namespace revt;
38 using namespace evt;
39 using namespace fwk;
40 using namespace utl;
41 using CLHEP::HepMatrix;
42 using CLHEP::HepVector;
43 
44 
45 namespace RdPlaneFit {
46 
47  // global variables
48  REvent* RdPlaneFit::fgCurrentREvent;
49  Point RdPlaneFit::fgBarycenter;
50  TimeStamp RdPlaneFit::fgBaryTime;
51  CoordinateSystemPtr RdPlaneFit::fgLocalCS;
52  Point RdPlaneFit::fgCoordinateOrigin;
53  double RdPlaneFit::fgMeanEventTime;
54 
55 
56  template<typename G>
57  inline
58  string
59  ToString(const G& g, const CoordinateSystemPtr cs)
60  {
61  ostringstream os;
62  os << '(' << g.GetX(cs) / meter << ", " << g.GetY(cs) / meter << ", " << g.GetZ(cs) / meter << ") [m]";
63  return os.str();
64  }
65 
66 
69  {
70  // Read in the configurations of the xml file
71  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdPlaneFit");
72  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
73 
74  fMinuitOutput = (fInfoLevel >= eInfoDebug) ? true : false;
75 
76  topBranch.GetChild("minNumberOfStations").GetData(fMinNumberOfStations);
77  topBranch.GetChild("allowUnphysicalCosines").GetData(fAllowUnphysicalCosines);
78 
79  const string yesnostr = topBranch.GetChild("allowMultipleCalls").Get<string>();
80  fLockParameterStorage = (yesnostr == "no");
81 
82  return eSuccess;
83  }
84 
85 
86  // analytic linear fit in local CS; approximation by neglecting
87  // z-coordinate, since z ~ 0 in local bary coordinate system,
88  // therefore loosing the w component of the axis. it is funny
89  // though, that stations living on a plane can not distinguish
90  // between upwards or downwards-going showers.
91 
93  RdPlaneFit::LinearFit(FitParameters& fit, const bool reuseFit)
94  const
95  {
96  //const double cosTheta = (reuseFit ? fit.w : 1);
97  const Vector approx_axis = (reuseFit ? Vector(fit.u, fit.v, fit.w, fgLocalCS) : Vector());
98  const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
99 
100  double s1 = 0;
101  double sx = 0;
102  double sy = 0;
103  double st = 0;
104  double sxx = 0;
105  double sxy = 0;
106  double syy = 0;
107  double sxt = 0;
108  double syt = 0;
109  //double stt = 0;
110 
111  // loop over all stations
112  for (auto sIt = fgCurrentREvent->SignalStationsBegin();
113  sIt != fgCurrentREvent->SignalStationsEnd(); ++sIt) {
114  const Vector sPos = rDetector.GetStation(*sIt).GetPosition() - fgBarycenter;
115  const double x = sPos.GetX(fgLocalCS);
116  const double y = sPos.GetY(fgLocalCS);
117  const StationRecData& sRec = sIt->GetRecData();
118  //const double t = (sRec.GetSignalTime() - fgBaryTime).GetInterval();
119  const double t = sRec.GetParameter(eSignalTime) - fgMeanEventTime;
120  //const double invSigma2 = 1 / (sRec.GetSignalTimeError() * sRec.GetSignalTimeError());
121  const double invSigma2 = 1 / (sRec.GetParameterError(eSignalTime) * sRec.GetParameterError(eSignalTime));
122  s1 += invSigma2;
123  const double x_s = x * invSigma2;
124  sx += x_s;
125  sxx += x * x_s;
126  sxy += y * x_s;
127  sxt += t * x_s;
128  const double y_s = y * invSigma2;
129  sy += y_s;
130  syy += y * y_s;
131  syt += t * y_s;
132  st += t * invSigma2;
133  //stt += t*t;
134  }
135 
136  st *= kSpeedOfLight;
137  sxt *= kSpeedOfLight;
138  syt *= kSpeedOfLight;
139  //stt *= kSpeedOfLight*kSpeedOfLight;
140 
141  HepMatrix mat(3, 3);
142 
143  mat[0][0] = sxx;
144  mat[0][1] = sxy;
145  mat[0][2] = -sx;
146  mat[1][0] = sxy;
147  mat[1][1] = syy;
148  mat[1][2] = -sy;
149  mat[2][0] = -sx;
150  mat[2][1] = -sy;
151  mat[2][2] = s1;
152 
153  int ierr = 0;
154  mat.invert(ierr);
155 
156  if (ierr) {
157  INFO("Matrix inversion failed.");
158  return eFailure;
159  }
160 
161  HepVector k(3);
162 
163  k[0] = -sxt;
164  k[1] = -syt;
165  k[2] = st;
166 
167  const HepVector p = mat * k;
168  double w2 = 1 - Sqr(p[0]) - Sqr(p[1]);
169 
170  if (w2 < 0) {
171  WARNING("Unphysical direction cosines");
172  if (fAllowUnphysicalCosines) {
173  WARNING("Setting z-compenent of the shower axis to 0");
174  w2 = 0;
175  } else
176  return eFailure;
177  }
178 
179  fit.u = p[0];
180  fit.v = p[1];
181  fit.w = sqrt(w2);
182  fit.ct0 = p[2];
183 
184  fit.sigmaU2 = mat[0][0];
185  fit.sigmaV2 = mat[1][1];
186  fit.sigmaUV = mat[0][1];
187  fit.sigmact02 = mat[2][2];
188 
189  return eSuccess;
190  }
191 
192 
194  RdPlaneFit::Run(evt::Event& event)
195  {
196  INFO("Plane fit");
197 
198  // nothing to do if there is no REvent
199  if (!event.HasREvent()) {
200  INFOIntermediate("eContinueLoop: No REvent, so no reconstruction");
201  return eContinueLoop;
202  }
203 
204  fgCurrentREvent = &event.GetREvent();
205  const REvent& rEvent = *fgCurrentREvent;
206 
207  const det::Detector& detector = det::Detector::GetInstance();
208  const rdet::RDetector& rDetector = detector.GetRDetector();
209 
210  if (!event.HasRecShower())
211  event.MakeRecShower();
212  if (!event.GetRecShower().HasRRecShower())
213  event.GetRecShower().MakeRRecShower();
214  ShowerRRecData& showerrrec = event.GetRecShower().GetRRecShower();
215 
216  try {
217  fgCoordinateOrigin = showerrrec.GetCoordinateOrigin();
218  fgLocalCS = LocalCoordinateSystem::Create(fgCoordinateOrigin);
220  ostringstream err;
221  err << "Problem when getting coordinate origin \n";
222  err << "Did you call the RdEventInitializer ? \n";
223  err << " Caught utl::NonExistentComponentException : " << e.what();
224  err << "\n Will Break loop \n";
225  ERROR(err.str());
226  return eBreakLoop;
227  }
228 
229  const TimeStamp& eventTime = rEvent.GetHeader().GetTime();
230 
231  // weighted sums
232  Vector barySum(0, 0, 0, fgLocalCS);
233  TimeInterval timeSum = 0;
234  double weightSum = 0;
235  int nStations = 0;
236  for (auto sIt = fgCurrentREvent->SignalStationsBegin();
237  sIt != fgCurrentREvent->SignalStationsEnd(); ++sIt) {
238  const rdet::Station& dStation = rDetector.GetStation(*sIt);
239  const StationRecData& sRec = sIt->GetRecData();
240  const double weight = sqrt(sRec.GetParameter(eSignal));
241  weightSum += weight;
242  barySum += weight * (dStation.GetPosition() - fgCoordinateOrigin);
243  timeSum += weight * sRec.GetParameter(eSignalTime);
244  ++nStations;
245  }
246 
247  ostringstream info;
248  info << "Number of signal stations = " << nStations;
249  INFOFinal(info);
250 
251  // not worth it
252  if (nStations < fMinNumberOfStations) {
253  info.str("");
254  info << "eContinueLoop: Not enough stations." << endl;
255  if (event.HasRecShower()) {
256  if (event.GetRecShower().HasRRecShower()) {
257  event.GetRecShower().GetRRecShower().SetParameter(eFitSuccess, 0, fLockParameterStorage);
258  info << "Set FitSuccess to false.";
259  }
260  }
261  INFOFinal(info);
262  return eContinueLoop;
263  }
264 
265  if (!weightSum) {
266  info.str("");
267  info << "eContinueLoop: sum of weights = 0" << endl;
268  if (event.HasRecShower()) {
269  if (event.GetRecShower().HasRRecShower()) {
270  event.GetRecShower().GetRRecShower().SetParameter(eFitSuccess, 0, fLockParameterStorage);
271  info << "Set FitSuccess to false.";
272  }
273  }
274  INFOIntermediate(info);
275  return eContinueLoop;
276  }
277 
278  barySum /= weightSum;
279  timeSum /= weightSum;
280  fgMeanEventTime = timeSum;
281  fgBarycenter = barySum + fgCoordinateOrigin;
282  fgBaryTime = eventTime + timeSum;
283 
284  // site coordinate system (usually Malargue), only you used for terminal output
285  const CoordinateSystemPtr siteCS = detector.GetSiteCoordinateSystem();
286  // get reference coordinate system of detector (usually PampaAmarilla)
287  const CoordinateSystemPtr referenceCS = detector.GetReferenceCoordinateSystem();
288  info.str("");
289  info << "barycenter = " << ToString(fgBarycenter, siteCS) << " (site)" << std::endl
290  << "bary time = " << timeSum / nanosecond << " [ns] (to event time)\n"
291  << "local/site zenith angle diff. = "
292  << acos(Vector(0, 0, 1, fgLocalCS) * Vector(0, 0, 1, siteCS)) / degree << " [deg]";
293  INFOIntermediate(info);
294 
295  // this will point to the final result
296  FitParameters finalFitResult;
297 
298  // first approximation
299  FitParameters fitLin;
300  if (LinearFit(fitLin) != eSuccess) {
301  INFOIntermediate("eContinueLoop: Linear fit was not successful");
302  if (event.HasRecShower()) {
303  if (event.GetRecShower().HasRRecShower()) {
304  event.GetRecShower().GetRRecShower().SetParameter(eFitSuccess, 0, fLockParameterStorage);
305  INFOIntermediate("Set FitSuccess to false.");
306  }
307  }
308  return eContinueLoop;
309  }
310 
311  // try again with previous values as approxiamtions for sigma
312  LinearFit(fitLin, true);
313 
314  // with first approximation on u and v, the nonlinear fit is attempted
315  FitParameters fitNonlin = fitLin;
316 
317  bool nonLinearFitUsed = false;
318 
319  info.str("");
320  if (PlaneFit3DDriver(fitNonlin) == eSuccess) {
321  //fitNonlin.stage = ShowerSRecData::kPlaneFit3d;
322  info << "\n\tStage " << fitLin.stage << ": linear plane fit"
323  << "\n\taxis = (" << fitLin.u << ", " << fitLin.v << ", " << fitLin.w << ") (bary)"
324  << "\n\ttheta = " << acos(fitLin.w) / degree
325  << "\n\tphi = " << atan2(fitLin.v, fitLin.u) / degree
326  << "\n\tct0 = " << fitLin.ct0 / meter << " [m]";
327  nonLinearFitUsed = true;
328  finalFitResult = fitNonlin;
329  } else {
330  info << " Nonlinear fit failed, using linear approximation.";
331  finalFitResult = fitLin;
332  }
333  INFOIntermediate(info);
334 
335 
336  // Fill the event
337  const Vector axis(finalFitResult.u, finalFitResult.v, finalFitResult.w, fgLocalCS);
338  showerrrec.SetParameter(eShowerAxisX, axis.GetX(fgLocalCS), fLockParameterStorage);
339  showerrrec.SetParameter(eShowerAxisY, axis.GetY(fgLocalCS), fLockParameterStorage);
340  showerrrec.SetParameter(eShowerAxisZ, axis.GetZ(fgLocalCS), fLockParameterStorage);
341 
342  // save Covariance matrix, copied from RdWaveFit
343  double thetaError;
344  double phiError;
345  double thetaPhiCorrelation;
346  PropagateAxisErrors(axis.GetCoordinates(fgLocalCS),
347  Vector::Triple(finalFitResult.sigmaU2, finalFitResult.sigmaUV, finalFitResult.sigmaV2),
348  thetaError, phiError, thetaPhiCorrelation);
349  int r = 1;
350  double theta = acos(finalFitResult.w);
351  double phi = atan2(finalFitResult.v, finalFitResult.u);
352  int c00 = 0;
353  int c01 = 0;
354  int c02 = 0; // radius not fitted
355  double c11 = thetaError * thetaError;
356  double c22 = phiError * phiError;
357  double c12 = thetaPhiCorrelation * thetaError * phiError;
358 
359  double tempCov =
360  AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(0, 0, r, theta, phi, c00, c11, c22, c01, c02, c12);
361  showerrrec.SetParameterCovariance(eShowerAxisX, eShowerAxisX, tempCov, fLockParameterStorage);
362  tempCov =
363  AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(1, 1, r, theta, phi, c00, c11, c22, c01, c02, c12);
364  showerrrec.SetParameterCovariance(eShowerAxisY, eShowerAxisY, tempCov, fLockParameterStorage);
365  tempCov =
366  AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(2, 2, r, theta, phi, c00, c11, c22, c01, c02, c12);
367  showerrrec.SetParameterCovariance(eShowerAxisZ, eShowerAxisZ, tempCov, fLockParameterStorage);
368  tempCov =
369  AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(0, 1, r, theta, phi, c00, c11, c22, c01, c02, c12);
370  showerrrec.SetParameterCovariance(eShowerAxisX, eShowerAxisY, tempCov, fLockParameterStorage);
371  tempCov =
372  AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(0, 2, r, theta, phi, c00, c11, c22, c01, c02, c12);
373  showerrrec.SetParameterCovariance(eShowerAxisX, eShowerAxisZ, tempCov, fLockParameterStorage);
374  tempCov =
375  AnalyticCoordinateTransformator::GetCartesianCovarianceFromSpherical(1, 2, r, theta, phi, c00, c11, c22, c01, c02, c12);
376  showerrrec.SetParameterCovariance(eShowerAxisY, eShowerAxisZ, tempCov, fLockParameterStorage);
377 
378  showerrrec.SetParameter(eCoreTime, fgMeanEventTime + finalFitResult.ct0 / kSpeedOfLight, fLockParameterStorage);
379  showerrrec.SetParameterError(eCoreTime, fgMeanEventTime + sqrt(finalFitResult.sigmact02), fLockParameterStorage);
380 
381  // set signal arrival direction for individual stations
382  // For a plane wave fit the direction is of course the same for all station, but
383  // for some applications the RdAntennaChannelToStationConverter has to know the individual
384  // arrival directions. So the values have to be set.
385  for (auto sIt = fgCurrentREvent->SignalStationsBegin();
386  sIt != fgCurrentREvent->SignalStationsEnd(); ++sIt) {
387  Station& station = *sIt;
388  station.GetRecData().SetParameter(eSignalArrivalDirectionX, axis.GetX(fgLocalCS), fLockParameterStorage);
389  station.GetRecData().SetParameter(eSignalArrivalDirectionY, axis.GetY(fgLocalCS), fLockParameterStorage);
390  station.GetRecData().SetParameter(eSignalArrivalDirectionZ, axis.GetZ(fgLocalCS), fLockParameterStorage);
391  }
392 
393  double chi2 = 0;
394  // calculates residuals and fill them in station rec
395  CalculateTimeResidual(axis, finalFitResult.ct0, chi2);
396 
397  const int angleNDOF = nStations - 3;
398  showerrrec.SetParameter(eWaveFitNDF, angleNDOF, fLockParameterStorage);
399  showerrrec.SetParameter(eWaveFitChi2, chi2, fLockParameterStorage);
400  showerrrec.SetParameter(eFitSuccess, 1, fLockParameterStorage);
401 
402  info.str("");
403  info << "\n\tStage " << finalFitResult.stage << ": " << (nonLinearFitUsed ? "3d" : "linear") << " plane fit"
404  << "\n\taxis = (" << finalFitResult.u << ", " << finalFitResult.v << ", " << finalFitResult.w << ") (bary)"
405  << "\n\ttheta = " << acos(finalFitResult.w) / degree << " +/- "
406  << showerrrec.GetZenithError()/degree << " [deg] (bary)"
407  << "\n\tphi = " << atan2(finalFitResult.v, finalFitResult.u) / degree << " +/- "
408  << showerrrec.GetAzimuthError()/degree << " [deg]"
409  << "\n\tct0 = " << finalFitResult.ct0 / meter << " [m]";
410  INFOFinal(info);
411 
412  return eSuccess;
413  }
414 
415 
417  RdPlaneFit::PlaneFit3DDriver(FitParameters& fit)
418  const
419  {
420  TMinuit minuit(3);
421  int errFlag = 0;
422  double argList[10];
423  argList[0] = -1;
424  if (!fMinuitOutput) {
425  minuit.mnexcm("SET PRINTOUT", argList, 1, errFlag);
426  minuit.mnexcm("SET NOWARNINGS", argList, 0, errFlag);
427  minuit.SetPrintLevel(-1);
428  }
429 
430  if (fAllowUnphysicalCosines) {
431  minuit.SetFCN(RdPlaneFit::PlaneFit3DHorizonFnc);
432  argList[0] = 1; // chi2
433  minuit.mnexcm("SET ERRORDEF", argList, 1, errFlag);
434  minuit.mnparm(0, "theta", acos(fit.w), 0.01, 0, 0, errFlag);
435  minuit.mnparm(1, "phi", atan2(fit.v, fit.u), 0.01, 0, 0, errFlag);
436  minuit.mnparm(2, "ct0", fit.ct0, 10 * meter, 0, 0, errFlag);
437  } else {
438  minuit.SetFCN(RdPlaneFit::PlaneFit3DFnc);
439  argList[0] = 1; // chi2
440  minuit.mnexcm("SET ERRORDEF", argList, 1, errFlag);
441  minuit.mnparm(0, "u", fit.u, 0.01, 0, 0, errFlag);
442  minuit.mnparm(1, "v", fit.v, 0.01, 0, 0, errFlag);
443  minuit.mnparm(2, "ct0", fit.ct0, 10 * meter, 0, 0, errFlag);
444  }
445 
446  ostringstream info;
447 
448  // init fnc
449  argList[0] = 1;
450  minuit.mnexcm("CALI", argList, 1, errFlag);
451 
452  argList[0] = 500;
453  minuit.mnexcm("MINIMIZE", argList, 1, errFlag);
454  if (errFlag) {
455  info.str("");
456  info << "minuit minimize error: " << errFlag << '\n';
457  INFOIntermediate(info);
458 
459  minuit.mnexcm("MINOS", argList, 0, errFlag);
460  if (errFlag) {
461  info.str("");
462  info << "minuit minos error: " << errFlag << '\n';
463  INFOIntermediate(info);
464 
465  return eFailure;
466  }
467  }
468 
469  // Get results
470  double foo = 0;
471  double par1 = 0;
472  double par2 = 0;
473 
474  minuit.GetParameter(0, par1, foo);
475  minuit.GetParameter(1, par2, foo);
476 
477  if (fAllowUnphysicalCosines) {
478  fit.u = sin(par1) * cos(par2);
479  fit.v = sin(par1) * sin(par2);
480  fit.w = cos(par1);
481  } else {
482  fit.u = par1;
483  fit.v = par2;
484  double w2 = 1 - Sqr(fit.u) - Sqr(fit.v);
485  if (w2 < 0) {
486  info.str("");
487  info << "eFailure: Fit failed due to unphysical angle cosines";
488  INFOFinal(info);
489 
490  return eFailure;
491  }
492  fit.w = sqrt(w2);
493  }
494 
495  minuit.GetParameter(2, fit.ct0, foo);
496 
497  // error matrix
498  double emat[3][3];
499  minuit.mnemat(&emat[0][0], 3);
500  fit.sigmaU2 = emat[0][0];
501  fit.sigmaV2 = emat[1][1];
502  fit.sigmaUV = emat[0][1];
503  fit.sigmact02 = emat[2][2];
504 
505  return eSuccess;
506  }
507 
508 
510  RdPlaneFit::Finish()
511  {
512  INFODebug("");
513  return eSuccess;
514  }
515 
516 
517  void
518  RdPlaneFit::PlaneFit3DFnc(int& /*nPar*/, double* const /*grad*/, double& value, double* const par, const int flag)
519  {
520  const double& u = par[0];
521  const double& v = par[1];
522  const double& ct0 = par[2];
523  static int nStations = 0;
524  static vector<double> sTiming; // station timing
525  static vector<double> sSignal; // station signal
526  static vector<Vector> sPosition; // station position
527  static vector<double> sTimeSigma2; // Uncurtainty on the pulse timing
528  //static const sdet::STimeVariance* timeVariance = 0;
529 
530  if (flag == 1) { // fnc init
531 
532  sTiming.clear();
533  sSignal.clear();
534  sPosition.clear();
535  sTimeSigma2.clear();
536 
537  const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
538 
539  for (auto sIt = fgCurrentREvent->SignalStationsBegin();
540  sIt != fgCurrentREvent->SignalStationsEnd(); ++sIt) {
541  const StationRecData& sRec = sIt->GetRecData();
542  //sTiming.push_back(kSpeedOfLight * (sRec.GetSignalTime() - fgBaryTime).GetInterval());
543  sTiming.push_back(kSpeedOfLight * (sRec.GetParameter(eSignalTime) - fgMeanEventTime));
544  sSignal.push_back(sRec.GetParameter(eSignal));
545  sPosition.push_back(rDetector.GetStation(*sIt).GetPosition() - fgBarycenter);
546  sTimeSigma2.push_back(sRec.GetParameterError(eSignalTime) * sRec.GetParameterError(eSignalTime));
547  }
548 
549  nStations = sTiming.size();
550 
551  //timeVariance = &sdet::STimeVariance::GetInstance();
552 
553  } // fnc init
554 
555  const double w2 = 1 - Sqr(u) - Sqr(v);
556 
557  if (w2 < 0) {
558  value = 1e30;
559  return;
560  }
561 
562  const double w = sqrt(w2);
563 
564  const Vector axis(u, v, w, fgLocalCS);
565 
566  double chi2 = 0;
567 
568  for (int i = 0; i < nStations; ++i)
569  chi2 += Sqr(sTiming[i] - ct0 + axis * sPosition[i]) / sTimeSigma2[i];
570 
571  value = chi2 / kSpeedOfLight2;
572  }
573 
574 
575  void
576  RdPlaneFit::PlaneFit3DHorizonFnc(int& /*nPar*/, double* const /*grad*/, double& value,
577  double* const par, const int flag)
578  {
579  const double& theta = par[0];
580  const double& phi = par[1];
581  const double& ct0 = par[2];
582  static int nStations = 0;
583  static vector<double> sTiming; // station timing
584  static vector<double> sSignal; // station signal
585  static vector<Vector> sPosition; // station position
586  static vector<double> sTimeSigma2; // Uncurtainty on the pulse timing
587  //static const sdet::STimeVariance* timeVariance = 0;
588 
589  if (flag == 1) { // fnc init
590 
591  sTiming.clear();
592  sSignal.clear();
593  sPosition.clear();
594  sTimeSigma2.clear();
595 
596  const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
597 
598  for (auto sIt = fgCurrentREvent->SignalStationsBegin();
599  sIt != fgCurrentREvent->SignalStationsEnd(); ++sIt) {
600  const StationRecData& sRec = sIt->GetRecData();
601  sTiming.push_back(kSpeedOfLight * (sRec.GetParameter(eSignalTime) - fgMeanEventTime));
602  sSignal.push_back(sRec.GetParameter(eSignal));
603  sPosition.push_back(rDetector.GetStation(*sIt).GetPosition() - fgBarycenter);
604  sTimeSigma2.push_back((sRec.GetParameterError(eSignalTime) * sRec.GetParameterError(eSignalTime)));
605  }
606 
607  nStations = sTiming.size();
608 
609  //timeVariance = &sdet::STimeVariance::GetInstance();
610 
611  } // fnc init
612 
613  const Vector axis(cos(phi) * sin(theta), sin(phi) * sin(theta), cos(theta), fgLocalCS);
614 
615  double chi2 = 0;
616 
617  for (int i = 0; i < nStations; ++i)
618  chi2 += Sqr(sTiming[i] - ct0 + axis * sPosition[i]) / sTimeSigma2[i];
619 
620  value = chi2 / kSpeedOfLight2;
621  }
622 
623 
624  void
625  RdPlaneFit::CalculateTimeResidual(const utl::Vector& axis, const double ct0, double& chi2)
626  const
627  {
628  const double t0 = ct0 / kSpeedOfLight;
629  const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
630  chi2 = 0;
631  for (auto sIt = fgCurrentREvent->SignalStationsBegin();
632  sIt != fgCurrentREvent->SignalStationsEnd(); ++sIt) {
633  StationRecData& sRec = sIt->GetRecData();
634  const Vector stLoc_c = (rDetector.GetStation(*sIt).GetPosition() - fgBarycenter) / kSpeedOfLight;
635  const double t = (sRec.GetParameter(eSignalTime) - fgMeanEventTime);
636  double sigma_t =sRec.GetParameterError(eSignalTime);
637  double timeResidual = t - t0 + (stLoc_c * axis);
638  sRec.SetParameter(eTimeResidual, timeResidual, fLockParameterStorage);
639  sRec.SetParameterError(eTimeResidual, sigma_t, fLockParameterStorage);
640  chi2 += pow(timeResidual / sigma_t,2);
641  }
642  }
643 
644 }
Branch GetTopBranch() const
Definition: Branch.cc:63
Class to access station level reconstructed data.
void SetParameter(Parameter i, double value, bool lock=true)
void SetParameterError(Parameter i, double value, bool lock=true)
double GetZenithError() const
returns the error of the zenith angle (from the wave fit)
const double degree
constexpr T Sqr(const T &x)
Point object.
Definition: Point.h:32
Detector description interface for Station-related data.
StationRecData & GetRecData()
Get station level reconstructed data.
bool HasRecShower() const
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
ShowerRecData & GetRecShower()
Interface class to access to the RD Reconstruction of a Shower.
utl::TimeStamp GetTime() const
Definition: REvent/Header.h:17
double GetParameterError(const Parameter i) const
const double meter
Definition: GalacticUnits.h:29
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
string ToString(const G &g, const CoordinateSystemPtr cs)
void Init()
Initialise the registry.
Base class for exceptions trying to access non-existing components.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
utl::CoordinateSystemPtr GetSiteCoordinateSystem() const
Get the coordinate system for the site.
Definition: Detector.h:137
double pow(const double x, const unsigned int i)
bool HasREvent() const
double GetAzimuthError() const
returns the error of the azimuth angle (from the wave fit)
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
T Get() const
Definition: Branch.h:271
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
#define INFOIntermediate(y)
Definition: VModule.h:162
Class representing a document branch.
Definition: Branch.h:107
boost::tuple< double, double, double > Triple
Coordinate triple for easy getting or setting of coordinates.
Definition: Triple.h:15
utl::Point GetCoordinateOrigin() const
void PropagateAxisErrors(const Vector::Triple &u_v_w, const Vector::Triple &sigma_u2_uv_v2, double &thetaError, double &phiError, double &thetaPhiCorrelation)
class to hold data at the radio Station level.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
constexpr double nanosecond
Definition: AugerUnits.h:143
bool HasRRecShower() const
Header & GetHeader()
access to REvent Header
Definition: REvent.h:239
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
constexpr double g
Definition: AugerUnits.h:200
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
#define INFODebug(y)
Definition: VModule.h:163
double GetParameter(const Parameter i) const
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
constexpr double kSpeedOfLight
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
void SetParameterError(Parameter i, double value, bool lock=true)
utl::CoordinateSystemPtr GetReferenceCoordinateSystem() const
Get the reference coordinate system used for analysis (usually PampaAmarilla for Auger) ...
Definition: Detector.h:141
void SetParameter(Parameter i, double value, bool lock=true)
Vector object.
Definition: Vector.h:30
const rdet::RDetector & GetRDetector() const
Definition: Detector.cc:143
constexpr double kSpeedOfLight2
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
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.
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
#define INFOFinal(y)
Definition: VModule.h:161
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
void SetParameterCovariance(Parameter i1, Parameter i2, double value, bool lock=true)
const char * what() const
std::exception will print this on crash

, generated on Tue Sep 26 2023.