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