]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/Base/AliTPCCorrection.cxx
- fix for TRD on-line track matching with tracks having TPCrefit but not TPCout ...
[u/mrichter/AliRoot.git] / TPC / Base / AliTPCCorrection.cxx
CommitLineData
0116859c 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
b4caed64 16// _________________________________________________________________
17//
18// Begin_Html
19// <h2> AliTPCCorrection class </h2>
20//
21// The AliTPCCorrection class provides a general framework to deal with space point distortions.
22// An correction class which inherits from here is for example AliTPCExBBShape or AliTPCExBTwist. <br>
23// General virtual functions are (for example) CorrectPoint(x,roc) where x is the vector of initial
24// positions in cartesian coordinates and roc represents the read-out chamber number according to
25// the offline numbering convention. The vector x is overwritten with the corrected coordinates. <br>
26// An alternative usage would be CorrectPoint(x,roc,dx), which leaves the vector x untouched, but
27// returns the distortions via the vector dx. <br>
28// This class is normally used via the general class AliTPCComposedCorrection.
29// <p>
30// Furthermore, the class contains basic geometrical descriptions like field cage radii
31// (fgkIFCRadius, fgkOFCRadius) and length (fgkTPCZ0) plus the voltages. Also, the definitions
32// of size and widths of the fulcrums building the grid of the final look-up table, which is
33// then interpolated, is defined in kNX and fgkXList).
34// <p>
35// All physics-model classes below are derived from this class in order to not duplicate code
36// and to allow a uniform treatment of all physics models.
37// <p>
38// <h3> Poisson solver </h3>
39// A numerical solver of the Poisson equation (relaxation technique) is implemented for 2-dimensional
40// geometries (r,z) as well as for 3-dimensional problems (r,$\phi$,z). The corresponding function
41// names are PoissonRelaxation?D. The relevant function arguments are the arrays of the boundary and
42// initial conditions (ArrayofArrayV, ArrayofChargeDensities) as well as the grid granularity which
43// is used during the calculation. These inputs can be chosen according to the needs of the physical
44// effect which is supposed to be simulated. In the 3D version, different symmetry conditions can be set
45// in order to reduce the calculation time (used in AliTPCFCVoltError3D).
46// <p>
47// <h3> Unified plotting functionality </h3>
48// Generic plot functions were implemented. They return a histogram pointer in the chosen plane of
49// the TPC drift volume with a selectable grid granularity and the magnitude of the correction vector.
50// For example, the function CreateHistoDZinXY(z,nx,ny) returns a 2-dimensional histogram which contains
51// the longitudinal corrections $dz$ in the (x,y)-plane at the given z position with the granularity of
52// nx and ny. The magnitude of the corrections is defined by the class from which this function is called.
53// In the same manner, standard plots for the (r,$\phi$)-plane and for the other corrections like $dr$ and $rd\phi$ are available
54// <p>
55// Note: This class is normally used via the class AliTPCComposedCorrection
56// End_Html
57//
6a1caa6b 58// Begin_Macro(source)
b4caed64 59// {
60// gROOT->SetStyle("Plain"); gStyle->SetPalette(1);
6a1caa6b 61// TCanvas *c2 = new TCanvas("cAliTPCCorrection","cAliTPCCorrection",700,1050); c2->Divide(2,3);
b4caed64 62// AliTPCROCVoltError3D roc; // EXAMPLE PLOTS - SEE BELOW
63// roc.SetOmegaTauT1T2(0,1,1); // B=0
64// Float_t z0 = 1; // at +1 cm -> A side
65// c2->cd(1); roc.CreateHistoDRinXY(1.,300,300)->Draw("cont4z");
66// c2->cd(3);roc.CreateHistoDRPhiinXY(1.,300,300)->Draw("cont4z");
67// c2->cd(5);roc.CreateHistoDZinXY(1.,300,300)->Draw("cont4z");
68// Float_t phi0=0.5;
69// c2->cd(2);roc.CreateHistoDRinZR(phi0)->Draw("surf2");
70// c2->cd(4);roc.CreateHistoDRPhiinZR(phi0)->Draw("surf2");
71// c2->cd(6);roc.CreateHistoDZinZR(phi0)->Draw("surf2");
72// return c2;
73// }
74// End_Macro
75//
76// Begin_Html
77// <p>
78// Date: 27/04/2010 <br>
79// Authors: Magnus Mager, Stefan Rossegger, Jim Thomas
80// End_Html
81// _________________________________________________________________
82
83
be67055b 84#include "Riostream.h"
0116859c 85
86#include <TH2F.h>
87#include <TMath.h>
88#include <TROOT.h>
cf5b0aa0 89#include <TTreeStream.h>
ffab0c37 90#include <TTree.h>
91#include <TFile.h>
e527a1b9 92#include <TTimeStamp.h>
ffab0c37 93#include <AliCDBStorage.h>
94#include <AliCDBId.h>
95#include <AliCDBMetaData.h>
c9cbd2f2 96#include "TVectorD.h"
97#include "AliTPCParamSR.h"
7f4cb119 98
c9cbd2f2 99#include "AliTPCCorrection.h"
100#include "AliLog.h"
1b923461 101
1b923461 102#include "AliExternalTrackParam.h"
103#include "AliTrackPointArray.h"
104#include "TDatabasePDG.h"
105#include "AliTrackerBase.h"
106#include "AliTPCROC.h"
107#include "THnSparse.h"
108
c9cbd2f2 109#include "AliTPCLaserTrack.h"
110#include "AliESDVertex.h"
111#include "AliVertexerTracks.h"
112#include "TDatabasePDG.h"
113#include "TF1.h"
7f4cb119 114#include "TRandom.h"
c9cbd2f2 115
116#include "TDatabasePDG.h"
117
7f4cb119 118#include "AliTPCTransform.h"
119#include "AliTPCcalibDB.h"
120#include "AliTPCExB.h"
cf5b0aa0 121
c9cbd2f2 122#include "AliTPCRecoParam.h"
fdbbc146 123#include "TLinearFitter.h"
1b923461 124
0116859c 125
cf5b0aa0 126ClassImp(AliTPCCorrection)
127
f1817479 128
129TObjArray *AliTPCCorrection::fgVisualCorrection=0;
130// instance of correction for visualization
131
132
0116859c 133// FIXME: the following values should come from the database
c9cbd2f2 134const Double_t AliTPCCorrection::fgkTPCZ0 = 249.7; // nominal gating grid position
2b68ab9c 135const Double_t AliTPCCorrection::fgkIFCRadius= 83.5; // radius which renders the "18 rod manifold" best -> compare calc. of Jim Thomas
136// compare gkIFCRadius= 83.05: Mean Radius of the Inner Field Cage ( 82.43 min, 83.70 max) (cm)
c9cbd2f2 137const Double_t AliTPCCorrection::fgkOFCRadius= 254.5; // Mean Radius of the Outer Field Cage (252.55 min, 256.45 max) (cm)
138const Double_t AliTPCCorrection::fgkZOffSet = 0.2; // Offset from CE: calculate all distortions closer to CE as if at this point
139const Double_t AliTPCCorrection::fgkCathodeV = -100000.0; // Cathode Voltage (volts)
140const Double_t AliTPCCorrection::fgkGG = -70.0; // Gating Grid voltage (volts)
0116859c 141
c9cbd2f2 142const Double_t AliTPCCorrection::fgkdvdE = 0.0024; // [cm/V] drift velocity dependency on the E field (from Magboltz for NeCO2N2 at standard environment)
0116859c 143
c9cbd2f2 144const Double_t AliTPCCorrection::fgkEM = -1.602176487e-19/9.10938215e-31; // charge/mass in [C/kg]
145const Double_t AliTPCCorrection::fgke0 = 8.854187817e-12; // vacuum permittivity [A·s/(V·m)]
c9cbd2f2 146
0116859c 147
148AliTPCCorrection::AliTPCCorrection()
c9cbd2f2 149 : TNamed("correction_unity","unity"),fILow(0),fJLow(0),fKLow(0), fT1(1), fT2(1)
0116859c 150{
151 //
152 // default constructor
153 //
f1817479 154 if (!fgVisualCorrection) fgVisualCorrection= new TObjArray;
c9cbd2f2 155
35ae345f 156 InitLookUpfulcrums();
c9cbd2f2 157
0116859c 158}
159
160AliTPCCorrection::AliTPCCorrection(const char *name,const char *title)
c9cbd2f2 161: TNamed(name,title),fILow(0),fJLow(0),fKLow(0), fT1(1), fT2(1)
0116859c 162{
163 //
164 // default constructor, that set the name and title
165 //
f1817479 166 if (!fgVisualCorrection) fgVisualCorrection= new TObjArray;
c9cbd2f2 167
35ae345f 168 InitLookUpfulcrums();
c9cbd2f2 169
0116859c 170}
171
172AliTPCCorrection::~AliTPCCorrection() {
173 //
174 // virtual destructor
175 //
176}
177
178void AliTPCCorrection::CorrectPoint(Float_t x[],const Short_t roc) {
179 //
180 // Corrects the initial coordinates x (cartesian coordinates)
181 // according to the given effect (inherited classes)
182 // roc represents the TPC read out chamber (offline numbering convention)
183 //
184 Float_t dx[3];
185 GetCorrection(x,roc,dx);
186 for (Int_t j=0;j<3;++j) x[j]+=dx[j];
187}
188
189void AliTPCCorrection::CorrectPoint(const Float_t x[],const Short_t roc,Float_t xp[]) {
190 //
191 // Corrects the initial coordinates x (cartesian coordinates) and stores the new
192 // (distorted) coordinates in xp. The distortion is set according to the given effect (inherited classes)
193 // roc represents the TPC read out chamber (offline numbering convention)
194 //
195 Float_t dx[3];
196 GetCorrection(x,roc,dx);
197 for (Int_t j=0;j<3;++j) xp[j]=x[j]+dx[j];
198}
199
200void AliTPCCorrection::DistortPoint(Float_t x[],const Short_t roc) {
201 //
202 // Distorts the initial coordinates x (cartesian coordinates)
203 // according to the given effect (inherited classes)
204 // roc represents the TPC read out chamber (offline numbering convention)
205 //
206 Float_t dx[3];
207 GetDistortion(x,roc,dx);
208 for (Int_t j=0;j<3;++j) x[j]+=dx[j];
209}
210
46e89793 211void AliTPCCorrection::DistortPointLocal(Float_t x[],const Short_t roc) {
212 //
213 // Distorts the initial coordinates x (cartesian coordinates)
214 // according to the given effect (inherited classes)
215 // roc represents the TPC read out chamber (offline numbering convention)
216 //
217 Float_t gxyz[3]={0,0,0};
218 Double_t alpha = TMath::Pi()*(roc%18+0.5)/18;
219 Double_t ca=TMath::Cos(alpha), sa= TMath::Sin(alpha);
220 gxyz[0]= ca*x[0]+sa*x[1];
221 gxyz[1]= -sa*x[0]+ca*x[1];
222 gxyz[2]= x[2];
223 DistortPoint(gxyz,roc);
224 x[0]= ca*gxyz[0]-sa*gxyz[1];
225 x[1]= +sa*gxyz[0]+ca*gxyz[1];
226 x[2]= gxyz[2];
227}
228void AliTPCCorrection::CorrectPointLocal(Float_t x[],const Short_t roc) {
229 //
230 // Distorts the initial coordinates x (cartesian coordinates)
231 // according to the given effect (inherited classes)
232 // roc represents the TPC read out chamber (offline numbering convention)
233 //
234 Float_t gxyz[3]={0,0,0};
235 Double_t alpha = TMath::Pi()*(roc%18+0.5)/18;
236 Double_t ca=TMath::Cos(alpha), sa= TMath::Sin(alpha);
237 gxyz[0]= ca*x[0]+sa*x[1];
238 gxyz[1]= -sa*x[0]+ca*x[1];
239 gxyz[2]= x[2];
240 CorrectPoint(gxyz,roc);
241 x[0]= ca*gxyz[0]-sa*gxyz[1];
242 x[1]= sa*gxyz[0]+ca*gxyz[1];
243 x[2]= gxyz[2];
244}
245
0116859c 246void AliTPCCorrection::DistortPoint(const Float_t x[],const Short_t roc,Float_t xp[]) {
247 //
248 // Distorts the initial coordinates x (cartesian coordinates) and stores the new
249 // (distorted) coordinates in xp. The distortion is set according to the given effect (inherited classes)
250 // roc represents the TPC read out chamber (offline numbering convention)
251 //
252 Float_t dx[3];
253 GetDistortion(x,roc,dx);
254 for (Int_t j=0;j<3;++j) xp[j]=x[j]+dx[j];
255}
256
257void AliTPCCorrection::GetCorrection(const Float_t /*x*/[],const Short_t /*roc*/,Float_t dx[]) {
258 //
259 // This function delivers the correction values dx in respect to the inital coordinates x
260 // roc represents the TPC read out chamber (offline numbering convention)
261 // Note: The dx is overwritten by the inherited effectice class ...
262 //
263 for (Int_t j=0;j<3;++j) { dx[j]=0.; }
264}
265
266void AliTPCCorrection::GetDistortion(const Float_t x[],const Short_t roc,Float_t dx[]) {
267 //
268 // This function delivers the distortion values dx in respect to the inital coordinates x
269 // roc represents the TPC read out chamber (offline numbering convention)
270 //
271 GetCorrection(x,roc,dx);
272 for (Int_t j=0;j<3;++j) dx[j]=-dx[j];
273}
274
fdbbc146 275void AliTPCCorrection::GetCorrectionDz(const Float_t x[],const Short_t roc,Float_t dx[], Float_t delta) {
276 // author: marian.ivanov@cern.ch
277 //
278 // In this (virtual)function calculates the dx'/dz, dy'/dz and dz'/dz at given point (x,y,z)
279 // Generic implementation. Better precision can be acchieved knowing the internal structure
280 // of underlying trasnformation. Derived classes can reimplement it.
281 // To calculate correction is fitted in small neighberhood:
282 // (x+-delta,y+-delta,z+-delta) where delta is an argument
283 //
284 // Input parameters:
285 // x[] - space point corrdinate
286 // roc - readout chamber identifier (important e.g to do not miss the side of detector)
287 // delta - define the size of neighberhood
288 // Output parameter:
289 // dx[] - array {dx'/dz, dy'/dz , dz'/dz }
290
291 static TLinearFitter fitx(2,"pol1");
292 static TLinearFitter fity(2,"pol1");
293 static TLinearFitter fitz(2,"pol1");
294 fitx.ClearPoints();
295 fity.ClearPoints();
296 fitz.ClearPoints();
297 for (Int_t xdelta=-1; xdelta<=1; xdelta++)
298 for (Int_t ydelta=-1; ydelta<=1; ydelta++){
299 for (Int_t zdelta=-1; zdelta<=1; zdelta++){
300 Float_t xyz[3]={x[0]+xdelta*delta, x[1]+ydelta*delta, x[2]+zdelta*delta};
301 Float_t dxyz[3];
302 GetCorrection(xyz,roc,dxyz);
303 Double_t adelta=zdelta*delta;
304 fitx.AddPoint(&adelta, dxyz[0]);
305 fity.AddPoint(&adelta, dxyz[1]);
306 fitz.AddPoint(&adelta, dxyz[2]);
307 }
308 }
309 fitx.Eval();
310 fity.Eval();
311 fitz.Eval();
312 dx[0] = fitx.GetParameter(1);
313 dx[1] = fity.GetParameter(1);
314 dx[2] = fitz.GetParameter(1);
315}
316
317void AliTPCCorrection::GetCorrectionIntegralDz(const Float_t x[],const Short_t roc,Float_t dx[], Float_t delta){
318 //
319 // Integrate 3D distortion along drift lines
320 // To define the drift lines virtual function AliTPCCorrection::GetCorrectionDz is used
321 //
322 // Input parameters:
323 // x[] - space point corrdinate
324 // roc - readout chamber identifier (important e.g to do not miss the side of detector)
325 // delta - define the size of neighberhood
326 // Output parameter:
327 // dx[] - array { integral(dx'/dz), integral(dy'/dz) , integral(dz'/dz) }
328
329 Float_t zroc= ((roc%36)<18) ? fgkTPCZ0:-fgkTPCZ0;
330 Double_t zdrift = TMath::Abs(x[2]-zroc);
331 Int_t nsteps = Int_t(zdrift/delta)+1;
332 //
333 //
334 Float_t xyz[3]={x[0],x[1],x[2]};
335 Float_t dxyz[3]={x[0],x[1],x[2]};
336 Float_t sign=((roc%36)<18) ? 1.:-1.;
337 Double_t sumdz=0;
338 for (Int_t i=0;i<nsteps; i++){
339 Float_t deltaZ=delta;
340 if (xyz[2]+deltaZ>fgkTPCZ0) deltaZ=TMath::Abs(xyz[2]-fgkTPCZ0);
341 if (xyz[2]-deltaZ<-fgkTPCZ0) deltaZ=TMath::Abs(xyz[2]-fgkTPCZ0);
342 deltaZ*=sign;
343 GetCorrectionDz(xyz,roc,dxyz,delta);
344 xyz[0]+=deltaZ*dxyz[0];
345 xyz[1]+=deltaZ*dxyz[1];
346 xyz[2]+=deltaZ; //
347 sumdz+=deltaZ*dxyz[2];
348 }
349 //
350 dx[0]=x[0]-xyz[0];
351 dx[1]=x[1]-xyz[1];
352 dx[2]= dxyz[2];
353
354}
355
356
357
0116859c 358void AliTPCCorrection::Init() {
359 //
360 // Initialization funtion (not used at the moment)
361 //
362}
363
e527a1b9 364void AliTPCCorrection::Update(const TTimeStamp &/*timeStamp*/) {
365 //
366 // Update function
367 //
368}
369
0116859c 370void AliTPCCorrection::Print(Option_t* /*option*/) const {
371 //
372 // Print function to check which correction classes are used
373 // option=="d" prints details regarding the setted magnitude
374 // option=="a" prints the C0 and C1 coefficents for calibration purposes
375 //
376 printf("TPC spacepoint correction: \"%s\"\n",GetTitle());
377}
378
534fd34a 379void AliTPCCorrection:: SetOmegaTauT1T2(Float_t /*omegaTau*/,Float_t t1,Float_t t2) {
0116859c 380 //
381 // Virtual funtion to pass the wt values (might become event dependent) to the inherited classes
382 // t1 and t2 represent the "effective omegaTau" corrections and were measured in a dedicated
383 // calibration run
384 //
534fd34a 385 fT1=t1;
386 fT2=t2;
387 //SetOmegaTauT1T2(omegaTau, t1, t2);
0116859c 388}
389
390TH2F* AliTPCCorrection::CreateHistoDRinXY(Float_t z,Int_t nx,Int_t ny) {
391 //
392 // Simple plot functionality.
393 // Returns a 2d hisogram which represents the corrections in radial direction (dr)
394 // in respect to position z within the XY plane.
395 // The histogramm has nx times ny entries.
396 //
c9cbd2f2 397 AliTPCParam* tpcparam = new AliTPCParamSR;
398
0116859c 399 TH2F *h=CreateTH2F("dr_xy",GetTitle(),"x [cm]","y [cm]","dr [cm]",
400 nx,-250.,250.,ny,-250.,250.);
401 Float_t x[3],dx[3];
402 x[2]=z;
403 Int_t roc=z>0.?0:18; // FIXME
404 for (Int_t iy=1;iy<=ny;++iy) {
405 x[1]=h->GetYaxis()->GetBinCenter(iy);
406 for (Int_t ix=1;ix<=nx;++ix) {
407 x[0]=h->GetXaxis()->GetBinCenter(ix);
408 GetCorrection(x,roc,dx);
409 Float_t r0=TMath::Sqrt((x[0] )*(x[0] )+(x[1] )*(x[1] ));
c9cbd2f2 410 if (tpcparam->GetPadRowRadii(0,0)<=r0 && r0<=tpcparam->GetPadRowRadii(36,95)) {
0116859c 411 Float_t r1=TMath::Sqrt((x[0]+dx[0])*(x[0]+dx[0])+(x[1]+dx[1])*(x[1]+dx[1]));
412 h->SetBinContent(ix,iy,r1-r0);
413 }
414 else
415 h->SetBinContent(ix,iy,0.);
416 }
417 }
c9cbd2f2 418 delete tpcparam;
0116859c 419 return h;
420}
421
422TH2F* AliTPCCorrection::CreateHistoDRPhiinXY(Float_t z,Int_t nx,Int_t ny) {
423 //
424 // Simple plot functionality.
425 // Returns a 2d hisogram which represents the corrections in rphi direction (drphi)
426 // in respect to position z within the XY plane.
427 // The histogramm has nx times ny entries.
428 //
429
c9cbd2f2 430 AliTPCParam* tpcparam = new AliTPCParamSR;
431
0116859c 432 TH2F *h=CreateTH2F("drphi_xy",GetTitle(),"x [cm]","y [cm]","drphi [cm]",
433 nx,-250.,250.,ny,-250.,250.);
434 Float_t x[3],dx[3];
435 x[2]=z;
436 Int_t roc=z>0.?0:18; // FIXME
437 for (Int_t iy=1;iy<=ny;++iy) {
438 x[1]=h->GetYaxis()->GetBinCenter(iy);
439 for (Int_t ix=1;ix<=nx;++ix) {
440 x[0]=h->GetXaxis()->GetBinCenter(ix);
441 GetCorrection(x,roc,dx);
442 Float_t r0=TMath::Sqrt((x[0] )*(x[0] )+(x[1] )*(x[1] ));
c9cbd2f2 443 if (tpcparam->GetPadRowRadii(0,0)<=r0 && r0<=tpcparam->GetPadRowRadii(36,95)) {
0116859c 444 Float_t phi0=TMath::ATan2(x[1] ,x[0] );
445 Float_t phi1=TMath::ATan2(x[1]+dx[1],x[0]+dx[0]);
446
447 Float_t dphi=phi1-phi0;
448 if (dphi<TMath::Pi()) dphi+=TMath::TwoPi();
449 if (dphi>TMath::Pi()) dphi-=TMath::TwoPi();
450
451 h->SetBinContent(ix,iy,r0*dphi);
452 }
453 else
454 h->SetBinContent(ix,iy,0.);
455 }
456 }
c9cbd2f2 457 delete tpcparam;
458 return h;
459}
460
461TH2F* AliTPCCorrection::CreateHistoDZinXY(Float_t z,Int_t nx,Int_t ny) {
462 //
463 // Simple plot functionality.
464 // Returns a 2d hisogram which represents the corrections in longitudinal direction (dz)
465 // in respect to position z within the XY plane.
466 // The histogramm has nx times ny entries.
467 //
468
469 AliTPCParam* tpcparam = new AliTPCParamSR;
470
471 TH2F *h=CreateTH2F("dz_xy",GetTitle(),"x [cm]","y [cm]","dz [cm]",
472 nx,-250.,250.,ny,-250.,250.);
473 Float_t x[3],dx[3];
474 x[2]=z;
475 Int_t roc=z>0.?0:18; // FIXME
476 for (Int_t iy=1;iy<=ny;++iy) {
477 x[1]=h->GetYaxis()->GetBinCenter(iy);
478 for (Int_t ix=1;ix<=nx;++ix) {
479 x[0]=h->GetXaxis()->GetBinCenter(ix);
480 GetCorrection(x,roc,dx);
481 Float_t r0=TMath::Sqrt((x[0] )*(x[0] )+(x[1] )*(x[1] ));
482 if (tpcparam->GetPadRowRadii(0,0)<=r0 && r0<=tpcparam->GetPadRowRadii(36,95)) {
483 h->SetBinContent(ix,iy,dx[2]);
484 }
485 else
486 h->SetBinContent(ix,iy,0.);
487 }
488 }
489 delete tpcparam;
0116859c 490 return h;
491}
492
493TH2F* AliTPCCorrection::CreateHistoDRinZR(Float_t phi,Int_t nz,Int_t nr) {
494 //
495 // Simple plot functionality.
496 // Returns a 2d hisogram which represents the corrections in r direction (dr)
497 // in respect to angle phi within the ZR plane.
498 // The histogramm has nx times ny entries.
499 //
500 TH2F *h=CreateTH2F("dr_zr",GetTitle(),"z [cm]","r [cm]","dr [cm]",
501 nz,-250.,250.,nr,85.,250.);
502 Float_t x[3],dx[3];
503 for (Int_t ir=1;ir<=nr;++ir) {
504 Float_t radius=h->GetYaxis()->GetBinCenter(ir);
505 x[0]=radius*TMath::Cos(phi);
506 x[1]=radius*TMath::Sin(phi);
507 for (Int_t iz=1;iz<=nz;++iz) {
508 x[2]=h->GetXaxis()->GetBinCenter(iz);
509 Int_t roc=x[2]>0.?0:18; // FIXME
510 GetCorrection(x,roc,dx);
511 Float_t r0=TMath::Sqrt((x[0] )*(x[0] )+(x[1] )*(x[1] ));
512 Float_t r1=TMath::Sqrt((x[0]+dx[0])*(x[0]+dx[0])+(x[1]+dx[1])*(x[1]+dx[1]));
513 h->SetBinContent(iz,ir,r1-r0);
514 }
515 }
0116859c 516 return h;
517
518}
519
520TH2F* AliTPCCorrection::CreateHistoDRPhiinZR(Float_t phi,Int_t nz,Int_t nr) {
521 //
522 // Simple plot functionality.
523 // Returns a 2d hisogram which represents the corrections in rphi direction (drphi)
524 // in respect to angle phi within the ZR plane.
525 // The histogramm has nx times ny entries.
526 //
527 TH2F *h=CreateTH2F("drphi_zr",GetTitle(),"z [cm]","r [cm]","drphi [cm]",
528 nz,-250.,250.,nr,85.,250.);
529 Float_t x[3],dx[3];
530 for (Int_t iz=1;iz<=nz;++iz) {
531 x[2]=h->GetXaxis()->GetBinCenter(iz);
532 Int_t roc=x[2]>0.?0:18; // FIXME
533 for (Int_t ir=1;ir<=nr;++ir) {
534 Float_t radius=h->GetYaxis()->GetBinCenter(ir);
535 x[0]=radius*TMath::Cos(phi);
536 x[1]=radius*TMath::Sin(phi);
537 GetCorrection(x,roc,dx);
538 Float_t r0=TMath::Sqrt((x[0] )*(x[0] )+(x[1] )*(x[1] ));
539 Float_t phi0=TMath::ATan2(x[1] ,x[0] );
540 Float_t phi1=TMath::ATan2(x[1]+dx[1],x[0]+dx[0]);
541
542 Float_t dphi=phi1-phi0;
543 if (dphi<TMath::Pi()) dphi+=TMath::TwoPi();
544 if (dphi>TMath::Pi()) dphi-=TMath::TwoPi();
545
546 h->SetBinContent(iz,ir,r0*dphi);
547 }
548 }
549 return h;
550}
551
c9cbd2f2 552TH2F* AliTPCCorrection::CreateHistoDZinZR(Float_t phi,Int_t nz,Int_t nr) {
553 //
554 // Simple plot functionality.
555 // Returns a 2d hisogram which represents the corrections in longitudinal direction (dz)
556 // in respect to angle phi within the ZR plane.
557 // The histogramm has nx times ny entries.
558 //
559 TH2F *h=CreateTH2F("dz_zr",GetTitle(),"z [cm]","r [cm]","dz [cm]",
560 nz,-250.,250.,nr,85.,250.);
561 Float_t x[3],dx[3];
562 for (Int_t ir=1;ir<=nr;++ir) {
563 Float_t radius=h->GetYaxis()->GetBinCenter(ir);
564 x[0]=radius*TMath::Cos(phi);
565 x[1]=radius*TMath::Sin(phi);
566 for (Int_t iz=1;iz<=nz;++iz) {
567 x[2]=h->GetXaxis()->GetBinCenter(iz);
568 Int_t roc=x[2]>0.?0:18; // FIXME
569 GetCorrection(x,roc,dx);
570 h->SetBinContent(iz,ir,dx[2]);
571 }
572 }
573 return h;
574
575}
576
577
0116859c 578TH2F* AliTPCCorrection::CreateTH2F(const char *name,const char *title,
579 const char *xlabel,const char *ylabel,const char *zlabel,
580 Int_t nbinsx,Double_t xlow,Double_t xup,
581 Int_t nbinsy,Double_t ylow,Double_t yup) {
582 //
583 // Helper function to create a 2d histogramm of given size
584 //
585
586 TString hname=name;
587 Int_t i=0;
588 if (gDirectory) {
589 while (gDirectory->FindObject(hname.Data())) {
590 hname =name;
591 hname+="_";
592 hname+=i;
593 ++i;
594 }
595 }
596 TH2F *h=new TH2F(hname.Data(),title,
597 nbinsx,xlow,xup,
598 nbinsy,ylow,yup);
599 h->GetXaxis()->SetTitle(xlabel);
600 h->GetYaxis()->SetTitle(ylabel);
601 h->GetZaxis()->SetTitle(zlabel);
602 h->SetStats(0);
603 return h;
604}
605
0116859c 606// Simple Interpolation functions: e.g. with bi(tri)cubic interpolations (not yet in TH2 and TH3)
607
608void AliTPCCorrection::Interpolate2DEdistortion( const Int_t order, const Double_t r, const Double_t z,
b1f0a2a5 609 const Double_t er[kNZ][kNR], Double_t &erValue ) {
0116859c 610 //
611 // Interpolate table - 2D interpolation
612 //
25732bff 613 Double_t saveEr[5] = {0,0,0,0,0};
0116859c 614
615 Search( kNZ, fgkZList, z, fJLow ) ;
616 Search( kNR, fgkRList, r, fKLow ) ;
617 if ( fJLow < 0 ) fJLow = 0 ; // check if out of range
618 if ( fKLow < 0 ) fKLow = 0 ;
619 if ( fJLow + order >= kNZ - 1 ) fJLow = kNZ - 1 - order ;
620 if ( fKLow + order >= kNR - 1 ) fKLow = kNR - 1 - order ;
621
622 for ( Int_t j = fJLow ; j < fJLow + order + 1 ; j++ ) {
b1f0a2a5 623 saveEr[j-fJLow] = Interpolate( &fgkRList[fKLow], &er[j][fKLow], order, r ) ;
0116859c 624 }
b1f0a2a5 625 erValue = Interpolate( &fgkZList[fJLow], saveEr, order, z ) ;
0116859c 626
627}
628
c9cbd2f2 629void AliTPCCorrection::Interpolate3DEdistortion( const Int_t order, const Double_t r, const Float_t phi, const Double_t z,
630 const Double_t er[kNZ][kNPhi][kNR], const Double_t ephi[kNZ][kNPhi][kNR], const Double_t ez[kNZ][kNPhi][kNR],
631 Double_t &erValue, Double_t &ephiValue, Double_t &ezValue) {
632 //
633 // Interpolate table - 3D interpolation
634 //
635
25732bff 636 Double_t saveEr[5]= {0,0,0,0,0};
637 Double_t savedEr[5]= {0,0,0,0,0} ;
638
639 Double_t saveEphi[5]= {0,0,0,0,0};
640 Double_t savedEphi[5]= {0,0,0,0,0} ;
641
642 Double_t saveEz[5]= {0,0,0,0,0};
643 Double_t savedEz[5]= {0,0,0,0,0} ;
c9cbd2f2 644
645 Search( kNZ, fgkZList, z, fILow ) ;
646 Search( kNPhi, fgkPhiList, z, fJLow ) ;
647 Search( kNR, fgkRList, r, fKLow ) ;
648
649 if ( fILow < 0 ) fILow = 0 ; // check if out of range
650 if ( fJLow < 0 ) fJLow = 0 ;
651 if ( fKLow < 0 ) fKLow = 0 ;
652
653 if ( fILow + order >= kNZ - 1 ) fILow = kNZ - 1 - order ;
654 if ( fJLow + order >= kNPhi - 1 ) fJLow = kNPhi - 1 - order ;
655 if ( fKLow + order >= kNR - 1 ) fKLow = kNR - 1 - order ;
656
657 for ( Int_t i = fILow ; i < fILow + order + 1 ; i++ ) {
658 for ( Int_t j = fJLow ; j < fJLow + order + 1 ; j++ ) {
659 saveEr[j-fJLow] = Interpolate( &fgkRList[fKLow], &er[i][j][fKLow], order, r ) ;
660 saveEphi[j-fJLow] = Interpolate( &fgkRList[fKLow], &ephi[i][j][fKLow], order, r ) ;
661 saveEz[j-fJLow] = Interpolate( &fgkRList[fKLow], &ez[i][j][fKLow], order, r ) ;
662 }
663 savedEr[i-fILow] = Interpolate( &fgkPhiList[fJLow], saveEr, order, phi ) ;
664 savedEphi[i-fILow] = Interpolate( &fgkPhiList[fJLow], saveEphi, order, phi ) ;
665 savedEz[i-fILow] = Interpolate( &fgkPhiList[fJLow], saveEz, order, phi ) ;
666 }
667 erValue = Interpolate( &fgkZList[fILow], savedEr, order, z ) ;
668 ephiValue = Interpolate( &fgkZList[fILow], savedEphi, order, z ) ;
669 ezValue = Interpolate( &fgkZList[fILow], savedEz, order, z ) ;
670
671}
672
673Double_t AliTPCCorrection::Interpolate2DTable( const Int_t order, const Double_t x, const Double_t y,
674 const Int_t nx, const Int_t ny, const Double_t xv[], const Double_t yv[],
675 const TMatrixD &array ) {
676 //
677 // Interpolate table (TMatrix format) - 2D interpolation
678 //
679
680 static Int_t jlow = 0, klow = 0 ;
25732bff 681 Double_t saveArray[5] = {0,0,0,0,0} ;
c9cbd2f2 682
683 Search( nx, xv, x, jlow ) ;
684 Search( ny, yv, y, klow ) ;
685 if ( jlow < 0 ) jlow = 0 ; // check if out of range
686 if ( klow < 0 ) klow = 0 ;
687 if ( jlow + order >= nx - 1 ) jlow = nx - 1 - order ;
688 if ( klow + order >= ny - 1 ) klow = ny - 1 - order ;
689
690 for ( Int_t j = jlow ; j < jlow + order + 1 ; j++ )
691 {
692 Double_t *ajkl = &((TMatrixD&)array)(j,klow);
693 saveArray[j-jlow] = Interpolate( &yv[klow], ajkl , order, y ) ;
694 }
695
696 return( Interpolate( &xv[jlow], saveArray, order, x ) ) ;
697
698}
699
700Double_t AliTPCCorrection::Interpolate3DTable( const Int_t order, const Double_t x, const Double_t y, const Double_t z,
701 const Int_t nx, const Int_t ny, const Int_t nz,
702 const Double_t xv[], const Double_t yv[], const Double_t zv[],
703 TMatrixD **arrayofArrays ) {
704 //
705 // Interpolate table (TMatrix format) - 3D interpolation
706 //
707
708 static Int_t ilow = 0, jlow = 0, klow = 0 ;
25732bff 709 Double_t saveArray[5]= {0,0,0,0,0};
710 Double_t savedArray[5]= {0,0,0,0,0} ;
c9cbd2f2 711
712 Search( nx, xv, x, ilow ) ;
713 Search( ny, yv, y, jlow ) ;
714 Search( nz, zv, z, klow ) ;
715
716 if ( ilow < 0 ) ilow = 0 ; // check if out of range
717 if ( jlow < 0 ) jlow = 0 ;
718 if ( klow < 0 ) klow = 0 ;
719
720 if ( ilow + order >= nx - 1 ) ilow = nx - 1 - order ;
721 if ( jlow + order >= ny - 1 ) jlow = ny - 1 - order ;
722 if ( klow + order >= nz - 1 ) klow = nz - 1 - order ;
723
724 for ( Int_t k = klow ; k < klow + order + 1 ; k++ )
725 {
726 TMatrixD &table = *arrayofArrays[k] ;
727 for ( Int_t i = ilow ; i < ilow + order + 1 ; i++ )
728 {
729 saveArray[i-ilow] = Interpolate( &yv[jlow], &table(i,jlow), order, y ) ;
730 }
731 savedArray[k-klow] = Interpolate( &xv[ilow], saveArray, order, x ) ;
732 }
733 return( Interpolate( &zv[klow], savedArray, order, z ) ) ;
734
735}
736
0116859c 737Double_t AliTPCCorrection::Interpolate( const Double_t xArray[], const Double_t yArray[],
b1f0a2a5 738 const Int_t order, const Double_t x ) {
0116859c 739 //
740 // Interpolate function Y(x) using linear (order=1) or quadratic (order=2) interpolation.
741 //
742
743 Double_t y ;
744 if ( order == 2 ) { // Quadratic Interpolation = 2
745 y = (x-xArray[1]) * (x-xArray[2]) * yArray[0] / ( (xArray[0]-xArray[1]) * (xArray[0]-xArray[2]) ) ;
746 y += (x-xArray[2]) * (x-xArray[0]) * yArray[1] / ( (xArray[1]-xArray[2]) * (xArray[1]-xArray[0]) ) ;
747 y += (x-xArray[0]) * (x-xArray[1]) * yArray[2] / ( (xArray[2]-xArray[0]) * (xArray[2]-xArray[1]) ) ;
748 } else { // Linear Interpolation = 1
749 y = yArray[0] + ( yArray[1]-yArray[0] ) * ( x-xArray[0] ) / ( xArray[1] - xArray[0] ) ;
750 }
751
752 return (y);
753
754}
755
2bf29b72 756Float_t AliTPCCorrection::Interpolate2DTable( const Int_t order, const Double_t x, const Double_t y,
757 const Int_t nx, const Int_t ny, const Double_t xv[], const Double_t yv[],
758 const TMatrixF &array ) {
759 //
760 // Interpolate table (TMatrix format) - 2D interpolation
761 // Float version (in order to decrease the OCDB size)
762 //
763
764 static Int_t jlow = 0, klow = 0 ;
765 Float_t saveArray[5] = {0.,0.,0.,0.,0.} ;
766
767 Search( nx, xv, x, jlow ) ;
768 Search( ny, yv, y, klow ) ;
769 if ( jlow < 0 ) jlow = 0 ; // check if out of range
770 if ( klow < 0 ) klow = 0 ;
771 if ( jlow + order >= nx - 1 ) jlow = nx - 1 - order ;
772 if ( klow + order >= ny - 1 ) klow = ny - 1 - order ;
773
774 for ( Int_t j = jlow ; j < jlow + order + 1 ; j++ )
775 {
776 Float_t *ajkl = &((TMatrixF&)array)(j,klow);
777 saveArray[j-jlow] = Interpolate( &yv[klow], ajkl , order, y ) ;
778 }
779
780 return( Interpolate( &xv[jlow], saveArray, order, x ) ) ;
781
782}
783
784Float_t AliTPCCorrection::Interpolate3DTable( const Int_t order, const Double_t x, const Double_t y, const Double_t z,
785 const Int_t nx, const Int_t ny, const Int_t nz,
786 const Double_t xv[], const Double_t yv[], const Double_t zv[],
787 TMatrixF **arrayofArrays ) {
788 //
789 // Interpolate table (TMatrix format) - 3D interpolation
790 // Float version (in order to decrease the OCDB size)
791 //
792
793 static Int_t ilow = 0, jlow = 0, klow = 0 ;
794 Float_t saveArray[5]= {0.,0.,0.,0.,0.};
795 Float_t savedArray[5]= {0.,0.,0.,0.,0.} ;
796
797 Search( nx, xv, x, ilow ) ;
798 Search( ny, yv, y, jlow ) ;
799 Search( nz, zv, z, klow ) ;
800
801 if ( ilow < 0 ) ilow = 0 ; // check if out of range
802 if ( jlow < 0 ) jlow = 0 ;
803 if ( klow < 0 ) klow = 0 ;
804
805 if ( ilow + order >= nx - 1 ) ilow = nx - 1 - order ;
806 if ( jlow + order >= ny - 1 ) jlow = ny - 1 - order ;
807 if ( klow + order >= nz - 1 ) klow = nz - 1 - order ;
808
809 for ( Int_t k = klow ; k < klow + order + 1 ; k++ )
810 {
811 TMatrixF &table = *arrayofArrays[k] ;
812 for ( Int_t i = ilow ; i < ilow + order + 1 ; i++ )
813 {
814 saveArray[i-ilow] = Interpolate( &yv[jlow], &table(i,jlow), order, y ) ;
815 }
816 savedArray[k-klow] = Interpolate( &xv[ilow], saveArray, order, x ) ;
817 }
818 return( Interpolate( &zv[klow], savedArray, order, z ) ) ;
819
820}
821Float_t AliTPCCorrection::Interpolate( const Double_t xArray[], const Float_t yArray[],
822 const Int_t order, const Double_t x ) {
823 //
824 // Interpolate function Y(x) using linear (order=1) or quadratic (order=2) interpolation.
825 // Float version (in order to decrease the OCDB size)
826 //
827
828 Float_t y ;
829 if ( order == 2 ) { // Quadratic Interpolation = 2
830 y = (x-xArray[1]) * (x-xArray[2]) * yArray[0] / ( (xArray[0]-xArray[1]) * (xArray[0]-xArray[2]) ) ;
831 y += (x-xArray[2]) * (x-xArray[0]) * yArray[1] / ( (xArray[1]-xArray[2]) * (xArray[1]-xArray[0]) ) ;
832 y += (x-xArray[0]) * (x-xArray[1]) * yArray[2] / ( (xArray[2]-xArray[0]) * (xArray[2]-xArray[1]) ) ;
833 } else { // Linear Interpolation = 1
834 y = yArray[0] + ( yArray[1]-yArray[0] ) * ( x-xArray[0] ) / ( xArray[1] - xArray[0] ) ;
835 }
836
837 return (y);
838
839}
840
841
0116859c 842
b1f0a2a5 843void AliTPCCorrection::Search( const Int_t n, const Double_t xArray[], const Double_t x, Int_t &low ) {
0116859c 844 //
845 // Search an ordered table by starting at the most recently used point
846 //
847
848 Long_t middle, high ;
849 Int_t ascend = 0, increment = 1 ;
850
851 if ( xArray[n-1] >= xArray[0] ) ascend = 1 ; // Ascending ordered table if true
852
853 if ( low < 0 || low > n-1 ) {
854 low = -1 ; high = n ;
855 } else { // Ordered Search phase
856 if ( (Int_t)( x >= xArray[low] ) == ascend ) {
857 if ( low == n-1 ) return ;
858 high = low + 1 ;
859 while ( (Int_t)( x >= xArray[high] ) == ascend ) {
860 low = high ;
861 increment *= 2 ;
862 high = low + increment ;
863 if ( high > n-1 ) { high = n ; break ; }
864 }
865 } else {
866 if ( low == 0 ) { low = -1 ; return ; }
867 high = low - 1 ;
868 while ( (Int_t)( x < xArray[low] ) == ascend ) {
869 high = low ;
870 increment *= 2 ;
871 if ( increment >= high ) { low = -1 ; break ; }
872 else low = high - increment ;
873 }
874 }
875 }
876
877 while ( (high-low) != 1 ) { // Binary Search Phase
878 middle = ( high + low ) / 2 ;
879 if ( (Int_t)( x >= xArray[middle] ) == ascend )
880 low = middle ;
881 else
882 high = middle ;
883 }
884
885 if ( x == xArray[n-1] ) low = n-2 ;
886 if ( x == xArray[0] ) low = 0 ;
887
888}
889
35ae345f 890void AliTPCCorrection::InitLookUpfulcrums() {
891 //
892 // Initialization of interpolation points - for main look up table
893 // (course grid in the middle, fine grid on the borders)
894 //
895
896 AliTPCROC * roc = AliTPCROC::Instance();
897 const Double_t rLow = TMath::Floor(roc->GetPadRowRadii(0,0))-1; // first padRow plus some margin
898
899 // fulcrums in R
900 fgkRList[0] = rLow;
901 for (Int_t i = 1; i<kNR; i++) {
902 fgkRList[i] = fgkRList[i-1] + 3.5; // 3.5 cm spacing
903 if (fgkRList[i]<90 ||fgkRList[i]>245)
904 fgkRList[i] = fgkRList[i-1] + 0.5; // 0.5 cm spacing
905 else if (fgkRList[i]<100 || fgkRList[i]>235)
906 fgkRList[i] = fgkRList[i-1] + 1.5; // 1.5 cm spacing
907 else if (fgkRList[i]<120 || fgkRList[i]>225)
908 fgkRList[i] = fgkRList[i-1] + 2.5; // 2.5 cm spacing
909 }
910
911 // fulcrums in Z
912 fgkZList[0] = -249.5;
913 fgkZList[kNZ-1] = 249.5;
914 for (Int_t j = 1; j<kNZ/2; j++) {
915 fgkZList[j] = fgkZList[j-1];
916 if (TMath::Abs(fgkZList[j])< 0.15)
917 fgkZList[j] = fgkZList[j-1] + 0.09; // 0.09 cm spacing
918 else if(TMath::Abs(fgkZList[j])< 0.6)
919 fgkZList[j] = fgkZList[j-1] + 0.4; // 0.4 cm spacing
920 else if (TMath::Abs(fgkZList[j])< 2.5 || TMath::Abs(fgkZList[j])>248)
921 fgkZList[j] = fgkZList[j-1] + 0.5; // 0.5 cm spacing
922 else if (TMath::Abs(fgkZList[j])<10 || TMath::Abs(fgkZList[j])>235)
923 fgkZList[j] = fgkZList[j-1] + 1.5; // 1.5 cm spacing
924 else if (TMath::Abs(fgkZList[j])<25 || TMath::Abs(fgkZList[j])>225)
925 fgkZList[j] = fgkZList[j-1] + 2.5; // 2.5 cm spacing
926 else
927 fgkZList[j] = fgkZList[j-1] + 4; // 4 cm spacing
928
929 fgkZList[kNZ-j-1] = -fgkZList[j];
930 }
931
932 // fulcrums in phi
933 for (Int_t k = 0; k<kNPhi; k++)
934 fgkPhiList[k] = TMath::TwoPi()*k/(kNPhi-1);
935
936
937}
938
939
c9cbd2f2 940void AliTPCCorrection::PoissonRelaxation2D(TMatrixD &arrayV, TMatrixD &chargeDensity,
941 TMatrixD &arrayErOverEz, TMatrixD &arrayDeltaEz,
942 const Int_t rows, const Int_t columns, const Int_t iterations,
943 const Bool_t rocDisplacement ) {
1b923461 944 //
945 // Solve Poisson's Equation by Relaxation Technique in 2D (assuming cylindrical symmetry)
946 //
947 // Solve Poissons equation in a cylindrical coordinate system. The arrayV matrix must be filled with the
948 // boundary conditions on the first and last rows, and the first and last columns. The remainder of the
949 // array can be blank or contain a preliminary guess at the solution. The Charge density matrix contains
950 // the enclosed spacecharge density at each point. The charge density matrix can be full of zero's if
951 // you wish to solve Laplaces equation however it should not contain random numbers or you will get
952 // random numbers back as a solution.
953 // Poisson's equation is solved by iteratively relaxing the matrix to the final solution. In order to
954 // speed up the convergence to the best solution, this algorithm does a binary expansion of the solution
955 // space. First it solves the problem on a very sparse grid by skipping rows and columns in the original
956 // matrix. Then it doubles the number of points and solves the problem again. Then it doubles the
957 // number of points and solves the problem again. This happens several times until the maximum number
958 // of points has been included in the array.
959 //
960 // NOTE: In order for this algorithmto work, the number of rows and columns must be a power of 2 plus one.
961 // So rows == 2**M + 1 and columns == 2**N + 1. The number of rows and columns can be different.
962 //
c9cbd2f2 963 // NOTE: rocDisplacement is used to include (or ignore) the ROC misalignment in the dz calculation
964 //
1b923461 965 // Original code by Jim Thomas (STAR TPC Collaboration)
966 //
967
968 Double_t ezField = (fgkCathodeV-fgkGG)/fgkTPCZ0; // = ALICE Electric Field (V/cm) Magnitude ~ -400 V/cm;
969
970 const Float_t gridSizeR = (fgkOFCRadius-fgkIFCRadius) / (rows-1) ;
971 const Float_t gridSizeZ = fgkTPCZ0 / (columns-1) ;
972 const Float_t ratio = gridSizeR*gridSizeR / (gridSizeZ*gridSizeZ) ;
973
974 TMatrixD arrayEr(rows,columns) ;
975 TMatrixD arrayEz(rows,columns) ;
976
977 //Check that number of rows and columns is suitable for a binary expansion
978
979 if ( !IsPowerOfTwo(rows-1) ) {
980 AliError("PoissonRelaxation - Error in the number of rows. Must be 2**M - 1");
981 return;
982 }
983 if ( !IsPowerOfTwo(columns-1) ) {
984 AliError("PoissonRelaxation - Error in the number of columns. Must be 2**N - 1");
985 return;
986 }
987
988 // Solve Poisson's equation in cylindrical coordinates by relaxation technique
989 // Allow for different size grid spacing in R and Z directions
990 // Use a binary expansion of the size of the matrix to speed up the solution of the problem
991
992 Int_t iOne = (rows-1)/4 ;
993 Int_t jOne = (columns-1)/4 ;
994 // Solve for N in 2**N, add one.
995 Int_t loops = 1 + (int) ( 0.5 + TMath::Log2( (double) TMath::Max(iOne,jOne) ) ) ;
996
997 for ( Int_t count = 0 ; count < loops ; count++ ) {
998 // Loop while the matrix expands & the resolution increases.
999
1000 Float_t tempGridSizeR = gridSizeR * iOne ;
1001 Float_t tempRatio = ratio * iOne * iOne / ( jOne * jOne ) ;
1002 Float_t tempFourth = 1.0 / (2.0 + 2.0*tempRatio) ;
1003
1004 // Do this the standard C++ way to avoid gcc extensions for Float_t coef1[rows]
1005 std::vector<float> coef1(rows) ;
1006 std::vector<float> coef2(rows) ;
1007
1008 for ( Int_t i = iOne ; i < rows-1 ; i+=iOne ) {
1009 Float_t radius = fgkIFCRadius + i*gridSizeR ;
1010 coef1[i] = 1.0 + tempGridSizeR/(2*radius);
1011 coef2[i] = 1.0 - tempGridSizeR/(2*radius);
1012 }
1013
1014 TMatrixD sumChargeDensity(rows,columns) ;
1015
1016 for ( Int_t i = iOne ; i < rows-1 ; i += iOne ) {
1017 Float_t radius = fgkIFCRadius + iOne*gridSizeR ;
1018 for ( Int_t j = jOne ; j < columns-1 ; j += jOne ) {
1019 if ( iOne == 1 && jOne == 1 ) sumChargeDensity(i,j) = chargeDensity(i,j) ;
1020 else {
1021 // Add up all enclosed charge density contributions within 1/2 unit in all directions
1022 Float_t weight = 0.0 ;
1023 Float_t sum = 0.0 ;
1024 sumChargeDensity(i,j) = 0.0 ;
1025 for ( Int_t ii = i-iOne/2 ; ii <= i+iOne/2 ; ii++ ) {
1026 for ( Int_t jj = j-jOne/2 ; jj <= j+jOne/2 ; jj++ ) {
1027 if ( ii == i-iOne/2 || ii == i+iOne/2 || jj == j-jOne/2 || jj == j+jOne/2 ) weight = 0.5 ;
1028 else
1029 weight = 1.0 ;
1030 // Note that this is cylindrical geometry
1031 sumChargeDensity(i,j) += chargeDensity(ii,jj)*weight*radius ;
1032 sum += weight*radius ;
1033 }
1034 }
1035 sumChargeDensity(i,j) /= sum ;
1036 }
1037 sumChargeDensity(i,j) *= tempGridSizeR*tempGridSizeR; // just saving a step later on
1038 }
1039 }
1040
1041 for ( Int_t k = 1 ; k <= iterations; k++ ) {
1042 // Solve Poisson's Equation
1043 // Over-relaxation index, must be >= 1 but < 2. Arrange for it to evolve from 2 => 1
1044 // as interations increase.
1045 Float_t overRelax = 1.0 + TMath::Sqrt( TMath::Cos( (k*TMath::PiOver2())/iterations ) ) ;
1046 Float_t overRelaxM1 = overRelax - 1.0 ;
1047 Float_t overRelaxtempFourth, overRelaxcoef5 ;
1048 overRelaxtempFourth = overRelax * tempFourth ;
1049 overRelaxcoef5 = overRelaxM1 / overRelaxtempFourth ;
1050
1051 for ( Int_t i = iOne ; i < rows-1 ; i += iOne ) {
1052 for ( Int_t j = jOne ; j < columns-1 ; j += jOne ) {
1053
1054 arrayV(i,j) = ( coef2[i] * arrayV(i-iOne,j)
1055 + tempRatio * ( arrayV(i,j-jOne) + arrayV(i,j+jOne) )
1056 - overRelaxcoef5 * arrayV(i,j)
1057 + coef1[i] * arrayV(i+iOne,j)
1058 + sumChargeDensity(i,j)
1059 ) * overRelaxtempFourth;
1060 }
1061 }
1062
1063 if ( k == iterations ) {
1064 // After full solution is achieved, copy low resolution solution into higher res array
1065 for ( Int_t i = iOne ; i < rows-1 ; i += iOne ) {
1066 for ( Int_t j = jOne ; j < columns-1 ; j += jOne ) {
1067
1068 if ( iOne > 1 ) {
1069 arrayV(i+iOne/2,j) = ( arrayV(i+iOne,j) + arrayV(i,j) ) / 2 ;
1070 if ( i == iOne ) arrayV(i-iOne/2,j) = ( arrayV(0,j) + arrayV(iOne,j) ) / 2 ;
1071 }
1072 if ( jOne > 1 ) {
1073 arrayV(i,j+jOne/2) = ( arrayV(i,j+jOne) + arrayV(i,j) ) / 2 ;
1074 if ( j == jOne ) arrayV(i,j-jOne/2) = ( arrayV(i,0) + arrayV(i,jOne) ) / 2 ;
1075 }
1076 if ( iOne > 1 && jOne > 1 ) {
1077 arrayV(i+iOne/2,j+jOne/2) = ( arrayV(i+iOne,j+jOne) + arrayV(i,j) ) / 2 ;
1078 if ( i == iOne ) arrayV(i-iOne/2,j-jOne/2) = ( arrayV(0,j-jOne) + arrayV(iOne,j) ) / 2 ;
1079 if ( j == jOne ) arrayV(i-iOne/2,j-jOne/2) = ( arrayV(i-iOne,0) + arrayV(i,jOne) ) / 2 ;
1080 // Note that this leaves a point at the upper left and lower right corners uninitialized.
1081 // -> Not a big deal.
1082 }
1083
1084 }
1085 }
1086 }
1087
1088 }
1089
1090 iOne = iOne / 2 ; if ( iOne < 1 ) iOne = 1 ;
1091 jOne = jOne / 2 ; if ( jOne < 1 ) jOne = 1 ;
1092
c9cbd2f2 1093 sumChargeDensity.Clear();
1b923461 1094 }
1095
1096 // Differentiate V(r) and solve for E(r) using special equations for the first and last rows
1097 for ( Int_t j = 0 ; j < columns ; j++ ) {
1098 for ( Int_t i = 1 ; i < rows-1 ; i++ ) arrayEr(i,j) = -1 * ( arrayV(i+1,j) - arrayV(i-1,j) ) / (2*gridSizeR) ;
1099 arrayEr(0,j) = -1 * ( -0.5*arrayV(2,j) + 2.0*arrayV(1,j) - 1.5*arrayV(0,j) ) / gridSizeR ;
1100 arrayEr(rows-1,j) = -1 * ( 1.5*arrayV(rows-1,j) - 2.0*arrayV(rows-2,j) + 0.5*arrayV(rows-3,j) ) / gridSizeR ;
1101 }
1102
1103 // Differentiate V(z) and solve for E(z) using special equations for the first and last columns
1104 for ( Int_t i = 0 ; i < rows ; i++) {
1105 for ( Int_t j = 1 ; j < columns-1 ; j++ ) arrayEz(i,j) = -1 * ( arrayV(i,j+1) - arrayV(i,j-1) ) / (2*gridSizeZ) ;
1106 arrayEz(i,0) = -1 * ( -0.5*arrayV(i,2) + 2.0*arrayV(i,1) - 1.5*arrayV(i,0) ) / gridSizeZ ;
1107 arrayEz(i,columns-1) = -1 * ( 1.5*arrayV(i,columns-1) - 2.0*arrayV(i,columns-2) + 0.5*arrayV(i,columns-3) ) / gridSizeZ ;
1108 }
1109
1110 for ( Int_t i = 0 ; i < rows ; i++) {
1111 // Note: go back and compare to old version of this code. See notes below.
1112 // JT Test ... attempt to divide by real Ez not Ez to first order
1113 for ( Int_t j = 0 ; j < columns ; j++ ) {
1114 arrayEz(i,j) += ezField;
1115 // This adds back the overall Z gradient of the field (main E field component)
1116 }
1117 // Warning: (-=) assumes you are using an error potetial without the overall Field included
1118 }
1119
1120 // Integrate Er/Ez from Z to zero
1121 for ( Int_t j = 0 ; j < columns ; j++ ) {
1122 for ( Int_t i = 0 ; i < rows ; i++ ) {
c9cbd2f2 1123
1b923461 1124 Int_t index = 1 ; // Simpsons rule if N=odd. If N!=odd then add extra point by trapezoidal rule.
1125 arrayErOverEz(i,j) = 0.0 ;
c9cbd2f2 1126 arrayDeltaEz(i,j) = 0.0 ;
1127
1b923461 1128 for ( Int_t k = j ; k < columns ; k++ ) {
1129 arrayErOverEz(i,j) += index*(gridSizeZ/3.0)*arrayEr(i,k)/arrayEz(i,k) ;
c9cbd2f2 1130 arrayDeltaEz(i,j) += index*(gridSizeZ/3.0)*(arrayEz(i,k)-ezField) ;
1b923461 1131 if ( index != 4 ) index = 4; else index = 2 ;
1132 }
c9cbd2f2 1133 if ( index == 4 ) {
1134 arrayErOverEz(i,j) -= (gridSizeZ/3.0)*arrayEr(i,columns-1)/arrayEz(i,columns-1) ;
1135 arrayDeltaEz(i,j) -= (gridSizeZ/3.0)*(arrayEz(i,columns-1)-ezField) ;
1136 }
1137 if ( index == 2 ) {
1138 arrayErOverEz(i,j) += (gridSizeZ/3.0) * ( 0.5*arrayEr(i,columns-2)/arrayEz(i,columns-2)
1139 -2.5*arrayEr(i,columns-1)/arrayEz(i,columns-1));
1140 arrayDeltaEz(i,j) += (gridSizeZ/3.0) * ( 0.5*(arrayEz(i,columns-2)-ezField)
1141 -2.5*(arrayEz(i,columns-1)-ezField));
1142 }
1143 if ( j == columns-2 ) {
1144 arrayErOverEz(i,j) = (gridSizeZ/3.0) * ( 1.5*arrayEr(i,columns-2)/arrayEz(i,columns-2)
1145 +1.5*arrayEr(i,columns-1)/arrayEz(i,columns-1) ) ;
1146 arrayDeltaEz(i,j) = (gridSizeZ/3.0) * ( 1.5*(arrayEz(i,columns-2)-ezField)
1147 +1.5*(arrayEz(i,columns-1)-ezField) ) ;
1148 }
1149 if ( j == columns-1 ) {
1150 arrayErOverEz(i,j) = 0.0 ;
1151 arrayDeltaEz(i,j) = 0.0 ;
1152 }
1b923461 1153 }
1154 }
1155
c9cbd2f2 1156 // calculate z distortion from the integrated Delta Ez residuals
1157 // and include the aquivalence (Volt to cm) of the ROC shift !!
1158
1159 for ( Int_t j = 0 ; j < columns ; j++ ) {
1160 for ( Int_t i = 0 ; i < rows ; i++ ) {
1161
1162 // Scale the Ez distortions with the drift velocity pertubation -> delivers cm
1163 arrayDeltaEz(i,j) = arrayDeltaEz(i,j)*fgkdvdE;
1164
1165 // ROC Potential in cm aquivalent
1166 Double_t dzROCShift = arrayV(i, columns -1)/ezField;
1167 if ( rocDisplacement ) arrayDeltaEz(i,j) = arrayDeltaEz(i,j) + dzROCShift; // add the ROC misaligment
1168
1169 }
1170 }
1171
1172 arrayEr.Clear();
1173 arrayEz.Clear();
1174
1b923461 1175}
1176
c9cbd2f2 1177void AliTPCCorrection::PoissonRelaxation3D( TMatrixD**arrayofArrayV, TMatrixD**arrayofChargeDensities,
1178 TMatrixD**arrayofEroverEz, TMatrixD**arrayofEPhioverEz, TMatrixD**arrayofDeltaEz,
1179 const Int_t rows, const Int_t columns, const Int_t phislices,
1180 const Float_t deltaphi, const Int_t iterations, const Int_t symmetry,
1181 Bool_t rocDisplacement ) {
1182 //
1183 // 3D - Solve Poisson's Equation in 3D by Relaxation Technique
1184 //
1185 // NOTE: In order for this algorith to work, the number of rows and columns must be a power of 2 plus one.
1186 // The number of rows and COLUMNS can be different.
1187 //
1188 // ROWS == 2**M + 1
1189 // COLUMNS == 2**N + 1
1190 // PHISLICES == Arbitrary but greater than 3
1191 //
1192 // DeltaPhi in Radians
1193 //
1194 // SYMMETRY = 0 if no phi symmetries, and no phi boundary conditions
1195 // = 1 if we have reflection symmetry at the boundaries (eg. sector symmetry or half sector symmetries).
1196 //
1197 // NOTE: rocDisplacement is used to include (or ignore) the ROC misalignment in the dz calculation
1198
1199 const Double_t ezField = (fgkCathodeV-fgkGG)/fgkTPCZ0; // = ALICE Electric Field (V/cm) Magnitude ~ -400 V/cm;
1200
1201 const Float_t gridSizeR = (fgkOFCRadius-fgkIFCRadius) / (rows-1) ;
1202 const Float_t gridSizePhi = deltaphi ;
1203 const Float_t gridSizeZ = fgkTPCZ0 / (columns-1) ;
1204 const Float_t ratioPhi = gridSizeR*gridSizeR / (gridSizePhi*gridSizePhi) ;
1205 const Float_t ratioZ = gridSizeR*gridSizeR / (gridSizeZ*gridSizeZ) ;
1206
1207 TMatrixD arrayE(rows,columns) ;
1208
1209 // Check that the number of rows and columns is suitable for a binary expansion
1210 if ( !IsPowerOfTwo((rows-1)) ) {
1211 AliError("Poisson3DRelaxation - Error in the number of rows. Must be 2**M - 1");
1212 return; }
1213 if ( !IsPowerOfTwo((columns-1)) ) {
1214 AliError("Poisson3DRelaxation - Error in the number of columns. Must be 2**N - 1");
1215 return; }
1216 if ( phislices <= 3 ) {
1217 AliError("Poisson3DRelaxation - Error in the number of phislices. Must be larger than 3");
1218 return; }
1219 if ( phislices > 1000 ) {
1220 AliError("Poisson3D phislices > 1000 is not allowed (nor wise) ");
1221 return; }
1222
1223 // Solve Poisson's equation in cylindrical coordinates by relaxation technique
1224 // Allow for different size grid spacing in R and Z directions
1225 // Use a binary expansion of the matrix to speed up the solution of the problem
1226
1227 Int_t loops, mplus, mminus, signplus, signminus ;
1228 Int_t ione = (rows-1)/4 ;
1229 Int_t jone = (columns-1)/4 ;
1230 loops = TMath::Max(ione, jone) ; // Calculate the number of loops for the binary expansion
1231 loops = 1 + (int) ( 0.5 + TMath::Log2((double)loops) ) ; // Solve for N in 2**N
1232
1233 TMatrixD* arrayofSumChargeDensities[1000] ; // Create temporary arrays to store low resolution charge arrays
1234
1235 for ( Int_t i = 0 ; i < phislices ; i++ ) { arrayofSumChargeDensities[i] = new TMatrixD(rows,columns) ; }
1236
1237 for ( Int_t count = 0 ; count < loops ; count++ ) { // START the master loop and do the binary expansion
1238
1239 Float_t tempgridSizeR = gridSizeR * ione ;
1240 Float_t tempratioPhi = ratioPhi * ione * ione ; // Used tobe divided by ( m_one * m_one ) when m_one was != 1
1241 Float_t tempratioZ = ratioZ * ione * ione / ( jone * jone ) ;
1242
1243 std::vector<float> coef1(rows) ; // Do this the standard C++ way to avoid gcc extensions for Float_t coef1[rows]
1244 std::vector<float> coef2(rows) ; // Do this the standard C++ way to avoid gcc extensions for Float_t coef1[rows]
1245 std::vector<float> coef3(rows) ; // Do this the standard C++ way to avoid gcc extensions for Float_t coef1[rows]
1246 std::vector<float> coef4(rows) ; // Do this the standard C++ way to avoid gcc extensions for Float_t coef1[rows]
1247
1248 for ( Int_t i = ione ; i < rows-1 ; i+=ione ) {
1249 Float_t radius = fgkIFCRadius + i*gridSizeR ;
1250 coef1[i] = 1.0 + tempgridSizeR/(2*radius);
1251 coef2[i] = 1.0 - tempgridSizeR/(2*radius);
1252 coef3[i] = tempratioPhi/(radius*radius);
1253 coef4[i] = 0.5 / (1.0 + tempratioZ + coef3[i]);
1254 }
1255
1256 for ( Int_t m = 0 ; m < phislices ; m++ ) {
1257 TMatrixD &chargeDensity = *arrayofChargeDensities[m] ;
1258 TMatrixD &sumChargeDensity = *arrayofSumChargeDensities[m] ;
1259 for ( Int_t i = ione ; i < rows-1 ; i += ione ) {
1260 Float_t radius = fgkIFCRadius + i*gridSizeR ;
1261 for ( Int_t j = jone ; j < columns-1 ; j += jone ) {
1262 if ( ione == 1 && jone == 1 ) sumChargeDensity(i,j) = chargeDensity(i,j) ;
1263 else { // Add up all enclosed charge density contributions within 1/2 unit in all directions
1264 Float_t weight = 0.0 ;
1265 Float_t sum = 0.0 ;
1266 sumChargeDensity(i,j) = 0.0 ;
1267 for ( Int_t ii = i-ione/2 ; ii <= i+ione/2 ; ii++ ) {
1268 for ( Int_t jj = j-jone/2 ; jj <= j+jone/2 ; jj++ ) {
1269 if ( ii == i-ione/2 || ii == i+ione/2 || jj == j-jone/2 || jj == j+jone/2 ) weight = 0.5 ;
1270 else
1271 weight = 1.0 ;
1272 sumChargeDensity(i,j) += chargeDensity(ii,jj)*weight*radius ;
1273 sum += weight*radius ;
1274 }
1275 }
1276 sumChargeDensity(i,j) /= sum ;
1277 }
1278 sumChargeDensity(i,j) *= tempgridSizeR*tempgridSizeR; // just saving a step later on
1279 }
1280 }
1281 }
1282
1283 for ( Int_t k = 1 ; k <= iterations; k++ ) {
1284
1285 // over-relaxation index, >= 1 but < 2
1286 Float_t overRelax = 1.0 + TMath::Sqrt( TMath::Cos( (k*TMath::PiOver2())/iterations ) ) ;
1287 Float_t overRelaxM1 = overRelax - 1.0 ;
1288
1289 std::vector<float> overRelaxcoef4(rows) ; // Do this the standard C++ way to avoid gcc extensions
1290 std::vector<float> overRelaxcoef5(rows) ; // Do this the standard C++ way to avoid gcc extensions
1291
1292 for ( Int_t i = ione ; i < rows-1 ; i+=ione ) {
1293 overRelaxcoef4[i] = overRelax * coef4[i] ;
1294 overRelaxcoef5[i] = overRelaxM1 / overRelaxcoef4[i] ;
1295 }
1296
1297 for ( Int_t m = 0 ; m < phislices ; m++ ) {
1298
1299 mplus = m + 1; signplus = 1 ;
1300 mminus = m - 1 ; signminus = 1 ;
1301 if (symmetry==1) { // Reflection symmetry in phi (e.g. symmetry at sector boundaries, or half sectors, etc.)
1302 if ( mplus > phislices-1 ) mplus = phislices - 2 ;
1303 if ( mminus < 0 ) mminus = 1 ;
1304 }
1305 else if (symmetry==-1) { // Anti-symmetry in phi
1306 if ( mplus > phislices-1 ) { mplus = phislices - 2 ; signplus = -1 ; }
1307 if ( mminus < 0 ) { mminus = 1 ; signminus = -1 ; }
1308 }
1309 else { // No Symmetries in phi, no boundaries, the calculation is continuous across all phi
1310 if ( mplus > phislices-1 ) mplus = m + 1 - phislices ;
1311 if ( mminus < 0 ) mminus = m - 1 + phislices ;
1312 }
1313 TMatrixD& arrayV = *arrayofArrayV[m] ;
1314 TMatrixD& arrayVP = *arrayofArrayV[mplus] ;
1315 TMatrixD& arrayVM = *arrayofArrayV[mminus] ;
1316 TMatrixD& sumChargeDensity = *arrayofSumChargeDensities[m] ;
1317
1318 for ( Int_t i = ione ; i < rows-1 ; i+=ione ) {
1319 for ( Int_t j = jone ; j < columns-1 ; j+=jone ) {
1320
1321 arrayV(i,j) = ( coef2[i] * arrayV(i-ione,j)
1322 + tempratioZ * ( arrayV(i,j-jone) + arrayV(i,j+jone) )
1323 - overRelaxcoef5[i] * arrayV(i,j)
1324 + coef1[i] * arrayV(i+ione,j)
1325 + coef3[i] * ( signplus*arrayVP(i,j) + signminus*arrayVM(i,j) )
1326 + sumChargeDensity(i,j)
1327 ) * overRelaxcoef4[i] ;
1328 // Note: over-relax the solution at each step. This speeds up the convergance.
1329
1330 }
1331 }
1332
1333 if ( k == iterations ) { // After full solution is achieved, copy low resolution solution into higher res array
1334 for ( Int_t i = ione ; i < rows-1 ; i+=ione ) {
1335 for ( Int_t j = jone ; j < columns-1 ; j+=jone ) {
1336
1337 if ( ione > 1 ) {
1338 arrayV(i+ione/2,j) = ( arrayV(i+ione,j) + arrayV(i,j) ) / 2 ;
1339 if ( i == ione ) arrayV(i-ione/2,j) = ( arrayV(0,j) + arrayV(ione,j) ) / 2 ;
1340 }
1341 if ( jone > 1 ) {
1342 arrayV(i,j+jone/2) = ( arrayV(i,j+jone) + arrayV(i,j) ) / 2 ;
1343 if ( j == jone ) arrayV(i,j-jone/2) = ( arrayV(i,0) + arrayV(i,jone) ) / 2 ;
1344 }
1345 if ( ione > 1 && jone > 1 ) {
1346 arrayV(i+ione/2,j+jone/2) = ( arrayV(i+ione,j+jone) + arrayV(i,j) ) / 2 ;
1347 if ( i == ione ) arrayV(i-ione/2,j-jone/2) = ( arrayV(0,j-jone) + arrayV(ione,j) ) / 2 ;
1348 if ( j == jone ) arrayV(i-ione/2,j-jone/2) = ( arrayV(i-ione,0) + arrayV(i,jone) ) / 2 ;
1349 // Note that this leaves a point at the upper left and lower right corners uninitialized. Not a big deal.
1350 }
1351 }
1352 }
1353 }
1354
1355 }
1356 }
1357
1358 ione = ione / 2 ; if ( ione < 1 ) ione = 1 ;
1359 jone = jone / 2 ; if ( jone < 1 ) jone = 1 ;
1360
1361 }
1362
1363 //Differentiate V(r) and solve for E(r) using special equations for the first and last row
1364 //Integrate E(r)/E(z) from point of origin to pad plane
1365
1366 for ( Int_t m = 0 ; m < phislices ; m++ ) {
1367 TMatrixD& arrayV = *arrayofArrayV[m] ;
1368 TMatrixD& eroverEz = *arrayofEroverEz[m] ;
1369
1370 for ( Int_t j = columns-1 ; j >= 0 ; j-- ) { // Count backwards to facilitate integration over Z
1371
1372 // Differentiate in R
1373 for ( Int_t i = 1 ; i < rows-1 ; i++ ) arrayE(i,j) = -1 * ( arrayV(i+1,j) - arrayV(i-1,j) ) / (2*gridSizeR) ;
1374 arrayE(0,j) = -1 * ( -0.5*arrayV(2,j) + 2.0*arrayV(1,j) - 1.5*arrayV(0,j) ) / gridSizeR ;
1375 arrayE(rows-1,j) = -1 * ( 1.5*arrayV(rows-1,j) - 2.0*arrayV(rows-2,j) + 0.5*arrayV(rows-3,j) ) / gridSizeR ;
1376 // Integrate over Z
1377 for ( Int_t i = 0 ; i < rows ; i++ ) {
1378 Int_t index = 1 ; // Simpsons rule if N=odd. If N!=odd then add extra point by trapezoidal rule.
1379 eroverEz(i,j) = 0.0 ;
1380 for ( Int_t k = j ; k < columns ; k++ ) {
1381
1382 eroverEz(i,j) += index*(gridSizeZ/3.0)*arrayE(i,k)/(-1*ezField) ;
1383 if ( index != 4 ) index = 4; else index = 2 ;
1384 }
1385 if ( index == 4 ) eroverEz(i,j) -= (gridSizeZ/3.0)*arrayE(i,columns-1)/ (-1*ezField) ;
1386 if ( index == 2 ) eroverEz(i,j) +=
1387 (gridSizeZ/3.0)*(0.5*arrayE(i,columns-2)-2.5*arrayE(i,columns-1))/(-1*ezField) ;
1388 if ( j == columns-2 ) eroverEz(i,j) =
1389 (gridSizeZ/3.0)*(1.5*arrayE(i,columns-2)+1.5*arrayE(i,columns-1))/(-1*ezField) ;
1390 if ( j == columns-1 ) eroverEz(i,j) = 0.0 ;
1391 }
1392 }
1393 // if ( m == 0 ) { TCanvas* c1 = new TCanvas("erOverEz","erOverEz",50,50,840,600) ; c1 -> cd() ;
1394 // eroverEz.Draw("surf") ; } // JT test
1395 }
1396
1397 //Differentiate V(r) and solve for E(phi)
1398 //Integrate E(phi)/E(z) from point of origin to pad plane
1399
1400 for ( Int_t m = 0 ; m < phislices ; m++ ) {
1401
1402 mplus = m + 1; signplus = 1 ;
1403 mminus = m - 1 ; signminus = 1 ;
1404 if (symmetry==1) { // Reflection symmetry in phi (e.g. symmetry at sector boundaries, or half sectors, etc.)
1405 if ( mplus > phislices-1 ) mplus = phislices - 2 ;
1406 if ( mminus < 0 ) mminus = 1 ;
1407 }
1408 else if (symmetry==-1) { // Anti-symmetry in phi
1409 if ( mplus > phislices-1 ) { mplus = phislices - 2 ; signplus = -1 ; }
1410 if ( mminus < 0 ) { mminus = 1 ; signminus = -1 ; }
1411 }
1412 else { // No Symmetries in phi, no boundaries, the calculations is continuous across all phi
1413 if ( mplus > phislices-1 ) mplus = m + 1 - phislices ;
1414 if ( mminus < 0 ) mminus = m - 1 + phislices ;
1415 }
1416 TMatrixD &arrayVP = *arrayofArrayV[mplus] ;
1417 TMatrixD &arrayVM = *arrayofArrayV[mminus] ;
1418 TMatrixD &ePhioverEz = *arrayofEPhioverEz[m] ;
1419 for ( Int_t j = columns-1 ; j >= 0 ; j-- ) { // Count backwards to facilitate integration over Z
1420 // Differentiate in Phi
1421 for ( Int_t i = 0 ; i < rows ; i++ ) {
1422 Float_t radius = fgkIFCRadius + i*gridSizeR ;
1423 arrayE(i,j) = -1 * (signplus * arrayVP(i,j) - signminus * arrayVM(i,j) ) / (2*radius*gridSizePhi) ;
1424 }
1425 // Integrate over Z
1426 for ( Int_t i = 0 ; i < rows ; i++ ) {
1427 Int_t index = 1 ; // Simpsons rule if N=odd. If N!=odd then add extra point by trapezoidal rule.
1428 ePhioverEz(i,j) = 0.0 ;
1429 for ( Int_t k = j ; k < columns ; k++ ) {
1430
1431 ePhioverEz(i,j) += index*(gridSizeZ/3.0)*arrayE(i,k)/(-1*ezField) ;
1432 if ( index != 4 ) index = 4; else index = 2 ;
1433 }
1434 if ( index == 4 ) ePhioverEz(i,j) -= (gridSizeZ/3.0)*arrayE(i,columns-1)/ (-1*ezField) ;
1435 if ( index == 2 ) ePhioverEz(i,j) +=
1436 (gridSizeZ/3.0)*(0.5*arrayE(i,columns-2)-2.5*arrayE(i,columns-1))/(-1*ezField) ;
1437 if ( j == columns-2 ) ePhioverEz(i,j) =
1438 (gridSizeZ/3.0)*(1.5*arrayE(i,columns-2)+1.5*arrayE(i,columns-1))/(-1*ezField) ;
1439 if ( j == columns-1 ) ePhioverEz(i,j) = 0.0 ;
1440 }
1441 }
1442 // if ( m == 5 ) { TCanvas* c2 = new TCanvas("arrayE","arrayE",50,50,840,600) ; c2 -> cd() ;
1443 // arrayE.Draw("surf") ; } // JT test
1444 }
1445
1446
1447 // Differentiate V(r) and solve for E(z) using special equations for the first and last row
1448 // Integrate (E(z)-Ezstd) from point of origin to pad plane
1449
1450 for ( Int_t m = 0 ; m < phislices ; m++ ) {
1451 TMatrixD& arrayV = *arrayofArrayV[m] ;
1452 TMatrixD& deltaEz = *arrayofDeltaEz[m] ;
1453
1454 // Differentiate V(z) and solve for E(z) using special equations for the first and last columns
1455 for ( Int_t i = 0 ; i < rows ; i++) {
1456 for ( Int_t j = 1 ; j < columns-1 ; j++ ) arrayE(i,j) = -1 * ( arrayV(i,j+1) - arrayV(i,j-1) ) / (2*gridSizeZ) ;
1457 arrayE(i,0) = -1 * ( -0.5*arrayV(i,2) + 2.0*arrayV(i,1) - 1.5*arrayV(i,0) ) / gridSizeZ ;
1458 arrayE(i,columns-1) = -1 * ( 1.5*arrayV(i,columns-1) - 2.0*arrayV(i,columns-2) + 0.5*arrayV(i,columns-3) ) / gridSizeZ ;
1459 }
1460
1461 for ( Int_t j = columns-1 ; j >= 0 ; j-- ) { // Count backwards to facilitate integration over Z
1462 // Integrate over Z
1463 for ( Int_t i = 0 ; i < rows ; i++ ) {
1464 Int_t index = 1 ; // Simpsons rule if N=odd. If N!=odd then add extra point by trapezoidal rule.
1465 deltaEz(i,j) = 0.0 ;
1466 for ( Int_t k = j ; k < columns ; k++ ) {
1467 deltaEz(i,j) += index*(gridSizeZ/3.0)*arrayE(i,k) ;
1468 if ( index != 4 ) index = 4; else index = 2 ;
1469 }
1470 if ( index == 4 ) deltaEz(i,j) -= (gridSizeZ/3.0)*arrayE(i,columns-1) ;
1471 if ( index == 2 ) deltaEz(i,j) +=
1472 (gridSizeZ/3.0)*(0.5*arrayE(i,columns-2)-2.5*arrayE(i,columns-1)) ;
1473 if ( j == columns-2 ) deltaEz(i,j) =
1474 (gridSizeZ/3.0)*(1.5*arrayE(i,columns-2)+1.5*arrayE(i,columns-1)) ;
1475 if ( j == columns-1 ) deltaEz(i,j) = 0.0 ;
1476 }
1477 }
1478 // if ( m == 0 ) { TCanvas* c1 = new TCanvas("erOverEz","erOverEz",50,50,840,600) ; c1 -> cd() ;
1479 // eroverEz.Draw("surf") ; } // JT test
1480
1481 // calculate z distortion from the integrated Delta Ez residuals
1482 // and include the aquivalence (Volt to cm) of the ROC shift !!
1483
1484 for ( Int_t j = 0 ; j < columns ; j++ ) {
1485 for ( Int_t i = 0 ; i < rows ; i++ ) {
1486
1487 // Scale the Ez distortions with the drift velocity pertubation -> delivers cm
1488 deltaEz(i,j) = deltaEz(i,j)*fgkdvdE;
1489
1490 // ROC Potential in cm aquivalent
1491 Double_t dzROCShift = arrayV(i, columns -1)/ezField;
1492 if ( rocDisplacement ) deltaEz(i,j) = deltaEz(i,j) + dzROCShift; // add the ROC misaligment
1493
1494 }
1495 }
1496
1497 } // end loop over phi
1498
1499
1500
1501 for ( Int_t k = 0 ; k < phislices ; k++ )
1502 {
1503 arrayofSumChargeDensities[k]->Delete() ;
1504 }
1505
1506
1507
1508 arrayE.Clear();
1509}
1b923461 1510
1511
710bda39 1512Int_t AliTPCCorrection::IsPowerOfTwo(Int_t i) const {
1b923461 1513 //
1514 // Helperfunction: Check if integer is a power of 2
1515 //
1516 Int_t j = 0;
1517 while( i > 0 ) { j += (i&1) ; i = (i>>1) ; }
1518 if ( j == 1 ) return(1) ; // True
1519 return(0) ; // False
1520}
1521
cf5b0aa0 1522
b1f0a2a5 1523AliExternalTrackParam * AliTPCCorrection::FitDistortedTrack(AliExternalTrackParam & trackIn, Double_t refX, Int_t dir, TTreeSRedirector * const pcstream){
cf5b0aa0 1524 //
1525 // Fit the track parameters - without and with distortion
1526 // 1. Space points in the TPC are simulated along the trajectory
1527 // 2. Space points distorted
1528 // 3. Fits the non distorted and distroted track to the reference plane at refX
1529 // 4. For visualization and debugging purposes the space points and tracks can be stored in the tree - using the TTreeSRedirector functionality
1530 //
1531 // trackIn - input track parameters
1532 // refX - reference X to fit the track
1533 // dir - direction - out=1 or in=-1
1534 // pcstream - debug streamer to check the results
1535 //
cad404e1 1536 // see AliExternalTrackParam.h documentation:
1537 // track1.fP[0] - local y (rphi)
1538 // track1.fP[1] - z
1539 // track1.fP[2] - sinus of local inclination angle
1540 // track1.fP[3] - tangent of deep angle
1541 // track1.fP[4] - 1/pt
1b923461 1542
cf5b0aa0 1543 AliTPCROC * roc = AliTPCROC::Instance();
1544 const Int_t npoints0=roc->GetNRows(0)+roc->GetNRows(36);
1545 const Double_t kRTPC0 =roc->GetPadRowRadii(0,0);
1546 const Double_t kRTPC1 =roc->GetPadRowRadii(36,roc->GetNRows(36)-1);
cf5b0aa0 1547 const Double_t kMaxSnp = 0.85;
1548 const Double_t kSigmaY=0.1;
1549 const Double_t kSigmaZ=0.1;
ca58ed4e 1550 const Double_t kMaxR=500;
1551 const Double_t kMaxZ=500;
46e89793 1552
cfe2c39a 1553 const Double_t kMaxZ0=220;
1554 const Double_t kZcut=3;
cf5b0aa0 1555 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
ca58ed4e 1556 Int_t npoints1=0;
1557 Int_t npoints2=0;
cf5b0aa0 1558
be67055b 1559 AliExternalTrackParam track(trackIn); //
cf5b0aa0 1560 // generate points
1561 AliTrackPointArray pointArray0(npoints0);
1562 AliTrackPointArray pointArray1(npoints0);
1563 Double_t xyz[3];
cfe2c39a 1564 if (!AliTrackerBase::PropagateTrackTo(&track,kRTPC0,kMass,5,kTRUE,kMaxSnp)) return 0;
cf5b0aa0 1565 //
1566 // simulate the track
1567 Int_t npoints=0;
1568 Float_t covPoint[6]={0,0,0, kSigmaY*kSigmaY,0,kSigmaZ*kSigmaZ}; //covariance at the local frame
1569 for (Double_t radius=kRTPC0; radius<kRTPC1; radius++){
cfe2c39a 1570 if (!AliTrackerBase::PropagateTrackTo(&track,radius,kMass,5,kTRUE,kMaxSnp)) return 0;
cf5b0aa0 1571 track.GetXYZ(xyz);
cfe2c39a 1572 xyz[0]+=gRandom->Gaus(0,0.000005);
1573 xyz[1]+=gRandom->Gaus(0,0.000005);
1574 xyz[2]+=gRandom->Gaus(0,0.000005);
1575 if (TMath::Abs(track.GetZ())>kMaxZ0) continue;
46e89793 1576 if (TMath::Abs(track.GetX())<kRTPC0) continue;
1577 if (TMath::Abs(track.GetX())>kRTPC1) continue;
cf5b0aa0 1578 AliTrackPoint pIn0; // space point
1579 AliTrackPoint pIn1;
ffab0c37 1580 Int_t sector= (xyz[2]>0)? 0:18;
cf5b0aa0 1581 pointArray0.GetPoint(pIn0,npoints);
1582 pointArray1.GetPoint(pIn1,npoints);
1583 Double_t alpha = TMath::ATan2(xyz[1],xyz[0]);
1584 Float_t distPoint[3]={xyz[0],xyz[1],xyz[2]};
ffab0c37 1585 DistortPoint(distPoint, sector);
cf5b0aa0 1586 pIn0.SetXYZ(xyz[0], xyz[1],xyz[2]);
1587 pIn1.SetXYZ(distPoint[0], distPoint[1],distPoint[2]);
1588 //
1589 track.Rotate(alpha);
1590 AliTrackPoint prot0 = pIn0.Rotate(alpha); // rotate to the local frame - non distoted point
1591 AliTrackPoint prot1 = pIn1.Rotate(alpha); // rotate to the local frame - distorted point
1592 prot0.SetXYZ(prot0.GetX(),prot0.GetY(), prot0.GetZ(),covPoint);
1593 prot1.SetXYZ(prot1.GetX(),prot1.GetY(), prot1.GetZ(),covPoint);
1594 pIn0=prot0.Rotate(-alpha); // rotate back to global frame
1595 pIn1=prot1.Rotate(-alpha); // rotate back to global frame
1596 pointArray0.AddPoint(npoints, &pIn0);
1597 pointArray1.AddPoint(npoints, &pIn1);
1598 npoints++;
1599 if (npoints>=npoints0) break;
1600 }
cfe2c39a 1601 if (npoints<npoints0/4.) return 0;
cf5b0aa0 1602 //
1603 // refit track
1604 //
1605 AliExternalTrackParam *track0=0;
1606 AliExternalTrackParam *track1=0;
1607 AliTrackPoint point1,point2,point3;
1608 if (dir==1) { //make seed inner
1609 pointArray0.GetPoint(point1,1);
cfe2c39a 1610 pointArray0.GetPoint(point2,11);
1611 pointArray0.GetPoint(point3,21);
cf5b0aa0 1612 }
1613 if (dir==-1){ //make seed outer
cfe2c39a 1614 pointArray0.GetPoint(point1,npoints-21);
1615 pointArray0.GetPoint(point2,npoints-11);
cf5b0aa0 1616 pointArray0.GetPoint(point3,npoints-1);
46e89793 1617 }
1618 if ((TMath::Abs(point1.GetX()-point3.GetX())+TMath::Abs(point1.GetY()-point3.GetY()))<10){
1619 printf("fit points not properly initialized\n");
1620 return 0;
1621 }
cf5b0aa0 1622 track0 = AliTrackerBase::MakeSeed(point1, point2, point3);
1623 track1 = AliTrackerBase::MakeSeed(point1, point2, point3);
cfe2c39a 1624 track0->ResetCovariance(10);
1625 track1->ResetCovariance(10);
1626 if (TMath::Abs(AliTrackerBase::GetBz())<0.01){
1627 ((Double_t*)track0->GetParameter())[4]= trackIn.GetParameter()[4];
1628 ((Double_t*)track1->GetParameter())[4]= trackIn.GetParameter()[4];
1629 }
cf5b0aa0 1630 for (Int_t jpoint=0; jpoint<npoints; jpoint++){
8b63d99c 1631 Int_t ipoint= (dir>0) ? jpoint: npoints-1-jpoint;
cf5b0aa0 1632 //
1633 AliTrackPoint pIn0;
1634 AliTrackPoint pIn1;
1635 pointArray0.GetPoint(pIn0,ipoint);
1636 pointArray1.GetPoint(pIn1,ipoint);
1637 AliTrackPoint prot0 = pIn0.Rotate(track0->GetAlpha()); // rotate to the local frame - non distoted point
1638 AliTrackPoint prot1 = pIn1.Rotate(track1->GetAlpha()); // rotate to the local frame - distorted point
46e89793 1639 if (TMath::Abs(prot0.GetX())<kRTPC0) continue;
1640 if (TMath::Abs(prot0.GetX())>kRTPC1) continue;
cf5b0aa0 1641 //
cfe2c39a 1642 if (!AliTrackerBase::PropagateTrackTo(track0,prot0.GetX(),kMass,5,kFALSE,kMaxSnp)) break;
1643 if (!AliTrackerBase::PropagateTrackTo(track1,prot0.GetX(),kMass,5,kFALSE,kMaxSnp)) break;
ca58ed4e 1644 if (TMath::Abs(track0->GetZ())>kMaxZ) break;
1645 if (TMath::Abs(track0->GetX())>kMaxR) break;
1646 if (TMath::Abs(track1->GetZ())>kMaxZ) break;
1647 if (TMath::Abs(track1->GetX())>kMaxR) break;
cfe2c39a 1648 if (dir>0 && track1->GetX()>refX) continue;
1649 if (dir<0 && track1->GetX()<refX) continue;
1650 if (TMath::Abs(track1->GetZ())<kZcut)continue;
8b63d99c 1651 track.GetXYZ(xyz); // distorted track also propagated to the same reference radius
cf5b0aa0 1652 //
1653 Double_t pointPos[2]={0,0};
1654 Double_t pointCov[3]={0,0,0};
1655 pointPos[0]=prot0.GetY();//local y
1656 pointPos[1]=prot0.GetZ();//local z
1657 pointCov[0]=prot0.GetCov()[3];//simay^2
1658 pointCov[1]=prot0.GetCov()[4];//sigmayz
1659 pointCov[2]=prot0.GetCov()[5];//sigmaz^2
ca58ed4e 1660 if (!track0->Update(pointPos,pointCov)) break;
cf5b0aa0 1661 //
8b63d99c 1662 Double_t deltaX=prot1.GetX()-prot0.GetX(); // delta X
1663 Double_t deltaYX=deltaX*TMath::Tan(TMath::ASin(track1->GetSnp())); // deltaY due delta X
1664 Double_t deltaZX=deltaX*track1->GetTgl(); // deltaZ due delta X
1665
0b736a46 1666 pointPos[0]=prot1.GetY()-deltaYX;//local y is sign correct? should be minus
1667 pointPos[1]=prot1.GetZ()-deltaZX;//local z is sign correct? should be minus
cf5b0aa0 1668 pointCov[0]=prot1.GetCov()[3];//simay^2
1669 pointCov[1]=prot1.GetCov()[4];//sigmayz
1670 pointCov[2]=prot1.GetCov()[5];//sigmaz^2
ca58ed4e 1671 if (!track1->Update(pointPos,pointCov)) break;
1672 npoints1++;
1673 npoints2++;
cf5b0aa0 1674 }
cfe2c39a 1675 if (npoints2<npoints/4.) return 0;
1676 AliTrackerBase::PropagateTrackTo(track0,refX,kMass,5.,kTRUE,kMaxSnp);
1677 AliTrackerBase::PropagateTrackTo(track0,refX,kMass,1.,kTRUE,kMaxSnp);
cf5b0aa0 1678 track1->Rotate(track0->GetAlpha());
cfe2c39a 1679 AliTrackerBase::PropagateTrackTo(track1,track0->GetX(),kMass,5.,kFALSE,kMaxSnp);
cf5b0aa0 1680
cad404e1 1681 if (pcstream) (*pcstream)<<Form("fitDistort%s",GetName())<<
cf5b0aa0 1682 "point0.="<<&pointArray0<< // points
1683 "point1.="<<&pointArray1<< // distorted points
1684 "trackIn.="<<&track<< // original track
1685 "track0.="<<track0<< // fitted track
1686 "track1.="<<track1<< // fitted distorted track
1687 "\n";
be67055b 1688 new(&trackIn) AliExternalTrackParam(*track0);
cf5b0aa0 1689 delete track0;
1690 return track1;
1691}
1692
1693
ffab0c37 1694
1695
1696
1697TTree* AliTPCCorrection::CreateDistortionTree(Double_t step){
1698 //
1699 // create the distortion tree on a mesh with granularity given by step
1700 // return the tree with distortions at given position
1701 // Map is created on the mesh with given step size
1702 //
1703 TTreeSRedirector *pcstream = new TTreeSRedirector(Form("correction%s.root",GetName()));
1704 Float_t xyz[3];
1705 for (Double_t x= -250; x<250; x+=step){
1706 for (Double_t y= -250; y<250; y+=step){
1707 Double_t r = TMath::Sqrt(x*x+y*y);
1708 if (r<80) continue;
1709 if (r>250) continue;
1710 for (Double_t z= -250; z<250; z+=step){
1711 Int_t roc=(z>0)?0:18;
1712 xyz[0]=x;
1713 xyz[1]=y;
1714 xyz[2]=z;
1715 Double_t phi = TMath::ATan2(y,x);
1716 DistortPoint(xyz,roc);
1717 Double_t r1 = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
1718 Double_t phi1 = TMath::ATan2(xyz[1],xyz[0]);
1719 if ((phi1-phi)>TMath::Pi()) phi1-=TMath::Pi();
1720 if ((phi1-phi)<-TMath::Pi()) phi1+=TMath::Pi();
1721 Double_t dx = xyz[0]-x;
1722 Double_t dy = xyz[1]-y;
1723 Double_t dz = xyz[2]-z;
1724 Double_t dr=r1-r;
1725 Double_t drphi=(phi1-phi)*r;
1726 (*pcstream)<<"distortion"<<
1727 "x="<<x<< // original position
1728 "y="<<y<<
1729 "z="<<z<<
1730 "r="<<r<<
1731 "phi="<<phi<<
1732 "x1="<<xyz[0]<< // distorted position
1733 "y1="<<xyz[1]<<
1734 "z1="<<xyz[2]<<
1735 "r1="<<r1<<
1736 "phi1="<<phi1<<
1737 //
1738 "dx="<<dx<< // delta position
1739 "dy="<<dy<<
1740 "dz="<<dz<<
1741 "dr="<<dr<<
1742 "drphi="<<drphi<<
1743 "\n";
1744 }
1745 }
1746 }
1747 delete pcstream;
1748 TFile f(Form("correction%s.root",GetName()));
1749 TTree * tree = (TTree*)f.Get("distortion");
1750 TTree * tree2= tree->CopyTree("1");
1751 tree2->SetName(Form("dist%s",GetName()));
1752 tree2->SetDirectory(0);
1753 delete tree;
1754 return tree2;
1755}
1756
1757
1758
be67055b 1759
46e89793 1760void AliTPCCorrection::MakeTrackDistortionTree(TTree *tinput, Int_t dtype, Int_t ptype, const TObjArray * corrArray, Int_t step, Int_t offset, Bool_t debug ){
be67055b 1761 //
1762 // Make a fit tree:
1763 // For each partial correction (specified in array) and given track topology (phi, theta, snp, refX)
1764 // calculates partial distortions
1765 // Partial distortion is stored in the resulting tree
1766 // Output is storred in the file distortion_<dettype>_<partype>.root
1767 // Partial distortion is stored with the name given by correction name
1768 //
1769 //
1770 // Parameters of function:
1771 // input - input tree
cfe2c39a 1772 // dtype - distortion type 0 - ITSTPC, 1 -TPCTRD, 2 - TPCvertex , 3 - TPC-TOF, 4 - TPCTPC track crossing
be67055b 1773 // ppype - parameter type
1774 // corrArray - array with partial corrections
1775 // step - skipe entries - if 1 all entries processed - it is slow
1776 // debug 0 if debug on also space points dumped - it is slow
c9cbd2f2 1777
b322e06a 1778 const Double_t kMaxSnp = 0.85;
cfe2c39a 1779 const Double_t kcutSnp=0.25;
1780 const Double_t kcutTheta=1.;
1781 const Double_t kRadiusTPC=85;
1782 // AliTPCROC *tpcRoc =AliTPCROC::Instance();
1783 //
b322e06a 1784 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
1785 // const Double_t kB2C=-0.299792458e-3;
46e89793 1786 const Int_t kMinEntries=20;
cfe2c39a 1787 Double_t phi,theta, snp, mean,rms, entries,sector,dsec;
46e89793 1788 Float_t refX;
1789 Int_t run;
1790 tinput->SetBranchAddress("run",&run);
be67055b 1791 tinput->SetBranchAddress("theta",&theta);
1792 tinput->SetBranchAddress("phi", &phi);
1793 tinput->SetBranchAddress("snp",&snp);
1794 tinput->SetBranchAddress("mean",&mean);
1795 tinput->SetBranchAddress("rms",&rms);
1796 tinput->SetBranchAddress("entries",&entries);
cfe2c39a 1797 tinput->SetBranchAddress("sector",&sector);
1798 tinput->SetBranchAddress("dsec",&dsec);
1799 tinput->SetBranchAddress("refX",&refX);
46e89793 1800 TTreeSRedirector *pcstream = new TTreeSRedirector(Form("distortion%d_%d_%d.root",dtype,ptype,offset));
be67055b 1801 //
1802 Int_t nentries=tinput->GetEntries();
1803 Int_t ncorr=corrArray->GetEntries();
7f4cb119 1804 Double_t corrections[100]={0}; //
be67055b 1805 Double_t tPar[5];
1806 Double_t cov[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
be67055b 1807 Int_t dir=0;
cfe2c39a 1808 if (dtype==5 || dtype==6) dtype=4;
1809 if (dtype==0) { dir=-1;}
1810 if (dtype==1) { dir=1;}
1811 if (dtype==2) { dir=-1;}
1812 if (dtype==3) { dir=1;}
1813 if (dtype==4) { dir=-1;}
be67055b 1814 //
46e89793 1815 for (Int_t ientry=offset; ientry<nentries; ientry+=step){
be67055b 1816 tinput->GetEntry(ientry);
7f4cb119 1817 if (TMath::Abs(snp)>kMaxSnp) continue;
be67055b 1818 tPar[0]=0;
1819 tPar[1]=theta*refX;
cfe2c39a 1820 if (dtype==2) tPar[1]=theta*kRadiusTPC;
be67055b 1821 tPar[2]=snp;
1822 tPar[3]=theta;
4486a91f 1823 tPar[4]=(gRandom->Rndm()-0.5)*0.02; // should be calculated - non equal to 0
cfe2c39a 1824 if (dtype==4){
1825 // tracks crossing CE
1826 tPar[1]=0; // track at the CE
1827 //if (TMath::Abs(theta) <0.05) continue; // deep cross
1828 }
1829
1830 if (TMath::Abs(snp) >kcutSnp) continue;
1831 if (TMath::Abs(theta) >kcutTheta) continue;
1832 printf("%f\t%f\t%f\t%f\t%f\t%f\n",entries, sector,theta,snp, mean,rms);
8b63d99c 1833 Double_t bz=AliTrackerBase::GetBz();
cfe2c39a 1834 if (dtype !=4) { //exclude TPC - for TPC mainly non primary tracks
1835 if (dtype!=2 && TMath::Abs(bz)>0.1 ) tPar[4]=snp/(refX*bz*kB2C*2);
1836
1837 if (dtype==2 && TMath::Abs(bz)>0.1 ) {
1838 tPar[4]=snp/(kRadiusTPC*bz*kB2C*2);//
1839 // snp at the TPC inner radius in case the vertex match used
1840 }
1841 }
1842 //
4486a91f 1843 tPar[4]+=(gRandom->Rndm()-0.5)*0.02;
7f4cb119 1844 AliExternalTrackParam track(refX,phi,tPar,cov);
1845 Double_t xyz[3];
1846 track.GetXYZ(xyz);
1847 Int_t id=0;
46e89793 1848 Double_t pt=1./tPar[4];
7f4cb119 1849 Double_t dRrec=0; // dummy value - needed for points - e.g for laser
cfe2c39a 1850 //if (ptype==4 &&bz<0) mean*=-1; // interpret as curvature -- COMMENTED out - in lookup signed 1/pt used
46e89793 1851 Double_t refXD=refX;
be67055b 1852 (*pcstream)<<"fit"<<
46e89793 1853 "run="<<run<< // run number
8b63d99c 1854 "bz="<<bz<< // magnetic filed used
be67055b 1855 "dtype="<<dtype<< // detector match type
1856 "ptype="<<ptype<< // parameter type
1857 "theta="<<theta<< // theta
1858 "phi="<<phi<< // phi
1859 "snp="<<snp<< // snp
1860 "mean="<<mean<< // mean dist value
1861 "rms="<<rms<< // rms
cfe2c39a 1862 "sector="<<sector<<
1863 "dsec="<<dsec<<
46e89793 1864 "refX="<<refXD<< // referece X as double
7f4cb119 1865 "gx="<<xyz[0]<< // global position at reference
1866 "gy="<<xyz[1]<< // global position at reference
1867 "gz="<<xyz[2]<< // global position at reference
1868 "dRrec="<<dRrec<< // delta Radius in reconstruction
46e89793 1869 "pt="<<pt<< // pt
7f4cb119 1870 "id="<<id<< // track id
be67055b 1871 "entries="<<entries;// number of entries in bin
1872 //
cfe2c39a 1873 Bool_t isOK=kTRUE;
46e89793 1874 if (entries<kMinEntries) isOK=kFALSE;
1875 //
cfe2c39a 1876 if (dtype!=4) for (Int_t icorr=0; icorr<ncorr; icorr++) {
be67055b 1877 AliTPCCorrection *corr = (AliTPCCorrection*)corrArray->At(icorr);
1878 corrections[icorr]=0;
1879 if (entries>kMinEntries){
1880 AliExternalTrackParam trackIn(refX,phi,tPar,cov);
1881 AliExternalTrackParam *trackOut = 0;
1882 if (debug) trackOut=corr->FitDistortedTrack(trackIn, refX, dir,pcstream);
1883 if (!debug) trackOut=corr->FitDistortedTrack(trackIn, refX, dir,0);
cfe2c39a 1884 if (dtype==0) {dir= -1;}
1885 if (dtype==1) {dir= 1;}
1886 if (dtype==2) {dir= -1;}
1887 if (dtype==3) {dir= 1;}
b1f0a2a5 1888 //
7f4cb119 1889 if (trackOut){
cfe2c39a 1890 if (!AliTrackerBase::PropagateTrackTo(&trackIn,refX,kMass,5,kTRUE,kMaxSnp)) isOK=kFALSE;
1891 if (!trackOut->Rotate(trackIn.GetAlpha())) isOK=kFALSE;
1892 if (!AliTrackerBase::PropagateTrackTo(trackOut,trackIn.GetX(),kMass,5,kFALSE,kMaxSnp)) isOK=kFALSE;
1893 // trackOut->PropagateTo(trackIn.GetX(),AliTrackerBase::GetBz());
1894 //
7f4cb119 1895 corrections[icorr]= trackOut->GetParameter()[ptype]-trackIn.GetParameter()[ptype];
1896 delete trackOut;
1897 }else{
1898 corrections[icorr]=0;
cfe2c39a 1899 isOK=kFALSE;
7f4cb119 1900 }
cfe2c39a 1901 //if (ptype==4 &&bz<0) corrections[icorr]*=-1; // interpret as curvature - commented out
be67055b 1902 }
1903 (*pcstream)<<"fit"<<
46e89793 1904 Form("%s=",corr->GetName())<<corrections[icorr]; // dump correction value
be67055b 1905 }
cfe2c39a 1906
1907 if (dtype==4) for (Int_t icorr=0; icorr<ncorr; icorr++) {
1908 //
1909 // special case of the TPC tracks crossing the CE
1910 //
1911 AliTPCCorrection *corr = (AliTPCCorrection*)corrArray->At(icorr);
1912 corrections[icorr]=0;
1913 if (entries>kMinEntries){
46e89793 1914 AliExternalTrackParam trackIn0(refX,phi,tPar,cov); //Outer - direction to vertex
1915 AliExternalTrackParam trackIn1(refX,phi,tPar,cov); //Inner - direction magnet
cfe2c39a 1916 AliExternalTrackParam *trackOut0 = 0;
1917 AliExternalTrackParam *trackOut1 = 0;
1918 //
1919 if (debug) trackOut0=corr->FitDistortedTrack(trackIn0, refX, dir,pcstream);
1920 if (!debug) trackOut0=corr->FitDistortedTrack(trackIn0, refX, dir,0);
1921 if (debug) trackOut1=corr->FitDistortedTrack(trackIn1, refX, -dir,pcstream);
1922 if (!debug) trackOut1=corr->FitDistortedTrack(trackIn1, refX, -dir,0);
1923 //
1924 if (trackOut0 && trackOut1){
1925 if (!AliTrackerBase::PropagateTrackTo(&trackIn0,refX,kMass,5,kTRUE,kMaxSnp)) isOK=kFALSE;
1926 if (!AliTrackerBase::PropagateTrackTo(&trackIn0,refX,kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
1927 if (!trackOut0->Rotate(trackIn0.GetAlpha())) isOK=kFALSE;
1928 if (!AliTrackerBase::PropagateTrackTo(trackOut0,trackIn0.GetX(),kMass,5,kFALSE,kMaxSnp)) isOK=kFALSE;
1929 //
1930 if (!AliTrackerBase::PropagateTrackTo(&trackIn1,refX,kMass,5,kTRUE,kMaxSnp)) isOK=kFALSE;
1931 if (!trackIn1.Rotate(trackIn0.GetAlpha())) isOK=kFALSE;
1932 if (!AliTrackerBase::PropagateTrackTo(&trackIn1,trackIn0.GetX(),kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
1933 if (!trackOut1->Rotate(trackIn1.GetAlpha())) isOK=kFALSE;
1934 if (!AliTrackerBase::PropagateTrackTo(trackOut1,trackIn1.GetX(),kMass,5,kFALSE,kMaxSnp)) isOK=kFALSE;
1935 //
1936 corrections[icorr] = (trackOut0->GetParameter()[ptype]-trackIn0.GetParameter()[ptype]);
1937 corrections[icorr]-= (trackOut1->GetParameter()[ptype]-trackIn1.GetParameter()[ptype]);
46e89793 1938 if (isOK)
1939 if ((TMath::Abs(trackOut0->GetX()-trackOut1->GetX())>0.1)||
1940 (TMath::Abs(trackOut0->GetX()-trackIn1.GetX())>0.1)||
1941 (TMath::Abs(trackOut0->GetAlpha()-trackOut1->GetAlpha())>0.00001)||
1942 (TMath::Abs(trackOut0->GetAlpha()-trackIn1.GetAlpha())>0.00001)||
1943 (TMath::Abs(trackIn0.GetTgl()-trackIn1.GetTgl())>0.0001)||
1944 (TMath::Abs(trackIn0.GetSnp()-trackIn1.GetSnp())>0.0001)
1945 ){
1946 isOK=kFALSE;
1947 }
cfe2c39a 1948 delete trackOut0;
46e89793 1949 delete trackOut1;
cfe2c39a 1950 }else{
1951 corrections[icorr]=0;
1952 isOK=kFALSE;
1953 }
1954 //
1955 //if (ptype==4 &&bz<0) corrections[icorr]*=-1; // interpret as curvature - commented out no in lookup
1956 }
cfe2c39a 1957 (*pcstream)<<"fit"<<
46e89793 1958 Form("%s=",corr->GetName())<<corrections[icorr]; // dump correction value
cfe2c39a 1959 }
1960 //
1961 (*pcstream)<<"fit"<<"isOK="<<isOK<<"\n";
be67055b 1962 }
cfe2c39a 1963
1964
be67055b 1965 delete pcstream;
1966}
1967
1968
1969
46e89793 1970void AliTPCCorrection::MakeSectorDistortionTree(TTree *tinput, Int_t dtype, Int_t ptype, const TObjArray * corrArray, Int_t step, Int_t offset, Bool_t debug ){
1971 //
1972 // Make a fit tree:
1973 // For each partial correction (specified in array) and given track topology (phi, theta, snp, refX)
1974 // calculates partial distortions
1975 // Partial distortion is stored in the resulting tree
1976 // Output is storred in the file distortion_<dettype>_<partype>.root
1977 // Partial distortion is stored with the name given by correction name
1978 //
1979 //
1980 // Parameters of function:
1981 // input - input tree
1982 // dtype - distortion type 10 - IROC-OROC
1983 // ppype - parameter type
1984 // corrArray - array with partial corrections
1985 // step - skipe entries - if 1 all entries processed - it is slow
1986 // debug 0 if debug on also space points dumped - it is slow
1987
1988 const Double_t kMaxSnp = 0.8;
1989 const Int_t kMinEntries=200;
1990 // AliTPCROC *tpcRoc =AliTPCROC::Instance();
1991 //
1992 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
1993 // const Double_t kB2C=-0.299792458e-3;
1994 Double_t phi,theta, snp, mean,rms, entries,sector,dsec,globalZ;
1995 Int_t isec1, isec0;
1996 Double_t refXD;
1997 Float_t refX;
1998 Int_t run;
1999 tinput->SetBranchAddress("run",&run);
2000 tinput->SetBranchAddress("theta",&theta);
2001 tinput->SetBranchAddress("phi", &phi);
2002 tinput->SetBranchAddress("snp",&snp);
2003 tinput->SetBranchAddress("mean",&mean);
2004 tinput->SetBranchAddress("rms",&rms);
2005 tinput->SetBranchAddress("entries",&entries);
2006 tinput->SetBranchAddress("sector",&sector);
2007 tinput->SetBranchAddress("dsec",&dsec);
2008 tinput->SetBranchAddress("refX",&refXD);
2009 tinput->SetBranchAddress("z",&globalZ);
2010 tinput->SetBranchAddress("isec0",&isec0);
2011 tinput->SetBranchAddress("isec1",&isec1);
2012 TTreeSRedirector *pcstream = new TTreeSRedirector(Form("distortionSector%d_%d_%d.root",dtype,ptype,offset));
2013 //
2014 Int_t nentries=tinput->GetEntries();
2015 Int_t ncorr=corrArray->GetEntries();
2016 Double_t corrections[100]={0}; //
2017 Double_t tPar[5];
2018 Double_t cov[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
2019 Int_t dir=0;
2020 //
2021 for (Int_t ientry=offset; ientry<nentries; ientry+=step){
2022 tinput->GetEntry(ientry);
2023 refX=refXD;
2024 Int_t id=-1;
2025 if (TMath::Abs(TMath::Abs(isec0%18)-TMath::Abs(isec1%18))==0) id=1; // IROC-OROC - opposite side
2026 if (TMath::Abs(TMath::Abs(isec0%36)-TMath::Abs(isec1%36))==0) id=2; // IROC-OROC - same side
2027 if (dtype==10 && id==-1) continue;
2028 //
2029 dir=-1;
2030 tPar[0]=0;
2031 tPar[1]=globalZ;
2032 tPar[2]=snp;
2033 tPar[3]=theta;
2034 tPar[4]=(gRandom->Rndm()-0.1)*0.2; //
2035 Double_t pt=1./tPar[4];
2036 //
2037 printf("%f\t%f\t%f\t%f\t%f\t%f\n",entries, sector,theta,snp, mean,rms);
2038 Double_t bz=AliTrackerBase::GetBz();
2039 AliExternalTrackParam track(refX,phi,tPar,cov);
2040 Double_t xyz[3],xyzIn[3],xyzOut[3];
2041 track.GetXYZ(xyz);
2042 track.GetXYZAt(85,bz,xyzIn);
2043 track.GetXYZAt(245,bz,xyzOut);
2044 Double_t phiIn = TMath::ATan2(xyzIn[1],xyzIn[0]);
2045 Double_t phiOut = TMath::ATan2(xyzOut[1],xyzOut[0]);
2046 Double_t phiRef = TMath::ATan2(xyz[1],xyz[0]);
2047 Int_t sectorRef = TMath::Nint(9.*phiRef/TMath::Pi()-0.5);
2048 Int_t sectorIn = TMath::Nint(9.*phiIn/TMath::Pi()-0.5);
2049 Int_t sectorOut = TMath::Nint(9.*phiOut/TMath::Pi()-0.5);
2050 //
2051 Bool_t isOK=kTRUE;
2052 if (sectorIn!=sectorOut) isOK=kFALSE; // requironment - cluster in the same sector
2053 if (sectorIn!=sectorRef) isOK=kFALSE; // requironment - cluster in the same sector
2054 if (entries<kMinEntries/(1+TMath::Abs(globalZ/100.))) isOK=kFALSE; // requironment - minimal amount of tracks in bin
2055 // Do downscale
2056 if (TMath::Abs(theta)>1) isOK=kFALSE;
2057 //
2058 Double_t dRrec=0; // dummy value - needed for points - e.g for laser
2059 //
2060 (*pcstream)<<"fit"<<
2061 "run="<<run<< //run
2062 "bz="<<bz<< // magnetic filed used
2063 "dtype="<<dtype<< // detector match type
2064 "ptype="<<ptype<< // parameter type
2065 "theta="<<theta<< // theta
2066 "phi="<<phi<< // phi
2067 "snp="<<snp<< // snp
2068 "mean="<<mean<< // mean dist value
2069 "rms="<<rms<< // rms
2070 "sector="<<sector<<
2071 "dsec="<<dsec<<
2072 "refX="<<refXD<< // referece X
2073 "gx="<<xyz[0]<< // global position at reference
2074 "gy="<<xyz[1]<< // global position at reference
2075 "gz="<<xyz[2]<< // global position at reference
2076 "dRrec="<<dRrec<< // delta Radius in reconstruction
2077 "pt="<<pt<< //pt
2078 "id="<<id<< // track id
2079 "entries="<<entries;// number of entries in bin
2080 //
2081 AliExternalTrackParam *trackOut0 = 0;
2082 AliExternalTrackParam *trackOut1 = 0;
2083 AliExternalTrackParam *ptrackIn0 = 0;
2084 AliExternalTrackParam *ptrackIn1 = 0;
2085
2086 for (Int_t icorr=0; icorr<ncorr; icorr++) {
2087 //
2088 // special case of the TPC tracks crossing the CE
2089 //
2090 AliTPCCorrection *corr = (AliTPCCorrection*)corrArray->At(icorr);
2091 corrections[icorr]=0;
2092 if (entries>kMinEntries &&isOK){
2093 AliExternalTrackParam trackIn0(refX,phi,tPar,cov);
2094 AliExternalTrackParam trackIn1(refX,phi,tPar,cov);
2095 ptrackIn1=&trackIn0;
2096 ptrackIn0=&trackIn1;
2097 //
2098 if (debug) trackOut0=corr->FitDistortedTrack(trackIn0, refX, dir,pcstream);
2099 if (!debug) trackOut0=corr->FitDistortedTrack(trackIn0, refX, dir,0);
2100 if (debug) trackOut1=corr->FitDistortedTrack(trackIn1, refX, -dir,pcstream);
2101 if (!debug) trackOut1=corr->FitDistortedTrack(trackIn1, refX, -dir,0);
2102 //
2103 if (trackOut0 && trackOut1){
2104 //
2105 if (!AliTrackerBase::PropagateTrackTo(&trackIn0,refX,kMass,1,kTRUE,kMaxSnp)) isOK=kFALSE;
2106 if (!AliTrackerBase::PropagateTrackTo(&trackIn0,refX,kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
2107 // rotate all tracks to the same frame
2108 if (!trackOut0->Rotate(trackIn0.GetAlpha())) isOK=kFALSE;
2109 if (!trackIn1.Rotate(trackIn0.GetAlpha())) isOK=kFALSE;
2110 if (!trackOut1->Rotate(trackIn0.GetAlpha())) isOK=kFALSE;
2111 //
2112 if (!AliTrackerBase::PropagateTrackTo(trackOut0,refX,kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
2113 if (!AliTrackerBase::PropagateTrackTo(&trackIn1,refX,kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
2114 if (!AliTrackerBase::PropagateTrackTo(trackOut1,refX,kMass,1,kFALSE,kMaxSnp)) isOK=kFALSE;
2115 //
2116 corrections[icorr] = (trackOut0->GetParameter()[ptype]-trackIn0.GetParameter()[ptype]);
2117 corrections[icorr]-= (trackOut1->GetParameter()[ptype]-trackIn1.GetParameter()[ptype]);
2118 (*pcstream)<<"fitDebug"<< // just to debug the correction
2119 "mean="<<mean<<
2120 "pIn0.="<<ptrackIn0<<
2121 "pIn1.="<<ptrackIn1<<
2122 "pOut0.="<<trackOut0<<
2123 "pOut1.="<<trackOut1<<
2124 "refX="<<refXD<<
2125 "\n";
2126 delete trackOut0;
2127 delete trackOut1;
2128 }else{
2129 corrections[icorr]=0;
2130 isOK=kFALSE;
2131 }
2132 }
2133 (*pcstream)<<"fit"<<
2134 Form("%s=",corr->GetName())<<corrections[icorr]; // dump correction value
2135 }
2136 //
2137 (*pcstream)<<"fit"<<"isOK="<<isOK<<"\n";
2138 }
2139 delete pcstream;
2140}
2141
2142
2143
2144void AliTPCCorrection::MakeLaserDistortionTreeOld(TTree* tree, TObjArray *corrArray, Int_t itype){
7f4cb119 2145 //
2146 // Make a laser fit tree for global minimization
2147 //
2148 const Double_t cutErrY=0.1;
2149 const Double_t cutErrZ=0.1;
2150 const Double_t kEpsilon=0.00000001;
46e89793 2151 const Double_t kMaxDist=1.; // max distance - space correction
2152 const Double_t kMaxRMS=0.05; // max distance -between point and local mean
7f4cb119 2153 TVectorD *vecdY=0;
2154 TVectorD *vecdZ=0;
2155 TVectorD *veceY=0;
2156 TVectorD *veceZ=0;
2157 AliTPCLaserTrack *ltr=0;
2158 AliTPCLaserTrack::LoadTracks();
2159 tree->SetBranchAddress("dY.",&vecdY);
2160 tree->SetBranchAddress("dZ.",&vecdZ);
2161 tree->SetBranchAddress("eY.",&veceY);
2162 tree->SetBranchAddress("eZ.",&veceZ);
2163 tree->SetBranchAddress("LTr.",&ltr);
2164 Int_t entries= tree->GetEntries();
cfe2c39a 2165 TTreeSRedirector *pcstream= new TTreeSRedirector("distortionLaser_0.root");
7f4cb119 2166 Double_t bz=AliTrackerBase::GetBz();
2167 //
2168
2169 for (Int_t ientry=0; ientry<entries; ientry++){
2170 tree->GetEntry(ientry);
2171 if (!ltr->GetVecGX()){
2172 ltr->UpdatePoints();
2173 }
2174 TVectorD * delta= (itype==0)? vecdY:vecdZ;
2175 TVectorD * err= (itype==0)? veceY:veceZ;
46e89793 2176 TLinearFitter fitter(2,"pol1");
2177 for (Int_t iter=0; iter<2; iter++){
2178 Double_t kfit0=0, kfit1=0;
2179 Int_t npoints=fitter.GetNpoints();
2180 if (npoints>80){
2181 fitter.Eval();
2182 kfit0=fitter.GetParameter(0);
2183 kfit1=fitter.GetParameter(1);
2184 }
2185 for (Int_t irow=0; irow<159; irow++){
2186 Bool_t isOK=kTRUE;
2187 Int_t isOKF=0;
2188 Int_t nentries = 1000;
2189 if (veceY->GetMatrixArray()[irow]>cutErrY||veceZ->GetMatrixArray()[irow]>cutErrZ) nentries=0;
2190 if (veceY->GetMatrixArray()[irow]<kEpsilon||veceZ->GetMatrixArray()[irow]<kEpsilon) nentries=0;
2191 Int_t dtype=5;
2192 Double_t array[10];
2193 Int_t first3=TMath::Max(irow-3,0);
2194 Int_t last3 =TMath::Min(irow+3,159);
2195 Int_t counter=0;
2196 if ((*ltr->GetVecSec())[irow]>=0 && err) {
2197 for (Int_t jrow=first3; jrow<=last3; jrow++){
2198 if ((*ltr->GetVecSec())[irow]!= (*ltr->GetVecSec())[jrow]) continue;
2199 if ((*err)[jrow]<kEpsilon) continue;
2200 array[counter]=(*delta)[jrow];
2201 counter++;
2202 }
2203 }
2204 Double_t rms3 = 0;
2205 Double_t mean3 = 0;
2206 if (counter>2){
2207 rms3 = TMath::RMS(counter,array);
2208 mean3 = TMath::Mean(counter,array);
2209 }else{
2210 isOK=kFALSE;
2211 }
2212 Double_t phi =(*ltr->GetVecPhi())[irow];
2213 Double_t theta =ltr->GetTgl();
2214 Double_t mean=delta->GetMatrixArray()[irow];
2215 Double_t gx=0,gy=0,gz=0;
2216 Double_t snp = (*ltr->GetVecP2())[irow];
2217 Double_t dRrec=0;
2218 // Double_t rms = err->GetMatrixArray()[irow];
cfe2c39a 2219 //
46e89793 2220 gx = (*ltr->GetVecGX())[irow];
2221 gy = (*ltr->GetVecGY())[irow];
2222 gz = (*ltr->GetVecGZ())[irow];
2223 //
2224 // get delta R used in reconstruction
2225 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
2226 AliTPCCorrection * correction = calib->GetTPCComposedCorrection(AliTrackerBase::GetBz());
2227 // const AliTPCRecoParam * recoParam = calib->GetTransform()->GetCurrentRecoParam();
2228 //Double_t xyz0[3]={gx,gy,gz};
2229 Double_t oldR=TMath::Sqrt(gx*gx+gy*gy);
2230 Double_t fphi = TMath::ATan2(gy,gx);
2231 Double_t fsector = 9.*fphi/TMath::Pi();
2232 if (fsector<0) fsector+=18;
2233 Double_t dsec = fsector-Int_t(fsector)-0.5;
2234 Double_t refX=0;
2235 Int_t id= ltr->GetId();
2236 Double_t pt=0;
2237 //
2238 if (1 && oldR>1) {
2239 Float_t xyz1[3]={gx,gy,gz};
2240 Int_t sector=(gz>0)?0:18;
2241 correction->CorrectPoint(xyz1, sector);
2242 refX=TMath::Sqrt(xyz1[0]*xyz1[0]+xyz1[1]*xyz1[1]);
2243 dRrec=oldR-refX;
2244 }
2245 if (TMath::Abs(rms3)>kMaxRMS) isOK=kFALSE;
2246 if (TMath::Abs(mean-mean3)>kMaxRMS) isOK=kFALSE;
2247 if (counter<4) isOK=kFALSE;
2248 if (npoints<90) isOK=kFALSE;
2249 if (isOK){
2250 fitter.AddPoint(&refX,mean);
7f4cb119 2251 }
46e89793 2252 Double_t deltaF=kfit0+kfit1*refX;
2253 if (iter==1){
2254 (*pcstream)<<"fitFull"<< // dumpe also intermediate results
2255 "bz="<<bz<< // magnetic filed used
2256 "dtype="<<dtype<< // detector match type
2257 "ptype="<<itype<< // parameter type
2258 "theta="<<theta<< // theta
2259 "phi="<<phi<< // phi
2260 "snp="<<snp<< // snp
2261 "mean="<<mean3<< // mean dist value
2262 "rms="<<rms3<< // rms
2263 "deltaF="<<deltaF<<
2264 "npoints="<<npoints<< //number of points
2265 "mean3="<<mean3<< // mean dist value
2266 "rms3="<<rms3<< // rms
2267 "counter="<<counter<<
2268 "sector="<<fsector<<
2269 "dsec="<<dsec<<
2270 //
2271 "refX="<<refX<< // reference radius
2272 "gx="<<gx<< // global position
2273 "gy="<<gy<< // global position
2274 "gz="<<gz<< // global position
2275 "dRrec="<<dRrec<< // delta Radius in reconstruction
2276 "id="<<id<< //bundle
2277 "entries="<<nentries<<// number of entries in bin
2278 "\n";
2279 }
2280 if (iter==1) (*pcstream)<<"fit"<< // dump valus for fit
2281 "bz="<<bz<< // magnetic filed used
2282 "dtype="<<dtype<< // detector match type
2283 "ptype="<<itype<< // parameter type
2284 "theta="<<theta<< // theta
2285 "phi="<<phi<< // phi
2286 "snp="<<snp<< // snp
2287 "mean="<<mean3<< // mean dist value
2288 "rms="<<rms3<< // rms
2289 "sector="<<fsector<<
2290 "dsec="<<dsec<<
2291 //
2292 "refX="<<refX<< // reference radius
2293 "gx="<<gx<< // global position
2294 "gy="<<gy<< // global position
2295 "gz="<<gz<< // global position
2296 "dRrec="<<dRrec<< // delta Radius in reconstruction
2297 "pt="<<pt<< //pt
2298 "id="<<id<< //bundle
2299 "entries="<<nentries;// number of entries in bin
2300 //
2301 //
2302 Double_t ky = TMath::Tan(TMath::ASin(snp));
2303 Int_t ncorr = corrArray->GetEntries();
2304 Double_t r0 = TMath::Sqrt(gx*gx+gy*gy);
2305 Double_t phi0 = TMath::ATan2(gy,gx);
2306 Double_t distortions[1000]={0};
2307 Double_t distortionsR[1000]={0};
2308 if (iter==1){
2309 for (Int_t icorr=0; icorr<ncorr; icorr++) {
2310 AliTPCCorrection *corr = (AliTPCCorrection*)corrArray->At(icorr);
2311 Float_t distPoint[3]={gx,gy,gz};
2312 Int_t sector= (gz>0)? 0:18;
2313 if (r0>80){
2314 corr->DistortPoint(distPoint, sector);
2315 }
2316 // Double_t value=distPoint[2]-gz;
2317 if (itype==0 && r0>1){
2318 Double_t r1 = TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
2319 Double_t phi1 = TMath::ATan2(distPoint[1],distPoint[0]);
2320 Double_t drphi= r0*(phi1-phi0);
2321 Double_t dr = r1-r0;
2322 distortions[icorr] = drphi-ky*dr;
2323 distortionsR[icorr] = dr;
2324 }
2325 if (TMath::Abs(distortions[icorr])>kMaxDist) {isOKF=icorr+1; isOK=kFALSE; }
2326 if (TMath::Abs(distortionsR[icorr])>kMaxDist) {isOKF=icorr+1; isOK=kFALSE;}
2327 (*pcstream)<<"fit"<<
2328 Form("%s=",corr->GetName())<<distortions[icorr]; // dump correction value
2329 }
2330 (*pcstream)<<"fit"<<"isOK="<<isOK<<"\n";
7f4cb119 2331 }
7f4cb119 2332 }
7f4cb119 2333 }
2334 }
2335 delete pcstream;
2336}
2337
2338
be67055b 2339
97d17739 2340void AliTPCCorrection::MakeDistortionMap(THnSparse * his0, TTreeSRedirector * const pcstream, const char* hname, Int_t run, Float_t refX, Int_t type, Int_t integ){
cfe2c39a 2341 //
2342 // make a distortion map out ou fthe residual histogram
2343 // Results are written to the debug streamer - pcstream
2344 // Parameters:
2345 // his0 - input (4D) residual histogram
2346 // pcstream - file to write the tree
2347 // run - run number
2348 // refX - track matching reference X
2349 // type - 0- y 1-z,2 -snp, 3-theta, 4=1/pt
2350 // THnSparse axes:
2351 // OBJ: TAxis #Delta #Delta
2352 // OBJ: TAxis tanTheta tan(#Theta)
2353 // OBJ: TAxis phi #phi
2354 // OBJ: TAxis snp snp
2355
2356 // marian.ivanov@cern.ch
2357 const Int_t kMinEntries=10;
2358 Double_t bz=AliTrackerBase::GetBz();
2359 Int_t idim[4]={0,1,2,3};
2360 //
2361 //
2362 //
2363 Int_t nbins3=his0->GetAxis(3)->GetNbins();
2364 Int_t first3=his0->GetAxis(3)->GetFirst();
2365 Int_t last3 =his0->GetAxis(3)->GetLast();
2366 //
2367 for (Int_t ibin3=first3; ibin3<last3; ibin3+=1){ // axis 3 - local angle
97d17739 2368 his0->GetAxis(3)->SetRange(TMath::Max(ibin3-integ,1),TMath::Min(ibin3+integ,nbins3));
cfe2c39a 2369 Double_t x3= his0->GetAxis(3)->GetBinCenter(ibin3);
2370 THnSparse * his3= his0->Projection(3,idim); //projected histogram according selection 3
2371 //
2372 Int_t nbins2 = his3->GetAxis(2)->GetNbins();
2373 Int_t first2 = his3->GetAxis(2)->GetFirst();
2374 Int_t last2 = his3->GetAxis(2)->GetLast();
2375 //
2376 for (Int_t ibin2=first2; ibin2<last2; ibin2+=1){ // axis 2 - phi
97d17739 2377 his3->GetAxis(2)->SetRange(TMath::Max(ibin2-integ,1),TMath::Min(ibin2+integ,nbins2));
cfe2c39a 2378 Double_t x2= his3->GetAxis(2)->GetBinCenter(ibin2);
2379 THnSparse * his2= his3->Projection(2,idim); //projected histogram according selection 2
2380 Int_t nbins1 = his2->GetAxis(1)->GetNbins();
2381 Int_t first1 = his2->GetAxis(1)->GetFirst();
2382 Int_t last1 = his2->GetAxis(1)->GetLast();
2383 for (Int_t ibin1=first1; ibin1<last1; ibin1++){ //axis 1 - theta
2384 //
2385 Double_t x1= his2->GetAxis(1)->GetBinCenter(ibin1);
2386 his2->GetAxis(1)->SetRange(TMath::Max(ibin1-1,1),TMath::Min(ibin1+1,nbins1));
2387 if (TMath::Abs(x1)<0.1){
2388 if (x1<0) his2->GetAxis(1)->SetRange(TMath::Max(ibin1-1,1),TMath::Min(ibin1,nbins1));
2389 if (x1>0) his2->GetAxis(1)->SetRange(TMath::Max(ibin1,1),TMath::Min(ibin1+1,nbins1));
2390 }
2391 if (TMath::Abs(x1)<0.06){
2392 his2->GetAxis(1)->SetRange(TMath::Max(ibin1,1),TMath::Min(ibin1,nbins1));
2393 }
2394 TH1 * hisDelta = his2->Projection(0);
2395 //
2396 Double_t entries = hisDelta->GetEntries();
2397 Double_t mean=0, rms=0;
2398 if (entries>kMinEntries){
2399 mean = hisDelta->GetMean();
2400 rms = hisDelta->GetRMS();
2401 }
2402 Double_t sector = 9.*x2/TMath::Pi();
2403 if (sector<0) sector+=18;
2404 Double_t dsec = sector-Int_t(sector)-0.5;
2405 Double_t z=refX*x1;
2406 (*pcstream)<<hname<<
2407 "run="<<run<<
2408 "bz="<<bz<<
2409 "theta="<<x1<<
2410 "phi="<<x2<<
2411 "z="<<z<< // dummy z
2412 "snp="<<x3<<
2413 "entries="<<entries<<
2414 "mean="<<mean<<
2415 "rms="<<rms<<
2416 "refX="<<refX<< // track matching refernce plane
2417 "type="<<type<< //
2418 "sector="<<sector<<
2419 "dsec="<<dsec<<
2420 "\n";
2421 delete hisDelta;
02cd5ade 2422 //printf("%f\t%f\t%f\t%f\t%f\n",x3,x2,x1, entries,mean);
cfe2c39a 2423 }
2424 delete his2;
2425 }
2426 delete his3;
2427 }
2428}
2429
2430
2431
2432
2433void AliTPCCorrection::MakeDistortionMapCosmic(THnSparse * hisInput, TTreeSRedirector * const pcstream, const char* hname, Int_t run, Float_t refX, Int_t type){
8b63d99c 2434 //
2435 // make a distortion map out ou fthe residual histogram
2436 // Results are written to the debug streamer - pcstream
2437 // Parameters:
2438 // his0 - input (4D) residual histogram
2439 // pcstream - file to write the tree
2440 // run - run number
cfe2c39a 2441 // refX - track matching reference X
2442 // type - 0- y 1-z,2 -snp, 3-theta, 4=1/pt
8b63d99c 2443 // marian.ivanov@cern.ch
cfe2c39a 2444 //
2445 // Histo axeses
2446 // Collection name='TObjArray', class='TObjArray', size=16
2447 // 0. OBJ: TAxis #Delta #Delta
2448 // 1. OBJ: TAxis N_{cl} N_{cl}
2449 // 2. OBJ: TAxis dca_{r} (cm) dca_{r} (cm)
2450 // 3. OBJ: TAxis z (cm) z (cm)
2451 // 4. OBJ: TAxis sin(#phi) sin(#phi)
2452 // 5. OBJ: TAxis tan(#theta) tan(#theta)
2453 // 6. OBJ: TAxis 1/pt (1/GeV) 1/pt (1/GeV)
2454 // 7. OBJ: TAxis pt (GeV) pt (GeV)
2455 // 8. OBJ: TAxis alpha alpha
2456 const Int_t kMinEntries=10;
2457 //
2458 // 1. make default selections
2459 //
2460 TH1 * hisDelta=0;
2461 Int_t idim0[4]={0 , 5, 8, 3}; // delta, theta, alpha, z
2462 hisInput->GetAxis(1)->SetRangeUser(110,190); //long tracks
2463 hisInput->GetAxis(2)->SetRangeUser(-10,35); //tracks close to beam pipe
2464 hisInput->GetAxis(4)->SetRangeUser(-0.3,0.3); //small snp at TPC entrance
2465 hisInput->GetAxis(7)->SetRangeUser(3,100); //"high pt tracks"
2466 hisDelta= hisInput->Projection(0);
2467 hisInput->GetAxis(0)->SetRangeUser(-6.*hisDelta->GetRMS(), +6.*hisDelta->GetRMS());
2468 delete hisDelta;
2469 THnSparse *his0= hisInput->Projection(4,idim0);
2470 //
2471 // 2. Get mean in diferent bins
2472 //
8b63d99c 2473 Int_t nbins1=his0->GetAxis(1)->GetNbins();
2474 Int_t first1=his0->GetAxis(1)->GetFirst();
2475 Int_t last1 =his0->GetAxis(1)->GetLast();
2476 //
2477 Double_t bz=AliTrackerBase::GetBz();
cfe2c39a 2478 Int_t idim[4]={0,1, 2, 3}; // delta, theta,alpha,z
2479 //
2480 for (Int_t ibin1=first1; ibin1<=last1; ibin1++){ //axis 1 - theta
2481 //
2482 Double_t x1= his0->GetAxis(1)->GetBinCenter(ibin1);
2483 his0->GetAxis(1)->SetRange(TMath::Max(ibin1-1,1),TMath::Min(ibin1+1,nbins1));
8b63d99c 2484 //
8b63d99c 2485 THnSparse * his1 = his0->Projection(4,idim); // projected histogram according range1
2486 Int_t nbins3 = his1->GetAxis(3)->GetNbins();
2487 Int_t first3 = his1->GetAxis(3)->GetFirst();
2488 Int_t last3 = his1->GetAxis(3)->GetLast();
2489 //
cfe2c39a 2490 for (Int_t ibin3=first3-1; ibin3<=last3; ibin3+=1){ // axis 3 - z at "vertex"
8b63d99c 2491 his1->GetAxis(3)->SetRange(TMath::Max(ibin3-1,1),TMath::Min(ibin3+1,nbins3));
2492 Double_t x3= his1->GetAxis(3)->GetBinCenter(ibin3);
2493 if (ibin3<first3) {
2494 his1->GetAxis(3)->SetRangeUser(-1,1);
2495 x3=0;
2496 }
2497 THnSparse * his3= his1->Projection(4,idim); //projected histogram according selection 3
2498 Int_t nbins2 = his3->GetAxis(2)->GetNbins();
2499 Int_t first2 = his3->GetAxis(2)->GetFirst();
2500 Int_t last2 = his3->GetAxis(2)->GetLast();
2501 //
cfe2c39a 2502 for (Int_t ibin2=first2; ibin2<=last2; ibin2+=1){
8b63d99c 2503 his3->GetAxis(2)->SetRange(TMath::Max(ibin2-1,1),TMath::Min(ibin2+1,nbins2));
2504 Double_t x2= his3->GetAxis(2)->GetBinCenter(ibin2);
cfe2c39a 2505 hisDelta = his3->Projection(0);
8b63d99c 2506 //
2507 Double_t entries = hisDelta->GetEntries();
2508 Double_t mean=0, rms=0;
2509 if (entries>kMinEntries){
2510 mean = hisDelta->GetMean();
2511 rms = hisDelta->GetRMS();
2512 }
cfe2c39a 2513 Double_t sector = 9.*x2/TMath::Pi();
2514 if (sector<0) sector+=18;
2515 Double_t dsec = sector-Int_t(sector)-0.5;
2516 Double_t snp=0; // dummy snp - equal 0
8b63d99c 2517 (*pcstream)<<hname<<
2518 "run="<<run<<
cfe2c39a 2519 "bz="<<bz<< // magnetic field
2520 "theta="<<x1<< // theta
2521 "phi="<<x2<< // phi (alpha)
2522 "z="<<x3<< // z at "vertex"
2523 "snp="<<snp<< // dummy snp
2524 "entries="<<entries<< // entries in bin
2525 "mean="<<mean<< // mean
8b63d99c 2526 "rms="<<rms<<
cfe2c39a 2527 "refX="<<refX<< // track matching refernce plane
2528 "type="<<type<< // parameter type
2529 "sector="<<sector<< // sector
2530 "dsec="<<dsec<< // dummy delta sector
8b63d99c 2531 "\n";
2532 delete hisDelta;
2533 printf("%f\t%f\t%f\t%f\t%f\n",x1,x3,x2, entries,mean);
2534 }
2535 delete his3;
2536 }
2537 delete his1;
2538 }
cfe2c39a 2539 delete his0;
2540}
2541
2542
2543
2544void AliTPCCorrection::MakeDistortionMapSector(THnSparse * hisInput, TTreeSRedirector * const pcstream, const char* hname, Int_t run, Int_t type){
2545 //
2546 // make a distortion map out of the residual histogram
2547 // Results are written to the debug streamer - pcstream
2548 // Parameters:
2549 // his0 - input (4D) residual histogram
2550 // pcstream - file to write the tree
2551 // run - run number
2552 // type - 0- y 1-z,2 -snp, 3-theta
2553 // marian.ivanov@cern.ch
2554
2555 //Collection name='TObjArray', class='TObjArray', size=16
2556 //0 OBJ: TAxis delta delta
2557 //1 OBJ: TAxis phi phi
2558 //2 OBJ: TAxis localX localX
2559 //3 OBJ: TAxis kY kY
2560 //4 OBJ: TAxis kZ kZ
2561 //5 OBJ: TAxis is1 is1
2562 //6 OBJ: TAxis is0 is0
2563 //7. OBJ: TAxis z z
2564 //8. OBJ: TAxis IsPrimary IsPrimary
2565
2566 const Int_t kMinEntries=10;
2567 THnSparse * hisSector0=0;
2568 TH1 * htemp=0; // histogram to calculate mean value of parameter
2569 Double_t bz=AliTrackerBase::GetBz();
2570
2571 //
2572 // Loop over pair of sector:
2573 // isPrim - 8 ==> 8
2574 // isec0 - 6 ==> 7
2575 // isec1 - 5 ==> 6
2576 // refX - 2 ==> 5
2577 //
2578 // phi - 1 ==> 4
2579 // z - 7 ==> 3
2580 // snp - 3 ==> 2
2581 // theta- 4 ==> 1
2582 // 0 ==> 0;
2583 for (Int_t isec0=0; isec0<72; isec0++){
2584 Int_t index0[9]={0, 4, 3, 7, 1, 2, 5, 6,8}; //regroup indeces
2585 //
2586 //hisInput->GetAxis(8)->SetRangeUser(-0.1,0.4); // select secondaries only ? - get out later ?
2587 hisInput->GetAxis(6)->SetRangeUser(isec0-0.1,isec0+0.1);
2588 hisSector0=hisInput->Projection(7,index0);
2589 //
2590 //
2591 for (Int_t isec1=isec0+1; isec1<72; isec1++){
2592 //if (isec1!=isec0+36) continue;
2593 if ( TMath::Abs((isec0%18)-(isec1%18))>1.5 && TMath::Abs((isec0%18)-(isec1%18))<16.5) continue;
2594 printf("Sectors %d\t%d\n",isec1,isec0);
2595 hisSector0->GetAxis(6)->SetRangeUser(isec1-0.1,isec1+0.1);
2596 TH1 * hisX=hisSector0->Projection(5);
2597 Double_t refX= hisX->GetMean();
2598 delete hisX;
2599 TH1 *hisDelta=hisSector0->Projection(0);
2600 Double_t dmean = hisDelta->GetMean();
2601 Double_t drms = hisDelta->GetRMS();
2602 hisSector0->GetAxis(0)->SetRangeUser(dmean-5.*drms, dmean+5.*drms);
2603 delete hisDelta;
2604 //
2605 // 1. make default selections
2606 //
2607 Int_t idim0[5]={0 , 1, 2, 3, 4}; // {delta, theta, snp, z, phi }
2608 THnSparse *hisSector1= hisSector0->Projection(5,idim0);
2609 //
2610 // 2. Get mean in diferent bins
2611 //
2612 Int_t idim[5]={0, 1, 2, 3, 4}; // {delta, theta-1,snp-2 ,z-3, phi-4}
2613 //
2614 // Int_t nbinsPhi=hisSector1->GetAxis(4)->GetNbins();
2615 Int_t firstPhi=hisSector1->GetAxis(4)->GetFirst();
2616 Int_t lastPhi =hisSector1->GetAxis(4)->GetLast();
2617 //
2618 for (Int_t ibinPhi=firstPhi; ibinPhi<=lastPhi; ibinPhi+=1){ //axis 4 - phi
2619 //
2620 // Phi loop
2621 //
2622 Double_t xPhi= hisSector1->GetAxis(4)->GetBinCenter(ibinPhi);
2623 Double_t psec = (9*xPhi/TMath::Pi());
2624 if (psec<0) psec+=18;
2625 Bool_t isOK0=kFALSE;
2626 Bool_t isOK1=kFALSE;
2627 if (TMath::Abs(psec-isec0%18-0.5)<1. || TMath::Abs(psec-isec0%18-17.5)<1.) isOK0=kTRUE;
2628 if (TMath::Abs(psec-isec1%18-0.5)<1. || TMath::Abs(psec-isec1%18-17.5)<1.) isOK1=kTRUE;
2629 if (!isOK0) continue;
2630 if (!isOK1) continue;
2631 //
2632 hisSector1->GetAxis(4)->SetRange(TMath::Max(ibinPhi-2,firstPhi),TMath::Min(ibinPhi+2,lastPhi));
2633 if (isec1!=isec0+36) {
2634 hisSector1->GetAxis(4)->SetRange(TMath::Max(ibinPhi-3,firstPhi),TMath::Min(ibinPhi+3,lastPhi));
2635 }
2636 //
2637 htemp = hisSector1->Projection(4);
2638 xPhi=htemp->GetMean();
2639 delete htemp;
2640 THnSparse * hisPhi = hisSector1->Projection(4,idim);
2641 //Int_t nbinsZ = hisPhi->GetAxis(3)->GetNbins();
2642 Int_t firstZ = hisPhi->GetAxis(3)->GetFirst();
2643 Int_t lastZ = hisPhi->GetAxis(3)->GetLast();
2644 //
2645 for (Int_t ibinZ=firstZ; ibinZ<=lastZ; ibinZ+=1){ // axis 3 - z
2646 //
2647 // Z loop
2648 //
2649 hisPhi->GetAxis(3)->SetRange(TMath::Max(ibinZ,firstZ),TMath::Min(ibinZ,lastZ));
2650 if (isec1!=isec0+36) {
2651 hisPhi->GetAxis(3)->SetRange(TMath::Max(ibinZ-1,firstZ),TMath::Min(ibinZ-1,lastZ));
2652 }
2653 htemp = hisPhi->Projection(3);
2654 Double_t xZ= htemp->GetMean();
2655 delete htemp;
2656 THnSparse * hisZ= hisPhi->Projection(3,idim);
2657 //projected histogram according selection 3 -z
2658 //
2659 //
2660 //Int_t nbinsSnp = hisZ->GetAxis(2)->GetNbins();
2661 Int_t firstSnp = hisZ->GetAxis(2)->GetFirst();
2662 Int_t lastSnp = hisZ->GetAxis(2)->GetLast();
2663 for (Int_t ibinSnp=firstSnp; ibinSnp<=lastSnp; ibinSnp+=2){ // axis 2 - snp
2664 //
2665 // Snp loop
2666 //
2667 hisZ->GetAxis(2)->SetRange(TMath::Max(ibinSnp-1,firstSnp),TMath::Min(ibinSnp+1,lastSnp));
2668 if (isec1!=isec0+36) {
2669 hisZ->GetAxis(2)->SetRange(TMath::Max(ibinSnp-2,firstSnp),TMath::Min(ibinSnp+2,lastSnp));
2670 }
2671 htemp = hisZ->Projection(2);
2672 Double_t xSnp= htemp->GetMean();
2673 delete htemp;
2674 THnSparse * hisSnp= hisZ->Projection(2,idim);
2675 //projected histogram according selection 2 - snp
2676
2677 //Int_t nbinsTheta = hisSnp->GetAxis(1)->GetNbins();
2678 Int_t firstTheta = hisSnp->GetAxis(1)->GetFirst();
2679 Int_t lastTheta = hisSnp->GetAxis(1)->GetLast();
2680 //
2681 for (Int_t ibinTheta=firstTheta; ibinTheta<=lastTheta; ibinTheta+=2){ // axis1 theta
2682
2683
2684 hisSnp->GetAxis(1)->SetRange(TMath::Max(ibinTheta-2,firstTheta),TMath::Min(ibinTheta+2,lastTheta));
2685 if (isec1!=isec0+36) {
2686 hisSnp->GetAxis(1)->SetRange(TMath::Max(ibinTheta-3,firstTheta),TMath::Min(ibinTheta+3,lastTheta));
2687 }
2688 htemp = hisSnp->Projection(1);
2689 Double_t xTheta=htemp->GetMean();
2690 delete htemp;
2691 hisDelta = hisSnp->Projection(0);
2692 //
2693 Double_t entries = hisDelta->GetEntries();
2694 Double_t mean=0, rms=0;
2695 if (entries>kMinEntries){
2696 mean = hisDelta->GetMean();
2697 rms = hisDelta->GetRMS();
2698 }
2699 Double_t sector = 9.*xPhi/TMath::Pi();
2700 if (sector<0) sector+=18;
2701 Double_t dsec = sector-Int_t(sector)-0.5;
2702 Int_t dtype=1; // TPC alignment type
2703 (*pcstream)<<hname<<
2704 "run="<<run<<
2705 "bz="<<bz<< // magnetic field
2706 "ptype="<<type<< // parameter type
2707 "dtype="<<dtype<< // parameter type
2708 "isec0="<<isec0<< // sector 0
2709 "isec1="<<isec1<< // sector 1
2710 "sector="<<sector<< // sector as float
2711 "dsec="<<dsec<< // delta sector
2712 //
2713 "theta="<<xTheta<< // theta
2714 "phi="<<xPhi<< // phi (alpha)
2715 "z="<<xZ<< // z
2716 "snp="<<xSnp<< // snp
2717 //
2718 "entries="<<entries<< // entries in bin
2719 "mean="<<mean<< // mean
2720 "rms="<<rms<< // rms
2721 "refX="<<refX<< // track matching reference plane
2722 "\n";
2723 delete hisDelta;
2724 printf("%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f\n",isec0, isec1, xPhi,xZ,xSnp, xTheta, entries,mean);
2725 //
2726 }//ibinTheta
2727 delete hisSnp;
2728 } //ibinSnp
2729 delete hisZ;
2730 }//ibinZ
2731 delete hisPhi;
2732 }//ibinPhi
2733 delete hisSector1;
2734 }//isec1
2735 delete hisSector0;
2736 }//isec0
8b63d99c 2737}
2738
2739
2740
2741
2742
cfe2c39a 2743
2744
ffab0c37 2745void AliTPCCorrection::StoreInOCDB(Int_t startRun, Int_t endRun, const char *comment){
2746 //
2747 // Store object in the OCDB
2748 // By default the object is stored in the current directory
2749 // default comment consit of user name and the date
2750 //
2751 TString ocdbStorage="";
2752 ocdbStorage+="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
2753 AliCDBMetaData *metaData= new AliCDBMetaData();
2754 metaData->SetObjectClassName("AliTPCCorrection");
2755 metaData->SetResponsible("Marian Ivanov");
2756 metaData->SetBeamPeriod(1);
2757 metaData->SetAliRootVersion("05-25-01"); //root version
2758 TString userName=gSystem->GetFromPipe("echo $USER");
2759 TString date=gSystem->GetFromPipe("date");
2760
2761 if (!comment) metaData->SetComment(Form("Space point distortion calibration\n User: %s\n Data%s",userName.Data(),date.Data()));
2762 if (comment) metaData->SetComment(comment);
2763 AliCDBId* id1=NULL;
2764 id1=new AliCDBId("TPC/Calib/Correction", startRun, endRun);
2765 AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
2766 gStorage->Put(this, (*id1), metaData);
2767}
2768
ca58ed4e 2769
7d85e147 2770void AliTPCCorrection::FastSimDistortedVertex(Double_t orgVertex[3], Int_t nTracks, AliESDVertex &aV, AliESDVertex &avOrg, AliESDVertex &cV, AliESDVertex &cvOrg, TTreeSRedirector * const pcstream, Double_t etaCuts){
c9cbd2f2 2771 //
2772 // Fast method to simulate the influence of the given distortion on the vertex reconstruction
2773 //
ca58ed4e 2774
c9cbd2f2 2775 AliMagF* magF= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
2776 if (!magF) AliError("Magneticd field - not initialized");
2777 Double_t bz = magF->SolenoidField(); //field in kGauss
9f3b99e2 2778 printf("bz: %f\n",bz);
c9cbd2f2 2779 AliVertexerTracks *vertexer = new AliVertexerTracks(bz); // bz in kGauss
ca58ed4e 2780
c9cbd2f2 2781 TObjArray aTrk; // Original Track array of Aside
2782 TObjArray daTrk; // Distorted Track array of A side
2783 UShort_t *aId = new UShort_t[nTracks]; // A side Track ID
2784 TObjArray cTrk;
2785 TObjArray dcTrk;
2786 UShort_t *cId = new UShort_t [nTracks];
2787 Int_t id=0;
ca58ed4e 2788 Double_t mass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
7d85e147 2789 TF1 fpt("fpt",Form("x*(1+(sqrt(x*x+%f^2)-%f)/([0]*[1]))^(-[0])",mass,mass),0.4,10);
ca58ed4e 2790 fpt.SetParameters(7.24,0.120);
2791 fpt.SetNpx(10000);
2792 for(Int_t nt=0; nt<nTracks; nt++){
2793 Double_t phi = gRandom->Uniform(0.0, 2*TMath::Pi());
7d85e147 2794 Double_t eta = gRandom->Uniform(-etaCuts, etaCuts);
c9cbd2f2 2795 Double_t pt = fpt.GetRandom(); // momentum for f1
2796 // printf("phi %lf eta %lf pt %lf\n",phi,eta,pt);
ca58ed4e 2797 Short_t sign=1;
2798 if(gRandom->Rndm() < 0.5){
2799 sign =1;
2800 }else{
2801 sign=-1;
2802 }
2803
2804 Double_t theta = 2*TMath::ATan(TMath::Exp(-eta))-TMath::Pi()/2.;
2805 Double_t pxyz[3];
2806 pxyz[0]=pt*TMath::Cos(phi);
2807 pxyz[1]=pt*TMath::Sin(phi);
2808 pxyz[2]=pt*TMath::Tan(theta);
2809 Double_t cv[21]={0};
2810 AliExternalTrackParam *t= new AliExternalTrackParam(orgVertex, pxyz, cv, sign);
2811
2812 Double_t refX=1.;
2813 Int_t dir=-1;
2814 AliExternalTrackParam *td = FitDistortedTrack(*t, refX, dir, NULL);
2815 if (!td) continue;
2816 if (pcstream) (*pcstream)<<"track"<<
2817 "eta="<<eta<<
2818 "theta="<<theta<<
2819 "tOrig.="<<t<<
2820 "td.="<<td<<
2821 "\n";
7d85e147 2822 if(( eta>0.07 )&&( eta<etaCuts )) { // - log(tan(0.5*theta)), theta = 0.5*pi - ATan(5.0/80.0)
ca58ed4e 2823 if (td){
c9cbd2f2 2824 daTrk.AddLast(td);
2825 aTrk.AddLast(t);
2826 Int_t nn=aTrk.GetEntriesFast();
2827 aId[nn]=id;
ca58ed4e 2828 }
7d85e147 2829 }else if(( eta<-0.07 )&&( eta>-etaCuts )){
ca58ed4e 2830 if (td){
c9cbd2f2 2831 dcTrk.AddLast(td);
2832 cTrk.AddLast(t);
2833 Int_t nn=cTrk.GetEntriesFast();
2834 cId[nn]=id;
ca58ed4e 2835 }
2836 }
c9cbd2f2 2837 id++;
ca58ed4e 2838 }// end of track loop
2839
2840 vertexer->SetTPCMode();
2841 vertexer->SetConstraintOff();
2842
c9cbd2f2 2843 aV = *((AliESDVertex*)vertexer->FindPrimaryVertex(&daTrk,aId));
2844 avOrg = *((AliESDVertex*)vertexer->FindPrimaryVertex(&aTrk,aId));
2845 cV = *((AliESDVertex*)vertexer->FindPrimaryVertex(&dcTrk,cId));
2846 cvOrg = *((AliESDVertex*)vertexer->FindPrimaryVertex(&cTrk,cId));
ca58ed4e 2847 if (pcstream) (*pcstream)<<"vertex"<<
2848 "x="<<orgVertex[0]<<
2849 "y="<<orgVertex[1]<<
2850 "z="<<orgVertex[2]<<
2851 "av.="<<&aV<< // distorted vertex A side
2852 "cv.="<<&cV<< // distroted vertex C side
2853 "avO.="<<&avOrg<< // original vertex A side
2854 "cvO.="<<&cvOrg<<
2855 "\n";
c9cbd2f2 2856 delete []aId;
2857 delete []cId;
ca58ed4e 2858}
f1817479 2859
2860void AliTPCCorrection::AddVisualCorrection(AliTPCCorrection* corr, Int_t position){
2861 //
2862 // make correction available for visualization using
2863 // TFormula, TFX and TTree::Draw
2864 // important in order to check corrections and also compute dervied variables
2865 // e.g correction partial derivatives
2866 //
2867 // NOTE - class is not owner of correction
2868 //
cfe2c39a 2869 if (!fgVisualCorrection) fgVisualCorrection=new TObjArray(10000);
2870 if (position>=fgVisualCorrection->GetEntriesFast())
2871 fgVisualCorrection->Expand((position+10)*2);
f1817479 2872 fgVisualCorrection->AddAt(corr, position);
2873}
2874
2875
2876
287fbdfa 2877Double_t AliTPCCorrection::GetCorrSector(Double_t sector, Double_t r, Double_t kZ, Int_t axisType, Int_t corrType){
f1817479 2878 //
2879 // calculate the correction at given position - check the geffCorr
2880 //
cfe2c39a 2881 // corrType return values
2882 // 0 - delta R
2883 // 1 - delta RPhi
2884 // 2 - delta Z
2885 // 3 - delta RPHI
2886 //
f1817479 2887 if (!fgVisualCorrection) return 0;
2888 AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
2889 if (!corr) return 0;
25732bff 2890
f1817479 2891 Double_t phi=sector*TMath::Pi()/9.;
287fbdfa 2892 Double_t gx = r*TMath::Cos(phi);
2893 Double_t gy = r*TMath::Sin(phi);
2894 Double_t gz = r*kZ;
f1817479 2895 Int_t nsector=(gz>0) ? 0:18;
2896 //
2897 //
2898 //
2899 Float_t distPoint[3]={gx,gy,gz};
2900 corr->DistortPoint(distPoint, nsector);
2901 Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
2902 Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
2903 Double_t phi0=TMath::ATan2(gy,gx);
2904 Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
2905 if (axisType==0) return r1-r0;
2906 if (axisType==1) return (phi1-phi0)*r0;
2907 if (axisType==2) return distPoint[2]-gz;
cfe2c39a 2908 if (axisType==3) return (TMath::Cos(phi)*(distPoint[0]-gx)+ TMath::Cos(phi)*(distPoint[1]-gy));
f1817479 2909 return phi1-phi0;
2910}
2911
2912Double_t AliTPCCorrection::GetCorrXYZ(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType){
2913 //
2914 // return correction at given x,y,z
2915 //
2916 if (!fgVisualCorrection) return 0;
2917 AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
2918 if (!corr) return 0;
2919 Double_t phi0= TMath::ATan2(gy,gx);
2920 Int_t nsector=(gz>0) ? 0:18;
2921 Float_t distPoint[3]={gx,gy,gz};
2922 corr->DistortPoint(distPoint, nsector);
2923 Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
2924 Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
2925 Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
2926 if (axisType==0) return r1-r0;
2927 if (axisType==1) return (phi1-phi0)*r0;
2928 if (axisType==2) return distPoint[2]-gz;
2929 return phi1-phi0;
2930}
46e89793 2931
fdbbc146 2932Double_t AliTPCCorrection::GetCorrXYZDz(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType,Double_t delta){
2933 //
2934 // return correction at given x,y,z
2935 //
2936 if (!fgVisualCorrection) return 0;
2937 AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
2938 if (!corr) return 0;
2939 Double_t phi0= TMath::ATan2(gy,gx);
2940 Int_t nsector=(gz>0) ? 0:18;
2941 Float_t distPoint[3]={gx,gy,gz};
2942 Float_t dxyz[3]={gx,gy,gz};
2943 //
2944 corr->GetCorrectionDz(distPoint, nsector,dxyz,delta);
2945 distPoint[0]-=dxyz[0];
2946 distPoint[1]-=dxyz[1];
2947 distPoint[2]-=dxyz[2];
2948 Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
2949 Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
2950 Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
2951 if (axisType==0) return r1-r0;
2952 if (axisType==1) return (phi1-phi0)*r0;
2953 if (axisType==2) return distPoint[2]-gz;
2954 return phi1-phi0;
2955}
2956
2957Double_t AliTPCCorrection::GetCorrXYZIntegrateZ(Double_t gx, Double_t gy, Double_t gz, Int_t axisType, Int_t corrType,Double_t delta){
2958 //
2959 // return correction at given x,y,z
2960 //
2961 if (!fgVisualCorrection) return 0;
2962 AliTPCCorrection *corr = (AliTPCCorrection*)fgVisualCorrection->At(corrType);
2963 if (!corr) return 0;
2964 Double_t phi0= TMath::ATan2(gy,gx);
2965 Int_t nsector=(gz>0) ? 0:18;
2966 Float_t distPoint[3]={gx,gy,gz};
2967 Float_t dxyz[3]={gx,gy,gz};
2968 //
2969 corr->GetCorrectionIntegralDz(distPoint, nsector,dxyz,delta);
2970 distPoint[0]-=dxyz[0];
2971 distPoint[1]-=dxyz[1];
2972 distPoint[2]-=dxyz[2];
2973 Double_t r0=TMath::Sqrt(gx*gx+gy*gy);
2974 Double_t r1=TMath::Sqrt(distPoint[0]*distPoint[0]+distPoint[1]*distPoint[1]);
2975 Double_t phi1=TMath::ATan2(distPoint[1],distPoint[0]);
2976 if (axisType==0) return r1-r0;
2977 if (axisType==1) return (phi1-phi0)*r0;
2978 if (axisType==2) return distPoint[2]-gz;
2979 return phi1-phi0;
2980}
2981
46e89793 2982
2983
2984
2985
284418bc 2986void AliTPCCorrection::MakeLaserDistortionTree(TTree* tree, TObjArray */*corrArray*/, Int_t /*itype*/){
46e89793 2987 //
2988 // Make a laser fit tree for global minimization
2989 //
2990 AliTPCcalibDB* calib=AliTPCcalibDB::Instance();
2991 AliTPCCorrection * correction = calib->GetTPCComposedCorrection();
2992 if (!correction) correction = calib->GetTPCComposedCorrection(AliTrackerBase::GetBz());
2993 correction->AddVisualCorrection(correction,0); //register correction
2994
284418bc 2995 // AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
2996 //AliTPCParam *param = AliTPCcalibDB::Instance()->GetParameters();
46e89793 2997 //
2998 const Double_t cutErrY=0.05;
2999 const Double_t kSigmaCut=4;
3000 // const Double_t cutErrZ=0.03;
3001 const Double_t kEpsilon=0.00000001;
284418bc 3002 // const Double_t kMaxDist=1.; // max distance - space correction
46e89793 3003 TVectorD *vecdY=0;
3004 TVectorD *vecdZ=0;
3005 TVectorD *veceY=0;
3006 TVectorD *veceZ=0;
3007 AliTPCLaserTrack *ltr=0;
3008 AliTPCLaserTrack::LoadTracks();
3009 tree->SetBranchAddress("dY.",&vecdY);
3010 tree->SetBranchAddress("dZ.",&vecdZ);
3011 tree->SetBranchAddress("eY.",&veceY);
3012 tree->SetBranchAddress("eZ.",&veceZ);
3013 tree->SetBranchAddress("LTr.",&ltr);
3014 Int_t entries= tree->GetEntries();
3015 TTreeSRedirector *pcstream= new TTreeSRedirector("distortionLaser_0.root");
3016 Double_t bz=AliTrackerBase::GetBz();
3017 //
284418bc 3018 // Double_t globalXYZ[3];
3019 //Double_t globalXYZCorr[3];
46e89793 3020 for (Int_t ientry=0; ientry<entries; ientry++){
3021 tree->GetEntry(ientry);
3022 if (!ltr->GetVecGX()){
3023 ltr->UpdatePoints();
3024 }
3025 //
3026 TVectorD fit10(5);
3027 TVectorD fit5(5);
3028 printf("Entry\t%d\n",ientry);
3029 for (Int_t irow0=0; irow0<158; irow0+=1){
3030 //
3031 TLinearFitter fitter10(4,"hyp3");
3032 TLinearFitter fitter5(2,"hyp1");
3033 Int_t sector= (Int_t)(*ltr->GetVecSec())[irow0];
3034 if (sector<0) continue;
3035 //if (TMath::Abs(vecdY->GetMatrixArray()[irow0])<kEpsilon) continue;
3036
3037 Double_t refX= (*ltr->GetVecLX())[irow0];
3038 Int_t firstRow1 = TMath::Max(irow0-10,0);
3039 Int_t lastRow1 = TMath::Min(irow0+10,158);
3040 Double_t padWidth=(irow0<64)?0.4:0.6;
3041 // make long range fit
3042 for (Int_t irow1=firstRow1; irow1<=lastRow1; irow1++){
3043 if (TMath::Abs((*ltr->GetVecSec())[irow1]-sector)>kEpsilon) continue;
3044 if (veceY->GetMatrixArray()[irow1]>cutErrY) continue;
3045 if (TMath::Abs(vecdY->GetMatrixArray()[irow1])<kEpsilon) continue;
3046 Double_t idealX= (*ltr->GetVecLX())[irow1];
3047 Double_t idealY= (*ltr->GetVecLY())[irow1];
284418bc 3048 // Double_t idealZ= (*ltr->GetVecLZ())[irow1];
46e89793 3049 Double_t gx= (*ltr->GetVecGX())[irow1];
3050 Double_t gy= (*ltr->GetVecGY())[irow1];
3051 Double_t gz= (*ltr->GetVecGZ())[irow1];
3052 Double_t measY=(*vecdY)[irow1]+idealY;
3053 Double_t deltaR = GetCorrXYZ(gx, gy, gz, 0,0);
3054 // deltaR = R distorted -R ideal
3055 Double_t xxx[4]={idealX+deltaR-refX,TMath::Cos(idealY/padWidth), TMath::Sin(idealY/padWidth)};
3056 fitter10.AddPoint(xxx,measY,1);
3057 }
3058 Bool_t isOK=kTRUE;
3059 Double_t rms10=0;//TMath::Sqrt(fitter10.GetChisquare()/(fitter10.GetNpoints()-4));
3060 Double_t mean10 =0;// fitter10.GetParameter(0);
3061 Double_t slope10 =0;// fitter10.GetParameter(0);
3062 Double_t cosPart10 = 0;// fitter10.GetParameter(2);
3063 Double_t sinPart10 =0;// fitter10.GetParameter(3);
3064
3065 if (fitter10.GetNpoints()>10){
3066 fitter10.Eval();
3067 rms10=TMath::Sqrt(fitter10.GetChisquare()/(fitter10.GetNpoints()-4));
3068 mean10 = fitter10.GetParameter(0);
3069 slope10 = fitter10.GetParameter(1);
3070 cosPart10 = fitter10.GetParameter(2);
3071 sinPart10 = fitter10.GetParameter(3);
3072 //
3073 // make short range fit
3074 //
3075 for (Int_t irow1=firstRow1+5; irow1<=lastRow1-5; irow1++){
3076 if (TMath::Abs((*ltr->GetVecSec())[irow1]-sector)>kEpsilon) continue;
3077 if (veceY->GetMatrixArray()[irow1]>cutErrY) continue;
3078 if (TMath::Abs(vecdY->GetMatrixArray()[irow1])<kEpsilon) continue;
3079 Double_t idealX= (*ltr->GetVecLX())[irow1];
3080 Double_t idealY= (*ltr->GetVecLY())[irow1];
284418bc 3081 // Double_t idealZ= (*ltr->GetVecLZ())[irow1];
46e89793 3082 Double_t gx= (*ltr->GetVecGX())[irow1];
3083 Double_t gy= (*ltr->GetVecGY())[irow1];
3084 Double_t gz= (*ltr->GetVecGZ())[irow1];
3085 Double_t measY=(*vecdY)[irow1]+idealY;
3086 Double_t deltaR = GetCorrXYZ(gx, gy, gz, 0,0);
3087 // deltaR = R distorted -R ideal
3088 Double_t expY= mean10+slope10*(idealX+deltaR-refX);
3089 if (TMath::Abs(measY-expY)>kSigmaCut*rms10) continue;
3090 //
3091 Double_t corr=cosPart10*TMath::Cos(idealY/padWidth)+sinPart10*TMath::Sin(idealY/padWidth);
3092 Double_t xxx[4]={idealX+deltaR-refX,TMath::Cos(idealY/padWidth), TMath::Sin(idealY/padWidth)};
3093 fitter5.AddPoint(xxx,measY-corr,1);
3094 }
3095 }else{
3096 isOK=kFALSE;
3097 }
3098 if (fitter5.GetNpoints()<8) isOK=kFALSE;
3099
3100 Double_t rms5=0;//TMath::Sqrt(fitter5.GetChisquare()/(fitter5.GetNpoints()-4));
3101 Double_t offset5 =0;// fitter5.GetParameter(0);
3102 Double_t slope5 =0;// fitter5.GetParameter(0);
3103 if (isOK){
3104 fitter5.Eval();
3105 rms5=TMath::Sqrt(fitter5.GetChisquare()/(fitter5.GetNpoints()-4));
3106 offset5 = fitter5.GetParameter(0);
3107 slope5 = fitter5.GetParameter(0);
3108 }
3109 //
3110 Double_t dtype=5;
3111 Double_t ptype=0;
3112 Double_t phi =(*ltr->GetVecPhi())[irow0];
3113 Double_t theta =ltr->GetTgl();
3114 Double_t mean=(vecdY)->GetMatrixArray()[irow0];
3115 Double_t gx=0,gy=0,gz=0;
3116 Double_t snp = (*ltr->GetVecP2())[irow0];
3117 Int_t bundle= ltr->GetBundle();
3118 Int_t id= ltr->GetId();
3119 // Double_t rms = err->GetMatrixArray()[irow];
3120 //
3121 gx = (*ltr->GetVecGX())[irow0];
3122 gy = (*ltr->GetVecGY())[irow0];
3123 gz = (*ltr->GetVecGZ())[irow0];
3124 Double_t dRrec = GetCorrXYZ(gx, gy, gz, 0,0);
3125 fitter10.GetParameters(fit10);
3126 fitter5.GetParameters(fit5);
3127 Double_t idealY= (*ltr->GetVecLY())[irow0];
3128 Double_t measY=(*vecdY)[irow0]+idealY;
3129 Double_t corr=cosPart10*TMath::Cos(idealY/padWidth)+sinPart10*TMath::Sin(idealY/padWidth);
3130 if (TMath::Max(rms5,rms10)>0.06) isOK=kFALSE;
3131 //
3132 (*pcstream)<<"fitFull"<< // dumpe also intermediate results
3133 "bz="<<bz<< // magnetic filed used
3134 "dtype="<<dtype<< // detector match type
3135 "ptype="<<ptype<< // parameter type
3136 "theta="<<theta<< // theta
3137 "phi="<<phi<< // phi
3138 "snp="<<snp<< // snp
3139 "sector="<<sector<<
3140 "bundle="<<bundle<<
3141// // "dsec="<<dsec<<
3142 "refX="<<refX<< // reference radius
3143 "gx="<<gx<< // global position
3144 "gy="<<gy<< // global position
3145 "gz="<<gz<< // global position
3146 "dRrec="<<dRrec<< // delta Radius in reconstruction
3147 "id="<<id<< //bundle
3148 "rms10="<<rms10<<
3149 "rms5="<<rms5<<
3150 "fit10.="<<&fit10<<
3151 "fit5.="<<&fit5<<
3152 "measY="<<measY<<
3153 "mean="<<mean<<
3154 "idealY="<<idealY<<
3155 "corr="<<corr<<
3156 "isOK="<<isOK<<
3157 "\n";
3158 }
3159 }
3160 delete pcstream;
3161}