CbmRoot
Loading...
Searching...
No Matches
LitFieldGrid.h
Go to the documentation of this file.
1/* Copyright (C) 2009-2019 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
11#ifndef LITFIELDGRID_H_
12#define LITFIELDGRID_H_
13
14#include "LitFieldValue.h"
15
16#include <iomanip>
17#include <sstream>
18#include <string>
19#include <vector>
20
21using std::ostream;
22using std::right;
23using std::setfill;
24using std::setw;
25using std::string;
26using std::stringstream;
27using std::vector;
28
29namespace lit
30{
31 namespace parallel
32 {
33
52 public:
57 : fXMin(0.)
58 , fXMax(0.)
59 , fYMin(0.)
60 , fYMax(0.)
61 , fZ(0.)
62 , fNofBinsX(0)
63 , fNofBinsY(0)
64 , fBinSizeX(0.)
65 , fBinSizeY(0.)
66 , fField()
67 {
68 }
69
74 fscal GetZ() const { return fZ; }
75
80 void SetZ(fscal Z) { fZ = Z; }
81
98 void SetField(const vector<vector<LitFieldValue<fscal>>>& field, fscal xmin, fscal xmax, fscal ymin, fscal ymax,
99 int nofBinsX, int nofBinsY)
100 {
101 fField = field;
102 fXMin = xmin;
103 fXMax = xmax;
104 fYMin = ymin;
105 fYMax = ymax;
106 fNofBinsX = nofBinsX;
107 fNofBinsY = nofBinsY;
108 fBinSizeX = ((xmax - xmin) / nofBinsX);
109 fBinSizeY = ((ymax - ymin) / nofBinsY);
110 }
111
119 {
120 // Check bound conditions and if out of bounds return zero field values.
121 // Can be removed considering performance!
123 B.Bx = 0.;
124 B.By = 0.;
125 B.Bz = 0.;
126 return;
127 }
128 // Calculate bin indices for X and Y
129 unsigned short ix = short((x - fXMin) / fBinSizeX);
130 unsigned short iy = short((y - fYMin) / fBinSizeY);
131
132 // Check bound conditions and if out of bounds return zero field values.
133 // Can be removed considering performance!
134 if (ix >= fNofBinsX - 1 || iy >= fNofBinsY - 1) {
135 B.Bx = 0.;
136 B.By = 0.;
137 B.Bz = 0.;
138 return;
139 }
140
141 B = fField[ix][iy];
142
143 // // Field values on the bin nodes
144 // const LitFieldValue<fscal>& v1 = fField[ix ][iy];
145 // const LitFieldValue<fscal>& v2 = fField[ix+1][iy];
146 // const LitFieldValue<fscal>& v3 = fField[ix ][iy+1];
147 // const LitFieldValue<fscal>& v4 = fField[ix+1][iy+1];
148 // // Calculate weights depending on the distance to the bin nodes
149 // fscal dx1 = (x - ix * fBinSizeX - fXMin);
150 // fscal dx2 = (x - (ix + 1) * fBinSizeX - fXMin);
151 // fscal dy1 = (y - iy * fBinSizeY - fYMin);
152 // fscal dy2 = (y - (iy + 1) * fBinSizeY - fYMin);
153 // fscal w1 = 1./(dx1 * dx1 + dy1 * dy1);
154 // fscal w2 = 1./(dx2 * dx2 + dy1 * dy1);
155 // fscal w3 = 1./(dx1 * dx1 + dy2 * dy2);
156 // fscal w4 = 1./(dx2 * dx2 + dy2 * dy2);
157 // fscal wsum = w1 + w2 + w3 + w4;
164 // if (wsum == 0.) { // Can be removed considering performance!
165 // B.Bx = 0.;
166 // B.By = 0.;
167 // B.Bz = 0.;
168 // cout << "LitFieldGrid::GetFieldValue: zero wsum=" << wsum << endl;
169 // return;
170 // }
171 // // Calculate output weighted mean B value
172 // B.Bx = (w1 * v1.Bx + w2 * v2.Bx + w3 * v3.Bx + w4 * v4.Bx) / wsum;
173 // B.By = (w1 * v1.By + w2 * v2.By + w3 * v3.By + w4 * v4.By) / wsum;
174 // B.Bz = (w1 * v1.Bz + w2 * v2.Bz + w3 * v3.Bz + w4 * v4.Bz) / wsum;
175 }
176
184 {
186 // Get field value for each packed value
187 for (size_t i = 0; i < fvec::size(); i++) {
188 // Get field value in scalar format
189 GetFieldValue(x[i], y[i], v);
190 // Store field value in vector format
191 B.Bx[i] = v.Bx;
192 B.By[i] = v.By;
193 B.Bz[i] = v.Bz;
194 }
195 }
196
200 bool IsEmpty() const { return fField.empty(); }
201
206 string ToString() const
207 {
208 stringstream ss;
209 ss << "LitFieldGrid: Z=" << fZ << " Xmin=" << fXMin << " Xmax=" << fXMax << " Ymin=" << fYMin
210 << " Ymax=" << fYMax << " nofBinsX=" << fNofBinsX << " nofBinsY=" << fNofBinsY << " binSizeX=" << fBinSizeX
211 << " binSizeY=" << fBinSizeY << " field.size=" << fField.size();
212 // if (fNofBinsX > 0 && fNofBinsY > 0) {
213 // ss << "\nGrid:\n";
214 // unsigned int stepX = fNofBinsX / 10;
215 // unsigned int stepY = fNofBinsY / 10;
216 // for (unsigned int i = 0; i < 10; i++) {
217 // for (unsigned int j = 0; j < 10; j++) {
218 // const LitFieldValue<fscal>& v = fField[i * stepX][j * stepY];
219 // ss << right << setfill(' ') << setw(15) << v.Bx;
220 // }
221 // ss << "\n";
222 // }
223 // }
224 return ss.str();
225 }
226
231 friend ostream& operator<<(ostream& strm, const LitFieldGrid& grid)
232 {
233 strm << grid.ToString();
234 return strm;
235 }
236
237 private:
238 fscal fXMin, fXMax; // Maximum and minimum grid size in X [cm]
239 fscal fYMin, fYMax; // Maximum and minimum grid size in Y [cm]
240 fscal fZ; // Z position of grid slice
241 unsigned short fNofBinsX; // Number of bins along X
242 unsigned short fNofBinsY; // Number of bins along Y
243 fscal fBinSizeX; // Bin size along X [cm]
244 fscal fBinSizeY; // Bin size along Y [cm]
245 // Field values in bin nodes.
246 // Total number of field values is
247 // (fNofBinsX + 1) * (fNofBinsY + 1)
248 vector<vector<LitFieldValue<fscal>>> fField;
250
251 } // namespace parallel
252} // namespace lit
253#endif /* LITFIELDGRID_H_ */
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
Magnetic field value at a certain point in the space.
Class stores a grid of magnetic field values in XY slice at Z position.
string ToString() const
Returns string representation of the class.
bool IsEmpty() const
Check if field was set.
void SetZ(fscal Z)
Sets Z position of the grid.
friend ostream & operator<<(ostream &strm, const LitFieldGrid &grid)
Operator << for convenient output to ostream.
fscal GetZ() const
Returns Z position of the grid.
void SetField(const vector< vector< LitFieldValue< fscal > > > &field, fscal xmin, fscal xmax, fscal ymin, fscal ymax, int nofBinsX, int nofBinsY)
Set field values for the grid.
void GetFieldValue(fvec x, fvec y, LitFieldValue< fvec > &B) const
Returns field value for (X, Y) position (SIMD version).
vector< vector< LitFieldValue< fscal > > > fField
void GetFieldValue(fscal x, fscal y, LitFieldValue< fscal > &B) const
Return field value for (X, Y) position (scalar version).
Magnetic field value at a certain point in the space.
class lit::parallel::LitDetectorLayout _fvecalignment