Jpp master_rocky-44-g75b7c4f75
the software that should make you happy
Loading...
Searching...
No Matches
JAcousticsTriggerProcessor.cc File Reference

Main program to trigger acoustic data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JHydrophone.hh"
#include "JLang/JPredicate.hh"
#include "JLang/JComparator.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/JToA.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/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...
 
struct  JACOUSTICS::JEventOverlap
 Match of two events considering overlap in time. More...
 

Namespaces

namespace  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

◆ main()

int main ( int argc,
char ** argv )

Definition at line 182 of file JAcousticsTriggerProcessor.cc.

183{
184 using namespace std;
185 using namespace JPP;
186
188
190
192 JLimit_t& numberOfEvents = inputFile.getLimit();
193 JTriggerParameters parameters;
194 int factoryLimit = 10000;
195 double TMaxExtra_s = 100.0e-6;
197 JSoundVelocity V = getSoundVelocity; // default sound velocity
198 string detectorFile;
199 hydrophones_container hydrophones; // hydrophones
200 double precision;
201 int debug;
202
203 try {
204
205 JProperties properties;
206
207 properties.insert(gmake_property(parameters.Q));
208 properties.insert(gmake_property(parameters.TMax_s));
209 properties.insert(gmake_property(parameters.numberOfHits));
210 properties.insert(gmake_property(factoryLimit));
211 properties.insert(gmake_property(TMaxExtra_s));
212
213 JParser<> zap("Main program to trigger acoustic data.");
214
215 zap['f'] = make_field(inputFile, "output of JConvertDB -q toashort");
216 zap['n'] = make_field(numberOfEvents) = JLimit::max();
217 zap['@'] = make_field(properties, "trigger parameters");
218 zap['o'] = make_field(outputFile, "output file") = "event.root";
219 zap['V'] = make_field(V, "sound velocity") = JPARSER::initialised();
220 zap['a'] = make_field(detectorFile, "detector file");
221 zap['H'] = make_field(hydrophones, "hydrophone data") = JPARSER::initialised();
222 zap['p'] = make_field(precision, "precision time-of-arrival") = 1.0e-6;
223 zap['W'] = make_field(getEmitterID, "waveform identification data") = JPARSER::initialised();
224 zap['d'] = make_field(debug) = 1;
225
226 zap(argc, argv);
227 }
228 catch(const exception &error) {
229 FATAL(error.what() << endl);
230 }
231
232
234
235 try {
236 load(detectorFile, detector);
237 }
238 catch(const JException& error) {
239 FATAL(error);
240 }
241
242 V.set(detector.getUTMZ());
243
244
245
246 const JMatch3D match(V, TMaxExtra_s);
247 const JEventOverlap overlap(parameters.TMax_s);
248
249
250 JHashMap<int, JReceiver> receivers;
251
252 for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
253
254 JPosition3D pos(0.0, 0.0, 0.0);
255
256 if (i->getFloor() == 0) { // get relative position of hydrophone
257
258 try {
259 pos = getPosition(hydrophones.begin(),
260 hydrophones.end(),
261 make_predicate(&JHydrophone::getString, i->getString()));
262 }
263 catch(const exception&) {
264 continue; // if no position available, discard hydrophone
265 }
266 }
267
268 receivers[i->getID()] = JReceiver(i->getID(),
269 i->getPosition() + pos,
270 i->getT0() * 1.0e-9);
271 }
272
273 outputFile.open();
274
275 if (!outputFile.is_open()) {
276 FATAL("Error opening file " << outputFile << endl);
277 }
278
279 outputFile.put(JMeta(argc, argv));
280 outputFile.put(parameters);
281
282
283 // input data
284
285 typedef vector<hit_type> buffer_type; // data type
286
287 map<int, map< int, buffer_type > > f1; // emitter -> receiver -> data
288
289 while (inputFile.hasNext()) {
290
291 if (inputFile.getCounter()%100000 == 0) {
292 STATUS("counter: " << setw(8) << inputFile.getCounter() << '\r' << flush); DEBUG(endl);
293 }
294
295 JToA* parameters = inputFile.next();
296
297 if (detector.getID() != parameters->DETID) { // consistency check
298 FATAL("Invalid detector identifier " << parameters->DETID << " != " << detector.getID() << endl);
299 }
300
301 if (receivers.has(parameters->DOMID)) {
302
303 const JReceiver& receiver = receivers[parameters->DOMID];
304
305 double toa = parameters->TOA_S();
306
307 const JTransmission transmission(parameters->RUN,
308 parameters->DOMID,
309 parameters->QUALITYFACTOR,
310 parameters->QUALITYNORMALISATION,
311 receiver.getT(toa),
312 receiver.getT(toa));
313 try {
314 f1[getEmitterID(parameters->WAVEFORMID)][receiver.getID()].push_back(hit_type(receiver.getPosition(), transmission));
315 }
316 catch(const exception&) {}
317 }
318 }
319 STATUS(endl);
320
321 for (map<int, map< int, buffer_type> >::iterator i = f1.begin(); i != f1.end(); ++i) {
322
324
325 for (map< int, buffer_type>::iterator receiver = i->second.begin(); receiver != i->second.end(); ++receiver) {
326
327 // filter similar hits
328
329 sort(receiver->second.begin(), receiver->second.end(), JTransmission::compare(precision));
330
331 buffer_type::iterator __end = unique(receiver->second.begin(), receiver->second.end(), JTransmission::equals(precision));
332
333 // selection based on quality
334
335 for (buffer_type::const_iterator p = receiver->second.begin(); p != __end; ++p) {
336 if (p->getQ() >= parameters.Q * (parameters.Q <= 1.0 ? p->getW() : 1.0)) {
337 data.push_back(*p);
338 }
339 }
340 }
341
342 sort(data.begin(), data.end(), make_comparator(&hit_type::getToA, JComparison::lt())); // sort according time-of-arrival
343
344 buffer_type buffer(factoryLimit); // local buffer of hits
345 JEvent out[2]; // FIFO of events
346
347 for (buffer_type::const_iterator p = data.begin(); p != data.end(); ++p) {
348
349 if (distance(data.cbegin(),p)%1000 == 0) {
350 STATUS("processed[" << i->first << "]: " << FIXED(5,1) << (double) (100 * distance(data.cbegin(),p)) / (double) data.size() << "%" << '\r' << flush); DEBUG(endl);
351 }
352
353 buffer_type::const_iterator q = p;
354
355 while (++q != data.end() && q->getToA() - p->getToA() <= parameters.TMax_s) {}
356
357 if (distance(p,q) >= parameters.numberOfHits) {
358
359 if (distance(p,q) < factoryLimit) {
360
361 buffer_type::iterator root = buffer.begin();
362 buffer_type::iterator __p = buffer.begin();
363 buffer_type::iterator __q = buffer.begin();
364
365 *root = *p;
366
367 ++__p;
368 ++__q;
369
370 for (buffer_type::const_iterator i = p; ++i != q; ) {
371 if (match(*p,*i)) {
372 *__q = *i;
373 ++__q;
374 }
375 }
376
377 if (distance(root,__q) >= parameters.numberOfHits) {
378
379 __q = clusterize(__p, __q, match, parameters.numberOfHits - 1);
380
381 if (distance(root,__q) >= parameters.numberOfHits) {
382 out[1] = JEvent(detector.getID(), out[0].getCounter() + 1, i->first, root, __q);
383 }
384 }
385
386 } else {
387
388 out[1] = JEvent(detector.getID(), out[0].getCounter() + 1, i->first, p, q);
389 }
390
391 if (out[0].empty()) {
392
393 out[0] = out[1]; // shift
394
395 } else if (overlap(out[0],out[1])) {
396
397 out[0].merge(out[1]); // merge
398
399 } else {
400
401 outputFile.put(out[0]); // write
402
403 out[0] = out[1]; // shift
404 }
405
406 out[1].clear();
407 }
408 }
409
410 if (!out[0].empty()) {
411
412 outputFile.put(out[0]); // write
413 }
414 STATUS(endl);
415 STATUS("triggers[" << i->first << "]: " << setw(7) << out[0].getCounter() << endl);
416 }
417
418 JMultipleFileScanner<JMeta> io(inputFile);
419
420 io >> outputFile;
421
422 outputFile.close();
423}
string outputFile
#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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
3D match criterion for acoustic signals.
Definition JBillabong.cc:96
Detector data structure.
Definition JDetector.hh:96
int getString() const
Get string number.
Definition JLocation.hh:135
Utility class to parse parameter values.
Data structure for position in three dimensions.
const JPosition3D & getPosition() const
Get position.
General exception.
Definition JException.hh:24
int getID() const
Get identifier.
Definition JObjectID.hh:50
Utility class to parse command line options.
Definition JParser.hh:1698
Object writing to file.
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.
const JPolynome f1(1.0, 2.0, 3.0)
Function.
JPosition3D getPosition(const Vec &pos)
Get position.
static JEmitterID getEmitterID
Function object for emitter identification.
JContainer< std::vector< JHydrophone > > hydrophones_container
Definition JSydney.cc:79
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).
std::vector< JHitW0 > buffer_type
hits
Definition JPerth.cc:71
JFIT::JEvent JEvent
Definition JHistory.hh:353
bool overlap(const JRange< T, JComparator_t > &first, const JRange< T, JComparator_t > &second)
Test overlap between ranges.
Definition JRange.hh:641
static const struct JTRIGGER::clusterize clusterize
Definition root.py:1
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
Match of two events considering overlap in time.
void merge(const JEvent &event)
Merge event.
Acoustic receiver.
Definition JReceiver.hh:30
double getT(const double t_s) const
Get corrected time.
Definition JReceiver.hh:72
Implementation for depth dependend velocity of sound.
JSoundVelocity & set(const double z0)
Set depth.
Time-of-arrival data from acoustic piezo sensor or hydrophone.
Definition JToA.hh:26
uint32_t DOMID
DAQ run number.
Definition JToA.hh:32
uint32_t QUALITYFACTOR
The ticks (16ns) part of the DAQ frame timestamp.
Definition JToA.hh:37
uint32_t QUALITYNORMALISATION
A measure of how good the waveform match was to the signal.
Definition JToA.hh:38
int32_t WAVEFORMID
DOM unique identifeir.
Definition JToA.hh:33
int32_t DETID
Definition JToA.hh:30
int32_t RUN
detector identifier
Definition JToA.hh:31
double TOA_S() const
Time of Arrival, expressed in seconds relative to Unix epoch (1 January 1970 00:00:00 UTC)
Definition JToAImp.cc:40
Auxiliary class to compare transmissions.
Auxiliary class to compare transmissions.
Acoustic transmission.
double Q
minimal quality if larger than one; else minimal normalised quality
double TMax_s
maximal difference between times of emission [s]
int numberOfHits
minimal number of hits to trigger event
Acoustic hit.
Definition JBillabong.cc:70
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition JContainer.hh:42
Type list.
Definition JTypeList.hh:23
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
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72
General purpose class for hash map of unique keys.
Definition JHashMap.hh:75