Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDiffPDF.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <fstream>
5 #include <iomanip>
6 #include <cmath>
7 
10 #include "JPhysics/JPDFTable.hh"
11 
12 #include "Jeep/JParser.hh"
13 #include "Jeep/JMessage.hh"
14 
15 
16 /**
17  * \file
18  *
19  * Auxiliary program to compare PDF tables of the arrival time of the Cherenkov light from a muon.
20  * \author mdejong
21  */
22 int main(int argc, char **argv)
23 {
24  using namespace std;
25 
26  string inputFileA;
27  string inputFileB;
28  double precision;
29  int debug;
30 
31  try {
32 
33  JParser<> zap("Auxiliary program to compare PDF tables of the arrival time of the Cherenkov light from a muon.");
34 
35  zap['a'] = make_field(inputFileA);
36  zap['b'] = make_field(inputFileB);
37  zap['p'] = make_field(precision) = 1.0e-4;
38  zap['d'] = make_field(debug) = 0;
39 
40  zap(argc, argv);
41  }
42  catch(const exception &error) {
43  FATAL(error.what() << endl);
44  }
45 
46 
47  using namespace JPP;
48 
49  typedef JSplineFunction1D_t JFunction1D_t;
50  typedef JMAPLIST<JPolint1FunctionalMap,
51  JPolint1FunctionalGridMap,
52  JPolint1FunctionalGridMap>::maplist JMapList_t;
53  typedef JPDFTable<JFunction1D_t, JMapList_t> JPDF_t;
54 
55  typedef JFunction1D_t::argument_type argument_type;
56  typedef JArray<3, argument_type> JArray_t;
57 
58 
59  JPDF_t pdfA;
60  JPDF_t pdfB;
61 
62 
63  const JFunction1D_t::JSupervisor supervisor(new JFunction1D_t::JDefaultResult(0.0));
64 
65 
66  struct JEntry_t {
67 
68  const char* file_name;
69  JPDF_t& pdf;
70 
71  } buffer[] = {
72  { inputFileA.c_str(), pdfA },
73  { inputFileB.c_str(), pdfB }
74  };
75 
76 
77  for (JEntry_t* p = buffer; p != buffer + sizeof(buffer)/sizeof(buffer[0]); ++p) {
78 
79  try {
80 
81  NOTICE("loading input from file " << p->file_name << "... " << flush);
82 
83  p->pdf.load(p->file_name);
84  p->pdf.compile();
85  p->pdf.setExceptionHandler(supervisor);
86 
87  NOTICE("OK" << endl);
88  }
89  catch(const JException& error) {
90  FATAL(error.what() << endl);
91  }
92  }
93 
94  bool ok = true;
95 
96  JPDF_t::super_const_iterator i = pdfA.super_begin();
97  JPDF_t::super_const_iterator j = pdfB.super_begin();
98 
99  for ( ; i != pdfA.super_end() &&
100  j != pdfB.super_end(); ++i, ++j) {
101 
102  const double Wa = pdfA.transformer->getWeight(JArray_t((*i).getKey()));
103  const double Wb = pdfB.transformer->getWeight(JArray_t((*j).getKey()));
104 
105  if (fabs(i->first - j->first) > precision ||
106  fabs(i->second->first - j->second->first) > precision ||
107  fabs(i->second->second->first - j->second->second->first) > precision ||
108  fabs(Wa - Wb) > precision) {
109 
110  DEBUG("a[] "
111  << i->first << ' '
112  << i->second->first << ' '
113  << i->second->second->first << ' '
114  << Wa << endl);
115 
116  DEBUG("b[] "
117  << j->first << ' '
118  << j->second->first << ' '
119  << j->second->second->first << ' '
120  << Wb << endl);
121 
122  ok = false;
123  }
124 
125 
126  const JFunction1D_t& fa = (*i).getValue();
127  const JFunction1D_t& fb = (*j).getValue();
128 
129  JFunction1D_t::const_iterator p = fa.begin();
130  JFunction1D_t::const_iterator q = fb.begin();
131 
132  while (p != fa.end() &&
133  q != fb.end()) {
134 
135  if (fabs(p->getX() - q->getX()) > precision) {
136 
137  DEBUG("a.f[] " << p->getX() << endl);
138  DEBUG("b.f[] " << q->getX() << endl);
139 
140  ok = false;
141  }
142 
143  if (fabs(p->getY() - q->getY()) > precision) {
144 
145  DEBUG("a.f() " << p->getX() << ' ' << p->getY() << endl);
146  DEBUG("b.f() " << q->getX() << ' ' << q->getY() << endl);
147 
148  ok = false;
149  }
150 
151  if (p->getX() < q->getX())
152  ++p;
153  else if (q->getX() < p->getX())
154  ++q;
155  else {
156  ++p;
157  ++q;
158  }
159  }
160 
161  for ( ; p != fa.end(); ++p) {
162 
163  DEBUG("a.f() " << p->getX() << endl);
164 
165  ok = false;
166  }
167 
168  for ( ; q != fb.end(); ++q) {
169 
170  DEBUG("b.f() " << q->getX() << endl);
171 
172  ok = false;
173  }
174  }
175 
176  for ( ; i != pdfA.super_end(); ++i) {
177 
178  DEBUG("a[] "
179  << i->first << ' '
180  << i->second->first << ' '
181  << i->second->second->first << endl);
182 
183  ok = false;
184  }
185 
186  for ( ; j != pdfB.super_end(); ++j) {
187 
188  DEBUG("b[] "
189  << j->first << ' '
190  << j->second->first << ' '
191  << j->second->second->first << endl);
192 
193  ok = false;
194  }
195 
196  if (!ok) {
197  ERROR(inputFileA << " and " << inputFileB << " differ." << endl);
198  }
199 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
Various implementations of functional maps.
#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
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 j
Definition: JPolint.hh:666