1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Class providing the calibration parameters by accessing the CDB //
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 //
27 // Jan Fiete Grosse-Oetringhaus (Jan.Fiete.Grosse-Oetringhaus@cern.ch) //
29 ///////////////////////////////////////////////////////////////////////////////
31 #include <TClonesArray.h>
32 #include <TObjArray.h>
34 #include "AliCDBManager.h"
35 #include "AliCDBEntry.h"
38 #include "AliTRDPIDReference.h"
39 #include "AliTRDcalibDB.h"
40 #include "AliTRDCommonParam.h"
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"
56 ClassImp(AliTRDcalibDB)
58 AliTRDcalibDB *AliTRDcalibDB::fgInstance = 0;
59 Bool_t AliTRDcalibDB::fgTerminated = kFALSE;
61 //_ singleton implementation __________________________________________________
62 AliTRDcalibDB* AliTRDcalibDB::Instance()
65 // Singleton implementation
66 // Returns an instance of this class, it is created if neccessary
69 if (fgTerminated != kFALSE) {
73 if (fgInstance == 0) {
74 fgInstance = new AliTRDcalibDB();
81 //_____________________________________________________________________________
82 void AliTRDcalibDB::Terminate()
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.
93 if (fgInstance != 0) {
100 //_____________________________________________________________________________
101 AliTRDcalibDB::AliTRDcalibDB()
111 ,fOnlineGainTableID(0)
114 // Default constructor
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.
121 for (Int_t i = 0; i < kCDBCacheSize; ++i) {
126 // Create the sampled PRF
131 //_____________________________________________________________________________
132 AliTRDcalibDB::AliTRDcalibDB(const AliTRDcalibDB &c)
142 ,fOnlineGainTableID(0)
145 // Copy constructor (not that it make any sense for a singleton...)
148 for (Int_t i = 0; i < kCDBCacheSize; ++i) {
153 // Create the sampled PRF
158 //_____________________________________________________________________________
159 AliTRDcalibDB &AliTRDcalibDB::operator=(const AliTRDcalibDB &c)
162 // Assignment operator (same as above ...)
166 AliFatal("No assignment operator defined");
173 //_____________________________________________________________________________
174 AliTRDcalibDB::~AliTRDcalibDB()
194 //_caching functions____________________________________________________________
195 const TObject *AliTRDcalibDB::GetCachedCDBObject(Int_t id)
198 // Retrieves a cdb object with the given id. The objects are cached as
199 // long as the run number is not changed.
201 // Put together the available objects here by using the lines
202 // a) For usual calibration objects:
204 // return CacheCDBEntry(kID<Name>,"TRD/Calib/<Path>");
206 // See function CacheCDBEntry for details.
208 // b) For calibration data which depends on two objects: One containing
209 // a value per detector and one the local fluctuations per pad:
211 // return CacheMergeCDBEntry(kID<Name>,"TRD/Calib/<padPath>","TRD/Calib/<chamberPath>");
213 // See function CacheMergeCDBEntry for details.
218 // Parameters defined per pad and chamber
220 return CacheCDBEntry(kIDVdriftPad ,"TRD/Calib/LocalVdrift");
222 case kIDVdriftChamber :
223 return CacheCDBEntry(kIDVdriftChamber ,"TRD/Calib/ChamberVdrift");
226 return CacheCDBEntry(kIDExBChamber ,"TRD/Calib/ChamberExB");
229 return CacheCDBEntry(kIDT0Pad ,"TRD/Calib/LocalT0");
232 return CacheCDBEntry(kIDT0Chamber ,"TRD/Calib/ChamberT0");
234 case kIDGainFactorPad :
235 return CacheCDBEntry(kIDGainFactorPad ,"TRD/Calib/LocalGainFactor");
237 case kIDGainFactorChamber :
238 return CacheCDBEntry(kIDGainFactorChamber ,"TRD/Calib/ChamberGainFactor");
241 case kIDOnlineGainFactor :
242 switch(GetOnlineGainTableID()) {
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");
249 // Online gain table ID 1
250 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Krypton_2011-01");
253 // Online gain table ID 2
254 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Gaintbl_Uniform_FGAN0_2011-01");
257 // Online gain table ID 3
258 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Gaintbl_Uniform_FGAN8_2011-01");
263 case kIDNoiseChamber :
264 return CacheCDBEntry(kIDNoiseChamber ,"TRD/Calib/DetNoise");
267 return CacheCDBEntry(kIDNoisePad ,"TRD/Calib/PadNoise");
270 // Parameters defined per pad
272 return CacheCDBEntry(kIDPRFWidth ,"TRD/Calib/PRFWidth");
276 case kIDChamberStatus :
277 return CacheCDBEntry(kIDChamberStatus ,"TRD/Calib/ChamberStatus");
280 return CacheCDBEntry(kIDPadStatus ,"TRD/Calib/PadStatus");
284 case kIDMonitoringData :
285 return CacheCDBEntry(kIDMonitoringData ,"TRD/Calib/MonitoringData");
288 return CacheCDBEntry(kIDFEE ,"TRD/Calib/FEE");
291 return CacheCDBEntry(kIDDCS ,"TRD/Calib/DCS");
294 return CacheCDBEntry(kIDPIDNN ,"TRD/Calib/PIDNN");
297 return CacheCDBEntry(kIDPIDLQ ,"TRD/Calib/PIDLQ");
300 return CacheCDBEntry(kIDPIDLQ1D ,"TRD/Calib/PIDLQ1D");
303 return CacheCDBEntry(kIDRecoParam ,"TRD/Calib/RecoParam");
306 return CacheCDBEntry(kIDAttach ,"TRD/Calib/TrkAttach");
314 //_____________________________________________________________________________
315 AliCDBEntry *AliTRDcalibDB::GetCDBEntry(const char *cdbPath)
318 // Retrieves an entry with path <cdbPath> from the CDB.
321 AliCDBEntry *entry = AliCDBManager::Instance()->Get(cdbPath,fRun);
323 AliError(Form("Failed to get entry: %s",cdbPath));
331 //_____________________________________________________________________________
332 const TObject *AliTRDcalibDB::CacheCDBEntry(Int_t id, const char *cdbPath)
335 // Caches the entry <id> with cdb path <cdbPath>
338 if (!fCDBCache[id]) {
339 fCDBEntries[id] = GetCDBEntry(cdbPath);
340 if (fCDBEntries[id]) {
341 fCDBCache[id] = fCDBEntries[id]->GetObject();
345 return fCDBCache[id];
349 //_____________________________________________________________________________
350 void AliTRDcalibDB::SetRun(Long64_t run)
353 // Sets current run number. Calibration data is read from the corresponding file.
354 // When the run number changes the caching is invalidated.
367 //_____________________________________________________________________________
368 void AliTRDcalibDB::Invalidate()
371 // Invalidates cache (when run number is changed).
374 for (Int_t i = 0; i < kCDBCacheSize; ++i) {
375 if (fCDBEntries[i]) {
376 if (AliCDBManager::Instance()->GetCacheFlag() == kFALSE) {
377 if ((fCDBEntries[i]->IsOwner() == kFALSE) &&
381 delete fCDBEntries[i];
388 fOnlineGainTableID = 0;
392 //_____________________________________________________________________________
393 Float_t AliTRDcalibDB::GetNoise(Int_t det, Int_t col, Int_t row)
396 // Returns the noise level in ADC counts for the given pad.
399 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
400 (GetCachedCDBObject(kIDNoisePad));
405 AliTRDCalROC *roc = calPad->GetCalROC(det);
410 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
411 (GetCachedCDBObject(kIDNoiseChamber));
416 return calChamber->GetValue(det) * roc->GetValue(col,row);
420 //_____________________________________________________________________________
421 AliTRDCalROC *AliTRDcalibDB::GetNoiseROC(Int_t det)
424 // Returns the Vdrift calibration object for a given ROC
425 // containing one number per pad
428 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
429 (GetCachedCDBObject(kIDNoisePad));
434 AliTRDCalROC *roc = calPad->GetCalROC(det);
444 //_____________________________________________________________________________
445 const AliTRDCalDet *AliTRDcalibDB::GetNoiseDet()
448 // Returns the Vdrift calibration object
449 // containing one number per detector
452 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
453 (GetCachedCDBObject(kIDNoiseChamber));
463 //_____________________________________________________________________________
464 Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
467 // Returns the drift velocity for the given pad.
470 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
471 (GetCachedCDBObject(kIDVdriftPad));
476 AliTRDCalROC *roc = calPad->GetCalROC(det);
481 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
482 (GetCachedCDBObject(kIDVdriftChamber));
487 return calChamber->GetValue(det) * roc->GetValue(col,row);
491 //_____________________________________________________________________________
492 AliTRDCalROC *AliTRDcalibDB::GetVdriftROC(Int_t det)
495 // Returns the Vdrift calibration object for a given ROC
496 // containing one number per pad
499 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
500 (GetCachedCDBObject(kIDVdriftPad));
505 AliTRDCalROC *roc = calPad->GetCalROC(det);
515 //_____________________________________________________________________________
516 const AliTRDCalDet *AliTRDcalibDB::GetVdriftDet()
519 // Returns the Vdrift calibration object
520 // containing one number per detector
523 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
524 (GetCachedCDBObject(kIDVdriftChamber));
534 //_____________________________________________________________________________
535 Float_t AliTRDcalibDB::GetVdriftAverage(Int_t det)
538 // Returns the average drift velocity for the given detector
541 const AliTRDCalDet *calDet = dynamic_cast<const AliTRDCalDet *>
542 (GetCachedCDBObject(kIDVdriftChamber));
547 return calDet->GetValue(det);
550 //_____________________________________________________________________________
551 const AliTRDCalDet *AliTRDcalibDB::GetExBDet()
554 // Returns the exB calibration object
555 // containing one number per detector
558 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> (GetCachedCDBObject(kIDExBChamber));
560 Double_t meanexb = 100.0;
561 if (calChamber) meanexb = calChamber->GetMean();
562 //printf("mean %f\n",meanexb);
564 if ((!calChamber) || (meanexb > 70.0)) {
566 const AliTRDCalDet *calChambervdrift = dynamic_cast<const AliTRDCalDet *>
567 (GetCachedCDBObject(kIDVdriftChamber));
568 if (!calChambervdrift) {
572 AliTRDCalDet *calDetExB = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
573 for(Int_t k = 0; k < 540; k++){
574 calDetExB->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(calChambervdrift->GetValue(k)));
579 else return calChamber;
582 //_____________________________________________________________________________
583 Float_t AliTRDcalibDB::GetT0(Int_t det, Int_t col, Int_t row)
586 // Returns t0 for the given pad.
589 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
590 (GetCachedCDBObject(kIDT0Pad));
595 AliTRDCalROC *roc = calPad->GetCalROC(det);
600 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
601 (GetCachedCDBObject(kIDT0Chamber));
606 return calChamber->GetValue(det) + roc->GetValue(col,row);
610 //_____________________________________________________________________________
611 AliTRDCalROC *AliTRDcalibDB::GetT0ROC(Int_t det)
614 // Returns the t0 calibration object for a given ROC
615 // containing one number per pad
618 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
619 (GetCachedCDBObject(kIDT0Pad));
624 AliTRDCalROC *roc = calPad->GetCalROC(det);
634 //_____________________________________________________________________________
635 const AliTRDCalDet *AliTRDcalibDB::GetT0Det()
638 // Returns the t0 calibration object
639 // containing one number per detector
642 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
643 (GetCachedCDBObject(kIDT0Chamber));
653 //_____________________________________________________________________________
654 Float_t AliTRDcalibDB::GetT0Average(Int_t det)
657 // Returns the average t0 for the given detector
660 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
661 (GetCachedCDBObject(kIDT0Pad));
666 AliTRDCalROC *roc = calPad->GetCalROC(det);
671 const AliTRDCalDet *calDet = dynamic_cast<const AliTRDCalDet *>
672 (GetCachedCDBObject(kIDT0Chamber));
678 for (Int_t channel = 0; channel < roc->GetNchannels(); ++channel) {
679 sum += roc->GetValue(channel);
681 sum /= roc->GetNchannels();
682 sum += calDet->GetValue(det);
687 //_____________________________________________________________________________
688 Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
691 // Returns the gain factor for the given pad.
694 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
695 (GetCachedCDBObject(kIDGainFactorPad));
700 AliTRDCalROC *roc = calPad->GetCalROC(det);
705 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
706 (GetCachedCDBObject(kIDGainFactorChamber));
711 return calChamber->GetValue(det) * roc->GetValue(col,row);
715 //_____________________________________________________________________________
716 AliTRDCalOnlineGainTableROC* AliTRDcalibDB::GetOnlineGainTableROC(Int_t det)
719 // Returns the online gain factor table for a given ROC.
722 const AliTRDCalOnlineGainTable *calOnline
723 = dynamic_cast<const AliTRDCalOnlineGainTable *>
724 (GetCachedCDBObject(kIDOnlineGainFactor));
729 return calOnline->GetGainTableROC(det);
733 //_____________________________________________________________________________
734 Float_t AliTRDcalibDB::GetOnlineGainFactor(Int_t det, Int_t col, Int_t row)
737 // Returns the online gain factor for the given pad.
740 const AliTRDCalOnlineGainTable *calOnline
741 = dynamic_cast<const AliTRDCalOnlineGainTable *>
742 (GetCachedCDBObject(kIDOnlineGainFactor));
747 return calOnline->GetGainCorrectionFactor(det,row,col);
751 //_____________________________________________________________________________
752 AliTRDCalROC *AliTRDcalibDB::GetGainFactorROC(Int_t det)
755 // Returns the gain factor calibration object for a given ROC
758 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
759 (GetCachedCDBObject(kIDGainFactorPad));
764 AliTRDCalROC *roc = calPad->GetCalROC(det);
774 //_____________________________________________________________________________
775 const AliTRDCalDet *AliTRDcalibDB::GetGainFactorDet()
778 // Returns the gain factor calibration object
779 // containing one number per detector
782 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
783 (GetCachedCDBObject(kIDGainFactorChamber));
793 //_____________________________________________________________________________
794 Float_t AliTRDcalibDB::GetGainFactorAverage(Int_t det)
797 // Returns the average gain factor for the given detector
800 const AliTRDCalDet *calDet = dynamic_cast<const AliTRDCalDet *>
801 (GetCachedCDBObject(kIDGainFactorChamber));
806 return calDet->GetValue(det);
810 //_____________________________________________________________________________
811 AliTRDCalROC *AliTRDcalibDB::GetPRFROC(Int_t det)
814 // Returns the PRF calibration object for a given ROC
815 // containing one number per pad
818 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
819 (GetCachedCDBObject(kIDPRFWidth));
824 AliTRDCalROC *roc = calPad->GetCalROC(det);
834 //_____________________________________________________________________________
835 Float_t AliTRDcalibDB::GetPRFWidth(Int_t det, Int_t col, Int_t row)
838 // Returns the PRF width for the given pad.
841 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
842 (GetCachedCDBObject(kIDPRFWidth));
847 AliTRDCalROC *roc = calPad->GetCalROC(det);
852 return roc->GetValue(col,row);
856 //_____________________________________________________________________________
857 Int_t AliTRDcalibDB::GetNumberOfTimeBinsDCS()
860 // Returns Number of time bins from the DCS
863 Int_t nMixed = -2; // not the same number for all chambers
864 Int_t nUndef = -1; // default value - has not been set!
865 Int_t nTbSor = nUndef;
866 Int_t nTbEor = nUndef;
867 Int_t calver = 0; // Check CalDCS version
869 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
871 AliError("No DCS object found!");
875 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS")) calver = 1;
876 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
880 const AliTRDCalDCS *calDCSsor = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(0));
881 const AliTRDCalDCS *calDCSeor = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(1));
883 // the SOR file is mandatory
884 AliError("NO SOR AliTRDCalDCS object found in CDB file!");
888 // this can happen if the run is shorter than a couple of seconds.
889 AliWarning("NO EOR AliTRDCalDCS object found in CDB file.");
893 nTbSor = calDCSsor->GetGlobalNumberOfTimeBins();
894 if (calDCSeor) nTbEor = calDCSeor->GetGlobalNumberOfTimeBins();
896 } else if (calver == 2) {
898 const AliTRDCalDCSv2 *calDCSsorv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(0));
899 const AliTRDCalDCSv2 *calDCSeorv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(1));
901 // the SOR file is mandatory
902 AliError("NO SOR AliTRDCalDCSv2 object found in CDB file!");
906 // this can happen if the run is shorter than a couple of seconds.
907 AliWarning("NO EOR AliTRDCalDCSv2 object found in CDB file.");
911 nTbSor = calDCSsorv2->GetGlobalNumberOfTimeBins();
912 if (calDCSeorv2) nTbEor = calDCSeorv2->GetGlobalNumberOfTimeBins();
914 } else AliError("NO DCS/DCSv2 OCDB entry found!");
916 // if they're the same return the value
917 // -2 means mixed, -1: no data, >= 0: good number of time bins
918 if (nTbSor == nTbEor) return nTbSor;
920 // if they're differing:
921 if (nTbSor == nMixed || nTbEor == nMixed) {
922 AliWarning("Inconsistent number of time bins found!");
926 // one is undefined, the other ok -> return that one
927 if (nTbSor == nUndef) return nTbEor;
928 if (nTbEor == nUndef) return nTbSor;
930 // only remains: two different numbers >= 0
935 //_____________________________________________________________________________
936 void AliTRDcalibDB::GetFilterType(TString &filterType)
939 // Returns the filter type
942 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
948 Int_t esor = 0; // Take SOR
949 Int_t calver = 0; // Check CalDCS version
950 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS")) calver = 1;
951 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
956 const AliTRDCalDCS *calDCS = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(esor));
961 filterType = calDCS->GetGlobalFilterType();
964 else if (calver == 2) {
967 const AliTRDCalDCSv2 *calDCSv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(esor));
972 filterType = calDCSv2->GetGlobalFilterType();
977 AliError("NO DCS/DCSv2 OCDB entry found!");
983 //_____________________________________________________________________________
984 Int_t AliTRDcalibDB::GetOnlineGainTableID()
987 // Get the gain table ID from the DCS
990 if (fOnlineGainTableID > 0) {
991 return fOnlineGainTableID;
994 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
999 Int_t esor = 0; // Take SOR
1000 Int_t calver = 0; // Check CalDCS version
1001 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS")) calver = 1;
1002 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
1006 // No data for old DCS object available, anyway
1010 else if (calver == 2) {
1013 const AliTRDCalDCSv2 *calDCSv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(esor));
1018 TString tableName = "";
1019 for (Int_t i = 0; i < 540; i++) {
1020 const AliTRDCalDCSFEEv2 *calDCSFEEv2 = calDCSv2->GetCalDCSFEEObj(0);
1021 tableName = calDCSFEEv2->GetGainTableName();
1022 if (tableName.Length() > 0) {
1026 if (tableName.CompareTo("Krypton_2011-01") == 0) {
1027 fOnlineGainTableID = 1;
1028 return fOnlineGainTableID;
1030 if (tableName.CompareTo("Gaintbl_Uniform_FGAN0_2011-01") == 0) {
1031 fOnlineGainTableID = 2;
1032 return fOnlineGainTableID;
1034 if (tableName.CompareTo("Gaintbl_Uniform_FGAN8_2011-01") == 0) {
1035 fOnlineGainTableID = 3;
1036 return fOnlineGainTableID;
1042 AliError("NO DCS/DCSv2 OCDB entry found!");
1051 //_____________________________________________________________________________
1052 void AliTRDcalibDB::GetGlobalConfiguration(TString &config)
1055 // Get Configuration from the DCS
1058 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
1064 Int_t esor = 0; // Take SOR
1065 Int_t calver = 0; // Check CalDCS version
1066 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS")) calver = 1;
1067 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
1072 const AliTRDCalDCS *calDCS = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(esor));
1077 config = calDCS->GetGlobalConfigName();
1080 else if (calver == 2) {
1083 const AliTRDCalDCSv2 *calDCSv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(esor));
1088 config = calDCSv2->GetGlobalConfigName();
1093 AliError("NO DCS/DCSv2 OCDB entry found!");
1099 //_____________________________________________________________________________
1100 void AliTRDcalibDB::GetGlobalConfigurationVersion(TString &version)
1103 // Get Version of Configuration from the DCS
1106 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
1112 Int_t esor = 0; // Take SOR
1113 Int_t calver = 0; // Check CalDCS version
1114 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS")) calver = 1;
1115 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
1120 const AliTRDCalDCS *calDCS = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(esor));
1125 version = calDCS->GetGlobalConfigVersion();
1128 else if (calver == 2) {
1131 const AliTRDCalDCSv2 *calDCSv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(esor));
1136 version = calDCSv2->GetGlobalConfigVersion();
1141 AliError("NO DCS/DCSv2 OCDB entry found!");
1147 //_____________________________________________________________________________
1148 Bool_t AliTRDcalibDB::HasOnlineFilterPedestal()
1151 // Checks whether pedestal filter was applied online
1156 // Temporary: Get the filter config from the configuration name
1157 GetGlobalConfiguration(cname);
1158 TString filterconfig = cname(cname.First("_") + 1, cname.First("-") - cname.First("_") - 1);
1160 // TString filterconfig;
1161 //GetFilterType(filterconfig);
1163 return filterconfig.Contains("p");
1167 //_____________________________________________________________________________
1168 Bool_t AliTRDcalibDB::HasOnlineFilterGain()
1171 // Checks whether online gain filter was applied
1176 // Temporary: Get the filter config from the configuration name
1177 GetGlobalConfiguration(cname);
1178 TString filterconfig = cname(cname.First("_") + 1, cname.First("-") - cname.First("_") - 1);
1180 //TString filterconfig;
1181 //GetFilterType(filterconfig);
1183 return filterconfig.Contains("g");
1187 //_____________________________________________________________________________
1188 Bool_t AliTRDcalibDB::HasOnlineTailCancellation()
1191 // Checks whether online tail cancellation was applied
1196 // Temporary: Get the filter config from the configuration name
1197 GetGlobalConfiguration(cname);
1198 TString filterconfig = cname(cname.First("_") + 1, cname.First("-") - cname.First("_") - 1);
1200 //TString filterconfig;
1201 //GetFilterType(filterconfig);
1203 return filterconfig.Contains("t");
1207 //_____________________________________________________________________________
1208 Char_t AliTRDcalibDB::GetPadStatus(Int_t det, Int_t col, Int_t row)
1211 // Returns the status of the given pad
1214 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1215 (GetCachedCDBObject(kIDPadStatus));
1220 const AliTRDCalSingleChamberStatus *roc = cal->GetCalROC(det);
1225 return roc->GetStatus(col,row);
1229 //_____________________________________________________________________________
1230 AliTRDCalSingleChamberStatus* AliTRDcalibDB::GetPadStatusROC(Int_t det)
1233 // Returns the pad status calibration object for a given ROC
1236 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1237 (GetCachedCDBObject(kIDPadStatus));
1242 AliTRDCalSingleChamberStatus *roc = cal->GetCalROC(det);
1252 //_____________________________________________________________________________
1253 Char_t AliTRDcalibDB::GetChamberStatus(Int_t det)
1256 // Returns the status of the given chamber
1259 const AliTRDCalChamberStatus *cal = dynamic_cast<const AliTRDCalChamberStatus *>
1260 (GetCachedCDBObject(kIDChamberStatus));
1265 return cal->GetStatus(det);
1269 //_____________________________________________________________________________
1270 AliTRDrecoParam* AliTRDcalibDB::GetRecoParam(Int_t */*eventtype*/)
1273 // Returns the TRD reconstruction parameters from the OCDB
1276 const TClonesArray *recos = dynamic_cast<const TClonesArray*>(GetCachedCDBObject(kIDRecoParam));
1277 if (!recos) return 0x0;
1279 // calculate entry based on event type info
1280 Int_t n = 0; //f(eventtype[0], eventtype[1], ....)
1282 return (AliTRDrecoParam *) recos->UncheckedAt(n);
1286 //_____________________________________________________________________________
1287 Bool_t AliTRDcalibDB::IsPadMasked(Int_t det, Int_t col, Int_t row)
1290 // Returns status, see name of functions for details ;-)
1293 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1294 (GetCachedCDBObject(kIDPadStatus));
1299 return cal->IsMasked(det,col,row);
1303 //_____________________________________________________________________________
1304 Bool_t AliTRDcalibDB::IsPadBridgedLeft(Int_t det, Int_t col, Int_t row)
1307 // Returns status, see name of functions for details ;-)
1310 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1311 (GetCachedCDBObject(kIDPadStatus));
1316 return cal->IsBridgedLeft(det,col,row);
1320 //_____________________________________________________________________________
1321 Bool_t AliTRDcalibDB::IsPadBridgedRight(Int_t det, Int_t col, Int_t row)
1324 // Returns status, see name of functions for details ;-)
1327 const AliTRDCalPadStatus * cal = dynamic_cast<const AliTRDCalPadStatus *>
1328 (GetCachedCDBObject(kIDPadStatus));
1333 return cal->IsBridgedRight(det,col,row);
1337 //_____________________________________________________________________________
1338 Bool_t AliTRDcalibDB::IsPadNotConnected(Int_t det, Int_t col, Int_t row)
1341 // Returns status, see name of functions for details ;-)
1344 const AliTRDCalPadStatus * cal = dynamic_cast<const AliTRDCalPadStatus *>
1345 (GetCachedCDBObject(kIDPadStatus));
1350 return cal->IsNotConnected(det,col,row);
1354 //_____________________________________________________________________________
1355 Bool_t AliTRDcalibDB::IsChamberGood(Int_t det)
1358 // Returns status, see name of functions for details ;-)
1361 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1362 (GetCachedCDBObject(kIDChamberStatus));
1367 return cal->IsGood(det);
1371 //_____________________________________________________________________________
1372 Bool_t AliTRDcalibDB::IsChamberNoData(Int_t det)
1375 // Returns status, see name of functions for details ;-)
1378 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1379 (GetCachedCDBObject(kIDChamberStatus));
1384 return cal->IsNoData(det);
1388 //_____________________________________________________________________________
1389 Bool_t AliTRDcalibDB::IsHalfChamberNoData(Int_t det, Int_t side)
1392 // Returns status, see name of functions for details ;-)
1395 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1396 (GetCachedCDBObject(kIDChamberStatus));
1401 return side > 0 ? cal->IsNoDataSideB(det) : cal->IsNoDataSideA(det);
1405 //_____________________________________________________________________________
1406 Bool_t AliTRDcalibDB::IsChamberBadCalibrated(Int_t det)
1409 // Returns status, see name of functions for details ;-)
1412 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1413 (GetCachedCDBObject(kIDChamberStatus));
1418 return cal->IsBadCalibrated(det);
1422 //_____________________________________________________________________________
1423 const AliTRDCalPID *AliTRDcalibDB::GetPIDObject(AliTRDpidUtil::ETRDPIDMethod method)
1426 // Returns the object storing the distributions for PID with likelihood
1430 case AliTRDpidUtil::kLQ:
1431 return dynamic_cast<const AliTRDCalPID *>(GetCachedCDBObject(kIDPIDLQ));
1432 case AliTRDpidUtil::kNN:
1433 return dynamic_cast<const AliTRDCalPID *>(GetCachedCDBObject(kIDPIDNN));
1434 case AliTRDpidUtil::kESD:
1435 return 0x0; // To avoid compiler warnings
1442 //_____________________________________________________________________________
1443 AliTRDPIDResponse *AliTRDcalibDB::GetPIDResponse(AliTRDPIDResponse::ETRDPIDMethod method)
1446 // Returns the PID response object for 1D-LQ
1449 if (!fPIDResponse) {
1451 fPIDResponse = new AliTRDPIDResponse;
1453 // Load Reference Histos from OCDB
1454 fPIDResponse->SetPIDmethod(method);
1455 const TObjArray *references = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDPIDLQ1D));
1457 TIter refs(references);
1458 TObject *obj = NULL;
1459 AliTRDPIDReference *ref = NULL;
1460 Bool_t hasReference = kFALSE;
1461 while ((obj = refs())){
1462 if ((ref = dynamic_cast<AliTRDPIDReference *>(obj))){
1463 fPIDResponse->Load(ref);
1464 hasReference = kTRUE;
1469 if (!hasReference) {
1470 AliError("Reference histograms not found in the OCDB");
1475 return fPIDResponse;
1479 //_____________________________________________________________________________
1480 const AliTRDCalTrkAttach* AliTRDcalibDB::GetAttachObject()
1483 // Returns the object storing likelihood distributions for cluster to track attachment
1486 return dynamic_cast<const AliTRDCalTrkAttach*>(GetCachedCDBObject(kIDAttach));
1490 //_____________________________________________________________________________
1491 const AliTRDCalMonitoring *AliTRDcalibDB::GetMonitoringObject()
1494 // Returns the object storing the monitoring data
1497 return dynamic_cast<const AliTRDCalMonitoring *>
1498 (GetCachedCDBObject(kIDMonitoringData));
1502 //_____________________________________________________________________________
1503 void AliTRDcalibDB::SamplePRF()
1506 // Samples the pad response function (should maybe go somewhere else ...)
1509 const Int_t kPRFbin = 61;
1511 Float_t prf[kNlayer][kPRFbin] = {
1512 {2.9037e-02, 3.3608e-02, 3.9020e-02, 4.5292e-02,
1513 5.2694e-02, 6.1362e-02, 7.1461e-02, 8.3362e-02,
1514 9.7063e-02, 1.1307e-01, 1.3140e-01, 1.5235e-01,
1515 1.7623e-01, 2.0290e-01, 2.3294e-01, 2.6586e-01,
1516 3.0177e-01, 3.4028e-01, 3.8077e-01, 4.2267e-01,
1517 4.6493e-01, 5.0657e-01, 5.4655e-01, 5.8397e-01,
1518 6.1767e-01, 6.4744e-01, 6.7212e-01, 6.9188e-01,
1519 7.0627e-01, 7.1499e-01, 7.1851e-01, 7.1499e-01,
1520 7.0627e-01, 6.9188e-01, 6.7212e-01, 6.4744e-01,
1521 6.1767e-01, 5.8397e-01, 5.4655e-01, 5.0657e-01,
1522 4.6493e-01, 4.2267e-01, 3.8077e-01, 3.4028e-01,
1523 3.0177e-01, 2.6586e-01, 2.3294e-01, 2.0290e-01,
1524 1.7623e-01, 1.5235e-01, 1.3140e-01, 1.1307e-01,
1525 9.7063e-02, 8.3362e-02, 7.1461e-02, 6.1362e-02,
1526 5.2694e-02, 4.5292e-02, 3.9020e-02, 3.3608e-02,
1528 {2.5478e-02, 2.9695e-02, 3.4655e-02, 4.0454e-02,
1529 4.7342e-02, 5.5487e-02, 6.5038e-02, 7.6378e-02,
1530 8.9696e-02, 1.0516e-01, 1.2327e-01, 1.4415e-01,
1531 1.6794e-01, 1.9516e-01, 2.2573e-01, 2.5959e-01,
1532 2.9694e-01, 3.3719e-01, 3.7978e-01, 4.2407e-01,
1533 4.6889e-01, 5.1322e-01, 5.5569e-01, 5.9535e-01,
1534 6.3141e-01, 6.6259e-01, 6.8882e-01, 7.0983e-01,
1535 7.2471e-01, 7.3398e-01, 7.3761e-01, 7.3398e-01,
1536 7.2471e-01, 7.0983e-01, 6.8882e-01, 6.6259e-01,
1537 6.3141e-01, 5.9535e-01, 5.5569e-01, 5.1322e-01,
1538 4.6889e-01, 4.2407e-01, 3.7978e-01, 3.3719e-01,
1539 2.9694e-01, 2.5959e-01, 2.2573e-01, 1.9516e-01,
1540 1.6794e-01, 1.4415e-01, 1.2327e-01, 1.0516e-01,
1541 8.9696e-02, 7.6378e-02, 6.5038e-02, 5.5487e-02,
1542 4.7342e-02, 4.0454e-02, 3.4655e-02, 2.9695e-02,
1544 {2.2363e-02, 2.6233e-02, 3.0782e-02, 3.6140e-02,
1545 4.2535e-02, 5.0157e-02, 5.9197e-02, 6.9900e-02,
1546 8.2707e-02, 9.7811e-02, 1.1548e-01, 1.3601e-01,
1547 1.5998e-01, 1.8739e-01, 2.1840e-01, 2.5318e-01,
1548 2.9182e-01, 3.3373e-01, 3.7837e-01, 4.2498e-01,
1549 4.7235e-01, 5.1918e-01, 5.6426e-01, 6.0621e-01,
1550 6.4399e-01, 6.7700e-01, 7.0472e-01, 7.2637e-01,
1551 7.4206e-01, 7.5179e-01, 7.5551e-01, 7.5179e-01,
1552 7.4206e-01, 7.2637e-01, 7.0472e-01, 6.7700e-01,
1553 6.4399e-01, 6.0621e-01, 5.6426e-01, 5.1918e-01,
1554 4.7235e-01, 4.2498e-01, 3.7837e-01, 3.3373e-01,
1555 2.9182e-01, 2.5318e-01, 2.1840e-01, 1.8739e-01,
1556 1.5998e-01, 1.3601e-01, 1.1548e-01, 9.7811e-02,
1557 8.2707e-02, 6.9900e-02, 5.9197e-02, 5.0157e-02,
1558 4.2535e-02, 3.6140e-02, 3.0782e-02, 2.6233e-02,
1560 {1.9635e-02, 2.3167e-02, 2.7343e-02, 3.2293e-02,
1561 3.8224e-02, 4.5335e-02, 5.3849e-02, 6.4039e-02,
1562 7.6210e-02, 9.0739e-02, 1.0805e-01, 1.2841e-01,
1563 1.5216e-01, 1.7960e-01, 2.1099e-01, 2.4671e-01,
1564 2.8647e-01, 3.2996e-01, 3.7660e-01, 4.2547e-01,
1565 4.7536e-01, 5.2473e-01, 5.7215e-01, 6.1632e-01,
1566 6.5616e-01, 6.9075e-01, 7.1939e-01, 7.4199e-01,
1567 7.5838e-01, 7.6848e-01, 7.7227e-01, 7.6848e-01,
1568 7.5838e-01, 7.4199e-01, 7.1939e-01, 6.9075e-01,
1569 6.5616e-01, 6.1632e-01, 5.7215e-01, 5.2473e-01,
1570 4.7536e-01, 4.2547e-01, 3.7660e-01, 3.2996e-01,
1571 2.8647e-01, 2.4671e-01, 2.1099e-01, 1.7960e-01,
1572 1.5216e-01, 1.2841e-01, 1.0805e-01, 9.0739e-02,
1573 7.6210e-02, 6.4039e-02, 5.3849e-02, 4.5335e-02,
1574 3.8224e-02, 3.2293e-02, 2.7343e-02, 2.3167e-02,
1576 {1.7224e-02, 2.0450e-02, 2.4286e-02, 2.8860e-02,
1577 3.4357e-02, 4.0979e-02, 4.8966e-02, 5.8612e-02,
1578 7.0253e-02, 8.4257e-02, 1.0102e-01, 1.2094e-01,
1579 1.4442e-01, 1.7196e-01, 2.0381e-01, 2.4013e-01,
1580 2.8093e-01, 3.2594e-01, 3.7450e-01, 4.2563e-01,
1581 4.7796e-01, 5.2991e-01, 5.7974e-01, 6.2599e-01,
1582 6.6750e-01, 7.0344e-01, 7.3329e-01, 7.5676e-01,
1583 7.7371e-01, 7.8410e-01, 7.8793e-01, 7.8410e-01,
1584 7.7371e-01, 7.5676e-01, 7.3329e-01, 7.0344e-01,
1585 6.6750e-01, 6.2599e-01, 5.7974e-01, 5.2991e-01,
1586 4.7796e-01, 4.2563e-01, 3.7450e-01, 3.2594e-01,
1587 2.8093e-01, 2.4013e-01, 2.0381e-01, 1.7196e-01,
1588 1.4442e-01, 1.2094e-01, 1.0102e-01, 8.4257e-02,
1589 7.0253e-02, 5.8612e-02, 4.8966e-02, 4.0979e-02,
1590 3.4357e-02, 2.8860e-02, 2.4286e-02, 2.0450e-02,
1592 {1.5096e-02, 1.8041e-02, 2.1566e-02, 2.5793e-02,
1593 3.0886e-02, 3.7044e-02, 4.4515e-02, 5.3604e-02,
1594 6.4668e-02, 7.8109e-02, 9.4364e-02, 1.1389e-01,
1595 1.3716e-01, 1.6461e-01, 1.9663e-01, 2.3350e-01,
1596 2.7527e-01, 3.2170e-01, 3.7214e-01, 4.2549e-01,
1597 4.8024e-01, 5.3460e-01, 5.8677e-01, 6.3512e-01,
1598 6.7838e-01, 7.1569e-01, 7.4655e-01, 7.7071e-01,
1599 7.8810e-01, 7.9871e-01, 8.0255e-01, 7.9871e-01,
1600 7.8810e-01, 7.7071e-01, 7.4655e-01, 7.1569e-01,
1601 6.7838e-01, 6.3512e-01, 5.8677e-01, 5.3460e-01,
1602 4.8024e-01, 4.2549e-01, 3.7214e-01, 3.2170e-01,
1603 2.7527e-01, 2.3350e-01, 1.9663e-01, 1.6461e-01,
1604 1.3716e-01, 1.1389e-01, 9.4364e-02, 7.8109e-02,
1605 6.4668e-02, 5.3604e-02, 4.4515e-02, 3.7044e-02,
1606 3.0886e-02, 2.5793e-02, 2.1566e-02, 1.8041e-02,
1609 // More sampling precision with linear interpolation
1612 Float_t pad[kPRFbin];
1613 Int_t sPRFbin = kPRFbin;
1614 Float_t sPRFwid = (fPRFhi - fPRFlo) / ((Float_t) sPRFbin);
1615 for (Int_t iPad = 0; iPad < sPRFbin; iPad++) {
1616 pad[iPad] = ((Float_t) iPad + 0.5) * sPRFwid + fPRFlo;
1619 fPRFwid = (fPRFhi - fPRFlo) / ((Float_t) fPRFbin);
1620 fPRFpad = ((Int_t) (1.0 / fPRFwid));
1622 if (fPRFsmp) delete [] fPRFsmp;
1623 fPRFsmp = new Float_t[kNlayer*fPRFbin];
1629 for (Int_t iLayer = 0; iLayer < kNlayer; iLayer++) {
1631 for (Int_t iBin = 0; iBin < fPRFbin; iBin++) {
1633 Float_t bin = (((Float_t) iBin) + 0.5) * fPRFwid + fPRFlo;
1637 diff = bin - pad[ipos2++];
1638 } while ((diff > 0) && (ipos2 < kPRFbin));
1639 if (ipos2 == kPRFbin) {
1640 fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2-1];
1642 else if (ipos2 == 1) {
1643 fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2-1];
1647 if (ipos2 >= kPRFbin) ipos2 = kPRFbin - 1;
1649 fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2]
1650 + diff * (prf[iLayer][ipos2] - prf[iLayer][ipos1])
1659 //_____________________________________________________________________________
1660 Int_t AliTRDcalibDB::PadResponse(Double_t signal, Double_t dist
1661 , Int_t layer, Double_t *pad) const
1664 // Applies the pad response
1665 // So far this is the fixed parametrization and should be replaced by
1666 // something dependent on calibration values
1669 Int_t iBin = ((Int_t) ((-dist - fPRFlo) / fPRFwid));
1670 Int_t iOff = layer * fPRFbin;
1672 Int_t iBin0 = iBin - fPRFpad + iOff;
1673 Int_t iBin1 = iBin + iOff;
1674 Int_t iBin2 = iBin + fPRFpad + iOff;
1679 if ((iBin1 >= 0) && (iBin1 < (fPRFbin*kNlayer))) {
1682 pad[0] = signal * fPRFsmp[iBin0];
1684 pad[1] = signal * fPRFsmp[iBin1];
1685 if (iBin2 < (fPRFbin*kNlayer)) {
1686 pad[2] = signal * fPRFsmp[iBin2];