]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCPreprocessorOffline.cxx
Adapt macro to read old SDD map format
[u/mrichter/AliRoot.git] / TPC / AliTPCPreprocessorOffline.cxx
CommitLineData
da268e11 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16
17
18/*
f12abd89 19 Responsible: marian.ivanov@cern.ch
20 Code to analyze the TPC calibration and to produce OCDB entries
21
22
da268e11 23 .x ~/rootlogon.C
24 gSystem->Load("libANALYSIS");
25 gSystem->Load("libTPCcalib");
da268e11 26
27 AliTPCPreprocessorOffline proces;
b322e06a 28 TString ocdbPath="local:////"
29 ocdbPath+=gSystem->GetFromPipe("pwd");
30
31 proces.CalibTimeGain("CalibObjects.root",run0,run1,ocdbPath);
32 proces.CalibTimeVdrift("CalibObjects.root",run0,run1,ocdbPath);
f12abd89 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
da268e11 37
68d461b2 38 e.g.
6d64657a 39 gSystem->Load("libANALYSIS");
40 gSystem->Load("libTPCcalib");
41 AliTPCPreprocessorOffline proces;
42 proces.CalibTimeGain("TPCMultObjects.root",114000,140040,0);
68d461b2 43 TFile oo("OCDB/TPC/Calib/TimeGain/Run114000_121040_v0_s0.root")
44 TObjArray * arr = AliCDBEntry->GetObject()
45 arr->At(4)->Draw("alp")
46
da268e11 47*/
f12abd89 48#include "Riostream.h"
49#include <fstream>
da268e11 50#include "TMap.h"
51#include "TGraphErrors.h"
52#include "AliExternalTrackParam.h"
53#include "TFile.h"
54#include "TGraph.h"
55#include "TMultiGraph.h"
56#include "TCanvas.h"
57#include "THnSparse.h"
58#include "TLegend.h"
59#include "TPad.h"
60#include "TH2D.h"
391ffdb2 61#include "TH3D.h"
da268e11 62#include "AliTPCROC.h"
63#include "AliTPCCalROC.h"
da268e11 64#include "AliESDfriend.h"
da268e11 65#include "AliTPCcalibTime.h"
66#include "AliSplineFit.h"
67#include "AliCDBMetaData.h"
68#include "AliCDBId.h"
69#include "AliCDBManager.h"
70#include "AliCDBStorage.h"
71#include "AliTPCcalibBase.h"
72#include "AliTPCcalibDB.h"
73#include "AliTPCcalibDButil.h"
74#include "AliRelAlignerKalman.h"
75#include "AliTPCParamSR.h"
76#include "AliTPCcalibTimeGain.h"
56b51ad9 77#include "AliTPCcalibGainMult.h"
da268e11 78#include "AliSplineFit.h"
79#include "AliTPCPreprocessorOffline.h"
da268e11 80
81
82ClassImp(AliTPCPreprocessorOffline)
83
84AliTPCPreprocessorOffline::AliTPCPreprocessorOffline():
f12abd89 85 TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
40120adc 86 fMinEntries(500), // minimal number of entries for fit
da268e11 87 startRun(0), // start Run - used to make fast selection in THnSparse
88 endRun(0), // end Run - used to make fast selection in THnSparse
89 startTime(0), // startTime - used to make fast selection in THnSparse
90 endTime(0), // endTime - used to make fast selection in THnSparse
91 ocdbStorage(""), // path to the OCDB storage
92 fVdriftArray(new TObjArray),
93 fTimeDrift(0),
94 fGraphMIP(0), // graph time dependence of MIP
95 fGraphCosmic(0), // graph time dependence at Plateu
391ffdb2 96 fGraphAttachmentMIP(0),
da268e11 97 fFitMIP(0), // fit of dependence - MIP
98 fFitCosmic(0), // fit of dependence - Plateu
99 fGainArray(new TObjArray), // array to be stored in the OCDB
100 fGainMIP(0), // calibration component for MIP
68d461b2 101 fGainCosmic(0), // calibration component for cosmic
56b51ad9 102 fGainMult(0),
68d461b2 103 fSwitchOnValidation(kFALSE) // flag to switch on validation of OCDB parameters
da268e11 104{
105 //
f12abd89 106 // default constructor
107 //
da268e11 108}
109
110AliTPCPreprocessorOffline::~AliTPCPreprocessorOffline() {
111 //
112 // Destructor
113 //
114}
115
116
117
118
40120adc 119void AliTPCPreprocessorOffline::GetRunRange(AliTPCcalibTime * const timeDrift){
da268e11 120 //
121 // find the fist and last run
122 //
f12abd89 123 TObjArray *hisArray =timeDrift->GetHistoDrift();
da268e11 124 {for (Int_t i=0; i<hisArray->GetEntriesFast(); i++){
125 THnSparse* addHist=(THnSparse*)hisArray->UncheckedAt(i);
40120adc 126 if (addHist->GetEntries()<fMinEntries) continue;
da268e11 127 if (!addHist) continue;
128 TH1D* histo =addHist->Projection(3);
129 TH1D* histoTime=addHist->Projection(0);
130 printf("%s\t%f\t%d\t%d\n",histo->GetName(), histo->GetEntries(),histo->FindFirstBinAbove(0),histo->FindLastBinAbove(0));
131
132 if (startRun<=0){
133 startRun=histo->FindFirstBinAbove(0);
134 endRun =histo->FindLastBinAbove(0);
135 }else{
136 startRun=TMath::Min(histo->FindFirstBinAbove(0),startRun);
137 endRun =TMath::Max(histo->FindLastBinAbove(0),endRun);
138 }
139 if (startTime==0){
140 startTime=histoTime->FindFirstBinAbove(0);
141 endTime =histoTime->FindLastBinAbove(0);
142 }else{
143 startTime=TMath::Min(histoTime->FindFirstBinAbove(0),startTime);
144 endTime =TMath::Max(histoTime->FindLastBinAbove(0),endTime);
145 }
146 delete histo;
147 delete histoTime;
148 }}
149 if (startRun<0) startRun=0;
150 if (endRun<0) endRun=100000000;
151 printf("Run range :\t%d-%d\n", startRun, endRun);
152 printf("Time range :\t%d-%d\n", startTime, endTime);
153
154}
155
156
157
40120adc 158void AliTPCPreprocessorOffline::CalibTimeVdrift(const Char_t* file, Int_t ustartRun, Int_t uendRun, TString pocdbStorage){
da268e11 159 //
40120adc 160 // make calibration of the drift velocity
161 // Input parameters:
162 // file - the location of input file
163 // ustartRun, uendrun - run validity period
164 // pocdbStorage - path to hte OCDB storage
165 // - if empty - local storage 'pwd' uesed
da268e11 166 if (pocdbStorage.Length()>0) ocdbStorage=pocdbStorage;
167 else
168 ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
169 //
170 // 1. Initialization and run range setting
171 TFile fcalib(file);
68d461b2 172 TObjArray * array = (TObjArray*)fcalib.Get("TPCCalib");
173 if (array){
174 fTimeDrift = (AliTPCcalibTime *)array->FindObject("calibTime");
175 } else {
176 fTimeDrift = (AliTPCcalibTime*)fcalib.Get("calibTime");
177 }
178 if(!fTimeDrift) return;
179
da268e11 180 startRun=ustartRun;
181 endRun=ustartRun;
182 TObjArray *hisArray =fTimeDrift->GetHistoDrift();
183 GetRunRange(fTimeDrift);
184 for (Int_t i=0; i<hisArray->GetEntriesFast(); i++){
185 THnSparse* addHist=(THnSparse*)hisArray->At(i);
186 if (!addHist) continue;
187 if (startTime<endTime) addHist->GetAxis(0)->SetRange(startTime-1,endTime+1);
188 if (startRun<endRun) addHist->GetAxis(3)->SetRange(startRun-1,endRun+1);
189 }
190 //
191 //
192 // 2. extraction of the information
193 //
194 fVdriftArray = new TObjArray();
195 AddAlignmentGraphs(fVdriftArray,fTimeDrift);
40120adc 196 AddHistoGraphs(fVdriftArray,fTimeDrift,fMinEntries);
da268e11 197 AddLaserGraphs(fVdriftArray,fTimeDrift);
198 //
199 // 3. Append QA plots
200 //
201 MakeDefaultPlots(fVdriftArray,fVdriftArray);
68d461b2 202
da268e11 203 //
68d461b2 204 // 4. validate OCDB entries
da268e11 205 //
68d461b2 206 if(fSwitchOnValidation==kTRUE && ValidateTimeDrift()==kFALSE) {
207 Printf("TPC time drift OCDB parameters out of range!");
208 return;
209 }
210
211 //
212 //
213 // 5. update of OCDB
da268e11 214 //
215 //
da268e11 216 UpdateOCDBDrift(ustartRun,uendRun,ocdbStorage);
217}
218
219void AliTPCPreprocessorOffline::UpdateOCDBDrift( Int_t ustartRun, Int_t uendRun, const char* storagePath ){
220 //
221 // Update OCDB
222 //
223 AliCDBMetaData *metaData= new AliCDBMetaData();
224 metaData->SetObjectClassName("TObjArray");
225 metaData->SetResponsible("Marian Ivanov");
226 metaData->SetBeamPeriod(1);
227 metaData->SetAliRootVersion("05-25-01"); //root version
228 metaData->SetComment("Calibration of the time dependence of the drift velocity");
229 AliCDBId* id1=NULL;
230 id1=new AliCDBId("TPC/Calib/TimeDrift", ustartRun, uendRun);
231 AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
232 gStorage->Put(fVdriftArray, (*id1), metaData);
233}
234
68d461b2 235Bool_t AliTPCPreprocessorOffline::ValidateTimeGain(Double_t minGain, Double_t maxGain)
236{
237 //
238 // Validate time gain corrections
239 //
240 Printf("ValidateTimeGain..." );
241
242 TGraphErrors *gr = (TGraphErrors*)fGainArray->FindObject("TGRAPHERRORS_MEAN_GAIN_BEAM_ALL");
243 if(!gr) return kFALSE;
244 if(gr->GetN()<1) return kFALSE;
245
246 // check whether gain in the range
247 for(Int_t iPoint=0; iPoint<gr->GetN(); iPoint++)
248 {
249 if(gr->GetY()[iPoint] < minGain || gr->GetY()[iPoint] > maxGain)
250 return kFALSE;
251 }
252
253return kTRUE;
254}
255
da268e11 256
68d461b2 257Bool_t AliTPCPreprocessorOffline::ValidateTimeDrift(Double_t maxVDriftCorr)
258{
259 //
260 // Validate time drift velocity corrections
261 //
262 Printf("ValidateTimeDrift..." );
263
264 TGraphErrors* gr = (TGraphErrors*)fVdriftArray->FindObject("ALIGN_ITSB_TPC_DRIFTVD");
265 if(!gr) return kFALSE;
266 if(gr->GetN()<1) return kFALSE;
267
268 // check whether drift velocity corrections in the range
269 for(Int_t iPoint = 0; iPoint<gr->GetN(); iPoint++)
270 {
271 if(TMath::Abs(gr->GetY()[iPoint]) > maxVDriftCorr)
272 return kFALSE;
273 }
274
275return kTRUE;
276}
da268e11 277
40120adc 278void AliTPCPreprocessorOffline::UpdateDriftParam(AliTPCParam *param, TObjArray *const arr, Int_t lstartRun){
da268e11 279 //
280 // update the OCDB entry for the nominal time0
281 //
282 //
283 // AliTPCParam * param = AliTPCcalibDB::Instance()->GetParameters();
284 AliTPCParam *paramNew = (AliTPCParam *)param->Clone();
285 TGraphErrors *grT = (TGraphErrors *)arr->FindObject("ALIGN_ITSM_TPC_T0");
286 Double_t deltaTcm = TMath::Median(grT->GetN(),grT->GetY());
287 Double_t deltaT = deltaTcm/param->GetDriftV();
288 paramNew->SetL1Delay(param->GetL1Delay()-deltaT);
289 paramNew->Update();
290
291 AliCDBMetaData *metaData= new AliCDBMetaData();
292 metaData->SetObjectClassName("TObjArray");
293 metaData->SetResponsible("Marian Ivanov");
294 metaData->SetBeamPeriod(1);
295 metaData->SetAliRootVersion("05-25-02"); //root version
296 metaData->SetComment("Updated calibration of nominal time 0");
297 AliCDBId* id1=NULL;
f12abd89 298 id1=new AliCDBId("TPC/Calib/Parameters", lstartRun, AliCDBRunRange::Infinity());
da268e11 299 AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
300 gStorage->Put(param, (*id1), metaData);
301
302}
303
304
305void AliTPCPreprocessorOffline::PrintArray(TObjArray *array){
306 //
40120adc 307 // Print the names of the entries in array
da268e11 308 //
309 Int_t entries = array->GetEntries();
310 for (Int_t i=0; i<entries; i++){
311 if (!array->At(i)) continue;
312 printf("%d\t %s\n", i, array->At(i)->GetName());
313 }
314}
315
316
317
318TGraphErrors* AliTPCPreprocessorOffline::FilterGraphDrift(TGraphErrors * graph, Float_t errSigmaCut, Float_t medianCutAbs){
319 // 2 filters:
320 // 1. filter graph - error cut errSigmaCut
321 // 2. filter graph - medianCutAbs around median
322 //
323 // errSigmaCut - cut on error
324 // medianCutAbs - cut on value around median
325 Double_t dummy=0; //
326 //
327 // 1. filter graph - error cut errSigmaCut
328 //
329 TGraphErrors *graphF;
330 graphF = AliTPCcalibDButil::FilterGraphMedianErr(graph,errSigmaCut,dummy);
331 delete graph;
332 if (!graphF) return 0;
333 graph = AliTPCcalibDButil::FilterGraphMedianErr(graphF,errSigmaCut,dummy);
334 delete graphF;
335 if (!graph) return 0;
336 //
337 // filter graph - kMedianCutAbs around median
338 //
339 graphF=FilterGraphMedianAbs(graph, medianCutAbs,dummy);
340 delete graph;
341 if (!graphF) return 0;
342 graph=FilterGraphMedianAbs(graphF, medianCutAbs,dummy);
343 delete graphF;
344 if (!graph) return 0;
345 return graph;
346}
347
348
349
350TGraphErrors* AliTPCPreprocessorOffline::FilterGraphMedianAbs(TGraphErrors * graph, Float_t cut,Double_t &medianY){
351 //
352 // filter outlyer measurement
353 // Only points around median +- cut filtered
354 //
355 if (!graph) return 0;
356 Int_t kMinPoints=2;
357 Int_t npoints0 = graph->GetN();
358 Int_t npoints=0;
359 Float_t rmsY=0;
360 Double_t *outx=new Double_t[npoints0];
361 Double_t *outy=new Double_t[npoints0];
362 Double_t *errx=new Double_t[npoints0];
363 Double_t *erry=new Double_t[npoints0];
364 //
365 //
366 if (npoints0<kMinPoints) return 0;
367 for (Int_t iter=0; iter<3; iter++){
368 npoints=0;
369 for (Int_t ipoint=0; ipoint<npoints0; ipoint++){
370 if (graph->GetY()[ipoint]==0) continue;
371 if (iter>0 &&TMath::Abs(graph->GetY()[ipoint]-medianY)>cut) continue;
372 outx[npoints] = graph->GetX()[ipoint];
373 outy[npoints] = graph->GetY()[ipoint];
374 errx[npoints] = graph->GetErrorX(ipoint);
375 erry[npoints] = graph->GetErrorY(ipoint);
376 npoints++;
377 }
378 if (npoints<=1) break;
379 medianY =TMath::Median(npoints,outy);
380 rmsY =TMath::RMS(npoints,outy);
381 }
382 TGraphErrors *graphOut=0;
383 if (npoints>1) graphOut= new TGraphErrors(npoints,outx,outy,errx,erry);
831e26ce 384 delete []outx;
385 delete []outy;
386 delete []errx;
387 delete []erry;
da268e11 388 return graphOut;
389}
390
391
40120adc 392void AliTPCPreprocessorOffline::AddHistoGraphs( TObjArray * vdriftArray, AliTPCcalibTime * const timeDrift, Int_t minEntries){
da268e11 393 //
394 // Add graphs corresponding to the alignment
395 //
396 const Double_t kErrSigmaCut=5; // error sigma cut - for filtering
397 const Double_t kMedianCutAbs=0.03; // error sigma cut - for filtering
398 //
399 TObjArray * array=timeDrift->GetHistoDrift();
400 if (array){
401 THnSparse* hist=NULL;
402 // 2.a) cosmics with different triggers
403 for (Int_t i=0; i<array->GetEntriesFast();i++){
404 hist=(THnSparseF*)array->UncheckedAt(i);
405 if(!hist) continue;
406 if (hist->GetEntries()<minEntries) continue;
407 //hist->Print();
408 TString name=hist->GetName();
409 Int_t dim[4]={0,1,2,3};
410 THnSparse* newHist=hist->Projection(4,dim);
411 newHist->SetName(name);
412 TGraphErrors* graph=AliTPCcalibBase::FitSlices(newHist,2,0,400,100,0.05,0.95, kTRUE);
413 printf("name=%s graph=%i, N=%i\n", name.Data(), graph==0, graph->GetN());
414 Int_t pos=name.Index("_");
415 name=name(pos,name.Capacity()-pos);
416 TString graphName=graph->ClassName();
417 graphName+=name;
418 graphName.ToUpper();
419 //
420 graph = FilterGraphDrift(graph, kErrSigmaCut, kMedianCutAbs);
421 if (!graph) {
422 printf("Graph =%s filtered out\n", name.Data());
423 continue;
56b51ad9 424 }
425 //
831e26ce 426 if (graph){
56b51ad9 427 graph->SetMarkerStyle(i%8+20);
428 graph->SetMarkerColor(i%7);
429 graph->GetXaxis()->SetTitle("Time");
430 graph->GetYaxis()->SetTitle("v_{dcor}");
431 graph->SetName(graphName);
432 graph->SetTitle(graphName);
433 printf("Graph %d\t=\t%s\n", i, graphName.Data());
434 vdriftArray->Add(graph);
da268e11 435 }
da268e11 436 }
437 }
438}
439
440
441
442
40120adc 443void AliTPCPreprocessorOffline::AddAlignmentGraphs( TObjArray * vdriftArray, AliTPCcalibTime *const timeDrift){
da268e11 444 //
445 // Add graphs corresponding to alignment to the object array
446 //
447 TObjArray *arrayITS=0;
448 TObjArray *arrayTOF=0;
449 TObjArray *arrayTRD=0;
450 TMatrixD *mstatITS=0;
451 TMatrixD *mstatTOF=0;
452 TMatrixD *mstatTRD=0;
453 //
454 arrayITS=timeDrift->GetAlignITSTPC();
455 arrayTRD=timeDrift->GetAlignTRDTPC();
456 arrayTOF=timeDrift->GetAlignTOFTPC();
457
458 if (arrayITS->GetEntries()>0) mstatITS= AliTPCcalibDButil::MakeStatRelKalman(arrayITS,0.9,50,0.025);
459 if (arrayTOF->GetEntries()>0) mstatTOF= AliTPCcalibDButil::MakeStatRelKalman(arrayTOF,0.9,1000,0.025);
460 if (arrayTRD->GetEntries()>0) mstatTRD= AliTPCcalibDButil::MakeStatRelKalman(arrayTRD,0.9,50,0.025);
461 //
462 TObjArray * arrayITSP= AliTPCcalibDButil::SmoothRelKalman(arrayITS,*mstatITS, 0, 5.);
463 TObjArray * arrayITSM= AliTPCcalibDButil::SmoothRelKalman(arrayITS,*mstatITS, 1, 5.);
464 TObjArray * arrayITSB= AliTPCcalibDButil::SmoothRelKalman(arrayITSP,arrayITSM);
465 TObjArray * arrayTOFP= AliTPCcalibDButil::SmoothRelKalman(arrayTOF,*mstatTOF, 0, 5.);
466 TObjArray * arrayTOFM= AliTPCcalibDButil::SmoothRelKalman(arrayTOF,*mstatTOF, 1, 5.);
467 TObjArray * arrayTOFB= AliTPCcalibDButil::SmoothRelKalman(arrayTOFP,arrayTOFM);
468
469 TObjArray * arrayTRDP= 0x0;
470 TObjArray * arrayTRDM= 0x0;
471 TObjArray * arrayTRDB= 0x0;
472 arrayTRDP= AliTPCcalibDButil::SmoothRelKalman(arrayTRD,*mstatTRD, 0, 5.);
473 arrayTRDM= AliTPCcalibDButil::SmoothRelKalman(arrayTRD,*mstatTRD, 1, 5.);
474 arrayTRDB= AliTPCcalibDButil::SmoothRelKalman(arrayTRDP,arrayTRDM);
475 //
476 //
477 Int_t entries=TMath::Max(arrayITS->GetEntriesFast(),arrayTOF->GetEntriesFast());
478 TObjArray *arrays[12]={arrayITS, arrayITSP, arrayITSM, arrayITSB,
479 arrayTRD, arrayTRDP, arrayTRDM, arrayTRDB,
480 arrayTOF, arrayTOFP, arrayTOFM, arrayTOFB};
481 TString grnames[12]={"ALIGN_ITS", "ALIGN_ITSP", "ALIGN_ITSM", "ALIGN_ITSB",
482 "ALIGN_TRD", "ALIGN_TRDP", "ALIGN_TRDM","ALIGN_TRDB",
483 "ALIGN_TOF", "ALIGN_TOFP", "ALIGN_TOFM","ALIGN_TOFB"};
484 TString grpar[9]={"DELTAPSI", "DELTATHETA", "DELTAPHI",
485 "DELTAX", "DELTAY", "DELTAZ",
486 "DRIFTVD", "T0", "VDGY"};
487
488
489 TVectorD vX(entries);
490 TVectorD vY(entries);
491 TVectorD vEx(entries);
492 TVectorD vEy(entries);
493 TObjArray *arr=0;
494 for (Int_t iarray=0; iarray<12; iarray++){
495 arr = arrays[iarray];
496 if (arr==0) continue;
497 for (Int_t ipar=0; ipar<9; ipar++){
498 Int_t counter=0;
499 for (Int_t itime=0; itime<arr->GetEntriesFast(); itime++){
500 AliRelAlignerKalman * kalman = (AliRelAlignerKalman *) arr->UncheckedAt(itime);
501 if (!kalman) continue;
502 vX[counter]=kalman->GetTimeStamp();
503 vY[counter]=(*(kalman->GetState()))[ipar];
504 if (ipar==6) vY[counter]=1./(*(kalman->GetState()))[ipar]-1;
505 vEx[counter]=0;
506 vEy[counter]=TMath::Sqrt((*(kalman->GetStateCov()))(ipar,ipar));
507 counter++;
508 }
509
510 TGraphErrors * graph=new TGraphErrors(counter, vX.GetMatrixArray(),
511 vY.GetMatrixArray(),
512 vEx.GetMatrixArray(),
513 vEy.GetMatrixArray());
514 TString grName=grnames[iarray];
515 grName+="_TPC_";
516 grName+=grpar[ipar];
517 graph->SetName(grName.Data());
518 vdriftArray->AddLast(graph);
519 }
520 }
521}
522
523
524
525
526void AliTPCPreprocessorOffline::AddLaserGraphs( TObjArray * vdriftArray, AliTPCcalibTime *timeDrift){
527 //
528 // add graphs for laser
529 //
530 const Double_t delayL0L1 = 0.071; //this is hack for 1/2 weeks
531 THnSparse *hisN=0;
532 TGraphErrors *grLaser[6]={0,0,0,0,0,0};
533 hisN = timeDrift->GetHistVdriftLaserA(0);
534 if (timeDrift->GetHistVdriftLaserA(0)){
535 grLaser[0]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserA(0),0,2,5,delayL0L1);
536 grLaser[0]->SetName("GRAPH_MEAN_DELAY_LASER_ALL_A");
537 vdriftArray->AddLast(grLaser[0]);
538 }
539 if (timeDrift->GetHistVdriftLaserA(1)){
540 grLaser[1]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserA(1),0,2,5);
541 grLaser[1]->SetName("GRAPH_MEAN_DRIFT_LASER_ALL_A");
542 vdriftArray->AddLast(grLaser[1]);
543 }
544 if (timeDrift->GetHistVdriftLaserA(2)){
545 grLaser[2]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserA(2),0,2,5);
546 grLaser[2]->SetName("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_A");
547 vdriftArray->AddLast(grLaser[2]);
548 }
549 if (timeDrift->GetHistVdriftLaserC(0)){
550 grLaser[3]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserC(0),0,2,5,delayL0L1);
551 grLaser[3]->SetName("GRAPH_MEAN_DELAY_LASER_ALL_C");
552 vdriftArray->AddLast(grLaser[3]);
553 }
554 if (timeDrift->GetHistVdriftLaserC(1)){
555 grLaser[4]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserC(1),0,2,5);
556 grLaser[4]->SetName("GRAPH_MEAN_DRIFT_LASER_ALL_C");
557 vdriftArray->AddLast(grLaser[4]);
558 }
559 if (timeDrift->GetHistVdriftLaserC(2)){
560 grLaser[5]=MakeGraphFilter0(timeDrift->GetHistVdriftLaserC(2),0,2,5);
561 grLaser[5]->SetName("GRAPH_MEAN_GLOBALYGRADIENT_LASER_ALL_C");
562 vdriftArray->AddLast(grLaser[5]);
563 }
564 for (Int_t i=0; i<6;i++){
565 if (grLaser[i]) {
566 SetDefaultGraphDrift(grLaser[i], 1,(i+20));
567 grLaser[i]->GetYaxis()->SetTitle("Laser Correction");
568 }
569 }
570}
571
572
573TGraphErrors * AliTPCPreprocessorOffline::MakeGraphFilter0(THnSparse *hisN, Int_t itime, Int_t ival, Int_t minEntries, Double_t offset){
574 //
575 // Make graph with mean values and rms
576 //
577 hisN->GetAxis(itime)->SetRange(0,100000000);
578 hisN->GetAxis(ival)->SetRange(0,100000000);
579 TH1 * hisT = hisN->Projection(itime);
580 TH1 * hisV = hisN->Projection(ival);
581 //
582 Int_t firstBinA = hisT->FindFirstBinAbove(2);
583 Int_t lastBinA = hisT->FindLastBinAbove(2);
584 Int_t firstBinV = hisV->FindFirstBinAbove(0);
585 Int_t lastBinV = hisV->FindLastBinAbove(0);
586 hisN->GetAxis(itime)->SetRange(firstBinA,lastBinA);
587 hisN->GetAxis(ival)->SetRange(firstBinV,lastBinV);
588 Int_t entries=0;
68d461b2 589 for (Int_t ibin=firstBinA; ibin<=lastBinA; ibin++){
da268e11 590 Double_t cont = hisT->GetBinContent(ibin);
591 if (cont<minEntries) continue;
592 entries++;
593 }
594 TVectorD vecTime(entries);
595 TVectorD vecMean0(entries);
596 TVectorD vecRMS0(entries);
597 TVectorD vecMean1(entries);
598 TVectorD vecRMS1(entries);
599 entries=0;
68d461b2 600 for (Int_t ibin=firstBinA; ibin<=lastBinA; ibin++){
da268e11 601 Double_t cont = hisT->GetBinContent(ibin);
602 if (cont<minEntries) continue;
68d461b2 603 //hisN->GetAxis(itime)->SetRange(ibin-1,ibin+1);
604 Int_t minBin = ibin-1;
605 Int_t maxBin = ibin+1;
606 if(minBin <= 0) minBin = 1;
607 if(maxBin >= hisN->GetAxis(itime)->GetNbins()) maxBin = hisN->GetAxis(itime)->GetNbins()-1;
608 hisN->GetAxis(itime)->SetRange(minBin,maxBin);
609
da268e11 610 Double_t time = hisT->GetBinCenter(ibin);
611 TH1 * his = hisN->Projection(ival);
612 Double_t nentries0= his->GetBinContent(his->FindBin(0));
613 if (cont-nentries0<minEntries) continue;
614 //
615 his->SetBinContent(his->FindBin(0),0);
616 vecTime[entries]=time;
617 vecMean0[entries]=his->GetMean()+offset;
618 vecMean1[entries]=his->GetMeanError();
619 vecRMS0[entries] =his->GetRMS();
620 vecRMS1[entries] =his->GetRMSError();
621 delete his;
622 entries++;
68d461b2 623 }
da268e11 624 delete hisT;
625 delete hisV;
626 TGraphErrors * graph = new TGraphErrors(entries,vecTime.GetMatrixArray(), vecMean0.GetMatrixArray(), 0, vecMean1.GetMatrixArray());
627 return graph;
628}
629
630
631
632
633
634
635
636
637void AliTPCPreprocessorOffline::SetDefaultGraphDrift(TGraph *graph, Int_t color, Int_t style){
638 //
40120adc 639 // Set default style for QA views
da268e11 640 //
641 graph->GetXaxis()->SetTimeDisplay(kTRUE);
642 graph->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
643 graph->SetMaximum( 0.025);
644 graph->SetMinimum(-0.025);
645 graph->GetXaxis()->SetTitle("Time");
646 graph->GetYaxis()->SetTitle("v_{dcorr}");
647 //
648 graph->GetYaxis()->SetLabelSize(0.03);
649 graph->GetXaxis()->SetLabelSize(0.03);
650 //
651 graph->GetXaxis()->SetNdivisions(10,5,0);
652 graph->GetYaxis()->SetNdivisions(10,5,0);
653 //
654 graph->GetXaxis()->SetLabelOffset(0.02);
655 graph->GetYaxis()->SetLabelOffset(0.005);
656 //
657 graph->GetXaxis()->SetTitleOffset(1.3);
658 graph->GetYaxis()->SetTitleOffset(1.2);
659 //
660 graph->SetMarkerColor(color);
661 graph->SetLineColor(color);
662 graph->SetMarkerStyle(style);
663}
664
665void AliTPCPreprocessorOffline::SetPadStyle(TPad *pad, Float_t mx0, Float_t mx1, Float_t my0, Float_t my1){
40120adc 666 //
667 // Set default pad style for QA
668 //
da268e11 669 pad->SetTicks(1,1);
670 pad->SetMargin(mx0,mx1,my0,my1);
671}
672
673
68d461b2 674void AliTPCPreprocessorOffline::MakeDefaultPlots(TObjArray * const arr, TObjArray * /*picArray*/){
da268e11 675 //
40120adc 676 // 0. make a default QA plots
677 // 1. Store them in the array
da268e11 678 //
679 //
da268e11 680 Float_t mx0=0.12, mx1=0.1, my0=0.15, my1=0.1;
681 //
682 TGraphErrors* laserA =(TGraphErrors*)arr->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_A");
683 TGraphErrors* laserC =(TGraphErrors*)arr->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_C");
684 TGraphErrors* cosmic =(TGraphErrors*)arr->FindObject("TGRAPHERRORS_MEAN_VDRIFT_COSMICS_ALL");
685 TGraphErrors* cross =(TGraphErrors*)arr->FindObject("TGRAPHERRORS_VDRIFT_CROSS_ALL");
686 TGraphErrors* itstpcP =(TGraphErrors*)arr->FindObject("ALIGN_ITSP_TPC_DRIFTVD");
687 TGraphErrors* itstpcM =(TGraphErrors*)arr->FindObject("ALIGN_ITSM_TPC_DRIFTVD");
688 TGraphErrors* itstpcB =(TGraphErrors*)arr->FindObject("ALIGN_ITSB_TPC_DRIFTVD");
689 //
690 if (laserA) SetDefaultGraphDrift(laserA,2,25);
691 if (laserC) SetDefaultGraphDrift(laserC,4,26);
692 if (cosmic) SetDefaultGraphDrift(cosmic,3,27);
693 if (cross) SetDefaultGraphDrift(cross,4,28);
694 if (itstpcP) SetDefaultGraphDrift(itstpcP,2,29);
695 if (itstpcM) SetDefaultGraphDrift(itstpcM,4,30);
696 if (itstpcB) SetDefaultGraphDrift(itstpcB,1,31);
697 //
698 //
699 TPad *pad=0;
700 //
701 // Laser-Laser
702 //
703 if (laserA&&laserC){
704 pad = new TCanvas("TPCLaserVDrift","TPCLaserVDrift");
705 laserA->Draw("alp");
706 SetPadStyle(pad,mx0,mx1,my0,my1);
707 laserA->Draw("apl");
708 laserC->Draw("p");
709 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
710 legend->AddEntry(laserA,"Laser A side");
711 legend->AddEntry(laserC,"Laser C side");
712 legend->Draw();
68d461b2 713 //picArray->AddLast(pad);
da268e11 714 }
715
831e26ce 716 if (itstpcP&&itstpcM&&itstpcB){
da268e11 717 pad = new TCanvas("ITSTPC","ITSTPC");
718 itstpcP->Draw("alp");
719 SetPadStyle(pad,mx0,mx1,my0,my1);
720 itstpcP->Draw("alp");
721 gPad->Clear();
722 itstpcM->Draw("apl");
723 itstpcP->Draw("p");
724 itstpcB->Draw("p");
725 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
726 legend->AddEntry(itstpcP,"ITS-TPC smooth plus");
727 legend->AddEntry(itstpcM,"ITS-TPC smooth minus");
728 legend->AddEntry(itstpcB,"ITS-TPC smooth ");
729 legend->Draw();
68d461b2 730 //picArray->AddLast(pad);
da268e11 731 }
732
831e26ce 733 if (itstpcB&&laserA&&itstpcP&&itstpcM){
da268e11 734 pad = new TCanvas("ITSTPC_LASER","ITSTPC_LASER");
735 SetPadStyle(pad,mx0,mx1,my0,my1);
736 laserA->Draw("alp");
737 itstpcP->Draw("p");
738 itstpcM->Draw("p");
739 itstpcB->Draw("p");
740 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
741 legend->AddEntry(laserA,"TPC laser");
742 legend->AddEntry(itstpcP,"ITS-TPC smooth plus");
743 legend->AddEntry(itstpcM,"ITS-TPC smooth minus");
744 legend->AddEntry(itstpcB,"ITS-TPC smooth ");
745 legend->Draw();
68d461b2 746 //picArray->AddLast(pad);
da268e11 747 }
748
749 if (itstpcP&&cross){
750 pad = new TCanvas("ITSTPC_CROSS","ITSTPC_CROSS");
751 SetPadStyle(pad,mx0,mx1,my0,my1);
752 itstpcP->Draw("alp");
753 pad->Clear();
754 cross->Draw("ap");
755 itstpcP->Draw("p");
756 //
757 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
758
759 legend->AddEntry(cross,"TPC cross tracks");
760 legend->AddEntry(itstpcB,"ITS-TPC smooth");
761 legend->Draw();
68d461b2 762 //picArray->AddLast(pad);
da268e11 763 }
764 if (itstpcP&&cosmic){
765 pad = new TCanvas("ITSTPC_COSMIC","ITSTPC_COSMIC");
766 SetPadStyle(pad,mx0,mx1,my0,my1);
767 itstpcP->Draw("alp");
768 pad->Clear();
769 cosmic->Draw("ap");
770 itstpcP->Draw("p");
771 //
772 TLegend *legend = new TLegend(mx0+0.01,1-my1-0.2, 0.5, 1-my1-0.01, "Drift velocity correction");
773
774 legend->AddEntry(cosmic,"TPC cross tracks0 up-down");
775 legend->AddEntry(itstpcB,"ITS-TPC smooth");
776 legend->Draw();
68d461b2 777 //picArray->AddLast(pad);
da268e11 778 }
779}
780
781
782
783
40120adc 784void AliTPCPreprocessorOffline::CalibTimeGain(const Char_t* fileName, Int_t startRunNumber, Int_t endRunNumber, TString pocdbStorage){
da268e11 785 //
786 // Update OCDB gain
787 //
68d461b2 788 if (pocdbStorage.Length()==0) pocdbStorage+="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
789
790 //
791 // 1. Read gain values
792 //
da268e11 793 ReadGainGlobal(fileName);
68d461b2 794
795 //
796 // 2. Extract calibration values
797 //
da268e11 798 AnalyzeGain(startRunNumber,endRunNumber, 1000,1.43);
391ffdb2 799 AnalyzeAttachment(startRunNumber,endRunNumber);
56b51ad9 800 AnalyzePadRegionGain();
6d64657a 801 AnalyzeGainMultiplicity();
68d461b2 802 //
803 // 3. Make control plots
804 //
805 MakeQAPlot(1.43);
da268e11 806
68d461b2 807 //
808 // 4. validate OCDB entries
809 //
810 if(fSwitchOnValidation==kTRUE && ValidateTimeGain()==kFALSE) {
811 Printf("TPC time gain OCDB parameters out of range!");
812 return;
813 }
da268e11 814
68d461b2 815 //
816 // 5. Update OCDB
817 //
818 UpdateOCDBGain( startRunNumber, endRunNumber, pocdbStorage.Data());
819}
da268e11 820
40120adc 821void AliTPCPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
da268e11 822 //
823 // read calibration entries from file
824 //
825 TFile fcalib(fileName);
826 TObjArray * array = (TObjArray*)fcalib.Get("TPCCalib");
827 if (array){
828 fGainMIP = ( AliTPCcalibTimeGain *)array->FindObject("calibTimeGain");
829 fGainCosmic = ( AliTPCcalibTimeGain *)array->FindObject("calibTimeGainCosmic");
56b51ad9 830 fGainMult = ( AliTPCcalibGainMult *)array->FindObject("calibGainMult");
da268e11 831 }else{
832 fGainMIP = ( AliTPCcalibTimeGain *)fcalib.Get("calibTimeGain");
833 fGainCosmic = ( AliTPCcalibTimeGain *)fcalib.Get("calibTimeGainCosmic");
56b51ad9 834 fGainMult = ( AliTPCcalibGainMult *)fcalib.Get("calibGainMult");
da268e11 835 }
836 TH1 * hisT=0;
837 Int_t firstBinA =0, lastBinA=0;
838
839 if (fGainCosmic){
840 hisT= fGainCosmic->GetHistGainTime()->Projection(1);
841 firstBinA = hisT->FindFirstBinAbove(2);
842 lastBinA = hisT->FindLastBinAbove(2);
843 fGainCosmic->GetHistGainTime()->GetAxis(1)->SetRange(firstBinA,lastBinA);
844 delete hisT;
845 }
846
847 if (fGainMIP){
848 hisT= fGainMIP->GetHistGainTime()->Projection(1);
849 firstBinA = hisT->FindFirstBinAbove(2);
850 lastBinA = hisT->FindLastBinAbove(2);
851 fGainMIP->GetHistGainTime()->GetAxis(1)->SetRange(firstBinA,lastBinA);
852 delete hisT;
853 }
854
855}
856
857
858
859Bool_t AliTPCPreprocessorOffline::AnalyzeGain(Int_t startRunNumber, Int_t endRunNumber, Int_t minEntriesGaussFit, Float_t FPtoMIPratio){
860 //
40120adc 861 // Analyze gain - produce the calibration graphs
da268e11 862 //
68d461b2 863
da268e11 864 // 1.) try to create MIP spline
68d461b2 865 if (fGainMIP)
866 {
867 fGainMIP->GetHistGainTime()->GetAxis(5)->SetRangeUser(startRunNumber, endRunNumber);
868 fGainMIP->GetHistGainTime()->GetAxis(2)->SetRangeUser(1.51,2.49); // only beam data
869 fGainMIP->GetHistGainTime()->GetAxis(4)->SetRangeUser(0.39,0.51); // only MIP pions
870 //
871 fGraphMIP = AliTPCcalibBase::FitSlices(fGainMIP->GetHistGainTime(),0,1,minEntriesGaussFit,10,0.1,0.7);
872 if (fGraphMIP->GetN()==0) fGraphMIP = 0x0;
873 if (fGraphMIP) fFitMIP = AliTPCcalibTimeGain::MakeSplineFit(fGraphMIP);
874 if (fGraphMIP) fGraphMIP->SetName("TGRAPHERRORS_MEAN_GAIN_BEAM_ALL");// set proper names according to naming convention
875 fGainArray->AddAt(fFitMIP,0);
876 }
da268e11 877
878 // 2.) try to create Cosmic spline
68d461b2 879 if (fGainCosmic)
880 {
6c8b3862 881 fGainCosmic->GetHistGainTime()->GetAxis(2)->SetRangeUser(0.51,1.49); // only cosmics
882 fGainCosmic->GetHistGainTime()->GetAxis(4)->SetRangeUser(20,100); // only Fermi-Plateau muons
883 //
884 fGraphCosmic = AliTPCcalibBase::FitSlices(fGainCosmic->GetHistGainTime(),0,1,minEntriesGaussFit,10);
885 if (fGraphCosmic->GetN()==0) fGraphCosmic = 0x0;
886 //
887 if (fGraphCosmic) {
888 for(Int_t i=0; i < fGraphCosmic->GetN(); i++) {
889 fGraphCosmic->GetY()[i] /= FPtoMIPratio;
890 fGraphCosmic->GetEY()[i] /= FPtoMIPratio;
891 }
da268e11 892 }
6c8b3862 893 //
894 if (fGraphCosmic) fFitCosmic = AliTPCcalibTimeGain::MakeSplineFit(fGraphCosmic);
895 if (fGraphCosmic) fGraphCosmic->SetName("TGRAPHERRORS_MEAN_GAIN_COSMIC_ALL"); // set proper names according to naming convention
896 fGainArray->AddAt(fFitCosmic,1);
da268e11 897 }
da268e11 898 // with naming convention and backward compatibility
899 fGainArray->AddAt(fGraphMIP,2);
900 fGainArray->AddAt(fGraphCosmic,3);
901 cout << "fGraphCosmic: " << fGraphCosmic << " fGraphMIP " << fGraphMIP << endl;
902 return kTRUE;
903
904}
905
391ffdb2 906Bool_t AliTPCPreprocessorOffline::AnalyzeAttachment(Int_t startRunNumber, Int_t endRunNumber, Int_t minEntriesFit) {
907 //
908 // determine slope as a function of mean driftlength
909 //
68d461b2 910 if(!fGainMIP) return kFALSE;
911
391ffdb2 912 fGainMIP->GetHistGainTime()->GetAxis(5)->SetRangeUser(startRunNumber, endRunNumber);
913 //
914 fGainMIP->GetHistGainTime()->GetAxis(2)->SetRangeUser(1.51,2.49); // only beam data
915 fGainMIP->GetHistGainTime()->GetAxis(4)->SetRangeUser(0.39,0.51); // only MIP pions
916 //
68d461b2 917 fGainMIP->GetHistGainTime()->GetAxis(3)->SetRangeUser(125,250);// only full tracking region (driftlength)
918 fGainMIP->GetHistGainTime()->GetAxis(0)->SetRangeUser(1.5,3.5);// only full tracking region (driftlength)
919 //
391ffdb2 920 TH3D * hist = fGainMIP->GetHistGainTime()->Projection(1, 0, 3);
921 //
922 Double_t *xvec = new Double_t[hist->GetNbinsX()];
923 Double_t *yvec = new Double_t[hist->GetNbinsX()];
924 Double_t *xerr = new Double_t[hist->GetNbinsX()];
925 Double_t *yerr = new Double_t[hist->GetNbinsX()];
926 Int_t counter = 0;
927 //
928 for(Int_t i=1; i < hist->GetNbinsX(); i++) {
929 Int_t nsum=0;
930 Int_t imin = i;
931 Int_t imax = i;
68d461b2 932 for (Int_t idelta=0; idelta<5; idelta++){
391ffdb2 933 //
934 imin = TMath::Max(i-idelta,1);
935 imax = TMath::Min(i+idelta,hist->GetNbinsX());
936 nsum = TMath::Nint(hist->Integral(imin,imax,1,hist->GetNbinsY()-1,1,hist->GetNbinsZ()-1));
937 //if (nsum==0) break;
938 if (nsum>minEntriesFit) break;
939 }
940 if (nsum<minEntriesFit) continue;
941 //
68d461b2 942 fGainMIP->GetHistGainTime()->GetAxis(1)->SetRangeUser(hist->GetXaxis()->GetBinCenter(imin-1),hist->GetXaxis()->GetBinCenter(imax+1)); // define time range
943 TH2D * histZdep = fGainMIP->GetHistGainTime()->Projection(0,3);
944 TObjArray arr;
945 histZdep->FitSlicesY(0,0,-1,0,"QNR",&arr);
946 TH1D * driftDep = (TH1D*)arr.At(1);
947 delete histZdep;
948 //TGraphErrors * driftDep = AliTPCcalibBase::FitSlices(fGainMIP->GetHistGainTime(),0,3,100,1,0.,1);
949 /*if (driftDep->GetN() < 4) {
391ffdb2 950 delete driftDep;
68d461b2 951 continue;
952 }*/
391ffdb2 953 //
68d461b2 954 //TObjArray arr;
391ffdb2 955 //
68d461b2 956 TF1 pol1("polynom1","pol1",125,240);
391ffdb2 957 //driftDep->Fit(&pol1,"QNRROB=0.8");
958 driftDep->Fit(&pol1,"QNR");
68d461b2 959 xvec[counter] = 0.5*(hist->GetXaxis()->GetBinCenter(imin-1)+hist->GetXaxis()->GetBinCenter(imax+1));
391ffdb2 960 yvec[counter] = pol1.GetParameter(1)/pol1.GetParameter(0);
68d461b2 961 xerr[counter] = hist->GetXaxis()->GetBinCenter(imax+1)-hist->GetXaxis()->GetBinCenter(imin-1);
391ffdb2 962 yerr[counter] = pol1.GetParError(1)/pol1.GetParameter(0);
963 counter++;
964 //
68d461b2 965 //delete driftDep;
391ffdb2 966 }
967 //
968 fGraphAttachmentMIP = new TGraphErrors(counter, xvec, yvec, xerr, yerr);
969 if (fGraphAttachmentMIP) fGraphAttachmentMIP->SetName("TGRAPHERRORS_MEAN_ATTACHMENT_BEAM_ALL");// set proper names according to naming convention
970 fGainArray->AddLast(fGraphAttachmentMIP);
971 //
972 delete [] xvec;
973 delete [] yvec;
974 delete [] xerr;
975 delete [] yerr;
976 delete hist;
977 //
978 if (counter < 1) return kFALSE;
979 return kTRUE;
391ffdb2 980
68d461b2 981}
391ffdb2 982
da268e11 983
56b51ad9 984Bool_t AliTPCPreprocessorOffline::AnalyzePadRegionGain(){
985 //
986 // Analyze gain for different pad regions - produce the calibration graphs 0,1,2
987 //
988 if (fGainMult)
989 {
990 TH2D * histQmax = (TH2D*) fGainMult->GetHistPadEqual()->Projection(0,2);
991 TH2D * histQtot = (TH2D*) fGainMult->GetHistPadEqual()->Projection(1,2);
992 //
993 TObjArray arr;
994 histQmax->FitSlicesY(0,0,-1,0,"QNR",&arr);
995 Double_t xMax[3] = {0,1,2};
996 Double_t yMax[3] = {((TH1D*)arr.At(1))->GetBinContent(1),
997 ((TH1D*)arr.At(1))->GetBinContent(2),
998 ((TH1D*)arr.At(1))->GetBinContent(3)};
999 Double_t yMaxErr[3] = {((TH1D*)arr.At(1))->GetBinError(1),
1000 ((TH1D*)arr.At(1))->GetBinError(2),
1001 ((TH1D*)arr.At(1))->GetBinError(3)};
1002 TGraphErrors * fitPadRegionQmax = new TGraphErrors(3, xMax, yMax, 0, yMaxErr);
1003 //
1004 histQtot->FitSlicesY(0,0,-1,0,"QNR",&arr);
1005 Double_t xTot[3] = {0,1,2};
1006 Double_t yTot[3] = {((TH1D*)arr.At(1))->GetBinContent(1),
1007 ((TH1D*)arr.At(1))->GetBinContent(2),
1008 ((TH1D*)arr.At(1))->GetBinContent(3)};
1009 Double_t yTotErr[3] = {((TH1D*)arr.At(1))->GetBinError(1),
1010 ((TH1D*)arr.At(1))->GetBinError(2),
1011 ((TH1D*)arr.At(1))->GetBinError(3)};
1012 TGraphErrors * fitPadRegionQtot = new TGraphErrors(3, xTot, yTot, 0, yTotErr);
1013 //
1014 fitPadRegionQtot->SetName("TGRAPHERRORS_MEANQTOT_PADREGIONGAIN_BEAM_ALL");// set proper names according to naming convention
1015 fitPadRegionQmax->SetName("TGRAPHERRORS_MEANQMAX_PADREGIONGAIN_BEAM_ALL");// set proper names according to naming convention
1016 //
1017 fGainArray->AddLast(fitPadRegionQtot);
1018 fGainArray->AddLast(fitPadRegionQmax);
1019 return kTRUE;
1020 }
1021 return kFALSE;
1022
1023}
1024
1025
6d64657a 1026Bool_t AliTPCPreprocessorOffline::AnalyzeGainMultiplicity() {
1027 //
1028 // Analyze gain as a function of multiplicity and produce calibration graphs
1029 //
1030 if (!fGainMult) return kFALSE;
1031 fGainMult->GetHistGainMult()->GetAxis(3)->SetRangeUser(3,3);
1032 TH2D * histMultMax = fGainMult->GetHistGainMult()->Projection(0,4);
1033 TH2D * histMultTot = fGainMult->GetHistGainMult()->Projection(1,4);
1034 histMultMax->RebinX(4);
1035 histMultTot->RebinX(4);
1036 //
1037 TObjArray arrMax;
1038 TObjArray arrTot;
1039 histMultMax->FitSlicesY(0,0,-1,0,"QNR",&arrMax);
1040 histMultTot->FitSlicesY(0,0,-1,0,"QNR",&arrTot);
1041 //
1042 TH1D * meanMax = (TH1D*)arrMax.At(1);
1043 TH1D * meanTot = (TH1D*)arrTot.At(1);
1044 Float_t meanMult = histMultMax->GetMean();
1045 meanMax->Scale(1./meanMax->GetBinContent(meanMax->FindBin(meanMult)));
1046 meanTot->Scale(1./meanTot->GetBinContent(meanTot->FindBin(meanMult)));
1047 Float_t xMultMax[50];
1048 Float_t yMultMax[50];
1049 Float_t yMultErrMax[50];
1050 Float_t xMultTot[50];
1051 Float_t yMultTot[50];
1052 Float_t yMultErrTot[50];
1053 //
1054 Int_t nCountMax = 0;
1055 for(Int_t iBin = 1; iBin < meanMax->GetXaxis()->GetNbins(); iBin++) {
1056 Float_t yValMax = meanMax->GetBinContent(iBin);
1057 if (yValMax < 0.01) continue;
1058 if (meanMax->GetBinError(iBin)/yValMax > 0.01) continue;
1059 xMultMax[nCountMax] = meanMax->GetXaxis()->GetBinCenter(iBin);
1060 yMultMax[nCountMax] = yValMax;
1061 yMultErrMax[nCountMax] = meanMax->GetBinError(iBin);
1062 nCountMax++;
1063 }
1064 //
1065 if (nCountMax < 10) return kFALSE;
1066 TGraphErrors * fitMultMax = new TGraphErrors(nCountMax, xMultMax, yMultMax, 0, yMultErrMax);
1067 fitMultMax->SetName("TGRAPHERRORS_MEANQMAX_MULTIPLICITYDEPENDENCE_BEAM_ALL");
1068 //
1069 Int_t nCountTot = 0;
1070 for(Int_t iBin = 1; iBin < meanTot->GetXaxis()->GetNbins(); iBin++) {
1071 Float_t yValTot = meanTot->GetBinContent(iBin);
1072 if (yValTot < 0.1) continue;
1073 if (meanTot->GetBinError(iBin)/yValTot > 0.1) continue;
1074 xMultTot[nCountTot] = meanTot->GetXaxis()->GetBinCenter(iBin);
1075 yMultTot[nCountTot] = yValTot;
1076 yMultErrTot[nCountTot] = meanTot->GetBinError(iBin);
1077 nCountTot++;
1078 }
1079 //
1080 if (nCountTot < 10) return kFALSE;
1081 TGraphErrors * fitMultTot = new TGraphErrors(nCountTot, xMultTot, yMultTot, 0, yMultErrTot);
1082 fitMultTot->SetName("TGRAPHERRORS_MEANQTOT_MULTIPLICITYDEPENDENCE_BEAM_ALL");
1083 //
1084 fGainArray->AddLast(fitMultMax);
1085 fGainArray->AddLast(fitMultTot);
1086 //
1087 return kTRUE;
1088
1089}
1090
1091
da268e11 1092void AliTPCPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
1093 //
1094 // Update OCDB entry
1095 //
1096 AliCDBMetaData *metaData= new AliCDBMetaData();
1097 metaData->SetObjectClassName("TObjArray");
1098 metaData->SetResponsible("Alexander Kalweit");
1099 metaData->SetBeamPeriod(1);
1100 metaData->SetAliRootVersion("05-24-00"); //root version
1101 metaData->SetComment("Calibration of the time dependence of the gain due to pressure and temperature changes.");
1102 AliCDBId id1("TPC/Calib/TimeGain", startRunNumber, endRunNumber);
1103 AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
1104 gStorage->Put(fGainArray, id1, metaData);
1105}
1106
1107void AliTPCPreprocessorOffline::MakeQAPlot(Float_t FPtoMIPratio) {
1108 //
1109 // Make QA plot to visualize results
1110 //
1111 //
1112 //
1113 if (fGraphCosmic) {
1114 TCanvas * canvasCosmic = new TCanvas("gain Cosmic", "time dependent gain QA histogram cosmic");
1115 canvasCosmic->cd();
1116 TH2D * gainHistoCosmic = fGainCosmic->GetHistGainTime()->Projection(0,1);
1117 gainHistoCosmic->SetDirectory(0);
1118 gainHistoCosmic->SetName("GainHistoCosmic");
1119 gainHistoCosmic->GetXaxis()->SetTimeDisplay(kTRUE);
1120 gainHistoCosmic->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
1121 gainHistoCosmic->Draw("colz");
1122 fGraphCosmic->SetMarkerStyle(25);
1123 fGraphCosmic->Draw("lp");
1124 fGraphCosmic->SetMarkerStyle(25);
1125 TGraph * grfFitCosmic = fFitCosmic->MakeGraph(fGraphCosmic->GetX()[0],fGraphCosmic->GetX()[fGraphCosmic->GetN()-1],50000,0);
1126 if (grfFitCosmic) {
1127 for(Int_t i=0; i < grfFitCosmic->GetN(); i++) {
1128 grfFitCosmic->GetY()[i] *= FPtoMIPratio;
1129 }
1130 for(Int_t i=0; i < fGraphCosmic->GetN(); i++) {
1131 fGraphCosmic->GetY()[i] *= FPtoMIPratio;
1132 }
1133 }
56b51ad9 1134 fGraphCosmic->Draw("lp");
1135 grfFitCosmic->SetLineColor(2);
1136 grfFitCosmic->Draw("lu");
1137 fGainArray->AddLast(gainHistoCosmic);
1138 //fGainArray->AddLast(canvasCosmic->Clone());
1139 delete canvasCosmic;
da268e11 1140 }
1141 if (fFitMIP) {
1142 TCanvas * canvasMIP = new TCanvas("gain MIP", "time dependent gain QA histogram MIP");
1143 canvasMIP->cd();
1144 TH2D * gainHistoMIP = fGainMIP->GetHistGainTime()->Projection(0,1);
1145 gainHistoMIP->SetName("GainHistoCosmic");
1146 gainHistoMIP->SetDirectory(0);
1147 gainHistoMIP->GetXaxis()->SetTimeDisplay(kTRUE);
1148 gainHistoMIP->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
1149 gainHistoMIP->Draw("colz");
1150 fGraphMIP->SetMarkerStyle(25);
1151 fGraphMIP->Draw("lp");
1152 TGraph * grfFitMIP = fFitMIP->MakeGraph(fGraphMIP->GetX()[0],fGraphMIP->GetX()[fGraphMIP->GetN()-1],50000,0);
1153 grfFitMIP->SetLineColor(2);
1154 grfFitMIP->Draw("lu");
1155 fGainArray->AddLast(gainHistoMIP);
68d461b2 1156 //fGainArray->AddLast(canvasMIP->Clone());
da268e11 1157 delete canvasMIP;
1158 }
1159}
1160
1161
1162