BmnRoot
Loading...
Searching...
No Matches
BmnNewFieldMap.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- BmnNewFieldMap source file -----
3// ----- Created 03/02/2015 by P. Batyuk -----
4// -------------------------------------------------------------------------
5#include "BmnNewFieldMap.h"
6
7#include "BmnFieldPar.h"
8#include "FairRun.h"
9#include "FairRuntimeDb.h"
10#include "TArrayF.h"
11#include "TMath.h"
12
13using namespace TMath;
14
16 : BmnFieldMap()
17{
18 fType = 1;
19}
20
21BmnNewFieldMap::BmnNewFieldMap(const char* mapFileName)
22 : BmnFieldMap(mapFileName)
23{
24 fType = 1;
25}
26
28 : BmnFieldMap(fieldPar)
29{
30 fType = 1;
31}
32
34
35Double_t BmnNewFieldMap::GetBx(Double_t x, Double_t y, Double_t z)
36{
37 return FieldInterpolate(fBx, x, y, z);
38}
39
40Double_t BmnNewFieldMap::GetBy(Double_t x, Double_t y, Double_t z)
41{
42 return FieldInterpolate(fBy, x, y, z);
43}
44
45Double_t BmnNewFieldMap::GetBz(Double_t x, Double_t y, Double_t z)
46{
47 return FieldInterpolate(fBz, x, y, z);
48}
49
50Bool_t BmnNewFieldMap::IsInside(Double_t x,
51 Double_t y,
52 Double_t z,
53 Int_t& ix,
54 Int_t& iy,
55 Int_t& iz,
56 Double_t& dx,
57 Double_t& dy,
58 Double_t& dz)
59{
60 // --- Check for being outside the map range
61 if (x < fXmin || x >= fXmax || y < fYmin || y >= fYmax || z < fZmin || z >= fZmax) {
62 ix = iy = iz = 0;
63 dx = dy = dz = 0.;
64 return kFALSE;
65 }
66
67 // Relative distance from grid point (in units of cell size) and grid cell numbers
68
69 Double_t xx, yy, zz;
70 xx = (x - fXmin) / fXstep;
71 yy = (y - fYmin) / fYstep;
72 zz = (z - fZmin) / fZstep;
73 ix = Int_t(xx);
74 iy = Int_t(yy);
75 iz = Int_t(zz);
76 dx = xx - Double_t(ix);
77 dy = yy - Double_t(iy);
78 dz = zz - Double_t(iz);
79
80 return kTRUE;
81}
82
83Double_t BmnNewFieldMap::FieldInterpolate(TArrayF* fcomp, Double_t x, Double_t y, Double_t z)
84{
85 Int_t ix = 0;
86 Int_t iy = 0;
87 Int_t iz = 0;
88 Double_t dx = 0.;
89 Double_t dy = 0.;
90 Double_t dz = 0.;
91
92 if (x < fXmin || x >= fXmax || y < fYmin || y >= fYmax || z < fZmin || z >= fZmax) {
93 return 0.;
94 }
95
96 // Relative distance from grid point (in units of cell size) and grid cell numbers
97
98 Double_t xx, yy, zz;
99 xx = (x - fXmin) / fXstep;
100 yy = (y - fYmin) / fYstep;
101 zz = (z - fZmin) / fZstep;
102 ix = Int_t(xx);
103 iy = Int_t(yy);
104 iz = Int_t(zz);
105 dx = xx - Double_t(ix);
106 dy = yy - Double_t(iy);
107 dz = zz - Double_t(iz);
108
109 Int_t ixyz1 = ix * fNy * fNz + iy * fNz + iz;
110 Int_t ixyz2 = ixyz1 + fNy * fNz;
111 Int_t ixyz3 = ixyz1 + fNz;
112 Int_t ixyz4 = ixyz2 + fNz;
113
114 fHa[0][0][0] = fcomp->At(ixyz1);
115 fHa[1][0][0] = fcomp->At(ixyz2);
116 fHa[0][1][0] = fcomp->At(ixyz3);
117 fHa[1][1][0] = fcomp->At(ixyz4);
118 fHa[0][0][1] = fcomp->At(ixyz1 + 1);
119 fHa[1][0][1] = fcomp->At(ixyz2 + 1);
120 fHa[0][1][1] = fcomp->At(ixyz3 + 1);
121 fHa[1][1][1] = fcomp->At(ixyz4 + 1);
122
123 return Interpolate(dx, dy, dz);
124}
125
127{
128 TString MapName = GetName();
129 LOG(debug) << "BmnNewFieldMap::FillParContainer() ";
130 FairRun* fRun = FairRun::Instance();
131 FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
132 // Bool_t kParameterMerged = kTRUE;
133 BmnFieldPar* fieldPar = (BmnFieldPar*)rtdb->getContainer("BmnFieldPar");
134 fieldPar->SetParameters(this);
135 fieldPar->setInputVersion(fRun->GetRunId(), 1);
136 fieldPar->setChanged();
137}
Double_t fHa[2][2][2]
TArrayF * fBy
TArrayF * GetBx() const
Definition BmnFieldMap.h:96
TArrayF * GetBy() const
Definition BmnFieldMap.h:97
TArrayF * fBz
Double_t Interpolate(Double_t dx, Double_t dy, Double_t dz)
Double_t fZmin
TArrayF * GetBz() const
Definition BmnFieldMap.h:98
Double_t fYmax
Double_t fXstep
Double_t fZstep
Double_t fXmin
TArrayF * fBx
Double_t fZmax
Double_t fYmin
Double_t fYstep
Double_t fXmax
void SetParameters(FairField *field)
Double_t FieldInterpolate(TArrayF *fcomp, Double_t x, Double_t y, Double_t z)
Bool_t IsInside(Double_t x, Double_t y, Double_t z, Int_t &ix, Int_t &iy, Int_t &iz, Double_t &dx, Double_t &dy, Double_t &dz)
virtual ~BmnNewFieldMap()