1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //-------------------------------------------------------
17 // Implementation of the TPC transformation class
19 // Origin: Marian Ivanov Marian.Ivanov@cern.ch
22 // Class for tranformation of the coordinate frame
24 // local coordinate frame (sector, padrow, pad, timebine) ==>
25 // rotated global (tracking) cooridnate frame (sector, lx,ly,lz)
27 // Unisochronity - (substract time0 - pad by pad)
28 // Drift velocity - Currently common drift velocity - functionality of AliTPCParam
31 // Time of flight correction -
32 // - Depends on the vertex position
36 // AliTPCclustererMI::AddCluster
37 // AliTPCtrackerMI::Transform
39 //-------------------------------------------------------
42 cdb=AliCDBManager::Instance()
43 cdb->SetDefaultStorage("local:///u/mmager/mycalib1")
44 c=AliTPCcalibDB::Instance()
46 Double_t x[]={1.0,2.0,3.0}
49 trafo.Transform(x,i,0,1)
54 #include "AliTPCROC.h"
55 #include "AliTPCCalPad.h"
56 #include "AliTPCCalROC.h"
57 #include "AliTPCcalibDB.h"
58 #include "AliTPCParam.h"
61 #include "AliTPCExB.h"
62 #include "TGeoMatrix.h"
63 #include "AliTPCRecoParam.h"
64 #include "AliTPCCalibVdrift.h"
65 #include "AliTPCTransform.h"
66 #include <AliCTPTimeParams.h>
68 ClassImp(AliTPCTransform)
71 AliTPCTransform::AliTPCTransform():
73 fCurrentRecoParam(0), //! current reconstruction parameters
74 fCurrentRun(0), //! current run
75 fCurrentTimeStamp(0) //! current time stamp
80 for (Int_t i=0;i<18;++i) {
81 Double_t alpha=TMath::DegToRad()*(10.+20.*(i%18));
82 fSins[i]=TMath::Sin(alpha);
83 fCoss[i]=TMath::Cos(alpha);
89 AliTPCTransform::AliTPCTransform(const AliTPCTransform& transform):
90 AliTransform(transform),
91 fCurrentRecoParam(transform.fCurrentRecoParam), //! current reconstruction parameters
92 fCurrentRun(transform.fCurrentRun), //! current run
93 fCurrentTimeStamp(transform.fCurrentTimeStamp) //! current time stamp
98 for (Int_t i=0;i<18;++i) {
99 Double_t alpha=TMath::DegToRad()*(10.+20.*(i%18));
100 fSins[i]=TMath::Sin(alpha);
101 fCoss[i]=TMath::Cos(alpha);
108 AliTPCTransform::~AliTPCTransform() {
114 void AliTPCTransform::SetPrimVertex(Double_t *vtx){
124 void AliTPCTransform::Transform(Double_t *x,Int_t *i,UInt_t /*time*/,
125 Int_t /*coordinateType*/) {
126 // input: x[0] - pad row
130 // output: x[0] - x (all in the rotated global coordinate frame)
134 // primvtx - position of the primary vertex
135 // used for the TOF correction
136 // TOF of particle calculated assuming the speed-of-light and
137 // line approximation
140 Int_t row=TMath::Nint(x[0]);
141 Int_t pad=TMath::Nint(x[1]);
143 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
145 AliTPCCalPad * time0TPC = calib->GetPadTime0();
146 AliTPCCalPad * distortionMapY = calib->GetDistortionMap(0);
147 AliTPCCalPad * distortionMapZ = calib->GetDistortionMap(1);
148 AliTPCParam * param = calib->GetParameters();
150 AliFatal("Time unisochronity missing");
154 AliFatal("Parameters missing");
158 // Apply Time0 correction - Pad by pad fluctuation
160 x[2]-=time0TPC->GetCalROC(sector)->GetValue(row,pad);
162 // Tranform from pad - time coordinate system to the rotated global (tracking) system
164 Local2RotatedGlobal(sector,x);
169 //TODO: calib->GetParameters()->GetClusterMatrix(sector)->LocalToMaster(x,xx);
170 RotatedGlobal2Global(sector,x);
175 if(fCurrentRecoParam&&fCurrentRecoParam->GetUseExBCorrection()) {
177 calib->GetExB()->Correct(x,xx);
187 // Time of flight correction
189 if (fCurrentRecoParam&&fCurrentRecoParam->GetUseTOFCorrection()){
190 const Int_t kNIS=param->GetNInnerSector(), kNOS=param->GetNOuterSector();
193 sign = (sector < kNIS/2) ? 1 : -1;
195 sign = ((sector-kNIS) < kNOS/2) ? 1 : -1;
199 dist+=(fPrimVtx[0]-x[0])*(fPrimVtx[0]-x[0]);
200 dist+=(fPrimVtx[1]-x[1])*(fPrimVtx[1]-x[1]);
201 dist+=(fPrimVtx[2]-x[2])*(fPrimVtx[2]-x[2]);
202 dist = TMath::Sqrt(dist);
203 // drift length correction because of TOF
204 // the drift velocity is in cm/s therefore multiplication by 0.01
205 deltaDr = (dist*(0.01*param->GetDriftV()))/TMath::C();
213 Global2RotatedGlobal(sector,xx);
216 // Apply non linear distortion correction
218 if (distortionMapY ){
219 //can be switch on for each dimension separatelly
220 if (fCurrentRecoParam->GetUseFieldCorrection()&0x2)
221 xx[1]-=distortionMapY->GetCalROC(sector)->GetValue(row,pad);
222 if (fCurrentRecoParam->GetUseFieldCorrection()&0x4)
223 xx[2]-=distortionMapZ->GetCalROC(sector)->GetValue(row,pad);
228 x[0]=xx[0];x[1]=xx[1];x[2]=xx[2];
231 void AliTPCTransform::Local2RotatedGlobal(Int_t sector, Double_t *x) const {
234 // Tranform coordinate from
235 // row, pad, time to x,y,z
238 // Current implementation - common drift velocity - for full chamber
239 // TODO: use a map or parametrisation!
243 const Int_t kMax =60; // cache for 60 seconds
244 static Int_t lastStamp=-1; //cached values
245 static Double_t lastCorr = 1;
247 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
248 AliTPCParam * param = calib->GetParameters();
249 AliTPCCalibVdrift *driftCalib = AliTPCcalibDB::Instance()->GetVdrift(fCurrentRun);
250 Double_t driftCorr = 1.;
253 // caching drift correction - temp. fix
254 // Extremally slow procedure
255 if ( TMath::Abs((lastStamp)-Int_t(fCurrentTimeStamp))<kMax){
256 driftCorr = lastCorr;
258 driftCorr = 1.+(driftCalib->GetPTRelative(fCurrentTimeStamp,0)+ driftCalib->GetPTRelative(fCurrentTimeStamp,1))*0.5;
260 lastStamp=fCurrentTimeStamp;
265 // simple caching non thread save
266 static Double_t vdcorrectionTime=1;
267 static Double_t time0corrTime=0;
268 static Int_t lastStampT=-1;
270 if (lastStampT!=(Int_t)fCurrentTimeStamp){
271 lastStampT=fCurrentTimeStamp;
272 if(fCurrentRecoParam&&fCurrentRecoParam->GetUseDriftCorrectionTime()>0) {
273 vdcorrectionTime = (1+AliTPCcalibDB::Instance()->
274 GetVDriftCorrectionTime(fCurrentTimeStamp,
277 fCurrentRecoParam->GetUseDriftCorrectionTime()));
278 time0corrTime= AliTPCcalibDB::Instance()->
279 GetTime0CorrectionTime(fCurrentTimeStamp,
282 fCurrentRecoParam->GetUseDriftCorrectionTime());
285 if(fCurrentRecoParam&&fCurrentRecoParam->GetUseDriftCorrectionGY()>0) {
287 AliTPCROC::Instance()->GetPositionGlobal(sector, TMath::Nint(x[0]) ,TMath::Nint(x[1]), xyzPad);
289 Double_t corrGy= (1+(xyzPad[1])*AliTPCcalibDB::Instance()->
290 GetVDriftCorrectionGy(fCurrentTimeStamp,
291 AliTPCcalibDB::Instance()->GetRun(),
293 fCurrentRecoParam->GetUseDriftCorrectionGY()));
294 vdcorrectionTime *=corrGy;
300 AliFatal("Parameters missing");
302 Int_t row=TMath::Nint(x[0]);
303 // Int_t pad=TMath::Nint(x[1]);
305 const Int_t kNIS=param->GetNInnerSector(), kNOS=param->GetNOuterSector();
307 Double_t zwidth = param->GetZWidth()*driftCorr*vdcorrectionTime;
308 Double_t padWidth = 0;
309 Double_t padLength = 0;
313 maxPad = param->GetNPadsLow(row);
314 sign = (sector < kNIS/2) ? 1 : -1;
315 padLength = param->GetPadPitchLength(sector,row);
316 padWidth = param->GetPadPitchWidth(sector);
318 maxPad = param->GetNPadsUp(row);
319 sign = ((sector-kNIS) < kNOS/2) ? 1 : -1;
320 padLength = param->GetPadPitchLength(sector,row);
321 padWidth = param->GetPadPitchWidth(sector);
325 x[0] = param->GetPadRowRadii(sector,row); // padrow X position - ideal
329 x[1]=(x[1]-0.5*maxPad)*padWidth;
330 // pads are mirrorred on C-side
340 if (AliTPCcalibDB::Instance()->IsTrgL0()){
341 // by defualt we assume L1 trigger is used - make a correction in case of L0
342 AliCTPTimeParams* ctp = AliTPCcalibDB::Instance()->GetCTPTimeParams();
343 Double_t delay = ctp->GetDelayL1L0()*0.000000025;
344 x[2]-=delay/param->GetTSample();
346 x[2]-= param->GetNTBinsL1();
347 x[2]*= zwidth; // tranform time bin to the distance to the ROC
348 x[2]-= 3.*param->GetZSigma() + time0corrTime;
349 // subtract the time offsets
350 x[2] = sign*( param->GetZLength(sector) - x[2]);
353 void AliTPCTransform::RotatedGlobal2Global(Int_t sector,Double_t *x) const {
355 // transform possition rotated global to the global
358 GetCosAndSin(sector,cos,sin);
360 x[0]= cos*tmp-sin*x[1];
361 x[1]=+sin*tmp+cos*x[1];
364 void AliTPCTransform::Global2RotatedGlobal(Int_t sector,Double_t *x) const {
366 // tranform possition Global2RotatedGlobal
369 GetCosAndSin(sector,cos,sin);
371 x[0]= cos*tmp+sin*x[1];
372 x[1]= -sin*tmp+cos*x[1];
375 void AliTPCTransform::GetCosAndSin(Int_t sector,Double_t &cos,
376 Double_t &sin) const {
377 cos=fCoss[sector%18];
378 sin=fSins[sector%18];
382 void AliTPCTransform::ApplyTransformations(Double_t */*xyz*/, Int_t /*volID*/){
384 // Modify global position
385 // xyz - global xyz position
386 // volID - volID of detector (sector number)