Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DQuickFit.h
Go to the documentation of this file.
1 // $Id$
2 //
3 /// Do a very fast, linear-regression type fit on a set of hits.
4 ///
5 /// <p>This class allows one to define a set of 2D or 3D points
6 /// which can then be fit to a circle (2D) or a helical track (3D)
7 /// via the FitCircle() and FitTrack() methods. This is written
8 /// in a generic way such that either CDC or FDC data or any
9 /// combination of the two can be used.</p>
10 ///
11 /// <p>DQuickFit, as the name implies, is intended to be very fast.
12 /// it will <b>NOT</b> produce a terribly accurate result.</p>
13 ///
14 /// <p>This will hopefully be useful in a couple of places:
15 ///
16 /// -# When trying to find clusters, it can be used to help
17 /// reject outlying hits.
18 /// -# In the Level-3 or filtering application, it can be used
19 /// to quickly identify whether a cluster has a reasonable
20 /// chance of becoming a "track"
21 /// -# To find first-guess parameters for tracks which can
22 /// be used as the starting point for real track fitting.
23 /// </p>
24 ///
25 /// <p>To use this class, simply instantiate it and then repeatedly
26 /// call one of the <i>AddHit</i> methods to add points you want to
27 /// fit. When all of the points have been added, invoke either
28 /// the FitCircle() (2D) or FitTrack() (3D) method to perform the fit.
29 /// Note that since the fits are done using a linear regression
30 /// style and other "one-pass" calculations, there is no iteration.
31 /// It also assumes the same error for each point.</p>
32 ///
33 /// <p>The fit results are stored in public members of the class.
34 /// The x0,y0 members represent the coordinates of the center of
35 /// the 2D circle in whatever units the hits had when added. The
36 /// chisq value is just the sum of the squares of the differences
37 /// between each hit's distance from x0,y0 and \f$ r_0=\sqrt{x_0^2 + y_0^2} \f$.
38 /// p_trans will have the transverse component of the particle's
39 /// momentum.</p>
40 ///
41 /// <p>A few methods are available to remove hits which do not
42 /// match certain criteria. These include PruneHits() and
43 /// PruneWorst() (both of with call PruneHit()). See the notes
44 /// in each for more info.</p>
45 
46 #ifndef _DQUICK_FIT_H_
47 #define _DQUICK_FIT_H_
48 
49 #include <vector>
50 using namespace std;
51 
52 #include <DVector3.h>
53 
54 #include "JANA/jerror.h"
55 
56 #include <math.h>
57 #ifndef atan2f
58 #define atan2f(x,y) atan2((double)x,(double)y)
59 #endif
60 
61 class DMagneticFieldMap;
62 
63 typedef struct{
64  float x,y,z; ///< point in lab coordinates
65  float phi_circle; ///< phi angle relative to axis of helix
66  float chisq; ///< chi-sq contribution of this hit
67 }DQFHit_t;
68 
69 class DQuickFit{
70  public:
71  DQuickFit(void);
72  DQuickFit(const DQuickFit &fit);
73  DQuickFit& operator=(const DQuickFit& fit);
74  void Copy(const DQuickFit &fit);
75  ~DQuickFit();
76 
77  jerror_t AddHit(float r, float phi, float z);
78  jerror_t AddHitXYZ(float x, float y, float z);
79  jerror_t PruneHit(int idx);
80  jerror_t Clear(void);
81  jerror_t FitCircle(void);
82  double ChisqCircle(void);
83  jerror_t FitCircleRiemann(double BeamRMS=0.100);
84  jerror_t FitCircleStraightTrack();
85  void SearchPtrans(double ptrans_max=9.0, double ptrans_step=0.5);
86  void QuickPtrans(void);
87  jerror_t GuessChargeFromCircleFit(void);
88  jerror_t FitTrack(void);
89  jerror_t FitTrack_FixedZvertex(float z_vertex);
90  jerror_t FitLine_FixedZvertex(float z_vertex);
91  jerror_t Fill_phi_circle(vector<DQFHit_t*> hits, float x0, float y0);
92  inline const vector<DQFHit_t*> GetHits() const {return hits;}
93  inline int GetNhits() const {return hits.size();}
94  inline const DMagneticFieldMap * GetMagneticFieldMap() const {return bfield;}
95  inline float GetBzAvg() const {return Bz_avg;}
96  inline float GetZMean() const {return z_mean;}
97  inline float GetPhiMean() const {return phi_mean;}
98  jerror_t PrintChiSqVector(void) const;
99  jerror_t Print(void) const;
100  jerror_t Dump(void) const;
101  inline void SetMagneticFieldMap(const DMagneticFieldMap *map){bfield=map;}
102 
106  TRACK
107  };
108 
109  float x0,y0,r0;
110  float q;
111  float p, p_trans;
112  float phi, theta;
113  float z_vertex;
114  float chisq;
115  float dzdphi;
117 
119  double c_origin;
120 
121  protected:
122  vector<DQFHit_t*> hits;
123  const DMagneticFieldMap *bfield; ///< pointer to magnetic field map
124  float Bz_avg;
125  float z_mean, phi_mean;
126 
127  jerror_t FillTrackParams(void);
128 };
129 
130 
131 
132 #endif //_DQUICK_FIT_H_
float z_mean
Definition: DQuickFit.h:125
vector< DQFHit_t * > hits
Definition: DQuickFit.h:122
c Clear()
float GetBzAvg() const
Definition: DQuickFit.h:95
ChiSqSourceType_t
Definition: DQuickFit.h:103
TVector3 DVector3
Definition: DVector3.h:14
double Bz_avg
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
locHist_ADCmulti Print()
#define y
float y0
Definition: DQuickFit.h:109
const vector< DQFHit_t * > GetHits() const
Definition: DQuickFit.h:92
float GetPhiMean() const
Definition: DQuickFit.h:97
ChiSqSourceType_t chisq_source
Definition: DQuickFit.h:116
int GetNhits() const
Definition: DQuickFit.h:93
float q
Definition: DQuickFit.h:110
DVector3 normal
Definition: DQuickFit.h:118
float chisq
chi-sq contribution of this hit
Definition: DQuickFit.h:66
float p_trans
Definition: DQuickFit.h:111
float GetZMean() const
Definition: DQuickFit.h:96
const DMagneticFieldMap * GetMagneticFieldMap() const
Definition: DQuickFit.h:94
float chisq
Definition: DQuickFit.h:114
float theta
Definition: DQuickFit.h:112
void SetMagneticFieldMap(const DMagneticFieldMap *map)
Definition: DQuickFit.h:101
float phi_circle
phi angle relative to axis of helix
Definition: DQuickFit.h:65
float z_vertex
Definition: DQuickFit.h:113
#define BeamRMS
float dzdphi
Definition: DQuickFit.h:115
double c_origin
Definition: DQuickFit.h:119
const DMagneticFieldMap * bfield
pointer to magnetic field map
Definition: DQuickFit.h:123
float z
point in lab coordinates
Definition: DQuickFit.h:64
float Bz_avg
Definition: DQuickFit.h:124