20 const std::vector<double>& TrkClusters_y,
21 const std::vector<double>& TrkClusters_z,
24 const bool& debug =
false,
25 const double threshold = 1000
34 printf(
"\nClusterFitter:");
42 if (TrkClusters_x.size() != TrkClusters_y.size() || TrkClusters_x.size() != TrkClusters_z.size())
45 cerr<<
"\n\nERROR! Argument cluster vector lengths are not equal.\n";
46 cerr<<
"SizeX = "<<TrkClusters_x.size()<<
", SizeY = "<<TrkClusters_y.size()<<
", SizeZ = "<<TrkClusters_z.size()<<endl;
47 cerr<<
"Returning empty vector\n\n";
53 cerr<<
"\nClusterFitter: number of clusters to be fitted for this tracks = "<<TrkClusters_x.size()<<endl;
54 if (TrkClusters_x.size() < 2)
58 TGraph * graph_clusters_XZ =
new TGraph(TrkClusters_x.size());
59 TGraph * graph_clusters_YZ =
new TGraph(TrkClusters_x.size());
60 TGraph * graph_clusters_XY =
new TGraph(TrkClusters_x.size());
61 for(
unsigned int iclust = 0; iclust < TrkClusters_x.size(); iclust++)
63 graph_clusters_XZ->SetPoint((
int)iclust, TrkClusters_x[iclust], TrkClusters_z[iclust]);
64 graph_clusters_YZ->SetPoint((
int)iclust, TrkClusters_y[iclust], TrkClusters_z[iclust]);
65 graph_clusters_XY->SetPoint((
int)iclust, TrkClusters_x[iclust], TrkClusters_y[iclust]);
71 graph_clusters_XZ->Fit(lin_fit_XZ,
"SQ");
72 graph_clusters_YZ->Fit(lin_fit_YZ,
"SQ");
73 graph_clusters_XY->Fit(lin_fit_XY,
"SQ");
74 TFitResultPtr r1 = graph_clusters_XZ->Fit(lin_fit_XZ,
"SQ");
75 TFitResultPtr r2 = graph_clusters_YZ->Fit(lin_fit_YZ,
"SQ");
76 TFitResultPtr r3 = graph_clusters_XY->Fit(lin_fit_XY,
"SQ");
78 double fit_xz_chi2ndf = r1->Chi2()/r1->Ndf();
79 double fit_yz_chi2ndf = r2->Chi2()/r2->Ndf();
80 double fit_xy_chi2ndf = r3->Chi2()/r3->Ndf();
82 delete graph_clusters_XZ;
83 delete graph_clusters_YZ;
84 delete graph_clusters_XY;
89 double mXZ = r1->Parameter(0);
90 double mPerErrXZ = 100*fabs(r1->ParError(0)/mXZ);
91 double sXZ = r1->Parameter(1);
92 double sPerErrXZ = 100*fabs(r1->ParError(1)/sXZ);
94 double mYZ = r2->Parameter(0);
95 double mPerErrYZ = 100*fabs(r2->ParError(0)/mYZ);
96 double sYZ = r2->Parameter(1);
97 double sPerErrYZ = 100*fabs(r2->ParError(1)/sYZ);
99 double mXY = r3->Parameter(0);
100 double mPerErrXY = 100*fabs(r3->ParError(0)/mXY);
101 double sXY = r3->Parameter(1);
102 double sPerErrXY = 100*fabs(r3->ParError(1)/sXY);
106 printf(
"Fit XZ: M = %14.7f, %%errM = %14.7f, C = %14.7f, %%errC = %14.7f, Chi-sq/ndf = %14.7f\n", mXZ, mPerErrXZ, sXZ, sPerErrXZ, fit_xz_chi2ndf);
107 printf(
"Fit YZ: M = %14.7f, %%errM = %14.7f, C = %14.7f, %%errC = %14.7f, Chi-sq/ndf = %14.7f\n", mYZ, mPerErrYZ, sYZ, sPerErrYZ, fit_yz_chi2ndf);
108 printf(
"Fit XY: M = %14.7f, %%errM = %14.7f, C = %14.7f, %%errC = %14.7f, Chi-sq/ndf = %14.7f\n", mXY, mPerErrXY, sXY, sPerErrXY, fit_xy_chi2ndf);
111 if (fit_xz_chi2ndf > threshold || fit_yz_chi2ndf > threshold || fit_xy_chi2ndf > threshold)
114 cerr<<
"\n\nINFO: Fit is poorer than provided threshold. Returning empty vector.\n\n";
118 Line::FitLine2D lineXZ (mXZ, sXZ, r1->ParError(0), r1->ParError(1), fit_xz_chi2ndf, trkID, g3PID);
119 Line::FitLine2D lineYZ (mYZ, sYZ, r2->ParError(0), r2->ParError(1), fit_yz_chi2ndf, trkID, g3PID);
120 Line::FitLine2D lineXY (mXY, sXY, r3->ParError(0), r3->ParError(1), fit_xy_chi2ndf, trkID, g3PID);
121 return {lineXZ, lineYZ, lineXY};
const int TRD_XYMAX
Definition: TRDConstants.h:8
const int TRD_XYMIN
cm
Definition: TRDConstants.h:9
Definition: ClusterFitter.h:17
std::vector< Line::FitLine2D > GetClusterProjectionLinearFits(const std::vector< double > &TrkClusters_x, const std::vector< double > &TrkClusters_y, const std::vector< double > &TrkClusters_z, const int &trkID, const int &g3PID, const bool &debug=false, const double threshold=1000)
Definition: ClusterFitter.h:19
void printVector(const std::vector< T > &v)
Definition: Utilities.h:58