Chi2ForSphericalWaveFitVarC.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 using namespace utl;
5 
6 
8 {
9  Spherical = true;
10  sigma_gamma = 1./60.;
11  doPenalty = true;
12  computeSigmaGamma = true;
13 }
15 
16 void Chi2ForSphericalWaveFitVarC::SetPenalty(bool dP){doPenalty = dP;}
17 
19  sigma_gamma = _sigma_gamma;
20  computeSigmaGamma = false;
21 }
22 
23 // Set Antenna Times and Positions
24 void Chi2ForSphericalWaveFitVarC::Set(const std::vector< Vector >& _AntennaPositions, const std::vector< double >& _AntennaTimes, const std::vector< double >& _AntennaTimesError, const utl::CoordinateSystemPtr& _fgLocalCS)
25 {
26  AntennaPositions = _AntennaPositions;
27  AntennaTimes = _AntennaTimes;
28  AntennaTimesError = _AntennaTimesError;
29  fgLocalCS = _fgLocalCS;
30 
31  double tau0;
32  tau0 = TMath::Mean(AntennaTimes.begin(),AntennaTimes.end());
33 
34  /* an absolute event time for both the test and measured times. The absolute event time is choosen to be the mean of all measured/test times
35  */
36  int n = AntennaTimes.size();
37  for (int i=0;i<n;i++)
38  {
39  AntennaTimes[i] -= tau0;
40  }
41 
42  if(computeSigmaGamma) {
43  sigma_gamma = kSpeedOfLight/125.*utl::m*TMath::Sqrt(2)*AntennaTimesError[0]; // (c/125m)*sqrt(2)*sigma
44  }
45 }
46 
47 
48 
49 // Objective function
50 double Chi2ForSphericalWaveFitVarC::DoEval(const double* x) const
51 {
52  double chi = 0.; // Chi Square / NDF
53  double c = kSpeedOfLight; // in AugerUnits
54  std::vector<double> ExpectedTimes; // Expected time for each antenna if the test position is the source position
55 
56  double gamma = 0;
57 
58  // Input values
59  utl::Vector TestPosition(x[0],x[1],x[2],fgLocalCS,utl::Vector::kSpherical); // Test Position
60 
61  gamma = x[3];
62  if (gamma==0.){gamma=1.e-12;} // avoid division by zero
63 
64  // Calculate the expected times
65  int n = AntennaPositions.size();
66  double exp_time;
67  for (int i=0;i<n;i++)
68  {
69  exp_time = ((AntennaPositions[i]-TestPosition).GetMag())/(c*gamma);
70  ExpectedTimes.push_back(exp_time);
71  }
72 
73  // get the minimum of ExpectedTimes
74  double t0;
75  t0 = TMath::Mean(ExpectedTimes.begin(),ExpectedTimes.end());
76 
77  // Calculate chi square
78  for (int i=0;i<n;i++)
79  {
80  chi += pow(AntennaTimes[i]-(ExpectedTimes[i]-t0),2)/pow(AntennaTimesError[i],2);
81  }
82  if(doPenalty){
83  chi += pow(1.-gamma,2)/pow(sigma_gamma,2); // penalty term
84  }
85 
86  // Return Chi Square for input Test Position
87  return chi;
88 }
89 
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
void SetSigmaGamma(double _sigma_gamma)
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.