|
11 | 11 | // |
12 | 12 | // Author: J. E. Munoz Mendez jesus.munoz@cern.ch |
13 | 13 |
|
| 14 | +#include <functional> |
| 15 | +#include <cmath> |
| 16 | +#include <TCanvas.h> |
| 17 | +#include <TH2F.h> |
| 18 | +#include <TStyle.h> |
| 19 | + |
14 | 20 | std::function<void(const double*, double*)> field() |
15 | 21 | { |
16 | 22 | return [](const double* x, double* b) { |
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 |
24 | | - |
25 | | - bool isMagAbs = true; |
26 | | - |
27 | | - // *********************** |
28 | | - // LAYOUT 1 |
29 | | - // *********************** |
30 | | - |
31 | 23 | // 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] |
| 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] |
35 | 27 |
|
36 | | - // 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 |
| 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 |
39 | 33 |
|
40 | | - 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 |
41 | 38 | b[0] = 0.; |
42 | 39 | b[1] = 0.; |
43 | 40 | b[2] = B1 * tokGauss; |
44 | | - } else if ((abs(x[2]) <= beamStart) && |
45 | | - (sqrt(x[0] * x[0] + x[1] * x[1]) >= Rc && |
46 | | - 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 |
47 | 42 | b[0] = 0.; |
48 | 43 | b[1] = 0.; |
49 | 44 | b[2] = 0.; |
50 | | - } else if ((abs(x[2]) <= beamStart) && |
51 | | - (sqrt(x[0] * x[0] + x[1] * x[1]) >= R1 && |
52 | | - 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 |
53 | 46 | b[0] = 0.; |
54 | 47 | b[1] = 0.; |
55 | 48 | if (isMagAbs) { |
56 | 49 | b[2] = B2 * tokGauss; |
57 | 50 | } else { |
58 | 51 | b[2] = 0.; |
59 | 52 | } |
60 | | - } else { |
| 53 | + } else { // We are outside of the magnet |
61 | 54 | b[0] = 0.; |
62 | 55 | b[1] = 0.; |
63 | 56 | b[2] = 0.; |
64 | 57 | } |
65 | 58 | }; |
66 | 59 | } |
| 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