Jpp  16.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JReconstruction/JEvt.hh
Go to the documentation of this file.
1 #ifndef __JRECONSTRUCTION__JEVT__
2 #define __JRECONSTRUCTION__JEVT__
3 
4 #include <istream>
5 #include <ostream>
6 #include <iomanip>
7 #include <limits>
8 #include <vector>
9 #include <algorithm>
10 #include <cmath>
11 
12 #include <TROOT.h>
13 #include <TObject.h>
14 
15 #include "JLang/JType.hh"
16 #include "JROOT/JRoot.hh"
17 #include "JROOT/JTreeParameters.hh"
18 
20 
21 /**
22  * \author mdejong
23  */
24 
25 namespace JRECONSTRUCTION {}
26 namespace JPP { using namespace JRECONSTRUCTION; }
27 
28 namespace JFIT {
29 
30  /**
31  * Data structure for track fit results with history and optional associated values.
32  */
33  class JFit :
34  public TObject,
35  public JHistory
36  {
37  public:
38  /**
39  * Default constructor.
40  *
41  * Parameters are initialized with non physical values.
42  */
43  JFit():
44  __x(std::numeric_limits<double>::lowest()),
45  __y(std::numeric_limits<double>::lowest()),
46  __z(std::numeric_limits<double>::lowest()),
47  __dx(0.0),
48  __dy(0.0),
49  __dz(0.0),
50  __t(std::numeric_limits<double>::lowest()),
51  __Q(std::numeric_limits<double>::lowest()),
52  __NDF(-1),
53  __E(0.0),
54  __status(-1)
55  {}
56 
57 
58  /**
59  * Constructor.
60  *
61  * \param history history
62  * \param x X-position
63  * \param y Y-position
64  * \param z Z-position
65  * \param dx X-slope
66  * \param dy Y-slope
67  * \param dz Z-slope
68  * \param t time
69  * \param Q quality
70  * \param NDF number of degrees of freedom
71  * \param E energy
72  * \param status status
73  */
74  JFit(const JHistory& history,
75  const double x,
76  const double y,
77  const double z,
78  const double dx,
79  const double dy,
80  const double dz,
81  const double t,
82  const double Q,
83  const int NDF,
84  const double E = 0.0,
85  const int status = -1) :
86  JHistory(history)
87  {
88  __x = x;
89  __y = y;
90  __z = z;
91  __dx = dx;
92  __dy = dy;
93  __dz = dz;
94  __t = t;
95  __Q = Q;
96  __NDF = NDF;
97  __E = E;
98  __status = status;
99  }
100 
101 
102  /**
103  * Constructor for storing position only.
104  *
105  * Note that the type of fit can be obtained via the history information.
106  *
107  * \param history history
108  * \param x X-position
109  * \param y Y-position
110  * \param z Z-position
111  * \param status status
112  */
113  JFit(const JHistory& history,
114  const double x,
115  const double y,
116  const double z,
117  const int status = -1):
118  JHistory(history)
119  {
120  __x = x;
121  __y = y;
122  __z = z;
123  __dx = 0.0;
124  __dy = 0.0;
125  __dz = 0.0;
126  __t = 0.0;
127  __Q = 0.0;
128  __NDF = -1;
129  __E = 0.0;
130  __status = status;
131  }
132 
133 
134  /**
135  * Add event to history.
136  *
137  * \param type application type
138  * \return this fit
139  */
140  JFit& add(const int type)
141  {
142  getHistory().add(type);
143 
144  return *this;
145  }
146 
147 
148  double getX() const { return __x; } //!< Get X-position.
149  double getY() const { return __y; } //!< Get Y-position.
150  double getZ() const { return __z; } //!< Get Z-position.
151  double getDX() const { return __dx; } //!< Get X-slope.
152  double getDY() const { return __dy; } //!< Get Y-slope.
153  double getDZ() const { return __dz; } //!< Get Z-slope.
154  double getT() const { return __t; } //!< Get time.
155  double getQ() const { return __Q; } //!< Get quality.
156  int getNDF() const { return __NDF; } //!< Get number of degrees of freedom.
157  double getE() const { return __E; } //!< Get energy.
158  int getStatus() const { return __status; } //!< Get status of the fit; negative values should refer to a bad fit.
159 
160 
161  /**
162  * Move vertex along this track with given velocity.
163  *
164  * \param step step
165  * \param velocity velocity
166  */
167  void move(const double step, const double velocity)
168  {
169  __x += step * __dx;
170  __y += step * __dy;
171  __z += step * __dz;
172  __t += step / velocity;
173  }
174 
175 
176  /**
177  * Set energy.
178  *
179  * \param E energy
180  */
181  void setE(const double E)
182  {
183  __E = E;
184  }
185 
186 
187  /**
188  * Get dimension of error matrix.
189  *
190  * \return dimension
191  */
193  {
194  return ((size_t) sqrt(1.0 + 8.0*V.size()) - 1) / 2;
195  }
196 
197 
198  /**
199  * Get error matrix.
200  *
201  * Note that only the lower-half of the matrix is returned.
202  *
203  * \return error matrix
204  */
205  const std::vector<double>& getV() const
206  {
207  return V;
208  }
209 
210 
211  /**
212  * Get element of error matrix.
213  *
214  * \param row row (<tt>0 <= row < dimension</tt>)
215  * \param col col (<tt>0 <= col < dimension</tt>)
216  * \return value
217  */
218  double getV(const size_t row, const size_t col) const
219  {
220  using namespace std;
221 
222  const size_t __row = max(row, col) + 1;
223  const size_t __col = min(row, col);
224 
225  return V.at((__row * (__row + 1)) / 2 - __row + __col);
226  }
227 
228 
229  /**
230  * Set error matrix.
231  *
232  * The given size corresponds to the dimension of a 2D-array of which
233  * the elements should be accessible via the usual array operators.\n
234  * Note that only the lower-half of the given matrix is stored.
235  *
236  * \param size size
237  * \param data matrix
238  */
239  template<class T>
240  void setV(const size_t size, const T& data)
241  {
242  V.clear();
243 
244  for (size_t row = 0; row != size; ++row) {
245  for (size_t col = 0; col <= row; ++col) {
246  V.push_back(data[row][col]);
247  }
248  }
249  }
250 
251 
252  /**
253  * Get associated values.
254  *
255  * \return values
256  */
257  const std::vector<double>& getW() const
258  {
259  return this->W;
260  }
261 
262 
263  /**
264  * Set associated values.
265  *
266  * \param W values
267  */
269  {
270  this->W = W;
271  }
272 
273 
274  /**
275  * Get number of associated values.
276  *
277  * \return number of values
278  */
279  int getN() const
280  {
281  return W.size();
282  }
283 
284 
285  /**
286  * Check availability of value.
287  *
288  * \param i index
289  * \return true if available; else false
290  */
291  bool hasW(const int i) const
292  {
293  return (i >= 0 && i < (int) W.size());
294  }
295 
296 
297  /**
298  * Get associated value.
299  *
300  * \param i index
301  * \return value
302  */
303  double getW(const int i) const
304  {
305  return W.at(i);
306  }
307 
308 
309  /**
310  * Get associated value.
311  *
312  * \param i index
313  * \param value default value
314  * \return value
315  */
316  double getW(const int i, const double value) const
317  {
318  if (hasW(i))
319  return W.at(i);
320  else
321  return value;
322  }
323 
324 
325  /**
326  * Set associated value.
327  *
328  * \param i index
329  * \param value value
330  */
331  void setW(const int i, const double value)
332  {
333  if (i >= (int) W.size()) {
334  W.resize(i + 1, 0.0);
335  }
336 
337  W[i] = value;
338  }
339 
340 
341  ClassDef(JFit, 6);
342 
343  protected:
344  double __x;
345  double __y;
346  double __z;
347  double __dx;
348  double __dy;
349  double __dz;
350  double __t;
351  double __Q;
352  int __NDF;
355  double __E;
356  int __status;
357  };
358 
359 
360  /**
361  * Data structure for set of track fit results.
362  */
363  class JEvt :
364  public TObject,
365  public std::vector<JFit>
366  {
367  public:
368  /**
369  * Default constructor.
370  */
372  {}
373 
374 
375  /**
376  * Select fits.
377  *
378  * \param selector fit selector
379  */
380  template<class JSelector_t>
381  void select(const JSelector_t& selector)
382  {
383  using namespace std;
384 
385  if (!empty()) {
386 
387  iterator __end = partition(this->begin(), this->end(), selector);
388 
389  this->erase(__end, this->end());
390  }
391  }
392 
393 
394  /**
395  * Select fits.
396  *
397  * \param number_of_fits maximal number of best fits to select
398  * \param comparator quality comparator
399  */
400  template<class JComparator_t>
401  void select(const size_t number_of_fits,
402  const JComparator_t& comparator)
403  {
404  using namespace std;
405 
406  if (!empty()) {
407 
408  iterator __end = this->end();
409 
410  if (number_of_fits > 0 && number_of_fits < this->size()) {
411 
412  advance(__end = this->begin(), number_of_fits);
413 
414  partial_sort(this->begin(), __end, this->end(), comparator);
415 
416  } else {
417 
418  sort(this->begin(), __end, comparator);
419  }
420 
421  this->erase(__end, this->end());
422  }
423  }
424 
425 
426  /**
427  * Write event to output.
428  *
429  * \param out output stream
430  * \param event event
431  * \return output stream
432  */
433  friend inline std::ostream& operator<<(std::ostream& out, const JEvt& event)
434  {
435  using namespace std;
436 
437  out << "Event: " << endl;
438 
439  for (JEvt::const_iterator fit = event.begin(); fit != event.end(); ++fit) {
440  out << *fit;
441  }
442 
443  return out;
444  }
445 
446 
447  ClassDef(JEvt, 4);
448  };
449 }
450 
451 
452 namespace JRECONSTRUCTION {
453  typedef JFIT::JFit JFit;
454  typedef JFIT::JEvt JEvt;
455 }
456 
457 
458 /**
459  * Write fit results to output.
460  *
461  * \param out output stream
462  * \param fit fit results
463  * \return output stream
464  */
465 std::ostream& operator<<(std::ostream& out, const JRECONSTRUCTION::JFit& fit);
466 
467 
468 /**
469  * Get TTree parameters for given data type.
470  *
471  * \return TTree parameters
472  */
474 {
475  return JROOT::JTreeParameters("EVT", "evt", "", 0);
476 }
477 
478 #endif
JFit(const JHistory &history, const double x, const double y, const double z, const double dx, const double dy, const double dz, const double t, const double Q, const int NDF, const double E=0.0, const int status=-1)
Constructor.
Q(UTCMax_s-UTCMin_s)-livetime_s
JHistory & add(const int type)
Add event to history.
Definition: JHistory.hh:269
friend std::ostream & operator<<(std::ostream &out, const JEvt &event)
Write event to output.
then usage E
Definition: JMuonPostfit.sh:35
void setW(const std::vector< double > &W)
Set associated values.
void setE(const double E)
Set energy.
void select(const size_t number_of_fits, const JComparator_t &comparator)
Select fits.
int getNDF() const
Get number of degrees of freedom.
void setW(const int i, const double value)
Set associated value.
int getN() const
Get number of associated values.
Definition: JRoot.hh:19
friend std::ostream & operator<<(std::ostream &out, const JHistory &history)
Write history to output stream.
Definition: JHistory.hh:284
Container for historical events.
Definition: JHistory.hh:98
This include file serves the purpose of hiding ROOT dependencies and circumphere namespace problems w...
Auxiliary class for a type holder.
Definition: JType.hh:19
void setV(const size_t size, const T &data)
Set error matrix.
JFit & add(const int type)
Add event to history.
size_t getDimensionOfErrorMatrix() const
Get dimension of error matrix.
std::vector< double > W
Data structure for track fit results with history and optional associated values. ...
double getV(const size_t row, const size_t col) const
Get element of error matrix.
bool hasW(const int i) const
Check availability of value.
double getT() const
Get time.
double getX() const
Get X-position.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
double getY() const
Get Y-position.
int getStatus() const
Get status of the fit; negative values should refer to a bad fit.
Data structure for TTree parameters.
JEvt()
Default constructor.
double getDZ() const
Get Z-slope.
JROOT::JTreeParameters getTreeParameters(JLANG::JType< JRECONSTRUCTION::JEvt >)
Get TTree parameters for given data type.
double getQ() const
Get quality.
Data structure for set of track fit results.
double getZ() const
Get Z-position.
const std::vector< double > & getV() const
Get error matrix.
double getW(const int i) const
Get associated value.
double getW(const int i, const double value) const
Get associated value.
JFit(const JHistory &history, const double x, const double y, const double z, const int status=-1)
Constructor for storing position only.
double getDY() const
Get Y-slope.
std::vector< double > V
void move(const double step, const double velocity)
Move vertex along this track with given velocity.
ClassDef(JFit, 6)
const std::vector< double > & getW() const
Get associated values.
const JHistory & getHistory() const
Get history.
Definition: JHistory.hh:228
void select(const JSelector_t &selector)
Select fits.
double getE() const
Get energy.
double getDX() const
Get X-slope.
JFit()
Default constructor.