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"
102 #include "AliTPCmapper.h"
111 #include "TGraphErrors.h"
113 #include "TObjArray.h"
114 #include "TObjString.h"
116 #include "TDirectory.h"
118 #include "AliTPCCalPad.h"
119 #include "AliTPCCalibPulser.h"
120 #include "AliTPCCalibPedestal.h"
121 #include "AliTPCCalibCE.h"
122 #include "AliTPCExBFirst.h"
123 #include "AliTPCTempMap.h"
124 #include "AliTPCCalibVdrift.h"
125 #include "AliTPCCalibRaw.h"
126 #include "AliTPCParam.h"
127 #include "AliTPCCorrection.h"
128 #include "AliTPCPreprocessorOnline.h"
131 ClassImp(AliTPCcalibDB)
133 AliTPCcalibDB* AliTPCcalibDB::fgInstance = 0;
134 Bool_t AliTPCcalibDB::fgTerminated = kFALSE;
135 TObjArray AliTPCcalibDB::fgExBArray; // array of ExB corrections
138 //_ singleton implementation __________________________________________________
139 AliTPCcalibDB* AliTPCcalibDB::Instance()
142 // Singleton implementation
143 // Returns an instance of this class, it is created if neccessary
146 if (fgTerminated != kFALSE)
150 fgInstance = new AliTPCcalibDB();
155 void AliTPCcalibDB::Terminate()
158 // Singleton implementation
159 // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
160 // This function can be called several times.
163 fgTerminated = kTRUE;
172 //_____________________________________________________________________________
173 AliTPCcalibDB::AliTPCcalibDB():
182 fComposedCorrection(0),
183 fComposedCorrectionArray(0),
196 fTimeGainSplinesArray(100000),
197 fGRPArray(100000), //! array of GRPs - per run - JUST for calibration studies
198 fGRPMaps(100000), //! array of GRPs - per run - JUST for calibration studies
199 fGoofieArray(100000), //! array of GOOFIE values -per run - Just for calibration studies
200 fVoltageArray(100000),
201 fTemperatureArray(100000), //! array of temperature sensors - per run - Just for calibration studies
202 fVdriftArray(100000), //! array of v drift interfaces
203 fDriftCorrectionArray(100000), //! array of drift correction
204 fRunList(100000), //! run list - indicates try to get the run param
213 Update(); // temporary
216 AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
225 fComposedCorrection(0),
226 fComposedCorrectionArray(0),
239 fTimeGainSplinesArray(100000),
240 fGRPArray(0), //! array of GRPs - per run - JUST for calibration studies
241 fGRPMaps(0), //! array of GRPs - per run - JUST for calibration studies
242 fGoofieArray(0), //! array of GOOFIE values -per run - Just for calibration studies
244 fTemperatureArray(0), //! array of temperature sensors - per run - Just for calibration studies
245 fVdriftArray(0), //! array of v drift interfaces
246 fDriftCorrectionArray(0), //! array of v drift corrections
247 fRunList(0), //! run list - indicates try to get the run param
252 // Copy constructor invalid -- singleton implementation
254 Error("copy constructor","invalid -- singleton implementation");
257 AliTPCcalibDB& AliTPCcalibDB::operator= (const AliTPCcalibDB& )
260 // Singleton implementation - no assignment operator
262 Error("operator =", "assignment operator not implemented");
268 //_____________________________________________________________________________
269 AliTPCcalibDB::~AliTPCcalibDB()
276 AliTPCCalPad* AliTPCcalibDB::GetDistortionMap(Int_t i) const {
278 // get distortion map - due E field distortions
280 return (fDistortionMap) ? (AliTPCCalPad*)fDistortionMap->At(i):0;
283 //_____________________________________________________________________________
284 AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
287 // Retrieves an entry with path <cdbPath> from the CDB.
291 AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun);
294 sprintf(chinfo,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
302 //_____________________________________________________________________________
303 void AliTPCcalibDB::SetRun(Long64_t run)
306 // Sets current run number. Calibration data is read from the corresponding file.
316 void AliTPCcalibDB::Update(){
318 // cache the OCDB entries for simulation, reconstruction, calibration
321 AliCDBEntry * entry=0;
322 Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
323 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
324 fDButil = new AliTPCcalibDButil;
327 entry = GetCDBEntry("TPC/Calib/PadGainFactor");
329 //if (fPadGainFactor) delete fPadGainFactor;
330 entry->SetOwner(kTRUE);
331 fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
333 AliFatal("TPC - Missing calibration entry TPC/Calib/PadGainFactor")
336 entry = GetCDBEntry("TPC/Calib/TimeGain");
338 //if (fTimeGainSplines) delete fTimeGainSplines;
339 entry->SetOwner(kTRUE);
340 fTimeGainSplines = (TObjArray*)entry->GetObject();
342 AliFatal("TPC - Missing calibration entry TPC/Calib/Timegain")
345 entry = GetCDBEntry("TPC/Calib/GainFactorDedx");
347 entry->SetOwner(kTRUE);
348 fDedxGainFactor = (AliTPCCalPad*)entry->GetObject();
350 AliFatal("TPC - Missing calibration entry TPC/Calib/gainFactordEdx")
353 entry = GetCDBEntry("TPC/Calib/PadTime0");
355 //if (fPadTime0) delete fPadTime0;
356 entry->SetOwner(kTRUE);
357 fPadTime0 = (AliTPCCalPad*)entry->GetObject();
359 AliFatal("TPC - Missing calibration entry")
362 entry = GetCDBEntry("TPC/Calib/Distortion");
364 //if (fPadTime0) delete fPadTime0;
365 entry->SetOwner(kTRUE);
366 fDistortionMap =dynamic_cast<TObjArray*>(entry->GetObject());
368 //AliFatal("TPC - Missing calibration entry")
374 entry = GetCDBEntry("TPC/Calib/PadNoise");
376 //if (fPadNoise) delete fPadNoise;
377 entry->SetOwner(kTRUE);
378 fPadNoise = (AliTPCCalPad*)entry->GetObject();
380 AliFatal("TPC - Missing calibration entry")
383 entry = GetCDBEntry("TPC/Calib/Pedestals");
385 //if (fPedestals) delete fPedestals;
386 entry->SetOwner(kTRUE);
387 fPedestals = (AliTPCCalPad*)entry->GetObject();
390 entry = GetCDBEntry("TPC/Calib/Temperature");
392 //if (fTemperature) delete fTemperature;
393 entry->SetOwner(kTRUE);
394 fTemperature = (AliTPCSensorTempArray*)entry->GetObject();
397 entry = GetCDBEntry("TPC/Calib/Parameters");
399 //if (fPadNoise) delete fPadNoise;
400 entry->SetOwner(kTRUE);
401 fParam = (AliTPCParam*)(entry->GetObject()->Clone());
403 AliFatal("TPC - Missing calibration entry TPC/Calib/Parameters")
406 entry = GetCDBEntry("TPC/Calib/ClusterParam");
408 entry->SetOwner(kTRUE);
409 fClusterParam = (AliTPCClusterParam*)(entry->GetObject()->Clone());
411 AliFatal("TPC - Missing calibration entry")
414 //ALTRO configuration data
415 entry = GetCDBEntry("TPC/Calib/AltroConfig");
417 entry->SetOwner(kTRUE);
418 fALTROConfigData=(TObjArray*)(entry->GetObject());
420 AliFatal("TPC - Missing calibration entry")
423 //Calibration Pulser data
424 entry = GetCDBEntry("TPC/Calib/Pulser");
426 entry->SetOwner(kTRUE);
427 fPulserData=(TObjArray*)(entry->GetObject());
431 entry = GetCDBEntry("TPC/Calib/CE");
433 entry->SetOwner(kTRUE);
434 fCEData=(TObjArray*)(entry->GetObject());
436 //RAW calibration data
437 // entry = GetCDBEntry("TPC/Calib/Raw");
439 entry = GetCDBEntry("TPC/Calib/Mapping");
441 //if (fPadNoise) delete fPadNoise;
442 entry->SetOwner(kTRUE);
443 TObjArray * array = dynamic_cast<TObjArray*>(entry->GetObject());
444 if (array && array->GetEntriesFast()==6){
445 fMapping = new AliTPCAltroMapping*[6];
446 for (Int_t i=0; i<6; i++){
447 fMapping[i] = dynamic_cast<AliTPCAltroMapping*>(array->At(i));
452 //CTP calibration data
453 entry = GetCDBEntry("GRP/CTP/CTPtiming");
455 //entry->SetOwner(kTRUE);
456 fCTPTimeParams=dynamic_cast<AliCTPTimeParams*>(entry->GetObject());
458 AliError("TPC - Missing calibration entry")
460 //TPC space point correction data
461 entry = GetCDBEntry("TPC/Calib/Correction");
463 //entry->SetOwner(kTRUE);
464 fComposedCorrection=dynamic_cast<AliTPCCorrection*>(entry->GetObject());
465 if (fComposedCorrection) fComposedCorrection->Init();
466 fComposedCorrectionArray=dynamic_cast<TObjArray*>(entry->GetObject());
467 if (fComposedCorrectionArray){
468 for (Int_t i=0; i<fComposedCorrectionArray->GetEntries(); i++){
469 AliTPCCorrection* composedCorrection= dynamic_cast<AliTPCCorrection*>(fComposedCorrectionArray->At(i));
470 if (composedCorrection) composedCorrection->Init();
474 AliError("TPC - Missing calibration entry- TPC/Calib/Correction")
479 fTransform=new AliTPCTransform();
480 fTransform->SetCurrentRun(AliCDBManager::Instance()->GetRun());
484 AliCDBManager::Instance()->SetCacheFlag(cdbCache); // reset original CDB cache
487 void AliTPCcalibDB::UpdateNonRec(){
489 // Update/Load the parameters which are important for QA studies
490 // and not used yet for the reconstruction
492 //RAW calibration data
493 AliCDBEntry * entry=0;
494 entry = GetCDBEntry("TPC/Calib/Raw");
496 entry->SetOwner(kTRUE);
497 TObjArray *arr=(TObjArray*)(entry->GetObject());
498 if (arr) fCalibRaw=(AliTPCCalibRaw*)arr->At(0);
500 //QA calibration data
501 entry = GetCDBEntry("TPC/Calib/QA");
503 entry->SetOwner(kTRUE);
504 fDataQA=dynamic_cast<AliTPCdataQA*>(entry->GetObject());
508 entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",fRun);
510 fVoltageArray.AddAt(entry->GetObject(),fRun);
518 void AliTPCcalibDB::CreateObjectList(const Char_t *filename, TObjArray *calibObjects)
521 // Create calibration objects and read contents from OCDB
523 if ( calibObjects == 0x0 ) return;
526 if ( !in.is_open() ){
527 fprintf(stderr,"Error: cannot open list file '%s'", filename);
531 AliTPCCalPad *calPad=0x0;
537 TObjArray *arrFileLine = sFile.Tokenize("\n");
539 TIter nextLine(arrFileLine);
541 TObjString *sObjLine=0x0;
542 while ( (sObjLine = (TObjString*)nextLine()) ){
543 TString sLine(sObjLine->GetString());
545 TObjArray *arrNextCol = sLine.Tokenize("\t");
547 TObjString *sObjType = (TObjString*)(arrNextCol->At(0));
548 TObjString *sObjFileName = (TObjString*)(arrNextCol->At(1));
550 if ( !sObjType || ! sObjFileName ) continue;
551 TString sType(sObjType->GetString());
552 TString sFileName(sObjFileName->GetString());
553 printf("%s\t%s\n",sType.Data(),sFileName.Data());
555 TFile *fIn = TFile::Open(sFileName);
557 fprintf(stderr,"File not found: '%s'", sFileName.Data());
561 if ( sType == "CE" ){
562 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
564 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
565 calPad->SetNameTitle("CETmean","CETmean");
566 calibObjects->Add(calPad);
568 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
569 calPad->SetNameTitle("CEQmean","CEQmean");
570 calibObjects->Add(calPad);
572 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
573 calPad->SetNameTitle("CETrms","CETrms");
574 calibObjects->Add(calPad);
576 } else if ( sType == "Pulser") {
577 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
579 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
580 calPad->SetNameTitle("PulserTmean","PulserTmean");
581 calibObjects->Add(calPad);
583 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
584 calPad->SetNameTitle("PulserQmean","PulserQmean");
585 calibObjects->Add(calPad);
587 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
588 calPad->SetNameTitle("PulserTrms","PulserTrms");
589 calibObjects->Add(calPad);
591 } else if ( sType == "Pedestals") {
592 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
594 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
595 calPad->SetNameTitle("Pedestals","Pedestals");
596 calibObjects->Add(calPad);
598 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
599 calPad->SetNameTitle("Noise","Noise");
600 calibObjects->Add(calPad);
603 fprintf(stderr,"Undefined Type: '%s'",sType.Data());
612 void AliTPCcalibDB::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad* outlierPad, Float_t ltmFraction) {
614 // Write a tree with all available information
615 // if mapFileName is specified, the Map information are also written to the tree
616 // pads specified in outlierPad are not used for calculating statistics
617 // - the same function as AliTPCCalPad::MakeTree -
619 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
621 TObjArray* mapIROCs = 0;
622 TObjArray* mapOROCs = 0;
623 TVectorF *mapIROCArray = 0;
624 TVectorF *mapOROCArray = 0;
625 Int_t mapEntries = 0;
626 TString* mapNames = 0;
629 TFile mapFile(mapFileName, "read");
631 TList* listOfROCs = mapFile.GetListOfKeys();
632 mapEntries = listOfROCs->GetEntries()/2;
633 mapIROCs = new TObjArray(mapEntries*2);
634 mapOROCs = new TObjArray(mapEntries*2);
635 mapIROCArray = new TVectorF[mapEntries];
636 mapOROCArray = new TVectorF[mapEntries];
638 mapNames = new TString[mapEntries];
639 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
640 TString nameROC(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
641 nameROC.Remove(nameROC.Length()-4, 4);
642 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "IROC").Data()), ivalue);
643 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "OROC").Data()), ivalue);
644 mapNames[ivalue].Append(nameROC);
647 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
648 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
649 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
651 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
652 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
653 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
654 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
657 } // if (mapFileName)
659 TTreeSRedirector cstream(fileName);
660 Int_t arrayEntries = array->GetEntries();
662 TString* names = new TString[arrayEntries];
663 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
664 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
666 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
668 // get statistic for given sector
670 TVectorF median(arrayEntries);
671 TVectorF mean(arrayEntries);
672 TVectorF rms(arrayEntries);
673 TVectorF ltm(arrayEntries);
674 TVectorF ltmrms(arrayEntries);
675 TVectorF medianWithOut(arrayEntries);
676 TVectorF meanWithOut(arrayEntries);
677 TVectorF rmsWithOut(arrayEntries);
678 TVectorF ltmWithOut(arrayEntries);
679 TVectorF ltmrmsWithOut(arrayEntries);
681 TVectorF *vectorArray = new TVectorF[arrayEntries];
682 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
683 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
685 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
686 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
687 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
688 AliTPCCalROC* outlierROC = 0;
689 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
691 median[ivalue] = calROC->GetMedian();
692 mean[ivalue] = calROC->GetMean();
693 rms[ivalue] = calROC->GetRMS();
694 Double_t ltmrmsValue = 0;
695 ltm[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction);
696 ltmrms[ivalue] = ltmrmsValue;
698 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
699 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
700 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
702 ltmWithOut[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction, outlierROC);
703 ltmrmsWithOut[ivalue] = ltmrmsValue;
712 medianWithOut[ivalue] = 0.;
713 meanWithOut[ivalue] = 0.;
714 rmsWithOut[ivalue] = 0.;
715 ltmWithOut[ivalue] = 0.;
716 ltmrmsWithOut[ivalue] = 0.;
721 // fill vectors of variable per pad
723 TVectorF *posArray = new TVectorF[8];
724 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
725 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
727 Float_t posG[3] = {0};
728 Float_t posL[3] = {0};
730 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
731 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
732 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
733 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
734 posArray[0][ichannel] = irow;
735 posArray[1][ichannel] = ipad;
736 posArray[2][ichannel] = posL[0];
737 posArray[3][ichannel] = posL[1];
738 posArray[4][ichannel] = posG[0];
739 posArray[5][ichannel] = posG[1];
740 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
741 posArray[7][ichannel] = ichannel;
743 // loop over array containing AliTPCCalPads
744 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
745 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
746 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
748 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
750 (vectorArray[ivalue])[ichannel] = 0;
756 cstream << "calPads" <<
757 "sector=" << isector;
759 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
760 cstream << "calPads" <<
761 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
762 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
763 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
764 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
765 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
767 cstream << "calPads" <<
768 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
769 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
770 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
771 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
772 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
776 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
777 cstream << "calPads" <<
778 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
782 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
784 cstream << "calPads" <<
785 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
787 cstream << "calPads" <<
788 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
792 cstream << "calPads" <<
793 "row.=" << &posArray[0] <<
794 "pad.=" << &posArray[1] <<
795 "lx.=" << &posArray[2] <<
796 "ly.=" << &posArray[3] <<
797 "gx.=" << &posArray[4] <<
798 "gy.=" << &posArray[5] <<
799 "rpad.=" << &posArray[6] <<
800 "channel.=" << &posArray[7];
802 cstream << "calPads" <<
806 delete[] vectorArray;
814 delete[] mapIROCArray;
815 delete[] mapOROCArray;
820 Int_t AliTPCcalibDB::GetRCUTriggerConfig() const
823 // return the RCU trigger configuration register
825 TMap *map=GetRCUconfig();
827 TVectorF *v=(TVectorF*)map->GetValue("TRGCONF_TRG_MODE");
829 for (Int_t i=0; i<v->GetNrows(); ++i){
830 Float_t newmode=v->GetMatrixArray()[i];
832 if (mode>-1&&newmode!=mode) AliWarning("Found different RCU trigger configurations!!!");
839 Bool_t AliTPCcalibDB::IsTrgL0()
842 // return if the FEE readout was triggered on L0
844 Int_t mode=GetRCUTriggerConfig();
845 if (mode<0) return kFALSE;
849 Bool_t AliTPCcalibDB::IsTrgL1()
852 // return if the FEE readout was triggered on L1
854 Int_t mode=GetRCUTriggerConfig();
855 if (mode<0) return kFALSE;
859 void AliTPCcalibDB::RegisterExB(Int_t index, Float_t bz, Bool_t bdelete){
861 // Register static ExB correction map
862 // index - registration index - used for visualization
863 // bz - bz field in kGaus
865 // Float_t factor = bz/(-5.); // default b filed in Cheb with minus sign
866 Float_t factor = bz/(5.); // default b filed in Cheb with minus sign
867 // was chenged in the Revision ???? (Ruben can you add here number)
869 AliMagF* bmap = new AliMagF("MapsExB","MapsExB", factor,TMath::Sign(1.f,factor),AliMagF::k5kG);
871 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
872 AliTPCExB::SetInstance(exb);
877 AliTPCExB::RegisterField(index,bmap);
879 if (index>=fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
880 fgExBArray.AddAt(exb,index);
884 AliTPCExB* AliTPCcalibDB::GetExB(Float_t bz, Bool_t deleteB) {
886 // bz filed in KGaus not in tesla
887 // Get ExB correction map
888 // if doesn't exist - create it
890 Int_t index = TMath::Nint(5+bz);
891 if (index>fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
892 if (!fgExBArray.At(index)) AliTPCcalibDB::RegisterExB(index,bz,deleteB);
893 return (AliTPCExB*)fgExBArray.At(index);
897 void AliTPCcalibDB::SetExBField(Float_t bz){
899 // Set magnetic filed for ExB correction
901 fExB = GetExB(bz,kFALSE);
904 void AliTPCcalibDB::SetExBField(const AliMagF* bmap){
906 // Set magnetic field for ExB correction
908 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
909 AliTPCExB::SetInstance(exb);
917 void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
919 // - > Don't use it for reconstruction - Only for Calibration studies
923 AliCDBEntry * entry = 0;
924 if (run>= fRunList.fN){
925 fRunList.Set(run*2+1);
926 fGRPArray.Expand(run*2+1);
927 fGRPMaps.Expand(run*2+1);
928 fGoofieArray.Expand(run*2+1);
929 fVoltageArray.Expand(run*2+1);
930 fTemperatureArray.Expand(run*2+1);
931 fVdriftArray.Expand(run*2+1);
932 fDriftCorrectionArray.Expand(run*2+1);
933 fTimeGainSplinesArray.Expand(run*2+1);
936 fALTROConfigData->Expand(run*2+1); // ALTRO configuration data
937 fPulserData->Expand(run*2+1); // Calibration Pulser data
938 fCEData->Expand(run*2+1); // CE data
939 if (!fTimeGainSplines) fTimeGainSplines = new TObjArray(run*2+1);
940 fTimeGainSplines->Expand(run*2+1); // Array of AliSplineFits: at 0 MIP position in
942 if (fRunList[run]>0 &&force==kFALSE) return;
944 fRunList[run]=1; // sign as used
947 entry = AliCDBManager::Instance()->Get("GRP/GRP/Data",run);
949 AliGRPObject * grpRun = dynamic_cast<AliGRPObject*>(entry->GetObject());
951 TMap* map = dynamic_cast<TMap*>(entry->GetObject());
953 //grpRun = new AliGRPObject;
954 //grpRun->ReadValuesFromMap(map);
955 grpRun = MakeGRPObjectFromMap(map);
957 fGRPMaps.AddAt(map,run);
960 fGRPArray.AddAt(grpRun,run);
962 entry = AliCDBManager::Instance()->Get("TPC/Calib/Goofie",run);
964 fGoofieArray.AddAt(entry->GetObject(),run);
969 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeGain",run);
971 fTimeGainSplinesArray.AddAt(entry->GetObject(),run);
973 AliFatal("TPC - Missing calibration entry TimeGain")
976 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeDrift",run);
978 fDriftCorrectionArray.AddAt(entry->GetObject(),run);
980 AliFatal("TPC - Missing calibration entry TimeDrift")
983 entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
985 fTemperatureArray.AddAt(entry->GetObject(),run);
987 //apply fDButil filters
989 fDButil->UpdateFromCalibDB();
990 if (fTemperature) fDButil->FilterTemperature(fTemperature);
992 AliDCSSensor * press = GetPressureSensor(run,0);
993 AliTPCSensorTempArray * temp = GetTemperatureSensor(run);
996 accept = fDButil->FilterTemperature(temp)>0.1;
999 const Double_t kMinP=950.;
1000 const Double_t kMaxP=1050.;
1001 const Double_t kMaxdP=10.;
1002 const Double_t kSigmaCut=4.;
1003 fDButil->FilterSensor(press,kMinP,kMaxP,kMaxdP,kSigmaCut);
1004 if (press->GetFit()==0) accept=kFALSE;
1007 if (press && temp &&accept){
1008 AliTPCCalibVdrift * vdrift = new AliTPCCalibVdrift(temp, press,0);
1009 fVdriftArray.AddAt(vdrift,run);
1012 fDButil->FilterCE(120., 3., 4.,0);
1013 fDButil->FilterTracks(run, 10.,0);
1018 Float_t AliTPCcalibDB::GetGain(Int_t sector, Int_t row, Int_t pad){
1020 // Get Gain factor for given pad
1022 AliTPCCalPad *calPad = Instance()->fDedxGainFactor;;
1023 if (!calPad) return 0;
1024 return calPad->GetCalROC(sector)->GetValue(row,pad);
1027 AliSplineFit* AliTPCcalibDB::GetVdriftSplineFit(const char* name, Int_t run){
1029 // GetDrift velocity spline fit
1031 TObjArray *arr=GetTimeVdriftSplineRun(run);
1033 return dynamic_cast<AliSplineFit*>(arr->FindObject(name));
1036 AliSplineFit* AliTPCcalibDB::CreateVdriftSplineFit(const char* graphName, Int_t run){
1038 // create spline fit from the drift time graph in TimeDrift
1040 TObjArray *arr=GetTimeVdriftSplineRun(run);
1042 TGraph *graph=dynamic_cast<TGraph*>(arr->FindObject(graphName));
1043 if (!graph) return 0;
1044 AliSplineFit *fit = new AliSplineFit();
1045 fit->SetGraph(graph);
1046 fit->SetMinPoints(graph->GetN()+1);
1047 fit->InitKnots(graph,2,0,0.001);
1052 AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
1054 // Get GRP object for given run
1056 if (run>= ((Instance()->fGRPArray)).GetEntriesFast()){
1057 Instance()->UpdateRunInformations(run);
1059 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).At(run));
1061 Instance()->UpdateRunInformations(run);
1062 grpRun = dynamic_cast<AliGRPObject *>(Instance()->fGRPArray.At(run));
1063 if (!grpRun) return 0;
1068 TMap * AliTPCcalibDB::GetGRPMap(Int_t run){
1070 // Get GRP map for given run
1072 TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).At(run));
1074 Instance()->UpdateRunInformations(run);
1075 grpRun = dynamic_cast<TMap *>(Instance()->fGRPMaps.At(run));
1076 if (!grpRun) return 0;
1082 AliDCSSensor * AliTPCcalibDB::GetPressureSensor(Int_t run, Int_t type){
1084 // Get Pressure sensor
1086 // type = 0 - Cavern pressure
1087 // 1 - Suface pressure
1088 // First try to get if trom map - if existing (Old format of data storing)
1092 TMap *map = GetGRPMap(run);
1094 AliDCSSensor * sensor = 0;
1096 if (type==0) osensor = ((*map)("fCavernPressure"));
1097 if (type==1) osensor = ((*map)("fP2Pressure"));
1098 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1099 if (sensor) return sensor;
1102 // If not map try to get it from the GRPObject
1104 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
1106 UpdateRunInformations(run);
1107 grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
1108 if (!grpRun) return 0;
1110 AliDCSSensor * sensor = grpRun->GetCavernAtmosPressure();
1111 if (type==1) sensor = grpRun->GetSurfaceAtmosPressure();
1115 AliTPCSensorTempArray * AliTPCcalibDB::GetTemperatureSensor(Int_t run){
1117 // Get temperature sensor array
1119 AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
1121 UpdateRunInformations(run);
1122 tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
1128 TObjArray * AliTPCcalibDB::GetTimeGainSplinesRun(Int_t run){
1130 // Get temperature sensor array
1132 TObjArray * gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
1134 UpdateRunInformations(run);
1135 gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
1140 TObjArray * AliTPCcalibDB::GetTimeVdriftSplineRun(Int_t run){
1142 // Get drift spline array
1144 TObjArray * driftSplines = (TObjArray *)fDriftCorrectionArray.At(run);
1145 if (!driftSplines) {
1146 UpdateRunInformations(run);
1147 driftSplines = (TObjArray *)fDriftCorrectionArray.At(run);
1149 return driftSplines;
1152 AliDCSSensorArray * AliTPCcalibDB::GetVoltageSensors(Int_t run){
1154 // Get temperature sensor array
1156 AliDCSSensorArray * voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
1157 if (!voltageArray) {
1158 UpdateRunInformations(run);
1159 voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
1161 return voltageArray;
1164 AliDCSSensorArray * AliTPCcalibDB::GetGoofieSensors(Int_t run){
1166 // Get temperature sensor array
1168 AliDCSSensorArray * goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
1170 UpdateRunInformations(run);
1171 goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
1178 AliTPCCalibVdrift * AliTPCcalibDB::GetVdrift(Int_t run){
1180 // Get the interface to the the vdrift
1182 AliTPCCalibVdrift * vdrift = (AliTPCCalibVdrift*)fVdriftArray.At(run);
1184 UpdateRunInformations(run);
1185 vdrift= (AliTPCCalibVdrift*)fVdriftArray.At(run);
1190 Float_t AliTPCcalibDB::GetCEdriftTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
1193 // GetCE drift time information for 'sector'
1194 // sector 72 is the mean drift time of the A-Side
1195 // sector 73 is the mean drift time of the C-Side
1196 // it timestamp==-1 return mean value
1198 AliTPCcalibDB::Instance()->SetRun(run);
1199 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocTgraph(sector);
1200 if (!gr||sector<0||sector>73) {
1201 if (entries) *entries=0;
1205 if (timeStamp==-1.){
1208 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1210 gr->GetPoint(ipoint,x,y);
1211 if (x<timeStamp) continue;
1219 Float_t AliTPCcalibDB::GetCEchargeTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
1222 // GetCE mean charge for 'sector'
1223 // it timestamp==-1 return mean value
1225 AliTPCcalibDB::Instance()->SetRun(run);
1226 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocQgraph(sector);
1227 if (!gr||sector<0||sector>71) {
1228 if (entries) *entries=0;
1232 if (timeStamp==-1.){
1235 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1237 gr->GetPoint(ipoint,x,y);
1238 if (x<timeStamp) continue;
1246 Float_t AliTPCcalibDB::GetDCSSensorValue(AliDCSSensorArray *arr, Int_t timeStamp, const char * sensorName, Int_t sigDigits)
1249 // Get Value for a DCS sensor 'sensorName', run 'run' at time 'timeStamp'
1252 const TString sensorNameString(sensorName);
1253 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1254 if (!sensor) return val;
1255 //use the dcs graph if possible
1256 TGraph *gr=sensor->GetGraph();
1258 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1260 gr->GetPoint(ipoint,x,y);
1261 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1262 if (time<timeStamp) continue;
1266 //if val is still 0, test if if the requested time if within 5min of the first/last
1267 //data point. If this is the case return the firs/last entry
1268 //the timestamps might not be syncronised for all calibration types, sometimes a 'pre'
1269 //and 'pos' period is requested. Especially to the HV this is not the case!
1273 gr->GetPoint(0,x,y);
1274 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1275 if ((time-timeStamp)<5*60) val=y;
1280 gr->GetPoint(gr->GetN()-1,x,y);
1281 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1282 if ((timeStamp-time)<5*60) val=y;
1285 val=sensor->GetValue(timeStamp);
1288 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1293 Float_t AliTPCcalibDB::GetDCSSensorMeanValue(AliDCSSensorArray *arr, const char * sensorName, Int_t sigDigits)
1296 // Get mean Value for a DCS sensor 'sensorName' during run 'run'
1299 const TString sensorNameString(sensorName);
1300 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1301 if (!sensor) return val;
1303 //use dcs graph if it exists
1304 TGraph *gr=sensor->GetGraph();
1308 //if we don't have the dcs graph, try to get some meaningful information
1309 if (!sensor->GetFit()) return val;
1310 Int_t nKnots=sensor->GetFit()->GetKnots();
1311 Double_t tMid=(sensor->GetEndTime()-sensor->GetStartTime())/2.;
1312 for (Int_t iKnot=0;iKnot<nKnots;++iKnot){
1313 if (sensor->GetFit()->GetX()[iKnot]>tMid/3600.) break;
1314 val=(Float_t)sensor->GetFit()->GetY0()[iKnot];
1319 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1325 Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits) {
1327 // return the chamber HV for given run and time: 0-35 IROC, 36-72 OROC
1328 // if timeStamp==-1 return mean value
1331 TString sensorName="";
1332 TTimeStamp stamp(timeStamp);
1333 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1334 if (!voltageArray || (sector<0) || (sector>71)) return val;
1335 Char_t sideName='A';
1336 if ((sector/18)%2==1) sideName='C';
1339 sensorName=Form("TPC_ANODE_I_%c%02d_VMEAS",sideName,sector%18);
1342 sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,sector%18);
1345 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1347 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1351 Float_t AliTPCcalibDB::GetSkirtVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1354 // Get the skirt voltage for 'run' at 'timeStamp' and 'sector': 0-35 IROC, 36-72 OROC
1355 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1356 // if timeStamp==-1 return the mean value for the run
1359 TString sensorName="";
1360 TTimeStamp stamp(timeStamp);
1361 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1362 if (!voltageArray || (sector<0) || (sector>71)) return val;
1363 Char_t sideName='A';
1364 if ((sector/18)%2==1) sideName='C';
1365 sensorName=Form("TPC_SKIRT_%c_VMEAS",sideName);
1367 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1369 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1374 Float_t AliTPCcalibDB::GetCoverVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1377 // Get the cover voltage for run 'run' at time 'timeStamp'
1378 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1379 // if timeStamp==-1 return the mean value for the run
1382 TString sensorName="";
1383 TTimeStamp stamp(timeStamp);
1384 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1385 if (!voltageArray || (sector<0) || (sector>71)) return val;
1386 Char_t sideName='A';
1387 if ((sector/18)%2==1) sideName='C';
1390 sensorName=Form("TPC_COVER_I_%c_VMEAS",sideName);
1393 sensorName=Form("TPC_COVER_O_%c_VMEAS",sideName);
1396 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1398 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1403 Float_t AliTPCcalibDB::GetGGoffsetVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1406 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1407 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1408 // if timeStamp==-1 return the mean value for the run
1411 TString sensorName="";
1412 TTimeStamp stamp(timeStamp);
1413 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1414 if (!voltageArray || (sector<0) || (sector>71)) return val;
1415 Char_t sideName='A';
1416 if ((sector/18)%2==1) sideName='C';
1419 sensorName=Form("TPC_GATE_I_%c_OFF_VMEAS",sideName);
1422 sensorName=Form("TPC_GATE_O_%c_OFF_VMEAS",sideName);
1425 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1427 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1432 Float_t AliTPCcalibDB::GetGGnegVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1435 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1436 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1437 // if timeStamp==-1 return the mean value for the run
1440 TString sensorName="";
1441 TTimeStamp stamp(timeStamp);
1442 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1443 if (!voltageArray || (sector<0) || (sector>71)) return val;
1444 Char_t sideName='A';
1445 if ((sector/18)%2==1) sideName='C';
1448 sensorName=Form("TPC_GATE_I_%c_NEG_VMEAS",sideName);
1451 sensorName=Form("TPC_GATE_O_%c_NEG_VMEAS",sideName);
1454 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1456 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1461 Float_t AliTPCcalibDB::GetGGposVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1464 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1465 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1466 // if timeStamp==-1 return the mean value for the run
1469 TString sensorName="";
1470 TTimeStamp stamp(timeStamp);
1471 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1472 if (!voltageArray || (sector<0) || (sector>71)) return val;
1473 Char_t sideName='A';
1474 if ((sector/18)%2==1) sideName='C';
1477 sensorName=Form("TPC_GATE_I_%c_POS_VMEAS",sideName);
1480 sensorName=Form("TPC_GATE_O_%c_POS_VMEAS",sideName);
1483 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1485 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1490 Float_t AliTPCcalibDB::GetPressure(Int_t timeStamp, Int_t run, Int_t type){
1492 // GetPressure for given time stamp and runt
1494 TTimeStamp stamp(timeStamp);
1495 AliDCSSensor * sensor = Instance()->GetPressureSensor(run,type);
1496 if (!sensor) return 0;
1497 return sensor->GetValue(stamp);
1500 Float_t AliTPCcalibDB::GetL3Current(Int_t run, Int_t statType){
1502 // return L3 current
1503 // stat type is: AliGRPObject::Stats: kMean = 0, kTruncMean = 1, kMedian = 2, kSDMean = 3, kSDMedian = 4
1506 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1507 if (grp) current=grp->GetL3Current((AliGRPObject::Stats)statType);
1511 Float_t AliTPCcalibDB::GetBz(Int_t run){
1513 // calculate BZ in T from L3 current
1516 Float_t current=AliTPCcalibDB::GetL3Current(run);
1517 if (current>-1) bz=5*current/30000.*.1;
1521 Char_t AliTPCcalibDB::GetL3Polarity(Int_t run) {
1523 // get l3 polarity from GRP
1526 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1527 if (grp) pol=grp->GetL3Polarity();
1531 TString AliTPCcalibDB::GetRunType(Int_t run){
1533 // return run type from grp
1536 // TString type("UNKNOWN");
1537 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1538 if (grp) return grp->GetRunType();
1542 Float_t AliTPCcalibDB::GetValueGoofie(Int_t timeStamp, Int_t run, Int_t type){
1544 // GetPressure for given time stamp and runt
1546 TTimeStamp stamp(timeStamp);
1547 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(run);
1548 if (!goofieArray) return 0;
1549 AliDCSSensor *sensor = goofieArray->GetSensor(type);
1550 return sensor->GetValue(stamp);
1558 Bool_t AliTPCcalibDB::GetTemperatureFit(Int_t timeStamp, Int_t run, Int_t side,TVectorD& fit){
1560 // GetTmeparature fit at parameter for given time stamp
1562 TTimeStamp tstamp(timeStamp);
1563 AliTPCSensorTempArray* tempArray = Instance()->GetTemperatureSensor(run);
1564 if (! tempArray) return kFALSE;
1565 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
1566 TLinearFitter * fitter = tempMap->GetLinearFitter(3,side,tstamp);
1569 fitter->GetParameters(fit);
1573 if (!fitter) return kFALSE;
1577 Float_t AliTPCcalibDB::GetTemperature(Int_t timeStamp, Int_t run, Int_t side){
1579 // Get mean temperature
1583 GetTemperatureFit(timeStamp,run,0,vec);
1587 GetTemperatureFit(timeStamp,run,0,vec);
1594 Double_t AliTPCcalibDB::GetPTRelative(UInt_t timeSec, Int_t run, Int_t side){
1597 // time - absolute time
1599 // side - 0 - A side 1-C side
1600 AliTPCCalibVdrift * vdrift = Instance()->GetVdrift(run);
1601 if (!vdrift) return 0;
1602 return vdrift->GetPTRelative(timeSec,side);
1605 AliGRPObject * AliTPCcalibDB::MakeGRPObjectFromMap(TMap *map){
1607 // Function to covert old GRP run information from TMap to GRPObject
1609 // TMap * map = AliTPCcalibDB::GetGRPMap(52406);
1611 AliDCSSensor * sensor = 0;
1613 osensor = ((*map)("fP2Pressure"));
1614 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1616 if (!sensor) return 0;
1618 AliDCSSensor * sensor2 = new AliDCSSensor(*sensor);
1619 osensor = ((*map)("fCavernPressure"));
1620 TGraph * gr = new TGraph(2);
1621 gr->GetX()[0]= -100000.;
1622 gr->GetX()[1]= 1000000.;
1623 gr->GetY()[0]= atof(osensor->GetName());
1624 gr->GetY()[1]= atof(osensor->GetName());
1625 sensor2->SetGraph(gr);
1629 AliGRPObject *grpRun = new AliGRPObject;
1630 grpRun->ReadValuesFromMap(map);
1631 grpRun->SetCavernAtmosPressure(sensor2);
1632 grpRun->SetSurfaceAtmosPressure(sensor);
1636 Bool_t AliTPCcalibDB::CreateGUITree(Int_t run, const char* filename)
1639 // Create a gui tree for run number 'run'
1642 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1643 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
1644 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
1648 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
1649 // retrieve cal pad objects
1651 db->CreateGUITree(filename);
1655 Bool_t AliTPCcalibDB::CreateGUITree(const char* filename){
1659 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1660 AliError("Default Storage not set. Cannot create calibration Tree!");
1663 UpdateNonRec(); // load all infromation now
1665 AliTPCPreprocessorOnline prep;
1666 //noise and pedestals
1667 if (GetPedestals()) prep.AddComponent(new AliTPCCalPad(*(GetPedestals())));
1668 if (GetPadNoise() ) prep.AddComponent(new AliTPCCalPad(*(GetPadNoise())));
1670 if (GetPulserTmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserTmean())));
1671 if (GetPulserTrms() ) prep.AddComponent(new AliTPCCalPad(*(GetPulserTrms())));
1672 if (GetPulserQmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserQmean())));
1674 if (GetCETmean()) prep.AddComponent(new AliTPCCalPad(*(GetCETmean())));
1675 if (GetCETrms() ) prep.AddComponent(new AliTPCCalPad(*(GetCETrms())));
1676 if (GetCEQmean()) prep.AddComponent(new AliTPCCalPad(*(GetCEQmean())));
1678 if (GetALTROAcqStart() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStart() )));
1679 if (GetALTROZsThr() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROZsThr() )));
1680 if (GetALTROFPED() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROFPED() )));
1681 if (GetALTROAcqStop() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStop() )));
1682 if (GetALTROMasked() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROMasked() )));
1684 AliTPCdataQA *dataQA=GetDataQA();
1686 if (dataQA->GetNLocalMaxima())
1687 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNLocalMaxima())));
1688 if (dataQA->GetMaxCharge())
1689 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMaxCharge())));
1690 if (dataQA->GetMeanCharge())
1691 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMeanCharge())));
1692 if (dataQA->GetNoThreshold())
1693 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNoThreshold())));
1694 if (dataQA->GetNTimeBins())
1695 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNTimeBins())));
1696 if (dataQA->GetNPads())
1697 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNPads())));
1698 if (dataQA->GetTimePosition())
1699 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetTimePosition())));
1703 TString file(filename);
1704 if (file.IsNull()) file=Form("guiTreeRun_%lld.root",fRun);
1705 prep.DumpToFile(file.Data());
1709 Bool_t AliTPCcalibDB::CreateRefFile(Int_t run, const char* filename)
1712 // Create a gui tree for run number 'run'
1715 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1716 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
1717 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
1720 TString file(filename);
1721 if (file.IsNull()) file=Form("RefCalPads_%d.root",run);
1722 TDirectory *currDir=gDirectory;
1724 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
1725 // retrieve cal pad objects
1728 TFile f(file.Data(),"recreate");
1729 //noise and pedestals
1730 db->GetPedestals()->Write("Pedestals");
1731 db->GetPadNoise()->Write("PadNoise");
1733 db->GetPulserTmean()->Write("PulserTmean");
1734 db->GetPulserTrms()->Write("PulserTrms");
1735 db->GetPulserQmean()->Write("PulserQmean");
1737 db->GetCETmean()->Write("CETmean");
1738 db->GetCETrms()->Write("CETrms");
1739 db->GetCEQmean()->Write("CEQmean");
1741 db->GetALTROAcqStart() ->Write("ALTROAcqStart");
1742 db->GetALTROZsThr() ->Write("ALTROZsThr");
1743 db->GetALTROFPED() ->Write("ALTROFPED");
1744 db->GetALTROAcqStop() ->Write("ALTROAcqStop");
1745 db->GetALTROMasked() ->Write("ALTROMasked");
1754 Double_t AliTPCcalibDB::GetVDriftCorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
1756 // Get time dependent drift velocity correction
1757 // multiplication factor vd = vdnom *(1+vdriftcorr)
1759 // mode determines the algorith how to combine the Laser Track, LaserCE and physics tracks
1760 // timestamp - timestamp
1762 // side - the drift velocity per side (possible for laser and CE)
1764 // Notice - Extrapolation outside of calibration range - using constant function
1767 // mode 1 automatic mode - according to the distance to the valid calibration
1769 Double_t deltaP=0, driftP=0, wP = 0.;
1770 Double_t deltaITS=0,driftITS=0, wITS= 0.;
1771 Double_t deltaLT=0, driftLT=0, wLT = 0.;
1772 Double_t deltaCE=0, driftCE=0, wCE = 0.;
1773 driftP = fDButil->GetVDriftTPC(deltaP,run,timeStamp);
1774 driftITS= fDButil->GetVDriftTPCITS(deltaITS,run,timeStamp);
1775 driftCE = fDButil->GetVDriftTPCCE(deltaCE, run,timeStamp,36000,2);
1776 driftLT = fDButil->GetVDriftTPCLaserTracks(deltaLT,run,timeStamp,36000,2);
1777 deltaITS = TMath::Abs(deltaITS);
1778 deltaP = TMath::Abs(deltaP);
1779 deltaLT = TMath::Abs(deltaLT);
1780 deltaCE = TMath::Abs(deltaCE);
1782 const Double_t kEpsilon=0.00000000001;
1783 const Double_t kdeltaT=360.; // 10 minutes
1784 if(TMath::Abs(deltaITS) < 12*kdeltaT) {
1787 wITS = 64.*kdeltaT/(deltaITS +kdeltaT);
1788 wLT = 16.*kdeltaT/(deltaLT +kdeltaT);
1789 wP = 0. *kdeltaT/(deltaP +kdeltaT);
1790 wCE = 1. *kdeltaT/(deltaCE +kdeltaT);
1793 if (TMath::Abs(driftP)<kEpsilon) wP=0; // invalid calibration
1794 if (TMath::Abs(driftITS)<kEpsilon)wITS=0; // invalid calibration
1795 if (TMath::Abs(driftLT)<kEpsilon) wLT=0; // invalid calibration
1796 if (TMath::Abs(driftCE)<kEpsilon) wCE=0; // invalid calibration
1797 if (wP+wITS+wLT+wCE<kEpsilon) return 0;
1798 result = (driftP*wP+driftITS*wITS+driftLT*wLT+driftCE*wCE)/(wP+wITS+wLT+wCE);
1807 Double_t AliTPCcalibDB::GetTime0CorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
1809 // Get time dependent time 0 (trigger delay in cm) correction
1810 // additive correction time0 = time0+ GetTime0CorrectionTime
1811 // Value etracted combining the vdrift correction using laser tracks and CE and the physics track matchin
1813 // mode determines the algorith how to combine the Laser Track and physics tracks
1814 // timestamp - timestamp
1816 // side - the drift velocity per side (possible for laser and CE)
1818 // Notice - Extrapolation outside of calibration range - using constant function
1823 result=fDButil->GetTriggerOffsetTPC(run,timeStamp);
1824 result *=fParam->GetZLength();
1829 result= -fDButil->GetTime0TPCITS(dist, run, timeStamp)*fParam->GetDriftV()/1000000.;
1838 Double_t AliTPCcalibDB::GetVDriftCorrectionGy(Int_t timeStamp, Int_t run, Int_t side, Int_t /*mode*/){
1840 // Get global y correction drift velocity correction factor
1841 // additive factor vd = vdnom*(1+GetVDriftCorrectionGy *gy)
1842 // Value etracted combining the vdrift correction using laser tracks and CE or TPC-ITS
1844 // mode determines the algorith how to combine the Laser Track, LaserCE or TPC-ITS
1845 // timestamp - timestamp
1847 // side - the drift velocity gy correction per side (CE and Laser tracks)
1849 // Notice - Extrapolation outside of calibration range - using constant function
1851 if (run<=0 && fTransform) run = fTransform->GetCurrentRunNumber();
1852 UpdateRunInformations(run,kFALSE);
1853 TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
1854 if (!array) return 0;
1857 // use TPC-ITS if present
1858 TGraphErrors *gr= (TGraphErrors*)array->FindObject("ALIGN_ITSB_TPC_VDGY");
1860 result = AliTPCcalibDButil::EvalGraphConst(gr,timeStamp);
1862 // transform from [(cm/mus)/ m] to [1/cm]
1863 result /= (fParam->GetDriftV()/1000000.);
1866 //printf("result %e \n", result);
1870 // use laser if ITS-TPC not present
1871 TGraphErrors *laserA= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_A");
1872 TGraphErrors *laserC= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_C");
1874 if (laserA && laserC){
1875 result= (laserA->Eval(timeStamp)+laserC->Eval(timeStamp))*0.5;
1877 if (laserA && side==0){
1878 result = (laserA->Eval(timeStamp));
1880 if (laserC &&side==1){
1881 result = (laserC->Eval(timeStamp));
1883 //printf("laser result %e \n", -result/250.);
1885 return -result/250.; //normalized before
1888 AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(Double_t notInMap, const char* nameMappingFile) {
1890 // Read list of active DDLs from OCDB entry
1891 // Generate and return AliTPCCalPad containing 1 for all pads in active DDLs,
1892 // 0 for all pads in non-active DDLs.
1893 // For DDLs with missing status information (no DCS input point to Shuttle),
1894 // the value of the AliTPCCalPad entry is determined by the parameter
1895 // notInMap (default value 1)
1899 TFile *fileMapping = new TFile(nameMappingFile, "read");
1900 AliTPCmapper *mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
1902 sprintf(chinfo,"Failed to get mapping object from %s. ...\n", nameMappingFile);
1907 AliTPCCalPad *deadMap = new AliTPCCalPad("deadMap","deadMap");
1909 AliError("Failed to allocate dead map AliTPCCalPad");
1913 /// get list of active DDLs from OCDB entry
1915 if (!fALTROConfigData ) {
1916 AliError("No ALTRO config OCDB entry available");
1919 TMap *activeDDL = (TMap*)fALTROConfigData->FindObject("DDLArray");
1920 TObjString *ddlArray=0;
1922 ddlArray = (TObjString*)activeDDL->GetValue("DDLArray");
1924 AliError("Empty list of active DDLs in OCDB entry");
1928 AliError("List of active DDLs not available in OCDB entry");
1931 TString arrDDL=ddlArray->GetString();
1932 Int_t offset = mapping->GetTpcDdlOffset();
1934 for (Int_t i=0; i<mapping->GetNumDdl(); i++) {
1936 Int_t patch = mapping->GetPatchFromEquipmentID(idDDL);
1937 Int_t roc=mapping->GetRocFromEquipmentID(idDDL);
1938 AliTPCCalROC *calRoc=deadMap->GetCalROC(roc);
1940 for ( Int_t branch = 0; branch < 2; branch++ ) {
1941 for ( Int_t fec = 0; fec < mapping->GetNfec(patch, branch); fec++ ) {
1942 for ( Int_t altro = 0; altro < 8; altro++ ) {
1943 for ( Int_t channel = 0; channel < 16; channel++ ) {
1944 Int_t hwadd = mapping->CodeHWAddress(branch, fec, altro, channel);
1945 Int_t row = mapping->GetPadRow(patch, hwadd); // row in a ROC (IROC or OROC)
1946 // Int_t globalrow = mapping.GetGlobalPadRow(patch, hwadd); // row in full sector (IROC plus OROC)
1947 Int_t pad = mapping->GetPad(patch, hwadd);
1948 if (!TString(arrDDL[i]).IsDigit()) {
1951 active=TString(arrDDL[i]).Atof();
1953 calRoc->SetValue(row,pad,active);
1954 } // end channel for loop
1955 } // end altro for loop
1956 } // end fec for loop
1957 } // end branch for loop
1959 } // end loop on active DDLs
1965 AliTPCCorrection * AliTPCcalibDB::GetTPCComposedCorrection(Float_t field) const{
1967 // GetComposed correction for given field setting
1969 if (!fComposedCorrectionArray) return 0;
1970 if (field>0.1) return (AliTPCCorrection *)fComposedCorrectionArray->At(1);
1971 if (field<-0.1) return (AliTPCCorrection *)fComposedCorrectionArray->At(2);
1972 return (AliTPCCorrection *)fComposedCorrectionArray->At(0);