Jpp
Functions
toa.cc File Reference
#include <iostream>
#include <iomanip>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "JGizmo/JManager.hh"
#include "JUTM/JUTMPosition.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JToAshort.hh"
#include "JDB/JDBToolkit.hh"
#include "JLang/JLangToolkit.hh"
#include "JLang/JPredicate.hh"
#include "JTools/JRange.hh"
#include "JTools/JQuantile.hh"
#include "JROOT/JRootPrinter.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 analyse acoustic data from data base.

Author
mdejong

Definition in file toa.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 75 of file toa.cc.

76 {
77  using namespace std;
78  using namespace JPP;
79 
80  typedef JRange<int> JRange_t;
81 
82  string usr;
83  string pwd;
84  string cookie;
85  string detectorFile;
86  string outputFile;
87  string detid;
88  JRange_t runs;
89  double TMax_s;
90  double Q;
91  int debug;
92 
93  try {
94 
95  JParser<> zap("Example program to analyse acoustic data from data base.");
96 
97  zap['u'] = make_field(usr) = "";
98  zap['!'] = make_field(pwd) = "";
99  zap['C'] = make_field(cookie) = "";
100  zap['a'] = make_field(detectorFile);
101  zap['o'] = make_field(outputFile) = "toa.root";
102  zap['D'] = make_field(detid);
103  zap['R'] = make_field(runs);
104  zap['T'] = make_field(TMax_s);
105  zap['Q'] = make_field(Q) = 0.0;
106  zap['d'] = make_field(debug) = 1;
107 
108  zap(argc, argv);
109  }
110  catch(const exception &error) {
111  FATAL(error.what() << endl);
112  }
113 
114 
115  const double SOUND_VELOCITY = 1481.0; // [m/s]
116 
117 
119 
120  try {
121  load(detectorFile, detector);
122  }
123  catch(const JException& error) {
124  FATAL(error);
125  }
126 
127  const JModuleRouter router(detector);
128 
129  const int MODULE[] = {
130  detector.getModule(JModuleLocation(1, 1)).getID(),
131  detector.getModule(JModuleLocation(1, 17)).getID()
132  };
133 
134  /*
135  Waveform #12 (sweep 26 kHz -28 kHz. 5 ms long)--> Tripod 1
136  Waveform #14 (sweep 30 kHz -32 kHz. 5 ms long)--> Tripod 2
137  Waveform #16 (sweep 34 kHz -36 kHz. 5 ms long)--> Tripod 3
138  */
139 
140  map<int, JPosition3D> tripod;
141 
142  tripod[12] = (JUTMPosition(587888, 4017079, detector.getUTMZ()) - detector.getUTMPosition()).getPosition();
143  tripod[14] = (JUTMPosition(587436, 4016992, detector.getUTMZ()) - detector.getUTMPosition()).getPosition();
144  tripod[16] = (JUTMPosition(587843, 4016727, detector.getUTMZ()) - detector.getUTMPosition()).getPosition();
145 
146  DEBUG("Tripods" << endl);
147 
148  for (map<int, JPosition3D>::const_iterator i = tripod.begin(); i != tripod.end(); ++i) {
149 
150  const JPosition3D pos = i->second - JPosition3D(detector.getModule(JModuleLocation(1, 1)).getX(),
151  detector.getModule(JModuleLocation(1, 1)).getY(),
152  0.0);
153 
154  DEBUG(setw(2) << i->first << ' '
155  << FIXED(7,2) << pos.getX() << ' '
156  << FIXED(7,2) << pos.getY() << ' '
157  << FIXED(7,2) << pos.getZ() << ' '
158  << FIXED(7,2) << sqrt(pos.getX()*pos.getX() + pos.getY()*pos.getY())
159  << endl);
160  }
161 
162  JManager<int, TH1D> H1(new TH1D("M[%]", NULL, 10000, -0.25, +0.25));
163 
164  typedef vector<JElement_t> buffer_type;
165 
166  map<int, // emitter
167  map< int, // module
168  buffer_type> > f1; // data
169 
170  try {
171 
172  JDB::reset(usr, pwd, cookie);
173 
174  if (is_integer(detid))
175  detid = getDetector(to_value<int>(detid));
176  else
177  getDetector(detid);
178 
179  JSelector selector = getSelector<JToAshort>(detid,
180  runs.getLowerLimit(),
181  runs.getUpperLimit());
182 
183  ResultSet& rs = getResultSet(getTable<JToAshort>(), selector);
184 
185  int number_of_rows = 0;
186 
187  for (JToAshort parameters; rs >> parameters; ++number_of_rows) {
188 
189  STATUS(setw(8) << number_of_rows << '\r' << flush); DEBUG(endl);
190 
191  if (debug >= debug_t) {
192  JRootPrinter::print(cout, parameters);
193  }
194 
195  const double d1 = (router.getModule(parameters.DOMID).getPosition() - tripod[parameters.EMITTERID]).getLength();
196  const double t1 = parameters.UNIXTIMEBASE + parameters.TOA_S - d1 / SOUND_VELOCITY;
197  const double q1 = parameters.QUALITYFACTOR;
198 
199  f1[parameters.EMITTERID][parameters.DOMID].push_back(JElement_t(t1,q1));
200  }
201  STATUS(endl);
202  }
203  catch(const exception& error) {
204  FATAL(error.what() << endl);
205  }
206 
207 
208  for (map<int, map< int, buffer_type> >::iterator emitter = f1.begin(); emitter != f1.end(); ++emitter) {
209 
210  TH1D* h1 = H1[emitter->first];
211 
212  // data selection
213 
214  for (int i = 0; i != sizeof(MODULE)/sizeof(MODULE[0]); ++i) {
215 
216  buffer_type& buffer = emitter->second[MODULE[i]];
217 
218  JQuantile Q1("quality", buffer.begin(), buffer.end(), &JElement_t::q1);
219 
220  const double Qmin = Q1.getQuantile(Q);
221 
222  buffer_type::iterator __end = partition(buffer.begin(), buffer.end(), make_predicate(&JElement_t::q1, Qmin, JComparison::gt()));
223 
224  buffer.erase(__end, buffer.end());
225 
226  sort(buffer.begin(), buffer.end());
227  }
228 
229  // correlator
230 
231  buffer_type::const_iterator p0 = emitter->second[MODULE[0]].begin();
232  buffer_type::const_iterator p1 = emitter->second[MODULE[1]].begin();
233 
234  buffer_type::const_iterator end0 = emitter->second[MODULE[0]].end();
235  buffer_type::const_iterator end1 = emitter->second[MODULE[1]].end();
236 
237  if (p0 != end0 && p1 != end1) {
238 
239  for ( ; ; ++p0, ++p1) {
240 
241  while (p0 != end0 && p0->t1 < p1->t1 - TMax_s) { ++p0; }
242  while (p1 != end1 && p1->t1 < p0->t1 - TMax_s) { ++p1; }
243 
244  if (p0 != end0 && p1 != end1)
245  h1->Fill(p1->t1 - p0->t1);
246  else
247  break;
248  }
249  }
250  }
251 
252 
253  TFile out(outputFile.c_str(), "recreate");
254 
255  out << H1;
256 
257  out.Write();
258  out.Close();
259 }
std::iterator
Definition: JSTDTypes.hh:18
FIXED
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
JLANG::is_integer
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58
JGEOMETRY3D::JVector3D::getZ
double getZ() const
Get z position.
Definition: JVector3D.hh:114
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:476
std::vector< JElement_t >
JDATABASE::JToAshort
Definition: JToAshort.hh:17
JTOOLS::JRange< int >
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JGIZMO::JManager
Auxiliary class to manage set of compatible ROOT objects (e.g.
Definition: JManager.hh:40
JDATABASE::getDetector
static const JDetectorsHelper & getDetector
Function object for mapping serial number and object identifier of detectors.
Definition: JDBToolkit.hh:131
JDATABASE::getResultSet
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:403
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDETECTOR::JModuleLocation
Logical location of module.
Definition: JModuleLocation.hh:36
debug
int debug
debug level
Definition: JSirene.cc:59
JGEOMETRY3D::JPosition3D
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
JUTM::JUTMPosition
Data structure for UTM position.
Definition: JUTMPosition.hh:34
JDATABASE::getSelector
Template definition for getting table specific selector.
Definition: JSelectorSupportkit.hh:31
std::map
Definition: JSTDTypes.hh:16
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JDETECTOR::reset
void reset(JCLBInput &data, size_t size)
Reset CLB buffers.
Definition: JCLBSimulator.hh:41
JTOOLS::JQuantile
Quantile calculator.
Definition: JQuantile.hh:34
JDETECTOR::JModuleRouter
Router for direct addressing of module data in detector data structure.
Definition: JModuleRouter.hh:34
JTOOLS::JQuantile::getQuantile
double getQuantile(const double Q, const bool reverse=false) const
Get quantile.
Definition: JQuantile.hh:288
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JAANET::getPosition
JPosition3D getPosition(const Vec &v)
Get position.
Definition: JAAnetToolkit.hh:197
JAANET::detector
Detector file.
Definition: JHead.hh:130
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JGEOMETRY3D::JVector3D::getY
double getY() const
Get y position.
Definition: JVector3D.hh:103
JLANG::make_predicate
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
JDATABASE::JSelector
Auxiliary class for specifying selection of database data.
Definition: JDB/JSelector.hh:67
p1
TPaveText * p1
Definition: JDrawModule3D.cc:35
JGEOMETRY3D::JVector3D::getX
double getX() const
Get x position.
Definition: JVector3D.hh:93
print
void print(const TH1 &h1, std::ostream &out)
Print histogram parameters.
Definition: JTriggerMonitor.cc:38
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JEEP::debug_t
debug
Definition: JMessage.hh:29
JLANG::JComparison::gt
Greater than.
Definition: JComparison.hh:73
JLANG::JException
General exception.
Definition: JException.hh:23