CbmRoot
CbmRichRingFitterQa.cxx
Go to the documentation of this file.
1 
8 #include "CbmRichRingFitterQa.h"
9 #include "CbmRichRingFitterCOP.h"
12 
13 #include "CbmRichRing.h"
14 #include "TCanvas.h"
15 #include "TH1D.h"
16 #include "TMath.h"
17 #include "TMatrixD.h"
18 #include "TRandom.h"
19 
20 #include <iostream>
21 #include <vector>
22 
23 using std::cout;
24 using std::endl;
25 using std::vector;
26 
28  : fhErrorA(NULL)
29  , fhErrorB(NULL)
30  , fhErrorX(NULL)
31  , fhErrorY(NULL)
32  , fhErrorPhi(NULL)
33  ,
34 
35  fhA(NULL)
36  , fhB(NULL)
37  , fhX(NULL)
38  , fhY(NULL)
39  , fhPhi(NULL)
40  ,
41 
42  fhRadiusErr(NULL)
43  , fhCircleXcErr(NULL)
44  , fhCircleYcErr(NULL)
45  ,
46 
47  fhRadius(NULL)
48  , fhCircleXc(NULL)
49  , fhCircleYc(NULL)
50  ,
51 
52  fhRadiusPool(NULL)
53  , fhCircleXcPool(NULL)
54  , fhCircleYcPool(NULL) {
55  fhErrorA = new TH1D("fhErrorA", "fhErrorA;dA [cm];Counter", 100, -2., 2.);
56  fhErrorB = new TH1D("fhErrorB", "fhErrorB;B [cm];Counter", 100, -2., 2.);
57  fhErrorX = new TH1D("fhErrorX", "fhErrorX;X [cm];Counter", 100, -2., 2.);
58  fhErrorY = new TH1D("fhErrorY", "fhErrorY;Y [cm];Counter", 100, -2., 2.);
59  fhErrorPhi =
60  new TH1D("fhErrorPhi", "fhErrorPhi;d#Phi [rad];Counter", 100, -2., 2.);
61 
62  fhA = new TH1D("fhA", "fhA;A [cm];Counter", 100, 5., 7.);
63  fhB = new TH1D("fhB", "fhB;B [cm];Counter", 100, 5., 7.);
64  fhX = new TH1D("fhX", "fhX;X [cm];Counter", 100, -1., 1.);
65  fhY = new TH1D("fhY", "fhY;Y [cm];Counter", 100, -1., 1.);
66  Double_t pi = TMath::Pi();
67  fhPhi = new TH1D("fhPhi",
68  "fhPhi;#Phi [rad];Counter",
69  100,
70  -pi / 2. - pi / 6.,
71  pi / 2. + pi / 6.);
72 
73  // circle fitting
74  fhRadiusErr =
75  new TH1D("fhRadiusErr", "fhRadiusErr;dR [cm];Counter", 100, -2., 2.);
77  new TH1D("fhCircleXcErr", "fhCircleXcErr;dXc [cm];Counter", 100, -2., 2.);
79  new TH1D("fhCircleYcErr", "fhCircleYcErr;dYc [cm];Counter", 100, -2., 2.);
80  fhRadius = new TH1D("fhRadius", "fhRadius;Radius [cm];Counter", 100, 4., 8.);
81  fhCircleXc =
82  new TH1D("fhCircleXc", "fhCircleXc;Xc [cm];Counter", 100, -2., 2.);
83  fhCircleYc =
84  new TH1D("fhCircleYc", "fhCircleYc;Yc [cm];Counter", 100, -2., 2.);
85  fhRadiusPool =
86  new TH1D("fhRadiusPool", "fhRadiusPool;Pool R;Counter", 100, -5., 5.);
88  new TH1D("fhCircleXcPool", "fhCircleXcPool;Pool Xc;Counter", 100, -5., 5.);
90  new TH1D("fhCircleYcPool", "fhCircleYcPool;Pool Yc;Counter", 100, -5., 5.);
91 }
92 
94 
96  // Double_t maxX = 15;
97  // Double_t maxY = 15;
98  Int_t nofHits = 50;
99  Double_t A = 6.;
100  Double_t B = 6.;
101  Double_t sigmaError = 0.2;
102  CbmRichRingLight ellipse;
103  Int_t nofBadFit = 0;
104  Double_t X0 = 0.; //gRandom->Rndm()*(maxX - A);
105  Double_t Y0 = 0.; //gRandom->Rndm()* (maxY - A);
106 
108  CbmRichRingFitterCOP* fitCircle = new CbmRichRingFitterCOP();
109 
110  for (Int_t iR = 0; iR < 50000; iR++) {
111  Double_t phi =
112  0.; //TMath::Pi()*(6./12.); //gRandom->Rndm()*TMath::Pi() - TMath::Pi()/2.;
113  ellipse.SetXYABP(X0, Y0, A, B, phi);
114  for (Int_t iH = 0; iH < nofHits; iH++) {
115  Double_t alfa = gRandom->Rndm() * 2. * TMath::Pi();
116 
117  Double_t errorX = gRandom->Gaus(0, sigmaError);
118  Double_t errorY = gRandom->Gaus(0, sigmaError);
119 
120  Double_t hx = A * cos(alfa);
121  Double_t hy = B * sin(alfa);
122 
123  Double_t hitXRot = hx * cos(phi) - hy * sin(phi);
124  Double_t hitYRot = hx * sin(phi) + hy * cos(phi);
125 
126  CbmRichHitLight hit(hitXRot + X0 + errorX, hitYRot + Y0 + errorY);
127  ellipse.AddHit(hit);
128  }
129  // ellipse fit
130  fitEllipse->DoFit(&ellipse);
131  fhErrorA->Fill(A - ellipse.GetAaxis());
132  fhErrorB->Fill(B - ellipse.GetBaxis());
133  fhErrorX->Fill(X0 - ellipse.GetCenterX());
134  fhErrorY->Fill(Y0 - ellipse.GetCenterY());
135  fhErrorPhi->Fill(phi - ellipse.GetPhi());
136  fhA->Fill(ellipse.GetAaxis());
137  fhB->Fill(ellipse.GetBaxis());
138  fhX->Fill(ellipse.GetCenterX());
139  fhY->Fill(ellipse.GetCenterY());
140  fhPhi->Fill(ellipse.GetPhi());
141 
142  // circle fit
143  fitCircle->DoFit(&ellipse);
144  TMatrixD cov(3, 3);
145  CalculateFitErrors(&ellipse, sigmaError, cov);
146  Double_t mcR = (A + B) / 2.;
147  fhRadiusErr->Fill(mcR - ellipse.GetRadius());
148  fhCircleXcErr->Fill(X0 - ellipse.GetCenterX());
149  fhCircleYcErr->Fill(Y0 - ellipse.GetCenterY());
150  fhRadius->Fill(ellipse.GetRadius());
151  fhCircleXc->Fill(ellipse.GetCenterX());
152  fhCircleYc->Fill(ellipse.GetCenterY());
153  fhRadiusPool->Fill((mcR - ellipse.GetRadius()) / sqrt(cov(2, 2)));
154  fhCircleXcPool->Fill((X0 - ellipse.GetCenterX()) / sqrt(cov(0, 0)));
155  fhCircleYcPool->Fill((Y0 - ellipse.GetCenterY()) / sqrt(cov(1, 1)));
156  } // iR
157 
158  Draw();
159  cout << nofBadFit << endl;
160 }
161 
162 void CbmRichRingFitterQa::Draw(Option_t*) {
163  TCanvas* c =
164  new TCanvas("rich_fitter_errors", "rich_fitter_errors", 900, 600);
165  c->Divide(3, 2);
166  c->cd(1);
167  fhErrorA->Draw();
168  c->cd(2);
169  fhErrorB->Draw();
170  c->cd(3);
171  fhErrorX->Draw();
172  c->cd(4);
173  fhErrorY->Draw();
174  c->cd(5);
175  fhErrorPhi->Draw();
176  cout.precision(4);
177  cout << fhErrorA->GetMean() << " " << fhErrorA->GetRMS() << endl;
178  cout << fhErrorB->GetMean() << " " << fhErrorB->GetRMS() << endl;
179  cout << fhErrorX->GetMean() << " " << fhErrorX->GetRMS() << endl;
180  cout << fhErrorY->GetMean() << " " << fhErrorY->GetRMS() << endl;
181  cout << fhErrorPhi->GetMean() << " " << fhErrorPhi->GetRMS() << endl;
182 
183  TCanvas* c2 =
184  new TCanvas("rich_fitter_params", "rich_fitter_params", 900, 600);
185  c2->Divide(3, 2);
186  c2->cd(1);
187  fhA->Draw();
188  c2->cd(2);
189  fhB->Draw();
190  c2->cd(3);
191  fhX->Draw();
192  c2->cd(4);
193  fhY->Draw();
194  c2->cd(5);
195  fhPhi->Draw();
196 
197  TCanvas* c3 =
198  new TCanvas("rich_fitter_circle", "rich_fitter_circle", 900, 900);
199  c3->Divide(3, 3);
200  c3->cd(1);
201  fhRadiusErr->Draw();
202  c3->cd(2);
203  fhCircleXcErr->Draw();
204  c3->cd(3);
205  fhCircleYcErr->Draw();
206  c3->cd(4);
207  fhRadius->Draw();
208  c3->cd(5);
209  fhCircleXc->Draw();
210  c3->cd(6);
211  fhCircleYc->Draw();
212  c3->cd(7);
213  fhRadiusPool->Draw();
214  c3->cd(8);
215  fhCircleXcPool->Draw();
216  c3->cd(9);
217  fhCircleYcPool->Draw();
218 }
219 
221  Double_t sigma,
222  TMatrixD& cov) {
223  //TMatrixD H3(3,3);
224  TMatrixD HY3(3, 1);
225  //TMatrixD Cov3(3,3);
226  TMatrixD HC3(3, 1);
227 
228  for (Int_t i = 0; i < 3; i++) {
229  HY3(i, 0) = 0;
230  HC3(i, 0) = 0;
231  for (Int_t j = 0; j < 3; j++) {
232  //H3(i,j) = 0;
233  cov(i, j) = 0;
234  }
235  }
236 
237  Double_t xc = ring->GetCenterX();
238  Double_t yc = ring->GetCenterY();
239  Double_t R = ring->GetRadius();
240  for (Int_t iHit = 0; iHit < ring->GetNofHits(); iHit++) {
241  Double_t xi = ring->GetHit(iHit).fX;
242  Double_t yi = ring->GetHit(iHit).fY;
243  Double_t ri = sqrt((xi - xc) * (xi - xc) + (yi - yc) * (yi - yc));
244  Double_t err = sigma;
245 
246  Double_t f1 = (-1.0 * (xi - xc)) / (ri * err);
247  Double_t f2 = (-1.0 * (yi - yc)) / (ri * err);
248  Double_t f3 = (-1.) / err;
249  Double_t Y = (R - ri) / err;
250 
251  cov(0, 0) = cov(0, 0) + f1 * f1;
252  cov(0, 1) = cov(0, 1) + f1 * f2;
253  cov(0, 2) = cov(0, 2) + f1 * f3;
254 
255  cov(1, 0) = cov(0, 1);
256  cov(1, 1) = cov(1, 1) + f2 * f2;
257  cov(1, 2) = cov(1, 2) + f2 * f3;
258 
259  cov(2, 0) = cov(0, 2);
260  cov(2, 1) = cov(1, 2);
261  cov(2, 2) = cov(2, 2) + f3 * f3;
262 
263  HY3(0, 0) = HY3(0, 0) + Y * f1;
264  HY3(1, 0) = HY3(1, 0) + Y * f2;
265  HY3(2, 0) = HY3(2, 0) + Y * f3;
266  } // iHit
267 
268  //H3.Print();
269  Double_t det = 0.0;
270  cov.Invert(&det);
271  //Cov3 = H3;
272  //H3.Print();
273  //Cov3.Print();
274 
275  //HC3 = H3 * HY3;
276  //HC3.Print();
277 
278  //cout << "dX0= " << HC3(0,0) << " +- " << sqrt(Cov3(0,0)) << endl;
279  // cout << "dY0= " << HC3(1,0) << " +- " << sqrt(Cov3(1,1)) << endl;
280  //cout << "dR= " << HC3(2,0) << " +- " << sqrt(Cov3(2,2)) << endl;
281 
282  //cout << "dX0= " << HC3(0,0) << " +- " << sqrt(Cov3(0,0)) << endl;
283  // cout << "dY0= " << HC3(1,0) << " +- " << sqrt(Cov3(1,1)) << endl;
284  // cout << "dR= " << HC3(2,0) << " +- " << sqrt(Cov3(2,2)) << endl;
285 }
286 
sin
friend F32vec4 sin(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:136
CbmRichRingFitterQa
Test ellipse and circle fitting on toy model.
Definition: CbmRichRingFitterQa.h:30
CbmRichRingFitterQa::fhErrorA
TH1D * fhErrorA
Definition: CbmRichRingFitterQa.h:54
CbmRichRingFitterQa::fhY
TH1D * fhY
Definition: CbmRichRingFitterQa.h:63
CbmRichRingFitterEllipseTau
Here the ring is fitted with Taubin algorithm from A. Ayriyan, G. Ososkov, N. Chernov.
Definition: CbmRichRingFitterEllipseTau.h:35
CbmRichRingFitterQa::fhErrorY
TH1D * fhErrorY
Definition: CbmRichRingFitterQa.h:57
CbmRichRingFitterEllipseTau.h
Here the ring is fitted with Taubin algorithm from A. Ayriyan, G. Ososkov, N. Chernov.
CbmRichRingFitterQa::fhRadius
TH1D * fhRadius
Definition: CbmRichRingFitterQa.h:70
CbmRichRingFitterQa::fhA
TH1D * fhA
Definition: CbmRichRingFitterQa.h:60
sqrt
friend F32vec4 sqrt(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:41
CbmRichRingFitterQa::GenerateEllipse
void GenerateEllipse()
Generate ellipse.
Definition: CbmRichRingFitterQa.cxx:95
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmRichRingFitterQa::fhCircleYcErr
TH1D * fhCircleYcErr
Definition: CbmRichRingFitterQa.h:68
CbmRichRingFitterQa::fhErrorB
TH1D * fhErrorB
Definition: CbmRichRingFitterQa.h:55
CbmRichHitLight::fX
float fX
Definition: CbmRichRingLight.h:34
CbmRichRingFitterQa::fhCircleXc
TH1D * fhCircleXc
Definition: CbmRichRingFitterQa.h:71
CbmRichRing.h
CbmRichRingFitterQa::Draw
void Draw(Option_t *="")
Draw generated and fitted circle/ellipse.
Definition: CbmRichRingFitterQa.cxx:162
ClassImp
ClassImp(CbmRichRingFitterQa)
CbmRichRingFitterCOP
Here the ring is fitted with the COP algorithm from A. Ayriyan/G. Ososkov.
Definition: CbmRichRingFitterCOP.h:28
CbmRichRingFitterQa::fhErrorX
TH1D * fhErrorX
Definition: CbmRichRingFitterQa.h:56
CbmRichRingFitterEllipseMinuit.h
This is the implementation of ellipse fitting using MINUIT.
CbmRichRingLight::GetNofHits
int GetNofHits() const
Return number of hits in ring.
Definition: CbmRichRingLight.h:108
CbmRichRingFitterQa.h
Test ellipse and circle fitting on toy model.
CbmRichRingLight::SetXYABP
void SetXYABP(float x, float y, float a, float b, float p)
Set all 5 ellipse parameters.
Definition: CbmRichRingLight.h:146
CbmRichRingLight::GetAaxis
float GetAaxis() const
Definition: CbmRichRingLight.h:163
CbmRichRingFitterQa::fhPhi
TH1D * fhPhi
Definition: CbmRichRingFitterQa.h:64
CbmRichRingLight::GetCenterY
float GetCenterY() const
Definition: CbmRichRingLight.h:160
CbmRichRingFitterQa::fhX
TH1D * fhX
Definition: CbmRichRingFitterQa.h:62
CbmRichRingLight::AddHit
void AddHit(CbmRichHitLight hit)
Add new hit to the ring.
Definition: CbmRichRingLight.h:87
CbmRichRingFitterQa::fhErrorPhi
TH1D * fhErrorPhi
Definition: CbmRichRingFitterQa.h:58
xMath::Pi
double Pi()
Definition: xMath.h:5
CbmRichRingFitterQa::fhCircleYc
TH1D * fhCircleYc
Definition: CbmRichRingFitterQa.h:72
CbmRichRingLight::GetBaxis
float GetBaxis() const
Definition: CbmRichRingLight.h:164
CbmRichRingFitterQa::fhCircleXcErr
TH1D * fhCircleXcErr
Definition: CbmRichRingFitterQa.h:67
CbmRichHitLight
Definition: CbmRichRingLight.h:14
CbmRichRingFitterCOP.h
Here the ring is fitted with the COP algorithm from A. Ayriyan/G. Ososkov.
CbmRichRingLight::GetRadius
float GetRadius() const
Definition: CbmRichRingLight.h:161
CbmRichRingFitterQa::CalculateFitErrors
void CalculateFitErrors(CbmRichRingLight *ring, Double_t sigma, TMatrixD &cov)
Definition: CbmRichRingFitterQa.cxx:220
CbmRichRingFitterQa::fhB
TH1D * fhB
Definition: CbmRichRingFitterQa.h:61
CbmRichRingFitterQa::fhCircleXcPool
TH1D * fhCircleXcPool
Definition: CbmRichRingFitterQa.h:75
CbmRichRingFitterCOP::DoFit
virtual void DoFit(CbmRichRingLight *ring)
Inherited from CbmRichRingFitterBase.
Definition: CbmRichRingFitterCOP.cxx:19
CbmRichHitLight::fY
float fY
Definition: CbmRichRingLight.h:35
CbmRichRingFitterQa::fhRadiusPool
TH1D * fhRadiusPool
Definition: CbmRichRingFitterQa.h:74
CbmRichRingLight::GetHit
CbmRichHitLight GetHit(int ind)
Return hit by the index.
Definition: CbmRichRingLight.h:114
cos
friend F32vec4 cos(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:137
CbmRichRingFitterQa::fhRadiusErr
TH1D * fhRadiusErr
Definition: CbmRichRingFitterQa.h:66
CbmRichRingFitterQa::CbmRichRingFitterQa
CbmRichRingFitterQa()
Standard constructor.
Definition: CbmRichRingFitterQa.cxx:27
CbmRichRingLight::GetCenterX
float GetCenterX() const
Definition: CbmRichRingLight.h:159
CbmRichRingFitterEllipseTau::DoFit
virtual void DoFit(CbmRichRingLight *ring)
Inherited from CbmRichRingFitterBase.
Definition: CbmRichRingFitterEllipseTau.cxx:94
CbmRichRingFitterQa::~CbmRichRingFitterQa
virtual ~CbmRichRingFitterQa()
Destructor.
Definition: CbmRichRingFitterQa.cxx:93
CbmRichRingLight
Definition: CbmRichRingLight.h:39
CbmRichRingFitterQa::fhCircleYcPool
TH1D * fhCircleYcPool
Definition: CbmRichRingFitterQa.h:76
CbmRichRingLight::GetPhi
float GetPhi() const
Definition: CbmRichRingLight.h:165