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
JPlotNPE-PDG.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <fstream>
5 #include <iomanip>
6 #include <vector>
7 
8 #include "TROOT.h"
9 #include "TFile.h"
10 #include "TH2D.h"
11 
12 #include "JTools/JFunction1D_t.hh"
16 #include "JPhysics/JPDFTable.hh"
17 #include "JPhysics/JCDFTable.hh"
18 #include "JPhysics/JNPETable.hh"
19 #include "JPhysics/JPDFTypes.hh"
20 #include "JROOT/JRootToolkit.hh"
21 
22 #include "Jeep/JPrint.hh"
23 #include "Jeep/JParser.hh"
24 #include "Jeep/JMessage.hh"
25 
26 
28 
29 std::istream& operator>>(std::istream& in, orientation& x) { return in >> x.first >> x.second; }
30 std::ostream& operator<<(std::ostream& out, const orientation& x) { return out << x.first << ' ' << x.second; }
31 
32 
33 /**
34  * \file
35  *
36  * Program to compare integrals of PDF of Cherenkov light from EM-shower using interpolation tables.
37  * \author lquinn
38  */
39 int main(int argc, char **argv)
40 {
41  using namespace std;
42  using namespace JPP;
43 
44  typedef JAbstractHistogram<Double_t> JHistogram_t;
45 
46  string pdfFile;
47  string cdfFile;
48  string outputFile;
49  orientation dir;
50  JHistogram_t x;
51  JHistogram_t y;
52  double E;
53  int numberOfPoints;
54  int debug;
55 
56  try {
57 
58  JParser<> zap("Program to plot PDF of Cherenkov light from EM-shower using interpolation tables.");
59 
60  zap['P'] = make_field(pdfFile);
61  zap['C'] = make_field(cdfFile);
62  zap['o'] = make_field(outputFile);
63  zap['D'] = make_field(dir, "(theta, phi) of PMT [rad]");
64  zap['x'] = make_field(x, "histogram x-binning") = JHistogram_t();
65  zap['y'] = make_field(y, "histogram y-binning") = JHistogram_t();
66  zap['E'] = make_field(E, "Energy [GeV]") = 1.0;
67  zap['N'] = make_field(numberOfPoints) = 10;
68  zap['d'] = make_field(debug) = 0;
69 
70  zap(argc, argv);
71  }
72  catch(const exception &error) {
73  FATAL(error.what() << endl);
74  }
75 
76 
77  const double theta = dir.first;
78  const double phi = dir.second;
79 
80  typedef JSplineFunction1S_t JFunction1D_t;
81  typedef
82  JMapList<JPolint1FunctionalMap,
83  JMapList<JPolint1FunctionalMap,
84  JMapList<JPolint1FunctionalGridMap,
85  JMapList<JPolint1FunctionalGridMap> > > > JMapList_t;
86  typedef JPDFTable<JFunction1D_t, JMapList_t> JPDF_t;
87  typedef JNPETable<double, double, JMapList_t> JNPE_t;
88  typedef JCDFTable<JFunction1D_t, JMapList_t> JCDF_t;
89 
90  JDistance<double>::precision = 1.0e-10;
91 
92  JPDF_t pdf;
93  JNPE_t npe;
94  JCDF_t cdf;
95 
96  try {
97 
98  NOTICE("loading input from file " << pdfFile << "... " << flush);
99 
100  pdf.load(pdfFile.c_str());
101 
102  pdf.setExceptionHandler(new JFunction1D_t::JDefaultResult(JMATH::zero));
103 
104  npe = JNPE_t(pdf);
105 
106  NOTICE("OK" << endl);
107 
108  NOTICE("loading input from file " << cdfFile << "... " << flush);
109 
110  cdf.load(cdfFile.c_str());
111 
112  NOTICE("OK" << endl);
113  }
114  catch(const JException& error) {
115  FATAL(error.what() << endl);
116  }
117 
118  if (!x.is_valid()) { x = JHistogram_t(250, 0.0, 250.0); }
119  if (!y.is_valid()) { y = JHistogram_t(200, -1.0, +1.0); }
120 
121  TH2D h0("pdf", NULL, x.getNumberOfBins(), x.getLowerLimit(), x.getUpperLimit(), y.getNumberOfBins(), y.getLowerLimit(), y.getUpperLimit());
122  TH2D h1("npe", NULL, x.getNumberOfBins(), x.getLowerLimit(), x.getUpperLimit(), y.getNumberOfBins(), y.getLowerLimit(), y.getUpperLimit());
123  TH2D h2("cdf", NULL, x.getNumberOfBins(), x.getLowerLimit(), x.getUpperLimit(), y.getNumberOfBins(), y.getLowerLimit(), y.getUpperLimit());
124 
125  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
126  for (int j = 1; j <= h0.GetNbinsY(); ++j) {
127 
128  const double D = h0.GetXaxis()->GetBinCenter(i);
129  const double cd = h0.GetYaxis()->GetBinCenter(j);
130 
131  try {
132 
133  const double y0 = get_integral(pdf(D, cd, theta, phi, 1.0e3));
134  const double y1 = npe (D, cd, theta, phi);
135  const double y2 = cdf.getNPE (D, cd, theta, phi);
136 
137  DEBUG("npe "
138  << FIXED(5,1) << D << ' '
139  << FIXED(5,1) << cd << ' '
140  << SCIENTIFIC(12,3) << y0 << ' '
141  << SCIENTIFIC(12,3) << y1 << ' '
142  << SCIENTIFIC(12,3) << y2 << endl);
143 
144  h0.SetBinContent(i, j, E * y0);
145  h1.SetBinContent(i, j, E * y1);
146  h2.SetBinContent(i, j, E * y2);
147  }
148  catch(const exception& error) {
149  ERROR(error.what());
150  }
151  }
152  }
153 
154  if (outputFile != "") {
155 
156  TFile out(outputFile.c_str(), "recreate");
157 
158  out << h0 << h1 << h2;
159 
160  out.Write();
161  out.Close();
162  }
163 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
then usage E
Definition: JMuonPostfit.sh:35
Various implementations of functional maps.
Numbering scheme for PDF types.
I/O formatting auxiliaries.
#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
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
then for FUNCTION in pdf npe cdf
Definition: JPlotNPE-PDG.sh:73
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition: JHead.hh:1618
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
int numberOfPoints
Definition: JResultPDF.cc:22
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
int j
Definition: JPolint.hh:666
std::pair< double, double > orientation
Definition: JDrawLED.cc:22
JResultEvaluator< JResult_t >::result_type get_integral(const JResult_t &value)
Helper method to convert function value to partial integral value.
Definition: JResult.hh:1024
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
do echo Generating $dir eval D
Definition: JDrawLED.sh:53