AliRoot Core  da88d91 (da88d91)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliTPCCorrection.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
58 
59 
60 #include "Riostream.h"
61 
62 #include <TH2F.h>
63 #include <TMath.h>
64 #include <TROOT.h>
65 #include <TTreeStream.h>
66 #include <TTree.h>
67 #include <TFile.h>
68 #include <TTimeStamp.h>
69 #include <AliCDBStorage.h>
70 #include <AliCDBId.h>
71 #include <AliCDBMetaData.h>
72 #include "TVectorD.h"
73 #include "AliTPCParamSR.h"
74 
75 #include "AliTPCCorrection.h"
76 #include "AliLog.h"
77 
78 #include "AliExternalTrackParam.h"
79 #include "AliTrackPointArray.h"
80 #include "TDatabasePDG.h"
81 #include "AliTrackerBase.h"
82 #include "AliTPCROC.h"
83 #include "THnSparse.h"
84 
85 #include "AliTPCLaserTrack.h"
86 #include "AliESDVertex.h"
87 #include "AliVertexerTracks.h"
88 #include "TDatabasePDG.h"
89 #include "TF1.h"
90 #include "TRandom.h"
91 
92 #include "TDatabasePDG.h"
93 
94 #include "AliTPCTransform.h"
95 #include "AliTPCcalibDB.h"
96 #include "AliTPCExB.h"
97 
98 //#include "AliTPCRecoParam.h"
99 #include "TLinearFitter.h"
100 #include <AliSysInfo.h>
101 
105 
106 
107 TObjArray *AliTPCCorrection::fgVisualCorrection=0;
108 // instance of correction for visualization
109 
110 
111 // FIXME: the following values should come from the database
112 const Double_t AliTPCCorrection::fgkTPCZ0 = 249.7;
113 const Double_t AliTPCCorrection::fgkIFCRadius= 83.5;
114 // compare gkIFCRadius= 83.05: Mean Radius of the Inner Field Cage ( 82.43 min, 83.70 max) (cm)
115 const Double_t AliTPCCorrection::fgkOFCRadius= 254.5;
116 const Double_t AliTPCCorrection::fgkZOffSet = 0.2;
117 const Double_t AliTPCCorrection::fgkCathodeV = -100000.0;
118 const Double_t AliTPCCorrection::fgkGG = -70.0;
119 
120 const Double_t AliTPCCorrection::fgkdvdE = 0.0024;
121 
122 const Double_t AliTPCCorrection::fgkEM = -1.602176487e-19/9.10938215e-31;
123 const Double_t AliTPCCorrection::fgke0 = 8.854187817e-12;
124 
125 
127  : TNamed("correction_unity","unity"),fILow(0),fJLow(0),fKLow(0), fT1(1), fT2(1), fIsLocal(kFALSE), fIntegrationType(kIntegral)
128 {
130 
131  if (!fgVisualCorrection) fgVisualCorrection= new TObjArray;
132 
133  InitLookUpfulcrums();
134 
135 }
136 
137 AliTPCCorrection::AliTPCCorrection(const char *name,const char *title)
138  : TNamed(name,title),fILow(0),fJLow(0),fKLow(0), fT1(1), fT2(1), fIsLocal(kFALSE), fIntegrationType(kIntegral)
139 {
141 
143 
145 
146 }
147 
150 
151 }
152 
158 
159  if (corr==NULL) {
160  AliError("Zerro pointer - correction");
161  return kFALSE;
162  }
163  AliError(TString::Format("Correction %s not implementend",IsA()->GetName()).Data());
164  return kFALSE;
165 }
166 
167 
168 void AliTPCCorrection::CorrectPoint(Float_t x[], Short_t roc) {
172 
173  Float_t dx[3];
174  GetCorrection(x,roc,dx);
175  for (Int_t j=0;j<3;++j) x[j]+=dx[j];
176 }
177 
178 void AliTPCCorrection::CorrectPoint(const Float_t x[], Short_t roc,Float_t xp[]) {
182 
183  Float_t dx[3];
184  GetCorrection(x,roc,dx);
185  for (Int_t j=0;j<3;++j) xp[j]=x[j]+dx[j];
186 }
187 
188 void AliTPCCorrection::DistortPoint(Float_t x[], Short_t roc) {
192 
193  Float_t dx[3];
194  GetDistortion(x,roc,dx);
195  for (Int_t j=0;j<3;++j) x[j]+=dx[j];
196 }
197 
198 void AliTPCCorrection::DistortPointLocal(Float_t x[], Short_t roc) {
202 
203  Float_t gxyz[3]={0,0,0};
204  Double_t alpha = TMath::TwoPi()*(roc%18+0.5)/18;
205  Double_t ca=TMath::Cos(alpha), sa= TMath::Sin(alpha);
206  gxyz[0]= ca*x[0]+sa*x[1];
207  gxyz[1]= -sa*x[0]+ca*x[1];
208  gxyz[2]= x[2];
209  DistortPoint(gxyz,roc);
210  x[0]= ca*gxyz[0]-sa*gxyz[1];
211  x[1]= +sa*gxyz[0]+ca*gxyz[1];
212  x[2]= gxyz[2];
213 }
214 void AliTPCCorrection::CorrectPointLocal(Float_t x[], Short_t roc) {
218 
219  Float_t gxyz[3]={0,0,0};
220  Double_t alpha = TMath::TwoPi()*(roc%18+0.5)/18;
221  Double_t ca=TMath::Cos(alpha), sa= TMath::Sin(alpha);
222  gxyz[0]= ca*x[0]+sa*x[1];
223  gxyz[1]= -sa*x[0]+ca*x[1];
224  gxyz[2]= x[2];
225  CorrectPoint(gxyz,roc);
226  x[0]= ca*gxyz[0]-sa*gxyz[1];
227  x[1]= sa*gxyz[0]+ca*gxyz[1];
228  x[2]= gxyz[2];
229 }
230 
231 void AliTPCCorrection::DistortPoint(const Float_t x[], Short_t roc,Float_t xp[]) {
235 
236  Float_t dx[3];
237  GetDistortion(x,roc,dx);
238  for (Int_t j=0;j<3;++j) xp[j]=x[j]+dx[j];
239 }
240 
241 void AliTPCCorrection::GetCorrection(const Float_t /*x*/[], Short_t /*roc*/,Float_t dx[]) {
245 
246  for (Int_t j=0;j<3;++j) { dx[j]=0.; }
247 }
248 
249 void AliTPCCorrection::GetDistortion(const Float_t x[], Short_t roc,Float_t dx[]) {
252 
253  GetCorrection(x,roc,dx);
254  for (Int_t j=0;j<3;++j) dx[j]=-dx[j];
255 }
256 
257 void AliTPCCorrection::GetCorrectionDz(const Float_t x[], Short_t roc,Float_t dx[], Float_t delta) {
272 
273  // if (fIsLocal){ //standard implemenation provides the correction/distortion integrated over full drift length
274  //
275  //
276  // GetCorrection(xyz,roc,dxyz);
277  // }
278 
279  //check if we are already in the differential mode
281  GetCorrection(x, roc, dx);
282  } else if (fIntegrationType == kIntegral) {
283 
284  static TLinearFitter fitx(2,"pol1");
285  static TLinearFitter fity(2,"pol1");
286  static TLinearFitter fitz(2,"pol1");
287  fitx.ClearPoints();
288  fity.ClearPoints();
289  fitz.ClearPoints();
290  Int_t zmin=-2;
291  Int_t zmax=0;
292  //adjust limits around CE to stay on one side
293  if ((roc%36)<18) {
294  //A-Side
295  if ((x[2]+zmin*delta)<0){
296  zmin=0;
297  zmax=2;
298  if ((x[2]-delta)>0){
299  zmin=-1;
300  zmax=1;
301  }
302  }
303  } else {
304  //C-Side
305  zmin=0;
306  zmax=2;
307  if ((x[2]+zmax*delta)>0){
308  zmin=-2;
309  zmax=0;
310  if ((x[2]+delta)<0){
311  zmin=-1;
312  zmax=1;
313  }
314  }
315  }
316 
317  for (Int_t xdelta=-1; xdelta<=1; xdelta++)
318  for (Int_t ydelta=-1; ydelta<=1; ydelta++){
319  // for (Int_t zdelta=-1; zdelta<=1; zdelta++){
320  // for (Int_t xdelta=-2; xdelta<=0; xdelta++)
321  // for (Int_t ydelta=-2; ydelta<=0; ydelta++){
322  for (Int_t zdelta=zmin; zdelta<=zmax; zdelta++){
323  //TODO: what happens if x[2] is on the A-Side, but x[2]+zdelta*delta
324  // will be on the C-Side?
325  Float_t xyz[3]={x[0]+xdelta*delta, x[1]+ydelta*delta, x[2]+zdelta*delta};
326  Float_t dxyz[3];
327  GetCorrection(xyz,roc,dxyz);
328  Double_t adelta=zdelta*delta;
329  fitx.AddPoint(&adelta, dxyz[0]);
330  fity.AddPoint(&adelta, dxyz[1]);
331  fitz.AddPoint(&adelta, dxyz[2]);
332  }
333  }
334  fitx.Eval();
335  fity.Eval();
336  fitz.Eval();
337  dx[0] = fitx.GetParameter(1);
338  dx[1] = fity.GetParameter(1);
339  dx[2] = fitz.GetParameter(1);
340  }
341 }
342 
343 void AliTPCCorrection::GetDistortionDz(const Float_t x[], Short_t roc,Float_t dx[], Float_t delta) {
358 
359  //check if we are already in the differential mode
361  GetDistortion(x, roc, dx);
362  } else if (fIntegrationType == kIntegral) {
363  //in this case do the differentiation first
364 
365  static TLinearFitter fitx(2,"pol1");
366  static TLinearFitter fity(2,"pol1");
367  static TLinearFitter fitz(2,"pol1");
368  fitx.ClearPoints();
369  fity.ClearPoints();
370  fitz.ClearPoints();
371 
372  Int_t zmin=-1;
373  Int_t zmax=1;
374  //adjust limits around CE to stay on one side
375  if ((roc%36)<18) {
376  //A-Side
377  if ((x[2]+zmin*delta)<0){
378  zmin=0;
379  zmax=2;
380  }
381  } else {
382  //C-Side
383  if ((x[2]+zmax*delta)>0){
384  zmin=-2;
385  zmax=0;
386  }
387  }
388 
389  //TODO: in principle one shuld check that x[2]+zdelta*delta does not get 'out of' bounds,
390  // so close to the CE it doesn't change the sign, since then the corrections will be wrong ...
391  for (Int_t xdelta=-1; xdelta<=1; xdelta++)
392  for (Int_t ydelta=-1; ydelta<=1; ydelta++){
393  for (Int_t zdelta=zmin; zdelta<=zmax; zdelta++){
394  //TODO: what happens if x[2] is on the A-Side, but x[2]+zdelta*delta
395  // will be on the C-Side?
396  //TODO: For the C-Side, does this have the correct sign?
397  Float_t xyz[3]={x[0]+xdelta*delta, x[1]+ydelta*delta, x[2]+zdelta*delta};
398  Float_t dxyz[3];
399  GetDistortion(xyz,roc,dxyz);
400  Double_t adelta=zdelta*delta;
401  fitx.AddPoint(&adelta, dxyz[0]);
402  fity.AddPoint(&adelta, dxyz[1]);
403  fitz.AddPoint(&adelta, dxyz[2]);
404  }
405  }
406  fitx.Eval();
407  fity.Eval();
408  fitz.Eval();
409  dx[0] = fitx.GetParameter(1);
410  dx[1] = fity.GetParameter(1);
411  dx[2] = fitz.GetParameter(1);
412  }
413 }
414 
415 void AliTPCCorrection::GetCorrectionIntegralDz(const Float_t x[], Short_t roc,Float_t dx[], Float_t delta){
427 
428  Float_t zroc= ((roc%36)<18) ? fgkTPCZ0:-fgkTPCZ0;
429  Double_t zdrift = TMath::Abs(x[2]-zroc);
430  Int_t nsteps = Int_t(zdrift/delta)+1;
431  //
432  //
433  Float_t xyz[3]={x[0],x[1],zroc};
434  Float_t dxyz[3]={x[0],x[1],x[2]};
435  Short_t side=(roc/18)%2;
436  Float_t sign=1-2*side;
437  Double_t sumdz=0;
438  for (Int_t i=0;i<nsteps; i++){
439  //propagate backwards, therefore opposite signs
440  Float_t deltaZ=delta*(-sign);
441 // if (xyz[2]+deltaZ>fgkTPCZ0) deltaZ=TMath::Abs(xyz[2]-fgkTPCZ0);
442 // if (xyz[2]-deltaZ<-fgkTPCZ0) deltaZ=TMath::Abs(xyz[2]-fgkTPCZ0);
443  // protect again integrating through the CE
444  if (side==0){
445  if (xyz[2]+deltaZ<0) deltaZ=-xyz[2]+1e-20;
446  } else {
447  if (xyz[2]+deltaZ>0) deltaZ=xyz[2]-+1e-20;
448  }
449  // since at larger drift (smaller z) the corrections are larger (absolute, but negative)
450  // the slopes will be positive.
451  // but since we chose deltaZ opposite sign the singn of the corretion should be fine
452 
453  Float_t xyz2[3]={xyz[0],xyz[1],static_cast<Float_t>(xyz[2]+deltaZ/2.)};
454  GetCorrectionDz(xyz2,roc,dxyz,delta/2.);
455  xyz[0]+=deltaZ*dxyz[0];
456  xyz[1]+=deltaZ*dxyz[1];
457  xyz[2]+=deltaZ; //
458  sumdz+=deltaZ*dxyz[2];
459  }
460  //
461  dx[0]=xyz[0]-x[0];
462  dx[1]=xyz[1]-x[1];
463  dx[2]= sumdz; //TODO: is sumdz correct?
464 }
465 
466 void AliTPCCorrection::GetDistortionIntegralDz(const Float_t x[], Short_t roc,Float_t dx[], Float_t delta){
476 
477  Float_t zroc= ((roc%36)<18) ? fgkTPCZ0:-fgkTPCZ0;
478  Double_t zdrift = TMath::Abs(x[2]-zroc);
479  Int_t nsteps = Int_t(zdrift/delta)+1;
480  //
481  //
482  Float_t xyz[3]={x[0],x[1],x[2]};
483  Float_t dxyz[3]={x[0],x[1],x[2]};
484  Float_t sign=((roc%36)<18) ? 1.:-1.;
485  Double_t sumdz=0;
486  for (Int_t i=0;i<nsteps; i++){
487  Float_t deltaZ=delta;
488  if (xyz[2]+deltaZ>fgkTPCZ0) deltaZ=TMath::Abs(xyz[2]-zroc);
489  if (xyz[2]-deltaZ<-fgkTPCZ0) deltaZ=TMath::Abs(xyz[2]-zroc);
490  // since at larger drift (smaller z) the distortions are larger
491  // the slopes will be negative.
492  // and since we are moving towards the read-out plane the deltaZ for
493  // weighting the dK/dz should have the opposite sign
494  deltaZ*=sign;
495  Float_t xyz2[3]={xyz[0],xyz[1],static_cast<Float_t>(xyz[2]+deltaZ/2.)};
496  GetDistortionDz(xyz2,roc,dxyz,delta/2.);
497  xyz[0]+=-deltaZ*dxyz[0];
498  xyz[1]+=-deltaZ*dxyz[1];
499  xyz[2]+=deltaZ; //TODO: Should this also be corrected for the dxyz[2]
500  sumdz+=-deltaZ*dxyz[2];
501  }
502  //
503  dx[0]=xyz[0]-x[0];
504  dx[1]=xyz[1]-x[1];
505  dx[2]= sumdz; //TODO: is sumdz correct?
506 
507 }
508 
509 
512 
513 }
514 
515 void AliTPCCorrection::Update(const TTimeStamp &/*timeStamp*/) {
517 
518 }
519 
520 void AliTPCCorrection::Print(Option_t* /*option*/) const {
524 
525  printf("TPC spacepoint correction: \"%s\"\n",GetTitle());
526 }
527 
528 void AliTPCCorrection:: SetOmegaTauT1T2(Float_t /*omegaTau*/,Float_t t1,Float_t t2) {
532 
533  fT1=t1;
534  fT2=t2;
535  //SetOmegaTauT1T2(omegaTau, t1, t2);
536 }
537 
538 TH2F* AliTPCCorrection::CreateHistoDRinXY(Float_t z,Int_t nx,Int_t ny) {
543 
544  AliTPCParam* tpcparam = new AliTPCParamSR;
545 
546  TH2F *h=CreateTH2F("dr_xy", TString::Format("%s: DRinXY Z=%2.0f", GetTitle(),z).Data(),"x [cm]","y [cm]","dr [cm]",
547  nx,-250.,250.,ny,-250.,250.);
548  Float_t x[3],dx[3];
549  x[2]=z;
550  Int_t roc=z>0.?0:18; // FIXME
551  for (Int_t iy=1;iy<=ny;++iy) {
552  x[1]=h->GetYaxis()->GetBinCenter(iy);
553  for (Int_t ix=1;ix<=nx;++ix) {
554  x[0]=h->GetXaxis()->GetBinCenter(ix);
555  GetCorrection(x,roc,dx);
556  Float_t r0=TMath::Sqrt((x[0] )*(x[0] )+(x[1] )*(x[1] ));
557  if (tpcparam->GetPadRowRadii(0,0)<=r0 && r0<=tpcparam->GetPadRowRadii(36,95)) {
558  Float_t r1=TMath::Sqrt((x[0]+dx[0])*(x[0]+dx[0])+(x[1]+dx[1])*(x[1]+dx[1]));
559  h->SetBinContent(ix,iy,r1-r0);
560  }
561  else
562  h->SetBinContent(ix,iy,0.);
563  }
564  }
565  delete tpcparam;
566  return h;
567 }
568 
569 TH2F* AliTPCCorrection::CreateHistoDRPhiinXY(Float_t z,Int_t nx,Int_t ny) {
574 
575  AliTPCParam* tpcparam = new AliTPCParamSR;
576 
577  TH2F *h=CreateTH2F("drphi_xy",TString::Format("%s: DRPhiinXY Z=%2.0f", GetTitle(),z).Data(),"x [cm]","y [cm]","drphi [cm]",
578  nx,-250.,250.,ny,-250.,250.);
579  Float_t x[3],dx[3];
580  x[2]=z;
581  Int_t roc=z>0.?0:18; // FIXME
582  for (Int_t iy=1;iy<=ny;++iy) {
583  x[1]=h->GetYaxis()->GetBinCenter(iy);
584  for (Int_t ix=1;ix<=nx;++ix) {
585  x[0]=h->GetXaxis()->GetBinCenter(ix);
586  GetCorrection(x,roc,dx);
587  Float_t r0=TMath::Sqrt((x[0] )*(x[0] )+(x[1] )*(x[1] ));
588  if (tpcparam->GetPadRowRadii(0,0)<=r0 && r0<=tpcparam->GetPadRowRadii(36,95)) {
589  Float_t phi0=TMath::ATan2(x[1] ,x[0] );
590  Float_t phi1=TMath::ATan2(x[1]+dx[1],x[0]+dx[0]);
591 
592  Float_t dphi=phi1-phi0;
593  if (dphi<TMath::Pi()) dphi+=TMath::TwoPi();
594  if (dphi>TMath::Pi()) dphi-=TMath::TwoPi();
595 
596  h->SetBinContent(ix,iy,r0*dphi);
597  }
598  else
599  h->SetBinContent(ix,iy,0.);
600  }
601  }
602  delete tpcparam;
603  return h;
604 }
605 
606 TH2F* AliTPCCorrection::CreateHistoDZinXY(Float_t z,Int_t nx,Int_t ny) {
611 
612  AliTPCParam* tpcparam = new AliTPCParamSR;
613 
614  TH2F *h=CreateTH2F("dz_xy",TString::Format("%s: DZinXY Z=%2.0f", GetTitle(),z).Data(),"x [cm]","y [cm]","dz [cm]",
615  nx,-250.,250.,ny,-250.,250.);
616  Float_t x[3],dx[3];
617  x[2]=z;
618  Int_t roc=z>0.?0:18; // FIXME
619  for (Int_t iy=1;iy<=ny;++iy) {
620  x[1]=h->GetYaxis()->GetBinCenter(iy);
621  for (Int_t ix=1;ix<=nx;++ix) {
622  x[0]=h->GetXaxis()->GetBinCenter(ix);
623  GetCorrection(x,roc,dx);
624  Float_t r0=TMath::Sqrt((x[0] )*(x[0] )+(x[1] )*(x[1] ));
625  if (tpcparam->GetPadRowRadii(0,0)<=r0 && r0<=tpcparam->GetPadRowRadii(36,95)) {
626  h->SetBinContent(ix,iy,dx[2]);
627  }
628  else
629  h->SetBinContent(ix,iy,0.);
630  }
631  }
632  delete tpcparam;
633  return h;
634 }
635 
636 TH2F* AliTPCCorrection::CreateHistoDRinZR(Float_t phi,Int_t nz,Int_t nr) {
641 
642  TH2F *h=CreateTH2F("dr_zr",TString::Format("%s: DRinZR Phi=%2.2f", GetTitle(),phi).Data(),"z [cm]","r [cm]","dr [cm]",
643  nz,-250.,250.,nr,85.,250.);
644  Float_t x[3],dx[3];
645  for (Int_t ir=1;ir<=nr;++ir) {
646  Float_t radius=h->GetYaxis()->GetBinCenter(ir);
647  x[0]=radius*TMath::Cos(phi);
648  x[1]=radius*TMath::Sin(phi);
649  for (Int_t iz=1;iz<=nz;++iz) {
650  x[2]=h->GetXaxis()->GetBinCenter(iz);
651  Int_t roc=x[2]>0.?0:18; // FIXME
652  GetCorrection(x,roc,dx);
653  Float_t r0=TMath::Sqrt((x[0] )*(x[0] )+(x[1] )*(x[1] ));
654  Float_t r1=TMath::Sqrt((x[0]+dx[0])*(x[0]+dx[0])+(x[1]+dx[1])*(x[1]+dx[1]));
655  h->SetBinContent(iz,ir,r1-r0);
656  }
657  }
658  return h;
659 
660 }
661 
662 TH2F* AliTPCCorrection::CreateHistoDRPhiinZR(Float_t phi,Int_t nz,Int_t nr) {
667 
668  TH2F *h=CreateTH2F("drphi_zr", TString::Format("%s: DRPhiinZR R=%2.2f", GetTitle(),phi).Data(),"z [cm]","r [cm]","drphi [cm]",
669  nz,-250.,250.,nr,85.,250.);
670  Float_t x[3],dx[3];
671  for (Int_t iz=1;iz<=nz;++iz) {
672  x[2]=h->GetXaxis()->GetBinCenter(iz);
673  Int_t roc=x[2]>0.?0:18; // FIXME
674  for (Int_t ir=1;ir<=nr;++ir) {
675  Float_t radius=h->GetYaxis()->GetBinCenter(ir);
676  x[0]=radius*TMath::Cos(phi);
677  x[1]=radius*TMath::Sin(phi);
678  GetCorrection(x,roc,dx);
679  Float_t r0=TMath::Sqrt((x[0] )*(x[0] )+(x[1] )*(x[1] ));
680  Float_t phi0=TMath::ATan2(x[1] ,x[0] );
681  Float_t phi1=TMath::ATan2(x[1]+dx[1],x[0]+dx[0]);
682 
683  Float_t dphi=phi1-phi0;
684  if (dphi<TMath::Pi()) dphi+=TMath::TwoPi();
685  if (dphi>TMath::Pi()) dphi-=TMath::TwoPi();
686 
687  h->SetBinContent(iz,ir,r0*dphi);
688  }
689  }
690  return h;
691 }
692 
693 TH2F* AliTPCCorrection::CreateHistoDZinZR(Float_t phi,Int_t nz,Int_t nr) {
698 
699  TH2F *h=CreateTH2F("dz_zr",TString::Format("%s: DZinZR Z=%2.0f", GetTitle(),phi).Data(),"z [cm]","r [cm]","dz [cm]",
700  nz,-250.,250.,nr,85.,250.);
701  Float_t x[3],dx[3];
702  for (Int_t ir=1;ir<=nr;++ir) {
703  Float_t radius=h->GetYaxis()->GetBinCenter(ir);
704  x[0]=radius*TMath::Cos(phi);
705  x[1]=radius*TMath::Sin(phi);
706  for (Int_t iz=1;iz<=nz;++iz) {
707  x[2]=h->GetXaxis()->GetBinCenter(iz);
708  Int_t roc=x[2]>0.?0:18; // FIXME
709  GetCorrection(x,roc,dx);
710  h->SetBinContent(iz,ir,dx[2]);
711  }
712  }
713  return h;
714 
715 }
716 
717 
718 TH2F* AliTPCCorrection::CreateTH2F(const char *name,const char *title,
719  const char *xlabel,const char *ylabel,const char *zlabel,
720  Int_t nbinsx,Double_t xlow,Double_t xup,
721  Int_t nbinsy,Double_t ylow,Double_t yup) {
723 
724  TString hname=name;
725  Int_t i=0;
726  if (gDirectory) {
727  while (gDirectory->FindObject(hname.Data())) {
728  hname =name;
729  hname+="_";
730  hname+=i;
731  ++i;
732  }
733  }
734  TH2F *h=new TH2F(hname.Data(),title,
735  nbinsx,xlow,xup,
736  nbinsy,ylow,yup);
737  h->GetXaxis()->SetTitle(xlabel);
738  h->GetYaxis()->SetTitle(ylabel);
739  h->GetZaxis()->SetTitle(zlabel);
740  h->SetStats(0);
741  return h;
742 }
743 
744 // Simple Interpolation functions: e.g. with bi(tri)cubic interpolations (not yet in TH2 and TH3)
745 
746 void AliTPCCorrection::Interpolate2DEdistortion( Int_t order, Double_t r, Double_t z,
747  const Double_t er[kNZ][kNR], Double_t &erValue ) {
749 
750  Double_t saveEr[5] = {0,0,0,0,0};
751 
752  Search( kNZ, fgkZList, z, fJLow ) ;
753  Search( kNR, fgkRList, r, fKLow ) ;
754  if ( fJLow < 0 ) fJLow = 0 ; // check if out of range
755  if ( fKLow < 0 ) fKLow = 0 ;
756  if ( fJLow + order >= kNZ - 1 ) fJLow = kNZ - 1 - order ;
757  if ( fKLow + order >= kNR - 1 ) fKLow = kNR - 1 - order ;
758 
759  for ( Int_t j = fJLow ; j < fJLow + order + 1 ; j++ ) {
760  saveEr[j-fJLow] = Interpolate( &fgkRList[fKLow], &er[j][fKLow], order, r ) ;
761  }
762  erValue = Interpolate( &fgkZList[fJLow], saveEr, order, z ) ;
763 
764 }
765 
766 void AliTPCCorrection::Interpolate3DEdistortion( Int_t order, Double_t r, Float_t phi, Double_t z,
767  const Double_t er[kNZ][kNPhi][kNR], const Double_t ephi[kNZ][kNPhi][kNR], const Double_t ez[kNZ][kNPhi][kNR],
768  Double_t &erValue, Double_t &ephiValue, Double_t &ezValue) {
770 
771  Double_t saveEr[5]= {0,0,0,0,0};
772  Double_t savedEr[5]= {0,0,0,0,0} ;
773 
774  Double_t saveEphi[5]= {0,0,0,0,0};
775  Double_t savedEphi[5]= {0,0,0,0,0} ;
776 
777  Double_t saveEz[5]= {0,0,0,0,0};
778  Double_t savedEz[5]= {0,0,0,0,0} ;
779 
780  Search( kNZ, fgkZList, z, fILow ) ;
781  Search( kNPhi, fgkPhiList, z, fJLow ) ;
782  Search( kNR, fgkRList, r, fKLow ) ;
783 
784  if ( fILow < 0 ) fILow = 0 ; // check if out of range
785  if ( fJLow < 0 ) fJLow = 0 ;
786  if ( fKLow < 0 ) fKLow = 0 ;
787 
788  if ( fILow + order >= kNZ - 1 ) fILow = kNZ - 1 - order ;
789  if ( fJLow + order >= kNPhi - 1 ) fJLow = kNPhi - 1 - order ;
790  if ( fKLow + order >= kNR - 1 ) fKLow = kNR - 1 - order ;
791 
792  for ( Int_t i = fILow ; i < fILow + order + 1 ; i++ ) {
793  for ( Int_t j = fJLow ; j < fJLow + order + 1 ; j++ ) {
794  saveEr[j-fJLow] = Interpolate( &fgkRList[fKLow], &er[i][j][fKLow], order, r ) ;
795  saveEphi[j-fJLow] = Interpolate( &fgkRList[fKLow], &ephi[i][j][fKLow], order, r ) ;
796  saveEz[j-fJLow] = Interpolate( &fgkRList[fKLow], &ez[i][j][fKLow], order, r ) ;
797  }
798  savedEr[i-fILow] = Interpolate( &fgkPhiList[fJLow], saveEr, order, phi ) ;
799  savedEphi[i-fILow] = Interpolate( &fgkPhiList[fJLow], saveEphi, order, phi ) ;
800  savedEz[i-fILow] = Interpolate( &fgkPhiList[fJLow], saveEz, order, phi ) ;
801  }
802  erValue = Interpolate( &fgkZList[fILow], savedEr, order, z ) ;
803  ephiValue = Interpolate( &fgkZList[fILow], savedEphi, order, z ) ;
804  ezValue = Interpolate( &fgkZList[fILow], savedEz, order, z ) ;
805 
806 }
807 
808 Double_t AliTPCCorrection::Interpolate2DTable( Int_t order, Double_t x, Double_t y,
809  Int_t nx, Int_t ny, const Double_t xv[], const Double_t yv[],
810  const TMatrixD &array ) {
812 
813  static Int_t jlow = 0, klow = 0 ;
814  Double_t saveArray[5] = {0,0,0,0,0} ;
815 
816  Search( nx, xv, x, jlow ) ;
817  Search( ny, yv, y, klow ) ;
818  if ( jlow < 0 ) jlow = 0 ; // check if out of range
819  if ( klow < 0 ) klow = 0 ;
820  if ( jlow + order >= nx - 1 ) jlow = nx - 1 - order ;
821  if ( klow + order >= ny - 1 ) klow = ny - 1 - order ;
822 
823  for ( Int_t j = jlow ; j < jlow + order + 1 ; j++ )
824  {
825  Double_t *ajkl = &((TMatrixD&)array)(j,klow);
826  saveArray[j-jlow] = Interpolate( &yv[klow], ajkl , order, y ) ;
827  }
828 
829  return( Interpolate( &xv[jlow], saveArray, order, x ) ) ;
830 
831 }
832 
833 Double_t AliTPCCorrection::Interpolate3DTable( Int_t order, Double_t x, Double_t y, Double_t z,
834  Int_t nx, Int_t ny, Int_t nz,
835  const Double_t xv[], const Double_t yv[], const Double_t zv[],
836  TMatrixD **arrayofArrays ) {
838 
839  static Int_t ilow = 0, jlow = 0, klow = 0 ;
840  Double_t saveArray[5]= {0,0,0,0,0};
841  Double_t savedArray[5]= {0,0,0,0,0} ;
842 
843  Search( nx, xv, x, ilow ) ;
844  Search( ny, yv, y, jlow ) ;
845  Search( nz, zv, z, klow ) ;
846 
847  if ( ilow < 0 ) ilow = 0 ; // check if out of range
848  if ( jlow < 0 ) jlow = 0 ;
849  if ( klow < 0 ) klow = 0 ;
850 
851  if ( ilow + order >= nx - 1 ) ilow = nx - 1 - order ;
852  if ( jlow + order >= ny - 1 ) jlow = ny - 1 - order ;
853  if ( klow + order >= nz - 1 ) klow = nz - 1 - order ;
854 
855  for ( Int_t k = klow ; k < klow + order + 1 ; k++ )
856  {
857  TMatrixD &table = *arrayofArrays[k] ;
858  for ( Int_t i = ilow ; i < ilow + order + 1 ; i++ )
859  {
860  saveArray[i-ilow] = Interpolate( &yv[jlow], &table(i,jlow), order, y ) ;
861  }
862  savedArray[k-klow] = Interpolate( &xv[ilow], saveArray, order, x ) ;
863  }
864  return( Interpolate( &zv[klow], savedArray, order, z ) ) ;
865 
866 }
867 
868 Double_t AliTPCCorrection::Interpolate( const Double_t xArray[], const Double_t yArray[],
869  Int_t order, Double_t x ) {
871 
872  Double_t y ;
873  if ( order == 2 ) { // Quadratic Interpolation = 2
874  y = (x-xArray[1]) * (x-xArray[2]) * yArray[0] / ( (xArray[0]-xArray[1]) * (xArray[0]-xArray[2]) ) ;
875  y += (x-xArray[2]) * (x-xArray[0]) * yArray[1] / ( (xArray[1]-xArray[2]) * (xArray[1]-xArray[0]) ) ;
876  y += (x-xArray[0]) * (x-xArray[1]) * yArray[2] / ( (xArray[2]-xArray[0]) * (xArray[2]-xArray[1]) ) ;
877  } else { // Linear Interpolation = 1
878  y = yArray[0] + ( yArray[1]-yArray[0] ) * ( x-xArray[0] ) / ( xArray[1] - xArray[0] ) ;
879  }
880 
881  return (y);
882 
883 }
884 
885 Float_t AliTPCCorrection::Interpolate2DTable( Int_t order, Double_t x, Double_t y,
886  Int_t nx, Int_t ny, const Double_t xv[], const Double_t yv[],
887  const TMatrixF &array ) {
890 
891  static Int_t jlow = 0, klow = 0 ;
892  Float_t saveArray[5] = {0.,0.,0.,0.,0.} ;
893 
894  Search( nx, xv, x, jlow ) ;
895  Search( ny, yv, y, klow ) ;
896  if ( jlow < 0 ) jlow = 0 ; // check if out of range
897  if ( klow < 0 ) klow = 0 ;
898  if ( jlow + order >= nx - 1 ) jlow = nx - 1 - order ;
899  if ( klow + order >= ny - 1 ) klow = ny - 1 - order ;
900 
901  for ( Int_t j = jlow ; j < jlow + order + 1 ; j++ )
902  {
903  Float_t *ajkl = &((TMatrixF&)array)(j,klow);
904  saveArray[j-jlow] = Interpolate( &yv[klow], ajkl , order, y ) ;
905  }
906 
907  return( Interpolate( &xv[jlow], saveArray, order, x ) ) ;
908 
909 }
910 
911 Float_t AliTPCCorrection::Interpolate3DTable( Int_t order, Double_t x, Double_t y, Double_t z,
912  Int_t nx, Int_t ny, Int_t nz,
913  const Double_t xv[], const Double_t yv[], const Double_t zv[],
914  TMatrixF **arrayofArrays ) {
917 
918  static Int_t ilow = 0, jlow = 0, klow = 0 ;
919  Float_t saveArray[5]= {0.,0.,0.,0.,0.};
920  Float_t savedArray[5]= {0.,0.,0.,0.,0.} ;
921 
922  Search( nx, xv, x, ilow ) ;
923  Search( ny, yv, y, jlow ) ;
924  Search( nz, zv, z, klow ) ;
925 
926  if ( ilow < 0 ) ilow = 0 ; // check if out of range
927  if ( jlow < 0 ) jlow = 0 ;
928  if ( klow < 0 ) klow = 0 ;
929 
930  if ( ilow + order >= nx - 1 ) ilow = nx - 1 - order ;
931  if ( jlow + order >= ny - 1 ) jlow = ny - 1 - order ;
932  if ( klow + order >= nz - 1 ) klow = nz - 1 - order ;
933 
934  for ( Int_t k = klow ; k < klow + order + 1 ; k++ )
935  {
936  TMatrixF &table = *arrayofArrays[k] ;
937  for ( Int_t i = ilow ; i < ilow + order + 1 ; i++ )
938  {
939  saveArray[i-ilow] = Interpolate( &yv[jlow], &table(i,jlow), order, y ) ;
940  }
941  savedArray[k-klow] = Interpolate( &xv[ilow], saveArray, order, x ) ;
942  }
943  return( Interpolate( &zv[klow], savedArray, order, z ) ) ;
944 
945 }
946 Float_t AliTPCCorrection::Interpolate( const Double_t xArray[], const Float_t yArray[],
947  Int_t order, Double_t x ) {
950 
951  Float_t y ;
952  if ( order == 2 ) { // Quadratic Interpolation = 2
953  y = (x-xArray[1]) * (x-xArray[2]) * yArray[0] / ( (xArray[0]-xArray[1]) * (xArray[0]-xArray[2]) ) ;
954  y += (x-xArray[2]) * (x-xArray[0]) * yArray[1] / ( (xArray[1]-xArray[2]) * (xArray[1]-xArray[0]) ) ;
955  y += (x-xArray[0]) * (x-xArray[1]) * yArray[2] / ( (xArray[2]-xArray[0]) * (xArray[2]-xArray[1]) ) ;
956  } else { // Linear Interpolation = 1
957  y = yArray[0] + ( yArray[1]-yArray[0] ) * ( x-xArray[0] ) / ( xArray[1] - xArray[0] ) ;
958  }
959 
960  return (y);
961 
962 }
963 
964 
965 
966 void AliTPCCorrection::Search( Int_t n, const Double_t xArray[], Double_t x, Int_t &low ) {
968 
969  Long_t middle, high ;
970  Int_t ascend = 0, increment = 1 ;
971 
972  if ( xArray[n-1] >= xArray[0] ) ascend = 1 ; // Ascending ordered table if true
973 
974  if ( low < 0 || low > n-1 ) {
975  low = -1 ; high = n ;
976  } else { // Ordered Search phase
977  if ( (Int_t)( x >= xArray[low] ) == ascend ) {
978  if ( low == n-1 ) return ;
979  high = low + 1 ;
980  while ( (Int_t)( x >= xArray[high] ) == ascend ) {
981  low = high ;
982  increment *= 2 ;
983  high = low + increment ;
984  if ( high > n-1 ) { high = n ; break ; }
985  }
986  } else {
987  if ( low == 0 ) { low = -1 ; return ; }
988  high = low - 1 ;
989  while ( (Int_t)( x < xArray[low] ) == ascend ) {
990  high = low ;
991  increment *= 2 ;
992  if ( increment >= high ) { low = -1 ; break ; }
993  else low = high - increment ;
994  }
995  }
996  }
997 
998  while ( (high-low) != 1 ) { // Binary Search Phase
999  middle = ( high + low ) / 2 ;
1000  if ( (Int_t)( x >= xArray[middle] ) == ascend )
1001  low = middle ;
1002  else
1003  high = middle ;
1004  }
1005 
1006  if ( x == xArray[n-1] ) low = n-2 ;
1007  if ( x == xArray[0] ) low = 0 ;
1008 
1009 }
1010 
1014 
1015  AliTPCROC * roc = AliTPCROC::Instance();
1016  const Double_t rLow = TMath::Floor(roc->GetPadRowRadii(0,0))-1; // first padRow plus some margin
1017 
1018  // fulcrums in R
1019  fgkRList[0] = rLow;
1020  for (Int_t i = 1; i<kNR; i++) {
1021  fgkRList[i] = fgkRList[i-1] + 3.5; // 3.5 cm spacing
1022  if (fgkRList[i]<90 ||fgkRList[i]>245)
1023  fgkRList[i] = fgkRList[i-1] + 0.5; // 0.5 cm spacing
1024  else if (fgkRList[i]<100 || fgkRList[i]>235)
1025  fgkRList[i] = fgkRList[i-1] + 1.5; // 1.5 cm spacing
1026  else if (fgkRList[i]<120 || fgkRList[i]>225)
1027  fgkRList[i] = fgkRList[i-1] + 2.5; // 2.5 cm spacing
1028  }
1029 
1030  // fulcrums in Z
1031  fgkZList[0] = -249.5;
1032  fgkZList[kNZ-1] = 249.5;
1033  for (Int_t j = 1; j<kNZ/2; j++) {
1034  fgkZList[j] = fgkZList[j-1];
1035  if (TMath::Abs(fgkZList[j])< 0.15)
1036  fgkZList[j] = fgkZList[j-1] + 0.09; // 0.09 cm spacing
1037  else if(TMath::Abs(fgkZList[j])< 0.6)
1038  fgkZList[j] = fgkZList[j-1] + 0.4; // 0.4 cm spacing
1039  else if (TMath::Abs(fgkZList[j])< 2.5 || TMath::Abs(fgkZList[j])>248)
1040  fgkZList[j] = fgkZList[j-1] + 0.5; // 0.5 cm spacing
1041  else if (TMath::Abs(fgkZList[j])<10 || TMath::Abs(fgkZList[j])>235)
1042  fgkZList[j] = fgkZList[j-1] + 1.5; // 1.5 cm spacing
1043  else if (TMath::Abs(fgkZList[j])<25 || TMath::Abs(fgkZList[j])>225)
1044  fgkZList[j] = fgkZList[j-1] + 2.5; // 2.5 cm spacing
1045  else
1046  fgkZList[j] = fgkZList[j-1] + 4; // 4 cm spacing
1047 
1048  fgkZList[kNZ-j-1] = -fgkZList[j];
1049  }
1050 
1051  // fulcrums in phi
1052  for (Int_t k = 0; k<kNPhi; k++)
1053  fgkPhiList[k] = TMath::TwoPi()*k/(kNPhi-1);
1054 
1055 
1056 }
1057 
1058 
1059 void AliTPCCorrection::PoissonRelaxation2D(TMatrixD &arrayV, TMatrixD &chargeDensity,
1060  TMatrixD &arrayErOverEz, TMatrixD &arrayDeltaEz,
1061  Int_t rows, Int_t columns, Int_t iterations,
1062  Bool_t rocDisplacement ) {
1084 
1085  Double_t ezField = (fgkCathodeV-fgkGG)/fgkTPCZ0; // = ALICE Electric Field (V/cm) Magnitude ~ -400 V/cm;
1086 
1087  const Float_t gridSizeR = (fgkOFCRadius-fgkIFCRadius) / (rows-1) ;
1088  const Float_t gridSizeZ = fgkTPCZ0 / (columns-1) ;
1089  const Float_t ratio = gridSizeR*gridSizeR / (gridSizeZ*gridSizeZ) ;
1090 
1091  TMatrixD arrayEr(rows,columns) ;
1092  TMatrixD arrayEz(rows,columns) ;
1093 
1094  //Check that number of rows and columns is suitable for a binary expansion
1095 
1096  if ( !IsPowerOfTwo(rows-1) ) {
1097  AliError("PoissonRelaxation - Error in the number of rows. Must be 2**M - 1");
1098  return;
1099  }
1100  if ( !IsPowerOfTwo(columns-1) ) {
1101  AliError("PoissonRelaxation - Error in the number of columns. Must be 2**N - 1");
1102  return;
1103  }
1104 
1105  // Solve Poisson's equation in cylindrical coordinates by relaxation technique
1106  // Allow for different size grid spacing in R and Z directions
1107  // Use a binary expansion of the size of the matrix to speed up the solution of the problem
1108 
1109  Int_t iOne = (rows-1)/4 ;
1110  Int_t jOne = (columns-1)/4 ;
1111  // Solve for N in 2**N, add one.
1112  Int_t loops = 1 + (int) ( 0.5 + TMath::Log2( (double) TMath::Max(iOne,jOne) ) ) ;
1113 
1114  for ( Int_t count = 0 ; count < loops ; count++ ) {
1115  // Loop while the matrix expands & the resolution increases.
1116 
1117  Float_t tempGridSizeR = gridSizeR * iOne ;
1118  Float_t tempRatio = ratio * iOne * iOne / ( jOne * jOne ) ;
1119  Float_t tempFourth = 1.0 / (2.0 + 2.0*tempRatio) ;
1120 
1121  // Do this the standard C++ way to avoid gcc extensions for Float_t coef1[rows]
1122  std::vector<float> coef1(rows) ;
1123  std::vector<float> coef2(rows) ;
1124 
1125  for ( Int_t i = iOne ; i < rows-1 ; i+=iOne ) {
1126  Float_t radius = fgkIFCRadius + i*gridSizeR ;
1127  coef1[i] = 1.0 + tempGridSizeR/(2*radius);
1128  coef2[i] = 1.0 - tempGridSizeR/(2*radius);
1129  }
1130 
1131  TMatrixD sumChargeDensity(rows,columns) ;
1132 
1133  for ( Int_t i = iOne ; i < rows-1 ; i += iOne ) {
1134  Float_t radius = fgkIFCRadius + iOne*gridSizeR ;
1135  for ( Int_t j = jOne ; j < columns-1 ; j += jOne ) {
1136  if ( iOne == 1 && jOne == 1 ) sumChargeDensity(i,j) = chargeDensity(i,j) ;
1137  else {
1138  // Add up all enclosed charge density contributions within 1/2 unit in all directions
1139  Float_t weight = 0.0 ;
1140  Float_t sum = 0.0 ;
1141  sumChargeDensity(i,j) = 0.0 ;
1142  for ( Int_t ii = i-iOne/2 ; ii <= i+iOne/2 ; ii++ ) {
1143  for ( Int_t jj = j-jOne/2 ; jj <= j+jOne/2 ; jj++ ) {
1144  if ( ii == i-iOne/2 || ii == i+iOne/2 || jj == j-jOne/2 || jj == j+jOne/2 ) weight = 0.5 ;
1145  else
1146  weight = 1.0 ;
1147  // Note that this is cylindrical geometry
1148  sumChargeDensity(i,j) += chargeDensity(ii,jj)*weight*radius ;
1149  sum += weight*radius ;
1150  }
1151  }
1152  sumChargeDensity(i,j) /= sum ;
1153  }
1154  sumChargeDensity(i,j) *= tempGridSizeR*tempGridSizeR; // just saving a step later on
1155  }
1156  }
1157 
1158  for ( Int_t k = 1 ; k <= iterations; k++ ) {
1159  // Solve Poisson's Equation
1160  // Over-relaxation index, must be >= 1 but < 2. Arrange for it to evolve from 2 => 1
1161  // as interations increase.
1162  Float_t overRelax = 1.0 + TMath::Sqrt( TMath::Cos( (k*TMath::PiOver2())/iterations ) ) ;
1163  Float_t overRelaxM1 = overRelax - 1.0 ;
1164  Float_t overRelaxtempFourth, overRelaxcoef5 ;
1165  overRelaxtempFourth = overRelax * tempFourth ;
1166  overRelaxcoef5 = overRelaxM1 / overRelaxtempFourth ;
1167 
1168  for ( Int_t i = iOne ; i < rows-1 ; i += iOne ) {
1169  for ( Int_t j = jOne ; j < columns-1 ; j += jOne ) {
1170 
1171  arrayV(i,j) = ( coef2[i] * arrayV(i-iOne,j)
1172  + tempRatio * ( arrayV(i,j-jOne) + arrayV(i,j+jOne) )
1173  - overRelaxcoef5 * arrayV(i,j)
1174  + coef1[i] * arrayV(i+iOne,j)
1175  + sumChargeDensity(i,j)
1176  ) * overRelaxtempFourth;
1177  }
1178  }
1179 
1180  if ( k == iterations ) {
1181  // After full solution is achieved, copy low resolution solution into higher res array
1182  for ( Int_t i = iOne ; i < rows-1 ; i += iOne ) {
1183  for ( Int_t j = jOne ; j < columns-1 ; j += jOne ) {
1184 
1185  if ( iOne > 1 ) {
1186  arrayV(i+iOne/2,j) = ( arrayV(i+iOne,j) + arrayV(i,j) ) / 2 ;
1187  if ( i == iOne ) arrayV(i-iOne/2,j) = ( arrayV(0,j) + arrayV(iOne,j) ) / 2 ;
1188  }
1189  if ( jOne > 1 ) {
1190  arrayV(i,j+jOne/2) = ( arrayV(i,j+jOne) + arrayV(i,j) ) / 2 ;
1191  if ( j == jOne ) arrayV(i,j-jOne/2) = ( arrayV(i,0) + arrayV(i,jOne) ) / 2 ;
1192  }
1193  if ( iOne > 1 && jOne > 1 ) {
1194  arrayV(i+iOne/2,j+jOne/2) = ( arrayV(i+iOne,j+jOne) + arrayV(i,j) ) / 2 ;
1195  if ( i == iOne ) arrayV(i-iOne/2,j-jOne/2) = ( arrayV(0,j-jOne) + arrayV(iOne,j) ) / 2 ;
1196  if ( j == jOne ) arrayV(i-iOne/2,j-jOne/2) = ( arrayV(i-iOne,0) + arrayV(i,jOne) ) / 2 ;
1197  // Note that this leaves a point at the upper left and lower right corners uninitialized.
1198  // -> Not a big deal.
1199  }
1200 
1201  }
1202  }
1203  }
1204 
1205  }
1206 
1207  iOne = iOne / 2 ; if ( iOne < 1 ) iOne = 1 ;
1208  jOne = jOne / 2 ; if ( jOne < 1 ) jOne = 1 ;
1209 
1210  sumChargeDensity.Clear();
1211  }
1212 
1213  // Differentiate V(r) and solve for E(r) using special equations for the first and last rows
1214  for ( Int_t j = 0 ; j < columns ; j++ ) {
1215  for ( Int_t i = 1 ; i < rows-1 ; i++ ) arrayEr(i,j) = -1 * ( arrayV(i+1,j) - arrayV(i-1,j) ) / (2*gridSizeR) ;
1216  arrayEr(0,j) = -1 * ( -0.5*arrayV(2,j) + 2.0*arrayV(1,j) - 1.5*arrayV(0,j) ) / gridSizeR ;
1217  arrayEr(rows-1,j) = -1 * ( 1.5*arrayV(rows-1,j) - 2.0*arrayV(rows-2,j) + 0.5*arrayV(rows-3,j) ) / gridSizeR ;
1218  }
1219 
1220  // Differentiate V(z) and solve for E(z) using special equations for the first and last columns
1221  for ( Int_t i = 0 ; i < rows ; i++) {
1222  for ( Int_t j = 1 ; j < columns-1 ; j++ ) arrayEz(i,j) = -1 * ( arrayV(i,j+1) - arrayV(i,j-1) ) / (2*gridSizeZ) ;
1223  arrayEz(i,0) = -1 * ( -0.5*arrayV(i,2) + 2.0*arrayV(i,1) - 1.5*arrayV(i,0) ) / gridSizeZ ;
1224  arrayEz(i,columns-1) = -1 * ( 1.5*arrayV(i,columns-1) - 2.0*arrayV(i,columns-2) + 0.5*arrayV(i,columns-3) ) / gridSizeZ ;
1225  }
1226 
1227  for ( Int_t i = 0 ; i < rows ; i++) {
1228  // Note: go back and compare to old version of this code. See notes below.
1229  // JT Test ... attempt to divide by real Ez not Ez to first order
1230  for ( Int_t j = 0 ; j < columns ; j++ ) {
1231  arrayEz(i,j) += ezField;
1232  // This adds back the overall Z gradient of the field (main E field component)
1233  }
1234  // Warning: (-=) assumes you are using an error potetial without the overall Field included
1235  }
1236 
1237  // Integrate Er/Ez from Z to zero
1238  for ( Int_t j = 0 ; j < columns ; j++ ) {
1239  for ( Int_t i = 0 ; i < rows ; i++ ) {
1240 
1241  Int_t index = 1 ; // Simpsons rule if N=odd. If N!=odd then add extra point by trapezoidal rule.
1242  arrayErOverEz(i,j) = 0.0 ;
1243  arrayDeltaEz(i,j) = 0.0 ;
1244 
1245  for ( Int_t k = j ; k < columns ; k++ ) {
1246  arrayErOverEz(i,j) += index*(gridSizeZ/3.0)*arrayEr(i,k)/arrayEz(i,k) ;
1247  arrayDeltaEz(i,j) += index*(gridSizeZ/3.0)*(arrayEz(i,k)-ezField) ;
1248  if ( index != 4 ) index = 4; else index = 2 ;
1249  }
1250  if ( index == 4 ) {
1251  arrayErOverEz(i,j) -= (gridSizeZ/3.0)*arrayEr(i,columns-1)/arrayEz(i,columns-1) ;
1252  arrayDeltaEz(i,j) -= (gridSizeZ/3.0)*(arrayEz(i,columns-1)-ezField) ;
1253  }
1254  if ( index == 2 ) {
1255  arrayErOverEz(i,j) += (gridSizeZ/3.0) * ( 0.5*arrayEr(i,columns-2)/arrayEz(i,columns-2)
1256  -2.5*arrayEr(i,columns-1)/arrayEz(i,columns-1));
1257  arrayDeltaEz(i,j) += (gridSizeZ/3.0) * ( 0.5*(arrayEz(i,columns-2)-ezField)
1258  -2.5*(arrayEz(i,columns-1)-ezField));
1259  }
1260  if ( j == columns-2 ) {
1261  arrayErOverEz(i,j) = (gridSizeZ/3.0) * ( 1.5*arrayEr(i,columns-2)/arrayEz(i,columns-2)
1262  +1.5*arrayEr(i,columns-1)/arrayEz(i,columns-1) ) ;
1263  arrayDeltaEz(i,j) = (gridSizeZ/3.0) * ( 1.5*(arrayEz(i,columns-2)-ezField)
1264  +1.5*(arrayEz(i,columns-1)-ezField) ) ;
1265  }
1266  if ( j == columns-1 ) {
1267  arrayErOverEz(i,j) = 0.0 ;
1268  arrayDeltaEz(i,j) = 0.0 ;
1269  }
1270  }
1271  }
1272 
1273  // calculate z distortion from the integrated Delta Ez residuals
1274  // and include the aquivalence (Volt to cm) of the ROC shift !!
1275 
1276  for ( Int_t j = 0 ; j < columns ; j++ ) {
1277  for ( Int_t i = 0 ; i < rows ; i++ ) {
1278 
1279  // Scale the Ez distortions with the drift velocity pertubation -> delivers cm
1280  arrayDeltaEz(i,j) = arrayDeltaEz(i,j)*fgkdvdE;
1281 
1282  // ROC Potential in cm aquivalent
1283  Double_t dzROCShift = arrayV(i, columns -1)/ezField;
1284  if ( rocDisplacement ) arrayDeltaEz(i,j) = arrayDeltaEz(i,j) + dzROCShift; // add the ROC misaligment
1285 
1286  }
1287  }
1288 
1289  arrayEr.Clear();
1290  arrayEz.Clear();
1291 
1292 }
1293 
1294 void AliTPCCorrection::PoissonRelaxation3D( TMatrixD**arrayofArrayV, TMatrixD**arrayofChargeDensities,
1295  TMatrixD**arrayofEroverEz, TMatrixD**arrayofEPhioverEz, TMatrixD**arrayofDeltaEz,
1296  Int_t rows, Int_t columns, Int_t phislices,
1297  Float_t deltaphi, Int_t iterations, Int_t symmetry,
1298  Bool_t rocDisplacement, IntegrationType integrationType/*=kIntegral*/ ) {
1314 
1315  const Double_t ezField = (fgkCathodeV-fgkGG)/fgkTPCZ0; // = ALICE Electric Field (V/cm) Magnitude ~ -400 V/cm;
1316 
1317  const Float_t gridSizeR = (fgkOFCRadius-fgkIFCRadius) / (rows-1) ;
1318  const Float_t gridSizePhi = deltaphi ;
1319  const Float_t gridSizeZ = fgkTPCZ0 / (columns-1) ;
1320  const Float_t ratioPhi = gridSizeR*gridSizeR / (gridSizePhi*gridSizePhi) ;
1321  const Float_t ratioZ = gridSizeR*gridSizeR / (gridSizeZ*gridSizeZ) ;
1322 
1323  TMatrixD arrayE(rows,columns) ;
1324 
1325  // set internal representation
1326  fIntegrationType = integrationType;
1327 
1328  // Check that the number of rows and columns is suitable for a binary expansion
1329  if ( !IsPowerOfTwo((rows-1)) ) {
1330  AliError("Poisson3DRelaxation - Error in the number of rows. Must be 2**M - 1");
1331  return; }
1332  if ( !IsPowerOfTwo((columns-1)) ) {
1333  AliError("Poisson3DRelaxation - Error in the number of columns. Must be 2**N - 1");
1334  return; }
1335  if ( phislices <= 3 ) {
1336  AliError("Poisson3DRelaxation - Error in the number of phislices. Must be larger than 3");
1337  return; }
1338  if ( phislices > 1000 ) {
1339  AliError("Poisson3D phislices > 1000 is not allowed (nor wise) ");
1340  return; }
1341 
1342  // Solve Poisson's equation in cylindrical coordinates by relaxation technique
1343  // Allow for different size grid spacing in R and Z directions
1344  // Use a binary expansion of the matrix to speed up the solution of the problem
1345 
1346  Int_t loops, mplus, mminus, signplus, signminus ;
1347  Int_t ione = (rows-1)/4 ;
1348  Int_t jone = (columns-1)/4 ;
1349  loops = TMath::Max(ione, jone) ; // Calculate the number of loops for the binary expansion
1350  loops = 1 + (int) ( 0.5 + TMath::Log2((double)loops) ) ; // Solve for N in 2**N
1351 
1352  TMatrixD* arrayofSumChargeDensities[1000] ; // Create temporary arrays to store low resolution charge arrays
1353 
1354  for ( Int_t i = 0 ; i < phislices ; i++ ) { arrayofSumChargeDensities[i] = new TMatrixD(rows,columns) ; }
1355  AliSysInfo::AddStamp("3DInit", 10,0,0);
1356 
1357  for ( Int_t count = 0 ; count < loops ; count++ ) { // START the master loop and do the binary expansion
1358  AliSysInfo::AddStamp("3Diter", 20,count,0);
1359 
1360  Float_t tempgridSizeR = gridSizeR * ione ;
1361  Float_t tempratioPhi = ratioPhi * ione * ione ; // Used tobe divided by ( m_one * m_one ) when m_one was != 1
1362  Float_t tempratioZ = ratioZ * ione * ione / ( jone * jone ) ;
1363 
1364  std::vector<float> coef1(rows) ; // Do this the standard C++ way to avoid gcc extensions for Float_t coef1[rows]
1365  std::vector<float> coef2(rows) ; // Do this the standard C++ way to avoid gcc extensions for Float_t coef1[rows]
1366  std::vector<float> coef3(rows) ; // Do this the standard C++ way to avoid gcc extensions for Float_t coef1[rows]
1367  std::vector<float> coef4(rows) ; // Do this the standard C++ way to avoid gcc extensions for Float_t coef1[rows]
1368 
1369  for ( Int_t i = ione ; i < rows-1 ; i+=ione ) {
1370  Float_t radius = fgkIFCRadius + i*gridSizeR ;
1371  coef1[i] = 1.0 + tempgridSizeR/(2*radius);
1372  coef2[i] = 1.0 - tempgridSizeR/(2*radius);
1373  coef3[i] = tempratioPhi/(radius*radius);
1374  coef4[i] = 0.5 / (1.0 + tempratioZ + coef3[i]);
1375  }
1376 
1377  for ( Int_t m = 0 ; m < phislices ; m++ ) {
1378  TMatrixD &chargeDensity = *arrayofChargeDensities[m] ;
1379  TMatrixD &sumChargeDensity = *arrayofSumChargeDensities[m] ;
1380  for ( Int_t i = ione ; i < rows-1 ; i += ione ) {
1381  Float_t radius = fgkIFCRadius + i*gridSizeR ;
1382  for ( Int_t j = jone ; j < columns-1 ; j += jone ) {
1383  if ( ione == 1 && jone == 1 ) sumChargeDensity(i,j) = chargeDensity(i,j) ;
1384  else { // Add up all enclosed charge density contributions within 1/2 unit in all directions
1385  Float_t weight = 0.0 ;
1386  Float_t sum = 0.0 ;
1387  sumChargeDensity(i,j) = 0.0 ;
1388  for ( Int_t ii = i-ione/2 ; ii <= i+ione/2 ; ii++ ) {
1389  for ( Int_t jj = j-jone/2 ; jj <= j+jone/2 ; jj++ ) {
1390  if ( ii == i-ione/2 || ii == i+ione/2 || jj == j-jone/2 || jj == j+jone/2 ) weight = 0.5 ;
1391  else
1392  weight = 1.0 ;
1393  sumChargeDensity(i,j) += chargeDensity(ii,jj)*weight*radius ;
1394  sum += weight*radius ;
1395  }
1396  }
1397  sumChargeDensity(i,j) /= sum ;
1398  }
1399  sumChargeDensity(i,j) *= tempgridSizeR*tempgridSizeR; // just saving a step later on
1400  }
1401  }
1402  }
1403 
1404  for ( Int_t k = 1 ; k <= iterations; k++ ) {
1405 
1406  // over-relaxation index, >= 1 but < 2
1407  Float_t overRelax = 1.0 + TMath::Sqrt( TMath::Cos( (k*TMath::PiOver2())/iterations ) ) ;
1408  Float_t overRelaxM1 = overRelax - 1.0 ;
1409 
1410  std::vector<float> overRelaxcoef4(rows) ; // Do this the standard C++ way to avoid gcc extensions
1411  std::vector<float> overRelaxcoef5(rows) ; // Do this the standard C++ way to avoid gcc extensions
1412 
1413  for ( Int_t i = ione ; i < rows-1 ; i+=ione ) {
1414  overRelaxcoef4[i] = overRelax * coef4[i] ;
1415  overRelaxcoef5[i] = overRelaxM1 / overRelaxcoef4[i] ;
1416  }
1417 
1418  for ( Int_t m = 0 ; m < phislices ; m++ ) {
1419 
1420  mplus = m + 1; signplus = 1 ;
1421  mminus = m - 1 ; signminus = 1 ;
1422  if (symmetry==1) { // Reflection symmetry in phi (e.g. symmetry at sector boundaries, or half sectors, etc.)
1423  if ( mplus > phislices-1 ) mplus = phislices - 2 ;
1424  if ( mminus < 0 ) mminus = 1 ;
1425  }
1426  else if (symmetry==-1) { // Anti-symmetry in phi
1427  if ( mplus > phislices-1 ) { mplus = phislices - 2 ; signplus = -1 ; }
1428  if ( mminus < 0 ) { mminus = 1 ; signminus = -1 ; }
1429  }
1430  else { // No Symmetries in phi, no boundaries, the calculation is continuous across all phi
1431  if ( mplus > phislices-1 ) mplus = m + 1 - phislices ;
1432  if ( mminus < 0 ) mminus = m - 1 + phislices ;
1433  }
1434  TMatrixD& arrayV = *arrayofArrayV[m] ;
1435  TMatrixD& arrayVP = *arrayofArrayV[mplus] ;
1436  TMatrixD& arrayVM = *arrayofArrayV[mminus] ;
1437  TMatrixD& sumChargeDensity = *arrayofSumChargeDensities[m] ;
1438  Double_t *arrayVfast = arrayV.GetMatrixArray();
1439  Double_t *arrayVPfast = arrayVP.GetMatrixArray();
1440  Double_t *arrayVMfast = arrayVM.GetMatrixArray();
1441  Double_t *sumChargeDensityFast=sumChargeDensity.GetMatrixArray();
1442 
1443  if (0){
1444  // slow implementation
1445  for ( Int_t i = ione ; i < rows-1 ; i+=ione ) {
1446  for ( Int_t j = jone ; j < columns-1 ; j+=jone ) {
1447 
1448  arrayV(i,j) = ( coef2[i] * arrayV(i-ione,j)
1449  + tempratioZ * ( arrayV(i,j-jone) + arrayV(i,j+jone) )
1450  - overRelaxcoef5[i] * arrayV(i,j)
1451  + coef1[i] * arrayV(i+ione,j)
1452  + coef3[i] * ( signplus*arrayVP(i,j) + signminus*arrayVM(i,j) )
1453  + sumChargeDensity(i,j)
1454  ) * overRelaxcoef4[i] ;
1455  // Note: over-relax the solution at each step. This speeds up the convergance.
1456  }
1457  }
1458  }else{
1459  for ( Int_t i = ione ; i < rows-1 ; i+=ione ) {
1460  Double_t *arrayVfastI = &(arrayVfast[i*columns]);
1461  Double_t *arrayVPfastI = &(arrayVPfast[i*columns]);
1462  Double_t *arrayVMfastI = &(arrayVMfast[i*columns]);
1463  Double_t *sumChargeDensityFastI=&(sumChargeDensityFast[i*columns]);
1464  for ( Int_t j = jone ; j < columns-1 ; j+=jone ) {
1465  Double_t /*resSlow*/resFast;
1466 // resSlow = ( coef2[i] * arrayV(i-ione,j)
1467 // + tempratioZ * ( arrayV(i,j-jone) + arrayV(i,j+jone) )
1468 // - overRelaxcoef5[i] * arrayV(i,j)
1469 // + coef1[i] * arrayV(i+ione,j)
1470 // + coef3[i] * ( signplus*arrayVP(i,j) + signminus*arrayVM(i,j) )
1471 // + sumChargeDensity(i,j)
1472 // ) * overRelaxcoef4[i] ;
1473  resFast = ( coef2[i] * arrayVfastI[j-columns*ione]
1474  + tempratioZ * ( arrayVfastI[j-jone] + arrayVfastI[j+jone] )
1475  - overRelaxcoef5[i] * arrayVfastI[j]
1476  + coef1[i] * arrayVfastI[j+columns*ione]
1477  + coef3[i] * ( signplus* arrayVPfastI[j] + signminus*arrayVMfastI[j])
1478  + sumChargeDensityFastI[j]
1479  ) * overRelaxcoef4[i] ;
1480 // if (resSlow!=resFast){
1481 // printf("problem\t%d\t%d\t%f\t%f\t%f\n",i,j,resFast,resSlow,resFast-resSlow);
1482 // }
1483  arrayVfastI[j]=resFast;
1484  // Note: over-relax the solution at each step. This speeds up the convergance.
1485  }
1486  }
1487  }
1488 
1489  if ( k == iterations ) { // After full solution is achieved, copy low resolution solution into higher res array
1490  for ( Int_t i = ione ; i < rows-1 ; i+=ione ) {
1491  for ( Int_t j = jone ; j < columns-1 ; j+=jone ) {
1492 
1493  if ( ione > 1 ) {
1494  arrayV(i+ione/2,j) = ( arrayV(i+ione,j) + arrayV(i,j) ) / 2 ;
1495  if ( i == ione ) arrayV(i-ione/2,j) = ( arrayV(0,j) + arrayV(ione,j) ) / 2 ;
1496  }
1497  if ( jone > 1 ) {
1498  arrayV(i,j+jone/2) = ( arrayV(i,j+jone) + arrayV(i,j) ) / 2 ;
1499  if ( j == jone ) arrayV(i,j-jone/2) = ( arrayV(i,0) + arrayV(i,jone) ) / 2 ;
1500  }
1501  if ( ione > 1 && jone > 1 ) {
1502  arrayV(i+ione/2,j+jone/2) = ( arrayV(i+ione,j+jone) + arrayV(i,j) ) / 2 ;
1503  if ( i == ione ) arrayV(i-ione/2,j-jone/2) = ( arrayV(0,j-jone) + arrayV(ione,j) ) / 2 ;
1504  if ( j == jone ) arrayV(i-ione/2,j-jone/2) = ( arrayV(i-ione,0) + arrayV(i,jone) ) / 2 ;
1505  // Note that this leaves a point at the upper left and lower right corners uninitialized. Not a big deal.
1506  }
1507  }
1508  }
1509  }
1510 
1511  }
1512  }
1513 
1514  ione = ione / 2 ; if ( ione < 1 ) ione = 1 ;
1515  jone = jone / 2 ; if ( jone < 1 ) jone = 1 ;
1516 
1517  }
1518 
1519  //Differentiate V(r) and solve for E(r) using special equations for the first and last row
1520  //Integrate E(r)/E(z) from point of origin to pad plane
1521  AliSysInfo::AddStamp("CalcField", 100,0,0);
1522 
1523  for ( Int_t m = 0 ; m < phislices ; m++ ) {
1524  TMatrixD& arrayV = *arrayofArrayV[m] ;
1525  TMatrixD& eroverEz = *arrayofEroverEz[m] ;
1526 
1527  for ( Int_t j = columns-1 ; j >= 0 ; j-- ) { // Count backwards to facilitate integration over Z
1528 
1529  // Differentiate in R
1530  for ( Int_t i = 1 ; i < rows-1 ; i++ ) arrayE(i,j) = -1 * ( arrayV(i+1,j) - arrayV(i-1,j) ) / (2*gridSizeR) ;
1531  arrayE(0,j) = -1 * ( -0.5*arrayV(2,j) + 2.0*arrayV(1,j) - 1.5*arrayV(0,j) ) / gridSizeR ;
1532  arrayE(rows-1,j) = -1 * ( 1.5*arrayV(rows-1,j) - 2.0*arrayV(rows-2,j) + 0.5*arrayV(rows-3,j) ) / gridSizeR ;
1533  // Integrate over Z
1534  for ( Int_t i = 0 ; i < rows ; i++ ) {
1535  Int_t index = 1 ; // Simpsons rule if N=odd. If N!=odd then add extra point by trapezoidal rule.
1536  eroverEz(i,j) = 0.0 ;
1537  if(integrationType==kIntegral) {
1538  for ( Int_t k = j ; k < columns ; k++ ) {
1539 
1540  eroverEz(i,j) += index*(gridSizeZ/3.0)*arrayE(i,k)/(-1*ezField) ;
1541  if ( index != 4 ) index = 4; else index = 2 ;
1542  }
1543  if ( index == 4 ) eroverEz(i,j) -= (gridSizeZ/3.0)*arrayE(i,columns-1)/ (-1*ezField) ;
1544  if ( index == 2 ) eroverEz(i,j) +=
1545  (gridSizeZ/3.0)*(0.5*arrayE(i,columns-2)-2.5*arrayE(i,columns-1))/(-1*ezField) ;
1546  if ( j == columns-2 ) eroverEz(i,j) =
1547  (gridSizeZ/3.0)*(1.5*arrayE(i,columns-2)+1.5*arrayE(i,columns-1))/(-1*ezField) ;
1548  if ( j == columns-1 ) eroverEz(i,j) = 0.0 ;
1549  } else if(integrationType==kDifferential) {
1550  eroverEz(i,j) = arrayE(i,j)/(-1*ezField);
1551 
1552 
1553  if ( j == columns-2 ) eroverEz(i,j) =
1554  (0.5*arrayE(i,columns-2)+0.5*arrayE(i,columns-1))/(-1*ezField) ;
1555  if ( j == columns-1 ) eroverEz(i,j) = 0.0 ;
1556 
1557  if ( j == 2 ) eroverEz(i,j) =
1558  (0.5*arrayE(i,2)+0.5*arrayE(i,1))/(-1*ezField) ;
1559  if ( j == 1 ) eroverEz(i,j) = 0.0 ;
1560  }
1561  }
1562  }
1563  // if ( m == 0 ) { TCanvas* c1 = new TCanvas("erOverEz","erOverEz",50,50,840,600) ; c1 -> cd() ;
1564  // eroverEz.Draw("surf") ; } // JT test
1565  }
1566  AliSysInfo::AddStamp("IntegrateEr", 120,0,0);
1567 
1568  //Differentiate V(r) and solve for E(phi)
1569  //Integrate E(phi)/E(z) from point of origin to pad plane
1570 
1571  for ( Int_t m = 0 ; m < phislices ; m++ ) {
1572 
1573  mplus = m + 1; signplus = 1 ;
1574  mminus = m - 1 ; signminus = 1 ;
1575  if (symmetry==1) { // Reflection symmetry in phi (e.g. symmetry at sector boundaries, or half sectors, etc.)
1576  if ( mplus > phislices-1 ) mplus = phislices - 2 ;
1577  if ( mminus < 0 ) mminus = 1 ;
1578  }
1579  else if (symmetry==-1) { // Anti-symmetry in phi
1580  if ( mplus > phislices-1 ) { mplus = phislices - 2 ; signplus = -1 ; }
1581  if ( mminus < 0 ) { mminus = 1 ; signminus = -1 ; }
1582  }
1583  else { // No Symmetries in phi, no boundaries, the calculations is continuous across all phi
1584  if ( mplus > phislices-1 ) mplus = m + 1 - phislices ;
1585  if ( mminus < 0 ) mminus = m - 1 + phislices ;
1586  }
1587  TMatrixD &arrayVP = *arrayofArrayV[mplus] ;
1588  TMatrixD &arrayVM = *arrayofArrayV[mminus] ;
1589  TMatrixD &ePhioverEz = *arrayofEPhioverEz[m] ;
1590  for ( Int_t j = columns-1 ; j >= 0 ; j-- ) { // Count backwards to facilitate integration over Z
1591  // Differentiate in Phi
1592  for ( Int_t i = 0 ; i < rows ; i++ ) {
1593  Float_t radius = fgkIFCRadius + i*gridSizeR ;
1594  arrayE(i,j) = -1 * (signplus * arrayVP(i,j) - signminus * arrayVM(i,j) ) / (2*radius*gridSizePhi) ;
1595  }
1596  // Integrate over Z
1597  for ( Int_t i = 0 ; i < rows ; i++ ) {
1598  Int_t index = 1 ; // Simpsons rule if N=odd. If N!=odd then add extra point by trapezoidal rule.
1599  ePhioverEz(i,j) = 0.0 ;
1600  if(integrationType==kIntegral) {
1601  for ( Int_t k = j ; k < columns ; k++ ) {
1602 
1603  ePhioverEz(i,j) += index*(gridSizeZ/3.0)*arrayE(i,k)/(-1*ezField) ;
1604  if ( index != 4 ) index = 4; else index = 2 ;
1605  }
1606  if ( index == 4 ) ePhioverEz(i,j) -= (gridSizeZ/3.0)*arrayE(i,columns-1)/ (-1*ezField) ;
1607  if ( index == 2 ) ePhioverEz(i,j) +=
1608  (gridSizeZ/3.0)*(0.5*arrayE(i,columns-2)-2.5*arrayE(i,columns-1))/(-1*ezField) ;
1609  if ( j == columns-2 ) ePhioverEz(i,j) =
1610  (gridSizeZ/3.0)*(1.5*arrayE(i,columns-2)+1.5*arrayE(i,columns-1))/(-1*ezField) ;
1611  if ( j == columns-1 ) ePhioverEz(i,j) = 0.0 ;
1612  } else if(integrationType==kDifferential) {
1613  ePhioverEz(i,j) = arrayE(i,j)/(-1*ezField);
1614  if ( j == columns-2 ) ePhioverEz(i,j) =
1615  (0.5*arrayE(i,columns-2)+0.5*arrayE(i,columns-1))/(-1*ezField) ;
1616  if ( j == columns-1 ) ePhioverEz(i,j) = 0.0 ;
1617 
1618  if ( j == 2 ) ePhioverEz(i,j) =
1619  (0.5*arrayE(i,2)+0.5*arrayE(i,1))/(-1*ezField) ;
1620  if ( j == 1 ) ePhioverEz(i,j) = 0.0 ;
1621  }
1622  }
1623  }
1624  // if ( m == 5 ) { TCanvas* c2 = new TCanvas("arrayE","arrayE",50,50,840,600) ; c2 -> cd() ;
1625  // arrayE.Draw("surf") ; } // JT test
1626  }
1627  AliSysInfo::AddStamp("IntegrateEphi", 130,0,0);
1628 
1629 
1630  // Differentiate V(r) and solve for E(z) using special equations for the first and last row
1631  // Integrate (E(z)-Ezstd) from point of origin to pad plane
1632 
1633  for ( Int_t m = 0 ; m < phislices ; m++ ) {
1634  TMatrixD& arrayV = *arrayofArrayV[m] ;
1635  TMatrixD& deltaEz = *arrayofDeltaEz[m] ;
1636 
1637  // Differentiate V(z) and solve for E(z) using special equations for the first and last columns
1638  for ( Int_t i = 0 ; i < rows ; i++) {
1639  for ( Int_t j = 1 ; j < columns-1 ; j++ ) arrayE(i,j) = -1 * ( arrayV(i,j+1) - arrayV(i,j-1) ) / (2*gridSizeZ) ;
1640  arrayE(i,0) = -1 * ( -0.5*arrayV(i,2) + 2.0*arrayV(i,1) - 1.5*arrayV(i,0) ) / gridSizeZ ;
1641  arrayE(i,columns-1) = -1 * ( 1.5*arrayV(i,columns-1) - 2.0*arrayV(i,columns-2) + 0.5*arrayV(i,columns-3) ) / gridSizeZ ;
1642  }
1643 
1644  for ( Int_t j = columns-1 ; j >= 0 ; j-- ) { // Count backwards to facilitate integration over Z
1645  // Integrate over Z
1646  for ( Int_t i = 0 ; i < rows ; i++ ) {
1647  Int_t index = 1 ; // Simpsons rule if N=odd. If N!=odd then add extra point by trapezoidal rule.
1648  deltaEz(i,j) = 0.0 ;
1649  if(integrationType==kIntegral) {
1650  for ( Int_t k = j ; k < columns ; k++ ) {
1651  deltaEz(i,j) += index*(gridSizeZ/3.0)*arrayE(i,k) ;
1652  if ( index != 4 ) index = 4; else index = 2 ;
1653  }
1654  if ( index == 4 ) deltaEz(i,j) -= (gridSizeZ/3.0)*arrayE(i,columns-1) ;
1655  if ( index == 2 ) deltaEz(i,j) +=
1656  (gridSizeZ/3.0)*(0.5*arrayE(i,columns-2)-2.5*arrayE(i,columns-1)) ;
1657  if ( j == columns-2 ) deltaEz(i,j) =
1658  (gridSizeZ/3.0)*(1.5*arrayE(i,columns-2)+1.5*arrayE(i,columns-1)) ;
1659  if ( j == columns-1 ) deltaEz(i,j) = 0.0 ;
1660  } else if(integrationType==kDifferential) {
1661  deltaEz(i,j) = arrayE(i,j) ;
1662  if ( j == columns-2 ) deltaEz(i,j) =
1663  (0.5*arrayE(i,columns-2)+0.5*arrayE(i,columns-1)) ;
1664  if ( j == columns-1 ) deltaEz(i,j) = 0.0 ;
1665  if ( j == 2 ) deltaEz(i,j) =
1666  (0.5*arrayE(i,2)+0.5*arrayE(i,1)) ;
1667  if ( j == 1 ) deltaEz(i,j) = 0.0 ;
1668  };
1669  }
1670  }
1671 
1672  // if ( m == 0 ) { TCanvas* c1 = new TCanvas("erOverEz","erOverEz",50,50,840,600) ; c1 -> cd() ;
1673  // eroverEz.Draw("surf") ; } // JT test
1674 
1675  // calculate z distortion from the integrated Delta Ez residuals
1676  // and include the aquivalence (Volt to cm) of the ROC shift !!
1677 
1678  for ( Int_t j = 0 ; j < columns ; j++ ) {
1679  for ( Int_t i = 0 ; i < rows ; i++ ) {
1680 
1681  // Scale the Ez distortions with the drift velocity pertubation -> delivers cm
1682  deltaEz(i,j) = deltaEz(i,j)*fgkdvdE;
1683 
1684  // ROC Potential in cm aquivalent
1685  Double_t dzROCShift = arrayV(i, columns -1)/ezField;
1686  if ( rocDisplacement ) deltaEz(i,j) = deltaEz(i,j) + dzROCShift; // add the ROC misaligment
1687 
1688  }
1689  }
1690 
1691  } // end loop over phi
1692  AliSysInfo::AddStamp("IntegrateEz", 140,0,0);
1693 
1694 
1695  for ( Int_t k = 0 ; k < phislices ; k++ )
1696  {
1697  arrayofSumChargeDensities[k]->Delete() ;
1698  }
1699 
1700 
1701 
1702  arrayE.Clear();
1703 }
1704 
1705 
1706 Int_t AliTPCCorrection::IsPowerOfTwo(Int_t i) const {
1708 
1709  Int_t j = 0;
1710  while( i > 0 ) { j += (i&1) ; i = (i>>1) ; }
1711  if ( j == 1 ) return(1) ; // True
1712  return(0) ; // False
1713 }
1714 
1715 
1716 AliExternalTrackParam * AliTPCCorrection::FitDistortedTrack(AliExternalTrackParam & trackIn, Double_t refX, Int_t dir, TTreeSRedirector * const pcstream){
1734 
1735  AliTPCROC * roc = AliTPCROC::Instance();
1736  const Int_t npoints0=roc->GetNRows(0)+roc->GetNRows(36);
1737  const Double_t kRTPC0 =roc->GetPadRowRadii(0,0);
1738  const Double_t kRTPC1 =roc->GetPadRowRadii(36,roc->GetNRows(36)-1);
1739  const Double_t kMaxSnp = 0.85;
1740  const Double_t kSigmaY=0.1;
1741  const Double_t kSigmaZ=0.1;
1742  const Double_t kMaxR=500;
1743  const Double_t kMaxZ=500;
1744 
1745  const Double_t kMaxZ0=220;
1746  const Double_t kZcut=3;
1747  const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
1748  Int_t npoints1=0;
1749  Int_t npoints2=0;
1750 
1751  AliExternalTrackParam track(trackIn); //
1752  // generate points
1753  AliTrackPointArray pointArray0(npoints0);
1754  AliTrackPointArray pointArray1(npoints0);
1755  Double_t xyz[3];
1756  if (!AliTrackerBase::PropagateTrackTo(&track,kRTPC0,kMass,5,kTRUE,kMaxSnp)) return 0;
1757  //
1758  // simulate the track
1759  Int_t npoints=0;
1760  Float_t covPoint[6]={0,0,0, static_cast<Float_t>(kSigmaY*kSigmaY),0,static_cast<Float_t>(kSigmaZ*kSigmaZ)}; //covariance at the local frame
1761  for (Double_t radius=kRTPC0; radius<kRTPC1; radius++){
1762  if (!AliTrackerBase::PropagateTrackTo(&track,radius,kMass,5,kTRUE,kMaxSnp)) return 0;
1763  track.GetXYZ(xyz);
1764  xyz[0]+=gRandom->Gaus(0,0.000005);
1765  xyz[1]+=gRandom->Gaus(0,0.000005);
1766  xyz[2]+=gRandom->Gaus(0,0.000005);
1767  if (TMath::Abs(track.GetZ())>kMaxZ0) continue;
1768  if (TMath::Abs(track.GetX())<kRTPC0) continue;
1769  if (TMath::Abs(track.GetX())>kRTPC1) continue;
1770  AliTrackPoint pIn0; // space point
1771  AliTrackPoint pIn1;
1772  Int_t sector= (xyz[2]>0)? 0:18;
1773  pointArray0.GetPoint(pIn0,npoints);
1774  pointArray1.GetPoint(pIn1,npoints);
1775  Double_t alpha = TMath::ATan2(xyz[1],xyz[0]);
1776  Float_t distPoint[3]={static_cast<Float_t>(xyz[0]),static_cast<Float_t>(xyz[1]),static_cast<Float_t>(xyz[2])};
1777  DistortPoint(distPoint, sector);
1778  pIn0.SetXYZ(xyz[0], xyz[1],xyz[2]);
1779  pIn1.SetXYZ(distPoint[0], distPoint[1],distPoint[2]);
1780  //
1781  track.Rotate(alpha);
1782  AliTrackPoint prot0 = pIn0.Rotate(alpha); // rotate to the local frame - non distoted point
1783  AliTrackPoint prot1 = pIn1.Rotate(alpha); // rotate to the local frame - distorted point
1784  prot0.SetXYZ(prot0.GetX(),prot0.GetY(), prot0.GetZ(),covPoint);
1785  prot1.SetXYZ(prot1.GetX(),prot1.GetY(), prot1.GetZ(),covPoint);
1786  pIn0=prot0.Rotate(-alpha); // rotate back to global frame
1787  pIn1=prot1.Rotate(-alpha); // rotate back to global frame
1788  pointArray0.AddPoint(npoints, &pIn0);
1789  pointArray1.AddPoint(npoints, &pIn1);
1790  npoints++;
1791  if (npoints>=npoints0) break;
1792  }
1793  if (npoints<npoints0/4.) return 0;
1794  //
1795  // refit track
1796  //
1797  AliExternalTrackParam *track0=0;
1798  AliExternalTrackParam *track1=0;
1799  AliTrackPoint point1,point2,point3;
1800  if (dir==1) { //make seed inner
1801  pointArray0.GetPoint(point1,1);
1802  pointArray0.GetPoint(point2,11);
1803  pointArray0.GetPoint(point3,21);
1804  }
1805  if (dir==-1){ //make seed outer
1806  pointArray0.GetPoint(point1,npoints-21);
1807  pointArray0.GetPoint(point2,npoints-11);
1808  pointArray0.GetPoint(point3,npoints-1);
1809  }
1810  if ((TMath::Abs(point1.GetX()-point3.GetX())+TMath::Abs(point1.GetY()-point3.GetY()))<10){
1811  printf("fit points not properly initialized\n");
1812  return 0;
1813  }
1814  track0 = AliTrackerBase::MakeSeed(point1, point2, point3);
1815  track1 = AliTrackerBase::MakeSeed(point1, point2, point3);
1816  track0->ResetCovariance(10);
1817  track1->ResetCovariance(10);
1818  if (TMath::Abs(AliTrackerBase::GetBz())<0.01){
1819  ((Double_t*)track0->GetParameter())[4]= trackIn.GetParameter()[4];
1820  ((Double_t*)track1->GetParameter())[4]= trackIn.GetParameter()[4];
1821  }
1822  for (Int_t jpoint=0; jpoint<npoints; jpoint++){
1823  Int_t ipoint= (dir>0) ? jpoint: npoints-1-jpoint;
1824  //
1825  AliTrackPoint pIn0;
1826  AliTrackPoint pIn1;
1827  pointArray0.GetPoint(pIn0,ipoint);
1828  pointArray1.GetPoint(pIn1,ipoint);
1829  AliTrackPoint prot0 = pIn0.Rotate(track0->GetAlpha()); // rotate to the local frame - non distoted point
1830  AliTrackPoint prot1 = pIn1.Rotate(track1->GetAlpha()); // rotate to the local frame - distorted point
1831  if (TMath::Abs(prot0.GetX())<kRTPC0) continue;
1832  if (TMath::Abs(prot0.GetX())>kRTPC1) continue;
1833  //
1834  if (!AliTrackerBase::PropagateTrackTo(track0,prot0.GetX(),kMass,5,kFALSE,kMaxSnp)) break;
1835  if (!AliTrackerBase::PropagateTrackTo(track1,prot0.GetX(),kMass,5,kFALSE,kMaxSnp)) break;
1836  if (TMath::Abs(track0->GetZ())>kMaxZ) break;
1837  if (TMath::Abs(track0->GetX())>kMaxR) break;
1838  if (TMath::Abs(track1->GetZ())>kMaxZ) break;
1839  if (TMath::Abs(track1->GetX())>kMaxR) break;
1840  if (dir>0 && track1->GetX()>refX) continue;
1841  if (dir<0 && track1->GetX()<refX) continue;
1842  if (TMath::Abs(track1->GetZ())<kZcut)continue;
1843  track.GetXYZ(xyz); // distorted track also propagated to the same reference radius
1844  //
1845  Double_t pointPos[2]={0,0};
1846  Double_t pointCov[3]={0,0,0};
1847  pointPos[0]=prot0.GetY();//local y
1848  pointPos[1]=prot0.GetZ();//local z
1849  pointCov[0]=prot0.GetCov()[3];//simay^2
1850  pointCov[1]=prot0.GetCov()[4];//sigmayz
1851  pointCov[2]=prot0.GetCov()[5];//sigmaz^2
1852  if (!track0->Update(pointPos,pointCov)) break;
1853  //
1854  Double_t deltaX=prot1.GetX()-prot0.GetX(); // delta X
1855  Double_t deltaYX=deltaX*TMath::Tan(TMath::ASin(track1->GetSnp())); // deltaY due delta X
1856  Double_t deltaZX=deltaX*track1->GetTgl(); // deltaZ due delta X
1857 
1858  pointPos[0]=prot1.GetY()-deltaYX;//local y is sign correct? should be minus
1859  pointPos[1]=prot1.GetZ()-deltaZX;//local z is sign correct? should be minus
1860  pointCov[0]=prot1.GetCov()[3];//simay^2
1861  pointCov[1]=prot1.GetCov()[4];//sigmayz
1862  pointCov[2]=prot1.GetCov()[5];//sigmaz^2
1863  if (!track1->Update(pointPos,pointCov)) break;
1864  npoints1++;
1865  npoints2++;
1866  }
1867  if (npoints2<npoints/4.) return 0;
1868  AliTrackerBase::PropagateTrackTo(track0,refX,kMass,5.,kTRUE,kMaxSnp);
1869  AliTrackerBase::PropagateTrackTo(track0,refX,kMass,1.,kTRUE,kMaxSnp);
1870  track1->Rotate(track0->GetAlpha());
1871  AliTrackerBase::PropagateTrackTo(track1,track0->GetX(),kMass,5.,kFALSE,kMaxSnp);
1872 
1873  if (pcstream) (*pcstream)<<Form("fitDistort%s",GetName())<<
1874  "point0.="<<&pointArray0<< // points
1875  "point1.="<<&pointArray1<< // distorted points
1876  "trackIn.="<<&track<< // original track
1877  "track0.="<<track0<< // fitted track
1878  "track1.="<<track1<< // fitted distorted track
1879  "\n";
1880  new(&trackIn) AliExternalTrackParam(*track0);
1881  delete track0;
1882  return track1;
1883 }
1884 
1885 
1886 
1887 
1888 
1889 TTree* AliTPCCorrection::CreateDistortionTree(Double_t step, Int_t type/*=0*/)
1890 {
1896 
1897  if (type<0 || type>1) {
1898  AliError("Unknown type");
1899  return 0x0;
1900  }
1901 
1902  TTreeSRedirector *pcstream = new TTreeSRedirector(Form("correction%s.root",GetName()));
1903  Float_t xyz[3]; // current point
1904  Float_t dist[3]; // distorion
1905  Float_t corr[3]; // correction
1906  Float_t xyzdist[3]; // distorted point
1907  Float_t xyzcorr[3]; // corrected point
1908 
1909  AliMagF* mag= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
1910  if (!mag) AliError("Magnetic field - not initialized");
1911 
1912  for (Double_t x= -250; x<250; x+=step){
1913  for (Double_t y= -250; y<250; y+=step){
1914  Double_t r = TMath::Sqrt(x*x+y*y);
1915  if (r<80) continue;
1916  if (r>250) continue;
1917 
1918  Double_t phi = TMath::ATan2(y,x);
1919 
1920  for (Double_t z= -250; z<250; z+=step){
1921  Int_t roc=(z>0)?0:18;
1922  xyz[0]=x;
1923  xyz[1]=y;
1924  xyz[2]=z;
1925 
1926  // === Get distortions and corrections =========================
1927  if (type==0) {
1928  GetDistortion(xyz, roc, dist);
1929  GetCorrection(xyz, roc, corr);
1930  } else if (type==1) {
1931  GetDistortionIntegralDz(xyz, roc, dist, .5);
1932  GetCorrectionIntegralDz(xyz, roc, corr, .5);
1933  }
1934 
1935  for (Int_t i=0; i<3; ++i) {
1936  xyzdist[i]=xyz[i]+dist[i];
1937  xyzcorr[i]=xyz[i]+corr[i];
1938  }
1939 
1940  // === r, rphi + residuals for the distorted point =========================
1941  Double_t rdist = TMath::Sqrt(xyzdist[0]*xyzdist[0]+xyzdist[1]*xyzdist[1]);
1942  Double_t phidist = TMath::ATan2(xyzdist[1],xyzdist[0]);
1943  if ((phidist-phi)>TMath::Pi()) phidist-=TMath::Pi();
1944  if ((phidist-phi)<-TMath::Pi()) phidist+=TMath::Pi();
1945 
1946  Double_t drdist=rdist-r;
1947  Double_t drphidist=(phidist-phi)*r;
1948 
1949  // === r, rphi + residuals for the corrected point =========================
1950  Double_t rcorr = TMath::Sqrt(xyzcorr[0]*xyzcorr[0]+xyzcorr[1]*xyzcorr[1]);
1951  Double_t phicorr = TMath::ATan2(xyzcorr[1],xyzcorr[0]);
1952  if ((phicorr-phi)>TMath::Pi()) phicorr-=TMath::Pi();
1953  if ((phicorr-phi)<-TMath::Pi()) phicorr+=TMath::Pi();
1954 
1955  Double_t drcorr=rcorr-r;
1956  Double_t drphicorr=(phicorr-phi)*r;
1957 
1958  // === get b field ===============
1959  Double_t bxyz[3]={0.,0.,0.};
1960  Double_t dblxyz[3] = {Double_t(xyzdist[0]),Double_t(xyzdist[1]),Double_t(xyzdist[2])};
1961  Double_t br = 0.;
1962  Double_t brfi = 0.;
1963  if (mag) {
1964  mag->Field(dblxyz,bxyz);
1965  if(rdist>0){
1966  br = (bxyz[0]*xyz[0]+bxyz[1]*xyz[1])/rdist;
1967  brfi = (-bxyz[0]*xyz[1]+bxyz[1]*xyz[0])/rdist;
1968  }
1969  }
1970 
1971  (*pcstream)<<"distortion"<<
1972  "x=" << x << // original position
1973  "y=" << y <<
1974  "z=" << z <<
1975  "r=" << r <<
1976  "phi="<< phi <<
1977  //
1978  "x_dist=" << xyzdist[0] << // distorted position
1979  "y_dist=" << xyzdist[1] <<
1980  "z_dist=" << xyzdist[2] <<
1981  "r_dist=" << rdist <<
1982  "phi_dist=" << phidist <<
1983  //
1984  "dx_dist=" << dist[0] << // distortion
1985  "dy_dist=" << dist[1] <<
1986  "dz_dist=" << dist[2] <<
1987  "dr_dist=" << drdist <<
1988  "drphi_dist="<< drphidist <<
1989  //
1990  //
1991  "x_corr=" << xyzcorr[0] << // corrected position
1992  "y_corr=" << xyzcorr[1] <<
1993  "z_corr=" << xyzcorr[2] <<
1994  "r_corr=" << rcorr <<
1995  "phi_corr=" << phicorr <<
1996  //
1997  "dx_corr=" << corr[0] << // correction
1998  "dy_corr=" << corr[1] <<
1999  "dz_corr=" << corr[2] <<
2000  "dr_corr=" << drcorr <<
2001  "drphi_corr="<< drphicorr <<
2002  // B-field integ
2003  "bx="<<bxyz[0]<<
2004  "by="<<bxyz[1]<<
2005  "bz="<<bxyz[2]<<
2006  "br="<< br<<
2007  "brfi="<<brfi<<
2008  "\n";
2009  }
2010  }
2011  }
2012  delete pcstream;
2013  TFile f(Form("correction%s.root",GetName()));
2014  TTree * tree = (TTree*)f.Get("distortion");
2015  TTree * tree2= tree->CopyTree("1");
2016  tree2->SetName(Form("dist%s",GetName()));
2017  tree2->SetDirectory(0);
2018  delete tree;
2019  return tree2;
2020 }
2021 
2022 
2023 
2024 
2025 void AliTPCCorrection::MakeTrackDistortionTree(TTree *tinput, Int_t dtype, Int_t ptype, const TObjArray * corrArray, Int_t step, Int_t offset, Bool_t debug ){
2040 
2041  const Double_t kMaxSnp = 0.85;
2042  const Double_t kcutSnp=0.25;
2043  const Double_t kcutTheta=1.;
2044  const Double_t kRadiusTPC=85;
2045  // AliTPCROC *tpcRoc =AliTPCROC::Instance();
2046  //
2047  const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
2048  // const Double_t kB2C=-0.299792458e-3;
2049  const Int_t kMinEntries=20;
2050  Double_t phi,theta, snp, mean,rms, entries,sector,dsec;
2051  Float_t refX;
2052  Int_t run;
2053  tinput->SetBranchAddress("run",&run);
2054  tinput->SetBranchAddress("theta",&theta);
2055  tinput->SetBranchAddress("phi", &phi);
2056  tinput->SetBranchAddress("snp",&snp);
2057  tinput->SetBranchAddress("mean",&mean);
2058  tinput->SetBranchAddress("rms",&rms);
2059  tinput->SetBranchAddress("entries",&entries);
2060  tinput->SetBranchAddress("sector",&sector);
2061  tinput->SetBranchAddress("dsec",&dsec);
2062  tinput->SetBranchAddress("refX",&refX);
2063  TTreeSRedirector *pcstream = new TTreeSRedirector(Form("distortion%d_%d_%d.root",dtype,ptype,offset));
2064  //
2065  Int_t nentries=tinput->GetEntries();
2066  Int_t ncorr=corrArray->GetEntries();
2067  Double_t corrections[100]={0}; //
2068  Double_t tPar[5];
2069  Double_t cov[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
2070  Int_t dir=0;
2071  if (dtype==5 || dtype==6) dtype=4;
2072  if (dtype==0) { dir=-1;}
2073  if (dtype==1) { dir=1;}
2074  if (dtype==2) { dir=-1;}
2075  if (dtype==3) { dir=1;}
2076  if (dtype==4) { dir=-1;}
2077  //
2078  for (Int_t ientry=offset; ientry<nentries; ientry+=step){
2079  tinput->GetEntry(ientry);
2080  if (TMath::Abs(snp)>kMaxSnp) continue;
2081  tPar[0]=0;
2082  tPar[1]=theta*refX;
2083  if (dtype==2) tPar[1]=theta*kRadiusTPC;
2084  tPar[2]=snp;
2085  tPar[3]=theta;
2086  tPar[4]=(gRandom->Rndm()-0.5)*0.02; // should be calculated - non equal to 0
2087  if (dtype==4){
2088  // tracks crossing CE
2089  tPar[1]=0; // track at the CE
2090  //if (TMath::Abs(theta) <0.05) continue; // deep cross
2091  }
2092 
2093  if (TMath::Abs(snp) >kcutSnp) continue;
2094  if (TMath::Abs(theta) >kcutTheta) continue;
2095  printf("%f\t%f\t%f\t%f\t%f\t%f\n",entries, sector,theta,snp, mean,rms);
2096  Double_t bz=AliTrackerBase::GetBz();
2097  if (dtype !=4) { //exclude TPC - for TPC mainly non primary tracks
2098  if (dtype!=2 && TMath::Abs(bz)>0.1 ) tPar[4]=snp/(refX*bz*kB2C*2);
2099 
2100  if (dtype==2 && TMath::Abs(bz)>0.1 ) {
2101  tPar[4]=snp/(kRadiusTPC*bz*kB2C*2);//
2102  // snp at the TPC inner radius in case the vertex match used
2103  }
2104  }
2105  //
2106  tPar[4]+=(gRandom->Rndm()-0.5)*0.02;
2107  AliExternalTrackParam track(refX,phi,tPar,cov);
2108  Double_t xyz[3];
2109  track.GetXYZ(xyz);
2110  Int_t id=0;
2111  Double_t pt=1./tPar[4];
2112  Double_t dRrec=0; // dummy value - needed for points - e.g for laser
2113  //if (ptype==4 &&bz<0) mean*=-1; // interpret as curvature -- COMMENTED out - in lookup signed 1/pt used
2114  Double_t refXD=refX;
2115  (*pcstream)<<"fit"<<
2116  "run="<<run<< // run number
2117  "bz="<<bz<< // magnetic filed used
2118  "dtype="<<dtype<< // detector match type
2119  "ptype="<<ptype<< // parameter type
2120  "theta="<<theta<< // theta
2121  "phi="<<phi<< // phi
2122  "snp="<<snp<< // snp
2123  "mean="<<mean<< // mean dist value
2124  "rms="<<rms<< // rms
2125  "sector="<<sector<<
2126  "dsec="<<dsec<<
2127  "refX="<<refXD<< // referece X as double
2128  "gx="<<xyz[0]<< // global position at reference
2129  "gy="<<xyz[1]<< // global position at reference
2130  "gz="<<xyz[2]<< // global position at reference
2131  "dRrec="<<dRrec<< // delta Radius in reconstruction
2132  "pt="<<pt<< // pt
2133  "id="<<id<< // track id
2134  "entries="<<entries;// number of entries in bin
2135  //
2136  Bool_t isOK=kTRUE;
2137  if (entries<kMinEntries) isOK=kFALSE;
2138  //
2139  if (dtype!=4) for (Int_t icorr=0; icorr<ncorr; icorr++) {
2140  AliTPCCorrection *corr = (AliTPCCorrection*)corrArray->At(icorr);
2141  corrections[icorr]=0;
2142  if (entries>kMinEntries){
2143  AliExternalTrackParam trackIn(refX,phi,tPar,cov);
2144  AliExternalTrackParam *trackOut = 0;
2145  if (debug) trackOut=corr->FitDistortedTrack(trackIn, refX, dir,pcstream);
2146  if (!debug) trackOut=corr->FitDistortedTrack(trackIn, refX, dir,0);
2147  if (dtype==0) {dir= -1;}
2148  if (dtype==1) {dir= 1;}
2149  if (dtype==2) {dir= -1;}
2150  if (dtype==3) {dir= 1;}
2151  //
2152  if (trackOut){
2153  if (!AliTrackerBase::PropagateTrackTo(&trackIn,refX,kMass,5,kTRUE,kMaxSnp)) isOK=kFALSE;
2154  if (!trackOut->Rotate(trackIn.GetAlpha())) isOK=kFALSE;
2155  if (!AliTrackerBase::PropagateTrackTo(trackOut,trackIn.GetX(),kMass,5,kFALSE,kMaxSnp)) isOK=kFALSE;
2156  // trackOut->PropagateTo(trackIn.GetX(),AliTrackerBase::GetBz());
2157  //
2158  corrections[icorr]= trackOut->GetParameter()[ptype]-trackIn.GetParameter()[ptype];
2159  delete trackOut;
2160  }else{
2161  corrections[icorr]=0;
2162  isOK=kFALSE;
2163  }
2164  //if (ptype==4 &&bz<0) corrections[icorr]*=-1; // interpret as curvature - commented out
2165  }
2166  (*pcstream)<<"fit"<<
2167  Form("%s=",corr->GetName())<<corrections[icorr]; // dump correction value
2168  }
2169 
2170  if (dtype==4) for (Int_t icorr=0; icorr<ncorr; icorr++) {
2171  //
2172  // special case of the TPC tracks crossing the CE
2173  //
2174  AliTPCCorrection *corr = (AliTPCCorrection*)corrArray->At(icorr);
2175  corrections[icorr]=0;
2176  if (entries>kMinEntries){
2177  AliExternalTrackParam trackIn0(refX,phi,tPar,cov); //Outer - direction to vertex
2178  AliExternalTrackParam trackIn1(refX,phi,tPar,cov); //Inner - direction magnet
2179  AliExternalTrackParam *trackOut0 = 0;
2180  AliExternalTrackParam *trackOut1 = 0;
2181  //
2182  if (debug) trackOut0=corr->FitDistortedTrack(trackIn0, refX, dir,pcstream);
2183  if (!debug) trackOut0=corr->FitDistortedTrack(trackIn0, refX, dir,0);
2184  if (debug) trackOut1=corr->FitDistortedTrack(trackIn1, refX, -dir,pcstream);
2185  if (!debug) trackOut1=corr->FitDistortedTrack(trackIn1, refX, -dir,0);
2186  //
2187  if (trackOut0 && trackOut1){
2188  if (!AliTrackerBase::PropagateTrackTo(&trackIn0,refX,kMass,5,kTRUE,kMaxSnp)) isOK=kFALSE;
2189  if (!AliTrackerBase::PropagateTrackTo(&trackIn0,refX,kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
2190  if (!trackOut0->Rotate(trackIn0.GetAlpha())) isOK=kFALSE;
2191  if (!AliTrackerBase::PropagateTrackTo(trackOut0,trackIn0.GetX(),kMass,5,kFALSE,kMaxSnp)) isOK=kFALSE;
2192  //
2193  if (!AliTrackerBase::PropagateTrackTo(&trackIn1,refX,kMass,5,kTRUE,kMaxSnp)) isOK=kFALSE;
2194  if (!trackIn1.Rotate(trackIn0.GetAlpha())) isOK=kFALSE;
2195  if (!AliTrackerBase::PropagateTrackTo(&trackIn1,trackIn0.GetX(),kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
2196  if (!trackOut1->Rotate(trackIn1.GetAlpha())) isOK=kFALSE;
2197  if (!AliTrackerBase::PropagateTrackTo(trackOut1,trackIn1.GetX(),kMass,5,kFALSE,kMaxSnp)) isOK=kFALSE;
2198  //
2199  corrections[icorr] = (trackOut0->GetParameter()[ptype]-trackIn0.GetParameter()[ptype]);
2200  corrections[icorr]-= (trackOut1->GetParameter()[ptype]-trackIn1.GetParameter()[ptype]);
2201  if (isOK)
2202  if ((TMath::Abs(trackOut0->GetX()-trackOut1->GetX())>0.1)||
2203  (TMath::Abs(trackOut0->GetX()-trackIn1.GetX())>0.1)||
2204  (TMath::Abs(trackOut0->GetAlpha()-trackOut1->GetAlpha())>0.00001)||
2205  (TMath::Abs(trackOut0->GetAlpha()-trackIn1.GetAlpha())>0.00001)||
2206  (TMath::Abs(trackIn0.GetTgl()-trackIn1.GetTgl())>0.0001)||
2207  (TMath::Abs(trackIn0.GetSnp()-trackIn1.GetSnp())>0.0001)
2208  ){
2209  isOK=kFALSE;
2210  }
2211  delete trackOut0;
2212  delete trackOut1;
2213  }else{
2214  corrections[icorr]=0;
2215  isOK=kFALSE;
2216  }
2217  //
2218  //if (ptype==4 &&bz<0) corrections[icorr]*=-1; // interpret as curvature - commented out no in lookup
2219  }
2220  (*pcstream)<<"fit"<<
2221  Form("%s=",corr->GetName())<<corrections[icorr]; // dump correction value
2222  }
2223  //
2224  (*pcstream)<<"fit"<<"isOK="<<isOK<<"\n";
2225  }
2226 
2227 
2228  delete pcstream;
2229 }
2230 
2231 
2232 
2233 void AliTPCCorrection::MakeSectorDistortionTree(TTree *tinput, Int_t dtype, Int_t ptype, const TObjArray * corrArray, Int_t step, Int_t offset, Bool_t debug ){
2248 
2249  const Double_t kMaxSnp = 0.8;
2250  const Int_t kMinEntries=200;
2251  // AliTPCROC *tpcRoc =AliTPCROC::Instance();
2252  //
2253  const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
2254  // const Double_t kB2C=-0.299792458e-3;
2255  Double_t phi,theta, snp, mean,rms, entries,sector,dsec,globalZ;
2256  Int_t isec1, isec0;
2257  Double_t refXD;
2258  Float_t refX;
2259  Int_t run;
2260  tinput->SetBranchAddress("run",&run);
2261  tinput->SetBranchAddress("theta",&theta);
2262  tinput->SetBranchAddress("phi", &phi);
2263  tinput->SetBranchAddress("snp",&snp);
2264  tinput->SetBranchAddress("mean",&mean);
2265  tinput->SetBranchAddress("rms",&rms);
2266  tinput->SetBranchAddress("entries",&entries);
2267  tinput->SetBranchAddress("sector",&sector);
2268  tinput->SetBranchAddress("dsec",&dsec);
2269  tinput->SetBranchAddress("refX",&refXD);
2270  tinput->SetBranchAddress("z",&globalZ);
2271  tinput->SetBranchAddress("isec0",&isec0);
2272  tinput->SetBranchAddress("isec1",&isec1);
2273  TTreeSRedirector *pcstream = new TTreeSRedirector(Form("distortionSector%d_%d_%d.root",dtype,ptype,offset));
2274  //
2275  Int_t nentries=tinput->GetEntries();
2276  Int_t ncorr=corrArray->GetEntries();
2277  Double_t corrections[100]={0}; //
2278  Double_t tPar[5];
2279  Double_t cov[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
2280  Int_t dir=0;
2281  //
2282  for (Int_t ientry=offset; ientry<nentries; ientry+=step){
2283  tinput->GetEntry(ientry);
2284  refX=refXD;
2285  Int_t id=-1;
2286  if (TMath::Abs(TMath::Abs(isec0%18)-TMath::Abs(isec1%18))==0) id=1; // IROC-OROC - opposite side
2287  if (TMath::Abs(TMath::Abs(isec0%36)-TMath::Abs(isec1%36))==0) id=2; // IROC-OROC - same side
2288  if (dtype==10 && id==-1) continue;
2289  //
2290  dir=-1;
2291  tPar[0]=0;
2292  tPar[1]=globalZ;
2293  tPar[2]=snp;
2294  tPar[3]=theta;
2295  tPar[4]=(gRandom->Rndm()-0.1)*0.2; //
2296  Double_t pt=1./tPar[4];
2297  //
2298  printf("%f\t%f\t%f\t%f\t%f\t%f\n",entries, sector,theta,snp, mean,rms);
2299  Double_t bz=AliTrackerBase::GetBz();
2300  AliExternalTrackParam track(refX,phi,tPar,cov);
2301  Double_t xyz[3],xyzIn[3],xyzOut[3];
2302  track.GetXYZ(xyz);
2303  track.GetXYZAt(85,bz,xyzIn);
2304  track.GetXYZAt(245,bz,xyzOut);
2305  Double_t phiIn = TMath::ATan2(xyzIn[1],xyzIn[0]);
2306  Double_t phiOut = TMath::ATan2(xyzOut[1],xyzOut[0]);
2307  Double_t phiRef = TMath::ATan2(xyz[1],xyz[0]);
2308  Int_t sectorRef = TMath::Nint(9.*phiRef/TMath::Pi()-0.5);
2309  Int_t sectorIn = TMath::Nint(9.*phiIn/TMath::Pi()-0.5);
2310  Int_t sectorOut = TMath::Nint(9.*phiOut/TMath::Pi()-0.5);
2311  //
2312  Bool_t isOK=kTRUE;
2313  if (sectorIn!=sectorOut) isOK=kFALSE; // requironment - cluster in the same sector
2314  if (sectorIn!=sectorRef) isOK=kFALSE; // requironment - cluster in the same sector
2315  if (entries<kMinEntries/(1+TMath::Abs(globalZ/100.))) isOK=kFALSE; // requironment - minimal amount of tracks in bin
2316  // Do downscale
2317  if (TMath::Abs(theta)>1) isOK=kFALSE;
2318  //
2319  Double_t dRrec=0; // dummy value - needed for points - e.g for laser
2320  //
2321  (*pcstream)<<"fit"<<
2322  "run="<<run<< //run
2323  "bz="<<bz<< // magnetic filed used
2324  "dtype="<<dtype<< // detector match type
2325  "ptype="<<ptype<< // parameter type
2326  "theta="<<theta<< // theta
2327  "phi="<<phi<< // phi
2328  "snp="<<snp<< // snp
2329  "mean="<<mean<< // mean dist value
2330  "rms="<<rms<< // rms
2331  "sector="<<sector<<
2332  "dsec="<<dsec<<
2333  "refX="<<refXD<< // referece X
2334  "gx="<<xyz[0]<< // global position at reference
2335  "gy="<<xyz[1]<< // global position at reference
2336  "gz="<<xyz[2]<< // global position at reference
2337  "dRrec="<<dRrec<< // delta Radius in reconstruction
2338  "pt="<<pt<< //pt
2339  "id="<<id<< // track id
2340  "entries="<<entries;// number of entries in bin
2341  //
2342  AliExternalTrackParam *trackOut0 = 0;
2343  AliExternalTrackParam *trackOut1 = 0;
2344  AliExternalTrackParam *ptrackIn0 = 0;
2345  AliExternalTrackParam *ptrackIn1 = 0;
2346 
2347  for (Int_t icorr=0; icorr<ncorr; icorr++) {
2348  //
2349  // special case of the TPC tracks crossing the CE
2350  //
2351  AliTPCCorrection *corr = (AliTPCCorrection*)corrArray->At(icorr);
2352  corrections[icorr]=0;
2353  if (entries>kMinEntries &&isOK){
2354  AliExternalTrackParam trackIn0(refX,phi,tPar,cov);
2355  AliExternalTrackParam trackIn1(refX,phi,tPar,cov);
2356  ptrackIn1=&trackIn0;
2357  ptrackIn0=&trackIn1;
2358  //
2359  if (debug) trackOut0=corr->FitDistortedTrack(trackIn0, refX, dir,pcstream);
2360  if (!debug) trackOut0=corr->FitDistortedTrack(trackIn0, refX, dir,0);
2361  if (debug) trackOut1=corr->FitDistortedTrack(trackIn1, refX, -dir,pcstream);
2362  if (!debug) trackOut1=corr->FitDistortedTrack(trackIn1, refX, -dir,0);
2363  //
2364  if (trackOut0 && trackOut1){
2365  //
2366  if (!AliTrackerBase::PropagateTrackTo(&trackIn0,refX,kMass,1,kTRUE,kMaxSnp)) isOK=kFALSE;
2367  if (!AliTrackerBase::PropagateTrackTo(&trackIn0,refX,kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
2368  // rotate all tracks to the same frame
2369  if (!trackOut0->Rotate(trackIn0.GetAlpha())) isOK=kFALSE;
2370  if (!trackIn1.Rotate(trackIn0.GetAlpha())) isOK=kFALSE;
2371  if (!trackOut1->Rotate(trackIn0.GetAlpha())) isOK=kFALSE;
2372  //
2373  if (!AliTrackerBase::PropagateTrackTo(trackOut0,refX,kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
2374  if (!AliTrackerBase::PropagateTrackTo(&trackIn1,refX,kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
2375  if (!AliTrackerBase::PropagateTrackTo(trackOut1,refX,kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
2376  //
2377  corrections[icorr] = (trackOut0->GetParameter()[ptype]-trackIn0.GetParameter()[ptype]);
2378  corrections[icorr]-= (trackOut1->GetParameter()[ptype]-trackIn1.GetParameter()[ptype]);
2379  (*pcstream)<<"fitDebug"<< // just to debug the correction
2380  "mean="<<mean<<
2381  "pIn0.="<<ptrackIn0<<
2382  "pIn1.="<<ptrackIn1<<
2383  "pOut0.="<<trackOut0<<
2384  "pOut1.="<<trackOut1<<
2385  "refX="<<refXD<<
2386  "\n";
2387  delete trackOut0;
2388  delete trackOut1;
2389  }else{
2390  corrections[icorr]=0;
2391  isOK=kFALSE;
2392  }
2393  }
2394  (*pcstream)<<"fit"<<
2395  Form("%s=",corr->GetName())<<corrections[icorr]; // dump correction value
2396  }
2397  //
2398  (*pcstream)<<"fit"<<"isOK="<<isOK<<"\n";
2399  }
2400  delete pcstream;
2401 }
2402 
2403 
2404 
2405 void AliTPCCorrection::MakeLaserDistortionTreeOld(TTree* tree, TObjArray *corrArray, Int_t itype){
2407 
2408  const Double_t cutErrY=0.1;
2409  const Double_t cutErrZ=0.1;
2410  const Double_t kEpsilon=0.00000001;
2411  const Double_t kMaxDist=1.; // max distance - space correction
2412  const Double_t kMaxRMS=0.05; // max distance -between point and local mean
2413  TVectorD *vecdY=0;
2414  TVectorD *vecdZ=0;
2415  TVectorD *veceY=0;
2416  TVectorD *veceZ=0;
2417  AliTPCLaserTrack *ltr=0;
2419  tree->SetBranchAddress("dY.",&vecdY);
2420  tree->SetBranchAddress("dZ.",&vecdZ);
2421  tree->SetBranchAddress("eY.",&veceY);
2422  tree->SetBranchAddress("eZ.",&veceZ);
2423  tree->SetBranchAddress("LTr.",&ltr);
2424  Int_t entries= tree->GetEntries();
2425  TTreeSRedirector *pcstream= new TTreeSRedirector("distortionLaser_0.root");
2426  Double_t bz=AliTrackerBase::GetBz();
2427  //
2428 
2429  for (Int_t ientry=0; ientry<entries; ientry++){
2430  tree->GetEntry(ientry);
2431  if (!ltr->GetVecGX()){
2432  ltr->UpdatePoints();
2433  }
2434  TVectorD * delta= (itype==0)? vecdY:vecdZ;
2435  TVectorD * err= (itype==0)? veceY:veceZ;
2436  TLinearFitter fitter(2,"pol1");
2437  for (Int_t iter=0; iter<2; iter++){
2438  Double_t kfit0=0, kfit1=0;
2439  Int_t npoints=fitter.GetNpoints();
2440  if (npoints>80){
2441  fitter.Eval();
2442  kfit0=fitter.GetParameter(0);
2443  kfit1=fitter.GetParameter(1);
2444  }
2445  for (Int_t irow=0; irow<159; irow++){
2446  Bool_t isOK=kTRUE;
2447  Int_t isOKF=0;
2448  Int_t nentries = 1000;
2449  if (veceY->GetMatrixArray()[irow]>cutErrY||veceZ->GetMatrixArray()[irow]>cutErrZ) nentries=0;
2450  if (veceY->GetMatrixArray()[irow]<kEpsilon||veceZ->GetMatrixArray()[irow]<kEpsilon) nentries=0;
2451  Int_t dtype=5;
2452  Double_t array[10];
2453  Int_t first3=TMath::Max(irow-3,0);
2454  Int_t last3 =TMath::Min(irow+3,159-1);
2455  Int_t counter=0;
2456  if ((*ltr->GetVecSec())[irow]>=0 && err) {
2457  for (Int_t jrow=first3; jrow<=last3; jrow++){
2458  if ((*ltr->GetVecSec())[irow]!= (*ltr->GetVecSec())[jrow]) continue;
2459  if ((*err)[jrow]<kEpsilon) continue;
2460  array[counter]=(*delta)[jrow];
2461  counter++;
2462  }
2463  }
2464  Double_t rms3 = 0;
2465  Double_t mean3 = 0;
2466  if (counter>2){
2467  rms3 = TMath::RMS(counter,array);
2468  mean3 = TMath::Mean(counter,array);
2469  }else{
2470  isOK=kFALSE;
2471  }
2472  Double_t phi =(*ltr->GetVecPhi())[irow];
2473  Double_t theta =ltr->GetTgl();
2474  Double_t mean=delta->GetMatrixArray()[irow];
2475  Double_t gx=0,gy=0,gz=0;
2476  Double_t snp = (*ltr->GetVecP2())[irow];
2477  Double_t dRrec=0;
2478  // Double_t rms = err->GetMatrixArray()[irow];
2479  //
2480  gx = (*ltr->GetVecGX())[irow];
2481  gy = (*ltr->GetVecGY())[irow];
2482  gz = (*ltr->GetVecGZ())[irow];
2483  //
2484  // get delta R used in reconstruction
2486  AliTPCCorrection * correction = calib->GetTPCComposedCorrection(AliTrackerBase::GetBz());
2487  // const AliTPCRecoParam * recoParam = calib->GetTransform()->GetCurrentRecoParam();
2488  //Double_t xyz0[3]={gx,gy,gz};
2489  Double_t oldR=TMath::Sqrt(gx*gx+gy*gy);
2490  Double_t fphi = TMath::ATan2(gy,gx);
2491  Double_t fsector = 9.*fphi/TMath::Pi();
2492  if (fsector<0) fsector+=18;
2493  Double_t dsec = fsector-Int_t(fsector)-0.5;
2494  Double_t refX=0;
2495  Int_t id= ltr->GetId();
2496  Double_t pt=0;
2497  //
2498  if (1 && oldR>1) {
2499  Float_t xyz1[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
2500  Int_t sector=(gz>0)?0:18;
2501  correction->CorrectPoint(xyz1, sector);
2502  refX=TMath::Sqrt(xyz1[0]*xyz1[0]+xyz1[1]*xyz1[1]);
2503  dRrec=oldR-refX;
2504  }
2505  if (TMath::Abs(rms3)>kMaxRMS) isOK=kFALSE;
2506  if (TMath::Abs(mean-mean3)>kMaxRMS) isOK=kFALSE;
2507  if (counter<4) isOK=kFALSE;
2508  if (npoints<90) isOK=kFALSE;
2509  if (isOK){
2510  fitter.AddPoint(&refX,mean);
2511  }
2512  Double_t deltaF=kfit0+kfit1*refX;
2513  if (iter==1){
2514  (*pcstream)<<"fitFull"<< // dumpe also intermediate results
2515  "bz="<<bz<< // magnetic filed used
2516  "dtype="<<dtype<< // detector match type
2517  "ptype="<<itype<< // parameter type
2518  "theta="<<theta<< // theta
2519  "phi="<<phi<< // phi
2520  "snp="<<snp<< // snp
2521  "mean="<<mean3<< // mean dist value
2522  "rms="<<rms3<< // rms
2523  "deltaF="<<deltaF<<
2524  "npoints="<<npoints<< //number of points
2525  "mean3="<<mean3<< // mean dist value
2526  "rms3="<<rms3<< // rms
2527  "counter="<<counter<<
2528  "sector="<<fsector<<
2529  "dsec="<<dsec<<
2530  //
2531  "refX="<<refX<< // reference radius
2532  "gx="<<gx<< // global position
2533  "gy="<<gy<< // global position
2534  "gz="<<gz<< // global position
2535  "dRrec="<<dRrec<< // delta Radius in reconstruction
2536  "id="<<id<< //bundle
2537  "entries="<<nentries<<// number of entries in bin
2538  "\n";
2539  }
2540  if (iter==1) (*pcstream)<<"fit"<< // dump valus for fit
2541  "bz="<<bz<< // magnetic filed used
2542  "dtype="<<dtype<< // detector match type
2543  "ptype="<<itype<< // parameter type
2544  "theta="<<theta<< // theta
2545  "phi="<<phi<< // phi
2546  "snp="<<snp<< // snp
2547  "mean="<<mean3<< // mean dist value
2548  "rms="<<rms3<< // rms
2549  "sector="<<fsector<<
2550  "dsec="<<dsec<<
2551  //
2552  "refX="<<refX<< // reference radius
2553  "gx="<<gx<< // global position
2554  "gy="<<gy<< // global position
2555  "gz="<<gz<< // global position
2556  "dRrec="<<dRrec<< // delta Radius in reconstruction
2557  "pt="<<pt<< //pt
2558  "id="<<id<< //bundle
2559  "entries="<<nentries;// number of entries in bin
2560  //
2561  //
2562  Double_t ky = TMath::Tan(TMath::ASin(snp));
2563  Int_t ncorr = corrArray->GetEntries();
2564  Double_t r0 = TMath::Sqrt(gx*gx+gy*gy);
2565  Double_t phi0 = TMath::ATan2(gy,gx);
2566  Double_t distortions[1000]={0};
2567  Double_t distortionsR[1000]={0};
2568  if (iter==1){
2569  for (Int_t icorr=0; icorr<ncorr; icorr++) {
2570  AliTPCCorrection *corr = (AliTPCCorrection*)corrArray->At(icorr);
2571  Float_t distPoint[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
2572  Int_t sector= (gz>0)? 0:18;
2573  if (r0>80){
2574  corr->DistortPoint(distPoint, sector);
2575  }
2576  // Double_t value=distPoint[2]-gz;
2577  if (itype==0 && r0>1){
2578  Double_t r1 = TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
2579  Double_t phi1 = TMath::ATan2(distPoint[1],distPoint[0]);
2580  Double_t drphi= r0*(phi1-phi0);
2581  Double_t dr = r1-r0;
2582  distortions[icorr] = drphi-ky*dr;
2583  distortionsR[icorr] = dr;
2584  }
2585  if (TMath::Abs(distortions[icorr])>kMaxDist) {isOKF=icorr+1; isOK=kFALSE; }
2586  if (TMath::Abs(distortionsR[icorr])>kMaxDist) {isOKF=icorr+1; isOK=kFALSE;}
2587  (*pcstream)<<"fit"<<
2588  Form("%s=",corr->GetName())<<distortions[icorr]; // dump correction value
2589  }
2590  (*pcstream)<<"fit"<<"isOK="<<isOK<<"\n";
2591  }
2592  }
2593  }
2594  }
2595  delete pcstream;
2596 }
2597 
2598 
2599 
2600 void AliTPCCorrection::MakeDistortionMap(THnSparse * his0, TTreeSRedirector * const pcstream, const char* hname, Int_t run, Float_t refX, Int_t type, Int_t integ){
2614 
2615  // marian.ivanov@cern.ch
2616  const Int_t kMinEntries=10;
2617  Double_t bz=AliTrackerBase::GetBz();
2618  Int_t idim[4]={0,1,2,3};
2619  //
2620  //
2621  //
2622  Int_t nbins3=his0->GetAxis(3)->GetNbins();
2623  Int_t first3=his0->GetAxis(3)->GetFirst();
2624  Int_t last3 =his0->GetAxis(3)->GetLast();
2625  //
2626  for (Int_t ibin3=first3; ibin3<last3; ibin3+=1){ // axis 3 - local angle
2627  his0->GetAxis(3)->SetRange(TMath::Max(ibin3-integ,1),TMath::Min(ibin3+integ,nbins3));
2628  Double_t x3= his0->GetAxis(3)->GetBinCenter(ibin3);
2629  THnSparse * his3= his0->Projection(3,idim); //projected histogram according selection 3
2630  //
2631  Int_t nbins2 = his3->GetAxis(2)->GetNbins();
2632  Int_t first2 = his3->GetAxis(2)->GetFirst();
2633  Int_t last2 = his3->GetAxis(2)->GetLast();
2634  //
2635  for (Int_t ibin2=first2; ibin2<last2; ibin2+=1){ // axis 2 - phi
2636  his3->GetAxis(2)->SetRange(TMath::Max(ibin2-integ,1),TMath::Min(ibin2+integ,nbins2));
2637  Double_t x2= his3->GetAxis(2)->GetBinCenter(ibin2);
2638  THnSparse * his2= his3->Projection(2,idim); //projected histogram according selection 2
2639  Int_t nbins1 = his2->GetAxis(1)->GetNbins();
2640  Int_t first1 = his2->GetAxis(1)->GetFirst();
2641  Int_t last1 = his2->GetAxis(1)->GetLast();
2642  for (Int_t ibin1=first1; ibin1<last1; ibin1++){ //axis 1 - theta
2643  //
2644  Double_t x1= his2->GetAxis(1)->GetBinCenter(ibin1);
2645  his2->GetAxis(1)->SetRange(TMath::Max(ibin1-1,1),TMath::Min(ibin1+1,nbins1));
2646  if (TMath::Abs(x1)<0.1){
2647  if (x1<0) his2->GetAxis(1)->SetRange(TMath::Max(ibin1-1,1),TMath::Min(ibin1,nbins1));
2648  if (x1>0) his2->GetAxis(1)->SetRange(TMath::Max(ibin1,1),TMath::Min(ibin1+1,nbins1));
2649  }
2650  if (TMath::Abs(x1)<0.06){
2651  his2->GetAxis(1)->SetRange(TMath::Max(ibin1,1),TMath::Min(ibin1,nbins1));
2652  }
2653  TH1 * hisDelta = his2->Projection(0);
2654  //
2655  Double_t entries = hisDelta->GetEntries();
2656  Double_t mean=0, rms=0;
2657  if (entries>kMinEntries){
2658  mean = hisDelta->GetMean();
2659  rms = hisDelta->GetRMS();
2660  }
2661  Double_t sector = 9.*x2/TMath::Pi();
2662  if (sector<0) sector+=18;
2663  Double_t dsec = sector-Int_t(sector)-0.5;
2664  Double_t z=refX*x1;
2665  (*pcstream)<<hname<<
2666  "run="<<run<<
2667  "bz="<<bz<<
2668  "theta="<<x1<<
2669  "phi="<<x2<<
2670  "z="<<z<< // dummy z
2671  "snp="<<x3<<
2672  "entries="<<entries<<
2673  "mean="<<mean<<
2674  "rms="<<rms<<
2675  "refX="<<refX<< // track matching refernce plane
2676  "type="<<type<< //
2677  "sector="<<sector<<
2678  "dsec="<<dsec<<
2679  "\n";
2680  delete hisDelta;
2681  //printf("%f\t%f\t%f\t%f\t%f\n",x3,x2,x1, entries,mean);
2682  }
2683  delete his2;
2684  }
2685  delete his3;
2686  }
2687 }
2688 
2689 
2690 
2691 
2692 void AliTPCCorrection::MakeDistortionMapCosmic(THnSparse * hisInput, TTreeSRedirector * const pcstream, const char* hname, Int_t run, Float_t refX, Int_t type){
2714 
2715  const Int_t kMinEntries=10;
2716  //
2717  // 1. make default selections
2718  //
2719  TH1 * hisDelta=0;
2720  Int_t idim0[4]={0 , 5, 8, 3}; // delta, theta, alpha, z
2721  hisInput->GetAxis(1)->SetRangeUser(110,190); //long tracks
2722  hisInput->GetAxis(2)->SetRangeUser(-10,35); //tracks close to beam pipe
2723  hisInput->GetAxis(4)->SetRangeUser(-0.3,0.3); //small snp at TPC entrance
2724  hisInput->GetAxis(7)->SetRangeUser(3,100); //"high pt tracks"
2725  hisDelta= hisInput->Projection(0);
2726  hisInput->GetAxis(0)->SetRangeUser(-6.*hisDelta->GetRMS(), +6.*hisDelta->GetRMS());
2727  delete hisDelta;
2728  THnSparse *his0= hisInput->Projection(4,idim0);
2729  //
2730  // 2. Get mean in diferent bins
2731  //
2732  Int_t nbins1=his0->GetAxis(1)->GetNbins();
2733  Int_t first1=his0->GetAxis(1)->GetFirst();
2734  Int_t last1 =his0->GetAxis(1)->GetLast();
2735  //
2736  Double_t bz=AliTrackerBase::GetBz();
2737  Int_t idim[4]={0,1, 2, 3}; // delta, theta,alpha,z
2738  //
2739  for (Int_t ibin1=first1; ibin1<=last1; ibin1++){ //axis 1 - theta
2740  //
2741  Double_t x1= his0->GetAxis(1)->GetBinCenter(ibin1);
2742  his0->GetAxis(1)->SetRange(TMath::Max(ibin1-1,1),TMath::Min(ibin1+1,nbins1));
2743  //
2744  THnSparse * his1 = his0->Projection(4,idim); // projected histogram according range1
2745  Int_t nbins3 = his1->GetAxis(3)->GetNbins();
2746  Int_t first3 = his1->GetAxis(3)->GetFirst();
2747  Int_t last3 = his1->GetAxis(3)->GetLast();
2748  //
2749  for (Int_t ibin3=first3-1; ibin3<=last3; ibin3+=1){ // axis 3 - z at "vertex"
2750  his1->GetAxis(3)->SetRange(TMath::Max(ibin3-1,1),TMath::Min(ibin3+1,nbins3));
2751  Double_t x3= his1->GetAxis(3)->GetBinCenter(ibin3);
2752  if (ibin3<first3) {
2753  his1->GetAxis(3)->SetRangeUser(-1,1);
2754  x3=0;
2755  }
2756  THnSparse * his3= his1->Projection(4,idim); //projected histogram according selection 3
2757  Int_t nbins2 = his3->GetAxis(2)->GetNbins();
2758  Int_t first2 = his3->GetAxis(2)->GetFirst();
2759  Int_t last2 = his3->GetAxis(2)->GetLast();
2760  //
2761  for (Int_t ibin2=first2; ibin2<=last2; ibin2+=1){
2762  his3->GetAxis(2)->SetRange(TMath::Max(ibin2-1,1),TMath::Min(ibin2+1,nbins2));
2763  Double_t x2= his3->GetAxis(2)->GetBinCenter(ibin2);
2764  hisDelta = his3->Projection(0);
2765  //
2766  Double_t entries = hisDelta->GetEntries();
2767  Double_t mean=0, rms=0;
2768  if (entries>kMinEntries){
2769  mean = hisDelta->GetMean();
2770  rms = hisDelta->GetRMS();
2771  }
2772  Double_t sector = 9.*x2/TMath::Pi();
2773  if (sector<0) sector+=18;
2774  Double_t dsec = sector-Int_t(sector)-0.5;
2775  Double_t snp=0; // dummy snp - equal 0
2776  (*pcstream)<<hname<<
2777  "run="<<run<<
2778  "bz="<<bz<< // magnetic field
2779  "theta="<<x1<< // theta
2780  "phi="<<x2<< // phi (alpha)
2781  "z="<<x3<< // z at "vertex"
2782  "snp="<<snp<< // dummy snp
2783  "entries="<<entries<< // entries in bin
2784  "mean="<<mean<< // mean
2785  "rms="<<rms<<
2786  "refX="<<refX<< // track matching refernce plane
2787  "type="<<type<< // parameter type
2788  "sector="<<sector<< // sector
2789  "dsec="<<dsec<< // dummy delta sector
2790  "\n";
2791  delete hisDelta;
2792  printf("%f\t%f\t%f\t%f\t%f\n",x1,x3,x2, entries,mean);
2793  }
2794  delete his3;
2795  }
2796  delete his1;
2797  }
2798  delete his0;
2799 }
2800 
2801 
2802 
2803 void AliTPCCorrection::MakeDistortionMapSector(THnSparse * hisInput, TTreeSRedirector * const pcstream, const char* hname, Int_t run, Int_t type){
2812 
2813  //Collection name='TObjArray', class='TObjArray', size=16
2814  //0 OBJ: TAxis delta delta
2815  //1 OBJ: TAxis phi phi
2816  //2 OBJ: TAxis localX localX
2817  //3 OBJ: TAxis kY kY
2818  //4 OBJ: TAxis kZ kZ
2819  //5 OBJ: TAxis is1 is1
2820  //6 OBJ: TAxis is0 is0
2821  //7. OBJ: TAxis z z
2822  //8. OBJ: TAxis IsPrimary IsPrimary
2823 
2824  const Int_t kMinEntries=10;
2825  THnSparse * hisSector0=0;
2826  TH1 * htemp=0; // histogram to calculate mean value of parameter
2827  Double_t bz=AliTrackerBase::GetBz();
2828 
2829  //
2830  // Loop over pair of sector:
2831  // isPrim - 8 ==> 8
2832  // isec0 - 6 ==> 7
2833  // isec1 - 5 ==> 6
2834  // refX - 2 ==> 5
2835  //
2836  // phi - 1 ==> 4
2837  // z - 7 ==> 3
2838  // snp - 3 ==> 2
2839  // theta- 4 ==> 1
2840  // 0 ==> 0;
2841  for (Int_t isec0=0; isec0<72; isec0++){
2842  Int_t index0[9]={0, 4, 3, 7, 1, 2, 5, 6,8}; //regroup indeces
2843  //
2844  //hisInput->GetAxis(8)->SetRangeUser(-0.1,0.4); // select secondaries only ? - get out later ?
2845  hisInput->GetAxis(6)->SetRangeUser(isec0-0.1,isec0+0.1);
2846  hisSector0=hisInput->Projection(7,index0);
2847  //
2848  //
2849  for (Int_t isec1=isec0+1; isec1<72; isec1++){
2850  //if (isec1!=isec0+36) continue;
2851  if ( TMath::Abs((isec0%18)-(isec1%18))>1.5 && TMath::Abs((isec0%18)-(isec1%18))<16.5) continue;
2852  printf("Sectors %d\t%d\n",isec1,isec0);
2853  hisSector0->GetAxis(6)->SetRangeUser(isec1-0.1,isec1+0.1);
2854  TH1 * hisX=hisSector0->Projection(5);
2855  Double_t refX= hisX->GetMean();
2856  delete hisX;
2857  TH1 *hisDelta=hisSector0->Projection(0);
2858  Double_t dmean = hisDelta->GetMean();
2859  Double_t drms = hisDelta->GetRMS();
2860  hisSector0->GetAxis(0)->SetRangeUser(dmean-5.*drms, dmean+5.*drms);
2861  delete hisDelta;
2862  //
2863  // 1. make default selections
2864  //
2865  Int_t idim0[5]={0 , 1, 2, 3, 4}; // {delta, theta, snp, z, phi }
2866  THnSparse *hisSector1= hisSector0->Projection(5,idim0);
2867  //
2868  // 2. Get mean in diferent bins
2869  //
2870  Int_t idim[5]={0, 1, 2, 3, 4}; // {delta, theta-1,snp-2 ,z-3, phi-4}
2871  //
2872  // Int_t nbinsPhi=hisSector1->GetAxis(4)->GetNbins();
2873  Int_t firstPhi=hisSector1->GetAxis(4)->GetFirst();
2874  Int_t lastPhi =hisSector1->GetAxis(4)->GetLast();
2875  //
2876  for (Int_t ibinPhi=firstPhi; ibinPhi<=lastPhi; ibinPhi+=1){ //axis 4 - phi
2877  //
2878  // Phi loop
2879  //
2880  Double_t xPhi= hisSector1->GetAxis(4)->GetBinCenter(ibinPhi);
2881  Double_t psec = (9*xPhi/TMath::Pi());
2882  if (psec<0) psec+=18;
2883  Bool_t isOK0=kFALSE;
2884  Bool_t isOK1=kFALSE;
2885  if (TMath::Abs(psec-isec0%18-0.5)<1. || TMath::Abs(psec-isec0%18-17.5)<1.) isOK0=kTRUE;
2886  if (TMath::Abs(psec-isec1%18-0.5)<1. || TMath::Abs(psec-isec1%18-17.5)<1.) isOK1=kTRUE;
2887  if (!isOK0) continue;
2888  if (!isOK1) continue;
2889  //
2890  hisSector1->GetAxis(4)->SetRange(TMath::Max(ibinPhi-2,firstPhi),TMath::Min(ibinPhi+2,lastPhi));
2891  if (isec1!=isec0+36) {
2892  hisSector1->GetAxis(4)->SetRange(TMath::Max(ibinPhi-3,firstPhi),TMath::Min(ibinPhi+3,lastPhi));
2893  }
2894  //
2895  htemp = hisSector1->Projection(4);
2896  xPhi=htemp->GetMean();
2897  delete htemp;
2898  THnSparse * hisPhi = hisSector1->Projection(4,idim);
2899  //Int_t nbinsZ = hisPhi->GetAxis(3)->GetNbins();
2900  Int_t firstZ = hisPhi->GetAxis(3)->GetFirst();
2901  Int_t lastZ = hisPhi->GetAxis(3)->GetLast();
2902  //
2903  for (Int_t ibinZ=firstZ; ibinZ<=lastZ; ibinZ+=1){ // axis 3 - z
2904  //
2905  // Z loop
2906  //
2907  hisPhi->GetAxis(3)->SetRange(TMath::Max(ibinZ,firstZ),TMath::Min(ibinZ,lastZ));
2908  if (isec1!=isec0+36) {
2909  hisPhi->GetAxis(3)->SetRange(TMath::Max(ibinZ-1,firstZ),TMath::Min(ibinZ-1,lastZ));
2910  }
2911  htemp = hisPhi->Projection(3);
2912  Double_t xZ= htemp->GetMean();
2913  delete htemp;
2914  THnSparse * hisZ= hisPhi->Projection(3,idim);
2915  //projected histogram according selection 3 -z
2916  //
2917  //
2918  //Int_t nbinsSnp = hisZ->GetAxis(2)->GetNbins();
2919  Int_t firstSnp = hisZ->GetAxis(2)->GetFirst();
2920  Int_t lastSnp = hisZ->GetAxis(2)->GetLast();
2921  for (Int_t ibinSnp=firstSnp; ibinSnp<=lastSnp; ibinSnp+=2){ // axis 2 - snp
2922  //
2923  // Snp loop
2924  //
2925  hisZ->GetAxis(2)->SetRange(TMath::Max(ibinSnp-1,firstSnp),TMath::Min(ibinSnp+1,lastSnp));
2926  if (isec1!=isec0+36) {
2927  hisZ->GetAxis(2)->SetRange(TMath::Max(ibinSnp-2,firstSnp),TMath::Min(ibinSnp+2,lastSnp));
2928  }
2929  htemp = hisZ->Projection(2);
2930  Double_t xSnp= htemp->GetMean();
2931  delete htemp;
2932  THnSparse * hisSnp= hisZ->Projection(2,idim);
2933  //projected histogram according selection 2 - snp
2934 
2935  //Int_t nbinsTheta = hisSnp->GetAxis(1)->GetNbins();
2936  Int_t firstTheta = hisSnp->GetAxis(1)->GetFirst();
2937  Int_t lastTheta = hisSnp->GetAxis(1)->GetLast();
2938  //
2939  for (Int_t ibinTheta=firstTheta; ibinTheta<=lastTheta; ibinTheta+=2){ // axis1 theta
2940 
2941 
2942  hisSnp->GetAxis(1)->SetRange(TMath::Max(ibinTheta-2,firstTheta),TMath::Min(ibinTheta+2,lastTheta));
2943  if (isec1!=isec0+36) {
2944  hisSnp->GetAxis(1)->SetRange(TMath::Max(ibinTheta-3,firstTheta),TMath::Min(ibinTheta+3,lastTheta));
2945  }
2946  htemp = hisSnp->Projection(1);
2947  Double_t xTheta=htemp->GetMean();
2948  delete htemp;
2949  hisDelta = hisSnp->Projection(0);
2950  //
2951  Double_t entries = hisDelta->GetEntries();
2952  Double_t mean=0, rms=0;
2953  if (entries>kMinEntries){
2954  mean = hisDelta->GetMean();
2955  rms = hisDelta->GetRMS();
2956  }
2957  Double_t sector = 9.*xPhi/TMath::Pi();
2958  if (sector<0) sector+=18;
2959  Double_t dsec = sector-Int_t(sector)-0.5;
2960  Int_t dtype=1; // TPC alignment type
2961  (*pcstream)<<hname<<
2962  "run="<<run<<
2963  "bz="<<bz<< // magnetic field
2964  "ptype="<<type<< // parameter type
2965  "dtype="<<dtype<< // parameter type
2966  "isec0="<<isec0<< // sector 0
2967  "isec1="<<isec1<< // sector 1
2968  "sector="<<sector<< // sector as float
2969  "dsec="<<dsec<< // delta sector
2970  //
2971  "theta="<<xTheta<< // theta
2972  "phi="<<xPhi<< // phi (alpha)
2973  "z="<<xZ<< // z
2974  "snp="<<xSnp<< // snp
2975  //
2976  "entries="<<entries<< // entries in bin
2977  "mean="<<mean<< // mean
2978  "rms="<<rms<< // rms
2979  "refX="<<refX<< // track matching reference plane
2980  "\n";
2981  delete hisDelta;
2982  printf("%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f\n",isec0, isec1, xPhi,xZ,xSnp, xTheta, entries,mean);
2983  //
2984  }//ibinTheta
2985  delete hisSnp;
2986  } //ibinSnp
2987  delete hisZ;
2988  }//ibinZ
2989  delete hisPhi;
2990  }//ibinPhi
2991  delete hisSector1;
2992  }//isec1
2993  delete hisSector0;
2994  }//isec0
2995 }
2996 
2997 
2998 
2999 
3000 
3001 
3002 
3003 void AliTPCCorrection::StoreInOCDB(Int_t startRun, Int_t endRun, const char *comment){
3007 
3008  TString ocdbStorage="";
3009  ocdbStorage+="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
3010  AliCDBMetaData *metaData= new AliCDBMetaData();
3011  metaData->SetObjectClassName("AliTPCCorrection");
3012  metaData->SetResponsible("Marian Ivanov");
3013  metaData->SetBeamPeriod(1);
3014  metaData->SetAliRootVersion("05-25-01"); //root version
3015  TString userName=gSystem->GetFromPipe("echo $USER");
3016  TString date=gSystem->GetFromPipe("date");
3017 
3018  if (!comment) metaData->SetComment(Form("Space point distortion calibration\n User: %s\n Data%s",userName.Data(),date.Data()));
3019  if (comment) metaData->SetComment(comment);
3020  AliCDBId* id1=NULL;
3021  id1=new AliCDBId("TPC/Calib/Correction", startRun, endRun);
3022  AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
3023  gStorage->Put(this, (*id1), metaData);
3024 }
3025 
3026 
3027 void AliTPCCorrection::FastSimDistortedVertex(Double_t orgVertex[3], Int_t nTracks, AliESDVertex &aV, AliESDVertex &avOrg, AliESDVertex &cV, AliESDVertex &cvOrg, TTreeSRedirector * const pcstream, Double_t etaCuts){
3029 
3030  AliMagF* magF= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
3031  if (!magF) AliError("Magneticd field - not initialized");
3032  Double_t bz = magF->SolenoidField(); //field in kGauss
3033  printf("bz: %f\n",bz);
3034  AliVertexerTracks *vertexer = new AliVertexerTracks(bz); // bz in kGauss
3035 
3036  TObjArray aTrk; // Original Track array of Aside
3037  TObjArray daTrk; // Distorted Track array of A side
3038  UShort_t *aId = new UShort_t[nTracks]; // A side Track ID
3039  TObjArray cTrk;
3040  TObjArray dcTrk;
3041  UShort_t *cId = new UShort_t [nTracks];
3042  Int_t id=0;
3043  Double_t mass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
3044  TF1 fpt("fpt",Form("x*(1+(sqrt(x*x+%f^2)-%f)/([0]*[1]))^(-[0])",mass,mass),0.4,10);
3045  fpt.SetParameters(7.24,0.120);
3046  fpt.SetNpx(10000);
3047  for(Int_t nt=0; nt<nTracks; nt++){
3048  Double_t phi = gRandom->Uniform(0.0, 2*TMath::Pi());
3049  Double_t eta = gRandom->Uniform(-etaCuts, etaCuts);
3050  Double_t pt = fpt.GetRandom(); // momentum for f1
3051  // printf("phi %lf eta %lf pt %lf\n",phi,eta,pt);
3052  Short_t sign=1;
3053  if(gRandom->Rndm() < 0.5){
3054  sign =1;
3055  }else{
3056  sign=-1;
3057  }
3058 
3059  Double_t theta = 2*TMath::ATan(TMath::Exp(-eta))-TMath::Pi()/2.;
3060  Double_t pxyz[3];
3061  pxyz[0]=pt*TMath::Cos(phi);
3062  pxyz[1]=pt*TMath::Sin(phi);
3063  pxyz[2]=pt*TMath::Tan(theta);
3064  Double_t cv[21]={0};
3065  AliExternalTrackParam *t= new AliExternalTrackParam(orgVertex, pxyz, cv, sign);
3066 
3067  Double_t refX=1.;
3068  Int_t dir=-1;
3069  AliExternalTrackParam *td = FitDistortedTrack(*t, refX, dir, NULL);
3070  if (!td) continue;
3071  if (pcstream) (*pcstream)<<"track"<<
3072  "eta="<<eta<<
3073  "theta="<<theta<<
3074  "tOrig.="<<t<<
3075  "td.="<<td<<
3076  "\n";
3077  if(( eta>0.07 )&&( eta<etaCuts )) { // - log(tan(0.5*theta)), theta = 0.5*pi - ATan(5.0/80.0)
3078  if (td){
3079  daTrk.AddLast(td);
3080  aTrk.AddLast(t);
3081  Int_t nn=aTrk.GetEntriesFast();
3082  aId[nn]=id;
3083  }
3084  }else if(( eta<-0.07 )&&( eta>-etaCuts )){
3085  if (td){
3086  dcTrk.AddLast(td);
3087  cTrk.AddLast(t);
3088  Int_t nn=cTrk.GetEntriesFast();
3089  cId[nn]=id;
3090  }
3091  }
3092  id++;
3093  }// end of track loop
3094 
3095  vertexer->SetTPCMode();
3096  vertexer->SetConstraintOff();
3097 
3098  aV = *((AliESDVertex*)vertexer->FindPrimaryVertex(&daTrk,aId));
3099  avOrg = *((AliESDVertex*)vertexer->FindPrimaryVertex(&aTrk,aId));
3100  cV = *((AliESDVertex*)vertexer->FindPrimaryVertex(&dcTrk,cId));
3101  cvOrg = *((AliESDVertex*)vertexer->FindPrimaryVertex(&cTrk,cId));
3102  if (pcstream) (*pcstream)<<"vertex"<<
3103  "x="<<orgVertex[0]<<
3104  "y="<<orgVertex[1]<<
3105  "z="<<orgVertex[2]<<
3106  "av.="<<&aV<< // distorted vertex A side
3107  "cv.="<<&cV<< // distroted vertex C side
3108  "avO.="<<&avOrg<< // original vertex A side
3109  "cvO.="<<&cvOrg<<
3110  "\n";
3111  delete []aId;
3112  delete []cId;
3113 }
3114 
3122 
3124  if (position>=fgVisualCorrection->GetEntriesFast())
3125  fgVisualCorrection->Expand((position+10)*2);
3126  fgVisualCorrection->AddAt(corr, position);
3127 }
3128 
3131 
3132  return fgVisualCorrection? (AliTPCCorrection*)fgVisualCorrection->At(position):0;
3133 }
3134 
3135 
3136 
3137 Double_t AliTPCCorrection::GetCorrSector(Double_t sector, Double_t r, Double_t kZ, Int_t axisType, Int_t corrType){
3145 
3146  if (!fgVisualCorrection) return 0;
3147  AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
3148  if (!corr) return 0;
3149 
3150  Double_t phi=sector*TMath::Pi()/9.;
3151  Double_t gx = r*TMath::Cos(phi);
3152  Double_t gy = r*TMath::Sin(phi);
3153  Double_t gz = r*kZ;
3154  Int_t nsector=(gz>=0) ? 0:18;
3155  //
3156  //
3157  //
3158  Float_t distPoint[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3159  corr->DistortPoint(distPoint, nsector);
3160  Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
3161  Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
3162  Double_t phi0=TMath::ATan2(gy,gx);
3163  Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
3164  if (axisType==0) return r1-r0;
3165  if (axisType==1) return (phi1-phi0)*r0;
3166  if (axisType==2) return distPoint[2]-gz;
3167  if (axisType==3) return (TMath::Cos(phi)*(distPoint[0]-gx)+ TMath::Cos(phi)*(distPoint[1]-gy));
3168  return phi1-phi0;
3169 }
3170 
3171 Double_t AliTPCCorrection::GetCorrectionSector(Double_t sector, Double_t r, Double_t kZ, Int_t axisType, Int_t corrType)
3172 {
3180 
3181  if (!fgVisualCorrection) return 0;
3182  AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
3183  if (!corr) return 0;
3184 
3185  Double_t phi=sector*TMath::Pi()/9.;
3186  Double_t gx = r*TMath::Cos(phi);
3187  Double_t gy = r*TMath::Sin(phi);
3188  Double_t gz = r*kZ;
3189  Int_t nsector=(gz>=0) ? 0:18;
3190  //
3191  //
3192  //
3193  Float_t distPoint[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3194  corr->CorrectPoint(distPoint, nsector);
3195  Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
3196  Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
3197  Double_t phi0=TMath::ATan2(gy,gx);
3198  Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
3199  if (axisType==0) return r1-r0;
3200  if (axisType==1) return (phi1-phi0)*r0;
3201  if (axisType==2) return distPoint[2]-gz;
3202  if (axisType==3) return (TMath::Cos(phi)*(distPoint[0]-gx)+ TMath::Cos(phi)*(distPoint[1]-gy));
3203  return phi1-phi0;
3204 }
3205 
3206 Double_t AliTPCCorrection::GetDistortionSector(Double_t sector, Double_t r, Double_t kZ, Int_t axisType, Int_t corrType)
3207 {
3215 
3216  if (!fgVisualCorrection) return 0;
3217  AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
3218  if (!corr) return 0;
3219 
3220  Double_t phi=sector*TMath::Pi()/9.;
3221  Double_t gx = r*TMath::Cos(phi);
3222  Double_t gy = r*TMath::Sin(phi);
3223  Double_t gz = r*kZ;
3224  Int_t nsector=(gz>=0) ? 0:18;
3225  //
3226  //
3227  //
3228  Float_t distPoint[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3229  corr->DistortPoint(distPoint, nsector);
3230  Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
3231  Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
3232  Double_t phi0=TMath::ATan2(gy,gx);
3233  Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
3234  if (axisType==0) return r1-r0;
3235  if (axisType==1) return (phi1-phi0)*r0;
3236  if (axisType==2) return distPoint[2]-gz;
3237  if (axisType==3) return (TMath::Cos(phi)*(distPoint[0]-gx)+ TMath::Cos(phi)*(distPoint[1]-gy));
3238  return phi1-phi0;
3239 }
3240 
3241 Double_t AliTPCCorrection::GetCorrXYZ(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType){
3243 
3244  if (!fgVisualCorrection) return 0;
3245  AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
3246  if (!corr) return 0;
3247  Double_t phi0= TMath::ATan2(gy,gx);
3248  Int_t nsector=(gz>=0) ? 0:18;
3249  Float_t distPoint[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3250  corr->CorrectPoint(distPoint, nsector);
3251  Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
3252  Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
3253  Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
3254  if (axisType==0) return r1-r0;
3255  if (axisType==1) return (phi1-phi0)*r0;
3256  if (axisType==2) return distPoint[2]-gz;
3257  return phi1-phi0;
3258 }
3259 
3260 Double_t AliTPCCorrection::GetCorrXYZDz(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType,Double_t delta){
3262 
3263  if (!fgVisualCorrection) return 0;
3264  AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
3265  if (!corr) return 0;
3266  Double_t phi0= TMath::ATan2(gy,gx);
3267  Int_t nsector=(gz>=0) ? 0:18;
3268  Float_t distPoint[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3269  Float_t dxyz[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3270  //
3271  corr->GetCorrectionDz(distPoint, nsector,dxyz,delta);
3272  distPoint[0]+=dxyz[0];
3273  distPoint[1]+=dxyz[1];
3274  distPoint[2]+=dxyz[2];
3275  Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
3276  Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
3277  Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
3278  if (axisType==0) return r1-r0;
3279  if (axisType==1) return (phi1-phi0)*r0;
3280  if (axisType==2) return distPoint[2]-gz;
3281  return phi1-phi0;
3282 }
3283 
3284 Double_t AliTPCCorrection::GetCorrXYZIntegrateZ(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType,Double_t delta){
3286 
3287  if (!fgVisualCorrection) return 0;
3288  AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
3289  if (!corr) return 0;
3290  Double_t phi0= TMath::ATan2(gy,gx);
3291  Int_t nsector=(gz>=0) ? 0:18;
3292  Float_t distPoint[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3293  Float_t dxyz[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3294  //
3295  corr->GetCorrectionIntegralDz(distPoint, nsector,dxyz,delta);
3296  distPoint[0]+=dxyz[0];
3297  distPoint[1]+=dxyz[1];
3298  distPoint[2]+=dxyz[2];
3299  Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
3300  Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
3301  Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
3302  if (axisType==0) return r1-r0;
3303  if (axisType==1) return (phi1-phi0)*r0;
3304  if (axisType==2) return distPoint[2]-gz;
3305  return phi1-phi0;
3306 }
3307 
3308 
3309 Double_t AliTPCCorrection::GetDistXYZ(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType){
3311 
3312  if (!fgVisualCorrection) return 0;
3313  AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
3314  if (!corr) return 0;
3315  Double_t phi0= TMath::ATan2(gy,gx);
3316  Int_t nsector=(gz>=0) ? 0:18;
3317  Float_t distPoint[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3318  corr->DistortPoint(distPoint, nsector);
3319  Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
3320  Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
3321  Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
3322  if (axisType==0) return r1-r0;
3323  if (axisType==1) return (phi1-phi0)*r0;
3324  if (axisType==2) return distPoint[2]-gz;
3325  return phi1-phi0;
3326 }
3327 
3328 Double_t AliTPCCorrection::GetDistXYZDz(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType,Double_t delta){
3330 
3331  if (!fgVisualCorrection) return 0;
3332  AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
3333  if (!corr) return 0;
3334  Double_t phi0= TMath::ATan2(gy,gx);
3335  Int_t nsector=(gz>=0) ? 0:18;
3336  Float_t distPoint[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3337  Float_t dxyz[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3338  //
3339  corr->GetDistortionDz(distPoint, nsector,dxyz,delta);
3340  distPoint[0]+=dxyz[0];
3341  distPoint[1]+=dxyz[1];
3342  distPoint[2]+=dxyz[2];
3343  Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
3344  Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
3345  Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
3346  if (axisType==0) return r1-r0;
3347  if (axisType==1) return (phi1-phi0)*r0;
3348  if (axisType==2) return distPoint[2]-gz;
3349  return phi1-phi0;
3350 }
3351 
3352 Double_t AliTPCCorrection::GetDistXYZIntegrateZ(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType,Double_t delta){
3354 
3355  if (!fgVisualCorrection) return 0;
3356  AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
3357  if (!corr) return 0;
3358  Double_t phi0= TMath::ATan2(gy,gx);
3359  Int_t nsector=(gz>=0) ? 0:18;
3360  Float_t distPoint[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3361  Float_t dxyz[3]={static_cast<Float_t>(gx),static_cast<Float_t>(gy),static_cast<Float_t>(gz)};
3362  //
3363  corr->GetDistortionIntegralDz(distPoint, nsector,dxyz,delta);
3364  distPoint[0]+=dxyz[0];
3365  distPoint[1]+=dxyz[1];
3366  distPoint[2]+=dxyz[2];
3367  Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
3368  Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
3369  Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
3370  if (axisType==0) return r1-r0;
3371  if (axisType==1) return (phi1-phi0)*r0;
3372  if (axisType==2) return distPoint[2]-gz;
3373  return phi1-phi0;
3374 }
3375 
3376 
3377 
3378 void AliTPCCorrection::MakeLaserDistortionTree(TTree* tree, TObjArray */*corrArray*/, Int_t /*itype*/){
3380 
3382  AliTPCCorrection * correction = calib->GetTPCComposedCorrection();
3383  if (!correction) correction = calib->GetTPCComposedCorrection(AliTrackerBase::GetBz());
3384  correction->AddVisualCorrection(correction,0); //register correction
3385 
3386  // AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
3387  //AliTPCParam *param = AliTPCcalibDB::Instance()->GetParameters();
3388  //
3389  const Double_t cutErrY=0.05;
3390  const Double_t kSigmaCut=4;
3391  // const Double_t cutErrZ=0.03;
3392  const Double_t kEpsilon=0.00000001;
3393  // const Double_t kMaxDist=1.; // max distance - space correction
3394  TVectorD *vecdY=0;
3395  TVectorD *vecdZ=0;
3396  TVectorD *veceY=0;
3397  TVectorD *veceZ=0;
3398  AliTPCLaserTrack *ltr=0;
3400  tree->SetBranchAddress("dY.",&vecdY);
3401  tree->SetBranchAddress("dZ.",&vecdZ);
3402  tree->SetBranchAddress("eY.",&veceY);
3403  tree->SetBranchAddress("eZ.",&veceZ);
3404  tree->SetBranchAddress("LTr.",&ltr);
3405  Int_t entries= tree->GetEntries();
3406  TTreeSRedirector *pcstream= new TTreeSRedirector("distortionLaser_0.root");
3407  Double_t bz=AliTrackerBase::GetBz();
3408  //
3409  // Double_t globalXYZ[3];
3410  //Double_t globalXYZCorr[3];
3411  for (Int_t ientry=0; ientry<entries; ientry++){
3412  tree->GetEntry(ientry);
3413  if (!ltr->GetVecGX()){
3414  ltr->UpdatePoints();
3415  }
3416  //
3417  TVectorD fit10(5);
3418  TVectorD fit5(5);
3419  printf("Entry\t%d\n",ientry);
3420  for (Int_t irow0=0; irow0<158; irow0+=1){
3421  //
3422  TLinearFitter fitter10(4,"hyp3");
3423  TLinearFitter fitter5(2,"hyp1");
3424  Int_t sector= (Int_t)(*ltr->GetVecSec())[irow0];
3425  if (sector<0) continue;
3426  //if (TMath::Abs(vecdY->GetMatrixArray()[irow0])<kEpsilon) continue;
3427 
3428  Double_t refX= (*ltr->GetVecLX())[irow0];
3429  Int_t firstRow1 = TMath::Max(irow0-10,0);
3430  Int_t lastRow1 = TMath::Min(irow0+10,158);
3431  Double_t padWidth=(irow0<64)?0.4:0.6;
3432  // make long range fit
3433  for (Int_t irow1=firstRow1; irow1<=lastRow1; irow1++){
3434  if (TMath::Abs((*ltr->GetVecSec())[irow1]-sector)>kEpsilon) continue;
3435  if (veceY->GetMatrixArray()[irow1]>cutErrY) continue;
3436  if (TMath::Abs(vecdY->GetMatrixArray()[irow1])<kEpsilon) continue;
3437  Double_t idealX= (*ltr->GetVecLX())[irow1];
3438  Double_t idealY= (*ltr->GetVecLY())[irow1];
3439  // Double_t idealZ= (*ltr->GetVecLZ())[irow1];
3440  Double_t gx= (*ltr->GetVecGX())[irow1];
3441  Double_t gy= (*ltr->GetVecGY())[irow1];
3442  Double_t gz= (*ltr->GetVecGZ())[irow1];
3443  Double_t measY=(*vecdY)[irow1]+idealY;
3444  Double_t deltaR = GetCorrXYZ(gx, gy, gz, 0,0);
3445  // deltaR = R distorted -R ideal
3446  Double_t xxx[4]={idealX+deltaR-refX,TMath::Cos(idealY/padWidth), TMath::Sin(idealY/padWidth)};
3447  fitter10.AddPoint(xxx,measY,1);
3448  }
3449  Bool_t isOK=kTRUE;
3450  Double_t rms10=0;//TMath::Sqrt(fitter10.GetChisquare()/(fitter10.GetNpoints()-4));
3451  Double_t mean10 =0;// fitter10.GetParameter(0);
3452  Double_t slope10 =0;// fitter10.GetParameter(0);
3453  Double_t cosPart10 = 0;// fitter10.GetParameter(2);
3454  Double_t sinPart10 =0;// fitter10.GetParameter(3);
3455 
3456  if (fitter10.GetNpoints()>10){
3457  fitter10.Eval();
3458  rms10=TMath::Sqrt(fitter10.GetChisquare()/(fitter10.GetNpoints()-4));
3459  mean10 = fitter10.GetParameter(0);
3460  slope10 = fitter10.GetParameter(1);
3461  cosPart10 = fitter10.GetParameter(2);
3462  sinPart10 = fitter10.GetParameter(3);
3463  //
3464  // make short range fit
3465  //
3466  for (Int_t irow1=firstRow1+5; irow1<=lastRow1-5; irow1++){
3467  if (TMath::Abs((*ltr->GetVecSec())[irow1]-sector)>kEpsilon) continue;
3468  if (veceY->GetMatrixArray()[irow1]>cutErrY) continue;
3469  if (TMath::Abs(vecdY->GetMatrixArray()[irow1])<kEpsilon) continue;
3470  Double_t idealX= (*ltr->GetVecLX())[irow1];
3471  Double_t idealY= (*ltr->GetVecLY())[irow1];
3472  // Double_t idealZ= (*ltr->GetVecLZ())[irow1];
3473  Double_t gx= (*ltr->GetVecGX())[irow1];
3474  Double_t gy= (*ltr->GetVecGY())[irow1];
3475  Double_t gz= (*ltr->GetVecGZ())[irow1];
3476  Double_t measY=(*vecdY)[irow1]+idealY;
3477  Double_t deltaR = GetCorrXYZ(gx, gy, gz, 0,0);
3478  // deltaR = R distorted -R ideal
3479  Double_t expY= mean10+slope10*(idealX+deltaR-refX);
3480  if (TMath::Abs(measY-expY)>kSigmaCut*rms10) continue;
3481  //
3482  Double_t corr=cosPart10*TMath::Cos(idealY/padWidth)+sinPart10*TMath::Sin(idealY/padWidth);
3483  Double_t xxx[4]={idealX+deltaR-refX,TMath::Cos(idealY/padWidth), TMath::Sin(idealY/padWidth)};
3484  fitter5.AddPoint(xxx,measY-corr,1);
3485  }
3486  }else{
3487  isOK=kFALSE;
3488  }
3489  if (fitter5.GetNpoints()<8) isOK=kFALSE;
3490 
3491  Double_t rms5=0;//TMath::Sqrt(fitter5.GetChisquare()/(fitter5.GetNpoints()-4));
3492  Double_t offset5 =0;// fitter5.GetParameter(0);
3493  Double_t slope5 =0;// fitter5.GetParameter(0);
3494  if (isOK){
3495  fitter5.Eval();
3496  rms5=TMath::Sqrt(fitter5.GetChisquare()/(fitter5.GetNpoints()-4));
3497  offset5 = fitter5.GetParameter(0);
3498  slope5 = fitter5.GetParameter(0);
3499  }
3500  //
3501  Double_t dtype=5;
3502  Double_t ptype=0;
3503  Double_t phi =(*ltr->GetVecPhi())[irow0];
3504  Double_t theta =ltr->GetTgl();
3505  Double_t mean=(vecdY)->GetMatrixArray()[irow0];
3506  Double_t gx=0,gy=0,gz=0;
3507  Double_t snp = (*ltr->GetVecP2())[irow0];
3508  Int_t bundle= ltr->GetBundle();
3509  Int_t id= ltr->GetId();
3510  // Double_t rms = err->GetMatrixArray()[irow];
3511  //
3512  gx = (*ltr->GetVecGX())[irow0];
3513  gy = (*ltr->GetVecGY())[irow0];
3514  gz = (*ltr->GetVecGZ())[irow0];
3515  Double_t dRrec = GetCorrXYZ(gx, gy, gz, 0,0);
3516  fitter10.GetParameters(fit10);
3517  fitter5.GetParameters(fit5);
3518  Double_t idealY= (*ltr->GetVecLY())[irow0];
3519  Double_t measY=(*vecdY)[irow0]+idealY;
3520  Double_t corr=cosPart10*TMath::Cos(idealY/padWidth)+sinPart10*TMath::Sin(idealY/padWidth);
3521  if (TMath::Max(rms5,rms10)>0.06) isOK=kFALSE;
3522  //
3523  (*pcstream)<<"fitFull"<< // dumpe also intermediate results
3524  "bz="<<bz<< // magnetic filed used
3525  "dtype="<<dtype<< // detector match type
3526  "ptype="<<ptype<< // parameter type
3527  "theta="<<theta<< // theta
3528  "phi="<<phi<< // phi
3529  "snp="<<snp<< // snp
3530  "sector="<<sector<<
3531  "bundle="<<bundle<<
3532 // // "dsec="<<dsec<<
3533  "refX="<<refX<< // reference radius
3534  "gx="<<gx<< // global position
3535  "gy="<<gy<< // global position
3536  "gz="<<gz<< // global position
3537  "dRrec="<<dRrec<< // delta Radius in reconstruction
3538  "id="<<id<< //bundle
3539  "rms10="<<rms10<<
3540  "rms5="<<rms5<<
3541  "fit10.="<<&fit10<<
3542  "fit5.="<<&fit5<<
3543  "measY="<<measY<<
3544  "mean="<<mean<<
3545  "idealY="<<idealY<<
3546  "corr="<<corr<<
3547  "isOK="<<isOK<<
3548  "\n";
3549  }
3550  }
3551  delete pcstream;
3552 }
static AliTPCcalibDB * Instance()
static Double_t GetDistXYZ(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType=0)
AliExternalTrackParam * FitDistortedTrack(AliExternalTrackParam &trackIn, Double_t refX, Int_t dir, TTreeSRedirector *pcstream)
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
const Double_t kEpsilon
void DistortPointLocal(Float_t x[], Short_t roc)
static Double_t GetDistortionSector(Double_t sector, Double_t r, Double_t kZ, Int_t axisType, Int_t corrType=0)
Double_t fgkZList[kNZ]
points in the z direction (for the lookup table)
void CorrectPoint(Float_t x[], Short_t roc)
sector
Definition: AliFMDv1.cxx:91
virtual void Print(Option_t *option="") const
Manager and of geomety classes for set: TPC.
Definition: AliTPCParamSR.h:15
#define TObjArray
static void LoadTracks()
Class providing the calibration parameters by accessing the CDB.
Definition: AliTPCcalibDB.h:43
static Double_t GetCorrSector(Double_t sector, Double_t r, Double_t kZ, Int_t axisType, Int_t corrType=0)
Manager and of geomety classes for set: TPC.
Definition: AliTPCParam.h:18
static Double_t GetDistXYZIntegrateZ(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType=0, Double_t delta=5)
UInt_t GetNRows(UInt_t sector) const
Definition: AliTPCROC.h:28
Double_t Interpolate3DTable(Int_t order, Double_t x, Double_t y, Double_t z, Int_t nx, Int_t ny, Int_t nz, const Double_t xv[], const Double_t yv[], const Double_t zv[], TMatrixD **arrayofArrays)
static Double_t GetCorrectionSector(Double_t sector, Double_t r, Double_t kZ, Int_t axisType, Int_t corrType=0)
Int_t GetBundle() const
static TString comment
Definition: ConfigCosmic.C:131
const TVectorD * GetVecGX() const
TFile f("CalibObjects.root")
virtual void SetOmegaTauT1T2(Float_t omegaTau, Float_t t1, Float_t t2)
static const Double_t fgkOFCRadius
Mean Radius of the Outer Field Cage (252.55 min, 256.45 max) (cm)
virtual Bool_t AddCorrectionCompact(AliTPCCorrection *corr, Double_t weight)
const TVectorD * GetVecGY() const
TH2F * CreateHistoDRPhiinXY(Float_t z=10., Int_t nx=100, Int_t nphi=100)
TTreeSRedirector * pcstream
virtual void GetDistortion(const Float_t x[], Short_t roc, Float_t dx[])
AliTPCfastTrack * track
static Double_t GetCorrXYZ(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType=0)
static void MakeSectorDistortionTree(TTree *tinput, Int_t dtype, Int_t ptype, const TObjArray *corrArray, Int_t step=1, Int_t offset=0, Bool_t debug=0)
TH2F * CreateHistoDRPhiinZR(Float_t phi=0., Int_t nZ=100, Int_t nR=100)
TTree * tree
virtual Int_t IsPowerOfTwo(Int_t i) const
TH2F * CreateHistoDRinZR(Float_t phi=0., Int_t nZ=100, Int_t nR=100)
npoints
Definition: driftITSTPC.C:85
Double_t fT1
tensor term of wt - T1
TObjArray * array
Definition: AnalyzeLaser.C:12
void PoissonRelaxation2D(TMatrixD &arrayV, TMatrixD &chargeDensity, TMatrixD &arrayErOverEz, TMatrixD &arrayDeltaEz, Int_t rows, Int_t columns, Int_t iterations, Bool_t rocDisplacement=kTRUE)
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Double_t t
Definition: AliFMDv1.cxx:90
virtual void GetDistortionIntegralDz(const Float_t x[], Short_t roc, Float_t dx[], Float_t delta)
AliTPCCorrection class.
void sum()
const TVectorD * GetVecLX() const
void CorrectPointLocal(Float_t x[], Short_t roc)
void Interpolate3DEdistortion(Int_t order, Double_t r, Float_t phi, Double_t z, const Double_t er[kNZ][kNPhi][kNR], const Double_t ephi[kNZ][kNPhi][kNR], const Double_t ez[kNZ][kNPhi][kNR], Double_t &erValue, Double_t &ephiValue, Double_t &ezValue)
const TVectorD * GetVecLY() const
Int_t GetId() const
Surveyed Laser Track positions.
TH2F * CreateTH2F(const char *name, const char *title, const char *xlabel, const char *ylabel, const char *zlabel, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, Double_t ylow, Double_t yup)
static const Double_t fgkTPCZ0
nominal gating grid position
virtual void GetCorrectionDz(const Float_t x[], Short_t roc, Float_t dx[], Float_t delta)
Double_t Interpolate2DTable(Int_t order, Double_t x, Double_t y, Int_t nx, Int_t ny, const Double_t xv[], const Double_t yv[], const TMatrixD &array)
Geometry class for a single ROC.
Definition: AliTPCROC.h:14
static void MakeTrackDistortionTree(TTree *tinput, Int_t dtype, Int_t ptype, const TObjArray *corrArray, Int_t step=1, Int_t offset=0, Bool_t debug=0)
const TVectorD * GetVecPhi() const
static void MakeDistortionMapSector(THnSparse *his0, TTreeSRedirector *pcstream, const char *hname, Int_t run, Int_t type)
Int_t fKLow
variable to help in the interpolation
static void MakeLaserDistortionTree(TTree *tree, TObjArray *corrArray, Int_t itype)
const Float_t kSigmaCut
TObject * htemp
Definition: PlotSys.C:37
void Search(Int_t n, const Double_t xArray[], Double_t x, Int_t &low)
static AliTPCCorrection * GetVisualCorrection(Int_t position)
Double_t theta
Definition: AliFMDv1.cxx:78
static Double_t GetCorrXYZDz(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType=0, Double_t delta=5)
static void AddVisualCorrection(AliTPCCorrection *corr, Int_t position)
Double_t Interpolate(const Double_t xArray[], const Double_t yArray[], Int_t order, Double_t x)
AliTPCCorrection * GetTPCComposedCorrection() const
Definition: AliTPCcalibDB.h:73
TH2F * CreateHistoDZinXY(Float_t z=10., Int_t nx=100, Int_t ny=100)
TTree * CreateDistortionTree(Double_t step=5, Int_t type=0)
static void MakeDistortionMapCosmic(THnSparse *his0, TTreeSRedirector *pcstream, const char *hname, Int_t run, Float_t refX, Int_t type)
static TObjArray * fgVisualCorrection
array of orrection for visualization
void DistortPoint(Float_t x[], Short_t roc)
TH2F * CreateHistoDRinXY(Float_t z=10., Int_t nx=100, Int_t ny=100)
static const Double_t fgkCathodeV
Cathode Voltage (volts)
const TVectorD * GetVecGZ() const
IntegrationType fIntegrationType
Presentation of the underlying corrections, integrated, or differential.
Double_t fgkPhiList[kNPhi]
points in the phi direction (for the lookup table)
virtual void GetCorrection(const Float_t x[], Short_t roc, Float_t dx[])
void Interpolate2DEdistortion(Int_t order, Double_t r, Double_t z, const Double_t er[kNZ][kNR], Double_t &erValue)
Double_t phi
Definition: AliFMDv1.cxx:88
void FastSimDistortedVertex(Double_t orgVertex[3], Int_t nTracks, AliESDVertex &aV, AliESDVertex &avOrg, AliESDVertex &cV, AliESDVertex &cvOrg, TTreeSRedirector *const pcstream, Double_t etaCuts)
static const Double_t fgkGG
Gating Grid voltage (volts)
void StoreInOCDB(Int_t startRun, Int_t endRun, const char *comment=0)
Double_t fT2
tensor term of wt - T2
static AliMagF::BMap_t mag
Double_t fgkRList[kNR]
points in the radial direction (for the lookup table)
static Double_t GetDistXYZDz(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType=0, Double_t delta=5)
virtual void GetDistortionDz(const Float_t x[], Short_t roc, Float_t dx[], Float_t delta)
static void MakeDistortionMap(THnSparse *his0, TTreeSRedirector *pcstream, const char *hname, Int_t run, Float_t refX, Int_t type, Int_t integ=1)
static AliTPCROC * Instance()
Definition: AliTPCROC.cxx:34
static void MakeLaserDistortionTreeOld(TTree *tree, TObjArray *corrArray, Int_t itype)
static Double_t GetCorrXYZIntegrateZ(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType=0, Double_t delta=5)
virtual void GetCorrectionIntegralDz(const Float_t x[], Short_t roc, Float_t dx[], Float_t delta)
const TVectorD * GetVecSec() const
Float_t GetPadRowRadii(Int_t isec, Int_t irow) const
Definition: AliTPCParam.h:312
virtual void Update(const TTimeStamp &timeStamp)
virtual void Init()
Float_t GetPadRowRadii(UInt_t isec, UInt_t irow) const
Definition: AliTPCROC.h:56
static const Double_t fgkIFCRadius
Mean Radius of the Inner Field Cage ( 82.43 min, 83.70 max) (cm)/hera/alice/wiechula/calib/guiTrees.
const TVectorD * GetVecP2() const
static const Double_t fgkdvdE
[cm/V] drift velocity dependency on the E field (from Magboltz for NeCO2N2 at standard environment) ...
TH2F * CreateHistoDZinZR(Float_t phi=0., Int_t nZ=100, Int_t nR=100)
Int_t debug
Double_t r
Definition: AliFMDv1.cxx:82
return kTRUE
Definition: AliFMDv1.cxx:97
void PoissonRelaxation3D(TMatrixD **arrayofArrayV, TMatrixD **arrayofChargeDensities, TMatrixD **arrayofEroverEz, TMatrixD **arrayofEPhioverEz, TMatrixD **arrayofEz, Int_t rows, Int_t columns, Int_t phislices, Float_t deltaphi, Int_t iterations, Int_t summetry, Bool_t rocDisplacement=kTRUE, IntegrationType integrationType=kIntegral)