Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-08-31 08:21:22

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
0003 #ifndef TPCTRACKRECO_TPCFITTINGTOOLS_H
0004 #define TPCTRACKRECO_TPCFITTINGTOOLS_H
0005 
0006 #include <vector>
0007 
0008 class Tpc_FittingTools
0009 {
0010  public:
0011   enum FitMode
0012   {
0013     FIT_LINEAR = 0,
0014     FIT_SAGITTA = 1
0015   };
0016 
0017   struct FitPoint
0018   {
0019     FitPoint();
0020     FitPoint(double x_, double y_, double w_ = 1.0);
0021 
0022     double x;
0023     double y;
0024     double w;
0025   };
0026 
0027   struct LineFit
0028   {
0029     LineFit();
0030 
0031     bool ok;
0032     double slope;
0033     double intercept;
0034     double chi2;
0035     int ndof;
0036   };
0037 
0038   struct SagittaFit
0039   {
0040     SagittaFit();
0041 
0042     bool ok;
0043     double S;
0044     double x0;
0045     double invR;
0046     double theta;
0047     double b;
0048     double chi2;
0049     int ndof;
0050   };
0051 
0052   struct Point
0053   {
0054     double x{0.0};
0055     double y{0.0};
0056     double z{0.0};
0057   };
0058 
0059   struct FitResult
0060   {
0061     bool ok{false};
0062     bool is_line{false};
0063     double cx{0.0};
0064     double cy{0.0};
0065     double d0{0.0};
0066     double z0{0.0};
0067     double phi0{0.0};
0068     double theta{0.0};
0069     double curvature{0.0};
0070     double line_x{0.0};
0071     double line_y{0.0};
0072     double line_z{0.0};
0073     double line_dx{0.0};
0074     double line_dy{0.0};
0075     double line_dz{0.0};
0076     double chi2_xy{0.0};
0077     double chi2_z{0.0};
0078     int ndof_xy{0};
0079     int ndof_z{0};
0080   };
0081 
0082   static double adcWeight(double adc, double maxadc, double power, double floor_frac);
0083 
0084   static bool weightedLineFit(const std::vector<double>& x,
0085                               const std::vector<double>& y,
0086                               const std::vector<double>& w,
0087                               double& m,
0088                               double& b,
0089                               double& chi2,
0090                               int& ndof);
0091 
0092   static LineFit fitLine(const std::vector<FitPoint>& points);
0093 
0094   static double sagittaModel(double xrot, double S, double x0, double invR);
0095 
0096   static bool weightedSagittaFit(const std::vector<double>& x,
0097                                  const std::vector<double>& y,
0098                                  const std::vector<double>& w,
0099                                  double& S,
0100                                  double& x0,
0101                                  double& invR,
0102                                  double& theta,
0103                                  double& bline,
0104                                  double& chi2,
0105                                  int& ndof);
0106 
0107   static SagittaFit fitSagitta(const std::vector<FitPoint>& points);
0108 
0109   static bool fit(const std::vector<Point>& points, FitResult& fit);
0110   static bool fitLine3D(const std::vector<Point>& points, FitResult& fit);
0111 };
0112 #endif