BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
smoothMap.C
Go to the documentation of this file.
1
#include <
Rtypes.h
>
2
#include <
TCanvas.h
>
3
#include <
TClonesArray.h
>
4
#include <
TGraph.h
>
5
#include <
TH2F.h
>
6
#include <
TList.h
>
7
#include <
TPaletteAxis.h
>
8
#include <
TString.h
>
9
#include <
TStyle.h
>
10
11
using namespace
std
;
12
13
R__ADD_INCLUDE_PATH
($VMCWORKDIR)
14
#include "macro/run/bmnloadlibs.C"
15
16
Double_t
FirstDerivative
(
BmnFieldMap
*,
Double_t
,
Double_t
,
Double_t
);
17
Double_t
SecondDerivative
(
BmnFieldMap
*,
Double_t
,
Double_t
,
Double_t
);
18
19
Double_t
GetX
(
BmnFieldMap
*,
Int_t
);
20
Double_t
GetY
(
BmnFieldMap
*,
Int_t
);
21
Double_t
GetZ
(
BmnFieldMap
*,
Int_t
);
22
23
void
SmoothByLine
(
Double_t
&,
Double_t
&,
Double_t
,
Double_t
,
Double_t
,
Double_t
);
24
25
class
mapNodes
:
public
TObject
26
{
27
public
:
28
mapNodes
()
29
{
30
nX
= -1;
31
nY
= -1;
32
nZ
= -1;
33
34
nXs
.resize(0);
35
nYs
.resize(0);
36
nZs
.resize(0);
37
38
toBeSmoothed
.resize(0);
39
}
40
41
virtual
~mapNodes
() { ; }
42
43
public
:
44
Int_t
nX
;
45
Int_t
nY
;
46
Int_t
nZ
;
47
48
vector<Int_t>
nXs
;
49
vector<Int_t>
nYs
;
50
vector<Int_t>
nZs
;
51
52
vector<Bool_t>
toBeSmoothed
;
53
54
ClassDef
(
mapNodes
, 1)
55
};
56
57
void
smoothMap
(
TString
in =
""
,
TString
out =
""
)
58
{
59
gStyle
->SetOptStat(0);
60
61
BmnFieldMap
* magField =
new
BmnNewFieldMap
(in);
62
magField->
SetScale
(1.);
63
magField->
Init
();
64
65
Int_t
node = 0;
66
67
map<Double_t, Int_t> xValueNode;
// xValue --> node number
68
map<Double_t, Int_t> yValueNode;
// yValue --> node number
69
map<Double_t, Int_t> zValueNode;
// zValue --> node number
70
71
for
(
Int_t
iX
= magField->
GetXmin
();
iX < magField->
GetXmax() + 1;
iX
+= magField->
GetXstep
()) {
72
xValueNode[(
Double_t
)
iX
] = node;
73
node++;
74
}
75
76
node = 0;
77
78
for
(
Int_t
iY
= magField->
GetYmin
();
iY < magField->
GetYmax() + 1;
iY
+= magField->
GetYstep
()) {
79
yValueNode[(
Double_t
)
iY
] = node;
80
81
node++;
82
}
83
84
node = 0;
85
86
for
(
Int_t
iZ
= magField->
GetZmin
();
iZ < magField->
GetZmax() + 1;
iZ
+= magField->
GetZstep
()) {
87
zValueNode[(
Double_t
)
iZ
] = node;
88
node++;
89
}
90
91
map<Double_t, Double_t> dBdx_fixedYZ[magField->
GetNy
()][magField->
GetNz
()];
92
for
(
Int_t
iNodeY = 0; iNodeY < magField->
GetNy
(); iNodeY++)
93
for
(
Int_t
iNodeZ = 0; iNodeZ < magField->
GetNz
(); iNodeZ++)
94
dBdx_fixedYZ[iNodeY][iNodeZ].clear();
95
96
map<Double_t, Double_t> d2Bdx2_fixedYZ[magField->
GetNy
()][magField->
GetNz
()];
97
for
(
Int_t
iNodeY = 0; iNodeY < magField->
GetNy
(); iNodeY++)
98
for
(
Int_t
iNodeZ = 0; iNodeZ < magField->
GetNz
(); iNodeZ++)
99
d2Bdx2_fixedYZ[iNodeY][iNodeZ].clear();
100
101
for
(
Int_t
iY
= magField->
GetYmin
();
iY < magField->
GetYmax() + 1;
iY
+= magField->
GetYstep
()) {
102
for
(
Int_t
iZ
= magField->
GetZmin
();
iZ < magField->
GetZmax() + 1;
iZ
+= magField->
GetZstep
()) {
103
104
map<Double_t, Double_t> tmp1;
105
map<Double_t, Double_t> tmp2;
106
107
for
(
Int_t
iX
= magField->
GetXmin
();
iX < magField->
GetXmax() + 1;
iX
+= magField->
GetXstep
()) {
108
tmp1[(
Double_t
)
iX
] =
FirstDerivative
(magField,
iX
,
iY
,
iZ
);
109
tmp2[(
Double_t
)
iX
] =
SecondDerivative
(magField,
iX
,
iY
,
iZ
);
110
}
111
dBdx_fixedYZ[yValueNode.find(
iY
)->second][zValueNode.find(
iZ
)->second] = tmp1;
112
d2Bdx2_fixedYZ[yValueNode.find(
iY
)->second][zValueNode.find(
iZ
)->second] = tmp2;
113
}
114
}
115
116
TClonesArray
* nodesInfo =
new
TClonesArray
(
"mapNodes"
);
117
118
for
(
Int_t
iNodeY = 0; iNodeY < magField->
GetNy
(); iNodeY++)
119
for
(
Int_t
iNodeZ = 0; iNodeZ < magField->
GetNz
(); iNodeZ++) {
120
121
mapNodes
* nodeYZ =
new
((*nodesInfo)[nodesInfo->
GetEntriesFast
()])
mapNodes
();
122
nodeYZ->
nY
= iNodeY;
123
nodeYZ->
nZ
= iNodeZ;
124
125
// Looking for X, where the second derivative is deviated strongly ...
126
map<Double_t, Double_t> der2 = d2Bdx2_fixedYZ[iNodeY][iNodeZ];
127
128
// Calculating abs. ave. value of the second derivative ...
129
Double_t
ave = 0;
130
Int_t
usedEntries = 0;
131
132
for
(
auto
it : der2) {
133
if
(
TMath::Abs
(it.first) > 110.)
134
continue
;
135
136
ave +=
TMath::Abs
(it.second);
137
138
usedEntries++;
139
}
140
141
ave /= usedEntries;
142
143
// Comparing current values with the average calculated ...
144
for
(
auto
it : der2) {
145
if
(
TMath::Abs
(it.first) > 110.)
146
continue
;
147
148
nodeYZ->
nXs
.push_back(xValueNode.find(it.first)->second);
149
150
if
(
TMath::Abs
(it.second) >
TMath::Abs
(ave))
151
nodeYZ->
toBeSmoothed
.push_back(
kTRUE
);
152
else
153
nodeYZ->
toBeSmoothed
.push_back(
kFALSE
);
154
}
155
156
if
(nodeYZ->
toBeSmoothed
.size() != nodeYZ->
nXs
.size())
157
throw
;
158
}
159
160
TClonesArray
* newFieldValues =
new
TClonesArray
(
"smoothedValues"
);
161
162
for
(
Int_t
iNodeInfo = 0; iNodeInfo < nodesInfo->
GetEntriesFast
(); iNodeInfo++) {
163
mapNodes
* node = (
mapNodes
*)nodesInfo->
UncheckedAt
(iNodeInfo);
164
165
// Looking for values to be smoothed ...
166
Double_t
Y =
GetY
(magField, node->
nY
);
167
Double_t
Z =
GetZ
(magField, node->
nZ
);
168
169
vector<Double_t> X;
170
171
for
(
Int_t
iNodeX = 0; iNodeX < node->
nXs
.size(); iNodeX++) {
172
173
if
(!node->
toBeSmoothed
[iNodeX])
174
continue
;
175
176
X.push_back(
GetX
(magField, node->
nXs
[iNodeX]));
177
}
178
179
vector<vector<Double_t>> ranges;
180
181
vector<Double_t> tmp;
182
for
(
auto
x0 = X.begin(); x0 < X.end(); x0++) {
183
auto
x1 = next(x0, 1);
184
185
Double_t
X0 = *x0;
186
Double_t
X1 = *x1;
187
188
if
(
TMath::Abs
(X1 - X0) == magField->
GetXstep
()) {
189
if
(tmp.size() != 0)
190
tmp.pop_back();
191
tmp.push_back(X0);
192
tmp.push_back(X1);
193
}
else
{
194
tmp.push_back(X0);
195
ranges.push_back(tmp);
196
tmp.resize(0);
197
}
198
}
199
200
for
(
auto
v
: ranges) {
201
Double_t
l =
v
.front() - magField->
GetXstep
();
202
Double_t
r =
v
.back() + magField->
GetXstep
();
203
204
Double_t
fL = magField->
GetBy
(l, Y, Z);
205
Double_t
fR = magField->
GetBy
(r, Y, Z);
206
207
Double_t
k = 0., b = 0.;
208
SmoothByLine
(k, b, l, fL, r, fR);
209
// cout << k << " -- " << b << endl;
210
211
if
(
v
.size() > 1)
212
v
.pop_back();
213
214
for
(
auto
it :
v
) {
215
smoothedValues
* newValue =
new
((*newFieldValues)[newFieldValues->
GetEntriesFast
()])
smoothedValues
();
216
// cout << it << " From map# " << magField->GetBy(it, Y, Z) << " Smoothed# " << k * it + b << endl;
217
newValue->
X
= it;
218
newValue->
Y
= Y;
219
newValue->
Z
= Z;
220
221
newValue->
fieldValue
= k * it + b;
222
}
223
}
224
}
225
226
BmnSP41FieldMapCreator
* smoothedMap =
new
BmnSP41FieldMapCreator
(in, out);
227
smoothedMap->
SmoothMap
(newFieldValues);
228
229
delete
smoothedMap;
230
delete
magField;
231
}
232
233
Double_t
FirstDerivative
(
BmnFieldMap
* map,
Double_t
x,
Double_t
Y,
Double_t
Z)
234
{
235
const
Double_t
h = map->
GetXstep
();
236
237
if
(
TMath::Abs
(x - map->
GetXmin
()) < FLT_EPSILON ||
TMath::Abs
(x - map->
GetXmax
()) < FLT_EPSILON)
238
return
0.;
239
240
Double_t
x1 = x;
241
Double_t
y1 = map->
GetBy
(x1, Y, Z);
242
243
Double_t
x0 = x1 - h;
244
Double_t
y0 = map->
GetBy
(x0, Y, Z);
245
246
Double_t
x2 = x1 + h;
247
Double_t
y2 = map->
GetBy
(x2, Y, Z);
248
249
Double_t
der = (1. / 2 * h * h) * ((x1 - x2) * y0 - 2 * (2 * x1 - x0 - x2) * y1 + (x1 - x0) * y2);
250
251
return
der;
252
}
253
254
Double_t
SecondDerivative
(
BmnFieldMap
* map,
Double_t
x,
Double_t
Y,
Double_t
Z)
255
{
256
const
Double_t
h = map->
GetXstep
();
257
258
if
(
TMath::Abs
(x - map->
GetXmin
()) < FLT_EPSILON ||
TMath::Abs
(x - map->
GetXmax
()) < FLT_EPSILON)
259
return
0.;
260
261
Double_t
x1 = x;
262
Double_t
y1 = map->
GetBy
(x1, Y, Z);
263
264
Double_t
x0 = x1 - h;
265
Double_t
y0 = map->
GetBy
(x0, Y, Z);
266
267
Double_t
x2 = x1 + h;
268
Double_t
y2 = map->
GetBy
(x2, Y, Z);
269
270
Double_t
der = (1. / h * h) * (y0 - 2 * y1 + y2);
271
272
return
der;
273
}
274
275
Double_t
GetZ
(
BmnFieldMap
* map,
Int_t
node)
276
{
277
return
map->
GetZmin
() + node * map->
GetZstep
();
278
}
279
280
Double_t
GetY
(
BmnFieldMap
* map,
Int_t
node)
281
{
282
return
map->
GetYmin
() + node * map->
GetYstep
();
283
}
284
285
Double_t
GetX
(
BmnFieldMap
* map,
Int_t
node)
286
{
287
return
map->
GetXmin
() + node * map->
GetXstep
();
288
}
289
290
void
SmoothByLine
(
Double_t
& k,
Double_t
& b,
Double_t
x0,
Double_t
y0,
Double_t
x1,
Double_t
y1)
291
{
292
k = (y1 - y0) / (x1 - x0);
293
294
b = y1 - k * x1;
295
}
v
__m128 v
Definition
P4_F32vec4.h:1
Int_t
int Int_t
kFALSE
constexpr Bool_t kFALSE
Double_t
double Double_t
kTRUE
constexpr Bool_t kTRUE
Rtypes.h
ClassDef
#define ClassDef(name, id)
R__ADD_INCLUDE_PATH
#define R__ADD_INCLUDE_PATH(PATH)
TCanvas.h
TClonesArray.h
TGraph.h
TH2F.h
TList.h
TPaletteAxis.h
TString.h
TStyle.h
gStyle
R__EXTERN TStyle * gStyle
iZ
@ iZ
Definition
BmnAlignDefines.h:87
iX
@ iX
Definition
BmnAlignDefines.h:85
iY
@ iY
Definition
BmnAlignDefines.h:86
BmnFieldMap
Definition
BmnFieldMap.h:22
BmnFieldMap::GetNz
Int_t GetNz() const
Definition
BmnFieldMap.h:82
BmnFieldMap::GetYstep
Double_t GetYstep() const
Definition
BmnFieldMap.h:77
BmnFieldMap::GetZstep
Double_t GetZstep() const
Definition
BmnFieldMap.h:78
BmnFieldMap::GetXstep
Double_t GetXstep() const
Definition
BmnFieldMap.h:76
BmnFieldMap::GetBy
virtual Double_t GetBy(Double_t x, Double_t y, Double_t z)=0
BmnFieldMap::GetZmin
Double_t GetZmin() const
Definition
BmnFieldMap.h:70
BmnFieldMap::GetYmin
Double_t GetYmin() const
Definition
BmnFieldMap.h:69
BmnFieldMap::SetScale
void SetScale(Double_t factor)
Set a global field scaling factor.
Definition
BmnFieldMap.h:55
BmnFieldMap::GetXmax
Double_t GetXmax() const
Definition
BmnFieldMap.h:72
BmnFieldMap::GetNy
Int_t GetNy() const
Definition
BmnFieldMap.h:81
BmnFieldMap::Init
virtual void Init()
Definition
BmnFieldMap.cxx:120
BmnFieldMap::GetXmin
Double_t GetXmin() const
Accessors to field parameters in local coordinate system.
Definition
BmnFieldMap.h:68
BmnNewFieldMap
Field Map does not have any symmetries w.r.t coordinate axises.
Definition
BmnNewFieldMap.h:16
BmnSP41FieldMapCreator
Definition
BmnSP41FieldMapCreator.h:79
BmnSP41FieldMapCreator::SmoothMap
void SmoothMap(TClonesArray *)
Definition
BmnSP41FieldMapCreator.cxx:554
TClonesArray
TObjArray::GetEntriesFast
Int_t GetEntriesFast() const
TObjArray::UncheckedAt
TObject * UncheckedAt(Int_t i) const
TObject
TString
mapNodes
Definition
smoothMap.C:26
mapNodes::mapNodes
mapNodes()
Definition
smoothMap.C:28
mapNodes::nX
Int_t nX
Definition
smoothMap.C:44
mapNodes::nXs
vector< Int_t > nXs
Definition
smoothMap.C:48
mapNodes::nZ
Int_t nZ
Definition
smoothMap.C:46
mapNodes::~mapNodes
virtual ~mapNodes()
Definition
smoothMap.C:41
mapNodes::nY
Int_t nY
Definition
smoothMap.C:45
mapNodes::nZs
vector< Int_t > nZs
Definition
smoothMap.C:50
mapNodes::toBeSmoothed
vector< Bool_t > toBeSmoothed
Definition
smoothMap.C:52
mapNodes::nYs
vector< Int_t > nYs
Definition
smoothMap.C:49
smoothedValues
Definition
BmnSP41FieldMapCreator.h:58
smoothedValues::X
Double_t X
Definition
BmnSP41FieldMapCreator.h:70
smoothedValues::Y
Double_t Y
Definition
BmnSP41FieldMapCreator.h:71
smoothedValues::fieldValue
Double_t fieldValue
Definition
BmnSP41FieldMapCreator.h:73
smoothedValues::Z
Double_t Z
Definition
BmnSP41FieldMapCreator.h:72
FirstDerivative
Double_t FirstDerivative(BmnFieldMap *, Double_t, Double_t, Double_t)
Definition
smoothMap.C:233
GetX
Double_t GetX(BmnFieldMap *, Int_t)
Definition
smoothMap.C:285
SecondDerivative
Double_t SecondDerivative(BmnFieldMap *, Double_t, Double_t, Double_t)
Definition
smoothMap.C:254
GetZ
Double_t GetZ(BmnFieldMap *, Int_t)
Definition
smoothMap.C:275
SmoothByLine
void SmoothByLine(Double_t &, Double_t &, Double_t, Double_t, Double_t, Double_t)
Definition
smoothMap.C:290
smoothMap
void smoothMap(TString in="", TString out="")
Definition
smoothMap.C:57
GetY
Double_t GetY(BmnFieldMap *, Int_t)
Definition
smoothMap.C:280
TMath::Abs
Double_t Abs(Double_t d)
std
Definition
json.hpp:4446
macro
magfield
smoothMap.C
Generated on
for BmnRoot by
1.17.0