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