1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // Class providing the calibration parameters by accessing the CDB //
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 ////
28 // Simulation - not yet
29 // Reconstruction - AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
31 // 1.) pad by pad calibration - AliTPCCalPad
34 // Simulation: AliTPCDigitizer::ExecFast - Multiply by gain
35 // Reconstruction : AliTPCclustererMI::Digits2Clusters - Divide by gain
38 // Simulation: AliTPCDigitizer::ExecFast
39 // Reconstruction: AliTPCclustererMI::FindClusters(AliTPCCalROC * noiseROC)
40 // Noise depending cut on clusters charge (n sigma)
42 // Simulation: Not used yet - To be impleneted - Rounding to the nearest integer
43 // Reconstruction: Used in AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
44 // if data taken without zero suppression
45 // Currently switch in fRecoParam->GetCalcPedestal();
48 // Simulation: applied in the AliTPC::MakeSector - adding offset
49 // Reconstruction: AliTPCTransform::Transform() - remove offset
50 // AliTPCTransform::Transform() - to be called
51 // in AliTPCtracker::Transform()
54 // 2.) Space points transformation:
56 // a.) General coordinate tranformation - AliTPCtransform (see $ALICE_ROOT/TPC/AliTPCtransform.cxx)
57 // Created on fly - use the other calibration components
58 // Unisochronity - (substract time0 - pad by pad)
59 // Drift velocity - Currently common drift velocity - functionality of AliTPCParam
61 // Simulation - Not used directly (the effects are applied one by one (see AliTPC::MakeSector)
63 // AliTPCclustererMI::AddCluster
64 // AliTPCtrackerMI::Transform
65 // b.) ExB effect calibration -
66 // classes (base class AliTPCExB, implementation- AliTPCExBExact.h AliTPCExBFirst.h)
67 // a.a) Simulation: applied in the AliTPC::MakeSector -
68 // calib->GetExB()->CorrectInverse(dxyz0,dxyz1);
69 // a.b) Reconstruction -
71 // in AliTPCtransform::Correct() - called calib->GetExB()->Correct(dxyz0,dxyz1)
73 // 3.) cluster error, shape and Q parameterization
77 ///////////////////////////////////////////////////////////////////////////////
83 #include <AliCDBManager.h>
84 #include <AliCDBEntry.h>
87 #include <AliMagWrapCheb.h>
89 #include "AliTPCcalibDB.h"
90 #include "AliTPCAltroMapping.h"
91 #include "AliTPCExB.h"
93 #include "AliTPCCalROC.h"
94 #include "AliTPCCalPad.h"
95 #include "AliTPCSensorTempArray.h"
96 #include "AliGRPObject.h"
97 #include "AliTPCTransform.h"
107 #include "TObjArray.h"
108 #include "TObjString.h"
110 #include "AliTPCCalPad.h"
111 #include "AliTPCCalibPulser.h"
112 #include "AliTPCCalibPedestal.h"
113 #include "AliTPCCalibCE.h"
114 #include "AliTPCExBFirst.h"
115 #include "AliTPCTempMap.h"
116 #include "AliTPCCalibVdrift.h"
121 ClassImp(AliTPCcalibDB)
123 AliTPCcalibDB* AliTPCcalibDB::fgInstance = 0;
124 Bool_t AliTPCcalibDB::fgTerminated = kFALSE;
125 TObjArray AliTPCcalibDB::fgExBArray; // array of ExB corrections
128 //_ singleton implementation __________________________________________________
129 AliTPCcalibDB* AliTPCcalibDB::Instance()
132 // Singleton implementation
133 // Returns an instance of this class, it is created if neccessary
136 if (fgTerminated != kFALSE)
140 fgInstance = new AliTPCcalibDB();
145 void AliTPCcalibDB::Terminate()
148 // Singleton implementation
149 // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
150 // This function can be called several times.
153 fgTerminated = kTRUE;
162 //_____________________________________________________________________________
163 AliTPCcalibDB::AliTPCcalibDB():
177 fGRPArray(100000), //! array of GRPs - per run - JUST for calibration studies
178 fGRPMaps(100000), //! array of GRPs - per run - JUST for calibration studies
179 fGoofieArray(100000), //! array of GOOFIE values -per run - Just for calibration studies
180 fTemperatureArray(100000), //! array of temperature sensors - per run - Just for calibration studies
181 fVdriftArray(100000), //! array of v drift interfaces
182 fRunList(100000) //! run list - indicates try to get the run param
189 Update(); // temporary
192 AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
206 fGRPArray(0), //! array of GRPs - per run - JUST for calibration studies
207 fGRPMaps(0), //! array of GRPs - per run - JUST for calibration studies
208 fGoofieArray(0), //! array of GOOFIE values -per run - Just for calibration studies
209 fTemperatureArray(0), //! array of temperature sensors - per run - Just for calibration studies
210 fVdriftArray(0), //! array of v drift interfaces
211 fRunList(0) //! run list - indicates try to get the run param
214 // Copy constructor invalid -- singleton implementation
216 Error("copy constructor","invalid -- singleton implementation");
219 AliTPCcalibDB& AliTPCcalibDB::operator= (const AliTPCcalibDB& )
222 // Singleton implementation - no assignment operator
224 Error("operator =", "assignment operator not implemented");
230 //_____________________________________________________________________________
231 AliTPCcalibDB::~AliTPCcalibDB()
237 // don't delete anything, CDB cache is active!
238 //if (fPadGainFactor) delete fPadGainFactor;
239 //if (fPadTime0) delete fPadTime0;
240 //if (fPadNoise) delete fPadNoise;
244 //_____________________________________________________________________________
245 AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
248 // Retrieves an entry with path <cdbPath> from the CDB.
252 AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun);
255 sprintf(chinfo,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
263 //_____________________________________________________________________________
264 void AliTPCcalibDB::SetRun(Long64_t run)
267 // Sets current run number. Calibration data is read from the corresponding file.
277 void AliTPCcalibDB::Update(){
279 AliCDBEntry * entry=0;
281 Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
282 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
285 entry = GetCDBEntry("TPC/Calib/PadGainFactor");
287 //if (fPadGainFactor) delete fPadGainFactor;
288 entry->SetOwner(kTRUE);
289 fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
292 entry = GetCDBEntry("TPC/Calib/GainFactorDedx");
294 entry->SetOwner(kTRUE);
295 fDedxGainFactor = (AliTPCCalPad*)entry->GetObject();
298 entry = GetCDBEntry("TPC/Calib/PadTime0");
300 //if (fPadTime0) delete fPadTime0;
301 entry->SetOwner(kTRUE);
302 fPadTime0 = (AliTPCCalPad*)entry->GetObject();
306 entry = GetCDBEntry("TPC/Calib/PadNoise");
308 //if (fPadNoise) delete fPadNoise;
309 entry->SetOwner(kTRUE);
310 fPadNoise = (AliTPCCalPad*)entry->GetObject();
313 entry = GetCDBEntry("TPC/Calib/Pedestals");
315 //if (fPedestals) delete fPedestals;
316 entry->SetOwner(kTRUE);
317 fPedestals = (AliTPCCalPad*)entry->GetObject();
320 entry = GetCDBEntry("TPC/Calib/Temperature");
322 //if (fTemperature) delete fTemperature;
323 entry->SetOwner(kTRUE);
324 fTemperature = (AliTPCSensorTempArray*)entry->GetObject();
327 entry = GetCDBEntry("TPC/Calib/Parameters");
329 //if (fPadNoise) delete fPadNoise;
330 entry->SetOwner(kTRUE);
331 fParam = (AliTPCParam*)(entry->GetObject()->Clone());
334 entry = GetCDBEntry("TPC/Calib/ClusterParam");
336 //if (fPadNoise) delete fPadNoise;
337 entry->SetOwner(kTRUE);
338 fClusterParam = (AliTPCClusterParam*)(entry->GetObject()->Clone());
341 entry = GetCDBEntry("TPC/Calib/Mapping");
343 //if (fPadNoise) delete fPadNoise;
344 entry->SetOwner(kTRUE);
345 TObjArray * array = dynamic_cast<TObjArray*>(entry->GetObject());
346 if (array && array->GetEntriesFast()==6){
347 fMapping = new AliTPCAltroMapping*[6];
348 for (Int_t i=0; i<6; i++){
349 fMapping[i] = dynamic_cast<AliTPCAltroMapping*>(array->At(i));
356 //entry = GetCDBEntry("TPC/Calib/ExB");
358 // entry->SetOwner(kTRUE);
359 // fExB=dynamic_cast<AliTPCExB*>(entry->GetObject()->Clone());
362 // ExB - calculate during initialization
364 fExB = GetExB(-5,kTRUE);
367 fTransform=new AliTPCTransform();
371 AliCDBManager::Instance()->SetCacheFlag(cdbCache); // reset original CDB cache
377 void AliTPCcalibDB::CreateObjectList(const Char_t *filename, TObjArray *calibObjects)
380 // Create calibration objects and read contents from OCDB
382 if ( calibObjects == 0x0 ) return;
385 if ( !in.is_open() ){
386 fprintf(stderr,"Error: cannot open list file '%s'", filename);
390 AliTPCCalPad *calPad=0x0;
396 TObjArray *arrFileLine = sFile.Tokenize("\n");
398 TIter nextLine(arrFileLine);
400 TObjString *sObjLine=0x0;
401 while ( (sObjLine = (TObjString*)nextLine()) ){
402 TString sLine(sObjLine->GetString());
404 TObjArray *arrNextCol = sLine.Tokenize("\t");
406 TObjString *sObjType = (TObjString*)(arrNextCol->At(0));
407 TObjString *sObjFileName = (TObjString*)(arrNextCol->At(1));
409 if ( !sObjType || ! sObjFileName ) continue;
410 TString sType(sObjType->GetString());
411 TString sFileName(sObjFileName->GetString());
412 printf("%s\t%s\n",sType.Data(),sFileName.Data());
414 TFile *fIn = TFile::Open(sFileName);
416 fprintf(stderr,"File not found: '%s'", sFileName.Data());
420 if ( sType == "CE" ){
421 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
423 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
424 calPad->SetNameTitle("CETmean","CETmean");
425 calibObjects->Add(calPad);
427 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
428 calPad->SetNameTitle("CEQmean","CEQmean");
429 calibObjects->Add(calPad);
431 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
432 calPad->SetNameTitle("CETrms","CETrms");
433 calibObjects->Add(calPad);
435 } else if ( sType == "Pulser") {
436 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
438 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
439 calPad->SetNameTitle("PulserTmean","PulserTmean");
440 calibObjects->Add(calPad);
442 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
443 calPad->SetNameTitle("PulserQmean","PulserQmean");
444 calibObjects->Add(calPad);
446 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
447 calPad->SetNameTitle("PulserTrms","PulserTrms");
448 calibObjects->Add(calPad);
450 } else if ( sType == "Pedestals") {
451 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
453 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
454 calPad->SetNameTitle("Pedestals","Pedestals");
455 calibObjects->Add(calPad);
457 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
458 calPad->SetNameTitle("Noise","Noise");
459 calibObjects->Add(calPad);
462 fprintf(stderr,"Undefined Type: '%s'",sType.Data());
471 void AliTPCcalibDB::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad* outlierPad, Float_t ltmFraction) {
473 // Write a tree with all available information
474 // if mapFileName is specified, the Map information are also written to the tree
475 // pads specified in outlierPad are not used for calculating statistics
476 // - the same function as AliTPCCalPad::MakeTree -
478 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
480 TObjArray* mapIROCs = 0;
481 TObjArray* mapOROCs = 0;
482 TVectorF *mapIROCArray = 0;
483 TVectorF *mapOROCArray = 0;
484 Int_t mapEntries = 0;
485 TString* mapNames = 0;
488 TFile mapFile(mapFileName, "read");
490 TList* listOfROCs = mapFile.GetListOfKeys();
491 mapEntries = listOfROCs->GetEntries()/2;
492 mapIROCs = new TObjArray(mapEntries*2);
493 mapOROCs = new TObjArray(mapEntries*2);
494 mapIROCArray = new TVectorF[mapEntries];
495 mapOROCArray = new TVectorF[mapEntries];
497 mapNames = new TString[mapEntries];
498 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
499 TString nameROC(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
500 nameROC.Remove(nameROC.Length()-4, 4);
501 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "IROC").Data()), ivalue);
502 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "OROC").Data()), ivalue);
503 mapNames[ivalue].Append(nameROC);
506 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
507 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
508 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
510 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
511 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
512 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
513 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
516 } // if (mapFileName)
518 TTreeSRedirector cstream(fileName);
519 Int_t arrayEntries = array->GetEntries();
521 TString* names = new TString[arrayEntries];
522 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
523 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
525 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
527 // get statistic for given sector
529 TVectorF median(arrayEntries);
530 TVectorF mean(arrayEntries);
531 TVectorF rms(arrayEntries);
532 TVectorF ltm(arrayEntries);
533 TVectorF ltmrms(arrayEntries);
534 TVectorF medianWithOut(arrayEntries);
535 TVectorF meanWithOut(arrayEntries);
536 TVectorF rmsWithOut(arrayEntries);
537 TVectorF ltmWithOut(arrayEntries);
538 TVectorF ltmrmsWithOut(arrayEntries);
540 TVectorF *vectorArray = new TVectorF[arrayEntries];
541 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
542 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
544 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
545 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
546 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
547 AliTPCCalROC* outlierROC = 0;
548 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
550 median[ivalue] = calROC->GetMedian();
551 mean[ivalue] = calROC->GetMean();
552 rms[ivalue] = calROC->GetRMS();
553 Double_t ltmrmsValue = 0;
554 ltm[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction);
555 ltmrms[ivalue] = ltmrmsValue;
557 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
558 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
559 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
561 ltmWithOut[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction, outlierROC);
562 ltmrmsWithOut[ivalue] = ltmrmsValue;
571 medianWithOut[ivalue] = 0.;
572 meanWithOut[ivalue] = 0.;
573 rmsWithOut[ivalue] = 0.;
574 ltmWithOut[ivalue] = 0.;
575 ltmrmsWithOut[ivalue] = 0.;
580 // fill vectors of variable per pad
582 TVectorF *posArray = new TVectorF[8];
583 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
584 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
586 Float_t posG[3] = {0};
587 Float_t posL[3] = {0};
589 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
590 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
591 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
592 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
593 posArray[0][ichannel] = irow;
594 posArray[1][ichannel] = ipad;
595 posArray[2][ichannel] = posL[0];
596 posArray[3][ichannel] = posL[1];
597 posArray[4][ichannel] = posG[0];
598 posArray[5][ichannel] = posG[1];
599 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
600 posArray[7][ichannel] = ichannel;
602 // loop over array containing AliTPCCalPads
603 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
604 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
605 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
607 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
609 (vectorArray[ivalue])[ichannel] = 0;
615 cstream << "calPads" <<
616 "sector=" << isector;
618 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
619 cstream << "calPads" <<
620 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
621 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
622 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
623 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
624 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
626 cstream << "calPads" <<
627 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
628 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
629 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
630 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
631 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
635 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
636 cstream << "calPads" <<
637 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
641 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
643 cstream << "calPads" <<
644 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
646 cstream << "calPads" <<
647 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
651 cstream << "calPads" <<
652 "row.=" << &posArray[0] <<
653 "pad.=" << &posArray[1] <<
654 "lx.=" << &posArray[2] <<
655 "ly.=" << &posArray[3] <<
656 "gx.=" << &posArray[4] <<
657 "gy.=" << &posArray[5] <<
658 "rpad.=" << &posArray[6] <<
659 "channel.=" << &posArray[7];
661 cstream << "calPads" <<
665 delete[] vectorArray;
673 delete[] mapIROCArray;
674 delete[] mapOROCArray;
681 void AliTPCcalibDB::RegisterExB(Int_t index, Float_t bz, Bool_t bdelete){
683 // Register static ExB correction map
684 // index - registration index - used for visualization
685 // bz - bz field in kGaus
687 Float_t factor = bz/(-5.); // default b filed in Cheb with minus sign
689 AliMagF* bmap = new AliMagWrapCheb("MapsExB","MapsExB", 2, factor, 10., AliMagWrapCheb::k5kG,kTRUE,"$(ALICE_ROOT)/data/maps/mfchebKGI_sym.root");
691 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
692 AliTPCExB::SetInstance(exb);
697 AliTPCExB::RegisterField(index,bmap);
699 if (index>=fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
700 fgExBArray.AddAt(exb,index);
704 AliTPCExB* AliTPCcalibDB::GetExB(Float_t bz, Bool_t deleteB) {
706 // bz filed in KGaus not in tesla
707 // Get ExB correction map
708 // if doesn't exist - create it
710 Int_t index = TMath::Nint(5+bz);
711 if (index>fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
712 if (!fgExBArray.At(index)) AliTPCcalibDB::RegisterExB(index,bz,deleteB);
713 return (AliTPCExB*)fgExBArray.At(index);
717 void AliTPCcalibDB::SetExBField(Float_t bz){
719 // Set magnetic filed for ExB correction
721 fExB = GetExB(bz,kFALSE);
726 void AliTPCcalibDB::GetRunInformations( Int_t run){
728 // - > Don't use it for reconstruction - Only for Calibration studies
730 AliCDBEntry * entry = 0;
731 if (run>= fRunList.GetSize()){
732 fRunList.Set(run*2+1);
733 fGRPArray.Expand(run*2+1);
734 fGRPMaps.Expand(run*2+1);
735 fGoofieArray.Expand(run*2+1);
736 fTemperatureArray.Expand(run*2+1);
737 fVdriftArray.Expand(run*2+1);
739 if (fRunList[run]>0) return;
740 entry = AliCDBManager::Instance()->Get("GRP/GRP/Data",run);
742 AliGRPObject * grpRun = dynamic_cast<AliGRPObject*>(entry->GetObject());
744 TMap* map = dynamic_cast<TMap*>(entry->GetObject());
746 grpRun = new AliGRPObject;
747 grpRun->ReadValuesFromMap(map);
748 fGRPMaps.AddAt(map,run);
751 fGRPArray.AddAt(grpRun,run);
753 entry = AliCDBManager::Instance()->Get("TPC/Calib/Goofie",run);
754 if (entry) fGoofieArray.AddAt(entry->GetObject(),run);
755 entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
756 if (entry) fTemperatureArray.AddAt(entry->GetObject(),run);
757 fRunList[run]=1; // sign as used
759 AliDCSSensor * press = GetPressureSensor(run);
760 AliTPCSensorTempArray * temp = GetTemperatureSensor(run);
762 AliTPCCalibVdrift * vdrift = new AliTPCCalibVdrift(temp, press,0);
763 fVdriftArray.AddAt(vdrift,run);
768 Float_t AliTPCcalibDB::GetGain(Int_t sector, Int_t row, Int_t pad){
771 AliTPCCalPad *calPad = Instance()->fDedxGainFactor;;
772 if (!calPad) return 0;
773 return calPad->GetCalROC(sector)->GetValue(row,pad);
777 AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
779 // Get GRP object for given run
781 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).At(run));
783 Instance()->GetRunInformations(run);
784 grpRun = dynamic_cast<AliGRPObject *>(Instance()->fGRPArray.At(run));
785 if (!grpRun) return 0;
790 TMap * AliTPCcalibDB::GetGRPMap(Int_t run){
794 TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).At(run));
796 Instance()->GetRunInformations(run);
797 grpRun = dynamic_cast<TMap *>(Instance()->fGRPMaps.At(run));
798 if (!grpRun) return 0;
804 AliDCSSensor * AliTPCcalibDB::GetPressureSensor(Int_t run, Int_t type){
806 // Get Pressure sensor
809 // First try to get if trom map - if existing (Old format of data storing)
811 TMap *map = GetGRPMap(run);
813 AliDCSSensor * sensor = 0;
815 if (type==0) osensor = ((*map)("fCavernPressure"));
816 if (type==1) osensor = ((*map)("fP2Pressure"));
817 sensor =dynamic_cast<AliDCSSensor *>(osensor);
818 if (sensor) return sensor;
821 // If not map try to get it from the GRPObject
823 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
825 GetRunInformations(run);
826 grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
827 if (!grpRun) return 0;
829 AliDCSSensor * sensor = grpRun->GetCavernAtmosPressure();
830 if (type==1) sensor = grpRun->GetSurfaceAtmosPressure();
834 AliTPCSensorTempArray * AliTPCcalibDB::GetTemperatureSensor(Int_t run){
836 // Get temperature sensor array
838 AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
840 GetRunInformations(run);
841 tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
846 AliDCSSensorArray * AliTPCcalibDB::GetGoofieSensors(Int_t run){
848 // Get temperature sensor array
850 AliDCSSensorArray * goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
852 GetRunInformations(run);
853 goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
858 AliTPCCalibVdrift * AliTPCcalibDB::GetVdrift(Int_t run){
860 // Get the interface to the the vdrift
862 AliTPCCalibVdrift * vdrift = (AliTPCCalibVdrift*)fVdriftArray.At(run);
864 GetRunInformations(run);
865 vdrift= (AliTPCCalibVdrift*)fVdriftArray.At(run);
873 Float_t AliTPCcalibDB::GetPressure(Int_t timeStamp, Int_t run, Int_t type){
875 // GetPressure for given time stamp and runt
877 TTimeStamp stamp(timeStamp);
878 AliDCSSensor * sensor = Instance()->GetPressureSensor(run,type);
879 if (!sensor) return 0;
881 if (!sensor->GetFit()) return 0;
882 return sensor->GetValue(stamp);
885 Float_t AliTPCcalibDB::GetValueGoofie(Int_t timeStamp, Int_t run, Int_t type){
887 // GetPressure for given time stamp and runt
889 TTimeStamp stamp(timeStamp);
890 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(run);
891 if (!goofieArray) return 0;
892 AliDCSSensor *sensor = goofieArray->GetSensor(type);
893 return sensor->GetValue(stamp);
901 Bool_t AliTPCcalibDB::GetTemperatureFit(Int_t timeStamp, Int_t run, Int_t side,TVectorD& fit){
905 TTimeStamp tstamp(timeStamp);
906 AliTPCSensorTempArray* tempArray = Instance()->GetTemperatureSensor(run);
907 if (! tempArray) return kFALSE;
908 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
909 TLinearFitter * fitter = tempMap->GetLinearFitter(3,side,tstamp);
912 fitter->GetParameters(fit);
916 if (!fitter) return kFALSE;
920 Float_t AliTPCcalibDB::GetTemperature(Int_t timeStamp, Int_t run, Int_t side){
926 GetTemperatureFit(timeStamp,run,0,vec);
930 GetTemperatureFit(timeStamp,run,0,vec);
937 Double_t AliTPCcalibDB::GetPTRelative(UInt_t timeSec, Int_t run, Int_t side){
940 // time - absolute time
942 // side - 0 - A side 1-C side
943 AliTPCCalibVdrift * vdrift = Instance()->GetVdrift(run);
944 if (!vdrift) return 0;
945 return vdrift->GetPTRelative(timeSec,side);
949 void AliTPCcalibDB::ProcessEnv(const char * runList){
951 // Example test function - how to use the environment variables
952 // runList - ascii file with run numbers
953 // output - dcsTime.root file with tree
958 TTreeSRedirector *pcstream = new TTreeSRedirector("dcsTime.root");
961 if (irun==0) continue;
962 printf("Processing run %d\n",irun);
963 AliDCSSensor * sensorPressure = AliTPCcalibDB::Instance()->GetPressureSensor(irun);
964 if (!sensorPressure) continue;
965 AliTPCSensorTempArray * tempArray = AliTPCcalibDB::Instance()->GetTemperatureSensor(irun);
966 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
967 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(irun);
969 Int_t startTime = sensorPressure->GetStartTime();
970 Int_t endTime = sensorPressure->GetEndTime();
971 Int_t dtime = TMath::Max((endTime-startTime)/20,10*60);
972 for (Int_t itime=startTime; itime<endTime; itime+=dtime){
974 TTimeStamp tstamp(itime);
975 Float_t valuePressure = sensorPressure->GetValue(tstamp);
977 TLinearFitter * fitter = 0;
978 TVectorD vecTemp[10];
979 if (itime<tempArray->GetStartTime().GetSec() || itime>tempArray->GetEndTime().GetSec()){
981 for (Int_t itype=0; itype<5; itype++)
982 for (Int_t iside=0; iside<2; iside++){
983 fitter= tempMap->GetLinearFitter(itype,iside,tstamp);
984 if (!fitter) continue;
985 fitter->Eval(); fitter->GetParameters(vecTemp[itype+iside*5]);
990 TVectorD vecGoofie, vecEntries, vecMean, vecMedian,vecRMS;
992 vecGoofie.ResizeTo(goofieArray->NumSensors());
993 ProcessGoofie(goofieArray, vecEntries ,vecMedian, vecMean, vecRMS);
995 for (Int_t isensor=0; isensor<goofieArray->NumSensors();isensor++){
996 AliDCSSensor *gsensor = goofieArray->GetSensor(isensor);
998 vecGoofie[isensor] = gsensor->GetValue(tstamp);
1004 //tempMap->GetLinearFitter(0,0,itime);
1005 (*pcstream)<<"dcs"<<
1008 "goofie.="<<&vecGoofie<<
1009 "goofieE.="<<&vecEntries<<
1010 "goofieMean.="<<&vecMean<<
1011 "goofieMedian.="<<&vecMedian<<
1012 "goofieRMS.="<<&vecRMS<<
1013 "press="<<valuePressure<<
1014 "temp00.="<<&vecTemp[0]<<
1015 "temp10.="<<&vecTemp[1]<<
1016 "temp20.="<<&vecTemp[2]<<
1017 "temp30.="<<&vecTemp[3]<<
1018 "temp40.="<<&vecTemp[4]<<
1019 "temp01.="<<&vecTemp[5]<<
1020 "temp11.="<<&vecTemp[6]<<
1021 "temp21.="<<&vecTemp[7]<<
1022 "temp31.="<<&vecTemp[8]<<
1023 "temp41.="<<&vecTemp[9]<<
1031 void AliTPCcalibDB::ProcessGoofie( AliDCSSensorArray* goofieArray, TVectorD & vecEntries, TVectorD & vecMedian, TVectorD &vecMean, TVectorD &vecRMS){
1034 1 TPC_ANODE_I_A00_STAT
1036 3 TPC_DVM_DriftVelocity
1041 8 TPC_DVM_NumberOfSparks
1042 9 TPC_DVM_PeakAreaFar
1043 10 TPC_DVM_PeakAreaNear
1044 11 TPC_DVM_PeakPosFar
1045 12 TPC_DVM_PeakPosNear
1048 15 TPC_DVM_T1_Over_P
1049 16 TPC_DVM_T2_Over_P
1051 18 TPC_DVM_TemperatureS1
1055 // TVectorD vecMedian; TVectorD vecEntries; TVectorD vecMean; TVectorD vecRMS;
1056 Double_t kEpsilon=0.0000000001;
1057 Double_t kBig=100000000000.;
1058 Int_t nsensors = goofieArray->NumSensors();
1059 vecEntries.ResizeTo(nsensors);
1060 vecMedian.ResizeTo(nsensors);
1061 vecMean.ResizeTo(nsensors);
1062 vecRMS.ResizeTo(nsensors);
1064 for (Int_t isensor=0; isensor<goofieArray->NumSensors();isensor++){
1065 AliDCSSensor *gsensor = goofieArray->GetSensor(isensor);
1066 if (gsensor && gsensor->GetGraph()){
1067 Int_t npoints = gsensor->GetGraph()->GetN();
1069 values.ResizeTo(npoints);
1071 for (Int_t ipoint=0; ipoint<npoints; ipoint++){
1072 if (TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])>kEpsilon &&
1073 TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])<kBig ){
1074 values[nused]=gsensor->GetGraph()->GetY()[ipoint];
1079 vecEntries[isensor]= nused;
1081 vecMedian[isensor] = TMath::Median(nused,values.GetMatrixArray());
1082 vecMean[isensor] = TMath::Mean(nused,values.GetMatrixArray());
1083 vecRMS[isensor] = TMath::RMS(nused,values.GetMatrixArray());