Jpp
JEvt.hh
Go to the documentation of this file.
1 #ifndef __JFIT__JEVT__
2 #define __JFIT__JEVT__
3 
4 #include <istream>
5 #include <ostream>
6 #include <iomanip>
7 #include <vector>
8 #include <limits>
9 
10 #include <TROOT.h>
11 #include <TObject.h>
12 
13 #include "JLang/JType.hh"
14 #include "JROOT/JRoot.hh"
15 #include "JROOT/JTreeParameters.hh"
16 
17 #include "JFit/JHistory.hh"
18 
19 /**
20  * \author mdejong
21  */
22 
23 namespace JFIT {}
24 namespace JPP { using namespace JFIT; }
25 
26 namespace JFIT {
27 
28  /**
29  * Data structure for track fit results.
30  */
31  class JFit :
32  public TObject,
33  public JHistory
34  {
35  public:
36  /**
37  * Default constructor.
38  * Parameters are initialized with non physical values
39  */
40  JFit():
41  __x( -std::numeric_limits<double>::max() ),
42  __y( -std::numeric_limits<double>::max() ),
43  __z( -std::numeric_limits<double>::max() ),
44  __dx(0.0),
45  __dy(0.0),
46  __dz(0.0),
47  __t( -std::numeric_limits<double>::max() ),
48  __Q( -std::numeric_limits<double>::max() ),
49  __NDF(-1),
50  __E(0.0),
51  __status(-1)
52  {}
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param history history
59  * \param x X-position
60  * \param y Y-position
61  * \param z Z-position
62  * \param dx X-slope
63  * \param dy Y-slope
64  * \param dz Z-slope
65  * \param t time
66  * \param Q quality
67  * \param NDF number of degrees of freedom
68  * \param E energy
69  * \param status status
70  */
71  JFit(const JHistory& history,
72  const double x,
73  const double y,
74  const double z,
75  const double dx,
76  const double dy,
77  const double dz,
78  const double t,
79  const double Q,
80  const int NDF,
81  const double E = 0.0,
82  const int status = -1) :
83  JHistory(history)
84  {
85  __x = x;
86  __y = y;
87  __z = z;
88  __dx = dx;
89  __dy = dy;
90  __dz = dz;
91  __t = t;
92  __Q = Q;
93  __NDF = NDF;
94  __E = E;
95  __status = status;
96  }
97 
98 
99  /**
100  * Constructor for storing position only.\n
101  * Note that the type of fit can be obtained via the history information.
102  *
103  * \param history history
104  * \param x X-position
105  * \param y Y-position
106  * \param z Z-position
107  * \param status status
108  */
109  JFit(const JHistory& history,
110  const double x,
111  const double y,
112  const double z,
113  const int status = -1):
114  JHistory(history)
115  {
116  __x = x;
117  __y = y;
118  __z = z;
119  __dx = 0.0;
120  __dy = 0.0;
121  __dz = 0.0;
122  __t = 0.0;
123  __Q = 0.0;
124  __NDF = -1;
125  __E = 0.0;
126  __status = status;
127  }
128 
129 
130  /**
131  * Add event to history.
132  *
133  * \param type application type
134  * \return this fit
135  */
136  JFit& add(const int type)
137  {
138  getHistory().add(type);
139 
140  return *this;
141  }
142 
143 
144  double getX() const { return __x; } //!< Get X-position.
145  double getY() const { return __y; } //!< Get Y-position.
146  double getZ() const { return __z; } //!< Get Z-position.
147  double getDX() const { return __dx; } //!< Get X-slope.
148  double getDY() const { return __dy; } //!< Get Y-slope.
149  double getDZ() const { return __dz; } //!< Get Z-slope.
150  double getT() const { return __t; } //!< Get time.
151  double getQ() const { return __Q; } //!< Get quality.
152  int getNDF() const { return __NDF; } //!< Get number of degrees of freedom.
153  double getE() const { return __E; } //!< Get energy.
154  int getStatus() const { return __status; } //!< Get status of the fit; negative values should refer to a bad fit.
155 
156 
157  /**
158  * Move vertex along this track with given velocity.
159  *
160  * \param step step
161  * \param velocity velocity
162  */
163  void move(const double step, const double velocity)
164  {
165  __x += step * __dx;
166  __y += step * __dy;
167  __z += step * __dz;
168  __t += step / velocity;
169  }
170 
171 
172  /**
173  * Set energy.
174  *
175  * \param E energy
176  */
177  void setE(const double E)
178  {
179  __E = E;
180  }
181 
182 
183  /**
184  * Get values.
185  *
186  * \return values
187  */
188  const std::vector<double>& getW() const
189  {
190  return this->W;
191  }
192 
193 
194  /**
195  * Set values.
196  *
197  * \param W values
198  */
200  {
201  this->W = W;
202  }
203 
204 
205  /**
206  * Get number of values.
207  *
208  * \return number of values
209  */
210  int getN() const
211  {
212  return W.size();
213  }
214 
215 
216  /**
217  * Check availability of value.
218  *
219  * \param i index
220  * \return true if available; else false
221  */
222  bool hasW(const int i) const
223  {
224  return (i >= 0 && i < (int) W.size());
225  }
226 
227 
228  /**
229  * Get value.
230  *
231  * \param i index
232  * \return value
233  */
234  double getW(const int i) const
235  {
236  return W.at(i);
237  }
238 
239 
240  /**
241  * Get value.
242  *
243  * \param i index
244  * \param value default value
245  * \return value
246  */
247  double getW(const int i, const double value) const
248  {
249  if (hasW(i))
250  return W.at(i);
251  else
252  return value;
253  }
254 
255 
256  /**
257  * Set value.
258  *
259  * \param i index
260  * \param value value
261  */
262  void setW(const int i, const double value)
263  {
264  if (i >= (int) W.size()) {
265  W.resize(i + 1, 0.0);
266  }
267 
268  W[i] = value;
269  }
270 
271 
272  ClassDef(JFit, 5);
273 
274  protected:
275  double __x;
276  double __y;
277  double __z;
278  double __dx;
279  double __dy;
280  double __dz;
281  double __t;
282  double __Q;
283  int __NDF;
285  double __E;
286  int __status;
287  };
288 
289 
290  /**
291  * Data structure for set of track fit results.
292  */
293  class JEvt :
294  public TObject,
295  public std::vector<JFit>
296  {
297  public:
298  /**
299  * Default constructor.
300  */
302  {}
303 
304 
305  /**
306  * Select fits.
307  *
308  * \param select fit selection
309  */
310  template<class JPredicate_t>
311  void partition(JPredicate_t select)
312  {
313  this->erase(std::partition(this->begin(), this->end(), select), this->end());
314  }
315 
316 
317  /**
318  * Write event to output.
319  *
320  * \param out output stream
321  * \param event event
322  * \return output stream
323  */
324  friend inline std::ostream& operator<<(std::ostream& out, const JEvt& event)
325  {
326  using namespace std;
327 
328  out << "Event: " << endl;
329 
330  for (JEvt::const_iterator fit = event.begin(); fit != event.end(); ++fit) {
331  out << *fit;
332  }
333 
334  return out;
335  }
336 
337 
338  ClassDef(JEvt, 3);
339  };
340 }
341 
342 
343 /**
344  * Write fit results to output.
345  *
346  * \param out output stream
347  * \param fit fit results
348  * \return output stream
349  */
350 std::ostream& operator<<(std::ostream& out, const JFIT::JFit& fit);
351 
352 
353 /**
354  * Get TTree parameters for given data type.
355  *
356  * \return TTree parameters
357  */
359 {
360  return JROOT::JTreeParameters("EVT", "evt", "", 0);
361 }
362 
363 
364 #endif
JFIT::JFit::getZ
double getZ() const
Get Z-position.
Definition: JEvt.hh:146
JFIT::JFit::getDX
double getDX() const
Get X-slope.
Definition: JEvt.hh:147
JFIT::JFit::setW
void setW(const std::vector< double > &W)
Set values.
Definition: JEvt.hh:199
JHistory.hh
JFIT::JFit::getW
double getW(const int i, const double value) const
Get value.
Definition: JEvt.hh:247
TObject
Definition: JRoot.hh:19
JFIT::JFit::__t
double __t
Definition: JEvt.hh:281
JLANG::JType
Auxiliary class for a type holder.
Definition: JType.hh:19
JFIT
Auxiliary classes and methods for linear and iterative data regression.
Definition: JEnergy.hh:15
JFIT::JFit::hasW
bool hasW(const int i) const
Check availability of value.
Definition: JEvt.hh:222
JFIT::JFit::add
JFit & add(const int type)
Add event to history.
Definition: JEvt.hh:136
JFIT::JFit::__dz
double __dz
Definition: JEvt.hh:280
JFIT::JFit::getN
int getN() const
Get number of values.
Definition: JEvt.hh:210
JTreeParameters.hh
JFIT::JFit::__z
double __z
Definition: JEvt.hh:277
JFIT::JEvt::ClassDef
ClassDef(JEvt, 3)
std::vector< double >
JFIT::JFit::getE
double getE() const
Get energy.
Definition: JEvt.hh:153
JFIT::JFit::getDZ
double getDZ() const
Get Z-slope.
Definition: JEvt.hh:149
JFIT::JFit::getW
double getW(const int i) const
Get value.
Definition: JEvt.hh:234
JFIT::JEvt
Data structure for set of track fit results.
Definition: JEvt.hh:293
JFIT::JFit::getW
const std::vector< double > & getW() const
Get values.
Definition: JEvt.hh:188
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JFIT::JFit::getQ
double getQ() const
Get quality.
Definition: JEvt.hh:151
JFIT::JFit::ClassDef
ClassDef(JFit, 5)
JFIT::JFit::__Q
double __Q
Definition: JEvt.hh:282
JFIT::JFit::setE
void setE(const double E)
Set energy.
Definition: JEvt.hh:177
JFIT::JFit::getNDF
int getNDF() const
Get number of degrees of freedom.
Definition: JEvt.hh:152
JFIT::JFit::setW
void setW(const int i, const double value)
Set value.
Definition: JEvt.hh:262
JFIT::JFit::__y
double __y
Definition: JEvt.hh:276
JFIT::JFit::W
std::vector< double > W
Definition: JEvt.hh:284
JFIT::JEvt::JEvt
JEvt()
Default constructor.
Definition: JEvt.hh:301
JFIT::JEvt::operator<<
friend std::ostream & operator<<(std::ostream &out, const JEvt &event)
Write event to output.
Definition: JEvt.hh:324
JFIT::JFit::getStatus
int getStatus() const
Get status of the fit; negative values should refer to a bad fit.
Definition: JEvt.hh:154
JFIT::JFit::JFit
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.
Definition: JEvt.hh:71
JFIT::JFit::__NDF
int __NDF
Definition: JEvt.hh:283
JFIT::JEvt::partition
void partition(JPredicate_t select)
Select fits.
Definition: JEvt.hh:311
JFIT::JFit::move
void move(const double step, const double velocity)
Move vertex along this track with given velocity.
Definition: JEvt.hh:163
JFIT::JFit::getX
double getX() const
Get X-position.
Definition: JEvt.hh:144
JFIT::JFit::__E
double __E
Definition: JEvt.hh:285
JFIT::JFit::JFit
JFit(const JHistory &history, const double x, const double y, const double z, const int status=-1)
Constructor for storing position only.
Definition: JEvt.hh:109
std
Definition: jaanetDictionary.h:36
JFIT::JFit::JFit
JFit()
Default constructor.
Definition: JEvt.hh:40
JFIT::JFit::__dx
double __dx
Definition: JEvt.hh:278
JFIT::JFit::getDY
double getDY() const
Get Y-slope.
Definition: JEvt.hh:148
JRoot.hh
JFIT::JHistory
Container for historical events.
Definition: JHistory.hh:95
operator<<
std::ostream & operator<<(std::ostream &out, const JFIT::JFit &fit)
Write fit results to output.
Definition: JEvt.cc:12
JFIT::JFit::getT
double getT() const
Get time.
Definition: JEvt.hh:150
JFIT::JFit::getY
double getY() const
Get Y-position.
Definition: JEvt.hh:145
JFIT::JFit::__status
int __status
Definition: JEvt.hh:286
JType.hh
JFIT::JFit::__x
double __x
Definition: JEvt.hh:275
JFIT::JHistory::add
JHistory & add(const int type)
Add event to history.
Definition: JHistory.hh:248
JFIT::JFit::__dy
double __dy
Definition: JEvt.hh:279
JFIT::JFit
Data structure for track fit results.
Definition: JEvt.hh:31
JFIT::JHistory::getHistory
const JHistory & getHistory() const
Get history.
Definition: JHistory.hh:225
getTreeParameters
JROOT::JTreeParameters getTreeParameters(JLANG::JType< JFIT::JEvt >)
Get TTree parameters for given data type.
Definition: JEvt.hh:358
JROOT::JTreeParameters
Data structure for TTree parameters.
Definition: JTreeParameters.hh:26