Project
Loading...
Searching...
No Matches
MagneticField.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#include "Field/MagneticField.h"
18#include <TFile.h> // for TFile
19#include <TPRegexp.h> // for TPRegexp
20#include <TString.h> // for TString
21#include <TSystem.h> // for TSystem, gSystem
22#include <fairlogger/Logger.h> // for FairLogger
23
24using namespace o2::field;
25
27
28const FieldOriginBiasParam* MagneticField::gOriginBias = nullptr;
29
30const Double_t MagneticField::sSolenoidToDipoleZ = -700.;
31
64const UShort_t MagneticField::sPolarityConvention = MagneticField::kConvLHC;
65
67 : FairField(),
68 mMeasuredMap(nullptr),
69 mFastField(nullptr),
70 mMapType(MagFieldParam::k5kG),
71 mSolenoid(0),
72 mBeamType(MagFieldParam::kNoBeamField),
73 mBeamEnergy(0),
74 mDefaultIntegration(0),
75 mPrecisionInteg(0),
76 mMultipicativeFactorSolenoid(1.),
77 mMultipicativeFactorDipole(1.),
78 mMaxField(15),
79 mDipoleOnOffFlag(kFALSE),
80 mQuadrupoleGradient(0),
81 mDipoleField(0),
82 mCompensatorField2C(0),
83 mCompensatorField1A(0),
84 mCompensatorField2A(0),
85 mParameterNames("", "")
86{
87 /*
88 * Default constructor
89 */
90 fType = 2; // flag non-constant field
91 if (!gOriginBias) {
93 }
94}
95
96MagneticField::MagneticField(const char* name, const char* title, Double_t factorSol, Double_t factorDip,
97 MagFieldParam::BMap_t maptype, MagFieldParam::BeamType_t bt, Double_t be, Int_t integ,
98 Double_t fmax, const std::string path)
99 : FairField(name, title),
100 mMeasuredMap(nullptr),
101 mFastField(nullptr),
102 mMapType(maptype),
103 mSolenoid(0),
104 mBeamType(bt),
105 mBeamEnergy(be),
106 mDefaultIntegration(integ),
107 mPrecisionInteg(1),
108 mMultipicativeFactorSolenoid(1.),
109 mMultipicativeFactorDipole(1.),
110 mMaxField(fmax),
111 mDipoleOnOffFlag(factorDip == 0.),
112 mQuadrupoleGradient(0),
113 mDipoleField(0),
114 mCompensatorField2C(0),
115 mCompensatorField1A(0),
116 mCompensatorField2A(0),
117 mParameterNames("", "")
118{
119 /*
120 * Constructor for human readable params
121 */
122 setFactorSolenoid(factorSol);
123 setFactorDipole(factorDip);
124 setDataFileName(path.c_str());
125 if (!gOriginBias) {
127 }
128 CreateField();
129}
130
132{
133 float fldCoeffL3, fldCoeffDip;
135 if (uniform) {
136 fldCoeffL3 = float(fld) / 5.;
137 fldCoeffDip = fld > 0 ? 1. : -1;
139 } else {
140 switch (std::abs(fld)) {
141 case 5:
143 fldCoeffL3 = fldCoeffDip = fld > 0 ? 1. : -1;
144 break;
145 case 0:
147 fldCoeffL3 = fldCoeffDip = 0;
148 break;
149 case 2:
151 fldCoeffL3 = fldCoeffDip = fld > 0 ? 1. : -1;
152 break;
153 default:
154 LOG(fatal) << "Field option " << fld << " is not supported, use +-2, +-5 or 0 or <int_kilogauss>U";
155 };
156 }
157 return new o2::field::MagneticField("Maps", "Maps", fldCoeffL3, fldCoeffDip, fldType);
158}
159
161{
162 /*
163 * field initialization
164 */
165
166 fType = 2; // flag non-constant field
167
168 // does real creation of the field
169 if (mDefaultIntegration < 0 || mDefaultIntegration > 2) {
170 LOG(warning) << "MagneticField::CreateField: Invalid magnetic field flag: " << mDefaultIntegration
171 << "; Helix tracking chosen instead";
172 mDefaultIntegration = 2;
173 }
174 if (mDefaultIntegration == 0) {
175 mPrecisionInteg = 0;
176 }
177
178 if (mBeamEnergy <= 0 && mBeamType != MagFieldParam::kNoBeamField) {
179 if (mBeamType == MagFieldParam::kBeamTypepp) {
180 mBeamEnergy = 7000.; // max proton energy
181 } else if (mBeamType == MagFieldParam::kBeamTypeAA) {
182 mBeamEnergy = 2760; // max PbPb energy
183 } else if (mBeamType == MagFieldParam::kBeamTypepA || mBeamType == MagFieldParam::kBeamTypeAp) {
184 mBeamEnergy = 2760; // same rigitiy max PbPb energy
185 }
186 //
187 LOG(info) << "MagneticField::CreateField: Maximim possible beam energy for requested beam is assumed";
188 }
189
190 const char* parname = nullptr;
191
192 if (mMapType == MagFieldParam::k2kG) {
193 parname = mDipoleOnOffFlag ? "Sol12_Dip0_Hole" : "Sol12_Dip6_Hole";
194 } else if (mMapType == MagFieldParam::k5kG) {
195 parname = mDipoleOnOffFlag ? "Sol30_Dip0_Hole" : "Sol30_Dip6_Hole";
196 } else if (mMapType == MagFieldParam::k5kGUniform) {
197 parname = "Sol30_Dip6_Uniform";
198 } else {
199 LOG(fatal) << "MagneticField::CreateField: Unknown field identifier " << mMapType << " is requested\n";
200 }
201
202 setParameterName(parname);
203
205 initializeMachineField(mBeamType, mBeamEnergy);
206 // The scaling factors are left alone: they already carry the polarity convention, and
207 // re-applying it would invert a field re-initialized after being read back from a file.
208 if (mFastField) {
209 mFastField->setFactorSol(getFactorSolenoid());
210 }
211 double xyz[3] = {0., 0., 0.};
212 mSolenoid = getBz(xyz);
213 Print("a");
214 //
215}
216
218{
219 /*
220 * load parametrization for measured field
221 */
222
223 if (mMeasuredMap) {
224 LOG(fatal) << "MagneticField::loadParameterization: Field data " << getParameterName()
225 << " are already loaded from " << getDataFileName() << "\n";
226 }
227 TString fname = getDataFileName();
228 gSystem->ExpandPathName(fname);
229 TFile* file = TFile::Open(fname);
230 if (!file) {
231 LOG(fatal) << "MagneticField::loadParameterization: Failed to open magnetic field data file " << fname << "\n";
232 }
233
234 mMeasuredMap =
235 std::unique_ptr<MagneticWrapperChebyshev>(dynamic_cast<MagneticWrapperChebyshev*>(file->Get(getParameterName())));
236 if (!mMeasuredMap) {
237 LOG(fatal) << "MagneticField::loadParameterization: Did not find field " << getParameterName() << " in " << fname
238 << "%s\n";
239 }
240 file->Close();
241 delete file;
242 return kTRUE;
243}
244
245void MagneticField::Field(const Double_t* __restrict__ xyzExt, Double_t* __restrict__ b)
246{
247 /*
248 * query field value at point
249 */
250 double xyz[3] = {xyzExt[0] - gOriginBias->x, xyzExt[1] - gOriginBias->y, xyzExt[2] - gOriginBias->z};
251 // b[0]=b[1]=b[2]=0.0;
252 if (mFastField && mFastField->Field(xyz, b)) {
253 return;
254 }
255
256 if (mMeasuredMap && xyz[2] > mMeasuredMap->getMinZ() && xyz[2] < mMeasuredMap->getMaxZ()) {
257 mMeasuredMap->Field(xyz, b);
258 if (xyz[2] > sSolenoidToDipoleZ || mDipoleOnOffFlag) {
259 for (int i = 3; i--;) {
260 b[i] *= mMultipicativeFactorSolenoid;
261 }
262 } else {
263 for (int i = 3; i--;) {
264 b[i] *= mMultipicativeFactorDipole;
265 }
266 }
267 } else {
268 MachineField(xyz, b);
269 }
270}
271
272Double_t MagneticField::getBz(const Double_t* xyzExt) const
273{
274 /*
275 * query field Bz component at point
276 */
277 double xyz[3] = {xyzExt[0] - gOriginBias->x, xyzExt[1] - gOriginBias->y, xyzExt[2] - gOriginBias->z};
278 if (mFastField) {
279 double bz = 0;
280 if (mFastField->GetBz(xyz, bz)) {
281 return bz;
282 }
283 }
284 if (mMeasuredMap && xyz[2] > mMeasuredMap->getMinZ() && xyz[2] < mMeasuredMap->getMaxZ()) {
285 double bz = mMeasuredMap->getBz(xyz);
286 return (xyz[2] > sSolenoidToDipoleZ || mDipoleOnOffFlag) ? bz * mMultipicativeFactorSolenoid
287 : bz * mMultipicativeFactorDipole;
288 } else {
289 return 0.;
290 }
291}
292
294{
295 /*
296 * assignment operator
297 */
298
299 if (this != &src) {
300 if (src.mMeasuredMap) {
301 mMeasuredMap.reset(new MagneticWrapperChebyshev(*src.getMeasuredMap()));
302 }
303 SetName(src.GetName());
304 mSolenoid = src.mSolenoid;
305 mBeamType = src.mBeamType;
306 mBeamEnergy = src.mBeamEnergy;
307 mDefaultIntegration = src.mDefaultIntegration;
308 mPrecisionInteg = src.mPrecisionInteg;
309 mMultipicativeFactorSolenoid = src.mMultipicativeFactorSolenoid;
310 mMultipicativeFactorDipole = src.mMultipicativeFactorDipole;
311 mMaxField = src.mMaxField;
312 mDipoleOnOffFlag = src.mDipoleOnOffFlag;
313 mParameterNames = src.mParameterNames;
314 mFastField.reset(src.mFastField ? new MagFieldFast(*src.getFastField()) : nullptr);
315 }
316 return *this;
317}
318
320{
321 if (btype == MagFieldParam::kNoBeamField) {
322 mQuadrupoleGradient = mDipoleField = mCompensatorField2C = mCompensatorField1A = mCompensatorField2A = 0.;
323 return;
324 }
325
326 double rigScale = benergy / 7000.; // scale according to ratio of E/Enominal
327 // for ions assume PbPb (with energy provided per nucleon) and account for A/Z
328 if (btype == MagFieldParam::kBeamTypeAA /* || btype==kBeamTypepA || btype==kBeamTypeAp */) {
329 rigScale *= 208. / 82.;
330 }
331 // Attention: in p-Pb the energy recorded in the GRP is the PROTON energy, no rigidity
332 // rescaling is needed
333
334 mQuadrupoleGradient = 22.0002 * rigScale;
335 mDipoleField = 37.8781 * rigScale;
336
337 // SIDE C
338 mCompensatorField2C = -9.6980;
339 // SIDE A
340 mCompensatorField1A = -13.2247;
341 mCompensatorField2A = 11.7905;
342}
343
344void MagneticField::MachineField(const Double_t* __restrict__ x, Double_t* __restrict__ b) const
345{
346 // ---- This is the ZDC part
347 // Compansators for Alice Muon Arm Dipole
348 const Double_t kBComp1CZ = 1075., kBComp1hDZ = 260. / 2., kBComp1SqR = 4.0 * 4.0;
349 const Double_t kBComp2CZ = 2049., kBComp2hDZ = 153. / 2., kBComp2SqR = 4.5 * 4.5;
350
351 const Double_t kTripQ1CZ = 2615., kTripQ1hDZ = 637. / 2., kTripQ1SqR = 3.5 * 3.5;
352 const Double_t kTripQ2CZ = 3480., kTripQ2hDZ = 550. / 2., kTripQ2SqR = 3.5 * 3.5;
353 const Double_t kTripQ3CZ = 4130., kTripQ3hDZ = 550. / 2., kTripQ3SqR = 3.5 * 3.5;
354 const Double_t kTripQ4CZ = 5015., kTripQ4hDZ = 637. / 2., kTripQ4SqR = 3.5 * 3.5;
355
356 const Double_t kDip1CZ = 6310.8, kDip1hDZ = 945. / 2., kDip1SqRC = 4.5 * 4.5, kDip1SqRA = 3.375 * 3.375;
357 const Double_t kDip2CZ = 12640.3, kDip2hDZ = 945. / 2., kDip2SqRC = 4.5 * 4.5, kDip2SqRA = 3.75 * 3.75;
358 const Double_t kDip2DXC = 9.7, kDip2DXA = 9.4;
359
360 double rad2 = x[0] * x[0] + x[1] * x[1];
361
362 b[0] = b[1] = b[2] = 0;
363
364 // SIDE C
365 if (x[2] < 0.) {
366 if (TMath::Abs(x[2] + kBComp2CZ) < kBComp2hDZ && rad2 < kBComp2SqR) {
367 b[0] = mCompensatorField2C * mMultipicativeFactorDipole;
368 } else if (TMath::Abs(x[2] + kTripQ1CZ) < kTripQ1hDZ && rad2 < kTripQ1SqR) {
369 b[0] = mQuadrupoleGradient * x[1];
370 b[1] = mQuadrupoleGradient * x[0];
371 } else if (TMath::Abs(x[2] + kTripQ2CZ) < kTripQ2hDZ && rad2 < kTripQ2SqR) {
372 b[0] = -mQuadrupoleGradient * x[1];
373 b[1] = -mQuadrupoleGradient * x[0];
374 } else if (TMath::Abs(x[2] + kTripQ3CZ) < kTripQ3hDZ && rad2 < kTripQ3SqR) {
375 b[0] = -mQuadrupoleGradient * x[1];
376 b[1] = -mQuadrupoleGradient * x[0];
377 } else if (TMath::Abs(x[2] + kTripQ4CZ) < kTripQ4hDZ && rad2 < kTripQ4SqR) {
378 b[0] = mQuadrupoleGradient * x[1];
379 b[1] = mQuadrupoleGradient * x[0];
380 } else if (TMath::Abs(x[2] + kDip1CZ) < kDip1hDZ && rad2 < kDip1SqRC) {
381 b[1] = mDipoleField;
382 } else if (TMath::Abs(x[2] + kDip2CZ) < kDip2hDZ && rad2 < kDip2SqRC) {
383 double dxabs = TMath::Abs(x[0]) - kDip2DXC;
384 if ((dxabs * dxabs + x[1] * x[1]) < kDip2SqRC) {
385 b[1] = -mDipoleField;
386 }
387 }
388 }
389
390 // SIDE A
391 else {
392 if (TMath::Abs(x[2] - kBComp1CZ) < kBComp1hDZ && rad2 < kBComp1SqR) {
393 // Compensator magnet at z = 1075 m
394 b[0] = mCompensatorField1A * mMultipicativeFactorDipole;
395 }
396
397 if (TMath::Abs(x[2] - kBComp2CZ) < kBComp2hDZ && rad2 < kBComp2SqR) {
398 b[0] = mCompensatorField2A * mMultipicativeFactorDipole;
399 } else if (TMath::Abs(x[2] - kTripQ1CZ) < kTripQ1hDZ && rad2 < kTripQ1SqR) {
400 b[0] = -mQuadrupoleGradient * x[1];
401 b[1] = -mQuadrupoleGradient * x[0];
402 } else if (TMath::Abs(x[2] - kTripQ2CZ) < kTripQ2hDZ && rad2 < kTripQ2SqR) {
403 b[0] = mQuadrupoleGradient * x[1];
404 b[1] = mQuadrupoleGradient * x[0];
405 } else if (TMath::Abs(x[2] - kTripQ3CZ) < kTripQ3hDZ && rad2 < kTripQ3SqR) {
406 b[0] = mQuadrupoleGradient * x[1];
407 b[1] = mQuadrupoleGradient * x[0];
408 } else if (TMath::Abs(x[2] - kTripQ4CZ) < kTripQ4hDZ && rad2 < kTripQ4SqR) {
409 b[0] = -mQuadrupoleGradient * x[1];
410 b[1] = -mQuadrupoleGradient * x[0];
411 } else if (TMath::Abs(x[2] - kDip1CZ) < kDip1hDZ && rad2 < kDip1SqRA) {
412 b[1] = -mDipoleField;
413 } else if (TMath::Abs(x[2] - kDip2CZ) < kDip2hDZ && rad2 < kDip2SqRA) {
414 double dxabs = TMath::Abs(x[0]) - kDip2DXA;
415 if ((dxabs * dxabs + x[1] * x[1]) < kDip2SqRA) {
416 b[1] = mDipoleField;
417 }
418 }
419 }
420}
421
422void MagneticField::getTPCIntegral(const Double_t* xyz, Double_t* b) const
423{
424 b[0] = b[1] = b[2] = 0.0;
425 if (mMeasuredMap) {
426 mMeasuredMap->getTPCIntegral(xyz, b);
427 for (int i = 3; i--;) {
428 b[i] *= mMultipicativeFactorSolenoid;
429 }
430 }
431}
432
433void MagneticField::getTPCRatIntegral(const Double_t* xyz, Double_t* b) const
434{
435 b[0] = b[1] = b[2] = 0.0;
436 if (mMeasuredMap) {
437 mMeasuredMap->getTPCRatIntegral(xyz, b);
438 b[2] /= 100;
439 }
440}
441
442void MagneticField::getTPCIntegralCylindrical(const Double_t* rphiz, Double_t* b) const
443{
444 b[0] = b[1] = b[2] = 0.0;
445 if (mMeasuredMap) {
446 mMeasuredMap->getTPCIntegralCylindrical(rphiz, b);
447 for (int i = 3; i--;) {
448 b[i] *= mMultipicativeFactorSolenoid;
449 }
450 }
451}
452
453void MagneticField::getTPCRatIntegralCylindrical(const Double_t* rphiz, Double_t* b) const
454{
455 b[0] = b[1] = b[2] = 0.0;
456 if (mMeasuredMap) {
457 mMeasuredMap->getTPCRatIntegralCylindrical(rphiz, b);
458 b[2] /= 100;
459 }
460}
461
463{
464 switch (sPolarityConvention) {
465 case kConvDCS2008:
466 mMultipicativeFactorSolenoid = -fc;
467 break;
468 case kConvLHC:
469 mMultipicativeFactorSolenoid = -fc;
470 break;
471 default:
472 mMultipicativeFactorSolenoid = fc;
473 break; // case kConvMap2005: mMultipicativeFactorSolenoid = fc; break;
474 }
475 if (mFastField) {
476 mFastField->setFactorSol(getFactorSolenoid());
477 }
478}
479
481{
482 switch (sPolarityConvention) {
483 case kConvDCS2008:
484 mMultipicativeFactorDipole = fc;
485 break;
486 case kConvLHC:
487 mMultipicativeFactorDipole = -fc;
488 break;
489 default:
490 mMultipicativeFactorDipole = fc;
491 break; // case kConvMap2005: mMultipicativeFactorDipole = fc; break;
492 }
493}
494
496{
497 switch (sPolarityConvention) {
498 case kConvDCS2008:
499 return -mMultipicativeFactorSolenoid;
500 case kConvLHC:
501 return -mMultipicativeFactorSolenoid;
502 default:
503 return mMultipicativeFactorSolenoid; // case kConvMap2005: return mMultipicativeFactorSolenoid;
504 }
505}
506
508{
509 switch (sPolarityConvention) {
510 case kConvDCS2008:
511 return mMultipicativeFactorDipole;
512 case kConvLHC:
513 return -mMultipicativeFactorDipole;
514 default:
515 return mMultipicativeFactorDipole; // case kConvMap2005: return mMultipicativeFactorDipole;
516 }
517}
518
519void MagneticField::rescaleField(float l3Cur, float diCur, bool uniform, int convention)
520{
521 // this function taks as input magnet currents and rescales existing field if the map is compatible
522 float sclL3 = l3Cur, sclDip = diCur;
523 MagFieldParam::BMap_t map = getFieldMapScale(sclL3, sclDip, uniform);
524 if (map != mMapType) {
525 LOGP(fatal, "Provided L3current={} DipCurrent={} uniform={} leads to map type {}, incompatible with loaded {}", l3Cur, diCur, uniform, (int)map, (int)mMapType);
526 }
527 setFactorSolenoid(sclL3);
528 setFactorDipole(sclDip);
529 LOGP(info, "Updating magnetic field: L3current={} DipCurrent={} uniform={}", l3Cur, diCur, uniform);
530}
531
532MagFieldParam::BMap_t MagneticField::getFieldMapScale(float& l3, float& dip, bool uniform, int convention)
533{
534 // this function taks as input magnet currents and returns the field type and scalings for L3 and dipole
535 const float l3NominalCurrent1 = 30000.f; // (A)
536 const float l3NominalCurrent2 = 12000.f; // (A)
537 const float diNominalCurrent = 6000.f; // (A)
538
539 const float tolerance = 0.03; // relative current tolerance
540 const float zero = 77.f; // "zero" current (A)
541
543 float sclL3, sclDip;
544 float l3sav = l3, dipsav = dip;
545
546 float l3Pol = l3 > 0 ? 1 : -1;
547 float diPol = dip > 0 ? 1 : -1;
548
549 l3 = TMath::Abs(l3);
550 dip = TMath::Abs(dip);
551 static bool overrideL3 = std::getenv("O2_OVERRIDE_L3_CURRENT") != nullptr;
552 static bool overrideDIP = std::getenv("O2_OVERRIDE_DIPOLE_CURRENT") != nullptr;
553 static bool warnL3Done = false, warnDipDone = false, warnPolarityDone = false;
554
555 if (TMath::Abs((sclDip = dip / diNominalCurrent) - 1.) > tolerance && !uniform) {
556 if (dip <= zero) {
557 sclDip = 0.; // some small current.. -> Dipole OFF
558 } else {
559 if (!overrideDIP) {
560 LOG(fatal) << "MagneticField::createFieldMap: Wrong dipole current (" << dipsav << " A)!";
561 } else {
562 if (!warnDipDone) {
563 LOGP(error, "Dipole current was overridden to unsupported value {}", dipsav);
564 warnDipDone = true;
565 }
566 }
567 }
568 }
569 if (uniform) {
570 // special treatment of special MC with uniform mag field (normalized to 0.5 T)
571 // no check for scaling/polarities are done
573 sclL3 = l3 / l3NominalCurrent1;
574 } else {
575 if (TMath::Abs((sclL3 = l3 / l3NominalCurrent1) - 1.) < tolerance) {
577 } else if (TMath::Abs((sclL3 = l3 / l3NominalCurrent2) - 1.) < tolerance) {
579 } else if (l3 <= zero && dip <= zero) {
580 sclL3 = 0;
581 sclDip = 0;
583 } else {
584 if (!overrideL3) {
585 LOG(fatal) << "MagneticField::createFieldMap: Wrong L3 current (" << l3sav << " A)!";
586 } else {
587 if (!warnL3Done) {
588 LOGP(error, "L3 current was overridden to unsupported value {}", l3sav);
589 warnL3Done = true;
590 }
592 sclL3 = l3 / l3NominalCurrent1;
593 }
594 }
595 }
596 if (sclDip != 0 && map != MagFieldParam::k5kGUniform) {
597 if ((l3 <= zero) ||
598 ((convention == kConvLHC && l3Pol != diPol) || (convention == kConvDCS2008 && l3Pol == diPol))) {
599 if (overrideL3 || overrideDIP) {
600 if (!warnPolarityDone) {
601 LOG(error) << "Overriden currents have wrong combination for L3/Dipole polarities ("
602 << (l3Pol > 0 ? '+' : '-') << "/" << (diPol > 0 ? '+' : '-') << ") for convention "
604 warnPolarityDone = true;
605 }
606 } else {
607 LOG(fatal) << "MagneticField::createFieldMap: Wrong combination for L3/Dipole polarities ("
608 << (l3Pol > 0 ? '+' : '-') << "/" << (diPol > 0 ? '+' : '-') << ") for convention "
610 }
611 }
612 }
613 l3 = (l3Pol < 0) ? -sclL3 : sclL3;
614 dip = (diPol < 0) ? -sclDip : sclDip;
615 return map;
616}
617
618MagneticField* MagneticField::createFieldMap(float l3Cur, float diCur, Int_t convention, Bool_t uniform,
619 float beamenergy, const Char_t* beamtype, const std::string path)
620{
621 float sclL3 = l3Cur, sclDip = diCur;
622 MagFieldParam::BMap_t map = getFieldMapScale(sclL3, sclDip, uniform);
624 TString btypestr = beamtype;
625 btypestr.ToLower();
626 TPRegexp protonBeam(R"((proton|p)\s*-?\s*\1)");
627 TPRegexp ionBeam(R"((lead|pb|ion|a|A)\s*-?\s*\1)");
628 TPRegexp protonionBeam(R"((proton|p)\s*-?\s*(lead|pb|ion|a|A))");
629 TPRegexp ionprotonBeam(R"((lead|pb|ion|a|A)\s*-?\s*(proton|p))");
630 if (btypestr.Contains(ionBeam)) {
632 } else if (btypestr.Contains(protonBeam)) {
634 } else if (btypestr.Contains(protonionBeam)) {
636 } else if (btypestr.Contains(ionprotonBeam)) {
638 } else {
639 LOG(info) << "Assume no LHC magnet field for the beam type " << beamtype;
640 }
641 char ttl[80];
642 snprintf(ttl, 79, "L3: %+5d Dip: %+4d kA; %s | Polarities in %s convention", (int)TMath::Sign(l3Cur, float(sclL3)),
643 (int)TMath::Sign(diCur, float(sclDip)), uniform ? " Constant" : "",
644 convention == kConvLHC ? "LHC" : "DCS2008");
645 // LHC and DCS08 conventions have opposite dipole polarities
646 if (getPolarityConvention() != convention) {
647 sclDip = -sclDip;
648 }
649
650 return new MagneticField("MagneticFieldMap", ttl, sclL3, sclDip, map, btype, beamenergy, 2, 10., path);
651}
652
654{
655 const char* beamNA = "No Beam";
656 const char* beamPP = "p-p";
657 const char* beamPbPb = "A-A";
658 const char* beamPPb = "p-A";
659 const char* beamPbP = "A-p";
660 switch (mBeamType) {
662 return beamPP;
664 return beamPbPb;
666 return beamPPb;
668 return beamPbP;
670 default:
671 return beamNA;
672 }
673}
674
675void MagneticField::Print(Option_t* opt) const
676{
677 TString opts = opt;
678 opts.ToLower();
679 LOG(info) << "MagneticField::Print: " << GetName() << ":" << GetTitle();
680 LOG(info) << "MagneticField::Print: Solenoid (" << getFactorSolenoid() << "*)"
681 << ((mMapType == MagFieldParam::k5kG || mMapType == MagFieldParam::k5kGUniform) ? 5. : 2) << " kG, Dipole "
682 << (mDipoleOnOffFlag ? "OFF" : "ON") << " (" << getFactorDipole() << ") "
683 << (mMapType == MagFieldParam::k5kGUniform ? " |Constant Field!" : "");
684 if (opts.Contains("a")) {
685 LOG(info) << "MagneticField::Print: Machine B fields for " << getBeamTypeText() << " beam (" << mBeamEnergy
686 << " GeV): QGrad: " << mQuadrupoleGradient << " Dipole: " << mDipoleField;
687 LOG(info) << "MagneticField::Print: Uses " << getParameterName() << " of " << getDataFileName();
688 }
689}
690
691//_____________________________________________________________________________
693{
694 if (v) {
695 if (!mFastField) {
696 mFastField = std::make_unique<MagFieldFast>(getFactorSolenoid(), mMapType == MagFieldParam::k2kG ? 2 : 5);
697 }
698 } else {
699 mFastField.reset(nullptr);
700 }
701}
702
703//_____________________________________________________________________________
705{
706 // posibility to globally bias all data members with the proper env.var
707 if (const auto* biasString = std::getenv("O2_DPL_FIELDORIGINBIAS"); biasString && *biasString) {
709 }
710 gOriginBias = &FieldOriginBiasParam::Instance();
711 LOGP(info, "Field origin is set to: XYZ: {:.4f},{:.4f},{:.4f}", gOriginBias->x, gOriginBias->y, gOriginBias->z);
712}
int32_t i
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
configStandalone Reconstruction rec_tpc float
char error[CURL_ERROR_SIZE]
ClassImp(MagneticField)
Definition of the MagF class.
Int_t fType
Definition FairField.h:110
static void updateFromString(std::string const &)
static MagFieldParam::BMap_t getFieldMapScale(float &l3, float &dip, bool uniform, int convention=0)
Double_t getBz(const Double_t *xyz) const
Method to calculate the field at point xyz.
Double_t getFactorDipole() const
Return the sign*scale of the current in the Dipole according to sPolarityConventionthe.
void getTPCRatIntegralCylindrical(const Double_t *rphiz, Double_t *b) const
void MachineField(const Double_t *__restrict__ x, Double_t *__restrict__ b) const
const char * getBeamTypeText() const
Returns beam type in text form.
void getTPCRatIntegral(const Double_t *xyz, Double_t *b) const
Method to calculate the integral_0^z of br,bt,bz.
void rescaleField(float l3Cur, float diCur, bool uniform, int convention=0)
void getTPCIntegralCylindrical(const Double_t *rphiz, Double_t *b) const
Method to calculate the integral_0^z of br,bt,bz in cylindrical coordinates ( -pi<phi<pi convention )
Char_t * getDataFileName() const
void setDataFileName(const Char_t *nm)
static MagneticField * createFieldMap(float l3Current=-30000., float diCurrent=-6000., Int_t convention=0, Bool_t uniform=kFALSE, float beamenergy=7000, const Char_t *btype="pp", const std::string path=std::string(gSystem->Getenv("VMCWORKDIR"))+std::string("/Common/maps/mfchebKGI_sym.root"))
void setFactorDipole(float fc=1.)
Sets the sign*scale of the current in the Dipole according to sPolarityConvention.
MagneticField & operator=(const MagneticField &src)
void AllowFastField(bool v=true)
allow fast field param
Double_t getFactorSolenoid() const
Returns the sign*scale of the current in the Dipole according to sPolarityConventionthe.
static Int_t getPolarityConvention()
void Field(const Double_t *__restrict__ point, Double_t *__restrict__ bField) override
void getTPCIntegral(const Double_t *xyz, Double_t *b) const
Method to calculate the integral_0^z of br,bt,bz.
void setParameterName(const Char_t *nm)
void Print(Option_t *opt) const override
Prints short or long info.
Char_t * getParameterName() const
MagneticField()
Default constructor.
void setFactorSolenoid(float fc=1.)
Sets the sign/scale of the current in the L3 according to sPolarityConvention.
void CreateField()
real field creation is here
static MagneticField * createNominalField(int fld, bool uniform=false)
create field from rounded value, i.e. +-5 or +-2 kGauss
void initializeMachineField(MagFieldParam::BeamType_t btype, Double_t benergy)
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLuint const GLchar * name
Definition glcorearb.h:781
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"