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