ROOT logo
/*
  Simple compiled macro for declaration of static distortion function
  on top of the AliTPCDistortion class.
  Why:
  1. Use static function in the fitting procedure
  2. Usage in TFormual, TF1, Tf2 ... for visualization.
  3. Usage in  tree->Draw() for visualization
  4. Simple visualization of fit residuals in multidemension - using tree Draw functionality


  
  Usage:
  gSystem->AddIncludePath("-I$ALICE_ROOT/TPC");
  .L $ALICE_ROOT/TPC/CalibMacros/AliTPCDistortions.cxx+
  .L $ALICE_ROOT/TPC/CalibMacros/AliTPCDistortionFun.C+
 
  Example:
  //
  // Draw integrated distortion in local x
  //
  TF2 fdistIFCXvZX("fdistIFCXvZX","GetIFCDistortion(y,0,x,0)*sign(x)",-250,250,80,250);
  fdistIFCXvZX.SetNpx(200);
  fdistIFCXvZX.SetNpy(200);  
  fdistIFCXvZX.GetXaxis()->SetTitle("Z (cm)");
  fdistIFCXvZX.GetYaxis()->SetTitle("local X (cm)");  
  fdistIFCXvZX->Draw("colz");
  //
  // Draw local distortion angle dx/dz  in mrad
  //
  TF2 fangleIFCXvZX("fangleIFCXvZX","1000*(GetIFCDistortion(y,0,x,0)-GetIFCDistortion(y,0,x-1,0))",-250,250,85,245);
  fangleIFCXvZX.SetNpx(200);
  fangleIFCXvZX.SetNpy(200);
  fangleIFCXvZX.GetXaxis()->SetTitle("Z (cm)");
  fangleIFCXvZX.GetYaxis()->SetTitle("local X (cm)");  
  fangleIFCXvZX->Draw("colz");

  //
  //
  //
  TF2 fangleGGXvZX("fangleGGXvZX","1000*(GetGGDistortion(y,0,x,0,1*400,1*400)-GetGGDistortion(y,0,x-1,0,1*400,1*400))*sign(x)",-250,250,85,245);
  fangleGGXvZX.SetNpx(200);
  fangleGGXvZX.SetNpy(200);
  fangleGGXvZX.GetXaxis()->SetTitle("Z (cm)");
  fangleGGXvZX.GetYaxis()->SetTitle("local X (cm)");  
  fangleGGXvZX->Draw("colz");
  


*/


#include "TCanvas.h"
#include "TF1.h"
#include "TLegend.h"
#include "AliTPCDistortions.h"

TObjArray *arrayPic=new TObjArray;

Double_t GetIFCDistortion(Double_t lx, Double_t ly, Double_t lz, Int_t icoord, Double_t shift=1.){
  //
  static AliTPCDistortions transform;
  static Bool_t doInit=kTRUE;
  if (doInit){
    transform.SetIFCShift(1);
    transform.InitIFCShiftDistortion();
    doInit=kFALSE;
  }

  Double_t xyzIn[3]={lx, ly, lz};
  Double_t xyzOut[3]={lx, ly, lz};
  Int_t dummyROC=0;
  if (lz<0) { dummyROC=36;}
  transform.UndoIFCShiftDistortion(xyzIn,xyzOut,dummyROC);
  Double_t result=0;
  if (icoord<3) result=xyzOut[icoord]-xyzIn[icoord];
  return result*shift;
}



Double_t GetGGDistortion(Double_t lx, Double_t ly, Double_t lz, Int_t icoord, Double_t deltaVGGA=1., Double_t deltaVGGC=1.){
  //
  // GG distortion induced distortions 
  //
  static AliTPCDistortions transform;
  static Bool_t doInit=kTRUE;
  if (doInit){
    transform.SetDeltaVGGA(1.);
    transform.SetDeltaVGGC(1.);
    transform.InitGGVoltErrorDistortion();
    doInit=kFALSE;
  }
  Double_t xyzIn[3]={lx, ly, lz};
  Double_t xyzOut[3]={lx, ly, lz};
  Int_t dummyROC=0;
  if (lz<0) { dummyROC=36;}
  transform.UndoGGVoltErrorDistortion(xyzIn,xyzOut,dummyROC);
  Double_t result=0;
  if (icoord<3) result=xyzOut[icoord]-xyzIn[icoord];
  if (lz<0) result*=deltaVGGA;
  if (lz>0) result*=deltaVGGC;
  return result;
}


