Skip to content

Commit c3added

Browse files
Nicola NicassioNicola Nicassio
authored andcommitted
Using latest magnetic field file
1 parent 87dfce3 commit c3added

1 file changed

Lines changed: 70 additions & 32 deletions

File tree

‎Detectors/Upgrades/ALICE3/macros/Fluence/ALICE3Field.C‎

Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,100 @@
88
// In applying this license CERN does not waive the privileges and immunities
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
11+
//
12+
// Author: J. E. Munoz Mendez jesus.munoz@cern.ch
1113

12-
/// \file make_geometry_csv.C
13-
/// \brief Export ALICE 3 geometry boundaries in the R-z plane to a CSV file.
14-
/// \author Nicola Nicassio (nicola.nicassio@cern.ch)
15-
/// \author Rocco Liotino (rocco.liotino@cern.ch)
14+
#include <functional>
15+
#include <cmath>
16+
#include <TCanvas.h>
17+
#include <TH2F.h>
18+
#include <TStyle.h>
1619

1720
std::function<void(const double*, double*)> field()
1821
{
1922
return [](const double* x, double* b) {
20-
double Rc;
21-
double R1;
22-
double R2;
23-
double B1;
24-
double B2;
25-
double beamStart = 500.; // [cm]
26-
double tokGauss = 1. / 0.1; // conversion from Tesla to kGauss
27-
28-
bool isMagAbs = true;
29-
30-
// ***********************
31-
// LAYOUT 1
32-
// ***********************
33-
3423
// RADIUS
35-
Rc = 165.; // [cm]
36-
R1 = 220.; // [cm]
37-
R2 = 290.; // [cm]
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]
3827

39-
// To set the B2
40-
B1 = 2.; // [T]
41-
B2 = -Rc * Rc * B1 / ((R2 * R2 - R1 * R1)); // [T]
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
4233

43-
if ((abs(x[2]) <= beamStart) && (sqrt(x[0] * x[0] + x[1] * x[1]) < Rc)) {
34+
static constexpr bool isMagAbs = true;
35+
36+
const double r = sqrt(x[0] * x[0] + x[1] * x[1]);
37+
if ((abs(x[2]) <= beamStart) && (r < Rc)) { // We are inside of the central region
4438
b[0] = 0.;
4539
b[1] = 0.;
4640
b[2] = B1 * tokGauss;
47-
} else if ((abs(x[2]) <= beamStart) &&
48-
(sqrt(x[0] * x[0] + x[1] * x[1]) >= Rc &&
49-
sqrt(x[0] * x[0] + x[1] * x[1]) < R1)) {
41+
} else if ((abs(x[2]) <= beamStart) && (r >= Rc && r < R1)) { // We are in the transition region
5042
b[0] = 0.;
5143
b[1] = 0.;
5244
b[2] = 0.;
53-
} else if ((abs(x[2]) <= beamStart) &&
54-
(sqrt(x[0] * x[0] + x[1] * x[1]) >= R1 &&
55-
sqrt(x[0] * x[0] + x[1] * x[1]) < R2)) {
45+
} else if ((abs(x[2]) <= beamStart) && (r >= R1 && r < R2)) { // We are within the magnet
5646
b[0] = 0.;
5747
b[1] = 0.;
5848
if (isMagAbs) {
5949
b[2] = B2 * tokGauss;
6050
} else {
6151
b[2] = 0.;
6252
}
63-
} else {
53+
} else { // We are outside of the magnet
6454
b[0] = 0.;
6555
b[1] = 0.;
6656
b[2] = 0.;
6757
}
6858
};
6959
}
60+
61+
void ALICE3Field()
62+
{
63+
gStyle->SetPalette(kRainBow);
64+
gStyle->SetNumberContours(255);
65+
66+
auto fieldFunc = field();
67+
// RZ plane visualization
68+
TCanvas* cRZ = new TCanvas("cRZ", "Field in RZ plane", 800, 800);
69+
gPad->SetRightMargin(0.15);
70+
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);
71+
hRZ->SetBit(TH1::kNoStats); // disable stats box
72+
for (int i = 1; i <= hRZ->GetNbinsX(); i++) {
73+
const double Z = hRZ->GetXaxis()->GetBinCenter(i);
74+
for (int j = 1; j <= hRZ->GetNbinsY(); j++) {
75+
const double R = hRZ->GetYaxis()->GetBinCenter(j);
76+
const double pos[3] = {R * 100, 0, Z * 100}; // convert to cm
77+
double b[3] = {0, 0, 0};
78+
fieldFunc(pos, b);
79+
hRZ->SetBinContent(i, j, b[2]);
80+
}
81+
}
82+
83+
hRZ->GetZaxis()->SetRangeUser(-30, 30);
84+
hRZ->Draw("COLZ");
85+
cRZ->Update();
86+
87+
// XY plane visualization
88+
TCanvas* cXY = new TCanvas("cXY", "Field in XY plane", 800, 800);
89+
gPad->SetRightMargin(0.15);
90+
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);
91+
hXY->SetBit(TH1::kNoStats); // disable stats box
92+
93+
for (int i = 1; i <= hXY->GetNbinsX(); i++) {
94+
const double X = hXY->GetXaxis()->GetBinCenter(i);
95+
for (int j = 1; j <= hXY->GetNbinsY(); j++) {
96+
const double Y = hXY->GetYaxis()->GetBinCenter(j);
97+
const double pos[3] = {X * 100, Y * 100, 0}; // convert to cm
98+
double b[3] = {0, 0, 0};
99+
fieldFunc(pos, b);
100+
hXY->SetBinContent(i, j, b[2]);
101+
}
102+
}
103+
104+
hXY->GetZaxis()->SetRangeUser(-30, 30);
105+
hXY->Draw("COLZ");
106+
cXY->Update();
107+
}

0 commit comments

Comments
 (0)