Jpp  19.0.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/JManager.hh"
#include "JROOT/JRootToolkit.hh"
#include "JGizmo/JGizmoToolkit.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 35 of file JPlotCDG.cc.

36 {
37  using namespace std;
38  using namespace JPP;
39 
40  typedef JAbstractHistogram<double> JHistogram_t;
41 
42  vector<string> inputFile;
43  string outputFile;
44  double E;
45  double D;
46  double cd;
47  JAngle3D dir;
48  int numberOfEvents;
50  int debug;
51 
52  try {
53 
54  JParser<> zap("Program to verify generation of arrival times of Cherenkov photons from a shower using tabulated CDF.");
55 
56  zap['f'] = make_field(inputFile);
57  zap['o'] = make_field(outputFile) = "";
58  zap['E'] = make_field(E, "muon energy [GeV]") = 1.0;
59  zap['R'] = make_field(D, "distance [m]");
60  zap['c'] = make_field(cd, "cosine emission angle");
61  zap['D'] = make_field(dir, "(theta, phi) of PMT [rad]");
62  zap['n'] = make_field(numberOfEvents) = 0;
63  zap['H'] = make_field(histogram, "histogram binning") = JHistogram_t();
64  zap['d'] = make_field(debug) = 2;
65 
66  zap(argc, argv);
67  }
68  catch(const exception& error) {
69  FATAL(error.what() << endl);
70  }
71 
72 
73  typedef JHermiteSplineFunction1D_t JFunction1D_t;
74  //typedef JSplineFunction1D_t JFunction1D_t;
75  //typedef JPolint1Function1D_t JFunction1D_t;
76  typedef JMAPLIST<JPolint1FunctionalMap,
77  JPolint1FunctionalMap,
78  JPolint1FunctionalGridMap,
79  JPolint1FunctionalGridMap>::maplist JMapList_t;
80  typedef JCDFTable<JFunction1D_t, JMapList_t> JCDF_t;
81 
82  const int N = inputFile.size();
83 
84  JCDF_t cdf [N];
85 
86  try {
87 
88  for (int i = 0; i != N; ++i) {
89 
90  NOTICE("loading input from file " << inputFile[i] << "... " << flush);
91 
92  cdf [i].load(inputFile[i].c_str());
93 
94  NOTICE("OK" << endl);
95  }
96  }
97  catch(const JException& error) {
98  FATAL(error.what() << endl);
99  }
100 
101 
102  if (outputFile == "") {
103 
104  for ( ; ; ) {
105 
106  double x;
107 
108  cout << "> " << flush;
109  cin >> x;
110 
111  cout << " --> ";
112 
113  for (int i = 0; i != N; ++i) {
114 
115  try {
116 
117  const double npe = cdf[i].getNPE (D, cd, dir.getTheta(), dir.getPhi()) * E;
118  const double t = cdf[i].getTime(D, cd, dir.getTheta(), dir.getPhi(), x);
119 
120  cout << ' ' << FIXED(6,2) << t << ' ' << FIXED(5,2) << npe;
121  }
122  catch(const exception& error) {
123  ERROR(error.what() << endl);
124  }
125  }
126 
127  cout << endl;
128  }
129 
130  return 0;
131  }
132 
133 
134  int function = 0;
135 
136  if (inputFile.size() == 1 && getPDFType(inputFile[0]) == DIRECT_LIGHT_FROM_EMSHOWER) {
137  function = 1;
138  }
139 
140  TH1D* h0 = NULL;
141 
142  //const double t0 = D * getIndexOfRefraction() / C; // time [ns]
143  const double t0 = 0.0; // time [ns]
144 
145  if (!histogram.is_valid()) {
146 
148 
149  double x = -100.0;
150 
151  {
152  for ( ; x < -10.0; x += 5.0) { X.push_back(t0 + x); }
153  for ( ; x < +20.0; x += 1.0) { X.push_back(t0 + x); }
154  for ( ; x < +50.0; x += 2.0) { X.push_back(t0 + x); }
155  }
156  if (function != 1) {
157  for ( ; x < +100.0; x += 5.0) { X.push_back(t0 + x); }
158  for ( ; x < +250.0; x += 10.0) { X.push_back(t0 + x); }
159  for ( ; x < +500.0; x += 25.0) { X.push_back(t0 + x); }
160  for ( ; x < +900.0; x += 50.0) { X.push_back(t0 + x); }
161  }
162 
163  h0 = new TH1D("h0", NULL, X.size() - 1, X.data());
164 
165  } else {
166 
167  h0 = new TH1D("h0", NULL, histogram.getNumberOfBins(), histogram.getLowerLimit(), histogram.getUpperLimit());
168  }
169 
170  h0->Sumw2();
171 
172  JManager<int, TH1D> H1(new TH1D("h1[%]", NULL, 100000, 0.0, +1.0));
173 
174  for (int i = 0; i != N; ++i) {
175 
176  for (int j = 1; j <= H1->GetNbinsX(); ++j) {
177 
178  try {
179 
180  const double x = H1->GetBinCenter(j);
181  const double t = cdf[i].getTime(D, cd, dir.getTheta(), dir.getPhi(), x);
182 
183  H1[i]->SetBinContent(j, t);
184  }
185  catch(const exception& error) {
186  ERROR(error.what() << endl);
187  }
188  }
189  }
190 
191  if (numberOfEvents > 0) {
192 
193  JTimer timer;
194 
195  timer.reset();
196 
197  for (int counter = 0; counter != numberOfEvents; ++counter) {
198 
199  if (counter%1000== 0) {
200  STATUS(setw(10) << counter << '\r'); DEBUG(endl);
201  }
202 
203  timer.start();
204 
205  for (int i = 0; i != N; ++i) {
206 
207  try {
208 
209  const double npe = cdf[i].getNPE(D, cd, dir.getTheta(), dir.getPhi()) * E;
210 
211  for (int j = gRandom->Poisson(npe); j != 0; --j) {
212 
213  const double x = gRandom->Rndm();
214  const double t = cdf[i].getTime(D, cd, dir.getTheta(), dir.getPhi(), x);
215 
216  h0->Fill(t + t0);
217  }
218  }
219  catch(const exception& error) {
220  NOTICE(error.what() << endl);
221  }
222  }
223 
224  timer.stop();
225  }
226  STATUS(endl);
227 
228  const double W = 1.0 / (double) numberOfEvents;
229 
230  if (debug > JEEP::status_t) {
231  timer.print(cout, W);
232  }
233 
234  convertToPDF(*h0, "WE", W);
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:1711
then usage $script< input file >[option[primary[working directory]]] nWhere option can be E
Definition: JMuonPostfit.sh:40
#define STATUS(A)
Definition: JMessage.hh:63
then warning Cannot perform comparison test for histogram
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:2158
void convertToPDF(TH1 &h1, const std::string &option="NW", const double factor=1.0)
Convert 1D histogram to PDF.
#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
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
no fit printf nominal n $STRING awk v X
int j
Definition: JPolint.hh:792
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
int debug
debug level
JAbstractHistogram< double > JHistogram_t
Type definition for scan along axis.
Definition: JBillabong.cc:61
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62