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