Jpp  18.0.0-rc.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JAcousticsEventReader.cc File Reference

Example program to process DAQ and acoustic events. More...

#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JDAQ/JDAQEvaluator.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JTreeScanner.hh"
#include "JSupport/JSupport.hh"
#include "JROOT/JRootToolkit.hh"
#include "JAcoustics/JEvent.hh"
#include "JAcoustics/JSupport.hh"
#include "JAcoustics/JAcousticsToolkit.hh"
#include "JAcoustics/JEvtToolkit.hh"
#include "Jeep/JProperties.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 process DAQ and acoustic events.

Author
mdejong

Definition in file JAcousticsEventReader.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 37 of file JAcousticsEventReader.cc.

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 }
Utility class to parse command line options.
Definition: JParser.hh:1514
double getUNIXTime(const KM3NETDAQ::JDAQChronometer &chronometer)
Get UNIX time of given DAQ object.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
#define STATUS(A)
Definition: JMessage.hh:63
Utility class to parse parameter values.
Definition: JProperties.hh:496
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
Template definition for direct access of elements in ROOT TChain.
size_t getNumberOfEmitters(T __begin, T __end)
Get number of emitters.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define FATAL(A)
Definition: JMessage.hh:67
Base class for JTreeScanner.
Definition: JTreeScanner.hh:54
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
General purpose class for object reading from a list of file names.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
int debug
debug level
JTriggerCounter_t next()
Increment trigger counter.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62