RdPreWaveFitter/Chi2ForPlaneWaveFit.cc
Go to the documentation of this file.
1 #include "Chi2ForPlaneWaveFit.h"
2 
3 #include <utl/PhysicalConstants.h>
4 
5 using namespace std;
6 using namespace utl;
7 
8 
9 namespace RdPreWaveFitter {
10 
11  // Set Antenna Times and Positions
12  void
13  Chi2ForPlaneWaveFit::Set(const std::vector< utl::Vector >& _AntennaPositions, const std::vector< double >& _AntennaTimes,
14  const std::vector< double >& _AntennaTimesError, const utl::CoordinateSystemPtr& _fgLocalCS)
15  {
16  AntennaPositions = _AntennaPositions;
17  AntennaTimes = _AntennaTimes;
18  AntennaTimesError = _AntennaTimesError;
19  fgLocalCS = _fgLocalCS;
20 
21  /* an absolute event time for both the test and measured times. The absolute event time
22  is choosen to be the mean of all measured/test times */
23  const double tau0 = TMath::Mean(AntennaTimes.begin(), AntennaTimes.end());
24  for (auto& time : AntennaTimes)
25  {
26  time -= tau0;
27  }
28  }
29 
30 
31  // Objective function
32  double
33  Chi2ForPlaneWaveFit::DoEval(const double* x) const
34  {
35  // Unit vector pointing to where the wave is coming from!
36  utl::Vector ShowerAxis(1.*utl::m, x[0], x[1], fgLocalCS, utl::Vector::kSpherical);
37 
38  // Calculate the expected times
39  std::vector<double> ExpectedTimes; // Expected time for each antenna if the test position is the source position
40  double exp_time;
41  for (auto pos: AntennaPositions)
42  {
43  exp_time = (-ShowerAxis * pos) / kSpeedOfLight; // calculate (negative) projection
44  ExpectedTimes.push_back(exp_time);
45 
46  }
47  const double t0 = TMath::Mean(ExpectedTimes.begin(), ExpectedTimes.end());
48 
49  // Calculate chi square
50  double chi = 0.;
51  const int n = AntennaTimes.size();
52  for (int i = 0; i < n; i++)
53  {
54  chi += pow(AntennaTimes[i] - (ExpectedTimes[i]-t0), 2) / pow(AntennaTimesError[i], 2);
55  }
56 
57  // Return Chi Square for input x
58  return chi;
59  }
60 }
double pow(const double x, const unsigned int i)
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
void Set(const std::vector< utl::Vector > &_AntennaPositions, const std::vector< double > &_AntennaTimes, const std::vector< double > &_AntennaTimesError, const utl::CoordinateSystemPtr &_fgLocalCS)
static const CSpherical kSpherical
Definition: BasicVector.h:335
constexpr double kSpeedOfLight
double DoEval(const double *x) const
Vector object.
Definition: Vector.h:30
double Mean(const std::vector< double > &v)
Definition: Functions.h:31
constexpr double m
Definition: AugerUnits.h:121

, generated on Tue Sep 26 2023.