Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JCanberra.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 
4 #include "TROOT.h"
5 #include "TFile.h"
6 #include "TH1D.h"
7 #include "TH2D.h"
8 
9 #include "JDetector/JDetector.hh"
11 #include "JDetector/JTripod.hh"
12 #include "JDetector/JModule.hh"
13 #include "JDetector/JHydrophone.hh"
14 
16 #include "JSupport/JTreeScanner.hh"
17 
18 #include "JROOT/JRootToolkit.hh"
19 #include "JROOT/JManager.hh"
20 
22 #include "JAcoustics/JGeometry.hh"
23 #include "JAcoustics/JEmitter.hh"
25 #include "JAcoustics/JHit.hh"
26 #include "JAcoustics/JEvent.hh"
27 #include "JAcoustics/JEvt.hh"
29 #include "JAcoustics/JSupport.hh"
30 
31 #include "Jeep/JContainer.hh"
32 #include "Jeep/JPrint.hh"
33 #include "Jeep/JParser.hh"
34 #include "Jeep/JMessage.hh"
35 
36 
37 /**
38  * \file
39  *
40  * Example program to plot acoustic fit results.
41  * \author mdejong
42  */
43 int main(int argc, char **argv)
44 {
45  using namespace std;
46  using namespace JPP;
47 
48  typedef JContainer< vector<JTripod> > tripods_container;
49  typedef JContainer< vector<JHydrophone> > hydrophones_container;
50 
52  JLimit_t& numberOfEvents = inputFile.getLimit();
53  string detectorFile;
54  string outputFile;
55  JSoundVelocity V = getSoundVelocity; // default sound velocity
56  tripods_container tripods; // tripods
57  hydrophones_container hydrophones; // hydrophones
58  int id; // emitter identifier
59  int debug;
60 
61  try {
62 
63  JParser<> zap("Example program to plot acoustic fit results.");
64 
65  zap['f'] = make_field(inputFile, "input file (output of JKatoomba)");
66  zap['n'] = make_field(numberOfEvents) = JLimit::max();
67  zap['a'] = make_field(detectorFile);
68  zap['o'] = make_field(outputFile) = "canberra.root";
69  zap['V'] = make_field(V, "sound velocity") = JPARSER::initialised();
70  zap['T'] = make_field(tripods, "tripod data");
71  zap['H'] = make_field(hydrophones, "hydrophone data") = JPARSER::initialised();
72  zap['E'] = make_field(id, "emitter identifier (-1 = all)") = -1;
73  zap['d'] = make_field(debug) = 2;
74 
75  zap(argc, argv);
76  }
77  catch(const exception &error) {
78  FATAL(error.what() << endl);
79  }
80 
81 
83 
84  try {
85  load(detectorFile, detector);
86  }
87  catch(const JException& error) {
88  FATAL(error);
89  }
90 
91  JHashMap<int, JLocation> receivers;
92  JHashMap<int, JEmitter> emitters;
93 
94  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
95  receivers[i->getID()] = i->getLocation();
96  }
97 
98  for (tripods_container::const_iterator i = tripods.begin(); i != tripods.end(); ++i) {
99  emitters[i->getID()] = JEmitter(i->getID(),
100  i->getUTMPosition() - detector.getUTMPosition());
101  }
102 
103  const JGeometry geometry(detector, hydrophones);
104 
105  V.set(detector.getUTMZ());
106 
107 
108  JManager<int, TH1D> H2(new TH1D("[%].toa", NULL, 1000, -1.0e-2, +1.0e-2));
109 
110 
112 
113  JTreeScanner_t in(inputFile);
114 
115  JTreeScanner_t::iterator p = in.begin();
116 
117  while (inputFile.hasNext()) {
118 
119  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
120 
121  const JEvt* evt = inputFile.next();
122  const JModel model = getModel(*evt);
123 
124  DEBUG("model" << endl << model << endl);
125 
126  for ( ; p != in.end() && p-> begin()->getToA() < evt->UNIXTimeStart - 0.5; ++p) {}
127 
128  JTreeScanner_t::iterator q = p;
129 
130  for ( ; q != in.end() && q->rbegin()->getToA() <= evt->UNIXTimeStop + 0.5; ++q) {}
131 
132  DEBUG("events " << distance(p, q) << endl);
133 
134  for (JTreeScanner_t::iterator i = p; i != q; ++i) {
135 
136  if (id == i->getID() || id == -1) {
137 
138  if (emitters.has(i->getID())) {
139 
140  const JEmitter& emitter = emitters[i->getID()];
141 
142  for (JEvent::const_iterator hit = i->begin(); hit != i->end(); ++hit) {
143 
144  if (receivers.has(hit->getID())) {
145 
146  const JLocation& location = receivers[hit->getID()];
147  const JGEOMETRY::JString& string = geometry[location.getString()];
148  const JMODEL ::JString& parameters = model.string[location.getString()];
149  const JPosition3D position = string.getPosition(parameters, location.getFloor());
150 
151  const double D = emitter.getDistance(position);
152  const double Vi = V.getInverseVelocity(D, emitter.getZ(), position.getZ());
153  const double toa = hit->getToE() + D * Vi;
154 
155  H2[hit->getID()]->Fill(hit->getToA() - toa);
156  }
157  }
158  }
159  }
160  }
161 
162  p = q;
163  }
164  STATUS(endl);
165 
166  TFile out(outputFile.c_str(), "recreate");
167 
168  out << H2;
169 
170  out.Write();
171  out.Close();
172 }
Utility class to parse command line options.
Definition: JParser.hh:1500
Acoustic hit.
General exception.
Definition: JException.hh:23
do echo Generating $dir eval D
Definition: JDrawLED.sh:50
JModel getModel(const JEvt &evt)
Get model.
Sound velocity.
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
General purpose class for hash map of unique keys.
Definition: JHashMap.hh:71
#define STATUS(A)
Definition: JMessage.hh:63
ROOT TTree parameter settings.
Detector data structure.
Definition: JDetector.hh:80
Acoustic geometries.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Acoustic event.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Dynamic ROOT object management.
string outputFile
Acoustic emitter.
double getDistance(const JVector3D &pos) const
Get distance to point.
Definition: JVector3D.hh:270
Template definition for direct access of elements in ROOT TChain.
Definition: JTreeScanner.hh:91
Data structure for detector geometry and calibration.
Data structure for hydrophone.
Model for fit to acoustics data.
Acoustic event fit.
double UNIXTimeStop
stop time
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
static const JSoundVelocity getSoundVelocity(1541.0,-17.0e-3,-2000.0)
Function object for velocity of sound.
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
Acoustic event fit.
Acoustic emitter.
Definition: JEmitter.hh:27
Logical location of module.
Definition: JLocation.hh:37
Acoustics toolkit.
Auxiliary wrapper for I/O of container with optional comment (see JComment).
Definition: JContainer.hh:39
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:295
int debug
debug level
Definition: JSirene.cc:63
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
General purpose messaging.
Implementation for velocity of sound.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Base class for JTreeScanner.
Definition: JTreeScanner.hh:52
JACOUSTICS::JModel::string_type string
int getString() const
Get string number.
Definition: JLocation.hh:134
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
double UNIXTimeStart
start time
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
Data structure for tripod.
Acoustic event fit.
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 source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
double getZ() const
Get z position.
Definition: JVector3D.hh:115
Container I/O.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
Data structure for a composite optical module.
int main(int argc, char *argv[])
Definition: Main.cpp:15