Jpp  debug
the software that should make you happy
Functions
JDiffPDF.cc File Reference

Auxiliary program to compare PDF tables of the arrival time of the Cherenkov light from a muon. 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 muon.

Author
mdejong

Definition in file JDiffPDF.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 39 of file JDiffPDF.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 muon.");
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;
67  JPolint1FunctionalGridMap>::maplist JMapList_t;
69 
70  typedef JFunction1D_t::argument_type argument_type;
71  typedef JArray<3, argument_type> JArray_t;
72 
73  JPDF_t pdfA;
74  JPDF_t pdfB;
75 
76  const JFunction1D_t::JSupervisor supervisor(new JFunction1D_t::JDefaultResult(0.0));
77 
78  struct pair_type {
79  const string file_name;
80  JPDF_t& pdf;
81  } buffer[] = {
82  { inputFileA, pdfA },
83  { inputFileB, pdfB }
84  };
85 
86  for (const pair_type& i : buffer) {
87 
88  try {
89 
90  NOTICE("loading input from file " << i.file_name << "... " << flush);
91 
92  i.pdf.load(i.file_name.c_str());
93  i.pdf.compile();
94  i.pdf.setExceptionHandler(supervisor);
95 
96  NOTICE("OK" << endl);
97  }
98  catch(const JException& error) {
99  FATAL(error.what() << endl);
100  }
101  }
102 
103  bool ok = true;
104 
105  JPDF_t::super_const_iterator i = pdfA.super_begin();
106  JPDF_t::super_const_iterator j = pdfB.super_begin();
107 
108  for ( ; i != pdfA.super_end() &&
109  j != pdfB.super_end(); ++i, ++j) {
110 
111  const double Wa = pdfA.transformer->getWeight(JArray_t((*i).getKey()));
112  const double Wb = pdfB.transformer->getWeight(JArray_t((*j).getKey()));
113 
114  if (fabs(i->first - j->first) > precision ||
115  fabs(i->second->first - j->second->first) > precision ||
116  fabs(i->second->second->first - j->second->second->first) > precision ||
117  fabs(Wa - Wb) > precision) {
118 
119  DEBUG("a[] "
120  << i->first << ' '
121  << i->second->first << ' '
122  << i->second->second->first << ' '
123  << Wa << endl);
124 
125  DEBUG("b[] "
126  << j->first << ' '
127  << j->second->first << ' '
128  << j->second->second->first << ' '
129  << Wb << endl);
130 
131  ok = false;
132  }
133 
134  const JFunction1D_t& fa = (*i).getValue();
135  const JFunction1D_t& fb = (*j).getValue();
136 
137  JFunction1D_t::const_iterator p = fa.begin();
138  JFunction1D_t::const_iterator q = fb.begin();
139 
140  while (p != fa.end() &&
141  q != fb.end()) {
142 
143  if (fabs(p->getX() - q->getX()) > precision) {
144 
145  DEBUG("a.x " << p->getX() << endl);
146  DEBUG("b.x " << q->getX() << endl);
147 
148  ok = false;
149  }
150 
151  if (!compare(p->getY(), q->getY(), precision)) {
152 
153  DEBUG("a.y " << p->getX() << ' ' << p->getY() << endl);
154  DEBUG("b.y " << q->getX() << ' ' << q->getY() << endl);
155 
156  ok = false;
157  }
158 
159  if (p->getX() < q->getX())
160  ++p;
161  else if (q->getX() < p->getX())
162  ++q;
163  else {
164  ++p;
165  ++q;
166  }
167  }
168 
169  for ( ; p != fa.end(); ++p) {
170 
171  DEBUG("a.x " << p->getX() << endl);
172 
173  ok = false;
174  }
175 
176  for ( ; q != fb.end(); ++q) {
177 
178  DEBUG("b.x " << q->getX() << endl);
179 
180  ok = false;
181  }
182  }
183 
184  for ( ; i != pdfA.super_end(); ++i) {
185 
186  DEBUG("a[] "
187  << i->first << ' '
188  << i->second->first << ' '
189  << i->second->second->first << endl);
190 
191  ok = false;
192  }
193 
194  for ( ; j != pdfB.super_end(); ++j) {
195 
196  DEBUG("b[] "
197  << j->first << ' '
198  << j->second->first << ' '
199  << j->second->second->first << endl);
200 
201  ok = false;
202  }
203 
204  if (!ok) {
205  ERROR(inputFileA << " and " << inputFileB << " differ." << endl);
206  }
207 
208  return (ok ? 0 : 1);
209 }
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define ERROR(A)
Definition: JMessage.hh:66
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
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
One dimensional array of template objects with fixed length.
Definition: JArray.hh:43
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
int j
Definition: JPolint.hh:792
Definition: JSTDTypes.hh:14
Data structure for a pair of indices.
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:109
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.
Type definition of a spline interpolation method based on a JCollection with double result type.