Jpp  master_rocky-43-ge265d140c
the software that should make you happy
JHydrophone.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 
4 #include "TROOT.h"
5 #include "TFile.h"
6 #include "TH1D.h"
7 
8 #include "JDetector/JDetector.hh"
10 #include "JDetector/JTripod.hh"
12 #include "JDetector/JHydrophone.hh"
13 
15 #include "JSupport/JTreeScanner.hh"
16 
17 #include "JTools/JHashMap.hh"
18 #include "JTools/JRange.hh"
19 #include "JLang/JComparator.hh"
20 #include "JLang/JComparison.hh"
21 
22 #include "JROOT/JManager.hh"
23 #include "JROOT/JRootToolkit.hh"
24 
25 #include "JAcoustics/JToA.hh"
26 #include "JAcoustics/JEmitterID.hh"
28 #include "JAcoustics/JEmitter.hh"
29 #include "JAcoustics/JReceiver.hh"
33 #include "JAcoustics/JHit.hh"
34 #include "JAcoustics/JEvent.hh"
35 #include "JAcoustics/JSupport.hh"
36 
37 #include "Jeep/JContainer.hh"
38 #include "Jeep/JPrint.hh"
39 #include "Jeep/JParser.hh"
40 #include "Jeep/JMessage.hh"
41 
42 namespace {
43 
44  /**
45  * Auxiliary data structure for organistation of histograms.
46  */
47  struct key_type :
48  public std::pair<int, int>
49  {
50  /**
51  * Constructor.
52  *
53  * \param first first value
54  * \param second second value
55  */
56  key_type(const int first,
57  const int second) :
58  std::pair<int, int>(first, second)
59  {}
60 
61 
62  /**
63  * Read key from input.
64  *
65  * \param in input stream
66  * \param key key
67  * \return input stream
68  */
69  friend inline std::istream& operator>>(std::istream& in, key_type& key)
70  {
71  in >> key.first;
72  in >> key.second;
73 
74  return in;
75  }
76 
77 
78  /**
79  * Write key to output.
80  *
81  * \param out output stream
82  * \param key key
83  * \return output stream
84  */
85  friend inline std::ostream& operator<<(std::ostream& out, const key_type& key)
86  {
87  out << key.first;
88  out << '.';
89  out << key.second;
90 
91  return out;
92  }
93 
94  /**
95  * Less=than operator.
96  *
97  * \param first first key
98  * \param second second key
99  * \return true if first key less than second key; else false
100  */
101  friend inline bool operator<(const key_type& first, const key_type& second)
102  {
103  if (first.first == second.first)
104  return first.second < second.second;
105  else
106  return first.first < second.first;
107  }
108  };
109 }
110 
111 
112 /**
113  * \file
114  *
115  * Example program to plot hydrophone data.
116  * \author mdejong
117  */
118 int main(int argc, char **argv)
119 {
120  using namespace std;
121  using namespace JPP;
122 
126 
128  string detectorFile;
129  JLimit_t& numberOfEvents = inputFile.getLimit();
130  string outputFile;
131  JSoundVelocity V = getSoundVelocity; // default sound velocity
132  tripods_container tripods; // tripods
133  transmitters_container transmitters; // transmitters
134  hydrophones_container hydrophones; // hydrophones
135  double Q;
136  int debug;
137 
138  try {
139 
140  JParser<> zap("Example program to plot hydrophone data.");
141 
142  zap['f'] = make_field(inputFile);
143  zap['n'] = make_field(numberOfEvents) = JLimit::max();
144  zap['o'] = make_field(outputFile) = "hydrophone.root";
145  zap['a'] = make_field(detectorFile);
146  zap['V'] = make_field(V, "sound velocity") = JPARSER::initialised();
147  zap['T'] = make_field(tripods, "tripod data");
148  zap['Y'] = make_field(transmitters, "transmitter data") = JPARSER::initialised();
149  zap['H'] = make_field(hydrophones, "hydrophone data") = JPARSER::initialised();
150  zap['W'] = make_field(getEmitterID, "waveform identification data") = JPARSER::initialised();
151  zap['Q'] = make_field(Q, "quality") = 0.0;
152  zap['d'] = make_field(debug) = 2;
153 
154  zap(argc, argv);
155  }
156  catch(const exception &error) {
157  FATAL(error.what() << endl);
158  }
159 
160 
162 
163  try {
164  load(detectorFile, detector);
165  }
166  catch(const JException& error) {
167  FATAL(error);
168  }
169 
170  V.set(detector.getUTMZ());
171 
172  JHashMap<int, JReceiver> receivers;
173  JHashMap<int, JEmitter> emitters;
174 
175  for (hydrophones_container::const_iterator i = hydrophones.begin(); i != hydrophones.end(); ++i) {
176 
177  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
178 
179  if (i->getLocation() == module->getLocation()) {
180 
181  receivers[module->getID()] = JReceiver(module->getID(),
182  module->getPosition() + i->getPosition(),
183  module->getT0() * 1.0e-9);
184  break;
185  }
186  }
187  }
188 
189  for (tripods_container::const_iterator i = tripods.begin(); i != tripods.end(); ++i) {
190  emitters[i->getID()] = JEmitter(i->getID(),
191  i->getUTMPosition() - detector.getUTMPosition());
192  }
193 
194  for (transmitters_container::const_iterator i = transmitters.begin(); i != transmitters.end(); ++i) {
195  try {
196  emitters[i->getID()] = JEmitter(i->getID(),
197  i->getPosition() + detector.getModule(i->getLocation()).getPosition());
198  }
199  catch(const exception&) {
200  continue; // if no string available, discard transmitter
201  }
202  }
203 
204 
205  const JRange<double> T0(-0.05, +0.05);
206  const JRange<double> T1(-0.01, +0.01);
207 
208  TH1D h0(MAKE_CSTRING("Q0 " << T0), NULL, 100, 0.0, 8.0);
209  TH1D h1(MAKE_CSTRING("Q1 " << T1), NULL, 100, 0.0, 8.0);
210 
211  JManager<key_type, TH1D> H1(new TH1D("[%]", NULL, 50000, -5.0e-2, +5.0e-2));
212 
213 
214  while (inputFile.hasNext()) {
215 
216  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
217 
218  const JEvent* evt = inputFile.next();
219 
220  if (!evt->empty() && emitters.has(evt->getID())) {
221 
223 
224  for (JEvent::const_iterator hit = evt->begin(); hit != evt->end(); ++hit) {
225  if (receivers.has(hit->getID())) {
226  buffer[hit->getID()].push_back(*hit);
227  }
228  }
229 
230  for (map<int, vector<JTransmission> >::iterator i = buffer.begin(); i != buffer.end(); ++i) {
231 
232  sort(i->second.begin(), i->second.end(), make_comparator(&JTransmission::getQ, JComparison::gt()));
233 
234  vector<JTransmission>::const_iterator hit = i->second.begin();
235 
236  if (hit->getQ() >= Q) {
237 
238  const JPosition3D& p1 = emitters [evt->getID()].getPosition();
239  const JPosition3D& p2 = receivers[hit->getID()].getPosition();
240 
241  const double D = p2.getDistance(p1);
242  const double Vi = V.getInverseVelocity(D, p1.getZ(), p2.getZ());
243 
244  const double t0 = evt->begin()->getToE() + D * Vi;
245  const double t1 = hit->getToA() - t0;
246 
247  H1[key_type(hit->getID(), evt->getID())]->Fill(t1);
248 
249  const double Q = log10(hit->getQ());
250 
251  if (T0(t1)) { h0.Fill(Q); }
252  if (T1(t1)) { h1.Fill(Q); }
253  }
254  }
255  }
256  }
257  STATUS(endl);
258 
259  TFile out(outputFile.c_str(), "recreate");
260 
261  out << h0 << h1 << H1;
262 
263  out.Write();
264  out.Close();
265 }
Acoustics support kit.
Acoustics toolkit.
Acoustic event.
Acoustic hit.
ROOT TTree parameter settings.
Container I/O.
string outputFile
Data structure for detector geometry and calibration.
TPaveText * p1
Emitter identification.
Acoustic emitter.
General purpose class for hash map of unique elements.
int main(int argc, char **argv)
Definition: JHydrophone.cc:118
Data structure for hydrophone.
Dynamic ROOT object management.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:72
Auxiliary class to define a range between two values.
Acoustic receiver.
Sound velocity.
Acoustic event.
Acoustic transceiver.
Data structure for transmitter.
Data structure for tripod.
Detector data structure.
Definition: JDetector.hh:96
Data structure for position in three dimensions.
Definition: JPosition3D.hh:38
double getDistance(const JVector3D &pos) const
Get distance to point.
Definition: JVector3D.hh:270
double getZ() const
Get z position.
Definition: JVector3D.hh:115
General exception.
Definition: JException.hh:24
Utility class to parse command line options.
Definition: JParser.hh:1698
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition: JManager.hh:47
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:304
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
counter_type getCounter() const
Get counter.
virtual const pointer_type & next() override
Get next element.
bool has(const T &value) const
Test whether given value is present.
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition: JHead.hh:1817
static JEmitterID getEmitterID
Function object for emitter identification.
Definition: JEmitterID.hh:119
JContainer< std::vector< JTripod > > tripods_container
Definition: JSydney.cc:78
JContainer< std::vector< JTransmitter > > transmitters_container
Definition: JSydney.cc:80
JContainer< std::vector< JHydrophone > > hydrophones_container
Definition: JSydney.cc:79
double getQ(const double D_m, const double f_kHz, const double d_m)
Get relative quality for given frequency at given distance.
static const JSoundVelocity getSoundVelocity(1541.0, -17.0e-3, -2000.0)
Function object for velocity of sound.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
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
std::istream & operator>>(std::istream &in, std::vector< int > &object)
Read std::vector<int> from input.
Detector file.
Definition: JHead.hh:227
Acoustic emitter.
Definition: JEmitter.hh:30
int getID() const
Get emitter identifier.
Acoustic receiver.
Definition: JReceiver.hh:30
Implementation for depth dependend velocity of sound.
JSoundVelocity & set(const double z0)
Set depth.
virtual double getInverseVelocity(const double D_m, const double z1, const double z2) const override
Get inverse velocity of sound.
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition: JContainer.hh:42
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:75