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 TChain * chainalign = tool.MakeChain("align.txt","Tracklet",0,1000000)
250 chainalign->Lookup();
252 // Cuts to be justified with the debug streamer
254 TCut c1pt("abs((tp1.fP[4]+tp2.fP[4])*0.5)<3"); // pt cut - OK
255 TCut cdy("abs(tp1.fP[0]-tp2.fP[0])<2");
256 TCut cdz("abs(tp1.fP[1]-tp2.fP[1])<2");
257 TCut cdphi("abs(tp1.fP[2]-tp2.fP[2])<0.02");
258 TCut cdt("abs(tp1.fP[3]-tp2.fP[3])<0.02");
259 TCut cd1pt("abs(tp1.fP[4]-tp2.fP[4])<0.3"); // delta 1/pt cut -OK
262 TCut acut = c1pt+cdy+cdz+cdphi+cdt+cd1pt;
271 printf("Process track\n");
272 if (TMath::Abs(tp1.GetParameter()[0]-tp2.GetParameter()[0])>2) return;
273 if (TMath::Abs(tp1.GetParameter()[1]-tp2.GetParameter()[1])>2) return;
274 if (TMath::Abs(tp1.GetParameter()[2]-tp2.GetParameter()[2])>0.02) return;
275 if (TMath::Abs(tp1.GetParameter()[3]-tp2.GetParameter()[3])>0.02) return;
276 if (TMath::Abs(tp1.GetParameter()[4]-tp2.GetParameter()[4])>0.3) return;
277 if (TMath::Abs((tp1.GetParameter()[4]+tp2.GetParameter()[4])*0.5)>3) return;
278 if (TMath::Abs((tp1.GetParameter()[0]-tp2.GetParameter()[0]))<0.000000001) return;
279 printf("Filling track\n");
281 // fill resolution histograms - previous cut included
282 FillHisto(tp1,tp2,s1,s2);
284 Process12(t1,t2,GetOrMakeFitter12(s1,s2));
285 Process9(t1,t2,GetOrMakeFitter9(s1,s2));
286 Process6(t1,t2,GetOrMakeFitter6(s1,s2));
287 ProcessDiff(tp1,tp2, seed,s1,s2);
288 ++fPoints[GetIndex(s1,s2)];
291 void AliTPCcalibAlign::ProcessDiff(const AliExternalTrackParam &t1,
292 const AliExternalTrackParam &t2,
293 const AliTPCseed *seed,
297 // Process local residuals function
302 TVectorD vecClY(160);
303 TVectorD vecClZ(160);
304 TClonesArray arrCl("AliTPCclusterMI",160);
305 arrCl.ExpandCreateFast(160);
306 Int_t count1=0, count2=0;
307 for (Int_t i=0;i<160;++i) {
308 AliTPCclusterMI *c=seed->GetClusterPointer(i);
313 AliTPCclusterMI & cl = (AliTPCclusterMI&) (*arrCl[i]);
314 if (c->GetDetector()!=s1 && c->GetDetector()!=s2) continue;
315 vecClY[i] = c->GetY();
316 vecClZ[i] = c->GetZ();
318 const AliExternalTrackParam *par = (c->GetDetector()==s1)? &t1:&t2;
319 if (c->GetDetector()==s1) ++count1;
320 if (c->GetDetector()==s2) ++count2;
321 Double_t gxyz[3],xyz[3];
323 Float_t bz = AliTracker::GetBz(gxyz);
324 par->GetYAt(c->GetX(), bz, xyz[1]);
325 par->GetZAt(c->GetX(), bz, xyz[2]);
334 // huge output - cluster residuals to be investigated
336 TTreeSRedirector *cstream = GetDebugStreamer();
337 AliTPCseed * t = (AliTPCseed*) seed;
338 //AliExternalTrackParam *p0 = &((AliExternalTrackParam&)seed);
339 AliExternalTrackParam *p1 = &((AliExternalTrackParam&)t1);
340 AliExternalTrackParam *p2 = &((AliExternalTrackParam&)t2);
343 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");
348 (*cstream)<<"Track"<<
370 void AliTPCcalibAlign::Process12(const Double_t *t1,
372 TLinearFitter *fitter) {
373 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
374 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
375 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
376 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
377 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
379 // a00 a01 a02 a03 p[0] p[1] p[2] p[9]
380 // a10 a11 a12 a13 ==> p[3] p[4] p[5] p[10]
381 // a20 a21 a22 a23 p[6] p[7] p[8] p[11]
385 const Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
386 const Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
391 Double_t sdydx = 0.001;
392 Double_t sdzdx = 0.001;
397 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
398 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
399 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
400 for (Int_t i=0; i<12;i++) p[i]=0.;
405 p[0+1] = y1*dydx2; // a01
406 p[0+2] = z1*dydx2; // a02
407 p[9+0] = dydx2; // a03
409 fitter->AddPoint(p,value,sy);
411 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
412 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
413 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
414 for (Int_t i=0; i<12;i++) p[i]=0.;
419 p[0+1] = y1*dzdx2; // a01
420 p[0+2] = z1*dzdx2; // a02
421 p[9+0] = dzdx2; // a03
423 fitter->AddPoint(p,value,sz);
425 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
426 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
427 for (Int_t i=0; i<12;i++) p[i]=0.;
429 p[3+1] = dydx1; // a11
430 p[3+2] = dzdx1; // a12
431 p[0+0] = -dydx2; // a00
432 p[0+1] = -dydx1*dydx2; // a01
433 p[0+2] = -dzdx1*dydx2; // a02
435 fitter->AddPoint(p,value,sdydx);
437 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
438 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
439 for (Int_t i=0; i<12;i++) p[i]=0.;
441 p[6+1] = dydx1; // a21
442 p[6+2] = dzdx1; // a22
443 p[0+0] = -dzdx2; // a00
444 p[0+1] = -dydx1*dzdx2; // a01
445 p[0+2] = -dzdx1*dzdx2; // a02
447 fitter->AddPoint(p,value,sdzdx);
450 void AliTPCcalibAlign::Process9(Double_t *t1,
452 TLinearFitter *fitter) {
453 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
454 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
455 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
456 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
457 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
459 // a00 a01 a02 a03 1 p[0] p[1] p[6]
460 // a10 a11 a12 a13 ==> p[2] 1 p[3] p[7]
461 // a20 a21 a21 a23 p[4] p[5] 1 p[8]
464 Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
465 Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
470 Double_t sdydx = 0.001;
471 Double_t sdzdx = 0.001;
476 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
477 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
478 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
479 for (Int_t i=0; i<12;i++) p[i]=0.;
484 p[0] += y1*dydx2; // a01
485 p[1] += z1*dydx2; // a02
486 p[6] += dydx2; // a03
487 value = y2-y1; //-a11
488 fitter->AddPoint(p,value,sy);
490 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
491 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
492 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
493 for (Int_t i=0; i<12;i++) p[i]=0.;
498 p[0] += y1*dzdx2; // a01
499 p[1] += z1*dzdx2; // a02
500 p[6] += dzdx2; // a03
501 value = z2-z1; //-a22
502 fitter->AddPoint(p,value,sz);
504 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
505 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
506 for (Int_t i=0; i<12;i++) p[i]=0.;
508 //p[] += dydx1; // a11
509 p[3] += dzdx1; // a12
510 //p[] += -dydx2; // a00
511 p[0] += -dydx1*dydx2; // a01
512 p[1] += -dzdx1*dydx2; // a02
513 value = -dydx1+dydx2; // -a11 + a00
514 fitter->AddPoint(p,value,sdydx);
516 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
517 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
518 for (Int_t i=0; i<12;i++) p[i]=0.;
520 p[5] += dydx1; // a21
521 //p[] += dzdx1; // a22
522 //p[] += -dzdx2; // a00
523 p[0] += -dydx1*dzdx2; // a01
524 p[1] += -dzdx1*dzdx2; // a02
525 value = -dzdx1+dzdx2; // -a22 + a00
526 fitter->AddPoint(p,value,sdzdx);
529 void AliTPCcalibAlign::Process6(Double_t *t1,
531 TLinearFitter *fitter) {
532 // x2 = 1 *x1 +-a01*y1 + 0 +a03
533 // y2 = a01*x1 + 1 *y1 + 0 +a13
534 // z2 = a20*x1 + a21*y1 + 1 *z1 +a23
535 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
536 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
538 // a00 a01 a02 a03 1 -p[0] 0 p[3]
539 // a10 a11 a12 a13 ==> p[0] 1 0 p[4]
540 // a20 a21 a21 a23 p[1] p[2] 1 p[5]
542 Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
543 Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
548 Double_t sdydx = 0.001;
549 Double_t sdzdx = 0.001;
553 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
554 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
555 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
556 for (Int_t i=0; i<12;i++) p[i]=0.;
561 p[0] += -y1*dydx2; // a01
562 //p[] += z1*dydx2; // a02
563 p[3] += dydx2; // a03
564 value = y2-y1; //-a11
565 fitter->AddPoint(p,value,sy);
567 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
568 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
569 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
570 for (Int_t i=0; i<12;i++) p[i]=0.;
575 p[0] += -y1*dzdx2; // a01
576 //p[] += z1*dzdx2; // a02
577 p[3] += dzdx2; // a03
578 value = z2-z1; //-a22
579 fitter->AddPoint(p,value,sz);
581 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
582 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
583 for (Int_t i=0; i<12;i++) p[i]=0.;
585 //p[] += dydx1; // a11
586 //p[] += dzdx1; // a12
587 //p[] += -dydx2; // a00
588 p[0] += dydx1*dydx2; // a01
589 //p[] += -dzdx1*dydx2; // a02
590 value = -dydx1+dydx2; // -a11 + a00
591 fitter->AddPoint(p,value,sdydx);
593 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
594 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
595 for (Int_t i=0; i<12;i++) p[i]=0.;
597 p[2] += dydx1; // a21
598 //p[] += dzdx1; // a22
599 //p[] += -dzdx2; // a00
600 p[0] += dydx1*dzdx2; // a01
601 //p[] += -dzdx1*dzdx2; // a02
602 value = -dzdx1+dzdx2; // -a22 + a00
603 fitter->AddPoint(p,value,sdzdx);
609 void AliTPCcalibAlign::EvalFitters() {
613 // Perform the fitting using linear fitters
615 Int_t kMinPoints =50;
617 TFile fff("alignDebug.root","recreate");
618 for (Int_t s1=0;s1<72;++s1)
619 for (Int_t s2=0;s2<72;++s2){
620 if ((f=GetFitter12(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
621 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
623 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
624 f->Write(Form("f12_%d_%d",s1,s2));
626 f->Write(Form("f12_%d_%d",s1,s2));
629 if ((f=GetFitter9(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
630 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
632 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
634 f->Write(Form("f9_%d_%d",s1,s2));
637 if ((f=GetFitter6(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
638 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
640 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
642 f->Write(Form("f6_%d_%d",s1,s2));
646 this->Write("align");
651 chi212 = align->GetChisquare()/(4.*entries);
655 align->GetParameters(par);
656 align->GetCovarianceMatrix(mat);
660 for (Int_t i=0; i<12;i++){
661 palign12(i)= par(i+1);
662 for (Int_t j=0; j<12;j++){
663 pcovar12(i,j) = mat(i+1,j+1);
664 pcovar12(i,j) *= chi212;
668 for (Int_t i=0; i<12;i++){
669 psigma12(i) = TMath::Sqrt(pcovar12(i,i));
670 palignR12(i) = palign12(i)/TMath::Sqrt(pcovar12(i,i));
671 for (Int_t j=0; j<12;j++){
672 pcovarN12(i,j) = pcovar12(i,j)/TMath::Sqrt(pcovar12(i,i)*pcovar12(j,j));
678 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter12(Int_t s1,Int_t s2) {
680 // get or make fitter - general linear transformation
682 static Int_t counter12=0;
683 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]");
684 TLinearFitter * fitter = GetFitter12(s1,s2);
685 if (fitter) return fitter;
686 // 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]");
687 fitter =new TLinearFitter(&f12,"");
688 fitter->StoreData(kFALSE);
689 fFitterArray12.AddAt(fitter,GetIndex(s1,s2));
691 if (GetDebugLevel()>0) cerr<<"Creating fitter12 "<<s1<<","<<s2<<" : "<<counter12<<endl;
695 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter9(Int_t s1,Int_t s2) {
697 //get or make fitter - general linear transformation - no scaling
699 static Int_t counter9=0;
700 static TF1 f9("f9","x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]");
701 TLinearFitter * fitter = GetFitter9(s1,s2);
702 if (fitter) return fitter;
703 // fitter =new TLinearFitter(9,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]");
704 fitter =new TLinearFitter(&f9,"");
705 fitter->StoreData(kFALSE);
706 fFitterArray9.AddAt(fitter,GetIndex(s1,s2));
708 if (GetDebugLevel()>0) cerr<<"Creating fitter12 "<<s1<<","<<s2<<" : "<<counter9<<endl;
712 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter6(Int_t s1,Int_t s2) {
714 // get or make fitter - 6 paramater linear tranformation
717 // - tilting x-z, y-z
718 static Int_t counter6=0;
719 static TF1 f6("f6","x[0]++x[1]++x[2]++x[3]++x[4]++x[5]");
720 TLinearFitter * fitter = GetFitter6(s1,s2);
721 if (fitter) return fitter;
722 // fitter=new TLinearFitter(6,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]");
723 fitter=new TLinearFitter(&f6,"");
724 fitter->StoreData(kFALSE);
725 fFitterArray6.AddAt(fitter,GetIndex(s1,s2));
727 if (GetDebugLevel()>0) cerr<<"Creating fitter6 "<<s1<<","<<s2<<" : "<<counter6<<endl;
735 Bool_t AliTPCcalibAlign::GetTransformation12(Int_t s1,Int_t s2,TMatrixD &a) {
737 // GetTransformation matrix - 12 paramaters - generael linear transformation
739 if (!GetFitter12(s1,s2))
743 GetFitter12(s1,s2)->GetParameters(p);
745 a[0][0]=p[0]; a[0][1]=p[1]; a[0][2]=p[2]; a[0][3]=p[9];
746 a[1][0]=p[3]; a[1][1]=p[4]; a[1][2]=p[5]; a[1][3]=p[10];
747 a[2][0]=p[6]; a[2][1]=p[7]; a[2][2]=p[8]; a[2][3]=p[11];
748 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
753 Bool_t AliTPCcalibAlign::GetTransformation9(Int_t s1,Int_t s2,TMatrixD &a) {
755 // GetTransformation matrix - 9 paramaters - general linear transformation
758 if (!GetFitter9(s1,s2))
762 GetFitter9(s1,s2)->GetParameters(p);
764 a[0][0]=1; a[0][1]=p[0]; a[0][2]=p[1]; a[0][3]=p[6];
765 a[1][0]=p[2]; a[1][1]=1; a[1][2]=p[3]; a[1][3]=p[7];
766 a[2][0]=p[4]; a[2][1]=p[5]; a[2][2]=1; a[2][3]=p[8];
767 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
772 Bool_t AliTPCcalibAlign::GetTransformation6(Int_t s1,Int_t s2,TMatrixD &a) {
774 // GetTransformation matrix - 6 paramaters
778 if (!GetFitter6(s1,s2))
782 GetFitter6(s1,s2)->GetParameters(p);
784 a[0][0]=1; a[0][1]=-p[0];a[0][2]=0; a[0][3]=p[3];
785 a[1][0]=p[0]; a[1][1]=1; a[1][2]=0; a[1][3]=p[4];
786 a[2][0]=p[1]; a[2][1]=p[2]; a[2][2]=1; a[2][3]=p[5];
787 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
792 void AliTPCcalibAlign::FillHisto(const AliExternalTrackParam &tp1,
793 const AliExternalTrackParam &tp2,
796 // Fill residual histograms
800 if (TMath::Abs(s2%36-s1%36)<2 || TMath::Abs(s2%18-s1%18)==0) {
801 GetHisto(kPhi,s1,s2,kTRUE)->Fill(TMath::ASin(tp1.GetSnp())-TMath::ASin(tp2.GetSnp()));
802 GetHisto(kTheta,s1,s2,kTRUE)->Fill(TMath::ATan(tp1.GetTgl())-TMath::ATan(tp2.GetTgl()));
803 GetHisto(kY,s1,s2,kTRUE)->Fill(tp1.GetY()-tp2.GetY());
804 GetHisto(kZ,s1,s2,kTRUE)->Fill(tp1.GetZ()-tp2.GetZ());
810 TH1 * AliTPCcalibAlign::GetHisto(HistoType type, Int_t s1, Int_t s2, Bool_t force)
813 // return specified residual histogram - it is only QA
814 // if force specified the histogram and given histogram is not existing
815 // new histogram is created
817 if (GetIndex(s1,s2)>=72*72) return 0;
818 TObjArray *histoArray=0;
821 histoArray = &fDyHistArray; break;
823 histoArray = &fDzHistArray; break;
825 histoArray = &fDphiHistArray; break;
827 histoArray = &fDthetaHistArray; break;
829 TH1 * histo= (TH1*)histoArray->At(GetIndex(s1,s2));
830 if (histo) return histo;
831 if (force==kFALSE) return 0;
837 name<<"hist_y_"<<s1<<"_"<<s2;
838 title<<"Y Missalignment for sectors "<<s1<<" and "<<s2;
839 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.3,0.3); // +/- 3 mm
842 name<<"hist_z_"<<s1<<"_"<<s2;
843 title<<"Z Missalignment for sectors "<<s1<<" and "<<s2;
844 histo = new TH1D(name.str().c_str(),title.str().c_str(),512,-0.3,0.3); // +/- 3 mm
847 name<<"hist_phi_"<<s1<<"_"<<s2;
848 title<<"Phi Missalignment for sectors "<<s1<<" and "<<s2;
849 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.01,0.01); // +/- 10 mrad
852 name<<"hist_theta_"<<s1<<"_"<<s2;
853 title<<"Theta Missalignment for sectors "<<s1<<" and "<<s2;
854 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.01,0.01); // +/- 10 mrad
857 histo->SetDirectory(0);
858 histoArray->AddAt(histo,GetIndex(s1,s2));
862 TGraphErrors * AliTPCcalibAlign::MakeGraph(Int_t sec0, Int_t sec1, Int_t dsec,
863 Int_t i0, Int_t i1, FitType type)
869 TObjArray *fitArray=0;
873 for (Int_t isec = sec0; isec<=sec1; isec++){
874 Int_t isec2 = (isec+dsec)%72;
877 GetTransformation6(isec,isec2,mat);break;
879 GetTransformation9(isec,isec2,mat);break;
881 GetTransformation12(isec,isec2,mat);break;
884 ysec[npoints]=mat(i0,i1);
887 TGraphErrors *gr = new TGraphErrors(npoints,xsec,ysec,0,0);
889 sprintf(name,"Mat[%d,%d] Type=%d",i0,i1,type);
894 void AliTPCcalibAlign::MakeTree(const char *fname){
896 // make tree with alignment cosntant -
897 // For QA visualization
900 TFile f("CalibObjects.root");
901 TObjArray *array = (TObjArray*)f.Get("TPCCalib");
902 AliTPCcalibAlign *alignTPC = (AliTPCcalibAlign *)array->At(0);
903 alignTPC->MakeTree("alignTree.root");
904 TFile falign("alignTree.root");
907 const Int_t kMinPoints=50;
908 TTreeSRedirector cstream(fname);
909 for (Int_t s1=0;s1<72;++s1)
910 for (Int_t s2=0;s2<72;++s2){
911 if (fPoints[GetIndex(s1,s2)]<kMinPoints) continue;
915 GetTransformation6(s1,s2,m6);
916 GetTransformation9(s1,s2,m9);
917 GetTransformation12(s1,s2,m12);
918 Double_t dy=0, dz=0, dphi=0,dtheta=0;
919 Double_t sy=0, sz=0, sphi=0,stheta=0;
920 Double_t ny=0, nz=0, nphi=0,ntheta=0;
922 his = GetHisto(kY,s1,s2);
923 if (his) { dy = his->GetMean(); sy = his->GetRMS(); ny = his->GetEntries();}
924 his = GetHisto(kZ,s1,s2);
925 if (his) { dz = his->GetMean(); sz = his->GetRMS(); nz = his->GetEntries();}
926 his = GetHisto(kPhi,s1,s2);
927 if (his) { dphi = his->GetMean(); sphi = his->GetRMS(); nphi = his->GetEntries();}
928 his = GetHisto(kTheta,s1,s2);
929 if (his) { dtheta = his->GetMean(); stheta = his->GetRMS(); ntheta = his->GetEntries();}
932 "s1="<<s1<< // reference sector
933 "s2="<<s2<< // sector to align
934 "m6.="<<&m6<< // tranformation matrix
937 // histograms mean RMS and entries
956 //_____________________________________________________________________
957 Long64_t AliTPCcalibAlign::Merge(TCollection* list) {
961 if (GetDebugLevel()>0) Info("AliTPCcalibAlign","Merge");
967 TIterator* iter = list->MakeIterator();
971 while((obj = iter->Next()) != 0)
973 AliTPCcalibAlign* entry = dynamic_cast<AliTPCcalibAlign*>(obj);
974 if (entry == 0) continue;
982 void AliTPCcalibAlign::Add(AliTPCcalibAlign * align){
987 for (Int_t i=0; i<72;i++){
988 for (Int_t j=0; j<72;j++){
989 fPoints[GetIndex(i,j)]+=align->fPoints[GetIndex(i,j)];
993 TH1* hdy0 = GetHisto(kY,i,j);
994 TH1* hdy1 = align->GetHisto(kY,i,j);
996 if (hdy0) hdy0->Add(hdy1);
998 hdy0 = GetHisto(kY,i,j,kTRUE);
1004 TH1* hdz0 = GetHisto(kZ,i,j);
1005 TH1* hdz1 = align->GetHisto(kZ,i,j);
1007 if (hdz0) hdz0->Add(hdz1);
1009 hdz0 = GetHisto(kZ,i,j,kTRUE);
1015 TH1* hdphi0 = GetHisto(kPhi,i,j);
1016 TH1* hdphi1 = align->GetHisto(kPhi,i,j);
1018 if (hdphi0) hdphi0->Add(hdphi1);
1020 hdphi0 = GetHisto(kPhi,i,j,kTRUE);
1021 hdphi0->Add(hdphi1);
1026 TH1* hdTheta0 = GetHisto(kTheta,i,j);
1027 TH1* hdTheta1 = align->GetHisto(kTheta,i,j);
1029 if (hdTheta0) hdTheta0->Add(hdTheta1);
1031 hdTheta0 = GetHisto(kTheta,i,j,kTRUE);
1032 hdTheta0->Add(hdTheta1);
1037 TLinearFitter *f0=0;
1038 TLinearFitter *f1=0;
1039 for (Int_t i=0; i<72;i++){
1040 for (Int_t j=0; j<72;j++){
1043 f0 = GetFitter12(i,j);
1044 f1 = GetFitter12(i,j);
1046 if (f0) f0->Add(f1);
1048 f0 = GetOrMakeFitter12(i,j);
1054 f0 = GetFitter9(i,j);
1055 f1 = GetFitter9(i,j);
1057 if (f0) f0->Add(f1);
1059 f0 = GetOrMakeFitter9(i,j);
1063 f0 = GetFitter6(i,j);
1064 f1 = GetFitter6(i,j);
1066 if (f0) f0->Add(f1);
1068 f0 = GetOrMakeFitter6(i,j);