TrdMCClusterR Fit Classifier
ClusterFitter3D.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <TF3.h>
4 #include <TGraph2D.h>
5 #include <TH3D.h>
6 #include <TCanvas.h>
7 #include <TStyle.h>
8 #include <TMinuit.h>
9 #include <TFitResult.h>
10 
11 #include "AMSTrdMCTrack.h"
12 #include "TRDConstants.h"
13 #include "Line.h"
14 
15 
16 namespace ClusterFitter3D
17 {
19  Line::FitLine3D fitClustersToLine3D(const AMSTrdMCTrack::Track &track, const int& eventID, TFile * file)
20  {
23  Line::FitLine3D result;
24  result.trkID = track.trkID;
25  result.g3PID = track.g3PID;
26 
28  TH3D * hist3D = setClustersInTH3D(track);
29 
32  TF3 * lin_fit_3D = new TF3("lin_fit_3D", Line::distanceFromLine3D, -100, 100, -100, 100, 90, 140, 6);
33 
34  lin_fit_3D->SetParameters(0, 0, 100, 1, 1, 1);
35 
37  TFitResultPtr fitResult = hist3D->Fit(lin_fit_3D, "SV");
38 
40  if (!fitResult)
41  printf("\n\nWARNING: Fit failed for Track with trkID: %d and g3PID: %d\n", result.trkID, result.g3PID);
42 
44  double chi2Ndf = fitResult->Chi2() / fitResult->Ndf();
45  printf("For track.trkID = %d, chi2/NDF = %f\n\n\n", track.trkID, chi2Ndf);
46 
48  // if (file && result.fitResult)
49  {
50  file->cd();
51  hist3D->Write(Form("graph2D_%d_%d_%d_%d", eventID, track.trkID, track.g3PID, track.clusters.size()));
52  lin_fit_3D->Write(Form("fit3D_%d_%d_%d_%d", eventID, track.trkID, track.g3PID, track.clusters.size()));
53  }
54 
55  delete lin_fit_3D;
56  delete hist3D;
57 
58  result.fit = fitResult;
59  return result;
60  }
61 }
Definition: ClusterFitter3D.h:17
Line::FitLine3D fitClustersToLine3D(const AMSTrdMCTrack::Track &track, const int &eventID, TFile *file)
Definition: ClusterFitter3D.h:19
double distanceFromLine3D(double *coords, double *params)
Definition: Line.h:122
Definition: AMSTrdMCTrack.h:49
int trkID
Definition: AMSTrdMCTrack.h:50
std::vector< Cluster > clusters
Definition: AMSTrdMCTrack.h:52
int g3PID
Definition: AMSTrdMCTrack.h:51
Definition: Line.h:49
int g3PID
Definition: Line.h:52
int trkID
Definition: Line.h:51
TFitResultPtr fit
Definition: Line.h:50