Jpp  16.0.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDiffAcousticsEvt.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <vector>
4 #include <algorithm>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 
9 #include "JAcoustics/JEvt.hh"
10 #include "JAcoustics/JSupport.hh"
11 
13 
14 #include "JLang/JComparator.hh"
15 #include "JLang/JComparison.hh"
16 
17 #include "Jeep/JParser.hh"
18 #include "Jeep/JMessage.hh"
19 
20 namespace {
21 
22  using JACOUSTICS::JFit;
23  using JACOUSTICS::JEvt;
24 
25 
26  const struct {
27 
28  /**
29  * Compare fits.
30  *
31  * \param first first fit
32  * \param second second fit
33  * \return true if first fit less than second; else false
34  */
35  inline bool operator()(const JFit& first, const JFit& second) const
36  {
37  if (first.id == second.id) {
38 
39  if (first.tx == second.tx) {
40 
41  return first.ty < second.ty;
42 
43  } else {
44 
45  return first.tx < second.tx;
46  }
47 
48  } else {
49 
50  return first.id < second.id;
51  }
52  }
53 
54 
55  /**
56  * Compare events.
57  *
58  * \param first first event
59  * \param second second event
60  * \return true if first event less than second; else false
61  */
62  inline bool operator()(const JEvt& first, const JEvt& second) const
63  {
64  if (first.oid == second.oid) {
65 
66  if (first.UNIXTimeStart == second.UNIXTimeStart) {
67 
68  if (first.UNIXTimeStop == second.UNIXTimeStop) {
69 
70  if (first.ndf == second.ndf) {
71 
72  if (first.size() == second.size()) {
73 
74  for (JEvt::const_iterator
75  p0 = first .begin(),
76  p1 = second.begin(); p0 != first.end() && p1 != second.end(); ++p0, ++p1) {
77 
78  if ((*this)(*p0, *p1)) {
79  return true;
80  }
81  }
82 
83  return false;
84 
85  } else {
86 
87  return first.size() < second.size();
88  }
89  } else {
90 
91  return first.ndf < second.ndf;
92  }
93  } else {
94 
95  return first.UNIXTimeStop < second.UNIXTimeStop;
96  }
97 
98  } else {
99 
100  return first.UNIXTimeStart < second.UNIXTimeStart;
101  }
102 
103  } else {
104 
105  return first.oid < second.oid;
106  }
107  }
108  } compare;
109 
110 
111  /**
112  * Printer.
113  */
114  struct printer {
115 
116  int debug;
117  size_t width;
118 
119  /**
120  * Print data.
121  *
122  * \param out output stream
123  * \param filename file name
124  * \param index index
125  * \param evt event
126  * \param prefix prefix
127  * \param postfix postfix
128  * \return output stream
129  */
130  std::ostream& operator()(std::ostream& out, const std::string& filename, const int index, const JEvt& evt, const std::string& prefix, const std::string& postfix) const
131  {
132  using namespace std;
133  using namespace JPP;
134 
135  if (debug >= debug_t) {
136  out << prefix << (prefix == "" ? "" : " ")
137  << setw(width) << left << filename << right << ' '
138  << "[" << FILL(6,'0') << index << "]" << FILL() << ' '
139  << evt.oid << ' '
140  << FIXED(20,5) << evt.UNIXTimeStart << ' '
141  << FIXED(20,5) << evt.UNIXTimeStop << ' '
142  << (postfix == "" ? "" : " ") << postfix << endl;
143  }
144 
145  return out;
146  }
147 
148 
149  /**
150  * Write fit to output stream.
151  *
152  * \param out output stream
153  * \param object fit
154  * \param prefix prefix
155  * \param postfix postfix
156  * \return output stream
157  */
158  std::ostream& operator()(std::ostream& out, const JFit& object, const std::string& prefix, const std::string& postfix) const
159  {
160  using namespace std;
161  using namespace JPP;
162 
163  if (debug >= debug_t) {
164  out << prefix << (prefix == "" ? "" : " ")
165  << FILL(4,'0') << object.id << FILL() << ' '
166  << FIXED(9,6) << object.tx << ' '
167  << FIXED(9,6) << object.ty << ' '
168  << (postfix == "" ? "" : " ") << postfix << endl;
169  }
170 
171  return out;
172  }
173  };
174 }
175 
176 /**
177  * \file
178  *
179  * Program to compare acoustics fit data.
180  * \author mdejong
181  */
182 int main(int argc, char **argv)
183 {
184  using namespace std;
185  using namespace JPP;
186 
187  vector<string> inputFile;
188  JLimit numberOfEvents;
189  int debug;
190 
191  try {
192 
193  JParser<> zap("Program to compare acoustics fit data.");
194 
195  zap['f'] = make_field(inputFile, "two outputs of JKatoomba[.sh]");
196  zap['n'] = make_field(numberOfEvents) = JLimit::max();
197  zap['d'] = make_field(debug) = 2;
198 
199  zap(argc, argv);
200  }
201  catch(const exception &error) {
202  FATAL(error.what() << endl);
203  }
204 
205  if (inputFile.size() != 2u) {
206  FATAL("Wrong number of input files " << inputFile.size() << endl);
207  }
208 
209  const size_t width = max(inputFile[0].size(), inputFile[1].size());
210  const printer print = { debug, width };
211 
212  vector<JEvt> buffer[2];
213 
214  for (int i = 0; i != 2; ++i) {
215 
216  for (JSingleFileScanner<JEvt> in(inputFile[i], numberOfEvents); in.hasNext(); ) {
217  buffer[i].push_back(*in.next());
218  }
219 
220  sort(buffer[i].begin(), buffer[i].end());
221  }
222 
223  if (true) {
224  for (int i = 0; i != 2; ++i) {
225  for (vector<JEvt>::iterator p = buffer[i].begin(); p != buffer[i].end(); ++p) {
226  sort(p->begin(), p->end(), make_comparator(&JFit::id, JComparison::lt()));
227  }
228  }
229  }
230 
231  int count[] = { 0, 0 };
232 
234  p0 = buffer[0].begin(),
235  p1 = buffer[1].begin(); p0 != buffer[0].end() && p1 != buffer[1].end(); ) {
236 
237  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && compare(*p0,*p1); ++p0, ++count[1]) {
238  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
239  }
240 
241  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && compare(*p1,*p0); ++p1, ++count[1]) {
242  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
243  }
244 
245  if (p0 != buffer[0].end() && p1 != buffer[1].end()) {
246 
247  if (!compare(*p0,*p1) && !compare(*p1,*p0)) {
248 
249  ++count[0];
250 
251  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "\\");
252  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "/ ");
253 
254  } else {
255 
256  ++count[1];
257 
258  if (p0->oid == p1->oid &&
259  p0->UNIXTimeStart == p1->UNIXTimeStart &&
260  p0->UNIXTimeStop == p1->UNIXTimeStop) {
261 
262  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "");
263  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "");
264 
265  JEvt::const_iterator i0 = p0->begin();
266  JEvt::const_iterator i1 = p1->begin();
267 
268  for ( ; i0 != p0->end() && i1 != p1->end(); ++i0, ++i1) {
269  if (compare(*i0, *i1) || compare(*i1,*i0)) {
270  print(cout, *i0, ">>", "");
271  print(cout, *i1, "<<", "");
272  }
273  }
274 
275  for ( ; i0 != p0->end(); ++i0) {
276  print(cout, *i0, ">>", "");
277  }
278 
279  for ( ; i1 != p1->end(); ++i1) {
280  print(cout, *i1, "<<", "");
281  }
282 
283  } else {
284 
285  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
286  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
287  }
288  }
289 
290  if (compare(*p0,*p1) || compare(*p1,*p0)) {
291 
292  } else {
293 
294  ++p0;
295  ++p1;
296  }
297  }
298  }
299 
300  STATUS("Number of differences / events: " << count[1] << " / " << count[0] << endl);
301 
302  if (count[1] != 0) {
303  FATAL("Number of differences " << count[1] << endl);
304  }
305 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int id
string identifier
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
TPaveText * p1
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Definition: JComparator.hh:185
std::string oid
detector identifier
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
#define STATUS(A)
Definition: JMessage.hh:63
ROOT TTree parameter settings.
int ndf
number of degrees of freedom
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
double ty
slope dy/dz
Acoustic single fit.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Scanning of objects from a single file according a format that follows from the extension of each fil...
double UNIXTimeStop
stop time
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
double tx
slope dx/dz
Acoustic event fit.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
print
Definition: JConvertDusj.sh:44
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
double UNIXTimeStart
start time
std::vector< int > count
Definition: JAlgorithm.hh:180
Utility class to parse command line options.
Object reading from a list of files.
double u[N+1]
Definition: JPolint.hh:755
Acoustic event fit.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:42