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 **************************************************************************/
19 Responsible: marian.ivanov@cern.ch
20 Code to analyze the TPC calibration and to produce OCDB entries
24 gSystem->Load("libANALYSIS");
25 gSystem->Load("libTPCcalib");
27 AliTPCPreprocessorOffline proces;
28 process.CalibTimeGain("CalibObjects.root",run0,run1,ocdbPath);
29 // take the raw calibration data from the file CalibObjects.root
30 // and make a OCDB entry with run validity run0-run1
31 // results are stored at the ocdbPath - local or alien ...
32 // default storage ""- data stored at current working directory
35 #include "Riostream.h"
38 #include "TGraphErrors.h"
39 #include "AliExternalTrackParam.h"
42 #include "TMultiGraph.h"
44 #include "THnSparse.h"
48 #include "AliTPCROC.h"
49 #include "AliTPCCalROC.h"
50 #include "AliESDfriend.h"
51 #include "AliTPCcalibTime.h"
52 #include "AliSplineFit.h"
53 #include "AliCDBMetaData.h"
55 #include "AliCDBManager.h"
56 #include "AliCDBStorage.h"
57 #include "AliTPCcalibBase.h"
58 #include "AliTPCcalibDB.h"
59 #include "AliTPCcalibDButil.h"
60 #include "AliRelAlignerKalman.h"
61 #include "AliTPCParamSR.h"
62 #include "AliTPCcalibTimeGain.h"
63 #include "AliSplineFit.h"
64 #include "AliTPCPreprocessorOffline.h"
67 ClassImp(AliTPCPreprocessorOffline)
69 AliTPCPreprocessorOffline::AliTPCPreprocessorOffline():
70 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
71 kMinEntries(500), // minimal number of entries for fit
72 startRun(0), // start Run - used to make fast selection in THnSparse
73 endRun(0), // end Run - used to make fast selection in THnSparse
74 startTime(0), // startTime - used to make fast selection in THnSparse
75 endTime(0), // endTime - used to make fast selection in THnSparse
76 ocdbStorage(""), // path to the OCDB storage
77 fVdriftArray(new TObjArray),
79 fGraphMIP(0), // graph time dependence of MIP
80 fGraphCosmic(0), // graph time dependence at Plateu
81 fFitMIP(0), // fit of dependence - MIP
82 fFitCosmic(0), // fit of dependence - Plateu
83 fGainArray(new TObjArray), // array to be stored in the OCDB
84 fGainMIP(0), // calibration component for MIP
85 fGainCosmic(0) // calibration component for cosmic
88 // default constructor
92 AliTPCPreprocessorOffline::~AliTPCPreprocessorOffline() {
101 void AliTPCPreprocessorOffline::GetRunRange(AliTPCcalibTime* timeDrift){
103 // find the fist and last run
105 TObjArray *hisArray =timeDrift->GetHistoDrift();
106 {for (Int_t i=0; i<hisArray->GetEntriesFast(); i++){
107 THnSparse* addHist=(THnSparse*)hisArray->UncheckedAt(i);
108 if (addHist->GetEntries()<kMinEntries) continue;
109 if (!addHist) continue;
110 TH1D* histo =addHist->Projection(3);
111 TH1D* histoTime=addHist->Projection(0);
112 printf("%s\t%f\t%d\t%d\n",histo->GetName(), histo->GetEntries(),histo->FindFirstBinAbove(0),histo->FindLastBinAbove(0));
115 startRun=histo->FindFirstBinAbove(0);
116 endRun =histo->FindLastBinAbove(0);
118 startRun=TMath::Min(histo->FindFirstBinAbove(0),startRun);
119 endRun =TMath::Max(histo->FindLastBinAbove(0),endRun);
122 startTime=histoTime->FindFirstBinAbove(0);
123 endTime =histoTime->FindLastBinAbove(0);
125 startTime=TMath::Min(histoTime->FindFirstBinAbove(0),startTime);
126 endTime =TMath::Max(histoTime->FindLastBinAbove(0),endTime);
131 if (startRun<0) startRun=0;
132 if (endRun<0) endRun=100000000;
133 printf("Run range :\t%d-%d\n", startRun, endRun);
134 printf("Time range :\t%d-%d\n", startTime, endTime);
140 void AliTPCPreprocessorOffline::CalibTimeVdrift(Char_t* file, Int_t ustartRun, Int_t uendRun, TString pocdbStorage){
144 if (pocdbStorage.Length()>0) ocdbStorage=pocdbStorage;
146 ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
148 // 1. Initialization and run range setting
150 fTimeDrift=(AliTPCcalibTime*)fcalib.Get("calibTime");
153 TObjArray *hisArray =fTimeDrift->GetHistoDrift();
154 GetRunRange(fTimeDrift);
155 for (Int_t i=0; i<hisArray->GetEntriesFast(); i++){
156 THnSparse* addHist=(THnSparse*)hisArray->At(i);
157 if (!addHist) continue;
158 if (startTime<endTime) addHist->GetAxis(0)->SetRange(startTime-1,endTime+1);
159 if (startRun<endRun) addHist->GetAxis(3)->SetRange(startRun-1,endRun+1);
163 // 2. extraction of the information
165 fVdriftArray = new TObjArray();
166 AddAlignmentGraphs(fVdriftArray,fTimeDrift);
167 AddHistoGraphs(fVdriftArray,fTimeDrift,kMinEntries);
168 AddLaserGraphs(fVdriftArray,fTimeDrift);
170 // 3. Append QA plots
172 MakeDefaultPlots(fVdriftArray,fVdriftArray);
179 UpdateOCDBDrift(ustartRun,uendRun,ocdbStorage);
182 void AliTPCPreprocessorOffline::UpdateOCDBDrift( Int_t ustartRun, Int_t uendRun, const char* storagePath ){
186 AliCDBMetaData *metaData= new AliCDBMetaData();
187 metaData->SetObjectClassName("TObjArray");
188 metaData->SetResponsible("Marian Ivanov");
189 metaData->SetBeamPeriod(1);
190 metaData->SetAliRootVersion("05-25-01"); //root version
191 metaData->SetComment("Calibration of the time dependence of the drift velocity");
193 id1=new AliCDBId("TPC/Calib/TimeDrift", ustartRun, uendRun);
194 AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
195 gStorage->Put(fVdriftArray, (*id1), metaData);
200 void AliTPCPreprocessorOffline::UpdateDriftParam(AliTPCParam *param, TObjArray *arr, Int_t lstartRun){
202 // update the OCDB entry for the nominal time0
205 // AliTPCParam * param = AliTPCcalibDB::Instance()->GetParameters();
206 AliTPCParam *paramNew = (AliTPCParam *)param->Clone();
207 TGraphErrors *grT = (TGraphErrors *)arr->FindObject("ALIGN_ITSM_TPC_T0");
208 Double_t deltaTcm = TMath::Median(grT->GetN(),grT->GetY());
209 Double_t deltaT = deltaTcm/param->GetDriftV();
210 paramNew->SetL1Delay(param->GetL1Delay()-deltaT);
213 AliCDBMetaData *metaData= new AliCDBMetaData();
214 metaData->SetObjectClassName("TObjArray");
215 metaData->SetResponsible("Marian Ivanov");
216 metaData->SetBeamPeriod(1);
217 metaData->SetAliRootVersion("05-25-02"); //root version
218 metaData->SetComment("Updated calibration of nominal time 0");
220 id1=new AliCDBId("TPC/Calib/Parameters", lstartRun, AliCDBRunRange::Infinity());
221 AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
222 gStorage->Put(param, (*id1), metaData);
227 void AliTPCPreprocessorOffline::PrintArray(TObjArray *array){
231 Int_t entries = array->GetEntries();
232 for (Int_t i=0; i<entries; i++){
233 if (!array->At(i)) continue;
234 printf("%d\t %s\n", i, array->At(i)->GetName());
240 TGraphErrors* AliTPCPreprocessorOffline::FilterGraphDrift(TGraphErrors * graph, Float_t errSigmaCut, Float_t medianCutAbs){
242 // 1. filter graph - error cut errSigmaCut
243 // 2. filter graph - medianCutAbs around median
245 // errSigmaCut - cut on error
246 // medianCutAbs - cut on value around median
249 // 1. filter graph - error cut errSigmaCut
251 TGraphErrors *graphF;
252 graphF = AliTPCcalibDButil::FilterGraphMedianErr(graph,errSigmaCut,dummy);
254 if (!graphF) return 0;
255 graph = AliTPCcalibDButil::FilterGraphMedianErr(graphF,errSigmaCut,dummy);
257 if (!graph) return 0;
259 // filter graph - kMedianCutAbs around median
261 graphF=FilterGraphMedianAbs(graph, medianCutAbs,dummy);
263 if (!graphF) return 0;
264 graph=FilterGraphMedianAbs(graphF, medianCutAbs,dummy);
266 if (!graph) return 0;
272 TGraphErrors* AliTPCPreprocessorOffline::FilterGraphMedianAbs(TGraphErrors * graph, Float_t cut,Double_t &medianY){
274 // filter outlyer measurement
275 // Only points around median +- cut filtered
277 if (!graph) return 0;
279 Int_t npoints0 = graph->GetN();
282 Double_t *outx=new Double_t[npoints0];
283 Double_t *outy=new Double_t[npoints0];
284 Double_t *errx=new Double_t[npoints0];
285 Double_t *erry=new Double_t[npoints0];
288 if (npoints0<kMinPoints) return 0;
289 for (Int_t iter=0; iter<3; iter++){
291 for (Int_t ipoint=0; ipoint<npoints0; ipoint++){
292 if (graph->GetY()[ipoint]==0) continue;
293 if (iter>0 &&TMath::Abs(graph->GetY()[ipoint]-medianY)>cut) continue;
294 outx[npoints] = graph->GetX()[ipoint];
295 outy[npoints] = graph->GetY()[ipoint];
296 errx[npoints] = graph->GetErrorX(ipoint);
297 erry[npoints] = graph->GetErrorY(ipoint);
300 if (npoints<=1) break;
301 medianY =TMath::Median(npoints,outy);
302 rmsY =TMath::RMS(npoints,outy);
304 TGraphErrors *graphOut=0;
305 if (npoints>1) graphOut= new TGraphErrors(npoints,outx,outy,errx,erry);
310 void AliTPCPreprocessorOffline::AddHistoGraphs( TObjArray * vdriftArray, AliTPCcalibTime *timeDrift, Int_t minEntries){
312 // Add graphs corresponding to the alignment
314 const Double_t kErrSigmaCut=5; // error sigma cut - for filtering
315 const Double_t kMedianCutAbs=0.03; // error sigma cut - for filtering
317 TObjArray * array=timeDrift->GetHistoDrift();
319 THnSparse* hist=NULL;
320 // 2.a) cosmics with different triggers
321 for (Int_t i=0; i<array->GetEntriesFast();i++){
322 hist=(THnSparseF*)array->UncheckedAt(i);
324 if (hist->GetEntries()<minEntries) continue;
326 TString name=hist->GetName();
327 Int_t dim[4]={0,1,2,3};
328 THnSparse* newHist=hist->Projection(4,dim);
329 newHist->SetName(name);
330 TGraphErrors* graph=AliTPCcalibBase::FitSlices(newHist,2,0,400,100,0.05,0.95, kTRUE);
331 printf("name=%s graph=%i, N=%i\n", name.Data(), graph==0, graph->GetN());
332 Int_t pos=name.Index("_");
333 name=name(pos,name.Capacity()-pos);
334 TString graphName=graph->ClassName();
338 graph = FilterGraphDrift(graph, kErrSigmaCut, kMedianCutAbs);
340 printf("Graph =%s filtered out\n", name.Data());
344 graph->SetMarkerStyle(i%8+20);
345 graph->SetMarkerColor(i%7);
346 graph->GetXaxis()->SetTitle("Time");
347 graph->GetYaxis()->SetTitle("v_{dcor}");
348 graph->SetName(graphName);
349 graph->SetTitle(graphName);
350 printf("Graph %d\t=\t%s\n", i, graphName.Data());
351 vdriftArray->Add(graph);
359 void AliTPCPreprocessorOffline::AddAlignmentGraphs( TObjArray * vdriftArray, AliTPCcalibTime *timeDrift){
361 // Add graphs corresponding to alignment to the object array
363 TObjArray *arrayITS=0;
364 TObjArray *arrayTOF=0;
365 TObjArray *arrayTRD=0;
366 TMatrixD *mstatITS=0;
367 TMatrixD *mstatTOF=0;
368 TMatrixD *mstatTRD=0;
370 arrayITS=timeDrift->GetAlignITSTPC();
371 arrayTRD=timeDrift->GetAlignTRDTPC();
372 arrayTOF=timeDrift->GetAlignTOFTPC();
374 if (arrayITS->GetEntries()>0) mstatITS= AliTPCcalibDButil::MakeStatRelKalman(arrayITS,0.9,50,0.025);
375 if (arrayTOF->GetEntries()>0) mstatTOF= AliTPCcalibDButil::MakeStatRelKalman(arrayTOF,0.9,1000,0.025);
376 if (arrayTRD->GetEntries()>0) mstatTRD= AliTPCcalibDButil::MakeStatRelKalman(arrayTRD,0.9,50,0.025);
378 TObjArray * arrayITSP= AliTPCcalibDButil::SmoothRelKalman(arrayITS,*mstatITS, 0, 5.);
379 TObjArray * arrayITSM= AliTPCcalibDButil::SmoothRelKalman(arrayITS,*mstatITS, 1, 5.);
380 TObjArray * arrayITSB= AliTPCcalibDButil::SmoothRelKalman(arrayITSP,arrayITSM);
381 TObjArray * arrayTOFP= AliTPCcalibDButil::SmoothRelKalman(arrayTOF,*mstatTOF, 0, 5.);
382 TObjArray * arrayTOFM= AliTPCcalibDButil::SmoothRelKalman(arrayTOF,*mstatTOF, 1, 5.);
383 TObjArray * arrayTOFB= AliTPCcalibDButil::SmoothRelKalman(arrayTOFP,arrayTOFM);
385 TObjArray * arrayTRDP= 0x0;
386 TObjArray * arrayTRDM= 0x0;
387 TObjArray * arrayTRDB= 0x0;
388 arrayTRDP= AliTPCcalibDButil::SmoothRelKalman(arrayTRD,*mstatTRD, 0, 5.);
389 arrayTRDM= AliTPCcalibDButil::SmoothRelKalman(arrayTRD,*mstatTRD, 1, 5.);
390 arrayTRDB= AliTPCcalibDButil::SmoothRelKalman(arrayTRDP,arrayTRDM);
393 Int_t entries=TMath::Max(arrayITS->GetEntriesFast(),arrayTOF->GetEntriesFast());
394 TObjArray *arrays[12]={arrayITS, arrayITSP, arrayITSM, arrayITSB,
395 arrayTRD, arrayTRDP, arrayTRDM, arrayTRDB,
396 arrayTOF, arrayTOFP, arrayTOFM, arrayTOFB};
397 TString grnames[12]={"ALIGN_ITS", "ALIGN_ITSP", "ALIGN_ITSM", "ALIGN_ITSB",
398 "ALIGN_TRD", "ALIGN_TRDP", "ALIGN_TRDM","ALIGN_TRDB",
399 "ALIGN_TOF", "ALIGN_TOFP", "ALIGN_TOFM","ALIGN_TOFB"};
400 TString grpar[9]={"DELTAPSI", "DELTATHETA", "DELTAPHI",
401 "DELTAX", "DELTAY", "DELTAZ",
402 "DRIFTVD", "T0", "VDGY"};
405 TVectorD vX(entries);
406 TVectorD vY(entries);
407 TVectorD vEx(entries);
408 TVectorD vEy(entries);
410 for (Int_t iarray=0; iarray<12; iarray++){
411 arr = arrays[iarray];
412 if (arr==0) continue;
413 for (Int_t ipar=0; ipar<9; ipar++){
415 for (Int_t itime=0; itime<arr->GetEntriesFast(); itime++){
416 AliRelAlignerKalman * kalman = (AliRelAlignerKalman *) arr->UncheckedAt(itime);
417 if (!kalman) continue;
418 vX[counter]=kalman->GetTimeStamp();
419 vY[counter]=(*(kalman->GetState()))[ipar];
420 if (ipar==6) vY[counter]=1./(*(kalman->GetState()))[ipar]-1;
422 vEy[counter]=TMath::Sqrt((*(kalman->GetStateCov()))(ipar,ipar));
426 TGraphErrors * graph=new TGraphErrors(counter, vX.GetMatrixArray(),
428 vEx.GetMatrixArray(),
429 vEy.GetMatrixArray());
430 TString grName=grnames[iarray];
433 graph->SetName(grName.Data());
434 vdriftArray->AddLast(graph);
442 void AliTPCPreprocessorOffline::AddLaserGraphs( TObjArray * vdriftArray, AliTPCcalibTime *timeDrift){
444 // add graphs for laser
446 const Double_t delayL0L1 = 0.071; //this is hack for 1/2 weeks
448 TGraphErrors *grLaser[6]={0,0,0,0,0,0};
449 hisN = timeDrift->GetHistVdriftLaserA(0);
450 if (timeDrift->GetHistVdriftLaserA(0)){
451 grLaser[0]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserA(0),0,2,5,delayL0L1);
452 grLaser[0]->SetName("GRAPH_MEAN_DELAY_LASER_ALL_A");
453 vdriftArray->AddLast(grLaser[0]);
455 if (timeDrift->GetHistVdriftLaserA(1)){
456 grLaser[1]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserA(1),0,2,5);
457 grLaser[1]->SetName("GRAPH_MEAN_DRIFT_LASER_ALL_A");
458 vdriftArray->AddLast(grLaser[1]);
460 if (timeDrift->GetHistVdriftLaserA(2)){
461 grLaser[2]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserA(2),0,2,5);
462 grLaser[2]->SetName("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_A");
463 vdriftArray->AddLast(grLaser[2]);
465 if (timeDrift->GetHistVdriftLaserC(0)){
466 grLaser[3]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserC(0),0,2,5,delayL0L1);
467 grLaser[3]->SetName("GRAPH_MEAN_DELAY_LASER_ALL_C");
468 vdriftArray->AddLast(grLaser[3]);
470 if (timeDrift->GetHistVdriftLaserC(1)){
471 grLaser[4]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserC(1),0,2,5);
472 grLaser[4]->SetName("GRAPH_MEAN_DRIFT_LASER_ALL_C");
473 vdriftArray->AddLast(grLaser[4]);
475 if (timeDrift->GetHistVdriftLaserC(2)){
476 grLaser[5]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserC(2),0,2,5);
477 grLaser[5]->SetName("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_C");
478 vdriftArray->AddLast(grLaser[5]);
480 for (Int_t i=0; i<6;i++){
482 SetDefaultGraphDrift(grLaser[i], 1,(i+20));
483 grLaser[i]->GetYaxis()->SetTitle("Laser Correction");
489 TGraphErrors * AliTPCPreprocessorOffline::MakeGraphFilter0(THnSparse *hisN, Int_t itime, Int_t ival, Int_t minEntries, Double_t offset){
491 // Make graph with mean values and rms
493 hisN->GetAxis(itime)->SetRange(0,100000000);
494 hisN->GetAxis(ival)->SetRange(0,100000000);
495 TH1 * hisT = hisN->Projection(itime);
496 TH1 * hisV = hisN->Projection(ival);
498 Int_t firstBinA = hisT->FindFirstBinAbove(2);
499 Int_t lastBinA = hisT->FindLastBinAbove(2);
500 Int_t firstBinV = hisV->FindFirstBinAbove(0);
501 Int_t lastBinV = hisV->FindLastBinAbove(0);
502 hisN->GetAxis(itime)->SetRange(firstBinA,lastBinA);
503 hisN->GetAxis(ival)->SetRange(firstBinV,lastBinV);
505 for (Int_t ibin=firstBinA; ibin<lastBinA; ibin++){
506 Double_t cont = hisT->GetBinContent(ibin);
507 if (cont<minEntries) continue;
510 TVectorD vecTime(entries);
511 TVectorD vecMean0(entries);
512 TVectorD vecRMS0(entries);
513 TVectorD vecMean1(entries);
514 TVectorD vecRMS1(entries);
516 {for (Int_t ibin=firstBinA; ibin<lastBinA; ibin++){
517 Double_t cont = hisT->GetBinContent(ibin);
518 if (cont<minEntries) continue;
519 hisN->GetAxis(itime)->SetRange(ibin-1,ibin+1);
520 Double_t time = hisT->GetBinCenter(ibin);
521 TH1 * his = hisN->Projection(ival);
522 Double_t nentries0= his->GetBinContent(his->FindBin(0));
523 if (cont-nentries0<minEntries) continue;
525 his->SetBinContent(his->FindBin(0),0);
526 vecTime[entries]=time;
527 vecMean0[entries]=his->GetMean()+offset;
528 vecMean1[entries]=his->GetMeanError();
529 vecRMS0[entries] =his->GetRMS();
530 vecRMS1[entries] =his->GetRMSError();
536 TGraphErrors * graph = new TGraphErrors(entries,vecTime.GetMatrixArray(), vecMean0.GetMatrixArray(), 0, vecMean1.GetMatrixArray());
547 void AliTPCPreprocessorOffline::SetDefaultGraphDrift(TGraph *graph, Int_t color, Int_t style){
551 graph->GetXaxis()->SetTimeDisplay(kTRUE);
552 graph->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
553 graph->SetMaximum( 0.025);
554 graph->SetMinimum(-0.025);
555 graph->GetXaxis()->SetTitle("Time");
556 graph->GetYaxis()->SetTitle("v_{dcorr}");
558 graph->GetYaxis()->SetLabelSize(0.03);
559 graph->GetXaxis()->SetLabelSize(0.03);
561 graph->GetXaxis()->SetNdivisions(10,5,0);
562 graph->GetYaxis()->SetNdivisions(10,5,0);
564 graph->GetXaxis()->SetLabelOffset(0.02);
565 graph->GetYaxis()->SetLabelOffset(0.005);
567 graph->GetXaxis()->SetTitleOffset(1.3);
568 graph->GetYaxis()->SetTitleOffset(1.2);
570 graph->SetMarkerColor(color);
571 graph->SetLineColor(color);
572 graph->SetMarkerStyle(style);
575 void AliTPCPreprocessorOffline::SetPadStyle(TPad *pad, Float_t mx0, Float_t mx1, Float_t my0, Float_t my1){
579 pad->SetMargin(mx0,mx1,my0,my1);
583 void AliTPCPreprocessorOffline::MakeDefaultPlots(TObjArray * arr, TObjArray *picArray){
588 Float_t mx0=0.12, mx1=0.1, my0=0.15, my1=0.1;
590 TGraphErrors* laserA =(TGraphErrors*)arr->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_A");
591 TGraphErrors* laserC =(TGraphErrors*)arr->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_C");
592 TGraphErrors* cosmic =(TGraphErrors*)arr->FindObject("TGRAPHERRORS_MEAN_VDRIFT_COSMICS_ALL");
593 TGraphErrors* cross =(TGraphErrors*)arr->FindObject("TGRAPHERRORS_VDRIFT_CROSS_ALL");
594 TGraphErrors* itstpcP =(TGraphErrors*)arr->FindObject("ALIGN_ITSP_TPC_DRIFTVD");
595 TGraphErrors* itstpcM =(TGraphErrors*)arr->FindObject("ALIGN_ITSM_TPC_DRIFTVD");
596 TGraphErrors* itstpcB =(TGraphErrors*)arr->FindObject("ALIGN_ITSB_TPC_DRIFTVD");
598 if (laserA) SetDefaultGraphDrift(laserA,2,25);
599 if (laserC) SetDefaultGraphDrift(laserC,4,26);
600 if (cosmic) SetDefaultGraphDrift(cosmic,3,27);
601 if (cross) SetDefaultGraphDrift(cross,4,28);
602 if (itstpcP) SetDefaultGraphDrift(itstpcP,2,29);
603 if (itstpcM) SetDefaultGraphDrift(itstpcM,4,30);
604 if (itstpcB) SetDefaultGraphDrift(itstpcB,1,31);
612 pad = new TCanvas("TPCLaserVDrift","TPCLaserVDrift");
614 SetPadStyle(pad,mx0,mx1,my0,my1);
617 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
618 legend->AddEntry(laserA,"Laser A side");
619 legend->AddEntry(laserC,"Laser C side");
621 picArray->AddLast(pad);
624 if (itstpcP&&itstpcM){
625 pad = new TCanvas("ITSTPC","ITSTPC");
626 itstpcP->Draw("alp");
627 SetPadStyle(pad,mx0,mx1,my0,my1);
628 itstpcP->Draw("alp");
630 itstpcM->Draw("apl");
633 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
634 legend->AddEntry(itstpcP,"ITS-TPC smooth plus");
635 legend->AddEntry(itstpcM,"ITS-TPC smooth minus");
636 legend->AddEntry(itstpcB,"ITS-TPC smooth ");
638 picArray->AddLast(pad);
641 if (itstpcB&&laserA){
642 pad = new TCanvas("ITSTPC_LASER","ITSTPC_LASER");
643 SetPadStyle(pad,mx0,mx1,my0,my1);
648 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
649 legend->AddEntry(laserA,"TPC laser");
650 legend->AddEntry(itstpcP,"ITS-TPC smooth plus");
651 legend->AddEntry(itstpcM,"ITS-TPC smooth minus");
652 legend->AddEntry(itstpcB,"ITS-TPC smooth ");
654 picArray->AddLast(pad);
658 pad = new TCanvas("ITSTPC_CROSS","ITSTPC_CROSS");
659 SetPadStyle(pad,mx0,mx1,my0,my1);
660 itstpcP->Draw("alp");
665 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
667 legend->AddEntry(cross,"TPC cross tracks");
668 legend->AddEntry(itstpcB,"ITS-TPC smooth");
670 picArray->AddLast(pad);
672 if (itstpcP&&cosmic){
673 pad = new TCanvas("ITSTPC_COSMIC","ITSTPC_COSMIC");
674 SetPadStyle(pad,mx0,mx1,my0,my1);
675 itstpcP->Draw("alp");
680 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
682 legend->AddEntry(cosmic,"TPC cross tracks0 up-down");
683 legend->AddEntry(itstpcB,"ITS-TPC smooth");
685 picArray->AddLast(pad);
692 void AliTPCPreprocessorOffline::CalibTimeGain(Char_t* fileName, Int_t startRunNumber, Int_t endRunNumber, TString pocdbStorage){
696 ReadGainGlobal(fileName);
697 AnalyzeGain(startRunNumber,endRunNumber, 1000,1.43);
699 if (pocdbStorage.Length()==0) pocdbStorage+="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
700 UpdateOCDBGain( startRunNumber, endRunNumber, pocdbStorage.Data());
706 void AliTPCPreprocessorOffline::ReadGainGlobal(Char_t* fileName){
708 // read calibration entries from file
710 TFile fcalib(fileName);
711 TObjArray * array = (TObjArray*)fcalib.Get("TPCCalib");
713 fGainMIP = ( AliTPCcalibTimeGain *)array->FindObject("calibTimeGain");
714 fGainCosmic = ( AliTPCcalibTimeGain *)array->FindObject("calibTimeGainCosmic");
716 fGainMIP = ( AliTPCcalibTimeGain *)fcalib.Get("calibTimeGain");
717 fGainCosmic = ( AliTPCcalibTimeGain *)fcalib.Get("calibTimeGainCosmic");
720 Int_t firstBinA =0, lastBinA=0;
723 hisT= fGainCosmic->GetHistGainTime()->Projection(1);
724 firstBinA = hisT->FindFirstBinAbove(2);
725 lastBinA = hisT->FindLastBinAbove(2);
726 fGainCosmic->GetHistGainTime()->GetAxis(1)->SetRange(firstBinA,lastBinA);
731 hisT= fGainMIP->GetHistGainTime()->Projection(1);
732 firstBinA = hisT->FindFirstBinAbove(2);
733 lastBinA = hisT->FindLastBinAbove(2);
734 fGainMIP->GetHistGainTime()->GetAxis(1)->SetRange(firstBinA,lastBinA);
742 Bool_t AliTPCPreprocessorOffline::AnalyzeGain(Int_t startRunNumber, Int_t endRunNumber, Int_t minEntriesGaussFit, Float_t FPtoMIPratio){
746 fGainMIP->GetHistGainTime()->GetAxis(5)->SetRangeUser(startRunNumber, endRunNumber);
747 // 1.) try to create MIP spline
748 fGainMIP->GetHistGainTime()->GetAxis(2)->SetRangeUser(1.51,2.49); // only beam data
749 fGainMIP->GetHistGainTime()->GetAxis(4)->SetRangeUser(0.39,0.51); // only MIP pions
751 fGraphMIP = AliTPCcalibBase::FitSlices(fGainMIP->GetHistGainTime(),0,1,minEntriesGaussFit,10,0.1,0.7);
752 if (fGraphMIP->GetN()==0) fGraphMIP = 0x0;
753 if (fGraphMIP) fFitMIP = AliTPCcalibTimeGain::MakeSplineFit(fGraphMIP);
754 if (fGraphMIP) fGraphMIP->SetName("TGRAPHERRORS_MEAN_GAIN_BEAM_ALL");// set proper names according to naming convention
755 fGainArray->AddAt(fFitMIP,0);
758 // 2.) try to create Cosmic spline
759 fGainCosmic->GetHistGainTime()->GetAxis(2)->SetRangeUser(0.51,1.49); // only cosmics
760 fGainCosmic->GetHistGainTime()->GetAxis(4)->SetRangeUser(20,100); // only Fermi-Plateau muons
762 fGraphCosmic = AliTPCcalibBase::FitSlices(fGainCosmic->GetHistGainTime(),0,1,minEntriesGaussFit,10);
763 if (fGraphCosmic->GetN()==0) fGraphCosmic = 0x0;
766 for(Int_t i=0; i < fGraphCosmic->GetN(); i++) {
767 fGraphCosmic->GetY()[i] /= FPtoMIPratio;
768 fGraphCosmic->GetEY()[i] /= FPtoMIPratio;
772 if (fGraphCosmic) fFitCosmic = AliTPCcalibTimeGain::MakeSplineFit(fGraphCosmic);
773 if (fGraphCosmic) fGraphCosmic->SetName("TGRAPHERRORS_MEAN_GAIN_COSMIC_ALL"); // set proper names according to naming convention
774 fGainArray->AddAt(fFitCosmic,1);
775 // with naming convention and backward compatibility
776 fGainArray->AddAt(fGraphMIP,2);
777 fGainArray->AddAt(fGraphCosmic,3);
778 cout << "fGraphCosmic: " << fGraphCosmic << " fGraphMIP " << fGraphMIP << endl;
785 void AliTPCPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
789 AliCDBMetaData *metaData= new AliCDBMetaData();
790 metaData->SetObjectClassName("TObjArray");
791 metaData->SetResponsible("Alexander Kalweit");
792 metaData->SetBeamPeriod(1);
793 metaData->SetAliRootVersion("05-24-00"); //root version
794 metaData->SetComment("Calibration of the time dependence of the gain due to pressure and temperature changes.");
795 AliCDBId id1("TPC/Calib/TimeGain", startRunNumber, endRunNumber);
796 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
797 gStorage->Put(fGainArray, id1, metaData);
800 void AliTPCPreprocessorOffline::MakeQAPlot(Float_t FPtoMIPratio) {
802 // Make QA plot to visualize results
807 TCanvas * canvasCosmic = new TCanvas("gain Cosmic", "time dependent gain QA histogram cosmic");
809 TH2D * gainHistoCosmic = fGainCosmic->GetHistGainTime()->Projection(0,1);
810 gainHistoCosmic->SetDirectory(0);
811 gainHistoCosmic->SetName("GainHistoCosmic");
812 gainHistoCosmic->GetXaxis()->SetTimeDisplay(kTRUE);
813 gainHistoCosmic->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
814 gainHistoCosmic->Draw("colz");
815 fGraphCosmic->SetMarkerStyle(25);
816 fGraphCosmic->Draw("lp");
817 fGraphCosmic->SetMarkerStyle(25);
818 TGraph * grfFitCosmic = fFitCosmic->MakeGraph(fGraphCosmic->GetX()[0],fGraphCosmic->GetX()[fGraphCosmic->GetN()-1],50000,0);
820 for(Int_t i=0; i < grfFitCosmic->GetN(); i++) {
821 grfFitCosmic->GetY()[i] *= FPtoMIPratio;
823 for(Int_t i=0; i < fGraphCosmic->GetN(); i++) {
824 fGraphCosmic->GetY()[i] *= FPtoMIPratio;
827 fGraphCosmic->Draw("lp");
828 grfFitCosmic->SetLineColor(2);
829 grfFitCosmic->Draw("lu");
830 fGainArray->AddLast(gainHistoCosmic);
831 fGainArray->AddLast(canvasCosmic->Clone());
835 TCanvas * canvasMIP = new TCanvas("gain MIP", "time dependent gain QA histogram MIP");
837 TH2D * gainHistoMIP = fGainMIP->GetHistGainTime()->Projection(0,1);
838 gainHistoMIP->SetName("GainHistoCosmic");
839 gainHistoMIP->SetDirectory(0);
840 gainHistoMIP->GetXaxis()->SetTimeDisplay(kTRUE);
841 gainHistoMIP->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
842 gainHistoMIP->Draw("colz");
843 fGraphMIP->SetMarkerStyle(25);
844 fGraphMIP->Draw("lp");
845 TGraph * grfFitMIP = fFitMIP->MakeGraph(fGraphMIP->GetX()[0],fGraphMIP->GetX()[fGraphMIP->GetN()-1],50000,0);
846 grfFitMIP->SetLineColor(2);
847 grfFitMIP->Draw("lu");
848 fGainArray->AddLast(gainHistoMIP);
849 fGainArray->AddLast(canvasMIP->Clone());