Jpp  18.0.0-rc.2
the software that should make you happy
 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 <algorithm>
#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 39 of file JDiffPDG.cc.

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