Jpp  18.2.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPlotNPE1D.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <fstream>
4 #include <iomanip>
5 #include <vector>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TH1D.h"
10 
11 #include "JTools/JFunction1D_t.hh"
15 #include "JPhysics/JPDFTable.hh"
16 #include "JPhysics/JPDFTypes.hh"
17 #include "JPhysics/JNPETable.hh"
18 #include "JPhysics/JGeanz.hh"
19 #include "JGeometry3D/JAngle3D.hh"
20 #include "Jeep/JPrint.hh"
21 #include "Jeep/JParser.hh"
22 #include "Jeep/JMessage.hh"
23 
24 
25 /**
26  * \file
27  *
28  * Program to plot PDF of Cherenkov light from EM-shower using interpolation tables.
29  * \author jseneca
30  */
31 int main(int argc, char **argv)
32 {
33  using namespace std;
34  using namespace JPP;
35 
36  typedef JAbstractHistogram<double> JHistogram_t;
37 
38  vector<string> inputFile;
39  string outputFile;
40  JAngle3D dir;
41  double D;
42  JHistogram_t x;
43  double E;
44  int numberOfPoints;
45  int debug;
46 
47  try {
48 
49  JParser<> zap("Program to plot PDF of Cherenkov light from EM-shower using interpolation tables.");
50 
51  zap['f'] = make_field(inputFile);
52  zap['o'] = make_field(outputFile) = "";
53  zap['D'] = make_field(dir, "(theta, phi) of PMT [rad]");
54  zap['R'] = make_field(D, "distance from vertex to PMT [m]");
55  zap['x'] = make_field(x, "histogram x-binning") = JHistogram_t();
56  zap['E'] = make_field(E, "Energy [GeV]") = 0.0;
57  zap['N'] = make_field(numberOfPoints) = 10;
58  zap['d'] = make_field(debug) = 2;
59 
60  zap(argc, argv);
61  }
62  catch(const exception &error) {
63  FATAL(error.what() << endl);
64  }
65 
66 
68 
69  if (E > 0.0) {
70  for (int i = 0; i != numberOfPoints; ++i) {
71  Z.push_back(geanz.getLength(E, (i + 0.5) / (double) numberOfPoints));
72  }
73  }
74 
75 
76  typedef JPolint0Function1D_t JFunction1D_t;
77  typedef
78  JMapList<JPolint1FunctionalMap,
79  JMapList<JPolint1FunctionalMap,
80  JMapList<JPolint1FunctionalGridMap,
81  JMapList<JPolint1FunctionalGridMap> > > > JMapList_t;
82  typedef JPDFTable<JFunction1D_t, JMapList_t> JPDF_t;
83  typedef JNPETable<double, double, JMapList_t> JNPE_t;
84 
85  JDistance<double>::precision = 1.0e-10;
86 
87  const int N = inputFile.size();
88 
89  JPDF_t pdf[N];
90  JNPE_t npe[N];
91 
92  try {
93 
94  for (int i = 0; i != N; ++i) {
95 
96  NOTICE("loading input from file " << inputFile[i] << "... " << flush);
97 
98  pdf[i].load(inputFile[i].c_str());
99 
100  pdf[i].setExceptionHandler(new JFunction1D_t::JDefaultResult(JMATH::zero));
101 
102  npe[i] = JNPE_t(pdf[i]);
103 
104  npe[i].setExceptionHandler(new JFunction<double, double>::JDefaultResult(JMATH::zero));
105 
106  NOTICE("OK" << endl);
107  }
108  }
109  catch(const JException& error) {
110  FATAL(error.what() << endl);
111  }
112 
113 
114  if (outputFile != "") {
115 
116  TFile out(outputFile.c_str(), "recreate");
117 
118  if (!x.is_valid()) { x = JHistogram_t(100000, -1.0, +1.0); }
119 
120  TH1D h0("h0", "PDF Projection; D [m]; P [npe]", x.getNumberOfBins(), x.getLowerLimit(), x.getUpperLimit());
121 
122 
123  for (int ix = 1; ix <= h0.GetNbinsX(); ++ix) {
124 
125  const double cd = h0.GetBinCenter(ix);
126 
127  double Y = 0.0;
128 
129  if (!Z.empty()) {
130 
131  const double W = 1.0 / (double) Z.size();
132 
133  for (vector<double>::const_iterator z = Z.begin(); z != Z.end(); ++z) {
134 
135  const double __D = sqrt(D*D - 2.0*(D*cd)*(*z) + (*z)*(*z));
136  const double __cd = (D * cd - (*z)) / __D;
137 
138  for (int i = 0; i != N; ++i) {
139  try {
140  Y += W * npe[i](__D, __cd, dir.getTheta(), dir.getPhi());
141  }
142  catch(const exception& error) {}
143  }
144  }
145 
146  } else {
147 
148  for (int i = 0; i != N; ++i) {
149  Y += npe[i](D, cd, dir.getTheta(), dir.getPhi());
150  }
151  }
152 
153  h0.SetBinContent(ix, Y);
154  }
155 
156  out.Write();
157  out.Close();
158 
159  } else {
160 
161  for (double cd; ; ) {
162 
163  cout << "> " << flush;
164  cin >> D >> cd;
165 
166  for (int i = 0; i != N; ++i) {
167  cout << i << ' ' << FIXED(9,5) << npe[i](D, cd, dir.getTheta(), dir.getPhi()) << endl;
168  }
169  }
170  }
171 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
then usage $script< input file >[option[primary[working directory]]] nWhere option can be E
Definition: JMuonPostfit.sh:40
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
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:1989
static const JGeanz geanz(1.85, 0.62, 0.54)
Function object for longitudinal EM-shower profile.
#define NOTICE(A)
Definition: JMessage.hh:64
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
Utility class to parse command line options.
int numberOfPoints
Definition: JResultPDF.cc:22
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
Longitudinal emission profile EM-shower.
double getLength(const double E, const double P, const double eps=1.0e-3) const
Get shower length for a given integrated probability.
Definition: JGeanz.hh:122
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
int debug
debug level