From 0cad98d8abe8ec8369953cc7a5f8dfae963e97f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Thu, 5 Mar 2026 09:28:21 +0100 Subject: [PATCH 1/4] Add short mag field macro --- .../Upgrades/ALICE3/macros/ALICE3Field.C | 45 ++++++++- .../ALICE3/macros/ALICE3FieldShortMagnet.C | 91 +++++++++++++++++++ .../Upgrades/ALICE3/macros/CMakeLists.txt | 5 +- 3 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 Detectors/Upgrades/ALICE3/macros/ALICE3FieldShortMagnet.C diff --git a/Detectors/Upgrades/ALICE3/macros/ALICE3Field.C b/Detectors/Upgrades/ALICE3/macros/ALICE3Field.C index a721a91ed2dcc..96b7dd4bbe858 100644 --- a/Detectors/Upgrades/ALICE3/macros/ALICE3Field.C +++ b/Detectors/Upgrades/ALICE3/macros/ALICE3Field.C @@ -19,8 +19,8 @@ std::function field() double R2; double B1; double B2; - double beamStart = 500.; //[cm] - double tokGauss = 1. / 0.1; // conversion from Tesla to kGauss + const double beamStart = 500.; //[cm] + const double tokGauss = 1. / 0.1; // conversion from Tesla to kGauss bool isMagAbs = true; @@ -63,4 +63,45 @@ std::function field() b[2] = 0.; } }; +} + +void ALICE3Field() +{ + auto fieldFunc = field(); + // RZ plane visualization + TCanvas* cRZ = new TCanvas("cRZ", "Field in RZ plane", 800, 600); + TH2F* hRZ = new TH2F("hRZ", "Magnetic Field B_z in RZ plane;Z [m];R [m]", 100, -10, 10, 100, -5, 5); + hRZ->SetBit(TH1::kNoStats); // disable stats box + for (int i = 1; i <= hRZ->GetNbinsX(); i++) { + const double Z = hRZ->GetXaxis()->GetBinCenter(i); + for (int j = 1; j <= hRZ->GetNbinsY(); j++) { + const double R = hRZ->GetYaxis()->GetBinCenter(j); + const double pos[3] = {R * 100, 0, Z * 100}; // convert to cm + double b[3] = {0, 0, 0}; + fieldFunc(pos, b); + hRZ->SetBinContent(i, j, b[2]); + } + } + + hRZ->Draw("COLZ"); + cRZ->Update(); + + // XY plane visualization + TCanvas* cXY = new TCanvas("cXY", "Field in XY plane", 800, 600); + TH2F* hXY = new TH2F("hXY", "Magnetic Field B_z in XY plane;X [m];Y [m]", 100, -5, 5, 100, -5, 5); + hXY->SetBit(TH1::kNoStats); // disable stats box + + for (int i = 1; i <= hXY->GetNbinsX(); i++) { + const double X = hXY->GetXaxis()->GetBinCenter(i); + for (int j = 1; j <= hXY->GetNbinsY(); j++) { + const double Y = hXY->GetYaxis()->GetBinCenter(j); + const double pos[3] = {X * 100, Y * 100, 0}; // convert to cm + double b[3] = {0, 0, 0}; + fieldFunc(pos, b); + hXY->SetBinContent(i, j, b[2]); + } + } + + hXY->Draw("COLZ"); + cXY->Update(); } \ No newline at end of file diff --git a/Detectors/Upgrades/ALICE3/macros/ALICE3FieldShortMagnet.C b/Detectors/Upgrades/ALICE3/macros/ALICE3FieldShortMagnet.C new file mode 100644 index 0000000000000..b12adaa0cc530 --- /dev/null +++ b/Detectors/Upgrades/ALICE3/macros/ALICE3FieldShortMagnet.C @@ -0,0 +1,91 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +// +// Author: J. E. Munoz Mendez jesus.munoz@cern.ch + +std::function field() +{ + return [](const double* x, double* b) { + const double Rc = 185.; //[cm] + const double R1 = 220.; //[cm] + const double R2 = 290.; //[cm] + const double B1 = 2.; //[T] + const double B2 = -Rc * Rc / ((R2 * R2 - R1 * R1) * B1); //[T] + const double beamStart = 370.; //[cm] + const double tokGauss = 1. / 0.1; // conversion from Tesla to kGauss + + const bool isMagAbs = true; + + const double r = sqrt(x[0] * x[0] + x[1] * x[1]); + if ((abs(x[2]) <= beamStart) && (r < Rc)) { // We are inside of the central region + b[0] = 0.; + b[1] = 0.; + b[2] = B1 * tokGauss; + } else if ((abs(x[2]) <= beamStart) && (r >= Rc && r < R1)) { // We are in the transition region + b[0] = 0.; + b[1] = 0.; + b[2] = 0.; + } else if ((abs(x[2]) <= beamStart) && (r >= R1 && r < R2)) { // We are within the magnet + b[0] = 0.; + b[1] = 0.; + if (isMagAbs) { + b[2] = B2 * tokGauss; + } else { + b[2] = 0.; + } + } else { // We are outside of the magnet + b[0] = 0.; + b[1] = 0.; + b[2] = 0.; + } + }; +} + +void ALICE3V3Magnet() +{ + auto fieldFunc = field(); + // RZ plane visualization + TCanvas* cRZ = new TCanvas("cRZ", "Field in RZ plane", 800, 600); + TH2F* hRZ = new TH2F("hRZ", "Magnetic Field B_z in RZ plane;Z [m];R [m]", 100, -10, 10, 100, -5, 5); + hRZ->SetBit(TH1::kNoStats); // disable stats box + for (int i = 1; i <= hRZ->GetNbinsX(); i++) { + const double Z = hRZ->GetXaxis()->GetBinCenter(i); + for (int j = 1; j <= hRZ->GetNbinsY(); j++) { + const double R = hRZ->GetYaxis()->GetBinCenter(j); + const double pos[3] = {R * 100, 0, Z * 100}; // convert to cm + double b[3] = {0, 0, 0}; + fieldFunc(pos, b); + hRZ->SetBinContent(i, j, b[2]); + } + } + + hRZ->Draw("COLZ"); + cRZ->Update(); + + // XY plane visualization + TCanvas* cXY = new TCanvas("cXY", "Field in XY plane", 800, 600); + TH2F* hXY = new TH2F("hXY", "Magnetic Field B_z in XY plane;X [m];Y [m]", 100, -5, 5, 100, -5, 5); + hXY->SetBit(TH1::kNoStats); // disable stats box + + for (int i = 1; i <= hXY->GetNbinsX(); i++) { + const double X = hXY->GetXaxis()->GetBinCenter(i); + for (int j = 1; j <= hXY->GetNbinsY(); j++) { + const double Y = hXY->GetYaxis()->GetBinCenter(j); + const double pos[3] = {X * 100, Y * 100, 0}; // convert to cm + double b[3] = {0, 0, 0}; + fieldFunc(pos, b); + hXY->SetBinContent(i, j, b[2]); + } + } + + hXY->Draw("COLZ"); + cXY->Update(); +} \ No newline at end of file diff --git a/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt b/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt index b31687cc85c0e..0a4f9031355a2 100644 --- a/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt +++ b/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt @@ -13,4 +13,7 @@ o2_add_test_root_macro(scanXX0.C LABELS alice3) o2_add_test_root_macro(plotHits.C - LABELS alice3) \ No newline at end of file + LABELS alice3) + +o2_add_test_root_macro(ALICE3FieldShortMagnet.C + LABELS alice3) From 702a12634b671e54161a8b74bff0145f4c172c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Fri, 21 Aug 2026 09:29:30 +0200 Subject: [PATCH 2/4] Update field --- .../Upgrades/ALICE3/macros/ALICE3Field.C | 66 +++++++++---------- .../ALICE3/macros/ALICE3FieldShortMagnet.C | 44 +++++++++---- 2 files changed, 63 insertions(+), 47 deletions(-) diff --git a/Detectors/Upgrades/ALICE3/macros/ALICE3Field.C b/Detectors/Upgrades/ALICE3/macros/ALICE3Field.C index 96b7dd4bbe858..edecb694a8261 100644 --- a/Detectors/Upgrades/ALICE3/macros/ALICE3Field.C +++ b/Detectors/Upgrades/ALICE3/macros/ALICE3Field.C @@ -11,45 +11,38 @@ // // Author: J. E. Munoz Mendez jesus.munoz@cern.ch +#include +#include +#include +#include +#include + std::function field() { return [](const double* x, double* b) { - double Rc; - double R1; - double R2; - double B1; - double B2; - const double beamStart = 500.; //[cm] - const double tokGauss = 1. / 0.1; // conversion from Tesla to kGauss - - bool isMagAbs = true; - - // *********************** - // LAYOUT 1 - // *********************** - // RADIUS - Rc = 185.; //[cm] - R1 = 220.; //[cm] - R2 = 290.; //[cm] + static constexpr double Rc = 170.; // [cm] — R_out_coil per Ian DetectorConstruction.cc; confirmed by A. Ortiz definition + static constexpr double R1 = 220.; // [cm] + static constexpr double R2 = 290.; // [cm] - // To set the B2 - B1 = 2.; //[T] - B2 = -Rc * Rc / ((R2 * R2 - R1 * R1) * B1); //[T] + // FIELD + static constexpr double B1 = 2.; // [T] + static constexpr double B2 = -B1 * Rc * Rc / (R2 * R2 - R1 * R1); // [T] — B1 in numerator, confirmed by A. Ortiz Aug 2026 + static constexpr double beamStart = 500.; // [cm] + static constexpr double tokGauss = 1. / 0.1; // conversion from Tesla to kGauss - if ((abs(x[2]) <= beamStart) && (sqrt(x[0] * x[0] + x[1] * x[1]) < Rc)) { + static constexpr bool isMagAbs = true; + + const double r = sqrt(x[0] * x[0] + x[1] * x[1]); + if ((abs(x[2]) <= beamStart) && (r < Rc)) { // We are inside of the central region b[0] = 0.; b[1] = 0.; b[2] = B1 * tokGauss; - } else if ((abs(x[2]) <= beamStart) && - (sqrt(x[0] * x[0] + x[1] * x[1]) >= Rc && - sqrt(x[0] * x[0] + x[1] * x[1]) < R1)) { + } else if ((abs(x[2]) <= beamStart) && (r >= Rc && r < R1)) { // We are in the transition region b[0] = 0.; b[1] = 0.; b[2] = 0.; - } else if ((abs(x[2]) <= beamStart) && - (sqrt(x[0] * x[0] + x[1] * x[1]) >= R1 && - sqrt(x[0] * x[0] + x[1] * x[1]) < R2)) { + } else if ((abs(x[2]) <= beamStart) && (r >= R1 && r < R2)) { // We are within the magnet b[0] = 0.; b[1] = 0.; if (isMagAbs) { @@ -57,7 +50,7 @@ std::function field() } else { b[2] = 0.; } - } else { + } else { // We are outside of the magnet b[0] = 0.; b[1] = 0.; b[2] = 0.; @@ -67,10 +60,14 @@ std::function field() void ALICE3Field() { + gStyle->SetPalette(kRainBow); + gStyle->SetNumberContours(255); + auto fieldFunc = field(); // RZ plane visualization - TCanvas* cRZ = new TCanvas("cRZ", "Field in RZ plane", 800, 600); - TH2F* hRZ = new TH2F("hRZ", "Magnetic Field B_z in RZ plane;Z [m];R [m]", 100, -10, 10, 100, -5, 5); + TCanvas* cRZ = new TCanvas("cRZ", "Field in RZ plane", 800, 800); + gPad->SetRightMargin(0.15); + 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); hRZ->SetBit(TH1::kNoStats); // disable stats box for (int i = 1; i <= hRZ->GetNbinsX(); i++) { const double Z = hRZ->GetXaxis()->GetBinCenter(i); @@ -83,12 +80,14 @@ void ALICE3Field() } } + hRZ->GetZaxis()->SetRangeUser(-30, 30); hRZ->Draw("COLZ"); cRZ->Update(); // XY plane visualization - TCanvas* cXY = new TCanvas("cXY", "Field in XY plane", 800, 600); - TH2F* hXY = new TH2F("hXY", "Magnetic Field B_z in XY plane;X [m];Y [m]", 100, -5, 5, 100, -5, 5); + TCanvas* cXY = new TCanvas("cXY", "Field in XY plane", 800, 800); + gPad->SetRightMargin(0.15); + 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); hXY->SetBit(TH1::kNoStats); // disable stats box for (int i = 1; i <= hXY->GetNbinsX(); i++) { @@ -102,6 +101,7 @@ void ALICE3Field() } } + hXY->GetZaxis()->SetRangeUser(-30, 30); hXY->Draw("COLZ"); cXY->Update(); -} \ No newline at end of file +} diff --git a/Detectors/Upgrades/ALICE3/macros/ALICE3FieldShortMagnet.C b/Detectors/Upgrades/ALICE3/macros/ALICE3FieldShortMagnet.C index b12adaa0cc530..356f9b2d0b7ae 100644 --- a/Detectors/Upgrades/ALICE3/macros/ALICE3FieldShortMagnet.C +++ b/Detectors/Upgrades/ALICE3/macros/ALICE3FieldShortMagnet.C @@ -11,18 +11,27 @@ // // Author: J. E. Munoz Mendez jesus.munoz@cern.ch +#include +#include +#include +#include +#include + std::function field() { return [](const double* x, double* b) { - const double Rc = 185.; //[cm] - const double R1 = 220.; //[cm] - const double R2 = 290.; //[cm] - const double B1 = 2.; //[T] - const double B2 = -Rc * Rc / ((R2 * R2 - R1 * R1) * B1); //[T] - const double beamStart = 370.; //[cm] - const double tokGauss = 1. / 0.1; // conversion from Tesla to kGauss + // RADIUS + static constexpr double Rc = 170.; // [cm] — R_out_coil per Ian DetectorConstruction.cc; confirmed by A. Ortiz definition + static constexpr double R1 = 220.; // [cm] + static constexpr double R2 = 290.; // [cm] + + // FIELD + static constexpr double B1 = 2.; // [T] + static constexpr double B2 = -B1 * Rc * Rc / (R2 * R2 - R1 * R1); // [T] — B1 in numerator, confirmed by A. Ortiz Aug 2026 + static constexpr double beamStart = 370.; // [cm] + static constexpr double tokGauss = 1. / 0.1; // conversion from Tesla to kGauss - const bool isMagAbs = true; + static constexpr bool isMagAbs = true; const double r = sqrt(x[0] * x[0] + x[1] * x[1]); if ((abs(x[2]) <= beamStart) && (r < Rc)) { // We are inside of the central region @@ -49,12 +58,16 @@ std::function field() }; } -void ALICE3V3Magnet() +void ALICE3FieldShortMagnet() { + gStyle->SetPalette(kRainBow); + gStyle->SetNumberContours(255); + auto fieldFunc = field(); // RZ plane visualization - TCanvas* cRZ = new TCanvas("cRZ", "Field in RZ plane", 800, 600); - TH2F* hRZ = new TH2F("hRZ", "Magnetic Field B_z in RZ plane;Z [m];R [m]", 100, -10, 10, 100, -5, 5); + TCanvas* cRZ = new TCanvas("cRZ", "Field in RZ plane", 800, 800); + gPad->SetRightMargin(0.15); + 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); hRZ->SetBit(TH1::kNoStats); // disable stats box for (int i = 1; i <= hRZ->GetNbinsX(); i++) { const double Z = hRZ->GetXaxis()->GetBinCenter(i); @@ -67,12 +80,14 @@ void ALICE3V3Magnet() } } + hRZ->GetZaxis()->SetRangeUser(-30, 30); hRZ->Draw("COLZ"); cRZ->Update(); // XY plane visualization - TCanvas* cXY = new TCanvas("cXY", "Field in XY plane", 800, 600); - TH2F* hXY = new TH2F("hXY", "Magnetic Field B_z in XY plane;X [m];Y [m]", 100, -5, 5, 100, -5, 5); + TCanvas* cXY = new TCanvas("cXY", "Field in XY plane", 800, 800); + gPad->SetRightMargin(0.15); + 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); hXY->SetBit(TH1::kNoStats); // disable stats box for (int i = 1; i <= hXY->GetNbinsX(); i++) { @@ -86,6 +101,7 @@ void ALICE3V3Magnet() } } + hXY->GetZaxis()->SetRangeUser(-30, 30); hXY->Draw("COLZ"); cXY->Update(); -} \ No newline at end of file +} From adc08b360142adbe3f5d450b8313008b56406f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Fri, 21 Aug 2026 10:13:05 +0200 Subject: [PATCH 3/4] Add ALICE3FieldMagnet.C test macro --- Detectors/Upgrades/ALICE3/macros/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt b/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt index 0a4f9031355a2..b10b6d4e8cfa5 100644 --- a/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt +++ b/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt @@ -17,3 +17,6 @@ o2_add_test_root_macro(plotHits.C o2_add_test_root_macro(ALICE3FieldShortMagnet.C LABELS alice3) + +o2_add_test_root_macro(ALICE3FieldMagnet.C + LABELS alice3) From e037979ae576953076e4f24c5c81377591a015d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Fri, 21 Aug 2026 16:12:35 +0200 Subject: [PATCH 4/4] Replace ALICE3FieldMagnet with ALICE3Field --- Detectors/Upgrades/ALICE3/macros/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt b/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt index b10b6d4e8cfa5..403c018066d37 100644 --- a/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt +++ b/Detectors/Upgrades/ALICE3/macros/CMakeLists.txt @@ -18,5 +18,5 @@ o2_add_test_root_macro(plotHits.C o2_add_test_root_macro(ALICE3FieldShortMagnet.C LABELS alice3) -o2_add_test_root_macro(ALICE3FieldMagnet.C +o2_add_test_root_macro(ALICE3Field.C LABELS alice3)