Skip to content

Commit 1bae27d

Browse files
authored
Refactor magnetic field calculation and conditions
Refactor magnetic field calculation by defining variables for Rc, R1, R2, B1, and B2. Update conditions for magnetic field assignment based on radius and beam start position.
1 parent 0b7791e commit 1bae27d

1 file changed

Lines changed: 21 additions & 67 deletions

File tree

Detectors/Upgrades/ALICE3/macros/ALICE3Field.C

Lines changed: 21 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,43 @@
1111
//
1212
// Author: J. E. Munoz Mendez jesus.munoz@cern.ch
1313

14-
#include <functional>
15-
#include <cmath>
16-
#include <TCanvas.h>
17-
#include <TH2F.h>
18-
#include <TStyle.h>
19-
2014
std::function<void(const double*, double*)> field()
2115
{
2216
return [](const double* x, double* b) {
23-
// RADIUS
24-
static constexpr double Rc = 170.; // [cm] — R_out_coil per Ian DetectorConstruction.cc; confirmed by A. Ortiz definition
25-
static constexpr double R1 = 220.; // [cm]
26-
static constexpr double R2 = 290.; // [cm]
17+
double Rc;
18+
double R1;
19+
double R2;
20+
double B1;
21+
double B2;
22+
double beamStart = 500.; //[cm]
23+
double tokGauss = 1. / 0.1; // conversion from Tesla to kGauss
2724

28-
// FIELD
29-
static constexpr double B1 = 2.; // [T]
30-
static constexpr double B2 = -B1 * Rc * Rc / (R2 * R2 - R1 * R1); // [T] — B1 in numerator, confirmed by A. Ortiz Aug 2026
31-
static constexpr double beamStart = 500.; // [cm]
32-
static constexpr double tokGauss = 1. / 0.1; // conversion from Tesla to kGauss
25+
bool isMagAbs = true;
3326

34-
static constexpr bool isMagAbs = true;
27+
// ***********************
28+
// LAYOUT 1
29+
// ***********************
30+
31+
// RADIUS
32+
Rc = 170.; //[cm] — R_out_coil per Ian DetectorConstruction.cc; confirmed by A. Ortiz definition
33+
R1 = 220.; //[cm]
34+
R2 = 290.; //[cm]
3535

3636
// To set the B2
37+
B1 = 2.; //[T]
38+
B2 = -B1 * Rc * Rc / (R2 * R2 - R1 * R1); //[T] — B1 in numerator, confirmed by A. Ortiz Aug 2026
3739

38-
if ((std::abs(x[2]) <= beamStart) && (sqrt(x[0] * x[0] + x[1] * x[1]) < Rc)) {
40+
if ((abs(x[2]) <= beamStart) && (sqrt(x[0] * x[0] + x[1] * x[1]) < Rc)) {
3941
b[0] = 0.;
4042
b[1] = 0.;
4143
b[2] = B1 * tokGauss;
42-
} else if ((std::abs(x[2]) <= beamStart) &&
44+
} else if ((abs(x[2]) <= beamStart) &&
4345
(sqrt(x[0] * x[0] + x[1] * x[1]) >= Rc &&
4446
sqrt(x[0] * x[0] + x[1] * x[1]) < R1)) {
4547
b[0] = 0.;
4648
b[1] = 0.;
4749
b[2] = 0.;
48-
} else if ((std::abs(x[2]) <= beamStart) &&
50+
} else if ((abs(x[2]) <= beamStart) &&
4951
(sqrt(x[0] * x[0] + x[1] * x[1]) >= R1 &&
5052
sqrt(x[0] * x[0] + x[1] * x[1]) < R2)) {
5153
b[0] = 0.;
@@ -62,51 +64,3 @@ std::function<void(const double*, double*)> field()
6264
}
6365
};
6466
}
65-
66-
void ALICE3Field()
67-
{
68-
gStyle->SetPalette(kRainBow);
69-
gStyle->SetNumberContours(255);
70-
71-
auto fieldFunc = field();
72-
// RZ plane visualization
73-
TCanvas* cRZ = new TCanvas("cRZ", "Field in RZ plane", 800, 800);
74-
gPad->SetRightMargin(0.15);
75-
TH2F* hRZ = new TH2F("hRZ", "Magnetic Field B_z in RZ plane;Z [m];R [m];B_{z} [kGauss]", 100, -10, 10, 100, -5, 5);
76-
hRZ->SetBit(TH1::kNoStats); // disable stats box
77-
for (int i = 1; i <= hRZ->GetNbinsX(); i++) {
78-
const double Z = hRZ->GetXaxis()->GetBinCenter(i);
79-
for (int j = 1; j <= hRZ->GetNbinsY(); j++) {
80-
const double R = hRZ->GetYaxis()->GetBinCenter(j);
81-
const double pos[3] = {R * 100, 0, Z * 100}; // convert to cm
82-
double b[3] = {0, 0, 0};
83-
fieldFunc(pos, b);
84-
hRZ->SetBinContent(i, j, b[2]);
85-
}
86-
}
87-
88-
hRZ->GetZaxis()->SetRangeUser(-30, 30);
89-
hRZ->Draw("COLZ");
90-
cRZ->Update();
91-
92-
// XY plane visualization
93-
TCanvas* cXY = new TCanvas("cXY", "Field in XY plane", 800, 800);
94-
gPad->SetRightMargin(0.15);
95-
TH2F* hXY = new TH2F("hXY", "Magnetic Field B_z in XY plane;X [m];Y [m];B_{z} [kGauss]", 100, -5, 5, 100, -5, 5);
96-
hXY->SetBit(TH1::kNoStats); // disable stats box
97-
98-
for (int i = 1; i <= hXY->GetNbinsX(); i++) {
99-
const double X = hXY->GetXaxis()->GetBinCenter(i);
100-
for (int j = 1; j <= hXY->GetNbinsY(); j++) {
101-
const double Y = hXY->GetYaxis()->GetBinCenter(j);
102-
const double pos[3] = {X * 100, Y * 100, 0}; // convert to cm
103-
double b[3] = {0, 0, 0};
104-
fieldFunc(pos, b);
105-
hXY->SetBinContent(i, j, b[2]);
106-
}
107-
}
108-
109-
hXY->GetZaxis()->SetRangeUser(-30, 30);
110-
hXY->Draw("COLZ");
111-
cXY->Update();
112-
}

0 commit comments

Comments
 (0)