////////////////////////////////////////////////////////////////////////////
#include <TGeoGlobalMagField.h>
-#include <TPRegexp.h>
#include "AliGRPManager.h"
#include "AliLog.h"
// Set the global mag field instance
if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
- AliInfo("Running with the externally locked B field !");
- }
- else {
- // Construct the field map out of the information retrieved from GRP.
- Bool_t ok = kTRUE;
- // L3
- Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
- if (l3Current == AliGRPObject::GetInvalidFloat()) {
- AliError("GRP/GRP/Data entry: missing value for the L3 current !");
- ok = kFALSE;
- }
-
- Char_t l3Polarity = fGRPData->GetL3Polarity();
- if (l3Polarity == AliGRPObject::GetInvalidChar()) {
- AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
- ok = kFALSE;
+ if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
+ AliInfo("ExpertMode!!! GRP information will be ignored !");
+ AliInfo("ExpertMode!!! Running with the externally locked B field !");
+ return kTRUE;
}
-
- // Dipole
- Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
- if (diCurrent == AliGRPObject::GetInvalidFloat()) {
- AliError("GRP/GRP/Data entry: missing value for the dipole current !");
- ok = kFALSE;
- }
-
- Char_t diPolarity = fGRPData->GetDipolePolarity();
- if (diPolarity == AliGRPObject::GetInvalidChar()) {
- AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
- ok = kFALSE;
+ else {
+ AliInfo("Destroying existing B field instance!");
+ delete TGeoGlobalMagField::Instance();
}
-
- if (ok) {
- if ( !SetFieldMap(l3Current, diCurrent, l3Polarity ? -1:1, diPolarity ? -1:1) ) {
- AliError("Failed to create a B field map !");
- ok = kFALSE;
- }
+ }
+ //
+ if (!fGRPData) {
+ AliError("GRP Data is not loaded");
+ return kFALSE;
+ }
+ //
+ // Construct the field map out of the information retrieved from GRP.
+ Bool_t ok = kTRUE;
+ // L3
+ Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
+ if (l3Current == AliGRPObject::GetInvalidFloat()) {
+ AliError("GRP/GRP/Data entry: missing value for the L3 current !");
+ ok = kFALSE;
+ }
+
+ Char_t l3Polarity = fGRPData->GetL3Polarity();
+ if (l3Polarity == AliGRPObject::GetInvalidChar()) {
+ AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
+ ok = kFALSE;
+ }
+
+ // Dipole
+ Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
+ if (diCurrent == AliGRPObject::GetInvalidFloat()) {
+ AliError("GRP/GRP/Data entry: missing value for the dipole current !");
+ ok = kFALSE;
+ }
+
+ Char_t diPolarity = fGRPData->GetDipolePolarity();
+ if (diPolarity == AliGRPObject::GetInvalidChar()) {
+ AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
+ 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; // temprorary suppressed to make read cosmics data
+ }
+
+ 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; // temprorary suppressed to make read cosmics data
+ }
+ // LHC: "multiply by 120 to get the energy in MeV"
+ beamEnergy *= 0.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) {
+ AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1),
+ TMath::Abs(diCurrent) * (diPolarity ? -1:1),
+ polConvention,uniformB,beamEnergy, beamType.Data());
+ if (fld) {
+ TGeoGlobalMagField::Instance()->SetField( fld );
+ TGeoGlobalMagField::Instance()->Lock();
AliInfo("Running with the B field constructed out of GRP !");
}
else {
- AliError("B field is neither set nor constructed from GRP ! Exitig...");
+ AliError("Failed to create a B field map !");
+ ok = kFALSE;
}
- return ok;
}
-
- return kTRUE;
+ else {
+ AliError("B field is neither set nor constructed from GRP ! Exitig...");
+ }
+
+ return ok;
}
//_____________________________________________________________________________
}
//_____________________________________________________________________________
-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)
+void AliGRPManager::SetGRPEntry(AliGRPObject* source)
{
- //------------------------------------------------
- // 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
- //------------------------------------------------
- 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)
- //
- TString s=(l3Pol < 0) ? "L3: -" : "L3: +";
- //
- AliMagF::BMap_t map = AliMagF::k5kG;
- //
- double fcL3,fcDip;
- //
- 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(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 (l3Pol!=diPol && (map==AliMagF::k5kG || map==AliMagF::k2kG) && fcDip!=0) {
- AliError("L3 and Dipole polarities must be the same");
- return kFALSE;
- }
- //
- if (l3Pol<0) fcL3 = -fcL3;
- if (diPol<0) fcDip = -fcDip;
- //
- AliMagF::BeamType_t btype = AliMagF::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 = AliMagF::kBeamTypeAA;
- else if (btypestr.Contains(protonBeam)) btype = AliMagF::kBeamTypepp;
- 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,
- btype,beamenergy);
- TGeoGlobalMagField::Instance()->SetField( fld );
- TGeoGlobalMagField::Instance()->Lock();
+ // Create a GRP entry from the extrnaly provide GRP object
+ // To be used by HLT to create an online GRP instance
+ if (!source) return;
+ if (fGRPData) delete fGRPData;
+ fGRPData = new AliGRPObject(*source);
+ AliInfo("Created GRP Data from external object");
//
- return kTRUE;
}
+