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
71 gSystem->AddIncludePath("-I$ALICE_ROOT/TPC/macros");
72 gROOT->LoadMacro("$ALICE_ROOT/TPC/macros/AliXRDPROOFtoolkit.cxx+")
73 AliXRDPROOFtoolkit tool;
74 TChain * chain = tool.MakeChain("align.txt","Track",0,10200);
78 gSystem->Load("libANALYSIS");
79 gSystem->Load("libTPCcalib");
80 TFile fcalib("CalibObjects.root");
81 TObjArray * array = (TObjArray*)fcalib.Get("TPCCalib");
82 AliTPCcalibAlign * align = ( AliTPCcalibAlign *)array->FindObject("alignTPC");
85 align->MakeTree("alignTree.root");
86 TFile f("alignTree.root");
87 TTree * tree = (TTree*)f.Get("Align");
95 #include "TLinearFitter.h"
96 #include "AliTPCcalibAlign.h"
97 #include "AliExternalTrackParam.h"
98 #include "AliTPCTracklet.h"
100 #include "TVectorD.h"
101 #include "TTreeStream.h"
104 #include "TGraphErrors.h"
105 #include "AliTPCclusterMI.h"
106 #include "AliTPCseed.h"
107 #include "AliTracker.h"
108 #include "TClonesArray.h"
111 #include "TTreeStream.h"
116 ClassImp(AliTPCcalibAlign)
118 AliTPCcalibAlign::AliTPCcalibAlign()
119 : fDphiHistArray(72*72),
120 fDthetaHistArray(72*72),
123 fFitterArray12(72*72),
124 fFitterArray9(72*72),
130 for (Int_t i=0;i<72*72;++i) {
135 AliTPCcalibAlign::AliTPCcalibAlign(const Text_t *name, const Text_t *title)
137 fDphiHistArray(72*72),
138 fDthetaHistArray(72*72),
141 fFitterArray12(72*72),
142 fFitterArray9(72*72),
150 for (Int_t i=0;i<72*72;++i) {
155 AliTPCcalibAlign::~AliTPCcalibAlign() {
161 void AliTPCcalibAlign::Process(AliTPCseed *seed) {
167 AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kKalman,
169 // TObjArray trackletsL=
170 // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kLinear,
172 // TObjArray trackletsQ=
173 // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kQuadratic,
175 // TObjArray trackletsR=
176 // AliTPCTracklet::CreateTracklets(seed,AliTPCTracklet::kRiemann,
178 tracklets.SetOwner();
179 // trackletsL.SetOwner();
180 // trackletsQ.SetOwner();
181 // trackletsR.SetOwner();
182 if (tracklets.GetEntries()==2) {
183 AliTPCTracklet *t1=static_cast<AliTPCTracklet*>(tracklets[0]);
184 AliTPCTracklet *t2=static_cast<AliTPCTracklet*>(tracklets[1]);
185 if (t1->GetSector()>t2->GetSector()) {
186 AliTPCTracklet* tmp=t1;
190 AliExternalTrackParam *common1=0,*common2=0;
191 if (AliTPCTracklet::PropagateToMeanX(*t1,*t2,common1,common2))
192 ProcessTracklets(*common1,*common2,seed, t1->GetSector(),t2->GetSector());
199 void AliTPCcalibAlign::Analyze(){
207 void AliTPCcalibAlign::Terminate(){
209 // Terminate function
210 // call base terminate + Eval of fitters
212 if (GetDebugLevel()>0) Info("AliTPCcalibAlign","Terminate");
214 AliTPCcalibBase::Terminate();
220 void AliTPCcalibAlign::ProcessTracklets(const AliExternalTrackParam &tp1,
221 const AliExternalTrackParam &tp2,
222 const AliTPCseed * seed,
230 // Process function to fill fitters
232 Double_t t1[5],t2[5];
233 Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
234 Double_t &x2=t2[0], &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
238 Double_t snp1=tp1.GetSnp();
239 dydx1=snp1/TMath::Sqrt(1.-snp1*snp1);
240 Double_t tgl1=tp1.GetTgl();
241 // dz/dx = 1/(cos(theta)*cos(phi))
242 dzdx1=tgl1/TMath::Sqrt(1.-snp1*snp1);
246 Double_t snp2=tp2.GetSnp();
247 dydx2=snp2/TMath::Sqrt(1.-snp2*snp2);
248 Double_t tgl2=tp2.GetTgl();
249 dzdx2=tgl2/TMath::Sqrt(1.-snp2*snp2);
254 TTreeSRedirector *cstream = GetDebugStreamer();
256 static TVectorD vec1(5);
257 static TVectorD vec2(5);
258 vec1.SetElements(t1);
259 vec2.SetElements(t2);
260 AliExternalTrackParam *p1 = &((AliExternalTrackParam&)tp1);
261 AliExternalTrackParam *p2 = &((AliExternalTrackParam&)tp2);
262 (*cstream)<<"Tracklet"<<
273 // Aplly cut selection
275 TChain * chainalign = tool.MakeChain("align.txt","Tracklet",0,1000000)
276 chainalign->Lookup();
278 // Cuts to be justified with the debug streamer
280 TCut c1pt("abs((tp1.fP[4]+tp2.fP[4])*0.5)<3"); // pt cut - OK
281 TCut cdy("abs(tp1.fP[0]-tp2.fP[0])<2");
282 TCut cdz("abs(tp1.fP[1]-tp2.fP[1])<2");
283 TCut cdphi("abs(tp1.fP[2]-tp2.fP[2])<0.02");
284 TCut cdt("abs(tp1.fP[3]-tp2.fP[3])<0.02");
285 TCut cd1pt("abs(tp1.fP[4]-tp2.fP[4])<0.3"); // delta 1/pt cut -OK
288 TCut acut = c1pt+cdy+cdz+cdphi+cdt+cd1pt;
297 if (GetDebugLevel()>50) printf("Process track\n");
298 if (TMath::Abs(tp1.GetParameter()[0]-tp2.GetParameter()[0])>2) return;
299 if (TMath::Abs(tp1.GetParameter()[1]-tp2.GetParameter()[1])>2) return;
300 if (TMath::Abs(tp1.GetParameter()[2]-tp2.GetParameter()[2])>0.02) return;
301 if (TMath::Abs(tp1.GetParameter()[3]-tp2.GetParameter()[3])>0.02) return;
302 if (TMath::Abs(tp1.GetParameter()[4]-tp2.GetParameter()[4])>0.3) return;
303 if (TMath::Abs((tp1.GetParameter()[4]+tp2.GetParameter()[4])*0.5)>3) return;
304 if (TMath::Abs((tp1.GetParameter()[0]-tp2.GetParameter()[0]))<0.000000001) return;
305 if (GetDebugLevel()>50) printf("Filling track\n");
307 // fill resolution histograms - previous cut included
308 FillHisto(tp1,tp2,s1,s2);
310 Process12(t1,t2,GetOrMakeFitter12(s1,s2));
311 Process9(t1,t2,GetOrMakeFitter9(s1,s2));
312 Process6(t1,t2,GetOrMakeFitter6(s1,s2));
313 ProcessDiff(tp1,tp2, seed,s1,s2);
314 ++fPoints[GetIndex(s1,s2)];
317 void AliTPCcalibAlign::ProcessDiff(const AliExternalTrackParam &t1,
318 const AliExternalTrackParam &t2,
319 const AliTPCseed *seed,
323 // Process local residuals function
328 TVectorD vecClY(160);
329 TVectorD vecClZ(160);
330 TClonesArray arrCl("AliTPCclusterMI",160);
331 arrCl.ExpandCreateFast(160);
332 Int_t count1=0, count2=0;
333 for (Int_t i=0;i<160;++i) {
334 AliTPCclusterMI *c=seed->GetClusterPointer(i);
339 AliTPCclusterMI & cl = (AliTPCclusterMI&) (*arrCl[i]);
340 if (c->GetDetector()!=s1 && c->GetDetector()!=s2) continue;
341 vecClY[i] = c->GetY();
342 vecClZ[i] = c->GetZ();
344 const AliExternalTrackParam *par = (c->GetDetector()==s1)? &t1:&t2;
345 if (c->GetDetector()==s1) ++count1;
346 if (c->GetDetector()==s2) ++count2;
347 Double_t gxyz[3],xyz[3];
349 Float_t bz = AliTracker::GetBz(gxyz);
350 par->GetYAt(c->GetX(), bz, xyz[1]);
351 par->GetZAt(c->GetX(), bz, xyz[2]);
360 // huge output - cluster residuals to be investigated
362 TTreeSRedirector *cstream = GetDebugStreamer();
363 AliTPCseed * t = (AliTPCseed*) seed;
364 //AliExternalTrackParam *p0 = &((AliExternalTrackParam&)seed);
365 AliExternalTrackParam *p1 = &((AliExternalTrackParam&)t1);
366 AliExternalTrackParam *p2 = &((AliExternalTrackParam&)t2);
369 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");
374 (*cstream)<<"Track"<<
396 void AliTPCcalibAlign::Process12(const Double_t *t1,
398 TLinearFitter *fitter) {
399 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
400 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
401 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
402 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
403 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
405 // a00 a01 a02 a03 p[0] p[1] p[2] p[9]
406 // a10 a11 a12 a13 ==> p[3] p[4] p[5] p[10]
407 // a20 a21 a22 a23 p[6] p[7] p[8] p[11]
411 const Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
412 const Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
417 Double_t sdydx = 0.001;
418 Double_t sdzdx = 0.001;
423 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
424 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
425 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
426 for (Int_t i=0; i<12;i++) p[i]=0.;
431 p[0+1] = y1*dydx2; // a01
432 p[0+2] = z1*dydx2; // a02
433 p[9+0] = dydx2; // a03
435 fitter->AddPoint(p,value,sy);
437 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
438 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
439 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
440 for (Int_t i=0; i<12;i++) p[i]=0.;
445 p[0+1] = y1*dzdx2; // a01
446 p[0+2] = z1*dzdx2; // a02
447 p[9+0] = dzdx2; // a03
449 fitter->AddPoint(p,value,sz);
451 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
452 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
453 for (Int_t i=0; i<12;i++) p[i]=0.;
455 p[3+1] = dydx1; // a11
456 p[3+2] = dzdx1; // a12
457 p[0+0] = -dydx2; // a00
458 p[0+1] = -dydx1*dydx2; // a01
459 p[0+2] = -dzdx1*dydx2; // a02
461 fitter->AddPoint(p,value,sdydx);
463 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
464 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
465 for (Int_t i=0; i<12;i++) p[i]=0.;
467 p[6+1] = dydx1; // a21
468 p[6+2] = dzdx1; // a22
469 p[0+0] = -dzdx2; // a00
470 p[0+1] = -dydx1*dzdx2; // a01
471 p[0+2] = -dzdx1*dzdx2; // a02
473 fitter->AddPoint(p,value,sdzdx);
476 void AliTPCcalibAlign::Process9(Double_t *t1,
478 TLinearFitter *fitter) {
479 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
480 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
481 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
482 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
483 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
485 // a00 a01 a02 a03 1 p[0] p[1] p[6]
486 // a10 a11 a12 a13 ==> p[2] 1 p[3] p[7]
487 // a20 a21 a21 a23 p[4] p[5] 1 p[8]
490 Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
491 Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
496 Double_t sdydx = 0.001;
497 Double_t sdzdx = 0.001;
502 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
503 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
504 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
505 for (Int_t i=0; i<12;i++) p[i]=0.;
510 p[0] += y1*dydx2; // a01
511 p[1] += z1*dydx2; // a02
512 p[6] += dydx2; // a03
513 value = y2-y1; //-a11
514 fitter->AddPoint(p,value,sy);
516 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
517 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
518 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
519 for (Int_t i=0; i<12;i++) p[i]=0.;
524 p[0] += y1*dzdx2; // a01
525 p[1] += z1*dzdx2; // a02
526 p[6] += dzdx2; // a03
527 value = z2-z1; //-a22
528 fitter->AddPoint(p,value,sz);
530 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
531 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
532 for (Int_t i=0; i<12;i++) p[i]=0.;
534 //p[] += dydx1; // a11
535 p[3] += dzdx1; // a12
536 //p[] += -dydx2; // a00
537 p[0] += -dydx1*dydx2; // a01
538 p[1] += -dzdx1*dydx2; // a02
539 value = -dydx1+dydx2; // -a11 + a00
540 fitter->AddPoint(p,value,sdydx);
542 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
543 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
544 for (Int_t i=0; i<12;i++) p[i]=0.;
546 p[5] += dydx1; // a21
547 //p[] += dzdx1; // a22
548 //p[] += -dzdx2; // a00
549 p[0] += -dydx1*dzdx2; // a01
550 p[1] += -dzdx1*dzdx2; // a02
551 value = -dzdx1+dzdx2; // -a22 + a00
552 fitter->AddPoint(p,value,sdzdx);
555 void AliTPCcalibAlign::Process6(Double_t *t1,
557 TLinearFitter *fitter) {
558 // x2 = 1 *x1 +-a01*y1 + 0 +a03
559 // y2 = a01*x1 + 1 *y1 + 0 +a13
560 // z2 = a20*x1 + a21*y1 + 1 *z1 +a23
561 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
562 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/(a00 + a01*dydx1 + a02*dzdx1)
564 // a00 a01 a02 a03 1 -p[0] 0 p[3]
565 // a10 a11 a12 a13 ==> p[0] 1 0 p[4]
566 // a20 a21 a21 a23 p[1] p[2] 1 p[5]
568 Double_t &x1=t1[0], &y1=t1[1], &z1=t1[2], &dydx1=t1[3], &dzdx1=t1[4];
569 Double_t /*&x2=t2[0],*/ &y2=t2[1], &z2=t2[2], &dydx2=t2[3], &dzdx2=t2[4];
574 Double_t sdydx = 0.001;
575 Double_t sdzdx = 0.001;
579 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
580 // y2 = a10*x1 + a11*y1 + a12*z1 + a13
581 // y2' = a10*x1 + a11*y1 + a12*z1 + a13 + (a01*y1 + a02*z1 + a03)*dydx2
582 for (Int_t i=0; i<12;i++) p[i]=0.;
587 p[0] += -y1*dydx2; // a01
588 //p[] += z1*dydx2; // a02
589 p[3] += dydx2; // a03
590 value = y2-y1; //-a11
591 fitter->AddPoint(p,value,sy);
593 // x2 = a00*x1 + a01*y1 + a02*z1 + a03
594 // z2 = a20*x1 + a21*y1 + a22*z1 + a23
595 // z2' = a20*x1 + a21*y1 + a22*z1 + a23 + (a01*y1 + a02*z1 + a03)*dzdx2;
596 for (Int_t i=0; i<12;i++) p[i]=0.;
601 p[0] += -y1*dzdx2; // a01
602 //p[] += z1*dzdx2; // a02
603 p[3] += dzdx2; // a03
604 value = z2-z1; //-a22
605 fitter->AddPoint(p,value,sz);
607 // dydx2 = (a10 + a11*dydx1 + a12*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
608 // (a10 + a11*dydx1 + a12*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dydx2 = 0
609 for (Int_t i=0; i<12;i++) p[i]=0.;
611 //p[] += dydx1; // a11
612 //p[] += dzdx1; // a12
613 //p[] += -dydx2; // a00
614 p[0] += dydx1*dydx2; // a01
615 //p[] += -dzdx1*dydx2; // a02
616 value = -dydx1+dydx2; // -a11 + a00
617 fitter->AddPoint(p,value,sdydx);
619 // dzdx2 = (a20 + a21*dydx1 + a22*dzdx1)/( a00 + a01*dydx1 + a02*dzdx1)
620 // (a20 + a21*dydx1 + a22*dzdx1) - (a00 + a01*dydx1 + a02*dzdx1)*dzdx2 = 0
621 for (Int_t i=0; i<12;i++) p[i]=0.;
623 p[2] += dydx1; // a21
624 //p[] += dzdx1; // a22
625 //p[] += -dzdx2; // a00
626 p[0] += dydx1*dzdx2; // a01
627 //p[] += -dzdx1*dzdx2; // a02
628 value = -dzdx1+dzdx2; // -a22 + a00
629 fitter->AddPoint(p,value,sdzdx);
635 void AliTPCcalibAlign::EvalFitters() {
639 // Perform the fitting using linear fitters
641 Int_t kMinPoints =50;
643 TFile fff("alignDebug.root","recreate");
644 for (Int_t s1=0;s1<72;++s1)
645 for (Int_t s2=0;s2<72;++s2){
646 if ((f=GetFitter12(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
647 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
649 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
650 f->Write(Form("f12_%d_%d",s1,s2));
652 f->Write(Form("f12_%d_%d",s1,s2));
655 if ((f=GetFitter9(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
656 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
658 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
660 f->Write(Form("f9_%d_%d",s1,s2));
663 if ((f=GetFitter6(s1,s2))&&fPoints[GetIndex(s1,s2)]>kMinPoints) {
664 // cerr<<s1<<","<<s2<<": "<<fPoints[GetIndex(s1,s2)]<<endl;
666 cerr<<"Evaluation failed for "<<s1<<","<<s2<<endl;
668 f->Write(Form("f6_%d_%d",s1,s2));
672 this->Write("align");
677 chi212 = align->GetChisquare()/(4.*entries);
681 align->GetParameters(par);
682 align->GetCovarianceMatrix(mat);
686 for (Int_t i=0; i<12;i++){
687 palign12(i)= par(i+1);
688 for (Int_t j=0; j<12;j++){
689 pcovar12(i,j) = mat(i+1,j+1);
690 pcovar12(i,j) *= chi212;
694 for (Int_t i=0; i<12;i++){
695 psigma12(i) = TMath::Sqrt(pcovar12(i,i));
696 palignR12(i) = palign12(i)/TMath::Sqrt(pcovar12(i,i));
697 for (Int_t j=0; j<12;j++){
698 pcovarN12(i,j) = pcovar12(i,j)/TMath::Sqrt(pcovar12(i,i)*pcovar12(j,j));
704 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter12(Int_t s1,Int_t s2) {
706 // get or make fitter - general linear transformation
708 static Int_t counter12=0;
709 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]");
710 TLinearFitter * fitter = GetFitter12(s1,s2);
711 if (fitter) return fitter;
712 // 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]");
713 fitter =new TLinearFitter(&f12,"");
714 fitter->StoreData(kFALSE);
715 fFitterArray12.AddAt(fitter,GetIndex(s1,s2));
717 if (GetDebugLevel()>0) cerr<<"Creating fitter12 "<<s1<<","<<s2<<" : "<<counter12<<endl;
721 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter9(Int_t s1,Int_t s2) {
723 //get or make fitter - general linear transformation - no scaling
725 static Int_t counter9=0;
726 static TF1 f9("f9","x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]");
727 TLinearFitter * fitter = GetFitter9(s1,s2);
728 if (fitter) return fitter;
729 // fitter =new TLinearFitter(9,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]++x[6]++x[7]++x[8]");
730 fitter =new TLinearFitter(&f9,"");
731 fitter->StoreData(kFALSE);
732 fFitterArray9.AddAt(fitter,GetIndex(s1,s2));
734 if (GetDebugLevel()>0) cerr<<"Creating fitter12 "<<s1<<","<<s2<<" : "<<counter9<<endl;
738 TLinearFitter* AliTPCcalibAlign::GetOrMakeFitter6(Int_t s1,Int_t s2) {
740 // get or make fitter - 6 paramater linear tranformation
743 // - tilting x-z, y-z
744 static Int_t counter6=0;
745 static TF1 f6("f6","x[0]++x[1]++x[2]++x[3]++x[4]++x[5]");
746 TLinearFitter * fitter = GetFitter6(s1,s2);
747 if (fitter) return fitter;
748 // fitter=new TLinearFitter(6,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]");
749 fitter=new TLinearFitter(&f6,"");
750 fitter->StoreData(kFALSE);
751 fFitterArray6.AddAt(fitter,GetIndex(s1,s2));
753 if (GetDebugLevel()>0) cerr<<"Creating fitter6 "<<s1<<","<<s2<<" : "<<counter6<<endl;
761 Bool_t AliTPCcalibAlign::GetTransformation12(Int_t s1,Int_t s2,TMatrixD &a) {
763 // GetTransformation matrix - 12 paramaters - generael linear transformation
765 if (!GetFitter12(s1,s2))
769 GetFitter12(s1,s2)->GetParameters(p);
771 a[0][0]=p[0]; a[0][1]=p[1]; a[0][2]=p[2]; a[0][3]=p[9];
772 a[1][0]=p[3]; a[1][1]=p[4]; a[1][2]=p[5]; a[1][3]=p[10];
773 a[2][0]=p[6]; a[2][1]=p[7]; a[2][2]=p[8]; a[2][3]=p[11];
774 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
779 Bool_t AliTPCcalibAlign::GetTransformation9(Int_t s1,Int_t s2,TMatrixD &a) {
781 // GetTransformation matrix - 9 paramaters - general linear transformation
784 if (!GetFitter9(s1,s2))
788 GetFitter9(s1,s2)->GetParameters(p);
790 a[0][0]=1; a[0][1]=p[0]; a[0][2]=p[1]; a[0][3]=p[6];
791 a[1][0]=p[2]; a[1][1]=1; a[1][2]=p[3]; a[1][3]=p[7];
792 a[2][0]=p[4]; a[2][1]=p[5]; a[2][2]=1; a[2][3]=p[8];
793 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
798 Bool_t AliTPCcalibAlign::GetTransformation6(Int_t s1,Int_t s2,TMatrixD &a) {
800 // GetTransformation matrix - 6 paramaters
804 if (!GetFitter6(s1,s2))
808 GetFitter6(s1,s2)->GetParameters(p);
810 a[0][0]=1; a[0][1]=-p[0];a[0][2]=0; a[0][3]=p[3];
811 a[1][0]=p[0]; a[1][1]=1; a[1][2]=0; a[1][3]=p[4];
812 a[2][0]=p[1]; a[2][1]=p[2]; a[2][2]=1; a[2][3]=p[5];
813 a[3][0]=0.; a[3][1]=0.; a[3][2]=0.; a[3][3]=1.;
818 void AliTPCcalibAlign::FillHisto(const AliExternalTrackParam &tp1,
819 const AliExternalTrackParam &tp2,
822 // Fill residual histograms
826 if (TMath::Abs(s2%36-s1%36)<2 || TMath::Abs(s2%18-s1%18)==0) {
827 GetHisto(kPhi,s1,s2,kTRUE)->Fill(TMath::ASin(tp1.GetSnp())-TMath::ASin(tp2.GetSnp()));
828 GetHisto(kTheta,s1,s2,kTRUE)->Fill(TMath::ATan(tp1.GetTgl())-TMath::ATan(tp2.GetTgl()));
829 GetHisto(kY,s1,s2,kTRUE)->Fill(tp1.GetY()-tp2.GetY());
830 GetHisto(kZ,s1,s2,kTRUE)->Fill(tp1.GetZ()-tp2.GetZ());
836 TH1 * AliTPCcalibAlign::GetHisto(HistoType type, Int_t s1, Int_t s2, Bool_t force)
839 // return specified residual histogram - it is only QA
840 // if force specified the histogram and given histogram is not existing
841 // new histogram is created
843 if (GetIndex(s1,s2)>=72*72) return 0;
844 TObjArray *histoArray=0;
847 histoArray = &fDyHistArray; break;
849 histoArray = &fDzHistArray; break;
851 histoArray = &fDphiHistArray; break;
853 histoArray = &fDthetaHistArray; break;
855 TH1 * histo= (TH1*)histoArray->At(GetIndex(s1,s2));
856 if (histo) return histo;
857 if (force==kFALSE) return 0;
863 name<<"hist_y_"<<s1<<"_"<<s2;
864 title<<"Y Missalignment for sectors "<<s1<<" and "<<s2;
865 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.3,0.3); // +/- 3 mm
868 name<<"hist_z_"<<s1<<"_"<<s2;
869 title<<"Z Missalignment for sectors "<<s1<<" and "<<s2;
870 histo = new TH1D(name.str().c_str(),title.str().c_str(),512,-0.3,0.3); // +/- 3 mm
873 name<<"hist_phi_"<<s1<<"_"<<s2;
874 title<<"Phi Missalignment for sectors "<<s1<<" and "<<s2;
875 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.01,0.01); // +/- 10 mrad
878 name<<"hist_theta_"<<s1<<"_"<<s2;
879 title<<"Theta Missalignment for sectors "<<s1<<" and "<<s2;
880 histo =new TH1D(name.str().c_str(),title.str().c_str(),512,-0.01,0.01); // +/- 10 mrad
883 histo->SetDirectory(0);
884 histoArray->AddAt(histo,GetIndex(s1,s2));
888 TGraphErrors * AliTPCcalibAlign::MakeGraph(Int_t sec0, Int_t sec1, Int_t dsec,
889 Int_t i0, Int_t i1, FitType type)
895 TObjArray *fitArray=0;
899 for (Int_t isec = sec0; isec<=sec1; isec++){
900 Int_t isec2 = (isec+dsec)%72;
903 GetTransformation6(isec,isec2,mat);break;
905 GetTransformation9(isec,isec2,mat);break;
907 GetTransformation12(isec,isec2,mat);break;
910 ysec[npoints]=mat(i0,i1);
913 TGraphErrors *gr = new TGraphErrors(npoints,xsec,ysec,0,0);
915 sprintf(name,"Mat[%d,%d] Type=%d",i0,i1,type);
920 void AliTPCcalibAlign::MakeTree(const char *fname){
922 // make tree with alignment cosntant -
923 // For QA visualization
926 TFile f("CalibObjects.root");
927 TObjArray *array = (TObjArray*)f.Get("TPCCalib");
928 AliTPCcalibAlign *alignTPC = (AliTPCcalibAlign *)array->At(0);
929 alignTPC->MakeTree("alignTree.root");
930 TFile falign("alignTree.root");
933 const Int_t kMinPoints=50;
934 TTreeSRedirector cstream(fname);
935 for (Int_t s1=0;s1<72;++s1)
936 for (Int_t s2=0;s2<72;++s2){
937 if (fPoints[GetIndex(s1,s2)]<kMinPoints) continue;
941 GetTransformation6(s1,s2,m6);
942 GetTransformation9(s1,s2,m9);
943 GetTransformation12(s1,s2,m12);
944 Double_t dy=0, dz=0, dphi=0,dtheta=0;
945 Double_t sy=0, sz=0, sphi=0,stheta=0;
946 Double_t ny=0, nz=0, nphi=0,ntheta=0;
948 his = GetHisto(kY,s1,s2);
949 if (his) { dy = his->GetMean(); sy = his->GetRMS(); ny = his->GetEntries();}
950 his = GetHisto(kZ,s1,s2);
951 if (his) { dz = his->GetMean(); sz = his->GetRMS(); nz = his->GetEntries();}
952 his = GetHisto(kPhi,s1,s2);
953 if (his) { dphi = his->GetMean(); sphi = his->GetRMS(); nphi = his->GetEntries();}
954 his = GetHisto(kTheta,s1,s2);
955 if (his) { dtheta = his->GetMean(); stheta = his->GetRMS(); ntheta = his->GetEntries();}
958 "s1="<<s1<< // reference sector
959 "s2="<<s2<< // sector to align
960 "m6.="<<&m6<< // tranformation matrix
963 // histograms mean RMS and entries
982 //_____________________________________________________________________
983 Long64_t AliTPCcalibAlign::Merge(TCollection* list) {
987 if (GetDebugLevel()>0) Info("AliTPCcalibAlign","Merge");
993 TIterator* iter = list->MakeIterator();
997 while((obj = iter->Next()) != 0)
999 AliTPCcalibAlign* entry = dynamic_cast<AliTPCcalibAlign*>(obj);
1000 if (entry == 0) continue;
1008 void AliTPCcalibAlign::Add(AliTPCcalibAlign * align){
1013 for (Int_t i=0; i<72;i++){
1014 for (Int_t j=0; j<72;j++){
1015 fPoints[GetIndex(i,j)]+=align->fPoints[GetIndex(i,j)];
1019 TH1* hdy0 = GetHisto(kY,i,j);
1020 TH1* hdy1 = align->GetHisto(kY,i,j);
1022 if (hdy0) hdy0->Add(hdy1);
1024 hdy0 = GetHisto(kY,i,j,kTRUE);
1030 TH1* hdz0 = GetHisto(kZ,i,j);
1031 TH1* hdz1 = align->GetHisto(kZ,i,j);
1033 if (hdz0) hdz0->Add(hdz1);
1035 hdz0 = GetHisto(kZ,i,j,kTRUE);
1041 TH1* hdphi0 = GetHisto(kPhi,i,j);
1042 TH1* hdphi1 = align->GetHisto(kPhi,i,j);
1044 if (hdphi0) hdphi0->Add(hdphi1);
1046 hdphi0 = GetHisto(kPhi,i,j,kTRUE);
1047 hdphi0->Add(hdphi1);
1052 TH1* hdTheta0 = GetHisto(kTheta,i,j);
1053 TH1* hdTheta1 = align->GetHisto(kTheta,i,j);
1055 if (hdTheta0) hdTheta0->Add(hdTheta1);
1057 hdTheta0 = GetHisto(kTheta,i,j,kTRUE);
1058 hdTheta0->Add(hdTheta1);
1063 TLinearFitter *f0=0;
1064 TLinearFitter *f1=0;
1065 for (Int_t i=0; i<72;i++){
1066 for (Int_t j=0; j<72;j++){
1069 f0 = GetFitter12(i,j);
1070 f1 = GetFitter12(i,j);
1072 if (f0) f0->Add(f1);
1074 f0 = GetOrMakeFitter12(i,j);
1080 f0 = GetFitter9(i,j);
1081 f1 = GetFitter9(i,j);
1083 if (f0) f0->Add(f1);
1085 f0 = GetOrMakeFitter9(i,j);
1089 f0 = GetFitter6(i,j);
1090 f1 = GetFitter6(i,j);
1092 if (f0) f0->Add(f1);
1094 f0 = GetOrMakeFitter6(i,j);