Jpp  19.1.0-rc.1
the software that should make you happy
Functions
JToAMonitor.cc File Reference

Example program to monitor acoustic events. More...

#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "JTools/JHashCollection.hh"
#include "JTools/JHashMap.hh"
#include "JTools/JRange.hh"
#include "JTools/JAbstractHistogram.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JLang/JComparator.hh"
#include "JLang/JComparison.hh"
#include "JROOT/JManager.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 monitor acoustic events.

Author
mdejong

Definition in file JToAMonitor.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 41 of file JToAMonitor.cc.

42 {
43  using namespace std;
44  using namespace JPP;
45 
46  typedef JRange<double> JRange_t;
48 
50  JLimit_t& numberOfEvents = inputFile.getLimit();
51  string outputFile;
52  string detectorFile;
53  JRange_t T_s;
55  int id; // emitter identifier
56  int debug;
57 
58  try {
59 
60  JParser<> zap("Example program to monitor acoustic events.");
61 
62  zap['f'] = make_field(inputFile, "output of JAcousticEventBuilder[.sh]");
63  zap['n'] = make_field(numberOfEvents) = JLimit::max();
64  zap['o'] = make_field(outputFile) = "toashort.root";
65  zap['a'] = make_field(detectorFile);
66  zap['T'] = make_field(T_s) = JRange_t(0.0, 10.0);
67  zap['x'] = make_field(x, "histogram x-binning") = JHistogram_t(100000, -2.0e-2, +2.0e-2);
68  zap['E'] = make_field(id, "emitter identifier (-1 = all)") = -1;
69  zap['d'] = make_field(debug) = 2;
70 
71  zap(argc, argv);
72  }
73  catch(const exception &error) {
74  FATAL(error.what() << endl);
75  }
76 
77 
79 
80  try {
81  load(detectorFile, detector);
82  }
83  catch(const JException& error) {
84  FATAL(error);
85  }
86 
87  JHashMap<int, JLocation> receivers;
88 
89  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
90  receivers[i->getID()] = i->getLocation();
91  }
92 
93 
94  JManager<JLocation, TH1D> H1(new TH1D("[%].t1", NULL, x.getNumberOfBins(), x.getLowerLimit(), x.getUpperLimit()));
95 
96 
98 
99  while (inputFile.hasNext()) {
100 
101  STATUS("input " << setw(6) << inputFile.getCounter() << '\r'); DEBUG(endl);
102 
103  const JEvent* evt = inputFile.next();
104 
105  zbuf[evt->getID()].push_back(*evt);
106  }
107  STATUS(endl);
108 
109 
110  for (map<int, vector<JEvent> >::iterator emitter = zbuf.begin(); emitter != zbuf.end(); ++emitter) {
111 
112  STATUS("Emitter " << setw(2) << emitter->first << ' ' << setw(6) << emitter->second.size() << endl);
113 
114  if (emitter->first == id || id == -1) {
115 
116  if (emitter->second.size() > 1) {
117 
118  sort(emitter->second.begin(), emitter->second.end()); // sort by time
119 
120  for (vector<JEvent>::iterator q = emitter->second.begin(), p = q++; q != emitter->second.end(); ++p, ++q) {
121 
122  if (!p->empty() && !q->empty()) {
123 
124  DEBUG("Time difference " << FIXED(7,3) << q->begin()->getToE() - p->begin()->getToE() << endl);
125 
126  if (T_s(q->begin()->getToE() - p->begin()->getToE())) {
127 
128  sort(p->begin(), p->end(), make_comparator(&JTransmission::getID)); // sort by identifier
129  sort(q->begin(), q->end(), make_comparator(&JTransmission::getID)); // sort by identifier
130 
131  map<JLocation, double> buffer;
132 
133  JEvent::const_iterator __p = p->begin();
134  JEvent::const_iterator __q = q->begin();
135 
136  while (__p != p->end() && __q != q->end()) {
137 
138  while (__p != p->end() && __q != q->end() && __p->getID() < __q->getID()) { ++__p; }
139  while (__p != p->end() && __q != q->end() && __q->getID() < __p->getID()) { ++__q; }
140 
141  if (__p != p->end() && __q != q->end() && __q->getID() == __p->getID()) {
142 
143  if (receivers.has(__p->getID())) {
144 
145  const JLocation& location = receivers[__p->getID()];
146  const double t1 = __q->getToA() - __p->getToA();
147 
148  buffer[location] = t1;
149  }
150 
151  ++__p;
152  ++__q;
153  }
154  }
155 
156  if (buffer.size() > 1) {
157 
158  for (map<JLocation, double>::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
159 
160  if (p->first.getString() == q->first.getString() && p->first.getFloor() + 1 == q->first.getFloor()) {
161 
162  const double t1 = q->second - p->second;
163 
164  H1[p->first]->Fill(t1);
165  H1 ->Fill(t1);
166  }
167  }
168  }
169  }
170  }
171  }
172  }
173  }
174  }
175 
176 
177  TFile out(outputFile.c_str(), "recreate");
178 
179  out << H1 << *H1;
180 
181  out.Write();
182  out.Close();
183 }
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:2158
Detector data structure.
Definition: JDetector.hh:96
Logical location of module.
Definition: JLocation.hh:39
General exception.
Definition: JException.hh:24
Utility class to parse command line options.
Definition: JParser.hh:1714
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition: JManager.hh:47
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.
JAbstractHistogram< double > JHistogram_t
Type definition for scan along axis.
Definition: JBillabong.cc:61
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).
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Type definition of range.
Definition: JHead.hh:43
Detector file.
Definition: JHead.hh:227
int getID() const
Get emitter identifier.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
Simple data structure for histogram binning.
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:75