Jpp  17.2.0
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 "JPhysics/JPDFToolkit.hh"
#include "JGeometry3D/JAngle3D.hh"
#include "JROOT/JRootToolkit.hh"
#include "JROOT/JManager.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 34 of file JPlotCDG.cc.

35 {
36  using namespace std;
37  using namespace JPP;
38 
39  typedef JAbstractHistogram<double> JHistogram_t;
40 
41  vector<string> inputFile;
42  string outputFile;
43  double E;
44  double D;
45  double cd;
46  JAngle3D dir;
47  int numberOfEvents;
48  JHistogram_t histogram;
49  int debug;
50 
51  try {
52 
53  JParser<> zap("Program to verify generation of arrival times of Cherenkov photons from a shower using tabulated CDF.");
54 
55  zap['f'] = make_field(inputFile);
56  zap['o'] = make_field(outputFile) = "";
57  zap['E'] = make_field(E, "muon energy [GeV]") = 1.0;
58  zap['R'] = make_field(D, "distance [m]");
59  zap['c'] = make_field(cd, "cosine emission angle");
60  zap['D'] = make_field(dir, "(theta, phi) of PMT [rad]");
61  zap['n'] = make_field(numberOfEvents) = 0;
62  zap['H'] = make_field(histogram, "histogram binning") = JHistogram_t();
63  zap['d'] = make_field(debug) = 2;
64 
65  zap(argc, argv);
66  }
67  catch(const exception& error) {
68  FATAL(error.what() << endl);
69  }
70 
71 
72  typedef JHermiteSplineFunction1D_t JFunction1D_t;
73  //typedef JSplineFunction1D_t JFunction1D_t;
74  //typedef JPolint1Function1D_t JFunction1D_t;
75  typedef JMAPLIST<JPolint1FunctionalMap,
76  JPolint1FunctionalMap,
77  JPolint1FunctionalGridMap,
78  JPolint1FunctionalGridMap>::maplist JMapList_t;
79  typedef JCDFTable<JFunction1D_t, JMapList_t> JCDF_t;
80 
81  const int N = inputFile.size();
82 
83  JCDF_t cdf [N];
84 
85  try {
86 
87  for (int i = 0; i != N; ++i) {
88 
89  NOTICE("loading input from file " << inputFile[i] << "... " << flush);
90 
91  cdf [i].load(inputFile[i].c_str());
92 
93  NOTICE("OK" << endl);
94  }
95  }
96  catch(const JException& error) {
97  FATAL(error.what() << endl);
98  }
99 
100 
101  if (outputFile == "") {
102 
103  for ( ; ; ) {
104 
105  double x;
106 
107  cout << "> " << flush;
108  cin >> x;
109 
110  cout << " --> ";
111 
112  for (int i = 0; i != N; ++i) {
113 
114  try {
115 
116  const double npe = cdf[i].getNPE (D, cd, dir.getTheta(), dir.getPhi()) * E;
117  const double t = cdf[i].getTime(D, cd, dir.getTheta(), dir.getPhi(), x);
118 
119  cout << ' ' << FIXED(6,2) << t << ' ' << FIXED(5,2) << npe;
120  }
121  catch(const exception& error) {
122  ERROR(error.what() << endl);
123  }
124  }
125 
126  cout << endl;
127  }
128 
129  return 0;
130  }
131 
132 
133  int function = 0;
134 
135  if (inputFile.size() == 1 && getPDFType(inputFile[0]) == DIRECT_LIGHT_FROM_EMSHOWER) {
136  function = 1;
137  }
138 
139  //const double t0 = D * getIndexOfRefraction() / C; // time [ns]
140  const double t0 = 0.0; // time [ns]
141 
142  if (!histogram.is_valid()) {
143 
144  if (function == 1) {
145 
146  histogram = JHistogram_t(t0 - 20.0, t0 + 50.0);
147 
148  histogram.setBinWidth(0.5);
149 
150  } else {
151 
152  histogram = JHistogram_t(t0 - 20.0, t0 + 500.0);
153 
154  histogram.setBinWidth(2.0);
155  }
156  }
157 
158  TH1D h0("h0", NULL, histogram.getNumberOfBins(), histogram.getLowerLimit(), histogram.getUpperLimit());
159 
160  h0.Sumw2();
161 
162  JManager<int, TH1D> H1(new TH1D("h1[%]", NULL, 100000, 0.0, +1.0));
163 
164  for (int i = 0; i != N; ++i) {
165 
166  for (int j = 1; j <= H1->GetNbinsX(); ++j) {
167 
168  try {
169 
170  const double x = H1->GetBinCenter(j);
171  const double t = cdf[i].getTime(D, cd, dir.getTheta(), dir.getPhi(), x);
172 
173  H1[i]->SetBinContent(j, t);
174  }
175  catch(const exception& error) {
176  ERROR(error.what() << endl);
177  }
178  }
179  }
180 
181  if (numberOfEvents > 0) {
182 
183  JTimer timer;
184 
185  timer.reset();
186 
187  for (int counter = 0; counter != numberOfEvents; ++counter) {
188 
189  if (counter%1000== 0) {
190  STATUS(setw(10) << counter << '\r'); DEBUG(endl);
191  }
192 
193  timer.start();
194 
195  for (int i = 0; i != N; ++i) {
196 
197  try {
198 
199  const double npe = cdf[i].getNPE(D, cd, dir.getTheta(), dir.getPhi()) * E;
200 
201  for (int j = gRandom->Poisson(npe); j != 0; --j) {
202 
203  const double x = gRandom->Rndm();
204  const double t = cdf[i].getTime(D, cd, dir.getTheta(), dir.getPhi(), x);
205 
206  h0.Fill(t + t0);
207  }
208  }
209  catch(const exception& error) {
210  NOTICE(error.what() << endl);
211  }
212  }
213 
214  timer.stop();
215  }
216  STATUS(endl);
217 
218  const double w = 1.0 / (double) numberOfEvents;
219 
220  if (debug > JEEP::status_t) {
221  timer.print(cout, w);
222  }
223 
224  // normalise histogram (dP/dt)
225 
226  for (int j = 1; j <= h0.GetNbinsX(); ++j) {
227 
228  const double y = h0.GetBinContent(j);
229  const double z = h0.GetBinError (j);
230  const double dx = h0.GetBinWidth (j);
231 
232  h0.SetBinContent(j, y / (dx*numberOfEvents));
233  h0.SetBinError (j, z / (dx*numberOfEvents));
234  }
235  }
236 
237  TFile out(outputFile.c_str(), "recreate");
238 
239  out << h0 << H1;
240 
241  out.Write();
242  out.Close();
243 }
Utility class to parse command line options.
Definition: JParser.hh:1517
data_type w[N+1][M+1]
Definition: JPolint.hh:778
then usage E
Definition: JMuonPostfit.sh:35
#define STATUS(A)
Definition: JMessage.hh:63
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
status
Definition: JMessage.hh:30
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
direct light from EM shower
Definition: JPDFTypes.hh:37
#define FATAL(A)
Definition: JMessage.hh:67
then for FUNCTION in pdf npe cdf
Definition: JPlotNPE-PDG.sh:73
int getPDFType(const std::string &file_name)
Get PDF type.
Definition: JPDFTypes.hh:77
int j
Definition: JPolint.hh:703
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62