Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JHydrophone.cc File Reference

Example program to plot hydrophone data. More...

#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "JDB/JToAshort.hh"
#include "JDB/JSupport.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JTripod.hh"
#include "JDetector/JHydrophone.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JTreeScanner.hh"
#include "JTools/JHashMap.hh"
#include "JROOT/JManager.hh"
#include "JAcoustics/JEmitterID.hh"
#include "JAcoustics/JSoundVelocity.hh"
#include "JAcoustics/JEmitter.hh"
#include "JAcoustics/JReceiver.hh"
#include "JAcoustics/JTransceiver.hh"
#include "JAcoustics/JAcousticsToolkit.hh"
#include "JAcoustics/JAcousticsSupportkit.hh"
#include "JAcoustics/JHit.hh"
#include "JAcoustics/JEvent.hh"
#include "JAcoustics/JSupport.hh"
#include "Jeep/JContainer.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to plot hydrophone data.

Author
mdejong

Definition in file JHydrophone.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 115 of file JHydrophone.cc.

116 {
117  using namespace std;
118  using namespace JPP;
119 
120  typedef JContainer< vector<JTripod> > tripods_container;
121  typedef JContainer< vector<JHydrophone> > hydrophones_container;
122 
124  JMultipleFileScanner<JToAshort> toashortFile;
125  string detectorFile;
126  JLimit_t& numberOfEvents = inputFile.getLimit();
127  string outputFile;
128  JSoundVelocity V = getSoundVelocity; // default sound velocity
129  tripods_container tripods; // tripods
130  hydrophones_container hydrophones; // hydrophones
131  int debug;
132 
133  try {
134 
135  JParser<> zap("Example program to plot hydrophone data.");
136 
137  zap['f'] = make_field(inputFile);
138  zap['n'] = make_field(numberOfEvents) = JLimit::max();
139  zap['i'] = make_field(toashortFile);
140  zap['o'] = make_field(outputFile) = "hydrophone.root";
141  zap['a'] = make_field(detectorFile);
142  zap['V'] = make_field(V, "sound velocity") = JPARSER::initialised();
143  zap['T'] = make_field(tripods, "tripod data");
144  zap['H'] = make_field(hydrophones, "hydrophone data") = JPARSER::initialised();
145  zap['d'] = make_field(debug) = 2;
146 
147  zap(argc, argv);
148  }
149  catch(const exception &error) {
150  FATAL(error.what() << endl);
151  }
152 
153 
155 
156  try {
157  load(detectorFile, detector);
158  }
159  catch(const JException& error) {
160  FATAL(error);
161  }
162 
164 
165  V.set(detector.getUTMZ());
166 
167  JHashMap<int, JReceiver> receivers;
168  JHashMap<int, JEmitter> emitters;
169 
170  for (hydrophones_container::const_iterator i = hydrophones.begin(); i != hydrophones.end(); ++i) {
171 
172  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
173 
174  if (i->getLocation() == module->getLocation()) {
175 
176  receivers[module->getID()] = JReceiver(module->getID(),
177  module->getPosition() + i->getPosition(),
178  module->getT0() * 1.0e-9);
179  break;
180  }
181  }
182  }
183 
184  for (tripods_container::const_iterator i = tripods.begin(); i != tripods.end(); ++i) {
185  emitters[i->getID()] = JEmitter(i->getID(),
186  i->getUTMPosition() - detector.getUTMPosition());
187  }
188 
189 
190  map<int, vector<double> > buffer; // emitter identifier -> times-of-emission
191 
192  while (inputFile.hasNext()) {
193 
194  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
195 
196  const JEvent* evt = inputFile.next();
197 
198  if (!evt->empty()) {
199  buffer[evt->getID()].push_back((*evt)[0].getToE());
200  }
201  }
202  STATUS(endl);
203 
204 
205  JManager<key_type, TH1D> H1(new TH1D("[%]", NULL, 2000, -2.0e-3, +2.0e-3));
206 
207  for (int counter = 0; toashortFile.hasNext(); ++counter) {
208 
209  if (counter%1000 == 0) {
210  STATUS("counter: " << setw(8) << counter << '\r' << flush); DEBUG(endl);
211  }
212 
213  const JToAshort* parameters = toashortFile.next();
214 
215  const int id = getEmitterID(parameters->EMITTERID);
216 
217  if (emitters.has(id) && receivers.has(parameters->DOMID) && !buffer[id].empty()) {
218 
219  const JTransceiver transceiver(emitters[id], receivers[parameters->DOMID]);
220 
221  const JTransmission transmission = transceiver.getTransmission(*parameters, V);
222 
223  double t1 = numeric_limits<double>::max();
224  double w1 = 1.0 / (double) buffer[id].size();
225 
226  for (vector<double>::const_iterator i = buffer[id].begin(); i != buffer[id].end(); ++i) {
227 
228  const double ti = transmission.getToE() - *i;
229 
230  if (fabs(ti) < fabs(t1)) {
231  t1 = ti;
232  }
233  }
234 
235  H1[key_type(parameters->DOMID, id)]->Fill(t1, w1);
236 
237  H1->Fill(t1);
238  }
239  }
240  STATUS(endl);
241 
242 
243  H1.Write(outputFile.c_str(), true);
244 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
Acoustic receiver.
Definition: JReceiver.hh:27
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:71
static JEmitterID & getEmitterID
Function object for emitter identification.
Definition: JEmitterID.hh:90
do rm f tmp H1
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:80
*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
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
string outputFile
double getToE() const
Get estimated time of emission.
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.
Acoustic transmission.
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Detector file.
Definition: JHead.hh:196
Acoustic emitter.
Definition: JEmitter.hh:27
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:1961
Acoustic transceiver.
Definition: JTransceiver.hh:29
int debug
debug level
Definition: JSirene.cc:63
Implementation for velocity of sound.
#define FATAL(A)
Definition: JMessage.hh:67
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
Acoustic event.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
int getID() const
Get identifier.
int EMITTERID
waveform identifier
Definition: JToAshort.hh:27
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62