Jpp  18.6.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Namespaces | Functions
JAcousticsTriggerProcessor.cc File Reference

Main program to trigger acoustic data. More...

#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "JLang/JComparator.hh"
#include "JDB/JToAshort.hh"
#include "JDB/JSupport.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JHydrophone.hh"
#include "JLang/JPredicate.hh"
#include "JTools/JRange.hh"
#include "JTools/JQuantile.hh"
#include "JTools/JHashMap.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMeta.hh"
#include "JAcoustics/JEmitterID.hh"
#include "JAcoustics/JTransmission.hh"
#include "JAcoustics/JReceiver.hh"
#include "JAcoustics/JSoundVelocity.hh"
#include "JAcoustics/JAcousticsToolkit.hh"
#include "JAcoustics/JAcousticsSupportkit.hh"
#include "JAcoustics/JTriggerParameters.hh"
#include "JAcoustics/JEvent.hh"
#include "JAcoustics/JTriggerOutput.hh"
#include "JAcoustics/JSupport.hh"
#include "Jeep/JContainer.hh"
#include "Jeep/JProperties.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JTrigger/JMatch.hh"
#include "JTrigger/JAlgorithm.hh"

Go to the source code of this file.

Classes

struct  JACOUSTICS::hit_type
 Acoustic hit. More...
 
class  JACOUSTICS::JMatch3D
 3D match criterion for acoustic signals. More...
 
class  JACOUSTICS::JEventOverlap
 Match of two events considering overlap in time. More...
 

Namespaces

 JACOUSTICS
 Auxiliary classes and methods for acoustic position calibration.
 

Functions

int main (int argc, char **argv)
 

Detailed Description

Main program to trigger acoustic data.

An acoustic event is based on coincidences between times of arrival.
If the number of coincident times of arrival exceeds a preset minimum, the event is triggered and subsequently stored in the output file.

Author
mdejong

Definition in file JAcousticsTriggerProcessor.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 184 of file JAcousticsTriggerProcessor.cc.

