Jpp  16.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JToAshortMonitor.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 "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 JToAshortMonitor.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 40 of file JToAshortMonitor.cc.

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
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
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Type definition of range.
Definition: JHead.hh:39
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Detector file.
Definition: JHead.hh:224
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
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
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.