]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDtransform.cxx
Make data members static for speed (Theo)
[u/mrichter/AliRoot.git] / TRD / AliTRDtransform.cxx
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 /* $Id$ */
17
18 ////////////////////////////////////////////////////////////////////////////
19 //                                                                        //
20 //  Transforms clusters into space points with calibrated positions       //
21 //  defined in the local tracking system                                  //
22 //                                                                        //
23 ////////////////////////////////////////////////////////////////////////////
24
25 #include <TGeoMatrix.h>
26
27 #include "AliLog.h"
28
29 #include "AliTRDtransform.h"
30 #include "AliTRDcluster.h"
31 #include "AliTRDgeometry.h"
32 #include "AliTRDpadPlane.h"
33 #include "AliTRDCommonParam.h"
34 #include "AliTRDcalibDB.h"
35 #include "Cal/AliTRDCalDet.h"
36 #include "Cal/AliTRDCalROC.h"
37
38 ClassImp(AliTRDtransform)
39
40 //_____________________________________________________________________________
41 AliTRDtransform::AliTRDtransform()
42   :TObject()
43   ,fGeo(0x0)
44   ,fDetector(0)
45   ,fParam(0x0)
46   ,fCalibration(0x0)
47   ,fCalVdriftROC(0x0)
48   ,fCalT0ROC(0x0)
49   ,fCalPRFROC(0x0)
50   ,fkCalVdriftDet(0x0)
51   ,fkCalT0Det(0x0)
52   ,fCalVdriftDetValue(0)
53   ,fCalT0DetValue(0)
54   ,fSamplingFrequency(0)
55   ,fPadPlane(0x0)
56   ,fZShiftIdeal(0)
57   ,fMatrix(0x0)
58 {
59   //
60   // AliTRDtransform default constructor
61   //
62
63   fGeo               = new AliTRDgeometry();
64   if (!fGeo->CreateClusterMatrixArray()) {
65     AliError("Could not get transformation matrices\n");
66   }
67
68   fParam             = AliTRDCommonParam::Instance();
69   if (!fParam) {
70     AliError("Could not get common parameters\n");
71   }
72   fSamplingFrequency = fParam->GetSamplingFrequency();
73
74   fCalibration       = AliTRDcalibDB::Instance();
75   if (!fCalibration) {
76     AliError("Cannot find calibration object");
77   }
78
79   // Get the calibration objects for the global calibration
80   fkCalVdriftDet     = fCalibration->GetVdriftDet();
81   fkCalT0Det         = fCalibration->GetT0Det();
82
83 }
84
85 //_____________________________________________________________________________
86 AliTRDtransform::AliTRDtransform(Int_t det)
87   :TObject()
88   ,fGeo(0x0)
89   ,fDetector(0)
90   ,fParam(0x0)
91   ,fCalibration(0x0)
92   ,fCalVdriftROC(0x0)
93   ,fCalT0ROC(0x0)
94   ,fCalPRFROC(0x0)
95   ,fkCalVdriftDet(0x0)
96   ,fkCalT0Det(0x0)
97   ,fCalVdriftDetValue(0)
98   ,fCalT0DetValue(0)
99   ,fSamplingFrequency(0)
100   ,fPadPlane(0x0)
101   ,fZShiftIdeal(0)
102   ,fMatrix(0x0)
103 {
104   //
105   // AliTRDtransform constructor for a given detector
106   //
107
108   fGeo               = new AliTRDgeometry();
109   if (!fGeo->CreateClusterMatrixArray()) {
110     AliError("Could not get transformation matrices\n");
111   }
112
113   fParam             = AliTRDCommonParam::Instance();
114   if (!fParam) {
115     AliError("Could not get common parameters\n");
116   }
117   fSamplingFrequency = fParam->GetSamplingFrequency();
118
119   fCalibration       = AliTRDcalibDB::Instance();
120   if (!fCalibration) {
121     AliError("Cannot find calibration object");
122   }
123
124   // Get the calibration objects for the global calibration
125   fkCalVdriftDet     = fCalibration->GetVdriftDet();
126   fkCalT0Det         = fCalibration->GetT0Det();
127
128   SetDetector(det);
129
130 }
131
132 //_____________________________________________________________________________
133 AliTRDtransform::AliTRDtransform(const AliTRDtransform &t)
134   :TObject(t)
135   ,fGeo(0x0)
136   ,fDetector(t.fDetector)
137   ,fParam(0x0)
138   ,fCalibration(0x0)
139   ,fCalVdriftROC(0x0)
140   ,fCalT0ROC(0x0)
141   ,fCalPRFROC(0x0)
142   ,fkCalVdriftDet(0x0)
143   ,fkCalT0Det(0x0)
144   ,fCalVdriftDetValue(0)
145   ,fCalT0DetValue(0)
146   ,fSamplingFrequency(0)
147   ,fPadPlane(0x0)
148   ,fZShiftIdeal(0)
149   ,fMatrix(0x0)
150 {
151   //
152   // AliTRDtransform copy constructor
153   //
154
155   if (fGeo) {
156     delete fGeo;
157   }
158   fGeo               = new AliTRDgeometry();
159   fGeo->CreateClusterMatrixArray();
160
161   fParam             = AliTRDCommonParam::Instance();
162   if (!fParam) {
163     AliError("Could not get common parameters\n");
164   }
165   fSamplingFrequency = fParam->GetSamplingFrequency();
166
167   fCalibration = AliTRDcalibDB::Instance();
168   if (!fCalibration) {
169     AliError("Cannot find calibration object");
170   }
171   fkCalVdriftDet     = fCalibration->GetVdriftDet();
172   fkCalT0Det         = fCalibration->GetT0Det();
173
174 }
175
176 //_____________________________________________________________________________
177 AliTRDtransform::~AliTRDtransform()
178 {
179   //
180   // AliTRDtransform destructor
181   //
182
183   if (fGeo) {
184     delete fGeo;
185   }
186
187 }
188
189 //_____________________________________________________________________________
190 void AliTRDtransform::SetDetector(Int_t det)
191 {
192   //
193   // Set to a new detector number and update the calibration objects
194   // and values accordingly
195   //
196
197   fDetector          = det;
198
199   // Get the calibration objects for the pad-by-pad calibration
200   fCalVdriftROC      = fCalibration->GetVdriftROC(det);
201   fCalT0ROC          = fCalibration->GetT0ROC(det);
202   fCalPRFROC         = fCalibration->GetPRFROC(det);
203
204   // Get the detector wise defined calibration values
205   fCalVdriftDetValue = fkCalVdriftDet->GetValue(det);
206   fCalT0DetValue     = fkCalT0Det->GetValue(det);
207
208   // Shift needed to define Z-position relative to middle of chamber
209   Int_t layer        = fGeo->GetLayer(det);
210   Int_t stack        = fGeo->GetStack(det);
211   fPadPlane          = fGeo->GetPadPlane(layer,stack);
212   fZShiftIdeal       = 0.5 * (fPadPlane->GetRow0() + fPadPlane->GetRowEnd());
213
214   // Get the current transformation matrix
215   fMatrix            = fGeo->GetClusterMatrix(det);
216
217 }
218
219 //_____________________________________________________________________________
220 Bool_t AliTRDtransform::Transform(AliTRDcluster *c)
221 {
222   //
223   // Transforms the local cluster coordinates into calibrated 
224   // space point positions defined in the local tracking system.
225   //
226   // Here the calibration for T0, Vdrift and ExB is applied as well.
227   //
228   // Input: Cluster in the local chamber coordinates
229   // Output: Tracking cluster
230
231   if (!fMatrix) return kFALSE;
232
233
234   // Parameters to adjust the X position of clusters in the alignable volume
235   const Double_t kX0shift = AliTRDgeometry::AnodePos(); //[cm]
236
237  
238   // Retrieve calibration values
239   Int_t col = c->GetPadCol(), row = c->GetPadRow();
240   // drift velocity
241   Double_t vd  = fCalVdriftDetValue * fCalVdriftROC->GetValue(col,row);
242   // t0
243   Double_t t0  = fCalT0DetValue     + fCalT0ROC->GetValue(col,row);
244   t0 /= fSamplingFrequency;
245   // ExB correction
246   Double_t exb = AliTRDCommonParam::Instance()->GetOmegaTau(vd);
247
248   Float_t x = c->GetXloc(t0, vd);
249
250   // Pad dimensions
251   Double_t rs = fPadPlane->GetRowSize(row);
252   Double_t cs = fPadPlane->GetColSize(col);
253
254   // cluster error with diffusion corrections
255   Double_t s2  = cs*fCalPRFROC->GetValue(col, row); 
256   s2 *= s2; 
257   Float_t dl, dt;
258   AliTRDCommonParam::Instance()->GetDiffCoeff(dl, dt, vd);
259
260   Double_t y0 = fPadPlane->GetColPos(col) + .5*cs;
261   Double_t loc[] = {
262     kX0shift-x,                    // Invert the X-position,
263     c->GetYloc(y0, s2, cs) - x*exb,// apply ExB correction
264     fPadPlane->GetRowPos(row) - .5*rs - fZShiftIdeal // move the Z-position relative to the middle of the chamber
265   };
266
267   // Go to tracking coordinates
268   Double_t trk[3];
269   fMatrix->LocalToMaster(loc, trk);
270
271   // store tracking values
272   c->SetX(trk[0]);c->SetY(trk[1]);c->SetZ(trk[2]);
273   c->SetSigmaY2(s2, dt, exb, x);
274   c->SetSigmaZ2(fPadPlane->GetRowSize(row)*fPadPlane->GetRowSize(row)/12.);
275   
276   return kTRUE;
277
278 }
279
280 //_____________________________________________________________________________
281 void AliTRDtransform::Recalibrate(AliTRDcluster *c, Bool_t setDet)
282 {
283   //
284   // Recalibrates the position of a given cluster
285   // If <setDet> is TRUE, the detector number is set for each cluster
286   // automatically. Otherwise, AliTRDtransform::SetDetector() has to
287   // be used.
288   //
289
290   if (setDet) SetDetector(c->GetDetector());
291   Transform(c);
292
293 }