1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 ////////////////////////////////////////////////////////////////////////////
18 // AliGRPManager class //
19 // The class can be used in order to access and read the Global Run //
20 // Parameters entry from OCDB. //
21 // It has a methods to set the magnetic field instanton and return //
22 // the run and event info objects. //
24 // cvetan.cheshkov@cern.ch 15/06/2009 //
27 // AliGRPManager grpMan; //
28 // Bool_t status = kTRUE; //
29 // status = grpMan.ReadGRPEntry(); // Read the corresponding OCDB entry //
30 // status = grpMan.SetMagField(); // Set global field instanton //
31 // AliRunInfo *runInfo = grpMan.GetRunInfo();// Get instance of run info //
33 // Note: CDB manager should be initialized beforehand //
34 ////////////////////////////////////////////////////////////////////////////
36 #include <TGeoGlobalMagField.h>
39 #include "AliGRPManager.h"
41 #include "AliRunInfo.h"
42 #include "AliGRPObject.h"
43 #include "AliCDBManager.h"
44 #include "AliCDBEntry.h"
47 ClassImp(AliGRPManager)
49 //_____________________________________________________________________________
50 AliGRPManager::AliGRPManager() :
54 // Default constructor
57 //_____________________________________________________________________________
58 AliGRPManager::~AliGRPManager()
61 if (fGRPData) delete fGRPData;
64 //_____________________________________________________________________________
65 Bool_t AliGRPManager::ReadGRPEntry()
67 //------------------------------------
68 // Initialization of the GRP entry.
69 // Returns kTRUE in case of success.
70 //------------------------------------
72 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
76 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
79 AliInfo("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject");
81 fGRPData = new AliGRPObject();
82 fGRPData->ReadValuesFromMap(m);
86 AliInfo("Found an AliGRPObject in GRP/GRP/Data, reading it");
87 fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
91 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
95 AliError("No GRP entry found in OCDB!");
102 //_____________________________________________________________________________
103 Bool_t AliGRPManager::SetMagField()
105 // Dealing with the magnetic field map
106 // Construct the mag field map from the data in GRP
107 // Set the global mag field instance
109 if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
110 if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
111 AliInfo("ExpertMode!!! GRP information will be ignored !");
112 AliInfo("ExpertMode!!! Running with the externally locked B field !");
116 AliInfo("Destroying existing B field instance!");
117 delete TGeoGlobalMagField::Instance();
121 // Construct the field map out of the information retrieved from GRP.
124 Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
125 if (l3Current == AliGRPObject::GetInvalidFloat()) {
126 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
130 Char_t l3Polarity = fGRPData->GetL3Polarity();
131 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
132 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
137 Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
138 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
139 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
143 Char_t diPolarity = fGRPData->GetDipolePolarity();
144 if (diPolarity == AliGRPObject::GetInvalidChar()) {
145 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
149 TString beamType = fGRPData->GetBeamType();
150 if (beamType==AliGRPObject::GetInvalidString()) {
151 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
152 beamType = "UNKNOWN";
153 //ok = kFALSE; // temprorary suppressed to make read cosmics data
156 Float_t beamEnergy = fGRPData->GetBeamEnergy();
157 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
158 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
160 //ok = kFALSE; // temprorary suppressed to make read cosmics data
162 // LHC: "multiply by 120 to get the energy in MeV"
165 // read special bits for the polarity convention and map type
166 Int_t polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
167 Bool_t uniformB = fGRPData->IsUniformBMap();
170 if ( !SetFieldMap(l3Current, diCurrent, l3Polarity ? -1:1, diPolarity ? -1:1,
171 polConvention,uniformB,beamEnergy, beamType.Data())) {
172 AliError("Failed to create a B field map !");
175 else AliInfo("Running with the B field constructed out of GRP !");
178 AliError("B field is neither set nor constructed from GRP ! Exitig...");
184 //_____________________________________________________________________________
185 AliRunInfo* AliGRPManager::GetRunInfo()
187 // Constructs and returns an object
188 // containing the run information
189 // The user code is the owner of the object
191 TString lhcState = fGRPData->GetLHCState();
192 if (lhcState==AliGRPObject::GetInvalidString()) {
193 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
194 lhcState = "UNKNOWN";
197 TString beamType = fGRPData->GetBeamType();
198 if (beamType==AliGRPObject::GetInvalidString()) {
199 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
200 beamType = "UNKNOWN";
203 Float_t beamEnergy = fGRPData->GetBeamEnergy();
204 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
205 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
208 // energy is provided in MeV*120
211 TString runType = fGRPData->GetRunType();
212 if (runType==AliGRPObject::GetInvalidString()) {
213 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
217 Int_t activeDetectors = fGRPData->GetDetectorMask();
218 if (activeDetectors==AliGRPObject::GetInvalidUInt()) {
219 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
220 activeDetectors = 1074790399;
223 return new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
226 //_____________________________________________________________________________
227 Bool_t AliGRPManager::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Pol,
228 Float_t diPol, Int_t convention, Bool_t uniform,
229 Float_t beamenergy, const Char_t *beamtype, const Char_t *path)
231 //------------------------------------------------
232 // The magnetic field map, defined externally...
233 // L3 current 30000 A -> 0.5 T
234 // L3 current 12000 A -> 0.2 T
235 // dipole current 6000 A
236 // The polarities must match the convention (LHC or DCS2008)
237 // unless the special uniform map was used for MC
238 //------------------------------------------------
239 const Float_t l3NominalCurrent1=30000.; // (A)
240 const Float_t l3NominalCurrent2=12000.; // (A)
241 const Float_t diNominalCurrent =6000. ; // (A)
243 const Float_t tolerance=0.03; // relative current tolerance
244 const Float_t zero=77.; // "zero" current (A)
249 l3Cur = TMath::Abs(l3Cur);
250 diCur = TMath::Abs(diCur);
252 if (TMath::Abs((sclDip=diCur/diNominalCurrent)-1.) > tolerance && !uniform) {
253 if (diCur <= zero) sclDip = 0.; // some small current.. -> Dipole OFF
255 AliError(Form("Wrong dipole current (%f A)!",diCur));
261 // special treatment of special MC with uniform mag field (normalized to 0.5 T)
262 // no check for scaling/polarities are done
263 map = AliMagF::k5kGUniform;
264 sclL3 = l3Cur/l3NominalCurrent1;
267 if (TMath::Abs((sclL3=l3Cur/l3NominalCurrent1)-1.) < tolerance) map = AliMagF::k5kG;
268 else if (TMath::Abs((sclL3=l3Cur/l3NominalCurrent2)-1.) < tolerance) map = AliMagF::k2kG;
269 else if (l3Cur <= zero) { sclL3 = 0; map = AliMagF::k5kGUniform;}
271 AliError(Form("Wrong L3 current (%f A)!",l3Cur));
276 if (sclDip!=0 && (map==AliMagF::k5kG || map==AliMagF::k2kG) &&
277 ((convention==AliMagF::kConvLHC && l3Pol!=diPol) ||
278 (convention==AliMagF::kConvDCS2008 && l3Pol==diPol)) ) {
279 AliError(Form("Wrong combination for L3/Dipole polarities (%c/%c) for convention %d",
280 l3Pol>0?'+':'-',diPol>0?'+':'-',AliMagF::GetPolarityConvention()));
284 if (l3Pol<0) sclL3 = -sclL3;
285 if (diPol<0) sclDip = -sclDip;
287 AliMagF::BeamType_t btype = AliMagF::kNoBeamField;
288 TString btypestr = beamtype;
290 TPRegexp protonBeam("(proton|p)\\s*-?\\s*\\1");
291 TPRegexp ionBeam("(lead|pb|ion|a)\\s*-?\\s*\\1");
292 if (btypestr.Contains(ionBeam)) btype = AliMagF::kBeamTypeAA;
293 else if (btypestr.Contains(protonBeam)) btype = AliMagF::kBeamTypepp;
294 else AliInfo(Form("Assume no LHC magnet field for the beam type %s, ",beamtype));
296 sprintf(ttl,"L3: %+5d Dip: %+4d kA; %s | Polarities in %s convention",(int)TMath::Sign(l3Cur,float(sclL3)),
297 (int)TMath::Sign(diCur,float(sclDip)),uniform ? " Constant":"",
298 convention==AliMagF::kConvLHC ? "LHC":"DCS2008");
299 // LHC and DCS08 conventions have opposite dipole polarities
300 if ( AliMagF::GetPolarityConvention() != convention) sclDip = -sclDip;
301 AliMagF* fld = new AliMagF("MagneticFieldMap", ttl, 2, sclL3, sclDip, 10., map, path,
303 TGeoGlobalMagField::Instance()->SetField( fld );
304 TGeoGlobalMagField::Instance()->Lock();