testProbability.cc
Go to the documentation of this file.
1 
9 #include <iostream>
10 
11 #include <tst/Verify.h>
12 
13 #include <utl/CoordinateSystem.h>
14 #include <utl/AugerCoordinateSystem.h>
15 #include <utl/Probability.h>
16 #include <utl/CoordinateSystem.h>
17 #include <utl/CoordinateSystemPtr.h>
18 #include <utl/Vector.h>
19 #include <utl/AugerUnits.h>
20 
21 #include <fwk/CentralConfig.h>
22 #include <fwk/CoordinateSystemRegistry.h>
23 
24 #include <cppunit/extensions/HelperMacros.h>
25 
26 #include <TH1D.h>
27 #include <TGraph.h>
28 #include <TF1.h>
29 #include <TCanvas.h>
30 #include <TStyle.h>
31 // #include <Python/geometry.i>
32 
33 using namespace std;
34 using namespace utl;
35 using namespace tst;
36 
37 
42 class TestProbability : public CppUnit::TestFixture {
43 
44  CPPUNIT_TEST_SUITE(TestProbability);
45  CPPUNIT_TEST(TestFisher);
46  CPPUNIT_TEST(TestVonMises);
47  //CPPUNIT_TEST(PlotFisher1);
48  //CPPUNIT_TEST(PlotFisher2);
49 
50  CPPUNIT_TEST_SUITE_END();
51 
52 private:
54 
55 public:
56  void
58  {
60  }
61 
62  void tearDown() { }
63 
64  void
66  {
67  const double kappa = 708.99;
68  for (int j = 0; j < 100; ++j) {
69  const double x = (0.5*j - 25) * utl::deg;
70  const double prob = Probability::GetInstance().GetVonMisesPDF(x, 0, kappa);
71  const double probGaus = Probability::GetInstance().GetNormalPDF(x, 0, sqrt(1./kappa));
72  CPPUNIT_ASSERT(Verify<CloseTo>(prob, probGaus, 2e-3));
73  }
74  }
75 
76  void
78  {
79  const int nTheta = 100;
80  const int nPhi = 100;
81  const int nAlpha = 100;
82  for (int iTheta = 0; iTheta < nTheta; ++iTheta) {
83  const double theta = 0.5 * iTheta / nTheta * M_PI;
84  for (int iPhi = 0; iPhi < nPhi; ++iPhi) {
85  const double phi = 2. * iPhi / nPhi * M_PI;
86  const Vector showeraxis(1, theta, phi, fCS, Vector::kSpherical);
87  for (int iAlpha = 0; iAlpha < nAlpha; ++iAlpha) {
88  double alpha = 5. * iAlpha/nAlpha * utl::deg;
89  const Vector smearedVector = Probability::GetInstance().GetFisher(showeraxis, alpha);
90  const double angle = Angle(showeraxis, smearedVector);
91  CPPUNIT_ASSERT(Verify<CloseTo>(alpha, angle, 1e-8));
92  }
93  }
94  }
95  }
96 
97  void
99  {
100  const int n = 10000000;
101  TH1D h = TH1D("h", "", 90, 0, 0.5);
102  TGraph g;
103  for (int i = 0; i < n; ++i) {
104  h.Fill(Probability::GetInstance().GetRandomFisher(250));
105  const double x = 1. * i/n * M_PI;
106  g.SetPoint(i, x, Probability::GetFisherPDF(x, 250));
107  }
108  h.Scale(1/h.Integral("width"));
109  // check compatibility
110  for (int i = 1; i <= 90; ++i) {
111  const double x = h.GetBinCenter(i);
112  CPPUNIT_ASSERT(Verify<CloseTo>(h.GetBinContent(i), Probability::GetFisherPDF(x, 250), 1e-2));
113  }
114 
115  gStyle->SetOptStat("merou");
116  TCanvas* const c = new TCanvas();
117  c->cd();
118  h.GetXaxis()->SetTitle("angle [deg]");
119  h.Draw("");
120  g.Draw("Psame");
121  c->SaveAs("hFisher.png");
122  delete c;
123  }
124 
125  void
127  {
128  const int n = 10000000;
129  TH1D h = TH1D("h", "", 90, 0, 0.5);
130  TGraph g;
131  const double sigma = 1 * utl::deg;
132  for (int i = 0; i < n; ++i) {
133  h.Fill(Probability::GetInstance().GetRandomFisher(1/(sigma*sigma)));
134  const double x = 1. * i/n * M_PI;
135  g.SetPoint(i, x, Probability::GetRayleighPDF(x, sigma));
136  }
137  h.Scale(1/h.Integral("width"));
138 
139  gStyle->SetOptStat("merou");
140  TCanvas* const c = new TCanvas();
141  c->cd();
142  h.GetXaxis()->SetTitle("angle [deg]");
143  h.Draw("");
144  g.Draw("Psame");
145  c->SaveAs("hFisher_Rayleigh.png");
146  delete c;
147  }
148 
149 };
150 
151 
153 
154 
155 // Configure (x)emacs for this file ...
156 // Local Variables:
157 // mode: c++
158 // End:
double Angle(const double theta1, const double phi1, const double theta2, const double phi2)
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
constexpr double deg
Definition: AugerUnits.h:140
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
constexpr double g
Definition: AugerUnits.h:200
CoordinateSystemPtr fCS
static CoordinateSystemPtr GetRootCoordinateSystem()
Vector object.
Definition: Vector.h:30

, generated on Tue Sep 26 2023.