Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JAcousticsEventBuilder.cc File Reference

Main program to trigger events in acoustic data. More...

#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "km3net-dataformat/definitions/module_status.hh"
#include "JLang/JComparator.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleSupportkit.hh"
#include "JDetector/JTripod.hh"
#include "JDetector/JTransmitter.hh"
#include "JDetector/JHydrophone.hh"
#include "JLang/JPredicate.hh"
#include "JTools/JRange.hh"
#include "JTools/JStats.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/JTransceiver.hh"
#include "JAcoustics/JTransmission.hh"
#include "JAcoustics/JAcousticsToolkit.hh"
#include "JAcoustics/JAcousticsSupportkit.hh"
#include "JAcoustics/JTriggerParameters.hh"
#include "JAcoustics/JEvent.hh"
#include "JAcoustics/JEventOverlap.hh"
#include "JAcoustics/JTriggerOutput.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

Main program to trigger events in acoustic data.

An acoustic event is based on a coincidence of estimated times of emission from the same emitter.
If the number of coincident times of emission exceeds a preset minimum, the event is triggered and subsequently stored in the output file.
Note that an event counter is added which can be used to disambiguate the different cycles from the same emitter within one "super" event that is used for the global fit.
In this, a super event refers to the coincidence of events from a variety of emitters.

Author
mdejong

Definition in file JAcousticsEventBuilder.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 81 of file JAcousticsEventBuilder.cc.

