]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDCommonParam.cxx
First implementation of calibration scheme by Jan Fiete
[u/mrichter/AliRoot.git] / TRD / AliTRDCommonParam.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 // Class containing constant common parameters                           //
21 //                                                                           //
22 // Request an instance with AliTRDCommonParam::Instance()                 //
23 // Then request the needed values                                            //
24 //                                                                           //
25 ///////////////////////////////////////////////////////////////////////////////
26
27 #include "AliRun.h"
28
29 #include "AliTRDCommonParam.h"
30 #include "AliTRDpadPlane.h"
31
32
33 ClassImp(AliTRDCommonParam)
34
35 AliTRDCommonParam* AliTRDCommonParam::fgInstance = 0;
36 Bool_t AliTRDCommonParam::fgTerminated = kFALSE;
37
38 //_ singleton implementation __________________________________________________
39 AliTRDCommonParam* AliTRDCommonParam::Instance()
40 {
41   //
42   // Singleton implementation
43   // Returns an instance of this class, it is created if neccessary
44   // 
45   
46   if (fgTerminated != kFALSE)
47     return 0;
48
49   if (fgInstance == 0)
50     fgInstance = new AliTRDCommonParam();
51   
52   return fgInstance;
53 }
54
55 void AliTRDCommonParam::Terminate()
56 {
57   //
58   // Singleton implementation
59   // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
60   // This function can be called several times.
61   //
62   
63   fgTerminated = kTRUE;
64   
65   if (fgInstance != 0)
66   {
67     delete fgInstance;
68     fgInstance = 0;
69   }
70 }
71
72 //_____________________________________________________________________________
73 AliTRDCommonParam::AliTRDCommonParam()
74 {
75   //
76   // constructor
77   //
78   
79   fField              = 0.0;
80   fPRFbin             = 0;
81   fPRFlo              = 0.0;
82   fPRFhi              = 0.0;
83   fPRFwid             = 0.0;
84   fPRFpad             = 0;
85
86   fPRFsmp             = 0;
87   
88   fExBOn              = kFALSE;
89   fPRFOn              = kFALSE;
90   
91   fPadPlaneArray      = 0;
92   
93   Init();
94 };
95
96 //_____________________________________________________________________________
97 void AliTRDCommonParam::Init()
98 {
99   //
100   // constructor helper
101   //
102   
103   // E x B effects
104   fExBOn          = kTRUE;
105
106   // The pad response function
107   fPRFOn          = kTRUE;
108
109   // The magnetic field strength in Tesla
110   Double_t x[3] = { 0.0, 0.0, 0.0 };
111   Double_t b[3];
112   gAlice->Field(x,b);  // b[] is in kilo Gauss
113   fField = b[2] * 0.1; // Tesla
114   
115   // Create the sampled PRF
116   SamplePRF();
117   
118   // ----------------------------------------------------------------------------
119   // The pad planes
120   // ----------------------------------------------------------------------------
121   
122   fPadPlaneArray = new TObjArray(kNplan * kNcham);
123   
124   for (Int_t iplan = 0; iplan < kNplan; iplan++) {
125     for (Int_t icham = 0; icham < kNcham; icham++) {
126       Int_t ipp = iplan + icham * kNplan;
127       fPadPlaneArray->AddAt(new AliTRDpadPlane(iplan,icham),ipp);
128     }
129   }
130 }
131
132 //_____________________________________________________________________________
133 AliTRDCommonParam::~AliTRDCommonParam() 
134 {
135   //
136   // destructor
137   //
138   
139   if (fPRFsmp) {
140     delete [] fPRFsmp;
141     fPRFsmp = 0;
142   }
143
144   if (fPadPlaneArray) {
145     fPadPlaneArray->Delete();
146     delete fPadPlaneArray;
147     fPadPlaneArray = 0;
148   }
149 };
150
151 //_____________________________________________________________________________
152 AliTRDCommonParam::AliTRDCommonParam(const AliTRDCommonParam &p):TObject(p)
153 {
154   //
155   // copy constructor
156   //
157
158   ((AliTRDCommonParam &) p).Copy(*this);
159 }
160
161
162 //_____________________________________________________________________________
163 AliTRDCommonParam &AliTRDCommonParam::operator=(const AliTRDCommonParam &p)
164 {
165   //
166   // Assignment operator
167   //
168
169   if (this != &p) ((AliTRDCommonParam &) p).Copy(*this);
170   return *this;
171 }
172
173 //_____________________________________________________________________________
174 void AliTRDCommonParam::Copy(TObject &p) const
175 {
176   //
177   // Copy function
178   //
179   
180   AliTRDCommonParam* target = dynamic_cast<AliTRDCommonParam*> (&p);
181   if (!target)
182     return;
183   
184   target->fExBOn              = fExBOn;
185   target->fPRFOn              = fPRFOn;
186   target->fPRFbin             = fPRFbin;
187   target->fPRFlo              = fPRFlo;
188   target->fPRFhi              = fPRFhi;
189   target->fPRFwid             = fPRFwid;
190   target->fPRFpad             = fPRFpad;
191   if (target->fPRFsmp) delete [] target->fPRFsmp;
192   target->fPRFsmp = new Float_t[fPRFbin];
193   for (Int_t iBin = 0; iBin < fPRFbin; iBin++) {
194     target->fPRFsmp[iBin] = fPRFsmp[iBin];
195   }
196 }
197
198 //_____________________________________________________________________________
199 void AliTRDCommonParam::SamplePRF()
200 {
201   //
202   // Samples the pad response function
203   //
204
205   const Int_t kPRFbin = 61;
206
207   Float_t prf[kNplan][kPRFbin] = { {2.9037e-02, 3.3608e-02, 3.9020e-02, 4.5292e-02,
208                     5.2694e-02, 6.1362e-02, 7.1461e-02, 8.3362e-02,
209                     9.7063e-02, 1.1307e-01, 1.3140e-01, 1.5235e-01,
210                     1.7623e-01, 2.0290e-01, 2.3294e-01, 2.6586e-01,
211                     3.0177e-01, 3.4028e-01, 3.8077e-01, 4.2267e-01,
212                     4.6493e-01, 5.0657e-01, 5.4655e-01, 5.8397e-01,
213                     6.1767e-01, 6.4744e-01, 6.7212e-01, 6.9188e-01,
214                     7.0627e-01, 7.1499e-01, 7.1851e-01, 7.1499e-01,
215                     7.0627e-01, 6.9188e-01, 6.7212e-01, 6.4744e-01,
216                     6.1767e-01, 5.8397e-01, 5.4655e-01, 5.0657e-01,
217                     4.6493e-01, 4.2267e-01, 3.8077e-01, 3.4028e-01,
218                     3.0177e-01, 2.6586e-01, 2.3294e-01, 2.0290e-01,
219                     1.7623e-01, 1.5235e-01, 1.3140e-01, 1.1307e-01,
220                     9.7063e-02, 8.3362e-02, 7.1461e-02, 6.1362e-02,
221                     5.2694e-02, 4.5292e-02, 3.9020e-02, 3.3608e-02,
222                     2.9037e-02},
223                    {2.5478e-02, 2.9695e-02, 3.4655e-02, 4.0454e-02,
224                     4.7342e-02, 5.5487e-02, 6.5038e-02, 7.6378e-02,
225                     8.9696e-02, 1.0516e-01, 1.2327e-01, 1.4415e-01,
226                     1.6794e-01, 1.9516e-01, 2.2573e-01, 2.5959e-01,
227                     2.9694e-01, 3.3719e-01, 3.7978e-01, 4.2407e-01,
228                     4.6889e-01, 5.1322e-01, 5.5569e-01, 5.9535e-01,
229                     6.3141e-01, 6.6259e-01, 6.8882e-01, 7.0983e-01,
230                     7.2471e-01, 7.3398e-01, 7.3761e-01, 7.3398e-01,
231                     7.2471e-01, 7.0983e-01, 6.8882e-01, 6.6259e-01,
232                     6.3141e-01, 5.9535e-01, 5.5569e-01, 5.1322e-01,
233                     4.6889e-01, 4.2407e-01, 3.7978e-01, 3.3719e-01,
234                     2.9694e-01, 2.5959e-01, 2.2573e-01, 1.9516e-01,
235                     1.6794e-01, 1.4415e-01, 1.2327e-01, 1.0516e-01,
236                     8.9696e-02, 7.6378e-02, 6.5038e-02, 5.5487e-02,
237                     4.7342e-02, 4.0454e-02, 3.4655e-02, 2.9695e-02,
238                     2.5478e-02},
239                    {2.2363e-02, 2.6233e-02, 3.0782e-02, 3.6140e-02,
240                     4.2535e-02, 5.0157e-02, 5.9197e-02, 6.9900e-02,
241                     8.2707e-02, 9.7811e-02, 1.1548e-01, 1.3601e-01,
242                     1.5998e-01, 1.8739e-01, 2.1840e-01, 2.5318e-01,
243                     2.9182e-01, 3.3373e-01, 3.7837e-01, 4.2498e-01,
244                     4.7235e-01, 5.1918e-01, 5.6426e-01, 6.0621e-01,
245                     6.4399e-01, 6.7700e-01, 7.0472e-01, 7.2637e-01,
246                     7.4206e-01, 7.5179e-01, 7.5551e-01, 7.5179e-01,
247                     7.4206e-01, 7.2637e-01, 7.0472e-01, 6.7700e-01,
248                     6.4399e-01, 6.0621e-01, 5.6426e-01, 5.1918e-01,
249                     4.7235e-01, 4.2498e-01, 3.7837e-01, 3.3373e-01,
250                     2.9182e-01, 2.5318e-01, 2.1840e-01, 1.8739e-01,
251                     1.5998e-01, 1.3601e-01, 1.1548e-01, 9.7811e-02,
252                     8.2707e-02, 6.9900e-02, 5.9197e-02, 5.0157e-02,
253                     4.2535e-02, 3.6140e-02, 3.0782e-02, 2.6233e-02,
254                     2.2363e-02},
255                    {1.9635e-02, 2.3167e-02, 2.7343e-02, 3.2293e-02,
256                     3.8224e-02, 4.5335e-02, 5.3849e-02, 6.4039e-02,
257                     7.6210e-02, 9.0739e-02, 1.0805e-01, 1.2841e-01,
258                     1.5216e-01, 1.7960e-01, 2.1099e-01, 2.4671e-01,
259                     2.8647e-01, 3.2996e-01, 3.7660e-01, 4.2547e-01,
260                     4.7536e-01, 5.2473e-01, 5.7215e-01, 6.1632e-01,
261                     6.5616e-01, 6.9075e-01, 7.1939e-01, 7.4199e-01,
262                     7.5838e-01, 7.6848e-01, 7.7227e-01, 7.6848e-01,
263                     7.5838e-01, 7.4199e-01, 7.1939e-01, 6.9075e-01,
264                     6.5616e-01, 6.1632e-01, 5.7215e-01, 5.2473e-01,
265                     4.7536e-01, 4.2547e-01, 3.7660e-01, 3.2996e-01,
266                     2.8647e-01, 2.4671e-01, 2.1099e-01, 1.7960e-01,
267                     1.5216e-01, 1.2841e-01, 1.0805e-01, 9.0739e-02,
268                     7.6210e-02, 6.4039e-02, 5.3849e-02, 4.5335e-02,
269                     3.8224e-02, 3.2293e-02, 2.7343e-02, 2.3167e-02,
270                     1.9635e-02},
271                    {1.7224e-02, 2.0450e-02, 2.4286e-02, 2.8860e-02,
272                     3.4357e-02, 4.0979e-02, 4.8966e-02, 5.8612e-02,
273                     7.0253e-02, 8.4257e-02, 1.0102e-01, 1.2094e-01,
274                     1.4442e-01, 1.7196e-01, 2.0381e-01, 2.4013e-01,
275                     2.8093e-01, 3.2594e-01, 3.7450e-01, 4.2563e-01,
276                     4.7796e-01, 5.2991e-01, 5.7974e-01, 6.2599e-01,
277                     6.6750e-01, 7.0344e-01, 7.3329e-01, 7.5676e-01,
278                     7.7371e-01, 7.8410e-01, 7.8793e-01, 7.8410e-01,
279                     7.7371e-01, 7.5676e-01, 7.3329e-01, 7.0344e-01,
280                     6.6750e-01, 6.2599e-01, 5.7974e-01, 5.2991e-01,
281                     4.7796e-01, 4.2563e-01, 3.7450e-01, 3.2594e-01,
282                     2.8093e-01, 2.4013e-01, 2.0381e-01, 1.7196e-01,
283                     1.4442e-01, 1.2094e-01, 1.0102e-01, 8.4257e-02,
284                     7.0253e-02, 5.8612e-02, 4.8966e-02, 4.0979e-02,
285                     3.4357e-02, 2.8860e-02, 2.4286e-02, 2.0450e-02,
286                     1.7224e-02},
287                    {1.5096e-02, 1.8041e-02, 2.1566e-02, 2.5793e-02,
288                     3.0886e-02, 3.7044e-02, 4.4515e-02, 5.3604e-02,
289                     6.4668e-02, 7.8109e-02, 9.4364e-02, 1.1389e-01,
290                     1.3716e-01, 1.6461e-01, 1.9663e-01, 2.3350e-01,
291                     2.7527e-01, 3.2170e-01, 3.7214e-01, 4.2549e-01,
292                     4.8024e-01, 5.3460e-01, 5.8677e-01, 6.3512e-01,
293                     6.7838e-01, 7.1569e-01, 7.4655e-01, 7.7071e-01,
294                     7.8810e-01, 7.9871e-01, 8.0255e-01, 7.9871e-01,
295                     7.8810e-01, 7.7071e-01, 7.4655e-01, 7.1569e-01,
296                     6.7838e-01, 6.3512e-01, 5.8677e-01, 5.3460e-01,
297                     4.8024e-01, 4.2549e-01, 3.7214e-01, 3.2170e-01,
298                     2.7527e-01, 2.3350e-01, 1.9663e-01, 1.6461e-01,
299                     1.3716e-01, 1.1389e-01, 9.4364e-02, 7.8109e-02,
300                     6.4668e-02, 5.3604e-02, 4.4515e-02, 3.7044e-02,
301                     3.0886e-02, 2.5793e-02, 2.1566e-02, 1.8041e-02,
302                     1.5096e-02}};
303
304   // More sampling precision with linear interpolation
305   fPRFlo  = -1.5;
306   fPRFhi  =  1.5;
307   Float_t pad[kPRFbin];
308   Int_t   sPRFbin = kPRFbin;  
309   Float_t sPRFwid = (fPRFhi - fPRFlo) / ((Float_t) sPRFbin);
310   for (Int_t iPad = 0; iPad < sPRFbin; iPad++) {
311     pad[iPad] = ((Float_t) iPad + 0.5) * sPRFwid + fPRFlo;
312   }
313   fPRFbin = 500;  
314   fPRFwid = (fPRFhi - fPRFlo) / ((Float_t) fPRFbin);
315   fPRFpad = ((Int_t) (1.0 / fPRFwid));
316
317   if (fPRFsmp) delete [] fPRFsmp;
318   fPRFsmp = new Float_t[kNplan*fPRFbin];
319
320   Int_t   ipos1;
321   Int_t   ipos2;
322   Float_t diff;
323
324   for (Int_t iPla = 0; iPla < kNplan; iPla++) {
325
326     for (Int_t iBin = 0; iBin < fPRFbin; iBin++) {
327
328       Float_t bin = (((Float_t) iBin) + 0.5) * fPRFwid + fPRFlo;
329       ipos1 = ipos2 = 0;
330       diff  = 0;
331       do {
332         diff = bin - pad[ipos2++];
333       } while ((diff > 0) && (ipos2 < kPRFbin));
334       if      (ipos2 == kPRFbin) {
335         fPRFsmp[iPla*fPRFbin+iBin] = prf[iPla][ipos2-1];
336       }
337       else if (ipos2 == 1) {
338         fPRFsmp[iPla*fPRFbin+iBin] = prf[iPla][ipos2-1];
339       }
340       else {
341         ipos2--;
342         if (ipos2 >= kPRFbin) ipos2 = kPRFbin - 1;
343         ipos1 = ipos2 - 1;
344         fPRFsmp[iPla*fPRFbin+iBin] = prf[iPla][ipos2] 
345                                    + diff * (prf[iPla][ipos2] - prf[iPla][ipos1]) 
346                                           / sPRFwid;
347       }
348
349     }
350   } 
351
352 }
353
354 //_____________________________________________________________________________
355 Int_t AliTRDCommonParam::PadResponse(Double_t signal, Double_t dist
356     , Int_t plane, Double_t *pad) const
357 {
358   //
359   // Applies the pad response
360   //
361
362   Int_t iBin  = ((Int_t) (( - dist - fPRFlo) / fPRFwid));
363   Int_t iOff  = plane * fPRFbin;
364
365   Int_t iBin0 = iBin - fPRFpad + iOff;
366   Int_t iBin1 = iBin           + iOff;
367   Int_t iBin2 = iBin + fPRFpad + iOff;
368
369   pad[0] = 0.0;
370   pad[1] = 0.0;
371   pad[2] = 0.0;
372   if ((iBin1 >= 0) && (iBin1 < (fPRFbin*kNplan))) {
373
374     if (iBin0 >= 0) {
375       pad[0] = signal * fPRFsmp[iBin0];
376     }
377     pad[1] = signal * fPRFsmp[iBin1];
378     if (iBin2 < (fPRFbin*kNplan)) {
379       pad[2] = signal * fPRFsmp[iBin2];
380     }
381
382     return 1;
383
384   }
385   else {
386
387     return 0;
388
389   }
390
391 }
392
393 //_____________________________________________________________________________
394 AliTRDpadPlane *AliTRDCommonParam::GetPadPlane(Int_t p, Int_t c) const
395 {
396   //
397   // Returns the pad plane for a given plane <p> and chamber <c> number
398   //
399
400   Int_t ipp = p + c * kNplan;
401   return ((AliTRDpadPlane *) fPadPlaneArray->At(ipp));
402
403 }
404
405 //_____________________________________________________________________________
406 Int_t AliTRDCommonParam::GetRowMax(Int_t p, Int_t c, Int_t /*s*/) const
407 {
408   //
409   // Returns the number of rows on the pad plane
410   //
411
412   return GetPadPlane(p,c)->GetNrows();
413
414 }
415
416 //_____________________________________________________________________________
417 Int_t AliTRDCommonParam::GetColMax(Int_t p) const
418 {
419   //
420   // Returns the number of rows on the pad plane
421   //
422
423   return GetPadPlane(p,0)->GetNcols();
424
425 }
426
427 //_____________________________________________________________________________
428 Double_t AliTRDCommonParam::GetRow0(Int_t p, Int_t c, Int_t /*s*/) const
429 {
430   //
431   // Returns the position of the border of the first pad in a row
432   //
433
434   return GetPadPlane(p,c)->GetRow0();
435
436 }
437
438 //_____________________________________________________________________________
439 Double_t AliTRDCommonParam::GetCol0(Int_t p) const
440 {
441   //
442   // Returns the position of the border of the first pad in a column
443   //
444
445   return GetPadPlane(p,0)->GetCol0();
446
447 }