]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/qaRec/AliTRDclusterResolution.cxx
various updates in the resolution performance/calibration tasks
[u/mrichter/AliRoot.git] / TRD / qaRec / AliTRDclusterResolution.cxx
CommitLineData
9462866a 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-commercialf 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/* $Id: AliTRDclusterResolution.cxx */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// TRD cluster error parameterization //
21// //
22// This class is designed to produce the reference plots for a detailed study//
23// and parameterization of TRD cluster errors. The following effects are taken//
24// into account : //
25// - dependence with the total charge of the cluster //
26// - dependence with the distance from the center pad. This is monitored
27// for each layer individually since the pad size varies with layer
28// - dependence with the drift length - here the influence of anisochronity
29// and diffusion are searched
30// - dependence with the distance to the anode wire - anisochronity effects
31// - dependence with track angle (for y resolution)
32// The correlation between effects is taken into account.
33//
34// Since magnetic field plays a very important role in the TRD measurement
35// the ExB correction is forced by the setter function SetExB(Int_t). The
36// argument is the detector index, if none is specified all will be
37// considered.
38//
39// Two cases are of big importance.
40// - comparison with MC
41// - comparison with Kalman fit. In this case the covariance matrix of the
42// Kalman fit are needed.
43//
44// The functionalities implemented in this class are based on the storage
45// class AliTRDclusterInfo.
46//
47// The Method
48// ----------
49//
50// The method to disentangle s_y and s_x is based on the relation (see also fig.)
51// BEGIN_LATEX
52// #sigma^{2} = #sigma^{2}_{y} + tg^{2}(#alpha_{L})*#sigma^{2}_{x_{d}} + tg^{2}(#phi-#alpha_{L})*(#sigma^{2}_{x_{d}}+#sigma^{2}_{x_{c}})
53// END_LATEX
54// with
55// BEGIN_LATEX
56// #sigma^{2}_{x_{c}} #approx 0
57// END_LATEX
58// we suppose the chamber is well calibrated for t_{0} and aligned in
59// radial direction.
60//
fa7831fb 61// Clusters can be radially shifted due to three causes:
9462866a 62// - globally shifted - due to residual misalignment/miscalibration(t0)
63// - locally shifted - due to different local drift velocity from the mean
64// - randomly shifted - due to neighboring (radial direction) clusters
65// charge induced by asymmetry of the TRF.
66//
67// We estimate this effects by the relations:
68// BEGIN_LATEX
69// #mu_{y} = tg(#alpha_{L})*#Delta x_{d}(...) + tg(#phi-#alpha_{L})*(#Delta x_{c}(...) + #Delta x_{d}(...))
70// END_LATEX
71// where
72// BEGIN_LATEX
73// #Delta x_{d}(...) = (<v_{d}> + #delta v_{d}(x_{d}, d)) * (t + t^{*}(Q))
74// END_LATEX
75// and we specified explicitely the variation of drift velocity parallel
76// with the track (x_{d}) and perpendicular to it due to anisochronity (d).
77//
78// For estimating the contribution from asymmetry of TRF the following
79// parameterization is being used
80// BEGIN_LATEX
81// t^{*}(Q) = #delta_{0} * #frac{Q_{t+1} - Q_{t-1}}{Q_{t-1} + Q_{t} + Q_{t+1}}
82// END_LATEX
83//
84//
fa7831fb 85// Clusters can also be r-phi shifted due to:
86// - wrong PRF or wrong cuts at digits level
87//The following correction is applied :
88// BEGIN_LATEX
89// <#Delta y> = a + b * sin(c*y_{pw})
90// END_LATEX
91
9462866a 92// The Models
93//
94// Parameterization against total charge
95//
96// Obtained for B=0T at phi=0. All other effects integrated out.
97// BEGIN_LATEX
98// #sigma^{2}_{y}(Q) = #sigma^{2}_{y}(...) + b(#frac{1}{Q} - #frac{1}{Q_{0}})
99// END_LATEX
100// For B diff 0T the error of the average ExB correction error has to be subtracted !!
101//
102// Parameterization Sx
103//
104// The parameterization of the error in the x direction can be written as
105// BEGIN_LATEX
106// #sigma_{x} = #sigma_{x}^{||} + #sigma_{x}^{#perp}
107// END_LATEX
108//
109// where the parallel component is given mainly by the TRF width while
110// the perpendicular component by the anisochronity. The model employed for
111// the parallel is gaus(0)+expo(3) with the following parameters
112// 1 C 5.49018e-01 1.23854e+00 3.84540e-04 -8.21084e-06
113// 2 M 7.82999e-01 6.22531e-01 2.71272e-04 -6.88485e-05
114// 3 S 2.74451e-01 1.13815e+00 2.90667e-04 1.13493e-05
115// 4 E1 2.53596e-01 1.08646e+00 9.95591e-05 -2.11625e-05
116// 5 E2 -2.40078e-02 4.26520e-01 4.67153e-05 -2.35392e-04
117//
118// and perpendicular to the track is pol2 with the parameters
119//
120// Par_0 = 0.190676 +/- 0.41785
121// Par_1 = -3.9269 +/- 7.49862
122// Par_2 = 14.7851 +/- 27.8012
123//
124// Parameterization Sy
125//
126// The parameterization of the error in the y direction along track uses
127// BEGIN_LATEX
f2231ce8 128// #sigma_{y}^{||} = #sigma_{y}^{0} -a*exp(1/(x-b))
9462866a 129// END_LATEX
130//
131// with following values for the parameters:
132// 1 sy0 2.60967e-01 2.99652e-03 7.82902e-06 -1.89636e-04
133// 2 a -7.68941e+00 1.87883e+00 3.84539e-04 9.38268e-07
134// 3 b -3.41160e-01 7.72850e-02 1.63231e-05 2.51602e-05
135//
136//==========================================================================
137// Example how to retrive reference plots from the task
138// void steerClErrParam(Int_t fig=0)
139// {
140// gSystem->Load("libANALYSIS.so");
141// gSystem->Load("libTRDqaRec.so");
142//
143// // initialize DB manager
144// AliCDBManager *cdb = AliCDBManager::Instance();
162637e4 145// cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
9462866a 146// cdb->SetRun(0);
147// // initialize magnetic field.
6fc46cba 148// AliMagFCheb *field=new AliMagFCheb("Maps","Maps", 2, 1., 10., AliMagFCheb::k5kG);
9462866a 149// AliTracker::SetFieldMap(field, kTRUE);
150//
151// AliTRDclusterResolution *res = new AliTRDclusterResolution();
152// res->SetMCdata();
153// res->Load("TRD.TaskClErrParam.root");
6fc46cba 154// res->SetExB();
155// res->SetVisual();
156// //res->SetSaveAs();
157// res->SetProcessCharge(kFALSE);
158// res->SetProcessCenterPad(kFALSE);
159// //res->SetProcessMean(kFALSE);
160// res->SetProcessSigma(kFALSE);
9462866a 161// if(!res->PostProcess()) return;
162// new TCanvas;
163// res->GetRefFigure(fig);
164// }
165//
166// Authors: //
167// Alexandru Bercuci <A.Bercuci@gsi.de> //
168////////////////////////////////////////////////////////////////////////////
169
b2dc316d 170#include "AliTRDclusterResolution.h"
873458ab 171#include "info/AliTRDclusterInfo.h"
5198d8c6 172#include "AliTRDgeometry.h"
6bc4a8f4 173#include "AliTRDcalibDB.h"
a076fc2f 174#include "AliTRDCommonParam.h"
6bc4a8f4 175#include "Cal/AliTRDCalROC.h"
176#include "Cal/AliTRDCalDet.h"
b2dc316d 177
178#include "AliLog.h"
6bc4a8f4 179#include "AliTracker.h"
180#include "AliCDBManager.h"
b2dc316d 181
f2231ce8 182#include "TROOT.h"
b2dc316d 183#include "TObjArray.h"
184#include "TAxis.h"
fc0946a7 185#include "TF1.h"
186#include "TGraphErrors.h"
f2231ce8 187#include "TLine.h"
b2dc316d 188#include "TH2I.h"
dad4c5fc 189#include "TH3S.h"
190#include "TTree.h"
b2dc316d 191#include "TMath.h"
9462866a 192#include "TLinearFitter.h"
193
194#include "TCanvas.h"
195#include "TSystem.h"
196
b2dc316d 197ClassImp(AliTRDclusterResolution)
198
ec3f0161 199const Float_t AliTRDclusterResolution::fgkTimeBinLength = 1./ AliTRDCommonParam::Instance()->GetSamplingFrequency();
b2dc316d 200//_______________________________________________________
eb0b16c1 201AliTRDclusterResolution::AliTRDclusterResolution(const char *name, const char *title)
202 : AliTRDrecoTask(name, title)
f2231ce8 203 ,fCanvas(0x0)
b2dc316d 204 ,fInfo(0x0)
fc0946a7 205 ,fResults(0x0)
206 ,fAt(0x0)
f2231ce8 207 ,fStatus(0)
208 ,fDet(-1)
fc0946a7 209 ,fExB(0.)
9462866a 210 ,fVdrift(0.)
dad4c5fc 211 ////////////
212 ,fLy(0)
213 ,fX(0.)
214 ,fY(0.)
215 ,fZ(0.)
b2dc316d 216{
dad4c5fc 217 memset(fR, 0, 4*sizeof(Float_t));
ec3f0161 218 // time drift axis
219 fAt = new TAxis(kNTB, 0., kNTB*fgkTimeBinLength);
f2231ce8 220
221 // By default register all analysis
222 // The user can switch them off in his steering macro
ec3f0161 223 SetProcess(kQRes);
224 SetProcess(kCenter);
225 SetProcess(kMean);
226 SetProcess(kSigm);
b2dc316d 227}
228
229//_______________________________________________________
230AliTRDclusterResolution::~AliTRDclusterResolution()
231{
f2231ce8 232 if(fCanvas) delete fCanvas;
fc0946a7 233 if(fAt) delete fAt;
234 if(fResults){
235 fResults->Delete();
236 delete fResults;
237 }
b2dc316d 238}
239
240//_______________________________________________________
241void AliTRDclusterResolution::ConnectInputData(Option_t *)
242{
243 fInfo = dynamic_cast<TObjArray *>(GetInputData(0));
244}
245
246//_______________________________________________________
247void AliTRDclusterResolution::CreateOutputObjects()
248{
249 OpenFile(0, "RECREATE");
250 fContainer = Histos();
251}
252
253//_______________________________________________________
e15179be 254Bool_t AliTRDclusterResolution::GetRefFigure(Int_t ifig)
b2dc316d 255{
e15179be 256 if(!fResults) return kFALSE;
fc0946a7 257
f2231ce8 258 TList *l = 0x0;
fc0946a7 259 TObjArray *arr = 0x0;
d667707c 260 TH2 *h2 = 0x0;TH1 *h1 = 0x0;
9462866a 261 TGraphErrors *gm(0x0), *gs(0x0), *gp(0x0);
fc0946a7 262 switch(ifig){
263 case kQRes:
264 if(!(arr = (TObjArray*)fResults->At(kQRes))) break;
265 if(!(gm = (TGraphErrors*)arr->At(0))) break;
266 if(!(gs = (TGraphErrors*)arr->At(1))) break;
9462866a 267 if(!(gp = (TGraphErrors*)arr->At(2))) break;
fc0946a7 268 gs->Draw("apl");
9462866a 269 gs->GetHistogram()->GetYaxis()->SetRangeUser(-.01, .6);
270 gs->GetHistogram()->SetXTitle("Q [a.u.]");
271 gs->GetHistogram()->SetYTitle("#sigma_{y} / #mu_{y} [mm] / freq");
272 gm->Draw("pl");
273 gp->Draw("pl");
e15179be 274 return kTRUE;
9462866a 275 case kCenter:
276 if(!(arr = (TObjArray*)fResults->At(kCenter))) break;
f2231ce8 277 gPad->Divide(3, 1); l = gPad->GetListOfPrimitives();
278 for(Int_t ipad = 3; ipad--;){
279 if(!(h2 = (TH2F*)arr->At(ipad))) return kFALSE;
280 ((TVirtualPad*)l->At(ipad))->cd();
281 h2->Draw("lego2fb");
282 }
e15179be 283 return kTRUE;
9462866a 284 case kSigm:
285 if(!(arr = (TObjArray*)fResults->At(kSigm))) break;
f2231ce8 286 gPad->Divide(2, 1); l = gPad->GetListOfPrimitives();
d667707c 287 if(!(h2 = (TH2F*)arr->At(0))) return kFALSE;
288 ((TVirtualPad*)l->At(0))->cd();
289 h1 = h2->ProjectionY("hsx_pyy"); h1->Scale(1.e4/kND); h1->SetMarkerStyle(24);
290 h1->SetYTitle("<#sigma_{x}> [#mum]");
291 h1->GetXaxis()->SetRange(2, kNTB-1); h1->Draw("pc");
292
293 if(!(h2 = (TH2F*)arr->At(1))) return kFALSE;
294 ((TVirtualPad*)l->At(1))->cd();
295 h1 = h2->ProjectionY("hsy_pyy"); h1->Scale(1.e4/kND); h1->SetMarkerStyle(24);
296 h1->SetYTitle("<#sigma_{y}> [#mum]");
297 h1->GetXaxis()->SetRange(2, kNTB-1); h1->Draw("pc");
9462866a 298 return kTRUE;
299 case kMean:
300 if(!(arr = (TObjArray*)fResults->At(kMean))) break;
f2231ce8 301 gPad->Divide(2, 1); l = gPad->GetListOfPrimitives();
d667707c 302 ((TVirtualPad*)l->At(0))->cd();
303 if(!(gm = (TGraphErrors*)arr->At(0))) return kFALSE;
304 gm->Draw("apl");
305 gm->GetHistogram()->SetXTitle("t_{drift} [#mus]");
306 gm->GetHistogram()->SetYTitle("dx [#mum]");
307
308 ((TVirtualPad*)l->At(1))->cd();
309 if(!(gm = (TGraphErrors*)arr->At(1))) return kFALSE;
310 gm->Draw("apl");
311 gm->GetHistogram()->SetXTitle("t_{drift} [#mus]");
312 gm->GetHistogram()->SetYTitle("dy [#mum]");
313
e15179be 314 return kTRUE;
fc0946a7 315 default:
316 break;
317 }
9462866a 318 AliWarning("No container/data found.");
e15179be 319 return kFALSE;
b2dc316d 320}
321
322//_______________________________________________________
323TObjArray* AliTRDclusterResolution::Histos()
324{
325 if(fContainer) return fContainer;
dad4c5fc 326 fContainer = new TObjArray(kNtasks);
b2dc316d 327 //fContainer->SetOwner(kTRUE);
328
5198d8c6 329 TH2I *h2 = 0x0;
dad4c5fc 330 TH3S *h3 = 0x0;
5198d8c6 331 TObjArray *arr = 0x0;
332
dad4c5fc 333 fContainer->AddAt(h2 = new TH2I("Charge", "dy=f(q)", 50, 2.2, 7.5, 60, -.3, .3), kQRes);
5198d8c6 334 h2->SetXTitle("log(q) [a.u.]");
335 h2->SetYTitle("#Delta y[cm]");
336 h2->SetZTitle("entries");
337
dad4c5fc 338 fContainer->AddAt(arr = new TObjArray(AliTRDgeometry::kNlayer), kCenter);
339 arr->SetName("Center");
340 for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++){
341 if(!(h3=(TH3S*)gROOT->FindObject(Form("hc_l%1d", il)))){
342 h3 = new TH3S(
343 Form("hc_l%1d", il),
344 Form(" ly [%d]", il),
345 kNTB, fAt->GetBinLowEdge(1), fAt->GetBinUpEdge(kNTB), // x
346 51, -.51, .51, // y
347 60, -.3, .3); // dy
348 h3->SetXTitle("x [#mus]");
349 h3->SetYTitle("y [pw]");
350 h3->SetZTitle("#Delta y[cm]");
351 } h3->Reset();
352 arr->AddAt(h3, il);
5198d8c6 353 }
354
dad4c5fc 355 fContainer->AddAt(arr = new TObjArray(kNTB), kSigm);
6fc46cba 356 arr->SetName("Resolution");
dad4c5fc 357 for(Int_t ix=0; ix<kNTB; ix++){
358 if(!(h3=(TH3S*)gROOT->FindObject(Form("hr_x%02d", ix)))){
359 h3 = new TH3S(
360 Form("hr_x%02d", ix),
361 Form(" t_{drift}(%3.1f-%3.1f)[#mus]", fAt->GetBinLowEdge(ix+1), fAt->GetBinUpEdge(ix+1)),
362 kND, 0., 2.5, // z
363 35, -.35, .35, // tgp
364 60, -.3, .3); // dy
365 h3->SetXTitle("z [mm]");
366 h3->SetYTitle("tg#phi");
367 h3->SetZTitle("#Delta y[cm]");
b2dc316d 368 }
dad4c5fc 369 arr->AddAt(h3, ix);
b2dc316d 370 }
9462866a 371
dad4c5fc 372 fContainer->AddAt(arr = new TObjArray(kNTB), kMean);
6fc46cba 373 arr->SetName("Systematics");
dad4c5fc 374 for(Int_t ix=0; ix<kNTB; ix++){
375 if(!(h3=(TH3S*)gROOT->FindObject(Form("hs_x%02d", ix)))){
376 h3 = new TH3S(
377 Form("hs_x%02d", ix),
378 Form(" t_{drift}(%3.1f-%3.1f)[#mus]", fAt->GetBinLowEdge(ix+1), fAt->GetBinUpEdge(ix+1)),
379 kND, 0., 2.5, // z
380 35, -.35, .35, // tgp-h tgt
381 60, -.3, .3); // dy
382 h3->SetXTitle("z [mm]");
383 h3->SetYTitle("tg(#phi) - h*tg(#theta)");
384 h3->SetZTitle("#Delta y[cm]");
9462866a 385 }
dad4c5fc 386 arr->AddAt(h3, ix);
9462866a 387 }
388
b2dc316d 389 return fContainer;
390}
391
392//_______________________________________________________
393void AliTRDclusterResolution::Exec(Option_t *)
394{
6bc4a8f4 395 if(!HasExB()) AliWarning("ExB was not set. Call SetExB() before running the task.");
396
87b166d3 397 Int_t det, t;
fc0946a7 398 Float_t x, y, z, q, dy, dydx, dzdx, cov[3], covcl[3];
b2dc316d 399 TH2I *h2 = 0x0;
dad4c5fc 400 TH3S *h3 = 0x0;
5198d8c6 401
9462866a 402 // define limits around ExB for which x contribution is negligible
403 const Float_t kDtgPhi = 3.5e-2; //(+- 2 deg)
404
dad4c5fc 405 TObjArray *arr0 = (TObjArray*)fContainer->At(kCenter);
9462866a 406 TObjArray *arr1 = (TObjArray*)fContainer->At(kSigm);
407 TObjArray *arr2 = (TObjArray*)fContainer->At(kMean);
5198d8c6 408
b2dc316d 409 const AliTRDclusterInfo *cli = 0x0;
410 TIterator *iter=fInfo->MakeIterator();
411 while((cli=dynamic_cast<AliTRDclusterInfo*>((*iter)()))){
6bc4a8f4 412 cli->GetCluster(det, x, y, z, q, t, covcl);
413 if(fDet>=0 && fDet!=det) continue;
9462866a 414
415 dy = cli->GetResolution();
416 cli->GetGlobalPosition(y, z, dydx, dzdx, &cov[0]);
417
418 // resolution as a function of cluster charge
419 // only for phi equal exB
420 if(TMath::Abs(dydx-fExB) < kDtgPhi){
421 h2 = (TH2I*)fContainer->At(kQRes);
422 h2->Fill(TMath::Log(q), dy);
423 }
424
425 // do not use problematic clusters in resolution analysis
426 // TODO define limits as calibration aware (gain) !!
427 if(q<20. || q>250.) continue;
428
dad4c5fc 429 x = (t+.5)*fgkTimeBinLength; // conservative approach !!
430
9462866a 431 // resolution as a function of y displacement from pad center
432 // only for phi equal exB
433 if(TMath::Abs(dydx-fExB) < kDtgPhi){
dad4c5fc 434 h3 = (TH3S*)arr0->At(AliTRDgeometry::GetLayer(det));
435 h3->Fill(x, cli->GetYDisplacement(), dy);
9462866a 436 }
6bc4a8f4 437
dad4c5fc 438 Int_t ix = fAt->FindBin(x);
439 if(ix==0 || ix == fAt->GetNbins()+1){
440 AliWarning(Form("Drift time %3.1f outside allowed range", x));
b2dc316d 441 continue;
442 }
b2dc316d 443
9462866a 444 // fill histo for resolution (sigma)
dad4c5fc 445 ((TH3S*)arr1->At(ix-1))->Fill(10.*cli->GetAnisochronity(), dydx, dy);
b2dc316d 446
9462866a 447 // fill histo for systematic (mean)
dad4c5fc 448 ((TH3S*)arr2->At(ix-1))->Fill(10.*cli->GetAnisochronity(), dydx-cli->GetTilt()*dzdx, dy);
b2dc316d 449 }
450 PostData(0, fContainer);
451}
452
453
454//_______________________________________________________
455Bool_t AliTRDclusterResolution::PostProcess()
456{
fc0946a7 457 if(!fContainer) return kFALSE;
6bc4a8f4 458 if(!HasExB()) AliWarning("ExB was not set. Call SetExB() before running the post processing.");
fc0946a7 459
5198d8c6 460 TObjArray *arr = 0x0;
dad4c5fc 461 TTree *t=0x0;
fc0946a7 462 if(!fResults){
463 TGraphErrors *g = 0x0;
dad4c5fc 464 fResults = new TObjArray(kNtasks);
fc0946a7 465 fResults->SetOwner();
9462866a 466 fResults->AddAt(arr = new TObjArray(3), kQRes);
fc0946a7 467 arr->SetOwner();
468 arr->AddAt(g = new TGraphErrors(), 0);
469 g->SetLineColor(kBlue); g->SetMarkerColor(kBlue);
470 g->SetMarkerStyle(7);
471 arr->AddAt(g = new TGraphErrors(), 1);
472 g->SetLineColor(kRed); g->SetMarkerColor(kRed);
473 g->SetMarkerStyle(23);
9462866a 474 arr->AddAt(g = new TGraphErrors(), 2);
475 g->SetLineColor(kGreen); g->SetMarkerColor(kGreen);
fc0946a7 476 g->SetMarkerStyle(7);
fc0946a7 477
dad4c5fc 478 // pad center dependence
479 fResults->AddAt(t = new TTree("cent", "dy=f(y,x,ly)"), kCenter);
480 t->Branch("ly", &fLy, "ly/B");
481 t->Branch("x", &fX, "x/F");
482 t->Branch("y", &fY, "y/F");
483 t->Branch("m", &fR[0], "m[2]/F");
484 t->Branch("s", &fR[2], "s[2]/F");
f2231ce8 485
dad4c5fc 486
487 fResults->AddAt(t = new TTree("sigm", "dy=f(dw,x,dydx)"), kSigm);
488 t->Branch("x", &fX, "x/F");
489 t->Branch("z", &fZ, "z/F");
490 t->Branch("sx", &fR[0], "sx[2]/F");
491 t->Branch("sy", &fR[2], "sy[2]/F");
492
493
494 fResults->AddAt(t = new TTree("mean", "dy=f(dw,x,dydx - h dzdx)"), kMean);
495 t->Branch("x", &fX, "x/F");
496 t->Branch("z", &fZ, "z/F");
497 t->Branch("dx", &fR[0], "dx[2]/F");
498 t->Branch("dy", &fR[2], "dy[2]/F");
fc0946a7 499 } else {
500 TObject *o = 0x0;
501 TIterator *iter=fResults->MakeIterator();
5198d8c6 502 while((o=((*iter)()))) o->Clear(); // maybe it is wrong but we should never reach this point
fc0946a7 503 }
9462866a 504
505 // precalculated value of tg^2(alpha_L)
506 Double_t exb2 = fExB*fExB;
507 // square of the mean value of sigma drift length.
508 // has to come from previous calibration
509 //Double_t sxd2 = 1.;// [mm^2]
fc0946a7 510
9462866a 511 printf("ExB[%e] ExB2[%e]\n", fExB, exb2);
fc0946a7 512
513 // process resolution dependency on charge
ec3f0161 514 if(HasProcess(kQRes)) ProcessCharge();
fc0946a7 515
fc0946a7 516 // process resolution dependency on y displacement
ec3f0161 517 if(HasProcess(kCenter)) ProcessCenterPad();
fc0946a7 518
5198d8c6 519 // process resolution dependency on drift legth and drift cell width
ec3f0161 520 if(HasProcess(kSigm)) ProcessSigma();
9462866a 521
522 // process systematic shift on drift legth and drift cell width
ec3f0161 523 if(HasProcess(kMean)) ProcessMean();
fc0946a7 524
525 return kTRUE;
b2dc316d 526}
527
6bc4a8f4 528//_______________________________________________________
9462866a 529Bool_t AliTRDclusterResolution::SetExB(Int_t det, Int_t col, Int_t row)
6bc4a8f4 530{
531 // check OCDB
532 AliCDBManager *cdb = AliCDBManager::Instance();
533 if(cdb->GetRun() < 0){
534 AliError("OCDB manager not properly initialized");
535 return kFALSE;
536 }
537
538 // check magnetic field
539 if(TMath::Abs(AliTracker::GetBz()) < 1.e-10){
540 AliWarning("B=0. Magnetic field may not be initialized. Continue if you know what you are doing !");
541 }
542
543 // set reference detector if any
544 if(det>=0 && det<AliTRDgeometry::kNdet) fDet = det;
545 else det = 0;
546
547 AliTRDcalibDB *fCalibration = AliTRDcalibDB::Instance();
548 AliTRDCalROC *fCalVdriftROC = fCalibration->GetVdriftROC(det);
549 const AliTRDCalDet *fCalVdriftDet = fCalibration->GetVdriftDet();
550
9462866a 551 fVdrift = fCalVdriftDet->GetValue(det) * fCalVdriftROC->GetValue(col, row);
a076fc2f 552 fExB = AliTRDCommonParam::Instance()->GetOmegaTau(fVdrift);
6bc4a8f4 553 SetBit(kExB);
554 return kTRUE;
555}
b2dc316d 556
f2231ce8 557//_______________________________________________________
558void AliTRDclusterResolution::SetVisual()
559{
560 if(fCanvas) return;
561 fCanvas = new TCanvas("clResCanvas", "Cluster Resolution Visualization", 10, 10, 600, 600);
562}
563
9462866a 564//_______________________________________________________
565void AliTRDclusterResolution::ProcessCharge()
566{
567 TH2I *h2 = 0x0;
568 if((h2 = (TH2I*)fContainer->At(kQRes))) {
569 AliWarning("Missing dy=f(Q) histo");
570 return;
571 }
572 TF1 f("f", "gaus", -.5, .5);
573 TAxis *ax = 0x0;
574 TH1D *h1 = 0x0;
575
576 TObjArray *arr = (TObjArray*)fResults->At(kQRes);
577 TGraphErrors *gqm = (TGraphErrors*)arr->At(0);
578 TGraphErrors *gqs = (TGraphErrors*)arr->At(1);
579 TGraphErrors *gqp = (TGraphErrors*)arr->At(2);
580 Double_t q, n = 0., entries;
581 ax = h2->GetXaxis();
582 for(Int_t ix=1; ix<=ax->GetNbins(); ix++){
2a12b21f 583 q = TMath::Exp(ax->GetBinCenter(ix));
9462866a 584 if(q<20. || q>250.) continue; // ?!
585
586 h1 = h2->ProjectionY("py", ix, ix);
587 entries = h1->GetEntries();
588 if(entries < 50) continue;
589 Adjust(&f, h1);
590 h1->Fit(&f, "Q");
591
592 // Fill sy^2 = f(q)
593 Int_t ip = gqm->GetN();
594 gqm->SetPoint(ip, q, 10.*f.GetParameter(1));
595 gqm->SetPointError(ip, 0., 10.*f.GetParError(1));
596
597 // correct sigma for ExB effect
598 gqs->SetPoint(ip, q, 1.e1*f.GetParameter(2)/**f.GetParameter(2)-exb2*sxd2*/);
599 gqs->SetPointError(ip, 0., 1.e1*f.GetParError(2)/**f.GetParameter(2)*/);
600
601 // save probability
602 n += entries;
603 gqp->SetPoint(ip, q, entries);
604 gqp->SetPointError(ip, 0., 0./*TMath::Sqrt(entries)*/);
605 }
606
607 // normalize probability and get mean sy
608 Double_t sm = 0., sy;
609 for(Int_t ip=gqp->GetN(); ip--;){
610 gqp->GetPoint(ip, q, entries);
611 entries/=n;
612 gqp->SetPoint(ip, q, entries);
613 gqs->GetPoint(ip, q, sy);
614 sm += entries*sy;
615 }
616
617 // error parametrization s(q) = <sy> + b(1/q-1/q0)
618 TF1 fq("fq", "[0] + [1]/x", 20., 250.);
619 gqs->Fit(&fq);
620 printf("sy(Q) :: sm[%f] b[%f] 1/q0[%f]\n", sm, fq.GetParameter(1), (sm-fq.GetParameter(0))/fq.GetParameter(1));
621}
622
623//_______________________________________________________
624void AliTRDclusterResolution::ProcessCenterPad()
625{
dad4c5fc 626 TObjArray *arr = (TObjArray*)fContainer->At(kCenter);
627 if(!arr) {
eb0b16c1 628 AliWarning("Missing dy=f(y | x, ly) container");
9462866a 629 return;
630 }
631 TF1 f("f", "gaus", -.5, .5);
dad4c5fc 632 TH1D *h1 = 0x0; TH3S *h3=0x0;
633 TTree *t = (TTree*)fResults->At(kCenter);
634 TAxis *ax = 0x0;
635 for(Int_t il=0; il<arr->GetEntriesFast(); il++){
636 if(!(h3 = (TH3S*)arr->At(il))) continue;
637
638 fLy = il;
639 for(Int_t ix=1; ix<=h3->GetXaxis()->GetNbins(); ix++){
640 ax = h3->GetXaxis();
641 ax->SetRange(ix, ix);
642 fX = ax->GetBinCenter(ix);
643 //printf(" x[%2d]=%4.2f\n", ix, fX);
644 for(Int_t iy=1; iy<=h3->GetYaxis()->GetNbins(); iy++){
645 ax = h3->GetYaxis();
646 ax->SetRange(iy, iy);
647 fY = ax->GetBinCenter(iy);
648 //printf(" y[%2d]=%5.2f\n", iy, fY);
eb0b16c1 649 // finish navigation in the HnSparse
650
dad4c5fc 651 h1 = (TH1D*)h3->Project3D("z");
652 Int_t entries = (Int_t)h1->Integral();
eb0b16c1 653 if(entries < 50) continue;
654 //Adjust(&f, h1);
655 h1->Fit(&f, "QN");
fa7831fb 656
dad4c5fc 657
658 // Fill sy,my=f(y_w,x,ly)
659 fR[0] = f.GetParameter(1); fR[1] = f.GetParError(1);
660 fR[2] = f.GetParameter(2); fR[3] = f.GetParError(2);
f2231ce8 661
dad4c5fc 662 //printf("ly[%d] x[%3.1f] y[%+5.2f] m[%5.3f] s[%5.3f] \n", fLy, fX, fY, fR[0], fR[2]);
663 t->Fill();
664 }
fa7831fb 665 }
f2231ce8 666 if(!fCanvas) continue;
dad4c5fc 667
668 t->Draw("y:x>>h(23, 0.1, 2.4, 51, -.51, .51)",
669 Form("m[0]*(ly==%d&&abs(m[0])<1.e-1)", fLy),
670 "lego2fb");
671 fCanvas->Modified(); fCanvas->Update();
672 if(IsSaveAs()) fCanvas->SaveAs(Form("Figures/ProcessCenter_ly[%d].gif", fLy));
673 else gSystem->Sleep(100);
f2231ce8 674 }
9462866a 675}
676
677//_______________________________________________________
678void AliTRDclusterResolution::ProcessSigma()
679{
680 TObjArray *arr = (TObjArray*)fContainer->At(kSigm);
681 if(!arr){
dad4c5fc 682 AliWarning("Missing dy=f(x_d, d_w) container");
9462866a 683 return;
684 }
d667707c 685
f2231ce8 686 // init visualization
687 TGraphErrors *ggs = 0x0;
d667707c 688 TGraph *line = 0x0;
f2231ce8 689 if(fCanvas){
690 ggs = new TGraphErrors();
d667707c 691 line = new TGraph();
692 line->SetLineColor(kRed);line->SetLineWidth(2);
f2231ce8 693 }
9462866a 694
dad4c5fc 695 // init logistic support
696 TF1 f("f", "gaus", -.5, .5);
697 TLinearFitter gs(1,"pol1");
698 TH1 *hFrame=0x0;
699 TH1D *h1 = 0x0; TH3S *h3=0x0;
700 TAxis *ax = 0x0;
701 Double_t exb2 = fExB*fExB;
702
703 TTree *t = (TTree*)fResults->At(kSigm);
704 for(Int_t ix=0; ix<kNTB; ix++){
705 if(!(h3=(TH3S*)arr->At(ix))) continue;
706 fX = fAt->GetBinCenter(ix+1);
707
708 for(Int_t iz=1; iz<=h3->GetXaxis()->GetNbins(); iz++){
709 ax = h3->GetXaxis();
710 ax->SetRange(iz, iz);
711 fZ = ax->GetBinCenter(iz);
f2231ce8 712
dad4c5fc 713 // reset visualization
f2231ce8 714 if(fCanvas){
715 new(ggs) TGraphErrors();
716 ggs->SetMarkerStyle(7);
717 }
9462866a 718 gs.ClearPoints();
dad4c5fc 719
720 for(Int_t ip=1; ip<=h3->GetYaxis()->GetNbins(); ip++){
721 ax = h3->GetYaxis();
722 ax->SetRange(ip, ip);
723 Double_t tgl = ax->GetBinCenter(ip);
724 // finish navigation in the HnSparse
725
d667707c 726 //if(TMath::Abs(dydx)>0.18) continue;
dad4c5fc 727 Double_t tgg = (tgl-fExB)/(1.+tgl*fExB);
9462866a 728 Double_t tgg2 = tgg*tgg;
dad4c5fc 729
730 h1 = (TH1D*)h3->Project3D("z");
731 Int_t entries = (Int_t)h1->Integral();
732 if(entries < 50) continue;
9462866a 733 //Adjust(&f, h1);
9462866a 734 h1->Fit(&f, "QN");
dad4c5fc 735
f2231ce8 736 Double_t s2 = f.GetParameter(2)*f.GetParameter(2);
737 Double_t s2e = 2.*f.GetParameter(2)*f.GetParError(2);
9462866a 738 // Fill sy^2 = f(tg^2(phi-a_L))
f2231ce8 739 gs.AddPoint(&tgg2, s2, s2e);
740
741 if(!ggs) continue;
742 Int_t ip = ggs->GetN();
743 ggs->SetPoint(ip, tgg2, s2);
744 ggs->SetPointError(ip, 0., s2e);
9462866a 745 }
746 if(gs.Eval()) continue;
d667707c 747
748 // s^2_x = s0^2_x - x^2*tg^2(a_L)/12
dad4c5fc 749 fR[0] = gs.GetParameter(1)/* - x*x*exb2/12.*/;
750 if(fR[0]<0.) continue;
751 fR[0] = TMath::Sqrt(fR[0]);
752 fR[1] = .5*gs.GetParError(1)/fR[0];
9462866a 753
d667707c 754 // s^2_y = s0^2_y + tg^2(a_L) * s^2_x
755 // s0^2_y = f(D_L)*x + s_PRF^2
dad4c5fc 756 fR[2]= gs.GetParameter(0)/*-exb2*sx*/;
757 if(fR[1] <0.) continue;
758 fR[2] = TMath::Sqrt(fR[2]);
759 fR[3] = gs.GetParError(0)+exb2*exb2*gs.GetParError(1);
760 t->Fill();
f2231ce8 761
d667707c 762 if(!fCanvas) continue;
763 fCanvas->cd(); fCanvas->SetLogx(); //fCanvas->SetLogy();
764 if(!hFrame){
765 hFrame=new TH1I("hFrame", "", 100, 0., .3);
766 hFrame->SetMinimum(0.);hFrame->SetMaximum(.005);
767 hFrame->SetXTitle("tg^{2}(#phi-#alpha_{L})");
768 hFrame->SetYTitle("#sigma^{2}y[cm^{2}]");
769 hFrame->SetLineColor(1);hFrame->SetLineWidth(1);
770 hFrame->Draw();
771 } else hFrame->Reset();
772 Double_t xx = 0., dxx=.2/50;
773 for(Int_t ip=0;ip<50;ip++){
774 line->SetPoint(ip, xx, gs.GetParameter(0)+xx*gs.GetParameter(1));
775 xx+=dxx;
776 }
777 ggs->Draw("pl"); line->Draw("l");
f2231ce8 778 fCanvas->Modified(); fCanvas->Update();
dad4c5fc 779 if(IsSaveAs()) fCanvas->SaveAs(Form("Figures/ProcessSigma_z[%5.3f]_x[%5.3f].gif", fZ, fX));
f2231ce8 780 else gSystem->Sleep(100);
781
dad4c5fc 782 printf(" xd=%4.1f[cm] sx=%5.3e[cm] sy=%5.3e[cm]\n", fX, TMath::Sqrt(fR[0]), TMath::Sqrt(fR[1]));
9462866a 783 }
784 }
d667707c 785 return;
9462866a 786}
787
788//_______________________________________________________
789void AliTRDclusterResolution::ProcessMean()
790{
791 TObjArray *arr = (TObjArray*)fContainer->At(kMean);
792 if(!arr){
dad4c5fc 793 AliWarning("Missing dy=f(x_d, d_w) container");
9462866a 794 return;
795 }
dad4c5fc 796
797 // init logistic support
9462866a 798 TF1 f("f", "gaus", -.5, .5);
81a6494d 799 TF1 line("l", "[0]+[1]*x", -.15, .15);
dad4c5fc 800 TGraphErrors *gm = new TGraphErrors();
81a6494d 801 TH1 *hFrame=0x0;
dad4c5fc 802 TH1D *h1 = 0x0; TH3S *h3 =0x0;
803 TAxis *ax = 0x0;
9462866a 804
dad4c5fc 805 TTree *t = (TTree*)fResults->At(kMean);
806 for(Int_t ix=0; ix<kNTB; ix++){
807 if(!(h3=(TH3S*)arr->At(ix))) continue;
808 fX = fAt->GetBinCenter(ix+1);
809
810 for(Int_t iz=1; iz<=h3->GetXaxis()->GetNbins(); iz++){
811 ax = h3->GetXaxis();
812 ax->SetRange(iz, iz);
813 fZ = ax->GetBinCenter(iz);
f2231ce8 814
dad4c5fc 815 // reset fitter
f2231ce8 816 new(gm) TGraphErrors();
817 gm->SetMarkerStyle(7);
dad4c5fc 818
819 for(Int_t ip=1; ip<=h3->GetYaxis()->GetNbins(); ip++){
820 ax = h3->GetYaxis();
821 ax->SetRange(ip, ip);
822 Double_t tgl = ax->GetBinCenter(ip);
823 // finish navigation in the HnSparse
824
825 h1 = (TH1D*)h3->Project3D("z");
826 Int_t entries = (Int_t)h1->Integral();
827 if(entries < 50) continue;
9462866a 828 //Adjust(&f, h1);
9462866a 829 h1->Fit(&f, "QN");
830
831 // Fill <Dy> = f(dydx - h*dzdx)
f2231ce8 832 Int_t ip = gm->GetN();
dad4c5fc 833 gm->SetPoint(ip, tgl, f.GetParameter(1));
f2231ce8 834 gm->SetPointError(ip, 0., f.GetParError(1));
9462866a 835 ip++;
836 }
837 if(gm->GetN()<4) continue;
838
839 gm->Fit(&line, "QN");
dad4c5fc 840 fR[0] = line.GetParameter(1); // dx
841 fR[1] = line.GetParError(1);
842 fR[2] = line.GetParameter(0) + fExB*fR[0]; // xs = dy - tg(a_L)*dx
843 t->Fill();
f2231ce8 844
845 if(!fCanvas) continue;
846 fCanvas->cd();
81a6494d 847 if(!hFrame){
848 hFrame=new TH1I("hFrame", "", 100, -.3, .3);
849 hFrame->SetMinimum(-.1);hFrame->SetMaximum(.1);
850 hFrame->SetXTitle("tg#phi-htg#theta");
851 hFrame->SetYTitle("#Deltay[cm]");
852 hFrame->SetLineColor(1);hFrame->SetLineWidth(1);
853 hFrame->Draw();
854 } else hFrame->Reset();
855 gm->Draw("pl"); line.Draw("same");
f2231ce8 856 fCanvas->Modified(); fCanvas->Update();
dad4c5fc 857 if(IsSaveAs()) fCanvas->SaveAs(Form("Figures/ProcessMean_Z[%5.3f]_X[%5.3f].gif", fZ, fX));
f2231ce8 858 else gSystem->Sleep(100);
dad4c5fc 859 printf(" xd=%4.2f[cm] dx=%5.3e[cm] dy=%5.3e[cm]\n", fX, fR[0], fR[2]);
9462866a 860 }
861 }
dad4c5fc 862
863 // draw shift results
864 //t->Draw("z:x>>h(24, 0, 2.4, 25, 0, 2.5)", "dx*(abs(dx)<1.e-2)", "lego2fb");
865 //t->Draw("z:x>>h(24, 0, 2.4, 25, 0, 2.5)", "dy*(abs(dx)<1.e-2)", "lego2fb");
9462866a 866
9462866a 867}