Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 35 of file JPlotCDG.cc.

36 {
37  using namespace std;
38  using namespace JPP;
39 
41 
42  vector<string> inputFile;
43  string outputFile;
44  double E;
45  double D;
46  double cd;
47  JAngle3D dir;
48  int numberOfEvents;
49  JHistogram_t histogram;
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;
79  JPolint1FunctionalGridMap>::maplist JMapList_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 }
string outputFile
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define ERROR(A)
Definition: JMessage.hh:66
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Auxiliary class for CPU timing and usage.
Definition: JTimer.hh:33
void print(std::ostream &out, const JScale_t scale=milli_t) const
Print timer data.
Definition: JTimer.hh:172
void stop()
Stop timer.
Definition: JTimer.hh:127
void reset()
Reset timer.
Definition: JTimer.hh:93
void start()
Start timer.
Definition: JTimer.hh:106
Data structure for angles in three dimensions.
Definition: JAngle3D.hh:35
double getTheta() const
Get theta angle.
Definition: JAngle3D.hh:86
double getPhi() const
Get phi angle.
Definition: JAngle3D.hh:97
General exception.
Definition: JException.hh:24
virtual const char * what() const override
Get error message.
Definition: JException.hh:64
Utility class to parse command line options.
Definition: JParser.hh:1698
Multi-dimensional CDF table for arrival time of Cherenkov light.
Definition: JCDFTable.hh:57
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition: JManager.hh:47
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
JAbstractHistogram< double > JHistogram_t
Type definition for scan along axis.
Definition: JBillabong.cc:61
@ status_t
status
Definition: JMessage.hh:30
void convertToPDF(TH1 &h1, const std::string &option="NW", const double factor=1.0)
Convert 1D histogram to PDF.
@ DIRECT_LIGHT_FROM_EMSHOWER
direct light from EM shower
Definition: JPDFTypes.hh:37
int getPDFType(const std::string &file_name)
Get PDF type.
Definition: JPDFTypes.hh:77
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
int j
Definition: JPolint.hh:792
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Simple data structure for histogram binning.
bool is_valid() const
Check validity of histogram binning.
int getNumberOfBins() const
Get number of bins.
Type definition of a spline interpolation method based on a JCollection with double result type.
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:109
Type definition of a 1st degree polynomial interpolation based on a JGridMap implementation.
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.