Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JOmega2D.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <cmath>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TH1D.h"
10 #include "TRandom3.h"
11 
12 #include "JTools/JConstants.hh"
13 #include "JTools/JQuantile.hh"
14 #include "JROOT/JRootToolkit.hh"
15 
16 #include "JGeometry2D/JOmega2D.hh"
17 
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 
22 /**
23  * \file
24  *
25  * Example program to test JGEOMETRY2D::JOmega2D class.
26  * \author mdejong
27  */
28 int main(int argc, char**argv)
29 {
30  using namespace std;
31  using namespace JPP;
32 
33  string outputFile;
34  int numberOfEvents;
35  JAngleRange range_Deg;
36  int debug;
37 
38  try {
39 
40  JParser<> zap("Example program to test JOmega2D class.");
41 
42  zap['o'] = make_field(outputFile) = "";
43  zap['n'] = make_field(numberOfEvents) = 1000;
44  zap['G'] = make_field(range_Deg) = JAngleRange(0.5, 10.5);
45  zap['d'] = make_field(debug) = 3;
46 
47  zap(argc, argv);
48  }
49  catch(const exception &error) {
50  FATAL(error.what() << endl);
51  }
52 
53 
54  const int N = 10;
55 
56  TH1D h0("h0[grid", NULL, N, range_Deg.getLowerLimit(), range_Deg.getUpperLimit());
57  TH1D h1("h1[RMS]", NULL, N, range_Deg.getLowerLimit(), range_Deg.getUpperLimit());
58  TH1D h2("h2[deviation]", NULL, N, range_Deg.getLowerLimit(), range_Deg.getUpperLimit());
59 
60 
61  vector<JOmega2D> omega;
62  vector<JQuantile> quantile;
63 
64  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
65 
66  const Double_t x = h0.GetBinCenter(i);
67 
68  omega .push_back(JOmega2D(x * PI/180.0));
69  quantile.push_back(JQuantile());
70  }
71 
72 
73  for (int i = 0; i != numberOfEvents; ++i) {
74 
75  STATUS("event: " << setw(10) << i << '\r'); DEBUG(endl);
76 
77  const double phi = gRandom->Uniform(0.0, 2*PI);
78 
79  const JAngle2D angle(phi);
80 
81  for (size_t j = 0; j != omega.size(); ++j) {
82 
83  const int pos = omega[j].find(angle);
84  const double dot = angle.getDot(omega[j][pos]);
85 
86  quantile[j].put(acos(dot) * 180.0/PI);
87  }
88  }
89  STATUS(endl);
90 
91 
92  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
93  h0.SetBinContent(i, omega [i-1].size());
94  h1.SetBinContent(i, quantile[i-1].getSTDev());
95  h2.SetBinContent(i, quantile[i-1].getDeviation());
96  }
97 
98  if (outputFile != "") {
99 
100  TFile out(outputFile.c_str(), "recreate");
101 
102  out << h0 << h1 << h2;
103 
104  out.Write();
105  out.Close();
106  }
107 
108  for (int i = 1; i <= h2.GetNbinsX(); ++i) {
109 
110  const Double_t x = h2.GetBinCenter (i);
111  const Double_t y = h2.GetBinContent(i);
112 
113  NOTICE("Grid test " << x << " [deg]: " << y << " [deg]." << endl);
114  ASSERT(y < x / 2.0);
115  }
116 
117  return 0;
118 }
Utility class to parse command line options.
Definition: JParser.hh:1410
JRange< double > JAngleRange
Type definition for angle range.
Definition: JAngleRange.hh:19
#define STATUS(A)
Definition: JMessage.hh:61
static const double PI
Constants.
Definition: JConstants.hh:20
string outputFile
Constants.
#define ASSERT(A)
Assert macro.
Definition: JMessage.hh:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
#define NOTICE(A)
Definition: JMessage.hh:62
int debug
debug level
Definition: JSirene.cc:59
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:65
Utility class to parse command line options.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
int main(int argc, char *argv[])
Definition: Main.cpp:15