added libAliHLTTrigger (Jochen)
[u/mrichter/AliRoot.git] / TPC / AliTPCTransform.cxx
CommitLineData
c1bdda91 1#include "AliTPCROC.h"
24db6af7 2#include "AliTPCCalPad.h"
c1bdda91 3#include "AliTPCCalROC.h"
4#include "AliTPCcalibDB.h"
5#include "AliTPCParam.h"
6#include "TMath.h"
24db6af7 7#include "AliLog.h"
418bbcaf 8#include "AliTPCExB.h"
24db6af7 9#include "AliTPCTransform.h"
c1bdda91 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
22AliTPCTransform::AliTPCTransform() {
24db6af7 23 //
c1bdda91 24 // Speed it up a bit!
24db6af7 25 //
c1bdda91 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
33AliTPCTransform::~AliTPCTransform() {
24db6af7 34 //
35 // Destructor
36 //
c1bdda91 37}
38
24db6af7 39void 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
c1bdda91 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
24db6af7 48 Int_t row=TMath::Nint(x[0]);
49 Int_t pad=TMath::Nint(x[1]);
c1bdda91 50 Int_t sector=i[0];
51 AliTPCcalibDB* const calib=AliTPCcalibDB::Instance();
24db6af7 52 //
53 AliTPCCalPad * time0TPC = calib->GetPadTime0();
54 AliTPCParam * param = calib->GetParameters();
55 if (!time0TPC){
56 AliFatal("Time unisochronity missing");
57 }
c1bdda91 58
24db6af7 59 if (!param){
60 AliFatal("Parameters missing");
61 }
c1bdda91 62
24db6af7 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 //
c1bdda91 74 // Alignment
75 //TODO: calib->GetParameters()->GetClusterMatrix(sector)->LocalToMaster(x,xx);
c1bdda91 76 RotatedGlobal2Global(sector,x);
24db6af7 77 //
78 //
79 // ExB correction
80 //
c1bdda91 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
24db6af7 88void 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]);
c1bdda91 146}
147
24db6af7 148inline void AliTPCTransform::RotatedGlobal2Global(Int_t sector,Double_t *x) const {
149 //
150 // transform possition rotated global to the global
151 //
c1bdda91 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
24db6af7 159inline void AliTPCTransform::Global2RotatedGlobal(Int_t sector,Double_t *x) const {
160 //
161 // tranform possition Global2RotatedGlobal
162 //
c1bdda91 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
170inline 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
176ClassImp(AliTPCTransform)
177