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