AliTPCclusterInof is added to the cluster only as option
[u/mrichter/AliRoot.git] / TPC / AliTPCcalibDB.cxx
CommitLineData
c5bbaa2c 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
17///////////////////////////////////////////////////////////////////////////////
18// //
19// Class providing the calibration parameters by accessing the CDB //
20// //
21// Request an instance with AliTPCcalibDB::Instance() //
22// If a new event is processed set the event number with SetRun //
23// Then request the calibration data //
24// //
25///////////////////////////////////////////////////////////////////////////////
26
27
28#include <AliCDBManager.h>
29#include <AliCDBStorage.h>
30#include <AliCDBEntry.h>
31#include <AliLog.h>
32
33#include "AliTPCcalibDB.h"
34
35#include "AliTPCCalROC.h"
36#include "AliTPCCalPad.h"
37#include "AliTPCCalDet.h"
54472e4f 38#include "AliTPCSensorTempArray.h"
86df2b3a 39//
40//
41
42#include <iostream>
43#include <fstream>
44#include "TFile.h"
45#include "TKey.h"
46
47#include "TObjArray.h"
48#include "TObjString.h"
49#include "TString.h"
50#include "AliTPCCalPad.h"
0fe7645c 51#include "AliTPCCalibPulser.h"
86df2b3a 52#include "AliTPCCalibPedestal.h"
53#include "AliTPCCalibCE.h"
54
55
56
57
c5bbaa2c 58
59ClassImp(AliTPCcalibDB)
60
61AliTPCcalibDB* AliTPCcalibDB::fgInstance = 0;
62Bool_t AliTPCcalibDB::fgTerminated = kFALSE;
63
64
65//_ singleton implementation __________________________________________________
66AliTPCcalibDB* AliTPCcalibDB::Instance()
67{
68 //
69 // Singleton implementation
70 // Returns an instance of this class, it is created if neccessary
71 //
72
73 if (fgTerminated != kFALSE)
74 return 0;
75
76 if (fgInstance == 0)
77 fgInstance = new AliTPCcalibDB();
78
79 return fgInstance;
80}
81
82void AliTPCcalibDB::Terminate()
83{
84 //
85 // Singleton implementation
86 // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
87 // This function can be called several times.
88 //
89
90 fgTerminated = kTRUE;
91
92 if (fgInstance != 0)
93 {
94 delete fgInstance;
95 fgInstance = 0;
96 }
97}
98
99//_____________________________________________________________________________
e4dce695 100AliTPCcalibDB::AliTPCcalibDB():
101 fRun(-1),
481f877b 102 fExB(0),
e4dce695 103 fPadGainFactor(0),
104 fPadTime0(0),
105 fPadPRFWidth(0),
106 fPadNoise(0),
107 fPedestals(0),
108 fTemperature(0),
109 fPressure(0),
481f877b 110 fParam(0),
111 fTrafo(0)
c5bbaa2c 112{
113 //
114 // constructor
115 //
54472e4f 116 //
c5bbaa2c 117 Update(); // temporary
118}
119
120//_____________________________________________________________________________
121AliTPCcalibDB::~AliTPCcalibDB()
122{
123 //
124 // destructor
125 //
68751c2c 126
127 // don't delete anything, CDB cache is active!
128 //if (fPadGainFactor) delete fPadGainFactor;
129 //if (fPadTime0) delete fPadTime0;
130 //if (fPadPRFWidth) delete fPadPRFWidth;
131 //if (fPadNoise) delete fPadNoise;
c5bbaa2c 132}
133
134
135//_____________________________________________________________________________
136AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
137{
138 //
139 // Retrieves an entry with path <cdbPath> from the CDB.
140 //
141 char chinfo[1000];
142
68751c2c 143 AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun);
c5bbaa2c 144 if (!entry)
145 {
146 sprintf(chinfo,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
147 AliError(chinfo);
148 return 0;
149 }
150 return entry;
151}
152
153
154//_____________________________________________________________________________
155void AliTPCcalibDB::SetRun(Long64_t run)
156{
157 //
158 // Sets current run number. Calibration data is read from the corresponding file.
159 //
160 if (fRun == run)
161 return;
162 fRun = run;
163 Update();
164}
165
166
167
168void AliTPCcalibDB::Update(){
169 //
170 AliCDBEntry * entry=0;
68751c2c 171
172 Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
173 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
174
c5bbaa2c 175 //
176 entry = GetCDBEntry("TPC/Calib/PadGainFactor");
177 if (entry){
68751c2c 178 //if (fPadGainFactor) delete fPadGainFactor;
c5bbaa2c 179 entry->SetOwner(kTRUE);
180 fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
181 }
182 //
183 entry = GetCDBEntry("TPC/Calib/PadTime0");
184 if (entry){
68751c2c 185 //if (fPadTime0) delete fPadTime0;
c5bbaa2c 186 entry->SetOwner(kTRUE);
187 fPadTime0 = (AliTPCCalPad*)entry->GetObject();
188 }
189 //
190 entry = GetCDBEntry("TPC/Calib/PadPRF");
191 if (entry){
68751c2c 192 //if (fPadPRFWidth) delete fPadPRFWidth;
c5bbaa2c 193 entry->SetOwner(kTRUE);
194 fPadPRFWidth = (AliTPCCalPad*)entry->GetObject();
195 }
196 //
197 entry = GetCDBEntry("TPC/Calib/PadNoise");
198 if (entry){
68751c2c 199 //if (fPadNoise) delete fPadNoise;
c5bbaa2c 200 entry->SetOwner(kTRUE);
201 fPadNoise = (AliTPCCalPad*)entry->GetObject();
202 }
8477f500 203
204 entry = GetCDBEntry("TPC/Calib/Pedestals");
205 if (entry){
206 //if (fPedestals) delete fPedestals;
207 entry->SetOwner(kTRUE);
208 fPedestals = (AliTPCCalPad*)entry->GetObject();
209 }
210
54472e4f 211 entry = GetCDBEntry("TPC/Calib/Temperature");
212 if (entry){
213 //if (fTemperature) delete fTemperature;
214 entry->SetOwner(kTRUE);
215 fTemperature = (AliTPCSensorTempArray*)entry->GetObject();
216 }
217
e4dce695 218 entry = GetCDBEntry("TPC/Calib/Pressure");
219 if (entry){
220 //if (fPressure) delete fPressure;
221 entry->SetOwner(kTRUE);
e7e39fb5 222 fPressure = (AliDCSSensorArray*)entry->GetObject();
e4dce695 223 }
224
8477f500 225 entry = GetCDBEntry("TPC/Calib/Parameters");
226 if (entry){
54472e4f 227 //if (fPadNoise) delete fPadNoise;
8477f500 228 entry->SetOwner(kTRUE);
a778f7e3 229 fParam = (AliTPCParam*)(entry->GetObject()->Clone());
8477f500 230 }
231
481f877b 232 entry = GetCDBEntry("TPC/Calib/ExB");
233 if (entry) {
234 entry->SetOwner(kTRUE);
235 fExB=dynamic_cast<AliTPCExB*>(entry->GetObject()->Clone());
236 }
237
238 delete fTrafo;
239 fTrafo=new AliTPCTransform();
8477f500 240
c5bbaa2c 241 //
68751c2c 242 AliCDBManager::Instance()->SetCacheFlag(cdbCache); // reset original CDB cache
243
c5bbaa2c 244}
e4dce695 245AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& org)
246{
247 //
248 // Copy constructor invalid -- singleton implementation
249 //
250 Error("copy constructor","invalid -- singleton implementation");
251}
252
253AliTPCcalibDB& AliTPCcalibDB::operator= (const AliTPCcalibDB& rhs)
254{
255//
256// Singleton implementation - no assignment operator
257//
258 Error("operator =", "assignment operator not implemented");
259 return *this;
260}
261
86df2b3a 262
263
264void AliTPCcalibDB::CreateObjectList(const Char_t *filename, TObjArray *calibObjects)
265{
266 if ( calibObjects == 0x0 ) return;
267 ifstream in;
268 in.open(filename);
269 if ( !in.is_open() ){
270 fprintf(stderr,"Error: cannot open list file '%s'", filename);
271 return;
272 }
273
274 AliTPCCalPad *calPad=0x0;
275
276 TString sFile;
277 sFile.ReadFile(in);
278 in.close();
279
280 TObjArray *arrFileLine = sFile.Tokenize("\n");
281
282 TIter nextLine(arrFileLine);
283
284 TObjString *sObjLine=0x0;
285 while ( sObjLine = (TObjString*)nextLine() ){
286 TString sLine(sObjLine->GetString());
287
288 TObjArray *arrNextCol = sLine.Tokenize("\t");
289
290 TObjString *sObjType = (TObjString*)(arrNextCol->At(0));
291 TObjString *sObjFileName = (TObjString*)(arrNextCol->At(1));
292
293 if ( !sObjType || ! sObjFileName ) continue;
294 TString sType(sObjType->GetString());
295 TString sFileName(sObjFileName->GetString());
296 printf("%s\t%s\n",sType.Data(),sFileName.Data());
297
298 TFile *fIn = TFile::Open(sFileName);
299 if ( !fIn ){
300 fprintf(stderr,"File not found: '%s'", sFileName.Data());
301 continue;
302 }
303
304 if ( sType == "CE" ){
305 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
306
307 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
308 calPad->SetNameTitle("CETmean","CETmean");
309 calibObjects->Add(calPad);
310
311 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
312 calPad->SetNameTitle("CEQmean","CEQmean");
313 calibObjects->Add(calPad);
314
315 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
316 calPad->SetNameTitle("CETrms","CETrms");
317 calibObjects->Add(calPad);
318
319 } else if ( sType == "Pulser") {
0fe7645c 320 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
86df2b3a 321
322 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
323 calPad->SetNameTitle("PulserTmean","PulserTmean");
324 calibObjects->Add(calPad);
325
326 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
327 calPad->SetNameTitle("PulserQmean","PulserQmean");
328 calibObjects->Add(calPad);
329
330 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
331 calPad->SetNameTitle("PulserTrms","PulserTrms");
332 calibObjects->Add(calPad);
333
334 } else if ( sType == "Pedestals") {
335 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
336
337 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
338 calPad->SetNameTitle("Pedestals","Pedestals");
339 calibObjects->Add(calPad);
340
341 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
342 calPad->SetNameTitle("Noise","Noise");
343 calibObjects->Add(calPad);
344
345 } else {
346 fprintf(stderr,"Undefined Type: '%s'",sType.Data());
347
348 }
349 delete fIn;
350 }
351}
352
353
354
355void AliTPCcalibDB::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad* outlierPad, Float_t ltmFraction) {
356 //
357 // Write a tree with all available information
358 // im mapFileName is speciefied, the Map information are also written to the tree
359 // pads specified in outlierPad are not used for calculating statistics
360 // - the same function as AliTPCCalPad::MakeTree -
361 //
362 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
363
364 TObjArray* mapIROCs = 0;
365 TObjArray* mapOROCs = 0;
366 TVectorF *mapIROCArray = 0;
367 TVectorF *mapOROCArray = 0;
368 Int_t mapEntries = 0;
369 TString* mapNames = 0;
370
371 if (mapFileName) {
372 TFile mapFile(mapFileName, "read");
373
374 TList* listOfROCs = mapFile.GetListOfKeys();
375 mapEntries = listOfROCs->GetEntries()/2;
376 mapIROCs = new TObjArray(mapEntries*2);
377 mapOROCs = new TObjArray(mapEntries*2);
378 mapIROCArray = new TVectorF[mapEntries];
379 mapOROCArray = new TVectorF[mapEntries];
380
381 mapNames = new TString[mapEntries];
382 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
383 TString ROCname(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
384 ROCname.Remove(ROCname.Length()-4, 4);
385 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((ROCname + "IROC").Data()), ivalue);
386 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((ROCname + "OROC").Data()), ivalue);
387 mapNames[ivalue].Append(ROCname);
388 }
389
390 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
391 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
392 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
393
394 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
395 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
396 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
397 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
398 }
399
400 } // if (mapFileName)
401
402 TTreeSRedirector cstream(fileName);
403 Int_t arrayEntries = array->GetEntries();
404
405 TString* names = new TString[arrayEntries];
406 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
407 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
408
409 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
410 //
411 // get statistic for given sector
412 //
413 TVectorF median(arrayEntries);
414 TVectorF mean(arrayEntries);
415 TVectorF rms(arrayEntries);
416 TVectorF ltm(arrayEntries);
417 TVectorF ltmrms(arrayEntries);
418 TVectorF medianWithOut(arrayEntries);
419 TVectorF meanWithOut(arrayEntries);
420 TVectorF rmsWithOut(arrayEntries);
421 TVectorF ltmWithOut(arrayEntries);
422 TVectorF ltmrmsWithOut(arrayEntries);
423
424 TVectorF *vectorArray = new TVectorF[arrayEntries];
425 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
426 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
427
428 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
429 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
430 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
431 AliTPCCalROC* outlierROC = 0;
432 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
433 if (calROC) {
434 median[ivalue] = calROC->GetMedian();
435 mean[ivalue] = calROC->GetMean();
436 rms[ivalue] = calROC->GetRMS();
437 Double_t ltmrmsValue = 0;
438 ltm[ivalue] = calROC->GetLTM(&ltmrmsValue, ltmFraction);
439 ltmrms[ivalue] = ltmrmsValue;
440 if (outlierROC) {
441 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
442 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
443 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
444 ltmrmsValue = 0;
445 ltmWithOut[ivalue] = calROC->GetLTM(&ltmrmsValue, ltmFraction, outlierROC);
446 ltmrmsWithOut[ivalue] = ltmrmsValue;
447 }
448 }
449 else {
450 median[ivalue] = 0.;
451 mean[ivalue] = 0.;
452 rms[ivalue] = 0.;
453 ltm[ivalue] = 0.;
454 ltmrms[ivalue] = 0.;
455 medianWithOut[ivalue] = 0.;
456 meanWithOut[ivalue] = 0.;
457 rmsWithOut[ivalue] = 0.;
458 ltmWithOut[ivalue] = 0.;
459 ltmrmsWithOut[ivalue] = 0.;
460 }
461 }
462
463 //
464 // fill vectors of variable per pad
465 //
466 TVectorF *posArray = new TVectorF[8];
467 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
468 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
469
470 Float_t posG[3] = {0};
471 Float_t posL[3] = {0};
472 Int_t ichannel = 0;
473 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
474 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
475 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
476 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
477 posArray[0][ichannel] = irow;
478 posArray[1][ichannel] = ipad;
479 posArray[2][ichannel] = posL[0];
480 posArray[3][ichannel] = posL[1];
481 posArray[4][ichannel] = posG[0];
482 posArray[5][ichannel] = posG[1];
483 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
484 posArray[7][ichannel] = ichannel;
485
486 // loop over array containing AliTPCCalPads
487 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
488 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
489 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
490 if (calROC)
491 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
492 else
493 (vectorArray[ivalue])[ichannel] = 0;
494 }
495 ichannel++;
496 }
497 }
498
499 cstream << "calPads" <<
500 "sector=" << isector;
501
502 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
503 cstream << "calPads" <<
504 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
505 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
506 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
507 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
508 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
509 if (outlierPad) {
510 cstream << "calPads" <<
511 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
512 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
513 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
514 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
515 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
516 }
517 }
518
519 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
520 cstream << "calPads" <<
521 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
522 }
523
524 if (mapFileName) {
525 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
526 if (isector < 36)
527 cstream << "calPads" <<
528 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
529 else
530 cstream << "calPads" <<
531 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
532 }
533 }
534
535 cstream << "calPads" <<
536 "row.=" << &posArray[0] <<
537 "pad.=" << &posArray[1] <<
538 "lx.=" << &posArray[2] <<
539 "ly.=" << &posArray[3] <<
540 "gx.=" << &posArray[4] <<
541 "gy.=" << &posArray[5] <<
542 "rpad.=" << &posArray[6] <<
543 "channel.=" << &posArray[7];
544
545 cstream << "calPads" <<
546 "\n";
547
548 delete[] posArray;
549 delete[] vectorArray;
550 }
551
552
553 delete[] names;
554 if (mapFileName) {
555 delete mapIROCs;
556 delete mapOROCs;
557 delete[] mapIROCArray;
558 delete[] mapOROCArray;
559 delete[] mapNames;
560 }
561}
562