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. The systematic effects - unlinearities has to be understood
25 // If systematic and unlinearities are not under control
26 // the alignment is just effective alignment. Not second order corrction
29 // The histograming of the edge effects and unlineratities integral part
30 // of the component (currently only in debug stream)
32 // 3 general type of linear transformation investigated (see bellow)
34 // By default only 6 parameter alignment to be used - other just for QA purposes
36 // Different linear tranformation investigated
37 // 12 parameters - arbitrary linear transformation
38 // a00 a01 a02 a03 p[0] p[1] p[2] p[9]
39 // a10 a11 a12 a13 ==> p[3] p[4] p[5] p[10]
40 // a20 a21 a22 a23 p[6] p[7] p[8] p[11]
42 // 9 parameters - scaling fixed to 1
43 // a00 a01 a02 a03 1 p[0] p[1] p[6]
44 // a10 a11 a12 a13 ==> p[2] 1 p[3] p[7]
45 // a20 a21 a22 a23 p[4] p[5] 1 p[8]
47 // 6 parameters - x-y rotation x-z, y-z tiliting
48 // a00 a01 a02 a03 1 -p[0] 0 p[3]
49 // a10 a11 a12 a13 ==> p[0] 1 0 p[4]
50 // a20 a21 a22 a23 p[1] p[2] 1 p[5]
53 // Debug stream supported
54 // 0. Align - The main output of the Alignment component
55 // - Used for visualization of the misalignment between sectors
56 // - Results of the missalignment fit and the mean and sigmas of histograms
58 // 1. Tracklet - StreamLevel >1
59 // - Dump all information about tracklet match from sector1 to sector 2
60 // - Default histogram residulas created in parallel
61 // - Check this streamer in case of suspicious content of these histograms
62 // 2. Track - StreamLevel>5
63 // - For debugging of the edge effects
64 // - All information - extrapolation inside of one sectors
65 // - Created in order to distinguish between unlinearities inside of o
66 // sector and missalignment
73 #include "TLinearFitter.h"
74 #include "AliTPCcalibAlign.h"
75 #include "AliExternalTrackParam.h"
76 #include "AliTPCTracklet.h"
79 #include "TTreeStream.h"
82 #include "TGraphErrors.h"
83 #include "AliTPCclusterMI.h"
84 #include "AliTPCseed.h"
85 #include "AliTracker.h"
86 #include "TClonesArray.h"
89 #include "TTreeStream.h"
94 ClassImp(AliTPCcalibAlign)
96 AliTPCcalibAlign::AliTPCcalibAlign()
97 : fDphiHistArray(72*72),
98 fDthetaHistArray(72*72),
101 fFitterArray12(72*72),
102 fFitterArray9(72*72),
108 for (Int_t i=0;i<72*72;++i) {
113 AliTPCcalibAlign::AliTPCcalibAlign(const Text_t *name, const Text_t *title)
115 fDphiHistArray(72*72),
116 fDthetaHistArray(72*72),
119 fFitterArray12(72*72),
120 fFitterArray9(72*72),
128 for (Int_t i=0;i<72*72;++i) {
133 AliTPCcalibAlign::~AliTPCcalibAlign() {
139 void AliTPCcalibAlign::Process(AliTPCseed *seed) {
141 AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kKalman,
143 // TObjArray trackletsL=
144 // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kLinear,
146 // TObjArray trackletsQ=
147 // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kQuadratic,
149 // TObjArray trackletsR=
150 // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kRiemann,
152 tracklets.SetOwner();
153 // trackletsL.SetOwner();
154 // trackletsQ.SetOwner();
155 // trackletsR.SetOwner();
156 if (tracklets.GetEntries()==2) {
157 AliTPCTracklet *t1=static_cast<AliTPCTracklet*>(tracklets[0]);
158 AliTPCTracklet *t2=static_cast<AliTPCTracklet*>(tracklets[1]);
159 if (t1->GetSector()>t2->GetSector()) {
160 AliTPCTracklet* tmp=t1;
164 AliExternalTrackParam *common1=0,*common2=0;
165 if (AliTPCTracklet::PropagateToMeanX(*t1,*t2,common1,common2))
166 ProcessTracklets(*common1,*common2,seed, t1->GetSector(),t2->GetSector());
173 void AliTPCcalibAlign::Analyze(){
181 void AliTPCcalibAlign::Terminate(){
183 // Terminate function
184 // call base terminate + Eval of fitters
186 if (GetDebugLevel()>0) Info("AliTPCcalibAlign","Terminate");
188 AliTPCcalibBase::Terminate();
194 void AliTPCcalibAlign::ProcessTracklets(const AliExternalTrackParam &tp1,
195 const AliExternalTrackParam &tp2,
196 const AliTPCseed * seed,
204 // Process function to fill fitters
206 Double_t t1[5],t2[5];
207 Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
208 Double_t &x2=t2[0], &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
212 Double_t snp1=tp1.GetSnp();
213 dydx1=snp1/TMath::Sqrt(1.-snp1*snp1);
214 Double_t tgl1=tp1.GetTgl();
215 // dz/dx = 1/(cos(theta)*cos(phi))
216 dzdx1=tgl1/TMath::Sqrt(1.-snp1*snp1);
220 Double_t snp2=tp2.GetSnp();
221 dydx2=snp2/TMath::Sqrt(1.-snp2*snp2);
222 Double_t tgl2=tp2.GetTgl();
223 dzdx2=tgl2/TMath::Sqrt(1.-snp2*snp2);
228 TTreeSRedirector *cstream = GetDebugStreamer();
230 static TVectorD vec1(5);
231 static TVectorD vec2(5);
232 vec1.SetElements(t1);
233 vec2.SetElements(t2);
234 AliExternalTrackParam *p1 = &((AliExternalTrackParam&)tp1);
235 AliExternalTrackParam *p2 = &((AliExternalTrackParam&)tp2);
236 (*cstream)<<"Tracklet"<<
247 // Aplly cut selection
249 // Cuts to be justified with the debug streamer
251 TCut c1pt("abs((tp1.fP[4]+tp2.fP[4])*0.5)<3"); // pt cut - OK
252 TCut cdy("abs(tp1.fP[0]-tp2.fP[0])<2");
253 TCut cdz("abs(tp1.fP[1]-tp2.fP[1])<2");
254 TCut cdphi("abs(tp1.fP[2]-tp2.fP[2])<0.02");
255 TCut cdt("abs(tp1.fP[3]-tp2.fP[3])<0.02");
256 TCut cd1pt("abs(tp1.fP[4]-tp2.fP[4])<0.3"); // delta 1/pt cut -OK
259 TCut acut = c1pt+cdy+cdz+cdphi+cdt+cd1pt;
268 if (TMath::Abs(tp1.GetParameter()[0]-tp2.GetParameter()[0])>2) return;
269 if (TMath::Abs(tp1.GetParameter()[1]-tp2.GetParameter()[1])>2) return;
270 if (TMath::Abs(tp1.GetParameter()[2]-tp2.GetParameter()[2])>0.02) return;
271 if (TMath::Abs(tp1.GetParameter()[3]-tp2.GetParameter()[3])>0.02) return;
272 if (TMath::Abs(tp1.GetParameter()[4]-tp2.GetParameter()[4])>0.3) return;
273 if (TMath::Abs((tp1.GetParameter()[4]+tp2.GetParameter()[4])*0.5)<3) return;
275 // fill resolution histograms - previous cut included
276 FillHisto(tp1,tp2,s1,s2);
278 Process12(t1,t2,GetOrMakeFitter12(s1,s2));
279 Process9(t1,t2,GetOrMakeFitter9(s1,s2));
280 Process6(t1,t2,GetOrMakeFitter6(s1,s2));
281 ProcessDiff(tp1,tp2, seed,s1,s2);
282 ++fPoints[GetIndex(s1,s2)];
285 void AliTPCcalibAlign::ProcessDiff(const AliExternalTrackParam &t1,
286 const AliExternalTrackParam &t2,
287 const AliTPCseed *seed,
291 // Process local residuals function
296 TVectorD vecClY(160);
297 TVectorD vecClZ(160);
298 TClonesArray arrCl("AliTPCclusterMI",160);
299 arrCl.ExpandCreateFast(160);
300 Int_t count1=0, count2=0;
301 for (Int_t i=0;i<160;++i) {
302 AliTPCclusterMI *c=seed->GetClusterPointer(i);
307 AliTPCclusterMI & cl = (AliTPCclusterMI&) (*arrCl[i]);
308 if (c->GetDetector()!=s1 && c->GetDetector()!=s2) continue;
309 vecClY[i] = c->GetY();
310 vecClZ[i] = c->GetZ();
312 const AliExternalTrackParam *par = (c->GetDetector()==s1)? &t1:&t2;
313 if (c->GetDetector()==s1) ++count1;
314 if (c->GetDetector()==s2) ++count2;
315 Double_t gxyz[3],xyz[3];
317 Float_t bz = AliTracker::GetBz(gxyz);
318 par->GetYAt(c->GetX(), bz, xyz[1]);
319 par->GetZAt(c->GetX(), bz, xyz[2]);
328 // huge output - cluster residuals to be investigated
330 TTreeSRedirector *cstream = GetDebugStreamer();
331 AliTPCseed * t = (AliTPCseed*) seed;
332 //AliExternalTrackParam *p0 = &((AliExternalTrackParam&)seed);
333 AliExternalTrackParam *p1 = &((AliExternalTrackParam&)t1);
334 AliExternalTrackParam *p2 = &((AliExternalTrackParam&)t2);
337 Track->Draw("Cl[].fY-vtY.fElements:vtY.fElements-vtX.fElements*tan(pi/18.)>>his(100,-10,0)","Cl.fY!=0&&abs(Cl.fY-vtY.fElements)<1","prof");
342 (*cstream)<<"Track"<<
364 void AliTPCcalibAlign::Process12(const Double_t *t1,
366 TLinearFitter *fitter) {
367 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
368 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
369 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
370 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
371 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
373 // a00 a01 a02 a03 p[0] p[1] p[2] p[9]
374 // a10 a11 a12 a13 ==> p[3] p[4] p[5] p[10]
375 // a20 a21 a22 a23 p[6] p[7] p[8] p[11]
379 const Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
380 const Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
385 Double_t sdydx = 0.001;
386 Double_t sdzdx = 0.001;
391 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
392 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
393 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
394 for (Int_t i=0; i<12;i++) p[i]=0.;
399 p[0+1] = y1*dydx2; // a01
400 p[0+2] = z1*dydx2; // a02
401 p[9+0] = dydx2; // a03
403 fitter->AddPoint(p,value,sy);
405 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
406 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
407 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
408 for (Int_t i=0; i<12;i++) p[i]=0.;
413 p[0+1] = y1*dzdx2; // a01
414 p[0+2] = z1*dzdx2; // a02
415 p[9+0] = dzdx2; // a03
417 fitter->AddPoint(p,value,sz);
419 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
420 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
421 for (Int_t i=0; i<12;i++) p[i]=0.;
423 p[3+1] = dydx1; // a11
424 p[3+2] = dzdx1; // a12
425 p[0+0] = -dydx2; // a00
426 p[0+1] = -dydx1*dydx2; // a01
427 p[0+2] = -dzdx1*dydx2; // a02
429 fitter->AddPoint(p,value,sdydx);
431 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
432 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
433 for (Int_t i=0; i<12;i++) p[i]=0.;
435 p[6+1] = dydx1; // a21
436 p[6+2] = dzdx1; // a22
437 p[0+0] = -dzdx2; // a00
438 p[0+1] = -dydx1*dzdx2; // a01
439 p[0+2] = -dzdx1*dzdx2; // a02
441 fitter->AddPoint(p,value,sdzdx);
444 void AliTPCcalibAlign::Process9(Double_t *t1,
446 TLinearFitter *fitter) {
447 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
448 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
449 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
450 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
451 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
453 // a00 a01 a02 a03 1 p[0] p[1] p[6]
454 // a10 a11 a12 a13 ==> p[2] 1 p[3] p[7]
455 // a20 a21 a21 a23 p[4] p[5] 1 p[8]
458 Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
459 Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
464 Double_t sdydx = 0.001;
465 Double_t sdzdx = 0.001;
470 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
471 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
472 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
473 for (Int_t i=0; i<12;i++) p[i]=0.;
478 p[0] += y1*dydx2; // a01
479 p[1] += z1*dydx2; // a02
480 p[6] += dydx2; // a03
481 value = y2-y1; //-a11
482 fitter->AddPoint(p,value,sy);
484 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
485 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
486 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
487 for (Int_t i=0; i<12;i++) p[i]=0.;
492 p[0] += y1*dzdx2; // a01
493 p[1] += z1*dzdx2; // a02
494 p[6] += dzdx2; // a03
495 value = z2-z1; //-a22
496 fitter->AddPoint(p,value,sz);
498 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
499 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
500 for (Int_t i=0; i<12;i++) p[i]=0.;
502 //p[] += dydx1; // a11
503 p[3] += dzdx1; // a12
504 //p[] += -dydx2; // a00
505 p[0] += -dydx1*dydx2; // a01
506 p[1] += -dzdx1*dydx2; // a02
507 value = -dydx1+dydx2; // -a11 + a00
508 fitter->AddPoint(p,value,sdydx);
510 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
511 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
512 for (Int_t i=0; i<12;i++) p[i]=0.;
514 p[5] += dydx1; // a21
515 //p[] += dzdx1; // a22
516 //p[] += -dzdx2; // a00
517 p[0] += -dydx1*dzdx2; // a01
518 p[1] += -dzdx1*dzdx2; // a02
519 value = -dzdx1+dzdx2; // -a22 + a00
520 fitter->AddPoint(p,value,sdzdx);
523 void AliTPCcalibAlign::Process6(Double_t *t1,
525 TLinearFitter *fitter) {
526 // x2 = 1 *x1 +-a01*y1 + 0 +a03
527 // y2 = a01*x1 + 1 *y1 + 0 +a13
528 // z2 = a20*x1 + a21*y1 + 1 *z1 +a23
529 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
530 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
532 // a00 a01 a02 a03 1 -p[0] 0 p[3]
533 // a10 a11 a12 a13 ==> p[0] 1 0 p[4]
534 // a20 a21 a21 a23 p[1] p[2] 1 p[5]
536 Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
537 Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
542 Double_t sdydx = 0.001;
543 Double_t sdzdx = 0.001;
547 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
548 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
549 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
550 for (Int_t i=0; i<12;i++) p[i]=0.;
555 p[0] += -y1*dydx2; // a01
556 //p[] += z1*dydx2; // a02
557 p[3] += dydx2; // a03
558 value = y2-y1; //-a11
559 fitter->AddPoint(p,value,sy);
561 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
562 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
563 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
564 for (Int_t i=0; i<12;i++) p[i]=0.;
569 p[0] += -y1*dzdx2; // a01
570 //p[] += z1*dzdx2; // a02
571 p[3] += dzdx2; // a03
572 value = z2-z1; //-a22
573 fitter->AddPoint(p,value,sz);
575 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
576 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
577 for (Int_t i=0; i<12;i++) p[i]=0.;
579 //p[] += dydx1; // a11
580 //p[] += dzdx1; // a12
581 //p[] += -dydx2; // a00
582 p[0] += dydx1*dydx2; // a01
583 //p[] += -dzdx1*dydx2; // a02
584 value = -dydx1+dydx2; // -a11 + a00
585 fitter->AddPoint(p,value,sdydx);
587 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
588 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
589 for (Int_t i=0; i<12;i++) p[i]=0.;
591 p[2] += dydx1; // a21
592 //p[] += dzdx1; // a22
593 //p[] += -dzdx2; // a00
594 p[0] += dydx1*dzdx2; // a01
595 //p[] += -dzdx1*dzdx2; // a02
596 value = -dzdx1+dzdx2; // -a22 + a00
597 fitter->AddPoint(p,value,sdzdx);
603 void AliTPCcalibAlign::EvalFitters() {
607 // Perform the fitting using linear fitters
609 Int_t kMinPoints =50;
611 TFile fff("alignDebug.root","recreate");
612 for (Int_t s1=0;s1<72;++s1)
613 for (Int_t s2=0;s2<72;++s2){
614 if ((f=GetFitter12(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
615 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
617 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
618 f->Write(Form("f12_%d_%d",s1,s2));
620 f->Write(Form("f12_%d_%d",s1,s2));
623 if ((f=GetFitter9(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
624 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
626 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
628 f->Write(Form("f9_%d_%d",s1,s2));
631 if ((f=GetFitter6(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
632 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
634 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
636 f->Write(Form("f6_%d_%d",s1,s2));
640 this->Write("align");
645 chi212 = align->GetChisquare()/(4.*entries);
649 align->GetParameters(par);
650 align->GetCovarianceMatrix(mat);
654 for (Int_t i=0; i<12;i++){
655 palign12(i)= par(i+1);
656 for (Int_t j=0; j<12;j++){
657 pcovar12(i,j) = mat(i+1,j+1);
658 pcovar12(i,j) *= chi212;
662 for (Int_t i=0; i<12;i++){
663 psigma12(i) = TMath::Sqrt(pcovar12(i,i));
664 palignR12(i) = palign12(i)/TMath::Sqrt(pcovar12(i,i));
665 for (Int_t j=0; j<12;j++){
666 pcovarN12(i,j) = pcovar12(i,j)/TMath::Sqrt(pcovar12(i,i)*pcovar12(j,j));
672 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter12(Int_t s1,Int_t s2) {
674 // get or make fitter - general linear transformation
676 static Int_t counter12=0;
677 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]");
678 TLinearFitter * fitter = GetFitter12(s1,s2);
679 if (fitter) return fitter;
680 // 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]");
681 fitter =new TLinearFitter(&f12,"");
682 fitter->StoreData(kFALSE);
683 fFitterArray12.AddAt(fitter,GetIndex(s1,s2));
685 if (GetDebugLevel()>0) cerr<<"Creating fitter12 "<<s1<<","<<s2<<" : "<<counter12<<endl;
689 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter9(Int_t s1,Int_t s2) {
691 //get or make fitter - general linear transformation - no scaling
693 static Int_t counter9=0;
694 static TF1 f9("f9","x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]");
695 TLinearFitter * fitter = GetFitter9(s1,s2);
696 if (fitter) return fitter;
697 // fitter =new TLinearFitter(9,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]");
698 fitter =new TLinearFitter(&f9,"");
699 fitter->StoreData(kFALSE);
700 fFitterArray9.AddAt(fitter,GetIndex(s1,s2));
702 if (GetDebugLevel()>0) cerr<<"Creating fitter12 "<<s1<<","<<s2<<" : "<<counter9<<endl;
706 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter6(Int_t s1,Int_t s2) {
708 // get or make fitter - 6 paramater linear tranformation
711 // - tilting x-z, y-z
712 static Int_t counter6=0;
713 static TF1 f6("f6","x[0]++x[1]++x[2]++x[3]++x[4]++x[5]");
714 TLinearFitter * fitter = GetFitter6(s1,s2);
715 if (fitter) return fitter;
716 // fitter=new TLinearFitter(6,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]");
717 fitter=new TLinearFitter(&f6,"");
718 fitter->StoreData(kFALSE);
719 fFitterArray6.AddAt(fitter,GetIndex(s1,s2));
721 if (GetDebugLevel()>0) cerr<<"Creating fitter6 "<<s1<<","<<s2<<" : "<<counter6<<endl;
729 Bool_t AliTPCcalibAlign::GetTransformation12(Int_t s1,Int_t s2,TMatrixD &a) {
731 // GetTransformation matrix - 12 paramaters - generael linear transformation
733 if (!GetFitter12(s1,s2))
737 GetFitter12(s1,s2)->GetParameters(p);
739 a[0][0]=p[0]; a[0][1]=p[1]; a[0][2]=p[2]; a[0][3]=p[9];
740 a[1][0]=p[3]; a[1][1]=p[4]; a[1][2]=p[5]; a[1][3]=p[10];
741 a[2][0]=p[6]; a[2][1]=p[7]; a[2][2]=p[8]; a[2][3]=p[11];
742 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
747 Bool_t AliTPCcalibAlign::GetTransformation9(Int_t s1,Int_t s2,TMatrixD &a) {
749 // GetTransformation matrix - 9 paramaters - general linear transformation
752 if (!GetFitter9(s1,s2))
756 GetFitter9(s1,s2)->GetParameters(p);
758 a[0][0]=1; a[0][1]=p[0]; a[0][2]=p[1]; a[0][3]=p[6];
759 a[1][0]=p[2]; a[1][1]=1; a[1][2]=p[3]; a[1][3]=p[7];
760 a[2][0]=p[4]; a[2][1]=p[5]; a[2][2]=1; a[2][3]=p[8];
761 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
766 Bool_t AliTPCcalibAlign::GetTransformation6(Int_t s1,Int_t s2,TMatrixD &a) {
768 // GetTransformation matrix - 6 paramaters
772 if (!GetFitter6(s1,s2))
776 GetFitter6(s1,s2)->GetParameters(p);
778 a[0][0]=1; a[0][1]=-p[0];a[0][2]=0; a[0][3]=p[3];
779 a[1][0]=p[0]; a[1][1]=1; a[1][2]=0; a[1][3]=p[4];
780 a[2][0]=p[1]; a[2][1]=p[2]; a[2][2]=1; a[2][3]=p[5];
781 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
786 void AliTPCcalibAlign::FillHisto(const AliExternalTrackParam &tp1,
787 const AliExternalTrackParam &tp2,
790 // Fill residual histograms
794 if (TMath::Abs(s2%36-s1%36)<2 || TMath::Abs(s2%18-s1%18)==0) {
795 GetHisto(kPhi,s1,s2,kTRUE)->Fill(TMath::ASin(tp1.GetSnp())-TMath::ASin(tp2.GetSnp()));
796 GetHisto(kTheta,s1,s2,kTRUE)->Fill(TMath::ATan(tp1.GetTgl())-TMath::ATan(tp2.GetTgl()));
797 GetHisto(kY,s1,s2,kTRUE)->Fill(tp1.GetY()-tp2.GetY());
798 GetHisto(kZ,s1,s2,kTRUE)->Fill(tp1.GetZ()-tp2.GetZ());
804 TH1 * AliTPCcalibAlign::GetHisto(HistoType type, Int_t s1, Int_t s2, Bool_t force)
807 // return specified residual histogram - it is only QA
808 // if force specified the histogram and given histogram is not existing
809 // new histogram is created
811 if (GetIndex(s1,s2)>=72*72) return 0;
812 TObjArray *histoArray=0;
815 histoArray = &fDyHistArray; break;
817 histoArray = &fDzHistArray; break;
819 histoArray = &fDphiHistArray; break;
821 histoArray = &fDthetaHistArray; break;
823 TH1 * histo= (TH1*)histoArray->At(GetIndex(s1,s2));
824 if (histo) return histo;
825 if (force==kFALSE) return 0;
831 name<<"hist_y_"<<s1<<"_"<<s2;
832 title<<"Y Missalignment for sectors "<<s1<<" and "<<s2;
833 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.3,0.3); // +/- 3 mm
836 name<<"hist_z_"<<s1<<"_"<<s2;
837 title<<"Z Missalignment for sectors "<<s1<<" and "<<s2;
838 histo = new TH1D(name.str().c_str(),title.str().c_str(),512,-0.3,0.3); // +/- 3 mm
841 name<<"hist_phi_"<<s1<<"_"<<s2;
842 title<<"Phi Missalignment for sectors "<<s1<<" and "<<s2;
843 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.01,0.01); // +/- 10 mrad
846 name<<"hist_theta_"<<s1<<"_"<<s2;
847 title<<"Theta Missalignment for sectors "<<s1<<" and "<<s2;
848 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.01,0.01); // +/- 10 mrad
851 histo->SetDirectory(0);
852 histoArray->AddAt(histo,GetIndex(s1,s2));
856 TGraphErrors * AliTPCcalibAlign::MakeGraph(Int_t sec0, Int_t sec1, Int_t dsec,
857 Int_t i0, Int_t i1, FitType type)
863 TObjArray *fitArray=0;
867 for (Int_t isec = sec0; isec<=sec1; isec++){
868 Int_t isec2 = (isec+dsec)%72;
871 GetTransformation6(isec,isec2,mat);break;
873 GetTransformation9(isec,isec2,mat);break;
875 GetTransformation12(isec,isec2,mat);break;
878 ysec[npoints]=mat(i0,i1);
881 TGraphErrors *gr = new TGraphErrors(npoints,xsec,ysec,0,0);
883 sprintf(name,"Mat[%d,%d] Type=%d",i0,i1,type);
888 void AliTPCcalibAlign::MakeTree(const char *fname){
890 // make tree with alignment cosntant -
891 // For QA visualization
893 const Int_t kMinPoints=50;
894 TTreeSRedirector cstream(fname);
895 for (Int_t s1=0;s1<72;++s1)
896 for (Int_t s2=0;s2<72;++s2){
897 if (fPoints[GetIndex(s1,s2)]<kMinPoints) continue;
901 GetTransformation6(s1,s2,m6);
902 GetTransformation9(s1,s2,m9);
903 GetTransformation12(s1,s2,m12);
904 Double_t dy=0, dz=0, dphi=0,dtheta=0;
905 Double_t sy=0, sz=0, sphi=0,stheta=0;
906 Double_t ny=0, nz=0, nphi=0,ntheta=0;
908 his = GetHisto(kY,s1,s2);
909 if (his) { dy = his->GetMean(); sy = his->GetRMS(); ny = his->GetEntries();}
910 his = GetHisto(kZ,s1,s2);
911 if (his) { dz = his->GetMean(); sz = his->GetRMS(); nz = his->GetEntries();}
912 his = GetHisto(kPhi,s1,s2);
913 if (his) { dphi = his->GetMean(); sphi = his->GetRMS(); nphi = his->GetEntries();}
914 his = GetHisto(kTheta,s1,s2);
915 if (his) { dtheta = his->GetMean(); stheta = his->GetRMS(); ntheta = his->GetEntries();}
918 "s1="<<s1<< // reference sector
919 "s2="<<s2<< // sector to align
920 "m6.="<<&m6<< // tranformation matrix
923 // histograms mean RMS and entries