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