Jpp  15.0.1-rc.1-highqe
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPlotCDG.cc File Reference

Program to verify generation of arrival times of Cherenkov photons from a shower using tabulated CDF. More...

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TProfile.h"
#include "TRandom3.h"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JTools/JAbstractHistogram.hh"
#include "JPhysics/JCDFTable.hh"
#include "JPhysics/JPDFTypes.hh"
#include "JGeometry3D/JAngle3D.hh"
#include "Jeep/JTimer.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program to verify generation of arrival times of Cherenkov photons from a shower using tabulated CDF.

Author
mdejong

Definition in file JPlotCDG.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 31 of file JPlotCDG.cc.

32 {
33  using namespace std;
34  using namespace JPP;
35 
36  typedef JAbstractHistogram<double> JHistogram_t;
37 
38  string inputFile;
39  string outputFile;
40  double E;
41  double D;
42  double cd;
43  JAngle3D dir;
44  int numberOfEvents;
45  JHistogram_t histogram;
46  int debug;
47 
48  try {
49 
50  JParser<> zap("Program to verify generation of arrival times of Cherenkov photons from a shower using tabulated CDF.");
51 
52  zap['f'] = make_field(inputFile);
53  zap['o'] = make_field(outputFile) = "";
54  zap['E'] = make_field(E, "muon energy [GeV]") = 1.0;
55  zap['R'] = make_field(D, "distance [m]");
56  zap['c'] = make_field(cd, "cosine emission angle");
57  zap['D'] = make_field(dir, "(theta, phi) of PMT [rad]");
58  zap['N'] = make_field(numberOfEvents) = 0;
59  zap['H'] = make_field(histogram, "histogram binning") = JHistogram_t();
60  zap['d'] = make_field(debug) = 0;
61 
62  zap(argc, argv);
63  }
64  catch(const exception& error) {
65  FATAL(error.what() << endl);
66  }
67 
68 
69  //typedef JSplineFunction1D_t JFunction1D_t;
70  typedef JPolint2Function1D_t JFunction1D_t;
71  typedef JMAPLIST<JPolint1FunctionalMap,
72  JPolint1FunctionalMap,
73  JPolint1FunctionalGridMap,
74  JPolint1FunctionalGridMap>::maplist JMapList_t;
75  typedef JCDFTable<JFunction1D_t, JMapList_t> JCDF_t;
76 
77  JCDF_t cdf;
78 
79 
80  try {
81 
82  NOTICE("loading input from file " << inputFile << "... " << flush);
83 
84  cdf.load(inputFile.c_str());
85 
86  NOTICE("OK" << endl);
87  }
88  catch(const JException& error) {
89  FATAL(error.what() << endl);
90  }
91 
92 
93  if (outputFile == "") {
94 
95  const double t0 = D * getIndexOfRefraction() / C; // time [ns]
96 
97  cout << "t0 " << t0 << endl;
98 
99  for ( ; ; ) {
100 
101  double x;
102 
103  cout << "> " << flush;
104  cin >> x;
105 
106  try {
107 
108  const double npe = cdf.getNPE (D, cd, dir.getTheta(), dir.getPhi()) * E;
109  const double t = cdf.getTime(D, cd, dir.getTheta(), dir.getPhi(), x);
110 
111  cout << " --> " << t << ' ' << t0 + t << ' ' << npe;
112  }
113  catch(const exception& error) {
114  ERROR(error.what() << endl);
115  }
116 
117  cout << endl;
118  }
119 
120  } else {
121 
122  TFile out(outputFile.c_str(), "recreate");
123 
124  int function = 1;
125 
126  if (inputFile.find(getLabel(DIRECT_LIGHT_FROM_EMSHOWER)) == string::npos) {
127  function = 0;
128  }
129 
130  const double t0 = D * getIndexOfRefraction() / C; // time [ns]
131  //const double t0 = 0.0; // time [ns]
132 
133  if (!histogram.is_valid()) {
134 
135  if (function == 0) {
136 
137  histogram = JHistogram_t(t0 - 20.0, t0 + 50.0);
138 
139  histogram.setBinWidth(0.1);
140 
141  } else {
142 
143  histogram = JHistogram_t(t0 - 20.0, t0 + 500.0);
144 
145  histogram.setBinWidth(0.5);
146  }
147  }
148 
149  TH1D h0("h0", NULL, histogram.getNumberOfBins(), histogram.getLowerLimit(), histogram.getUpperLimit());
150  TH1D h1("h1", NULL, 5000, 0.0, +1.0);
151 
152  for (int j = 1; j <= h1.GetNbinsX(); ++j) {
153 
154  try {
155 
156  const double x = h1.GetBinCenter(j);
157  const double t = cdf.getTime(D, cd, dir.getTheta(), dir.getPhi(), x);
158 
159  h1.SetBinContent(j, t);
160  }
161  catch(const exception& error) {
162  ERROR(error.what() << endl);
163  }
164  }
165 
166  if (numberOfEvents > 0) {
167 
168 
169  JTimer timer;
170 
171  timer.reset();
172 
173  for (int i = 0; i != numberOfEvents; ++i) {
174 
175  if (i%1000== 0) { NOTICE(i << '\r'); }
176 
177  timer.start();
178 
179  try {
180 
181  const double npe = cdf.getNPE(D, cd, dir.getTheta(), dir.getPhi()) * E;
182 
183  for (int j = gRandom->Poisson(npe); j != 0; --j) {
184 
185  const double x = gRandom->Rndm();
186  const double t = cdf.getTime(D, cd, dir.getTheta(), dir.getPhi(), x);
187 
188  h0.Fill(t + t0);
189  }
190  }
191  catch(const exception& error) {
192  ERROR(error.what() << endl);
193  }
194 
195  timer.stop();
196  }
197  NOTICE(endl);
198 
199  const double w = 1.0 / (double) numberOfEvents;
200 
201  if (debug > JEEP::notice_t) {
202  timer.print(cout, w);
203  }
204 
205  // normalise histogram (dP/dt)
206 
207  for (int j = 1; j <= h0.GetNbinsX(); ++j) {
208 
209  const double y = h0.GetBinContent(j);
210  const double dx = h0.GetBinWidth (j);
211 
212  h0.SetBinContent(j, y / (dx*numberOfEvents*E));
213  }
214  }
215 
216  out.Write();
217  out.Close();
218  }
219 }
Utility class to parse command line options.
Definition: JParser.hh:1500
data_type w[N+1][M+1]
Definition: JPolint.hh:741
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition: JLocation.hh:246
notice
Definition: JMessage.hh:32
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
string outputFile
then usage E
Definition: JMuonPostfit.sh:35
static const double C
Physics constants.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
direct light from EM shower
Definition: JPDFTypes.hh:40
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
then for FUNCTION in pdf npe cdf
Definition: JPlotNPE-PDG.sh:73
int j
Definition: JPolint.hh:666
do echo Generating $dir eval D
Definition: JDrawLED.sh:53