+Bool_t AliTPCcalibDB::CreateGUITree(Int_t run, const char* filename)
+{
+ //
+ // Create a gui tree for run number 'run'
+ //
+
+ if (!AliCDBManager::Instance()->GetDefaultStorage()){
+ AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
+ MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
+ return kFALSE;
+ }
+ //db instance
+ AliTPCcalibDB *db=AliTPCcalibDB::Instance();
+ // retrieve cal pad objects
+ db->SetRun(run);
+ db->CreateGUITree(filename);
+ return kTRUE;
+}
+
+Bool_t AliTPCcalibDB::CreateGUITree(const char* filename){
+ //
+ //
+ //
+ if (!AliCDBManager::Instance()->GetDefaultStorage()){
+ AliError("Default Storage not set. Cannot create calibration Tree!");
+ return kFALSE;
+ }
+ UpdateNonRec(); // load all infromation now
+
+ AliTPCPreprocessorOnline prep;
+ //noise and pedestals
+ if (GetPedestals()) prep.AddComponent(new AliTPCCalPad(*(GetPedestals())));
+ if (GetPadNoise() ) prep.AddComponent(new AliTPCCalPad(*(GetPadNoise())));
+ //pulser data
+ if (GetPulserTmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserTmean())));
+ if (GetPulserTrms() ) prep.AddComponent(new AliTPCCalPad(*(GetPulserTrms())));
+ if (GetPulserQmean()) prep.AddComponent(new AliTPCCalPad(*(GetPulserQmean())));
+ //CE data
+ if (GetCETmean()) prep.AddComponent(new AliTPCCalPad(*(GetCETmean())));
+ if (GetCETrms() ) prep.AddComponent(new AliTPCCalPad(*(GetCETrms())));
+ if (GetCEQmean()) prep.AddComponent(new AliTPCCalPad(*(GetCEQmean())));
+ //Altro data
+ if (GetALTROAcqStart() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStart() )));
+ if (GetALTROZsThr() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROZsThr() )));
+ if (GetALTROFPED() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROFPED() )));
+ if (GetALTROAcqStop() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROAcqStop() )));
+ if (GetALTROMasked() ) prep.AddComponent(new AliTPCCalPad(*(GetALTROMasked() )));
+ //QA
+ AliTPCdataQA *dataQA=GetDataQA();
+ if (dataQA) {
+ if (dataQA->GetNLocalMaxima())
+ prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNLocalMaxima())));
+ if (dataQA->GetMaxCharge())
+ prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMaxCharge())));
+ if (dataQA->GetMeanCharge())
+ prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMeanCharge())));
+ if (dataQA->GetNoThreshold())
+ prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNoThreshold())));
+ if (dataQA->GetNTimeBins())
+ prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNTimeBins())));
+ if (dataQA->GetNPads())
+ prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNPads())));
+ if (dataQA->GetTimePosition())
+ prep.AddComponent(new AliTPCCalPad(*(dataQA->GetTimePosition())));
+ }
+
+ //
+ TString file(filename);
+ if (file.IsNull()) file=Form("guiTreeRun_%lld.root",fRun);
+ prep.DumpToFile(file.Data());
+ return kTRUE;
+}
+
+Bool_t AliTPCcalibDB::CreateRefFile(Int_t run, const char* filename)
+{
+ //
+ // Create a gui tree for run number 'run'
+ //
+
+ if (!AliCDBManager::Instance()->GetDefaultStorage()){
+ AliLog::Message(AliLog::kError, "Default Storage not set. Cannot create Calibration Tree!",
+ MODULENAME(), "AliTPCcalibDB", FUNCTIONNAME(), __FILE__, __LINE__);
+ return kFALSE;
+ }
+ TString file(filename);
+ if (file.IsNull()) file=Form("RefCalPads_%d.root",run);
+ TDirectory *currDir=gDirectory;
+ //db instance
+ AliTPCcalibDB *db=AliTPCcalibDB::Instance();
+ // retrieve cal pad objects
+ db->SetRun(run);
+ //open file
+ TFile f(file.Data(),"recreate");
+ //noise and pedestals
+ db->GetPedestals()->Write("Pedestals");
+ db->GetPadNoise()->Write("PadNoise");
+ //pulser data
+ db->GetPulserTmean()->Write("PulserTmean");
+ db->GetPulserTrms()->Write("PulserTrms");
+ db->GetPulserQmean()->Write("PulserQmean");
+ //CE data
+ db->GetCETmean()->Write("CETmean");
+ db->GetCETrms()->Write("CETrms");
+ db->GetCEQmean()->Write("CEQmean");
+ //Altro data
+ db->GetALTROAcqStart() ->Write("ALTROAcqStart");
+ db->GetALTROZsThr() ->Write("ALTROZsThr");
+ db->GetALTROFPED() ->Write("ALTROFPED");
+ db->GetALTROAcqStop() ->Write("ALTROAcqStop");
+ db->GetALTROMasked() ->Write("ALTROMasked");
+ //
+ f.Close();
+ currDir->cd();
+ return kTRUE;
+}
+
+
+
+Double_t AliTPCcalibDB::GetVDriftCorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
+ //
+ // Get time dependent drift velocity correction
+ // multiplication factor vd = vdnom *(1+vdriftcorr)
+ // Arguments:
+ // mode determines the algorith how to combine the Laser Track, LaserCE and physics tracks
+ // timestamp - timestamp
+ // run - run number
+ // side - the drift velocity per side (possible for laser and CE)
+ //
+ // Notice - Extrapolation outside of calibration range - using constant function
+ //
+ Double_t result=0;
+ // mode 1 automatic mode - according to the distance to the valid calibration
+ // -
+ Double_t deltaP=0, driftP=0, wP = 0.;
+ Double_t deltaITS=0,driftITS=0, wITS= 0.;
+ Double_t deltaLT=0, driftLT=0, wLT = 0.;
+ Double_t deltaCE=0, driftCE=0, wCE = 0.;
+ driftP = fDButil->GetVDriftTPC(deltaP,run,timeStamp);
+ driftITS= fDButil->GetVDriftTPCITS(deltaITS,run,timeStamp);
+ driftCE = fDButil->GetVDriftTPCCE(deltaCE, run,timeStamp,36000,2);
+ driftLT = fDButil->GetVDriftTPCLaserTracks(deltaLT,run,timeStamp,36000,2);
+ deltaITS = TMath::Abs(deltaITS);
+ deltaP = TMath::Abs(deltaP);
+ deltaLT = TMath::Abs(deltaLT);
+ deltaCE = TMath::Abs(deltaCE);
+ if (mode==1) {
+ const Double_t kEpsilon=0.00000000001;
+ const Double_t kdeltaT=360.; // 10 minutes
+ if(TMath::Abs(deltaITS) < 12*kdeltaT) {
+ result = driftITS;
+ } else {
+ wITS = 64.*kdeltaT/(deltaITS +kdeltaT);
+ wLT = 16.*kdeltaT/(deltaLT +kdeltaT);
+ wP = 0. *kdeltaT/(deltaP +kdeltaT);
+ wCE = 1. *kdeltaT/(deltaCE +kdeltaT);
+ //
+ //
+ if (TMath::Abs(driftP)<kEpsilon) wP=0; // invalid calibration
+ if (TMath::Abs(driftITS)<kEpsilon)wITS=0; // invalid calibration
+ if (TMath::Abs(driftLT)<kEpsilon) wLT=0; // invalid calibration
+ if (TMath::Abs(driftCE)<kEpsilon) wCE=0; // invalid calibration
+ if (wP+wITS+wLT+wCE<kEpsilon) return 0;
+ result = (driftP*wP+driftITS*wITS+driftLT*wLT+driftCE*wCE)/(wP+wITS+wLT+wCE);
+ }
+
+
+ }
+
+ return result;
+}
+
+Double_t AliTPCcalibDB::GetTime0CorrectionTime(Int_t timeStamp, Int_t run, Int_t /*side*/, Int_t mode){
+ //
+ // Get time dependent time 0 (trigger delay in cm) correction
+ // additive correction time0 = time0+ GetTime0CorrectionTime
+ // Value etracted combining the vdrift correction using laser tracks and CE and the physics track matchin
+ // Arguments:
+ // mode determines the algorith how to combine the Laser Track and physics tracks
+ // timestamp - timestamp
+ // run - run number
+ // side - the drift velocity per side (possible for laser and CE)
+ //
+ // Notice - Extrapolation outside of calibration range - using constant function
+ //
+ Double_t result=0;
+ if (mode==2) {
+ // TPC-TPC mode
+ result=fDButil->GetTriggerOffsetTPC(run,timeStamp);
+ result *=fParam->GetZLength();
+ }
+ if (mode==1){
+ // TPC-ITS mode
+ Double_t dist=0;
+ result= -fDButil->GetTime0TPCITS(dist, run, timeStamp)*fParam->GetDriftV()/1000000.;
+ }
+ return result;
+
+}
+
+
+
+
+Double_t AliTPCcalibDB::GetVDriftCorrectionGy(Int_t timeStamp, Int_t run, Int_t side, Int_t /*mode*/){
+ //
+ // Get global y correction drift velocity correction factor
+ // additive factor vd = vdnom*(1+GetVDriftCorrectionGy *gy)
+ // Value etracted combining the vdrift correction using laser tracks and CE or TPC-ITS
+ // Arguments:
+ // mode determines the algorith how to combine the Laser Track, LaserCE or TPC-ITS
+ // timestamp - timestamp
+ // run - run number
+ // side - the drift velocity gy correction per side (CE and Laser tracks)
+ //
+ // Notice - Extrapolation outside of calibration range - using constant function
+ //
+ if (run<=0 && fTransform) run = fTransform->GetCurrentRunNumber();
+ UpdateRunInformations(run,kFALSE);
+ TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
+ if (!array) return 0;
+ Double_t result=0;
+
+ // use TPC-ITS if present
+ TGraphErrors *gr= (TGraphErrors*)array->FindObject("ALIGN_ITSB_TPC_VDGY");
+ if(gr) {
+ result = AliTPCcalibDButil::EvalGraphConst(gr,timeStamp);
+
+ // transform from [(cm/mus)/ m] to [1/cm]
+ result /= (fParam->GetDriftV()/1000000.);
+ result /= 100.;
+
+ //printf("result %e \n", result);
+ return result;
+ }
+
+ // use laser if ITS-TPC not present
+ TGraphErrors *laserA= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_A");
+ TGraphErrors *laserC= (TGraphErrors*)array->FindObject("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_C");
+
+ if (laserA && laserC){
+ result= (laserA->Eval(timeStamp)+laserC->Eval(timeStamp))*0.5;
+ }
+ if (laserA && side==0){
+ result = (laserA->Eval(timeStamp));
+ }
+ if (laserC &&side==1){
+ result = (laserC->Eval(timeStamp));
+ }
+ //printf("laser result %e \n", -result/250.);
+
+ return -result/250.; //normalized before
+}