Track.h
Go to the documentation of this file.
1 //
2 // Track.hpp
3 // garsoft-mrb
4 //
5 // Created by Brian Rebel on 10/6/16.
6 // original Copyright 2016 Brian Rebel. All rights reserved.
7 // Additions by Tom Junk, 2018
8 // Little cute additions by Leo Bellantoni, 2019
9 
10 #ifndef Track_hpp
11 #define Track_hpp
12 
13 #include <stdio.h>
14 #include "RtypesCore.h"
15 #include <stdint.h>
16 #include "IDNumberGen.h"
17 
18 
19 
20 namespace gar {
21  namespace rec {
22 
23 
24 
25  // Sometimes we need to specify which end of the track we are using, as in
26  // vertexing. If the Start/Vtx/beg end of track i is used, want true for
27  // the TrackEnd; if the far/End end, use false. However, we can't use a bool
28  // because the C++ STL does wierd stuff to make std::vector<bool> efficient...
29  // thereby breaking all our code. Another thing that will break code is
30  // changing the numeric values (1, 0) of TrackEndBeg and TrackEndEnd. Don't
31  // do that casually, OK? Thanks.
32  typedef int TrackEnd;
33  TrackEnd const TrackEndBeg = 1; TrackEnd const TrackEndEnd = 0;
34 
35 
36 
37  class Track {
38 
39  public:
40  Track();
41 
42  // let the compiler provide the dtor
43 
44 
45 
46  private:
47  static gar::rec::IDNumber const FirstNumber = 100000;
49 
50  float fLengthforwards; ///< length of the track in cm from forwards fit
51  float fLengthbackwards; ///< length of the track in cm from backwards fit
52  float fMomentum_beg; ///< momentum of the track at the vertex in GeV/c
53  float fMomentum_end; ///< momentum of the track at the end in GeV/c
54  float fVertex[3]; ///< track vertex position in cm -- == "beginning" of track. Arbitrary choice made by patrec
55  float fEnd[3]; ///< track end position in cm
56  float fVtxDir[3]; ///< track vertex direction
57  float fEndDir[3]; ///< track end direction
58  float fChisqForward; ///< chisquared forward fit
59  float fChisqBackward; ///< chisquared backward fit
60  size_t fNHits; ///< number of hits
61  double fTime; ///< time in ns from trigger
62 
63  // use the x from fVertex and fEnd to specify the independent variable -- no need to store them twice
64 
65  float fTrackParBeg[5]; ///< Track parameters at beginning of track y, z, curvature, phi, lambda -- 5-parameter track (cm, cm, cm-1, radians, radians)
66  float fTrackParEnd[5]; ///< Track parameters at end of track y, z, curvature, phi, lambda -- 5-parameter track (cm, cm, cm-1, radians, radians)
67 
68  float fCovMatBeg[15]; ///< covariance matrix at beginning of track -- packed in a 1D array, assuming symmetry
69  float fCovMatEnd[15]; ///< covariance matrix at end of track
70 
71  #ifndef __GCCXML__
72 
73  public:
74 
75  // Cartesian coordinate constructor -- to be used with the MC Cheater, where
76  // the uncertainties are not specified and are set to zero in the constructor.
77 
78  Track(const float length,
79  const float momentum_beg,
80  const float momentum_end,
81  const float *vtx,
82  const float *end,
83  const float *vtxDir,
84  const float *endDir,
85  const size_t nhits,
86  const int charge, // units of e. Need this to convert momentum into curvature
87  const double time);
88 
89  // constructor to fill after the fits -- including covariance matrix
90 
91  Track(const float lengthforwards,
92  const float lengthbackwards,
93  const size_t nhits,
94  const float xbeg, // x location at beginning of track in cm
95  const float *trackparbeg, // y, z, curvature, phi, lambda -- 5-parameter track (cm, cm, cm-1, radians, radians)
96  const float *covmatbeg, // covariance matrix at beginning of track -- symmetric 5x5
97  const float chisqforward, // chisquared of forwards fit
98  const float xend, // x location at end of track
99  const float *trackparend, // y, z, curvature, phi, lambda -- 5-parameter track (cm, cm, cm-1, radians, radians)
100  const float *covmatend, // covariance matrix at beginning of track -- symmetric 5x5
101  const float chisqbackward, // chisquared of backwards fit
102  const double time); // timestamp
103 
104  //Track(gar::rec::TrackPar &tp); // constructor using the track parameter class
105 
106  bool operator==(const Track& rhs) const;
107  bool operator!=(const Track& rhs) const;
109 
110  const float* Vertex() const;
111  const float* End() const;
112  const float* VtxDir() const;
113  const float* EndDir() const;
114  float Length(); // returns average length
115  float const& LengthForward() const; // returns length from forward fit
116  float const& LengthBackward() const; // returns length from backward fit
117  float const& Momentum_beg() const;
118  float const& Momentum_end() const;
119  float const& ChisqForward() const;
120  float const& ChisqBackward() const;
121  size_t const& NHits() const;
122  const float* TrackParBeg() const;
123  const float* TrackParEnd() const;
124  void CovMatBegSymmetric(float *cmb) const; // fill a 5x5 array of floats owned by the caller with the values of the covariance matrix at the beginning of the track
125  void CovMatEndSymmetric(float *cme) const; // fill a 5x5 array of floats owned by the caller with the values of the covariance matrix at the beginning of the track
126  const float* CovMatBegPacked() const;
127  const float* CovMatEndPacked() const;
128  int ChargeBeg() const; // Charge if the true particle progressed from Vertex to End
129  int ChargeEnd() const; // Charge if the starting of the particle's track is End not Vertex
130  // the charge assumes the track started at the beginning or the end above, and is expected to change sign
131  // depending on which way the track is hypothesized to go
132  double const& Time() const;
133 
134  // expose this so we can use it elsewhere, and it's used twice in a constructor
135  #endif
136 
137  };
138 
139  inline const float* Track::Vertex() const { return fVertex; }
140  inline const float* Track::End() const { return fEnd; }
141  inline const float* Track::VtxDir() const { return fVtxDir; }
142  inline const float* Track::EndDir() const { return fEndDir; }
143  inline float Track::Length() { return 0.5*(fLengthforwards+fLengthbackwards); }
144  inline float const& Track::LengthForward() const { return fLengthforwards; }
145  inline float const& Track::LengthBackward() const { return fLengthbackwards; }
146  inline float const& Track::Momentum_beg() const { return fMomentum_beg; }
147  inline float const& Track::Momentum_end() const { return fMomentum_end; }
148  inline float const& Track::ChisqForward() const { return fChisqForward; }
149  inline float const& Track::ChisqBackward() const { return fChisqBackward; }
150  inline size_t const& Track::NHits() const { return fNHits; }
151  inline const float* Track::TrackParBeg() const { return fTrackParBeg; }
152  inline const float* Track::TrackParEnd() const { return fTrackParEnd; }
153  inline const float* Track::CovMatBegPacked() const { return fCovMatBeg; }
154  inline const float* Track::CovMatEndPacked() const { return fCovMatEnd; }
155  inline double const& Track::Time() const { return fTime; }
156 
157  // non-class functions
158 
159  // finds a unit vector pointing along the track momentum at one end. If
160  // you want to extrapolate beyond the end, flip the sign of the direction
161  void FindDirectionFromTrackParameters(const float *tparms,
162  const float thisXend,const float farXend, float *dir);
163 
164 
165  } // rec
166 } // gar
167 
168 #endif /* Track_hpp */
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
float fChisqBackward
chisquared backward fit
Definition: Track.h:59
bool operator!=(const Track &rhs) const
Definition: Track.cxx:38
float const & Momentum_beg() const
Definition: Track.h:146
rec
Definition: tracks.py:88
float fChisqForward
chisquared forward fit
Definition: Track.h:58
int TrackEnd
Definition: Track.h:32
const float * TrackParBeg() const
Definition: Track.h:151
float fCovMatBeg[15]
covariance matrix at beginning of track – packed in a 1D array, assuming symmetry ...
Definition: Track.h:68
float fMomentum_beg
momentum of the track at the vertex in GeV/c
Definition: Track.h:52
float fCovMatEnd[15]
covariance matrix at end of track
Definition: Track.h:69
float Length()
Definition: Track.h:143
double fTime
time in ns from trigger
Definition: Track.h:61
float fTrackParBeg[5]
Track parameters at beginning of track y, z, curvature, phi, lambda – 5-parameter track (cm...
Definition: Track.h:65
float fLengthforwards
length of the track in cm from forwards fit
Definition: Track.h:50
float const & LengthBackward() const
Definition: Track.h:145
string dir
TrackEnd const TrackEndEnd
Definition: Track.h:33
static gar::rec::IDNumber const FirstNumber
Definition: Track.h:47
float fLengthbackwards
length of the track in cm from backwards fit
Definition: Track.h:51
float const & ChisqBackward() const
Definition: Track.h:149
size_t fNHits
number of hits
Definition: Track.h:60
const float * VtxDir() const
Definition: Track.h:141
float fMomentum_end
momentum of the track at the end in GeV/c
Definition: Track.h:53
double const & Time() const
Definition: Track.h:155
float const & LengthForward() const
Definition: Track.h:144
const float * Vertex() const
Definition: Track.h:139
int ChargeEnd() const
Definition: Track.cxx:236
int ChargeBeg() const
Definition: Track.cxx:229
float fVertex[3]
track vertex position in cm – == "beginning" of track. Arbitrary choice made by patrec ...
Definition: Track.h:54
const float * TrackParEnd() const
Definition: Track.h:152
float const & ChisqForward() const
Definition: Track.h:148
const float * End() const
Definition: Track.h:140
bool operator==(const Track &rhs) const
Definition: Track.cxx:34
float fEndDir[3]
track end direction
Definition: Track.h:57
float fTrackParEnd[5]
Track parameters at end of track y, z, curvature, phi, lambda – 5-parameter track (cm...
Definition: Track.h:66
General GArSoft Utilities.
float fEnd[3]
track end position in cm
Definition: Track.h:55
TrackEnd const TrackEndBeg
Definition: Track.h:33
float fVtxDir[3]
track vertex direction
Definition: Track.h:56
void FindDirectionFromTrackParameters(const float *tparms, const float thisXend, const float farXend, float *dir)
Definition: Track.cxx:269
gar::rec::IDNumber fIDnumero
Definition: Track.h:48
float const & Momentum_end() const
Definition: Track.h:147
size_t const & NHits() const
Definition: Track.h:150
gar::rec::IDNumber getIDNumber() const
Definition: Track.cxx:42
void CovMatBegSymmetric(float *cmb) const
Definition: Track.cxx:246
const float * CovMatEndPacked() const
Definition: Track.h:154
const float * CovMatBegPacked() const
Definition: Track.h:153
void CovMatEndSymmetric(float *cme) const
Definition: Track.cxx:257
size_t IDNumber
Definition: IDNumberGen.h:71
const float * EndDir() const
Definition: Track.h:142