Jpp
JAddHDF.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <fstream>
4 #include <iomanip>
5 
6 #include "JPhysics/JPDFTable.hh"
7 
8 #include "JIO/JFileStreamIO.hh"
9 
10 #include "JTools/JHistogram1D_t.hh"
13 #include "JTools/JFunction1D_t.hh"
15 
16 #include "JGeometry3D/JAngle3D.hh"
17 #include "JGeometry3D/JVersor3D.hh"
18 #include "JTools/JConstants.hh"
19 
20 #include "Jeep/JParser.hh"
21 #include "Jeep/JMessage.hh"
22 
24 
25 
26 /**
27  * \file
28  *
29  * Program to add multi-dimensional histograms of muon light
30  * \author lquinn
31  */
32 int main(int argc, char **argv)
33 {
34  using namespace std;
35  using namespace JPP;
36 
37  vector<string> inputFile;
38  string outputFile;
39  int debug;
40 
41  try {
42 
43  JParser<> zap("Program to add multi-dimensional histograms of muon light");
44 
45  zap['f'] = make_field(inputFile);
46  zap['o'] = make_field(outputFile);
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  typedef JHistogram1D_t::abscissa_type abscissa_type;
57 
58  typedef JTransformableMultiHistogram<JHistogram1D_t,
59  JMAPLIST<JHistogramMap_t,
60  JHistogramGridMap_t,
61  JHistogramGridMap_t>::maplist> JMultiHistogram_t;
62 
63  typedef JPDFTransformer<3, abscissa_type> JFunctionTransformer_t;
64 
65  JMultiHistogram_t h0; // occurrence rate of PMT (used for normalisation)
66  JMultiHistogram_t h1; // light from muon
67  JMultiHistogram_t h2; // light from EM showers
68 
69  h1.transformer.reset(new JFunctionTransformer_t());
70  h2.transformer.reset(new JFunctionTransformer_t());
71 
72  bool add = false;
73 
74  for(vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
75 
76  NOTICE("loading input from file " << *file_name << "... " << flush);
77 
78  try {
79 
80  JFileStreamReader in(file_name->c_str());
81 
82  if (add) {
83 
84  JMultiHistogram_t p0;
85  JMultiHistogram_t p1;
86  JMultiHistogram_t p2;
87 
88  p1.transformer.reset(new JFunctionTransformer_t());
89  p2.transformer.reset(new JFunctionTransformer_t());
90 
91  for(JMultiHistogram_t* buffer[] = { &p0, &p1, &p2, NULL }, **i = buffer; *i != NULL; ++i) {
92  in.load(**i);
93  }
94 
95  in.close();
96 
97  NOTICE("done." << endl);
98 
99  // Add new histogram to first histogram
100 
101  for(JMultiHistogram_t::super_iterator
102  i0 = h0.super_begin(), i1 = h1.super_begin(), i2 = h2.super_begin(),
103  j0 = p0.super_begin(), j1 = p1.super_begin(), j2 = p2.super_begin();
104  i0 != h0.super_end(); ++i0, ++i1, ++i2, ++j0, ++j1, ++j2)
105  {
106  i0.getValue().add(j0.getValue());
107  i1.getValue().add(j1.getValue());
108  i2.getValue().add(j2.getValue());
109  }
110  }
111  else {
112 
113  for(JMultiHistogram_t* buffer[] = { &h0, &h1, &h2, NULL }, **i = buffer; *i != NULL; ++i) {
114  in.load(**i);
115  }
116 
117  in.close();
118 
119  NOTICE("done." << endl);
120 
121  add = true;
122  }
123  }
124  catch(const JException& error) {
125  FATAL(error.what() << endl);
126  }
127  }
128 
129  JFileStreamWriter out(outputFile.c_str());
130 
131  NOTICE("Storing, " << flush);
132 
133  for (const JMultiHistogram_t* buffer[] = { &h0, &h1, &h2, NULL }, **i = buffer; *i != NULL; ++i) {
134  out.store(**i);
135  }
136 
137  out.close();
138  NOTICE("done." << endl);
139 }
JMessage.hh
JHistogramMap_t.hh
JFileStreamIO.hh
std::vector
Definition: JSTDTypes.hh:12
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JPDFTransformer.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JTransformableMultiHistogram.hh
JFunction1D_t.hh
JTOOLS::JHistogram1D::abscissa_type
collection_type::abscissa_type abscissa_type
Definition: JHistogram1D.hh:121
debug
int debug
debug level
Definition: JSirene.cc:59
JConstants.hh
JFunctionalMap_t.hh
JAngle3D.hh
JParser.hh
JTOOLS::JHistogram1D_t
JHistogram1D< JElement2D< double, double >, JCollection > JHistogram1D_t
Type definition of a 1 dimensional histogram based on a JCollection.
Definition: JHistogram1D_t.hh:22
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std
Definition: jaanetDictionary.h:36
p1
TPaveText * p1
Definition: JDrawModule3D.cc:35
JHistogram1D_t.hh
JVersor3D.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
main
int main(int argc, char **argv)
Definition: JAddHDF.cc:32
JPDFTable.hh