void MakePicIFCDX(){
  //
  // 
  //
  TCanvas *canvasIFC1D= new TCanvas("IFC radial shift", "IFC radial shift");
  TLegend *legend = new TLegend(0.1,0.60,0.5,0.9, "Radial distortion due IFC shift 1 mm ");

  for (Int_t iradius=0; iradius<=10; iradius++){
    Double_t radius=85+iradius*(245-85)/10.;
    TF1 *f1= new TF1(Form("fIFC_ZX%f",radius),Form("0.1*GetIFCDistortion(%f,0,x,0)*sign(x)",radius),-250,250);
    f1->SetMaximum( 0.6);
    f1->SetMinimum(-0.6);
    f1->SetNpx(200);
    f1->SetLineColor(1+((20+iradius)%20));
    f1->SetLineWidth(1);
    if (iradius==0) f1->Draw("p");
    f1->Draw("samep");
    legend->AddEntry(f1,Form("R=%f",radius));    
  }
  legend->Draw();  
}

void MakePicIFCDXangle(){
  //
  // 
  //
  TCanvas *canvasIFC1D= new TCanvas("IFC radial shift - angle", "IFC radial shift angle");
  TLegend *legend = new TLegend(0.1,0.60,0.9,0.9, "Radial distortion due IFC shift 1 mm ");

  for (Int_t iradius=0; iradius<=10; iradius++){
    Double_t radius=85+iradius*(245-85)/10.;
    TF1 *f1= new TF1(Form("fIFC_ZX%f",radius),Form("0.1*1000*(GetIFCDistortion(%f,0,x,0)-GetIFCDistortion(%f,0,x+1,0))",radius,radius),-250,250);
    f1->SetMaximum( 10);
    f1->SetMinimum(-10);
    f1->SetNpx(200);
    f1->SetLineColor(1+(iradius%10));
    f1->SetLineWidth(1);
    //f1->SetLineStyle(2+(iradius%6));
    if (iradius==0) f1->Draw("");
    f1->Draw("same");
    legend->AddEntry(f1,Form("R=%f",radius));    
  }
  legend->Draw();  
}

 AliTPCDistortionFun.C:1
 AliTPCDistortionFun.C:2
 AliTPCDistortionFun.C:3
 AliTPCDistortionFun.C:4
 AliTPCDistortionFun.C:5
 AliTPCDistortionFun.C:6
 AliTPCDistortionFun.C:7
 AliTPCDistortionFun.C:8
 AliTPCDistortionFun.C:9
 AliTPCDistortionFun.C:10
 AliTPCDistortionFun.C:11
 AliTPCDistortionFun.C:12
 AliTPCDistortionFun.C:13
 AliTPCDistortionFun.C:14
 AliTPCDistortionFun.C:15
 AliTPCDistortionFun.C:16
 AliTPCDistortionFun.C:17
 AliTPCDistortionFun.C:18
 AliTPCDistortionFun.C:19
 AliTPCDistortionFun.C:20
 AliTPCDistortionFun.C:21
 AliTPCDistortionFun.C:22
 AliTPCDistortionFun.C:23
 AliTPCDistortionFun.C:24
 AliTPCDistortionFun.C:25
 AliTPCDistortionFun.C:26
 AliTPCDistortionFun.C:27
 AliTPCDistortionFun.C:28
 AliTPCDistortionFun.C:29
 AliTPCDistortionFun.C:30
 AliTPCDistortionFun.C:31
 AliTPCDistortionFun.C:32
 AliTPCDistortionFun.C:33
 AliTPCDistortionFun.C:34
 AliTPCDistortionFun.C:35
 AliTPCDistortionFun.C:36
 AliTPCDistortionFun.C:37
 AliTPCDistortionFun.C:38
 AliTPCDistortionFun.C:39
 AliTPCDistortionFun.C:40
 AliTPCDistortionFun.C:41
 AliTPCDistortionFun.C:42
 AliTPCDistortionFun.C:43
 AliTPCDistortionFun.C:44
 AliTPCDistortionFun.C:45
 AliTPCDistortionFun.C:46
 AliTPCDistortionFun.C:47
 AliTPCDistortionFun.C:48
 AliTPCDistortionFun.C:49
 AliTPCDistortionFun.C:50
 AliTPCDistortionFun.C:51
 AliTPCDistortionFun.C:52
 AliTPCDistortionFun.C:53
 AliTPCDistortionFun.C:54
 AliTPCDistortionFun.C:55
 AliTPCDistortionFun.C:56
 AliTPCDistortionFun.C:57
 AliTPCDistortionFun.C:58
 AliTPCDistortionFun.C:59
 AliTPCDistortionFun.C:60
 AliTPCDistortionFun.C:61
 AliTPCDistortionFun.C:62
 AliTPCDistortionFun.C:63
 AliTPCDistortionFun.C:64
 AliTPCDistortionFun.C:65
 AliTPCDistortionFun.C:66
 AliTPCDistortionFun.C:67
 AliTPCDistortionFun.C:68
 AliTPCDistortionFun.C:69
 AliTPCDistortionFun.C:70
 AliTPCDistortionFun.C:71
 AliTPCDistortionFun.C:72
 AliTPCDistortionFun.C:73
 AliTPCDistortionFun.C:74
 AliTPCDistortionFun.C:75
 AliTPCDistortionFun.C:76
 AliTPCDistortionFun.C:77
 AliTPCDistortionFun.C:78
 AliTPCDistortionFun.C:79
 AliTPCDistortionFun.C:80
 AliTPCDistortionFun.C:81
 AliTPCDistortionFun.C:82
 AliTPCDistortionFun.C:83
 AliTPCDistortionFun.C:84
 AliTPCDistortionFun.C:85
 AliTPCDistortionFun.C:86
 AliTPCDistortionFun.C:87
 AliTPCDistortionFun.C:88
 AliTPCDistortionFun.C:89
 AliTPCDistortionFun.C:90
 AliTPCDistortionFun.C:91
 AliTPCDistortionFun.C:92
 AliTPCDistortionFun.C:93
 AliTPCDistortionFun.C:94
 AliTPCDistortionFun.C:95
 AliTPCDistortionFun.C:96
 AliTPCDistortionFun.C:97
 AliTPCDistortionFun.C:98
 AliTPCDistortionFun.C:99
 AliTPCDistortionFun.C:100
 AliTPCDistortionFun.C:101
 AliTPCDistortionFun.C:102
 AliTPCDistortionFun.C:103
 AliTPCDistortionFun.C:104
 AliTPCDistortionFun.C:105
 AliTPCDistortionFun.C:106
 AliTPCDistortionFun.C:107
 AliTPCDistortionFun.C:108
 AliTPCDistortionFun.C:109
 AliTPCDistortionFun.C:110
 AliTPCDistortionFun.C:111
 AliTPCDistortionFun.C:112
 AliTPCDistortionFun.C:113
 AliTPCDistortionFun.C:114
 AliTPCDistortionFun.C:115
 AliTPCDistortionFun.C:116
 AliTPCDistortionFun.C:117
 AliTPCDistortionFun.C:118
 AliTPCDistortionFun.C:119
 AliTPCDistortionFun.C:120
 AliTPCDistortionFun.C:121
 AliTPCDistortionFun.C:122
 AliTPCDistortionFun.C:123
 AliTPCDistortionFun.C:124
 AliTPCDistortionFun.C:125
 AliTPCDistortionFun.C:126
 AliTPCDistortionFun.C:127
 AliTPCDistortionFun.C:128
 AliTPCDistortionFun.C:129
 AliTPCDistortionFun.C:130
 AliTPCDistortionFun.C:131
 AliTPCDistortionFun.C:132
 AliTPCDistortionFun.C:133
 AliTPCDistortionFun.C:134
 AliTPCDistortionFun.C:135
 AliTPCDistortionFun.C:136
 AliTPCDistortionFun.C:137
 AliTPCDistortionFun.C:138
 AliTPCDistortionFun.C:139
 AliTPCDistortionFun.C:140
 AliTPCDistortionFun.C:141
 AliTPCDistortionFun.C:142
 AliTPCDistortionFun.C:143
 AliTPCDistortionFun.C:144
 AliTPCDistortionFun.C:145
 AliTPCDistortionFun.C:146
 AliTPCDistortionFun.C:147
 AliTPCDistortionFun.C:148
 AliTPCDistortionFun.C:149
 AliTPCDistortionFun.C:150
 AliTPCDistortionFun.C:151