#include <AliMagF.h>
#include "TGeoGlobalMagField.h"
#include "AliTPCcalibDB.h"
#include "AliTPCParam.h"
#include "AliLog.h"
#include "AliTPCExBBShape.h"
AliTPCExBBShape::AliTPCExBBShape()
: AliTPCCorrection("exb_bshape","ExB B-shape"),
fC1(0.),fC2(0.),
fBField(0)
{
}
AliTPCExBBShape::~AliTPCExBBShape() {
}
void AliTPCExBBShape::Init() {
AliMagF* magF= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
if (!magF) AliError("Magneticd field - not initialized");
Double_t bzField = magF->SolenoidField()/10.;
SetBField(magF);
AliTPCParam *param= AliTPCcalibDB::Instance()->GetParameters();
if (!param) AliError("Parameters - not initialized");
Double_t vdrift = param->GetDriftV()/1000000.;
Double_t ezField = 400;
Double_t wt = -10.0 * (bzField*10) * vdrift / ezField ;
SetOmegaTauT1T2(wt,fT1,fT2);
}
void AliTPCExBBShape::Update(const TTimeStamp &) {
AliMagF* magF= (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
if (!magF) AliError("Magneticd field - not initialized");
Double_t bzField = magF->SolenoidField()/10.;
SetBField(magF);
AliTPCParam *param= AliTPCcalibDB::Instance()->GetParameters();
if (!param) AliError("Parameters - not initialized");
Double_t vdrift = param->GetDriftV()/1000000.;
Double_t ezField = 400;
Double_t wt = -10.0 * (bzField*10) * vdrift / ezField ;
SetOmegaTauT1T2(wt,fT1,fT2);
}
void AliTPCExBBShape::GetCorrection(const Float_t x[],const Short_t roc,Float_t dx[]) {
if (!fBField) {
for (Int_t j=0;j<3;++j) dx[j]=0.;
return;
}
const Double_t xStart[3]={ x[0], x[1], x[2] };
const Double_t xEnd[3]={ x[0], x[1], roc%36<18?fgkTPCZ0:-fgkTPCZ0 };
Double_t intBStart[3];
Double_t intBEnd[3];
fBField->GetTPCRatInt(xStart,intBStart);
fBField->GetTPCRatInt(xEnd, intBEnd );
const Float_t intBxOverBz=(intBEnd[0]-intBStart[0]);
const Float_t intByOverBz=(intBEnd[1]-intBStart[1]);
dx[0]=fC2*intBxOverBz-fC1*intByOverBz;
dx[1]=fC1*intBxOverBz+fC2*intByOverBz;
dx[2]=0.;
}
void AliTPCExBBShape::GetBxAndByOverBz(const Float_t x[],const Short_t roc,Float_t BxByOverBz[]) {
if (!fBField) {
for (Int_t j=0;j<3;++j) BxByOverBz[j]=0.;
return;
}
const Double_t xStart[3]={ x[0], x[1], x[2] };
const Double_t xEnd[3]={ x[0], x[1], roc%36<18?fgkTPCZ0:-fgkTPCZ0 };
Double_t intBStart[3];
Double_t intBEnd[3];
fBField->GetTPCRatInt(xStart,intBStart);
fBField->GetTPCRatInt(xEnd, intBEnd );
const Float_t intBxOverBz=(intBEnd[0]-intBStart[0]);
const Float_t intByOverBz=(intBEnd[1]-intBStart[1]);
BxByOverBz[0]=intBxOverBz;
BxByOverBz[1]=intByOverBz;
}
void AliTPCExBBShape::Print(Option_t* option) const {
TString opt = option; opt.ToLower();
printf("%s\t%s\n - B field settings:\n",GetTitle(),GetName());
fBField->Print(option);
if (opt.Contains("a")) {
printf(" - T1: %1.4f, T2: %1.4f \n",fT1,fT2);
printf(" - C1: %1.4f, C2: %1.4f \n",fC1,fC2);
}
}
Double_t AliTPCExBBShape::GetBFieldXYZ(Double_t gx, Double_t gy, Double_t gz, Int_t axisType){
AliMagF* field = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
if (!field) return 0;
Double_t xyz[3]={gx,gy,gz};
Double_t bxyz[3]={0};
field->Field(xyz,bxyz);
Double_t r=TMath::Sqrt(gx*gx+gy*gy);
if (axisType==0) {
return (xyz[0]*bxyz[1]-xyz[1]*bxyz[0])/(bxyz[2]*r);
}
if (axisType==1){
return (xyz[0]*bxyz[0]+xyz[1]*bxyz[1])/(bxyz[2]*r);
}
if (axisType==2) return bxyz[2];
if (axisType==3) return bxyz[0];
if (axisType==4) return bxyz[1];
if (axisType==5) return bxyz[2];
return bxyz[2];
}