3 //#include "TTreeStream.h"
5 #include "TLinearFitter.h"
6 #include "AliTPCcalibDB.h"
10 // Abstract class for ExB effect parameterization
14 // The ExB correction map is stored in the calib DB
15 // The lookup can be dumped to the tree:
19 char *storage = "local://OCDBres"
21 AliCDBManager::Instance()->SetDefaultStorage(storage);
22 AliCDBManager::Instance()->SetRun(RunNumber)
23 AliTPCExBFirst * exb = AliTPCcalibDB::Instance()->GetExB();
25 // See example macro $ALICE_ROOT/TPC/macros/AliTPCExBdraw.C
27 .L $ALICE_ROOT/TPC/macros/AliTPCExBdraw.C
35 AliTPCExB* AliTPCExB::fgInstance = 0;
37 TObjArray AliTPCExB::fgArray;
43 AliTPCExB::AliTPCExB():
45 fMatBrBz(0), //param matrix Br/Bz
46 fMatBrfiBz(0), //param matrix Br/Bz
47 fMatBrBzI0(0), //param matrix Br/Bz integral z>0
48 fMatBrBzI1(0), //param matrix Br/Bz integral z<0
49 fMatBrfiBzI0(0), //param matrix Br/Bz integral z>0
50 fMatBrfiBzI1(0) //param matrix Br/Bz integral z<0
53 // default constructor
57 AliTPCExB::AliTPCExB(const AliTPCExB& exb):
59 fMatBrBz(new TVectorD(*(exb.fMatBrBz))), //param matrix Br/Bz
60 fMatBrfiBz(new TVectorD(*(exb.fMatBrfiBz))), //param matrix Br/Bz
61 fMatBrBzI0(new TVectorD(*(exb.fMatBrBzI0))), //param matrix Br/Bz integral z>0
62 fMatBrBzI1(new TVectorD(*(exb.fMatBrBzI1))), //param matrix Br/Bz integral z<0
63 fMatBrfiBzI0(new TVectorD(*(exb.fMatBrfiBzI0))), //param matrix Br/Bz integral z>0
64 fMatBrfiBzI1(new TVectorD(*(exb.fMatBrfiBzI1))) //param matrix Br/Bz integral z<0
71 AliTPCExB& AliTPCExB::operator=(const AliTPCExB &/*exb*/)
82 void AliTPCExB::TestExB(const char* fileName) {
85 // Dump the filed and corrections to the tree in file fileName
88 TTreeSRedirector ts(fileName);
90 for (x[0]=-250.;x[0]<=250.;x[0]+=10.)
91 for (x[1]=-250.;x[1]<=250.;x[1]+=10.)
92 for (x[2]=-250.;x[2]<=250.;x[2]+=20.) {
93 Double_t r=TMath::Sqrt(x[0]*x[0]+x[1]*x[1]);
99 Double_t rd=TMath::Sqrt(d[0]*d[0]+d[1]*d[1]);
101 Double_t phi=TMath::ATan2(x[1],x[0]);
102 Double_t phid=TMath::ATan2(d[1],d[0]);
103 Double_t dphi=phi-phid;
104 if (dphi<0.) dphi+=TMath::TwoPi();
105 if (dphi>TMath::Pi()) dphi=TMath::TwoPi()-dphi;
106 Double_t drphi=r*dphi;
107 Double_t dx=x[0]-d[0];
108 Double_t dy=x[1]-d[1];
109 Double_t dz=x[2]-d[2];
111 Double_t bx = GetBx(r,phi,z,0);
112 Double_t by = GetBy(r,phi,z,0);
113 Double_t bz = GetBz(r,phi,z,0);
114 Double_t br = GetBr(r,phi,z,0);
115 Double_t brfi = GetBrfi(r,phi,z,0);
117 Double_t bxi = GetBxI(r,phi,z,0);
118 Double_t byi = GetByI(r,phi,z,0);
119 Double_t bzi = GetBzI(r,phi,z,0);
120 Double_t bri = GetBrI(r,phi,z,0);
121 Double_t brfii = GetBrfiI(r,phi,z,0);
154 Double_t AliTPCExB::GetDr(Double_t r, Double_t phi, Double_t z, Double_t bz){
157 // Posibble to us it for visualization
160 AliTPCExB *exb = Instance();
161 if (!exb) exb = AliTPCcalibDB::GetExB(bz,kFALSE);
163 Double_t pos0[3] = {r*TMath::Cos(phi), r*TMath::Sin(phi),z};
165 exb->Correct(pos0,pos1);
166 Double_t dx=pos1[0]-pos0[0];
167 Double_t dy=pos1[1]-pos0[1];
168 // Double_t dz=pos1[2]-pos0[2];
169 // return TMath::Sqrt(dx*dx+dy*dy);
170 Float_t dr = (dx*pos0[0]+dy*pos0[1])/r;
175 Double_t AliTPCExB::GetDrphi(Double_t r, Double_t phi, Double_t z, Double_t bz){
179 AliTPCExB *exb = Instance();
180 if (!exb) exb = AliTPCcalibDB::GetExB(bz,kFALSE);
182 Double_t pos0[3] = {r*TMath::Cos(phi), r*TMath::Sin(phi),z};
184 exb->Correct(pos0,pos1);
185 Double_t dphi=TMath::ATan2(pos1[1],pos1[0])-TMath::ATan2(pos0[1],pos0[0]);
186 if (dphi>TMath::Pi()) dphi-=TMath::TwoPi();
187 if (dphi<-TMath::Pi()) dphi+=TMath::TwoPi();
193 Double_t AliTPCExB::GetDphi(Double_t r, Double_t phi, Double_t z, Double_t bz){
197 AliTPCExB *exb = Instance();
198 if (!exb) exb = AliTPCcalibDB::GetExB(bz,kFALSE);
200 Double_t pos0[3] = {r*TMath::Cos(phi), r*TMath::Sin(phi),z};
202 exb->Correct(pos0,pos1);
203 Double_t dphi=TMath::ATan2(pos1[1],pos1[0])-TMath::ATan2(pos0[1],pos0[0]);
208 Double_t AliTPCExB::GetDz(Double_t r, Double_t phi, Double_t z, Double_t bz){
212 AliTPCExB *exb = Instance();
213 if (!exb) exb = AliTPCcalibDB::GetExB(bz,kFALSE);
215 Double_t pos0[3] = {r*TMath::Cos(phi), r*TMath::Sin(phi),z};
217 exb->Correct(pos0,pos1);
218 Double_t dz=pos1[2]-pos0[2];
229 void AliTPCExB::RegisterField(Int_t index, AliMagF * magf){
231 // add the filed to the list
233 fgArray.AddAt(magf,index);
238 Double_t AliTPCExB::GetBx(Double_t r, Double_t phi, Double_t z,Int_t index){
242 AliMagF *mag = (AliMagF*)fgArray.At(index);
244 Double_t xyz[3]={r*TMath::Cos(phi),r*TMath::Sin(phi),z};
247 mag->Field(xyz,bxyz);
251 Double_t AliTPCExB::GetBy(Double_t r, Double_t phi, Double_t z,Int_t index){
255 AliMagF *mag = (AliMagF*)fgArray.At(index);
257 Double_t xyz[3]={r*TMath::Cos(phi),r*TMath::Sin(phi),z};
260 mag->Field(xyz,bxyz);
264 Double_t AliTPCExB::GetBz(Double_t r, Double_t phi, Double_t z,Int_t index){
268 AliMagF *mag = (AliMagF*)fgArray.At(index);
270 Double_t xyz[3]={r*TMath::Cos(phi),r*TMath::Sin(phi),z};
273 mag->Field(xyz,bxyz);
279 Double_t AliTPCExB::GetBr(Double_t r, Double_t phi, Double_t z,Int_t index){
283 AliMagF *mag = (AliMagF*)fgArray.At(index);
285 Double_t xyz[3]={r*TMath::Cos(phi),r*TMath::Sin(phi),z};
288 mag->Field(xyz,bxyz);
290 Double_t br = (bxyz[0]*xyz[0]+bxyz[1]*xyz[1])/r;
294 Double_t AliTPCExB::GetBrfi(Double_t r, Double_t phi, Double_t z,Int_t index){
298 AliMagF *mag = (AliMagF*)fgArray.At(index);
300 Double_t xyz[3]={r*TMath::Cos(phi),r*TMath::Sin(phi),z};
303 mag->Field(xyz,bxyz);
305 Double_t br = (-bxyz[0]*xyz[1]+bxyz[1]*xyz[0])/r;
312 Double_t AliTPCExB::GetBxI(Double_t r, Double_t phi, Double_t z,Int_t index)
316 for (Float_t zi=z;zi<250;zi+=5){
317 sumf+=GetBx(r,phi,zi,index)/GetBz(r,phi,zi,index);
321 for (Float_t zi=z;zi>-250;zi-=5){
322 sumf+=GetBx(r,phi,zi,index)/GetBz(r,phi,zi,index);
328 Double_t AliTPCExB::GetByI(Double_t r, Double_t phi, Double_t z,Int_t index)
332 for (Float_t zi=z;zi<250;zi+=5){
333 sumf+=GetBy(r,phi,zi,index)/GetBz(r,phi,zi,index);
337 for (Float_t zi=z;zi>-250;zi-=5){
338 sumf+=GetBy(r,phi,zi,index)/GetBz(r,phi,zi,index);
344 Double_t AliTPCExB::GetBzI(Double_t r, Double_t phi, Double_t z,Int_t index)
348 for (Float_t zi=z;zi<250;zi+=5){
349 sumf+=GetBz(r,phi,zi,index);
353 for (Float_t zi=z;zi>-250;zi-=5){
354 sumf+=GetBz(r,phi,zi,index);
361 Double_t AliTPCExB::GetBrI(Double_t r, Double_t phi, Double_t z,Int_t index)
365 for (Float_t zi=z;zi<250;zi+=5){
366 sumf+=GetBr(r,phi,zi,index)/GetBz(r,phi,zi,index);
370 for (Float_t zi=z;zi>-250;zi-=5){
371 sumf+=GetBr(r,phi,zi,index)/GetBz(r,phi,zi,index);
377 Double_t AliTPCExB::GetBrfiI(Double_t r, Double_t phi, Double_t z,Int_t index)
381 for (Float_t zi=z;zi<250;zi+=5.){
382 sumf+=GetBrfi(r,phi,zi,index)/GetBz(r,phi,zi,index);
386 for (Float_t zi=z;zi>-250;zi-=5){
387 sumf+=GetBrfi(r,phi,zi,index)/GetBz(r,phi,zi,index);
394 Double_t AliTPCExB::Eval(Int_t type, Double_t r, Double_t phi, Double_t z){
396 // Evaluate parameterization
400 if (z>0 && fMatBrBzI0) return EvalMat(*fMatBrBzI0,r,phi,z);
401 if (z<0 && fMatBrBzI1) return EvalMat(*fMatBrBzI1,r,phi,z);
403 // brfi integral param
405 if (z>0 && fMatBrfiBzI0) return EvalMat(*fMatBrfiBzI0,r,phi,z);
406 if (z<0 && fMatBrfiBzI1) return EvalMat(*fMatBrfiBzI1,r,phi,z);
409 if (type==2 && fMatBrBz) return EvalMat(*fMatBrBz,r,phi,z);
411 if (type==3 && fMatBrfiBz) return EvalMat(*fMatBrfiBz,r,phi,z);
416 Double_t AliTPCExB::EvalMat(const TVectorD &vec, Double_t r, Double_t phi, Double_t z){
418 // Evaluate taylor expansion in r,phi,z
421 //tree->SetAlias("sa","sin(phi+0.0)");
422 //tree->SetAlias("ca","cos(phi+0.0)");
423 //tree->SetAlias("sa2","sin(phi*2+0.0)");
424 //tree->SetAlias("ca2","cos(phi*2+0.0)");
425 //tree->SetAlias("zn","(x2/250.)");
426 //tree->SetAlias("rn","(r/250.)")
427 // TString fstringSym="";
429 // fstringSym+="zn++";
430 // fstringSym+="rn++";
431 // fstringSym+="zn*rn++";
432 // fstringSym+="zn*zn++";
433 // fstringSym+="zn*zn*rn++";
434 // fstringSym+="zn*rn*rn++";
436 // fstringSym+="sa++";
437 // fstringSym+="ca++";
438 // fstringSym+="ca2++";
439 // fstringSym+="sa2++";
440 // fstringSym+="ca*zn++";
441 // fstringSym+="sa*zn++";
442 // fstringSym+="ca2*zn++";
443 // fstringSym+="sa2*zn++";
444 // fstringSym+="ca*zn*zn++";
445 // fstringSym+="sa*zn*zn++";
446 // fstringSym+="ca*zn*rn++";
447 // fstringSym+="sa*zn*rn++";
450 Double_t sa = TMath::Sin(phi);
451 Double_t ca = TMath::Cos(phi);
452 Double_t sa2 = TMath::Sin(phi*2);
453 Double_t ca2 = TMath::Cos(phi*2);
454 Double_t zn = z/250.;
455 Double_t rn = r/250.;
457 Double_t res = vec[ipoint++];
458 res+=vec[ipoint++]*zn;
459 res+=vec[ipoint++]*rn;
460 res+=vec[ipoint++]*zn*rn;
461 res+=vec[ipoint++]*zn*zn;
462 res+=vec[ipoint++]*zn*zn*rn;
463 res+=vec[ipoint++]*zn*rn*rn;
465 res+=vec[ipoint++]*sa;
466 res+=vec[ipoint++]*ca;
467 res+=vec[ipoint++]*ca2;
468 res+=vec[ipoint++]*sa2;
469 res+=vec[ipoint++]*ca*zn;
470 res+=vec[ipoint++]*sa*zn;
471 res+=vec[ipoint++]*ca2*zn;
472 res+=vec[ipoint++]*sa2*zn;
473 res+=vec[ipoint++]*ca*zn*zn;
474 res+=vec[ipoint++]*sa*zn*zn;
475 res+=vec[ipoint++]*ca*zn*rn;
476 res+=vec[ipoint++]*sa*zn*rn;
496 draw.RegisterField(0,new AliMagWrapCheb("Maps","Maps", 2, 1., 10., AliMagWrapCheb::k5kG));
497 draw.RegisterField(1,new AliMagFMaps("Maps","Maps", 2, 1., 10., 2));
499 TF2 fbz_rz_0pi("fbz_rz_0pi","AliTPCExB::GetBz(x,0*pi,y)",0,250,-250,250);
500 fbz_rz_0pi->Draw("surf2");
502 TF1 fbz_z_90_00pi("fbz_z_90_00pi","AliTPCExB::GetBz(90,0*pi,x)",-250,250);
503 TF1 fbz_z_90_05pi("fbz_z_90_05pi","AliTPCExB::GetBz(90,0.5*pi,x)",-250,250);
504 TF1 fbz_z_90_10pi("fbz_z_90_10pi","AliTPCExB::GetBz(90,1.0*pi,x)",-250,250);
505 TF1 fbz_z_90_15pi("fbz_z_90_15pi","AliTPCExB::GetBz(90,1.5*pi,x)",-250,250);
506 fbz_z_90_00pi->SetLineColor(2);
507 fbz_z_90_05pi->SetLineColor(3);
508 fbz_z_90_10pi->SetLineColor(4);
509 fbz_z_90_15pi->SetLineColor(5);
510 fbz_z_90_00pi->Draw()
511 fbz_z_90_05pi->Draw("same")
512 fbz_z_90_15pi->Draw("same")
513 fbz_z_90_10pi->Draw("same")
516 TF1 fbr_z_90_00pi("fbz_z_90_00pi","AliTPCExB::GetBr(90,0*pi,x)",-250,250);
517 TF1 fbr_z_90_05pi("fbz_z_90_05pi","AliTPCExB::GetBr(90,0.5*pi,x)",-250,250);
518 TF1 fbr_z_90_10pi("fbz_z_90_10pi","AliTPCExB::GetBr(90,1.0*pi,x)",-250,250);
519 TF1 fbr_z_90_15pi("fbz_z_90_15pi","AliTPCExB::GetBr(90,1.5*pi,x)",-250,250);
520 fbr_z_90_00pi->SetLineColor(2);
521 fbr_z_90_05pi->SetLineColor(3);
522 fbr_z_90_10pi->SetLineColor(4);
523 fbr_z_90_15pi->SetLineColor(5);
524 fbr_z_90_00pi->Draw()
525 fbr_z_90_05pi->Draw("same")
526 fbr_z_90_15pi->Draw("same")
527 fbr_z_90_10pi->Draw("same")
530 TF2 fbz_xy_0z("fbz_xy_0z","AliTPCExB::GetBz(sqrt(x^2+y^2),atan2(y,x),0)",-250,250,-250,250);
531 fbz_xy_0z.SetNpy(100);
532 fbz_xy_0z.SetNpx(100);
533 fbz_xy_0z->Draw("colz");
535 TF2 fbz_xy_250z("fbz_xy_250z","AliTPCExB::GetBz(sqrt(x^2+y^2),atan2(y,x),250)",-250,250,-250,250);
536 fbz_xy_250z.SetNpy(100);
537 fbz_xy_250z.SetNpx(100)
538 fbz_xy_250z->Draw("colz");
540 TF2 fbz_xy_m250z("fbz_xy_m250z","AliTPCExB::GetBz(sqrt(x^2+y^2),atan2(y,x),-250)",-250,250,-250,250);
541 fbz_xy_m250z.SetNpy(100);
542 fbz_xy_m250z.SetNpx(100)
543 fbz_xy_m250z->Draw("colz");