+//_______________________________________________________________________
+Double_t AliMagF::GetFactorDip() const
+{
+ // return the sign*scale of the current in the Dipole according to fgkPolarityConventionthe
+ switch (fgkPolarityConvention) {
+ case kConvDCS2008: return fFactorDip;
+ case kConvLHC : return -fFactorDip;
+ default : return fFactorDip; // case kConvMap2005: return fFactorDip;
+ }
+}
+
+//_____________________________________________________________________________
+AliMagF* AliMagF::CreateFieldMap(Float_t l3Cur, Float_t diCur, Int_t convention, Bool_t uniform,
+ Float_t beamenergy, const Char_t *beamtype, const Char_t *path)
+{
+ //------------------------------------------------
+ // The magnetic field map, defined externally...
+ // L3 current 30000 A -> 0.5 T
+ // L3 current 12000 A -> 0.2 T
+ // dipole current 6000 A
+ // The polarities must match the convention (LHC or DCS2008)
+ // unless the special uniform map was used for MC
+ //------------------------------------------------
+ const Float_t l3NominalCurrent1=30000.; // (A)
+ const Float_t l3NominalCurrent2=12000.; // (A)
+ const Float_t diNominalCurrent =6000. ; // (A)
+
+ const Float_t tolerance=0.03; // relative current tolerance
+ const Float_t zero=77.; // "zero" current (A)
+ //
+ BMap_t map = k5kG;
+ double sclL3,sclDip;
+ //
+ Float_t l3Pol = l3Cur > 0 ? 1:-1;
+ Float_t diPol = diCur > 0 ? 1:-1;
+
+ l3Cur = TMath::Abs(l3Cur);
+ diCur = TMath::Abs(diCur);
+ //
+ if (TMath::Abs((sclDip=diCur/diNominalCurrent)-1.) > tolerance && !uniform) {
+ if (diCur <= zero) sclDip = 0.; // some small current.. -> Dipole OFF
+ else {
+ AliFatalGeneral("AliMagF",Form("Wrong dipole current (%f A)!",diCur));
+ }
+ }
+ //
+ if (uniform) {
+ // special treatment of special MC with uniform mag field (normalized to 0.5 T)
+ // no check for scaling/polarities are done
+ map = k5kGUniform;
+ sclL3 = l3Cur/l3NominalCurrent1;
+ }
+ else {
+ if (TMath::Abs((sclL3=l3Cur/l3NominalCurrent1)-1.) < tolerance) map = k5kG;
+ else if (TMath::Abs((sclL3=l3Cur/l3NominalCurrent2)-1.) < tolerance) map = k2kG;
+ else if (l3Cur <= zero && diCur<=zero) { sclL3=0; sclDip=0; map = k5kGUniform;}
+ else {
+ AliFatalGeneral("AliMagF",Form("Wrong L3 current (%f A)!",l3Cur));
+ }
+ }
+ //
+ if (sclDip!=0 && map!=k5kGUniform) {
+ if ( (l3Cur<=zero) || ((convention==kConvLHC && l3Pol!=diPol) || (convention==kConvDCS2008 && l3Pol==diPol)) ) {
+ AliFatalGeneral("AliMagF",Form("Wrong combination for L3/Dipole polarities (%c/%c) for convention %d",
+ l3Pol>0?'+':'-',diPol>0?'+':'-',GetPolarityConvention()));
+ }
+ }
+ //
+ if (l3Pol<0) sclL3 = -sclL3;
+ if (diPol<0) sclDip = -sclDip;
+ //
+ BeamType_t btype = kNoBeamField;
+ TString btypestr = beamtype;
+ btypestr.ToLower();
+ TPRegexp protonBeam("(proton|p)\\s*-?\\s*\\1");
+ TPRegexp ionBeam("(lead|pb|ion|a)\\s*-?\\s*\\1");
+ if (btypestr.Contains(ionBeam)) btype = kBeamTypeAA;
+ else if (btypestr.Contains(protonBeam)) btype = kBeamTypepp;
+ else AliInfoGeneral("AliMagF",Form("Assume no LHC magnet field for the beam type %s, ",beamtype));
+ char ttl[80];
+ snprintf(ttl,79,"L3: %+5d Dip: %+4d kA; %s | Polarities in %s convention",(int)TMath::Sign(l3Cur,float(sclL3)),
+ (int)TMath::Sign(diCur,float(sclDip)),uniform ? " Constant":"",
+ convention==kConvLHC ? "LHC":"DCS2008");
+ // LHC and DCS08 conventions have opposite dipole polarities
+ if ( GetPolarityConvention() != convention) sclDip = -sclDip;
+ //
+ return new AliMagF("MagneticFieldMap", ttl,sclL3,sclDip,map,btype,beamenergy,2,10.,path);
+ //
+}
+
+//_____________________________________________________________________________
+const char* AliMagF::GetBeamTypeText() const
+{
+ const char *beamNA = "No Beam";
+ const char *beamPP = "p-p";
+ const char *beamPbPb= "Pb-Pb";
+ switch ( fBeamType ) {
+ case kBeamTypepp : return beamPP;
+ case kBeamTypeAA : return beamPbPb;
+ case kNoBeamField:
+ default: return beamNA;
+ }
+}
+
+//_____________________________________________________________________________
+void AliMagF::Print(Option_t *opt) const
+{
+ // print short or long info
+ TString opts = opt; opts.ToLower();
+ AliInfo(Form("%s:%s",GetName(),GetTitle()));
+ AliInfo(Form("Solenoid (%+.2f*)%.0f kG, Dipole %s (%+.2f) %s",
+ GetFactorSol(),(fMapType==k5kG||fMapType==k5kGUniform)?5.:2.,
+ fDipoleOFF ? "OFF":"ON",GetFactorDip(),fMapType==k5kGUniform?" |Constant Field!":""));
+ if (opts.Contains("a")) {
+ AliInfo(Form("Machine B fields for %s beam (%.0f GeV): QGrad: %.4f Dipole: %.4f",
+ fBeamType==kBeamTypeAA ? "A-A":(fBeamType==kBeamTypepp ? "p-p":"OFF"),
+ fBeamEnergy,fQuadGradient,fDipoleField));
+ AliInfo(Form("Uses %s of %s",GetParamName(),GetDataFileName()));
+ }
+}