]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCTransform.cxx
Applying transformation AliTPCTransform
[u/mrichter/AliRoot.git] / TPC / AliTPCTransform.cxx
1 #include "AliTPCROC.h"
2 #include "AliTPCCalPad.h"
3 #include "AliTPCCalROC.h"
4 #include "AliTPCcalibDB.h"
5 #include "AliTPCParam.h"
6 #include "TMath.h"
7 #include "AliLog.h"
8 #include "AliTPCExB.h"
9 #include "AliTPCTransform.h"
10
11 /* To test it:
12    cdb=AliCDBManager::Instance()
13    cdb->SetDefaultStorage("local:///u/mmager/mycalib1")
14    c=AliTPCcalibDB::Instance()
15    c->SetRun(0)
16    Double_t x[]={1.0,2.0,3.0}
17    Int_t i[]={4}
18    AliTPCTransform trafo
19    trafo.Transform(x,i,0,1)
20  */
21
22 AliTPCTransform::AliTPCTransform() {
23   //
24   // Speed it up a bit!
25   //
26   for (Int_t i=0;i<18;++i) {
27     Double_t alpha=TMath::DegToRad()*(10.+20.*(i%18));
28     fSins[i]=TMath::Sin(alpha);
29     fCoss[i]=TMath::Cos(alpha);
30   }
31 }
32
33 AliTPCTransform::~AliTPCTransform() {
34   //
35   // Destructor
36   //
37 }
38
39 void AliTPCTransform::Transform(Double_t *x,Int_t *i,UInt_t /*time*/,
40                                 Int_t /*coordinateType*/) {
41   // input: x[0] - pad row
42   //        x[1] - pad 
43   //        x[2] - time in us
44   //        i[0] - sector
45   // output: x[0] - x (all in the rotated global coordinate frame)
46   //         x[1] - y
47   //         x[2] - z
48   Int_t row=TMath::Nint(x[0]);
49   Int_t pad=TMath::Nint(x[1]);
50   Int_t sector=i[0];
51   AliTPCcalibDB* const calib=AliTPCcalibDB::Instance();
52   //
53   AliTPCCalPad * time0TPC = calib->GetPadTime0(); 
54   AliTPCParam  * param    = calib->GetParameters(); 
55   if (!time0TPC){
56     AliFatal("Time unisochronity missing");
57   }
58
59   if (!param){
60     AliFatal("Parameters missing");
61   }
62
63   Double_t xx[3];
64   //  Apply Time0 correction - Pad by pad fluctuation
65   //
66   x[2]-=time0TPC->GetCalROC(sector)->GetValue(row,pad);
67   //
68   // Tranform from pad - time coordinate system to the rotated global (tracking) system
69   //
70   Local2RotatedGlobal(sector,x);
71   //
72   //
73   //
74   // Alignment
75   //TODO:  calib->GetParameters()->GetClusterMatrix(sector)->LocalToMaster(x,xx);
76   RotatedGlobal2Global(sector,x);
77   //
78   //
79   // ExB correction
80   //
81   calib->GetExB()->Correct(x,xx);
82
83   Global2RotatedGlobal(sector,xx);
84
85   x[0]=xx[0];x[1]=xx[1];x[2]=xx[2];
86 }
87
88 void AliTPCTransform::Local2RotatedGlobal(Int_t sector, Double_t *x) const {
89   //
90   //  
91   // 
92   //
93   // Drift Velocity - time bin to the 
94   // Current implementation - common drift velocity 
95   // for full chamber
96   // TODO: use a map or parametrisation!
97   //
98   //  
99   //
100   AliTPCcalibDB* const calib=AliTPCcalibDB::Instance();
101   AliTPCParam  * param    = calib->GetParameters(); 
102   if (!param){
103     AliFatal("Parameters missing");
104   }
105   Int_t row=TMath::Nint(x[0]);
106   Int_t pad=TMath::Nint(x[1]);
107   //
108   const Int_t kNIS=param->GetNInnerSector(), kNOS=param->GetNOuterSector();
109   Double_t sign = 1.;
110   Double_t zwidth    = param->GetZWidth();
111   Double_t padWidth  = 0;
112   Double_t padLength = 0;
113   Double_t    maxPad    = 0;
114   //
115   if (sector < kNIS) {
116     maxPad = param->GetNPadsLow(row);
117     sign = (sector < kNIS/2) ? 1 : -1;
118     padLength = param->GetPadPitchLength(sector,row);
119     padWidth = param->GetPadPitchWidth(sector);
120   } else {
121     maxPad = param->GetNPadsUp(row);
122     sign = ((sector-kNIS) < kNOS/2) ? 1 : -1;
123     padLength = param->GetPadPitchLength(sector,row);
124     padWidth  = param->GetPadPitchWidth(sector);
125   }
126   //
127   // X coordinate
128   x[0] = param->GetPadRowRadii(sector,row);
129   // padrow X position - ideal
130   //
131   // Y coordinate
132   //
133   x[1]=(x[1]-0.5*maxPad)*padWidth;
134   //  if (!fRecoParam->GetBYMirror()){
135   //     if (sector%36>17){
136   //       x[1] *=-1.;
137   //     }
138   //   }
139   //
140   // Z coordinate
141   //
142   x[2]*= zwidth;  // tranform time bin to the distance to the ROC
143   x[2]-= 3.*param->GetZSigma() + param->GetNTBinsL1()*zwidth;
144   // subtract the time offsets
145   x[2] = sign*( param->GetZLength(sector) - x[2]);
146 }
147
148 inline void AliTPCTransform::RotatedGlobal2Global(Int_t sector,Double_t *x) const {
149   //
150   // transform possition rotated global to the global
151   //
152   Double_t cos,sin;
153   GetCosAndSin(sector,cos,sin);
154   Double_t tmp=x[0];
155   x[0]= cos*tmp+sin*x[1];
156   x[1]=-sin*tmp+cos*x[1];
157 }
158
159 inline void AliTPCTransform::Global2RotatedGlobal(Int_t sector,Double_t *x) const {
160   //
161   // tranform possition Global2RotatedGlobal
162   //
163   Double_t cos,sin;
164   GetCosAndSin(sector,cos,sin);
165   Double_t tmp=x[0];
166   x[0]= cos*tmp-sin*x[1];
167   x[1]= sin*tmp+cos*x[1];
168 }
169
170 inline void AliTPCTransform::GetCosAndSin(Int_t sector,Double_t &cos,
171                                           Double_t &sin) const {
172   cos=fCoss[sector%18];
173   sin=fSins[sector%18];
174 }
175
176 ClassImp(AliTPCTransform)
177