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