Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
11 #include <TROOT.h>
12 #include <TObject.h>
13 
14 #include "JLang/JType.hh"
15 #include "JROOT/JRoot.hh"
16 #include "JROOT/JTreeParameters.hh"
17 
19 
20 /**
21  * \author mdejong
22  */
23 
24 namespace JRECONSTRUCTION {}
25 namespace JPP { using namespace JRECONSTRUCTION; }
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>::lowest()),
43  __y(std::numeric_limits<double>::lowest()),
44  __z(std::numeric_limits<double>::lowest()),
45  __dx(0.0),
46  __dy(0.0),
47  __dz(0.0),
48  __t(std::numeric_limits<double>::lowest()),
49  __Q(std::numeric_limits<double>::lowest()),
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.\n
102  * Note that the type of fit can be obtained via the history information.
103  *
104  * \param history history
105  * \param x X-position
106  * \param y Y-position
107  * \param z Z-position
108  * \param status status
109  */
110  JFit(const JHistory& history,
111  const double x,
112  const double y,
113  const double z,
114  const int status = -1):
115  JHistory(history)
116  {
117  __x = x;
118  __y = y;
119  __z = z;
120  __dx = 0.0;
121  __dy = 0.0;
122  __dz = 0.0;
123  __t = 0.0;
124  __Q = 0.0;
125  __NDF = -1;
126  __E = 0.0;
127  __status = status;
128  }
129 
130 
131  /**
132  * Add event to history.
133  *
134  * \param type application type
135  * \return this fit
136  */
137  JFit& add(const int type)
138  {
139  getHistory().add(type);
140 
141  return *this;
142  }
143 
144 
145  double getX() const { return __x; } //!< Get X-position.
146  double getY() const { return __y; } //!< Get Y-position.
147  double getZ() const { return __z; } //!< Get Z-position.
148  double getDX() const { return __dx; } //!< Get X-slope.
149  double getDY() const { return __dy; } //!< Get Y-slope.
150  double getDZ() const { return __dz; } //!< Get Z-slope.
151  double getT() const { return __t; } //!< Get time.
152  double getQ() const { return __Q; } //!< Get quality.
153  int getNDF() const { return __NDF; } //!< Get number of degrees of freedom.
154  double getE() const { return __E; } //!< Get energy.
155  int getStatus() const { return __status; } //!< Get status of the fit; negative values should refer to a bad fit.
156 
157 
158  /**
159  * Move vertex along this track with given velocity.
160  *
161  * \param step step
162  * \param velocity velocity
163  */
164  void move(const double step, const double velocity)
165  {
166  __x += step * __dx;
167  __y += step * __dy;
168  __z += step * __dz;
169  __t += step / velocity;
170  }
171 
172 
173  /**
174  * Set energy.
175  *
176  * \param E energy
177  */
178  void setE(const double E)
179  {
180  __E = E;
181  }
182 
183 
184  /**
185  * Get values.
186  *
187  * \return values
188  */
189  const std::vector<double>& getW() const
190  {
191  return this->W;
192  }
193 
194 
195  /**
196  * Set values.
197  *
198  * \param W values
199  */
201  {
202  this->W = W;
203  }
204 
205 
206  /**
207  * Get number of values.
208  *
209  * \return number of values
210  */
211  int getN() const
212  {
213  return W.size();
214  }
215 
216 
217  /**
218  * Check availability of value.
219  *
220  * \param i index
221  * \return true if available; else false
222  */
223  bool hasW(const int i) const
224  {
225  return (i >= 0 && i < (int) W.size());
226  }
227 
228 
229  /**
230  * Get value.
231  *
232  * \param i index
233  * \return value
234  */
235  double getW(const int i) const
236  {
237  return W.at(i);
238  }
239 
240 
241  /**
242  * Get value.
243  *
244  * \param i index
245  * \param value default value
246  * \return value
247  */
248  double getW(const int i, const double value) const
249  {
250  if (hasW(i))
251  return W.at(i);
252  else
253  return value;
254  }
255 
256 
257  /**
258  * Set value.
259  *
260  * \param i index
261  * \param value value
262  */
263  void setW(const int i, const double value)
264  {
265  if (i >= (int) W.size()) {
266  W.resize(i + 1, 0.0);
267  }
268 
269  W[i] = value;
270  }
271 
272 
273  ClassDef(JFit, 5);
274 
275  protected:
276  double __x;
277  double __y;
278  double __z;
279  double __dx;
280  double __dy;
281  double __dz;
282  double __t;
283  double __Q;
284  int __NDF;
286  double __E;
287  int __status;
288  };
289 
290 
291  /**
292  * Data structure for set of track fit results.
293  */
294  class JEvt :
295  public TObject,
296  public std::vector<JFit>
297  {
298  public:
299  /**
300  * Default constructor.
301  */
303  {}
304 
305 
306 
307 
308  /**
309  * Select fits.
310  *
311  * \param selector fit selector
312  */
313  template<class JSelector_t>
314  void select(const JSelector_t& selector)
315  {
316  using namespace std;
317 
318  if (!empty()) {
319 
320  iterator __end = partition(this->begin(), this->end(), selector);
321 
322  this->erase(__end, this->end());
323  }
324  }
325 
326 
327  /**
328  * Select fits.
329  *
330  * \param number_of_fits maximal number of best fits to select
331  * \param comparator quality comparator
332  */
333  template<class JComparator_t>
334  void select(const size_t number_of_fits,
335  const JComparator_t& comparator)
336  {
337  using namespace std;
338 
339  if (!empty()) {
340 
341  iterator __end = this->end();
342 
343  if (number_of_fits > 0 && number_of_fits < this->size()) {
344 
345  advance(__end = this->begin(), number_of_fits);
346 
347  partial_sort(this->begin(), __end, this->end(), comparator);
348 
349  } else {
350 
351  sort(this->begin(), __end, comparator);
352  }
353 
354  this->erase(__end, this->end());
355  }
356  }
357 
358 
359  /**
360  * Write event to output.
361  *
362  * \param out output stream
363  * \param event event
364  * \return output stream
365  */
366  friend inline std::ostream& operator<<(std::ostream& out, const JEvt& event)
367  {
368  using namespace std;
369 
370  out << "Event: " << endl;
371 
372  for (JEvt::const_iterator fit = event.begin(); fit != event.end(); ++fit) {
373  out << *fit;
374  }
375 
376  return out;
377  }
378 
379 
380  ClassDef(JEvt, 3);
381  };
382 }
383 
384 
385 namespace JRECONSTRUCTION {
386  typedef JFIT::JFit JFit;
387  typedef JFIT::JEvt JEvt;
388 }
389 
390 
391 /**
392  * Write fit results to output.
393  *
394  * \param out output stream
395  * \param fit fit results
396  * \return output stream
397  */
398 std::ostream& operator<<(std::ostream& out, const JRECONSTRUCTION::JFit& fit);
399 
400 
401 /**
402  * Get TTree parameters for given data type.
403  *
404  * \return TTree parameters
405  */
407 {
408  return JROOT::JTreeParameters("EVT", "evt", "", 0);
409 }
410 
411 #endif
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.
JHistory & add(const int type)
Add event to history.
Definition: JHistory.hh:251
friend std::ostream & operator<<(std::ostream &out, const JEvt &event)
Write event to output.
void setW(const std::vector< double > &W)
Set values.
void setE(const double E)
Set energy.
void select(const size_t number_of_fits, const JComparator_t &comparator)
Select fits.
int getNDF() const
Get number of degrees of freedom.
void setW(const int i, const double value)
Set value.
int getN() const
Get number of values.
Definition: JRoot.hh:19
Container for historical events.
Definition: JHistory.hh:98
This include file serves the purpose of hiding ROOT dependencies and circumphere namespace problems w...
Auxiliary class for a type holder.
Definition: JType.hh:19
JFit & add(const int type)
Add event to history.
std::vector< double > W
Data structure for track fit results.
bool hasW(const int i) const
Check availability of value.
double getT() const
Get time.
double getX() const
Get X-position.
ClassDef(JFit, 5)
ClassDef(JEvt, 3)
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
double getY() const
Get Y-position.
int getStatus() const
Get status of the fit; negative values should refer to a bad fit.
Data structure for TTree parameters.
JEvt()
Default constructor.
double getDZ() const
Get Z-slope.
JROOT::JTreeParameters getTreeParameters(JLANG::JType< JRECONSTRUCTION::JEvt >)
Get TTree parameters for given data type.
double getQ() const
Get quality.
Data structure for set of track fit results.
double getZ() const
Get Z-position.
double getW(const int i) const
Get value.
double getW(const int i, const double value) const
Get value.
JFit(const JHistory &history, const double x, const double y, const double z, const int status=-1)
Constructor for storing position only.
double getDY() const
Get Y-slope.
void move(const double step, const double velocity)
Move vertex along this track with given velocity.
const std::vector< double > & getW() const
Get values.
const JHistory & getHistory() const
Get history.
Definition: JHistory.hh:228
void select(const JSelector_t &selector)
Select fits.
double getE() const
Get energy.
double getDX() const
Get X-slope.
then usage $script[input file[working directory[option]]] nWhere option can be E
Definition: JMuonPostfit.sh:37
JFit()
Default constructor.