Jpp  18.3.0-209-g56ce19a
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JCanberra.cc File Reference

Example program to plot acoustic fit results. More...

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TF1.h"
#include "TFitResult.h"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JTripod.hh"
#include "JDetector/JTransmitter.hh"
#include "JDetector/JHydrophone.hh"
#include "JDetector/JModule.hh"
#include "JDetector/JModuleRouter.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JTreeScanner.hh"
#include "JROOT/JRootToolkit.hh"
#include "JROOT/JManager.hh"
#include "JAcoustics/JSoundVelocity.hh"
#include "JAcoustics/JGeometry.hh"
#include "JAcoustics/JEmitter.hh"
#include "JAcoustics/JAcousticsToolkit.hh"
#include "JAcoustics/JHit.hh"
#include "JAcoustics/JEvent.hh"
#include "JAcoustics/JEvt.hh"
#include "JAcoustics/JEvtToolkit.hh"
#include "JAcoustics/JSupport.hh"
#include "JAcoustics/JTransmission_t.hh"
#include "Jeep/JContainer.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 plot acoustic fit results.

Author
mdejong

Definition in file JCanberra.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 51 of file JCanberra.cc.

52 {
53  using namespace std;
54  using namespace JPP;
55 
59  typedef JContainer< set<JTransmission_t> > disable_container;
60 
62  JLimit_t& numberOfEvents = inputFile.getLimit();
63  string detectorFile;
64  string outputFile;
65  JSoundVelocity V = getSoundVelocity; // default sound velocity
66  tripods_container tripods; // tripods
67  transmitters_container transmitters; // transmitters
68  hydrophones_container hydrophones; // hydrophones
69  int id; // emitter identifier
70  disable_container disable; // disable tansmissions
71  bool revert;
72  string option;
73  int numberOfEntries = 21;
74  int debug;
75 
76  try {
77 
78  JParser<> zap("Example program to plot acoustic fit results.");
79 
80  JProperties properties;
81 
82  properties.insert(gmake_property(numberOfEntries));
83 
84  zap['f'] = make_field(inputFile, "input file (output of JKatoomba[.sh])");
85  zap['n'] = make_field(numberOfEvents) = JLimit::max();
86  zap['a'] = make_field(detectorFile);
87  zap['o'] = make_field(outputFile) = "canberra.root";
88  zap['V'] = make_field(V, "sound velocity") = JPARSER::initialised();
89  zap['T'] = make_field(tripods, "tripod data");
90  zap['Y'] = make_field(transmitters, "transmitter data") = JPARSER::initialised();
91  zap['H'] = make_field(hydrophones, "hydrophone data") = JPARSER::initialised();
92  zap['M'] = make_field(getMechanics, "mechanics data") = JPARSER::initialised();
93  zap['E'] = make_field(id, "emitter identifier (-1 = all)") = -1;
94  zap['!'] = make_field(disable, "disable transmission") = JPARSER::initialised();
95  zap['r'] = make_field(revert, "revert disabling of transmissions");
96  zap['O'] = make_field(option, "ROOT fit option, see TH1::Fit.") = "LS";
97  zap['@'] = make_field(properties) = JPARSER::initialised();
98  zap['d'] = make_field(debug) = 2;
99 
100  zap(argc, argv);
101  }
102  catch(const exception &error) {
103  FATAL(error.what() << endl);
104  }
105 
106 
107  if (option.find('Q') == string::npos && debug < JEEP::debug_t) { option += 'Q'; }
108 
110 
111  try {
112  load(detectorFile, detector);
113  }
114  catch(const JException& error) {
115  FATAL(error);
116  }
117 
118  JHashMap<int, JLocation> receivers;
119  JHashMap<int, JEmitter> emitters;
120 
121  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
122  receivers[i->getID()] = i->getLocation();
123  }
124 
125  for (tripods_container::const_iterator i = tripods.begin(); i != tripods.end(); ++i) {
126  emitters[i->getID()] = JEmitter(i->getID(),
127  i->getUTMPosition() - detector.getUTMPosition());
128  }
129 
130  for (transmitters_container::const_iterator i = transmitters.begin(); i != transmitters.end(); ++i) {
131  try {
132  emitters[i->getID()] = JEmitter(i->getID(), i->getPosition() + detector.getModule(i->getLocation()).getPosition());
133  }
134  catch(const exception&) {} // if no module available, discard transmitter
135  }
136 
137  const JGeometry geometry(detector, hydrophones);
138 
139  V.set(detector.getUTMZ());
140 
141 
142  JManager<JTransmission_t, TH1D> H2(new TH1D("[%].toa", NULL, 1000, -1.0e-2, +1.0e-2));
143 
144  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
145  for (JHashMap<int, JEmitter>::const_iterator i = emitters.begin(); i != emitters.end(); ++i) {
146  if (id == i->first || id == -1) {
147  H2[JTransmission_t(i->first, module->getID())];
148  }
149  }
150  }
151 
153 
154  JTreeScanner_t in(inputFile);
155 
156  JTreeScanner_t::iterator p = in.begin();
157 
158  while (inputFile.hasNext()) {
159 
160  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
161 
162  const JEvt* evt = inputFile.next();
163  const JModel model = getModel(*evt);
164 
165  DEBUG("model" << endl << model << endl);
166 
167  for ( ; p != in.end() && p-> begin()->getToA() < evt->UNIXTimeStart - 0.5; ++p) {}
168 
169  JTreeScanner_t::iterator q = p;
170 
171  for ( ; q != in.end() && q->rbegin()->getToA() <= evt->UNIXTimeStop + 0.5; ++q) {}
172 
173  DEBUG("events " << distance(p, q) << endl);
174 
175  for (JTreeScanner_t::iterator i = p; i != q; ++i) {
176 
177  if (id == i->getID() || id == -1) {
178 
179  if (emitters.has(i->getID())) {
180 
181  const JEmitter& emitter = emitters[i->getID()];
182 
183  for (JEvent::const_iterator hit = i->begin(); hit != i->end(); ++hit) {
184 
185  if (receivers.has(hit->getID()) && geometry.hasLocation(receivers[hit->getID()])) {
186 
187  if ((disable.count(JTransmission_t(i->getID(), hit->getID())) == 0 &&
188  disable.count(JTransmission_t(-1, hit->getID())) == 0) == !revert) {
189 
190  const JLocation& location = receivers[hit->getID()];
191 
192  if (geometry .has(location.getString()) &&
193  model.string.has(location.getString())) {
194 
195  const JGEOMETRY::JString& string = geometry [location.getString()];
196  const JMODEL ::JString& parameters = model.string[location.getString()];
197  const JPosition3D position = string.getPosition(parameters, location.getFloor());
198 
199  const double D = emitter.getDistance(position);
200  const double Vi = V.getInverseVelocity(D, emitter.getZ(), position.getZ());
201  const double toa = hit->getToE() + D * Vi;
202 
203  H2[JTransmission_t(i->getID(), hit->getID())]->Fill(hit->getToA() - toa);
204  }
205  }
206  }
207  }
208  }
209  }
210  }
211 
212  p = q;
213  }
214  STATUS(endl);
215 
216 
218 
219  JManager<int, TH2D> HA(new TH2D("[%].mean", NULL,
221  range.getLength() + 1, range.getLowerLimit() - 0.5, range.getUpperLimit() + 0.5));
222 
223  JManager<int, TH2D> HB(new TH2D("[%].sigma", NULL,
225  range.getLength() + 1, range.getLowerLimit() - 0.5, range.getUpperLimit() + 0.5));
226 
227  for (Int_t i = 1; i <= HA->GetXaxis()->GetNbins(); ++i) {
228  HA->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(geometry.at(i-1).first));
229  HB->GetXaxis()->SetBinLabel(i, MAKE_CSTRING(geometry.at(i-1).first));
230  }
231 
232  const JModuleRouter router(detector);
233 
234  TF1 f1("f1", "[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2]))");
235 
236  const vector<Double_t> Q = { 0.33, 0.55, 0.66 };
237 
238  for (JManager<JTransmission_t, TH1D>::iterator i = H2.begin(); i != H2.end(); ++i) {
239 
240  TH1* h1 = i->second;
241 
242  const JLocation location = router.getModule(i->first.rx).getLocation();
243 
244  if (h1->GetEntries() >= numberOfEntries) {
245 
246  vector<Double_t> X(Q.size(), 0.0);
247 
248  h1->GetQuantiles(Q.size(), X.data(), Q.data());
249 
250  f1.SetParameter(0, h1->GetMaximum());
251  f1.SetParameter(1, X[1]);
252  f1.SetParameter(2, 0.5*(X[2] - X[0]));
253 
254  TFitResultPtr result = h1->Fit(&f1, option.c_str(), "same", X[1] - 5.0 * (X[2] - X[0]), X[1] + 5.0 * (X[2] - X[0]));
255 
256  if (result.Get() == NULL) {
257 
258  ERROR("Invalid TFitResultPtr " << h1->GetName() << endl);
259 
260  } else {
261 
262  HA[i->first.tx]->Fill(geometry.getIndex(location.getString()), location.getFloor(), f1.GetParameter(1) * 1.0e3);
263  HB[i->first.tx]->Fill(geometry.getIndex(location.getString()), location.getFloor(), f1.GetParameter(2) * 1.0e3);
264  }
265 
266  } else {
267 
268  HA[i->first.tx]->Fill(geometry.getIndex(location.getString()), location.getFloor(), numeric_limits<double>::lowest());
269  }
270  }
271 
272 
273  TFile out(outputFile.c_str(), "recreate");
274 
275  out << H2 << HA << HB;
276 
277  out.Write();
278  out.Close();
279 }
JModel getModel(const JEvt &evt)
Get model.
Utility class to parse command line options.
Definition: JParser.hh:1711
General exception.
Definition: JException.hh:24
Q(UTCMax_s-UTCMin_s)-livetime_s
debug
Definition: JMessage.hh:29
int getFloor() const
Get floor number.
Definition: JLocation.hh:145
JContainer< std::vector< JTransmitter > > transmitters_container
Definition: JSydney.cc:79
static JDetectorMechanics getMechanics
Function object to get string mechanics.
Definition: JMechanics.hh:242
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 gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
Utility class to parse parameter values.
Definition: JProperties.hh:497
*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
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
then fatal Number of tripods
Definition: JFootprint.sh:45
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:84
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
string outputFile
double getDistance(const JVector3D &pos) const
Get distance to point.
Definition: JVector3D.hh:270
floor_range getRangeOfFloors(const JDetector &detector)
Get range of floors.
Template definition for direct access of elements in ROOT TChain.
const JPolynome f1(1.0, 2.0, 3.0)
Function.
Model for fit to acoustics data.
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
Detector file.
Definition: JHead.hh:226
JContainer< std::vector< JHydrophone > > hydrophones_container
Definition: JSydney.cc:78
Acoustic event fit.
Acoustic emitter.
Definition: JEmitter.hh:27
Logical location of module.
Definition: JLocation.hh:37
const JLocation & getLocation() const
Get location.
Definition: JLocation.hh:69
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:2158
JPosition3D getPosition(const Vec &pos)
Get position.
#define ERROR(A)
Definition: JMessage.hh:66
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
JContainer< std::vector< JTripod > > tripods_container
Definition: JSydney.cc:77
static const JStringCounter getNumberOfStrings
Function object to count unique strings.
Implementation for depth dependend velocity of sound.
#define FATAL(A)
Definition: JMessage.hh:67
Base class for JTreeScanner.
Definition: JTreeScanner.hh:54
JACOUSTICS::JModel::string_type string
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
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.
then fatal The output file must have the wildcard in the e g root fi 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:48
no fit printf nominal n $STRING awk v X
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
container_type::const_iterator const_iterator
Definition: JHashMap.hh:86
do set_variable DETECTOR_TXT $WORKDIR detector
Acoustic transmission identifier.
bool has(const T &value) const
Test whether given value is present.
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
double getZ() const
Get z position.
Definition: JVector3D.hh:115
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62