Fix of ACORDE-QAChecker
[u/mrichter/AliRoot.git] / TPC / AliTPCTransform.cxx
CommitLineData
022ee144 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
16//-------------------------------------------------------
17// Implementation of the TPC transformation class
18//
19// Origin: Marian Ivanov Marian.Ivanov@cern.ch
20// Magnus Mager
21//
22// Class for tranformation of the coordinate frame
66954e3f 23// Transformation
022ee144 24// local coordinate frame (sector, padrow, pad, timebine) ==>
25// rotated global (tracking) cooridnate frame (sector, lx,ly,lz)
26//
27// Unisochronity - (substract time0 - pad by pad)
28// Drift velocity - Currently common drift velocity - functionality of AliTPCParam
29// ExB effect -
30//
003b43ed 31// Time of flight correction -
32// - Depends on the vertex position
33// - by default
34//
022ee144 35// Usage:
36// AliTPCclustererMI::AddCluster
37// AliTPCtrackerMI::Transform
38//
39//-------------------------------------------------------
c1bdda91 40
41/* To test it:
42 cdb=AliCDBManager::Instance()
43 cdb->SetDefaultStorage("local:///u/mmager/mycalib1")
44 c=AliTPCcalibDB::Instance()
45 c->SetRun(0)
46 Double_t x[]={1.0,2.0,3.0}
47 Int_t i[]={4}
48 AliTPCTransform trafo
49 trafo.Transform(x,i,0,1)
50 */
51
022ee144 52/* $Id$ */
53
54#include "AliTPCROC.h"
55#include "AliTPCCalPad.h"
56#include "AliTPCCalROC.h"
57#include "AliTPCcalibDB.h"
58#include "AliTPCParam.h"
59#include "TMath.h"
60#include "AliLog.h"
61#include "AliTPCExB.h"
66954e3f 62#include "TGeoMatrix.h"
9430b11a 63#include "AliTPCRecoParam.h"
64#include "AliTPCCalibVdrift.h"
022ee144 65#include "AliTPCTransform.h"
66
66954e3f 67ClassImp(AliTPCTransform)
022ee144 68
69
9430b11a 70AliTPCTransform::AliTPCTransform():
71 AliTransform(),
72 fCurrentRecoParam(0), //! current reconstruction parameters
73 fCurrentRun(0), //! current run
74 fCurrentTimeStamp(0) //! current time stamp
75{
76 //
77 // Speed it up a bit!
78 //
79 for (Int_t i=0;i<18;++i) {
80 Double_t alpha=TMath::DegToRad()*(10.+20.*(i%18));
81 fSins[i]=TMath::Sin(alpha);
82 fCoss[i]=TMath::Cos(alpha);
83 }
84 fPrimVtx[0]=0;
85 fPrimVtx[1]=0;
86 fPrimVtx[2]=0;
87}
88AliTPCTransform::AliTPCTransform(const AliTPCTransform& transform):
89 AliTransform(transform),
90 fCurrentRecoParam(transform.fCurrentRecoParam), //! current reconstruction parameters
91 fCurrentRun(transform.fCurrentRun), //! current run
92 fCurrentTimeStamp(transform.fCurrentTimeStamp) //! current time stamp
003b43ed 93{
24db6af7 94 //
c1bdda91 95 // Speed it up a bit!
24db6af7 96 //
c1bdda91 97 for (Int_t i=0;i<18;++i) {
98 Double_t alpha=TMath::DegToRad()*(10.+20.*(i%18));
99 fSins[i]=TMath::Sin(alpha);
100 fCoss[i]=TMath::Cos(alpha);
101 }
003b43ed 102 fPrimVtx[0]=0;
103 fPrimVtx[1]=0;
104 fPrimVtx[2]=0;
c1bdda91 105}
106
107AliTPCTransform::~AliTPCTransform() {
24db6af7 108 //
109 // Destructor
110 //
c1bdda91 111}
112
003b43ed 113void AliTPCTransform::SetPrimVertex(Double_t *vtx){
114 //
115 //
116 //
117 fPrimVtx[0]=vtx[0];
118 fPrimVtx[1]=vtx[1];
119 fPrimVtx[2]=vtx[2];
120}
121
122
24db6af7 123void AliTPCTransform::Transform(Double_t *x,Int_t *i,UInt_t /*time*/,
003b43ed 124 Int_t /*coordinateType*/) {
24db6af7 125 // input: x[0] - pad row
126 // x[1] - pad
c1bdda91 127 // x[2] - time in us
128 // i[0] - sector
129 // output: x[0] - x (all in the rotated global coordinate frame)
130 // x[1] - y
131 // x[2] - z
ecc5dd8f 132 //
133 // primvtx - position of the primary vertex
134 // used for the TOF correction
135 // TOF of particle calculated assuming the speed-of-light and
136 // line approximation
137 //
138
24db6af7 139 Int_t row=TMath::Nint(x[0]);
140 Int_t pad=TMath::Nint(x[1]);
c1bdda91 141 Int_t sector=i[0];
9430b11a 142 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
24db6af7 143 //
144 AliTPCCalPad * time0TPC = calib->GetPadTime0();
145 AliTPCParam * param = calib->GetParameters();
146 if (!time0TPC){
147 AliFatal("Time unisochronity missing");
148 }
c1bdda91 149
24db6af7 150 if (!param){
151 AliFatal("Parameters missing");
152 }
c1bdda91 153
24db6af7 154 Double_t xx[3];
155 // Apply Time0 correction - Pad by pad fluctuation
156 //
157 x[2]-=time0TPC->GetCalROC(sector)->GetValue(row,pad);
158 //
159 // Tranform from pad - time coordinate system to the rotated global (tracking) system
160 //
161 Local2RotatedGlobal(sector,x);
162 //
163 //
164 //
c1bdda91 165 // Alignment
166 //TODO: calib->GetParameters()->GetClusterMatrix(sector)->LocalToMaster(x,xx);
c1bdda91 167 RotatedGlobal2Global(sector,x);
24db6af7 168 //
169 //
170 // ExB correction
171 //
3ce45991 172 if(fCurrentRecoParam&&fCurrentRecoParam->GetUseExBCorrection()) {
173
174 calib->GetExB()->Correct(x,xx);
175
176 } else {
177
178 xx[0] = x[0];
179 xx[1] = x[1];
180 xx[2] = x[2];
181 }
182
ecc5dd8f 183 //
184 // Time of flight correction
003b43ed 185 //
9430b11a 186 if (fCurrentRecoParam&&fCurrentRecoParam->GetUseTOFCorrection()){
187 const Int_t kNIS=param->GetNInnerSector(), kNOS=param->GetNOuterSector();
188 Float_t sign=1;
189 if (sector < kNIS) {
190 sign = (sector < kNIS/2) ? 1 : -1;
191 } else {
192 sign = ((sector-kNIS) < kNOS/2) ? 1 : -1;
193 }
194 Float_t deltaDr =0;
195 Float_t dist=0;
196 dist+=(fPrimVtx[0]-x[0])*(fPrimVtx[0]-x[0]);
197 dist+=(fPrimVtx[1]-x[1])*(fPrimVtx[1]-x[1]);
198 dist+=(fPrimVtx[2]-x[2])*(fPrimVtx[2]-x[2]);
199 dist = TMath::Sqrt(dist);
200 // drift length correction because of TOF
201 // the drift velocity is in cm/s therefore multiplication by 0.01
202 deltaDr = (dist*(0.01*param->GetDriftV()))/TMath::C();
203 xx[2]+=sign*deltaDr;
ecc5dd8f 204 }
9430b11a 205 //
206 //
207 //
208
ecc5dd8f 209 //
c1bdda91 210 Global2RotatedGlobal(sector,xx);
003b43ed 211 //
c1bdda91 212 x[0]=xx[0];x[1]=xx[1];x[2]=xx[2];
213}
214
24db6af7 215void AliTPCTransform::Local2RotatedGlobal(Int_t sector, Double_t *x) const {
216 //
217 //
022ee144 218 // Tranform coordinate from
219 // row, pad, time to x,y,z
24db6af7 220 //
022ee144 221 // Drift Velocity
222 // Current implementation - common drift velocity - for full chamber
24db6af7 223 // TODO: use a map or parametrisation!
224 //
225 //
226 //
9430b11a 227 const Int_t kMax =60; // cache for 60 seconds
228 static Int_t lastStamp=-1; //cached values
229 static Double_t lastCorr = 1;
230 //
66954e3f 231 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
24db6af7 232 AliTPCParam * param = calib->GetParameters();
9430b11a 233 AliTPCCalibVdrift *driftCalib = AliTPCcalibDB::Instance()->GetVdrift(fCurrentRun);
234 Double_t driftCorr = 1.;
235 if (driftCalib){
236 //
237 // caching drift correction - temp. fix
238 // Extremally slow procedure
239 if ( TMath::Abs((lastStamp)-Int_t(fCurrentTimeStamp))<kMax){
240 driftCorr = lastCorr;
241 }else{
242 driftCorr = 1.+(driftCalib->GetPTRelative(fCurrentTimeStamp,0)+ driftCalib->GetPTRelative(fCurrentTimeStamp,1))*0.5;
243 lastCorr=driftCorr;
244 lastStamp=fCurrentTimeStamp;
245
246 }
247 }
43a74775 248 //
a8f8b6a1 249 // simple caching non thread save
250 static Double_t vdcorrectionTime=1;
251 static Double_t time0corrTime=0;
252 static Int_t lastStampT=-1;
253 //
817766d5 254 if (lastStampT!=(Int_t)fCurrentTimeStamp){
a8f8b6a1 255 lastStampT=fCurrentTimeStamp;
256 if(fCurrentRecoParam&&fCurrentRecoParam->GetUseDriftCorrectionTime()>0) {
257 vdcorrectionTime = (1+AliTPCcalibDB::Instance()->
258 GetVDriftCorrectionTime(fCurrentTimeStamp,
fefec90f 259 fCurrentRun,
a8f8b6a1 260 sector%36>=18,
261 fCurrentRecoParam->GetUseDriftCorrectionTime()));
262 time0corrTime= AliTPCcalibDB::Instance()->
263 GetTime0CorrectionTime(fCurrentTimeStamp,
fefec90f 264 fCurrentRun,
a8f8b6a1 265 sector%36>=18,
266 fCurrentRecoParam->GetUseDriftCorrectionTime());
267 }
268 //
269 if(fCurrentRecoParam&&fCurrentRecoParam->GetUseDriftCorrectionGY()>0) {
270 Float_t xyzPad[3];
271 AliTPCROC::Instance()->GetPositionGlobal(sector, TMath::Nint(x[0]) ,TMath::Nint(x[1]), xyzPad);
272
273 Double_t corrGy= (1+(xyzPad[1])*AliTPCcalibDB::Instance()->
274 GetVDriftCorrectionGy(fCurrentTimeStamp,
275 AliTPCcalibDB::Instance()->GetRun(),
276 sector%36>=18,
277 fCurrentRecoParam->GetUseDriftCorrectionGY()));
278 vdcorrectionTime *=corrGy;
279 }
43a74775 280 }
9430b11a 281
282
24db6af7 283 if (!param){
284 AliFatal("Parameters missing");
285 }
286 Int_t row=TMath::Nint(x[0]);
9389f9a4 287 // Int_t pad=TMath::Nint(x[1]);
24db6af7 288 //
289 const Int_t kNIS=param->GetNInnerSector(), kNOS=param->GetNOuterSector();
290 Double_t sign = 1.;
43a74775 291 Double_t zwidth = param->GetZWidth()*driftCorr*vdcorrectionTime;
24db6af7 292 Double_t padWidth = 0;
293 Double_t padLength = 0;
294 Double_t maxPad = 0;
295 //
296 if (sector < kNIS) {
297 maxPad = param->GetNPadsLow(row);
298 sign = (sector < kNIS/2) ? 1 : -1;
299 padLength = param->GetPadPitchLength(sector,row);
300 padWidth = param->GetPadPitchWidth(sector);
301 } else {
302 maxPad = param->GetNPadsUp(row);
303 sign = ((sector-kNIS) < kNOS/2) ? 1 : -1;
304 padLength = param->GetPadPitchLength(sector,row);
305 padWidth = param->GetPadPitchWidth(sector);
306 }
307 //
308 // X coordinate
022ee144 309 x[0] = param->GetPadRowRadii(sector,row); // padrow X position - ideal
24db6af7 310 //
311 // Y coordinate
312 //
313 x[1]=(x[1]-0.5*maxPad)*padWidth;
afbaa016 314 // pads are mirrorred on C-side
315 if (sector%36>17){
316 x[1]*=-1;
317 }
318
319 //
320
24db6af7 321 //
322 // Z coordinate
323 //
324 x[2]*= zwidth; // tranform time bin to the distance to the ROC
43a74775 325 x[2]-= 3.*param->GetZSigma() + param->GetNTBinsL1()*zwidth+ time0corrTime;
24db6af7 326 // subtract the time offsets
327 x[2] = sign*( param->GetZLength(sector) - x[2]);
c1bdda91 328}
329
c2da420d 330void AliTPCTransform::RotatedGlobal2Global(Int_t sector,Double_t *x) const {
24db6af7 331 //
332 // transform possition rotated global to the global
333 //
c1bdda91 334 Double_t cos,sin;
335 GetCosAndSin(sector,cos,sin);
336 Double_t tmp=x[0];
e81544f7 337 x[0]= cos*tmp-sin*x[1];
338 x[1]=+sin*tmp+cos*x[1];
c1bdda91 339}
340
c2da420d 341void AliTPCTransform::Global2RotatedGlobal(Int_t sector,Double_t *x) const {
24db6af7 342 //
343 // tranform possition Global2RotatedGlobal
344 //
c1bdda91 345 Double_t cos,sin;
346 GetCosAndSin(sector,cos,sin);
347 Double_t tmp=x[0];
e81544f7 348 x[0]= cos*tmp+sin*x[1];
349 x[1]= -sin*tmp+cos*x[1];
c1bdda91 350}
351
c2da420d 352void AliTPCTransform::GetCosAndSin(Int_t sector,Double_t &cos,
c1bdda91 353 Double_t &sin) const {
354 cos=fCoss[sector%18];
355 sin=fSins[sector%18];
356}
357
c1bdda91 358
43a74775 359void AliTPCTransform::ApplyTransformations(Double_t */*xyz*/, Int_t /*volID*/){
360 //
361 // Modify global position
362 // xyz - global xyz position
363 // volID - volID of detector (sector number)
364 //
365 //
366
367}