CbmRoot
LitFieldGrid.h
Go to the documentation of this file.
1 
7 #ifndef LITFIELDGRID_H_
8 #define LITFIELDGRID_H_
9 
10 #include "LitFieldValue.h"
11 #include <iomanip>
12 #include <sstream>
13 #include <string>
14 #include <vector>
15 
16 using std::ostream;
17 using std::right;
18 using std::setfill;
19 using std::setw;
20 using std::string;
21 using std::stringstream;
22 using std::vector;
23 
24 namespace lit {
25  namespace parallel {
26 
44  class LitFieldGrid {
45  public:
50  : fXMin(0.)
51  , fXMax(0.)
52  , fYMin(0.)
53  , fYMax(0.)
54  , fZ(0.)
55  , fNofBinsX(0)
56  , fNofBinsY(0)
57  , fBinSizeX(0.)
58  , fBinSizeY(0.)
59  , fField() {}
60 
65  fscal GetZ() const { return fZ; }
66 
71  void SetZ(fscal Z) { fZ = Z; }
72 
89  void SetField(const vector<vector<LitFieldValue<fscal>>>& field,
90  fscal xmin,
91  fscal xmax,
92  fscal ymin,
93  fscal ymax,
94  int nofBinsX,
95  int nofBinsY) {
96  fField = field;
97  fXMin = xmin;
98  fXMax = xmax;
99  fYMin = ymin;
100  fYMax = ymax;
101  fNofBinsX = nofBinsX;
102  fNofBinsY = nofBinsY;
103  fBinSizeX = ((xmax - xmin) / nofBinsX);
104  fBinSizeY = ((ymax - ymin) / nofBinsY);
105  }
106 
114  // Check bound conditions and if out of bounds return zero field values.
115  // Can be removed considering performance!
116  if (x < fXMin || x > fXMax || y < fYMin || y > fXMax) {
117  B.Bx = 0.;
118  B.By = 0.;
119  B.Bz = 0.;
120  return;
121  }
122  // Calculate bin indices for X and Y
123  unsigned short ix = short((x - fXMin) / fBinSizeX);
124  unsigned short iy = short((y - fYMin) / fBinSizeY);
125 
126  // Check bound conditions and if out of bounds return zero field values.
127  // Can be removed considering performance!
128  if (ix >= fNofBinsX - 1 || iy >= fNofBinsY - 1) {
129  B.Bx = 0.;
130  B.By = 0.;
131  B.Bz = 0.;
132  return;
133  }
134 
135  B = fField[ix][iy];
136 
137  // // Field values on the bin nodes
138  // const LitFieldValue<fscal>& v1 = fField[ix ][iy];
139  // const LitFieldValue<fscal>& v2 = fField[ix+1][iy];
140  // const LitFieldValue<fscal>& v3 = fField[ix ][iy+1];
141  // const LitFieldValue<fscal>& v4 = fField[ix+1][iy+1];
142  // // Calculate weights depending on the distance to the bin nodes
143  // fscal dx1 = (x - ix * fBinSizeX - fXMin);
144  // fscal dx2 = (x - (ix + 1) * fBinSizeX - fXMin);
145  // fscal dy1 = (y - iy * fBinSizeY - fYMin);
146  // fscal dy2 = (y - (iy + 1) * fBinSizeY - fYMin);
147  // fscal w1 = 1./(dx1 * dx1 + dy1 * dy1);
148  // fscal w2 = 1./(dx2 * dx2 + dy1 * dy1);
149  // fscal w3 = 1./(dx1 * dx1 + dy2 * dy2);
150  // fscal w4 = 1./(dx2 * dx2 + dy2 * dy2);
151  // fscal wsum = w1 + w2 + w3 + w4;
158  // if (wsum == 0.) { // Can be removed considering performance!
159  // B.Bx = 0.;
160  // B.By = 0.;
161  // B.Bz = 0.;
162  // cout << "LitFieldGrid::GetFieldValue: zero wsum=" << wsum << endl;
163  // return;
164  // }
165  // // Calculate output weighted mean B value
166  // B.Bx = (w1 * v1.Bx + w2 * v2.Bx + w3 * v3.Bx + w4 * v4.Bx) / wsum;
167  // B.By = (w1 * v1.By + w2 * v2.By + w3 * v3.By + w4 * v4.By) / wsum;
168  // B.Bz = (w1 * v1.Bz + w2 * v2.Bz + w3 * v3.Bz + w4 * v4.Bz) / wsum;
169  }
170 
179  // Get field value for each packed value
180  for (unsigned int i = 0; i < fvecLen; i++) {
181  // Get field value in scalar format
182  GetFieldValue(x[i], y[i], v);
183  // Store field value in vector format
184  B.Bx[i] = v.Bx;
185  B.By[i] = v.By;
186  B.Bz[i] = v.Bz;
187  }
188  }
189 
193  bool IsEmpty() const { return fField.empty(); }
194 
199  string ToString() const {
200  stringstream ss;
201  ss << "LitFieldGrid: Z=" << fZ << " Xmin=" << fXMin << " Xmax=" << fXMax
202  << " Ymin=" << fYMin << " Ymax=" << fYMax
203  << " nofBinsX=" << fNofBinsX << " nofBinsY=" << fNofBinsY
204  << " binSizeX=" << fBinSizeX << " binSizeY=" << fBinSizeY
205  << " field.size=" << fField.size();
206  // if (fNofBinsX > 0 && fNofBinsY > 0) {
207  // ss << "\nGrid:\n";
208  // unsigned int stepX = fNofBinsX / 10;
209  // unsigned int stepY = fNofBinsY / 10;
210  // for (unsigned int i = 0; i < 10; i++) {
211  // for (unsigned int j = 0; j < 10; j++) {
212  // const LitFieldValue<fscal>& v = fField[i * stepX][j * stepY];
213  // ss << right << setfill(' ') << setw(15) << v.Bx;
214  // }
215  // ss << "\n";
216  // }
217  // }
218  return ss.str();
219  }
220 
225  friend ostream& operator<<(ostream& strm, const LitFieldGrid& grid) {
226  strm << grid.ToString();
227  return strm;
228  }
229 
230  private:
231  fscal fXMin, fXMax; // Maximum and minimum grid size in X [cm]
232  fscal fYMin, fYMax; // Maximum and minimum grid size in Y [cm]
233  fscal fZ; // Z position of grid slice
234  unsigned short fNofBinsX; // Number of bins along X
235  unsigned short fNofBinsY; // Number of bins along Y
236  fscal fBinSizeX; // Bin size along X [cm]
237  fscal fBinSizeY; // Bin size along Y [cm]
238  // Field values in bin nodes.
239  // Total number of field values is
240  // (fNofBinsX + 1) * (fNofBinsY + 1)
241  vector<vector<LitFieldValue<fscal>>> fField;
242  } _fvecalignment;
243 
244  } // namespace parallel
245 } // namespace lit
246 #endif /* LITFIELDGRID_H_ */
fscal
float fscal
Definition: L1/vectors/P4_F32vec4.h:250
lit::parallel::LitFieldGrid::GetFieldValue
void GetFieldValue(fscal x, fscal y, LitFieldValue< fscal > &B) const
Return field value for (X, Y) position (scalar version).
Definition: LitFieldGrid.h:113
lit::parallel::LitFieldGrid::GetFieldValue
void GetFieldValue(fvec x, fvec y, LitFieldValue< fvec > &B) const
Returns field value for (X, Y) position (SIMD version).
Definition: LitFieldGrid.h:177
F32vec4
Definition: L1/vectors/P4_F32vec4.h:47
lit::parallel::LitFieldGrid::LitFieldGrid
LitFieldGrid()
Constructor.
Definition: LitFieldGrid.h:49
lit::parallel::LitFieldGrid::operator<<
friend ostream & operator<<(ostream &strm, const LitFieldGrid &grid)
Operator << for convenient output to ostream.
Definition: LitFieldGrid.h:225
lit::parallel::LitFieldGrid::fBinSizeY
fscal fBinSizeY
Definition: LitFieldGrid.h:237
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
lit::parallel::_fvecalignment
class lit::parallel::LitDetectorLayout _fvecalignment
lit::parallel::LitFieldGrid::ToString
string ToString() const
Returns string representation of the class.
Definition: LitFieldGrid.h:199
lit::parallel::LitFieldValue::Bx
T Bx
Definition: LitFieldValue.h:57
lit::parallel::LitFieldGrid::IsEmpty
bool IsEmpty() const
Check if field was set.
Definition: LitFieldGrid.h:193
lit::parallel::LitFieldGrid::fBinSizeX
fscal fBinSizeX
Definition: LitFieldGrid.h:236
lit::parallel::LitFieldGrid::fXMin
fscal fXMin
Definition: LitFieldGrid.h:231
lit::parallel::LitFieldGrid
Class stores a grid of magnetic field values in XY slice at Z position.
Definition: LitFieldGrid.h:44
fvecLen
const int fvecLen
Definition: L1/vectors/P4_F32vec4.h:251
lit::parallel::LitFieldValue
Magnetic field value at a certain point in the space.
Definition: LitFieldValue.h:29
lit::parallel::LitFieldGrid::fZ
fscal fZ
Definition: LitFieldGrid.h:233
lit::parallel::LitFieldGrid::SetZ
void SetZ(fscal Z)
Sets Z position of the grid.
Definition: LitFieldGrid.h:71
lit::parallel::LitFieldGrid::SetField
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.
Definition: LitFieldGrid.h:89
lit::parallel::LitFieldGrid::fYMin
fscal fYMin
Definition: LitFieldGrid.h:232
LitFieldValue.h
Magnetic field value at a certain point in the space.
lit::parallel::LitFieldGrid::fNofBinsX
unsigned short fNofBinsX
Definition: LitFieldGrid.h:234
lit::parallel::LitFieldGrid::fYMax
fscal fYMax
Definition: LitFieldGrid.h:232
lit::parallel::LitFieldValue::By
T By
Definition: LitFieldValue.h:57
lit::parallel::LitFieldGrid::GetZ
fscal GetZ() const
Returns Z position of the grid.
Definition: LitFieldGrid.h:65
v
__m128 v
Definition: L1/vectors/P4_F32vec4.h:1
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
lit::parallel::LitFieldGrid::fXMax
fscal fXMax
Definition: LitFieldGrid.h:231
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
lit::parallel::LitFieldGrid::fField
vector< vector< LitFieldValue< fscal > > > fField
Definition: LitFieldGrid.h:241
lit::parallel::LitFieldGrid::fNofBinsY
unsigned short fNofBinsY
Definition: LitFieldGrid.h:235
lit::parallel::LitFieldValue::Bz
T Bz
Definition: LitFieldValue.h:57
lit
Definition: LitTrackFinderNNVecElectron.h:19