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