Jpp master_rocky-44-g75b7c4f75
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"
16#include "JROOT/JRoot.hh"
18
21
22/**
23 * \author mdejong
24 */
25
26namespace JRECONSTRUCTION {}
27namespace JPP { using namespace JRECONSTRUCTION; }
28
29namespace 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 */
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 */
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 */
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
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;
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
461 };
462}
463
464
465namespace JRECONSTRUCTION {
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 */
478std::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 */
490
491#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.
This include file serves the purpose of hiding ROOT dependencies and circumphere namespace problems w...
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()
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:101
const JHistory & getHistory() const
Get history.
Definition JHistory.hh:229
JHistory & add(const int type)
Add event to history.
Definition JHistory.hh:295
Auxiliary class for a type holder.
Definition JType.hh:19