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