185 {
186  using namespace std;
187  using namespace JPP;
188 
190 
192 
194  JLimit_t& numberOfEvents = inputFile.getLimit();
196  int factoryLimit = 10000;
197  double TMaxExtra_s = 100.0e-6;
199  JSoundVelocity V = getSoundVelocity; // default sound velocity
200  string detectorFile;
201  hydrophones_container hydrophones; // hydrophones
202  double precision;
203  int debug;
204 
205  try {
206 
207  JProperties properties;
208 
209  properties.insert(gmake_property(parameters.Q));
210  properties.insert(gmake_property(parameters.TMax_s));
211  properties.insert(gmake_property(parameters.numberOfHits));
212  properties.insert(gmake_property(factoryLimit));
213  properties.insert(gmake_property(TMaxExtra_s));
214 
215  JParser<> zap("Main program to trigger acoustic data.");
216 
217  zap['f'] = make_field(inputFile, "output of JConvertDB -q toashort");
218  zap['n'] = make_field(numberOfEvents) = JLimit::max();
219  zap['@'] = make_field(properties, "trigger parameters");
220  zap['o'] = make_field(outputFile, "output file") = "event.root";
221  zap['V'] = make_field(V, "sound velocity") = JPARSER::initialised();
222  zap['a'] = make_field(detectorFile, "detector file");
223  zap['H'] = make_field(hydrophones, "hydrophone data") = JPARSER::initialised();
224  zap['p'] = make_field(precision, "precision time-of-arrival") = 1.0e-6;
225  zap['W'] = make_field(getEmitterID, "waveform identification data") = JPARSER::initialised();
226  zap['d'] = make_field(debug) = 1;
227 
228  zap(argc, argv);
229  }
230  catch(const exception &error) {
231  FATAL(error.what() << endl);
232  }
233 
234 
236 
237  try {
238  load(detectorFile, detector);
239  }
240  catch(const JException& error) {
241  FATAL(error);
242  }
243 
244  V.set(detector.getUTMZ());
245 
246 
247 
248  const JMatch3D match(V, TMaxExtra_s);
249  const JEventOverlap overlap(parameters.TMax_s);
250 
251 
252  JHashMap<int, JReceiver> receivers;
253 
254  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
255 
256  JPosition3D pos(0.0, 0.0, 0.0);
257 
258  if (i->getFloor() == 0) { // get relative position of hydrophone
259 
260  try {
261  pos = getPosition(hydrophones.begin(),
262  hydrophones.end(),
263  make_predicate(&JHydrophone::getString, i->getString()));
264  }
265  catch(const exception&) {
266  continue; // if no position available, discard hydrophone
267  }
268  }
269 
270  receivers[i->getID()] = JReceiver(i->getID(),
271  i->getPosition() + pos,
272  i->getT0() * 1.0e-9);
273  }
274 
275  const JRange<double> unit(0.0, 1.0);
276 
277  outputFile.open();
278 
279  if (!outputFile.is_open()) {
280  FATAL("Error opening file " << outputFile << endl);
281  }
282 
283  outputFile.put(JMeta(argc, argv));
284  outputFile.put(parameters);
285 
286 
287  // input data
288 
289  string oid; // detector identifier
290 
291  typedef vector<hit_type> buffer_type; // data type
292 
293  map<int, map< int, buffer_type > > f1; // emitter -> receiver -> data
294 
295  while (inputFile.hasNext()) {
296 
297  if (inputFile.getCounter()%100000 == 0) {
298  STATUS("counter: " << setw(8) << inputFile.getCounter() << '\r' << flush); DEBUG(endl);
299  }
300 
301  JToAshort* parameters = inputFile.next();
302 
303  if (oid == "") {
304  oid = parameters->DETID;
305  }
306 
307  if (oid != parameters->DETID) { // consistency check
308  FATAL("Invalid detector identifier " << parameters->DETID << " != " << oid << endl);
309  }
310 
311  if (receivers.has(parameters->DOMID)) {
312 
313  const JReceiver& receiver = receivers[parameters->DOMID];
314 
315  const JTransmission transmission(parameters->RUNNUMBER,
316  parameters->DOMID,
317  parameters->QUALITYFACTOR,
318  parameters->QUALITYNORMALISATION,
319  parameters->UNIXTIMEBASE + receiver.getT(parameters->TOA_S),
320  parameters->UNIXTIMEBASE + receiver.getT(parameters->TOA_S));
321  try {
322  f1[getEmitterID(parameters->EMITTERID)][receiver.getID()].push_back(hit_type(receiver.getPosition(), transmission));
323  }
324  catch(const exception&) {}
325  }
326  }
327  STATUS(endl);
328 
329  for (map<int, map< int, buffer_type> >::iterator i = f1.begin(); i != f1.end(); ++i) {
330 
332 
333  for (map< int, buffer_type>::iterator receiver = i->second.begin(); receiver != i->second.end(); ++receiver) {
334 
335  // filter similar hits
336 
337  sort(receiver->second.begin(), receiver->second.end(), JTransmission::compare(precision));
338 
339  buffer_type::iterator __end = unique(receiver->second.begin(), receiver->second.end(), JTransmission::equals(precision));
340 
341  // selection based on quality
342 
343  for (buffer_type::const_iterator p = receiver->second.begin(); p != __end; ++p) {
344  if (p->getQ() >= parameters.Q * (unit(parameters.Q) ? p->getW() : 1.0)) {
345  data.push_back(*p);
346  }
347  }
348  }
349 
350  sort(data.begin(), data.end(), make_comparator(&hit_type::getToA, JComparison::lt())); // sort according time-of-arrival
351 
352  buffer_type buffer(factoryLimit); // local buffer of hits
353  JEvent out[2]; // FIFO of events
354  int number_of_events = 0;
355 
356  for (buffer_type::const_iterator p = data.begin(); p != data.end(); ++p) {
357 
358  if (distance(data.cbegin(),p)%1000 == 0) {
359  STATUS("processed[" << i->first << "]: " << FIXED(5,1) << (double) (100 * distance(data.cbegin(),p)) / (double) data.size() << "%" << '\r' << flush); DEBUG(endl);
360  }
361 
362  buffer_type::const_iterator q = p;
363 
364  while (++q != data.end() && q->getToA() - p->getToA() <= parameters.TMax_s) {}
365 
366  if (distance(p,q) >= parameters.numberOfHits) {
367 
368  if (distance(p,q) < factoryLimit) {
369 
370  buffer_type::iterator root = buffer.begin();
371  buffer_type::iterator __p = buffer.begin();
372  buffer_type::iterator __q = buffer.begin();
373 
374  *root = *p;
375 
376  ++__p;
377  ++__q;
378 
379  for (buffer_type::const_iterator i = p; ++i != q; ) {
380  if (match(*p,*i)) {
381  *__q = *i;
382  ++__q;
383  }
384  }
385 
386  if (distance(root,__q) >= parameters.numberOfHits) {
387 
388  __q = clusterize(__p, __q, match, parameters.numberOfHits - 1);
389 
390  if (distance(root,__q) >= parameters.numberOfHits) {
391  out[1] = JEvent(oid, number_of_events, i->first, root, __q);
392  }
393  }
394 
395  } else {
396 
397  out[1] = JEvent(oid, number_of_events, i->first, p, q);
398  }
399 
400  if (out[0].empty()) {
401 
402  out[0] = out[1]; // shift
403 
404  } else if (overlap(out[0],out[1])) {
405 
406  out[0].merge(out[1]); // merge
407 
408  } else {
409 
410  number_of_events += 1;
411 
412  outputFile.put(out[0]); // write
413 
414  out[0] = out[1]; // shift
415  }
416 
417  out[1].clear();
418  }
419  }
420 
421  if (!out[0].empty()) {
422 
423  number_of_events += 1;
424 
425  outputFile.put(out[0]); // write
426  }
427  STATUS(endl);
428  STATUS("triggers[" << i->first << "]: " << setw(7) << number_of_events << endl);
429  }
430 
431  JMultipleFileScanner<JMeta> io(inputFile);
432 
433  io >> outputFile;
434 
435  outputFile.close();
436 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Object writing to file.
double UNIXTIMEBASE
[s]
Definition: JToAshort.hh:25
Utility class to parse command line options.
Definition: JParser.hh:1711
General exception.
Definition: JException.hh:24
Acoustic receiver.
Definition: JReceiver.hh:27
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
void merge(const JEvent &event)
Merge event.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:72
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Match of two events considering overlap in time.
Utility class to parse parameter values.
Definition: JProperties.hh:497
std::string DETID
constraint
Definition: JToAshort.hh:22
*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:84
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
3D match criterion for acoustic signals.
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
string outputFile
do JPlot2D f $WORKDIR canberra[${EMITTER}\] root
JMODEL::JString getString(const JFit &fit)
Get model parameters of string.
std::vector< JHitW0 > buffer_type
hits
Definition: JPerth.cc:70
Type list.
Definition: JTypeList.hh:22
JFIT::JEvent JEvent
Definition: JHistory.hh:353
const JPolynome f1(1.0, 2.0, 3.0)
Function.
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.
Detector file.
Definition: JHead.hh:226
JContainer< std::vector< JHydrophone > > hydrophones_container
Definition: JSydney.cc:79
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:2158
int getID() const
Get identifier.
Definition: JObjectID.hh:50
JPosition3D getPosition(const Vec &pos)
Get position.
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
Implementation for depth dependend velocity of sound.
#define FATAL(A)
Definition: JMessage.hh:67
double getT(const double t_s) const
Get corrected time.
Definition: JReceiver.hh:72
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.
Auxiliary class to compare transmissions.
Acoustic event.
double TOA_S
[s]
Definition: JToAshort.hh:28
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
bool equals(const JFirst_t &first, const JSecond_t &second, const double precision=std::numeric_limits< double >::min())
Check equality.
Definition: JMathToolkit.hh:86
bool overlap(const JRange< T, JComparator_t > &first, const JRange< T, JComparator_t > &second)
Test overlap between ranges.
Definition: JRange.hh:641
static JEmitterID getEmitterID
Function object for emitter identification.
Definition: JEmitterID.hh:119
do set_variable DETECTOR_TXT $WORKDIR detector
int EMITTERID
waveform identifier
Definition: JToAshort.hh:27
static struct JTRIGGER::clusterize clusterize
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62