Jpp  master_rocky-43-ge265d140c
the software that should make you happy
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.detid == second.detid) {
65 
66  if (first.UNIXTimeStart == second.UNIXTimeStart) {
67 
68  if (first.UNIXTimeStop == second.UNIXTimeStop) {
69 
70  if (first.nhit == second.nhit) {
71 
72  if (first.npar == second.npar) {
73 
74  if (first.size() == second.size()) {
75 
76  for (JEvt::const_iterator
77  p0 = first .begin(),
78  p1 = second.begin(); p0 != first.end() && p1 != second.end(); ++p0, ++p1) {
79 
80  if ((*this)(*p0, *p1)) {
81  return true;
82  }
83  }
84 
85  return false;
86 
87  } else {
88 
89  return first.size() < second.size();
90  }
91 
92  } else {
93 
94  return first.npar < second.npar;
95  }
96 
97  } else {
98 
99  return first.nhit < second.nhit;
100  }
101 
102  } else {
103 
104  return first.UNIXTimeStop < second.UNIXTimeStop;
105  }
106 
107  } else {
108 
109  return first.UNIXTimeStart < second.UNIXTimeStart;
110  }
111 
112  } else {
113 
114  return first.detid < second.detid;
115  }
116  }
117  } compare;
118 
119 
120  /**
121  * Printer.
122  */
123  struct printer {
124 
125  int debug;
126  size_t width;
127 
128  /**
129  * Print data.
130  *
131  * \param out output stream
132  * \param filename file name
133  * \param index index
134  * \param evt event
135  * \param prefix prefix
136  * \param postfix postfix
137  * \return output stream
138  */
139  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
140  {
141  using namespace std;
142  using namespace JPP;
143 
144  if (debug >= debug_t) {
145  out << prefix << (prefix == "" ? "" : " ")
146  << setw(width) << left << filename << right << ' '
147  << "[" << FILL(6,'0') << index << "]" << FILL() << ' '
148  << evt.detid << ' '
149  << FIXED(20,5) << evt.UNIXTimeStart << ' '
150  << FIXED(20,5) << evt.UNIXTimeStop << ' '
151  << (postfix == "" ? "" : " ") << postfix << endl;
152  }
153 
154  return out;
155  }
156 
157 
158  /**
159  * Write fit to output stream.
160  *
161  * \param out output stream
162  * \param object fit
163  * \param prefix prefix
164  * \param postfix postfix
165  * \return output stream
166  */
167  std::ostream& operator()(std::ostream& out, const JFit& object, const std::string& prefix, const std::string& postfix) const
168  {
169  using namespace std;
170  using namespace JPP;
171 
172  if (debug >= debug_t) {
173  out << prefix << (prefix == "" ? "" : " ")
174  << FILL(4,'0') << object.id << FILL() << ' '
175  << FIXED(9,6) << object.tx << ' '
176  << FIXED(9,6) << object.ty << ' '
177  << (postfix == "" ? "" : " ") << postfix << endl;
178  }
179 
180  return out;
181  }
182  };
183 }
184 
185 /**
186  * \file
187  *
188  * Program to compare acoustics fit data.
189  * \author mdejong
190  */
191 int main(int argc, char **argv)
192 {
193  using namespace std;
194  using namespace JPP;
195 
196  vector<string> inputFile;
197  JLimit numberOfEvents;
198  int debug;
199 
200  try {
201 
202  JParser<> zap("Program to compare acoustics fit data.");
203 
204  zap['f'] = make_field(inputFile, "two outputs of JKatoomba[.sh]");
205  zap['n'] = make_field(numberOfEvents) = JLimit::max();
206  zap['d'] = make_field(debug) = 2;
207 
208  zap(argc, argv);
209  }
210  catch(const exception &error) {
211  FATAL(error.what() << endl);
212  }
213 
214  if (inputFile.size() != 2u) {
215  FATAL("Wrong number of input files " << inputFile.size() << endl);
216  }
217 
218  const size_t width = max(inputFile[0].size(), inputFile[1].size());
219  const printer print = { debug, width };
220 
221  vector<JEvt> buffer[2];
222 
223  for (int i = 0; i != 2; ++i) {
224 
225  for (JSingleFileScanner<JEvt> in(inputFile[i], numberOfEvents); in.hasNext(); ) {
226  buffer[i].push_back(*in.next());
227  }
228 
229  sort(buffer[i].begin(), buffer[i].end());
230  }
231 
232  if (true) {
233  for (int i = 0; i != 2; ++i) {
234  for (vector<JEvt>::iterator p = buffer[i].begin(); p != buffer[i].end(); ++p) {
235  sort(p->begin(), p->end(), make_comparator(&JFit::id, JComparison::lt()));
236  }
237  }
238  }
239 
240  int count[] = { 0, 0 };
241 
243  p0 = buffer[0].begin(),
244  p1 = buffer[1].begin(); p0 != buffer[0].end() && p1 != buffer[1].end(); ) {
245 
246  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && compare(*p0,*p1); ++p0, ++count[1]) {
247  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
248  }
249 
250  for ( ; p0 != buffer[0].end() && p1 != buffer[1].end() && compare(*p1,*p0); ++p1, ++count[1]) {
251  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
252  }
253 
254  if (p0 != buffer[0].end() && p1 != buffer[1].end()) {
255 
256  if (!compare(*p0,*p1) && !compare(*p1,*p0)) {
257 
258  ++count[0];
259 
260  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "\\");
261  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "/ ");
262 
263  } else {
264 
265  ++count[1];
266 
267  if (p0->detid == p1->detid &&
268  p0->UNIXTimeStart == p1->UNIXTimeStart &&
269  p0->UNIXTimeStop == p1->UNIXTimeStop) {
270 
271  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, "", "");
272  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "", "");
273 
274  JEvt::const_iterator i0 = p0->begin();
275  JEvt::const_iterator i1 = p1->begin();
276 
277  for ( ; i0 != p0->end() && i1 != p1->end(); ++i0, ++i1) {
278  if (compare(*i0, *i1) || compare(*i1,*i0)) {
279  print(cout, *i0, ">>", "");
280  print(cout, *i1, "<<", "");
281  }
282  }
283 
284  for ( ; i0 != p0->end(); ++i0) {
285  print(cout, *i0, ">>", "");
286  }
287 
288  for ( ; i1 != p1->end(); ++i1) {
289  print(cout, *i1, "<<", "");
290  }
291 
292  } else {
293 
294  print(cout, inputFile[0], distance(buffer[0].cbegin(),p0), *p0, ">>", "");
295  print(cout, inputFile[1], distance(buffer[1].cbegin(),p1), *p1, "<<", "");
296  }
297  }
298 
299  if (compare(*p0,*p1) || compare(*p1,*p0)) {
300 
301  } else {
302 
303  ++p0;
304  ++p1;
305  }
306  }
307  }
308 
309  STATUS("Number of differences / events: " << count[1] << " / " << count[0] << endl);
310 
311  if (buffer[0].size() != buffer[1].size()) {
312  FATAL("Different size " << buffer[0].size() << ' ' << buffer[1].size() << endl);
313  }
314 
315  if (count[1] != 0) {
316  FATAL("Number of differences " << count[1] << endl);
317  }
318 }
Acoustic event fit.
ROOT TTree parameter settings.
int main(int argc, char **argv)
TPaveText * p1
General purpose messaging.
#define STATUS(A)
Definition: JMessage.hh:63
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Scanning of objects from a single file according a format that follows from the extension of each fil...
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Utility class to parse command line options.
Definition: JParser.hh:1698
Object reading from a list of files.
virtual bool hasNext() override
Check availability of next element.
std::ostream & print(std::ostream &out, const JTestSummary &summary, const char delimiter=' ', const bool useColors=true)
Print test summary.
@ debug_t
debug
Definition: JMessage.hh:29
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:330
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Acoustic event fit.
Acoustic single fit.
double tx
slope dx/dz
int id
string identifier
double ty
slope dy/dz
int nhit
number of hits
double UNIXTimeStop
stop time
int detid
detector identifier
int npar
number of fit parameters
double UNIXTimeStart
start time
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45