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. We keep it inside of JFit in order to restrict the ROOT-TObject participation in the software
101  * Whether this is related to a Position or a real fit can be obtained via JFitApplication_t
102  * \param history history
103  * \param x X-position
104  * \param y Y-position
105  * \param z Z-position
106  * \param status status
107  */
108  JFit(const JHistory& history,
109  const double x,
110  const double y,
111  const double z,
112  const int status = -1):
113  JHistory(history)
114  {
115  __x = x;
116  __y = y;
117  __z = z;
118  __dx = 0.0;
119  __dy = 0.0;
120  __dz = 0.0;
121  __t = 0.0;
122  __Q = 0.0;
123  __NDF = -1;
124  __E = 0.0;
125  __status = status;
126  }
127 
128 
129  /**
130  * Add event to history.
131  *
132  * \param type application type
133  * \return this fit
134  */
135  JFit& add(const JFitApplication_t& type)
136  {
137  getHistory().add(type);
138 
139  return *this;
140  }
141 
142 
143  double getX() const { return __x; } //!< Get X-position.
144  double getY() const { return __y; } //!< Get Y-position.
145  double getZ() const { return __z; } //!< Get Z-position.
146  double getDX() const { return __dx; } //!< Get X-slope.
147  double getDY() const { return __dy; } //!< Get Y-slope.
148  double getDZ() const { return __dz; } //!< Get Z-slope.
149  double getT() const { return __t; } //!< Get time.
150  double getQ() const { return __Q; } //!< Get quality.
151  int getNDF() const { return __NDF; } //!< Get number of degrees of freedom.
152  double getE() const { return __E; } //!< Get energy.
153  int getStatus() const { return __status; } //!< Get status of the fit; negative values should refer to a bad fit.
154 
155 
156  /**
157  * Move vertex along this track with given velocity.
158  *
159  * \param step step
160  * \param velocity velocity
161  */
162  void move(const double step, const double velocity)
163  {
164  __x += step * __dx;
165  __y += step * __dy;
166  __z += step * __dz;
167  __t += step / velocity;
168  }
169 
170 
171  /**
172  * Set energy.
173  *
174  * \param E energy
175  */
176  void setE(const double E)
177  {
178  __E = E;
179  }
180 
181 
182  /**
183  * Get values.
184  *
185  * \return values
186  */
187  const std::vector<double>& getW() const
188  {
189  return this->W;
190  }
191 
192 
193  /**
194  * Set values.
195  *
196  * \param W values
197  */
199  {
200  this->W = W;
201  }
202 
203 
204  /**
205  * Get number of values.
206  *
207  * \return number of values
208  */
209  int getN() const
210  {
211  return W.size();
212  }
213 
214 
215  /**
216  * Check availability of value.
217  *
218  * \param i index
219  * \return true if available; else false
220  */
221  bool hasW(const int i) const
222  {
223  return (i >= 0 && i < (int) W.size());
224  }
225 
226 
227  /**
228  * Get value.
229  *
230  * \param i index
231  * \return value
232  */
233  double getW(const int i) const
234  {
235  return W.at(i);
236  }
237 
238 
239  /**
240  * Get value.
241  *
242  * \param i index
243  * \param value default value
244  * \return value
245  */
246  double getW(const int i, const double value) const
247  {
248  if (hasW(i))
249  return W.at(i);
250  else
251  return value;
252  }
253 
254 
255  /**
256  * Set value.
257  *
258  * \param i index
259  * \param value value
260  */
261  void setW(const int i, const double value)
262  {
263  if (i >= (int) W.size()) {
264  W.resize(i + 1, 0.0);
265  }
266 
267  W[i] = value;
268  }
269 
270 
271  ClassDef(JFit, 5);
272 
273  protected:
274  double __x;
275  double __y;
276  double __z;
277  double __dx;
278  double __dy;
279  double __dz;
280  double __t;
281  double __Q;
282  int __NDF;
284  double __E;
285  int __status;
286  };
287 
288 
289  /**
290  * Data structure for set of track fit results.
291  */
292  class JEvt :
293  public TObject,
294  public std::vector<JFit>
295  {
296  public:
297  /**
298  * Default constructor.
299  */
301  {}
302 
303 
304  /**
305  * Select fits.
306  *
307  * \param select fit selection
308  */
309  template<class JPredicate_t>
310  void partition(JPredicate_t select)
311  {
312  this->erase(std::partition(this->begin(), this->end(), select), this->end());
313  }
314 
315 
316  /**
317  * Write event to output.
318  *
319  * \param out output stream
320  * \param event event
321  * \return output stream
322  */
323  friend inline std::ostream& operator<<(std::ostream& out, const JEvt& event)
324  {
325  using namespace std;
326 
327  out << "Event: " << endl;
328 
329  for (JEvt::const_iterator fit = event.begin(); fit != event.end(); ++fit) {
330  out << *fit;
331  }
332 
333  return out;
334  }
335 
336 
337  ClassDef(JEvt, 3);
338  };
339 }
340 
341 
342 /**
343  * Write fit results to output.
344  *
345  * \param out output stream
346  * \param fit fit results
347  * \return output stream
348  */
349 std::ostream& operator<<(std::ostream& out, const JFIT::JFit& fit);
350 
351 
352 /**
353  * Get TTree parameters for given data type.
354  *
355  * \return TTree parameters
356  */
358 {
359  return JROOT::JTreeParameters("EVT", "evt", "", 0);
360 }
361 
362 
363 #endif
JFIT::JFit::getZ
double getZ() const
Get Z-position.
Definition: JEvt.hh:145
JFIT::JFit::getDX
double getDX() const
Get X-slope.
Definition: JEvt.hh:146
JFIT::JFit::setW
void setW(const std::vector< double > &W)
Set values.
Definition: JEvt.hh:198
JHistory.hh
JFIT::JFit::getW
double getW(const int i, const double value) const
Get value.
Definition: JEvt.hh:246
TObject
Definition: JRoot.hh:19
JFIT::JFit::__t
double __t
Definition: JEvt.hh:280
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:221
JFIT::JFit::__dz
double __dz
Definition: JEvt.hh:279
JFIT::JFit::getN
int getN() const
Get number of values.
Definition: JEvt.hh:209
JTreeParameters.hh
JFIT::JFit::__z
double __z
Definition: JEvt.hh:276
JFIT::JEvt::ClassDef
ClassDef(JEvt, 3)
std::vector< double >
JFIT::JFit::getE
double getE() const
Get energy.
Definition: JEvt.hh:152
JFIT::JFitApplication_t
JFitApplication_t
Definition: JFitApplications.hh:20
JFIT::JFit::getDZ
double getDZ() const
Get Z-slope.
Definition: JEvt.hh:148
JFIT::JFit::getW
double getW(const int i) const
Get value.
Definition: JEvt.hh:233
JFIT::JEvt
Data structure for set of track fit results.
Definition: JEvt.hh:292
JFIT::JFit::getW
const std::vector< double > & getW() const
Get values.
Definition: JEvt.hh:187
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:150
JFIT::JFit::ClassDef
ClassDef(JFit, 5)
JFIT::JFit::__Q
double __Q
Definition: JEvt.hh:281
JFIT::JFit::setE
void setE(const double E)
Set energy.
Definition: JEvt.hh:176
JFIT::JFit::getNDF
int getNDF() const
Get number of degrees of freedom.
Definition: JEvt.hh:151
JFIT::JFit::setW
void setW(const int i, const double value)
Set value.
Definition: JEvt.hh:261
JFIT::JFit::__y
double __y
Definition: JEvt.hh:275
JFIT::JFit::W
std::vector< double > W
Definition: JEvt.hh:283
JFIT::JEvt::JEvt
JEvt()
Default constructor.
Definition: JEvt.hh:300
JFIT::JEvt::operator<<
friend std::ostream & operator<<(std::ostream &out, const JEvt &event)
Write event to output.
Definition: JEvt.hh:323
JFIT::JFit::getStatus
int getStatus() const
Get status of the fit; negative values should refer to a bad fit.
Definition: JEvt.hh:153
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:282
JFIT::JEvt::partition
void partition(JPredicate_t select)
Select fits.
Definition: JEvt.hh:310
JFIT::JFit::move
void move(const double step, const double velocity)
Move vertex along this track with given velocity.
Definition: JEvt.hh:162
JFIT::JFit::getX
double getX() const
Get X-position.
Definition: JEvt.hh:143
JFIT::JFit::__E
double __E
Definition: JEvt.hh:284
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:108
std
Definition: jaanetDictionary.h:36
JFIT::JFit::JFit
JFit()
Default constructor.
Definition: JEvt.hh:40
JFIT::JFit::__dx
double __dx
Definition: JEvt.hh:277
JFIT::JFit::getDY
double getDY() const
Get Y-slope.
Definition: JEvt.hh:147
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::add
JFit & add(const JFitApplication_t &type)
Add event to history.
Definition: JEvt.hh:135
JFIT::JFit::getT
double getT() const
Get time.
Definition: JEvt.hh:149
JFIT::JFit::getY
double getY() const
Get Y-position.
Definition: JEvt.hh:144
JFIT::JFit::__status
int __status
Definition: JEvt.hh:285
JType.hh
JFIT::JFit::__x
double __x
Definition: JEvt.hh:274
JFIT::JFit::__dy
double __dy
Definition: JEvt.hh:278
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:357
JROOT::JTreeParameters
Data structure for TTree parameters.
Definition: JTreeParameters.hh:26
JFIT::JHistory::add
JHistory & add(const JFitApplication_t &type)
Add event to history.
Definition: JHistory.hh:248