]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDcalibDB.cxx
c558283dd6c074b7fe3517530cfb863175f7fa8b
[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 <TClonesArray.h>
32 #include <TObjArray.h>
33
34 #include "AliCDBManager.h"
35 #include "AliCDBEntry.h"
36 #include "AliLog.h"
37
38 #include "AliTRDPIDReference.h"
39 #include "AliTRDcalibDB.h"
40
41 #include "Cal/AliTRDCalROC.h"
42 #include "Cal/AliTRDCalPad.h"
43 #include "Cal/AliTRDCalDet.h"
44 #include "Cal/AliTRDCalDCS.h"
45 #include "Cal/AliTRDCalDCSv2.h"
46 #include "Cal/AliTRDCalPID.h"
47 #include "Cal/AliTRDCalMonitoring.h"
48 #include "Cal/AliTRDCalChamberStatus.h"
49 #include "Cal/AliTRDCalPadStatus.h"
50 #include "Cal/AliTRDCalSingleChamberStatus.h"
51 #include "Cal/AliTRDCalTrkAttach.h"
52
53 ClassImp(AliTRDcalibDB)
54
55 AliTRDcalibDB *AliTRDcalibDB::fgInstance   = 0;
56 Bool_t         AliTRDcalibDB::fgTerminated = kFALSE;
57
58 //_ singleton implementation __________________________________________________
59 AliTRDcalibDB* AliTRDcalibDB::Instance()
60 {
61   //
62   // Singleton implementation
63   // Returns an instance of this class, it is created if neccessary
64   //
65   
66   if (fgTerminated != kFALSE) {
67     return 0;
68   }
69
70   if (fgInstance == 0) {
71     fgInstance = new AliTRDcalibDB();
72   }
73
74   return fgInstance;
75
76 }
77
78 //_____________________________________________________________________________
79 void AliTRDcalibDB::Terminate()
80 {
81   //
82   // Singleton implementation
83   // Deletes the instance of this class and sets the terminated flag,
84   // 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   ,fPIDResponse(NULL)
108 {
109   //
110   // Default constructor
111   //
112   // TODO Default runnumber is set to 0, this should be changed later
113   //      to an invalid value (e.g. -1) to prevent
114   // TODO invalid calibration data to be used.
115   //
116
117   for (Int_t i = 0; i < kCDBCacheSize; ++i) {
118     fCDBCache[i]   = 0;
119     fCDBEntries[i] = 0;
120   }
121   
122   // Create the sampled PRF
123   SamplePRF();
124   
125 }
126
127 //_____________________________________________________________________________
128 AliTRDcalibDB::AliTRDcalibDB(const AliTRDcalibDB &c)
129   :TObject(c)
130   ,fRun(-1)
131   ,fPRFsmp(0)
132   ,fPRFbin(0)
133   ,fPRFlo(0)
134   ,fPRFhi(0)
135   ,fPRFwid(0)
136   ,fPRFpad(0)
137   ,fPIDResponse(NULL)
138 {
139   //
140   // Copy constructor (not that it make any sense for a singleton...)
141   //
142
143   for (Int_t i = 0; i < kCDBCacheSize; ++i) {
144     fCDBCache[i]   = 0;
145     fCDBEntries[i] = 0;
146   }
147   
148   // Create the sampled PRF
149   SamplePRF();
150
151 }
152
153 //_____________________________________________________________________________
154 AliTRDcalibDB &AliTRDcalibDB::operator=(const AliTRDcalibDB &c) 
155 {
156   //
157   // Assignment operator (same as above ...)
158   //
159
160   if (this != &c) {
161     AliFatal("No assignment operator defined");
162   }
163
164   return *this;
165
166 }
167
168 //_____________________________________________________________________________
169 AliTRDcalibDB::~AliTRDcalibDB() 
170 {
171   //
172   // destructor
173   //
174   
175   if (fPRFsmp) {
176     delete [] fPRFsmp;
177     fPRFsmp = 0;
178   }
179   if(fPIDResponse) delete fPIDResponse;
180
181   Invalidate();
182
183 }
184
185 //_caching functions____________________________________________________________
186 const TObject *AliTRDcalibDB::GetCachedCDBObject(Int_t id)
187 {
188   //
189   // Retrieves a cdb object with the given id. The objects are cached as
190   // long as the run number is not changed.
191   //
192   // Put together the available objects here by using the lines
193   //   a) For usual calibration objects:
194   //      case kID<Name> : 
195   //        return CacheCDBEntry(kID<Name>,"TRD/Calib/<Path>"); 
196   //        break;
197   //      See function CacheCDBEntry for details.
198   //   and
199   //   b) For calibration data which depends on two objects: One containing 
200   //      a value per detector and one the local fluctuations per pad:
201   //      case kID<Name> :
202   //        return CacheMergeCDBEntry(kID<Name>,"TRD/Calib/<padPath>","TRD/Calib/<chamberPath>"); 
203   //        break;
204   //      See function CacheMergeCDBEntry for details.
205   //
206     
207   switch (id) {
208
209     // Parameters defined per pad and chamber
210     case kIDVdriftPad : 
211       return CacheCDBEntry(kIDVdriftPad         ,"TRD/Calib/LocalVdrift"); 
212       break;
213     case kIDVdriftChamber : 
214       return CacheCDBEntry(kIDVdriftChamber     ,"TRD/Calib/ChamberVdrift"); 
215       break;
216     case kIDT0Pad : 
217       return CacheCDBEntry(kIDT0Pad             ,"TRD/Calib/LocalT0"); 
218       break;
219     case kIDT0Chamber : 
220       return CacheCDBEntry(kIDT0Chamber         ,"TRD/Calib/ChamberT0"); 
221       break;
222     case kIDGainFactorPad : 
223       return CacheCDBEntry(kIDGainFactorPad     ,"TRD/Calib/LocalGainFactor"); 
224       break;
225     case kIDGainFactorChamber : 
226       return CacheCDBEntry(kIDGainFactorChamber ,"TRD/Calib/ChamberGainFactor"); 
227       break;
228     case kIDNoiseChamber : 
229       return CacheCDBEntry(kIDNoiseChamber ,"TRD/Calib/DetNoise"); 
230       break;
231     case kIDNoisePad : 
232       return CacheCDBEntry(kIDNoisePad ,"TRD/Calib/PadNoise"); 
233       break;
234
235
236     // Parameters defined per pad
237     case kIDPRFWidth : 
238       return CacheCDBEntry(kIDPRFWidth          ,"TRD/Calib/PRFWidth"); 
239       break;
240
241     // Status values
242     case kIDChamberStatus : 
243       return CacheCDBEntry(kIDChamberStatus     ,"TRD/Calib/ChamberStatus"); 
244       break;
245     case kIDPadStatus : 
246       return CacheCDBEntry(kIDPadStatus         ,"TRD/Calib/PadStatus"); 
247       break;
248
249     // Global parameters
250     case kIDMonitoringData : 
251       return CacheCDBEntry(kIDMonitoringData    ,"TRD/Calib/MonitoringData"); 
252       break;
253     case kIDFEE : 
254       return CacheCDBEntry(kIDFEE               ,"TRD/Calib/FEE"); 
255       break;
256     case kIDDCS :
257       return CacheCDBEntry(kIDDCS               ,"TRD/Calib/DCS");
258       break;
259     case kIDPIDNN : 
260       return CacheCDBEntry(kIDPIDNN             ,"TRD/Calib/PIDNN");
261     case kIDPIDLQ : 
262       return CacheCDBEntry(kIDPIDLQ             ,"TRD/Calib/PIDLQ"); 
263       break;
264     case kIDPIDLQ1D:
265       return CacheCDBEntry(kIDPIDLQ1D           ,"TRD/Calib/PIDLQ1D");
266       break;
267     case kIDRecoParam : 
268       return CacheCDBEntry(kIDRecoParam         ,"TRD/Calib/RecoParam"); 
269       break;
270     case kIDAttach : 
271       return CacheCDBEntry(kIDAttach            ,"TRD/Calib/TrkAttach"); 
272       break;
273   }
274
275   return 0;
276
277 }
278
279 //_____________________________________________________________________________
280 AliCDBEntry *AliTRDcalibDB::GetCDBEntry(const char *cdbPath)
281 {
282   // 
283   // Retrieves an entry with path <cdbPath> from the CDB.
284   //
285     
286   AliCDBEntry *entry = AliCDBManager::Instance()->Get(cdbPath,fRun);
287   if (!entry) { 
288     AliError(Form("Failed to get entry: %s",cdbPath));
289     return 0; 
290   }
291   
292   return entry;
293
294 }
295
296 //_____________________________________________________________________________
297 const TObject *AliTRDcalibDB::CacheCDBEntry(Int_t id, const char *cdbPath)
298 {
299   //
300   // Caches the entry <id> with cdb path <cdbPath>
301   //
302
303   if (!fCDBCache[id]) {
304     fCDBEntries[id] = GetCDBEntry(cdbPath);
305     if (fCDBEntries[id]) {
306       fCDBCache[id] = fCDBEntries[id]->GetObject();
307     }
308   } 
309   
310   return fCDBCache[id];
311 }
312
313 //_____________________________________________________________________________
314 void AliTRDcalibDB::SetRun(Long64_t run)
315 {
316   //
317   // Sets current run number. Calibration data is read from the corresponding file.
318   // When the run number changes the caching is invalidated.
319   //
320
321   if (fRun == run) {
322     return;
323   }
324
325   fRun = run;
326
327   Invalidate();
328
329 }
330
331 //_____________________________________________________________________________
332 void AliTRDcalibDB::Invalidate()
333 {
334   //
335   // Invalidates cache (when run number is changed).
336   //
337   
338   for (Int_t i = 0; i < kCDBCacheSize; ++i) {
339     if (fCDBEntries[i]) {
340       if (AliCDBManager::Instance()->GetCacheFlag() == kFALSE) {
341         if ((fCDBEntries[i]->IsOwner() == kFALSE) && 
342             (fCDBCache[i])) {
343           delete fCDBCache[i];
344         }
345         delete fCDBEntries[i];
346       }
347       fCDBEntries[i] = 0;
348       fCDBCache[i]   = 0;
349     }
350   }
351
352 }
353 //_____________________________________________________________________________
354 Float_t AliTRDcalibDB::GetNoise(Int_t det, Int_t col, Int_t row)
355 {
356   //
357   // Returns the noise level in ADC counts for the given pad.
358   //
359
360   const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
361                                    (GetCachedCDBObject(kIDNoisePad));
362   if (!calPad) {
363     return -1;
364   }
365
366   AliTRDCalROC       *roc        = calPad->GetCalROC(det);
367   if (!roc) {
368     return -1;
369   }
370
371   const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> 
372                                    (GetCachedCDBObject(kIDNoiseChamber));
373   if (!calChamber) {
374     return -1;
375   }
376
377   return calChamber->GetValue(det) * roc->GetValue(col,row);
378
379 }
380  
381 //_____________________________________________________________________________
382 AliTRDCalROC *AliTRDcalibDB::GetNoiseROC(Int_t det)
383 {
384   //
385   // Returns the Vdrift calibration object for a given ROC
386   // containing one number per pad 
387   //
388   
389   const AliTRDCalPad     *calPad     = dynamic_cast<const AliTRDCalPad *> 
390                                        (GetCachedCDBObject(kIDNoisePad));
391   if (!calPad) {
392     return 0;
393   }
394
395   AliTRDCalROC           *roc        = calPad->GetCalROC(det);
396   if (!roc) {
397     return 0;
398   }
399   else {
400     return roc;
401   }
402
403 }
404
405 //_____________________________________________________________________________
406 const AliTRDCalDet *AliTRDcalibDB::GetNoiseDet()
407 {
408   //
409   // Returns the Vdrift calibration object
410   // containing one number per detector
411   //
412   
413   const AliTRDCalDet     *calChamber = dynamic_cast<const AliTRDCalDet *> 
414                                        (GetCachedCDBObject(kIDNoiseChamber));
415   if (!calChamber) {
416     return 0;
417   }
418   else {
419     return calChamber;
420   }
421
422 }
423
424 //_____________________________________________________________________________
425 Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
426 {
427   //
428   // Returns the drift velocity for the given pad.
429   //
430
431   const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
432                                    (GetCachedCDBObject(kIDVdriftPad));
433   if (!calPad) {
434     return -1;
435   }
436
437   AliTRDCalROC       *roc        = calPad->GetCalROC(det);
438   if (!roc) {
439     return -1;
440   }
441
442   const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> 
443                                    (GetCachedCDBObject(kIDVdriftChamber));
444   if (!calChamber) {
445     return -1;
446   }
447
448   return calChamber->GetValue(det) * roc->GetValue(col,row);
449
450 }
451  
452 //_____________________________________________________________________________
453 AliTRDCalROC *AliTRDcalibDB::GetVdriftROC(Int_t det)
454 {
455   //
456   // Returns the Vdrift calibration object for a given ROC
457   // containing one number per pad 
458   //
459   
460   const AliTRDCalPad     *calPad     = dynamic_cast<const AliTRDCalPad *> 
461                                        (GetCachedCDBObject(kIDVdriftPad));
462   if (!calPad) {
463     return 0;
464   }
465
466   AliTRDCalROC           *roc        = calPad->GetCalROC(det);
467   if (!roc) {
468     return 0;
469   }
470   else {
471     return roc;
472   }
473
474 }
475
476 //_____________________________________________________________________________
477 const AliTRDCalDet *AliTRDcalibDB::GetVdriftDet()
478 {
479   //
480   // Returns the Vdrift calibration object
481   // containing one number per detector
482   //
483   
484   const AliTRDCalDet     *calChamber = dynamic_cast<const AliTRDCalDet *> 
485                                        (GetCachedCDBObject(kIDVdriftChamber));
486   if (!calChamber) {
487     return 0;
488   }
489   else {
490     return calChamber;
491   }
492
493 }
494
495 //_____________________________________________________________________________
496 Float_t AliTRDcalibDB::GetVdriftAverage(Int_t det)
497 {
498   //
499   // Returns the average drift velocity for the given detector
500   //
501
502   const AliTRDCalDet *calDet     = dynamic_cast<const AliTRDCalDet *> 
503                                    (GetCachedCDBObject(kIDVdriftChamber));
504   if (!calDet) {
505     return -1;
506   }
507
508   return calDet->GetValue(det);
509
510 }
511
512 //_____________________________________________________________________________
513 Float_t AliTRDcalibDB::GetT0(Int_t det, Int_t col, Int_t row)
514 {
515   //
516   // Returns t0 for the given pad.
517   //
518   
519   const AliTRDCalPad     *calPad     = dynamic_cast<const AliTRDCalPad *> 
520                                        (GetCachedCDBObject(kIDT0Pad));
521   if (!calPad) {
522     return -1;
523   }
524
525   AliTRDCalROC           *roc        = calPad->GetCalROC(det);
526   if (!roc) {
527     return -1;
528   }
529
530   const AliTRDCalDet     *calChamber = dynamic_cast<const AliTRDCalDet *> 
531                                        (GetCachedCDBObject(kIDT0Chamber));
532   if (!calChamber) {
533     return -1;
534   }
535
536   return calChamber->GetValue(det) + roc->GetValue(col,row);
537
538 }
539  
540 //_____________________________________________________________________________
541 AliTRDCalROC *AliTRDcalibDB::GetT0ROC(Int_t det)
542 {
543   //
544   // Returns the t0 calibration object for a given ROC
545   // containing one number per pad 
546   //
547   
548   const AliTRDCalPad     *calPad     = dynamic_cast<const AliTRDCalPad *> 
549                                        (GetCachedCDBObject(kIDT0Pad));
550   if (!calPad) {
551     return 0;
552   }
553
554   AliTRDCalROC           *roc        = calPad->GetCalROC(det);
555   if (!roc) {
556     return 0;
557   }
558   else {
559     return roc;
560   }
561
562 }
563
564 //_____________________________________________________________________________
565 const AliTRDCalDet *AliTRDcalibDB::GetT0Det()
566 {
567   //
568   // Returns the t0 calibration object
569   // containing one number per detector
570   //
571   
572   const AliTRDCalDet     *calChamber = dynamic_cast<const AliTRDCalDet *> 
573                                        (GetCachedCDBObject(kIDT0Chamber));
574   if (!calChamber) {
575     return 0;
576   }
577   else {
578     return calChamber;
579   }
580
581 }
582
583 //_____________________________________________________________________________
584 Float_t AliTRDcalibDB::GetT0Average(Int_t det)
585 {
586   //
587   // Returns the average t0 for the given detector
588   //
589
590   const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
591                                    (GetCachedCDBObject(kIDT0Pad));
592   if (!calPad) {
593     return -1;
594   }
595
596   AliTRDCalROC       *roc        = calPad->GetCalROC(det);
597   if (!roc) {
598     return -1;
599   }
600
601   const AliTRDCalDet *calDet     = dynamic_cast<const AliTRDCalDet *> 
602                                    (GetCachedCDBObject(kIDT0Chamber));
603   if (!calDet) {
604     return -1;
605   }
606
607   Double_t sum = 0.0; 
608   for (Int_t channel = 0; channel < roc->GetNchannels(); ++channel) {
609     sum += roc->GetValue(channel);
610   }
611   sum /= roc->GetNchannels();
612   sum += calDet->GetValue(det);
613   return sum;
614
615 }
616
617 //_____________________________________________________________________________
618 Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
619 {
620   //
621   // Returns the gain factor for the given pad.
622   //
623   
624   const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
625                                    (GetCachedCDBObject(kIDGainFactorPad));
626   if (!calPad) {
627     return -1;
628   }
629
630   AliTRDCalROC       *roc        = calPad->GetCalROC(det);
631   if (!roc) {
632     return -1;
633   }
634
635   const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> 
636                                    (GetCachedCDBObject(kIDGainFactorChamber));
637   if (!calChamber) {
638     return -1;
639   }
640
641   return calChamber->GetValue(det) * roc->GetValue(col,row);
642
643 }
644
645 //_____________________________________________________________________________
646 AliTRDCalROC *AliTRDcalibDB::GetGainFactorROC(Int_t det)
647 {
648   //
649   // Returns the gain factor calibration object for a given ROC
650   //
651   
652   const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
653                                    (GetCachedCDBObject(kIDGainFactorPad));
654   if (!calPad) {
655     return 0;
656   }
657
658   AliTRDCalROC       *roc        = calPad->GetCalROC(det);
659   if (!roc) {
660     return 0;
661   }
662   else {
663     return roc;
664   }
665
666 }
667
668 //_____________________________________________________________________________
669 const AliTRDCalDet *AliTRDcalibDB::GetGainFactorDet()
670 {
671   //
672   // Returns the gain factor calibration object
673   // containing one number per detector
674   //
675
676   const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> 
677                                    (GetCachedCDBObject(kIDGainFactorChamber));
678   if (!calChamber) {
679     return 0;
680   }
681   else {
682     return calChamber;
683   }
684
685 }
686
687 //_____________________________________________________________________________
688 Float_t AliTRDcalibDB::GetGainFactorAverage(Int_t det)
689 {
690   //
691   // Returns the average gain factor for the given detector
692   //
693
694   const AliTRDCalDet *calDet     = dynamic_cast<const AliTRDCalDet *> 
695                                    (GetCachedCDBObject(kIDGainFactorChamber));
696   if (!calDet) {
697     return -1;
698   }
699
700   return calDet->GetValue(det);
701
702 }
703
704 //_____________________________________________________________________________
705 AliTRDCalROC *AliTRDcalibDB::GetPRFROC(Int_t det)
706 {
707   //
708   // Returns the PRF calibration object for a given ROC
709   // containing one number per pad 
710   //
711   
712   const AliTRDCalPad     *calPad     = dynamic_cast<const AliTRDCalPad *> 
713                                        (GetCachedCDBObject(kIDPRFWidth));
714   if (!calPad) {
715     return 0;
716   }
717
718   AliTRDCalROC           *roc        = calPad->GetCalROC(det);
719   if (!roc) {
720     return 0;
721   }
722   else {
723     return roc;
724   }
725
726 }
727
728 //_____________________________________________________________________________
729 Float_t AliTRDcalibDB::GetPRFWidth(Int_t det, Int_t col, Int_t row)
730 {
731   //
732   // Returns the PRF width for the given pad.
733   //
734   
735   const AliTRDCalPad *calPad     = dynamic_cast<const AliTRDCalPad *> 
736                                    (GetCachedCDBObject(kIDPRFWidth));
737   if (!calPad) {
738     return -1;
739   }
740
741   AliTRDCalROC       *roc        = calPad->GetCalROC(det);
742   if (!roc) {
743     return -1;
744   }
745
746   return roc->GetValue(col,row);
747
748 }
749   
750 //_____________________________________________________________________________
751 Int_t AliTRDcalibDB::GetNumberOfTimeBinsDCS()
752 {
753   //
754   // Returns Number of time bins from the DCS
755   //
756
757   Int_t nMixed = -2; // not the same number for all chambers
758   Int_t nUndef = -1; // default value - has not been set!
759   Int_t nTbSor = nUndef;
760   Int_t nTbEor = nUndef;
761   Int_t calver = 0; // Check CalDCS version
762
763   const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
764   if (!dcsArr) {
765     AliError("No DCS object found!");
766     return nUndef;
767   }
768
769   if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS"))   calver = 1;
770   if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
771
772   if (calver == 1) {
773     // DCS object
774     const AliTRDCalDCS *calDCSsor = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(0));
775     const AliTRDCalDCS *calDCSeor = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(1));
776     if (!calDCSsor) {
777       // the SOR file is mandatory
778       AliError("NO SOR AliTRDCalDCS object found in CDB file!");
779       return nUndef;
780     }
781     if (!calDCSeor) {
782       // this can happen if the run is shorter than a couple of seconds.
783       AliWarning("NO EOR AliTRDCalDCS object found in CDB file.");
784     }
785
786     // get the numbers
787     nTbSor = calDCSsor->GetGlobalNumberOfTimeBins();
788     if (calDCSeor) nTbEor = calDCSeor->GetGlobalNumberOfTimeBins();
789
790   } else if (calver == 2) {
791     // DCSv2 object
792     const AliTRDCalDCSv2 *calDCSsorv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(0));
793     const AliTRDCalDCSv2 *calDCSeorv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(1));
794     if (!calDCSsorv2) {
795       // the SOR file is mandatory
796       AliError("NO SOR AliTRDCalDCSv2 object found in CDB file!");
797       return nUndef;
798     }
799     if (!calDCSeorv2) {
800       // this can happen if the run is shorter than a couple of seconds.
801       AliWarning("NO EOR AliTRDCalDCSv2 object found in CDB file.");
802     }
803
804     // get the numbers
805     nTbSor = calDCSsorv2->GetGlobalNumberOfTimeBins();
806     if (calDCSeorv2) nTbEor = calDCSeorv2->GetGlobalNumberOfTimeBins();
807
808   } else AliError("NO DCS/DCSv2 OCDB entry found!");
809
810   // if they're the same return the value
811   // -2 means mixed, -1: no data, >= 0: good number of time bins
812   if (nTbSor == nTbEor) return nTbSor;
813
814   // if they're differing:
815   if (nTbSor == nMixed || nTbEor == nMixed) {
816     AliWarning("Inconsistent number of time bins found!");
817     return nMixed;
818   }
819
820   // one is undefined, the other ok -> return that one
821   if (nTbSor == nUndef) return nTbEor;
822   if (nTbEor == nUndef) return nTbSor;
823
824   // only remains: two different numbers >= 0
825   return nMixed;
826 }
827
828 //_____________________________________________________________________________
829 void AliTRDcalibDB::GetFilterType(TString &filterType)
830 {
831   //
832   // Returns the filter type
833   //
834
835   const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
836   if(!dcsArr){
837     filterType = "";
838     return;
839   }
840
841   Int_t esor   = 0; // Take SOR
842   Int_t calver = 0; // Check CalDCS version
843   if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS"))   calver = 1;
844   if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
845
846   if (calver == 1) {
847     // DCS object
848     const AliTRDCalDCS *calDCS = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(esor));
849     if(!calDCS){
850       filterType = "";
851       return;
852     } 
853     filterType = calDCS->GetGlobalFilterType();
854   } else if (calver == 2) {
855     // DCSv2 object
856     const AliTRDCalDCSv2 *calDCSv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(esor));
857     if(!calDCSv2){
858       filterType = "";
859       return;
860     } 
861     filterType = calDCSv2->GetGlobalFilterType();
862   } else AliError("NO DCS/DCSv2 OCDB entry found!"); 
863
864 }
865
866 //_____________________________________________________________________________
867 void AliTRDcalibDB::GetGlobalConfiguration(TString &config){
868   //
869   // Get Configuration from the DCS
870   //
871
872   const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
873   if(!dcsArr){
874     config = "";
875     return;
876   }
877
878   Int_t esor   = 0; // Take SOR
879   Int_t calver = 0; // Check CalDCS version
880   if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS"))   calver = 1;
881   if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
882
883   if (calver == 1) {
884     // DCS object
885     const AliTRDCalDCS *calDCS = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(esor));
886     if(!calDCS){
887       config = "";
888       return;
889     } 
890     config = calDCS->GetGlobalConfigName();
891   } else if (calver == 2) {
892     // DCSv2 object
893     const AliTRDCalDCSv2 *calDCSv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(esor));
894     if(!calDCSv2){
895       config = "";
896       return;
897     } 
898     config = calDCSv2->GetGlobalConfigName();
899   } else AliError("NO DCS/DCSv2 OCDB entry found!");
900
901 }
902
903 //_____________________________________________________________________________
904 Bool_t AliTRDcalibDB::HasOnlineFilterPedestal()
905 {
906   //
907   // Checks whether pedestal filter was applied online
908   //
909   TString cname;
910   // Temporary: Get the filter config from the configuration name
911   GetGlobalConfiguration(cname);
912   TString filterconfig = cname(cname.First("_") + 1, cname.First("-") - cname.First("_") - 1);
913   // TString filterconfig;
914   //GetFilterType(filterconfig);
915   return filterconfig.Contains("p");
916 }
917
918 //_____________________________________________________________________________
919 Bool_t AliTRDcalibDB::HasOnlineFilterGain(){
920   //
921   // Checks whether online gain filter was applied
922   //
923   TString cname;
924   // Temporary: Get the filter config from the configuration name
925   GetGlobalConfiguration(cname);
926   TString filterconfig = cname(cname.First("_") + 1, cname.First("-") - cname.First("_") - 1);
927   //TString filterconfig;
928   //GetFilterType(filterconfig);
929   return filterconfig.Contains("g");
930 }
931
932 //_____________________________________________________________________________
933 Bool_t AliTRDcalibDB::HasOnlineTailCancellation(){
934   //
935   // Checks whether online tail cancellation was applied
936   //
937   TString cname;
938   // Temporary: Get the filter config from the configuration name
939   GetGlobalConfiguration(cname);
940   TString filterconfig = cname(cname.First("_") + 1, cname.First("-") - cname.First("_") - 1);
941   //TString filterconfig;
942   //GetFilterType(filterconfig);
943   return filterconfig.Contains("t");
944 }
945
946 //_____________________________________________________________________________
947 Char_t AliTRDcalibDB::GetPadStatus(Int_t det, Int_t col, Int_t row)
948 {
949   //
950   // Returns the status of the given pad
951   //
952
953   const AliTRDCalPadStatus *cal  = dynamic_cast<const AliTRDCalPadStatus *> 
954                                    (GetCachedCDBObject(kIDPadStatus));
955   if (!cal) {
956     return -1;
957   }
958
959   const AliTRDCalSingleChamberStatus *roc = cal->GetCalROC(det);
960   if (!roc) {
961     return -1;
962   }
963
964   return roc->GetStatus(col,row);
965
966 }
967
968 //_____________________________________________________________________________
969 AliTRDCalSingleChamberStatus* AliTRDcalibDB::GetPadStatusROC(Int_t det)
970 {
971   //
972   // Returns the pad status calibration object for a given ROC
973   //
974
975   const AliTRDCalPadStatus *cal  = dynamic_cast<const AliTRDCalPadStatus *> 
976                                    (GetCachedCDBObject(kIDPadStatus));
977   if (!cal) {
978     return 0;
979   }
980
981   AliTRDCalSingleChamberStatus *roc = cal->GetCalROC(det);
982   if (!roc) {
983     return 0;
984   }
985   else {
986     return roc;
987   }
988
989 }
990
991 //_____________________________________________________________________________
992 Char_t AliTRDcalibDB::GetChamberStatus(Int_t det)
993 {
994   //
995   // Returns the status of the given chamber
996   //
997
998   const AliTRDCalChamberStatus *cal = dynamic_cast<const AliTRDCalChamberStatus *> 
999                                       (GetCachedCDBObject(kIDChamberStatus));
1000   if (!cal) {
1001     return -1;
1002   }
1003
1004   return cal->GetStatus(det);
1005
1006 }
1007
1008 //_____________________________________________________________________________
1009 AliTRDrecoParam* AliTRDcalibDB::GetRecoParam(Int_t */*eventtype*/)
1010 {
1011   //
1012   // Returns the TRD reconstruction parameters from the OCDB
1013   //
1014
1015   const TClonesArray *recos = dynamic_cast<const TClonesArray*>(GetCachedCDBObject(kIDRecoParam));
1016   if (!recos) return 0x0;
1017
1018   // calculate entry based on event type info
1019   Int_t n = 0; //f(eventtype[0], eventtype[1], ....)
1020
1021   return (AliTRDrecoParam*)recos->UncheckedAt(n);
1022
1023 }
1024
1025 //_____________________________________________________________________________
1026 Bool_t AliTRDcalibDB::IsPadMasked(Int_t det, Int_t col, Int_t row)
1027 {
1028   //
1029   // Returns status, see name of functions for details ;-)
1030   //
1031
1032   const AliTRDCalPadStatus         *cal = dynamic_cast<const AliTRDCalPadStatus *> 
1033                                           (GetCachedCDBObject(kIDPadStatus));
1034   if (!cal) {
1035     return -1;
1036   }
1037
1038   return cal->IsMasked(det,col,row);
1039
1040 }
1041
1042 //_____________________________________________________________________________
1043 Bool_t AliTRDcalibDB::IsPadBridgedLeft(Int_t det, Int_t col, Int_t row)
1044 {
1045   //
1046   // Returns status, see name of functions for details ;-)
1047   //
1048
1049   const AliTRDCalPadStatus         *cal = dynamic_cast<const AliTRDCalPadStatus *> 
1050                                           (GetCachedCDBObject(kIDPadStatus));
1051   if (!cal) {
1052     return -1;
1053   }
1054
1055   return cal->IsBridgedLeft(det,col,row);
1056
1057 }
1058
1059 //_____________________________________________________________________________
1060 Bool_t AliTRDcalibDB::IsPadBridgedRight(Int_t det, Int_t col, Int_t row)
1061 {
1062   //
1063   // Returns status, see name of functions for details ;-)
1064   //
1065
1066   const AliTRDCalPadStatus         * cal = dynamic_cast<const AliTRDCalPadStatus *> 
1067                                            (GetCachedCDBObject(kIDPadStatus));
1068   if (!cal) {
1069     return -1;
1070   }
1071
1072   return cal->IsBridgedRight(det,col,row);
1073
1074 }
1075
1076 //_____________________________________________________________________________
1077 Bool_t AliTRDcalibDB::IsPadNotConnected(Int_t det, Int_t col, Int_t row)
1078 {
1079   //
1080   // Returns status, see name of functions for details ;-)
1081   //
1082
1083   const AliTRDCalPadStatus         * cal = dynamic_cast<const AliTRDCalPadStatus *> 
1084                                            (GetCachedCDBObject(kIDPadStatus));
1085   if (!cal) {
1086     return -1;
1087   }
1088
1089   return cal->IsNotConnected(det,col,row);
1090
1091 }
1092
1093 //_____________________________________________________________________________
1094 Bool_t AliTRDcalibDB::IsChamberInstalled(Int_t det)
1095 {
1096   //
1097   // Returns status, see name of functions for details ;-)
1098   //
1099
1100   const AliTRDCalChamberStatus     * cal = dynamic_cast<const AliTRDCalChamberStatus *> 
1101                                            (GetCachedCDBObject(kIDChamberStatus));
1102   if (!cal) {
1103     return -1;
1104   }
1105
1106   return cal->IsInstalled(det);
1107
1108 }
1109
1110 //_____________________________________________________________________________
1111 Bool_t AliTRDcalibDB::IsChamberMasked(Int_t det)
1112 {
1113   //
1114   // Returns status, see name of functions for details ;-)
1115   //
1116
1117   const AliTRDCalChamberStatus     * cal = dynamic_cast<const AliTRDCalChamberStatus *> 
1118                                            (GetCachedCDBObject(kIDChamberStatus));
1119   if (!cal) {
1120     return -1;
1121   }
1122
1123   return cal->IsMasked(det);
1124
1125 }
1126 //_____________________________________________________________________________
1127 Bool_t AliTRDcalibDB::IsHalfChamberMasked(Int_t det, Int_t side){
1128   //
1129   // Returns status, see name of functions for details ;-)
1130   //
1131
1132   const AliTRDCalChamberStatus     * cal = dynamic_cast<const AliTRDCalChamberStatus *> 
1133                                            (GetCachedCDBObject(kIDChamberStatus));
1134   if (!cal) {
1135     return -1;
1136   }
1137
1138   return side > 0 ? cal->IsHalfChamberSideBMasked(det) : cal->IsHalfChamberSideAMasked(det);
1139
1140 }
1141 //_____________________________________________________________________________
1142 const AliTRDCalPID *AliTRDcalibDB::GetPIDObject(AliTRDpidUtil::ETRDPIDMethod method)
1143 {
1144   //
1145   // Returns the object storing the distributions for PID with likelihood
1146   //
1147
1148   switch(method) {
1149   case AliTRDpidUtil::kLQ: 
1150     return dynamic_cast<const AliTRDCalPID *>(GetCachedCDBObject(kIDPIDLQ));
1151   case AliTRDpidUtil::kNN: 
1152     return dynamic_cast<const AliTRDCalPID *>(GetCachedCDBObject(kIDPIDNN));
1153   case AliTRDpidUtil::kESD:
1154     return 0x0; // To avoid compiler warnings 
1155   }
1156
1157   return 0x0;
1158
1159 }
1160
1161 //_____________________________________________________________________________
1162 AliTRDPIDResponse *AliTRDcalibDB::GetPIDResponse(AliTRDPIDResponse::ETRDPIDMethod method){
1163   if(!fPIDResponse){
1164     fPIDResponse = new AliTRDPIDResponse;
1165     // Load Reference Histos from OCDB
1166     fPIDResponse->SetPIDmethod(method);
1167     const TObjArray *references = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDPIDLQ1D));
1168     TIter refs(references);
1169     TObject *obj = NULL;
1170     AliTRDPIDReference *ref = NULL;
1171     Bool_t hasReference = kFALSE;
1172     while((obj = refs())){
1173         if((ref = dynamic_cast<AliTRDPIDReference *>(obj))){
1174                 fPIDResponse->Load(ref);
1175                 hasReference = kTRUE;
1176                 break;
1177         }
1178     }
1179     if(!hasReference) AliError("Reference histograms not found in the OCDB");
1180   }
1181   return fPIDResponse;
1182 }
1183
1184 //_____________________________________________________________________________
1185 const AliTRDCalTrkAttach* AliTRDcalibDB::GetAttachObject()
1186 {
1187   //
1188   // Returns the object storing likelihood distributions for cluster to track attachment
1189   //
1190   return dynamic_cast<const AliTRDCalTrkAttach*>(GetCachedCDBObject(kIDAttach));
1191 }
1192
1193
1194 //_____________________________________________________________________________
1195 const AliTRDCalMonitoring *AliTRDcalibDB::GetMonitoringObject()
1196 {
1197   //
1198   // Returns the object storing the monitoring data
1199   //
1200
1201   return dynamic_cast<const AliTRDCalMonitoring *> 
1202          (GetCachedCDBObject(kIDMonitoringData));
1203    
1204 }
1205
1206 //_____________________________________________________________________________
1207 void AliTRDcalibDB::SamplePRF()
1208 {
1209   //
1210   // Samples the pad response function (should maybe go somewhere else ...)
1211   //
1212
1213   const Int_t kPRFbin = 61;
1214
1215   Float_t prf[kNlayer][kPRFbin] = { 
1216                    {2.9037e-02, 3.3608e-02, 3.9020e-02, 4.5292e-02,
1217                     5.2694e-02, 6.1362e-02, 7.1461e-02, 8.3362e-02,
1218                     9.7063e-02, 1.1307e-01, 1.3140e-01, 1.5235e-01,
1219                     1.7623e-01, 2.0290e-01, 2.3294e-01, 2.6586e-01,
1220                     3.0177e-01, 3.4028e-01, 3.8077e-01, 4.2267e-01,
1221                     4.6493e-01, 5.0657e-01, 5.4655e-01, 5.8397e-01,
1222                     6.1767e-01, 6.4744e-01, 6.7212e-01, 6.9188e-01,
1223                     7.0627e-01, 7.1499e-01, 7.1851e-01, 7.1499e-01,
1224                     7.0627e-01, 6.9188e-01, 6.7212e-01, 6.4744e-01,
1225                     6.1767e-01, 5.8397e-01, 5.4655e-01, 5.0657e-01,
1226                     4.6493e-01, 4.2267e-01, 3.8077e-01, 3.4028e-01,
1227                     3.0177e-01, 2.6586e-01, 2.3294e-01, 2.0290e-01,
1228                     1.7623e-01, 1.5235e-01, 1.3140e-01, 1.1307e-01,
1229                     9.7063e-02, 8.3362e-02, 7.1461e-02, 6.1362e-02,
1230                     5.2694e-02, 4.5292e-02, 3.9020e-02, 3.3608e-02,
1231                     2.9037e-02},
1232                    {2.5478e-02, 2.9695e-02, 3.4655e-02, 4.0454e-02,
1233                     4.7342e-02, 5.5487e-02, 6.5038e-02, 7.6378e-02,
1234                     8.9696e-02, 1.0516e-01, 1.2327e-01, 1.4415e-01,
1235                     1.6794e-01, 1.9516e-01, 2.2573e-01, 2.5959e-01,
1236                     2.9694e-01, 3.3719e-01, 3.7978e-01, 4.2407e-01,
1237                     4.6889e-01, 5.1322e-01, 5.5569e-01, 5.9535e-01,
1238                     6.3141e-01, 6.6259e-01, 6.8882e-01, 7.0983e-01,
1239                     7.2471e-01, 7.3398e-01, 7.3761e-01, 7.3398e-01,
1240                     7.2471e-01, 7.0983e-01, 6.8882e-01, 6.6259e-01,
1241                     6.3141e-01, 5.9535e-01, 5.5569e-01, 5.1322e-01,
1242                     4.6889e-01, 4.2407e-01, 3.7978e-01, 3.3719e-01,
1243                     2.9694e-01, 2.5959e-01, 2.2573e-01, 1.9516e-01,
1244                     1.6794e-01, 1.4415e-01, 1.2327e-01, 1.0516e-01,
1245                     8.9696e-02, 7.6378e-02, 6.5038e-02, 5.5487e-02,
1246                     4.7342e-02, 4.0454e-02, 3.4655e-02, 2.9695e-02,
1247                     2.5478e-02},
1248                    {2.2363e-02, 2.6233e-02, 3.0782e-02, 3.6140e-02,
1249                     4.2535e-02, 5.0157e-02, 5.9197e-02, 6.9900e-02,
1250                     8.2707e-02, 9.7811e-02, 1.1548e-01, 1.3601e-01,
1251                     1.5998e-01, 1.8739e-01, 2.1840e-01, 2.5318e-01,
1252                     2.9182e-01, 3.3373e-01, 3.7837e-01, 4.2498e-01,
1253                     4.7235e-01, 5.1918e-01, 5.6426e-01, 6.0621e-01,
1254                     6.4399e-01, 6.7700e-01, 7.0472e-01, 7.2637e-01,
1255                     7.4206e-01, 7.5179e-01, 7.5551e-01, 7.5179e-01,
1256                     7.4206e-01, 7.2637e-01, 7.0472e-01, 6.7700e-01,
1257                     6.4399e-01, 6.0621e-01, 5.6426e-01, 5.1918e-01,
1258                     4.7235e-01, 4.2498e-01, 3.7837e-01, 3.3373e-01,
1259                     2.9182e-01, 2.5318e-01, 2.1840e-01, 1.8739e-01,
1260                     1.5998e-01, 1.3601e-01, 1.1548e-01, 9.7811e-02,
1261                     8.2707e-02, 6.9900e-02, 5.9197e-02, 5.0157e-02,
1262                     4.2535e-02, 3.6140e-02, 3.0782e-02, 2.6233e-02,
1263                     2.2363e-02},
1264                    {1.9635e-02, 2.3167e-02, 2.7343e-02, 3.2293e-02,
1265                     3.8224e-02, 4.5335e-02, 5.3849e-02, 6.4039e-02,
1266                     7.6210e-02, 9.0739e-02, 1.0805e-01, 1.2841e-01,
1267                     1.5216e-01, 1.7960e-01, 2.1099e-01, 2.4671e-01,
1268                     2.8647e-01, 3.2996e-01, 3.7660e-01, 4.2547e-01,
1269                     4.7536e-01, 5.2473e-01, 5.7215e-01, 6.1632e-01,
1270                     6.5616e-01, 6.9075e-01, 7.1939e-01, 7.4199e-01,
1271                     7.5838e-01, 7.6848e-01, 7.7227e-01, 7.6848e-01,
1272                     7.5838e-01, 7.4199e-01, 7.1939e-01, 6.9075e-01,
1273                     6.5616e-01, 6.1632e-01, 5.7215e-01, 5.2473e-01,
1274                     4.7536e-01, 4.2547e-01, 3.7660e-01, 3.2996e-01,
1275                     2.8647e-01, 2.4671e-01, 2.1099e-01, 1.7960e-01,
1276                     1.5216e-01, 1.2841e-01, 1.0805e-01, 9.0739e-02,
1277                     7.6210e-02, 6.4039e-02, 5.3849e-02, 4.5335e-02,
1278                     3.8224e-02, 3.2293e-02, 2.7343e-02, 2.3167e-02,
1279                     1.9635e-02},
1280                    {1.7224e-02, 2.0450e-02, 2.4286e-02, 2.8860e-02,
1281                     3.4357e-02, 4.0979e-02, 4.8966e-02, 5.8612e-02,
1282                     7.0253e-02, 8.4257e-02, 1.0102e-01, 1.2094e-01,
1283                     1.4442e-01, 1.7196e-01, 2.0381e-01, 2.4013e-01,
1284                     2.8093e-01, 3.2594e-01, 3.7450e-01, 4.2563e-01,
1285                     4.7796e-01, 5.2991e-01, 5.7974e-01, 6.2599e-01,
1286                     6.6750e-01, 7.0344e-01, 7.3329e-01, 7.5676e-01,
1287                     7.7371e-01, 7.8410e-01, 7.8793e-01, 7.8410e-01,
1288                     7.7371e-01, 7.5676e-01, 7.3329e-01, 7.0344e-01,
1289                     6.6750e-01, 6.2599e-01, 5.7974e-01, 5.2991e-01,
1290                     4.7796e-01, 4.2563e-01, 3.7450e-01, 3.2594e-01,
1291                     2.8093e-01, 2.4013e-01, 2.0381e-01, 1.7196e-01,
1292                     1.4442e-01, 1.2094e-01, 1.0102e-01, 8.4257e-02,
1293                     7.0253e-02, 5.8612e-02, 4.8966e-02, 4.0979e-02,
1294                     3.4357e-02, 2.8860e-02, 2.4286e-02, 2.0450e-02,
1295                     1.7224e-02},
1296                    {1.5096e-02, 1.8041e-02, 2.1566e-02, 2.5793e-02,
1297                     3.0886e-02, 3.7044e-02, 4.4515e-02, 5.3604e-02,
1298                     6.4668e-02, 7.8109e-02, 9.4364e-02, 1.1389e-01,
1299                     1.3716e-01, 1.6461e-01, 1.9663e-01, 2.3350e-01,
1300                     2.7527e-01, 3.2170e-01, 3.7214e-01, 4.2549e-01,
1301                     4.8024e-01, 5.3460e-01, 5.8677e-01, 6.3512e-01,
1302                     6.7838e-01, 7.1569e-01, 7.4655e-01, 7.7071e-01,
1303                     7.8810e-01, 7.9871e-01, 8.0255e-01, 7.9871e-01,
1304                     7.8810e-01, 7.7071e-01, 7.4655e-01, 7.1569e-01,
1305                     6.7838e-01, 6.3512e-01, 5.8677e-01, 5.3460e-01,
1306                     4.8024e-01, 4.2549e-01, 3.7214e-01, 3.2170e-01,
1307                     2.7527e-01, 2.3350e-01, 1.9663e-01, 1.6461e-01,
1308                     1.3716e-01, 1.1389e-01, 9.4364e-02, 7.8109e-02,
1309                     6.4668e-02, 5.3604e-02, 4.4515e-02, 3.7044e-02,
1310                     3.0886e-02, 2.5793e-02, 2.1566e-02, 1.8041e-02,
1311                     1.5096e-02}};
1312
1313   // More sampling precision with linear interpolation
1314   fPRFlo  = -1.5;
1315   fPRFhi  =  1.5;
1316   Float_t pad[kPRFbin];
1317   Int_t   sPRFbin = kPRFbin;  
1318   Float_t sPRFwid = (fPRFhi - fPRFlo) / ((Float_t) sPRFbin);
1319   for (Int_t iPad = 0; iPad < sPRFbin; iPad++) {
1320     pad[iPad] = ((Float_t) iPad + 0.5) * sPRFwid + fPRFlo;
1321   }
1322   fPRFbin = 500;  
1323   fPRFwid = (fPRFhi - fPRFlo) / ((Float_t) fPRFbin);
1324   fPRFpad = ((Int_t) (1.0 / fPRFwid));
1325
1326   if (fPRFsmp) delete [] fPRFsmp;
1327   fPRFsmp = new Float_t[kNlayer*fPRFbin];
1328
1329   Int_t   ipos1;
1330   Int_t   ipos2;
1331   Float_t diff;
1332
1333   for (Int_t iLayer = 0; iLayer < kNlayer; iLayer++) {
1334
1335     for (Int_t iBin = 0; iBin < fPRFbin; iBin++) {
1336
1337       Float_t bin = (((Float_t) iBin) + 0.5) * fPRFwid + fPRFlo;
1338       ipos1 = ipos2 = 0;
1339       diff  = 0;
1340       do {
1341         diff = bin - pad[ipos2++];
1342       } while ((diff > 0) && (ipos2 < kPRFbin));
1343       if      (ipos2 == kPRFbin) {
1344         fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2-1];
1345       }
1346       else if (ipos2 == 1) {
1347         fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2-1];
1348       }
1349       else {
1350         ipos2--;
1351         if (ipos2 >= kPRFbin) ipos2 = kPRFbin - 1;
1352         ipos1 = ipos2 - 1;
1353         fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2] 
1354                                      + diff * (prf[iLayer][ipos2] - prf[iLayer][ipos1]) 
1355                                      / sPRFwid;
1356       }
1357
1358     }
1359   } 
1360
1361 }
1362
1363 //_____________________________________________________________________________
1364 Int_t AliTRDcalibDB::PadResponse(Double_t signal, Double_t dist
1365                                , Int_t layer, Double_t *pad) const
1366 {
1367   //
1368   // Applies the pad response
1369   // So far this is the fixed parametrization and should be replaced by
1370   // something dependent on calibration values
1371   //
1372
1373   Int_t iBin  = ((Int_t) ((-dist - fPRFlo) / fPRFwid));
1374   Int_t iOff  = layer * fPRFbin;
1375
1376   Int_t iBin0 = iBin - fPRFpad + iOff;
1377   Int_t iBin1 = iBin           + iOff;
1378   Int_t iBin2 = iBin + fPRFpad + iOff;
1379
1380   pad[0] = 0.0;
1381   pad[1] = 0.0;
1382   pad[2] = 0.0;
1383   if ((iBin1 >= 0) && (iBin1 < (fPRFbin*kNlayer))) {
1384
1385     if (iBin0 >= 0) {
1386       pad[0] = signal * fPRFsmp[iBin0];
1387     }
1388     pad[1] = signal * fPRFsmp[iBin1];
1389     if (iBin2 < (fPRFbin*kNlayer)) {
1390       pad[2] = signal * fPRFsmp[iBin2];
1391     }
1392
1393     return 1;
1394
1395   }
1396   else {
1397
1398     return 0;
1399
1400   }
1401
1402 }
1403
1404