Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
examples/JAcoustics/JToA.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <vector>
4 #include <map>
5 #include <algorithm>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 
10 #include "JLang/JPredicate.hh"
12 
13 #include "JAcoustics/JToA.hh"
14 #include "JAcoustics/JSupport.hh"
16 
17 #include "Jeep/JPrint.hh"
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 
22 namespace {
23 
24  using namespace JPP;
25 
26  /**
27  * Auxiliary class to extend JACOUSTICS::JToA.
28  */
29  struct JToA_t :
30  public JToA
31  {
32  /**
33  * Constructor.
34  *
35  * \param data data
36  * \param counter counter
37  */
38  JToA_t( const JToA& data, const int counter) :
39  JToA(data),
40  counter(counter)
41  {}
42 
43 
44  /**
45  * Write data to output stream.
46  *
47  * \param out output stream
48  * \param object object
49  * \return output stream
50  */
51  friend inline std::ostream& operator<<(std::ostream& out, const JToA_t& object)
52  {
53  using namespace std;
54  using namespace JPP;
55 
56  out << setw(6) << object.RUN << ' '
57  << setw(8) << object.counter << ' '
58  << FIXED(20,5) << (static_cast<double>(object.SECONDS) + static_cast<double>(object.TICKS)*16E-9) << ' '
59  << setw(10) << object.DOMID << ' '
60  << FIXED(9,6) << object.TOA_NS << ' '
61  << FIXED(5,0) << object.QUALITYFACTOR;
62 
63  return out;
64  }
65 
66  int counter;
67 
68 
69  /**
70  * Compare times of arrival.
71  *
72  * \param first first time-of-arrival
73  * \param second second time-of-arrival
74  * \return true if first time-of-arrival less than second; else false
75  */
76  friend inline bool operator<(const JToA_t& first, const JToA_t& second)
77  {
78  return (first.TOA_NS < second.TOA_NS);
79  }
80  };
81 }
82 
83 
84 /**
85  * \file
86  *
87  * Example program to test acoustic data.
88  * \author mdejong
89  */
90 int main(int argc, char **argv)
91 {
92  using namespace std;
93  using namespace JPP;
94 
96  JLimit_t& numberOfEvents = inputFile.getLimit();
97  double precision;
98  bool allowed;
99  int debug;
100 
101  try {
102 
103  JParser<> zap("Example program to test acoustic data.");
104 
105  zap['f'] = make_field(inputFile);
106  zap['n'] = make_field(numberOfEvents) = JLimit::max();
107  zap['A'] = make_field(allowed);
108  zap['e'] = make_field(precision) = 1.0e-7;
109  zap['d'] = make_field(debug) = 2;
110 
111  zap(argc, argv);
112  }
113  catch(const exception &error) {
114  FATAL(error.what() << endl);
115  }
116 
117 
118  typedef vector<JToA_t> buffer_type; // acoustic data type
119 
120  map<int, map< int, buffer_type > > data; // emitter -> receiver -> data
121 
122  for (int counter = 0; inputFile.hasNext(); ++counter) {
123 
124  STATUS("counter: " << setw(8) << counter << '\r' << flush); DEBUG(endl);
125 
126  const JToA* parameters = inputFile.next();
127 
128  data[parameters->WAVEFORMID][parameters->DOMID].push_back(JToA_t(*parameters, counter));
129  }
130  STATUS(endl);
131 
132  constexpr double s2ns = 1E9;
133 
134  for (map<int, map< int, buffer_type> >::iterator i = data.begin(); i != data.end(); ++i) {
135 
136  for (map< int, buffer_type>::iterator module = i->second.begin(); module != i->second.end(); ++module) {
137 
138  buffer_type& buffer = module->second;
139 
140  sort(buffer.begin(), buffer.end());
141 
142  for (buffer_type::const_iterator p = buffer.begin(); p != buffer.end(); ++p) {
143  for (buffer_type::const_iterator q = buffer.begin(); q != p; ++q) {
144 
145  if (p->DOMID == q->DOMID &&
146  p->QUALITYFACTOR - q->QUALITYFACTOR <= lrint(s2ns*precision) &&
147  llabs(p->TOA_NS - q->TOA_NS) <= llrint(s2ns*precision)) {
148 
149  if (!allowed || (p->TOA_NS < llrint(s2ns*TOAMAX_S) &&
150  q->TOA_NS < llrint(s2ns*TOAMAX_S))) {
151 
152  cout << *p << endl;
153  cout << *q << endl;
154 
155  cout << "Difference between absolute times "
156  << SCIENTIFIC(12,3) << (p->TOA_NS-q->TOA_NS) << " nanoseconds\n";
157  }
158  }
159  }
160  }
161  }
162  }
163 }
Utility class to parse command line options.
Definition: JParser.hh:1711
int main(int argc, char *argv[])
Definition: Main.cc:15
then usage $script< input file >[option[primary[working directory]]] nWhere option can be E
Definition: JMuonPostfit.sh:40
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition: JHead.hh:1817
#define STATUS(A)
Definition: JMessage.hh:63
ROOT TTree parameter settings.
int32_t WAVEFORMID
DOM unique identifeir.
Definition: JToA.hh:33
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
static counter_type max()
Get maximum counter value.
Definition: JLimit.hh:128
Time-of-arrival data from acoustic piezo sensor or hydrophone.
Definition: JToA.hh:25
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
std::vector< JHitW0 > buffer_type
hits
Definition: JPerth.cc:70
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
static const double TOAMAX_S
Maximal allowed time-of-arrival [s].
I/O formatting auxiliaries.
Acoustics support kit.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
Acoustic event.
uint32_t DOMID
DAQ run number.
Definition: JToA.hh:32
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:486
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62