Jpp  debug
the software that should make you happy
JAcousticsEventReader.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 
10 #include "JDAQ/JDAQEventIO.hh"
12 #include "JDAQ/JDAQEvaluator.hh"
13 
15 #include "JSupport/JTreeScanner.hh"
16 #include "JSupport/JSupport.hh"
17 
18 #include "JROOT/JRootToolkit.hh"
19 
20 #include "JAcoustics/JEvent.hh"
21 #include "JAcoustics/JSupport.hh"
24 
25 #include "Jeep/JProperties.hh"
26 #include "Jeep/JPrint.hh"
27 #include "Jeep/JParser.hh"
28 #include "Jeep/JMessage.hh"
29 
30 
31 /**
32  * \file
33  *
34  * Example program to process DAQ and acoustic events.
35  * \author mdejong
36  */
37 int main(int argc, char **argv)
38 {
39  using namespace std;
40  using namespace JPP;
41  using namespace KM3NETDAQ;
42 
44  JMultipleFileScanner<> acousticsFile;
45  JLimit_t& numberOfEvents = inputFile.getLimit();
46  string outputFile;
47  double Tmax_s = 300.0; // time window [s]
48  size_t Nmin = 3; // minimum number of emitters
49  int debug;
50 
51  try {
52 
53  JProperties properties;
54 
55  properties.insert(gmake_property(Tmax_s));
56  properties.insert(gmake_property(Nmin));
57 
58  JParser<> zap("Example program to process DAQ and acoustic events.");
59 
60  zap['f'] = make_field(inputFile);
61  zap['A'] = make_field(acousticsFile);
62  zap['o'] = make_field(outputFile) = "example.root";
63  zap['n'] = make_field(numberOfEvents) = JLimit::max();
64  zap['@'] = make_field(properties) = JPARSER::initialised();
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 
74  TH1D h1("h1", NULL, 101, -0.5, +100.5);
75  TH1D hn("hn", NULL, 101, -0.5, +100.5);
76  TH1D ht("ht", NULL, 100, -1.0e3, +1.0e3);
77 
78 
79  map<double, double> data; // time-of-emission -> range of times-of-emission
80 
82 
83  JTreeScanner_t in(acousticsFile);
84 
85  for (JTreeScanner_t::iterator p = in.begin(), q; p != in.end(); p = q) {
86 
87  STATUS("event " << FIXED(20,6) << p->begin()->getToE() << '\r'); DEBUG(endl);
88 
89  for (q = p; ++q != in.end() && q->begin()->getToE() <= p->rbegin()->getToE() + Tmax_s; ) {}
90 
91  h1.Fill((double) getNumberOfEmitters(p,q));
92  hn.Fill((double) distance(p,q));
93 
94  if (getNumberOfEmitters(p,q) >= Nmin) {
95 
96  double range = 0.0;
97 
98  for (JTreeScanner_t::iterator i = p; i != q; ++i) {
99  if (i->rbegin()->getToE() - p->begin()->getToE() > range) {
100  range = i->rbegin()->getToE() - p->begin()->getToE();
101  }
102  }
103 
104  data[p->begin()->getToE()] = range;
105  }
106  }
107  STATUS(endl);
108 
109 
110  while (inputFile.hasNext()) {
111 
112  const JDAQEvent* evt = inputFile.next();
113  const double t0 = getUNIXTime(*evt);
114 
115  STATUS("DAQ event " << FIXED(20,6) << t0 << '\r'); DEBUG(endl);
116 
117  map<double, double>::const_iterator p = data.lower_bound(t0);
118 
119  double t1 = (p != data.end() ? p->first : 0.0);
120 
121  if (p != data.begin()) {
122 
123  --p;
124 
125  if (fabs(t1 - t0) > fabs(p->first - t0)) { t1 = p->first; }
126  if (fabs(t1 - t0) > fabs(p->first + p->second - t0)) { t1 = p->first + p->second; }
127  }
128 
129  ht.Fill(t0 - t1);
130  }
131  STATUS(endl);
132 
133 
134  TFile out(outputFile.c_str(), "recreate");
135 
136  out << h1 << hn << ht;
137 
138  out.Write();
139  out.Close();
140 }
int main(int argc, char **argv)
Acoustics toolkit.
Acoustic event.
Acoustic event fit toolkit.
ROOT TTree parameter settings.
string outputFile
General purpose messaging.
#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
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
I/O formatting auxiliaries.
Utility class to parse parameter values.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
ROOT TTree parameter settings of various packages.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Utility class to parse parameter values.
Definition: JProperties.hh:501
Utility class to parse command line options.
Definition: JParser.hh:1714
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
Base class for JTreeScanner.
Definition: JTreeScanner.hh:56
Template definition for direct access of elements in ROOT TChain.
double getUNIXTime(const KM3NETDAQ::JDAQChronometer &chronometer)
Get UNIX time of given DAQ object.
size_t getNumberOfEmitters(T __begin, T __end)
Get number of emitters.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:84
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45