Jpp  17.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JAcoustics/JToAshortMonitor.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <limits>
4 #include <map>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH1D.h"
9 #include "TH2D.h"
10 
12 #include "JTools/JHashMap.hh"
13 #include "JTools/JRange.hh"
15 
16 #include "JDetector/JDetector.hh"
18 
20 
21 #include "JLang/JComparator.hh"
22 #include "JLang/JComparison.hh"
23 
24 #include "JROOT/JManager.hh"
25 
26 #include "JAcoustics/JEvent.hh"
27 #include "JAcoustics/JSupport.hh"
28 
29 #include "Jeep/JContainer.hh"
30 #include "Jeep/JPrint.hh"
31 #include "Jeep/JParser.hh"
32 #include "Jeep/JMessage.hh"
33 
34 
35 /**
36  * \file
37  *
38  * Example program to monitor acoustic events.
39  * \author mdejong
40  */
41 int main(int argc, char **argv)
42 {
43  using namespace std;
44  using namespace JPP;
45 
46  typedef JRange<double> JRange_t;
47  typedef JAbstractHistogram<double> JHistogram_t;
48 
50  JLimit_t& numberOfEvents = inputFile.getLimit();
51  string outputFile;
52  string detectorFile;
53  JRange_t T_s;
54  JHistogram_t x;
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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Definition: JComparator.hh:185
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:72
General purpose class for hash map of unique elements.
#define STATUS(A)
Definition: JMessage.hh:63
ROOT TTree parameter settings.
Detector data structure.
Definition: JDetector.hh:89
Acoustic event.
General purpose class for a hash collection of unique elements.
Dynamic ROOT object management.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
Simple data structure for histogram binning.
string outputFile
Data structure for detector geometry and calibration.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Type definition of range.
Definition: JHead.hh:41
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:226
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:295
int debug
debug level
Definition: JSirene.cc:67
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Auxiliary class to define a range between two values.
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
Acoustic event.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
int getID() const
Get identifier.
Container I/O.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62