Skip to content

Commit ae79547

Browse files
refactor(r3bbase):Update classes and remove old macro to generate GLAD geometry
Co-authored-by: YanzhaoW <yannzhaow@gmail.com>
1 parent 075fa1f commit ae79547

43 files changed

Lines changed: 619 additions & 6498 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

field/R3BFieldConst.cxx

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
22
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3-
* Copyright (C) 2019-2025 Members of R3B Collaboration *
3+
* Copyright (C) 2019-2026 Members of R3B Collaboration *
44
* *
55
* This software is distributed under the terms of the *
66
* GNU General Public Licence (GPL) version 3, *
@@ -14,45 +14,38 @@
1414
// -------------------------------------------------------------------------
1515
// ----- R3BFieldConst source file -----
1616
// -------------------------------------------------------------------------
17-
#include "R3BFieldConst.h"
1817

18+
#include "R3BFieldConst.h"
19+
#include "R3BException.h"
1920
#include "R3BFieldPar.h"
2021

21-
#include <iomanip>
22+
#include <FairLogger.h>
23+
#include <FairRun.h>
24+
#include <FairRuntimeDb.h>
25+
26+
#include <fmt/format.h>
2227
#include <iostream>
2328

24-
using std::cerr;
25-
using std::cout;
26-
using std::endl;
27-
using std::setw;
29+
using fmt::format;
2830

2931
// ----- Default constructor -------------------------------------------
3032
R3BFieldConst::R3BFieldConst()
31-
: fXmin(0.)
32-
, fXmax(0.)
33-
, fYmin(0.)
34-
, fYmax(0.)
35-
, fZmin(0.)
36-
, fZmax(0.)
37-
, fBx(0.)
38-
, fBy(0.)
39-
, fBz(0.)
33+
: R3BFieldConst{ "R3BConstField", 0., 0., 0., 0., 0., 0., 0., 0., 0. }
4034
{
41-
fType = 0;
4235
}
4336
// -------------------------------------------------------------------------
4437

