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