]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliGRPManager.cxx
MCEvent::GetTrack gives back *VParticle.
[u/mrichter/AliRoot.git] / STEER / AliGRPManager.cxx
index c191ea966ca57faa4e60de9e601fec71e241b715..5a2affdf40dfee1a3320f4921aaec3418cbe319e 100644 (file)
@@ -138,8 +138,28 @@ Bool_t AliGRPManager::SetMagField()
       ok = kFALSE;
     }
 
+    TString beamType = fGRPData->GetBeamType();
+    if (beamType==AliGRPObject::GetInvalidString()) {
+      AliError("GRP/GRP/Data entry:  missing value for the beam type ! Using UNKNOWN");
+      beamType = "UNKNOWN";
+      ok = kFALSE;
+    }
+
+    Float_t beamEnergy = fGRPData->GetBeamEnergy();
+    if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
+      AliError("GRP/GRP/Data entry:  missing value for the beam energy ! Using 0");
+      beamEnergy = 0;
+      ok = kFALSE;
+    }
+    beamEnergy /= 120E3;       // energy is provided in MeV*120
+
+    // read special bits for the polarity convention and map type
+    Int_t  polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
+    Bool_t uniformB = fGRPData->IsUniformBMap();
+
     if (ok) { 
-      if ( !SetFieldMap(l3Current, diCurrent, l3Polarity ? -1:1, diPolarity ? -1:1) ) {
+      if ( !SetFieldMap(l3Current, diCurrent, l3Polarity ? -1:1, diPolarity ? -1:1, 
+                       polConvention,uniformB,beamEnergy, beamType.Data())) {
        AliError("Failed to create a B field map !");
        ok = kFALSE;
       }
@@ -198,15 +218,16 @@ AliRunInfo* AliGRPManager::GetRunInfo()
 
 //_____________________________________________________________________________
 Bool_t AliGRPManager::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Pol, 
-                                 Float_t diPol, Float_t beamenergy, 
-                                 const Char_t *beamtype, const Char_t *path) 
+                                 Float_t diPol, 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 be the same
+  // 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)
@@ -215,51 +236,46 @@ Bool_t AliGRPManager::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Pol,
   const Float_t tolerance=0.03; // relative current tolerance
   const Float_t zero=77.;       // "zero" current (A)
   //
-  TString s=(l3Pol < 0) ? "L3: -" : "L3: +";
-  //
-  AliMagF::BMap_t map = AliMagF::k5kG;
-  //
-  double fcL3,fcDip;
+  AliMagF::BMap_t map;
+  double sclL3,sclDip;
   //
   l3Cur = TMath::Abs(l3Cur);
-  if (TMath::Abs(l3Cur-l3NominalCurrent1)/l3NominalCurrent1 < tolerance) {
-    fcL3 = l3Cur/l3NominalCurrent1;
-    map  = AliMagF::k5kG;
-    s   += "0.5 T;  ";
-  } else if (TMath::Abs(l3Cur-l3NominalCurrent2)/l3NominalCurrent2 < tolerance) {
-    fcL3 = l3Cur/l3NominalCurrent2;
-    map  = AliMagF::k2kG;
-    s   += "0.2 T;  ";
-  } else if (l3Cur <= zero) {
-    fcL3 = 0;
-    map  = AliMagF::k5kGUniform;
-    s   += "0.0 T;  ";
-    //    fUniformField=kTRUE;        // track with the uniform (zero) B field
-  } else {
-    AliError(Form("Wrong L3 current (%f A)!",l3Cur));
-    return kFALSE;
+  diCur = TMath::Abs(diCur);
+  //
+  if (TMath::Abs((sclDip=diCur/diNominalCurrent)-1.) > tolerance && !uniform) {
+    if (diCur <= zero) sclDip = 0.; // some small current.. -> Dipole OFF
+    else {
+      AliError(Form("Wrong dipole current (%f A)!",diCur));
+      return kFALSE;
+    }
   }
   //
-  diCur = TMath::Abs(diCur);
-  if (TMath::Abs(diCur-diNominalCurrent)/diNominalCurrent < tolerance) {
-    // 3% current tolerance...
-    fcDip = diCur/diNominalCurrent;
-    s    += "Dipole ON";
-  } else if (diCur <= zero) { // some small current..
-    fcDip = 0.;
-    s    += "Dipole OFF";
-  } else {
-    AliError(Form("Wrong dipole current (%f A)!",diCur));
-    return kFALSE;
+  if (uniform) { 
+    // special treatment of special MC with uniform mag field (normalized to 0.5 T)
+    // no check for scaling/polarities are done
+    map   = AliMagF::k5kGUniform;
+    sclL3 = l3Cur/l3NominalCurrent1; 
+  }
+  else {
+    if      (TMath::Abs((sclL3=l3Cur/l3NominalCurrent1)-1.) < tolerance) map  = AliMagF::k5kG;
+    else if (TMath::Abs((sclL3=l3Cur/l3NominalCurrent2)-1.) < tolerance) map  = AliMagF::k2kG;
+    else if (l3Cur <= zero)                                { sclL3 = 0;  map  = AliMagF::k5kGUniform;}
+    else {
+      AliError(Form("Wrong L3 current (%f A)!",l3Cur));
+      return kFALSE;
+    }
   }
   //
-  if (l3Pol!=diPol && (map==AliMagF::k5kG || map==AliMagF::k2kG) && fcDip!=0) {
-    AliError("L3 and Dipole polarities must be the same");
+  if (sclDip!=0 && (map==AliMagF::k5kG || map==AliMagF::k2kG) &&
+      ((convention==AliMagF::kConvLHC     && l3Pol!=diPol) ||
+       (convention==AliMagF::kConvDCS2008 && l3Pol==diPol)) ) { 
+    AliError(Form("Wrong combination for L3/Dipole polarities (%c/%c) for convention %d",
+                 l3Pol>0?'+':'-',diPol>0?'+':'-',AliMagF::GetPolarityConvention()));
     return kFALSE;
   }
   //
-  if (l3Pol<0) fcL3  = -fcL3;
-  if (diPol<0) fcDip = -fcDip;
+  if (l3Pol<0) sclL3  = -sclL3;
+  if (diPol<0) sclDip = -sclDip;
   //
   AliMagF::BeamType_t btype = AliMagF::kNoBeamField;
   TString btypestr = beamtype;
@@ -271,8 +287,10 @@ Bool_t AliGRPManager::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Pol,
   else {
     AliInfo(Form("Cannot determine the beam type from %s, assume no LHC magnet field",beamtype));
   }
-  
-  AliMagF* fld = new AliMagF("MagneticFieldMap", s.Data(), 2, fcL3, fcDip, 10., map, path, 
+  char ttl[50];
+  sprintf(ttl,"L3: %+5d Dip: %+4d kA; %s",(int)TMath::Sign(l3Cur,float(sclL3)),
+         (int)TMath::Sign(diCur,float(sclDip)),uniform ? " Constant":"");
+  AliMagF* fld = new AliMagF("MagneticFieldMap", ttl, 2, sclL3, sclDip, 10., map, path, 
                             btype,beamenergy);
   TGeoGlobalMagField::Instance()->SetField( fld );
   TGeoGlobalMagField::Instance()->Lock();