]>
Commit | Line | Data |
---|---|---|
9318a5b4 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | ||
17 | /////////////////////////////////////////////////////////////////////////////// | |
18 | // // | |
19 | // Class to make a internal alignemnt of TPC chambers // | |
20 | // | |
21 | // Different linear tranformation investigated | |
f8a2dcfb | 22 | |
972cf6f2 | 23 | // 12 parameters - arbitrary linear transformation |
f8a2dcfb | 24 | // a00 a01 a02 a03 p[0] p[1] p[2] p[9] |
25 | // a10 a11 a12 a13 ==> p[3] p[4] p[5] p[10] | |
26 | // a20 a21 a22 a23 p[6] p[7] p[8] p[11] | |
27 | // | |
9318a5b4 | 28 | // 9 parameters - scaling fixed to 1 |
f8a2dcfb | 29 | // a00 a01 a02 a03 1 p[0] p[1] p[6] |
30 | // a10 a11 a12 a13 ==> p[2] 1 p[3] p[7] | |
31 | // a20 a21 a22 a23 p[4] p[5] 1 p[8] | |
32 | // | |
972cf6f2 | 33 | // 6 parameters - x-y rotation x-z, y-z tiliting |
f8a2dcfb | 34 | // a00 a01 a02 a03 1 -p[0] 0 p[3] |
35 | // a10 a11 a12 a13 ==> p[0] 1 0 p[4] | |
36 | // a20 a21 a22 a23 p[1] p[2] 1 p[5] | |
37 | // | |
9318a5b4 | 38 | //// |
39 | //// | |
40 | ||
41 | #include "TLinearFitter.h" | |
42 | #include "AliTPCcalibAlign.h" | |
43 | #include "AliExternalTrackParam.h" | |
e4042305 | 44 | #include "AliTPCTracklet.h" |
45 | #include "TH1D.h" | |
7eaa723e | 46 | #include "TVectorD.h" |
e149f26d | 47 | #include "TTreeStream.h" |
7eaa723e | 48 | #include "TFile.h" |
e81dc112 | 49 | #include "TF1.h" |
8b3c60d8 | 50 | #include "TGraphErrors.h" |
9318a5b4 | 51 | |
8b3c60d8 | 52 | |
53 | #include "TTreeStream.h" | |
9318a5b4 | 54 | #include <iostream> |
e4042305 | 55 | #include <sstream> |
9318a5b4 | 56 | using namespace std; |
57 | ||
58 | ClassImp(AliTPCcalibAlign) | |
59 | ||
60 | AliTPCcalibAlign::AliTPCcalibAlign() | |
e4042305 | 61 | : fDphiHistArray(72*72), |
62 | fDthetaHistArray(72*72), | |
63 | fDyHistArray(72*72), | |
64 | fDzHistArray(72*72), | |
65 | fFitterArray12(72*72), | |
66 | fFitterArray9(72*72), | |
67 | fFitterArray6(72*72) | |
9318a5b4 | 68 | { |
69 | // | |
70 | // Constructor | |
71 | // | |
72 | for (Int_t i=0;i<72*72;++i) { | |
73 | fPoints[i]=0; | |
74 | } | |
75 | } | |
76 | ||
e149f26d | 77 | AliTPCcalibAlign::AliTPCcalibAlign(const Text_t *name, const Text_t *title) |
78 | :AliTPCcalibBase(), | |
79 | fDphiHistArray(72*72), | |
80 | fDthetaHistArray(72*72), | |
81 | fDyHistArray(72*72), | |
82 | fDzHistArray(72*72), | |
83 | fFitterArray12(72*72), | |
84 | fFitterArray9(72*72), | |
85 | fFitterArray6(72*72) | |
86 | { | |
87 | // | |
88 | // Constructor | |
89 | // | |
90 | SetName(name); | |
91 | SetTitle(title); | |
92 | for (Int_t i=0;i<72*72;++i) { | |
93 | fPoints[i]=0; | |
94 | } | |
95 | } | |
96 | ||
9318a5b4 | 97 | AliTPCcalibAlign::~AliTPCcalibAlign() { |
98 | // | |
99 | // destructor | |
100 | // | |
101 | } | |
102 | ||
e4042305 | 103 | void AliTPCcalibAlign::Process(AliTPCseed *seed) { |
104 | TObjArray tracklets= | |
105 | AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kKalman, | |
106 | kFALSE,20,2); | |
cbc19295 | 107 | // TObjArray trackletsL= |
108 | // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kLinear, | |
109 | // kFALSE,20,2); | |
110 | // TObjArray trackletsQ= | |
111 | // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kQuadratic, | |
112 | // kFALSE,20,2); | |
113 | // TObjArray trackletsR= | |
114 | // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kRiemann, | |
115 | // kFALSE,20,2); | |
e4042305 | 116 | tracklets.SetOwner(); |
cbc19295 | 117 | // trackletsL.SetOwner(); |
118 | // trackletsQ.SetOwner(); | |
119 | // trackletsR.SetOwner(); | |
e4042305 | 120 | if (tracklets.GetEntries()==2) { |
121 | AliTPCTracklet *t1=static_cast<AliTPCTracklet*>(tracklets[0]); | |
122 | AliTPCTracklet *t2=static_cast<AliTPCTracklet*>(tracklets[1]); | |
123 | if (t1->GetSector()>t2->GetSector()) { | |
124 | AliTPCTracklet* tmp=t1; | |
125 | t1=t2; | |
126 | t2=tmp; | |
127 | } | |
128 | AliExternalTrackParam *common1=0,*common2=0; | |
129 | if (AliTPCTracklet::PropagateToMeanX(*t1,*t2,common1,common2)) | |
130 | ProcessTracklets(*common1,*common2,t1->GetSector(),t2->GetSector()); | |
131 | delete common1; | |
132 | delete common2; | |
133 | } | |
cbc19295 | 134 | |
e4042305 | 135 | } |
136 | ||
7eaa723e | 137 | void AliTPCcalibAlign::Analyze(){ |
138 | // | |
139 | // Analyze function | |
140 | // | |
141 | EvalFitters(); | |
142 | } | |
143 | ||
144 | ||
145 | void AliTPCcalibAlign::Terminate(){ | |
146 | // | |
147 | // Terminate function | |
148 | // call base terminate + Eval of fitters | |
149 | // | |
150 | if (GetDebugLevel()>0) Info("AliTPCcalibAlign","Teminate"); | |
151 | EvalFitters(); | |
152 | AliTPCcalibBase::Terminate(); | |
153 | } | |
154 | ||
155 | ||
156 | ||
157 | ||
e4042305 | 158 | void AliTPCcalibAlign::ProcessTracklets(const AliExternalTrackParam &tp1, |
159 | const AliExternalTrackParam &tp2, | |
160 | Int_t s1,Int_t s2) { | |
161 | ||
972cf6f2 | 162 | // |
163 | // | |
164 | // | |
8b3c60d8 | 165 | // |
9318a5b4 | 166 | // |
167 | // Process function to fill fitters | |
168 | // | |
169 | Double_t t1[5],t2[5]; | |
170 | Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4]; | |
7eaa723e | 171 | Double_t &x2=t2[0], &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4]; |
9318a5b4 | 172 | x1 =tp1.GetX(); |
173 | y1 =tp1.GetY(); | |
174 | z1 =tp1.GetZ(); | |
175 | Double_t snp1=tp1.GetSnp(); | |
176 | dydx1=snp1/TMath::Sqrt(1.-snp1*snp1); | |
177 | Double_t tgl1=tp1.GetTgl(); | |
178 | // dz/dx = 1/(cos(theta)*cos(phi)) | |
7eaa723e | 179 | dzdx1=tgl1/TMath::Sqrt(1.-snp1*snp1); |
180 | x2 =tp2.GetX(); | |
9318a5b4 | 181 | y2 =tp2.GetY(); |
182 | z2 =tp2.GetZ(); | |
183 | Double_t snp2=tp2.GetSnp(); | |
184 | dydx2=snp2/TMath::Sqrt(1.-snp2*snp2); | |
185 | Double_t tgl2=tp2.GetTgl(); | |
7eaa723e | 186 | dzdx2=tgl2/TMath::Sqrt(1.-snp2*snp2); |
7eaa723e | 187 | // |
188 | // | |
189 | // | |
190 | if (fStreamLevel>1){ | |
191 | TTreeSRedirector *cstream = GetDebugStreamer(); | |
192 | if (cstream){ | |
193 | static TVectorD vec1(5); | |
194 | static TVectorD vec2(5); | |
195 | vec1.SetElements(t1); | |
196 | vec2.SetElements(t2); | |
197 | AliExternalTrackParam *p1 = &((AliExternalTrackParam&)tp1); | |
198 | AliExternalTrackParam *p2 = &((AliExternalTrackParam&)tp2); | |
199 | (*cstream)<<"Tracklet"<< | |
200 | "tp1.="<<p1<< | |
201 | "tp2.="<<p2<< | |
202 | "v1.="<<&vec1<< | |
203 | "v2.="<<&vec2<< | |
204 | "s1="<<s1<< | |
205 | "s2="<<s2<< | |
206 | "\n"; | |
207 | } | |
208 | } | |
8b3c60d8 | 209 | // |
210 | // Aplly cut selection | |
211 | /* | |
212 | // Cuts to be justified with the debug streamer | |
213 | // | |
214 | TCut c1pt("abs((tp1.fP[4]+tp2.fP[4])*0.5)<5"); // pt cut | |
215 | TCut cd1pt("abs(tp1.fP[4]-tp2.fP[4])<0.5"); | |
216 | TCut c1ptpull("abs((tp1.fP[4]-tp2.fP[4])/sqrt(tp1.fC[14]+tp2.fC[14]))<5"); | |
217 | TCut csy("sqrt(tp1.fC[0]+tp2.fC[0])<0.5"); | |
218 | TCut csz("sqrt(tp1.fC[2]+tp2.fC[2])<0.3"); | |
219 | TCut cphi("abs(v1.fElements[3])<1") | |
220 | TCut ctheta("abs(v1.fElements[4])<1") | |
221 | // | |
222 | // | |
223 | TCut acut = c1ptpull+c1pt+cd1pt+csy+csz+cphi+ctheta; | |
224 | */ | |
225 | // 1. pt cut | |
226 | // 2. delta in curvature | |
227 | // 3. pull in 1pt | |
228 | // 4. sigma y | |
229 | // 5. sigma z | |
230 | // 6. angle phi | |
231 | // 7. angle theta | |
232 | Double_t sigma1pt = TMath::Sqrt(tp1.GetSigma1Pt2()+tp1.GetSigma1Pt2()); | |
233 | Double_t delta1pt = (tp1.GetParameter()[4]-tp2.GetParameter()[4]); | |
234 | Double_t pull1pt = delta1pt/sigma1pt; | |
235 | if (0.5*TMath::Abs(tp1.GetParameter()[4]+tp2.GetParameter()[4])>5) return; | |
236 | if (TMath::Abs(delta1pt)>0.5) return; | |
237 | if (TMath::Abs(pull1pt)>5) return; | |
238 | if (TMath::Sqrt(tp1.GetSigmaY2()+tp2.GetSigmaY2())>0.5) return; | |
239 | if (TMath::Sqrt(tp1.GetSigmaZ2()+tp2.GetSigmaZ2())>0.3) return; | |
240 | if (TMath::Abs(dydx1)>1.) return; | |
241 | if (TMath::Abs(dzdx1)>1.) return; | |
242 | // | |
243 | // fill resolution histograms - previous cut included | |
244 | FillHisto(tp1,tp2,s1,s2); | |
245 | // | |
9318a5b4 | 246 | Process12(t1,t2,GetOrMakeFitter12(s1,s2)); |
7eaa723e | 247 | Process9(t1,t2,GetOrMakeFitter9(s1,s2)); |
248 | Process6(t1,t2,GetOrMakeFitter6(s1,s2)); | |
e81dc112 | 249 | ++fPoints[GetIndex(s1,s2)]; |
9318a5b4 | 250 | } |
251 | ||
7eaa723e | 252 | void AliTPCcalibAlign::Process12(const Double_t *t1, |
253 | const Double_t *t2, | |
9318a5b4 | 254 | TLinearFitter *fitter) { |
255 | // x2 = a00*x1 + a01*y1 + a02*z1 + a03 | |
256 | // y2 = a10*x1 + a11*y1 + a12*z1 + a13 | |
257 | // z2 = a20*x1 + a21*y1 + a22*z1 + a23 | |
258 | // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1) | |
259 | // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1) | |
260 | // | |
f8a2dcfb | 261 | // a00 a01 a02 a03 p[0] p[1] p[2] p[9] |
262 | // a10 a11 a12 a13 ==> p[3] p[4] p[5] p[10] | |
263 | // a20 a21 a22 a23 p[6] p[7] p[8] p[11] | |
264 | ||
265 | ||
266 | ||
7eaa723e | 267 | const Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4]; |
268 | const Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4]; | |
9318a5b4 | 269 | |
270 | // TODO: | |
7eaa723e | 271 | Double_t sy = 0.1; |
272 | Double_t sz = 0.1; | |
273 | Double_t sdydx = 0.001; | |
274 | Double_t sdzdx = 0.001; | |
9318a5b4 | 275 | |
276 | Double_t p[12]; | |
277 | Double_t value; | |
278 | ||
279 | // x2 = a00*x1 + a01*y1 + a02*z1 + a03 | |
280 | // y2 = a10*x1 + a11*y1 + a12*z1 + a13 | |
281 | // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2 | |
282 | for (Int_t i=0; i<12;i++) p[i]=0.; | |
283 | p[3+0] = x1; // a10 | |
284 | p[3+1] = y1; // a11 | |
285 | p[3+2] = z1; // a12 | |
286 | p[9+1] = 1.; // a13 | |
287 | p[0+1] = y1*dydx2; // a01 | |
288 | p[0+2] = z1*dydx2; // a02 | |
289 | p[9+0] = dydx2; // a03 | |
290 | value = y2; | |
291 | fitter->AddPoint(p,value,sy); | |
292 | ||
293 | // x2 = a00*x1 + a01*y1 + a02*z1 + a03 | |
294 | // z2 = a20*x1 + a21*y1 + a22*z1 + a23 | |
295 | // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2; | |
296 | for (Int_t i=0; i<12;i++) p[i]=0.; | |
297 | p[6+0] = x1; // a20 | |
298 | p[6+1] = y1; // a21 | |
299 | p[6+2] = z1; // a22 | |
300 | p[9+2] = 1.; // a23 | |
301 | p[0+1] = y1*dzdx2; // a01 | |
302 | p[0+2] = z1*dzdx2; // a02 | |
303 | p[9+0] = dzdx2; // a03 | |
304 | value = z2; | |
305 | fitter->AddPoint(p,value,sz); | |
306 | ||
307 | // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1) | |
308 | // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0 | |
309 | for (Int_t i=0; i<12;i++) p[i]=0.; | |
310 | p[3+0] = 1.; // a10 | |
311 | p[3+1] = dydx1; // a11 | |
312 | p[3+2] = dzdx1; // a12 | |
313 | p[0+0] = -dydx2; // a00 | |
314 | p[0+1] = -dydx1*dydx2; // a01 | |
315 | p[0+2] = -dzdx1*dydx2; // a02 | |
316 | value = 0.; | |
317 | fitter->AddPoint(p,value,sdydx); | |
318 | ||
319 | // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1) | |
320 | // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0 | |
321 | for (Int_t i=0; i<12;i++) p[i]=0.; | |
322 | p[6+0] = 1; // a20 | |
323 | p[6+1] = dydx1; // a21 | |
324 | p[6+2] = dzdx1; // a22 | |
325 | p[0+0] = -dzdx2; // a00 | |
326 | p[0+1] = -dydx1*dzdx2; // a01 | |
327 | p[0+2] = -dzdx1*dzdx2; // a02 | |
328 | value = 0.; | |
329 | fitter->AddPoint(p,value,sdzdx); | |
330 | } | |
331 | ||
332 | void AliTPCcalibAlign::Process9(Double_t *t1, | |
333 | Double_t *t2, | |
334 | TLinearFitter *fitter) { | |
335 | // x2 = a00*x1 + a01*y1 + a02*z1 + a03 | |
336 | // y2 = a10*x1 + a11*y1 + a12*z1 + a13 | |
337 | // z2 = a20*x1 + a21*y1 + a22*z1 + a23 | |
338 | // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1) | |
339 | // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1) | |
340 | // | |
f8a2dcfb | 341 | // a00 a01 a02 a03 1 p[0] p[1] p[6] |
342 | // a10 a11 a12 a13 ==> p[2] 1 p[3] p[7] | |
343 | // a20 a21 a21 a23 p[4] p[5] 1 p[8] | |
344 | ||
345 | ||
9318a5b4 | 346 | Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4]; |
cec17745 | 347 | Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4]; |
9318a5b4 | 348 | |
349 | // TODO: | |
f8a2dcfb | 350 | Double_t sy = 0.1; |
351 | Double_t sz = 0.1; | |
352 | Double_t sdydx = 0.001; | |
353 | Double_t sdzdx = 0.001; | |
354 | // | |
9318a5b4 | 355 | Double_t p[12]; |
356 | Double_t value; | |
357 | ||
358 | // x2 = a00*x1 + a01*y1 + a02*z1 + a03 | |
359 | // y2 = a10*x1 + a11*y1 + a12*z1 + a13 | |
f8a2dcfb | 360 | // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2 |
9318a5b4 | 361 | for (Int_t i=0; i<12;i++) p[i]=0.; |
f8a2dcfb | 362 | p[2] += x1; // a10 |
363 | //p[] +=1; // a11 | |
364 | p[3] += z1; // a12 | |
365 | p[7] += 1; // a13 | |
366 | p[0] += y1*dydx2; // a01 | |
367 | p[1] += z1*dydx2; // a02 | |
368 | p[6] += dydx2; // a03 | |
369 | value = y2-y1; //-a11 | |
9318a5b4 | 370 | fitter->AddPoint(p,value,sy); |
f8a2dcfb | 371 | // |
9318a5b4 | 372 | // x2 = a00*x1 + a01*y1 + a02*z1 + a03 |
373 | // z2 = a20*x1 + a21*y1 + a22*z1 + a23 | |
f8a2dcfb | 374 | // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2; |
9318a5b4 | 375 | for (Int_t i=0; i<12;i++) p[i]=0.; |
f8a2dcfb | 376 | p[4] += x1; // a20 |
377 | p[5] += y1; // a21 | |
378 | //p[] += z1; // a22 | |
379 | p[8] += 1.; // a23 | |
380 | p[0] += y1*dzdx2; // a01 | |
381 | p[1] += z1*dzdx2; // a02 | |
382 | p[6] += dzdx2; // a03 | |
383 | value = z2-z1; //-a22 | |
9318a5b4 | 384 | fitter->AddPoint(p,value,sz); |
385 | ||
386 | // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1) | |
387 | // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0 | |
388 | for (Int_t i=0; i<12;i++) p[i]=0.; | |
f8a2dcfb | 389 | p[2] += 1.; // a10 |
390 | //p[] += dydx1; // a11 | |
391 | p[3] += dzdx1; // a12 | |
392 | //p[] += -dydx2; // a00 | |
393 | p[0] += -dydx1*dydx2; // a01 | |
394 | p[1] += -dzdx1*dydx2; // a02 | |
395 | value = -dydx1+dydx2; // -a11 + a00 | |
9318a5b4 | 396 | fitter->AddPoint(p,value,sdydx); |
397 | ||
398 | // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1) | |
399 | // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0 | |
400 | for (Int_t i=0; i<12;i++) p[i]=0.; | |
f8a2dcfb | 401 | p[4] += 1; // a20 |
402 | p[5] += dydx1; // a21 | |
403 | //p[] += dzdx1; // a22 | |
404 | //p[] += -dzdx2; // a00 | |
405 | p[0] += -dydx1*dzdx2; // a01 | |
406 | p[1] += -dzdx1*dzdx2; // a02 | |
407 | value = -dzdx1+dzdx2; // -a22 + a00 | |
9318a5b4 | 408 | fitter->AddPoint(p,value,sdzdx); |
409 | } | |
410 | ||
411 | void AliTPCcalibAlign::Process6(Double_t *t1, | |
412 | Double_t *t2, | |
413 | TLinearFitter *fitter) { | |
414 | // x2 = 1 *x1 +-a01*y1 + 0 +a03 | |
415 | // y2 = a01*x1 + 1 *y1 + 0 +a13 | |
416 | // z2 = a20*x1 + a21*y1 + 1 *z1 +a23 | |
417 | // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1) | |
418 | // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1) | |
419 | // | |
f8a2dcfb | 420 | // a00 a01 a02 a03 1 -p[0] 0 p[3] |
421 | // a10 a11 a12 a13 ==> p[0] 1 0 p[4] | |
422 | // a20 a21 a21 a23 p[1] p[2] 1 p[5] | |
423 | ||
9318a5b4 | 424 | Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4]; |
cec17745 | 425 | Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4]; |
9318a5b4 | 426 | |
427 | // TODO: | |
7eaa723e | 428 | Double_t sy = 0.1; |
429 | Double_t sz = 0.1; | |
430 | Double_t sdydx = 0.001; | |
431 | Double_t sdzdx = 0.001; | |
9318a5b4 | 432 | |
433 | Double_t p[12]; | |
434 | Double_t value; | |
f8a2dcfb | 435 | // x2 = a00*x1 + a01*y1 + a02*z1 + a03 |
436 | // y2 = a10*x1 + a11*y1 + a12*z1 + a13 | |
9318a5b4 | 437 | // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2 |
438 | for (Int_t i=0; i<12;i++) p[i]=0.; | |
f8a2dcfb | 439 | p[0] += x1; // a10 |
440 | //p[] +=1; // a11 | |
441 | //p[] += z1; // a12 | |
442 | p[4] += 1; // a13 | |
443 | p[0] += -y1*dydx2; // a01 | |
444 | //p[] += z1*dydx2; // a02 | |
445 | p[3] += dydx2; // a03 | |
446 | value = y2-y1; //-a11 | |
9318a5b4 | 447 | fitter->AddPoint(p,value,sy); |
f8a2dcfb | 448 | // |
449 | // x2 = a00*x1 + a01*y1 + a02*z1 + a03 | |
450 | // z2 = a20*x1 + a21*y1 + a22*z1 + a23 | |
451 | // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2; | |
9318a5b4 | 452 | for (Int_t i=0; i<12;i++) p[i]=0.; |
f8a2dcfb | 453 | p[1] += x1; // a20 |
454 | p[2] += y1; // a21 | |
455 | //p[] += z1; // a22 | |
456 | p[5] += 1.; // a23 | |
457 | p[0] += -y1*dzdx2; // a01 | |
458 | //p[] += z1*dzdx2; // a02 | |
459 | p[3] += dzdx2; // a03 | |
460 | value = z2-z1; //-a22 | |
9318a5b4 | 461 | fitter->AddPoint(p,value,sz); |
462 | ||
463 | // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1) | |
464 | // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0 | |
465 | for (Int_t i=0; i<12;i++) p[i]=0.; | |
f8a2dcfb | 466 | p[0] += 1.; // a10 |
467 | //p[] += dydx1; // a11 | |
468 | //p[] += dzdx1; // a12 | |
469 | //p[] += -dydx2; // a00 | |
470 | p[0] += dydx1*dydx2; // a01 | |
471 | //p[] += -dzdx1*dydx2; // a02 | |
472 | value = -dydx1+dydx2; // -a11 + a00 | |
9318a5b4 | 473 | fitter->AddPoint(p,value,sdydx); |
474 | ||
475 | // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1) | |
476 | // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0 | |
477 | for (Int_t i=0; i<12;i++) p[i]=0.; | |
f8a2dcfb | 478 | p[1] += 1; // a20 |
479 | p[2] += dydx1; // a21 | |
480 | //p[] += dzdx1; // a22 | |
481 | //p[] += -dzdx2; // a00 | |
482 | p[0] += dydx1*dzdx2; // a01 | |
483 | //p[] += -dzdx1*dzdx2; // a02 | |
484 | value = -dzdx1+dzdx2; // -a22 + a00 | |
9318a5b4 | 485 | fitter->AddPoint(p,value,sdzdx); |
486 | } | |
487 | ||
7eaa723e | 488 | |
489 | ||
490 | ||
491 | void AliTPCcalibAlign::EvalFitters() { | |
492 | // | |
493 | // Analyze function | |
494 | // | |
495 | // Perform the fitting using linear fitters | |
496 | // | |
497 | Int_t kMinPoints =50; | |
9318a5b4 | 498 | TLinearFitter *f; |
7eaa723e | 499 | TFile fff("alignDebug.root","recreate"); |
9318a5b4 | 500 | for (Int_t s1=0;s1<72;++s1) |
7eaa723e | 501 | for (Int_t s2=0;s2<72;++s2){ |
e81dc112 | 502 | if ((f=GetFitter12(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) { |
503 | // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl; | |
0ebabeb6 | 504 | if (f->Eval()!=0) { |
9318a5b4 | 505 | cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl; |
7eaa723e | 506 | f->Write(Form("f12_%d_%d",s1,s2)); |
507 | }else{ | |
508 | f->Write(Form("f12_%d_%d",s1,s2)); | |
9318a5b4 | 509 | } |
510 | } | |
e81dc112 | 511 | if ((f=GetFitter9(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) { |
512 | // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl; | |
0ebabeb6 | 513 | if (f->Eval()!=0) { |
7eaa723e | 514 | cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl; |
515 | }else{ | |
516 | f->Write(Form("f9_%d_%d",s1,s2)); | |
517 | } | |
518 | } | |
e81dc112 | 519 | if ((f=GetFitter6(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) { |
520 | // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl; | |
972cf6f2 | 521 | if (f->Eval()!=0) { |
7eaa723e | 522 | cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl; |
523 | }else{ | |
524 | f->Write(Form("f6_%d_%d",s1,s2)); | |
525 | } | |
526 | } | |
527 | } | |
0ebabeb6 | 528 | this->Write("align"); |
9318a5b4 | 529 | /* |
530 | ||
531 | fitter->Eval(); | |
532 | fitter->Eval(); | |
533 | chi212 = align->GetChisquare()/(4.*entries); | |
534 | ||
535 | TMatrixD mat(13,13); | |
536 | TVectorD par(13); | |
537 | align->GetParameters(par); | |
538 | align->GetCovarianceMatrix(mat); | |
539 | ||
540 | // | |
541 | // | |
542 | for (Int_t i=0; i<12;i++){ | |
543 | palign12(i)= par(i+1); | |
544 | for (Int_t j=0; j<12;j++){ | |
545 | pcovar12(i,j) = mat(i+1,j+1); | |
546 | pcovar12(i,j) *= chi212; | |
547 | } | |
548 | } | |
549 | // | |
550 | for (Int_t i=0; i<12;i++){ | |
551 | psigma12(i) = TMath::Sqrt(pcovar12(i,i)); | |
552 | palignR12(i) = palign12(i)/TMath::Sqrt(pcovar12(i,i)); | |
553 | for (Int_t j=0; j<12;j++){ | |
554 | pcovarN12(i,j) = pcovar12(i,j)/TMath::Sqrt(pcovar12(i,i)*pcovar12(j,j)); | |
555 | } | |
556 | } | |
557 | */ | |
558 | } | |
559 | ||
972cf6f2 | 560 | TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter12(Int_t s1,Int_t s2) { |
561 | // | |
562 | // get or make fitter - general linear transformation | |
563 | // | |
e81dc112 | 564 | static Int_t counter12=0; |
565 | static TF1 f12("f12","x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]++x[9]++x[10]++x[11]"); | |
972cf6f2 | 566 | TLinearFitter * fitter = GetFitter12(s1,s2); |
567 | if (fitter) return fitter; | |
e81dc112 | 568 | // fitter =new TLinearFitter(12,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]++x[9]++x[10]++x[11]"); |
569 | fitter =new TLinearFitter(&f12,""); | |
972cf6f2 | 570 | fitter->StoreData(kFALSE); |
e81dc112 | 571 | fFitterArray12.AddAt(fitter,GetIndex(s1,s2)); |
572 | counter12++; | |
573 | if (GetDebugLevel()>0) cerr<<"Creating fitter12 "<<s1<<","<<s2<<" : "<<counter12<<endl; | |
972cf6f2 | 574 | return fitter; |
575 | } | |
576 | ||
577 | TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter9(Int_t s1,Int_t s2) { | |
578 | // | |
579 | //get or make fitter - general linear transformation - no scaling | |
580 | // | |
e81dc112 | 581 | static Int_t counter9=0; |
582 | static TF1 f9("f9","x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]"); | |
972cf6f2 | 583 | TLinearFitter * fitter = GetFitter9(s1,s2); |
584 | if (fitter) return fitter; | |
e81dc112 | 585 | // fitter =new TLinearFitter(9,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]"); |
586 | fitter =new TLinearFitter(&f9,""); | |
972cf6f2 | 587 | fitter->StoreData(kFALSE); |
588 | fFitterArray9.AddAt(fitter,GetIndex(s1,s2)); | |
e81dc112 | 589 | counter9++; |
590 | if (GetDebugLevel()>0) cerr<<"Creating fitter12 "<<s1<<","<<s2<<" : "<<counter9<<endl; | |
972cf6f2 | 591 | return fitter; |
592 | } | |
593 | ||
594 | TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter6(Int_t s1,Int_t s2) { | |
595 | // | |
596 | // get or make fitter - 6 paramater linear tranformation | |
597 | // - no scaling | |
598 | // - rotation x-y | |
599 | // - tilting x-z, y-z | |
e81dc112 | 600 | static Int_t counter6=0; |
601 | static TF1 f6("f6","x[0]++x[1]++x[2]++x[3]++x[4]++x[5]"); | |
972cf6f2 | 602 | TLinearFitter * fitter = GetFitter6(s1,s2); |
603 | if (fitter) return fitter; | |
e81dc112 | 604 | // fitter=new TLinearFitter(6,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]"); |
605 | fitter=new TLinearFitter(&f6,""); | |
972cf6f2 | 606 | fitter->StoreData(kFALSE); |
607 | fFitterArray6.AddAt(fitter,GetIndex(s1,s2)); | |
e81dc112 | 608 | counter6++; |
609 | if (GetDebugLevel()>0) cerr<<"Creating fitter6 "<<s1<<","<<s2<<" : "<<counter6<<endl; | |
972cf6f2 | 610 | return fitter; |
611 | } | |
612 | ||
613 | ||
614 | ||
615 | ||
616 | ||
9318a5b4 | 617 | Bool_t AliTPCcalibAlign::GetTransformation12(Int_t s1,Int_t s2,TMatrixD &a) { |
972cf6f2 | 618 | // |
619 | // GetTransformation matrix - 12 paramaters - generael linear transformation | |
620 | // | |
9318a5b4 | 621 | if (!GetFitter12(s1,s2)) |
622 | return false; | |
623 | else { | |
624 | TVectorD p(12); | |
9318a5b4 | 625 | GetFitter12(s1,s2)->GetParameters(p); |
9318a5b4 | 626 | a.ResizeTo(4,4); |
972cf6f2 | 627 | a[0][0]=p[0]; a[0][1]=p[1]; a[0][2]=p[2]; a[0][3]=p[9]; |
628 | a[1][0]=p[3]; a[1][1]=p[4]; a[1][2]=p[5]; a[1][3]=p[10]; | |
629 | a[2][0]=p[6]; a[2][1]=p[7]; a[2][2]=p[8]; a[2][3]=p[11]; | |
630 | a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.; | |
9318a5b4 | 631 | return true; |
632 | } | |
633 | } | |
634 | ||
635 | Bool_t AliTPCcalibAlign::GetTransformation9(Int_t s1,Int_t s2,TMatrixD &a) { | |
972cf6f2 | 636 | // |
637 | // GetTransformation matrix - 9 paramaters - general linear transformation | |
638 | // No scaling | |
639 | // | |
9318a5b4 | 640 | if (!GetFitter9(s1,s2)) |
641 | return false; | |
642 | else { | |
643 | TVectorD p(9); | |
644 | GetFitter9(s1,s2)->GetParameters(p); | |
645 | a.ResizeTo(4,4); | |
f8a2dcfb | 646 | a[0][0]=1; a[0][1]=p[0]; a[0][2]=p[1]; a[0][3]=p[6]; |
647 | a[1][0]=p[2]; a[1][1]=1; a[1][2]=p[3]; a[1][3]=p[7]; | |
648 | a[2][0]=p[4]; a[2][1]=p[5]; a[2][2]=1; a[2][3]=p[8]; | |
972cf6f2 | 649 | a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.; |
9318a5b4 | 650 | return true; |
651 | } | |
652 | } | |
653 | ||
654 | Bool_t AliTPCcalibAlign::GetTransformation6(Int_t s1,Int_t s2,TMatrixD &a) { | |
972cf6f2 | 655 | // |
656 | // GetTransformation matrix - 6 paramaters | |
657 | // 3 translation | |
658 | // 1 rotation -x-y | |
659 | // 2 tilting x-z y-z | |
9318a5b4 | 660 | if (!GetFitter6(s1,s2)) |
661 | return false; | |
662 | else { | |
663 | TVectorD p(6); | |
9318a5b4 | 664 | GetFitter6(s1,s2)->GetParameters(p); |
9318a5b4 | 665 | a.ResizeTo(4,4); |
f8a2dcfb | 666 | a[0][0]=1; a[0][1]=-p[0];a[0][2]=0; a[0][3]=p[3]; |
667 | a[1][0]=p[0]; a[1][1]=1; a[1][2]=0; a[1][3]=p[4]; | |
668 | a[2][0]=p[1]; a[2][1]=p[2]; a[2][2]=1; a[2][3]=p[5]; | |
972cf6f2 | 669 | a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.; |
9318a5b4 | 670 | return true; |
671 | } | |
672 | } | |
972cf6f2 | 673 | |
674 | void AliTPCcalibAlign::FillHisto(const AliExternalTrackParam &tp1, | |
675 | const AliExternalTrackParam &tp2, | |
676 | Int_t s1,Int_t s2) { | |
677 | // | |
678 | // Fill residual histograms | |
8b3c60d8 | 679 | // Innner-Outer |
680 | // Left right - x-y | |
681 | // A-C side | |
682 | if (TMath::Abs(s2%36-s1%36)<2 || TMath::Abs(s2%18-s1%18)==0) { | |
972cf6f2 | 683 | GetHisto(kPhi,s1,s2,kTRUE)->Fill(TMath::ASin(tp1.GetSnp())-TMath::ASin(tp2.GetSnp())); |
684 | GetHisto(kTheta,s1,s2,kTRUE)->Fill(TMath::ATan(tp1.GetTgl())-TMath::ATan(tp2.GetTgl())); | |
685 | GetHisto(kY,s1,s2,kTRUE)->Fill(tp1.GetY()-tp2.GetY()); | |
686 | GetHisto(kZ,s1,s2,kTRUE)->Fill(tp1.GetZ()-tp2.GetZ()); | |
687 | } | |
688 | } | |
689 | ||
690 | ||
691 | ||
692 | TH1 * AliTPCcalibAlign::GetHisto(HistoType type, Int_t s1, Int_t s2, Bool_t force) | |
693 | { | |
694 | // | |
695 | // return specified residual histogram - it is only QA | |
696 | // if force specified the histogram and given histogram is not existing | |
697 | // new histogram is created | |
698 | // | |
699 | if (GetIndex(s1,s2)>=72*72) return 0; | |
700 | TObjArray *histoArray=0; | |
701 | switch (type) { | |
702 | case kY: | |
703 | histoArray = &fDyHistArray; break; | |
704 | case kZ: | |
705 | histoArray = &fDzHistArray; break; | |
706 | case kPhi: | |
707 | histoArray = &fDphiHistArray; break; | |
708 | case kTheta: | |
709 | histoArray = &fDthetaHistArray; break; | |
710 | } | |
711 | TH1 * histo= (TH1*)histoArray->At(GetIndex(s1,s2)); | |
712 | if (histo) return histo; | |
713 | if (force==kFALSE) return 0; | |
714 | // | |
715 | stringstream name; | |
716 | stringstream title; | |
717 | switch (type) { | |
718 | case kY: | |
719 | name<<"hist_y_"<<s1<<"_"<<s2; | |
720 | title<<"Y Missalignment for sectors "<<s1<<" and "<<s2; | |
721 | histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.3,0.3); // +/- 3 mm | |
722 | break; | |
723 | case kZ: | |
724 | name<<"hist_z_"<<s1<<"_"<<s2; | |
725 | title<<"Z Missalignment for sectors "<<s1<<" and "<<s2; | |
726 | histo = new TH1D(name.str().c_str(),title.str().c_str(),512,-0.3,0.3); // +/- 3 mm | |
727 | break; | |
728 | case kPhi: | |
729 | name<<"hist_phi_"<<s1<<"_"<<s2; | |
730 | title<<"Phi Missalignment for sectors "<<s1<<" and "<<s2; | |
731 | histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.01,0.01); // +/- 10 mrad | |
732 | break; | |
733 | case kTheta: | |
734 | name<<"hist_theta_"<<s1<<"_"<<s2; | |
735 | title<<"Theta Missalignment for sectors "<<s1<<" and "<<s2; | |
736 | histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.01,0.01); // +/- 10 mrad | |
737 | break; | |
738 | } | |
739 | histo->SetDirectory(0); | |
740 | histoArray->AddAt(histo,GetIndex(s1,s2)); | |
741 | return histo; | |
742 | } | |
8b3c60d8 | 743 | |
744 | TGraphErrors * AliTPCcalibAlign::MakeGraph(Int_t sec0, Int_t sec1, Int_t dsec, | |
745 | Int_t i0, Int_t i1, FitType type) | |
746 | { | |
747 | // | |
748 | // | |
749 | // | |
750 | TMatrixD mat; | |
751 | TObjArray *fitArray=0; | |
752 | Double_t xsec[1000]; | |
753 | Double_t ysec[1000]; | |
754 | Int_t npoints=0; | |
755 | for (Int_t isec = sec0; isec<=sec1; isec++){ | |
756 | Int_t isec2 = (isec+dsec)%72; | |
757 | switch (type) { | |
758 | case k6: | |
759 | GetTransformation6(isec,isec2,mat);break; | |
760 | case k9: | |
761 | GetTransformation9(isec,isec2,mat);break; | |
762 | case k12: | |
763 | GetTransformation12(isec,isec2,mat);break; | |
764 | } | |
765 | xsec[npoints]=isec; | |
766 | ysec[npoints]=mat(i0,i1); | |
767 | ++npoints; | |
768 | } | |
769 | TGraphErrors *gr = new TGraphErrors(npoints,xsec,ysec,0,0); | |
770 | Char_t name[1000]; | |
771 | sprintf(name,"Mat[%d,%d] Type=%d",i0,i1,type); | |
772 | gr->SetName(name); | |
773 | return gr; | |
774 | } | |
775 | ||
776 | void AliTPCcalibAlign::MakeTree(const char *fname){ | |
777 | // | |
778 | // make tree with alignment cosntant - | |
779 | // For QA visualization | |
780 | // | |
781 | const Int_t kMinPoints=50; | |
782 | TTreeSRedirector cstream(fname); | |
783 | for (Int_t s1=0;s1<72;++s1) | |
784 | for (Int_t s2=0;s2<72;++s2){ | |
785 | if (fPoints[GetIndex(s1,s2)]<kMinPoints) continue; | |
786 | TMatrixD m6; | |
787 | TMatrixD m9; | |
788 | TMatrixD m12; | |
789 | GetTransformation6(s1,s2,m6); | |
790 | GetTransformation9(s1,s2,m9); | |
791 | GetTransformation12(s1,s2,m12); | |
792 | Double_t dy=0, dz=0, dphi=0,dtheta=0; | |
793 | Double_t sy=0, sz=0, sphi=0,stheta=0; | |
794 | Double_t ny=0, nz=0, nphi=0,ntheta=0; | |
795 | TH1 * his=0; | |
796 | his = GetHisto(kY,s1,s2); | |
797 | if (his) { dy = his->GetMean(); sy = his->GetRMS(); ny = his->GetEntries();} | |
798 | his = GetHisto(kZ,s1,s2); | |
799 | if (his) { dz = his->GetMean(); sz = his->GetRMS(); nz = his->GetEntries();} | |
800 | his = GetHisto(kPhi,s1,s2); | |
801 | if (his) { dphi = his->GetMean(); sphi = his->GetRMS(); nphi = his->GetEntries();} | |
802 | his = GetHisto(kTheta,s1,s2); | |
803 | if (his) { dtheta = his->GetMean(); stheta = his->GetRMS(); ntheta = his->GetEntries();} | |
804 | // | |
805 | cstream<<"Align"<< | |
806 | "s1="<<s1<< // reference sector | |
807 | "s2="<<s2<< // sector to align | |
808 | "m6.="<<&m6<< // tranformation matrix | |
809 | "m9.="<<&m9<< // | |
810 | "m12.="<<&m12<< | |
811 | // hsitograms mean RMS and entries | |
812 | "dy="<<dy<< | |
813 | "sy="<<sy<< | |
814 | "ny="<<ny<< | |
815 | "dz="<<dz<< | |
816 | "sz="<<sz<< | |
817 | "nz="<<nz<< | |
818 | "dphi="<<dphi<< | |
819 | "sphi="<<sphi<< | |
820 | "nphi="<<nphi<< | |
821 | "dtheta="<<dtheta<< | |
822 | "stheta="<<stheta<< | |
823 | "ntheta="<<ntheta<< | |
824 | "\n"; | |
825 | } | |
826 | ||
827 | } |