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