Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "Jeep/JPrint.hh"
14 #include "JLang/JType.hh"
15 #include "JROOT/JRoot.hh"
16 #include "JROOT/JTreeParameters.hh"
17 
18 #include "JFit/JHistory.hh"
19 
20 /**
21  * \author mdejong
22  */
23 
24 namespace JFIT {}
25 namespace JPP { using namespace JFIT; }
26 
27 namespace JFIT {
28 
29  /**
30  * Data structure for track fit results.
31  */
32  class JFit :
33  public TObject,
34  public JHistory
35  {
36  public:
37  /**
38  * Default constructor.
39  * Parameters are initialized with non physical values
40  */
41  JFit():
42  __x( -std::numeric_limits<double>::max() ),
43  __y( -std::numeric_limits<double>::max() ),
44  __z( -std::numeric_limits<double>::max() ),
45  __dx(0.0),
46  __dy(0.0),
47  __dz(0.0),
48  __t( -std::numeric_limits<double>::max() ),
49  __Q( -std::numeric_limits<double>::max() ),
50  __NDF(-1),
51  __E(0.0),
52  __status(-1)
53  {}
54 
55 
56  /**
57  * Constructor.
58  *
59  * \param history history
60  * \param x X-position
61  * \param y Y-position
62  * \param z Z-position
63  * \param dx X-slope
64  * \param dy Y-slope
65  * \param dz Z-slope
66  * \param t time
67  * \param Q quality
68  * \param NDF number of degrees of freedom
69  * \param E energy
70  * \param status status
71  */
72  JFit(const JHistory& history,
73  const double x,
74  const double y,
75  const double z,
76  const double dx,
77  const double dy,
78  const double dz,
79  const double t,
80  const double Q,
81  const int NDF,
82  const double E = 0.0,
83  const int status = -1) :
84  JHistory(history)
85  {
86  __x = x;
87  __y = y;
88  __z = z;
89  __dx = dx;
90  __dy = dy;
91  __dz = dz;
92  __t = t;
93  __Q = Q;
94  __NDF = NDF;
95  __E = E;
96  __status = status;
97  }
98 
99 
100  /**
101  * Constructor for storing position only. We keep it inside of JFit in order to restrict the ROOT-TObject participation in the software
102  * Whether this is related to a Position or a real fit can be obtained via JFitApplication_t
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 JFitApplication_t& 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 number of values.
185  *
186  * \return number of values
187  */
188  int getN() const
189  {
190  return W.size();
191  }
192 
193 
194  /**
195  * Check availability of value.
196  *
197  * \param i index
198  * \return true if available; else false
199  */
200  bool hasW(const int i) const
201  {
202  return (i >= 0 && i < (int) W.size());
203  }
204 
205 
206  /**
207  * Get value.
208  *
209  * \param i index
210  * \return value
211  */
212  double getW(const int i) const
213  {
214  return W.at(i);
215  }
216 
217 
218  /**
219  * Get value.
220  *
221  * \param i index
222  * \param value default value
223  * \return value
224  */
225  double getW(const int i, const double value) const
226  {
227  if (hasW(i))
228  return W.at(i);
229  else
230  return value;
231  }
232 
233 
234  /**
235  * Set value.
236  *
237  * \param i index
238  * \param value value
239  */
240  void setW(const int i, const double value)
241  {
242  if (i >= (int) W.size()) {
243  W.resize(i + 1, 0.0);
244  }
245 
246  W[i] = value;
247  }
248 
249 
250  /**
251  * Write fit results to output.
252  *
253  * \param out output stream
254  * \param fit fit results
255  * \return output stream
256  */
257  friend inline std::ostream& operator<<(std::ostream& out, const JFit& fit)
258  {
259  using namespace std;
260 
261  const JHistory& history = fit.getHistory();
262 
263  out << "history:";
264 
265  for (JHistory::const_reverse_iterator i = history.rbegin(); i != history.rend(); ++i) {
266  out << ' ' << i->type;
267  }
268 
269  out << endl;
270 
271  out << "x " << FIXED(7,2) << fit.getX() << endl;
272  out << "y " << FIXED(7,2) << fit.getY() << endl;
273  out << "z " << FIXED(7,2) << fit.getZ() << endl;
274  out << "dx " << FIXED(7,3) << fit.getDX() << endl;
275  out << "dy " << FIXED(7,3) << fit.getDY() << endl;
276  out << "dz " << FIXED(7,3) << fit.getDZ() << endl;
277 
278  out << "Q " << FIXED(12,5) << fit.getQ() << endl;
279  out << "NDF " << setw(5) << fit.getNDF() << endl;
280 
281  out << "status " << fit.getStatus() << endl;
282 
283  for (int i = 0; i != fit.getN(); ++i) {
284  out << "W[" << i << "] = " << FIXED(10,5) << fit.getW(i) << endl;
285  }
286 
287  return out;
288  }
289 
290 
291  ClassDef(JFit, 5);
292 
293  protected:
294  double __x;
295  double __y;
296  double __z;
297  double __dx;
298  double __dy;
299  double __dz;
300  double __t;
301  double __Q;
302  int __NDF;
304  double __E;
305  int __status;
306  };
307 
308 
309  /**
310  * Data structure for set of track fit results.
311  */
312  class JEvt :
313  public TObject,
314  public std::vector<JFit>
315  {
316  public:
317  /**
318  * Default constructor.
319  */
321  {}
322 
323 
324  /**
325  * Select fits.
326  *
327  * \param select fit selection
328  */
329  template<class JPredicate_t>
330  void partition(JPredicate_t select)
331  {
332  this->erase(std::partition(this->begin(), this->end(), select), this->end());
333  }
334 
335 
336  /**
337  * Write event to output.
338  *
339  * \param out output stream
340  * \param event event
341  * \return output stream
342  */
343  friend inline std::ostream& operator<<(std::ostream& out, const JEvt& event)
344  {
345  using namespace std;
346 
347  out << "Event: " << endl;
348 
349  for (JEvt::const_iterator fit = event.begin(); fit != event.end(); ++fit) {
350  out << *fit;
351  }
352 
353  return out;
354  }
355 
356 
357  ClassDef(JEvt, 3);
358  };
359 }
360 
361 
362 /**
363  * Get TTree parameters for given data type.
364  *
365  * \return TTree parameters
366  */
368 {
369  return JROOT::JTreeParameters("EVT", "evt", "", 0);
370 }
371 
372 
373 #endif
friend std::ostream & operator<<(std::ostream &out, const JFit &fit)
Write fit results to output.
Definition: JEvt.hh:257
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:72
friend std::ostream & operator<<(std::ostream &out, const JEvt &event)
Write event to output.
Definition: JEvt.hh:343
double __dy
Definition: JEvt.hh:298
int __NDF
Definition: JEvt.hh:302
void setE(const double E)
Set energy.
Definition: JEvt.hh:177
double __z
Definition: JEvt.hh:296
int getNDF() const
Get number of degrees of freedom.
Definition: JEvt.hh:152
void setW(const int i, const double value)
Set value.
Definition: JEvt.hh:240
int getN() const
Get number of values.
Definition: JEvt.hh:188
int __status
Definition: JEvt.hh:305
Definition: JRoot.hh:19
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
Container for historical events.
Definition: JHistory.hh:95
This include file serves the purpose of hiding ROOT dependencies and circumphere namespace problems w...
double __y
Definition: JEvt.hh:295
Auxiliary class for a type holder.
Definition: JType.hh:19
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:461
std::vector< double > W
Definition: JEvt.hh:303
Data structure for track fit results.
Definition: JEvt.hh:32
double __E
Definition: JEvt.hh:304
I/O formatting auxiliaries.
bool hasW(const int i) const
Check availability of value.
Definition: JEvt.hh:200
JROOT::JTreeParameters getTreeParameters(JLANG::JType< JFIT::JEvt >)
Get TTree parameters for given data type.
Definition: JEvt.hh:367
double getT() const
Get time.
Definition: JEvt.hh:150
double getX() const
Get X-position.
Definition: JEvt.hh:144
double __t
Definition: JEvt.hh:300
ClassDef(JFit, 5)
double getY() const
Get Y-position.
Definition: JEvt.hh:145
int getStatus() const
Get status of the fit; negative values should refer to a bad fit.
Definition: JEvt.hh:154
Data structure for TTree parameters.
JEvt()
Default constructor.
Definition: JEvt.hh:320
double getDZ() const
Get Z-slope.
Definition: JEvt.hh:149
double getQ() const
Get quality.
Definition: JEvt.hh:151
double __dx
Definition: JEvt.hh:297
Data structure for set of track fit results.
Definition: JEvt.hh:312
double getZ() const
Get Z-position.
Definition: JEvt.hh:146
JFit & add(const JFitApplication_t &type)
Add event to history.
Definition: JEvt.hh:136
double __dz
Definition: JEvt.hh:299
double getW(const int i) const
Get value.
Definition: JEvt.hh:212
double getW(const int i, const double value) const
Get value.
Definition: JEvt.hh:225
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
double getDY() const
Get Y-slope.
Definition: JEvt.hh:148
void move(const double step, const double velocity)
Move vertex along this track with given velocity.
Definition: JEvt.hh:163
const JHistory & getHistory() const
Get history.
Definition: JHistory.hh:225
void partition(JPredicate_t select)
Select fits.
Definition: JEvt.hh:330
double __Q
Definition: JEvt.hh:301
double getE() const
Get energy.
Definition: JEvt.hh:153
double getDX() const
Get X-slope.
Definition: JEvt.hh:147
JHistory & add(const JFitApplication_t &type)
Add event to history.
Definition: JHistory.hh:248
double __x
Definition: JEvt.hh:294
JFit()
Default constructor.
Definition: JEvt.hh:41