Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JDiffPDG.cc File Reference

Auxiliary program to compare PDF tables of the arrival time of the Cherenkov light from a shower. More...

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include "JTools/JFunction1D_t.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JPhysics/JPDFTable.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to compare PDF tables of the arrival time of the Cherenkov light from a shower.

Author
mdejong

Definition in file JDiffPDG.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 22 of file JDiffPDG.cc.

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 shower.");
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  JPolint1FunctionalMap,
52  JPolint1FunctionalGridMap,
53  JPolint1FunctionalGridMap>::maplist JMapList_t;
54  typedef JPDFTable<JFunction1D_t, JMapList_t> JPDF_t;
55 
56  typedef JFunction1D_t::argument_type argument_type;
57  typedef JArray<4, argument_type> JArray_t;
58 
59 
60  JPDF_t pdfA;
61  JPDF_t pdfB;
62 
63 
64  const JFunction1D_t::JSupervisor supervisor(new JFunction1D_t::JDefaultResult(0.0));
65 
66 
67  struct JEntry_t {
68 
69  const char* file_name;
70  JPDF_t& pdf;
71 
72  void load()
73  {
74  pdf.load(file_name);
75  }
76 
77  } buffer[] = {
78  { inputFileA.c_str(), pdfA },
79  { inputFileB.c_str(), pdfB }
80  };
81 
82 
83  for (JEntry_t* p = buffer; p != buffer + sizeof(buffer)/sizeof(buffer[0]); ++p) {
84 
85  try {
86 
87  NOTICE("loading input from file " << p->file_name << "... " << flush);
88 
89  p->load();
90 
91  NOTICE("OK" << endl);
92  }
93  catch(const JException& error) {
94  FATAL(error.what() << endl);
95  }
96 
97  p->pdf.compile();
98  p->pdf.setExceptionHandler(supervisor);
99  }
100 
101  bool ok = true;
102 
103  JPDF_t::super_const_iterator i = pdfA.super_begin();
104  JPDF_t::super_const_iterator j = pdfB.super_begin();
105 
106  for ( ; i != pdfA.super_end() &&
107  j != pdfB.super_end(); ++i, ++j) {
108 
109  const double Wa = pdfA.transformer->getWeight(JArray_t((*i).getKey()));
110  const double Wb = pdfB.transformer->getWeight(JArray_t((*j).getKey()));
111 
112  if (fabs(i->first - j->first) > precision ||
113  fabs(i->second->first - j->second->first) > precision ||
114  fabs(i->second->second->first - j->second->second->first) > precision ||
115  fabs(i->second->second->second->first - j->second->second->second->first) > precision ||
116  fabs(Wa - Wb) > precision) {
117 
118  DEBUG("a[] "
119  << i->first << ' '
120  << i->second->first << ' '
121  << i->second->second->first << ' '
122  << i->second->second->second->first << ' '
123  << Wa << endl);
124 
125  DEBUG("b[] "
126  << j->first << ' '
127  << j->second->first << ' '
128  << j->second->second->first << ' '
129  << j->second->second->second->first << ' '
130  << Wb << endl);
131 
132  ok = false;
133  }
134 
135 
136  const JFunction1D_t& fa = (*i).getValue();
137  const JFunction1D_t& fb = (*j).getValue();
138 
139  JFunction1D_t::const_iterator p = fa.begin();
140  JFunction1D_t::const_iterator q = fb.begin();
141 
142  while (p != fa.end() &&
143  q != fb.end()) {
144 
145  if (fabs(p->getX() - q->getX()) > precision) {
146 
147  DEBUG("a.f[] " << p->getX() << endl);
148  DEBUG("b.f[] " << q->getX() << endl);
149 
150  ok = false;
151  }
152 
153  if (fabs(p->getY() - q->getY()) > precision) {
154 
155  DEBUG("a.f() " << p->getX() << ' ' << p->getY() << endl);
156  DEBUG("b.f() " << q->getX() << ' ' << q->getY() << endl);
157 
158  ok = false;
159  }
160 
161  if (p->getX() < q->getX())
162  ++p;
163  else if (q->getX() < p->getX())
164  ++q;
165  else {
166  ++p;
167  ++q;
168  }
169  }
170 
171  for ( ; p != fa.end(); ++p) {
172 
173  DEBUG("a.f() " << p->getX() << endl);
174 
175  ok = false;
176  }
177 
178  for ( ; q != fb.end(); ++q) {
179 
180  DEBUG("b.f() " << q->getX() << endl);
181 
182  ok = false;
183  }
184  }
185 
186  for ( ; i != pdfA.super_end(); ++i) {
187 
188  DEBUG("a[] "
189  << i->first << ' '
190  << i->second->first << ' '
191  << i->second->second->first << ' '
192  << i->second->second->second->first << endl);
193 
194  ok = false;
195  }
196 
197  for ( ; j != pdfB.super_end(); ++j) {
198 
199  DEBUG("b[] "
200  << j->first << ' '
201  << j->second->first << ' '
202  << j->second->second->first << ' '
203  << j->second->second->second->first << endl);
204 
205  ok = false;
206  }
207 
208  if (!ok) {
209  ERROR(inputFileA << " and " << inputFileB << " differ." << endl);
210  }
211 }
Utility class to parse command line options.
Definition: JParser.hh:1493
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:61
#define FATAL(A)
Definition: JMessage.hh:67
int j
Definition: JPolint.hh:634
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62