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, *
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 -------------------------------------------
3032R3BFieldConst::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 ------------------------------------------
4639R3BFieldConst::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 -------------------------------
7265R3BFieldConst::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 -------------------------------------------------
162141void 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+
179167ClassImp (R3BFieldConst)
0 commit comments