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