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 - AliTPCclusterer::Digits2Clusters(AliRawReader* rawReader)
31 // 1.) pad by pad calibration - AliTPCCalPad
34 // Simulation: AliTPCDigitizer::ExecFast - Multiply by gain
35 // Reconstruction : AliTPCclusterer::Digits2Clusters - Divide by gain
38 // Simulation: AliTPCDigitizer::ExecFast
39 // Reconstruction: AliTPCclusterer::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 AliTPCclusterer::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 // AliTPCclusterer::AddCluster
64 // AliTPCtracker::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 "AliTPCComposedCorrection.h"
129 #include "AliTPCPreprocessorOnline.h"
130 #include "AliTimeStamp.h"
131 #include "AliTriggerRunScalers.h"
132 #include "AliTriggerScalers.h"
133 #include "AliTriggerScalersRecord.h"
135 ClassImp(AliTPCcalibDB)
137 AliTPCcalibDB* AliTPCcalibDB::fgInstance = 0;
138 Bool_t AliTPCcalibDB::fgTerminated = kFALSE;
139 TObjArray AliTPCcalibDB::fgExBArray; // array of ExB corrections
142 //_ singleton implementation __________________________________________________
143 AliTPCcalibDB* AliTPCcalibDB::Instance()
146 // Singleton implementation
147 // Returns an instance of this class, it is created if necessary
150 if (fgTerminated != kFALSE)
154 fgInstance = new AliTPCcalibDB();
159 void AliTPCcalibDB::Terminate()
162 // Singleton implementation
163 // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
164 // This function can be called several times.
167 fgTerminated = kTRUE;
176 //_____________________________________________________________________________
177 AliTPCcalibDB::AliTPCcalibDB():
183 fActiveChannelMap(0),
187 fComposedCorrection(0),
188 fComposedCorrectionArray(0),
205 fTimeGainSplinesArray(1),
206 fGRPArray(1), //! array of GRPs - per run - JUST for calibration studies
207 fGRPMaps(1), //! array of GRPs - per run - JUST for calibration studies
208 fGoofieArray(1), //! array of GOOFIE values -per run - Just for calibration studies
210 fTemperatureArray(1), //! array of temperature sensors - per run - Just for calibration studies
211 fVdriftArray(1), //! array of v drift interfaces
212 fDriftCorrectionArray(1), //! array of drift correction
213 fRunList(1), //! run list - indicates try to get the run param
214 fBHasAlignmentOCDB(kFALSE), // Flag - has the alignment on the composed correction ?
224 for (Int_t i=0;i<72;++i){
225 fChamberHVStatus[i]=kTRUE;
226 fChamberHVmedian[i]=-1;
227 fCurrentNominalVoltage[i]=0.;
228 fChamberHVgoodFraction[i]=0.;
230 Update(); // temporary
231 fTimeGainSplinesArray.SetOwner(); //own the keys
232 fGRPArray.SetOwner(); //own the keys
233 fGRPMaps.SetOwner(); //own the keys
234 fGoofieArray.SetOwner(); //own the keys
235 fVoltageArray.SetOwner(); //own the keys
236 fTemperatureArray.SetOwner(); //own the keys
237 fVdriftArray.SetOwner(); //own the keys
238 fDriftCorrectionArray.SetOwner(); //own the keys
241 AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
247 fActiveChannelMap(0),
251 fComposedCorrection(0),
252 fComposedCorrectionArray(0),
269 fTimeGainSplinesArray(1),
270 fGRPArray(0), //! array of GRPs - per run - JUST for calibration studies
271 fGRPMaps(0), //! array of GRPs - per run - JUST for calibration studies
272 fGoofieArray(0), //! array of GOOFIE values -per run - Just for calibration studies
274 fTemperatureArray(0), //! array of temperature sensors - per run - Just for calibration studies
275 fVdriftArray(0), //! array of v drift interfaces
276 fDriftCorrectionArray(0), //! array of v drift corrections
277 fRunList(0), //! run list - indicates try to get the run param
278 fBHasAlignmentOCDB(kFALSE), // Flag - has the alignment on the composed correction ?
284 // Copy constructor invalid -- singleton implementation
286 Error("copy constructor","invalid -- singleton implementation");
287 for (Int_t i=0;i<72;++i){
288 fChamberHVStatus[i]=kTRUE;
289 fChamberHVmedian[i]=-1;
290 fCurrentNominalVoltage[i]=0.;
291 fChamberHVgoodFraction[i]=0.;
293 fTimeGainSplinesArray.SetOwner(); //own the keys
294 fGRPArray.SetOwner(); //own the keys
295 fGRPMaps.SetOwner(); //own the keys
296 fGoofieArray.SetOwner(); //own the keys
297 fVoltageArray.SetOwner(); //own the keys
298 fTemperatureArray.SetOwner(); //own the keys
299 fVdriftArray.SetOwner(); //own the keys
300 fDriftCorrectionArray.SetOwner(); //own the keys
303 AliTPCcalibDB& AliTPCcalibDB::operator= (const AliTPCcalibDB& )
306 // Singleton implementation - no assignment operator
308 Error("operator =", "assignment operator not implemented");
314 //_____________________________________________________________________________
315 AliTPCcalibDB::~AliTPCcalibDB()
321 delete fActiveChannelMap;
324 AliTPCCalPad* AliTPCcalibDB::GetDistortionMap(Int_t i) const {
326 // get distortion map - due E field distortions
328 return (fDistortionMap) ? (AliTPCCalPad*)fDistortionMap->At(i):0;
331 AliTPCRecoParam* AliTPCcalibDB::GetRecoParam(Int_t i) const {
332 return (fRecoParamList) ? (AliTPCRecoParam*)fRecoParamList->At(i):0;
335 //_____________________________________________________________________________
336 AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
339 // Retrieves an entry with path <cdbPath> from the CDB.
343 AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun);
346 snprintf(chinfo,1000,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
354 //_____________________________________________________________________________
355 void AliTPCcalibDB::SetRun(Long64_t run)
358 // Sets current run number. Calibration data is read from the corresponding file.
368 void AliTPCcalibDB::Update(){
370 // cache the OCDB entries for simulation, reconstruction, calibration
373 AliCDBEntry * entry=0;
374 Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
375 AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
376 fDButil = new AliTPCcalibDButil;
378 fRun = AliCDBManager::Instance()->GetRun();
380 entry = GetCDBEntry("TPC/Calib/PadGainFactor");
382 //if (fPadGainFactor) delete fPadGainFactor;
383 entry->SetOwner(kTRUE);
384 fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
386 AliFatal("TPC - Missing calibration entry TPC/Calib/PadGainFactor");
389 entry = GetCDBEntry("TPC/Calib/TimeGain");
391 //if (fTimeGainSplines) delete fTimeGainSplines;
392 entry->SetOwner(kTRUE);
393 fTimeGainSplines = (TObjArray*)entry->GetObject();
395 AliFatal("TPC - Missing calibration entry TPC/Calib/Timegain");
398 entry = GetCDBEntry("TPC/Calib/GainFactorDedx");
400 entry->SetOwner(kTRUE);
401 fDedxGainFactor = (AliTPCCalPad*)entry->GetObject();
403 AliFatal("TPC - Missing calibration entry TPC/Calib/gainFactordEdx");
406 entry = GetCDBEntry("TPC/Calib/PadTime0");
408 //if (fPadTime0) delete fPadTime0;
409 entry->SetOwner(kTRUE);
410 fPadTime0 = (AliTPCCalPad*)entry->GetObject();
412 AliFatal("TPC - Missing calibration entry");
415 entry = GetCDBEntry("TPC/Calib/Distortion");
417 //if (fPadTime0) delete fPadTime0;
418 entry->SetOwner(kTRUE);
419 fDistortionMap =dynamic_cast<TObjArray*>(entry->GetObject());
421 //AliFatal("TPC - Missing calibration entry")
427 entry = GetCDBEntry("TPC/Calib/PadNoise");
429 //if (fPadNoise) delete fPadNoise;
430 entry->SetOwner(kTRUE);
431 fPadNoise = (AliTPCCalPad*)entry->GetObject();
433 AliFatal("TPC - Missing calibration entry");
436 entry = GetCDBEntry("TPC/Calib/Pedestals");
438 //if (fPedestals) delete fPedestals;
439 entry->SetOwner(kTRUE);
440 fPedestals = (AliTPCCalPad*)entry->GetObject();
443 entry = GetCDBEntry("TPC/Calib/Temperature");
445 //if (fTemperature) delete fTemperature;
446 entry->SetOwner(kTRUE);
447 fTemperature = (AliTPCSensorTempArray*)entry->GetObject();
450 entry = GetCDBEntry("TPC/Calib/Parameters");
452 //if (fPadNoise) delete fPadNoise;
453 entry->SetOwner(kTRUE);
454 fParam = (AliTPCParam*)(entry->GetObject());
456 AliFatal("TPC - Missing calibration entry TPC/Calib/Parameters");
459 entry = GetCDBEntry("TPC/Calib/ClusterParam");
461 entry->SetOwner(kTRUE);
462 fClusterParam = (AliTPCClusterParam*)(entry->GetObject());
464 AliFatal("TPC - Missing calibration entry");
467 entry = GetCDBEntry("TPC/Calib/RecoParam");
469 entry->SetOwner(kTRUE);
470 fRecoParamList = dynamic_cast<TObjArray*>(entry->GetObject());
473 AliFatal("TPC - Missing calibration entry TPC/Calib/RecoParam");
477 //ALTRO configuration data
478 entry = GetCDBEntry("TPC/Calib/AltroConfig");
480 entry->SetOwner(kTRUE);
481 fALTROConfigData=(TObjArray*)(entry->GetObject());
483 AliFatal("TPC - Missing calibration entry");
486 //Calibration Pulser data
487 entry = GetCDBEntry("TPC/Calib/Pulser");
489 entry->SetOwner(kTRUE);
490 fPulserData=(TObjArray*)(entry->GetObject());
493 //Calibration ION tail data
494 // entry = GetCDBEntry("TPC/Calib/IonTail");
496 // entry->SetOwner(kTRUE);
497 // fIonTailArray=(TObjArray*)(entry->GetObject());
502 entry = GetCDBEntry("TPC/Calib/CE");
504 entry->SetOwner(kTRUE);
505 fCEData=(TObjArray*)(entry->GetObject());
507 //RAW calibration data
508 // entry = GetCDBEntry("TPC/Calib/Raw");
510 entry = GetCDBEntry("TPC/Calib/Mapping");
512 //if (fPadNoise) delete fPadNoise;
513 entry->SetOwner(kTRUE);
514 TObjArray * array = dynamic_cast<TObjArray*>(entry->GetObject());
515 if (array && array->GetEntriesFast()==6){
516 fMapping = new AliTPCAltroMapping*[6];
517 for (Int_t i=0; i<6; i++){
518 fMapping[i] = dynamic_cast<AliTPCAltroMapping*>(array->At(i));
523 //CTP calibration data
524 entry = GetCDBEntry("GRP/CTP/CTPtiming");
526 //entry->SetOwner(kTRUE);
527 fCTPTimeParams=dynamic_cast<AliCTPTimeParams*>(entry->GetObject());
529 AliError("TPC - Missing calibration entry");
531 //TPC space point correction data
532 entry = GetCDBEntry("TPC/Calib/Correction");
534 //entry->SetOwner(kTRUE);
535 fComposedCorrection=dynamic_cast<AliTPCCorrection*>(entry->GetObject());
536 if (fComposedCorrection) fComposedCorrection->Init();
537 fComposedCorrectionArray=dynamic_cast<TObjArray*>(entry->GetObject());
538 if (fComposedCorrectionArray){
539 for (Int_t i=0; i<fComposedCorrectionArray->GetEntries(); i++){
540 AliTPCComposedCorrection* composedCorrection= dynamic_cast<AliTPCComposedCorrection*>(fComposedCorrectionArray->At(i));
541 if (composedCorrection) {
542 composedCorrection->Init();
543 if (composedCorrection->GetCorrections()){
544 if (composedCorrection->GetCorrections()->FindObject("FitAlignTPC")){
545 fBHasAlignmentOCDB=kTRUE;
552 AliError("TPC - Missing calibration entry- TPC/Calib/Correction");
554 //RCU trigger config mode
555 fMode=GetRCUTriggerConfig();
558 fTransform=new AliTPCTransform();
559 fTransform->SetCurrentRun(AliCDBManager::Instance()->GetRun());
563 // needs to be called before InitDeadMap
564 UpdateChamberHighVoltageData();
566 // Create Dead Channel Map
570 AliCDBManager::Instance()->SetCacheFlag(cdbCache); // reset original CDB cache
573 void AliTPCcalibDB::UpdateNonRec(){
575 // Update/Load the parameters which are important for QA studies
576 // and not used yet for the reconstruction
578 //RAW calibration data
579 AliCDBEntry * entry=0;
580 entry = GetCDBEntry("TPC/Calib/Raw");
582 entry->SetOwner(kTRUE);
583 TObjArray *arr=dynamic_cast<TObjArray*>(entry->GetObject());
584 if (arr) fCalibRaw=(AliTPCCalibRaw*)arr->At(0);
585 else fCalibRaw = (AliTPCCalibRaw*)(entry->GetObject());
587 //QA calibration data
588 entry = GetCDBEntry("TPC/Calib/QA");
590 entry->SetOwner(kTRUE);
591 fDataQA=dynamic_cast<AliTPCdataQA*>(entry->GetObject());
594 if (fRun>=0 && !fVoltageArray.GetValue(Form("%i",fRun))){
595 entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",fRun);
597 fVoltageArray.Add(new TObjString(Form("%i",fRun)),entry->GetObject());
605 void AliTPCcalibDB::CreateObjectList(const Char_t *filename, TObjArray *calibObjects)
608 // Create calibration objects and read contents from OCDB
610 if ( calibObjects == 0x0 ) return;
613 if ( !in.is_open() ){
614 fprintf(stderr,"Error: cannot open list file '%s'", filename);
618 AliTPCCalPad *calPad=0x0;
624 TObjArray *arrFileLine = sFile.Tokenize("\n");
626 TIter nextLine(arrFileLine);
628 TObjString *sObjLine=0x0;
629 while ( (sObjLine = (TObjString*)nextLine()) ){
630 TString sLine(sObjLine->GetString());
632 TObjArray *arrNextCol = sLine.Tokenize("\t");
634 TObjString *sObjType = (TObjString*)(arrNextCol->At(0));
635 TObjString *sObjFileName = (TObjString*)(arrNextCol->At(1));
638 if ( !sObjType || ! sObjFileName ) continue;
639 TString sType(sObjType->GetString());
640 TString sFileName(sObjFileName->GetString());
641 // printf("%s\t%s\n",sType.Data(),sFileName.Data());
643 TFile *fIn = TFile::Open(sFileName);
645 fprintf(stderr,"File not found: '%s'", sFileName.Data());
649 if ( sType == "CE" ){
650 AliTPCCalibCE *ce = (AliTPCCalibCE*)fIn->Get("AliTPCCalibCE");
652 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadT0());
653 calPad->SetNameTitle("CETmean","CETmean");
654 calibObjects->Add(calPad);
656 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadQ());
657 calPad->SetNameTitle("CEQmean","CEQmean");
658 calibObjects->Add(calPad);
660 calPad = new AliTPCCalPad((TObjArray*)ce->GetCalPadRMS());
661 calPad->SetNameTitle("CETrms","CETrms");
662 calibObjects->Add(calPad);
664 } else if ( sType == "Pulser") {
665 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fIn->Get("AliTPCCalibPulser");
667 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadT0());
668 calPad->SetNameTitle("PulserTmean","PulserTmean");
669 calibObjects->Add(calPad);
671 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadQ());
672 calPad->SetNameTitle("PulserQmean","PulserQmean");
673 calibObjects->Add(calPad);
675 calPad = new AliTPCCalPad((TObjArray*)sig->GetCalPadRMS());
676 calPad->SetNameTitle("PulserTrms","PulserTrms");
677 calibObjects->Add(calPad);
679 } else if ( sType == "Pedestals") {
680 AliTPCCalibPedestal *ped = (AliTPCCalibPedestal*)fIn->Get("AliTPCCalibPedestal");
682 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadPedestal());
683 calPad->SetNameTitle("Pedestals","Pedestals");
684 calibObjects->Add(calPad);
686 calPad = new AliTPCCalPad((TObjArray*)ped->GetCalPadRMS());
687 calPad->SetNameTitle("Noise","Noise");
688 calibObjects->Add(calPad);
691 fprintf(stderr,"Undefined Type: '%s'",sType.Data());
699 Int_t AliTPCcalibDB::InitDeadMap() {
700 // Initialize DeadChannel Map
701 // Source of information:
702 // - HV (see UpdateChamberHighVoltageData())
703 // - Altro disabled channels. Noisy channels.
706 // check necessary information
707 const Int_t run=GetRun();
709 AliError("run not set in CDB manager. Cannot create active channel map");
712 AliDCSSensorArray* voltageArray = GetVoltageSensors(run);
713 AliTPCCalPad* altroMap = GetALTROMasked();
714 TMap* mapddl = GetDDLMap();
716 if (!voltageArray && !altroMap && !mapddl) {
717 AliError("All necessary information to create the activate channel are map missing.");
721 //=============================================================
724 Bool_t ddlMap[216]={0};
725 for (Int_t iddl=0; iddl<216; ++iddl) ddlMap[iddl]=1;
727 TObjString *s = (TObjString*)mapddl->GetValue("DDLArray");
729 for (Int_t iddl=0; iddl<216; ++iddl) ddlMap[iddl]=TString(s->GetString()(iddl))!="0";
732 AliError("DDL map missing. ActiveChannelMap can only be created with parts of the information.");
734 // Setup DDL map done
735 // ============================================================
737 //=============================================================
738 // Setup active chnnel map
741 if (!fActiveChannelMap) fActiveChannelMap=new AliTPCCalPad("ActiveChannelMap","ActiveChannelMap");
743 AliTPCmapper map(gSystem->ExpandPathName("$ALICE_ROOT/TPC/mapping/"));
745 if (!altroMap) AliError("ALTRO dead channel map missing. ActiveChannelMap can only be created with parts of the information.");
747 for (Int_t iROC=0;iROC<AliTPCCalPad::kNsec;++iROC){
748 AliTPCCalROC *roc=fActiveChannelMap->GetCalROC(iROC);
750 AliError(Form("No ROC %d in active channel map",iROC));
754 // check for bad voltage
755 // see UpdateChamberHighVoltageData()
756 if (!fChamberHVStatus[iROC]){
761 AliTPCCalROC *masked=0x0;
762 if (altroMap) masked=altroMap->GetCalROC(iROC);
764 for (UInt_t irow=0; irow<roc->GetNrows(); ++irow){
765 for (UInt_t ipad=0; ipad<roc->GetNPads(irow); ++ipad){
766 //per default the channel is on
767 roc->SetValue(irow,ipad,1);
768 // apply altro dead channel mask (inverse logik, it is not active, but inactive channles)
769 if (masked && masked->GetValue(irow, ipad)) roc->SetValue(irow, ipad ,0);
770 // mask channels if a DDL is inactive
771 Int_t ddlId=map.GetEquipmentID(iROC, irow, ipad)-768;
772 if (ddlId>=0 && !ddlMap[ddlId]) roc->SetValue(irow, ipad ,0);
780 void AliTPCcalibDB::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad* outlierPad, Float_t ltmFraction) {
782 // Write a tree with all available information
783 // if mapFileName is specified, the Map information are also written to the tree
784 // pads specified in outlierPad are not used for calculating statistics
785 // - the same function as AliTPCCalPad::MakeTree -
787 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
789 TObjArray* mapIROCs = 0;
790 TObjArray* mapOROCs = 0;
791 TVectorF *mapIROCArray = 0;
792 TVectorF *mapOROCArray = 0;
793 Int_t mapEntries = 0;
794 TString* mapNames = 0;
797 TFile mapFile(mapFileName, "read");
799 TList* listOfROCs = mapFile.GetListOfKeys();
800 mapEntries = listOfROCs->GetEntries()/2;
801 mapIROCs = new TObjArray(mapEntries*2);
802 mapOROCs = new TObjArray(mapEntries*2);
803 mapIROCArray = new TVectorF[mapEntries];
804 mapOROCArray = new TVectorF[mapEntries];
806 mapNames = new TString[mapEntries];
807 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
808 TString nameROC(((TKey*)(listOfROCs->At(ivalue*2)))->GetName());
809 nameROC.Remove(nameROC.Length()-4, 4);
810 mapIROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "IROC").Data()), ivalue);
811 mapOROCs->AddAt((AliTPCCalROC*)mapFile.Get((nameROC + "OROC").Data()), ivalue);
812 mapNames[ivalue].Append(nameROC);
815 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
816 mapIROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(0));
817 mapOROCArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(36));
819 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(0); ichannel++)
820 (mapIROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapIROCs->At(ivalue)))->GetValue(ichannel);
821 for (UInt_t ichannel = 0; ichannel < tpcROCinstance->GetNChannels(36); ichannel++)
822 (mapOROCArray[ivalue])[ichannel] = ((AliTPCCalROC*)(mapOROCs->At(ivalue)))->GetValue(ichannel);
825 } // if (mapFileName)
827 TTreeSRedirector cstream(fileName);
828 Int_t arrayEntries = array->GetEntries();
830 TString* names = new TString[arrayEntries];
831 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
832 names[ivalue].Append(((AliTPCCalPad*)array->At(ivalue))->GetName());
834 for (UInt_t isector = 0; isector < tpcROCinstance->GetNSectors(); isector++) {
836 // get statistic for given sector
838 TVectorF median(arrayEntries);
839 TVectorF mean(arrayEntries);
840 TVectorF rms(arrayEntries);
841 TVectorF ltm(arrayEntries);
842 TVectorF ltmrms(arrayEntries);
843 TVectorF medianWithOut(arrayEntries);
844 TVectorF meanWithOut(arrayEntries);
845 TVectorF rmsWithOut(arrayEntries);
846 TVectorF ltmWithOut(arrayEntries);
847 TVectorF ltmrmsWithOut(arrayEntries);
849 TVectorF *vectorArray = new TVectorF[arrayEntries];
850 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++)
851 vectorArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
853 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
854 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
855 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
856 AliTPCCalROC* outlierROC = 0;
857 if (outlierPad) outlierROC = outlierPad->GetCalROC(isector);
859 median[ivalue] = calROC->GetMedian();
860 mean[ivalue] = calROC->GetMean();
861 rms[ivalue] = calROC->GetRMS();
862 Double_t ltmrmsValue = 0;
863 ltm[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction);
864 ltmrms[ivalue] = ltmrmsValue;
866 medianWithOut[ivalue] = calROC->GetMedian(outlierROC);
867 meanWithOut[ivalue] = calROC->GetMean(outlierROC);
868 rmsWithOut[ivalue] = calROC->GetRMS(outlierROC);
870 ltmWithOut[ivalue] = calROC->GetLTM(<mrmsValue, ltmFraction, outlierROC);
871 ltmrmsWithOut[ivalue] = ltmrmsValue;
880 medianWithOut[ivalue] = 0.;
881 meanWithOut[ivalue] = 0.;
882 rmsWithOut[ivalue] = 0.;
883 ltmWithOut[ivalue] = 0.;
884 ltmrmsWithOut[ivalue] = 0.;
889 // fill vectors of variable per pad
891 TVectorF *posArray = new TVectorF[8];
892 for (Int_t ivalue = 0; ivalue < 8; ivalue++)
893 posArray[ivalue].ResizeTo(tpcROCinstance->GetNChannels(isector));
895 Float_t posG[3] = {0};
896 Float_t posL[3] = {0};
898 for (UInt_t irow = 0; irow < tpcROCinstance->GetNRows(isector); irow++) {
899 for (UInt_t ipad = 0; ipad < tpcROCinstance->GetNPads(isector, irow); ipad++) {
900 tpcROCinstance->GetPositionLocal(isector, irow, ipad, posL);
901 tpcROCinstance->GetPositionGlobal(isector, irow, ipad, posG);
902 posArray[0][ichannel] = irow;
903 posArray[1][ichannel] = ipad;
904 posArray[2][ichannel] = posL[0];
905 posArray[3][ichannel] = posL[1];
906 posArray[4][ichannel] = posG[0];
907 posArray[5][ichannel] = posG[1];
908 posArray[6][ichannel] = (Int_t)(ipad - (Double_t)(tpcROCinstance->GetNPads(isector, irow))/2);
909 posArray[7][ichannel] = ichannel;
911 // loop over array containing AliTPCCalPads
912 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
913 AliTPCCalPad* calPad = (AliTPCCalPad*) array->At(ivalue);
914 AliTPCCalROC* calROC = calPad->GetCalROC(isector);
916 (vectorArray[ivalue])[ichannel] = calROC->GetValue(irow, ipad);
918 (vectorArray[ivalue])[ichannel] = 0;
924 cstream << "calPads" <<
925 "sector=" << isector;
927 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
928 cstream << "calPads" <<
929 (Char_t*)((names[ivalue] + "_Median=").Data()) << median[ivalue] <<
930 (Char_t*)((names[ivalue] + "_Mean=").Data()) << mean[ivalue] <<
931 (Char_t*)((names[ivalue] + "_RMS=").Data()) << rms[ivalue] <<
932 (Char_t*)((names[ivalue] + "_LTM=").Data()) << ltm[ivalue] <<
933 (Char_t*)((names[ivalue] + "_RMS_LTM=").Data()) << ltmrms[ivalue];
935 cstream << "calPads" <<
936 (Char_t*)((names[ivalue] + "_Median_OutlierCutted=").Data()) << medianWithOut[ivalue] <<
937 (Char_t*)((names[ivalue] + "_Mean_OutlierCutted=").Data()) << meanWithOut[ivalue] <<
938 (Char_t*)((names[ivalue] + "_RMS_OutlierCutted=").Data()) << rmsWithOut[ivalue] <<
939 (Char_t*)((names[ivalue] + "_LTM_OutlierCutted=").Data()) << ltmWithOut[ivalue] <<
940 (Char_t*)((names[ivalue] + "_RMS_LTM_OutlierCutted=").Data()) << ltmrmsWithOut[ivalue];
944 for (Int_t ivalue = 0; ivalue < arrayEntries; ivalue++) {
945 cstream << "calPads" <<
946 (Char_t*)((names[ivalue] + ".=").Data()) << &vectorArray[ivalue];
950 for (Int_t ivalue = 0; ivalue < mapEntries; ivalue++) {
952 cstream << "calPads" <<
953 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapIROCArray[ivalue];
955 cstream << "calPads" <<
956 (Char_t*)((mapNames[ivalue] + ".=").Data()) << &mapOROCArray[ivalue];
960 cstream << "calPads" <<
961 "row.=" << &posArray[0] <<
962 "pad.=" << &posArray[1] <<
963 "lx.=" << &posArray[2] <<
964 "ly.=" << &posArray[3] <<
965 "gx.=" << &posArray[4] <<
966 "gy.=" << &posArray[5] <<
967 "rpad.=" << &posArray[6] <<
968 "channel.=" << &posArray[7];
970 cstream << "calPads" <<
974 delete[] vectorArray;
982 delete[] mapIROCArray;
983 delete[] mapOROCArray;
988 Int_t AliTPCcalibDB::GetRCUTriggerConfig() const
991 // return the RCU trigger configuration register
993 TMap *map=GetRCUconfig();
995 TVectorF *v=(TVectorF*)map->GetValue("TRGCONF_TRG_MODE");
997 for (Int_t i=0; i<v->GetNrows(); ++i){
998 Float_t newmode=v->GetMatrixArray()[i];
1000 if (mode>-1&&newmode!=mode) AliWarning("Found different RCU trigger configurations!!!");
1007 Bool_t AliTPCcalibDB::IsTrgL0()
1010 // return if the FEE readout was triggered on L0
1012 if (fMode<0) return kFALSE;
1016 Bool_t AliTPCcalibDB::IsTrgL1()
1019 // return if the FEE readout was triggered on L1
1021 if (fMode<0) return kFALSE;
1025 void AliTPCcalibDB::RegisterExB(Int_t index, Float_t bz, Bool_t bdelete){
1027 // Register static ExB correction map
1028 // index - registration index - used for visualization
1029 // bz - bz field in kGaus
1031 // Float_t factor = bz/(-5.); // default b filed in Cheb with minus sign
1032 Float_t factor = bz/(5.); // default b filed in Cheb with minus sign
1033 // was chenged in the Revision ???? (Ruben can you add here number)
1035 AliMagF* bmap = new AliMagF("MapsExB","MapsExB", factor,TMath::Sign(1.f,factor),AliMagF::k5kG);
1037 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
1038 AliTPCExB::SetInstance(exb);
1043 AliTPCExB::RegisterField(index,bmap);
1045 if (index>=fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
1046 fgExBArray.AddAt(exb,index);
1050 AliTPCExB* AliTPCcalibDB::GetExB(Float_t bz, Bool_t deleteB) {
1052 // bz filed in KGaus not in tesla
1053 // Get ExB correction map
1054 // if doesn't exist - create it
1056 Int_t index = TMath::Nint(5+bz);
1057 if (index>fgExBArray.GetEntries()) fgExBArray.Expand((index+1)*2+11);
1058 if (!fgExBArray.At(index)) AliTPCcalibDB::RegisterExB(index,bz,deleteB);
1059 return (AliTPCExB*)fgExBArray.At(index);
1063 void AliTPCcalibDB::SetExBField(Float_t bz){
1065 // Set magnetic filed for ExB correction
1067 fExB = GetExB(bz,kFALSE);
1070 void AliTPCcalibDB::SetExBField(const AliMagF* bmap){
1072 // Set magnetic field for ExB correction
1074 AliTPCExBFirst *exb = new AliTPCExBFirst(bmap,0.88*2.6400e+04,50,50,50);
1075 AliTPCExB::SetInstance(exb);
1081 void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
1083 // - > Don't use it for reconstruction - Only for Calibration studies
1086 TObjString runstr(Form("%i",run));
1088 AliCDBEntry * entry = 0;
1089 if (run>= fRunList.fN){
1090 fRunList.Set(run*2+1);
1093 fALTROConfigData->Expand(run*2+1); // ALTRO configuration data
1094 fPulserData->Expand(run*2+1); // Calibration Pulser data
1095 fCEData->Expand(run*2+1); // CE data
1096 if (!fTimeGainSplines) fTimeGainSplines = new TObjArray(run*2+1);
1097 fTimeGainSplines->Expand(run*2+1); // Array of AliSplineFits: at 0 MIP position in
1099 if (fRunList[run]>0 &&force==kFALSE) return;
1101 fRunList[run]=1; // sign as used
1104 entry = AliCDBManager::Instance()->Get("GRP/GRP/Data",run);
1106 AliGRPObject * grpRun = dynamic_cast<AliGRPObject*>(entry->GetObject());
1108 TMap* map = dynamic_cast<TMap*>(entry->GetObject());
1110 //grpRun = new AliGRPObject;
1111 //grpRun->ReadValuesFromMap(map);
1112 grpRun = MakeGRPObjectFromMap(map);
1114 fGRPMaps.Add(new TObjString(runstr),map);
1117 fGRPArray.Add(new TObjString(runstr),grpRun);
1119 entry = AliCDBManager::Instance()->Get("TPC/Calib/Goofie",run);
1121 fGoofieArray.Add(new TObjString(runstr),entry->GetObject());
1126 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeGain",run);
1128 fTimeGainSplinesArray.Add(new TObjString(runstr),entry->GetObject());
1130 AliFatal("TPC - Missing calibration entry TimeGain");
1133 entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeDrift",run);
1135 TObjArray * timeArray = (TObjArray*)entry->GetObject();
1136 fDriftCorrectionArray.Add(new TObjString(runstr),entry->GetObject());
1137 AliTPCCorrection * correctionTime = (AliTPCCorrection *)timeArray->FindObject("FitCorrectionTime");
1138 if (correctionTime && fComposedCorrectionArray){
1139 correctionTime->Init();
1140 if (fComposedCorrectionArray->GetEntriesFast()<4) fComposedCorrectionArray->Expand(40);
1141 fComposedCorrectionArray->AddAt(correctionTime,4); //add time dependent correction to the list of available corrections
1144 AliFatal("TPC - Missing calibration entry TimeDrift");
1147 entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
1149 fTemperatureArray.Add(new TObjString(runstr),entry->GetObject());
1153 entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",run);
1154 if (!fVoltageArray.GetValue(runstr.GetName()) && entry) {
1155 fVoltageArray.Add(new TObjString(runstr),entry->GetObject());
1158 //apply fDButil filters
1160 fDButil->UpdateFromCalibDB();
1161 if (fTemperature) fDButil->FilterTemperature(fTemperature);
1163 AliDCSSensor * press = GetPressureSensor(run,0);
1164 AliTPCSensorTempArray * temp = GetTemperatureSensor(run);
1165 Bool_t accept=kTRUE;
1167 accept = fDButil->FilterTemperature(temp)>0.1;
1170 const Double_t kMinP=900.;
1171 const Double_t kMaxP=1050.;
1172 const Double_t kMaxdP=10.;
1173 const Double_t kSigmaCut=4.;
1174 fDButil->FilterSensor(press,kMinP,kMaxP,kMaxdP,kSigmaCut);
1175 if (press->GetFit()==0) accept=kFALSE;
1178 if (press && temp &&accept){
1179 AliTPCCalibVdrift * vdrift = new AliTPCCalibVdrift(temp, press,0);
1180 fVdriftArray.Add(new TObjString(runstr),vdrift);
1183 fDButil->FilterCE(120., 3., 4.,0);
1184 fDButil->FilterTracks(run, 10.,0);
1189 Float_t AliTPCcalibDB::GetGain(Int_t sector, Int_t row, Int_t pad){
1191 // Get Gain factor for given pad
1193 AliTPCCalPad *calPad = Instance()->fDedxGainFactor;;
1194 if (!calPad) return 0;
1195 return calPad->GetCalROC(sector)->GetValue(row,pad);
1198 AliSplineFit* AliTPCcalibDB::GetVdriftSplineFit(const char* name, Int_t run){
1200 // GetDrift velocity spline fit
1202 TObjArray *arr=GetTimeVdriftSplineRun(run);
1204 return dynamic_cast<AliSplineFit*>(arr->FindObject(name));
1207 AliSplineFit* AliTPCcalibDB::CreateVdriftSplineFit(const char* graphName, Int_t run){
1209 // create spline fit from the drift time graph in TimeDrift
1211 TObjArray *arr=GetTimeVdriftSplineRun(run);
1213 TGraph *graph=dynamic_cast<TGraph*>(arr->FindObject(graphName));
1214 if (!graph) return 0;
1215 AliSplineFit *fit = new AliSplineFit();
1216 fit->SetGraph(graph);
1217 fit->SetMinPoints(graph->GetN()+1);
1218 fit->InitKnots(graph,2,0,0.001);
1223 AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
1225 // Get GRP object for given run
1227 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).GetValue(Form("%i",run)));
1229 Instance()->UpdateRunInformations(run);
1230 grpRun = dynamic_cast<AliGRPObject *>(Instance()->fGRPArray.GetValue(Form("%i",run)));
1231 if (!grpRun) return 0;
1236 TMap * AliTPCcalibDB::GetGRPMap(Int_t run){
1238 // Get GRP map for given run
1240 TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).GetValue(Form("%i",run)));
1242 Instance()->UpdateRunInformations(run);
1243 grpRun = dynamic_cast<TMap *>(Instance()->fGRPMaps.GetValue(Form("%i",run)));
1244 if (!grpRun) return 0;
1250 AliDCSSensor * AliTPCcalibDB::GetPressureSensor(Int_t run, Int_t type){
1252 // Get Pressure sensor
1254 // type = 0 - Cavern pressure
1255 // 1 - Suface pressure
1256 // First try to get if trom map - if existing (Old format of data storing)
1260 TMap *map = GetGRPMap(run);
1262 AliDCSSensor * sensor = 0;
1264 if (type==0) osensor = ((*map)("fCavernPressure"));
1265 if (type==1) osensor = ((*map)("fP2Pressure"));
1266 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1267 if (sensor) return sensor;
1270 // If not map try to get it from the GRPObject
1272 AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.GetValue(Form("%i",run)));
1274 UpdateRunInformations(run);
1275 grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.GetValue(Form("%i",run)));
1276 if (!grpRun) return 0;
1278 AliDCSSensor * sensor = grpRun->GetCavernAtmosPressure();
1279 if (type==1) sensor = grpRun->GetSurfaceAtmosPressure();
1283 AliTPCSensorTempArray * AliTPCcalibDB::GetTemperatureSensor(Int_t run){
1285 // Get temperature sensor array
1287 AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)fTemperatureArray.GetValue(Form("%i",run));
1289 UpdateRunInformations(run);
1290 tempArray = (AliTPCSensorTempArray *)fTemperatureArray.GetValue(Form("%i",run));
1296 TObjArray * AliTPCcalibDB::GetTimeGainSplinesRun(Int_t run){
1298 // Get temperature sensor array
1300 TObjArray * gainSplines = (TObjArray *)fTimeGainSplinesArray.GetValue(Form("%i",run));
1302 UpdateRunInformations(run);
1303 gainSplines = (TObjArray *)fTimeGainSplinesArray.GetValue(Form("%i",run));
1308 TObjArray * AliTPCcalibDB::GetTimeVdriftSplineRun(Int_t run){
1310 // Get drift spline array
1312 TObjArray * driftSplines = (TObjArray *)fDriftCorrectionArray.GetValue(Form("%i",run));
1313 if (!driftSplines) {
1314 UpdateRunInformations(run);
1315 driftSplines = (TObjArray *)fDriftCorrectionArray.GetValue(Form("%i",run));
1317 return driftSplines;
1320 AliDCSSensorArray * AliTPCcalibDB::GetVoltageSensors(Int_t run){
1322 // Get temperature sensor array
1324 AliDCSSensorArray * voltageArray = (AliDCSSensorArray *)fVoltageArray.GetValue(Form("%i",run));
1325 if (!voltageArray) {
1326 UpdateRunInformations(run);
1327 voltageArray = (AliDCSSensorArray *)fVoltageArray.GetValue(Form("%i",run));
1329 return voltageArray;
1332 AliDCSSensorArray * AliTPCcalibDB::GetGoofieSensors(Int_t run){
1334 // Get temperature sensor array
1336 AliDCSSensorArray * goofieArray = (AliDCSSensorArray *)fGoofieArray.GetValue(Form("%i",run));
1338 UpdateRunInformations(run);
1339 goofieArray = (AliDCSSensorArray *)fGoofieArray.GetValue(Form("%i",run));
1346 AliTPCCalibVdrift * AliTPCcalibDB::GetVdrift(Int_t run){
1348 // Get the interface to the the vdrift
1350 AliTPCCalibVdrift * vdrift = (AliTPCCalibVdrift*)fVdriftArray.GetValue(Form("%i",run));
1352 UpdateRunInformations(run);
1353 vdrift= (AliTPCCalibVdrift*)fVdriftArray.GetValue(Form("%i",run));
1358 Float_t AliTPCcalibDB::GetCEdriftTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
1361 // GetCE drift time information for 'sector'
1362 // sector 72 is the mean drift time of the A-Side
1363 // sector 73 is the mean drift time of the C-Side
1364 // it timestamp==-1 return mean value
1366 AliTPCcalibDB::Instance()->SetRun(run);
1367 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocTgraph(sector);
1368 if (!gr||sector<0||sector>73) {
1369 if (entries) *entries=0;
1373 if (timeStamp==-1.){
1376 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1378 gr->GetPoint(ipoint,x,y);
1379 if (x<timeStamp) continue;
1387 Float_t AliTPCcalibDB::GetCEchargeTime(Int_t run, Int_t sector, Double_t timeStamp, Int_t *entries)
1390 // GetCE mean charge for 'sector'
1391 // it timestamp==-1 return mean value
1393 AliTPCcalibDB::Instance()->SetRun(run);
1394 TGraph *gr=AliTPCcalibDB::Instance()->GetCErocQgraph(sector);
1395 if (!gr||sector<0||sector>71) {
1396 if (entries) *entries=0;
1400 if (timeStamp==-1.){
1403 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1405 gr->GetPoint(ipoint,x,y);
1406 if (x<timeStamp) continue;
1414 Float_t AliTPCcalibDB::GetDCSSensorValue(AliDCSSensorArray *arr, Int_t timeStamp, const char * sensorName, Int_t sigDigits)
1417 // Get Value for a DCS sensor 'sensorName', run 'run' at time 'timeStamp'
1420 const TString sensorNameString(sensorName);
1421 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1422 if (!sensor) return val;
1423 //use the dcs graph if possible
1424 TGraph *gr=sensor->GetGraph();
1426 for (Int_t ipoint=0;ipoint<gr->GetN();++ipoint){
1428 gr->GetPoint(ipoint,x,y);
1429 Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1430 if (time<timeStamp) continue;
1434 //if val is still 0, test if if the requested time if within 5min of the first/last
1435 //data point. If this is the case return the firs/last entry
1436 //the timestamps might not be syncronised for all calibration types, sometimes a 'pre'
1437 //and 'pos' period is requested. Especially to the HV this is not the case!
1441 gr->GetPoint(0,x,y);
1442 const Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1443 const Int_t dtime=time-timeStamp;
1444 if ( (dtime>0) && (dtime<5*60) ) val=y;
1449 gr->GetPoint(gr->GetN()-1,x,y);
1450 const Int_t time=TMath::Nint(sensor->GetStartTime()+x*3600); //time in graph is hours
1451 const Int_t dtime=timeStamp-time;
1452 if ( (dtime>0) && (dtime<5*60) ) val=y;
1455 val=sensor->GetValue(timeStamp);
1458 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1463 Float_t AliTPCcalibDB::GetDCSSensorMeanValue(AliDCSSensorArray *arr, const char * sensorName, Int_t sigDigits)
1466 // Get mean Value for a DCS sensor 'sensorName' during run 'run'
1469 const TString sensorNameString(sensorName);
1470 AliDCSSensor *sensor = arr->GetSensor(sensorNameString);
1471 if (!sensor) return val;
1473 //use dcs graph if it exists
1474 TGraph *gr=sensor->GetGraph();
1478 //if we don't have the dcs graph, try to get some meaningful information
1479 if (!sensor->GetFit()) return val;
1480 Int_t nKnots=sensor->GetFit()->GetKnots();
1481 Double_t tMid=(sensor->GetEndTime()-sensor->GetStartTime())/2.;
1482 for (Int_t iKnot=0;iKnot<nKnots;++iKnot){
1483 if (sensor->GetFit()->GetX()[iKnot]>tMid/3600.) break;
1484 val=(Float_t)sensor->GetFit()->GetY0()[iKnot];
1489 val=(Float_t)TMath::Floor(val * TMath::Power(10., sigDigits) + .5) / TMath::Power(10., sigDigits);
1495 Bool_t AliTPCcalibDB::IsDataTakingActive(time_t timeStamp)
1497 if (!fGrRunState) return kFALSE;
1498 Double_t time=Double_t(timeStamp);
1499 Int_t currentPoint=0;
1500 Bool_t currentVal=fGrRunState->GetY()[currentPoint]>0.5;
1501 Bool_t retVal=currentVal;
1502 Double_t currentTime=fGrRunState->GetX()[currentPoint];
1504 while (time>currentTime){
1506 if (currentPoint==fGrRunState->GetN()) break;
1507 currentVal=fGrRunState->GetY()[currentPoint]>0.5;
1508 currentTime=fGrRunState->GetX()[currentPoint];
1515 void AliTPCcalibDB::UpdateChamberHighVoltageData()
1518 // set chamber high voltage data
1519 // 1. Robust median (sampling the hv graphs over time)
1520 // 2. Current nominal voltages (nominal voltage corrected for common HV offset)
1521 // 3. Fraction of good HV values over time (deviation from robust median)
1522 // 4. HV status, based on the above
1525 // start and end time of the run
1526 const Int_t run=GetRun();
1529 // if no valid run information - return
1530 AliGRPObject* grp = GetGRP(run);
1533 const Int_t startTimeGRP = grp->GetTimeStart();
1534 const Int_t stopTimeGRP = grp->GetTimeEnd();
1537 // check active state by analysing the scalers
1539 // initialise graph with active running
1540 AliCDBEntry *entry = GetCDBEntry("GRP/CTP/Scalers");
1542 // entry->SetOwner(kTRUE);
1543 AliTriggerRunScalers *sca = (AliTriggerRunScalers*)entry->GetObject();
1544 Int_t nchannels = sca->GetNumClasses(); // number of scaler channels (i.e. trigger classes)
1545 Int_t npoints = sca->GetScalersRecords()->GetEntries(); // number of samples
1548 fGrRunState=new TGraph;
1549 fGrRunState->SetPoint(fGrRunState->GetN(),Double_t(startTimeGRP)-.001,0);
1550 fGrRunState->SetPoint(fGrRunState->GetN(),Double_t(startTimeGRP),1);
1551 ULong64_t lastSum=0;
1552 Double_t timeLast=0.;
1553 Bool_t active=kTRUE;
1554 for (int i=0; i<npoints; i++) {
1555 AliTriggerScalersRecord *rec = (AliTriggerScalersRecord *) sca->GetScalersRecord(i);
1556 Double_t time = ((AliTimeStamp*) rec->GetTimeStamp())->GetSeconds();
1558 for (int j=0; j<nchannels; j++) sum += ((AliTriggerScalers*) rec->GetTriggerScalers()->At(j))->GetL2CA();
1559 if (TMath::Abs(time-timeLast)<.001 && sum==lastSum ) continue;
1560 if (active && sum==lastSum){
1561 fGrRunState->SetPoint(fGrRunState->GetN(),timeLast-.01,1);
1562 fGrRunState->SetPoint(fGrRunState->GetN(),timeLast,0);
1564 } else if (!active && sum>lastSum ){
1565 fGrRunState->SetPoint(fGrRunState->GetN(),timeLast-.01,0);
1566 fGrRunState->SetPoint(fGrRunState->GetN(),timeLast,1);
1572 fGrRunState->SetPoint(fGrRunState->GetN(),Double_t(stopTimeGRP),active);
1573 fGrRunState->SetPoint(fGrRunState->GetN(),Double_t(stopTimeGRP)+.001,0);
1578 for (Int_t iROC=0;iROC<72;++iROC) {
1579 fChamberHVmedian[iROC] = -1;
1580 fChamberHVgoodFraction[iROC] = 0.;
1581 fCurrentNominalVoltage[iROC] = -999.;
1582 fChamberHVStatus[iROC] = kFALSE;
1585 AliDCSSensorArray* voltageArray = GetVoltageSensors(run);
1586 if (!voltageArray) {
1587 AliError("Voltage Array missing. Cannot calculate HV information!");
1591 // max HV diffs before a chamber is masked
1592 const Float_t maxVdiff = fParam->GetMaxVoltageDeviation();
1593 const Float_t maxDipVoltage = fParam->GetMaxDipVoltage();
1594 const Float_t maxFracHVbad = fParam->GetMaxFractionHVbad();
1596 const Int_t samplingPeriod=1;
1598 // array with sampled voltages
1599 const Int_t maxSamples=(stopTimeGRP-startTimeGRP)/samplingPeriod + 10*samplingPeriod;
1600 Float_t *vSampled = new Float_t[maxSamples];
1602 // deviation of the median from the nominal voltage
1603 Double_t chamberMedianDeviation[72]={0.};
1605 for (Int_t iROC=0; iROC<72; ++iROC){
1606 chamberMedianDeviation[iROC]=0.;
1607 TString sensorName="";
1608 Char_t sideName='A';
1609 if ((iROC/18)%2==1) sideName='C';
1610 if (iROC<36) sensorName=Form("TPC_ANODE_I_%c%02d_VMEAS",sideName,iROC%18);
1611 else sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,iROC%18);
1613 AliDCSSensor *sensor = voltageArray->GetSensor(sensorName);
1615 fHVsensors[iROC]=sensor;
1616 if (!sensor) continue;
1618 Int_t nPointsSampled=0;
1620 TGraph *gr=sensor->GetGraph();
1621 if ( gr && gr->GetN()>1 ){
1622 //1. sample voltage over time
1623 // get a robust median
1624 // buffer sampled voltages
1626 // current sampling time
1627 Int_t time=startTimeGRP;
1629 // input graph sampling point
1630 const Int_t nGraph=gr->GetN();
1633 //initialise graph information
1634 Int_t timeGraph=TMath::Nint(gr->GetX()[pointGraph+1]*3600+sensor->GetStartTime());
1635 Double_t sampledHV=gr->GetY()[pointGraph++];
1637 while (time<stopTimeGRP){
1638 while (timeGraph<=time && pointGraph+1<nGraph){
1639 timeGraph=TMath::Nint(gr->GetX()[pointGraph+1]*3600+sensor->GetStartTime());
1640 sampledHV=gr->GetY()[pointGraph++];
1642 time+=samplingPeriod;
1643 if (!IsDataTakingActive(time-samplingPeriod)) continue;
1644 vSampled[nPointsSampled++]=sampledHV;
1647 if (nPointsSampled<1) continue;
1649 fChamberHVmedian[iROC]=TMath::Median(nPointsSampled,vSampled);
1650 chamberMedianDeviation[iROC]=fChamberHVmedian[iROC]-fParam->GetNominalVoltage(iROC);
1652 //2. calculate good HV fraction
1654 for (Int_t ipoint=0; ipoint<nPointsSampled; ++ipoint) {
1655 if (TMath::Abs(vSampled[ipoint]-fChamberHVmedian[iROC])<maxDipVoltage) ++ngood;
1658 fChamberHVgoodFraction[iROC]=Float_t(ngood)/Float_t(nPointsSampled);
1660 AliError(Form("No Graph or too few points found for HV sensor of ROC %d",iROC));
1667 // get median deviation from all chambers (detect e.g. -50V)
1668 const Double_t medianIROC=TMath::Median( 36, chamberMedianDeviation );
1669 const Double_t medianOROC=TMath::Median( 36, chamberMedianDeviation+36 );
1671 // Define current default voltages
1672 for (Int_t iROC=0;iROC<72/*AliTPCCalPad::kNsec*/;++iROC){
1673 const Float_t averageDeviation=(iROC<36)?medianIROC:medianOROC;
1674 fCurrentNominalVoltage[iROC]=fParam->GetNominalVoltage(iROC)+averageDeviation;
1680 for (Int_t iROC=0;iROC<72/*AliTPCCalPad::kNsec*/;++iROC){
1681 fChamberHVStatus[iROC]=kTRUE;
1683 //a. Deviation of median from current nominal voltage
1684 // allow larger than nominal voltages
1685 if (fCurrentNominalVoltage[iROC]-fChamberHVmedian[iROC] > maxVdiff) fChamberHVStatus[iROC]=kFALSE;
1687 //b. Fraction of bad hv values
1688 if ( 1-fChamberHVgoodFraction[iROC] > maxFracHVbad ) fChamberHVStatus[iROC]=kFALSE;
1692 Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits, Bool_t current) {
1694 // return the chamber HV for given run and time: 0-35 IROC, 36-72 OROC
1695 // if timeStamp==-1 return mean value
1698 TString sensorName="";
1699 TTimeStamp stamp(timeStamp);
1700 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1701 if (!voltageArray || (sector<0) || (sector>71)) return val;
1702 Char_t sideName='A';
1703 if ((sector/18)%2==1) sideName='C';
1706 sensorName=Form("TPC_ANODE_I_%c%02d_VMEAS",sideName,sector%18);
1709 sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,sector%18);
1714 sensorName=Form("TPC_ANODE_I_%c%02d_IMEAS",sideName,sector%18);
1717 sensorName=Form("TPC_ANODE_O_%c%02d_0_IMEAS",sideName,sector%18);
1722 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1724 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1728 Float_t AliTPCcalibDB::GetSkirtVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1731 // Get the skirt voltage for 'run' at 'timeStamp' and 'sector': 0-35 IROC, 36-72 OROC
1732 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1733 // if timeStamp==-1 return the mean value for the run
1736 TString sensorName="";
1737 TTimeStamp stamp(timeStamp);
1738 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1739 if (!voltageArray || (sector<0) || (sector>71)) return val;
1740 Char_t sideName='A';
1741 if ((sector/18)%2==1) sideName='C';
1742 sensorName=Form("TPC_SKIRT_%c_VMEAS",sideName);
1744 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1746 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1751 Float_t AliTPCcalibDB::GetCoverVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1754 // Get the cover voltage for run 'run' at time 'timeStamp'
1755 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1756 // if timeStamp==-1 return the mean value for the run
1759 TString sensorName="";
1760 TTimeStamp stamp(timeStamp);
1761 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1762 if (!voltageArray || (sector<0) || (sector>71)) return val;
1763 Char_t sideName='A';
1764 if ((sector/18)%2==1) sideName='C';
1767 sensorName=Form("TPC_COVER_I_%c_VMEAS",sideName);
1770 sensorName=Form("TPC_COVER_O_%c_VMEAS",sideName);
1773 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1775 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1780 Float_t AliTPCcalibDB::GetGGoffsetVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1783 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1784 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1785 // if timeStamp==-1 return the mean value for the run
1788 TString sensorName="";
1789 TTimeStamp stamp(timeStamp);
1790 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1791 if (!voltageArray || (sector<0) || (sector>71)) return val;
1792 Char_t sideName='A';
1793 if ((sector/18)%2==1) sideName='C';
1796 sensorName=Form("TPC_GATE_I_%c_OFF_VMEAS",sideName);
1799 sensorName=Form("TPC_GATE_O_%c_OFF_VMEAS",sideName);
1802 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1804 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1809 Float_t AliTPCcalibDB::GetGGnegVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1812 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1813 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1814 // if timeStamp==-1 return the mean value for the run
1817 TString sensorName="";
1818 TTimeStamp stamp(timeStamp);
1819 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1820 if (!voltageArray || (sector<0) || (sector>71)) return val;
1821 Char_t sideName='A';
1822 if ((sector/18)%2==1) sideName='C';
1825 sensorName=Form("TPC_GATE_I_%c_NEG_VMEAS",sideName);
1828 sensorName=Form("TPC_GATE_O_%c_NEG_VMEAS",sideName);
1831 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1833 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1838 Float_t AliTPCcalibDB::GetGGposVoltage(Int_t run, Int_t sector, Int_t timeStamp, Int_t sigDigits)
1841 // Get the GG offset voltage for run 'run' at time 'timeStamp'
1842 // type corresponds to the following: 0 - IROC A-Side; 1 - IROC C-Side; 2 - OROC A-Side; 3 - OROC C-Side
1843 // if timeStamp==-1 return the mean value for the run
1846 TString sensorName="";
1847 TTimeStamp stamp(timeStamp);
1848 AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
1849 if (!voltageArray || (sector<0) || (sector>71)) return val;
1850 Char_t sideName='A';
1851 if ((sector/18)%2==1) sideName='C';
1854 sensorName=Form("TPC_GATE_I_%c_POS_VMEAS",sideName);
1857 sensorName=Form("TPC_GATE_O_%c_POS_VMEAS",sideName);
1860 val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
1862 val=AliTPCcalibDB::GetDCSSensorValue(voltageArray, timeStamp, sensorName.Data(),sigDigits);
1867 Float_t AliTPCcalibDB::GetPressure(Int_t timeStamp, Int_t run, Int_t type){
1869 // GetPressure for given time stamp and runt
1871 TTimeStamp stamp(timeStamp);
1872 AliDCSSensor * sensor = Instance()->GetPressureSensor(run,type);
1873 if (!sensor) return 0;
1874 return sensor->GetValue(stamp);
1877 Float_t AliTPCcalibDB::GetL3Current(Int_t run, Int_t statType){
1879 // return L3 current
1880 // stat type is: AliGRPObject::Stats: kMean = 0, kTruncMean = 1, kMedian = 2, kSDMean = 3, kSDMedian = 4
1883 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1884 if (grp) current=grp->GetL3Current((AliGRPObject::Stats)statType);
1888 Float_t AliTPCcalibDB::GetBz(Int_t run){
1890 // calculate BZ in T from L3 current
1893 Float_t current=AliTPCcalibDB::GetL3Current(run);
1894 if (current>-1) bz=5*current/30000.*.1;
1898 Char_t AliTPCcalibDB::GetL3Polarity(Int_t run) {
1900 // get l3 polarity from GRP
1903 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1904 if (grp) pol=grp->GetL3Polarity();
1908 TString AliTPCcalibDB::GetRunType(Int_t run){
1910 // return run type from grp
1913 // TString type("UNKNOWN");
1914 AliGRPObject *grp=AliTPCcalibDB::GetGRP(run);
1915 if (grp) return grp->GetRunType();
1919 Float_t AliTPCcalibDB::GetValueGoofie(Int_t timeStamp, Int_t run, Int_t type){
1921 // GetPressure for given time stamp and runt
1923 TTimeStamp stamp(timeStamp);
1924 AliDCSSensorArray* goofieArray = AliTPCcalibDB::Instance()->GetGoofieSensors(run);
1925 if (!goofieArray) return 0;
1926 AliDCSSensor *sensor = goofieArray->GetSensor(type);
1927 return sensor->GetValue(stamp);
1935 Bool_t AliTPCcalibDB::GetTemperatureFit(Int_t timeStamp, Int_t run, Int_t side,TVectorD& fit){
1937 // GetTmeparature fit at parameter for given time stamp
1939 TTimeStamp tstamp(timeStamp);
1940 AliTPCSensorTempArray* tempArray = Instance()->GetTemperatureSensor(run);
1941 if (! tempArray) return kFALSE;
1942 AliTPCTempMap * tempMap = new AliTPCTempMap(tempArray);
1943 TLinearFitter * fitter = tempMap->GetLinearFitter(3,side,tstamp);
1946 fitter->GetParameters(fit);
1950 if (!fitter) return kFALSE;
1954 Float_t AliTPCcalibDB::GetTemperature(Int_t timeStamp, Int_t run, Int_t side){
1956 // Get mean temperature
1960 GetTemperatureFit(timeStamp,run,0,vec);
1964 GetTemperatureFit(timeStamp,run,0,vec);
1971 Double_t AliTPCcalibDB::GetPTRelative(UInt_t timeSec, Int_t run, Int_t side){
1974 // time - absolute time
1976 // side - 0 - A side 1-C side
1977 AliTPCCalibVdrift * vdrift = Instance()->GetVdrift(run);
1978 if (!vdrift) return 0;
1979 return vdrift->GetPTRelative(timeSec,side);
1982 AliGRPObject * AliTPCcalibDB::MakeGRPObjectFromMap(TMap *map){
1984 // Function to covert old GRP run information from TMap to GRPObject
1986 // TMap * map = AliTPCcalibDB::GetGRPMap(52406);
1988 AliDCSSensor * sensor = 0;
1990 osensor = ((*map)("fP2Pressure"));
1991 sensor =dynamic_cast<AliDCSSensor *>(osensor);
1993 if (!sensor) return 0;
1995 AliDCSSensor * sensor2 = new AliDCSSensor(*sensor);
1996 osensor = ((*map)("fCavernPressure"));
1997 TGraph * gr = new TGraph(2);
1998 gr->GetX()[0]= -100000.;
1999 gr->GetX()[1]= 1000000.;
2000 gr->GetY()[0]= atof(osensor->GetName());
2001 gr->GetY()[1]= atof(osensor->GetName());
2002 sensor2->SetGraph(gr);
2006 AliGRPObject *grpRun = new AliGRPObject;
2007 grpRun->ReadValuesFromMap(map);
2008 grpRun->SetCavernAtmosPressure(sensor2);
2009 grpRun->SetCavernAtmosPressure(sensor2);
2010 grpRun->SetSurfaceAtmosPressure(sensor);
2014 Bool_t AliTPCcalibDB::CreateGUITree(Int_t run, const char* filename)
2017 // Create a gui tree for run number 'run'
2020 if (!AliCDBManager::Instance()->GetDefaultStorage()){
2021 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
2022 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
2026 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
2027 // retrieve cal pad objects
2029 db->CreateGUITree(filename);
2033 Bool_t AliTPCcalibDB::CreateGUITree(const char* filename){
2037 if (!AliCDBManager::Instance()->GetDefaultStorage()){
2038 AliError("Default Storage not set. Cannot create calibration Tree!");
2041 UpdateNonRec(); // load all infromation now
2043 AliTPCPreprocessorOnline prep;
2044 //noise and pedestals
2045 if (GetPedestals()) prep.AddComponent(new AliTPCCalPad(*(GetPedestals())));
2046 if (GetPadNoise() ) prep.AddComponent(new AliTPCCalPad(*(GetPadNoise())));
2048 if (GetPulserTmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserTmean())));
2049 if (GetPulserTrms() ) prep.AddComponent(new AliTPCCalPad(*(GetPulserTrms())));
2050 if (GetPulserQmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserQmean())));
2052 if (GetCETmean()) prep.AddComponent(new AliTPCCalPad(*(GetCETmean())));
2053 if (GetCETrms() ) prep.AddComponent(new AliTPCCalPad(*(GetCETrms())));
2054 if (GetCEQmean()) prep.AddComponent(new AliTPCCalPad(*(GetCEQmean())));
2056 if (GetALTROAcqStart() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStart() )));
2057 if (GetALTROZsThr() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROZsThr() )));
2058 if (GetALTROFPED() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROFPED() )));
2059 if (GetALTROAcqStop() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStop() )));
2060 if (GetALTROMasked() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROMasked() )));
2062 AliTPCdataQA *dataQA=GetDataQA();
2064 if (dataQA->GetNLocalMaxima())
2065 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNLocalMaxima())));
2066 if (dataQA->GetMaxCharge())
2067 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMaxCharge())));
2068 if (dataQA->GetMeanCharge())
2069 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMeanCharge())));
2070 if (dataQA->GetNoThreshold())
2071 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNoThreshold())));
2072 if (dataQA->GetNTimeBins())
2073 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNTimeBins())));
2074 if (dataQA->GetNPads())
2075 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNPads())));
2076 if (dataQA->GetTimePosition())
2077 prep.AddComponent(new AliTPCCalPad(*(dataQA->GetTimePosition())));
2081 TString file(filename);
2082 if (file.IsNull()) file=Form("guiTreeRun_%i.root",fRun);
2083 prep.DumpToFile(file.Data());
2087 Bool_t AliTPCcalibDB::CreateRefFile(Int_t run, const char* filename)
2090 // Create a gui tree for run number 'run'
2093 if (!AliCDBManager::Instance()->GetDefaultStorage()){
2094 AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
2095 MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
2098 TString file(filename);
2099 if (file.IsNull()) file=Form("RefCalPads_%d.root",run);
2100 TDirectory *currDir=gDirectory;
2102 AliTPCcalibDB *db=AliTPCcalibDB::Instance();
2103 // retrieve cal pad objects
2106 TFile f(file.Data(),"recreate");
2107 //noise and pedestals
2108 db->GetPedestals()->Write("Pedestals");
2109 db->GetPadNoise()->Write("PadNoise");
2111 db->GetPulserTmean()->Write("PulserTmean");
2112 db->GetPulserTrms()->Write("PulserTrms");
2113 db->GetPulserQmean()->Write("PulserQmean");
2115 db->GetCETmean()->Write("CETmean");
2116 db->GetCETrms()->Write("CETrms");
2117 db->GetCEQmean()->Write("CEQmean");
2119 db->GetALTROAcqStart() ->Write("ALTROAcqStart");
2120 db->GetALTROZsThr() ->Write("ALTROZsThr");
2121 db->GetALTROFPED() ->Write("ALTROFPED");
2122 db->GetALTROAcqStop() ->Write("ALTROAcqStop");
2123 db->GetALTROMasked() ->Write("ALTROMasked");
2132 Double_t AliTPCcalibDB::GetVDriftCorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
2134 // Get time dependent drift velocity correction
2135 // multiplication factor vd = vdnom *(1+vdriftcorr)
2137 // mode determines the algorith how to combine the Laser Track, LaserCE and physics tracks
2138 // timestamp - timestamp
2140 // side - the drift velocity per side (possible for laser and CE)
2142 // Notice - Extrapolation outside of calibration range - using constant function
2145 // mode 1 automatic mode - according to the distance to the valid calibration
2147 Double_t deltaP=0, driftP=0, wP = 0.;
2148 Double_t deltaITS=0,driftITS=0, wITS= 0.;
2149 Double_t deltaLT=0, driftLT=0, wLT = 0.;
2150 Double_t deltaCE=0, driftCE=0, wCE = 0.;
2151 driftP = fDButil->GetVDriftTPC(deltaP,run,timeStamp);
2152 driftITS= fDButil->GetVDriftTPCITS(deltaITS,run,timeStamp);
2153 driftCE = fDButil->GetVDriftTPCCE(deltaCE, run,timeStamp,36000,2);
2154 driftLT = fDButil->GetVDriftTPCLaserTracks(deltaLT,run,timeStamp,36000,2);
2155 deltaITS = TMath::Abs(deltaITS);
2156 deltaP = TMath::Abs(deltaP);
2157 deltaLT = TMath::Abs(deltaLT);
2158 deltaCE = TMath::Abs(deltaCE);
2160 const Double_t kEpsilon=0.00000000001;
2161 const Double_t kdeltaT=360.; // 10 minutes
2162 if(TMath::Abs(deltaITS) < 12*kdeltaT) {
2165 wITS = 64.*kdeltaT/(deltaITS +kdeltaT);
2166 wLT = 16.*kdeltaT/(deltaLT +kdeltaT);
2167 wP = 0. *kdeltaT/(deltaP +kdeltaT);
2168 wCE = 1. *kdeltaT/(deltaCE +kdeltaT);
2171 if (TMath::Abs(driftP)<kEpsilon) wP=0; // invalid calibration
2172 if (TMath::Abs(driftITS)<kEpsilon)wITS=0; // invalid calibration
2173 if (TMath::Abs(driftLT)<kEpsilon) wLT=0; // invalid calibration
2174 if (TMath::Abs(driftCE)<kEpsilon) wCE=0; // invalid calibration
2175 if (wP+wITS+wLT+wCE<kEpsilon) return 0;
2176 result = (driftP*wP+driftITS*wITS+driftLT*wLT+driftCE*wCE)/(wP+wITS+wLT+wCE);
2185 Double_t AliTPCcalibDB::GetTime0CorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
2187 // Get time dependent time 0 (trigger delay in cm) correction
2188 // additive correction time0 = time0+ GetTime0CorrectionTime
2189 // Value etracted combining the vdrift correction using laser tracks and CE and the physics track matchin
2191 // mode determines the algorith how to combine the Laser Track and physics tracks
2192 // timestamp - timestamp
2194 // side - the drift velocity per side (possible for laser and CE)
2196 // Notice - Extrapolation outside of calibration range - using constant function
2201 result=fDButil->GetTriggerOffsetTPC(run,timeStamp);
2202 result *=fParam->GetZLength();
2207 result= -fDButil->GetTime0TPCITS(dist, run, timeStamp)*fParam->GetDriftV()/1000000.;
2216 Double_t AliTPCcalibDB::GetVDriftCorrectionGy(Int_t timeStamp, Int_t run, Int_t side, Int_t /*mode*/){
2218 // Get global y correction drift velocity correction factor
2219 // additive factor vd = vdnom*(1+GetVDriftCorrectionGy *gy)
2220 // Value etracted combining the vdrift correction using laser tracks and CE or TPC-ITS
2222 // mode determines the algorith how to combine the Laser Track, LaserCE or TPC-ITS
2223 // timestamp - timestamp
2225 // side - the drift velocity gy correction per side (CE and Laser tracks)
2227 // Notice - Extrapolation outside of calibration range - using constant function
2229 if (run<=0 && fTransform) run = fTransform->GetCurrentRunNumber();
2230 UpdateRunInformations(run,kFALSE);
2231 TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
2232 if (!array) return 0;
2235 // use TPC-ITS if present
2236 TGraphErrors *gr= (TGraphErrors*)array->FindObject("ALIGN_ITSB_TPC_VDGY");
2237 if (!gr) gr = (TGraphErrors*)array->FindObject("ALIGN_TOFB_TPC_VDGY");
2239 result = AliTPCcalibDButil::EvalGraphConst(gr,timeStamp);
2241 // transform from [(cm/mus)/ m] to [1/cm]
2242 result /= (fParam->GetDriftV()/1000000.);
2245 //printf("result %e \n", result);
2249 // use laser if ITS-TPC not present
2250 TGraphErrors *laserA= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_A");
2251 TGraphErrors *laserC= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_C");
2253 if (laserA && laserC){
2254 result= (laserA->Eval(timeStamp)+laserC->Eval(timeStamp))*0.5;
2256 if (laserA && side==0){
2257 result = (laserA->Eval(timeStamp));
2259 if (laserC &&side==1){
2260 result = (laserC->Eval(timeStamp));
2262 //printf("laser result %e \n", -result/250.);
2264 return -result/250.; //normalized before
2267 AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(Double_t notInMap, const char* nameMappingFile) {
2269 // Read list of active DDLs from OCDB entry
2270 // Generate and return AliTPCCalPad containing 1 for all pads in active DDLs,
2271 // 0 for all pads in non-active DDLs.
2272 // For DDLs with missing status information (no DCS input point to Shuttle),
2273 // the value of the AliTPCCalPad entry is determined by the parameter
2274 // notInMap (default value 1)
2278 TFile *fileMapping = new TFile(nameMappingFile, "read");
2279 AliTPCmapper *mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
2281 snprintf(chinfo,1000,"Failed to get mapping object from %s. ...\n", nameMappingFile);
2286 AliTPCCalPad *deadMap = new AliTPCCalPad("deadMap","deadMap");
2288 AliError("Failed to allocate dead map AliTPCCalPad");
2292 /// get list of active DDLs from OCDB entry
2294 if (!fALTROConfigData ) {
2295 AliError("No ALTRO config OCDB entry available");
2298 TMap *activeDDL = (TMap*)fALTROConfigData->FindObject("DDLArray");
2299 TObjString *ddlArray=0;
2301 ddlArray = (TObjString*)activeDDL->GetValue("DDLArray");
2303 AliError("Empty list of active DDLs in OCDB entry");
2307 AliError("List of active DDLs not available in OCDB entry");
2310 TString arrDDL=ddlArray->GetString();
2311 Int_t offset = mapping->GetTpcDdlOffset();
2313 for (Int_t i=0; i<mapping->GetNumDdl(); i++) {
2315 if (idDDL<0) continue;
2316 Int_t patch = mapping->GetPatchFromEquipmentID(idDDL);
2317 if (patch<0) continue;
2318 Int_t roc=mapping->GetRocFromEquipmentID(idDDL);
2319 if (roc<0) continue;
2320 AliTPCCalROC *calRoc=deadMap->GetCalROC(roc);
2322 for ( Int_t branch = 0; branch < 2; branch++ ) {
2323 for ( Int_t fec = 0; fec < mapping->GetNfec(patch, branch); fec++ ) {
2324 for ( Int_t altro = 0; altro < 8; altro++ ) {
2325 for ( Int_t channel = 0; channel < 16; channel++ ) {
2326 Int_t hwadd = mapping->CodeHWAddress(branch, fec, altro, channel);
2327 Int_t row = mapping->GetPadRow(patch, hwadd); // row in a ROC (IROC or OROC)
2328 // Int_t globalrow = mapping.GetGlobalPadRow(patch, hwadd); // row in full sector (IROC plus OROC)
2329 Int_t pad = mapping->GetPad(patch, hwadd);
2330 if (!TString(arrDDL[i]).IsDigit()) {
2333 active=TString(arrDDL[i]).Atof();
2335 calRoc->SetValue(row,pad,active);
2336 } // end channel for loop
2337 } // end altro for loop
2338 } // end fec for loop
2339 } // end branch for loop
2341 } // end loop on active DDLs
2347 AliTPCCorrection * AliTPCcalibDB::GetTPCComposedCorrection(Float_t field) const{
2349 // GetComposed correction for given field setting
2350 // If not specific correction for field used return correction for all field
2351 // - Complication needed to gaurantee OCDB back compatibility
2352 // - Not neeeded for the new space point correction
2353 if (!fComposedCorrectionArray) return 0;
2354 if (field>0.1 && fComposedCorrectionArray->At(1)) {
2355 return (AliTPCCorrection *)fComposedCorrectionArray->At(1);
2357 if (field<-0.1 &&fComposedCorrectionArray->At(2)) {
2358 return (AliTPCCorrection *)fComposedCorrectionArray->At(2);
2360 return (AliTPCCorrection *)fComposedCorrectionArray->At(0);
2365 AliTPCCorrection * AliTPCcalibDB::GetTPCComposedCorrectionDelta() const{
2367 // GetComposedCorrection delta
2368 // Delta is time dependent - taken form the CalibTime OCDB entry
2370 if (!fComposedCorrectionArray) return 0;
2371 if (fRun<0) return 0;
2372 if (fDriftCorrectionArray.GetValue(Form("%i",fRun))==0) return 0;
2373 if (fComposedCorrectionArray->GetEntriesFast()<=4) {
2374 fComposedCorrectionArray->Expand(5);
2375 TObjArray * timeArray =(TObjArray*)(fDriftCorrectionArray.GetValue(Form("%i",fRun)));
2376 AliTPCCorrection * correctionTime = (AliTPCCorrection *)timeArray->FindObject("FitCorrectionTime");
2377 if (correctionTime){
2378 correctionTime->Init();
2379 fComposedCorrectionArray->AddAt(correctionTime,4); //add time dependent c
2382 return (AliTPCCorrection *)fComposedCorrectionArray->At(4); //