Jpp  15.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
14 
15 #include "JDetector/JDetector.hh"
17 
19 
20 #include "JLang/JComparator.hh"
21 #include "JLang/JComparison.hh"
22 
23 #include "JROOT/JManager.hh"
24 
25 #include "JAcoustics/JEvent.hh"
26 #include "JAcoustics/JSupport.hh"
27 
28 #include "Jeep/JContainer.hh"
29 #include "Jeep/JPrint.hh"
30 #include "Jeep/JParser.hh"
31 #include "Jeep/JMessage.hh"
32 
33 
34 /**
35  * \file
36  *
37  * Example program to monitor acoustic events.
38  * \author mdejong
39  */
40 int main(int argc, char **argv)
41 {
42  using namespace std;
43  using namespace JPP;
44 
45  typedef JRange<double> JRange_t;
46 
48  JLimit_t& numberOfEvents = inputFile.getLimit();
49  string outputFile;
50  string detectorFile;
51  JRange_t T_s;
52  int id; // emitter identifier
53  int debug;
54 
55  try {
56 
57  JParser<> zap("Example program to monitor acoustic events.");
58 
59  zap['f'] = make_field(inputFile, "output of JAcousticEventBuilder[.sh]");
60  zap['n'] = make_field(numberOfEvents) = JLimit::max();
61  zap['o'] = make_field(outputFile) = "toashort.root";
62  zap['a'] = make_field(detectorFile);
63  zap['T'] = make_field(T_s) = JRange_t(0.0, 10.0);
64  zap['E'] = make_field(id, "emitter identifier (-1 = all)") = -1;
65  zap['d'] = make_field(debug) = 2;
66 
67  zap(argc, argv);
68  }
69  catch(const exception &error) {
70  FATAL(error.what() << endl);
71  }
72 
73 
75 
76  try {
77  load(detectorFile, detector);
78  }
79  catch(const JException& error) {
80  FATAL(error);
81  }
82 
83  JHashMap<int, JLocation> receivers;
84 
85  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
86  receivers[i->getID()] = i->getLocation();
87  }
88 
89 
90  JManager<JLocation, TH1D> H1(new TH1D("[%].t1", NULL, 10000, -5.0e-3, +5.0e-3));
91 
92 
94 
95  while (inputFile.hasNext()) {
96 
97  STATUS("input " << setw(6) << inputFile.getCounter() << '\r'); DEBUG(endl);
98 
99  const JEvent* evt = inputFile.next();
100 
101  zbuf[evt->getID()].push_back(*evt);
102  }
103  STATUS(endl);
104 
105 
106  for (map<int, vector<JEvent> >::iterator emitter = zbuf.begin(); emitter != zbuf.end(); ++emitter) {
107 
108  STATUS("Emitter " << setw(2) << emitter->first << ' ' << setw(6) << emitter->second.size() << endl);
109 
110  if (emitter->first == id || id == -1) {
111 
112  if (emitter->second.size() > 1) {
113 
114  sort(emitter->second.begin(), emitter->second.end()); // sort by time
115 
116  for (vector<JEvent>::iterator q = emitter->second.begin(), p = q++; q != emitter->second.end(); ++p, ++q) {
117 
118  if (!p->empty() && !q->empty()) {
119 
120  DEBUG("Time difference " << FIXED(7,3) << q->begin()->getToE() - p->begin()->getToE() << endl);
121 
122  if (T_s(q->begin()->getToE() - p->begin()->getToE())) {
123 
124  sort(p->begin(), p->end(), make_comparator(&JTransmission::getID)); // sort by identifier
125  sort(q->begin(), q->end(), make_comparator(&JTransmission::getID)); // sort by identifier
126 
127  map<JLocation, double> buffer;
128 
129  JEvent::const_iterator __p = p->begin();
130  JEvent::const_iterator __q = q->begin();
131 
132  while (__p != p->end() && __q != q->end()) {
133 
134  while (__p != p->end() && __q != q->end() && __p->getID() < __q->getID()) { ++__p; }
135  while (__p != p->end() && __q != q->end() && __q->getID() < __p->getID()) { ++__q; }
136 
137  if (__p != p->end() && __q != q->end() && __q->getID() == __p->getID()) {
138 
139  if (receivers.has(__p->getID())) {
140 
141  const JLocation& location = receivers[__p->getID()];
142  const double t1 = __q->getToA() - __p->getToA();
143 
144  buffer[location] = t1;
145  }
146 
147  ++__p;
148  ++__q;
149  }
150  }
151 
152  if (buffer.size() > 1) {
153 
154  for (map<JLocation, double>::const_iterator q = buffer.begin(), p = q++; q != buffer.end(); ++p, ++q) {
155 
156  if (p->first.getString() == q->first.getString() && p->first.getFloor() + 1 == q->first.getFloor()) {
157 
158  const double t1 = q->second - p->second;
159 
160  H1[p->first]->Fill(t1);
161  H1 ->Fill(t1);
162  }
163  }
164  }
165  }
166  }
167  }
168  }
169  }
170  }
171 
172 
173  TFile out(outputFile.c_str(), "recreate");
174 
175  out << H1 << *H1;
176 
177  out.Write();
178  out.Close();
179 }
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
do rm f tmp H1
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
string outputFile
Data structure for detector geometry and calibration.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.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:196
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
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.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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.