Removing useless flag.
[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
f2391aef 31#include <TROOT.h>
a7ac01d2 32#include <TClonesArray.h>
e232d349 33#include <TObjArray.h>
3551db50 34
2745a409 35#include "AliCDBManager.h"
2745a409 36#include "AliCDBEntry.h"
37#include "AliLog.h"
3551db50 38
51a0ce25 39#include "AliTRDPIDReference.h"
121fadea 40#include "AliTRDPIDResponseObject.h"
3551db50 41#include "AliTRDcalibDB.h"
a9e22145 42#include "AliTRDtrapConfig.h"
43#include "AliTRDtrapConfigHandler.h"
eda91732 44#include "AliTRDCommonParam.h"
56a188ab 45#include "AliTRDgeometry.h"
3551db50 46
7754cd1f 47#include "Cal/AliTRDCalROC.h"
7754cd1f 48#include "Cal/AliTRDCalPad.h"
49#include "Cal/AliTRDCalDet.h"
e232d349 50#include "Cal/AliTRDCalDCS.h"
01bf853b 51#include "Cal/AliTRDCalDCSFEE.h"
d6a1ec13 52#include "Cal/AliTRDCalDCSv2.h"
ea3eaa08 53#include "Cal/AliTRDCalDCSFEEv2.h"
720a0a16 54#include "Cal/AliTRDCalPID.h"
7754cd1f 55#include "Cal/AliTRDCalMonitoring.h"
7754cd1f 56#include "Cal/AliTRDCalChamberStatus.h"
7754cd1f 57#include "Cal/AliTRDCalPadStatus.h"
58#include "Cal/AliTRDCalSingleChamberStatus.h"
9dcc64cc 59#include "Cal/AliTRDCalTrkAttach.h"
ea3eaa08 60#include "Cal/AliTRDCalOnlineGainTable.h"
3551db50 61
62ClassImp(AliTRDcalibDB)
63
2745a409 64AliTRDcalibDB *AliTRDcalibDB::fgInstance = 0;
65Bool_t AliTRDcalibDB::fgTerminated = kFALSE;
3551db50 66
67//_ singleton implementation __________________________________________________
68AliTRDcalibDB* AliTRDcalibDB::Instance()
69{
70 //
71 // Singleton implementation
72 // Returns an instance of this class, it is created if neccessary
63a700c6 73 //
3551db50 74
6d50f529 75 if (fgTerminated != kFALSE) {
3551db50 76 return 0;
6d50f529 77 }
3551db50 78
6d50f529 79 if (fgInstance == 0) {
3551db50 80 fgInstance = new AliTRDcalibDB();
6d50f529 81 }
e254cad1 82
3551db50 83 return fgInstance;
4e009ce4 84
3551db50 85}
86
2745a409 87//_____________________________________________________________________________
3551db50 88void AliTRDcalibDB::Terminate()
89{
90 //
91 // Singleton implementation
6bf5f0ce 92 // Deletes the instance of this class and sets the terminated flag,
93 // instances cannot be requested anymore
3551db50 94 // This function can be called several times.
95 //
96
97 fgTerminated = kTRUE;
98
6d50f529 99 if (fgInstance != 0) {
3551db50 100 delete fgInstance;
101 fgInstance = 0;
102 }
2745a409 103
3551db50 104}
105
106//_____________________________________________________________________________
107AliTRDcalibDB::AliTRDcalibDB()
2745a409 108 :TObject()
109 ,fRun(-1)
6d50f529 110 ,fPRFsmp(0)
111 ,fPRFbin(0)
112 ,fPRFlo(0)
113 ,fPRFhi(0)
114 ,fPRFwid(0)
115 ,fPRFpad(0)
9dcc64cc 116 ,fPIDResponse(NULL)
ea3eaa08 117 ,fOnlineGainTableID(0)
a9e22145 118 ,fTrapConfig(0x0)
f16844ef 119 ,fTrapConfigName("")
120 ,fTrapConfigVersion("")
3551db50 121{
122 //
2745a409 123 // Default constructor
3551db50 124 //
2745a409 125 // TODO Default runnumber is set to 0, this should be changed later
126 // to an invalid value (e.g. -1) to prevent
3551db50 127 // TODO invalid calibration data to be used.
2745a409 128 //
129
95867fd1 130 for (Int_t i = 0; i < kCDBCacheSize; ++i) {
2745a409 131 fCDBCache[i] = 0;
132 fCDBEntries[i] = 0;
133 }
3551db50 134
2745a409 135 // Create the sampled PRF
136 SamplePRF();
d4c6453d 137
2745a409 138}
139
140//_____________________________________________________________________________
141AliTRDcalibDB::AliTRDcalibDB(const AliTRDcalibDB &c)
142 :TObject(c)
6d50f529 143 ,fRun(-1)
144 ,fPRFsmp(0)
145 ,fPRFbin(0)
146 ,fPRFlo(0)
147 ,fPRFhi(0)
148 ,fPRFwid(0)
149 ,fPRFpad(0)
9dcc64cc 150 ,fPIDResponse(NULL)
ea3eaa08 151 ,fOnlineGainTableID(0)
a9e22145 152 ,fTrapConfig(0x0)
f16844ef 153 ,fTrapConfigName("")
154 ,fTrapConfigVersion("")
2745a409 155{
156 //
157 // Copy constructor (not that it make any sense for a singleton...)
158 //
159
95867fd1 160 for (Int_t i = 0; i < kCDBCacheSize; ++i) {
2745a409 161 fCDBCache[i] = 0;
3551db50 162 fCDBEntries[i] = 0;
163 }
6a739e92 164
165 // Create the sampled PRF
166 SamplePRF();
2745a409 167
168}
169
170//_____________________________________________________________________________
171AliTRDcalibDB &AliTRDcalibDB::operator=(const AliTRDcalibDB &c)
172{
173 //
174 // Assignment operator (same as above ...)
175 //
176
177 if (this != &c) {
178 AliFatal("No assignment operator defined");
179 }
4e009ce4 180
2745a409 181 return *this;
182
acba9bad 183}
3551db50 184
185//_____________________________________________________________________________
186AliTRDcalibDB::~AliTRDcalibDB()
187{
188 //
189 // destructor
190 //
191
6d50f529 192 if (fPRFsmp) {
193 delete [] fPRFsmp;
194 fPRFsmp = 0;
6a739e92 195 }
ea3eaa08 196
197 if (fPIDResponse) {
198 delete fPIDResponse;
199 fPIDResponse = 0x0;
200 }
6a739e92 201
3551db50 202 Invalidate();
2745a409 203
acba9bad 204}
3551db50 205
63a700c6 206//_caching functions____________________________________________________________
95867fd1 207const TObject *AliTRDcalibDB::GetCachedCDBObject(Int_t id)
63a700c6 208{
2745a409 209 //
210 // Retrieves a cdb object with the given id. The objects are cached as
211 // long as the run number is not changed.
212 //
213 // Put together the available objects here by using the lines
214 // a) For usual calibration objects:
215 // case kID<Name> :
216 // return CacheCDBEntry(kID<Name>,"TRD/Calib/<Path>");
217 // break;
218 // See function CacheCDBEntry for details.
219 // and
220 // b) For calibration data which depends on two objects: One containing
221 // a value per detector and one the local fluctuations per pad:
222 // case kID<Name> :
223 // return CacheMergeCDBEntry(kID<Name>,"TRD/Calib/<padPath>","TRD/Calib/<chamberPath>");
224 // break;
225 // See function CacheMergeCDBEntry for details.
226 //
63a700c6 227
6d50f529 228 switch (id) {
2745a409 229
230 // Parameters defined per pad and chamber
231 case kIDVdriftPad :
6d50f529 232 return CacheCDBEntry(kIDVdriftPad ,"TRD/Calib/LocalVdrift");
2745a409 233 break;
234 case kIDVdriftChamber :
6d50f529 235 return CacheCDBEntry(kIDVdriftChamber ,"TRD/Calib/ChamberVdrift");
2745a409 236 break;
eda91732 237 case kIDExBChamber :
238 return CacheCDBEntry(kIDExBChamber ,"TRD/Calib/ChamberExB");
239 break;
2745a409 240 case kIDT0Pad :
6d50f529 241 return CacheCDBEntry(kIDT0Pad ,"TRD/Calib/LocalT0");
2745a409 242 break;
243 case kIDT0Chamber :
6d50f529 244 return CacheCDBEntry(kIDT0Chamber ,"TRD/Calib/ChamberT0");
2745a409 245 break;
246 case kIDGainFactorPad :
6d50f529 247 return CacheCDBEntry(kIDGainFactorPad ,"TRD/Calib/LocalGainFactor");
2745a409 248 break;
249 case kIDGainFactorChamber :
6d50f529 250 return CacheCDBEntry(kIDGainFactorChamber ,"TRD/Calib/ChamberGainFactor");
2745a409 251 break;
ea3eaa08 252
253 case kIDOnlineGainFactor :
254 switch(GetOnlineGainTableID()) {
255 case 0:
256 // For testing purposes only !!!
257 AliInfo("No gain table name from OCDB. Use default table!");
258 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Krypton_2011-01");
259 break;
260 case 1:
261 // Online gain table ID 1
262 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Krypton_2011-01");
263 break;
412d07b9 264 case 2:
265 // Online gain table ID 2
266 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Gaintbl_Uniform_FGAN0_2011-01");
267 break;
268 case 3:
269 // Online gain table ID 3
270 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Gaintbl_Uniform_FGAN8_2011-01");
271 break;
3abf1c06 272 case 4:
273 // Online gain table ID 4
274 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Krypton_2011-02");
275 break;
4a05be5f 276 case 5:
277 // Online gain table ID 5
278 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Krypton_2011-03");
279 break;
280 case 6:
281 // Online gain table ID 6
282 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Gaintbl_Uniform_FGAN0_2012-01");
283 break;
284 case 7:
285 // Online gain table ID 7
d9e5ae00 286 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Gaintbl_Uniform_FGAN8_2012-01");
287 break;
288 case 8:
289 // Online gain table ID 8
290 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Krypton_2012-01");
4a05be5f 291 break;
56a188ab 292 default:
293 AliError(Form("unknown gaintable requested with ID"));
ea3eaa08 294 }
295 break;
296
df83a620 297 case kIDNoiseChamber :
ea3eaa08 298 return CacheCDBEntry(kIDNoiseChamber ,"TRD/Calib/DetNoise");
df83a620 299 break;
300 case kIDNoisePad :
ea3eaa08 301 return CacheCDBEntry(kIDNoisePad ,"TRD/Calib/PadNoise");
df83a620 302 break;
303
2745a409 304 // Parameters defined per pad
305 case kIDPRFWidth :
6d50f529 306 return CacheCDBEntry(kIDPRFWidth ,"TRD/Calib/PRFWidth");
2745a409 307 break;
308
309 // Status values
2745a409 310 case kIDChamberStatus :
6d50f529 311 return CacheCDBEntry(kIDChamberStatus ,"TRD/Calib/ChamberStatus");
2745a409 312 break;
2745a409 313 case kIDPadStatus :
6d50f529 314 return CacheCDBEntry(kIDPadStatus ,"TRD/Calib/PadStatus");
2745a409 315 break;
316
317 // Global parameters
318 case kIDMonitoringData :
6d50f529 319 return CacheCDBEntry(kIDMonitoringData ,"TRD/Calib/MonitoringData");
2745a409 320 break;
aa617684 321 case kIDFEE :
322 return CacheCDBEntry(kIDFEE ,"TRD/Calib/FEE");
2745a409 323 break;
a9e22145 324 case kIDTrapConfig :
56a188ab 325 return CacheCDBEntry(kIDTrapConfig ,"TRD/Calib/TrapConfig");
a9e22145 326 break;
e232d349 327 case kIDDCS :
5f481838 328 return CacheCDBEntry(kIDDCS ,"TRD/Calib/DCS");
e232d349 329 break;
44dbae42 330 case kIDPIDNN :
331 return CacheCDBEntry(kIDPIDNN ,"TRD/Calib/PIDNN");
ea3eaa08 332 break;
2745a409 333 case kIDPIDLQ :
6d50f529 334 return CacheCDBEntry(kIDPIDLQ ,"TRD/Calib/PIDLQ");
2745a409 335 break;
9dcc64cc 336 case kIDPIDLQ1D:
337 return CacheCDBEntry(kIDPIDLQ1D ,"TRD/Calib/PIDLQ1D");
338 break;
a7ac01d2 339 case kIDRecoParam :
9dcc64cc 340 return CacheCDBEntry(kIDRecoParam ,"TRD/Calib/RecoParam");
341 break;
342 case kIDAttach :
343 return CacheCDBEntry(kIDAttach ,"TRD/Calib/TrkAttach");
a7ac01d2 344 break;
e2a1c98b 345 case kIDPHQ :
346 return CacheCDBEntry(kIDPHQ ,"TRD/Calib/PHQ");
347 break;
2745a409 348 }
349
350 return 0;
351
63a700c6 352}
353
354//_____________________________________________________________________________
95867fd1 355AliCDBEntry *AliTRDcalibDB::GetCDBEntry(const char *cdbPath)
63a700c6 356{
357 //
358 // Retrieves an entry with path <cdbPath> from the CDB.
359 //
360
95867fd1 361 AliCDBEntry *entry = AliCDBManager::Instance()->Get(cdbPath,fRun);
2745a409 362 if (!entry) {
a7ac01d2 363 AliError(Form("Failed to get entry: %s",cdbPath));
63a700c6 364 return 0;
365 }
366
63a700c6 367 return entry;
2745a409 368
63a700c6 369}
370
371//_____________________________________________________________________________
95867fd1 372const TObject *AliTRDcalibDB::CacheCDBEntry(Int_t id, const char *cdbPath)
63a700c6 373{
374 //
375 // Caches the entry <id> with cdb path <cdbPath>
376 //
d6a1ec13 377
2745a409 378 if (!fCDBCache[id]) {
63a700c6 379 fCDBEntries[id] = GetCDBEntry(cdbPath);
95867fd1 380 if (fCDBEntries[id]) {
63a700c6 381 fCDBCache[id] = fCDBEntries[id]->GetObject();
56a188ab 382 if (id == kIDOnlineGainFactor)
383 AliInfo(Form("loaded gain table: %s", fCDBEntries[id]->GetId().GetAliCDBPath().GetPath().Data()));
95867fd1 384 }
d6a1ec13 385 }
386
63a700c6 387 return fCDBCache[id];
ea3eaa08 388
63a700c6 389}
390
391//_____________________________________________________________________________
3551db50 392void AliTRDcalibDB::SetRun(Long64_t run)
393{
394 //
7754cd1f 395 // Sets current run number. Calibration data is read from the corresponding file.
3551db50 396 // When the run number changes the caching is invalidated.
397 //
7754cd1f 398
6d50f529 399 if (fRun == run) {
3551db50 400 return;
6d50f529 401 }
7754cd1f 402
3551db50 403 fRun = run;
95867fd1 404
3551db50 405 Invalidate();
2745a409 406
3551db50 407}
7754cd1f 408
3551db50 409//_____________________________________________________________________________
410void AliTRDcalibDB::Invalidate()
411{
412 //
413 // Invalidates cache (when run number is changed).
414 //
415
95867fd1 416 for (Int_t i = 0; i < kCDBCacheSize; ++i) {
2745a409 417 if (fCDBEntries[i]) {
418 if (AliCDBManager::Instance()->GetCacheFlag() == kFALSE) {
11f5dd43 419 if ((fCDBEntries[i]->IsOwner() == kFALSE) &&
420 (fCDBCache[i])) {
e254cad1 421 delete fCDBCache[i];
2745a409 422 }
e254cad1 423 delete fCDBEntries[i];
424 }
3551db50 425 fCDBEntries[i] = 0;
2745a409 426 fCDBCache[i] = 0;
3551db50 427 }
428 }
2745a409 429
ea3eaa08 430 fOnlineGainTableID = 0;
431
3551db50 432}
ea3eaa08 433
df83a620 434//_____________________________________________________________________________
435Float_t AliTRDcalibDB::GetNoise(Int_t det, Int_t col, Int_t row)
436{
437 //
438 // Returns the noise level in ADC counts for the given pad.
439 //
440
441 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
442 (GetCachedCDBObject(kIDNoisePad));
443 if (!calPad) {
444 return -1;
445 }
446
447 AliTRDCalROC *roc = calPad->GetCalROC(det);
448 if (!roc) {
449 return -1;
450 }
451
452 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
453 (GetCachedCDBObject(kIDNoiseChamber));
454 if (!calChamber) {
455 return -1;
456 }
457
458 return calChamber->GetValue(det) * roc->GetValue(col,row);
459
460}
461
462//_____________________________________________________________________________
463AliTRDCalROC *AliTRDcalibDB::GetNoiseROC(Int_t det)
464{
465 //
466 // Returns the Vdrift calibration object for a given ROC
467 // containing one number per pad
468 //
469
470 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
471 (GetCachedCDBObject(kIDNoisePad));
472 if (!calPad) {
473 return 0;
474 }
475
476 AliTRDCalROC *roc = calPad->GetCalROC(det);
477 if (!roc) {
478 return 0;
479 }
480 else {
481 return roc;
482 }
483
484}
485
486//_____________________________________________________________________________
487const AliTRDCalDet *AliTRDcalibDB::GetNoiseDet()
488{
489 //
490 // Returns the Vdrift calibration object
491 // containing one number per detector
492 //
493
494 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
495 (GetCachedCDBObject(kIDNoiseChamber));
496 if (!calChamber) {
497 return 0;
498 }
499 else {
500 return calChamber;
501 }
502
503}
3551db50 504
505//_____________________________________________________________________________
3551db50 506Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
507{
508 //
509 // Returns the drift velocity for the given pad.
510 //
7754cd1f 511
95867fd1 512 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
6d50f529 513 (GetCachedCDBObject(kIDVdriftPad));
514 if (!calPad) {
3551db50 515 return -1;
6d50f529 516 }
3551db50 517
95867fd1 518 AliTRDCalROC *roc = calPad->GetCalROC(det);
6d50f529 519 if (!roc) {
3551db50 520 return -1;
6d50f529 521 }
3551db50 522
95867fd1 523 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
6d50f529 524 (GetCachedCDBObject(kIDVdriftChamber));
525 if (!calChamber) {
7754cd1f 526 return -1;
6d50f529 527 }
7754cd1f 528
95867fd1 529 return calChamber->GetValue(det) * roc->GetValue(col,row);
2745a409 530
7754cd1f 531}
afb9f880 532
533//_____________________________________________________________________________
534AliTRDCalROC *AliTRDcalibDB::GetVdriftROC(Int_t det)
535{
536 //
537 // Returns the Vdrift calibration object for a given ROC
538 // containing one number per pad
539 //
540
541 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
542 (GetCachedCDBObject(kIDVdriftPad));
543 if (!calPad) {
544 return 0;
545 }
546
547 AliTRDCalROC *roc = calPad->GetCalROC(det);
548 if (!roc) {
549 return 0;
550 }
551 else {
552 return roc;
553 }
554
555}
556
557//_____________________________________________________________________________
558const AliTRDCalDet *AliTRDcalibDB::GetVdriftDet()
559{
560 //
561 // Returns the Vdrift calibration object
562 // containing one number per detector
563 //
564
565 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
566 (GetCachedCDBObject(kIDVdriftChamber));
567 if (!calChamber) {
568 return 0;
569 }
570 else {
571 return calChamber;
572 }
573
574}
7754cd1f 575
576//_____________________________________________________________________________
e2a1c98b 577TObjArray * AliTRDcalibDB::GetPHQ()
578{
579 //
580 //return PHQ calibration object
581 //
582 TObjArray *arr = (TObjArray *) (GetCachedCDBObject(kIDPHQ));
583 return arr;
584}
585
586//_____________________________________________________________________________
7754cd1f 587Float_t AliTRDcalibDB::GetVdriftAverage(Int_t det)
588{
589 //
590 // Returns the average drift velocity for the given detector
591 //
592
95867fd1 593 const AliTRDCalDet *calDet = dynamic_cast<const AliTRDCalDet *>
6d50f529 594 (GetCachedCDBObject(kIDVdriftChamber));
595 if (!calDet) {
7754cd1f 596 return -1;
6d50f529 597 }
7754cd1f 598
599 return calDet->GetValue(det);
2745a409 600
acba9bad 601}
eda91732 602//_____________________________________________________________________________
603const AliTRDCalDet *AliTRDcalibDB::GetExBDet()
604{
605 //
606 // Returns the exB calibration object
607 // containing one number per detector
608 //
609
610 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> (GetCachedCDBObject(kIDExBChamber));
611
612 Double_t meanexb = 100.0;
613 if (calChamber) meanexb = calChamber->GetMean();
614 //printf("mean %f\n",meanexb);
3551db50 615
eda91732 616 if ((!calChamber) || (meanexb > 70.0)) {
617
618 const AliTRDCalDet *calChambervdrift = dynamic_cast<const AliTRDCalDet *>
619 (GetCachedCDBObject(kIDVdriftChamber));
620 if (!calChambervdrift) {
621 return 0;
622 }
623 else {
624 AliTRDCalDet *calDetExB = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
625 for(Int_t k = 0; k < 540; k++){
626 calDetExB->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(calChambervdrift->GetValue(k)));
eda91732 627 }
628 return calDetExB;
629 }
630 }
631 else return calChamber;
632
633}
3551db50 634//_____________________________________________________________________________
635Float_t AliTRDcalibDB::GetT0(Int_t det, Int_t col, Int_t row)
636{
637 //
638 // Returns t0 for the given pad.
639 //
640
d4c6453d 641 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
642 (GetCachedCDBObject(kIDT0Pad));
6d50f529 643 if (!calPad) {
3551db50 644 return -1;
6d50f529 645 }
3551db50 646
d4c6453d 647 AliTRDCalROC *roc = calPad->GetCalROC(det);
6d50f529 648 if (!roc) {
3551db50 649 return -1;
6d50f529 650 }
3551db50 651
d4c6453d 652 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
653 (GetCachedCDBObject(kIDT0Chamber));
6d50f529 654 if (!calChamber) {
7754cd1f 655 return -1;
6d50f529 656 }
7754cd1f 657
8d786fb8 658 return calChamber->GetValue(det) + roc->GetValue(col,row);
2745a409 659
7754cd1f 660}
afb9f880 661
7754cd1f 662//_____________________________________________________________________________
56178ff4 663AliTRDCalROC *AliTRDcalibDB::GetT0ROC(Int_t det)
664{
665 //
666 // Returns the t0 calibration object for a given ROC
667 // containing one number per pad
668 //
669
670 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
671 (GetCachedCDBObject(kIDT0Pad));
672 if (!calPad) {
673 return 0;
674 }
675
676 AliTRDCalROC *roc = calPad->GetCalROC(det);
677 if (!roc) {
678 return 0;
679 }
680 else {
681 return roc;
682 }
683
684}
685
686//_____________________________________________________________________________
687const AliTRDCalDet *AliTRDcalibDB::GetT0Det()
688{
689 //
690 // Returns the t0 calibration object
691 // containing one number per detector
692 //
693
694 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
695 (GetCachedCDBObject(kIDT0Chamber));
696 if (!calChamber) {
697 return 0;
698 }
699 else {
700 return calChamber;
701 }
702
703}
704
705//_____________________________________________________________________________
7754cd1f 706Float_t AliTRDcalibDB::GetT0Average(Int_t det)
707{
708 //
709 // Returns the average t0 for the given detector
710 //
711
5aba4f09 712 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
713 (GetCachedCDBObject(kIDT0Pad));
714 if (!calPad) {
715 return -1;
716 }
717
718 AliTRDCalROC *roc = calPad->GetCalROC(det);
719 if (!roc) {
720 return -1;
721 }
722
95867fd1 723 const AliTRDCalDet *calDet = dynamic_cast<const AliTRDCalDet *>
6d50f529 724 (GetCachedCDBObject(kIDT0Chamber));
725 if (!calDet) {
7754cd1f 726 return -1;
6d50f529 727 }
7754cd1f 728
4eb02ab1 729 Double_t sum = 0.0;
5aba4f09 730 for (Int_t channel = 0; channel < roc->GetNchannels(); ++channel) {
4eb02ab1 731 sum += roc->GetValue(channel);
5aba4f09 732 }
4eb02ab1 733 sum /= roc->GetNchannels();
734 sum += calDet->GetValue(det);
735 return sum;
2745a409 736
acba9bad 737}
3551db50 738
739//_____________________________________________________________________________
ea3eaa08 740AliTRDCalOnlineGainTableROC* AliTRDcalibDB::GetOnlineGainTableROC(Int_t det)
741{
742 //
743 // Returns the online gain factor table for a given ROC.
744 //
c36ddf52 745
746 if (!HasOnlineFilterGain()) {
747 return 0x0;
748 }
ea3eaa08 749
750 const AliTRDCalOnlineGainTable *calOnline
751 = dynamic_cast<const AliTRDCalOnlineGainTable *>
752 (GetCachedCDBObject(kIDOnlineGainFactor));
753 if (!calOnline) {
754 return 0x0;
755 }
756
757 return calOnline->GetGainTableROC(det);
758
759}
760
761//_____________________________________________________________________________
762Float_t AliTRDcalibDB::GetOnlineGainFactor(Int_t det, Int_t col, Int_t row)
763{
764 //
765 // Returns the online gain factor for the given pad.
766 //
c36ddf52 767
768 if (!HasOnlineFilterGain()) {
6c3e7ad0 769 return -1;
c36ddf52 770 }
ea3eaa08 771
772 const AliTRDCalOnlineGainTable *calOnline
773 = dynamic_cast<const AliTRDCalOnlineGainTable *>
774 (GetCachedCDBObject(kIDOnlineGainFactor));
775 if (!calOnline) {
776 return -1;
777 }
778
779 return calOnline->GetGainCorrectionFactor(det,row,col);
780
781}
782
783//_____________________________________________________________________________
56178ff4 784AliTRDCalROC *AliTRDcalibDB::GetGainFactorROC(Int_t det)
785{
786 //
787 // Returns the gain factor calibration object for a given ROC
56178ff4 788 //
789
790 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
791 (GetCachedCDBObject(kIDGainFactorPad));
792 if (!calPad) {
793 return 0;
794 }
795
796 AliTRDCalROC *roc = calPad->GetCalROC(det);
797 if (!roc) {
798 return 0;
799 }
800 else {
801 return roc;
802 }
803
804}
805
806//_____________________________________________________________________________
c36ddf52 807Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
808{
809 //
810 // Returns the gain factor for the given pad.
811 //
812
813 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
814 (GetCachedCDBObject(kIDGainFactorPad));
815 if (!calPad) {
816 return -1;
817 }
818
819 AliTRDCalROC *roc = calPad->GetCalROC(det);
820 if (!roc) {
821 return -1;
822 }
823
824 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
825 (GetCachedCDBObject(kIDGainFactorChamber));
826 if (!calChamber) {
827 return -1;
828 }
829
830 return calChamber->GetValue(det) * roc->GetValue(col,row);
831
832}
833
834//_____________________________________________________________________________
56178ff4 835const AliTRDCalDet *AliTRDcalibDB::GetGainFactorDet()
836{
837 //
838 // Returns the gain factor calibration object
839 // containing one number per detector
840 //
841
842 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
843 (GetCachedCDBObject(kIDGainFactorChamber));
844 if (!calChamber) {
845 return 0;
846 }
847 else {
848 return calChamber;
849 }
850
851}
852
853//_____________________________________________________________________________
7754cd1f 854Float_t AliTRDcalibDB::GetGainFactorAverage(Int_t det)
855{
856 //
857 // Returns the average gain factor for the given detector
858 //
859
95867fd1 860 const AliTRDCalDet *calDet = dynamic_cast<const AliTRDCalDet *>
6d50f529 861 (GetCachedCDBObject(kIDGainFactorChamber));
862 if (!calDet) {
7754cd1f 863 return -1;
6d50f529 864 }
7754cd1f 865
866 return calDet->GetValue(det);
2745a409 867
acba9bad 868}
6a739e92 869
870//_____________________________________________________________________________
524fc8fa 871AliTRDCalROC *AliTRDcalibDB::GetPRFROC(Int_t det)
872{
873 //
874 // Returns the PRF calibration object for a given ROC
875 // containing one number per pad
876 //
877
878 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
879 (GetCachedCDBObject(kIDPRFWidth));
880 if (!calPad) {
881 return 0;
882 }
883
884 AliTRDCalROC *roc = calPad->GetCalROC(det);
885 if (!roc) {
886 return 0;
887 }
888 else {
889 return roc;
890 }
891
892}
893
894//_____________________________________________________________________________
6a739e92 895Float_t AliTRDcalibDB::GetPRFWidth(Int_t det, Int_t col, Int_t row)
896{
897 //
898 // Returns the PRF width for the given pad.
899 //
900
95867fd1 901 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
6d50f529 902 (GetCachedCDBObject(kIDPRFWidth));
903 if (!calPad) {
6a739e92 904 return -1;
6d50f529 905 }
6a739e92 906
95867fd1 907 AliTRDCalROC *roc = calPad->GetCalROC(det);
6d50f529 908 if (!roc) {
6a739e92 909 return -1;
6d50f529 910 }
6a739e92 911
95867fd1 912 return roc->GetValue(col,row);
2745a409 913
acba9bad 914}
3551db50 915
916//_____________________________________________________________________________
5b7ccf04 917Int_t AliTRDcalibDB::ExtractTimeBinsFromString(TString tbstr)
3551db50 918{
a835b5d7 919 // Check if there is any content in the string first
920 if (tbstr.Length() == 0) {
921 AliError("Parameter for number of timebins is empty!");
6c3e7ad0 922 return -1;
e232d349 923 }
c6f7c6cb 924
a835b5d7 925 // Check if we have the correct config parameter
926 TString tbident = "tb";
927 TString tbsubstr = tbstr(0,2);
928 if (!tbsubstr.EqualTo(tbident)) {
929 AliError(Form("Parameter for number of timebins is corrupted (%s)!", tbstr.Data()));
6c3e7ad0 930 return -1;
a835b5d7 931 }
c6f7c6cb 932
a835b5d7 933 tbstr.Remove(0,2);
934 // check if there is more than a number
935 if (!tbstr.IsDigit()) {
936 AliError(Form("Parameter for number of timebins is corrupted (%s)!", tbstr.Data()));
6c3e7ad0 937 return -1;
e232d349 938 }
d6a1ec13 939
5b7ccf04 940 return tbstr.Atoi();
c6f7c6cb 941
5b7ccf04 942}
943
944//_____________________________________________________________________________
01bf853b 945Int_t AliTRDcalibDB::GetNumberOfTimeBinsDCSBoard(){
946 // This is an old way to extract the number of time bins,
947 // only to be used as a fallback to see whether there's
948 // a patched OCDB object!
949
950 Int_t nTB=-1;
951 // Get the array with SOR and EOR
952 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
953 if(!dcsArr)
954 return -1; // Error
955 // Check CalDCS version
956 Int_t calver = 0;
957 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS")) calver = 1;
958 else if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
959 // CalDCS version 1
960 if (calver == 1) {
961 // DCS object
962 AliTRDCalDCS *calSOR = dynamic_cast<AliTRDCalDCS *>(dcsArr->At(0));
963 // SOR mandantory
964 if(!calSOR)
965 return -1; // Error
966 else
967 nTB=calSOR->GetGlobalNumberOfTimeBins();
968 AliTRDCalDCS *calEOR = dynamic_cast<AliTRDCalDCS *>(dcsArr->At(1));
969 if(calEOR && calEOR->GetGlobalNumberOfTimeBins()!=nTB)
970 return -2; // Mixed
971 }
972 else if (calver == 2) {
973 // DCS object
974 AliTRDCalDCSv2 *calSOR = dynamic_cast<AliTRDCalDCSv2 *>(dcsArr->At(0));
975 // SOR mandantory
976 if(!calSOR)
977 return -1; // Error
978 else
979 nTB=calSOR->GetGlobalNumberOfTimeBins();
980 AliTRDCalDCSv2 *calEOR = dynamic_cast<AliTRDCalDCSv2 *>(dcsArr->At(1));
981 if(calEOR && calEOR->GetGlobalNumberOfTimeBins()!=nTB)
982 return -2; // Mixed
983 }
984 else{
985 // No version 1 nor version 2 object
986 return -1; // Error
987 }
988
989 // All well
990 return nTB;
991}
992//_____________________________________________________________________________
5b7ccf04 993Int_t AliTRDcalibDB::GetNumberOfTimeBinsDCS()
994{
995 //
996 // Returns number of time bins from the DCS
997 //
998
01bf853b 999 // Initialize with values indicating no information
1000 TString cfg="";
1001 Int_t nTB = -1;
1002 // Extract the global configuration name
1003 GetGlobalConfigurationByChamber(cfg,kTimebin);
1004 // Extract the number of time bins from
1005 // the global configuration
1006 if(cfg.Length()>0){
1007 nTB = ExtractTimeBinsFromString(cfg);
1008 }
1009 if(nTB>0){
1010 // All well, we could extract the number
1011 // of time bins from the configuration name
1012 return nTB;
1013 }
1014 else{
1015 // No number of time bins from config name.
1016 // No board responded or similar.
1017 // We patched some OCDB entries with
1018 // only the global number of time bins set.
1019 // We should get these here
1020 nTB=GetNumberOfTimeBinsDCSBoard();
1021 if(nTB>0){
1022 AliWarning("Using old method for number of time bins."
1023 " This is probably a patched OCDB entry");
1024 return nTB;
1025 }
1026 else{
1027 // Error
1028 AliError("No number of time bins either"
1029 " from config name or patched OCDB entry");
1030 return -1;
1031 }
1032 }
1033
1034
1035 // // Get the corresponding parameter
1036 // TString cfgstr = "", cfgname = "";
1037 // GetGlobalConfiguration(cfgname);
1038 // if(cfgname.Length()==0)
1039 // return -1;
1040 // GetDCSConfigParOption(cfgname, kTimebin, 0, cfgstr);
1041 // if(cfgstr.Length()==0)
1042 // return -1;
1043 // return ExtractTimeBinsFromString(cfgstr);
ea3eaa08 1044
e232d349 1045}
1046
1047//_____________________________________________________________________________
f1dcad37 1048void AliTRDcalibDB::GetFilterType(TString &filterType)
1049{
1050 //
1051 // Returns the filter type
1052 //
1053
5b7ccf04 1054 TString cfgname = "";
1055 GetGlobalConfiguration(cfgname);
1056 GetDCSConfigParOption(cfgname, kFltrSet, 0, filterType);
d6a1ec13 1057
af086c5e 1058}
1059
1060//_____________________________________________________________________________
ea3eaa08 1061Int_t AliTRDcalibDB::GetOnlineGainTableID()
1062{
1063 //
1064 // Get the gain table ID from the DCS
1065 //
1066
1067 if (fOnlineGainTableID > 0) {
1068 return fOnlineGainTableID;
1069 }
1070
1071 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
1072 if (!dcsArr){
1073 return -1;
1074 }
1075
1076 Int_t esor = 0; // Take SOR
1077 Int_t calver = 0; // Check CalDCS version
1078 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS")) calver = 1;
1079 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
1080
1081 if (calver == 1) {
1082
1083 // No data for old DCS object available, anyway
1084 return -1;
1085
1086 }
1087 else if (calver == 2) {
1088
1089 // DCSv2 object
1090 const AliTRDCalDCSv2 *calDCSv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(esor));
1091 if(!calDCSv2){
1092 return -1;
1093 }
1094
1095 TString tableName = "";
1096 for (Int_t i = 0; i < 540; i++) {
1097 const AliTRDCalDCSFEEv2 *calDCSFEEv2 = calDCSv2->GetCalDCSFEEObj(0);
1098 tableName = calDCSFEEv2->GetGainTableName();
1099 if (tableName.Length() > 0) {
1100 break;
1101 }
1102 }
56a188ab 1103 if (tableName.CompareTo("Krypton_2011-01") == 0)
ea3eaa08 1104 fOnlineGainTableID = 1;
56a188ab 1105 else if (tableName.CompareTo("Gaintbl_Uniform_FGAN0_2011-01") == 0)
412d07b9 1106 fOnlineGainTableID = 2;
56a188ab 1107 else if (tableName.CompareTo("Gaintbl_Uniform_FGAN8_2011-01") == 0)
412d07b9 1108 fOnlineGainTableID = 3;
56a188ab 1109 else if (tableName.CompareTo("Krypton_2011-02") == 0)
3abf1c06 1110 fOnlineGainTableID = 4;
56a188ab 1111 else if (tableName.CompareTo("Krypton_2011-03") == 0)
4a05be5f 1112 fOnlineGainTableID = 5;
56a188ab 1113 else if (tableName.CompareTo("Gaintbl_Uniform_FGAN0_2012-01") == 0)
4a05be5f 1114 fOnlineGainTableID = 6;
56a188ab 1115 else if (tableName.CompareTo("Gaintbl_Uniform_FGAN8_2012-01") == 0)
4a05be5f 1116 fOnlineGainTableID = 7;
56a188ab 1117 else if (tableName.CompareTo("Krypton_2012-01") == 0)
d9e5ae00 1118 fOnlineGainTableID = 8;
56a188ab 1119 else
1120 AliFatal(Form("unknown gaintable <%s> requested", tableName.Data()));
1121
1122 AliInfo(Form("looking for gaintable: %s (id %i)",
1123 tableName.Data(), fOnlineGainTableID));
ea3eaa08 1124
56a188ab 1125 if (fOnlineGainTableID > 0)
1126 return fOnlineGainTableID;
ea3eaa08 1127 }
1128 else {
1129
1130 AliError("NO DCS/DCSv2 OCDB entry found!");
1131 return -1;
1132
1133 }
1134
45b38fb0 1135 return -1;
1136
ea3eaa08 1137}
1138
1139//_____________________________________________________________________________
1140void AliTRDcalibDB::GetGlobalConfiguration(TString &config)
1141{
af086c5e 1142 //
1143 // Get Configuration from the DCS
1144 //
d6a1ec13 1145
af086c5e 1146 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
1147 if(!dcsArr){
a835b5d7 1148 AliError("No DCS CDB Object available!");
af086c5e 1149 config = "";
1150 return;
1151 }
d6a1ec13 1152
a835b5d7 1153 Int_t idSOR = 0, idEOR=1; // The index of SOR and EOR
1154 Bool_t hasSOR = (dcsArr->At(idSOR));
1155 Bool_t hasEOR = (dcsArr->At(idEOR));
1156 TString cfgSOR = "", cfgEOR = ""; // The configuration at SOR/EOR
d6a1ec13 1157
a835b5d7 1158 // The SOR object is mandatory
1159 if (!hasSOR) {
1160 AliError("NO SOR object found in CDB file!");
1161 config = "";
1162 return;
1163 }
1164 if (!hasEOR) AliWarning("NO EOR object found in CDB file!");
ea3eaa08 1165
a835b5d7 1166 // Check CalDCS version
1167 Int_t calver = 0;
1168 if (!strcmp(dcsArr->At(idSOR)->ClassName(),"AliTRDCalDCS")) calver = 1;
1169 else if (!strcmp(dcsArr->At(idSOR)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
ea3eaa08 1170
a835b5d7 1171 // Get the configuration strings
1172 if (calver == 1) {
1173 // DCS object
1174 const AliTRDCalDCS *calSOR = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(idSOR));
1175 cfgSOR = calSOR->GetGlobalConfigName();
1176 if (hasEOR) {
1177 const AliTRDCalDCS *calEOR = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(idEOR));
1178 cfgEOR = calEOR->GetGlobalConfigName();
1179 }
ea3eaa08 1180 }
1181 else if (calver == 2) {
d6a1ec13 1182 // DCSv2 object
a835b5d7 1183 const AliTRDCalDCSv2 *calv2SOR = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(idSOR));
1184 cfgSOR = calv2SOR->GetGlobalConfigName();
1185 if (hasEOR) {
1186 const AliTRDCalDCSv2 *calv2EOR = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(idEOR));
1187 cfgEOR = calv2EOR->GetGlobalConfigName();
1188 }
ea3eaa08 1189 }
1190 else {
ea3eaa08 1191 AliError("NO DCS/DCSv2 OCDB entry found!");
a835b5d7 1192 config = "";
1193 return;
1194 }
ea3eaa08 1195
a835b5d7 1196 // If there is no EOR entry, return the SOR value
1197 if (!hasEOR || cfgEOR.Length()==0) {
1198 config = cfgSOR;
1199 return;
ea3eaa08 1200 }
d6a1ec13 1201
a835b5d7 1202 // Check if the configuration is the same for both
1203 if (cfgSOR.EqualTo(cfgEOR)) {
1204 config = cfgSOR;
1205 return;
1206 }
1207
1208 // When both SOR and EOR have an entry but are different, the config is not defined
1209 AliError("Inconsistent configuration at start and end of run found!");
1210 config = "";
1211 return;
1212
af086c5e 1213}
01bf853b 1214//_____________________________________________________________________________
1215void AliTRDcalibDB::GetGlobalConfigurationByChamber(TString &config,Int_t par, Int_t opt)
1216{
1217 //
1218 // Get Configuration from the DCS
1219 //
1220
1221 // par is the enumeration from kFltrSet = 1 ... kAddOpti 6
1222 // example:
1223 // cf_p_nozs_tb30_csmtrk_ptrg
1224 // par 1 2 3 4 5
1225 // kFltrSet kTimebin kTrigSet
1226 // kReadout kTrkMode
1227 // opt is 0 for the value itself and 1,2,3 for the first, second option
1228 // opt has standard value of 0 in header file
f1dcad37 1229
01bf853b 1230
1231 // The point is that we extract the parameter/option for
1232 // each of the 540 chambers and compare only this
1233 // parameter/option for a global value, not the full
1234 // configuration name with all parameters
1235
1236 // Get the array with SOR and EOR
1237 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
1238 if(!dcsArr){
1239 AliError("No DCS CDB Object available!");
1240 config = "";
1241 return;
1242 }
1243
1244 // Check CalDCS version
1245 Int_t calver = 0;
1246 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS")) calver = 1;
1247 else if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
1248 //
1249 // Get the configuration strings
1250 //
1251 // CalDCS version 1
1252 if (calver == 1) {
1253
1254 // Loop over SOR/EOR
1255 for(Int_t iSEOR=0;iSEOR<2;iSEOR++){
1256
1257 // DCS object
1258 AliTRDCalDCS *cal = dynamic_cast<AliTRDCalDCS *>(dcsArr->At(iSEOR));
1259 if(!cal){
1260 // SOR mandantory
1261 if(iSEOR==0){
1262 AliError("NO SOR object found in CDB file!");
1263 config = "";
1264 return;
1265 }
1266 else{
1267 AliWarning("NO EOR object found in CDB file!");
1268 continue;
1269 }
1270 } // Check DCS object is there
1271
1272 // Loop over 540 chambers
1273 {
1274 Int_t iDet=0;
1275 // Find the first chamber in SOR
1276 if(iSEOR==0){
1277 // Loop until we find the first chamber
1278 for(;iDet<kNdet;iDet++){
1279 const AliTRDCalDCSFEE *DCSFEEObj = cal->GetCalDCSFEEObj(iDet);
1280 // Check it's an installed chamber that responded
1281 if(DCSFEEObj && !DCSFEEObj->GetStatusBit()) {
1282
1283 // We ask for a valid configuration name starting with cf_
1284 if(DCSFEEObj->GetConfigName().BeginsWith("cf_")){
1285 // Set the parameter of the first good ROC as global,
1286 // we take only the requested part!
1287 GetDCSConfigParOption(DCSFEEObj->GetConfigName(), par, opt, config);
1288 // Increase counter to not look at this chamber again
1289 // and break loop
1290 iDet++;
1291 break;
1292 } // End: valid config name
1293 } // End: first good chamber
1294 } // End: find the first chamber
1295 } // End: is SOR
1296
1297 // Now compare the other chambers with the first one
1298 for(;iDet<kNdet;iDet++){
1299 const AliTRDCalDCSFEE *DCSFEEObj = cal->GetCalDCSFEEObj(iDet);
1300 // Check it's an installed chamber that responded
1301 if(DCSFEEObj && !DCSFEEObj->GetStatusBit()) {
1302
1303 // We ask for a valid configuration name starting with cf_
1304 if(DCSFEEObj->GetConfigName().BeginsWith("cf_")){
1305
1306 // Get the parameter/option of this chamber
1307 TString tmpcfg;
1308 GetDCSConfigParOption(DCSFEEObj->GetConfigName(), par, opt, tmpcfg);
1309 // Compare with the global value
1310 if(config.CompareTo(tmpcfg)){
1311 // Two cases mixed or changed during run
1312 if(iSEOR==0){
1313 AliError("Mixed DCS configuration for different chambers!");
1314 config="mixed";
1315 return;
1316 } else {
1317 AliError("Inconsistent configuration at start and end of run found!");
1318 config = "";
1319 return;
1320 }
1321 }
1322 }// Valid config name
1323 }// Good chamber
1324 } // Second half loop
1325 } // Loop over 540 chambers
1326 } // Loop over SOR / EOR
1327 } // End calver 1
1328 //
1329 // CalDCS version 2
1330 //
1331 else if (calver == 2) {
1332
1333 // Loop over SOR/EOR
1334 for(Int_t iSEOR=0;iSEOR<2;iSEOR++){
1335
1336 // DCS object
1337 AliTRDCalDCSv2 *cal = dynamic_cast<AliTRDCalDCSv2 *>(dcsArr->At(iSEOR));
1338 if(!cal){
1339 // SOR mandantory
1340 if(iSEOR==0){
1341 AliError("NO SOR object found in CDB file!");
1342 config = "";
1343 return;
1344 }
1345 else{
1346 AliWarning("NO EOR object found in CDB file!");
1347 continue;
1348 }
1349 } // Check DCS object is there
1350
1351 // Loop over 540 chambers
1352 {
1353 Int_t iDet=0;
1354 // Find the first chamber in SOR
1355 if(iSEOR==0){
1356 // Loop until we find the first chamber
1357 for(;iDet<kNdet;iDet++){
1358 const AliTRDCalDCSFEEv2 *DCSFEEObj = cal->GetCalDCSFEEObj(iDet);
1359 // Check it's an installed chamber that responded
1360 if(DCSFEEObj && !DCSFEEObj->GetStatusBit()) {
1361 // Check for a valid config name
1362 if(DCSFEEObj->GetConfigName().BeginsWith("cf_")){
1363
1364 // Set the parameter of the first good ROC as global,
1365 // we take only the requested part!
1366 GetDCSConfigParOption(DCSFEEObj->GetConfigName(), par, opt, config);
1367 // Increase counter to not look at this chamber again
1368 // and break loop
1369 iDet++;
1370 break;
1371 } // End: valid config name
1372 } // End: first good chamber
1373 } // End: find the first chamber
1374 } // End: is SOR
1375
1376 // Now compare the other chambers with the first one
1377 for(;iDet<kNdet;iDet++){
1378 const AliTRDCalDCSFEEv2 *DCSFEEObj = cal->GetCalDCSFEEObj(iDet);
1379 // Check it's an installed chamber that responded
1380 if(DCSFEEObj && !DCSFEEObj->GetStatusBit()) {
1381
1382 // Check for a valid config name
1383 if(DCSFEEObj->GetConfigName().BeginsWith("cf_")){
1384
1385 // Get the parameter/option of this chamber
1386 TString tmpcfg;
1387 GetDCSConfigParOption(DCSFEEObj->GetConfigName(), par, opt, tmpcfg);
1388 // Compare with the global value
1389 if(config.CompareTo(tmpcfg)){
1390 // Two cases mixed or changed during run
1391 if(iSEOR==0){
1392 AliError("Mixed DCS configuration for different chambers!");
1393 config="mixed";
1394 return;
1395 } else {
1396 AliError("Inconsistent configuration at start and end of run found!");
1397 config = "";
1398 return;
1399 }
1400 }
1401 } // End: valid config name
1402 } // End: Good chamber
1403 } // End: Second half loop
1404 } // Loop over 540 chambers
1405 } // Loop over SOR / EOR
1406 } // End calver 2
1407 else {
1408 AliError("NO DCS/DCSv2 OCDB entry found!");
1409 config = "";
1410 return;
1411 }
1412
1413}
af086c5e 1414//_____________________________________________________________________________
f8059b39 1415void AliTRDcalibDB::GetGlobalConfigurationVersion(TString &version)
1416{
1417 //
1418 // Get Version of Configuration from the DCS
1419 //
1420
1421 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
1422 if(!dcsArr){
1423 version = "";
1424 return;
1425 }
1426
1427 Int_t esor = 0; // Take SOR
1428 Int_t calver = 0; // Check CalDCS version
1429 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS")) calver = 1;
1430 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
1431
1432 if (calver == 1) {
1433
1434 // DCS object
1435 const AliTRDCalDCS *calDCS = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(esor));
1436 if(!calDCS){
1437 version = "";
1438 return;
1439 }
1440 version = calDCS->GetGlobalConfigVersion();
1441
1442 }
1443 else if (calver == 2) {
1444
1445 // DCSv2 object
1446 const AliTRDCalDCSv2 *calDCSv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(esor));
1447 if(!calDCSv2){
1448 version = "";
1449 return;
1450 }
1451 version = calDCSv2->GetGlobalConfigVersion();
1452
1453 }
1454 else {
1455
1456 AliError("NO DCS/DCSv2 OCDB entry found!");
1457
1458 }
1459
1460}
1461
1462//_____________________________________________________________________________
1567d9a4 1463Int_t AliTRDcalibDB::GetNumberOfParsDCS(TString cname, Char_t delimiter)
5b7ccf04 1464{
1465 // Get the number of configuration parameters from the DCS config
1466
1567d9a4 1467 //AliInfo(Form("\"%s\" tokenized by \"%c\"", cname.Data(), delimiter));
1468 if(!cname.Length()) return -1; // -1 for the "cf"
1469 Int_t nconf(0);
1470 for(Int_t ich(1); ich<cname.Length()-1; ich++){ if(cname[ich]==delimiter) nconf++;}
1471 return nconf;
5b7ccf04 1472}
1473
1474//_____________________________________________________________________________
1475Int_t AliTRDcalibDB::GetNumberOfOptsDCS(TString cname, Int_t cfgType)
1476{
1477 // Get the number of options of a given configuration parameter from DCS
1478
1567d9a4 1479 Char_t cdelim = '_', // define the delimiters
1480 odelim = '-';
1481 Int_t nconfig = GetNumberOfParsDCS(cname, cdelim);
5b7ccf04 1482
1483 // protect
1567d9a4 1484 if ((nconfig == -1) || (nconfig < cfgType)) {
5b7ccf04 1485 AliError("Not enough parameters in DCS configuration name!");
1486 return 0;
1487 }
1488
1567d9a4 1489 TObjArray *carr = cname.Tokenize(cdelim);
1490 Int_t nopt = GetNumberOfParsDCS(((TObjString*)carr->At(cfgType))->GetString(), odelim);
1491 carr->Delete(); delete carr;
1492 return nopt;
5b7ccf04 1493}
1494
1495//_____________________________________________________________________________
1496void AliTRDcalibDB::GetDCSConfigParOption(TString cname, Int_t cfgType, Int_t option, TString &cfgo)
af086c5e 1497{
1498 //
fc358d0f 1499 // Get a configuration (see enum in header file) or the options of a configuration
1500 // option == 0 returns the configuration itself
1501 // option > 0 returns the optional parameter Nr. (option) of the configuration (cfgType)
af086c5e 1502 //
ea3eaa08 1503
1567d9a4 1504 Char_t cdelim = '_', // define the delimiters
1505 odelim = '-';
fc358d0f 1506
1567d9a4 1507 Int_t nconfig = GetNumberOfParsDCS(cname, cdelim);
fc358d0f 1508 // protect
1567d9a4 1509 if (nconfig == -1) {
5b7ccf04 1510 AliError("DCS configuration name empty!");
fc358d0f 1511 cfgo = "";
1512 return;
1567d9a4 1513 } else if (nconfig < cfgType) {
01bf853b 1514 AliError(Form("Not enough parameters in DCS configuration name!"
1515 " Name %s",cname.Data()));
fc358d0f 1516 cfgo = "";
1517 return;
1518 }
1519
1567d9a4 1520 TObjArray *carr = cname.Tokenize(cdelim);
1521 TString cfgString(((TObjString*)carr->At(cfgType))->GetString());
1522 Int_t noptions = GetNumberOfParsDCS(cfgString, odelim);
5b7ccf04 1523 // protect
1567d9a4 1524 if (noptions < option) {
01bf853b 1525 AliError(Form("Not enough options in DCS configuration name!"
1526 " Name %s",cname.Data()));
5b7ccf04 1527 cfgo = "";
1567d9a4 1528 carr->Delete(); delete carr;
fc358d0f 1529 return;
fc358d0f 1530 }
1567d9a4 1531 TObjArray *oarr = cfgString.Tokenize(odelim);
5b7ccf04 1532 cfgo = ((TObjString*)oarr->At(option))->GetString();
1567d9a4 1533 carr->Delete(); delete carr;
1534 oarr->Delete(); delete oarr;
5b7ccf04 1535 return;
fc358d0f 1536
1537}
1538
1539//_____________________________________________________________________________
1540Bool_t AliTRDcalibDB::HasOnlineFilterPedestal()
1541{
1542 //
1543 // Checks whether pedestal filter was applied online
1544 //
1545
1546 TString filterconfig;
1547 GetFilterType(filterconfig);
ea3eaa08 1548
af086c5e 1549 return filterconfig.Contains("p");
ea3eaa08 1550
af086c5e 1551}
1552
1553//_____________________________________________________________________________
ea3eaa08 1554Bool_t AliTRDcalibDB::HasOnlineFilterGain()
1555{
af086c5e 1556 //
1557 // Checks whether online gain filter was applied
1558 //
ea3eaa08 1559
fc358d0f 1560 TString filterconfig;
1561 GetFilterType(filterconfig);
ea3eaa08 1562
af086c5e 1563 return filterconfig.Contains("g");
ea3eaa08 1564
af086c5e 1565}
1566
1567//_____________________________________________________________________________
ea3eaa08 1568Bool_t AliTRDcalibDB::HasOnlineTailCancellation()
1569{
af086c5e 1570 //
1571 // Checks whether online tail cancellation was applied
1572 //
ea3eaa08 1573
fc358d0f 1574 TString filterconfig;
1575 GetFilterType(filterconfig);
ea3eaa08 1576
af086c5e 1577 return filterconfig.Contains("t");
ea3eaa08 1578
e232d349 1579}
1580
1581//_____________________________________________________________________________
7754cd1f 1582Char_t AliTRDcalibDB::GetPadStatus(Int_t det, Int_t col, Int_t row)
1583{
1584 //
1585 // Returns the status of the given pad
1586 //
1587
aa617684 1588 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1589 (GetCachedCDBObject(kIDPadStatus));
6d50f529 1590 if (!cal) {
7754cd1f 1591 return -1;
6d50f529 1592 }
7754cd1f 1593
95867fd1 1594 const AliTRDCalSingleChamberStatus *roc = cal->GetCalROC(det);
6d50f529 1595 if (!roc) {
7754cd1f 1596 return -1;
6d50f529 1597 }
7754cd1f 1598
95867fd1 1599 return roc->GetStatus(col,row);
2745a409 1600
7754cd1f 1601}
1602
1603//_____________________________________________________________________________
0e09df31 1604AliTRDCalSingleChamberStatus* AliTRDcalibDB::GetPadStatusROC(Int_t det)
1605{
1606 //
1607 // Returns the pad status calibration object for a given ROC
1608 //
1609
1610 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1611 (GetCachedCDBObject(kIDPadStatus));
1612 if (!cal) {
1613 return 0;
1614 }
1615
1616 AliTRDCalSingleChamberStatus *roc = cal->GetCalROC(det);
1617 if (!roc) {
1618 return 0;
1619 }
1620 else {
1621 return roc;
1622 }
1623
1624}
1625
1626//_____________________________________________________________________________
7754cd1f 1627Char_t AliTRDcalibDB::GetChamberStatus(Int_t det)
1628{
1629 //
1630 // Returns the status of the given chamber
1631 //
1632
95867fd1 1633 const AliTRDCalChamberStatus *cal = dynamic_cast<const AliTRDCalChamberStatus *>
6d50f529 1634 (GetCachedCDBObject(kIDChamberStatus));
1635 if (!cal) {
7754cd1f 1636 return -1;
6d50f529 1637 }
7754cd1f 1638
1639 return cal->GetStatus(det);
2745a409 1640
7754cd1f 1641}
1642
1643//_____________________________________________________________________________
a7ac01d2 1644AliTRDrecoParam* AliTRDcalibDB::GetRecoParam(Int_t */*eventtype*/)
1645{
be28462a 1646 //
1647 // Returns the TRD reconstruction parameters from the OCDB
1648 //
1649
a7ac01d2 1650 const TClonesArray *recos = dynamic_cast<const TClonesArray*>(GetCachedCDBObject(kIDRecoParam));
be28462a 1651 if (!recos) return 0x0;
a7ac01d2 1652
1653 // calculate entry based on event type info
1654 Int_t n = 0; //f(eventtype[0], eventtype[1], ....)
be28462a 1655
ea3eaa08 1656 return (AliTRDrecoParam *) recos->UncheckedAt(n);
a7ac01d2 1657
be28462a 1658}
a7ac01d2 1659
1660//_____________________________________________________________________________
7754cd1f 1661Bool_t AliTRDcalibDB::IsPadMasked(Int_t det, Int_t col, Int_t row)
1662{
1663 //
1664 // Returns status, see name of functions for details ;-)
1665 //
1666
95867fd1 1667 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1668 (GetCachedCDBObject(kIDPadStatus));
6d50f529 1669 if (!cal) {
7754cd1f 1670 return -1;
6d50f529 1671 }
7754cd1f 1672
95867fd1 1673 return cal->IsMasked(det,col,row);
2745a409 1674
7754cd1f 1675}
1676
1677//_____________________________________________________________________________
1678Bool_t AliTRDcalibDB::IsPadBridgedLeft(Int_t det, Int_t col, Int_t row)
1679{
1680 //
1681 // Returns status, see name of functions for details ;-)
1682 //
1683
95867fd1 1684 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1685 (GetCachedCDBObject(kIDPadStatus));
6d50f529 1686 if (!cal) {
7754cd1f 1687 return -1;
6d50f529 1688 }
7754cd1f 1689
95867fd1 1690 return cal->IsBridgedLeft(det,col,row);
2745a409 1691
7754cd1f 1692}
1693
1694//_____________________________________________________________________________
1695Bool_t AliTRDcalibDB::IsPadBridgedRight(Int_t det, Int_t col, Int_t row)
1696{
1697 //
1698 // Returns status, see name of functions for details ;-)
1699 //
1700
95867fd1 1701 const AliTRDCalPadStatus * cal = dynamic_cast<const AliTRDCalPadStatus *>
1702 (GetCachedCDBObject(kIDPadStatus));
6d50f529 1703 if (!cal) {
7754cd1f 1704 return -1;
6d50f529 1705 }
7754cd1f 1706
95867fd1 1707 return cal->IsBridgedRight(det,col,row);
2745a409 1708
7754cd1f 1709}
1710
1711//_____________________________________________________________________________
fa7427d0 1712Bool_t AliTRDcalibDB::IsPadNotConnected(Int_t det, Int_t col, Int_t row)
1713{
1714 //
1715 // Returns status, see name of functions for details ;-)
1716 //
f1dcad37 1717
fa7427d0 1718 const AliTRDCalPadStatus * cal = dynamic_cast<const AliTRDCalPadStatus *>
1719 (GetCachedCDBObject(kIDPadStatus));
1720 if (!cal) {
1721 return -1;
1722 }
1723
1724 return cal->IsNotConnected(det,col,row);
1725
1726}
1727
1728//_____________________________________________________________________________
eda91732 1729Bool_t AliTRDcalibDB::IsChamberGood(Int_t det)
1730{
1731 //
1732 // Returns status, see name of functions for details ;-)
1733 //
1734
1735 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1736 (GetCachedCDBObject(kIDChamberStatus));
1737 if (!cal) {
1738 return -1;
1739 }
1740
1741 return cal->IsGood(det);
1742
1743}
1744
1745//_____________________________________________________________________________
1746Bool_t AliTRDcalibDB::IsChamberNoData(Int_t det)
7754cd1f 1747{
1748 //
1749 // Returns status, see name of functions for details ;-)
1750 //
1751
95867fd1 1752 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1753 (GetCachedCDBObject(kIDChamberStatus));
6d50f529 1754 if (!cal) {
7754cd1f 1755 return -1;
6d50f529 1756 }
7754cd1f 1757
eda91732 1758 return cal->IsNoData(det);
2745a409 1759
7754cd1f 1760}
1761
1762//_____________________________________________________________________________
eda91732 1763Bool_t AliTRDcalibDB::IsHalfChamberNoData(Int_t det, Int_t side)
7754cd1f 1764{
1765 //
1766 // Returns status, see name of functions for details ;-)
1767 //
1768
95867fd1 1769 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1770 (GetCachedCDBObject(kIDChamberStatus));
6d50f529 1771 if (!cal) {
7754cd1f 1772 return -1;
6d50f529 1773 }
7754cd1f 1774
eda91732 1775 return side > 0 ? cal->IsNoDataSideB(det) : cal->IsNoDataSideA(det);
2745a409 1776
7754cd1f 1777}
ea3eaa08 1778
7a6352a6 1779//_____________________________________________________________________________
eda91732 1780Bool_t AliTRDcalibDB::IsChamberBadCalibrated(Int_t det)
ea3eaa08 1781{
7a6352a6 1782 //
1783 // Returns status, see name of functions for details ;-)
1784 //
7754cd1f 1785
7a6352a6 1786 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1787 (GetCachedCDBObject(kIDChamberStatus));
1788 if (!cal) {
1789 return -1;
1790 }
1791
eda91732 1792 return cal->IsBadCalibrated(det);
7a6352a6 1793
1794}
ea3eaa08 1795
7754cd1f 1796//_____________________________________________________________________________
67abca5c 1797Bool_t AliTRDcalibDB::IsChamberNotCalibrated(Int_t det)
1798{
1799 //
1800 // Returns status, see name of functions for details ;-)
1801 //
1802
1803 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1804 (GetCachedCDBObject(kIDChamberStatus));
1805 if (!cal) {
1806 return -1;
1807 }
1808
1809 return cal->IsNotCalibrated(det);
1810
1811}
1812
1813//_____________________________________________________________________________
0d83b3a5 1814const AliTRDCalPID *AliTRDcalibDB::GetPIDObject(AliTRDpidUtil::ETRDPIDMethod method)
cc7cef99 1815{
1816 //
1817 // Returns the object storing the distributions for PID with likelihood
1818 //
9a96f175 1819
1820 switch(method) {
0d83b3a5 1821 case AliTRDpidUtil::kLQ:
4ba1d6ae 1822 return dynamic_cast<const AliTRDCalPID *>(GetCachedCDBObject(kIDPIDLQ));
0d83b3a5 1823 case AliTRDpidUtil::kNN:
4ba1d6ae 1824 return dynamic_cast<const AliTRDCalPID *>(GetCachedCDBObject(kIDPIDNN));
543691ea 1825 case AliTRDpidUtil::kESD:
1826 return 0x0; // To avoid compiler warnings
9a96f175 1827 }
1828
10f75631 1829 return 0x0;
2745a409 1830
cc7cef99 1831}
1832
1833//_____________________________________________________________________________
f2391aef 1834AliTRDPIDResponse *AliTRDcalibDB::GetPIDResponse(AliTRDPIDResponse::ETRDPIDMethod /*method*/)
ea3eaa08 1835{
1836 //
1837 // Returns the PID response object for 1D-LQ
1838 //
1839
1840 if (!fPIDResponse) {
f2391aef 1841 AliDebug(2, "Setting new PID response.");
ea3eaa08 1842
9dcc64cc 1843 fPIDResponse = new AliTRDPIDResponse;
ea3eaa08 1844
9dcc64cc 1845 // Load Reference Histos from OCDB
f2391aef 1846// if(method == AliTRDPIDResponse::kLQ1D){
bd58d4b9 1847 //fPIDResponse->SetPIDmethod(AliTRDPIDResponse::kLQ1D);
f2391aef 1848 const TObjArray *references = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDPIDLQ1D));
1849
1850 TIter refs(references);
1851 TObject *obj = NULL;
1852 AliTRDPIDReference *ref = NULL;
1853 Bool_t hasReference = kFALSE;
1854 while ((obj = refs())){
1855 if ((ref = dynamic_cast<AliTRDPIDReference *>(obj))){
1856 AliDebug(2, "Setting new PID response object.");
1857 TDirectory *bkpdir = gDirectory;
1858 gROOT->cd();
1859 AliTRDPIDResponseObject *ro = new AliTRDPIDResponseObject;
1860 ro->SetPIDReference(ref);
1861 fPIDResponse->SetPIDResponseObject(ro);
1862 hasReference = kTRUE;
1863 gDirectory = bkpdir;
1864 break;
121fadea 1865 }
ea3eaa08 1866 }
1867
f2391aef 1868 if (!hasReference) {
1869 AliError("Reference histograms not found in the OCDB");
1870 }
9dcc64cc 1871 }
ea3eaa08 1872
f2391aef 1873// }
1874
9dcc64cc 1875 return fPIDResponse;
ea3eaa08 1876
9dcc64cc 1877}
1878
1879//_____________________________________________________________________________
1880const AliTRDCalTrkAttach* AliTRDcalibDB::GetAttachObject()
1881{
1882 //
1883 // Returns the object storing likelihood distributions for cluster to track attachment
1884 //
ea3eaa08 1885
9dcc64cc 1886 return dynamic_cast<const AliTRDCalTrkAttach*>(GetCachedCDBObject(kIDAttach));
9dcc64cc 1887
ea3eaa08 1888}
9dcc64cc 1889
1890//_____________________________________________________________________________
d4c6453d 1891const AliTRDCalMonitoring *AliTRDcalibDB::GetMonitoringObject()
7754cd1f 1892{
1893 //
1894 // Returns the object storing the monitoring data
1895 //
1896
d4c6453d 1897 return dynamic_cast<const AliTRDCalMonitoring *>
1898 (GetCachedCDBObject(kIDMonitoringData));
1b95a37b 1899
7754cd1f 1900}
1901
1902//_____________________________________________________________________________
6a739e92 1903void AliTRDcalibDB::SamplePRF()
1904{
1905 //
2745a409 1906 // Samples the pad response function (should maybe go somewhere else ...)
6a739e92 1907 //
1908
1909 const Int_t kPRFbin = 61;
1910
053767a4 1911 Float_t prf[kNlayer][kPRFbin] = {
6d50f529 1912 {2.9037e-02, 3.3608e-02, 3.9020e-02, 4.5292e-02,
6a739e92 1913 5.2694e-02, 6.1362e-02, 7.1461e-02, 8.3362e-02,
1914 9.7063e-02, 1.1307e-01, 1.3140e-01, 1.5235e-01,
1915 1.7623e-01, 2.0290e-01, 2.3294e-01, 2.6586e-01,
1916 3.0177e-01, 3.4028e-01, 3.8077e-01, 4.2267e-01,
1917 4.6493e-01, 5.0657e-01, 5.4655e-01, 5.8397e-01,
1918 6.1767e-01, 6.4744e-01, 6.7212e-01, 6.9188e-01,
1919 7.0627e-01, 7.1499e-01, 7.1851e-01, 7.1499e-01,
1920 7.0627e-01, 6.9188e-01, 6.7212e-01, 6.4744e-01,
1921 6.1767e-01, 5.8397e-01, 5.4655e-01, 5.0657e-01,
1922 4.6493e-01, 4.2267e-01, 3.8077e-01, 3.4028e-01,
1923 3.0177e-01, 2.6586e-01, 2.3294e-01, 2.0290e-01,
1924 1.7623e-01, 1.5235e-01, 1.3140e-01, 1.1307e-01,
1925 9.7063e-02, 8.3362e-02, 7.1461e-02, 6.1362e-02,
1926 5.2694e-02, 4.5292e-02, 3.9020e-02, 3.3608e-02,
1927 2.9037e-02},
1928 {2.5478e-02, 2.9695e-02, 3.4655e-02, 4.0454e-02,
1929 4.7342e-02, 5.5487e-02, 6.5038e-02, 7.6378e-02,
1930 8.9696e-02, 1.0516e-01, 1.2327e-01, 1.4415e-01,
1931 1.6794e-01, 1.9516e-01, 2.2573e-01, 2.5959e-01,
1932 2.9694e-01, 3.3719e-01, 3.7978e-01, 4.2407e-01,
1933 4.6889e-01, 5.1322e-01, 5.5569e-01, 5.9535e-01,
1934 6.3141e-01, 6.6259e-01, 6.8882e-01, 7.0983e-01,
1935 7.2471e-01, 7.3398e-01, 7.3761e-01, 7.3398e-01,
1936 7.2471e-01, 7.0983e-01, 6.8882e-01, 6.6259e-01,
1937 6.3141e-01, 5.9535e-01, 5.5569e-01, 5.1322e-01,
1938 4.6889e-01, 4.2407e-01, 3.7978e-01, 3.3719e-01,
1939 2.9694e-01, 2.5959e-01, 2.2573e-01, 1.9516e-01,
1940 1.6794e-01, 1.4415e-01, 1.2327e-01, 1.0516e-01,
1941 8.9696e-02, 7.6378e-02, 6.5038e-02, 5.5487e-02,
1942 4.7342e-02, 4.0454e-02, 3.4655e-02, 2.9695e-02,
1943 2.5478e-02},
1944 {2.2363e-02, 2.6233e-02, 3.0782e-02, 3.6140e-02,
1945 4.2535e-02, 5.0157e-02, 5.9197e-02, 6.9900e-02,
1946 8.2707e-02, 9.7811e-02, 1.1548e-01, 1.3601e-01,
1947 1.5998e-01, 1.8739e-01, 2.1840e-01, 2.5318e-01,
1948 2.9182e-01, 3.3373e-01, 3.7837e-01, 4.2498e-01,
1949 4.7235e-01, 5.1918e-01, 5.6426e-01, 6.0621e-01,
1950 6.4399e-01, 6.7700e-01, 7.0472e-01, 7.2637e-01,
1951 7.4206e-01, 7.5179e-01, 7.5551e-01, 7.5179e-01,
1952 7.4206e-01, 7.2637e-01, 7.0472e-01, 6.7700e-01,
1953 6.4399e-01, 6.0621e-01, 5.6426e-01, 5.1918e-01,
1954 4.7235e-01, 4.2498e-01, 3.7837e-01, 3.3373e-01,
1955 2.9182e-01, 2.5318e-01, 2.1840e-01, 1.8739e-01,
1956 1.5998e-01, 1.3601e-01, 1.1548e-01, 9.7811e-02,
1957 8.2707e-02, 6.9900e-02, 5.9197e-02, 5.0157e-02,
1958 4.2535e-02, 3.6140e-02, 3.0782e-02, 2.6233e-02,
1959 2.2363e-02},
1960 {1.9635e-02, 2.3167e-02, 2.7343e-02, 3.2293e-02,
1961 3.8224e-02, 4.5335e-02, 5.3849e-02, 6.4039e-02,
1962 7.6210e-02, 9.0739e-02, 1.0805e-01, 1.2841e-01,
1963 1.5216e-01, 1.7960e-01, 2.1099e-01, 2.4671e-01,
1964 2.8647e-01, 3.2996e-01, 3.7660e-01, 4.2547e-01,
1965 4.7536e-01, 5.2473e-01, 5.7215e-01, 6.1632e-01,
1966 6.5616e-01, 6.9075e-01, 7.1939e-01, 7.4199e-01,
1967 7.5838e-01, 7.6848e-01, 7.7227e-01, 7.6848e-01,
1968 7.5838e-01, 7.4199e-01, 7.1939e-01, 6.9075e-01,
1969 6.5616e-01, 6.1632e-01, 5.7215e-01, 5.2473e-01,
1970 4.7536e-01, 4.2547e-01, 3.7660e-01, 3.2996e-01,
1971 2.8647e-01, 2.4671e-01, 2.1099e-01, 1.7960e-01,
1972 1.5216e-01, 1.2841e-01, 1.0805e-01, 9.0739e-02,
1973 7.6210e-02, 6.4039e-02, 5.3849e-02, 4.5335e-02,
1974 3.8224e-02, 3.2293e-02, 2.7343e-02, 2.3167e-02,
1975 1.9635e-02},
1976 {1.7224e-02, 2.0450e-02, 2.4286e-02, 2.8860e-02,
1977 3.4357e-02, 4.0979e-02, 4.8966e-02, 5.8612e-02,
1978 7.0253e-02, 8.4257e-02, 1.0102e-01, 1.2094e-01,
1979 1.4442e-01, 1.7196e-01, 2.0381e-01, 2.4013e-01,
1980 2.8093e-01, 3.2594e-01, 3.7450e-01, 4.2563e-01,
1981 4.7796e-01, 5.2991e-01, 5.7974e-01, 6.2599e-01,
1982 6.6750e-01, 7.0344e-01, 7.3329e-01, 7.5676e-01,
1983 7.7371e-01, 7.8410e-01, 7.8793e-01, 7.8410e-01,
1984 7.7371e-01, 7.5676e-01, 7.3329e-01, 7.0344e-01,
1985 6.6750e-01, 6.2599e-01, 5.7974e-01, 5.2991e-01,
1986 4.7796e-01, 4.2563e-01, 3.7450e-01, 3.2594e-01,
1987 2.8093e-01, 2.4013e-01, 2.0381e-01, 1.7196e-01,
1988 1.4442e-01, 1.2094e-01, 1.0102e-01, 8.4257e-02,
1989 7.0253e-02, 5.8612e-02, 4.8966e-02, 4.0979e-02,
1990 3.4357e-02, 2.8860e-02, 2.4286e-02, 2.0450e-02,
1991 1.7224e-02},
1992 {1.5096e-02, 1.8041e-02, 2.1566e-02, 2.5793e-02,
1993 3.0886e-02, 3.7044e-02, 4.4515e-02, 5.3604e-02,
1994 6.4668e-02, 7.8109e-02, 9.4364e-02, 1.1389e-01,
1995 1.3716e-01, 1.6461e-01, 1.9663e-01, 2.3350e-01,
1996 2.7527e-01, 3.2170e-01, 3.7214e-01, 4.2549e-01,
1997 4.8024e-01, 5.3460e-01, 5.8677e-01, 6.3512e-01,
1998 6.7838e-01, 7.1569e-01, 7.4655e-01, 7.7071e-01,
1999 7.8810e-01, 7.9871e-01, 8.0255e-01, 7.9871e-01,
2000 7.8810e-01, 7.7071e-01, 7.4655e-01, 7.1569e-01,
2001 6.7838e-01, 6.3512e-01, 5.8677e-01, 5.3460e-01,
2002 4.8024e-01, 4.2549e-01, 3.7214e-01, 3.2170e-01,
2003 2.7527e-01, 2.3350e-01, 1.9663e-01, 1.6461e-01,
2004 1.3716e-01, 1.1389e-01, 9.4364e-02, 7.8109e-02,
2005 6.4668e-02, 5.3604e-02, 4.4515e-02, 3.7044e-02,
2006 3.0886e-02, 2.5793e-02, 2.1566e-02, 1.8041e-02,
2007 1.5096e-02}};
2008
2009 // More sampling precision with linear interpolation
6d50f529 2010 fPRFlo = -1.5;
2011 fPRFhi = 1.5;
6a739e92 2012 Float_t pad[kPRFbin];
2013 Int_t sPRFbin = kPRFbin;
6d50f529 2014 Float_t sPRFwid = (fPRFhi - fPRFlo) / ((Float_t) sPRFbin);
6a739e92 2015 for (Int_t iPad = 0; iPad < sPRFbin; iPad++) {
6d50f529 2016 pad[iPad] = ((Float_t) iPad + 0.5) * sPRFwid + fPRFlo;
6a739e92 2017 }
6d50f529 2018 fPRFbin = 500;
2019 fPRFwid = (fPRFhi - fPRFlo) / ((Float_t) fPRFbin);
2020 fPRFpad = ((Int_t) (1.0 / fPRFwid));
6a739e92 2021
6d50f529 2022 if (fPRFsmp) delete [] fPRFsmp;
053767a4 2023 fPRFsmp = new Float_t[kNlayer*fPRFbin];
6a739e92 2024
2025 Int_t ipos1;
2026 Int_t ipos2;
2027 Float_t diff;
2028
053767a4 2029 for (Int_t iLayer = 0; iLayer < kNlayer; iLayer++) {
6a739e92 2030
6d50f529 2031 for (Int_t iBin = 0; iBin < fPRFbin; iBin++) {
6a739e92 2032
6d50f529 2033 Float_t bin = (((Float_t) iBin) + 0.5) * fPRFwid + fPRFlo;
6a739e92 2034 ipos1 = ipos2 = 0;
2035 diff = 0;
2036 do {
2037 diff = bin - pad[ipos2++];
2038 } while ((diff > 0) && (ipos2 < kPRFbin));
2039 if (ipos2 == kPRFbin) {
053767a4 2040 fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2-1];
6a739e92 2041 }
2042 else if (ipos2 == 1) {
053767a4 2043 fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2-1];
6a739e92 2044 }
2045 else {
2046 ipos2--;
2047 if (ipos2 >= kPRFbin) ipos2 = kPRFbin - 1;
2048 ipos1 = ipos2 - 1;
053767a4 2049 fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2]
2050 + diff * (prf[iLayer][ipos2] - prf[iLayer][ipos1])
2051 / sPRFwid;
6a739e92 2052 }
2053
2054 }
2055 }
2056
2057}
2058
2059//_____________________________________________________________________________
2060Int_t AliTRDcalibDB::PadResponse(Double_t signal, Double_t dist
eb52b657 2061 , Int_t layer, Double_t *pad) const
6a739e92 2062{
2063 //
2064 // Applies the pad response
56178ff4 2065 // So far this is the fixed parametrization and should be replaced by
2066 // something dependent on calibration values
6a739e92 2067 //
2068
eb52b657 2069 Int_t iBin = ((Int_t) ((-dist - fPRFlo) / fPRFwid));
053767a4 2070 Int_t iOff = layer * fPRFbin;
6a739e92 2071
6d50f529 2072 Int_t iBin0 = iBin - fPRFpad + iOff;
6a739e92 2073 Int_t iBin1 = iBin + iOff;
6d50f529 2074 Int_t iBin2 = iBin + fPRFpad + iOff;
6a739e92 2075
2076 pad[0] = 0.0;
2077 pad[1] = 0.0;
2078 pad[2] = 0.0;
053767a4 2079 if ((iBin1 >= 0) && (iBin1 < (fPRFbin*kNlayer))) {
6a739e92 2080
2081 if (iBin0 >= 0) {
6d50f529 2082 pad[0] = signal * fPRFsmp[iBin0];
6a739e92 2083 }
6d50f529 2084 pad[1] = signal * fPRFsmp[iBin1];
053767a4 2085 if (iBin2 < (fPRFbin*kNlayer)) {
6d50f529 2086 pad[2] = signal * fPRFsmp[iBin2];
6a739e92 2087 }
2088
2089 return 1;
2090
2091 }
2092 else {
2093
2094 return 0;
2095
2096 }
ab0a4106 2097
3551db50 2098}
7a6352a6 2099
2100
a9e22145 2101AliTRDtrapConfig* AliTRDcalibDB::GetTrapConfig()
2102{
2103 // return an existing TRAPconfig or load it from the OCDB
2104 // in case of failure, a default TRAPconfig is created
2105
2106 if (fTrapConfig)
2107 return fTrapConfig;
2108 else {
1b1afdd3 2109 if ((fTrapConfigName.Length() <= 0) || (fTrapConfigVersion.Length() <= 0)) {
2110 // query the configuration to be used
15224417 2111 this->GetGlobalConfiguration(fTrapConfigName);
2112 this->GetGlobalConfigurationVersion(fTrapConfigVersion);
1b1afdd3 2113 }
a9e22145 2114
1b1afdd3 2115 // try to load the requested configuration
2116 this->LoadTrapConfig(fTrapConfigName, fTrapConfigVersion);
a9e22145 2117
2118 // if we still don't have a valid TRAPconfig, create a default one
2119 if (!fTrapConfig) {
2120 AliWarning("Falling back to default configuration");
b3b30cf6 2121 static AliTRDtrapConfig trapConfigDefault("default", "default TRAP configuration");
2122 fTrapConfig = &trapConfigDefault;
a9e22145 2123 AliTRDtrapConfigHandler cfgHandler(fTrapConfig);
2124 cfgHandler.Init();
2125 cfgHandler.LoadConfig();
2126 }
2127
2128 AliInfo(Form("using TRAPconfig \"%s\"", fTrapConfig->GetTitle()));
2129
56a188ab 2130 // we still have to load the gain tables
2131 // if the gain filter is active
2132 if (HasOnlineFilterGain()) {
2133 const Int_t nDets = AliTRDgeometry::Ndet();
2134 const Int_t nMcms = AliTRDgeometry::MCMmax();
2135 const Int_t nChs = AliTRDgeometry::ADCmax();
2136
2137 // gain factors are per MCM
2138 // allocate the registers accordingly
2139 for (Int_t ch = 0; ch < nChs; ++ch) {
2140 AliTRDtrapConfig::TrapReg_t regFGAN = (AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kFGA0 + ch);
2141 AliTRDtrapConfig::TrapReg_t regFGFN = (AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kFGF0 + ch);
2142 fTrapConfig->SetTrapRegAlloc(regFGAN, AliTRDtrapConfig::kAllocByMCM);
2143 fTrapConfig->SetTrapRegAlloc(regFGFN, AliTRDtrapConfig::kAllocByMCM);
2144 }
2145
2146 for (Int_t iDet = 0; iDet < nDets; ++iDet) {
2147 AliTRDCalOnlineGainTableROC *gainTbl = GetOnlineGainTableROC(iDet);
2148 if (gainTbl) {
2149 const Int_t nRobs = AliTRDgeometry::GetStack(iDet) == 2 ?
2150 AliTRDgeometry::ROBmaxC0() : AliTRDgeometry::ROBmaxC1();
2151 for (Int_t rob = 0; rob < nRobs; ++rob) {
2152 for (Int_t mcm = 0; mcm < nMcms; ++mcm) {
2153 AliTRDCalOnlineGainTableMCM *gainTblMCM = gainTbl->GetGainTableMCM(rob, mcm);
2154
2155 // set ADC reference voltage
2156 fTrapConfig->SetTrapReg(AliTRDtrapConfig::kADCDAC, gainTblMCM->GetAdcdac(), iDet, rob, mcm);
2157
2158 // set constants channel-wise
2159 for (Int_t ch = 0; ch < nChs; ++ch) {
2160 AliTRDtrapConfig::TrapReg_t regFGAN = (AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kFGA0 + ch);
2161 AliTRDtrapConfig::TrapReg_t regFGFN = (AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kFGF0 + ch);
2162 fTrapConfig->SetTrapReg(regFGAN, gainTblMCM->GetFGAN(ch), iDet, rob, mcm);
2163 fTrapConfig->SetTrapReg(regFGFN, gainTblMCM->GetFGFN(ch), iDet, rob, mcm);
2164 }
2165 }
2166 }
2167 }
2168 }
2169 }
2170
a9e22145 2171 return fTrapConfig;
2172 }
2173}
2174
2175
2176AliTRDtrapConfig* AliTRDcalibDB::LoadTrapConfig(const TString &name, const TString &version)
2177{
2178 // try to load the specified configuration from the OCDB
2179 // if it fails, or it does not exist, return null
2180
2181 AliInfo(Form("looking for TRAPconfig \"%s.%s\"", name.Data(), version.Data()));
2182
2183 const AliTRDCalTrapConfig *caltrap = dynamic_cast<const AliTRDCalTrapConfig*> (GetCachedCDBObject(kIDTrapConfig));
2184
2185 if (caltrap) {
2186 TString configName(name);
2187 configName.Append(".");
2188 configName.Append(version);
2189 fTrapConfig = caltrap->Get(configName);
2190 }
2191 else {
2192 fTrapConfig = 0x0;
2193 AliError("No TRAPconfig entry found!");
2194 }
2195
2196 return fTrapConfig;
2197}