CbmRoot
Loading...
Searching...
No Matches
CbmFieldMapCreator.cxx
Go to the documentation of this file.
1
/* Copyright (C) 2008-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2
SPDX-License-Identifier: GPL-3.0-only
3
Authors: Volker Friese [committer], Florian Uhlig */
4
5
// -------------------------------------------------------------------------
6
// ----- CbmFieldMapCreator source file -----
7
// ----- Created 15/01/08 by V. Friese -----
8
// -------------------------------------------------------------------------
9
#include "
CbmFieldMapCreator.h
"
10
11
#include "
CbmFieldMap.h
"
// for CbmFieldMap
12
13
#include <FairField.h>
// for FairField
14
15
#include <TArrayF.h>
// for TArrayF
16
#include <TCollection.h>
// for TIter
17
#include <TList.h>
// for TList
18
19
#include <cstring>
// for strcmp
20
#include <iostream>
// for operator<<, basic_ostream, endl, ostream, cout
21
22
using namespace
std
;
23
24
// ------------- Default constructor -----------------------------------
25
CbmFieldMapCreator::CbmFieldMapCreator
()
26
: fMapName(
""
)
27
, fNx(0)
28
, fNy(0)
29
, fNz(0)
30
, fXmin(0.)
31
, fXmax(0.)
32
, fYmin(0.)
33
, fYmax(0.)
34
, fZmin(0.)
35
, fZmax(0.)
36
, fBx(nullptr)
37
, fBy(nullptr)
38
, fBz(nullptr)
39
, fFieldList()
40
, fInit(kFALSE)
41
{
42
}
43
// ------------------------------------------------------------------------
44
45
46
// ------------- Standard constructor ----------------------------------
47
CbmFieldMapCreator::CbmFieldMapCreator
(
const
char
* mapName)
48
: fMapName(mapName)
49
, fNx(0)
50
, fNy(0)
51
, fNz(0)
52
, fXmin(0.)
53
, fXmax(0.)
54
, fYmin(0.)
55
, fYmax(0.)
56
, fZmin(0.)
57
, fZmax(0.)
58
, fBx(nullptr)
59
, fBy(nullptr)
60
, fBz(nullptr)
61
, fFieldList()
62
, fInit(kFALSE)
63
64
{
65
}
66
// ------------------------------------------------------------------------
67
68
69
// ------------ Destructor --------------------------------------------
70
CbmFieldMapCreator::~CbmFieldMapCreator
()
71
{
72
if
(
fBx
)
delete
fBx
;
73
if
(
fBy
)
delete
fBy
;
74
if
(
fBz
)
delete
fBz
;
75
fFieldList
.Clear();
76
}
77
// ------------------------------------------------------------------------
78
79
80
// ------------- Public method SetGridParameters ----------------------
81
void
CbmFieldMapCreator::SetGridParameters
(
Int_t
nx, Double_t xmin, Double_t xmax,
Int_t
ny, Double_t ymin,
82
Double_t ymax,
Int_t
nz, Double_t zmin, Double_t zmax)
83
{
84
fNx
= nx;
85
fNy
= ny;
86
fNz
= nz;
87
fXmin
= xmin;
88
fYmin
= ymin;
89
fZmin
= zmin;
90
fXmax
= xmax;
91
fYmax
= ymax;
92
fZmax
= zmax;
93
fInit
= kTRUE;
94
}
95
// ------------------------------------------------------------------------
96
97
98
// ----------- Public method CreateMap --------------------------------
99
Bool_t
CbmFieldMapCreator::CreateMap
(
const
char
* fileName)
100
{
101
102
// Define output file name
103
TString outFileName = fileName;
104
105
if
(strcmp(fileName,
""
) == 0) {
106
// if (fileName == "") {
107
outFileName =
fMapName
+
".root"
;
108
}
109
110
// Check for proper intialisation
111
if
(!
fInit
) {
112
cout <<
"-E- CbmFieldMapCreator::CreateMap: "
113
<<
"Grid parameters are not specified!"
<< endl;
114
return
kFALSE;
115
}
116
if
(
fFieldList
.IsEmpty()) {
117
cout <<
"-E- CbmFieldMapCreator::CreateMap: "
118
<<
"No input field(s) specified!"
<< endl;
119
return
kFALSE;
120
}
121
122
// Create field arrays
123
fBx
=
new
TArrayF(
fNx
*
fNy
*
fNz
);
124
fBy
=
new
TArrayF(
fNx
*
fNy
*
fNz
);
125
fBz
=
new
TArrayF(
fNx
*
fNy
*
fNz
);
126
127
// Calculate grid step sizes
128
Double_t xStep = (
fXmax
-
fXmin
) / Double_t(
fNx
- 1);
129
Double_t yStep = (
fYmax
-
fYmin
) / Double_t(
fNy
- 1);
130
Double_t zStep = (
fZmax
-
fZmin
) / Double_t(
fNz
- 1);
131
132
// Control output
133
cout.precision(2);
134
cout <<
"-I- CbmFieldMapCreator: Grid step sizes are "
<< xStep <<
", "
<< yStep <<
", "
<< zStep <<
" cm"
<< endl;
135
cout <<
" Using "
<<
fFieldList
.GetSize() <<
" input fields."
<< endl;
136
cout <<
" Total number of grid points is "
<<
fNx
*
fNy
*
fNz
<< endl;
137
138
// Triple loop over grid points
139
Double_t
x
= 0.;
140
Double_t
y
= 0.;
141
Double_t z = 0.;
142
for
(
Int_t
ix = 0; ix <
fNx
; ix++) {
143
x
=
fXmin
+ Double_t(ix) * xStep;
144
for
(
Int_t
iy = 0; iy <
fNy
; iy++) {
145
y
=
fYmin
+ Double_t(iy) * yStep;
146
for
(
Int_t
iz = 0; iz <
fNz
; iz++) {
147
z =
fZmin
+ Double_t(iz) * zStep;
148
149
// Get and add all field values at this grid point
150
Double_t bx = 0.;
151
Double_t by = 0.;
152
Double_t bz = 0.;
153
TIter next(&
fFieldList
);
154
while
(FairField* field = ((FairField*) next())) {
155
bx += field->GetBx(
x
,
y
, z);
156
by += field->GetBy(
x
,
y
, z);
157
bz += field->GetBz(
x
,
y
, z);
158
}
159
160
// Store field values in arrays
161
Int_t
index = ix *
fNy
*
fNz
+ iy *
fNz
+ iz;
162
fBx
->AddAt(
Float_t
(bx), index);
163
fBy
->AddAt(
Float_t
(by), index);
164
fBz
->AddAt(
Float_t
(bz), index);
165
}
166
}
167
}
168
169
// Create new field map
170
CbmFieldMap
* fieldMap =
new
CbmFieldMap
(
this
);
171
172
// Write the new field map to the ROOT file
173
fieldMap->
WriteRootFile
(outFileName.Data(),
fMapName
.Data());
174
175
// Delete new field map
176
delete
fieldMap;
177
178
cout <<
"-I- CbmFieldMapCreator: Field map "
<<
fMapName
<<
" was stored in "
<< outFileName << endl;
179
return
kTRUE;
180
}
181
// ------------------------------------------------------------------------
CbmFieldMapCreator.h
CbmFieldMap.h
y
Double_t y
Definition
CbmMvdSensorDigiToHitTask.cxx:64
x
Double_t x
Definition
CbmMvdSensorDigiToHitTask.cxx:64
Float_t
float Float_t
Definition
RootTypesDef.h:17
Int_t
int Int_t
Definition
RootTypesDef.h:16
Bool_t
bool Bool_t
Definition
RootTypesDef.h:15
CbmFieldMapCreator::fNy
Int_t fNy
Definition
CbmFieldMapCreator.h:91
CbmFieldMapCreator::fNz
Int_t fNz
Definition
CbmFieldMapCreator.h:91
CbmFieldMapCreator::SetGridParameters
void SetGridParameters(Int_t nx, Double_t xmin, Double_t xmax, Int_t ny, Double_t ymin, Double_t ymax, Int_t nz, Double_t zmin, Double_t zmax)
Definition
CbmFieldMapCreator.cxx:81
CbmFieldMapCreator::fYmin
Double_t fYmin
Definition
CbmFieldMapCreator.h:93
CbmFieldMapCreator::fBz
TArrayF * fBz
Definition
CbmFieldMapCreator.h:97
CbmFieldMapCreator::fFieldList
TList fFieldList
Definition
CbmFieldMapCreator.h:98
CbmFieldMapCreator::fNx
Int_t fNx
Definition
CbmFieldMapCreator.h:91
CbmFieldMapCreator::fInit
Bool_t fInit
Definition
CbmFieldMapCreator.h:99
CbmFieldMapCreator::fBy
TArrayF * fBy
Definition
CbmFieldMapCreator.h:96
CbmFieldMapCreator::fZmin
Double_t fZmin
Definition
CbmFieldMapCreator.h:94
CbmFieldMapCreator::fMapName
TString fMapName
Definition
CbmFieldMapCreator.h:90
CbmFieldMapCreator::CbmFieldMapCreator
CbmFieldMapCreator()
Definition
CbmFieldMapCreator.cxx:25
CbmFieldMapCreator::CreateMap
Bool_t CreateMap(const char *fileName="")
Definition
CbmFieldMapCreator.cxx:99
CbmFieldMapCreator::fXmin
Double_t fXmin
Definition
CbmFieldMapCreator.h:92
CbmFieldMapCreator::~CbmFieldMapCreator
virtual ~CbmFieldMapCreator()
Definition
CbmFieldMapCreator.cxx:70
CbmFieldMapCreator::fYmax
Double_t fYmax
Definition
CbmFieldMapCreator.h:93
CbmFieldMapCreator::fBx
TArrayF * fBx
Definition
CbmFieldMapCreator.h:95
CbmFieldMapCreator::fZmax
Double_t fZmax
Definition
CbmFieldMapCreator.h:94
CbmFieldMapCreator::fXmax
Double_t fXmax
Definition
CbmFieldMapCreator.h:92
CbmFieldMap
Definition
CbmFieldMap.h:38
CbmFieldMap::WriteRootFile
void WriteRootFile(const char *fileName, const char *mapName)
Definition
CbmFieldMap.cxx:526
std
Hash for CbmL1LinkKey.
Definition
algo/base/Options.cxx:21
core
field
CbmFieldMapCreator.cxx
Generated on Fri Mar 7 2025 23:04:09 for CbmRoot by
1.12.0