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 TString ocdbPath="local:////"
29 ocdbPath+=gSystem->GetFromPipe("pwd");
31 proces.CalibTimeGain("CalibObjects.root",run0,run1,ocdbPath);
32 proces.CalibTimeVdrift("CalibObjects.root",run0,run1,ocdbPath);
33 // take the raw calibration data from the file CalibObjects.root
34 // and make a OCDB entry with run validity run0-run1
35 // results are stored at the ocdbPath - local or alien ...
36 // default storage ""- data stored at current working directory
39 AliTPCPreprocessorOffline process;
40 process.CalibTimeGain("CalibObjects.root",114000,121040,0);
41 TFile oo("OCDB/TPC/Calib/TimeGain/Run114000_121040_v0_s0.root")
42 TObjArray * arr = AliCDBEntry->GetObject()
43 arr->At(4)->Draw("alp")
46 #include "Riostream.h"
49 #include "TGraphErrors.h"
50 #include "AliExternalTrackParam.h"
53 #include "TMultiGraph.h"
55 #include "THnSparse.h"
60 #include "AliTPCROC.h"
61 #include "AliTPCCalROC.h"
62 #include "AliESDfriend.h"
63 #include "AliTPCcalibTime.h"
64 #include "AliSplineFit.h"
65 #include "AliCDBMetaData.h"
67 #include "AliCDBManager.h"
68 #include "AliCDBStorage.h"
69 #include "AliTPCcalibBase.h"
70 #include "AliTPCcalibDB.h"
71 #include "AliTPCcalibDButil.h"
72 #include "AliRelAlignerKalman.h"
73 #include "AliTPCParamSR.h"
74 #include "AliTPCcalibTimeGain.h"
75 #include "AliSplineFit.h"
76 #include "AliTPCPreprocessorOffline.h"
79 ClassImp(AliTPCPreprocessorOffline)
81 AliTPCPreprocessorOffline::AliTPCPreprocessorOffline():
82 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
83 fMinEntries(500), // minimal number of entries for fit
84 startRun(0), // start Run - used to make fast selection in THnSparse
85 endRun(0), // end Run - used to make fast selection in THnSparse
86 startTime(0), // startTime - used to make fast selection in THnSparse
87 endTime(0), // endTime - used to make fast selection in THnSparse
88 ocdbStorage(""), // path to the OCDB storage
89 fVdriftArray(new TObjArray),
91 fGraphMIP(0), // graph time dependence of MIP
92 fGraphCosmic(0), // graph time dependence at Plateu
93 fGraphAttachmentMIP(0),
94 fFitMIP(0), // fit of dependence - MIP
95 fFitCosmic(0), // fit of dependence - Plateu
96 fGainArray(new TObjArray), // array to be stored in the OCDB
97 fGainMIP(0), // calibration component for MIP
98 fGainCosmic(0), // calibration component for cosmic
99 fSwitchOnValidation(kFALSE) // flag to switch on validation of OCDB parameters
102 // default constructor
106 AliTPCPreprocessorOffline::~AliTPCPreprocessorOffline() {
115 void AliTPCPreprocessorOffline::GetRunRange(AliTPCcalibTime * const timeDrift){
117 // find the fist and last run
119 TObjArray *hisArray =timeDrift->GetHistoDrift();
120 {for (Int_t i=0; i<hisArray->GetEntriesFast(); i++){
121 THnSparse* addHist=(THnSparse*)hisArray->UncheckedAt(i);
122 if (addHist->GetEntries()<fMinEntries) continue;
123 if (!addHist) continue;
124 TH1D* histo =addHist->Projection(3);
125 TH1D* histoTime=addHist->Projection(0);
126 printf("%s\t%f\t%d\t%d\n",histo->GetName(), histo->GetEntries(),histo->FindFirstBinAbove(0),histo->FindLastBinAbove(0));
129 startRun=histo->FindFirstBinAbove(0);
130 endRun =histo->FindLastBinAbove(0);
132 startRun=TMath::Min(histo->FindFirstBinAbove(0),startRun);
133 endRun =TMath::Max(histo->FindLastBinAbove(0),endRun);
136 startTime=histoTime->FindFirstBinAbove(0);
137 endTime =histoTime->FindLastBinAbove(0);
139 startTime=TMath::Min(histoTime->FindFirstBinAbove(0),startTime);
140 endTime =TMath::Max(histoTime->FindLastBinAbove(0),endTime);
145 if (startRun<0) startRun=0;
146 if (endRun<0) endRun=100000000;
147 printf("Run range :\t%d-%d\n", startRun, endRun);
148 printf("Time range :\t%d-%d\n", startTime, endTime);
154 void AliTPCPreprocessorOffline::CalibTimeVdrift(const Char_t* file, Int_t ustartRun, Int_t uendRun, TString pocdbStorage){
156 // make calibration of the drift velocity
158 // file - the location of input file
159 // ustartRun, uendrun - run validity period
160 // pocdbStorage - path to hte OCDB storage
161 // - if empty - local storage 'pwd' uesed
162 if (pocdbStorage.Length()>0) ocdbStorage=pocdbStorage;
164 ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
166 // 1. Initialization and run range setting
168 TObjArray * array = (TObjArray*)fcalib.Get("TPCCalib");
170 fTimeDrift = (AliTPCcalibTime *)array->FindObject("calibTime");
172 fTimeDrift = (AliTPCcalibTime*)fcalib.Get("calibTime");
174 if(!fTimeDrift) return;
178 TObjArray *hisArray =fTimeDrift->GetHistoDrift();
179 GetRunRange(fTimeDrift);
180 for (Int_t i=0; i<hisArray->GetEntriesFast(); i++){
181 THnSparse* addHist=(THnSparse*)hisArray->At(i);
182 if (!addHist) continue;
183 if (startTime<endTime) addHist->GetAxis(0)->SetRange(startTime-1,endTime+1);
184 if (startRun<endRun) addHist->GetAxis(3)->SetRange(startRun-1,endRun+1);
188 // 2. extraction of the information
190 fVdriftArray = new TObjArray();
191 AddAlignmentGraphs(fVdriftArray,fTimeDrift);
192 AddHistoGraphs(fVdriftArray,fTimeDrift,fMinEntries);
193 AddLaserGraphs(fVdriftArray,fTimeDrift);
195 // 3. Append QA plots
197 MakeDefaultPlots(fVdriftArray,fVdriftArray);
200 // 4. validate OCDB entries
202 if(fSwitchOnValidation==kTRUE && ValidateTimeDrift()==kFALSE) {
203 Printf("TPC time drift OCDB parameters out of range!");
212 UpdateOCDBDrift(ustartRun,uendRun,ocdbStorage);
215 void AliTPCPreprocessorOffline::UpdateOCDBDrift( Int_t ustartRun, Int_t uendRun, const char* storagePath ){
219 AliCDBMetaData *metaData= new AliCDBMetaData();
220 metaData->SetObjectClassName("TObjArray");
221 metaData->SetResponsible("Marian Ivanov");
222 metaData->SetBeamPeriod(1);
223 metaData->SetAliRootVersion("05-25-01"); //root version
224 metaData->SetComment("Calibration of the time dependence of the drift velocity");
226 id1=new AliCDBId("TPC/Calib/TimeDrift", ustartRun, uendRun);
227 AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
228 gStorage->Put(fVdriftArray, (*id1), metaData);
231 Bool_t AliTPCPreprocessorOffline::ValidateTimeGain(Double_t minGain, Double_t maxGain)
234 // Validate time gain corrections
236 Printf("ValidateTimeGain..." );
238 TGraphErrors *gr = (TGraphErrors*)fGainArray->FindObject("TGRAPHERRORS_MEAN_GAIN_BEAM_ALL");
239 if(!gr) return kFALSE;
240 if(gr->GetN()<1) return kFALSE;
242 // check whether gain in the range
243 for(Int_t iPoint=0; iPoint<gr->GetN(); iPoint++)
245 if(gr->GetY()[iPoint] < minGain || gr->GetY()[iPoint] > maxGain)
253 Bool_t AliTPCPreprocessorOffline::ValidateTimeDrift(Double_t maxVDriftCorr)
256 // Validate time drift velocity corrections
258 Printf("ValidateTimeDrift..." );
260 TGraphErrors* gr = (TGraphErrors*)fVdriftArray->FindObject("ALIGN_ITSB_TPC_DRIFTVD");
261 if(!gr) return kFALSE;
262 if(gr->GetN()<1) return kFALSE;
264 // check whether drift velocity corrections in the range
265 for(Int_t iPoint = 0; iPoint<gr->GetN(); iPoint++)
267 if(TMath::Abs(gr->GetY()[iPoint]) > maxVDriftCorr)
274 void AliTPCPreprocessorOffline::UpdateDriftParam(AliTPCParam *param, TObjArray *const arr, Int_t lstartRun){
276 // update the OCDB entry for the nominal time0
279 // AliTPCParam * param = AliTPCcalibDB::Instance()->GetParameters();
280 AliTPCParam *paramNew = (AliTPCParam *)param->Clone();
281 TGraphErrors *grT = (TGraphErrors *)arr->FindObject("ALIGN_ITSM_TPC_T0");
282 Double_t deltaTcm = TMath::Median(grT->GetN(),grT->GetY());
283 Double_t deltaT = deltaTcm/param->GetDriftV();
284 paramNew->SetL1Delay(param->GetL1Delay()-deltaT);
287 AliCDBMetaData *metaData= new AliCDBMetaData();
288 metaData->SetObjectClassName("TObjArray");
289 metaData->SetResponsible("Marian Ivanov");
290 metaData->SetBeamPeriod(1);
291 metaData->SetAliRootVersion("05-25-02"); //root version
292 metaData->SetComment("Updated calibration of nominal time 0");
294 id1=new AliCDBId("TPC/Calib/Parameters", lstartRun, AliCDBRunRange::Infinity());
295 AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
296 gStorage->Put(param, (*id1), metaData);
301 void AliTPCPreprocessorOffline::PrintArray(TObjArray *array){
303 // Print the names of the entries in array
305 Int_t entries = array->GetEntries();
306 for (Int_t i=0; i<entries; i++){
307 if (!array->At(i)) continue;
308 printf("%d\t %s\n", i, array->At(i)->GetName());
314 TGraphErrors* AliTPCPreprocessorOffline::FilterGraphDrift(TGraphErrors * graph, Float_t errSigmaCut, Float_t medianCutAbs){
316 // 1. filter graph - error cut errSigmaCut
317 // 2. filter graph - medianCutAbs around median
319 // errSigmaCut - cut on error
320 // medianCutAbs - cut on value around median
323 // 1. filter graph - error cut errSigmaCut
325 TGraphErrors *graphF;
326 graphF = AliTPCcalibDButil::FilterGraphMedianErr(graph,errSigmaCut,dummy);
328 if (!graphF) return 0;
329 graph = AliTPCcalibDButil::FilterGraphMedianErr(graphF,errSigmaCut,dummy);
331 if (!graph) return 0;
333 // filter graph - kMedianCutAbs around median
335 graphF=FilterGraphMedianAbs(graph, medianCutAbs,dummy);
337 if (!graphF) return 0;
338 graph=FilterGraphMedianAbs(graphF, medianCutAbs,dummy);
340 if (!graph) return 0;
346 TGraphErrors* AliTPCPreprocessorOffline::FilterGraphMedianAbs(TGraphErrors * graph, Float_t cut,Double_t &medianY){
348 // filter outlyer measurement
349 // Only points around median +- cut filtered
351 if (!graph) return 0;
353 Int_t npoints0 = graph->GetN();
356 Double_t *outx=new Double_t[npoints0];
357 Double_t *outy=new Double_t[npoints0];
358 Double_t *errx=new Double_t[npoints0];
359 Double_t *erry=new Double_t[npoints0];
362 if (npoints0<kMinPoints) return 0;
363 for (Int_t iter=0; iter<3; iter++){
365 for (Int_t ipoint=0; ipoint<npoints0; ipoint++){
366 if (graph->GetY()[ipoint]==0) continue;
367 if (iter>0 &&TMath::Abs(graph->GetY()[ipoint]-medianY)>cut) continue;
368 outx[npoints] = graph->GetX()[ipoint];
369 outy[npoints] = graph->GetY()[ipoint];
370 errx[npoints] = graph->GetErrorX(ipoint);
371 erry[npoints] = graph->GetErrorY(ipoint);
374 if (npoints<=1) break;
375 medianY =TMath::Median(npoints,outy);
376 rmsY =TMath::RMS(npoints,outy);
378 TGraphErrors *graphOut=0;
379 if (npoints>1) graphOut= new TGraphErrors(npoints,outx,outy,errx,erry);
388 void AliTPCPreprocessorOffline::AddHistoGraphs( TObjArray * vdriftArray, AliTPCcalibTime * const timeDrift, Int_t minEntries){
390 // Add graphs corresponding to the alignment
392 const Double_t kErrSigmaCut=5; // error sigma cut - for filtering
393 const Double_t kMedianCutAbs=0.03; // error sigma cut - for filtering
395 TObjArray * array=timeDrift->GetHistoDrift();
397 THnSparse* hist=NULL;
398 // 2.a) cosmics with different triggers
399 for (Int_t i=0; i<array->GetEntriesFast();i++){
400 hist=(THnSparseF*)array->UncheckedAt(i);
402 if (hist->GetEntries()<minEntries) continue;
404 TString name=hist->GetName();
405 Int_t dim[4]={0,1,2,3};
406 THnSparse* newHist=hist->Projection(4,dim);
407 newHist->SetName(name);
408 TGraphErrors* graph=AliTPCcalibBase::FitSlices(newHist,2,0,400,100,0.05,0.95, kTRUE);
409 printf("name=%s graph=%i, N=%i\n", name.Data(), graph==0, graph->GetN());
410 Int_t pos=name.Index("_");
411 name=name(pos,name.Capacity()-pos);
412 TString graphName=graph->ClassName();
416 graph = FilterGraphDrift(graph, kErrSigmaCut, kMedianCutAbs);
418 printf("Graph =%s filtered out\n", name.Data());
422 graph->SetMarkerStyle(i%8+20);
423 graph->SetMarkerColor(i%7);
424 graph->GetXaxis()->SetTitle("Time");
425 graph->GetYaxis()->SetTitle("v_{dcor}");
426 graph->SetName(graphName);
427 graph->SetTitle(graphName);
428 printf("Graph %d\t=\t%s\n", i, graphName.Data());
429 vdriftArray->Add(graph);
438 void AliTPCPreprocessorOffline::AddAlignmentGraphs( TObjArray * vdriftArray, AliTPCcalibTime *const timeDrift){
440 // Add graphs corresponding to alignment to the object array
442 TObjArray *arrayITS=0;
443 TObjArray *arrayTOF=0;
444 TObjArray *arrayTRD=0;
445 TMatrixD *mstatITS=0;
446 TMatrixD *mstatTOF=0;
447 TMatrixD *mstatTRD=0;
449 arrayITS=timeDrift->GetAlignITSTPC();
450 arrayTRD=timeDrift->GetAlignTRDTPC();
451 arrayTOF=timeDrift->GetAlignTOFTPC();
453 if (arrayITS->GetEntries()>0) mstatITS= AliTPCcalibDButil::MakeStatRelKalman(arrayITS,0.9,50,0.025);
454 if (arrayTOF->GetEntries()>0) mstatTOF= AliTPCcalibDButil::MakeStatRelKalman(arrayTOF,0.9,1000,0.025);
455 if (arrayTRD->GetEntries()>0) mstatTRD= AliTPCcalibDButil::MakeStatRelKalman(arrayTRD,0.9,50,0.025);
457 TObjArray * arrayITSP= AliTPCcalibDButil::SmoothRelKalman(arrayITS,*mstatITS, 0, 5.);
458 TObjArray * arrayITSM= AliTPCcalibDButil::SmoothRelKalman(arrayITS,*mstatITS, 1, 5.);
459 TObjArray * arrayITSB= AliTPCcalibDButil::SmoothRelKalman(arrayITSP,arrayITSM);
460 TObjArray * arrayTOFP= AliTPCcalibDButil::SmoothRelKalman(arrayTOF,*mstatTOF, 0, 5.);
461 TObjArray * arrayTOFM= AliTPCcalibDButil::SmoothRelKalman(arrayTOF,*mstatTOF, 1, 5.);
462 TObjArray * arrayTOFB= AliTPCcalibDButil::SmoothRelKalman(arrayTOFP,arrayTOFM);
464 TObjArray * arrayTRDP= 0x0;
465 TObjArray * arrayTRDM= 0x0;
466 TObjArray * arrayTRDB= 0x0;
467 arrayTRDP= AliTPCcalibDButil::SmoothRelKalman(arrayTRD,*mstatTRD, 0, 5.);
468 arrayTRDM= AliTPCcalibDButil::SmoothRelKalman(arrayTRD,*mstatTRD, 1, 5.);
469 arrayTRDB= AliTPCcalibDButil::SmoothRelKalman(arrayTRDP,arrayTRDM);
472 Int_t entries=TMath::Max(arrayITS->GetEntriesFast(),arrayTOF->GetEntriesFast());
473 TObjArray *arrays[12]={arrayITS, arrayITSP, arrayITSM, arrayITSB,
474 arrayTRD, arrayTRDP, arrayTRDM, arrayTRDB,
475 arrayTOF, arrayTOFP, arrayTOFM, arrayTOFB};
476 TString grnames[12]={"ALIGN_ITS", "ALIGN_ITSP", "ALIGN_ITSM", "ALIGN_ITSB",
477 "ALIGN_TRD", "ALIGN_TRDP", "ALIGN_TRDM","ALIGN_TRDB",
478 "ALIGN_TOF", "ALIGN_TOFP", "ALIGN_TOFM","ALIGN_TOFB"};
479 TString grpar[9]={"DELTAPSI", "DELTATHETA", "DELTAPHI",
480 "DELTAX", "DELTAY", "DELTAZ",
481 "DRIFTVD", "T0", "VDGY"};
484 TVectorD vX(entries);
485 TVectorD vY(entries);
486 TVectorD vEx(entries);
487 TVectorD vEy(entries);
489 for (Int_t iarray=0; iarray<12; iarray++){
490 arr = arrays[iarray];
491 if (arr==0) continue;
492 for (Int_t ipar=0; ipar<9; ipar++){
494 for (Int_t itime=0; itime<arr->GetEntriesFast(); itime++){
495 AliRelAlignerKalman * kalman = (AliRelAlignerKalman *) arr->UncheckedAt(itime);
496 if (!kalman) continue;
497 vX[counter]=kalman->GetTimeStamp();
498 vY[counter]=(*(kalman->GetState()))[ipar];
499 if (ipar==6) vY[counter]=1./(*(kalman->GetState()))[ipar]-1;
501 vEy[counter]=TMath::Sqrt((*(kalman->GetStateCov()))(ipar,ipar));
505 TGraphErrors * graph=new TGraphErrors(counter, vX.GetMatrixArray(),
507 vEx.GetMatrixArray(),
508 vEy.GetMatrixArray());
509 TString grName=grnames[iarray];
512 graph->SetName(grName.Data());
513 vdriftArray->AddLast(graph);
521 void AliTPCPreprocessorOffline::AddLaserGraphs( TObjArray * vdriftArray, AliTPCcalibTime *timeDrift){
523 // add graphs for laser
525 const Double_t delayL0L1 = 0.071; //this is hack for 1/2 weeks
527 TGraphErrors *grLaser[6]={0,0,0,0,0,0};
528 hisN = timeDrift->GetHistVdriftLaserA(0);
529 if (timeDrift->GetHistVdriftLaserA(0)){
530 grLaser[0]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserA(0),0,2,5,delayL0L1);
531 grLaser[0]->SetName("GRAPH_MEAN_DELAY_LASER_ALL_A");
532 vdriftArray->AddLast(grLaser[0]);
534 if (timeDrift->GetHistVdriftLaserA(1)){
535 grLaser[1]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserA(1),0,2,5);
536 grLaser[1]->SetName("GRAPH_MEAN_DRIFT_LASER_ALL_A");
537 vdriftArray->AddLast(grLaser[1]);
539 if (timeDrift->GetHistVdriftLaserA(2)){
540 grLaser[2]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserA(2),0,2,5);
541 grLaser[2]->SetName("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_A");
542 vdriftArray->AddLast(grLaser[2]);
544 if (timeDrift->GetHistVdriftLaserC(0)){
545 grLaser[3]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserC(0),0,2,5,delayL0L1);
546 grLaser[3]->SetName("GRAPH_MEAN_DELAY_LASER_ALL_C");
547 vdriftArray->AddLast(grLaser[3]);
549 if (timeDrift->GetHistVdriftLaserC(1)){
550 grLaser[4]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserC(1),0,2,5);
551 grLaser[4]->SetName("GRAPH_MEAN_DRIFT_LASER_ALL_C");
552 vdriftArray->AddLast(grLaser[4]);
554 if (timeDrift->GetHistVdriftLaserC(2)){
555 grLaser[5]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserC(2),0,2,5);
556 grLaser[5]->SetName("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_C");
557 vdriftArray->AddLast(grLaser[5]);
559 for (Int_t i=0; i<6;i++){
561 SetDefaultGraphDrift(grLaser[i], 1,(i+20));
562 grLaser[i]->GetYaxis()->SetTitle("Laser Correction");
568 TGraphErrors * AliTPCPreprocessorOffline::MakeGraphFilter0(THnSparse *hisN, Int_t itime, Int_t ival, Int_t minEntries, Double_t offset){
570 // Make graph with mean values and rms
572 hisN->GetAxis(itime)->SetRange(0,100000000);
573 hisN->GetAxis(ival)->SetRange(0,100000000);
574 TH1 * hisT = hisN->Projection(itime);
575 TH1 * hisV = hisN->Projection(ival);
577 Int_t firstBinA = hisT->FindFirstBinAbove(2);
578 Int_t lastBinA = hisT->FindLastBinAbove(2);
579 Int_t firstBinV = hisV->FindFirstBinAbove(0);
580 Int_t lastBinV = hisV->FindLastBinAbove(0);
581 hisN->GetAxis(itime)->SetRange(firstBinA,lastBinA);
582 hisN->GetAxis(ival)->SetRange(firstBinV,lastBinV);
584 for (Int_t ibin=firstBinA; ibin<=lastBinA; ibin++){
585 Double_t cont = hisT->GetBinContent(ibin);
586 if (cont<minEntries) continue;
589 TVectorD vecTime(entries);
590 TVectorD vecMean0(entries);
591 TVectorD vecRMS0(entries);
592 TVectorD vecMean1(entries);
593 TVectorD vecRMS1(entries);
595 for (Int_t ibin=firstBinA; ibin<=lastBinA; ibin++){
596 Double_t cont = hisT->GetBinContent(ibin);
597 if (cont<minEntries) continue;
598 //hisN->GetAxis(itime)->SetRange(ibin-1,ibin+1);
599 Int_t minBin = ibin-1;
600 Int_t maxBin = ibin+1;
601 if(minBin <= 0) minBin = 1;
602 if(maxBin >= hisN->GetAxis(itime)->GetNbins()) maxBin = hisN->GetAxis(itime)->GetNbins()-1;
603 hisN->GetAxis(itime)->SetRange(minBin,maxBin);
605 Double_t time = hisT->GetBinCenter(ibin);
606 TH1 * his = hisN->Projection(ival);
607 Double_t nentries0= his->GetBinContent(his->FindBin(0));
608 if (cont-nentries0<minEntries) continue;
610 his->SetBinContent(his->FindBin(0),0);
611 vecTime[entries]=time;
612 vecMean0[entries]=his->GetMean()+offset;
613 vecMean1[entries]=his->GetMeanError();
614 vecRMS0[entries] =his->GetRMS();
615 vecRMS1[entries] =his->GetRMSError();
621 TGraphErrors * graph = new TGraphErrors(entries,vecTime.GetMatrixArray(), vecMean0.GetMatrixArray(), 0, vecMean1.GetMatrixArray());
632 void AliTPCPreprocessorOffline::SetDefaultGraphDrift(TGraph *graph, Int_t color, Int_t style){
634 // Set default style for QA views
636 graph->GetXaxis()->SetTimeDisplay(kTRUE);
637 graph->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
638 graph->SetMaximum( 0.025);
639 graph->SetMinimum(-0.025);
640 graph->GetXaxis()->SetTitle("Time");
641 graph->GetYaxis()->SetTitle("v_{dcorr}");
643 graph->GetYaxis()->SetLabelSize(0.03);
644 graph->GetXaxis()->SetLabelSize(0.03);
646 graph->GetXaxis()->SetNdivisions(10,5,0);
647 graph->GetYaxis()->SetNdivisions(10,5,0);
649 graph->GetXaxis()->SetLabelOffset(0.02);
650 graph->GetYaxis()->SetLabelOffset(0.005);
652 graph->GetXaxis()->SetTitleOffset(1.3);
653 graph->GetYaxis()->SetTitleOffset(1.2);
655 graph->SetMarkerColor(color);
656 graph->SetLineColor(color);
657 graph->SetMarkerStyle(style);
660 void AliTPCPreprocessorOffline::SetPadStyle(TPad *pad, Float_t mx0, Float_t mx1, Float_t my0, Float_t my1){
662 // Set default pad style for QA
665 pad->SetMargin(mx0,mx1,my0,my1);
669 void AliTPCPreprocessorOffline::MakeDefaultPlots(TObjArray * const arr, TObjArray * /*picArray*/){
671 // 0. make a default QA plots
672 // 1. Store them in the array
675 Float_t mx0=0.12, mx1=0.1, my0=0.15, my1=0.1;
677 TGraphErrors* laserA =(TGraphErrors*)arr->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_A");
678 TGraphErrors* laserC =(TGraphErrors*)arr->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_C");
679 TGraphErrors* cosmic =(TGraphErrors*)arr->FindObject("TGRAPHERRORS_MEAN_VDRIFT_COSMICS_ALL");
680 TGraphErrors* cross =(TGraphErrors*)arr->FindObject("TGRAPHERRORS_VDRIFT_CROSS_ALL");
681 TGraphErrors* itstpcP =(TGraphErrors*)arr->FindObject("ALIGN_ITSP_TPC_DRIFTVD");
682 TGraphErrors* itstpcM =(TGraphErrors*)arr->FindObject("ALIGN_ITSM_TPC_DRIFTVD");
683 TGraphErrors* itstpcB =(TGraphErrors*)arr->FindObject("ALIGN_ITSB_TPC_DRIFTVD");
685 if (laserA) SetDefaultGraphDrift(laserA,2,25);
686 if (laserC) SetDefaultGraphDrift(laserC,4,26);
687 if (cosmic) SetDefaultGraphDrift(cosmic,3,27);
688 if (cross) SetDefaultGraphDrift(cross,4,28);
689 if (itstpcP) SetDefaultGraphDrift(itstpcP,2,29);
690 if (itstpcM) SetDefaultGraphDrift(itstpcM,4,30);
691 if (itstpcB) SetDefaultGraphDrift(itstpcB,1,31);
699 pad = new TCanvas("TPCLaserVDrift","TPCLaserVDrift");
701 SetPadStyle(pad,mx0,mx1,my0,my1);
704 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
705 legend->AddEntry(laserA,"Laser A side");
706 legend->AddEntry(laserC,"Laser C side");
708 //picArray->AddLast(pad);
711 if (itstpcP&&itstpcM&&itstpcB){
712 pad = new TCanvas("ITSTPC","ITSTPC");
713 itstpcP->Draw("alp");
714 SetPadStyle(pad,mx0,mx1,my0,my1);
715 itstpcP->Draw("alp");
717 itstpcM->Draw("apl");
720 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
721 legend->AddEntry(itstpcP,"ITS-TPC smooth plus");
722 legend->AddEntry(itstpcM,"ITS-TPC smooth minus");
723 legend->AddEntry(itstpcB,"ITS-TPC smooth ");
725 //picArray->AddLast(pad);
728 if (itstpcB&&laserA&&itstpcP&&itstpcM){
729 pad = new TCanvas("ITSTPC_LASER","ITSTPC_LASER");
730 SetPadStyle(pad,mx0,mx1,my0,my1);
735 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
736 legend->AddEntry(laserA,"TPC laser");
737 legend->AddEntry(itstpcP,"ITS-TPC smooth plus");
738 legend->AddEntry(itstpcM,"ITS-TPC smooth minus");
739 legend->AddEntry(itstpcB,"ITS-TPC smooth ");
741 //picArray->AddLast(pad);
745 pad = new TCanvas("ITSTPC_CROSS","ITSTPC_CROSS");
746 SetPadStyle(pad,mx0,mx1,my0,my1);
747 itstpcP->Draw("alp");
752 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
754 legend->AddEntry(cross,"TPC cross tracks");
755 legend->AddEntry(itstpcB,"ITS-TPC smooth");
757 //picArray->AddLast(pad);
759 if (itstpcP&&cosmic){
760 pad = new TCanvas("ITSTPC_COSMIC","ITSTPC_COSMIC");
761 SetPadStyle(pad,mx0,mx1,my0,my1);
762 itstpcP->Draw("alp");
767 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
769 legend->AddEntry(cosmic,"TPC cross tracks0 up-down");
770 legend->AddEntry(itstpcB,"ITS-TPC smooth");
772 //picArray->AddLast(pad);
779 void AliTPCPreprocessorOffline::CalibTimeGain(const Char_t* fileName, Int_t startRunNumber, Int_t endRunNumber, TString pocdbStorage){
783 if (pocdbStorage.Length()==0) pocdbStorage+="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
786 // 1. Read gain values
788 ReadGainGlobal(fileName);
791 // 2. Extract calibration values
793 AnalyzeGain(startRunNumber,endRunNumber, 1000,1.43);
794 AnalyzeAttachment(startRunNumber,endRunNumber);
797 // 3. Make control plots
802 // 4. validate OCDB entries
804 if(fSwitchOnValidation==kTRUE && ValidateTimeGain()==kFALSE) {
805 Printf("TPC time gain OCDB parameters out of range!");
812 UpdateOCDBGain( startRunNumber, endRunNumber, pocdbStorage.Data());
815 void AliTPCPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
817 // read calibration entries from file
819 TFile fcalib(fileName);
820 TObjArray * array = (TObjArray*)fcalib.Get("TPCCalib");
822 fGainMIP = ( AliTPCcalibTimeGain *)array->FindObject("calibTimeGain");
823 fGainCosmic = ( AliTPCcalibTimeGain *)array->FindObject("calibTimeGainCosmic");
825 fGainMIP = ( AliTPCcalibTimeGain *)fcalib.Get("calibTimeGain");
826 fGainCosmic = ( AliTPCcalibTimeGain *)fcalib.Get("calibTimeGainCosmic");
829 Int_t firstBinA =0, lastBinA=0;
832 hisT= fGainCosmic->GetHistGainTime()->Projection(1);
833 firstBinA = hisT->FindFirstBinAbove(2);
834 lastBinA = hisT->FindLastBinAbove(2);
835 fGainCosmic->GetHistGainTime()->GetAxis(1)->SetRange(firstBinA,lastBinA);
840 hisT= fGainMIP->GetHistGainTime()->Projection(1);
841 firstBinA = hisT->FindFirstBinAbove(2);
842 lastBinA = hisT->FindLastBinAbove(2);
843 fGainMIP->GetHistGainTime()->GetAxis(1)->SetRange(firstBinA,lastBinA);
851 Bool_t AliTPCPreprocessorOffline::AnalyzeGain(Int_t startRunNumber, Int_t endRunNumber, Int_t minEntriesGaussFit, Float_t FPtoMIPratio){
853 // Analyze gain - produce the calibration graphs
856 // 1.) try to create MIP spline
859 fGainMIP->GetHistGainTime()->GetAxis(5)->SetRangeUser(startRunNumber, endRunNumber);
860 fGainMIP->GetHistGainTime()->GetAxis(2)->SetRangeUser(1.51,2.49); // only beam data
861 fGainMIP->GetHistGainTime()->GetAxis(4)->SetRangeUser(0.39,0.51); // only MIP pions
863 fGraphMIP = AliTPCcalibBase::FitSlices(fGainMIP->GetHistGainTime(),0,1,minEntriesGaussFit,10,0.1,0.7);
864 if (fGraphMIP->GetN()==0) fGraphMIP = 0x0;
865 if (fGraphMIP) fFitMIP = AliTPCcalibTimeGain::MakeSplineFit(fGraphMIP);
866 if (fGraphMIP) fGraphMIP->SetName("TGRAPHERRORS_MEAN_GAIN_BEAM_ALL");// set proper names according to naming convention
867 fGainArray->AddAt(fFitMIP,0);
870 // 2.) try to create Cosmic spline
873 fGainCosmic->GetHistGainTime()->GetAxis(2)->SetRangeUser(0.51,1.49); // only cosmics
874 fGainCosmic->GetHistGainTime()->GetAxis(4)->SetRangeUser(20,100); // only Fermi-Plateau muons
876 fGraphCosmic = AliTPCcalibBase::FitSlices(fGainCosmic->GetHistGainTime(),0,1,minEntriesGaussFit,10);
877 if (fGraphCosmic->GetN()==0) fGraphCosmic = 0x0;
880 for(Int_t i=0; i < fGraphCosmic->GetN(); i++) {
881 fGraphCosmic->GetY()[i] /= FPtoMIPratio;
882 fGraphCosmic->GetEY()[i] /= FPtoMIPratio;
886 if (fGraphCosmic) fFitCosmic = AliTPCcalibTimeGain::MakeSplineFit(fGraphCosmic);
887 if (fGraphCosmic) fGraphCosmic->SetName("TGRAPHERRORS_MEAN_GAIN_COSMIC_ALL"); // set proper names according to naming convention
888 fGainArray->AddAt(fFitCosmic,1);
890 // with naming convention and backward compatibility
891 fGainArray->AddAt(fGraphMIP,2);
892 fGainArray->AddAt(fGraphCosmic,3);
893 cout << "fGraphCosmic: " << fGraphCosmic << " fGraphMIP " << fGraphMIP << endl;
898 Bool_t AliTPCPreprocessorOffline::AnalyzeAttachment(Int_t startRunNumber, Int_t endRunNumber, Int_t minEntriesFit) {
900 // determine slope as a function of mean driftlength
902 if(!fGainMIP) return kFALSE;
904 fGainMIP->GetHistGainTime()->GetAxis(5)->SetRangeUser(startRunNumber, endRunNumber);
906 fGainMIP->GetHistGainTime()->GetAxis(2)->SetRangeUser(1.51,2.49); // only beam data
907 fGainMIP->GetHistGainTime()->GetAxis(4)->SetRangeUser(0.39,0.51); // only MIP pions
909 fGainMIP->GetHistGainTime()->GetAxis(3)->SetRangeUser(125,250);// only full tracking region (driftlength)
910 fGainMIP->GetHistGainTime()->GetAxis(0)->SetRangeUser(1.5,3.5);// only full tracking region (driftlength)
912 TH3D * hist = fGainMIP->GetHistGainTime()->Projection(1, 0, 3);
914 Double_t *xvec = new Double_t[hist->GetNbinsX()];
915 Double_t *yvec = new Double_t[hist->GetNbinsX()];
916 Double_t *xerr = new Double_t[hist->GetNbinsX()];
917 Double_t *yerr = new Double_t[hist->GetNbinsX()];
920 for(Int_t i=1; i < hist->GetNbinsX(); i++) {
924 for (Int_t idelta=0; idelta<5; idelta++){
926 imin = TMath::Max(i-idelta,1);
927 imax = TMath::Min(i+idelta,hist->GetNbinsX());
928 nsum = TMath::Nint(hist->Integral(imin,imax,1,hist->GetNbinsY()-1,1,hist->GetNbinsZ()-1));
929 //if (nsum==0) break;
930 if (nsum>minEntriesFit) break;
932 if (nsum<minEntriesFit) continue;
934 fGainMIP->GetHistGainTime()->GetAxis(1)->SetRangeUser(hist->GetXaxis()->GetBinCenter(imin-1),hist->GetXaxis()->GetBinCenter(imax+1)); // define time range
935 TH2D * histZdep = fGainMIP->GetHistGainTime()->Projection(0,3);
937 histZdep->FitSlicesY(0,0,-1,0,"QNR",&arr);
938 TH1D * driftDep = (TH1D*)arr.At(1);
940 //TGraphErrors * driftDep = AliTPCcalibBase::FitSlices(fGainMIP->GetHistGainTime(),0,3,100,1,0.,1);
941 /*if (driftDep->GetN() < 4) {
948 TF1 pol1("polynom1","pol1",125,240);
949 //driftDep->Fit(&pol1,"QNRROB=0.8");
950 driftDep->Fit(&pol1,"QNR");
951 xvec[counter] = 0.5*(hist->GetXaxis()->GetBinCenter(imin-1)+hist->GetXaxis()->GetBinCenter(imax+1));
952 yvec[counter] = pol1.GetParameter(1)/pol1.GetParameter(0);
953 xerr[counter] = hist->GetXaxis()->GetBinCenter(imax+1)-hist->GetXaxis()->GetBinCenter(imin-1);
954 yerr[counter] = pol1.GetParError(1)/pol1.GetParameter(0);
960 fGraphAttachmentMIP = new TGraphErrors(counter, xvec, yvec, xerr, yerr);
961 if (fGraphAttachmentMIP) fGraphAttachmentMIP->SetName("TGRAPHERRORS_MEAN_ATTACHMENT_BEAM_ALL");// set proper names according to naming convention
962 fGainArray->AddLast(fGraphAttachmentMIP);
970 if (counter < 1) return kFALSE;
976 void AliTPCPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
980 AliCDBMetaData *metaData= new AliCDBMetaData();
981 metaData->SetObjectClassName("TObjArray");
982 metaData->SetResponsible("Alexander Kalweit");
983 metaData->SetBeamPeriod(1);
984 metaData->SetAliRootVersion("05-24-00"); //root version
985 metaData->SetComment("Calibration of the time dependence of the gain due to pressure and temperature changes.");
986 AliCDBId id1("TPC/Calib/TimeGain", startRunNumber, endRunNumber);
987 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
988 gStorage->Put(fGainArray, id1, metaData);
991 void AliTPCPreprocessorOffline::MakeQAPlot(Float_t FPtoMIPratio) {
993 // Make QA plot to visualize results
998 TCanvas * canvasCosmic = new TCanvas("gain Cosmic", "time dependent gain QA histogram cosmic");
1000 TH2D * gainHistoCosmic = fGainCosmic->GetHistGainTime()->Projection(0,1);
1001 gainHistoCosmic->SetDirectory(0);
1002 gainHistoCosmic->SetName("GainHistoCosmic");
1003 gainHistoCosmic->GetXaxis()->SetTimeDisplay(kTRUE);
1004 gainHistoCosmic->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
1005 gainHistoCosmic->Draw("colz");
1006 fGraphCosmic->SetMarkerStyle(25);
1007 fGraphCosmic->Draw("lp");
1008 fGraphCosmic->SetMarkerStyle(25);
1009 TGraph * grfFitCosmic = fFitCosmic->MakeGraph(fGraphCosmic->GetX()[0],fGraphCosmic->GetX()[fGraphCosmic->GetN()-1],50000,0);
1011 for(Int_t i=0; i < grfFitCosmic->GetN(); i++) {
1012 grfFitCosmic->GetY()[i] *= FPtoMIPratio;
1014 for(Int_t i=0; i < fGraphCosmic->GetN(); i++) {
1015 fGraphCosmic->GetY()[i] *= FPtoMIPratio;
1018 fGraphCosmic->Draw("lp");
1019 grfFitCosmic->SetLineColor(2);
1020 grfFitCosmic->Draw("lu");
1021 fGainArray->AddLast(gainHistoCosmic);
1022 //fGainArray->AddLast(canvasCosmic->Clone());
1023 delete canvasCosmic;
1027 TCanvas * canvasMIP = new TCanvas("gain MIP", "time dependent gain QA histogram MIP");
1029 TH2D * gainHistoMIP = fGainMIP->GetHistGainTime()->Projection(0,1);
1030 gainHistoMIP->SetName("GainHistoCosmic");
1031 gainHistoMIP->SetDirectory(0);
1032 gainHistoMIP->GetXaxis()->SetTimeDisplay(kTRUE);
1033 gainHistoMIP->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
1034 gainHistoMIP->Draw("colz");
1035 fGraphMIP->SetMarkerStyle(25);
1036 fGraphMIP->Draw("lp");
1037 TGraph * grfFitMIP = fFitMIP->MakeGraph(fGraphMIP->GetX()[0],fGraphMIP->GetX()[fGraphMIP->GetN()-1],50000,0);
1038 grfFitMIP->SetLineColor(2);
1039 grfFitMIP->Draw("lu");
1040 fGainArray->AddLast(gainHistoMIP);
1041 //fGainArray->AddLast(canvasMIP->Clone());