]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDcalibDB.cxx
Fix bug in digitization of multiple events
[u/mrichter/AliRoot.git] / TRD / AliTRDcalibDB.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 providing the calibration parameters by accessing the CDB           //
21 //                                                                           //
22 // Request an instance with AliTRDcalibDB::Instance()                        //
23 // If a new event is processed set the event number with SetRun              //
24 // Then request the calibration data                                         // 
25 //                                                                           //
26 // Author:                                                                   //
27 //   Jan Fiete Grosse-Oetringhaus (Jan.Fiete.Grosse-Oetringhaus@cern.ch)     //
28 //                                                                           //
29 ///////////////////////////////////////////////////////////////////////////////
30
31 #include <TRandom.h>
32
33 #include "AliCDBManager.h"
34 #include "AliCDBStorage.h"
35 #include "AliCDBEntry.h"
36 #include "AliLog.h"
37
38 #include "AliTRDcalibDB.h"
39 #include "AliTRDgeometry.h"
40 #include "AliTRDpadPlane.h"
41 #include "AliTRDCommonParam.h"
42
43 #include "Cal/AliTRDCalROC.h"
44 #include "Cal/AliTRDCalPad.h"
45 #include "Cal/AliTRDCalDet.h"
46 #include "Cal/AliTRDCalGlobals.h"
47 #include "Cal/AliTRDCalPIDLQ.h"
48 #include "Cal/AliTRDCalMonitoring.h"
49 #include "Cal/AliTRDCalSuperModuleStatus.h"
50 #include "Cal/AliTRDCalChamberStatus.h"
51 #include "Cal/AliTRDCalMCMStatus.h"
52 #include "Cal/AliTRDCalPadStatus.h"
53 #include "Cal/AliTRDCalSingleChamberStatus.h"
54
55 ClassImp(AliTRDcalibDB)
56
57 AliTRDcalibDB *AliTRDcalibDB::fgInstance   = 0;
58 Bool_t         AliTRDcalibDB::fgTerminated = kFALSE;
59
60 //_ singleton implementation __________________________________________________
61 AliTRDcalibDB* AliTRDcalibDB::Instance()
62 {
63   //
64   // Singleton implementation
65   // Returns an instance of this class, it is created if neccessary
66   //
67   
68   if (fgTerminated != kFALSE) {
69     return 0;
70   }
71
72   if (fgInstance == 0) {
73     fgInstance = new AliTRDcalibDB();
74   }
75
76   return fgInstance;
77 }
78
79 //_____________________________________________________________________________
80 void AliTRDcalibDB::Terminate()
81 {
82   //
83   // Singleton implementation
84   // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
85   // This function can be called several times.
86   //
87   
88   fgTerminated = kTRUE;
89   
90   if (fgInstance != 0) {
91     delete fgInstance;
92     fgInstance = 0;
93   }
94
95 }
96
97 //_____________________________________________________________________________
98 AliTRDcalibDB::AliTRDcalibDB()
99   :TObject()
100   ,fRun(-1)
101   ,fPRFsmp(0)
102   ,fPRFbin(0)
103   ,fPRFlo(0)
104   ,fPRFhi(0)
105   ,fPRFwid(0)
106   ,fPRFpad(0)
107 {
108   //
109   // Default constructor
110   //
111   // TODO Default runnumber is set to 0, this should be changed later
112   //      to an invalid value (e.g. -1) to prevent
113   // TODO invalid calibration data to be used.
114   //
115
116   for (Int_t i = 0; i < kCDBCacheSize; ++i) {
117     fCDBCache[i]   = 0;
118     fCDBEntries[i] = 0;
119   }
120   
121   // Create the sampled PRF
122   SamplePRF();
123
124 }
125
126 //_____________________________________________________________________________
127 AliTRDcalibDB::AliTRDcalibDB(const AliTRDcalibDB &c)
128   :TObject(c)
129   ,fRun(-1)
130   ,fPRFsmp(0)
131   ,fPRFbin(0)
132   ,fPRFlo(0)
133   ,fPRFhi(0)
134   ,fPRFwid(0)
135   ,fPRFpad(0)
136 {
137   //
138   // Copy constructor (not that it make any sense for a singleton...)
139   //
140
141   for (Int_t i = 0; i < kCDBCacheSize; ++i) {
142     fCDBCache[i]   = 0;
143     fCDBEntries[i] = 0;
144   }
145   
146   // Create the sampled PRF
147   SamplePRF();
148
149 }
150
151 //_____________________________________________________________________________
152 AliTRDcalibDB &AliTRDcalibDB::operator=(const AliTRDcalibDB &c) 
153 {
154   //
155   // Assignment operator (same as above ...)
156   //
157
158   if (this != &c) {
159     AliFatal("No assignment operator defined");
160   }
161   return *this;
162
163 }
164
165 //_____________________________________________________________________________
166 AliTRDcalibDB::~AliTRDcalibDB() 
167 {
168   //
169   // destructor
170   //
171   
172   if (fPRFsmp) {
173     delete [] fPRFsmp;
174     fPRFsmp = 0;
175   }
176
177   Invalidate();
178
179 }
180
181 //_caching functions____________________________________________________________
182 const TObject *AliTRDcalibDB::GetCachedCDBObject(Int_t id)
183 {
184   //
185   // Retrieves a cdb object with the given id. The objects are cached as
186   // long as the run number is not changed.
187   //
188   // Put together the available objects here by using the lines
189   //   a) For usual calibration objects:
190   //      case kID<Name> : 
191   //        return CacheCDBEntry(kID<Name>,"TRD/Calib/<Path>"); 
192   //        break;
193   //      See function CacheCDBEntry for details.
194   //   and
195   //   b) For calibration data which depends on two objects: One containing 
196   //      a value per detector and one the local fluctuations per pad:
197   //      case kID<Name> :
198   //        return CacheMergeCDBEntry(kID<Name>,"TRD/Calib/<padPath>","TRD/Calib/<chamberPath>"); 
199   //        break;
200   //      See function CacheMergeCDBEntry for details.
201   //
202     
203   switch (id) {
204
205     // Parameters defined per pad and chamber
206     case kIDVdriftPad : 
207       return CacheCDBEntry(kIDVdriftPad         ,"TRD/Calib/LocalVdrift"); 
208       break;
209     case kIDVdriftChamber : 
210       return CacheCDBEntry(kIDVdriftChamber     ,"TRD/Calib/ChamberVdrift"); 
211       break;
212     case kIDT0Pad : 
213       return CacheCDBEntry(kIDT0Pad             ,"TRD/Calib/LocalT0"); 
214       break;
215     case kIDT0Chamber : 
216       return CacheCDBEntry(kIDT0Chamber         ,"TRD/Calib/ChamberT0"); 
217       break;
218     case kIDGainFactorPad : 
219       return CacheCDBEntry(kIDGainFactorPad     ,"TRD/Calib/LocalGainFactor"); 
220       break;
221     case kIDGainFactorChamber : 
222       return CacheCDBEntry(kIDGainFactorChamber ,"TRD/Calib/ChamberGainFactor"); 
223       break;
224
225     // Parameters defined per pad
226     case kIDPRFWidth : 
227       return CacheCDBEntry(kIDPRFWidth          ,"TRD/Calib/PRFWidth"); 
228       break;
229
230     // Status values
231     case kIDSuperModuleStatus : 
232       return CacheCDBEntry(kIDSuperModuleStatus ,"TRD/Calib/SuperModuleStatus"); 
233       break;
234     case kIDChamberStatus : 
235       return CacheCDBEntry(kIDChamberStatus     ,"TRD/Calib/ChamberStatus"); 
236       break;
237     case kIDMCMStatus : 
238       return CacheCDBEntry(kIDMCMStatus         ,"TRD/Calib/MCMStatus"); 
239       break;
240     case kIDPadStatus : 
241       return CacheCDBEntry(kIDPadStatus         ,"TRD/Calib/PadStatus"); 
242       break;
243
244     // Global parameters
245     case kIDMonitoringData : 
246       return CacheCDBEntry(kIDMonitoringData    ,"TRD/Calib/MonitoringData"); 
247       break;
248     case kIDGlobals : 
249       return CacheCDBEntry(kIDGlobals           ,"TRD/Calib/Globals"); 
250       break;
251     case kIDPIDLQ : 
252       return CacheCDBEntry(kIDPIDLQ             ,"TRD/Calib/PIDLQ"); 
253       break;
254
255   }
256
257   return 0;
258
259 }
260
261 //_____________________________________________________________________________
262 AliCDBEntry *AliTRDcalibDB::GetCDBEntry(const char *cdbPath)
263 {
264   // 
265   // Retrieves an entry with path <cdbPath> from the CDB.
266   //
267     
268   AliCDBEntry *entry = AliCDBManager::Instance()->Get(cdbPath,fRun);
269   if (!entry) { 
270     AliError(Form("Failed to get entry: %s",cdbPath));
271     return 0; 
272   }
273   
274   AliDebug(1,Form("AliTRDcalibDB: Retrieved object: %s",cdbPath));
275
276   return entry;
277
278 }
279
280 //_____________________________________________________________________________
281 const TObject *AliTRDcalibDB::CacheCDBEntry(Int_t id, const char *cdbPath)
282 {
283   //
284   // Caches the entry <id> with cdb path <cdbPath>
285   //
286   
287   if (!fCDBCache[id]) {
288     fCDBEntries[id] = GetCDBEntry(cdbPath);
289     if (fCDBEntries[id]) {
290       fCDBCache[id] = fCDBEntries[id]->GetObject();
291     }
292   }
293
294   return fCDBCache[id];
295
296 }
297
298 //_____________________________________________________________________________
299 void AliTRDcalibDB::SetRun(Long64_t run)
300 {
301   //
302   // Sets current run number. Calibration data is read from the corresponding file.
303   // When the run number changes the caching is invalidated.
304   //
305
306   if (fRun == run) {
307     return;
308   }
309
310   fRun = run;
311
312   Invalidate();
313
314 }
315
316 //_____________________________________________________________________________
317 void AliTRDcalibDB::Invalidate()
318 {
319   //
320   // Invalidates cache (when run number is changed).
321   //
322   
323   for (Int_t i = 0; i < kCDBCacheSize; ++i) {
324     if (fCDBEntries[i]) {
325       if (AliCDBManager::Instance()->GetCacheFlag() == kFALSE) {
326         if ((fCDBEntries[i]->IsOwner() == kFALSE) && fCDBCache[i]) {
327           delete fCDBCache[i];
328         }
329         delete fCDBEntries[i];
330       }
331       fCDBEntries[i] = 0;
332       fCDBCache[i]   = 0;
333     }
334   }
335
336 }
337
338 //_____________________________________________________________________________
339 Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
340 {
341   //
342   // Returns the drift velocity for the given pad.
343   //
344
345   const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
346                                    (GetCachedCDBObject(kIDVdriftPad));
347   if (!calPad) {
348     return -1;
349   }
350
351   AliTRDCalROC       *roc        = calPad->GetCalROC(det);
352   if (!roc) {
353     return -1;
354   }
355
356   const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> 
357                                    (GetCachedCDBObject(kIDVdriftChamber));
358   if (!calChamber) {
359     return -1;
360   }
361
362   return calChamber->GetValue(det) * roc->GetValue(col,row);
363
364 }
365
366 //_____________________________________________________________________________
367 Float_t AliTRDcalibDB::GetVdriftAverage(Int_t det)
368 {
369   //
370   // Returns the average drift velocity for the given detector
371   //
372
373   const AliTRDCalDet *calDet     = dynamic_cast<const AliTRDCalDet *> 
374                                    (GetCachedCDBObject(kIDVdriftChamber));
375   if (!calDet) {
376     return -1;
377   }
378
379   return calDet->GetValue(det);
380
381 }
382
383 //_____________________________________________________________________________
384 Float_t AliTRDcalibDB::GetT0(Int_t det, Int_t col, Int_t row)
385 {
386   //
387   // Returns t0 for the given pad.
388   //
389   
390   const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
391                                    (GetCachedCDBObject(kIDT0Pad));
392   if (!calPad) {
393     return -1;
394   }
395
396   AliTRDCalROC       *roc        = calPad->GetCalROC(det);
397   if (!roc) {
398     return -1;
399   }
400
401   const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> 
402                                    (GetCachedCDBObject(kIDT0Chamber));
403   if (!calChamber) {
404     return -1;
405   }
406
407   return calChamber->GetValue(det) * roc->GetValue(col,row);
408
409 }
410
411 //_____________________________________________________________________________
412 Float_t AliTRDcalibDB::GetT0Average(Int_t det)
413 {
414   //
415   // Returns the average t0 for the given detector
416   //
417
418   const AliTRDCalDet *calDet     = dynamic_cast<const AliTRDCalDet *> 
419                                    (GetCachedCDBObject(kIDT0Chamber));
420   if (!calDet) {
421     return -1;
422   }
423
424   return calDet->GetValue(det);
425
426 }
427
428 //_____________________________________________________________________________
429 Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
430 {
431   //
432   // Returns the gain factor for the given pad.
433   //
434   
435   const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
436                                    (GetCachedCDBObject(kIDGainFactorPad));
437   if (!calPad) {
438     return -1;
439   }
440
441   AliTRDCalROC       *roc        = calPad->GetCalROC(det);
442   if (!roc)
443     return -1;
444
445   const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> 
446                                    (GetCachedCDBObject(kIDGainFactorChamber));
447   if (!calChamber) {
448     return -1;
449   }
450
451   return calChamber->GetValue(det) * roc->GetValue(col,row);
452
453 }
454
455 //_____________________________________________________________________________
456 Float_t AliTRDcalibDB::GetGainFactorAverage(Int_t det)
457 {
458   //
459   // Returns the average gain factor for the given detector
460   //
461
462   const AliTRDCalDet *calDet     = dynamic_cast<const AliTRDCalDet *> 
463                                    (GetCachedCDBObject(kIDGainFactorChamber));
464   if (!calDet) {
465     return -1;
466   }
467
468   return calDet->GetValue(det);
469
470 }
471
472 //_____________________________________________________________________________
473 Float_t AliTRDcalibDB::GetPRFWidth(Int_t det, Int_t col, Int_t row)
474 {
475   //
476   // Returns the PRF width for the given pad.
477   //
478   
479   const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
480                                    (GetCachedCDBObject(kIDPRFWidth));
481   if (!calPad) {
482     return -1;
483   }
484
485   AliTRDCalROC       *roc        = calPad->GetCalROC(det);
486   if (!roc) {
487     return -1;
488   }
489
490   return roc->GetValue(col,row);
491
492 }
493
494 //_____________________________________________________________________________
495 Float_t AliTRDcalibDB::GetSamplingFrequency()
496 {
497   //
498   // Returns the sampling frequency of the TRD read-out.
499   //
500   
501   const AliTRDCalGlobals *calGlobal = dynamic_cast<const AliTRDCalGlobals *> 
502                                       (GetCachedCDBObject(kIDGlobals));
503   if (!calGlobal) {
504     return -1;  
505   }  
506
507   return calGlobal->GetSamplingFrequency();
508
509 }
510   
511 //_____________________________________________________________________________
512 Int_t AliTRDcalibDB::GetNumberOfTimeBins()
513 {
514   //
515   // Returns the number of time bins which are read-out.
516   //
517
518   const AliTRDCalGlobals *calGlobal = dynamic_cast<const AliTRDCalGlobals *> 
519                                       (GetCachedCDBObject(kIDGlobals));
520   if (!calGlobal) {
521     return -1;
522   }
523
524   return calGlobal->GetNumberOfTimeBins();
525
526 }
527
528 //_____________________________________________________________________________
529 Char_t AliTRDcalibDB::GetPadStatus(Int_t det, Int_t col, Int_t row)
530 {
531   //
532   // Returns the status of the given pad
533   //
534
535   const AliTRDCalPadStatus *cal     = dynamic_cast<const AliTRDCalPadStatus *> 
536                                       (GetCachedCDBObject(kIDPadStatus));
537   if (!cal) {
538     return -1;
539   }
540
541   const AliTRDCalSingleChamberStatus *roc = cal->GetCalROC(det);
542   if (!roc) {
543     return -1;
544   }
545
546   return roc->GetStatus(col,row);
547
548 }
549
550 //_____________________________________________________________________________
551 Char_t AliTRDcalibDB::GetMCMStatus(Int_t det, Int_t col, Int_t row)
552 {
553   //
554   // Returns the status of the given MCM
555   //
556
557   // To translate pad column number into MCM number
558   Int_t mcm = ((Int_t) col / 18);
559
560   const AliTRDCalMCMStatus *cal     = dynamic_cast<const AliTRDCalMCMStatus *> 
561                                       (GetCachedCDBObject(kIDMCMStatus));
562   if (!cal) {
563     return -1;
564   }
565
566   const AliTRDCalSingleChamberStatus *roc = cal->GetCalROC(det);
567   if (!roc) {
568     return -1;
569   }
570
571   return roc->GetStatus(mcm,row);
572
573 }
574
575 //_____________________________________________________________________________
576 Char_t AliTRDcalibDB::GetChamberStatus(Int_t det)
577 {
578   //
579   // Returns the status of the given chamber
580   //
581
582   const AliTRDCalChamberStatus *cal = dynamic_cast<const AliTRDCalChamberStatus *> 
583                                       (GetCachedCDBObject(kIDChamberStatus));
584   if (!cal) {
585     return -1;
586   }
587
588   return cal->GetStatus(det);
589
590 }
591
592 //_____________________________________________________________________________
593 Char_t AliTRDcalibDB::GetSuperModuleStatus(Int_t sm)
594 {
595   //
596   // Returns the status of the given chamber
597   //
598
599   const AliTRDCalSuperModuleStatus *cal = dynamic_cast<const AliTRDCalSuperModuleStatus *> 
600                                           (GetCachedCDBObject(kIDSuperModuleStatus));
601   if (!cal) {
602     return -1;
603   }
604
605   return cal->GetStatus(sm);
606
607 }
608
609 //_____________________________________________________________________________
610 Bool_t AliTRDcalibDB::IsPadMasked(Int_t det, Int_t col, Int_t row)
611 {
612   //
613   // Returns status, see name of functions for details ;-)
614   //
615
616   const AliTRDCalPadStatus         *cal = dynamic_cast<const AliTRDCalPadStatus *> 
617                                           (GetCachedCDBObject(kIDPadStatus));
618   if (!cal) {
619     return -1;
620   }
621
622   return cal->IsMasked(det,col,row);
623
624 }
625
626 //_____________________________________________________________________________
627 Bool_t AliTRDcalibDB::IsPadBridgedLeft(Int_t det, Int_t col, Int_t row)
628 {
629   //
630   // Returns status, see name of functions for details ;-)
631   //
632
633   const AliTRDCalPadStatus         *cal = dynamic_cast<const AliTRDCalPadStatus *> 
634                                           (GetCachedCDBObject(kIDPadStatus));
635   if (!cal) {
636     return -1;
637   }
638
639   return cal->IsBridgedLeft(det,col,row);
640
641 }
642
643 //_____________________________________________________________________________
644 Bool_t AliTRDcalibDB::IsPadBridgedRight(Int_t det, Int_t col, Int_t row)
645 {
646   //
647   // Returns status, see name of functions for details ;-)
648   //
649
650   const AliTRDCalPadStatus         * cal = dynamic_cast<const AliTRDCalPadStatus *> 
651                                            (GetCachedCDBObject(kIDPadStatus));
652   if (!cal) {
653     return -1;
654   }
655
656   return cal->IsBridgedRight(det,col,row);
657
658 }
659
660 //_____________________________________________________________________________
661 Bool_t AliTRDcalibDB::IsMCMMasked(Int_t det, Int_t col, Int_t row)
662 {
663   //
664   // Returns status, see name of functions for details ;-)
665   //
666
667   const AliTRDCalMCMStatus         * cal = dynamic_cast<const AliTRDCalMCMStatus *> 
668                                            (GetCachedCDBObject(kIDMCMStatus));
669   if (!cal) {
670     return -1;
671   }
672
673   return cal->IsMasked(det,col,row);
674
675 }
676
677 //_____________________________________________________________________________
678 Bool_t AliTRDcalibDB::IsChamberInstalled(Int_t det)
679 {
680   //
681   // Returns status, see name of functions for details ;-)
682   //
683
684   const AliTRDCalChamberStatus     * cal = dynamic_cast<const AliTRDCalChamberStatus *> 
685                                            (GetCachedCDBObject(kIDChamberStatus));
686   if (!cal) {
687     return -1;
688   }
689
690   return cal->IsInstalled(det);
691
692 }
693
694 //_____________________________________________________________________________
695 Bool_t AliTRDcalibDB::IsChamberMasked(Int_t det)
696 {
697   //
698   // Returns status, see name of functions for details ;-)
699   //
700
701   const AliTRDCalChamberStatus     * cal = dynamic_cast<const AliTRDCalChamberStatus *> 
702                                            (GetCachedCDBObject(kIDChamberStatus));
703   if (!cal) {
704     return -1;
705   }
706
707   return cal->IsMasked(det);
708
709 }
710
711 //_____________________________________________________________________________
712 Bool_t AliTRDcalibDB::IsSuperModuleInstalled(Int_t det)
713 {
714   //
715   // Returns status, see name of functions for details ;-)
716   //
717
718   const AliTRDCalSuperModuleStatus * cal = dynamic_cast<const AliTRDCalSuperModuleStatus *> 
719                                            (GetCachedCDBObject(kIDSuperModuleStatus));
720   if (!cal) {
721     return -1;
722   }
723
724   return cal->IsInstalled(det);
725
726 }
727
728 //_____________________________________________________________________________
729 Bool_t AliTRDcalibDB::IsSuperModuleMasked(Int_t det)
730 {
731   //
732   // Returns status, see name of functions for details ;-)
733   //
734
735   const AliTRDCalSuperModuleStatus * cal = dynamic_cast<const AliTRDCalSuperModuleStatus *> 
736                                            (GetCachedCDBObject(kIDSuperModuleStatus));
737   if (!cal) {
738     return -1;
739   }
740
741   return cal->IsMasked(det);
742
743 }
744
745 //_____________________________________________________________________________
746 const AliTRDCalPIDLQ* AliTRDcalibDB::GetPIDLQObject()
747 {
748   //
749   // Returns the object storing the distributions for PID with likelihood
750   //
751
752   return dynamic_cast<const AliTRDCalPIDLQ *> (GetCachedCDBObject(kIDPIDLQ));
753
754 }
755
756 //_____________________________________________________________________________
757 const AliTRDCalMonitoring* AliTRDcalibDB::GetMonitoringObject()
758 {
759   //
760   // Returns the object storing the monitoring data
761   //
762
763   return dynamic_cast<const AliTRDCalMonitoring *> (GetCachedCDBObject(kIDMonitoringData));
764
765 }
766
767 //_____________________________________________________________________________
768 Float_t AliTRDcalibDB::GetOmegaTau(Float_t vdrift)
769 {
770   //
771   // Returns omega*tau (tan(Lorentz-angle)) for a given drift velocity <vd> 
772   // and a B-field <b> for Xe/CO2 (15%).
773   // The values are according to a GARFIELD simulation.
774   //
775   // This function basically does not belong to the calibration class. It should be moved somewhere else. 
776   // However, currently it is in use by simulation and reconstruction.
777   //
778   
779   AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
780   if (!commonParam) {
781     return -1;
782   }
783
784   Float_t fieldAbs = TMath::Abs(commonParam->GetField());
785   Float_t fieldSgn = 1.0;
786   if (fieldAbs > 0.0) {
787     fieldSgn = commonParam->GetField() / fieldAbs;
788   }
789
790   const Int_t kNb = 5;
791   Float_t p0[kNb] = {  0.004810,  0.007412,  0.010252,  0.013409,  0.016888 };
792   Float_t p1[kNb] = {  0.054875,  0.081534,  0.107333,  0.131983,  0.155455 };
793   Float_t p2[kNb] = { -0.008682, -0.012896, -0.016987, -0.020880, -0.024623 };
794   Float_t p3[kNb] = {  0.000155,  0.000238,  0.000330,  0.000428,  0.000541 };
795
796   Int_t ib = ((Int_t) (10 * (fieldAbs - 0.15)));
797   ib       = TMath::Max(  0,ib);
798   ib       = TMath::Min(kNb,ib);
799
800   Float_t alphaL = p0[ib] 
801                  + p1[ib] * vdrift
802                  + p2[ib] * vdrift*vdrift
803                  + p3[ib] * vdrift*vdrift*vdrift;
804
805   return TMath::Tan(fieldSgn * alphaL);
806
807 }
808
809 //_____________________________________________________________________________
810 void AliTRDcalibDB::SamplePRF()
811 {
812   //
813   // Samples the pad response function (should maybe go somewhere else ...)
814   //
815
816   const Int_t kPRFbin = 61;
817
818   Float_t prf[kNplan][kPRFbin] = { 
819                    {2.9037e-02, 3.3608e-02, 3.9020e-02, 4.5292e-02,
820                     5.2694e-02, 6.1362e-02, 7.1461e-02, 8.3362e-02,
821                     9.7063e-02, 1.1307e-01, 1.3140e-01, 1.5235e-01,
822                     1.7623e-01, 2.0290e-01, 2.3294e-01, 2.6586e-01,
823                     3.0177e-01, 3.4028e-01, 3.8077e-01, 4.2267e-01,
824                     4.6493e-01, 5.0657e-01, 5.4655e-01, 5.8397e-01,
825                     6.1767e-01, 6.4744e-01, 6.7212e-01, 6.9188e-01,
826                     7.0627e-01, 7.1499e-01, 7.1851e-01, 7.1499e-01,
827                     7.0627e-01, 6.9188e-01, 6.7212e-01, 6.4744e-01,
828                     6.1767e-01, 5.8397e-01, 5.4655e-01, 5.0657e-01,
829                     4.6493e-01, 4.2267e-01, 3.8077e-01, 3.4028e-01,
830                     3.0177e-01, 2.6586e-01, 2.3294e-01, 2.0290e-01,
831                     1.7623e-01, 1.5235e-01, 1.3140e-01, 1.1307e-01,
832                     9.7063e-02, 8.3362e-02, 7.1461e-02, 6.1362e-02,
833                     5.2694e-02, 4.5292e-02, 3.9020e-02, 3.3608e-02,
834                     2.9037e-02},
835                    {2.5478e-02, 2.9695e-02, 3.4655e-02, 4.0454e-02,
836                     4.7342e-02, 5.5487e-02, 6.5038e-02, 7.6378e-02,
837                     8.9696e-02, 1.0516e-01, 1.2327e-01, 1.4415e-01,
838                     1.6794e-01, 1.9516e-01, 2.2573e-01, 2.5959e-01,
839                     2.9694e-01, 3.3719e-01, 3.7978e-01, 4.2407e-01,
840                     4.6889e-01, 5.1322e-01, 5.5569e-01, 5.9535e-01,
841                     6.3141e-01, 6.6259e-01, 6.8882e-01, 7.0983e-01,
842                     7.2471e-01, 7.3398e-01, 7.3761e-01, 7.3398e-01,
843                     7.2471e-01, 7.0983e-01, 6.8882e-01, 6.6259e-01,
844                     6.3141e-01, 5.9535e-01, 5.5569e-01, 5.1322e-01,
845                     4.6889e-01, 4.2407e-01, 3.7978e-01, 3.3719e-01,
846                     2.9694e-01, 2.5959e-01, 2.2573e-01, 1.9516e-01,
847                     1.6794e-01, 1.4415e-01, 1.2327e-01, 1.0516e-01,
848                     8.9696e-02, 7.6378e-02, 6.5038e-02, 5.5487e-02,
849                     4.7342e-02, 4.0454e-02, 3.4655e-02, 2.9695e-02,
850                     2.5478e-02},
851                    {2.2363e-02, 2.6233e-02, 3.0782e-02, 3.6140e-02,
852                     4.2535e-02, 5.0157e-02, 5.9197e-02, 6.9900e-02,
853                     8.2707e-02, 9.7811e-02, 1.1548e-01, 1.3601e-01,
854                     1.5998e-01, 1.8739e-01, 2.1840e-01, 2.5318e-01,
855                     2.9182e-01, 3.3373e-01, 3.7837e-01, 4.2498e-01,
856                     4.7235e-01, 5.1918e-01, 5.6426e-01, 6.0621e-01,
857                     6.4399e-01, 6.7700e-01, 7.0472e-01, 7.2637e-01,
858                     7.4206e-01, 7.5179e-01, 7.5551e-01, 7.5179e-01,
859                     7.4206e-01, 7.2637e-01, 7.0472e-01, 6.7700e-01,
860                     6.4399e-01, 6.0621e-01, 5.6426e-01, 5.1918e-01,
861                     4.7235e-01, 4.2498e-01, 3.7837e-01, 3.3373e-01,
862                     2.9182e-01, 2.5318e-01, 2.1840e-01, 1.8739e-01,
863                     1.5998e-01, 1.3601e-01, 1.1548e-01, 9.7811e-02,
864                     8.2707e-02, 6.9900e-02, 5.9197e-02, 5.0157e-02,
865                     4.2535e-02, 3.6140e-02, 3.0782e-02, 2.6233e-02,
866                     2.2363e-02},
867                    {1.9635e-02, 2.3167e-02, 2.7343e-02, 3.2293e-02,
868                     3.8224e-02, 4.5335e-02, 5.3849e-02, 6.4039e-02,
869                     7.6210e-02, 9.0739e-02, 1.0805e-01, 1.2841e-01,
870                     1.5216e-01, 1.7960e-01, 2.1099e-01, 2.4671e-01,
871                     2.8647e-01, 3.2996e-01, 3.7660e-01, 4.2547e-01,
872                     4.7536e-01, 5.2473e-01, 5.7215e-01, 6.1632e-01,
873                     6.5616e-01, 6.9075e-01, 7.1939e-01, 7.4199e-01,
874                     7.5838e-01, 7.6848e-01, 7.7227e-01, 7.6848e-01,
875                     7.5838e-01, 7.4199e-01, 7.1939e-01, 6.9075e-01,
876                     6.5616e-01, 6.1632e-01, 5.7215e-01, 5.2473e-01,
877                     4.7536e-01, 4.2547e-01, 3.7660e-01, 3.2996e-01,
878                     2.8647e-01, 2.4671e-01, 2.1099e-01, 1.7960e-01,
879                     1.5216e-01, 1.2841e-01, 1.0805e-01, 9.0739e-02,
880                     7.6210e-02, 6.4039e-02, 5.3849e-02, 4.5335e-02,
881                     3.8224e-02, 3.2293e-02, 2.7343e-02, 2.3167e-02,
882                     1.9635e-02},
883                    {1.7224e-02, 2.0450e-02, 2.4286e-02, 2.8860e-02,
884                     3.4357e-02, 4.0979e-02, 4.8966e-02, 5.8612e-02,
885                     7.0253e-02, 8.4257e-02, 1.0102e-01, 1.2094e-01,
886                     1.4442e-01, 1.7196e-01, 2.0381e-01, 2.4013e-01,
887                     2.8093e-01, 3.2594e-01, 3.7450e-01, 4.2563e-01,
888                     4.7796e-01, 5.2991e-01, 5.7974e-01, 6.2599e-01,
889                     6.6750e-01, 7.0344e-01, 7.3329e-01, 7.5676e-01,
890                     7.7371e-01, 7.8410e-01, 7.8793e-01, 7.8410e-01,
891                     7.7371e-01, 7.5676e-01, 7.3329e-01, 7.0344e-01,
892                     6.6750e-01, 6.2599e-01, 5.7974e-01, 5.2991e-01,
893                     4.7796e-01, 4.2563e-01, 3.7450e-01, 3.2594e-01,
894                     2.8093e-01, 2.4013e-01, 2.0381e-01, 1.7196e-01,
895                     1.4442e-01, 1.2094e-01, 1.0102e-01, 8.4257e-02,
896                     7.0253e-02, 5.8612e-02, 4.8966e-02, 4.0979e-02,
897                     3.4357e-02, 2.8860e-02, 2.4286e-02, 2.0450e-02,
898                     1.7224e-02},
899                    {1.5096e-02, 1.8041e-02, 2.1566e-02, 2.5793e-02,
900                     3.0886e-02, 3.7044e-02, 4.4515e-02, 5.3604e-02,
901                     6.4668e-02, 7.8109e-02, 9.4364e-02, 1.1389e-01,
902                     1.3716e-01, 1.6461e-01, 1.9663e-01, 2.3350e-01,
903                     2.7527e-01, 3.2170e-01, 3.7214e-01, 4.2549e-01,
904                     4.8024e-01, 5.3460e-01, 5.8677e-01, 6.3512e-01,
905                     6.7838e-01, 7.1569e-01, 7.4655e-01, 7.7071e-01,
906                     7.8810e-01, 7.9871e-01, 8.0255e-01, 7.9871e-01,
907                     7.8810e-01, 7.7071e-01, 7.4655e-01, 7.1569e-01,
908                     6.7838e-01, 6.3512e-01, 5.8677e-01, 5.3460e-01,
909                     4.8024e-01, 4.2549e-01, 3.7214e-01, 3.2170e-01,
910                     2.7527e-01, 2.3350e-01, 1.9663e-01, 1.6461e-01,
911                     1.3716e-01, 1.1389e-01, 9.4364e-02, 7.8109e-02,
912                     6.4668e-02, 5.3604e-02, 4.4515e-02, 3.7044e-02,
913                     3.0886e-02, 2.5793e-02, 2.1566e-02, 1.8041e-02,
914                     1.5096e-02}};
915
916   // More sampling precision with linear interpolation
917   fPRFlo  = -1.5;
918   fPRFhi  =  1.5;
919   Float_t pad[kPRFbin];
920   Int_t   sPRFbin = kPRFbin;  
921   Float_t sPRFwid = (fPRFhi - fPRFlo) / ((Float_t) sPRFbin);
922   for (Int_t iPad = 0; iPad < sPRFbin; iPad++) {
923     pad[iPad] = ((Float_t) iPad + 0.5) * sPRFwid + fPRFlo;
924   }
925   fPRFbin = 500;  
926   fPRFwid = (fPRFhi - fPRFlo) / ((Float_t) fPRFbin);
927   fPRFpad = ((Int_t) (1.0 / fPRFwid));
928
929   if (fPRFsmp) delete [] fPRFsmp;
930   fPRFsmp = new Float_t[kNplan*fPRFbin];
931
932   Int_t   ipos1;
933   Int_t   ipos2;
934   Float_t diff;
935
936   for (Int_t iPla = 0; iPla < kNplan; iPla++) {
937
938     for (Int_t iBin = 0; iBin < fPRFbin; iBin++) {
939
940       Float_t bin = (((Float_t) iBin) + 0.5) * fPRFwid + fPRFlo;
941       ipos1 = ipos2 = 0;
942       diff  = 0;
943       do {
944         diff = bin - pad[ipos2++];
945       } while ((diff > 0) && (ipos2 < kPRFbin));
946       if      (ipos2 == kPRFbin) {
947         fPRFsmp[iPla*fPRFbin+iBin] = prf[iPla][ipos2-1];
948       }
949       else if (ipos2 == 1) {
950         fPRFsmp[iPla*fPRFbin+iBin] = prf[iPla][ipos2-1];
951       }
952       else {
953         ipos2--;
954         if (ipos2 >= kPRFbin) ipos2 = kPRFbin - 1;
955         ipos1 = ipos2 - 1;
956         fPRFsmp[iPla*fPRFbin+iBin] = prf[iPla][ipos2] 
957                                    + diff * (prf[iPla][ipos2] - prf[iPla][ipos1]) 
958                                           / sPRFwid;
959       }
960
961     }
962   } 
963
964 }
965
966 //_____________________________________________________________________________
967 Int_t AliTRDcalibDB::PadResponse(Double_t signal, Double_t dist
968                                 , Int_t plane, Double_t *pad) const
969 {
970   //
971   // Applies the pad response
972   //
973
974   Int_t iBin  = ((Int_t) (( - dist - fPRFlo) / fPRFwid));
975   Int_t iOff  = plane * fPRFbin;
976
977   Int_t iBin0 = iBin - fPRFpad + iOff;
978   Int_t iBin1 = iBin           + iOff;
979   Int_t iBin2 = iBin + fPRFpad + iOff;
980
981   pad[0] = 0.0;
982   pad[1] = 0.0;
983   pad[2] = 0.0;
984   if ((iBin1 >= 0) && (iBin1 < (fPRFbin*kNplan))) {
985
986     if (iBin0 >= 0) {
987       pad[0] = signal * fPRFsmp[iBin0];
988     }
989     pad[1] = signal * fPRFsmp[iBin1];
990     if (iBin2 < (fPRFbin*kNplan)) {
991       pad[2] = signal * fPRFsmp[iBin2];
992     }
993
994     return 1;
995
996   }
997   else {
998
999     return 0;
1000
1001   }
1002
1003 }
1004