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>
88 #include <AliSplineFit.h>
89 #include <AliCTPTimeParams.h>
91 #include "AliTPCcalibDB.h"
92 #include "AliTPCdataQA.h"
93 #include "AliTPCcalibDButil.h"
94 #include "AliTPCAltroMapping.h"
95 #include "AliTPCExB.h"
97 #include "AliTPCCalROC.h"
98 #include "AliTPCCalPad.h"
99 #include "AliTPCSensorTempArray.h"
100 #include "AliGRPObject.h"
101 #include "AliTPCTransform.h"
110 #include "TGraphErrors.h"
112 #include "TObjArray.h"
113 #include "TObjString.h"
115 #include "TDirectory.h"
116 #include "AliTPCCalPad.h"
117 #include "AliTPCCalibPulser.h"
118 #include "AliTPCCalibPedestal.h"
119 #include "AliTPCCalibCE.h"
120 #include "AliTPCExBFirst.h"
121 #include "AliTPCTempMap.h"
122 #include "AliTPCCalibVdrift.h"
123 #include "AliTPCCalibRaw.h"
124 #include "AliTPCParam.h"
126 #include "AliTPCPreprocessorOnline.h"
129 ClassImp(AliTPCcalibDB)
131 AliTPCcalibDB* AliTPCcalibDB::fgInstance = 0;
132 Bool_t AliTPCcalibDB::fgTerminated = kFALSE;
133 TObjArray AliTPCcalibDB::fgExBArray; // array of ExB corrections
136 //_ singleton implementation __________________________________________________
137 AliTPCcalibDB* AliTPCcalibDB::Instance()
140 // Singleton implementation
141 // Returns an instance of this class, it is created if neccessary
144 if (fgTerminated != kFALSE)
148 fgInstance = new AliTPCcalibDB();
153 void AliTPCcalibDB::Terminate()
156 // Singleton implementation
157 // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
158 // This function can be called several times.
161 fgTerminated = kTRUE;
170 //_____________________________________________________________________________
171 AliTPCcalibDB::AliTPCcalibDB():
192 fTimeGainSplinesArray(100000),
193 fGRPArray(100000), //! array of GRPs - per run - JUST for calibration studies
194 fGRPMaps(100000), //! array of GRPs - per run - JUST for calibration studies
195 fGoofieArray(100000), //! array of GOOFIE values -per run - Just for calibration studies
196 fVoltageArray(100000),
197 fTemperatureArray(100000), //! array of temperature sensors - per run - Just for calibration studies
198 fVdriftArray(100000), //! array of v drift interfaces
199 fDriftCorrectionArray(100000), //! array of drift correction
200 fRunList(100000), //! run list - indicates try to get the run param
208 Update(); // temporary
211 AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
232 fTimeGainSplinesArray(100000),
233 fGRPArray(0), //! array of GRPs - per run - JUST for calibration studies
234 fGRPMaps(0), //! array of GRPs - per run - JUST for calibration studies
235 fGoofieArray(0), //! array of GOOFIE values -per run - Just for calibration studies
237 fTemperatureArray(0), //! array of temperature sensors - per run - Just for calibration studies
238 fVdriftArray(0), //! array of v drift interfaces
239 fDriftCorrectionArray(0), //! array of v drift interfaces
240 fRunList(0), //! run list - indicates try to get the run param
245 // Copy constructor invalid -- singleton implementation
247 Error("copy constructor","invalid -- singleton implementation");
250 AliTPCcalibDB& AliTPCcalibDB::operator= (const AliTPCcalibDB& )
253 // Singleton implementation - no assignment operator
255 Error("operator =", "assignment operator not implemented");
261 //_____________________________________________________________________________
262 AliTPCcalibDB::~AliTPCcalibDB()
271 //_____________________________________________________________________________
272 AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
275 // Retrieves an entry with path <cdbPath> from the CDB.
279 AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun);
282 sprintf(chinfo,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
290 //_____________________________________________________________________________
291 void AliTPCcalibDB::SetRun(Long64_t run)
294 // Sets current run number. Calibration data is read from the corresponding file.
304 void AliTPCcalibDB::Update(){
306 AliCDBEntry * entry=0;
307 Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
308 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
309 fDButil = new AliTPCcalibDButil;
311 entry = GetCDBEntry("TPC/Calib/PadGainFactor");
313 //if (fPadGainFactor) delete fPadGainFactor;
314 entry->SetOwner(kTRUE);
315 fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
317 AliFatal("TPC - Missing calibration entry")
320 entry = GetCDBEntry("TPC/Calib/TimeGain");
322 //if (fTimeGainSplines) delete fTimeGainSplines;
323 entry->SetOwner(kTRUE);
324 fTimeGainSplines = (TObjArray*)entry->GetObject();
326 AliFatal("TPC - Missing calibration entry")
329 entry = GetCDBEntry("TPC/Calib/GainFactorDedx");
331 entry->SetOwner(kTRUE);
332 fDedxGainFactor = (AliTPCCalPad*)entry->GetObject();
334 AliFatal("TPC - Missing calibration entry")
337 entry = GetCDBEntry("TPC/Calib/PadTime0");
339 //if (fPadTime0) delete fPadTime0;
340 entry->SetOwner(kTRUE);
341 fPadTime0 = (AliTPCCalPad*)entry->GetObject();
343 AliFatal("TPC - Missing calibration entry")
346 entry = GetCDBEntry("TPC/Calib/Distortion");
348 //if (fPadTime0) delete fPadTime0;
349 entry->SetOwner(kTRUE);
350 fDistortionMap =(TObjArray*)entry->GetObject();
352 //AliFatal("TPC - Missing calibration entry")
358 entry = GetCDBEntry("TPC/Calib/PadNoise");
360 //if (fPadNoise) delete fPadNoise;
361 entry->SetOwner(kTRUE);
362 fPadNoise = (AliTPCCalPad*)entry->GetObject();
364 AliFatal("TPC - Missing calibration entry")
367 entry = GetCDBEntry("TPC/Calib/Pedestals");
369 //if (fPedestals) delete fPedestals;
370 entry->SetOwner(kTRUE);
371 fPedestals = (AliTPCCalPad*)entry->GetObject();
374 entry = GetCDBEntry("TPC/Calib/Temperature");
376 //if (fTemperature) delete fTemperature;
377 entry->SetOwner(kTRUE);
378 fTemperature = (AliTPCSensorTempArray*)entry->GetObject();
381 entry = GetCDBEntry("TPC/Calib/Parameters");
383 //if (fPadNoise) delete fPadNoise;
384 entry->SetOwner(kTRUE);
385 fParam = (AliTPCParam*)(entry->GetObject()->Clone());
387 AliFatal("TPC - Missing calibration entry")
390 entry = GetCDBEntry("TPC/Calib/ClusterParam");
392 entry->SetOwner(kTRUE);
393 fClusterParam = (AliTPCClusterParam*)(entry->GetObject()->Clone());
395 AliFatal("TPC - Missing calibration entry")
398 //ALTRO configuration data
399 entry = GetCDBEntry("TPC/Calib/AltroConfig");
401 entry->SetOwner(kTRUE);
402 fALTROConfigData=(TObjArray*)(entry->GetObject());
404 AliFatal("TPC - Missing calibration entry")
407 //Calibration Pulser data
408 entry = GetCDBEntry("TPC/Calib/Pulser");
410 entry->SetOwner(kTRUE);
411 fPulserData=(TObjArray*)(entry->GetObject());
415 entry = GetCDBEntry("TPC/Calib/CE");
417 entry->SetOwner(kTRUE);
418 fCEData=(TObjArray*)(entry->GetObject());
420 //RAW calibration data
421 // entry = GetCDBEntry("TPC/Calib/Raw");
423 entry = GetCDBEntry("TPC/Calib/Mapping");
425 //if (fPadNoise) delete fPadNoise;
426 entry->SetOwner(kTRUE);
427 TObjArray * array = dynamic_cast<TObjArray*>(entry->GetObject());
428 if (array && array->GetEntriesFast()==6){
429 fMapping = new AliTPCAltroMapping*[6];
430 for (Int_t i=0; i<6; i++){
431 fMapping[i] = dynamic_cast<AliTPCAltroMapping*>(array->At(i));
436 //CTP calibration data
437 entry = GetCDBEntry("GRP/CTP/CTPtiming");
439 //entry->SetOwner(kTRUE);
440 fCTPTimeParams=dynamic_cast<AliCTPTimeParams*>(entry->GetObject());
442 AliFatal("TPC - Missing calibration entry")
446 fTransform=new AliTPCTransform();
447 fTransform->SetCurrentRun(AliCDBManager::Instance()->GetRun());
451 AliCDBManager::Instance()->SetCacheFlag(cdbCache); // reset original CDB cache
454 void AliTPCcalibDB::UpdateNonRec(){
456 // Update/Load the parameters which are important for QA studies
457 // and not used yet for the reconstruction
459 //RAW calibration data
460 AliCDBEntry * entry=0;
461 entry = GetCDBEntry("TPC/Calib/Raw");
463 entry->SetOwner(kTRUE);
464 TObjArray *arr=(TObjArray*)(entry->GetObject());
465 if (arr) fCalibRaw=(AliTPCCalibRaw*)arr->At(0);
467 //QA calibration data
468 entry = GetCDBEntry("TPC/Calib/QA");
470 entry->SetOwner(kTRUE);
471 fDataQA=dynamic_cast<AliTPCdataQA*>(entry->GetObject());
474 entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",fRun);
476 fVoltageArray.AddAt(entry->GetObject(),fRun);
483 void AliTPCcalibDB::CreateObjectList(const Char_t *filename, TObjArray *calibObjects)
486 // Create calibration objects and read contents from OCDB
488 if ( calibObjects == 0x0 ) return;
491 if ( !in.is_open() ){
492 fprintf(stderr,"Error: cannot open list file '%s'", filename);
496 AliTPCCalPad *calPad=0x0;
502 TObjArray *arrFileLine = sFile.Tokenize("\n");
504 TIter nextLine(arrFileLine);
506 TObjString *sObjLine=0x0;
507 while ( (sObjLine = (TObjString*)nextLine()) ){
508 TString sLine(sObjLine->GetString());
510 TObjArray *arrNextCol = sLine.Tokenize("\t");
512 TObjString *sObjType = (TObjString*)(arrNextCol->At(0));
513 TObjString *sObjFileName = (TObjString*)(arrNextCol->At(1));
515 if ( !sObjType || ! sObjFileName ) continue;
516 TString sType(sObjType->GetString());
517 TString sFileName(sObjFileName->GetString());
518 printf("%s\t%s\n",sType.Data(),sFileName.Data());
520 TFile *fIn = TFile::Open(sFileName);
522 fprintf(stderr,"File not found: '%s'", sFileName.Data());
526 if ( sType == "CE" ){
527 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
529 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
530 calPad->SetNameTitle("CETmean","CETmean");
531 calibObjects->Add(calPad);
533 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
534 calPad->SetNameTitle("CEQmean","CEQmean");
535 calibObjects->Add(calPad);
537 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
538 calPad->SetNameTitle("CETrms","CETrms");
539 calibObjects->Add(calPad);
541 } else if ( sType == "Pulser") {
542 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
544 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
545 calPad->SetNameTitle("PulserTmean","PulserTmean");
546 calibObjects->Add(calPad);
548 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
549 calPad->SetNameTitle("PulserQmean","PulserQmean");
550 calibObjects->Add(calPad);
552 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
553 calPad->SetNameTitle("PulserTrms","PulserTrms");
554 calibObjects->Add(calPad);
556 } else if ( sType == "Pedestals") {
557 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
559 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
560 calPad->SetNameTitle("Pedestals","Pedestals");
561 calibObjects->Add(calPad);
563 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
564 calPad->SetNameTitle("Noise","Noise");
565 calibObjects->Add(calPad);
568 fprintf(stderr,"Undefined Type: '%s'",sType.Data());
577 void AliTPCcalibDB::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad* outlierPad, Float_t ltmFraction) {
579 // Write a tree with all available information
580 // if mapFileName is specified, the Map information are also written to the tree
581 // pads specified in outlierPad are not used for calculating statistics
582 // - the same function as AliTPCCalPad::MakeTree -
584 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
586 TObjArray* mapIROCs = 0;
587 TObjArray* mapOROCs = 0;
588 TVectorF *mapIROCArray = 0;
589 TVectorF *mapOROCArray = 0;
590 Int_t mapEntries = 0;
591 TString* mapNames = 0;
594 TFile mapFile(mapFileName, "read");
596 TList* listOfROCs = mapFile.GetListOfKeys();
597 mapEntries = listOfROCs->GetEntries()/2;
598 mapIROCs = new TObjArray(mapEntries*2);
599 mapOROCs = new TObjArray(mapEntries*2);
600 mapIROCArray = new TVectorF[mapEntries];
601 mapOROCArray = new TVectorF[mapEntries];
603 mapNames = new TString[mapEntries];
604 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
605 TString nameROC(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
606 nameROC.Remove(nameROC.Length()-4, 4);
607 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "IROC").Data()), ivalue);
608 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "OROC").Data()), ivalue);
609 mapNames[ivalue].Append(nameROC);
612 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
613 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
614 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
616 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
617 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
618 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
619 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
622 } // if (mapFileName)
624 TTreeSRedirector cstream(fileName);
625 Int_t arrayEntries = array->GetEntries();
627 TString* names = new TString[arrayEntries];
628 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
629 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
631 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
633 // get statistic for given sector
635 TVectorF median(arrayEntries);
636 TVectorF mean(arrayEntries);
637 TVectorF rms(arrayEntries);
638 TVectorF ltm(arrayEntries);
639 TVectorF ltmrms(arrayEntries);
640 TVectorF medianWithOut(arrayEntries);
641 TVectorF meanWithOut(arrayEntries);
642 TVectorF rmsWithOut(arrayEntries);
643 TVectorF ltmWithOut(arrayEntries);
644 TVectorF ltmrmsWithOut(arrayEntries);
646 TVectorF *vectorArray = new TVectorF[arrayEntries];
647 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
648 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
650 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
651 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
652 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
653 AliTPCCalROC* outlierROC = 0;
654 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
656 median[ivalue] = calROC->GetMedian();
657 mean[ivalue] = calROC->GetMean();
658 rms[ivalue] = calROC->GetRMS();
659 Double_t ltmrmsValue = 0;
660 ltm[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction);
661 ltmrms[ivalue] = ltmrmsValue;
663 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
664 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
665 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
667 ltmWithOut[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction, outlierROC);
668 ltmrmsWithOut[ivalue] = ltmrmsValue;
677 medianWithOut[ivalue] = 0.;
678 meanWithOut[ivalue] = 0.;
679 rmsWithOut[ivalue] = 0.;
680 ltmWithOut[ivalue] = 0.;
681 ltmrmsWithOut[ivalue] = 0.;
686 // fill vectors of variable per pad
688 TVectorF *posArray = new TVectorF[8];
689 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
690 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
692 Float_t posG[3] = {0};
693 Float_t posL[3] = {0};
695 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
696 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
697 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
698 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
699 posArray[0][ichannel] = irow;
700 posArray[1][ichannel] = ipad;
701 posArray[2][ichannel] = posL[0];
702 posArray[3][ichannel] = posL[1];
703 posArray[4][ichannel] = posG[0];
704 posArray[5][ichannel] = posG[1];
705 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
706 posArray[7][ichannel] = ichannel;
708 // loop over array containing AliTPCCalPads
709 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
710 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
711 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
713 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
715 (vectorArray[ivalue])[ichannel] = 0;
721 cstream << "calPads" <<
722 "sector=" << isector;
724 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
725 cstream << "calPads" <<
726 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
727 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
728 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
729 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
730 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
732 cstream << "calPads" <<
733 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
734 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
735 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
736 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
737 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
741 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
742 cstream << "calPads" <<
743 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
747 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
749 cstream << "calPads" <<
750 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
752 cstream << "calPads" <<
753 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
757 cstream << "calPads" <<
758 "row.=" << &posArray[0] <<
759 "pad.=" << &posArray[1] <<
760 "lx.=" << &posArray[2] <<
761 "ly.=" << &posArray[3] <<
762 "gx.=" << &posArray[4] <<
763 "gy.=" << &posArray[5] <<
764 "rpad.=" << &posArray[6] <<
765 "channel.=" << &posArray[7];
767 cstream << "calPads" <<
771 delete[] vectorArray;
779 delete[] mapIROCArray;
780 delete[] mapOROCArray;
785 Int_t AliTPCcalibDB::GetRCUTriggerConfig() const
788 // return the RCU trigger configuration register
790 TMap *map=GetRCUconfig();
792 TVectorF *v=(TVectorF*)map->GetValue("TRGCONF_TRG_MODE");
794 for (Int_t i=0; i<v->GetNrows(); ++i){
795 Float_t newmode=v->GetMatrixArray()[i];
797 if (mode>-1&&newmode!=mode) AliWarning("Found different RCU trigger configurations!!!");
804 Bool_t AliTPCcalibDB::IsTrgL0()
807 // return if the FEE readout was triggered on L0
809 Int_t mode=GetRCUTriggerConfig();
810 if (mode<0) return kFALSE;
814 Bool_t AliTPCcalibDB::IsTrgL1()
817 // return if the FEE readout was triggered on L1
819 Int_t mode=GetRCUTriggerConfig();
820 if (mode<0) return kFALSE;
824 void AliTPCcalibDB::RegisterExB(Int_t index, Float_t bz, Bool_t bdelete){
826 // Register static ExB correction map
827 // index - registration index - used for visualization
828 // bz - bz field in kGaus
830 // Float_t factor = bz/(-5.); // default b filed in Cheb with minus sign
831 Float_t factor = bz/(5.); // default b filed in Cheb with minus sign
832 // was chenged in the Revision ???? (Ruben can you add here number)
834 AliMagF* bmap = new AliMagF("MapsExB","MapsExB", factor,TMath::Sign(1.f,factor),AliMagF::k5kG);
836 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
837 AliTPCExB::SetInstance(exb);
842 AliTPCExB::RegisterField(index,bmap);
844 if (index>=fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
845 fgExBArray.AddAt(exb,index);
849 AliTPCExB* AliTPCcalibDB::GetExB(Float_t bz, Bool_t deleteB) {
851 // bz filed in KGaus not in tesla
852 // Get ExB correction map
853 // if doesn't exist - create it
855 Int_t index = TMath::Nint(5+bz);
856 if (index>fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
857 if (!fgExBArray.At(index)) AliTPCcalibDB::RegisterExB(index,bz,deleteB);
858 return (AliTPCExB*)fgExBArray.At(index);
862 void AliTPCcalibDB::SetExBField(Float_t bz){
864 // Set magnetic filed for ExB correction
866 fExB = GetExB(bz,kFALSE);
869 void AliTPCcalibDB::SetExBField(const AliMagF* bmap){
871 // Set magnetic field for ExB correction
873 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
874 AliTPCExB::SetInstance(exb);
882 void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
884 // - > Don't use it for reconstruction - Only for Calibration studies
887 AliCDBEntry * entry = 0;
888 if (run>= fRunList.fN){
889 fRunList.Set(run*2+1);
890 fGRPArray.Expand(run*2+1);
891 fGRPMaps.Expand(run*2+1);
892 fGoofieArray.Expand(run*2+1);
893 fVoltageArray.Expand(run*2+1);
894 fTemperatureArray.Expand(run*2+1);
895 fVdriftArray.Expand(run*2+1);
896 fDriftCorrectionArray.Expand(run*2+1);
897 fTimeGainSplinesArray.Expand(run*2+1);
900 fALTROConfigData->Expand(run*2+1); // ALTRO configuration data
901 fPulserData->Expand(run*2+1); // Calibration Pulser data
902 fCEData->Expand(run*2+1); // CE data
903 if (!fTimeGainSplines) fTimeGainSplines = new TObjArray(run*2+1);
904 fTimeGainSplines->Expand(run*2+1); // Array of AliSplineFits: at 0 MIP position in
906 if (fRunList[run]>0 &&force==kFALSE) return;
908 fRunList[run]=1; // sign as used
911 entry = AliCDBManager::Instance()->Get("GRP/GRP/Data",run);
913 AliGRPObject * grpRun = dynamic_cast<AliGRPObject*>(entry->GetObject());
915 TMap* map = dynamic_cast<TMap*>(entry->GetObject());
917 //grpRun = new AliGRPObject;
918 //grpRun->ReadValuesFromMap(map);
919 grpRun = MakeGRPObjectFromMap(map);
921 fGRPMaps.AddAt(map,run);
924 fGRPArray.AddAt(grpRun,run);
926 entry = AliCDBManager::Instance()->Get("TPC/Calib/Goofie",run);
928 fGoofieArray.AddAt(entry->GetObject(),run);
933 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeGain",run);
935 fTimeGainSplinesArray.AddAt(entry->GetObject(),run);
937 AliFatal("TPC - Missing calibration entry TimeGain")
940 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeDrift",run);
942 fDriftCorrectionArray.AddAt(entry->GetObject(),run);
944 AliFatal("TPC - Missing calibration entry TimeDrift")
947 entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
949 fTemperatureArray.AddAt(entry->GetObject(),run);
951 //apply fDButil filters
953 fDButil->UpdateFromCalibDB();
954 if (fTemperature) fDButil->FilterTemperature(fTemperature);
956 AliDCSSensor * press = GetPressureSensor(run,0);
957 AliTPCSensorTempArray * temp = GetTemperatureSensor(run);
960 accept = fDButil->FilterTemperature(temp)>0.1;
963 const Double_t kMinP=950.;
964 const Double_t kMaxP=1050.;
965 const Double_t kMaxdP=10.;
966 const Double_t kSigmaCut=4.;
967 fDButil->FilterSensor(press,kMinP,kMaxP,kMaxdP,kSigmaCut);
968 if (press->GetFit()==0) accept=kFALSE;
970 if (press && temp &&accept){
971 AliTPCCalibVdrift * vdrift = new AliTPCCalibVdrift(temp, press,0);
972 fVdriftArray.AddAt(vdrift,run);
974 fDButil->FilterCE(120., 3., 4.,0);
975 fDButil->FilterTracks(run, 10.,0);
979 Float_t AliTPCcalibDB::GetGain(Int_t sector, Int_t row, Int_t pad){
982 AliTPCCalPad *calPad = Instance()->fDedxGainFactor;;
983 if (!calPad) return 0;
984 return calPad->GetCalROC(sector)->GetValue(row,pad);
987 AliSplineFit* AliTPCcalibDB::GetVdriftSplineFit(const char* name, Int_t run){
991 TObjArray *arr=GetTimeVdriftSplineRun(run);
993 return dynamic_cast<AliSplineFit*>(arr->FindObject(name));
996 AliSplineFit* AliTPCcalibDB::CreateVdriftSplineFit(const char* graphName, Int_t run){
998 // create spline fit from the drift time graph in TimeDrift
1000 TObjArray *arr=GetTimeVdriftSplineRun(run);
1002 TGraph *graph=dynamic_cast<TGraph*>(arr->FindObject(graphName));
1003 if (!graph) return 0;
1004 AliSplineFit *fit = new AliSplineFit();
1005 fit->SetGraph(graph);
1006 fit->SetMinPoints(graph->GetN()+1);
1007 fit->InitKnots(graph,2,0,0.001);
1012 AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
1014 // Get GRP object for given run
1016 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).At(run));
1018 Instance()->UpdateRunInformations(run);
1019 grpRun = dynamic_cast<AliGRPObject *>(Instance()->fGRPArray.At(run));
1020 if (!grpRun) return 0;
1025 TMap * AliTPCcalibDB::GetGRPMap(Int_t run){
1029 TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).At(run));
1031 Instance()->UpdateRunInformations(run);
1032 grpRun = dynamic_cast<TMap *>(Instance()->fGRPMaps.At(run));
1033 if (!grpRun) return 0;
1039 AliDCSSensor * AliTPCcalibDB::GetPressureSensor(Int_t run, Int_t type){
1041 // Get Pressure sensor
1043 // type = 0 - Cavern pressure
1044 // 1 - Suface pressure
1045 // First try to get if trom map - if existing (Old format of data storing)
1049 TMap *map = GetGRPMap(run);
1051 AliDCSSensor * sensor = 0;
1053 if (type==0) osensor = ((*map)("fCavernPressure"));
1054 if (type==1) osensor = ((*map)("fP2Pressure"));
1055 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1056 if (sensor) return sensor;
1059 // If not map try to get it from the GRPObject
1061 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
1063 UpdateRunInformations(run);
1064 grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
1065 if (!grpRun) return 0;
1067 AliDCSSensor * sensor = grpRun->GetCavernAtmosPressure();
1068 if (type==1) sensor = grpRun->GetSurfaceAtmosPressure();
1072 AliTPCSensorTempArray * AliTPCcalibDB::GetTemperatureSensor(Int_t run){
1074 // Get temperature sensor array
1076 AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
1078 UpdateRunInformations(run);
1079 tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
1085 TObjArray * AliTPCcalibDB::GetTimeGainSplinesRun(Int_t run){
1087 // Get temperature sensor array
1089 TObjArray * gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
1091 UpdateRunInformations(run);
1092 gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
1097 TObjArray * AliTPCcalibDB::GetTimeVdriftSplineRun(Int_t run){
1099 // Get drift spline array
1101 TObjArray * driftSplines = (TObjArray *)fDriftCorrectionArray.At(run);
1102 if (!driftSplines) {
1103 UpdateRunInformations(run);
1104 driftSplines = (TObjArray *)fDriftCorrectionArray.At(run);
1106 return driftSplines;
1109 AliDCSSensorArray * AliTPCcalibDB::GetVoltageSensors(Int_t run){
1111 // Get temperature sensor array
1113 AliDCSSensorArray * voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
1114 if (!voltageArray) {
1115 UpdateRunInformations(run);
1116 voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
1118 return voltageArray;
1121 AliDCSSensorArray * AliTPCcalibDB::GetGoofieSensors(Int_t run){
1123 // Get temperature sensor array
1125 AliDCSSensorArray * goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
1127 UpdateRunInformations(run);
1128 goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
1135 AliTPCCalibVdrift * AliTPCcalibDB::GetVdrift(Int_t run){
1137 // Get the interface to the the vdrift
1139 AliTPCCalibVdrift * vdrift = (AliTPCCalibVdrift*)fVdriftArray.At(run);
1141 UpdateRunInformations(run);
1142 vdrift= (AliTPCCalibVdrift*)fVdriftArray.At(run);
1147 Float_t AliTPCcalibDB::GetCEdriftTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
1150 // GetCE drift time information for 'sector'
1151 // sector 72 is the mean drift time of the A-Side
1152 // sector 73 is the mean drift time of the C-Side
1153 // it timestamp==-1 return mean value
1155 AliTPCcalibDB::Instance()->SetRun(run);
1156 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocTgraph(sector);
1157 if (!gr||sector<0||sector>73) {
1158 if (entries) *entries=0;
1162 if (timeStamp==-1.){
1165 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1167 gr->GetPoint(ipoint,x,y);
1168 if (x<timeStamp) continue;
1176 Float_t AliTPCcalibDB::GetCEchargeTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
1179 // GetCE mean charge for 'sector'
1180 // it timestamp==-1 return mean value
1182 AliTPCcalibDB::Instance()->SetRun(run);
1183 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocQgraph(sector);
1184 if (!gr||sector<0||sector>71) {
1185 if (entries) *entries=0;
1189 if (timeStamp==-1.){
1192 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1194 gr->GetPoint(ipoint,x,y);
1195 if (x<timeStamp) continue;
1203 Float_t AliTPCcalibDB::GetDCSSensorValue(AliDCSSensorArray *arr, Int_t timeStamp, const char * sensorName, Int_t sigDigits)
1206 // Get Value for a DCS sensor 'sensorName', run 'run' at time 'timeStamp'
1209 const TString sensorNameString(sensorName);
1210 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1211 if (!sensor) return val;
1212 //use the dcs graph if possible
1213 TGraph *gr=sensor->GetGraph();
1215 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1217 gr->GetPoint(ipoint,x,y);
1218 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1219 if (time<timeStamp) continue;
1223 //if val is still 0, test if if the requested time if within 5min of the first/last
1224 //data point. If this is the case return the firs/last entry
1225 //the timestamps might not be syncronised for all calibration types, sometimes a 'pre'
1226 //and 'pos' period is requested. Especially to the HV this is not the case!
1230 gr->GetPoint(0,x,y);
1231 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1232 if ((time-timeStamp)<5*60) val=y;
1237 gr->GetPoint(gr->GetN()-1,x,y);
1238 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1239 if ((timeStamp-time)<5*60) val=y;
1242 val=sensor->GetValue(timeStamp);
1245 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1250 Float_t AliTPCcalibDB::GetDCSSensorMeanValue(AliDCSSensorArray *arr, const char * sensorName, Int_t sigDigits)
1253 // Get mean Value for a DCS sensor 'sensorName' during run 'run'
1256 const TString sensorNameString(sensorName);
1257 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1258 if (!sensor) return val;
1260 //use dcs graph if it exists
1261 TGraph *gr=sensor->GetGraph();
1265 //if we don't have the dcs graph, try to get some meaningful information
1266 if (!sensor->GetFit()) return val;
1267 Int_t nKnots=sensor->GetFit()->GetKnots();
1268 Double_t tMid=(sensor->GetEndTime()-sensor->GetStartTime())/2.;
1269 for (Int_t iKnot=0;iKnot<nKnots;++iKnot){
1270 if (sensor->GetFit()->GetX()[iKnot]>tMid/3600.) break;
1271 val=(Float_t)sensor->GetFit()->GetY0()[iKnot];
1276 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1282 Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits) {
1284 // return the chamber HV for given run and time: 0-35 IROC, 36-72 OROC
1285 // if timeStamp==-1 return mean value
1288 TString sensorName="";
1289 TTimeStamp stamp(timeStamp);
1290 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1291 if (!voltageArray || (sector<0) || (sector>71)) return val;
1292 Char_t sideName='A';
1293 if ((sector/18)%2==1) sideName='C';
1296 sensorName=Form("TPC_ANODE_I_%c%02d_VMEAS",sideName,sector%18);
1299 sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,sector%18);
1302 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1304 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1308 Float_t AliTPCcalibDB::GetSkirtVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1311 // Get the skirt voltage for 'run' at 'timeStamp' and 'sector': 0-35 IROC, 36-72 OROC
1312 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1313 // if timeStamp==-1 return the mean value for the run
1316 TString sensorName="";
1317 TTimeStamp stamp(timeStamp);
1318 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1319 if (!voltageArray || (sector<0) || (sector>71)) return val;
1320 Char_t sideName='A';
1321 if ((sector/18)%2==1) sideName='C';
1322 sensorName=Form("TPC_SKIRT_%c_VMEAS",sideName);
1324 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1326 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1331 Float_t AliTPCcalibDB::GetCoverVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1334 // Get the cover voltage for run 'run' at time 'timeStamp'
1335 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1336 // if timeStamp==-1 return the mean value for the run
1339 TString sensorName="";
1340 TTimeStamp stamp(timeStamp);
1341 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1342 if (!voltageArray || (sector<0) || (sector>71)) return val;
1343 Char_t sideName='A';
1344 if ((sector/18)%2==1) sideName='C';
1347 sensorName=Form("TPC_COVER_I_%c_VMEAS",sideName);
1350 sensorName=Form("TPC_COVER_O_%c_VMEAS",sideName);
1353 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1355 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1360 Float_t AliTPCcalibDB::GetGGoffsetVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1363 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1364 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1365 // if timeStamp==-1 return the mean value for the run
1368 TString sensorName="";
1369 TTimeStamp stamp(timeStamp);
1370 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1371 if (!voltageArray || (sector<0) || (sector>71)) return val;
1372 Char_t sideName='A';
1373 if ((sector/18)%2==1) sideName='C';
1376 sensorName=Form("TPC_GATE_I_%c_OFF_VMEAS",sideName);
1379 sensorName=Form("TPC_GATE_O_%c_OFF_VMEAS",sideName);
1382 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1384 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1389 Float_t AliTPCcalibDB::GetGGnegVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1392 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1393 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1394 // if timeStamp==-1 return the mean value for the run
1397 TString sensorName="";
1398 TTimeStamp stamp(timeStamp);
1399 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1400 if (!voltageArray || (sector<0) || (sector>71)) return val;
1401 Char_t sideName='A';
1402 if ((sector/18)%2==1) sideName='C';
1405 sensorName=Form("TPC_GATE_I_%c_NEG_VMEAS",sideName);
1408 sensorName=Form("TPC_GATE_O_%c_NEG_VMEAS",sideName);
1411 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1413 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1418 Float_t AliTPCcalibDB::GetGGposVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1421 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1422 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1423 // if timeStamp==-1 return the mean value for the run
1426 TString sensorName="";
1427 TTimeStamp stamp(timeStamp);
1428 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1429 if (!voltageArray || (sector<0) || (sector>71)) return val;
1430 Char_t sideName='A';
1431 if ((sector/18)%2==1) sideName='C';
1434 sensorName=Form("TPC_GATE_I_%c_POS_VMEAS",sideName);
1437 sensorName=Form("TPC_GATE_O_%c_POS_VMEAS",sideName);
1440 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1442 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1447 Float_t AliTPCcalibDB::GetPressure(Int_t timeStamp, Int_t run, Int_t type){
1449 // GetPressure for given time stamp and runt
1451 TTimeStamp stamp(timeStamp);
1452 AliDCSSensor * sensor = Instance()->GetPressureSensor(run,type);
1453 if (!sensor) return 0;
1454 return sensor->GetValue(stamp);
1457 Float_t AliTPCcalibDB::GetL3Current(Int_t run, Int_t statType){
1459 // return L3 current
1460 // stat type is: AliGRPObject::Stats: kMean = 0, kTruncMean = 1, kMedian = 2, kSDMean = 3, kSDMedian = 4
1463 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1464 if (grp) current=grp->GetL3Current((AliGRPObject::Stats)statType);
1468 Float_t AliTPCcalibDB::GetBz(Int_t run){
1470 // calculate BZ in T from L3 current
1473 Float_t current=AliTPCcalibDB::GetL3Current(run);
1474 if (current>-1) bz=5*current/30000.*.1;
1478 Char_t AliTPCcalibDB::GetL3Polarity(Int_t run) {
1480 // get l3 polarity from GRP
1483 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1484 if (grp) pol=grp->GetL3Polarity();
1488 TString AliTPCcalibDB::GetRunType(Int_t run){
1490 // return run type from grp
1493 // TString type("UNKNOWN");
1494 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1495 if (grp) return grp->GetRunType();
1499 Float_t AliTPCcalibDB::GetValueGoofie(Int_t timeStamp, Int_t run, Int_t type){
1501 // GetPressure for given time stamp and runt
1503 TTimeStamp stamp(timeStamp);
1504 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(run);
1505 if (!goofieArray) return 0;
1506 AliDCSSensor *sensor = goofieArray->GetSensor(type);
1507 return sensor->GetValue(stamp);
1515 Bool_t AliTPCcalibDB::GetTemperatureFit(Int_t timeStamp, Int_t run, Int_t side,TVectorD& fit){
1519 TTimeStamp tstamp(timeStamp);
1520 AliTPCSensorTempArray* tempArray = Instance()->GetTemperatureSensor(run);
1521 if (! tempArray) return kFALSE;
1522 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
1523 TLinearFitter * fitter = tempMap->GetLinearFitter(3,side,tstamp);
1526 fitter->GetParameters(fit);
1530 if (!fitter) return kFALSE;
1534 Float_t AliTPCcalibDB::GetTemperature(Int_t timeStamp, Int_t run, Int_t side){
1540 GetTemperatureFit(timeStamp,run,0,vec);
1544 GetTemperatureFit(timeStamp,run,0,vec);
1551 Double_t AliTPCcalibDB::GetPTRelative(UInt_t timeSec, Int_t run, Int_t side){
1554 // time - absolute time
1556 // side - 0 - A side 1-C side
1557 AliTPCCalibVdrift * vdrift = Instance()->GetVdrift(run);
1558 if (!vdrift) return 0;
1559 return vdrift->GetPTRelative(timeSec,side);
1562 AliGRPObject * AliTPCcalibDB::MakeGRPObjectFromMap(TMap *map){
1564 // Function to covert old GRP run information from TMap to GRPObject
1566 // TMap * map = AliTPCcalibDB::GetGRPMap(52406);
1568 AliDCSSensor * sensor = 0;
1570 osensor = ((*map)("fP2Pressure"));
1571 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1573 if (!sensor) return 0;
1575 AliDCSSensor * sensor2 = new AliDCSSensor(*sensor);
1576 osensor = ((*map)("fCavernPressure"));
1577 TGraph * gr = new TGraph(2);
1578 gr->GetX()[0]= -100000.;
1579 gr->GetX()[1]= 1000000.;
1580 gr->GetY()[0]= atof(osensor->GetName());
1581 gr->GetY()[1]= atof(osensor->GetName());
1582 sensor2->SetGraph(gr);
1586 AliGRPObject *grpRun = new AliGRPObject;
1587 grpRun->ReadValuesFromMap(map);
1588 grpRun->SetCavernAtmosPressure(sensor2);
1589 grpRun->SetSurfaceAtmosPressure(sensor);
1593 Bool_t AliTPCcalibDB::CreateGUITree(Int_t run, const char* filename)
1596 // Create a gui tree for run number 'run'
1599 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1600 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
1601 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
1605 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
1606 // retrieve cal pad objects
1608 db->CreateGUITree(filename);
1612 Bool_t AliTPCcalibDB::CreateGUITree(const char* filename){
1616 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1617 AliError("Default Storage not set. Cannot create calibration Tree!");
1620 UpdateNonRec(); // load all infromation now
1622 AliTPCPreprocessorOnline prep;
1623 //noise and pedestals
1624 if (GetPedestals()) prep.AddComponent(new AliTPCCalPad(*(GetPedestals())));
1625 if (GetPadNoise() ) prep.AddComponent(new AliTPCCalPad(*(GetPadNoise())));
1627 if (GetPulserTmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserTmean())));
1628 if (GetPulserTrms() ) prep.AddComponent(new AliTPCCalPad(*(GetPulserTrms())));
1629 if (GetPulserQmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserQmean())));
1631 if (GetCETmean()) prep.AddComponent(new AliTPCCalPad(*(GetCETmean())));
1632 if (GetCETrms() ) prep.AddComponent(new AliTPCCalPad(*(GetCETrms())));
1633 if (GetCEQmean()) prep.AddComponent(new AliTPCCalPad(*(GetCEQmean())));
1635 if (GetALTROAcqStart() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStart() )));
1636 if (GetALTROZsThr() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROZsThr() )));
1637 if (GetALTROFPED() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROFPED() )));
1638 if (GetALTROAcqStop() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStop() )));
1639 if (GetALTROMasked() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROMasked() )));
1641 AliTPCdataQA *dataQA=GetDataQA();
1643 if (dataQA->GetNLocalMaxima())
1644 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNLocalMaxima())));
1645 if (dataQA->GetMaxCharge())
1646 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMaxCharge())));
1647 if (dataQA->GetMeanCharge())
1648 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMeanCharge())));
1649 if (dataQA->GetNoThreshold())
1650 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNoThreshold())));
1651 if (dataQA->GetNTimeBins())
1652 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNTimeBins())));
1653 if (dataQA->GetNPads())
1654 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNPads())));
1655 if (dataQA->GetTimePosition())
1656 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetTimePosition())));
1660 TString file(filename);
1661 if (file.IsNull()) file=Form("guiTreeRun_%d.root",fRun);
1662 prep.DumpToFile(file.Data());
1666 Bool_t AliTPCcalibDB::CreateRefFile(Int_t run, const char* filename)
1669 // Create a gui tree for run number 'run'
1672 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1673 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
1674 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
1677 TString file(filename);
1678 if (file.IsNull()) file=Form("RefCalPads_%d.root",run);
1679 TDirectory *currDir=gDirectory;
1681 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
1682 // retrieve cal pad objects
1685 TFile f(file.Data(),"recreate");
1686 //noise and pedestals
1687 db->GetPedestals()->Write("Pedestals");
1688 db->GetPadNoise()->Write("PadNoise");
1690 db->GetPulserTmean()->Write("PulserTmean");
1691 db->GetPulserTrms()->Write("PulserTrms");
1692 db->GetPulserQmean()->Write("PulserQmean");
1694 db->GetCETmean()->Write("CETmean");
1695 db->GetCETrms()->Write("CETrms");
1696 db->GetCEQmean()->Write("CEQmean");
1698 db->GetALTROAcqStart() ->Write("ALTROAcqStart");
1699 db->GetALTROZsThr() ->Write("ALTROZsThr");
1700 db->GetALTROFPED() ->Write("ALTROFPED");
1701 db->GetALTROAcqStop() ->Write("ALTROAcqStop");
1702 db->GetALTROMasked() ->Write("ALTROMasked");
1711 Double_t AliTPCcalibDB::GetVDriftCorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
1713 // Get time dependent drift velocity correction
1714 // multiplication factor vd = vdnom *(1+vdriftcorr)
1716 // mode determines the algorith how to combine the Laser Track, LaserCE and physics tracks
1717 // timestamp - timestamp
1719 // side - the drift velocity per side (possible for laser and CE)
1721 // Notice - Extrapolation outside of calibration range - using constant function
1724 // mode 1 automatic mode - according to the distance to the valid calibration
1726 Double_t deltaP=0, driftP=0, wP = 0.;
1727 Double_t deltaITS=0,driftITS=0, wITS= 0.;
1728 Double_t deltaLT=0, driftLT=0, wLT = 0.;
1729 Double_t deltaCE=0, driftCE=0, wCE = 0.;
1730 driftP = fDButil->GetVDriftTPC(deltaP,run,timeStamp);
1731 driftITS= fDButil->GetVDriftTPCITS(deltaITS,run,timeStamp);
1732 driftCE = fDButil->GetVDriftTPCCE(deltaCE, run,timeStamp,36000,2);
1733 driftLT = fDButil->GetVDriftTPCLaserTracks(deltaLT,run,timeStamp,36000,2);
1734 deltaITS = TMath::Abs(deltaITS);
1735 deltaP = TMath::Abs(deltaP);
1736 deltaLT = TMath::Abs(deltaLT);
1737 deltaCE = TMath::Abs(deltaCE);
1739 const Double_t kEpsilon=0.00000000001;
1740 const Double_t kdeltaT=360.; // 10 minutes
1741 wITS = 64.*kdeltaT/(deltaITS +kdeltaT);
1742 wLT = 16.*kdeltaT/(deltaLT +kdeltaT);
1743 wP = 0. *kdeltaT/(deltaP +kdeltaT);
1744 wCE = 1. *kdeltaT/(deltaCE +kdeltaT);
1747 if (TMath::Abs(driftP)<kEpsilon) wP=0; // invalid calibration
1748 if (TMath::Abs(driftITS)<kEpsilon)wITS=0; // invalid calibration
1749 if (TMath::Abs(driftLT)<kEpsilon) wLT=0; // invalid calibration
1750 if (TMath::Abs(driftCE)<kEpsilon) wCE=0; // invalid calibration
1751 if (wP+wITS+wLT+wCE<kEpsilon) return 0;
1752 result = (driftP*wP+driftITS*wITS+driftLT*wLT+driftCE*wCE)/(wP+wITS+wLT+wCE);
1758 Double_t AliTPCcalibDB::GetTime0CorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
1760 // Get time dependent time 0 (trigger delay in cm) correction
1761 // additive correction time0 = time0+ GetTime0CorrectionTime
1762 // Value etracted combining the vdrift correction using laser tracks and CE and the physics track matchin
1764 // mode determines the algorith how to combine the Laser Track and physics tracks
1765 // timestamp - timestamp
1767 // side - the drift velocity per side (possible for laser and CE)
1769 // Notice - Extrapolation outside of calibration range - using constant function
1774 result=fDButil->GetTriggerOffsetTPC(run,timeStamp);
1775 result *=fParam->GetZLength();
1780 result= -fDButil->GetTime0TPCITS(dist, run, timeStamp)*fParam->GetDriftV()/1000000.;
1789 Double_t AliTPCcalibDB::GetVDriftCorrectionGy(Int_t timeStamp, Int_t run, Int_t side, Int_t /*mode*/){
1791 // Get global y correction drift velocity correction factor
1792 // additive factor vd = vdnom*(1+GetVDriftCorrectionGy *gy)
1793 // Value etracted combining the vdrift correction using laser tracks and CE
1795 // mode determines the algorith how to combine the Laser Track, LaserCE
1796 // timestamp - timestamp
1798 // side - the drift velocity gy correction per side (CE and Laser tracks)
1800 // Notice - Extrapolation outside of calibration range - using constant function
1802 if (run<=0 && fTransform) run = fTransform->GetCurrentRunNumber();
1803 UpdateRunInformations(run,kFALSE);
1804 TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
1805 if (!array) return 0;
1806 TGraphErrors *laserA= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_A");
1807 TGraphErrors *laserC= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_C");
1810 if (laserA && laserC){
1811 result= (laserA->Eval(timeStamp)+laserC->Eval(timeStamp))*0.5;
1813 if (laserA && side==0){
1814 result = (laserA->Eval(timeStamp));
1816 if (laserC &&side==1){
1817 result = (laserC->Eval(timeStamp));
1819 return -result/250.; //normalized before