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"
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():
194 fTimeGainSplinesArray(100000),
195 fGRPArray(100000), //! array of GRPs - per run - JUST for calibration studies
196 fGRPMaps(100000), //! array of GRPs - per run - JUST for calibration studies
197 fGoofieArray(100000), //! array of GOOFIE values -per run - Just for calibration studies
198 fVoltageArray(100000),
199 fTemperatureArray(100000), //! array of temperature sensors - per run - Just for calibration studies
200 fVdriftArray(100000), //! array of v drift interfaces
201 fDriftCorrectionArray(100000), //! array of drift correction
202 fRunList(100000), //! run list - indicates try to get the run param
210 Update(); // temporary
213 AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
234 fTimeGainSplinesArray(100000),
235 fGRPArray(0), //! array of GRPs - per run - JUST for calibration studies
236 fGRPMaps(0), //! array of GRPs - per run - JUST for calibration studies
237 fGoofieArray(0), //! array of GOOFIE values -per run - Just for calibration studies
239 fTemperatureArray(0), //! array of temperature sensors - per run - Just for calibration studies
240 fVdriftArray(0), //! array of v drift interfaces
241 fDriftCorrectionArray(0), //! array of v drift interfaces
242 fRunList(0), //! run list - indicates try to get the run param
247 // Copy constructor invalid -- singleton implementation
249 Error("copy constructor","invalid -- singleton implementation");
252 AliTPCcalibDB& AliTPCcalibDB::operator= (const AliTPCcalibDB& )
255 // Singleton implementation - no assignment operator
257 Error("operator =", "assignment operator not implemented");
263 //_____________________________________________________________________________
264 AliTPCcalibDB::~AliTPCcalibDB()
273 //_____________________________________________________________________________
274 AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
277 // Retrieves an entry with path <cdbPath> from the CDB.
281 AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun);
284 sprintf(chinfo,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
292 //_____________________________________________________________________________
293 void AliTPCcalibDB::SetRun(Long64_t run)
296 // Sets current run number. Calibration data is read from the corresponding file.
306 void AliTPCcalibDB::Update(){
308 // cache the OCDB entries for simulation, reconstruction, calibration
311 AliCDBEntry * entry=0;
312 Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
313 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
314 fDButil = new AliTPCcalibDButil;
316 entry = GetCDBEntry("TPC/Calib/PadGainFactor");
318 //if (fPadGainFactor) delete fPadGainFactor;
319 entry->SetOwner(kTRUE);
320 fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
322 AliFatal("TPC - Missing calibration entry")
325 entry = GetCDBEntry("TPC/Calib/TimeGain");
327 //if (fTimeGainSplines) delete fTimeGainSplines;
328 entry->SetOwner(kTRUE);
329 fTimeGainSplines = (TObjArray*)entry->GetObject();
331 AliFatal("TPC - Missing calibration entry")
334 entry = GetCDBEntry("TPC/Calib/GainFactorDedx");
336 entry->SetOwner(kTRUE);
337 fDedxGainFactor = (AliTPCCalPad*)entry->GetObject();
339 AliFatal("TPC - Missing calibration entry")
342 entry = GetCDBEntry("TPC/Calib/PadTime0");
344 //if (fPadTime0) delete fPadTime0;
345 entry->SetOwner(kTRUE);
346 fPadTime0 = (AliTPCCalPad*)entry->GetObject();
348 AliFatal("TPC - Missing calibration entry")
351 entry = GetCDBEntry("TPC/Calib/Distortion");
353 //if (fPadTime0) delete fPadTime0;
354 entry->SetOwner(kTRUE);
355 fDistortionMap =(TObjArray*)entry->GetObject();
357 //AliFatal("TPC - Missing calibration entry")
363 entry = GetCDBEntry("TPC/Calib/PadNoise");
365 //if (fPadNoise) delete fPadNoise;
366 entry->SetOwner(kTRUE);
367 fPadNoise = (AliTPCCalPad*)entry->GetObject();
369 AliFatal("TPC - Missing calibration entry")
372 entry = GetCDBEntry("TPC/Calib/Pedestals");
374 //if (fPedestals) delete fPedestals;
375 entry->SetOwner(kTRUE);
376 fPedestals = (AliTPCCalPad*)entry->GetObject();
379 entry = GetCDBEntry("TPC/Calib/Temperature");
381 //if (fTemperature) delete fTemperature;
382 entry->SetOwner(kTRUE);
383 fTemperature = (AliTPCSensorTempArray*)entry->GetObject();
386 entry = GetCDBEntry("TPC/Calib/Parameters");
388 //if (fPadNoise) delete fPadNoise;
389 entry->SetOwner(kTRUE);
390 fParam = (AliTPCParam*)(entry->GetObject()->Clone());
392 AliFatal("TPC - Missing calibration entry")
395 entry = GetCDBEntry("TPC/Calib/ClusterParam");
397 entry->SetOwner(kTRUE);
398 fClusterParam = (AliTPCClusterParam*)(entry->GetObject()->Clone());
400 AliFatal("TPC - Missing calibration entry")
403 //ALTRO configuration data
404 entry = GetCDBEntry("TPC/Calib/AltroConfig");
406 entry->SetOwner(kTRUE);
407 fALTROConfigData=(TObjArray*)(entry->GetObject());
409 AliFatal("TPC - Missing calibration entry")
412 //Calibration Pulser data
413 entry = GetCDBEntry("TPC/Calib/Pulser");
415 entry->SetOwner(kTRUE);
416 fPulserData=(TObjArray*)(entry->GetObject());
420 entry = GetCDBEntry("TPC/Calib/CE");
422 entry->SetOwner(kTRUE);
423 fCEData=(TObjArray*)(entry->GetObject());
425 //RAW calibration data
426 // entry = GetCDBEntry("TPC/Calib/Raw");
428 entry = GetCDBEntry("TPC/Calib/Mapping");
430 //if (fPadNoise) delete fPadNoise;
431 entry->SetOwner(kTRUE);
432 TObjArray * array = dynamic_cast<TObjArray*>(entry->GetObject());
433 if (array && array->GetEntriesFast()==6){
434 fMapping = new AliTPCAltroMapping*[6];
435 for (Int_t i=0; i<6; i++){
436 fMapping[i] = dynamic_cast<AliTPCAltroMapping*>(array->At(i));
441 //CTP calibration data
442 entry = GetCDBEntry("GRP/CTP/CTPtiming");
444 //entry->SetOwner(kTRUE);
445 fCTPTimeParams=dynamic_cast<AliCTPTimeParams*>(entry->GetObject());
447 AliError("TPC - Missing calibration entry")
451 fTransform=new AliTPCTransform();
452 fTransform->SetCurrentRun(AliCDBManager::Instance()->GetRun());
456 AliCDBManager::Instance()->SetCacheFlag(cdbCache); // reset original CDB cache
459 void AliTPCcalibDB::UpdateNonRec(){
461 // Update/Load the parameters which are important for QA studies
462 // and not used yet for the reconstruction
464 //RAW calibration data
465 AliCDBEntry * entry=0;
466 entry = GetCDBEntry("TPC/Calib/Raw");
468 entry->SetOwner(kTRUE);
469 TObjArray *arr=(TObjArray*)(entry->GetObject());
470 if (arr) fCalibRaw=(AliTPCCalibRaw*)arr->At(0);
472 //QA calibration data
473 entry = GetCDBEntry("TPC/Calib/QA");
475 entry->SetOwner(kTRUE);
476 fDataQA=dynamic_cast<AliTPCdataQA*>(entry->GetObject());
479 entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",fRun);
481 fVoltageArray.AddAt(entry->GetObject(),fRun);
488 void AliTPCcalibDB::CreateObjectList(const Char_t *filename, TObjArray *calibObjects)
491 // Create calibration objects and read contents from OCDB
493 if ( calibObjects == 0x0 ) return;
496 if ( !in.is_open() ){
497 fprintf(stderr,"Error: cannot open list file '%s'", filename);
501 AliTPCCalPad *calPad=0x0;
507 TObjArray *arrFileLine = sFile.Tokenize("\n");
509 TIter nextLine(arrFileLine);
511 TObjString *sObjLine=0x0;
512 while ( (sObjLine = (TObjString*)nextLine()) ){
513 TString sLine(sObjLine->GetString());
515 TObjArray *arrNextCol = sLine.Tokenize("\t");
517 TObjString *sObjType = (TObjString*)(arrNextCol->At(0));
518 TObjString *sObjFileName = (TObjString*)(arrNextCol->At(1));
520 if ( !sObjType || ! sObjFileName ) continue;
521 TString sType(sObjType->GetString());
522 TString sFileName(sObjFileName->GetString());
523 printf("%s\t%s\n",sType.Data(),sFileName.Data());
525 TFile *fIn = TFile::Open(sFileName);
527 fprintf(stderr,"File not found: '%s'", sFileName.Data());
531 if ( sType == "CE" ){
532 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
534 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
535 calPad->SetNameTitle("CETmean","CETmean");
536 calibObjects->Add(calPad);
538 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
539 calPad->SetNameTitle("CEQmean","CEQmean");
540 calibObjects->Add(calPad);
542 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
543 calPad->SetNameTitle("CETrms","CETrms");
544 calibObjects->Add(calPad);
546 } else if ( sType == "Pulser") {
547 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
549 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
550 calPad->SetNameTitle("PulserTmean","PulserTmean");
551 calibObjects->Add(calPad);
553 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
554 calPad->SetNameTitle("PulserQmean","PulserQmean");
555 calibObjects->Add(calPad);
557 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
558 calPad->SetNameTitle("PulserTrms","PulserTrms");
559 calibObjects->Add(calPad);
561 } else if ( sType == "Pedestals") {
562 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
564 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
565 calPad->SetNameTitle("Pedestals","Pedestals");
566 calibObjects->Add(calPad);
568 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
569 calPad->SetNameTitle("Noise","Noise");
570 calibObjects->Add(calPad);
573 fprintf(stderr,"Undefined Type: '%s'",sType.Data());
582 void AliTPCcalibDB::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad* outlierPad, Float_t ltmFraction) {
584 // Write a tree with all available information
585 // if mapFileName is specified, the Map information are also written to the tree
586 // pads specified in outlierPad are not used for calculating statistics
587 // - the same function as AliTPCCalPad::MakeTree -
589 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
591 TObjArray* mapIROCs = 0;
592 TObjArray* mapOROCs = 0;
593 TVectorF *mapIROCArray = 0;
594 TVectorF *mapOROCArray = 0;
595 Int_t mapEntries = 0;
596 TString* mapNames = 0;
599 TFile mapFile(mapFileName, "read");
601 TList* listOfROCs = mapFile.GetListOfKeys();
602 mapEntries = listOfROCs->GetEntries()/2;
603 mapIROCs = new TObjArray(mapEntries*2);
604 mapOROCs = new TObjArray(mapEntries*2);
605 mapIROCArray = new TVectorF[mapEntries];
606 mapOROCArray = new TVectorF[mapEntries];
608 mapNames = new TString[mapEntries];
609 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
610 TString nameROC(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
611 nameROC.Remove(nameROC.Length()-4, 4);
612 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "IROC").Data()), ivalue);
613 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "OROC").Data()), ivalue);
614 mapNames[ivalue].Append(nameROC);
617 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
618 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
619 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
621 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
622 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
623 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
624 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
627 } // if (mapFileName)
629 TTreeSRedirector cstream(fileName);
630 Int_t arrayEntries = array->GetEntries();
632 TString* names = new TString[arrayEntries];
633 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
634 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
636 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
638 // get statistic for given sector
640 TVectorF median(arrayEntries);
641 TVectorF mean(arrayEntries);
642 TVectorF rms(arrayEntries);
643 TVectorF ltm(arrayEntries);
644 TVectorF ltmrms(arrayEntries);
645 TVectorF medianWithOut(arrayEntries);
646 TVectorF meanWithOut(arrayEntries);
647 TVectorF rmsWithOut(arrayEntries);
648 TVectorF ltmWithOut(arrayEntries);
649 TVectorF ltmrmsWithOut(arrayEntries);
651 TVectorF *vectorArray = new TVectorF[arrayEntries];
652 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
653 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
655 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
656 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
657 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
658 AliTPCCalROC* outlierROC = 0;
659 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
661 median[ivalue] = calROC->GetMedian();
662 mean[ivalue] = calROC->GetMean();
663 rms[ivalue] = calROC->GetRMS();
664 Double_t ltmrmsValue = 0;
665 ltm[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction);
666 ltmrms[ivalue] = ltmrmsValue;
668 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
669 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
670 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
672 ltmWithOut[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction, outlierROC);
673 ltmrmsWithOut[ivalue] = ltmrmsValue;
682 medianWithOut[ivalue] = 0.;
683 meanWithOut[ivalue] = 0.;
684 rmsWithOut[ivalue] = 0.;
685 ltmWithOut[ivalue] = 0.;
686 ltmrmsWithOut[ivalue] = 0.;
691 // fill vectors of variable per pad
693 TVectorF *posArray = new TVectorF[8];
694 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
695 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
697 Float_t posG[3] = {0};
698 Float_t posL[3] = {0};
700 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
701 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
702 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
703 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
704 posArray[0][ichannel] = irow;
705 posArray[1][ichannel] = ipad;
706 posArray[2][ichannel] = posL[0];
707 posArray[3][ichannel] = posL[1];
708 posArray[4][ichannel] = posG[0];
709 posArray[5][ichannel] = posG[1];
710 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
711 posArray[7][ichannel] = ichannel;
713 // loop over array containing AliTPCCalPads
714 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
715 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
716 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
718 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
720 (vectorArray[ivalue])[ichannel] = 0;
726 cstream << "calPads" <<
727 "sector=" << isector;
729 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
730 cstream << "calPads" <<
731 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
732 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
733 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
734 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
735 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
737 cstream << "calPads" <<
738 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
739 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
740 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
741 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
742 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
746 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
747 cstream << "calPads" <<
748 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
752 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
754 cstream << "calPads" <<
755 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
757 cstream << "calPads" <<
758 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
762 cstream << "calPads" <<
763 "row.=" << &posArray[0] <<
764 "pad.=" << &posArray[1] <<
765 "lx.=" << &posArray[2] <<
766 "ly.=" << &posArray[3] <<
767 "gx.=" << &posArray[4] <<
768 "gy.=" << &posArray[5] <<
769 "rpad.=" << &posArray[6] <<
770 "channel.=" << &posArray[7];
772 cstream << "calPads" <<
776 delete[] vectorArray;
784 delete[] mapIROCArray;
785 delete[] mapOROCArray;
790 Int_t AliTPCcalibDB::GetRCUTriggerConfig() const
793 // return the RCU trigger configuration register
795 TMap *map=GetRCUconfig();
797 TVectorF *v=(TVectorF*)map->GetValue("TRGCONF_TRG_MODE");
799 for (Int_t i=0; i<v->GetNrows(); ++i){
800 Float_t newmode=v->GetMatrixArray()[i];
802 if (mode>-1&&newmode!=mode) AliWarning("Found different RCU trigger configurations!!!");
809 Bool_t AliTPCcalibDB::IsTrgL0()
812 // return if the FEE readout was triggered on L0
814 Int_t mode=GetRCUTriggerConfig();
815 if (mode<0) return kFALSE;
819 Bool_t AliTPCcalibDB::IsTrgL1()
822 // return if the FEE readout was triggered on L1
824 Int_t mode=GetRCUTriggerConfig();
825 if (mode<0) return kFALSE;
829 void AliTPCcalibDB::RegisterExB(Int_t index, Float_t bz, Bool_t bdelete){
831 // Register static ExB correction map
832 // index - registration index - used for visualization
833 // bz - bz field in kGaus
835 // Float_t factor = bz/(-5.); // default b filed in Cheb with minus sign
836 Float_t factor = bz/(5.); // default b filed in Cheb with minus sign
837 // was chenged in the Revision ???? (Ruben can you add here number)
839 AliMagF* bmap = new AliMagF("MapsExB","MapsExB", factor,TMath::Sign(1.f,factor),AliMagF::k5kG);
841 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
842 AliTPCExB::SetInstance(exb);
847 AliTPCExB::RegisterField(index,bmap);
849 if (index>=fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
850 fgExBArray.AddAt(exb,index);
854 AliTPCExB* AliTPCcalibDB::GetExB(Float_t bz, Bool_t deleteB) {
856 // bz filed in KGaus not in tesla
857 // Get ExB correction map
858 // if doesn't exist - create it
860 Int_t index = TMath::Nint(5+bz);
861 if (index>fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
862 if (!fgExBArray.At(index)) AliTPCcalibDB::RegisterExB(index,bz,deleteB);
863 return (AliTPCExB*)fgExBArray.At(index);
867 void AliTPCcalibDB::SetExBField(Float_t bz){
869 // Set magnetic filed for ExB correction
871 fExB = GetExB(bz,kFALSE);
874 void AliTPCcalibDB::SetExBField(const AliMagF* bmap){
876 // Set magnetic field for ExB correction
878 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
879 AliTPCExB::SetInstance(exb);
887 void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
889 // - > Don't use it for reconstruction - Only for Calibration studies
892 AliCDBEntry * entry = 0;
893 if (run>= fRunList.fN){
894 fRunList.Set(run*2+1);
895 fGRPArray.Expand(run*2+1);
896 fGRPMaps.Expand(run*2+1);
897 fGoofieArray.Expand(run*2+1);
898 fVoltageArray.Expand(run*2+1);
899 fTemperatureArray.Expand(run*2+1);
900 fVdriftArray.Expand(run*2+1);
901 fDriftCorrectionArray.Expand(run*2+1);
902 fTimeGainSplinesArray.Expand(run*2+1);
905 fALTROConfigData->Expand(run*2+1); // ALTRO configuration data
906 fPulserData->Expand(run*2+1); // Calibration Pulser data
907 fCEData->Expand(run*2+1); // CE data
908 if (!fTimeGainSplines) fTimeGainSplines = new TObjArray(run*2+1);
909 fTimeGainSplines->Expand(run*2+1); // Array of AliSplineFits: at 0 MIP position in
911 if (fRunList[run]>0 &&force==kFALSE) return;
913 fRunList[run]=1; // sign as used
916 entry = AliCDBManager::Instance()->Get("GRP/GRP/Data",run);
918 AliGRPObject * grpRun = dynamic_cast<AliGRPObject*>(entry->GetObject());
920 TMap* map = dynamic_cast<TMap*>(entry->GetObject());
922 //grpRun = new AliGRPObject;
923 //grpRun->ReadValuesFromMap(map);
924 grpRun = MakeGRPObjectFromMap(map);
926 fGRPMaps.AddAt(map,run);
929 fGRPArray.AddAt(grpRun,run);
931 entry = AliCDBManager::Instance()->Get("TPC/Calib/Goofie",run);
933 fGoofieArray.AddAt(entry->GetObject(),run);
938 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeGain",run);
940 fTimeGainSplinesArray.AddAt(entry->GetObject(),run);
942 AliFatal("TPC - Missing calibration entry TimeGain")
945 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeDrift",run);
947 fDriftCorrectionArray.AddAt(entry->GetObject(),run);
949 AliFatal("TPC - Missing calibration entry TimeDrift")
952 entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
954 fTemperatureArray.AddAt(entry->GetObject(),run);
956 //apply fDButil filters
958 fDButil->UpdateFromCalibDB();
959 if (fTemperature) fDButil->FilterTemperature(fTemperature);
961 AliDCSSensor * press = GetPressureSensor(run,0);
962 AliTPCSensorTempArray * temp = GetTemperatureSensor(run);
965 accept = fDButil->FilterTemperature(temp)>0.1;
968 const Double_t kMinP=950.;
969 const Double_t kMaxP=1050.;
970 const Double_t kMaxdP=10.;
971 const Double_t kSigmaCut=4.;
972 fDButil->FilterSensor(press,kMinP,kMaxP,kMaxdP,kSigmaCut);
973 if (press->GetFit()==0) accept=kFALSE;
975 if (press && temp &&accept){
976 AliTPCCalibVdrift * vdrift = new AliTPCCalibVdrift(temp, press,0);
977 fVdriftArray.AddAt(vdrift,run);
979 fDButil->FilterCE(120., 3., 4.,0);
980 fDButil->FilterTracks(run, 10.,0);
984 Float_t AliTPCcalibDB::GetGain(Int_t sector, Int_t row, Int_t pad){
986 // Get Gain factor for given pad
988 AliTPCCalPad *calPad = Instance()->fDedxGainFactor;;
989 if (!calPad) return 0;
990 return calPad->GetCalROC(sector)->GetValue(row,pad);
993 AliSplineFit* AliTPCcalibDB::GetVdriftSplineFit(const char* name, Int_t run){
995 // GetDrift velocity spline fit
997 TObjArray *arr=GetTimeVdriftSplineRun(run);
999 return dynamic_cast<AliSplineFit*>(arr->FindObject(name));
1002 AliSplineFit* AliTPCcalibDB::CreateVdriftSplineFit(const char* graphName, Int_t run){
1004 // create spline fit from the drift time graph in TimeDrift
1006 TObjArray *arr=GetTimeVdriftSplineRun(run);
1008 TGraph *graph=dynamic_cast<TGraph*>(arr->FindObject(graphName));
1009 if (!graph) return 0;
1010 AliSplineFit *fit = new AliSplineFit();
1011 fit->SetGraph(graph);
1012 fit->SetMinPoints(graph->GetN()+1);
1013 fit->InitKnots(graph,2,0,0.001);
1018 AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
1020 // Get GRP object for given run
1022 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).At(run));
1024 Instance()->UpdateRunInformations(run);
1025 grpRun = dynamic_cast<AliGRPObject *>(Instance()->fGRPArray.At(run));
1026 if (!grpRun) return 0;
1031 TMap * AliTPCcalibDB::GetGRPMap(Int_t run){
1033 // Get GRP map for given run
1035 TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).At(run));
1037 Instance()->UpdateRunInformations(run);
1038 grpRun = dynamic_cast<TMap *>(Instance()->fGRPMaps.At(run));
1039 if (!grpRun) return 0;
1045 AliDCSSensor * AliTPCcalibDB::GetPressureSensor(Int_t run, Int_t type){
1047 // Get Pressure sensor
1049 // type = 0 - Cavern pressure
1050 // 1 - Suface pressure
1051 // First try to get if trom map - if existing (Old format of data storing)
1055 TMap *map = GetGRPMap(run);
1057 AliDCSSensor * sensor = 0;
1059 if (type==0) osensor = ((*map)("fCavernPressure"));
1060 if (type==1) osensor = ((*map)("fP2Pressure"));
1061 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1062 if (sensor) return sensor;
1065 // If not map try to get it from the GRPObject
1067 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
1069 UpdateRunInformations(run);
1070 grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
1071 if (!grpRun) return 0;
1073 AliDCSSensor * sensor = grpRun->GetCavernAtmosPressure();
1074 if (type==1) sensor = grpRun->GetSurfaceAtmosPressure();
1078 AliTPCSensorTempArray * AliTPCcalibDB::GetTemperatureSensor(Int_t run){
1080 // Get temperature sensor array
1082 AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
1084 UpdateRunInformations(run);
1085 tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
1091 TObjArray * AliTPCcalibDB::GetTimeGainSplinesRun(Int_t run){
1093 // Get temperature sensor array
1095 TObjArray * gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
1097 UpdateRunInformations(run);
1098 gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
1103 TObjArray * AliTPCcalibDB::GetTimeVdriftSplineRun(Int_t run){
1105 // Get drift spline array
1107 TObjArray * driftSplines = (TObjArray *)fDriftCorrectionArray.At(run);
1108 if (!driftSplines) {
1109 UpdateRunInformations(run);
1110 driftSplines = (TObjArray *)fDriftCorrectionArray.At(run);
1112 return driftSplines;
1115 AliDCSSensorArray * AliTPCcalibDB::GetVoltageSensors(Int_t run){
1117 // Get temperature sensor array
1119 AliDCSSensorArray * voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
1120 if (!voltageArray) {
1121 UpdateRunInformations(run);
1122 voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
1124 return voltageArray;
1127 AliDCSSensorArray * AliTPCcalibDB::GetGoofieSensors(Int_t run){
1129 // Get temperature sensor array
1131 AliDCSSensorArray * goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
1133 UpdateRunInformations(run);
1134 goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
1141 AliTPCCalibVdrift * AliTPCcalibDB::GetVdrift(Int_t run){
1143 // Get the interface to the the vdrift
1145 AliTPCCalibVdrift * vdrift = (AliTPCCalibVdrift*)fVdriftArray.At(run);
1147 UpdateRunInformations(run);
1148 vdrift= (AliTPCCalibVdrift*)fVdriftArray.At(run);
1153 Float_t AliTPCcalibDB::GetCEdriftTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
1156 // GetCE drift time information for 'sector'
1157 // sector 72 is the mean drift time of the A-Side
1158 // sector 73 is the mean drift time of the C-Side
1159 // it timestamp==-1 return mean value
1161 AliTPCcalibDB::Instance()->SetRun(run);
1162 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocTgraph(sector);
1163 if (!gr||sector<0||sector>73) {
1164 if (entries) *entries=0;
1168 if (timeStamp==-1.){
1171 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1173 gr->GetPoint(ipoint,x,y);
1174 if (x<timeStamp) continue;
1182 Float_t AliTPCcalibDB::GetCEchargeTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
1185 // GetCE mean charge for 'sector'
1186 // it timestamp==-1 return mean value
1188 AliTPCcalibDB::Instance()->SetRun(run);
1189 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocQgraph(sector);
1190 if (!gr||sector<0||sector>71) {
1191 if (entries) *entries=0;
1195 if (timeStamp==-1.){
1198 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1200 gr->GetPoint(ipoint,x,y);
1201 if (x<timeStamp) continue;
1209 Float_t AliTPCcalibDB::GetDCSSensorValue(AliDCSSensorArray *arr, Int_t timeStamp, const char * sensorName, Int_t sigDigits)
1212 // Get Value for a DCS sensor 'sensorName', run 'run' at time 'timeStamp'
1215 const TString sensorNameString(sensorName);
1216 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1217 if (!sensor) return val;
1218 //use the dcs graph if possible
1219 TGraph *gr=sensor->GetGraph();
1221 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1223 gr->GetPoint(ipoint,x,y);
1224 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1225 if (time<timeStamp) continue;
1229 //if val is still 0, test if if the requested time if within 5min of the first/last
1230 //data point. If this is the case return the firs/last entry
1231 //the timestamps might not be syncronised for all calibration types, sometimes a 'pre'
1232 //and 'pos' period is requested. Especially to the HV this is not the case!
1236 gr->GetPoint(0,x,y);
1237 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1238 if ((time-timeStamp)<5*60) val=y;
1243 gr->GetPoint(gr->GetN()-1,x,y);
1244 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1245 if ((timeStamp-time)<5*60) val=y;
1248 val=sensor->GetValue(timeStamp);
1251 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1256 Float_t AliTPCcalibDB::GetDCSSensorMeanValue(AliDCSSensorArray *arr, const char * sensorName, Int_t sigDigits)
1259 // Get mean Value for a DCS sensor 'sensorName' during run 'run'
1262 const TString sensorNameString(sensorName);
1263 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1264 if (!sensor) return val;
1266 //use dcs graph if it exists
1267 TGraph *gr=sensor->GetGraph();
1271 //if we don't have the dcs graph, try to get some meaningful information
1272 if (!sensor->GetFit()) return val;
1273 Int_t nKnots=sensor->GetFit()->GetKnots();
1274 Double_t tMid=(sensor->GetEndTime()-sensor->GetStartTime())/2.;
1275 for (Int_t iKnot=0;iKnot<nKnots;++iKnot){
1276 if (sensor->GetFit()->GetX()[iKnot]>tMid/3600.) break;
1277 val=(Float_t)sensor->GetFit()->GetY0()[iKnot];
1282 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1288 Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits) {
1290 // return the chamber HV for given run and time: 0-35 IROC, 36-72 OROC
1291 // if timeStamp==-1 return mean value
1294 TString sensorName="";
1295 TTimeStamp stamp(timeStamp);
1296 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1297 if (!voltageArray || (sector<0) || (sector>71)) return val;
1298 Char_t sideName='A';
1299 if ((sector/18)%2==1) sideName='C';
1302 sensorName=Form("TPC_ANODE_I_%c%02d_VMEAS",sideName,sector%18);
1305 sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,sector%18);
1308 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1310 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1314 Float_t AliTPCcalibDB::GetSkirtVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1317 // Get the skirt voltage for 'run' at 'timeStamp' and 'sector': 0-35 IROC, 36-72 OROC
1318 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1319 // if timeStamp==-1 return the mean value for the run
1322 TString sensorName="";
1323 TTimeStamp stamp(timeStamp);
1324 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1325 if (!voltageArray || (sector<0) || (sector>71)) return val;
1326 Char_t sideName='A';
1327 if ((sector/18)%2==1) sideName='C';
1328 sensorName=Form("TPC_SKIRT_%c_VMEAS",sideName);
1330 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1332 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1337 Float_t AliTPCcalibDB::GetCoverVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1340 // Get the cover voltage for run 'run' at time 'timeStamp'
1341 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1342 // if timeStamp==-1 return the mean value for the run
1345 TString sensorName="";
1346 TTimeStamp stamp(timeStamp);
1347 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1348 if (!voltageArray || (sector<0) || (sector>71)) return val;
1349 Char_t sideName='A';
1350 if ((sector/18)%2==1) sideName='C';
1353 sensorName=Form("TPC_COVER_I_%c_VMEAS",sideName);
1356 sensorName=Form("TPC_COVER_O_%c_VMEAS",sideName);
1359 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1361 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1366 Float_t AliTPCcalibDB::GetGGoffsetVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1369 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1370 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1371 // if timeStamp==-1 return the mean value for the run
1374 TString sensorName="";
1375 TTimeStamp stamp(timeStamp);
1376 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1377 if (!voltageArray || (sector<0) || (sector>71)) return val;
1378 Char_t sideName='A';
1379 if ((sector/18)%2==1) sideName='C';
1382 sensorName=Form("TPC_GATE_I_%c_OFF_VMEAS",sideName);
1385 sensorName=Form("TPC_GATE_O_%c_OFF_VMEAS",sideName);
1388 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1390 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1395 Float_t AliTPCcalibDB::GetGGnegVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1398 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1399 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1400 // if timeStamp==-1 return the mean value for the run
1403 TString sensorName="";
1404 TTimeStamp stamp(timeStamp);
1405 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1406 if (!voltageArray || (sector<0) || (sector>71)) return val;
1407 Char_t sideName='A';
1408 if ((sector/18)%2==1) sideName='C';
1411 sensorName=Form("TPC_GATE_I_%c_NEG_VMEAS",sideName);
1414 sensorName=Form("TPC_GATE_O_%c_NEG_VMEAS",sideName);
1417 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1419 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1424 Float_t AliTPCcalibDB::GetGGposVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1427 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1428 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1429 // if timeStamp==-1 return the mean value for the run
1432 TString sensorName="";
1433 TTimeStamp stamp(timeStamp);
1434 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1435 if (!voltageArray || (sector<0) || (sector>71)) return val;
1436 Char_t sideName='A';
1437 if ((sector/18)%2==1) sideName='C';
1440 sensorName=Form("TPC_GATE_I_%c_POS_VMEAS",sideName);
1443 sensorName=Form("TPC_GATE_O_%c_POS_VMEAS",sideName);
1446 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1448 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1453 Float_t AliTPCcalibDB::GetPressure(Int_t timeStamp, Int_t run, Int_t type){
1455 // GetPressure for given time stamp and runt
1457 TTimeStamp stamp(timeStamp);
1458 AliDCSSensor * sensor = Instance()->GetPressureSensor(run,type);
1459 if (!sensor) return 0;
1460 return sensor->GetValue(stamp);
1463 Float_t AliTPCcalibDB::GetL3Current(Int_t run, Int_t statType){
1465 // return L3 current
1466 // stat type is: AliGRPObject::Stats: kMean = 0, kTruncMean = 1, kMedian = 2, kSDMean = 3, kSDMedian = 4
1469 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1470 if (grp) current=grp->GetL3Current((AliGRPObject::Stats)statType);
1474 Float_t AliTPCcalibDB::GetBz(Int_t run){
1476 // calculate BZ in T from L3 current
1479 Float_t current=AliTPCcalibDB::GetL3Current(run);
1480 if (current>-1) bz=5*current/30000.*.1;
1484 Char_t AliTPCcalibDB::GetL3Polarity(Int_t run) {
1486 // get l3 polarity from GRP
1489 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1490 if (grp) pol=grp->GetL3Polarity();
1494 TString AliTPCcalibDB::GetRunType(Int_t run){
1496 // return run type from grp
1499 // TString type("UNKNOWN");
1500 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1501 if (grp) return grp->GetRunType();
1505 Float_t AliTPCcalibDB::GetValueGoofie(Int_t timeStamp, Int_t run, Int_t type){
1507 // GetPressure for given time stamp and runt
1509 TTimeStamp stamp(timeStamp);
1510 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(run);
1511 if (!goofieArray) return 0;
1512 AliDCSSensor *sensor = goofieArray->GetSensor(type);
1513 return sensor->GetValue(stamp);
1521 Bool_t AliTPCcalibDB::GetTemperatureFit(Int_t timeStamp, Int_t run, Int_t side,TVectorD& fit){
1523 // GetTmeparature fit at parameter for given time stamp
1525 TTimeStamp tstamp(timeStamp);
1526 AliTPCSensorTempArray* tempArray = Instance()->GetTemperatureSensor(run);
1527 if (! tempArray) return kFALSE;
1528 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
1529 TLinearFitter * fitter = tempMap->GetLinearFitter(3,side,tstamp);
1532 fitter->GetParameters(fit);
1536 if (!fitter) return kFALSE;
1540 Float_t AliTPCcalibDB::GetTemperature(Int_t timeStamp, Int_t run, Int_t side){
1542 // Get mean temperature
1546 GetTemperatureFit(timeStamp,run,0,vec);
1550 GetTemperatureFit(timeStamp,run,0,vec);
1557 Double_t AliTPCcalibDB::GetPTRelative(UInt_t timeSec, Int_t run, Int_t side){
1560 // time - absolute time
1562 // side - 0 - A side 1-C side
1563 AliTPCCalibVdrift * vdrift = Instance()->GetVdrift(run);
1564 if (!vdrift) return 0;
1565 return vdrift->GetPTRelative(timeSec,side);
1568 AliGRPObject * AliTPCcalibDB::MakeGRPObjectFromMap(TMap *map){
1570 // Function to covert old GRP run information from TMap to GRPObject
1572 // TMap * map = AliTPCcalibDB::GetGRPMap(52406);
1574 AliDCSSensor * sensor = 0;
1576 osensor = ((*map)("fP2Pressure"));
1577 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1579 if (!sensor) return 0;
1581 AliDCSSensor * sensor2 = new AliDCSSensor(*sensor);
1582 osensor = ((*map)("fCavernPressure"));
1583 TGraph * gr = new TGraph(2);
1584 gr->GetX()[0]= -100000.;
1585 gr->GetX()[1]= 1000000.;
1586 gr->GetY()[0]= atof(osensor->GetName());
1587 gr->GetY()[1]= atof(osensor->GetName());
1588 sensor2->SetGraph(gr);
1592 AliGRPObject *grpRun = new AliGRPObject;
1593 grpRun->ReadValuesFromMap(map);
1594 grpRun->SetCavernAtmosPressure(sensor2);
1595 grpRun->SetSurfaceAtmosPressure(sensor);
1599 Bool_t AliTPCcalibDB::CreateGUITree(Int_t run, const char* filename)
1602 // Create a gui tree for run number 'run'
1605 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1606 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
1607 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
1611 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
1612 // retrieve cal pad objects
1614 db->CreateGUITree(filename);
1618 Bool_t AliTPCcalibDB::CreateGUITree(const char* filename){
1622 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1623 AliError("Default Storage not set. Cannot create calibration Tree!");
1626 UpdateNonRec(); // load all infromation now
1628 AliTPCPreprocessorOnline prep;
1629 //noise and pedestals
1630 if (GetPedestals()) prep.AddComponent(new AliTPCCalPad(*(GetPedestals())));
1631 if (GetPadNoise() ) prep.AddComponent(new AliTPCCalPad(*(GetPadNoise())));
1633 if (GetPulserTmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserTmean())));
1634 if (GetPulserTrms() ) prep.AddComponent(new AliTPCCalPad(*(GetPulserTrms())));
1635 if (GetPulserQmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserQmean())));
1637 if (GetCETmean()) prep.AddComponent(new AliTPCCalPad(*(GetCETmean())));
1638 if (GetCETrms() ) prep.AddComponent(new AliTPCCalPad(*(GetCETrms())));
1639 if (GetCEQmean()) prep.AddComponent(new AliTPCCalPad(*(GetCEQmean())));
1641 if (GetALTROAcqStart() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStart() )));
1642 if (GetALTROZsThr() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROZsThr() )));
1643 if (GetALTROFPED() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROFPED() )));
1644 if (GetALTROAcqStop() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStop() )));
1645 if (GetALTROMasked() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROMasked() )));
1647 AliTPCdataQA *dataQA=GetDataQA();
1649 if (dataQA->GetNLocalMaxima())
1650 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNLocalMaxima())));
1651 if (dataQA->GetMaxCharge())
1652 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMaxCharge())));
1653 if (dataQA->GetMeanCharge())
1654 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMeanCharge())));
1655 if (dataQA->GetNoThreshold())
1656 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNoThreshold())));
1657 if (dataQA->GetNTimeBins())
1658 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNTimeBins())));
1659 if (dataQA->GetNPads())
1660 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNPads())));
1661 if (dataQA->GetTimePosition())
1662 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetTimePosition())));
1666 TString file(filename);
1667 if (file.IsNull()) file=Form("guiTreeRun_%d.root",fRun);
1668 prep.DumpToFile(file.Data());
1672 Bool_t AliTPCcalibDB::CreateRefFile(Int_t run, const char* filename)
1675 // Create a gui tree for run number 'run'
1678 if (!AliCDBManager::Instance()->GetDefaultStorage()){
1679 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
1680 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
1683 TString file(filename);
1684 if (file.IsNull()) file=Form("RefCalPads_%d.root",run);
1685 TDirectory *currDir=gDirectory;
1687 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
1688 // retrieve cal pad objects
1691 TFile f(file.Data(),"recreate");
1692 //noise and pedestals
1693 db->GetPedestals()->Write("Pedestals");
1694 db->GetPadNoise()->Write("PadNoise");
1696 db->GetPulserTmean()->Write("PulserTmean");
1697 db->GetPulserTrms()->Write("PulserTrms");
1698 db->GetPulserQmean()->Write("PulserQmean");
1700 db->GetCETmean()->Write("CETmean");
1701 db->GetCETrms()->Write("CETrms");
1702 db->GetCEQmean()->Write("CEQmean");
1704 db->GetALTROAcqStart() ->Write("ALTROAcqStart");
1705 db->GetALTROZsThr() ->Write("ALTROZsThr");
1706 db->GetALTROFPED() ->Write("ALTROFPED");
1707 db->GetALTROAcqStop() ->Write("ALTROAcqStop");
1708 db->GetALTROMasked() ->Write("ALTROMasked");
1717 Double_t AliTPCcalibDB::GetVDriftCorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
1719 // Get time dependent drift velocity correction
1720 // multiplication factor vd = vdnom *(1+vdriftcorr)
1722 // mode determines the algorith how to combine the Laser Track, LaserCE and physics tracks
1723 // timestamp - timestamp
1725 // side - the drift velocity per side (possible for laser and CE)
1727 // Notice - Extrapolation outside of calibration range - using constant function
1730 // mode 1 automatic mode - according to the distance to the valid calibration
1732 Double_t deltaP=0, driftP=0, wP = 0.;
1733 Double_t deltaITS=0,driftITS=0, wITS= 0.;
1734 Double_t deltaLT=0, driftLT=0, wLT = 0.;
1735 Double_t deltaCE=0, driftCE=0, wCE = 0.;
1736 driftP = fDButil->GetVDriftTPC(deltaP,run,timeStamp);
1737 driftITS= fDButil->GetVDriftTPCITS(deltaITS,run,timeStamp);
1738 driftCE = fDButil->GetVDriftTPCCE(deltaCE, run,timeStamp,36000,2);
1739 driftLT = fDButil->GetVDriftTPCLaserTracks(deltaLT,run,timeStamp,36000,2);
1740 deltaITS = TMath::Abs(deltaITS);
1741 deltaP = TMath::Abs(deltaP);
1742 deltaLT = TMath::Abs(deltaLT);
1743 deltaCE = TMath::Abs(deltaCE);
1745 const Double_t kEpsilon=0.00000000001;
1746 const Double_t kdeltaT=360.; // 10 minutes
1747 wITS = 64.*kdeltaT/(deltaITS +kdeltaT);
1748 wLT = 16.*kdeltaT/(deltaLT +kdeltaT);
1749 wP = 0. *kdeltaT/(deltaP +kdeltaT);
1750 wCE = 1. *kdeltaT/(deltaCE +kdeltaT);
1753 if (TMath::Abs(driftP)<kEpsilon) wP=0; // invalid calibration
1754 if (TMath::Abs(driftITS)<kEpsilon)wITS=0; // invalid calibration
1755 if (TMath::Abs(driftLT)<kEpsilon) wLT=0; // invalid calibration
1756 if (TMath::Abs(driftCE)<kEpsilon) wCE=0; // invalid calibration
1757 if (wP+wITS+wLT+wCE<kEpsilon) return 0;
1758 result = (driftP*wP+driftITS*wITS+driftLT*wLT+driftCE*wCE)/(wP+wITS+wLT+wCE);
1764 Double_t AliTPCcalibDB::GetTime0CorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
1766 // Get time dependent time 0 (trigger delay in cm) correction
1767 // additive correction time0 = time0+ GetTime0CorrectionTime
1768 // Value etracted combining the vdrift correction using laser tracks and CE and the physics track matchin
1770 // mode determines the algorith how to combine the Laser Track and physics tracks
1771 // timestamp - timestamp
1773 // side - the drift velocity per side (possible for laser and CE)
1775 // Notice - Extrapolation outside of calibration range - using constant function
1780 result=fDButil->GetTriggerOffsetTPC(run,timeStamp);
1781 result *=fParam->GetZLength();
1786 result= -fDButil->GetTime0TPCITS(dist, run, timeStamp)*fParam->GetDriftV()/1000000.;
1795 Double_t AliTPCcalibDB::GetVDriftCorrectionGy(Int_t timeStamp, Int_t run, Int_t side, Int_t /*mode*/){
1797 // Get global y correction drift velocity correction factor
1798 // additive factor vd = vdnom*(1+GetVDriftCorrectionGy *gy)
1799 // Value etracted combining the vdrift correction using laser tracks and CE
1801 // mode determines the algorith how to combine the Laser Track, LaserCE
1802 // timestamp - timestamp
1804 // side - the drift velocity gy correction per side (CE and Laser tracks)
1806 // Notice - Extrapolation outside of calibration range - using constant function
1808 if (run<=0 && fTransform) run = fTransform->GetCurrentRunNumber();
1809 UpdateRunInformations(run,kFALSE);
1810 TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
1811 if (!array) return 0;
1812 TGraphErrors *laserA= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_A");
1813 TGraphErrors *laserC= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_C");
1816 if (laserA && laserC){
1817 result= (laserA->Eval(timeStamp)+laserC->Eval(timeStamp))*0.5;
1819 if (laserA && side==0){
1820 result = (laserA->Eval(timeStamp));
1822 if (laserC &&side==1){
1823 result = (laserC->Eval(timeStamp));
1825 return -result/250.; //normalized before
1828 AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(const char* nameMappingFile) {
1830 // Read list of active DDLs from OCDB entry
1831 // Generate and return AliTPCCalPad containing 1 for all pads in active DDLs,
1832 // 0 for all pads in non-active DDLs.
1836 TFile *fileMapping = new TFile(nameMappingFile, "read");
1837 AliTPCmapper *mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
1839 sprintf(chinfo,"Failed to get mapping object from %s. ...\n", nameMappingFile);
1844 AliTPCCalPad *deadMap = new AliTPCCalPad("deadMap","deadMap");
1846 AliError("Failed to allocate dead map AliTPCCalPad");
1850 /// get list of active DDLs from OCDB entry
1852 if (!fALTROConfigData ) {
1853 AliError("No ALTRO config OCDB entry available");
1856 TMap *activeDDL = (TMap*)fALTROConfigData->FindObject("DDLArray");
1857 TObjString *ddlArray=0;
1859 ddlArray = (TObjString*)activeDDL->GetValue("DDLArray");
1861 AliError("Empty list of active DDLs in OCDB entry");
1865 AliError("List of active DDLs not available in OCDB entry");
1868 TString arrDDL=ddlArray->GetString();
1869 Int_t offset = mapping->GetTpcDdlOffset();
1871 for (Int_t i=0; i<mapping->GetNumDdl(); i++) {
1873 Int_t patch = mapping->GetPatchFromEquipmentID(idDDL);
1874 Int_t roc=mapping->GetRocFromEquipmentID(idDDL);
1875 AliTPCCalROC *calRoc=deadMap->GetCalROC(roc);
1877 for ( Int_t branch = 0; branch < 2; branch++ ) {
1878 for ( Int_t fec = 0; fec < mapping->GetNfec(patch, branch); fec++ ) {
1879 for ( Int_t altro = 0; altro < 8; altro++ ) {
1880 for ( Int_t channel = 0; channel < 16; channel++ ) {
1881 Int_t hwadd = mapping->CodeHWAddress(branch, fec, altro, channel);
1882 Int_t row = mapping->GetPadRow(patch, hwadd); // row in a ROC (IROC or OROC)
1883 // Int_t globalrow = mapping.GetGlobalPadRow(patch, hwadd); // row in full sector (IROC plus OROC)
1884 Int_t pad = mapping->GetPad(patch, hwadd);
1885 active=TString(arrDDL[i]).Atof();
1886 calRoc->SetValue(row,pad,active);
1887 } // end channel for loop
1888 } // end altro for loop
1889 } // end fec for loop
1890 } // end branch for loop
1892 } // end loop on active DDLs