82{
83 using namespace std;
84 using namespace JPP;
85
87
91
93 JLimit_t& numberOfEvents = inputFile.getLimit();
94 JTriggerParameters parameters;
96 JSoundVelocity V = getSoundVelocity; // default sound velocity
97 string detectorFile;
98 tripods_container tripods; // tripods
99 transmitters_container transmitters; // transmitters
100 hydrophones_container hydrophones; // hydrophones
101 double precision;
102 int debug;
103
104 try {
105
106 JParser<> zap("Main program to trigger events in acoustic data.");
107
108 zap['f'] = make_field(inputFile, "output of JToA");
109 zap['n'] = make_field(numberOfEvents) = JLimit::max();
110 zap['@'] = make_field(parameters, "trigger parameters");
111 zap['o'] = make_field(outputFile, "output file") = "event.root";
112 zap['V'] = make_field(V, "sound velocity") = JPARSER::initialised();
113 zap['a'] = make_field(detectorFile, "detector file");
114 zap['T'] = make_field(tripods, "tripod data");
115 zap['Y'] = make_field(transmitters, "transmitter data") = JPARSER::initialised();
116 zap['H'] = make_field(hydrophones, "hydrophone data") = JPARSER::initialised();
117 zap['W'] = make_field(getEmitterID, "waveform identification data") = JPARSER::initialised();
118 zap['p'] = make_field(precision, "precision time-of-arrival") = 1.0e-6;
119 zap['d'] = make_field(debug) = 1;
120
121 zap(argc, argv);
122 }
123 catch(const exception &error) {
124 FATAL(error.what() << endl);
125 }
126
127
129
130 try {
131 load(detectorFile, detector);
132 }
133 catch(const JException& error) {
134 FATAL(error);
135 }
136
137 V.set(detector.getUTMZ());
138
139 JHashMap<int, JReceiver> receivers;
141
142 for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
143
144 if ((i->getFloor() == 0 && !i->has(HYDROPHONE_DISABLE)) ||
145 (i->getFloor() != 0 && !i->has(PIEZO_DISABLE))) {
146
148
149 if (i->getFloor() == 0) { // get relative position of hydrophone
150
151 try {
152 pos = getPosition(hydrophones.begin(),
153 hydrophones.end(),
154 make_predicate(&JHydrophone::getString, i->getString()));
155 }
156 catch(const exception&) {
157 continue; // if no position available, discard hydrophone
158 }
159 }
160
161 receivers[i->getID()] = JReceiver(i->getID(),
162 i->getPosition() + pos,
163 i->getT0() * 1.0e-9);
164 }
165 }
166
167 for (tripods_container::const_iterator i = tripods.begin(); i != tripods.end(); ++i) {
168 emitters[i->getID()] = JEmitter(i->getID(),
169 i->getUTMPosition() - detector.getUTMPosition());
170 }
171
172 for (transmitters_container::const_iterator i = transmitters.begin(); i != transmitters.end(); ++i) {
173 try {
174 emitters[i->getID()] = JEmitter(i->getID(),
175 i->getPosition() + detector.getModule(i->getLocation()).getPosition());
176 }
177 catch(const exception&) {
178 continue; // if no string available, discard transmitter
179 }
180 }
181
182 outputFile.open();
183
184 if (!outputFile.is_open()) {
185 FATAL("Error opening file " << outputFile << endl);
186 }
187
188 outputFile.put(JMeta(argc, argv));
189 outputFile.put(parameters);
190
191
192 map_type number_of_entries;
193 map_type number_of_aliens;
194 map_type number_of_misses;
195 map_type number_of_triggers;
196 map_type number_of_events;
197
198 // input data
199
200 typedef vector<JTransmission> buffer_type; // data type
201
202 map<int, map< int, buffer_type > > f1; // emitter -> receiver -> data
203
204 while (inputFile.hasNext()) {
205
206 if (inputFile.getCounter()%10000 == 0) {
207 STATUS("counter: " << setw(8) << inputFile.getCounter() << '\r' << flush); DEBUG(endl);
208 }
209
210 JToA* parameters = inputFile.next();
211
212 if (detector.getID() != parameters->DETID) { // consistency check
213 FATAL("Invalid detector identifier " << parameters->DETID << " != " << detector.getID() << endl);
214 }
215
216 try {
217
218 const int id = getEmitterID(parameters->WAVEFORMID);
219
220 number_of_entries[parameters->WAVEFORMID].put(1);
221
222 if (emitters.has(id)) {
223
224 if (receivers.has(parameters->DOMID)) {
225
226 const JTransceiver transceiver(emitters[id], receivers[parameters->DOMID]);
227
228 f1[transceiver.emitter.getID()][transceiver.receiver.getID()].push_back(transceiver.getTransmission(*parameters, V));
229 }
230
231 } else {
232 number_of_misses[id].put(1);
233 }
234 }
235 catch(const exception&) {
236 number_of_aliens[parameters->WAVEFORMID].put(1);
237 }
238 }
239 STATUS(endl);
240
241 for (map_type::const_iterator i = number_of_entries.begin(); i != number_of_entries.end(); ++i) {
242 STATUS("number of entries: " << setw(3) << i->first << ' ' << setw(8) << i->second.getCount() << endl);
243 }
244
245 for (map_type::const_iterator i = number_of_aliens.begin(); i != number_of_aliens.end(); ++i) {
246 STATUS("number of aliens: " << setw(3) << i->first << ' ' << setw(8) << i->second.getCount() << endl);
247 }
248
249 for (map_type::const_iterator i = number_of_misses.begin(); i != number_of_misses.end(); ++i) {
250 STATUS("number of misses: " << setw(3) << i->first << ' ' << setw(8) << i->second.getCount() << endl);
251 }
252
253 const JEventOverlap match(parameters.TMax_s);
254
255 for (map<int, map< int, buffer_type> >::iterator i = f1.begin(); i != f1.end(); ++i) {
256
257 const double Q = parameters[i->first].Q;
258 const int numberOfHits = parameters[i->first].numberOfHits;
259 const double TMax_s = parameters[i->first].TMax_s;
260
261 buffer_type buffer;
262
263 for (map< int, buffer_type>::iterator receiver = i->second.begin(); receiver != i->second.end(); ++receiver) {
264
265 // filter similar hits
266
267 sort(receiver->second.begin(), receiver->second.end(), JTransmission::compare(precision));
268
269 buffer_type::iterator __end = unique(receiver->second.begin(), receiver->second.end(), JTransmission::equals(precision));
270
271 // selection based on quality
272
273 for (buffer_type::const_iterator p = receiver->second.begin(); p != __end; ++p) {
274 if (p->getQ() >= Q * (Q <= 1.0 ? p->getW() : 1.0)) {
275 buffer.push_back(*p);
276 }
277 }
278 }
279
280 sort(buffer.begin(), buffer.end()); // sort according time-of-emisson
281
282 JStats qs; // monitor of trigger
283 JEvent out; // temporary storage of event(s)
284
285 for (buffer_type::const_iterator p = buffer.begin(); p != buffer.end(); ++p) {
286
287 buffer_type::const_iterator q = p;
288
289 // basic correlator
290
291 while (++q != buffer.end() && q->getToE() - p->getToE() <= TMax_s) {}
292
293 qs.put(distance(p,q));
294
295 if (distance(p,q) >= numberOfHits) {
296
297 JEvent event(detector.getID(), number_of_triggers.sum(), i->first, p, q);
298
299 number_of_triggers[i->first].put(event.size());
300
301 DEBUG("trigger: " << endl << event);
302
303 if (out.empty()) {
304
305 out = event;
306
307 } else if (match(out, event)) {
308
309 out.merge(event);
310
311 } else {
312
313 outputFile.put(out);
314
315 number_of_events[out.getID()].put(out.size());
316
317 out = event;
318 }
319 }
320 }
321
322 if (!out.empty()) {
323
324 outputFile.put(out); // pending event
325
326 number_of_events[out.getID()].put(out.size());
327 }
328
329 STATUS("number of toes: " << setw(3) << i->first << ' ' << setw(8) << buffer.size());
330 if (qs.getCount() > 0) {
331 STATUS(' ' << FIXED(6,1) << qs.getMean() <<
332 ' ' << FIXED(6,1) << qs.getXmin() <<
333 ' ' << FIXED(6,1) << qs.getXmax());
334 }
335 STATUS(endl);
336 }
337 STATUS(endl);
338
339 for (map_type::const_iterator i = number_of_triggers.begin(); i != number_of_triggers.end(); ++i) {
340 STATUS("number of triggers: " << setw(3) << i->first << ' ' << setw(8) << i->second.getCount() << endl);
341 }
342
343 for (map_type::const_iterator i = number_of_events.begin(); i != number_of_events.end(); ++i) {
344 STATUS("number of events: " << setw(3) << i->first << ' ' << setw(8) << i->second.getCount() << ' ' << FIXED(7,3) << i->second.getMean() << endl);
345 }
346
347 JMultipleFileScanner<JMeta> io(inputFile);
348
349 io >> outputFile;
350
351 outputFile.close();
352
353 return 0;
354}
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:74
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2107
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Detector data structure.
Definition JDetector.hh:96
int getString() const
Get string number.
Definition JLocation.hh:135
Data structure for position in three dimensions.
General exception.
Definition JException.hh:25
Utility class to parse command line options.
Definition JParser.hh:1664
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.
static const int HYDROPHONE_DISABLE
Enable (disable) use of hydrophone if this status bit is 0 (1);.
static const int PIEZO_DISABLE
Enable (disable) use of piezo if this status bit is 0 (1);.
double getW(const Trk &track, const size_t index, const double value)
Get track information.
JPosition3D getPosition(const Vec &pos)
Get position.
static JEmitterID getEmitterID
Function object for emitter identification.
JContainer< std::vector< JTripod > > tripods_container
Definition JSydney.cc:80
JContainer< std::vector< JTransmitter > > transmitters_container
Definition JSydney.cc:82
JContainer< std::vector< JHydrophone > > hydrophones_container
Definition JSydney.cc:81
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.
JPosition3D getPiezoPosition()
Get relative position of piezo in optical module.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< JHitW0 > buffer_type
hits
Definition JPerth.cc:74
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
Acoustic emitter.
Definition JEmitter.hh:30
Match of two events considering overlap in time and position.
void merge(const JEvent &event)
Merge event.
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.
Time-of-arrival data from acoustic piezo sensor or hydrophone.
Definition JToA.hh:28
uint32_t DOMID
DAQ run number.
Definition JToA.hh:34
int32_t WAVEFORMID
DOM unique identifeir.
Definition JToA.hh:35
int32_t DETID
Definition JToA.hh:32
Acoustic transceiver.
Auxiliary class to compare transmissions.
Auxiliary class to compare transmissions.
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition JContainer.hh:41
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:66
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
Auxiliary data structure for running average and standard deviation.
Definition JStats.hh:44
double getXmax() const
Get maximum value.
Definition JStats.hh:201
long long int getCount() const
Get total count.
Definition JStats.hh:168
void put(const double x, const double w=1.0)
Put value.
Definition JStats.hh:119
double getMean() const
Get mean value.
Definition JStats.hh:234
double getXmin() const
Get minimum value.
Definition JStats.hh:190