]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCTransform.cxx
Add new class for drift velocity
[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"
cf5b0aa0 62#include "AliTPCCorrection.h"
66954e3f 63#include "TGeoMatrix.h"
9430b11a 64#include "AliTPCRecoParam.h"
65#include "AliTPCCalibVdrift.h"
022ee144 66#include "AliTPCTransform.h"
0b736a46 67#include "AliMagF.h"
68#include "TGeoGlobalMagField.h"
69#include "AliTracker.h"
1e6337b1 70#include <AliCTPTimeParams.h>
022ee144 71
66954e3f 72ClassImp(AliTPCTransform)
022ee144 73
74
9430b11a 75AliTPCTransform::AliTPCTransform():
76 AliTransform(),
77 fCurrentRecoParam(0), //! current reconstruction parameters
78 fCurrentRun(0), //! current run
79 fCurrentTimeStamp(0) //! current time stamp
80{
81 //
82 // Speed it up a bit!
83 //
84 for (Int_t i=0;i<18;++i) {
85 Double_t alpha=TMath::DegToRad()*(10.+20.*(i%18));
86 fSins[i]=TMath::Sin(alpha);
87 fCoss[i]=TMath::Cos(alpha);
88 }
89 fPrimVtx[0]=0;
90 fPrimVtx[1]=0;
91 fPrimVtx[2]=0;
92}
93AliTPCTransform::AliTPCTransform(const AliTPCTransform& transform):
94 AliTransform(transform),
95 fCurrentRecoParam(transform.fCurrentRecoParam), //! current reconstruction parameters
96 fCurrentRun(transform.fCurrentRun), //! current run
97 fCurrentTimeStamp(transform.fCurrentTimeStamp) //! current time stamp
003b43ed 98{
24db6af7 99 //
c1bdda91 100 // Speed it up a bit!
24db6af7 101 //
c1bdda91 102 for (Int_t i=0;i<18;++i) {
103 Double_t alpha=TMath::DegToRad()*(10.+20.*(i%18));
104 fSins[i]=TMath::Sin(alpha);
105 fCoss[i]=TMath::Cos(alpha);
106 }
003b43ed 107 fPrimVtx[0]=0;
108 fPrimVtx[1]=0;
109 fPrimVtx[2]=0;
c1bdda91 110}
111
112AliTPCTransform::~AliTPCTransform() {
24db6af7 113 //
114 // Destructor
115 //
c1bdda91 116}
117
003b43ed 118void AliTPCTransform::SetPrimVertex(Double_t *vtx){
119 //
120 //
121 //
122 fPrimVtx[0]=vtx[0];
123 fPrimVtx[1]=vtx[1];
124 fPrimVtx[2]=vtx[2];
125}
126
127
24db6af7 128void AliTPCTransform::Transform(Double_t *x,Int_t *i,UInt_t /*time*/,
003b43ed 129 Int_t /*coordinateType*/) {
24db6af7 130 // input: x[0] - pad row
131 // x[1] - pad
c1bdda91 132 // x[2] - time in us
133 // i[0] - sector
134 // output: x[0] - x (all in the rotated global coordinate frame)
135 // x[1] - y
136 // x[2] - z
ecc5dd8f 137 //
138 // primvtx - position of the primary vertex
139 // used for the TOF correction
140 // TOF of particle calculated assuming the speed-of-light and
141 // line approximation
142 //
143
24db6af7 144 Int_t row=TMath::Nint(x[0]);
145 Int_t pad=TMath::Nint(x[1]);
c1bdda91 146 Int_t sector=i[0];
9430b11a 147 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
24db6af7 148 //
149 AliTPCCalPad * time0TPC = calib->GetPadTime0();
2293155b 150 AliTPCCalPad * distortionMapY = calib->GetDistortionMap(0);
151 AliTPCCalPad * distortionMapZ = calib->GetDistortionMap(1);
4486a91f 152 AliTPCCalPad * distortionMapR = calib->GetDistortionMap(2);
24db6af7 153 AliTPCParam * param = calib->GetParameters();
0b736a46 154 AliTPCCorrection * correction = calib->GetTPCComposedCorrection(); // first user defined correction // if does not exist try to get it from calibDB array
155 if (!correction) correction = calib->GetTPCComposedCorrection(AliTracker::GetBz());
24db6af7 156 if (!time0TPC){
157 AliFatal("Time unisochronity missing");
158 }
c1bdda91 159
24db6af7 160 if (!param){
161 AliFatal("Parameters missing");
162 }
c1bdda91 163
24db6af7 164 Double_t xx[3];
165 // Apply Time0 correction - Pad by pad fluctuation
166 //
9fb81082 167 x[2]-=time0TPC->GetCalROC(sector)->GetValue(row,pad);
24db6af7 168 //
169 // Tranform from pad - time coordinate system to the rotated global (tracking) system
170 //
171 Local2RotatedGlobal(sector,x);
172 //
173 //
174 //
c1bdda91 175 // Alignment
176 //TODO: calib->GetParameters()->GetClusterMatrix(sector)->LocalToMaster(x,xx);
c1bdda91 177 RotatedGlobal2Global(sector,x);
cf5b0aa0 178
24db6af7 179 //
cf5b0aa0 180 // old ExB correction
24db6af7 181 //
3ce45991 182 if(fCurrentRecoParam&&fCurrentRecoParam->GetUseExBCorrection()) {
183
184 calib->GetExB()->Correct(x,xx);
185
186 } else {
187
188 xx[0] = x[0];
189 xx[1] = x[1];
190 xx[2] = x[2];
191 }
192
cf5b0aa0 193 //
194 // new composed correction - will replace soon ExB correction
195 //
196 if(fCurrentRecoParam&&fCurrentRecoParam->GetUseComposedCorrection()&&correction) {
197 Float_t distPoint[3]={xx[0],xx[1],xx[2]};
198 correction->CorrectPoint(distPoint, sector);
199 xx[0]=distPoint[0];
200 xx[1]=distPoint[1];
201 xx[2]=distPoint[2];
202 }
203
204
ecc5dd8f 205 //
206 // Time of flight correction
003b43ed 207 //
9430b11a 208 if (fCurrentRecoParam&&fCurrentRecoParam->GetUseTOFCorrection()){
209 const Int_t kNIS=param->GetNInnerSector(), kNOS=param->GetNOuterSector();
210 Float_t sign=1;
211 if (sector < kNIS) {
212 sign = (sector < kNIS/2) ? 1 : -1;
213 } else {
214 sign = ((sector-kNIS) < kNOS/2) ? 1 : -1;
215 }
216 Float_t deltaDr =0;
217 Float_t dist=0;
218 dist+=(fPrimVtx[0]-x[0])*(fPrimVtx[0]-x[0]);
219 dist+=(fPrimVtx[1]-x[1])*(fPrimVtx[1]-x[1]);
220 dist+=(fPrimVtx[2]-x[2])*(fPrimVtx[2]-x[2]);
221 dist = TMath::Sqrt(dist);
222 // drift length correction because of TOF
223 // the drift velocity is in cm/s therefore multiplication by 0.01
224 deltaDr = (dist*(0.01*param->GetDriftV()))/TMath::C();
225 xx[2]+=sign*deltaDr;
ecc5dd8f 226 }
9430b11a 227 //
228 //
229 //
230
ecc5dd8f 231 //
c1bdda91 232 Global2RotatedGlobal(sector,xx);
2293155b 233
234 //
235 // Apply non linear distortion correction
236 //
237 if (distortionMapY ){
0b736a46 238 // wt - to get it form the OCDB
239 // ignore T1 and T2
240 AliMagF* magF= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
241 Double_t bzField = magF->SolenoidField()/10.; //field in T
242 Double_t vdrift = param->GetDriftV()/1000000.; // [cm/us] // From dataBase: to be updated: per second (ideally)
243 Double_t ezField = 400; // [V/cm] // to be updated: never (hopefully)
244 if (sector%36<18) ezField*=-1;
245 Double_t wt = -10.0 * (bzField*10) * vdrift / ezField ;
246 Double_t c0=1./(1.+wt*wt);
247 Double_t c1=wt/c0;
248
2293155b 249 //can be switch on for each dimension separatelly
4486a91f 250 if (fCurrentRecoParam->GetUseFieldCorrection()&0x2)
0b736a46 251 if (distortionMapY){
252 xx[1]-= c0*distortionMapY->GetCalROC(sector)->GetValue(row,pad);
253 xx[0]-= c1*distortionMapY->GetCalROC(sector)->GetValue(row,pad);
254 }
2293155b 255 if (fCurrentRecoParam->GetUseFieldCorrection()&0x4)
4486a91f 256 if (distortionMapZ)
257 xx[2]-=distortionMapZ->GetCalROC(sector)->GetValue(row,pad);
258 if (fCurrentRecoParam->GetUseFieldCorrection()&0x8)
0b736a46 259 if (distortionMapR){
260 xx[0]-= c0*distortionMapR->GetCalROC(sector)->GetValue(row,pad);
261 xx[1]-=-c1*distortionMapR->GetCalROC(sector)->GetValue(row,pad)*wt;
262 }
263
2293155b 264 }
4486a91f 265 //
2293155b 266
003b43ed 267 //
c1bdda91 268 x[0]=xx[0];x[1]=xx[1];x[2]=xx[2];
269}
270
24db6af7 271void AliTPCTransform::Local2RotatedGlobal(Int_t sector, Double_t *x) const {
272 //
273 //
022ee144 274 // Tranform coordinate from
275 // row, pad, time to x,y,z
24db6af7 276 //
022ee144 277 // Drift Velocity
278 // Current implementation - common drift velocity - for full chamber
24db6af7 279 // TODO: use a map or parametrisation!
280 //
281 //
282 //
9430b11a 283 const Int_t kMax =60; // cache for 60 seconds
284 static Int_t lastStamp=-1; //cached values
285 static Double_t lastCorr = 1;
286 //
66954e3f 287 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
24db6af7 288 AliTPCParam * param = calib->GetParameters();
9430b11a 289 AliTPCCalibVdrift *driftCalib = AliTPCcalibDB::Instance()->GetVdrift(fCurrentRun);
290 Double_t driftCorr = 1.;
291 if (driftCalib){
292 //
293 // caching drift correction - temp. fix
294 // Extremally slow procedure
295 if ( TMath::Abs((lastStamp)-Int_t(fCurrentTimeStamp))<kMax){
296 driftCorr = lastCorr;
297 }else{
298 driftCorr = 1.+(driftCalib->GetPTRelative(fCurrentTimeStamp,0)+ driftCalib->GetPTRelative(fCurrentTimeStamp,1))*0.5;
299 lastCorr=driftCorr;
300 lastStamp=fCurrentTimeStamp;
301
302 }
303 }
43a74775 304 //
a8f8b6a1 305 // simple caching non thread save
306 static Double_t vdcorrectionTime=1;
5647625c 307 static Double_t vdcorrectionTimeGY=0;
a8f8b6a1 308 static Double_t time0corrTime=0;
309 static Int_t lastStampT=-1;
310 //
817766d5 311 if (lastStampT!=(Int_t)fCurrentTimeStamp){
a8f8b6a1 312 lastStampT=fCurrentTimeStamp;
313 if(fCurrentRecoParam&&fCurrentRecoParam->GetUseDriftCorrectionTime()>0) {
314 vdcorrectionTime = (1+AliTPCcalibDB::Instance()->
315 GetVDriftCorrectionTime(fCurrentTimeStamp,
fefec90f 316 fCurrentRun,
a8f8b6a1 317 sector%36>=18,
318 fCurrentRecoParam->GetUseDriftCorrectionTime()));
319 time0corrTime= AliTPCcalibDB::Instance()->
320 GetTime0CorrectionTime(fCurrentTimeStamp,
fefec90f 321 fCurrentRun,
a8f8b6a1 322 sector%36>=18,
323 fCurrentRecoParam->GetUseDriftCorrectionTime());
324 }
325 //
326 if(fCurrentRecoParam&&fCurrentRecoParam->GetUseDriftCorrectionGY()>0) {
a8f8b6a1 327
5647625c 328 Double_t corrGy= AliTPCcalibDB::Instance()->
a8f8b6a1 329 GetVDriftCorrectionGy(fCurrentTimeStamp,
330 AliTPCcalibDB::Instance()->GetRun(),
331 sector%36>=18,
5647625c 332 fCurrentRecoParam->GetUseDriftCorrectionGY());
333 vdcorrectionTimeGY = corrGy;
a8f8b6a1 334 }
43a74775 335 }
9430b11a 336
337
24db6af7 338 if (!param){
339 AliFatal("Parameters missing");
340 }
341 Int_t row=TMath::Nint(x[0]);
9389f9a4 342 // Int_t pad=TMath::Nint(x[1]);
24db6af7 343 //
344 const Int_t kNIS=param->GetNInnerSector(), kNOS=param->GetNOuterSector();
345 Double_t sign = 1.;
502d13b5 346 Double_t zwidth = param->GetZWidth()*driftCorr;
5647625c 347 Float_t xyzPad[3];
348 AliTPCROC::Instance()->GetPositionGlobal(sector, TMath::Nint(x[0]) ,TMath::Nint(x[1]), xyzPad);
349 if (AliTPCRecoParam:: GetUseTimeCalibration()) zwidth*=vdcorrectionTime*(1+xyzPad[1]*vdcorrectionTimeGY);
24db6af7 350 Double_t padWidth = 0;
351 Double_t padLength = 0;
352 Double_t maxPad = 0;
353 //
354 if (sector < kNIS) {
355 maxPad = param->GetNPadsLow(row);
356 sign = (sector < kNIS/2) ? 1 : -1;
357 padLength = param->GetPadPitchLength(sector,row);
358 padWidth = param->GetPadPitchWidth(sector);
359 } else {
360 maxPad = param->GetNPadsUp(row);
361 sign = ((sector-kNIS) < kNOS/2) ? 1 : -1;
362 padLength = param->GetPadPitchLength(sector,row);
363 padWidth = param->GetPadPitchWidth(sector);
364 }
365 //
366 // X coordinate
022ee144 367 x[0] = param->GetPadRowRadii(sector,row); // padrow X position - ideal
24db6af7 368 //
369 // Y coordinate
370 //
371 x[1]=(x[1]-0.5*maxPad)*padWidth;
afbaa016 372 // pads are mirrorred on C-side
373 if (sector%36>17){
374 x[1]*=-1;
375 }
376
377 //
378
24db6af7 379 //
380 // Z coordinate
381 //
1e6337b1 382 if (AliTPCcalibDB::Instance()->IsTrgL0()){
383 // by defualt we assume L1 trigger is used - make a correction in case of L0
384 AliCTPTimeParams* ctp = AliTPCcalibDB::Instance()->GetCTPTimeParams();
3d1b41c1 385 if (ctp){
386 //for TPC standalone runs no ctp info
387 Double_t delay = ctp->GetDelayL1L0()*0.000000025;
388 x[2]-=delay/param->GetTSample();
389 }
1e6337b1 390 }
391 x[2]-= param->GetNTBinsL1();
24db6af7 392 x[2]*= zwidth; // tranform time bin to the distance to the ROC
1e6337b1 393 x[2]-= 3.*param->GetZSigma() + time0corrTime;
24db6af7 394 // subtract the time offsets
395 x[2] = sign*( param->GetZLength(sector) - x[2]);
c1bdda91 396}
397
c2da420d 398void AliTPCTransform::RotatedGlobal2Global(Int_t sector,Double_t *x) const {
24db6af7 399 //
400 // transform possition rotated global to the global
401 //
c1bdda91 402 Double_t cos,sin;
403 GetCosAndSin(sector,cos,sin);
404 Double_t tmp=x[0];
e81544f7 405 x[0]= cos*tmp-sin*x[1];
406 x[1]=+sin*tmp+cos*x[1];
c1bdda91 407}
408
c2da420d 409void AliTPCTransform::Global2RotatedGlobal(Int_t sector,Double_t *x) const {
24db6af7 410 //
411 // tranform possition Global2RotatedGlobal
412 //
c1bdda91 413 Double_t cos,sin;
414 GetCosAndSin(sector,cos,sin);
415 Double_t tmp=x[0];
e81544f7 416 x[0]= cos*tmp+sin*x[1];
417 x[1]= -sin*tmp+cos*x[1];
c1bdda91 418}
419
c2da420d 420void AliTPCTransform::GetCosAndSin(Int_t sector,Double_t &cos,
c1bdda91 421 Double_t &sin) const {
422 cos=fCoss[sector%18];
423 sin=fSins[sector%18];
424}
425
c1bdda91 426
43a74775 427void AliTPCTransform::ApplyTransformations(Double_t */*xyz*/, Int_t /*volID*/){
428 //
429 // Modify global position
430 // xyz - global xyz position
431 // volID - volID of detector (sector number)
432 //
433 //
434
435}