Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DHelicalFit.h
Go to the documentation of this file.
1 // DHelicalFit: class containing helix-based fitting routines assuming
2 // uniform magnetic field
3 //
4 ///<p>Two sets of helix-based fitting routines are contained in this class:</p>
5 ///
6 /// <h4> Quick Fit: </h4>
7 /// Do a very fast, linear-regression type fit on a set of hits.
8 ///
9 /// <p>This class allows one to define a set of 2D or 3D points
10 /// which can then be fit to a circle (2D) or a helical track (3D)
11 /// via the FitCircle() and FitTrack() methods. This is written
12 /// in a generic way such that either CDC or FDC data or any
13 /// combination of the two can be used.</p>
14 ///
15 /// <p> The QuickFit, as the name implies, is intended to be very fast.
16 /// it will <b>NOT</b> produce a terribly accurate result.</p>
17 ///
18 /// <p>This will hopefully be useful in a couple of places:
19 ///
20 /// -# When trying to find clusters, it can be used to help
21 /// reject outlying hits.
22 /// -# In the Level-3 or filtering application, it can be used
23 /// to quickly identify whether a cluster has a reasonable
24 /// chance of becoming a "track"
25 /// -# To find first-guess parameters for tracks which can
26 /// be used as the starting point for real track fitting.
27 /// </p>
28 ///
29 /// <p>To use this class, simply instantiate it and then repeatedly
30 /// call one of the <i>AddHit</i> methods to add points you want to
31 /// fit. When all of the points have been added, invoke either
32 /// the FitCircle() (2D) or FitTrack() (3D) method to perform the fit.
33 /// Note that since the fits are done using a linear regression
34 /// style and other "one-pass" calculations, there is no iteration.
35 /// It also assumes the same error for each point.</p>
36 ///
37 /// <p>The fit results are stored in public members of the class.
38 /// The x0,y0 members represent the coordinates of the center of
39 /// the 2D circle in whatever units the hits had when added. The
40 /// chisq value is just the sum of the squares of the differences
41 /// between each hit's distance from x0,y0 and \f$ r_0=\sqrt{x_0^2 + y_0^2} \f$.
42 /// p_trans will have the transverse component of the particle's
43 /// momentum.</p>
44 ///
45 /// <p>A few methods are available to remove hits which do not
46 /// match certain criteria. These include PruneHits() and
47 /// PruneWorst() (both of with call PruneHit()). See the notes
48 /// in each for more info.</p>
49 ///
50 /// <h4> 2) Riemann Helical Fit </h4>
51 ///
52 /// <p> This approach also a has a circle fit and an extension to a helix.
53 /// The circle fit maps points on a circle to a Riemann surface such that the
54 /// task of finding the radius and center of a circle for the helix projected
55 /// onto a plane perpendicular to the beam line becomes the task of obtaining
56 /// the normal vector for a plane slicing this surface. The (0,0) point does
57 /// not have to be included for the fit to work, but it can be included as a
58 /// fuzzy fake point to better constrain pT. The extension to a helix for the
59 /// forward direction requires a linear regression relating the arc length
60 /// between measurements and z, from which the dip angle can be determined.</p>
61 
62 #ifndef _DHELICAL_FIT_H_
63 #define _DHELICAL_FIT_H_
64 
65 #include <vector>
66 using namespace std;
67 
68 #include <DMatrix.h>
69 #include <DVector3.h>
70 #include <DVector2.h>
71 #include "FDC/DFDCPseudo.h"
72 #include "CDC/DCDCWire.h"
73 
74 #include "JANA/jerror.h"
75 
76 #include <math.h>
77 #ifndef atan2f
78 #define atan2f(x,y) atan2((double)x,(double)y)
79 #endif
80 
81 class DMagneticFieldMap;
82 
83 typedef struct{
84  float x,y,z; ///< point in lab coordinates
85  double covx,covy,covxy; ///< error info for x and y coordinates
86  double covrphi; /// < error info in RPhi coordinates
87  double covr; /// < error info in radial coordinates
88  float phi_circle; ///< phi angle relative to axis of helix
89  float chisq; ///< chi-sq contribution of this hit
90  bool is_axial; /// True if the wire is a CDC axial wire
91 }DHFHit_t;
92 
93  typedef struct{
95  float covR,z;
97 
98 
100  public:
101  DHelicalFit(void);
102  DHelicalFit(const DHelicalFit &fit);
103  DHelicalFit& operator=(const DHelicalFit& fit);
104  void Copy(const DHelicalFit &fit);
105  ~DHelicalFit();
106  void Reset(void);
107 
108 
109  jerror_t AddStereoHit(const DCDCWire *wire);
110  jerror_t AddHit(float r, float phi, float z);
111  jerror_t AddHitXYZ(float x, float y, float z);
112  jerror_t AddHitXYZ(float x,float y, float z,float covx,float covy,
113  float covxy,bool is_axial=false);
114  jerror_t AddHit(const DFDCPseudo *fdchit);
115  jerror_t PruneHit(int idx);
116  jerror_t Clear(void);
117  jerror_t FitCircle(void);
118  double ChisqCircle(void);
119  jerror_t FitCircleRiemann(float rc=0.);
120  jerror_t FitCircleRiemann(float z_vertex,float BeamRMS);
121  jerror_t FitLineRiemann(void);
122  jerror_t FitCircleStraightTrack();
123  void SearchPtrans(double ptrans_max=9.0, double ptrans_step=0.5);
124  void QuickPtrans(void);
125  jerror_t GuessChargeFromCircleFit(void);
126  jerror_t FitTrack(void);
127  jerror_t FitTrackRiemann(float rc);
128  jerror_t FitCircleAndLineRiemann(float rc);
129  jerror_t FitTrack_FixedZvertex(float z_vertex);
130  jerror_t FitLine_FixedZvertex(float z_vertex);
131  jerror_t Fill_phi_circle(vector<DHFHit_t*> hits, float x0, float y0);
132  inline const vector<DHFHit_t*> GetHits() const {return hits;}
133  inline int GetNhits() const {return hits.size();}
134  inline const DMagneticFieldMap * GetMagneticFieldMap() const {return bfield;}
135  inline float GetBzAvg() const {return Bz_avg;}
136  inline float GetZMean() const {return z_mean;}
137  inline float GetPhiMean() const {return phi_mean;}
138  jerror_t PrintChiSqVector(void) const;
139  jerror_t Print(void) const;
140  void FindSenseOfRotation(void);
141  jerror_t Dump(void) const;
142  inline void SetMagneticFieldMap(const DMagneticFieldMap *map){bfield=map;}
143  // for Riemann plane
144  void GetPlaneParameters(double &c,DVector3 &n){
145  c=c_origin;
146  n.SetXYZ(N[0],N[1],N[2]);
147  };
148 
152  TRACK
153  };
154 
155  float x0,y0,r0;
156  float h; // Sense of rotation in the x-y plane
157  float phi, theta, tanl;
158  float z_vertex;
159  float chisq;
160  int ndof;
161  float dzdphi;
163 
165  double c_origin; // distance to "origin" for Riemann circle fit
166 
167  protected:
168  vector<DHFHit_t*> hits;
169  const DMagneticFieldMap *bfield; ///< pointer to magnetic field map
170  float Bz_avg;
171  float z_mean, phi_mean;
172 
173  jerror_t FillTrackParams(void);
174 
175  private:
176 
177  // Riemann circle fit parameters
178  double N[3];
179  double xavg[3],var_avg;
180 };
181 
182 
183 
184 #endif //_DHELICAL_FIT_H_
bool is_axial
Definition: DHelicalFit.h:90
c Clear()
TVector2 DVector2
Definition: DVector2.h:9
float GetZMean() const
Definition: DHelicalFit.h:136
TVector3 DVector3
Definition: DVector3.h:14
double Bz_avg
void SetMagneticFieldMap(const DMagneticFieldMap *map)
Definition: DHelicalFit.h:142
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
float z_vertex
Definition: DHelicalFit.h:158
locHist_ADCmulti Print()
#define c
#define y
class DFDCPseudo: definition for a reconstructed point in the FDC
Definition: DFDCPseudo.h:74
DVector3 normal
Definition: DHelicalFit.h:164
float chisq
chi-sq contribution of this hit
Definition: DHelicalFit.h:89
const DMagneticFieldMap * bfield
pointer to magnetic field map
Definition: DHelicalFit.h:169
double covrphi
Definition: DHelicalFit.h:86
float GetPhiMean() const
Definition: DHelicalFit.h:137
double covy
Definition: DHelicalFit.h:85
ChiSqSourceType_t chisq_source
Definition: DHelicalFit.h:162
float dzdphi
Definition: DHelicalFit.h:161
const DMagneticFieldMap * GetMagneticFieldMap() const
Definition: DHelicalFit.h:134
vector< DHFHit_t * > hits
Definition: DHelicalFit.h:168
float z_mean
Definition: DHelicalFit.h:171
const vector< DHFHit_t * > GetHits() const
Definition: DHelicalFit.h:132
float phi_circle
&lt; error info in radial coordinates
Definition: DHelicalFit.h:88
float GetBzAvg() const
Definition: DHelicalFit.h:135
double c_origin
Definition: DHelicalFit.h:165
float Bz_avg
Definition: DHelicalFit.h:170
#define BeamRMS
float z
point in lab coordinates
Definition: DHelicalFit.h:84
double covr
&lt; error info in RPhi coordinates
Definition: DHelicalFit.h:87
void GetPlaneParameters(double &c, DVector3 &n)
Definition: DHelicalFit.h:144
int GetNhits() const
Definition: DHelicalFit.h:133