Chi2ForConicalWaveFit.cc
Go to the documentation of this file.
1 /*
2  * Chi2ForConicalWaveFit.cc
3  *
4  * Created on: Oct 30, 2012
5  * Author: leurs
6  * modified by Qader Dorosti
7  * on: Jun 14, 2013
8  */
10 #include <cmath>
11 
12 using namespace std;
13 using namespace utl;
14 
15 
17 {
18  Cylindrical = true;
19 }
20 
21 
23 { }
24 
25 
26 // Use cartesic coordinate system
27 void
29 {
30  Cylindrical = false;
31 }
32 
33 
34 // Use cylindrical coordinate system (default)
35 void
37 {
38  Cylindrical = true;
39 }
40 
41 
42 // Set Antenna Times and Positions
43 void
44 Chi2ForConicalWaveFit::Set(const std::vector<utl::Vector>& _AntennaPositions,
45  const std::vector<double>& _AntennaTimes,
46  const std::vector<double>& _AntennaTimesError,
47  const utl::CoordinateSystemPtr& _fgLocalCS)
48 {
49  AntennaPositions = _AntennaPositions;
50  AntennaTimes = _AntennaTimes;
51  AntennaTimesError = _AntennaTimesError;
52  fgLocalCS = _fgLocalCS;
53 
54  /* an absolute event time for both the test and measured times. The absolute event time is chosen to be the mean of all measured/test times
55  */
56  double tau0 = 0;
57  tau0 = TMath::Mean(AntennaTimes.begin(), AntennaTimes.end());
58  int n = AntennaTimes.size();
59  for (int i = 0; i < n; ++i) {
60  AntennaTimes[i] -= tau0;
61  }
62 }
63 
64 
65 // Objective function
66 double
67 Chi2ForConicalWaveFit::DoEval(const double* const x)
68  const
69 {
70  double chi = 0; // Chi^2/ndf
71  double c = kSpeedOfLight; // in AugerUnits
72  std::vector<double> ExpectedTimes; // Expected time for each antenna if the test position is the source position
73 
74  utl::Vector ShowerAxis(1.*utl::m, x[1], x[2], fgLocalCS, utl::Vector::kSpherical); // Unit vector pointing to where the wave is coming from!
75  //ShowerAxis.SetMagThetaPhi(1., x[0], x[1]);
76 
77  // calculate the expected times
78  int n = AntennaPositions.size();
79  double exp_time;
80 
81  for (int i = 0; i < n; ++i) {
82 
83  double L = fabs((fabs(ShowerAxis*AntennaPositions[i])*ShowerAxis-AntennaPositions[i]).GetMag());
84  exp_time = (-ShowerAxis*AntennaPositions[i] + tan(x[0]) * L) / c;
85 
86  ExpectedTimes.push_back(exp_time);
87 
88  }
89 
90  double t0 = 0;
91  t0 = TMath::Mean(ExpectedTimes.begin(),ExpectedTimes.end());
92 
93  //calculate Chi Squared
94  for (int i = 0; i < n; ++i) {
95  chi += pow(AntennaTimes[i] - (ExpectedTimes[i] - t0), 2) / pow(AntennaTimesError[i], 2);
96  }
97 
98  //cout << "chi = " << chi << endl;
99 
100  // return chi squared
101  return chi;
102 }
void Set(const std::vector< utl::Vector > &_AntennaPositions, const std::vector< double > &_AntennaTimes, const std::vector< double > &AntennaTimesErrors, const utl::CoordinateSystemPtr &_fgLocalCS)
double pow(const double x, const unsigned int i)
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
static const CSpherical kSpherical
Definition: BasicVector.h:335
double DoEval(const double *x) const
constexpr double kSpeedOfLight
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.