Jpp  15.0.4
the software that should make you happy
 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['M'] = make_field(getMechanics, "mechanics data") = JPARSER::initialised();
73  zap['E'] = make_field(id, "emitter identifier (-1 = all)") = -1;
74  zap['d'] = make_field(debug) = 2;
75 
76  zap(argc, argv);
77  }
78  catch(const exception &error) {
79  FATAL(error.what() << endl);
80  }
81 
82 
84 
85  try {
86  load(detectorFile, detector);
87  }
88  catch(const JException& error) {
89  FATAL(error);
90  }
91 
92  JHashMap<int, JLocation> receivers;
93  JHashMap<int, JEmitter> emitters;
94 
95  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
96  receivers[i->getID()] = i->getLocation();
97  }
98 
99  for (tripods_container::const_iterator i = tripods.begin(); i != tripods.end(); ++i) {
100  emitters[i->getID()] = JEmitter(i->getID(),
101  i->getUTMPosition() - detector.getUTMPosition());
102  }
103 
104  const JGeometry geometry(detector, hydrophones);
105 
106  V.set(detector.getUTMZ());
107 
108 
109  JManager<int, TH1D> H2(new TH1D("[%].toa", NULL, 1000, -1.0e-2, +1.0e-2));
110 
111 
113 
114  JTreeScanner_t in(inputFile);
115 
116  JTreeScanner_t::iterator p = in.begin();
117 
118  while (inputFile.hasNext()) {
119 
120  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
121 
122  const JEvt* evt = inputFile.next();
123  const JModel model = getModel(*evt);
124 
125  DEBUG("model" << endl << model << endl);
126 
127  for ( ; p != in.end() && p-> begin()->getToA() < evt->UNIXTimeStart - 0.5; ++p) {}
128 
129  JTreeScanner_t::iterator q = p;
130 
131  for ( ; q != in.end() && q->rbegin()->getToA() <= evt->UNIXTimeStop + 0.5; ++q) {}
132 
133  DEBUG("events " << distance(p, q) << endl);
134 
135  for (JTreeScanner_t::iterator i = p; i != q; ++i) {
136 
137  if (id == i->getID() || id == -1) {
138 
139  if (emitters.has(i->getID())) {
140 
141  const JEmitter& emitter = emitters[i->getID()];
142 
143  for (JEvent::const_iterator hit = i->begin(); hit != i->end(); ++hit) {
144 
145  if (receivers.has(hit->getID())) {
146 
147  const JLocation& location = receivers[hit->getID()];
148  const JGEOMETRY::JString& string = geometry[location.getString()];
149  const JMODEL ::JString& parameters = model.string[location.getString()];
150  const JPosition3D position = string.getPosition(parameters, location.getFloor());
151 
152  const double D = emitter.getDistance(position);
153  const double Vi = V.getInverseVelocity(D, emitter.getZ(), position.getZ());
154  const double toa = hit->getToE() + D * Vi;
155 
156  H2[hit->getID()]->Fill(hit->getToA() - toa);
157  }
158  }
159  }
160  }
161  }
162 
163  p = q;
164  }
165  STATUS(endl);
166 
167  TFile out(outputFile.c_str(), "recreate");
168 
169  out << H2;
170 
171  out.Write();
172  out.Close();
173 }
Utility class to parse command line options.
Definition: JParser.hh:1500
Acoustic hit.
General exception.
Definition: JException.hh:23
JModel getModel(const JEvt &evt)
Get model.
int main(int argc, char *argv[])
Definition: Main.cc:15
Sound velocity.
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
static JDetectorMechanics getMechanics
Function object to get string mechanics.
Definition: JMechanics.hh:243
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:72
#define STATUS(A)
Definition: JMessage.hh:63
ROOT TTree parameter settings.
Detector data structure.
Definition: JDetector.hh:89
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.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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 CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
double getZ() const
Get z position.
Definition: JVector3D.hh:115
Container I/O.
Data structure for optical module.