1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // Class to make a internal alignemnt of TPC chambers //
21 // Requierements - Warnings:
22 // 1. Before using this componenent the magnetic filed has to be set properly //
23 // 2. Teh systematic effects - unlinearities has to be understood
25 // Different linear tranformation investigated
27 // 12 parameters - arbitrary linear transformation
28 // a00 a01 a02 a03 p[0] p[1] p[2] p[9]
29 // a10 a11 a12 a13 ==> p[3] p[4] p[5] p[10]
30 // a20 a21 a22 a23 p[6] p[7] p[8] p[11]
32 // 9 parameters - scaling fixed to 1
33 // a00 a01 a02 a03 1 p[0] p[1] p[6]
34 // a10 a11 a12 a13 ==> p[2] 1 p[3] p[7]
35 // a20 a21 a22 a23 p[4] p[5] 1 p[8]
37 // 6 parameters - x-y rotation x-z, y-z tiliting
38 // a00 a01 a02 a03 1 -p[0] 0 p[3]
39 // a10 a11 a12 a13 ==> p[0] 1 0 p[4]
40 // a20 a21 a22 a23 p[1] p[2] 1 p[5]
45 #include "TLinearFitter.h"
46 #include "AliTPCcalibAlign.h"
47 #include "AliExternalTrackParam.h"
48 #include "AliTPCTracklet.h"
51 #include "TTreeStream.h"
54 #include "TGraphErrors.h"
55 #include "AliTPCclusterMI.h"
56 #include "AliTPCseed.h"
57 #include "AliTracker.h"
58 #include "TClonesArray.h"
61 #include "TTreeStream.h"
66 ClassImp(AliTPCcalibAlign)
68 AliTPCcalibAlign::AliTPCcalibAlign()
69 : fDphiHistArray(72*72),
70 fDthetaHistArray(72*72),
73 fFitterArray12(72*72),
80 for (Int_t i=0;i<72*72;++i) {
85 AliTPCcalibAlign::AliTPCcalibAlign(const Text_t *name, const Text_t *title)
87 fDphiHistArray(72*72),
88 fDthetaHistArray(72*72),
91 fFitterArray12(72*72),
100 for (Int_t i=0;i<72*72;++i) {
105 AliTPCcalibAlign::~AliTPCcalibAlign() {
111 void AliTPCcalibAlign::Process(AliTPCseed *seed) {
113 AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kKalman,
115 // TObjArray trackletsL=
116 // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kLinear,
118 // TObjArray trackletsQ=
119 // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kQuadratic,
121 // TObjArray trackletsR=
122 // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kRiemann,
124 tracklets.SetOwner();
125 // trackletsL.SetOwner();
126 // trackletsQ.SetOwner();
127 // trackletsR.SetOwner();
128 if (tracklets.GetEntries()==2) {
129 AliTPCTracklet *t1=static_cast<AliTPCTracklet*>(tracklets[0]);
130 AliTPCTracklet *t2=static_cast<AliTPCTracklet*>(tracklets[1]);
131 if (t1->GetSector()>t2->GetSector()) {
132 AliTPCTracklet* tmp=t1;
136 AliExternalTrackParam *common1=0,*common2=0;
137 if (AliTPCTracklet::PropagateToMeanX(*t1,*t2,common1,common2))
138 ProcessTracklets(*common1,*common2,seed, t1->GetSector(),t2->GetSector());
145 void AliTPCcalibAlign::Analyze(){
153 void AliTPCcalibAlign::Terminate(){
155 // Terminate function
156 // call base terminate + Eval of fitters
158 if (GetDebugLevel()>0) Info("AliTPCcalibAlign","Terminate");
160 AliTPCcalibBase::Terminate();
166 void AliTPCcalibAlign::ProcessTracklets(const AliExternalTrackParam &tp1,
167 const AliExternalTrackParam &tp2,
168 const AliTPCseed * seed,
176 // Process function to fill fitters
178 Double_t t1[5],t2[5];
179 Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
180 Double_t &x2=t2[0], &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
184 Double_t snp1=tp1.GetSnp();
185 dydx1=snp1/TMath::Sqrt(1.-snp1*snp1);
186 Double_t tgl1=tp1.GetTgl();
187 // dz/dx = 1/(cos(theta)*cos(phi))
188 dzdx1=tgl1/TMath::Sqrt(1.-snp1*snp1);
192 Double_t snp2=tp2.GetSnp();
193 dydx2=snp2/TMath::Sqrt(1.-snp2*snp2);
194 Double_t tgl2=tp2.GetTgl();
195 dzdx2=tgl2/TMath::Sqrt(1.-snp2*snp2);
200 TTreeSRedirector *cstream = GetDebugStreamer();
202 static TVectorD vec1(5);
203 static TVectorD vec2(5);
204 vec1.SetElements(t1);
205 vec2.SetElements(t2);
206 AliExternalTrackParam *p1 = &((AliExternalTrackParam&)tp1);
207 AliExternalTrackParam *p2 = &((AliExternalTrackParam&)tp2);
208 (*cstream)<<"Tracklet"<<
219 // Aplly cut selection
221 // Cuts to be justified with the debug streamer
223 TCut c1pt("abs((tp1.fP[4]+tp2.fP[4])*0.5)<5"); // pt cut
224 TCut cd1pt("abs(tp1.fP[4]-tp2.fP[4])<0.5");
225 TCut c1ptpull("abs((tp1.fP[4]-tp2.fP[4])/sqrt(tp1.fC[14]+tp2.fC[14]))<5");
226 TCut csy("sqrt(tp1.fC[0]+tp2.fC[0])<0.5");
227 TCut csz("sqrt(tp1.fC[2]+tp2.fC[2])<0.3");
228 TCut cphi("abs(v1.fElements[3])<1")
229 TCut ctheta("abs(v1.fElements[4])<1")
232 TCut acut = c1ptpull+c1pt+cd1pt+csy+csz+cphi+ctheta;
235 // 2. delta in curvature
241 Double_t sigma1pt = TMath::Sqrt(tp1.GetSigma1Pt2()+tp1.GetSigma1Pt2());
242 Double_t delta1pt = (tp1.GetParameter()[4]-tp2.GetParameter()[4]);
243 Double_t pull1pt = delta1pt/sigma1pt;
244 if (0.5*TMath::Abs(tp1.GetParameter()[4]+tp2.GetParameter()[4])>5) return;
245 if (TMath::Abs(delta1pt)>0.5) return;
246 if (TMath::Abs(pull1pt)>5) return;
247 if (TMath::Sqrt(tp1.GetSigmaY2()+tp2.GetSigmaY2())>0.5) return;
248 if (TMath::Sqrt(tp1.GetSigmaZ2()+tp2.GetSigmaZ2())>0.3) return;
249 if (TMath::Abs(dydx1)>1.) return;
250 if (TMath::Abs(dzdx1)>1.) return;
252 // fill resolution histograms - previous cut included
253 FillHisto(tp1,tp2,s1,s2);
255 Process12(t1,t2,GetOrMakeFitter12(s1,s2));
256 Process9(t1,t2,GetOrMakeFitter9(s1,s2));
257 Process6(t1,t2,GetOrMakeFitter6(s1,s2));
258 ProcessDiff(tp1,tp2, seed,s1,s2);
259 ++fPoints[GetIndex(s1,s2)];
262 void AliTPCcalibAlign::ProcessDiff(const AliExternalTrackParam &t1,
263 const AliExternalTrackParam &t2,
264 const AliTPCseed *seed,
268 // Process local residuals function
273 TVectorD vecClY(160);
274 TVectorD vecClZ(160);
275 TClonesArray arrCl("AliTPCclusterMI",160);
276 arrCl.ExpandCreateFast(160);
277 Int_t count1=0, count2=0;
278 for (Int_t i=0;i<160;++i) {
279 AliTPCclusterMI *c=seed->GetClusterPointer(i);
284 AliTPCclusterMI & cl = (AliTPCclusterMI&) (*arrCl[i]);
285 if (c->GetDetector()!=s1 && c->GetDetector()!=s2) continue;
286 vecClY[i] = c->GetY();
287 vecClZ[i] = c->GetZ();
289 const AliExternalTrackParam *par = (c->GetDetector()==s1)? &t1:&t2;
290 if (c->GetDetector()==s1) ++count1;
291 if (c->GetDetector()==s2) ++count2;
292 Double_t gxyz[3],xyz[3];
294 Float_t bz = AliTracker::GetBz(gxyz);
295 par->GetYAt(c->GetX(), bz, xyz[1]);
296 par->GetZAt(c->GetX(), bz, xyz[2]);
305 // huge output - cluster residuals to be investigated
307 TTreeSRedirector *cstream = GetDebugStreamer();
308 AliTPCseed * t = (AliTPCseed*) seed;
309 //AliExternalTrackParam *p0 = &((AliExternalTrackParam&)seed);
310 AliExternalTrackParam *p1 = &((AliExternalTrackParam&)t1);
311 AliExternalTrackParam *p2 = &((AliExternalTrackParam&)t2);
314 (*cstream)<<"Track"<<
336 void AliTPCcalibAlign::Process12(const Double_t *t1,
338 TLinearFitter *fitter) {
339 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
340 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
341 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
342 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
343 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
345 // a00 a01 a02 a03 p[0] p[1] p[2] p[9]
346 // a10 a11 a12 a13 ==> p[3] p[4] p[5] p[10]
347 // a20 a21 a22 a23 p[6] p[7] p[8] p[11]
351 const Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
352 const Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
357 Double_t sdydx = 0.001;
358 Double_t sdzdx = 0.001;
363 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
364 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
365 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
366 for (Int_t i=0; i<12;i++) p[i]=0.;
371 p[0+1] = y1*dydx2; // a01
372 p[0+2] = z1*dydx2; // a02
373 p[9+0] = dydx2; // a03
375 fitter->AddPoint(p,value,sy);
377 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
378 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
379 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
380 for (Int_t i=0; i<12;i++) p[i]=0.;
385 p[0+1] = y1*dzdx2; // a01
386 p[0+2] = z1*dzdx2; // a02
387 p[9+0] = dzdx2; // a03
389 fitter->AddPoint(p,value,sz);
391 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
392 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
393 for (Int_t i=0; i<12;i++) p[i]=0.;
395 p[3+1] = dydx1; // a11
396 p[3+2] = dzdx1; // a12
397 p[0+0] = -dydx2; // a00
398 p[0+1] = -dydx1*dydx2; // a01
399 p[0+2] = -dzdx1*dydx2; // a02
401 fitter->AddPoint(p,value,sdydx);
403 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
404 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
405 for (Int_t i=0; i<12;i++) p[i]=0.;
407 p[6+1] = dydx1; // a21
408 p[6+2] = dzdx1; // a22
409 p[0+0] = -dzdx2; // a00
410 p[0+1] = -dydx1*dzdx2; // a01
411 p[0+2] = -dzdx1*dzdx2; // a02
413 fitter->AddPoint(p,value,sdzdx);
416 void AliTPCcalibAlign::Process9(Double_t *t1,
418 TLinearFitter *fitter) {
419 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
420 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
421 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
422 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
423 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
425 // a00 a01 a02 a03 1 p[0] p[1] p[6]
426 // a10 a11 a12 a13 ==> p[2] 1 p[3] p[7]
427 // a20 a21 a21 a23 p[4] p[5] 1 p[8]
430 Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
431 Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
436 Double_t sdydx = 0.001;
437 Double_t sdzdx = 0.001;
442 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
443 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
444 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
445 for (Int_t i=0; i<12;i++) p[i]=0.;
450 p[0] += y1*dydx2; // a01
451 p[1] += z1*dydx2; // a02
452 p[6] += dydx2; // a03
453 value = y2-y1; //-a11
454 fitter->AddPoint(p,value,sy);
456 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
457 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
458 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
459 for (Int_t i=0; i<12;i++) p[i]=0.;
464 p[0] += y1*dzdx2; // a01
465 p[1] += z1*dzdx2; // a02
466 p[6] += dzdx2; // a03
467 value = z2-z1; //-a22
468 fitter->AddPoint(p,value,sz);
470 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
471 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
472 for (Int_t i=0; i<12;i++) p[i]=0.;
474 //p[] += dydx1; // a11
475 p[3] += dzdx1; // a12
476 //p[] += -dydx2; // a00
477 p[0] += -dydx1*dydx2; // a01
478 p[1] += -dzdx1*dydx2; // a02
479 value = -dydx1+dydx2; // -a11 + a00
480 fitter->AddPoint(p,value,sdydx);
482 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
483 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
484 for (Int_t i=0; i<12;i++) p[i]=0.;
486 p[5] += dydx1; // a21
487 //p[] += dzdx1; // a22
488 //p[] += -dzdx2; // a00
489 p[0] += -dydx1*dzdx2; // a01
490 p[1] += -dzdx1*dzdx2; // a02
491 value = -dzdx1+dzdx2; // -a22 + a00
492 fitter->AddPoint(p,value,sdzdx);
495 void AliTPCcalibAlign::Process6(Double_t *t1,
497 TLinearFitter *fitter) {
498 // x2 = 1 *x1 +-a01*y1 + 0 +a03
499 // y2 = a01*x1 + 1 *y1 + 0 +a13
500 // z2 = a20*x1 + a21*y1 + 1 *z1 +a23
501 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
502 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
504 // a00 a01 a02 a03 1 -p[0] 0 p[3]
505 // a10 a11 a12 a13 ==> p[0] 1 0 p[4]
506 // a20 a21 a21 a23 p[1] p[2] 1 p[5]
508 Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
509 Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
514 Double_t sdydx = 0.001;
515 Double_t sdzdx = 0.001;
519 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
520 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
521 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
522 for (Int_t i=0; i<12;i++) p[i]=0.;
527 p[0] += -y1*dydx2; // a01
528 //p[] += z1*dydx2; // a02
529 p[3] += dydx2; // a03
530 value = y2-y1; //-a11
531 fitter->AddPoint(p,value,sy);
533 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
534 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
535 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
536 for (Int_t i=0; i<12;i++) p[i]=0.;
541 p[0] += -y1*dzdx2; // a01
542 //p[] += z1*dzdx2; // a02
543 p[3] += dzdx2; // a03
544 value = z2-z1; //-a22
545 fitter->AddPoint(p,value,sz);
547 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
548 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
549 for (Int_t i=0; i<12;i++) p[i]=0.;
551 //p[] += dydx1; // a11
552 //p[] += dzdx1; // a12
553 //p[] += -dydx2; // a00
554 p[0] += dydx1*dydx2; // a01
555 //p[] += -dzdx1*dydx2; // a02
556 value = -dydx1+dydx2; // -a11 + a00
557 fitter->AddPoint(p,value,sdydx);
559 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
560 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
561 for (Int_t i=0; i<12;i++) p[i]=0.;
563 p[2] += dydx1; // a21
564 //p[] += dzdx1; // a22
565 //p[] += -dzdx2; // a00
566 p[0] += dydx1*dzdx2; // a01
567 //p[] += -dzdx1*dzdx2; // a02
568 value = -dzdx1+dzdx2; // -a22 + a00
569 fitter->AddPoint(p,value,sdzdx);
575 void AliTPCcalibAlign::EvalFitters() {
579 // Perform the fitting using linear fitters
581 Int_t kMinPoints =50;
583 TFile fff("alignDebug.root","recreate");
584 for (Int_t s1=0;s1<72;++s1)
585 for (Int_t s2=0;s2<72;++s2){
586 if ((f=GetFitter12(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
587 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
589 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
590 f->Write(Form("f12_%d_%d",s1,s2));
592 f->Write(Form("f12_%d_%d",s1,s2));
595 if ((f=GetFitter9(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
596 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
598 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
600 f->Write(Form("f9_%d_%d",s1,s2));
603 if ((f=GetFitter6(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
604 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
606 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
608 f->Write(Form("f6_%d_%d",s1,s2));
612 this->Write("align");
617 chi212 = align->GetChisquare()/(4.*entries);
621 align->GetParameters(par);
622 align->GetCovarianceMatrix(mat);
626 for (Int_t i=0; i<12;i++){
627 palign12(i)= par(i+1);
628 for (Int_t j=0; j<12;j++){
629 pcovar12(i,j) = mat(i+1,j+1);
630 pcovar12(i,j) *= chi212;
634 for (Int_t i=0; i<12;i++){
635 psigma12(i) = TMath::Sqrt(pcovar12(i,i));
636 palignR12(i) = palign12(i)/TMath::Sqrt(pcovar12(i,i));
637 for (Int_t j=0; j<12;j++){
638 pcovarN12(i,j) = pcovar12(i,j)/TMath::Sqrt(pcovar12(i,i)*pcovar12(j,j));
644 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter12(Int_t s1,Int_t s2) {
646 // get or make fitter - general linear transformation
648 static Int_t counter12=0;
649 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]");
650 TLinearFitter * fitter = GetFitter12(s1,s2);
651 if (fitter) return fitter;
652 // 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]");
653 fitter =new TLinearFitter(&f12,"");
654 fitter->StoreData(kFALSE);
655 fFitterArray12.AddAt(fitter,GetIndex(s1,s2));
657 if (GetDebugLevel()>0) cerr<<"Creating fitter12 "<<s1<<","<<s2<<" : "<<counter12<<endl;
661 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter9(Int_t s1,Int_t s2) {
663 //get or make fitter - general linear transformation - no scaling
665 static Int_t counter9=0;
666 static TF1 f9("f9","x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]");
667 TLinearFitter * fitter = GetFitter9(s1,s2);
668 if (fitter) return fitter;
669 // fitter =new TLinearFitter(9,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]");
670 fitter =new TLinearFitter(&f9,"");
671 fitter->StoreData(kFALSE);
672 fFitterArray9.AddAt(fitter,GetIndex(s1,s2));
674 if (GetDebugLevel()>0) cerr<<"Creating fitter12 "<<s1<<","<<s2<<" : "<<counter9<<endl;
678 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter6(Int_t s1,Int_t s2) {
680 // get or make fitter - 6 paramater linear tranformation
683 // - tilting x-z, y-z
684 static Int_t counter6=0;
685 static TF1 f6("f6","x[0]++x[1]++x[2]++x[3]++x[4]++x[5]");
686 TLinearFitter * fitter = GetFitter6(s1,s2);
687 if (fitter) return fitter;
688 // fitter=new TLinearFitter(6,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]");
689 fitter=new TLinearFitter(&f6,"");
690 fitter->StoreData(kFALSE);
691 fFitterArray6.AddAt(fitter,GetIndex(s1,s2));
693 if (GetDebugLevel()>0) cerr<<"Creating fitter6 "<<s1<<","<<s2<<" : "<<counter6<<endl;
701 Bool_t AliTPCcalibAlign::GetTransformation12(Int_t s1,Int_t s2,TMatrixD &a) {
703 // GetTransformation matrix - 12 paramaters - generael linear transformation
705 if (!GetFitter12(s1,s2))
709 GetFitter12(s1,s2)->GetParameters(p);
711 a[0][0]=p[0]; a[0][1]=p[1]; a[0][2]=p[2]; a[0][3]=p[9];
712 a[1][0]=p[3]; a[1][1]=p[4]; a[1][2]=p[5]; a[1][3]=p[10];
713 a[2][0]=p[6]; a[2][1]=p[7]; a[2][2]=p[8]; a[2][3]=p[11];
714 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
719 Bool_t AliTPCcalibAlign::GetTransformation9(Int_t s1,Int_t s2,TMatrixD &a) {
721 // GetTransformation matrix - 9 paramaters - general linear transformation
724 if (!GetFitter9(s1,s2))
728 GetFitter9(s1,s2)->GetParameters(p);
730 a[0][0]=1; a[0][1]=p[0]; a[0][2]=p[1]; a[0][3]=p[6];
731 a[1][0]=p[2]; a[1][1]=1; a[1][2]=p[3]; a[1][3]=p[7];
732 a[2][0]=p[4]; a[2][1]=p[5]; a[2][2]=1; a[2][3]=p[8];
733 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
738 Bool_t AliTPCcalibAlign::GetTransformation6(Int_t s1,Int_t s2,TMatrixD &a) {
740 // GetTransformation matrix - 6 paramaters
744 if (!GetFitter6(s1,s2))
748 GetFitter6(s1,s2)->GetParameters(p);
750 a[0][0]=1; a[0][1]=-p[0];a[0][2]=0; a[0][3]=p[3];
751 a[1][0]=p[0]; a[1][1]=1; a[1][2]=0; a[1][3]=p[4];
752 a[2][0]=p[1]; a[2][1]=p[2]; a[2][2]=1; a[2][3]=p[5];
753 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
758 void AliTPCcalibAlign::FillHisto(const AliExternalTrackParam &tp1,
759 const AliExternalTrackParam &tp2,
762 // Fill residual histograms
766 if (TMath::Abs(s2%36-s1%36)<2 || TMath::Abs(s2%18-s1%18)==0) {
767 GetHisto(kPhi,s1,s2,kTRUE)->Fill(TMath::ASin(tp1.GetSnp())-TMath::ASin(tp2.GetSnp()));
768 GetHisto(kTheta,s1,s2,kTRUE)->Fill(TMath::ATan(tp1.GetTgl())-TMath::ATan(tp2.GetTgl()));
769 GetHisto(kY,s1,s2,kTRUE)->Fill(tp1.GetY()-tp2.GetY());
770 GetHisto(kZ,s1,s2,kTRUE)->Fill(tp1.GetZ()-tp2.GetZ());
776 TH1 * AliTPCcalibAlign::GetHisto(HistoType type, Int_t s1, Int_t s2, Bool_t force)
779 // return specified residual histogram - it is only QA
780 // if force specified the histogram and given histogram is not existing
781 // new histogram is created
783 if (GetIndex(s1,s2)>=72*72) return 0;
784 TObjArray *histoArray=0;
787 histoArray = &fDyHistArray; break;
789 histoArray = &fDzHistArray; break;
791 histoArray = &fDphiHistArray; break;
793 histoArray = &fDthetaHistArray; break;
795 TH1 * histo= (TH1*)histoArray->At(GetIndex(s1,s2));
796 if (histo) return histo;
797 if (force==kFALSE) return 0;
803 name<<"hist_y_"<<s1<<"_"<<s2;
804 title<<"Y Missalignment for sectors "<<s1<<" and "<<s2;
805 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.3,0.3); // +/- 3 mm
808 name<<"hist_z_"<<s1<<"_"<<s2;
809 title<<"Z Missalignment for sectors "<<s1<<" and "<<s2;
810 histo = new TH1D(name.str().c_str(),title.str().c_str(),512,-0.3,0.3); // +/- 3 mm
813 name<<"hist_phi_"<<s1<<"_"<<s2;
814 title<<"Phi Missalignment for sectors "<<s1<<" and "<<s2;
815 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.01,0.01); // +/- 10 mrad
818 name<<"hist_theta_"<<s1<<"_"<<s2;
819 title<<"Theta Missalignment for sectors "<<s1<<" and "<<s2;
820 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.01,0.01); // +/- 10 mrad
823 histo->SetDirectory(0);
824 histoArray->AddAt(histo,GetIndex(s1,s2));
828 TGraphErrors * AliTPCcalibAlign::MakeGraph(Int_t sec0, Int_t sec1, Int_t dsec,
829 Int_t i0, Int_t i1, FitType type)
835 TObjArray *fitArray=0;
839 for (Int_t isec = sec0; isec<=sec1; isec++){
840 Int_t isec2 = (isec+dsec)%72;
843 GetTransformation6(isec,isec2,mat);break;
845 GetTransformation9(isec,isec2,mat);break;
847 GetTransformation12(isec,isec2,mat);break;
850 ysec[npoints]=mat(i0,i1);
853 TGraphErrors *gr = new TGraphErrors(npoints,xsec,ysec,0,0);
855 sprintf(name,"Mat[%d,%d] Type=%d",i0,i1,type);
860 void AliTPCcalibAlign::MakeTree(const char *fname){
862 // make tree with alignment cosntant -
863 // For QA visualization
865 const Int_t kMinPoints=50;
866 TTreeSRedirector cstream(fname);
867 for (Int_t s1=0;s1<72;++s1)
868 for (Int_t s2=0;s2<72;++s2){
869 if (fPoints[GetIndex(s1,s2)]<kMinPoints) continue;
873 GetTransformation6(s1,s2,m6);
874 GetTransformation9(s1,s2,m9);
875 GetTransformation12(s1,s2,m12);
876 Double_t dy=0, dz=0, dphi=0,dtheta=0;
877 Double_t sy=0, sz=0, sphi=0,stheta=0;
878 Double_t ny=0, nz=0, nphi=0,ntheta=0;
880 his = GetHisto(kY,s1,s2);
881 if (his) { dy = his->GetMean(); sy = his->GetRMS(); ny = his->GetEntries();}
882 his = GetHisto(kZ,s1,s2);
883 if (his) { dz = his->GetMean(); sz = his->GetRMS(); nz = his->GetEntries();}
884 his = GetHisto(kPhi,s1,s2);
885 if (his) { dphi = his->GetMean(); sphi = his->GetRMS(); nphi = his->GetEntries();}
886 his = GetHisto(kTheta,s1,s2);
887 if (his) { dtheta = his->GetMean(); stheta = his->GetRMS(); ntheta = his->GetEntries();}
890 "s1="<<s1<< // reference sector
891 "s2="<<s2<< // sector to align
892 "m6.="<<&m6<< // tranformation matrix
895 // histograms mean RMS and entries