4538
// ----- Standard constructor ------------------------------------------
4639
R3BFieldConst::R3BFieldConst(const char* name,
47-
Double_t xMin,
48-
Double_t xMax,
49-
Double_t yMin,
50-
Double_t yMax,
51-
Double_t zMin,
52-
Double_t zMax,
53-
Double_t bX,
54-
Double_t bY,
55-
Double_t bZ)
40+
double xMin,
41+
double xMax,
42+
double yMin,
43+
double yMax,
44+
double zMin,
45+
double zMax,
46+
double bX,
47+
double bY,
48+
double bZ)
5649
: FairField(name)
5750
, fXmin(xMin)
5851
, fXmax(xMax)
@@ -70,19 +63,10 @@ R3BFieldConst::R3BFieldConst(const char* name,
7063

7164
// -------- Constructor from R3BFieldPar -------------------------------
7265
R3BFieldConst::R3BFieldConst(R3BFieldPar* fieldPar)
73-
: fXmin(0.)
74-
, fXmax(0.)
75-
, fYmin(0.)
76-
, fYmax(0.)
77-
, fZmin(0.)
78-
, fZmax(0.)
79-
, fBx(0.)
80-
, fBy(0.)
81-
, fBz(0.)
8266
{
8367
if (!fieldPar)
8468
{
85-
cerr << "-W- R3BFieldConst::R3BFieldConst: empty parameter container!" << endl;
69+
LOG(warn) << "R3BFieldConst: Empty parameter container.";
8670
fType = 0;
8771
}
8872
else
@@ -106,12 +90,7 @@ R3BFieldConst::~R3BFieldConst() {}
10690
// -------------------------------------------------------------------------
10791

10892
// ----- Set field region ----------------------------------------------
109-
void R3BFieldConst::SetFieldRegion(Double_t xMin,
110-
Double_t xMax,
111-
Double_t yMin,
112-
Double_t yMax,
113-
Double_t zMin,
114-
Double_t zMax)
93+
void R3BFieldConst::SetFieldRegion(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax)
11594
{
11695
fXmin = xMin;
11796
fXmax = xMax;
@@ -123,7 +102,7 @@ void R3BFieldConst::SetFieldRegion(Double_t xMin,
123102
// -------------------------------------------------------------------------
124103

125104
// ----- Set field values ----------------------------------------------
126-
void R3BFieldConst::SetField(Double_t bX, Double_t bY, Double_t bZ)
105+
void R3BFieldConst::SetField(double bX, double bY, double bZ)
127106
{
128107
fBx = bX;
129108
fBy = bY;
@@ -132,7 +111,7 @@ void R3BFieldConst::SetField(Double_t bX, Double_t bY, Double_t bZ)
132111
// -------------------------------------------------------------------------
133112

134113
// ----- Get x component of field --------------------------------------
135-
Double_t R3BFieldConst::GetBx(Double_t x, Double_t y, Double_t z)
114+
double R3BFieldConst::GetBx(double x, double y, double z)
136115
{
137116
if (x < fXmin || x > fXmax || y < fYmin || y > fYmax || z < fZmin || z > fZmax)
138117
return 0.;
@@ -141,7 +120,7 @@ Double_t R3BFieldConst::GetBx(Double_t x, Double_t y, Double_t z)
141120
// -------------------------------------------------------------------------
142121

143122
// ----- Get y component of field --------------------------------------
144-
Double_t R3BFieldConst::GetBy(Double_t x, Double_t y, Double_t z)
123+
double R3BFieldConst::GetBy(double x, double y, double z)
145124
{
146125
if (x < fXmin || x > fXmax || y < fYmin || y > fYmax || z < fZmin || z > fZmax)
147126
return 0.;
@@ -150,7 +129,7 @@ Double_t R3BFieldConst::GetBy(Double_t x, Double_t y, Double_t z)
150129
// -------------------------------------------------------------------------
151130

152131
// ----- Get z component of field --------------------------------------
153-
Double_t R3BFieldConst::GetBz(Double_t x, Double_t y, Double_t z)
132+
double R3BFieldConst::GetBz(double x, double y, double z)
154133
{
155134
if (x < fXmin || x > fXmax || y < fYmin || y > fYmax || z < fZmin || z > fZmax)
156135
return 0.;
@@ -161,19 +140,28 @@ Double_t R3BFieldConst::GetBz(Double_t x, Double_t y, Double_t z)
161140
// ----- Screen output -------------------------------------------------
162141
void R3BFieldConst::Print(Option_t*) const
163142
{
164-
cout << "======================================================" << endl;
165-
cout << "---- " << fTitle << " : " << fName << endl;
166-
cout << "----" << endl;
167-
cout << "---- Field type : constant" << endl;
168-
cout << "----" << endl;
169-
cout << "---- Field regions : " << endl;
170-
cout << "---- x = " << setw(4) << fXmin << " to " << setw(4) << fXmax << " cm" << endl;
171-
cout << "---- y = " << setw(4) << fYmin << " to " << setw(4) << fYmax << " cm" << endl;
172-
cout << "---- z = " << setw(4) << fZmin << " to " << setw(4) << fZmax << " cm" << endl;
173-
cout.precision(4);
174-
cout << "---- B = ( " << fBx << ", " << fBy << ", " << fBz << " ) kG" << endl;
175-
cout << "======================================================" << endl;
143+
std::cout << "======================================================" << std::endl;
144+
std::cout << format("---- {} : {}\n", fTitle.Data(), fName.Data());
145+
std::cout << "---- Field type : constant\n";
146+
std::cout << "---- Field regions :\n";
147+
std::cout << format("---- x = {:6.2f} to {:6.2f} cm\n", fXmin, fXmax);
148+
std::cout << format("---- y = {:6.2f} to {:6.2f} cm\n", fYmin, fYmax);
149+
std::cout << format("---- z = {:6.2f} to {:6.2f} cm\n", fZmin, fZmax);
150+
std::cout << format("---- B = ( {:.4f}, {:.4f}, {:.4f} ) kG\n", fBx, fBy, fBz);
176151
}
177152
// -------------------------------------------------------------------------
178153

154+
void R3BFieldConst::FillParContainer()
155+
{
156+
auto* run = FairRun::Instance();
157+
auto* rtdb = run->GetRuntimeDb();
158+
auto* par = std::make_unique<R3BFieldPar>().release();
159+
par->SetParameters(this);
160+
par->setChanged();
161+
if (rtdb->addContainer(par); par == nullptr)
162+
{
163+
throw R3B::runtime_error("Calibration parameter becomes nullptr!");
164+
}
165+
}
166+
179167
ClassImp(R3BFieldConst)

field/R3BFieldConst.h

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
22
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3-
* Copyright (C) 2019-2025 Members of R3B Collaboration *
3+
* Copyright (C) 2019-2026 Members of R3B Collaboration *
44
* *
55
* This software is distributed under the terms of the *
66
* GNU General Public Licence (GPL) version 3, *
@@ -15,13 +15,6 @@
1515
// ----- R3BFieldConst header file -----
1616
// -------------------------------------------------------------------------
1717

18-
/** R3BFieldConst.h
19-
** @since 12.01.2004
20-
** @version1.0
21-
**
22-
** A constant (homogeneous) magnetic field
23-
**/
24-
2518
#pragma once
2619

2720
#include <FairField.h>
@@ -49,71 +42,73 @@ class R3BFieldConst : public FairField
4942
** @param bX,bY,bZ Field values [kG]
5043
**/
5144
R3BFieldConst(const char* name,
52-
Double_t xMin,
53-
Double_t xMax,
54-
Double_t yMin,
55-
Double_t yMax,
56-
Double_t zMin,
57-
Double_t zMax,
58-
Double_t bX,
59-
Double_t bY,
60-
Double_t bZ);
45+
double xMin,
46+
double xMax,
47+
double yMin,
48+
double yMax,
49+
double zMin,
50+
double zMax,
51+
double bX,
52+
double bY,
53+
double bZ);
6154

6255
/** Constructor from R3BFieldPar **/
6356
R3BFieldConst(R3BFieldPar* fieldPar);
6457

6558
/** Destructor **/
66-
virtual ~R3BFieldConst();
59+
~R3BFieldConst() override;
6760

6861
/** Set the field region
6962
** @param xMin,xMax x region of field (global coordinates)
7063
** @param yMin,yMax y region of field (global coordinates)
7164
** @param zMin,zMax z region of field (global coordinates)
7265
**/
73-
void SetFieldRegion(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin, Double_t zMax);
66+
void SetFieldRegion(double xMin, double xMax, double yMin, double yMax, double zMin, double zMax);
7467

7568
/** Set the field values
7669
** @param bX,bY,bZ Field values [kG]
7770
**/
78-
void SetField(Double_t bX, Double_t bY, Double_t bZ);
71+
void SetField(double bX, double bY, double bZ);
7972

8073
/** Get components of field at a given point
8174
** @param x,y,z Point coordinates [cm]
8275
**/
83-
virtual Double_t GetBx(Double_t x, Double_t y, Double_t z);
84-
virtual Double_t GetBy(Double_t x, Double_t y, Double_t z);
85-
virtual Double_t GetBz(Double_t x, Double_t y, Double_t z);
76+
auto GetBx(double x, double y, double z) -> double override;
77+
auto GetBy(double x, double y, double z) -> double override;
78+
auto GetBz(double x, double y, double z) -> double override;
8679

8780
/** Accessors to field region **/
88-
Double_t GetXmin() const { return fXmin; }
89-
Double_t GetXmax() const { return fXmax; }
90-
Double_t GetYmin() const { return fYmin; }
91-
Double_t GetYmax() const { return fYmax; }
92-
Double_t GetZmin() const { return fZmin; }
93-
Double_t GetZmax() const { return fZmax; }
81+
[[nodiscard]] auto GetXmin() const -> double { return fXmin; }
82+
[[nodiscard]] auto GetXmax() const -> double { return fXmax; }
83+
[[nodiscard]] auto GetYmin() const -> double { return fYmin; }
84+
[[nodiscard]] auto GetYmax() const -> double { return fYmax; }
85+
[[nodiscard]] auto GetZmin() const -> double { return fZmin; }
86+
[[nodiscard]] auto GetZmax() const -> double { return fZmax; }
9487

9588
/** Accessors to field values **/
96-
Double_t GetBx() const { return fBx; }
97-
Double_t GetBy() const { return fBy; }
98-
Double_t GetBz() const { return fBz; }
89+
[[nodiscard]] auto GetBx() const -> double { return fBx; }
90+
[[nodiscard]] auto GetBy() const -> double { return fBy; }
91+
[[nodiscard]] auto GetBz() const -> double { return fBz; }
9992

10093
/** Screen output **/
101-
virtual void Print(Option_t* option = "") const;
94+
void Print(Option_t* option = "") const override;
10295

10396
private:
10497
/** Limits of the field region **/
105-
Double_t fXmin;
106-
Double_t fXmax;
107-
Double_t fYmin;
108-
Double_t fYmax;
109-
Double_t fZmin;
110-
Double_t fZmax;
98+
double fXmin{};
99+
double fXmax{};
100+
double fYmin{};
101+
double fYmax{};
102+
double fZmin{};
103+
double fZmax{};
111104

112105
/** Field components inside the field region **/
113-
Double_t fBx;
114-
Double_t fBy;
115-
Double_t fBz;
106+
double fBx{};
107+
double fBy{};
108+
double fBz{};
109+
110+
void FillParContainer() override;
116111

117112
public:
118-
ClassDef(R3BFieldConst, 1);
113+
ClassDefOverride(R3BFieldConst, 1);
119114
};

field/R3BFieldContFact.cxx

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
22
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3-
* Copyright (C) 2019-2025 Members of R3B Collaboration *
3+
* Copyright (C) 2019-2026 Members of R3B Collaboration *
44
* *
55
* This software is distributed under the terms of the *
66
* GNU General Public Licence (GPL) version 3, *
@@ -15,18 +15,16 @@
1515
// ----- R3BFieldContFact source file -----
1616
// ----- Created 20/02/06 by V. Friese -----
1717
// -------------------------------------------------------------------------
18-
#include "R3BFieldContFact.h"
1918

19+
#include "R3BFieldContFact.h"
2020
#include "R3BFieldPar.h"
21+
#include <R3BLogger.h>
2122

22-
#include "FairLogger.h"
23-
#include "FairParSet.h"
24-
#include "FairRuntimeDb.h"
23+
#include <FairParSet.h>
24+
#include <FairRuntimeDb.h>
2525

2626
#include <iostream>
27-
28-
using std::cout;
29-
using std::endl;
27+
#include <string>
3028

3129
static R3BFieldContFact gR3BFieldContFact;
3230

@@ -38,31 +36,27 @@ R3BFieldContFact::R3BFieldContFact()
3836
SetAllContainers();
3937
FairRuntimeDb::instance()->addContFactory(this);
4038
}
41-
// -------------------------------------------------------------------------
42-
43-
// ----- Destructor ----------------------------------------------------
44-
R3BFieldContFact::~R3BFieldContFact() {}
45-
// -------------------------------------------------------------------------
4639

4740
// ----- Create containers ---------------------------------------------
4841
FairParSet* R3BFieldContFact::createContainer(FairContainer* container)
4942
{
43+
const std::string name(container->GetName());
44+
R3BLOG(info, "Create container name: " << name.c_str());
45+
46+
FairParSet* set = nullptr;
5047

51-
const char* name = container->GetName();
52-
LOG(info) << "create R3BFieldPar container " << name;
53-
FairParSet* set = NULL;
54-
if (strcmp(name, "R3BFieldPar") == 0)
48+
if (name == "R3BFieldPar")
49+
{
5550
set = new R3BFieldPar(container->getConcatName().Data(), container->GetTitle(), container->getContext());
51+
}
5652
return set;
5753
}
58-
// -------------------------------------------------------------------------
5954

6055
// ----- Set all containers (private) ----------------------------------
6156
void R3BFieldContFact::SetAllContainers()
6257
{
63-
FairContainer* container = new FairContainer("R3BFieldPar", "Field parameter container", "Default field");
58+
auto* container = new FairContainer("R3BFieldPar", "Field parameter container", "Default field");
6459
containers->Add(container);
6560
}
66-
// -------------------------------------------------------------------------
6761

6862
ClassImp(R3BFieldContFact)

0 commit comments

Comments
 (0)