]>
Commit | Line | Data |
---|---|---|
10c2f85a | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | //////////////////////////////////////////////////////////////////////////// | |
17 | // // | |
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. // | |
23 | // // | |
24 | // cvetan.cheshkov@cern.ch 15/06/2009 // | |
25 | // // | |
26 | // Usage: // | |
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 // | |
32 | // // | |
33 | // Note: CDB manager should be initialized beforehand // | |
34 | //////////////////////////////////////////////////////////////////////////// | |
35 | ||
36 | #include <TGeoGlobalMagField.h> | |
37 | #include <TPRegexp.h> | |
38 | ||
39 | #include "AliGRPManager.h" | |
40 | #include "AliLog.h" | |
41 | #include "AliRunInfo.h" | |
42 | #include "AliGRPObject.h" | |
43 | #include "AliCDBManager.h" | |
44 | #include "AliCDBEntry.h" | |
45 | #include "AliMagF.h" | |
46 | ||
47 | ClassImp(AliGRPManager) | |
48 | ||
49 | //_____________________________________________________________________________ | |
50 | AliGRPManager::AliGRPManager() : | |
51 | TObject(), | |
52 | fGRPData(NULL) | |
53 | { | |
54 | // Default constructor | |
55 | } | |
56 | ||
57 | //_____________________________________________________________________________ | |
58 | AliGRPManager::~AliGRPManager() | |
59 | { | |
60 | // Destructor | |
61 | if (fGRPData) delete fGRPData; | |
62 | } | |
63 | ||
64 | //_____________________________________________________________________________ | |
65 | Bool_t AliGRPManager::ReadGRPEntry() | |
66 | { | |
67 | //------------------------------------ | |
68 | // Initialization of the GRP entry. | |
69 | // Returns kTRUE in case of success. | |
70 | //------------------------------------ | |
71 | ||
72 | AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data"); | |
73 | ||
74 | if (entry) { | |
75 | ||
76 | TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry | |
77 | ||
78 | if (m) { | |
79 | AliInfo("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject"); | |
80 | m->Print(); | |
81 | fGRPData = new AliGRPObject(); | |
82 | fGRPData->ReadValuesFromMap(m); | |
83 | } | |
84 | ||
85 | else { | |
86 | AliInfo("Found an AliGRPObject in GRP/GRP/Data, reading it"); | |
87 | fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry | |
88 | entry->SetOwner(0); | |
89 | } | |
90 | ||
91 | AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data"); | |
92 | } | |
93 | ||
94 | if (!fGRPData) { | |
95 | AliError("No GRP entry found in OCDB!"); | |
96 | return kFALSE; | |
97 | } | |
98 | ||
99 | return kTRUE; | |
100 | } | |
101 | ||
102 | //_____________________________________________________________________________ | |
103 | Bool_t AliGRPManager::SetMagField() | |
104 | { | |
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 | |
108 | ||
109 | if ( TGeoGlobalMagField::Instance()->IsLocked() ) { | |
110 | AliInfo("Running with the externally locked B field !"); | |
111 | } | |
112 | else { | |
113 | // Construct the field map out of the information retrieved from GRP. | |
114 | Bool_t ok = kTRUE; | |
115 | // L3 | |
116 | Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0); | |
117 | if (l3Current == AliGRPObject::GetInvalidFloat()) { | |
118 | AliError("GRP/GRP/Data entry: missing value for the L3 current !"); | |
119 | ok = kFALSE; | |
120 | } | |
121 | ||
122 | Char_t l3Polarity = fGRPData->GetL3Polarity(); | |
123 | if (l3Polarity == AliGRPObject::GetInvalidChar()) { | |
124 | AliError("GRP/GRP/Data entry: missing value for the L3 polarity !"); | |
125 | ok = kFALSE; | |
126 | } | |
127 | ||
128 | // Dipole | |
129 | Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0); | |
130 | if (diCurrent == AliGRPObject::GetInvalidFloat()) { | |
131 | AliError("GRP/GRP/Data entry: missing value for the dipole current !"); | |
132 | ok = kFALSE; | |
133 | } | |
134 | ||
135 | Char_t diPolarity = fGRPData->GetDipolePolarity(); | |
136 | if (diPolarity == AliGRPObject::GetInvalidChar()) { | |
137 | AliError("GRP/GRP/Data entry: missing value for the dipole polarity !"); | |
138 | ok = kFALSE; | |
139 | } | |
140 | ||
141 | if (ok) { | |
142 | if ( !SetFieldMap(l3Current, diCurrent, l3Polarity ? -1:1, diPolarity ? -1:1) ) { | |
143 | AliError("Failed to create a B field map !"); | |
144 | ok = kFALSE; | |
145 | } | |
146 | AliInfo("Running with the B field constructed out of GRP !"); | |
147 | } | |
148 | else { | |
149 | AliError("B field is neither set nor constructed from GRP ! Exitig..."); | |
150 | } | |
151 | return ok; | |
152 | } | |
153 | ||
154 | return kTRUE; | |
155 | } | |
156 | ||
157 | //_____________________________________________________________________________ | |
158 | AliRunInfo* AliGRPManager::GetRunInfo() | |
159 | { | |
160 | // Constructs and returns an object | |
161 | // containing the run information | |
162 | // The user code is the owner of the object | |
163 | ||
164 | TString lhcState = fGRPData->GetLHCState(); | |
165 | if (lhcState==AliGRPObject::GetInvalidString()) { | |
166 | AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN"); | |
167 | lhcState = "UNKNOWN"; | |
168 | } | |
169 | ||
170 | TString beamType = fGRPData->GetBeamType(); | |
171 | if (beamType==AliGRPObject::GetInvalidString()) { | |
172 | AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN"); | |
173 | beamType = "UNKNOWN"; | |
174 | } | |
175 | ||
176 | Float_t beamEnergy = fGRPData->GetBeamEnergy(); | |
177 | if (beamEnergy==AliGRPObject::GetInvalidFloat()) { | |
178 | AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0"); | |
179 | beamEnergy = 0; | |
180 | } | |
181 | // energy is provided in MeV*120 | |
182 | beamEnergy /= 120E3; | |
183 | ||
184 | TString runType = fGRPData->GetRunType(); | |
185 | if (runType==AliGRPObject::GetInvalidString()) { | |
186 | AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN"); | |
187 | runType = "UNKNOWN"; | |
188 | } | |
189 | ||
190 | Int_t activeDetectors = fGRPData->GetDetectorMask(); | |
191 | if (activeDetectors==AliGRPObject::GetInvalidUInt()) { | |
192 | AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399"); | |
193 | activeDetectors = 1074790399; | |
194 | } | |
195 | ||
196 | return new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors); | |
197 | } | |
198 | ||
199 | //_____________________________________________________________________________ | |
200 | Bool_t AliGRPManager::SetFieldMap(Float_t l3Cur, Float_t diCur, Float_t l3Pol, | |
201 | Float_t diPol, Float_t beamenergy, | |
202 | const Char_t *beamtype, const Char_t *path) | |
203 | { | |
204 | //------------------------------------------------ | |
205 | // The magnetic field map, defined externally... | |
206 | // L3 current 30000 A -> 0.5 T | |
207 | // L3 current 12000 A -> 0.2 T | |
208 | // dipole current 6000 A | |
209 | // The polarities must be the same | |
210 | //------------------------------------------------ | |
211 | const Float_t l3NominalCurrent1=30000.; // (A) | |
212 | const Float_t l3NominalCurrent2=12000.; // (A) | |
213 | const Float_t diNominalCurrent =6000. ; // (A) | |
214 | ||
215 | const Float_t tolerance=0.03; // relative current tolerance | |
216 | const Float_t zero=77.; // "zero" current (A) | |
217 | // | |
218 | TString s=(l3Pol < 0) ? "L3: -" : "L3: +"; | |
219 | // | |
220 | AliMagF::BMap_t map = AliMagF::k5kG; | |
221 | // | |
222 | double fcL3,fcDip; | |
223 | // | |
224 | l3Cur = TMath::Abs(l3Cur); | |
225 | if (TMath::Abs(l3Cur-l3NominalCurrent1)/l3NominalCurrent1 < tolerance) { | |
226 | fcL3 = l3Cur/l3NominalCurrent1; | |
227 | map = AliMagF::k5kG; | |
228 | s += "0.5 T; "; | |
229 | } else if (TMath::Abs(l3Cur-l3NominalCurrent2)/l3NominalCurrent2 < tolerance) { | |
230 | fcL3 = l3Cur/l3NominalCurrent2; | |
231 | map = AliMagF::k2kG; | |
232 | s += "0.2 T; "; | |
233 | } else if (l3Cur <= zero) { | |
234 | fcL3 = 0; | |
235 | map = AliMagF::k5kGUniform; | |
236 | s += "0.0 T; "; | |
237 | // fUniformField=kTRUE; // track with the uniform (zero) B field | |
238 | } else { | |
239 | AliError(Form("Wrong L3 current (%f A)!",l3Cur)); | |
240 | return kFALSE; | |
241 | } | |
242 | // | |
243 | diCur = TMath::Abs(diCur); | |
244 | if (TMath::Abs(diCur-diNominalCurrent)/diNominalCurrent < tolerance) { | |
245 | // 3% current tolerance... | |
246 | fcDip = diCur/diNominalCurrent; | |
247 | s += "Dipole ON"; | |
248 | } else if (diCur <= zero) { // some small current.. | |
249 | fcDip = 0.; | |
250 | s += "Dipole OFF"; | |
251 | } else { | |
252 | AliError(Form("Wrong dipole current (%f A)!",diCur)); | |
253 | return kFALSE; | |
254 | } | |
255 | // | |
256 | if (l3Pol!=diPol && (map==AliMagF::k5kG || map==AliMagF::k2kG) && fcDip!=0) { | |
257 | AliError("L3 and Dipole polarities must be the same"); | |
258 | return kFALSE; | |
259 | } | |
260 | // | |
261 | if (l3Pol<0) fcL3 = -fcL3; | |
262 | if (diPol<0) fcDip = -fcDip; | |
263 | // | |
264 | AliMagF::BeamType_t btype = AliMagF::kNoBeamField; | |
265 | TString btypestr = beamtype; | |
266 | btypestr.ToLower(); | |
267 | TPRegexp protonBeam("(proton|p)\\s*-?\\s*\\1"); | |
268 | TPRegexp ionBeam("(lead|pb|ion|a)\\s*-?\\s*\\1"); | |
269 | if (btypestr.Contains(ionBeam)) btype = AliMagF::kBeamTypeAA; | |
270 | else if (btypestr.Contains(protonBeam)) btype = AliMagF::kBeamTypepp; | |
271 | else { | |
272 | AliInfo(Form("Cannot determine the beam type from %s, assume no LHC magnet field",beamtype)); | |
273 | } | |
274 | ||
275 | AliMagF* fld = new AliMagF("MagneticFieldMap", s.Data(), 2, fcL3, fcDip, 10., map, path, | |
276 | btype,beamenergy); | |
277 | TGeoGlobalMagField::Instance()->SetField( fld ); | |
278 | TGeoGlobalMagField::Instance()->Lock(); | |
279 | // | |
280 | return kTRUE; | |
281 | } |