Jpp  debug
the software that should make you happy
JMakeHDF.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <fstream>
4 #include <iomanip>
5 
7 #include "JPhysics/JPDFTable.hh"
8 #include "JPhysics/JPDFTypes.hh"
9 
10 #include "JIO/JFileStreamIO.hh"
11 
12 #include "JTools/JHistogram1D_t.hh"
15 #include "JTools/JFunction1D_t.hh"
17 
18 #include "JGeometry3D/JAngle3D.hh"
20 #include "JPhysics/JConstants.hh"
21 
22 #include "Jeep/JParser.hh"
23 #include "Jeep/JMessage.hh"
24 
25 
26 /**
27  * \file
28  *
29  * Program to convert multi-dimensional histograms of muon light to multi-dimensional PDFs.
30  * \author mdejong
31  */
32 int main(int argc, char **argv)
33 {
34  using namespace std;
35  using namespace JPP;
36 
37  string inputFile;
38  string fileDescriptor;
39  int debug;
40 
41  try {
42 
43  JParser<> zap("Program to convert multi-dimensional histograms of muon light to multi-dimensional PDFs.");
44 
45  zap['f'] = make_field(inputFile);
46  zap['o'] = make_field(fileDescriptor) = "J%p.dat";
47  zap['d'] = make_field(debug) = 1;
48 
49  zap(argc, argv);
50  }
51  catch(const exception &error) {
52  FATAL(error.what() << endl);
53  }
54 
55 
56  if (!hasWildCard(fileDescriptor)) {
57  FATAL("error file descriptor " << fileDescriptor << endl);
58  }
59 
60  typedef JHistogram1D_t::abscissa_type abscissa_type;
61 
65  JHistogramGridMap_t>::maplist> JMultiHistogram_t;
66 
67  typedef JPDFTransformer<3, abscissa_type> JFunction3DTransformer_t;
68 
69  JMultiHistogram_t h0; // occurrence rate of PMT (used for normalisation)
70  JMultiHistogram_t h1; // light from muon
71  JMultiHistogram_t h2; // light from EM showers
72 
73  h1.transformer.reset(new JFunction3DTransformer_t());
74  h2.transformer.reset(new JFunction3DTransformer_t());
75 
76 
77  // input
78 
79  JFileStreamReader in(inputFile.c_str());
80 
81  for (JMultiHistogram_t* p : { &h0, &h1, &h2 }) {
82  in.load(*p);
83  }
84 
85  in.close();
86 
87 
88  // rebin histograms according angle of incidence on PMT and normalise contents to PMT occurrence rate
89 
90  for (JMultiHistogram_t::super_iterator
91  i0 = h0.super_begin(),
92  i1 = h1.super_begin(),
93  i2 = h2.super_begin(); i0 != h0.super_end(); ++i0, ++i1, ++i2) {
94 
95  const double W = i0.getValue().getIntegral();
96 
97  if (W != 0.0) {
98 
99  const JDirection3D u(JAngle3D(i0->second->first, i0->second->second->first));
100  const JDirection3D v(getSinThetaC(), 0.0, getCosThetaC());
101 
102  int number_of_bins = (int) (2 + u.getDot(v));
103 
104  for (JHistogram1D_t* p : { &i1.getValue(), &i2.getValue() }) {
105  p->rebin(JHistogram1D_t::JRebin(number_of_bins));
106  p->div(W);
107  }
108  }
109  }
110 
111 
112  // output
113 
114  struct tuple {
115  const JPDFType_t type;
116  const JMultiHistogram_t& value;
117  };
118 
119  tuple ntuple[] = { // map histogram to PDF type
122  };
123 
124 
128  JPolint1FunctionalGridMap>::maplist> JPDF_t;
129 
130  for (int i = 0; i != sizeof(ntuple)/sizeof(ntuple[0]); ++i) {
131 
132  const string file_name = getFilename(fileDescriptor, ntuple[i].type);
133 
134  try {
135 
136  NOTICE("storing output to file " << file_name << "... " << flush);
137 
138  const JPDF_t pdf(ntuple[i].value);
139 
140  pdf.store(file_name.c_str());
141 
142  NOTICE("OK" << endl);
143  }
144  catch(const JException& error) {
145  FATAL(error.what() << endl);
146  }
147  }
148 }
Various implementations of functional maps.
int main(int argc, char **argv)
Definition: JMakeHDF.cc:32
General purpose messaging.
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
Numbering scheme for PDF types.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
Physics constants.
Data structure for angles in three dimensions.
Definition: JAngle3D.hh:35
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:35
Binary buffered file input.
JReader & load(JSerialisable &object)
Read object.
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:1714
Multi-dimensional PDF table for arrival time of Cherenkov light.
Definition: JPDFTable.hh:44
Template definition of transformer of the probability density function (PDF) of the time response of ...
Histogram in 1D.
collection_type::abscissa_type abscissa_type
Transformable multidimensional histogram.
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
Definition: JeepToolkit.hh:128
bool hasWildCard(const std::string &file_name)
Check presence of wild card.
Definition: JeepToolkit.hh:53
double getCosThetaC()
Get average cosine of Cherenkov angle of water corresponding to group velocity.
double getSinThetaC()
Get average sine of Cherenkov angle of water corresponding to group velocity.
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:24
@ SCATTERED_LIGHT_FROM_EMSHOWERS
scattered light from EM showers
Definition: JPDFTypes.hh:30
@ SCATTERED_LIGHT_FROM_MUON
scattered light from muon
Definition: JPDFTypes.hh:27
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JHistogram1D< JElement2D< double, double >, JCollection > JHistogram1D_t
Type definition of a 1 dimensional histogram based on a JCollection.
double u[N+1]
Definition: JPolint.hh:865
data_type v[N+1][M+1]
Definition: JPolint.hh:866
Definition: JSTDTypes.hh:14
Type definition of a JHistogramMap based on JGridMap implementation.
Type definition of a JHistogramMap based on JMap implementation.
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:109
Type definition of a 1st degree polynomial interpolation with result type double.
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.
Auxiliary class for merging of fixed number of consecutive bins.
Definition: JHistogram1D.hh:30