Jpp  18.2.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JAcoustics/JEvt.hh
Go to the documentation of this file.
1 #ifndef __JACOUSTICS__JEVT__
2 #define __JACOUSTICS__JEVT__
3 
4 #include <string>
5 #include <ostream>
6 #include <iomanip>
7 #include <vector>
8 
9 #include <TROOT.h>
10 #include <TObject.h>
11 
12 #include "JLang/JManip.hh"
13 #include "JIO/JSerialisable.hh"
14 #include "JIO/JSTDIO.hh"
15 #include "JAcoustics/JTimeRange.hh"
16 
17 /**
18  * \file
19  *
20  * Acoustic event fit.
21  * \author mdejong
22  */
23 namespace JACOUSTICS {}
24 namespace JPP { using namespace JACOUSTICS; }
25 
26 namespace JACOUSTICS {
27 
28  using JIO::JSerialisable;
29  using JIO::JReader;
30  using JIO::JWriter;
31 
32  /**
33  * Acoustic single fit.
34  */
35  struct JFit :
36  public TObject
37  {
38  /**
39  * Default constructor.
40  */
41  JFit() :
42  id (-1),
43  tx (0.0),
44  ty (0.0),
45  tx2(0.0),
46  ty2(0.0),
47  vs (0.0)
48  {}
49 
50 
51  /**
52  * Constructor.
53  *
54  * \param id string identifier
55  * \param tx slope dx/dz
56  * \param ty slope dy/dz
57  * \param tx2 2nd order correction of slope dx/dz
58  * \param ty2 2nd order correction of slope dy/dz
59  * \param vs stretching factor
60  */
61  JFit(const int id,
62  const double tx,
63  const double ty,
64  const double tx2,
65  const double ty2,
66  const double vs) :
67  id (id),
68  tx (tx),
69  ty (ty),
70  tx2(tx2),
71  ty2(ty2),
72  vs (vs)
73  {}
74 
75 
76  /**
77  * Virtual destructor.
78  */
79  virtual ~JFit()
80  {}
81 
82 
83  /**
84  * Write fit to output.
85  *
86  * \param out output stream
87  * \param fit fit
88  * \return output stream
89  */
90  friend inline std::ostream& operator<<(std::ostream& out, const JFit& fit)
91  {
92  using namespace std;
93 
94  out << setw(4) << fit.id << ' '
95  << FIXED(10,7) << fit.tx << ' '
96  << FIXED(10,7) << fit.ty << ' '
97  << SCIENTIFIC(12,3) << fit.tx2 << ' '
98  << SCIENTIFIC(12,3) << fit.ty2 << ' '
99  << FIXED(8,5) << fit.vs;
100 
101  return out;
102  }
103 
104 
105  /**
106  * Read fit from input.
107  *
108  * \param in reader
109  * \param object fit
110  * \return reader
111  */
112  friend inline JReader& operator>>(JReader& in, JFit& object)
113  {
114  in >> object.id;
115  in >> object.tx;
116  in >> object.ty;
117  in >> object.tx2;
118  in >> object.ty2;
119  in >> object.vs;
120 
121  return in;
122  }
123 
124 
125  /**
126  * Write fit to output.
127  *
128  * \param out writer
129  * \param object fit
130  * \return writer
131  */
132  friend inline JWriter& operator<<(JWriter& out, const JFit& object)
133  {
134  out << object.id;
135  out << object.tx;
136  out << object.ty;
137  out << object.tx2;
138  out << object.ty2;
139  out << object.vs;
140 
141  return out;
142  }
143 
145 
146  int id; ///< string identifier
147  double tx; ///< slope dx/dz
148  double ty; ///< slope dy/dz
149  double tx2; ///< 2nd order correction of slope dx/dz
150  double ty2; ///< 2nd order correction of slope dy/dz
151  double vs; ///< stretching factor
152  };
153 
154 
155  /**
156  * Acoustic event header.
157  */
158  struct JHead {
159  /**
160  * Default constructor.
161  */
162  JHead() :
163  oid (),
164  UNIXTimeStart(0.0),
165  UNIXTimeStop (0.0),
166  nhit(0),
167  nfit(0),
168  npar(0),
169  ndf (0.0),
170  chi2(0.0)
171  {}
172 
173 
174  /**
175  * Constructor.
176  *
177  * \param oid detector identifer
178  * \param range UNIX start and stop time [s]
179  * \param nhit number of hits
180  * \param nfit number of hits used in fit (after outlier removal)
181  * \param npar number of fit parameters
182  * \param ndf weighed number of degrees of freedom
183  * \param chi2 chi2
184  */
185  JHead(const std::string& oid,
186  const JTimeRange& range,
187  const int nhit,
188  const int nfit,
189  const int npar,
190  const double ndf,
191  const double chi2) :
192  oid (oid),
193  UNIXTimeStart(range.getLowerLimit()),
194  UNIXTimeStop (range.getUpperLimit()),
195  nhit(nhit),
196  nfit(nfit),
197  npar(npar),
198  ndf (ndf),
199  chi2(chi2)
200  {}
201 
202 
203  /**
204  * Virtual destructor.
205  */
206  virtual ~JHead()
207  {}
208 
209 
210  /**
211  * Read head from input.
212  *
213  * \param in reader
214  * \param object head
215  * \return reader
216  */
217  friend inline JReader& operator>>(JReader& in, JHead& object)
218  {
219  in >> object.oid;
220  in >> object.UNIXTimeStart;
221  in >> object.UNIXTimeStop;
222  in >> object.nhit;
223  in >> object.nfit;
224  in >> object.npar;
225  in >> object.ndf;
226  in >> object.chi2;
227 
228  return in;
229  }
230 
231 
232  /**
233  * Write head to output.
234  *
235  * \param out writer
236  * \param object head
237  * \return writer
238  */
239  friend inline JWriter& operator<<(JWriter& out, const JHead& object)
240  {
241  out << object.oid;
242  out << object.UNIXTimeStart;
243  out << object.UNIXTimeStop;
244  out << object.nhit;
245  out << object.nfit;
246  out << object.npar;
247  out << object.ndf;
248  out << object.chi2;
249 
250  return out;
251  }
252 
253  ClassDef(JHead, 5);
254 
255  std::string oid; ///< detector identifier
256  double UNIXTimeStart; ///< start time
257  double UNIXTimeStop; ///< stop time
258  int nhit; ///< number of hits
259  int nfit; ///< number of hits used in fit (after outlier removal)
260  int npar; ///< number of fit parameters
261  double ndf; ///< weighed number of degrees of freedom
262  double chi2; ///< chi2
263  };
264 
265 
266  /**
267  * Less than operator for acoustics event headers.
268  *
269  * The less than operator is applied to the object identifier,
270  * the UNIX start time and the UNIX stop time, respectively.
271  *
272  * \param first first header
273  * \param second second header
274  * \return true if first event header earliear than second; else false
275  */
276  inline bool operator<(const JHead& first, const JHead& second)
277  {
278  if (first.oid == second.oid) {
279 
280  if (first.UNIXTimeStart == second.UNIXTimeStart) {
281 
282  return first.UNIXTimeStop < second.UNIXTimeStop;
283 
284  } else {
285 
286  return first.UNIXTimeStart < second.UNIXTimeStart;
287  }
288 
289  } else {
290 
291  return first.oid < second.oid;
292  }
293  }
294 
295 
296  /**
297  * Acoustic event fit.
298  */
299  struct JEvt :
300  public virtual JSerialisable,
301  public JHead,
302  public std::vector<JFit>,
303  public TObject
304  {
305  /**
306  * Auxiliary class to determine value of acoustic events.\n
307  * This class can be used with JSUPPORT::JTreeScanner so to read acoustics events in order of start time.
308  */
309  struct JEvaluator {
310  /**
311  * Default constructor.
312  */
314  {}
315 
316 
317  /**
318  * Get value of object.
319  *
320  * \param event event
321  * \return value
322  */
323  inline double operator()(const JEvt& event) const
324  {
325  return event.UNIXTimeStart;
326  }
327  };
328 
329 
330  /**
331  * Default constructor.
332  */
333  JEvt() :
334  JHead()
335  {}
336 
337 
338  /**
339  * Constructor.
340  *
341  * \param header header
342  */
343  JEvt(const JHead& header) :
344  JHead(header)
345  {}
346 
347 
348  /**
349  * Virtual destructor.
350  */
351  virtual ~JEvt()
352  {}
353 
354 
355  /**
356  * Write event to output.
357  *
358  * \param out output stream
359  * \param event event
360  * \return output stream
361  */
362  friend inline std::ostream& operator<<(std::ostream& out, const JEvt& event)
363  {
364  using namespace std;
365 
366  out << event.oid << endl
367  << FIXED(20,5) << event.UNIXTimeStart << endl
368  << FIXED(20,5) << event.UNIXTimeStop << endl
369  << setw(5) << event.nhit << ' '
370  << setw(5) << event.nfit << ' '
371  << setw(4) << event.npar << endl
372  << FIXED(12,3) << event.chi2 << '/'
373  << FIXED(7,1) << event.ndf << endl;
374 
375  for (JEvt::const_iterator fit = event.begin(); fit != event.end(); ++fit) {
376  out << *fit << endl;
377  }
378 
379  return out;
380  }
381 
382 
383  /**
384  * Read from input.
385  *
386  * \param in reader
387  * \return reader
388  */
389  virtual JReader& read(JReader& in) override
390  {
391  in >> static_cast<JHead&> (*this);
392  in >> static_cast<std::vector<JFit>&>(*this);
393 
394  return in;
395  }
396 
397 
398  /**
399  * Write to output.
400  *
401  * \param out writer
402  * \return writer
403  */
404  virtual JWriter& write(JWriter& out) const override
405  {
406  out << static_cast<const JHead&> (*this);
407  out << static_cast<const std::vector<JFit>&>(*this);
408 
409  return out;
410  }
411 
413  };
414 }
415 
416 #endif
friend JReader & operator>>(JReader &in, JHead &object)
Read head from input.
int id
string identifier
int npar
number of fit parameters
Interface for binary output.
ClassDefOverride(JFit, 2)
int nfit
number of hits used in fit (after outlier removal)
JEvaluator()
Default constructor.
JHead(const std::string &oid, const JTimeRange &range, const int nhit, const int nfit, const int npar, const double ndf, const double chi2)
Constructor.
JFit(const int id, const double tx, const double ty, const double tx2, const double ty2, const double vs)
Constructor.
std::string oid
detector identifier
friend JWriter & operator<<(JWriter &out, const JHead &object)
Write head to output.
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition: JHead.hh:1814
friend std::ostream & operator<<(std::ostream &out, const JFit &fit)
Write fit to output.
friend JReader & operator>>(JReader &in, JFit &object)
Read fit from input.
Definition: JRoot.hh:19
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
double ty
slope dy/dz
Acoustic single fit.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
virtual ~JFit()
Virtual destructor.
Auxiliary class to determine value of acoustic events.
friend std::ostream & operator<<(std::ostream &out, const JEvt &event)
Write event to output.
Forward declaration of binary output.
double UNIXTimeStop
stop time
double operator()(const JEvt &event) const
Get value of object.
double tx
slope dx/dz
Acoustic event header.
Acoustic event fit.
double ndf
weighed number of degrees of freedom
JEvt(const JHead &header)
Constructor.
virtual ~JEvt()
Virtual destructor.
then awk string
JHead()
Default constructor.
Interface for binary input.
double ty2
2nd order correction of slope dy/dz
I/O manipulators.
double vs
stretching factor
int nhit
number of hits
#define ClassDef(name, version)
Definition: JRoot.hh:32
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
double UNIXTimeStart
start time
then if[[!-f $DETECTOR]] then JDetector sh $DETECTOR fi cat $WORKDIR trigger_parameters txt<< EOFtrigger3DMuon.enabled=1;trigger3DMuon.numberOfHits=5;trigger3DMuon.gridAngle_deg=1;ctMin=0.0;TMaxLocal_ns=15.0;EOF set_variable TRIGGEREFFICIENCY_TRIGGERED_EVENTS_ONLY INPUT_FILES=() for((i=1;$i<=$NUMBER_OF_RUNS;++i));do JSirene.sh $DETECTOR $JPP_DATA/genhen.km3net_wpd_V2_0.evt.gz $WORKDIR/sirene_ ${i}.root JTriggerEfficiency.sh $DETECTOR $DETECTOR $WORKDIR/sirene_ ${i}.root $WORKDIR/trigger_efficiency_ ${i}.root $WORKDIR/trigger_parameters.txt $JPP_DATA/PMT_parameters.txt INPUT_FILES+=($WORKDIR/trigger_efficiency_ ${i}.root) done for ANGLE_DEG in $ANGLES_DEG[*];do set_variable SIGMA_NS 3.0 set_variable OUTLIERS 3 set_variable OUTPUT_FILE $WORKDIR/matrix\[${ANGLE_DEG}\deg\].root $JPP_DIR/examples/JReconstruction-f"$INPUT_FILES[*]"-o $OUTPUT_FILE-S ${SIGMA_NS}-A ${ANGLE_DEG}-O ${OUTLIERS}-d ${DEBUG}--!fiif[[$OPTION=="plot"]];then if((0));then for H1 in h0 h1;do JPlot1D-f"$WORKDIR/matrix["${^ANGLES_DEG}" deg].root:${H1}"-y"1 2e3"-Y-L TR-T""-\^"number of events [a.u.]"-> o chi2
Definition: JMatrixNZ.sh:106
double tx2
2nd order correction of slope dx/dz
friend JWriter & operator<<(JWriter &out, const JFit &object)
Write fit to output.
virtual ~JHead()
Virtual destructor.
virtual JWriter & write(JWriter &out) const override
Write to output.
virtual JReader & read(JReader &in) override
Read from input.
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
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
JEvt()
Default constructor.
STD extensions for binary I/O.
JFit()
Default constructor.