CbmRoot
LitMaterialGrid.h
Go to the documentation of this file.
1 
8 #ifndef LITMATERIALGRID_H_
9 #define LITMATERIALGRID_H_
10 
11 #include "LitTypes.h"
12 #include <iomanip>
13 #include <sstream>
14 #include <string>
15 #include <vector>
16 
17 using std::ostream;
18 using std::right;
19 using std::setfill;
20 using std::setw;
21 using std::string;
22 using std::stringstream;
23 using std::vector;
24 
25 namespace lit {
26  namespace parallel {
27 
38  public:
43  // fscal GetZ() const { return fZ; }
44 
49  // void SetZ(fscal Z) { fZ = Z; }
50 
67  void SetMaterial(const vector<vector<fscal>>& material,
68  fscal xmin,
69  fscal xmax,
70  fscal ymin,
71  fscal ymax,
72  int nofBinsX,
73  int nofBinsY) {
74  fMaterial = material;
75  fXMin = xmin;
76  fXMax = xmax;
77  fYMin = ymin;
78  fYMax = ymax;
79  fNofBinsX = nofBinsX;
80  fNofBinsY = nofBinsY;
81  fBinSizeX = ((xmax - xmin) / nofBinsX);
82  fBinSizeY = ((ymax - ymin) / nofBinsY);
83  }
84 
92  // Check bound conditions and if out of bounds return zero.
93  // Can be removed considering performance!
94  if (x < fXMin || x > fXMax || y < fYMin || y > fXMax) {
95  // std::cout << "LitMaterialGrid::GetMaterial: out of bounds x=" << x << " y=" << y << std::endl;
96  return 0.;
97  }
98  // Calculate bin indices for X and Y
99  short ix = short((x - fXMin) / fBinSizeX);
100  short iy = short((y - fYMin) / fBinSizeY);
101 
102  // Check bound conditions and if out of bounds return zero.
103  // Can be removed considering performance!
104  if (ix < 0 || iy < 0 || ix >= fNofBinsX - 1 || iy >= fNofBinsY - 1) {
105  // std::cout << "LitMaterialGrid::GetMaterial: out of bounds ix=" << ix << " iy=" << iy << std::endl;
106  return 0.;
107  }
108 
109  return fMaterial[ix][iy];
110 
111 
112  // Implementation based on the weighted mean of material thicknesses.
113 
114 
115  // // Material thickness on the bin nodes
116  // const fscal v1 = fMaterial[ix ][iy];
117  // const fscal v2 = fMaterial[ix+1][iy];
118  // const fscal v3 = fMaterial[ix ][iy+1];
119  // const fscal v4 = fMaterial[ix+1][iy+1];
120  // // Calculate weights depending on the distance to the bin nodes
121  // fscal dx1 = (x - ix * fBinSizeX - fXMin);
122  // fscal dx2 = (x - (ix + 1) * fBinSizeX - fXMin);
123  // fscal dy1 = (y - iy * fBinSizeY - fYMin);
124  // fscal dy2 = (y - (iy + 1) * fBinSizeY - fYMin);
125  // fscal w1 = 1./(dx1 * dx1 + dy1 * dy1);
126  // fscal w2 = 1./(dx2 * dx2 + dy1 * dy1);
127  // fscal w3 = 1./(dx1 * dx1 + dy2 * dy2);
128  // fscal w4 = 1./(dx2 * dx2 + dy2 * dy2);
129  // fscal wsum = w1 + w2 + w3 + w4;
136  // if (wsum == 0.) { // Can be removed considering performance!
137  // return 0.;
138  // }
139  // // Calculate output weighted mean material thickness
140  // return (w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4) / wsum;
141  }
142 
150  fvec v;
151  // Get material thickness for each packed value
152  for (unsigned int i = 0; i < fvecLen; i++) {
153  v[i] = GetMaterial(x[i], y[i]);
154  }
155  return v;
156  }
157 
161  bool IsEmpty() const { return fMaterial.empty(); }
162 
167  string ToString() const {
168  stringstream ss;
169  ss << "LitMaterialGrid:" /*Z=" << fZ*/ << " Xmin=" << fXMin
170  << " Xmax=" << fXMax << " Ymin=" << fYMin << " Ymax=" << fYMax
171  << " nofBinsX=" << fNofBinsX << " nofBinsY=" << fNofBinsY
172  << " binSizeX=" << fBinSizeX << " binSizeY=" << fBinSizeY
173  << " material.size=" << fMaterial.size();
174  if (fNofBinsX > 0 && fNofBinsY > 0) {
175  unsigned int stepX = fNofBinsX / 10;
176  unsigned int stepY = fNofBinsY / 10;
177  ss << "\nGrid: stepX=" << stepX << " stepY=" << stepY << "\n";
178  for (unsigned int i = 0; i < 11; i++) {
179  for (unsigned int j = 0; j < 11; j++) {
180  if (i < 10 && j < 10)
181  ss << right << setfill(' ') << setw(10)
182  << fMaterial[i * stepX][j * stepY] << " ";
183  if (j == 10 && i != 10)
184  ss << right << setfill(' ') << setw(10)
185  << fMaterial[i * stepX][fNofBinsY - 1] << " ";
186  if (i == 10 && j != 10)
187  ss << right << setfill(' ') << setw(10)
188  << fMaterial[fNofBinsX - 1][j * stepY] << " ";
189  if (i == 10 && j == 10)
190  ss << right << setfill(' ') << setw(10)
191  << fMaterial[fNofBinsX - 1][fNofBinsY - 1] << " ";
192  }
193  ss << "\n";
194  }
195  }
196  return ss.str();
197  }
198 
203  friend ostream& operator<<(ostream& strm, const LitMaterialGrid& grid) {
204  strm << grid.ToString();
205  return strm;
206  }
207 
208  private:
209  fscal fXMin, fXMax; // Maximum and minimum grid size in X [cm]
210  fscal fYMin, fYMax; // Maximum and minimum grid size in Y [cm]
211  // fscal fZ; // Z position of grid slice
212  unsigned short fNofBinsX; // Number of bins along X
213  unsigned short fNofBinsY; // Number of bins along Y
214  fscal fBinSizeX; // Bin size along X [cm]
215  fscal fBinSizeY; // Bin size along Y [cm]
216  // Material thickness in bin nodes.
217  // Total number of values is
218  // (fNofBinsX + 1) * (fNofBinsY + 1)
219  vector<vector<fscal>> fMaterial;
220  } _fvecalignment;
221 
222  } // namespace parallel
223 } // namespace lit
224 
225 
226 #endif /* LITMATERIALGRID_H_ */
lit::parallel::LitMaterialGrid::fMaterial
vector< vector< fscal > > fMaterial
Definition: LitMaterialGrid.h:219
fscal
float fscal
Definition: L1/vectors/P4_F32vec4.h:250
F32vec4
Definition: L1/vectors/P4_F32vec4.h:47
lit::parallel::LitMaterialGrid
Class stores a grid of material thickness in silicon equivalent.
Definition: LitMaterialGrid.h:37
lit::parallel::LitMaterialGrid::fXMax
fscal fXMax
Definition: LitMaterialGrid.h:209
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
lit::parallel::LitMaterialGrid::GetMaterial
fscal GetMaterial(fscal x, fscal y) const
Return material thickness in silicon equivalent for (X, Y) position (scalar version).
Definition: LitMaterialGrid.h:91
lit::parallel::_fvecalignment
class lit::parallel::LitDetectorLayout _fvecalignment
lit::parallel::LitMaterialGrid::fNofBinsY
unsigned short fNofBinsY
Definition: LitMaterialGrid.h:213
lit::parallel::LitMaterialGrid::fNofBinsX
unsigned short fNofBinsX
Definition: LitMaterialGrid.h:212
lit::parallel::LitMaterialGrid::SetMaterial
void SetMaterial(const vector< vector< fscal >> &material, fscal xmin, fscal xmax, fscal ymin, fscal ymax, int nofBinsX, int nofBinsY)
Returns Z position of the grid.
Definition: LitMaterialGrid.h:67
lit::parallel::LitMaterialGrid::fBinSizeY
fscal fBinSizeY
Definition: LitMaterialGrid.h:215
lit::parallel::LitMaterialGrid::ToString
string ToString() const
Return string representation of the class.
Definition: LitMaterialGrid.h:167
LitTypes.h
Header files for SSE operations.
lit::parallel::LitMaterialGrid::operator<<
friend ostream & operator<<(ostream &strm, const LitMaterialGrid &grid)
Operator << for convenient output to ostream.
Definition: LitMaterialGrid.h:203
fvecLen
const int fvecLen
Definition: L1/vectors/P4_F32vec4.h:251
lit::parallel::LitMaterialGrid::IsEmpty
bool IsEmpty() const
Check if material was set.
Definition: LitMaterialGrid.h:161
lit::parallel::LitMaterialGrid::fBinSizeX
fscal fBinSizeX
Definition: LitMaterialGrid.h:214
lit::parallel::LitMaterialGrid::GetMaterialValue
fvec GetMaterialValue(fvec x, fvec y) const
Return material thickness in silicon equivalent for (X, Y) position (SIMD version).
Definition: LitMaterialGrid.h:149
v
__m128 v
Definition: L1/vectors/P4_F32vec4.h:1
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
lit::parallel::LitMaterialGrid::fYMin
fscal fYMin
Definition: LitMaterialGrid.h:210
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
lit::parallel::LitMaterialGrid::fXMin
fscal fXMin
Definition: LitMaterialGrid.h:209
lit
Definition: LitTrackFinderNNVecElectron.h:19
lit::parallel::LitMaterialGrid::fYMax
fscal fYMax
Definition: LitMaterialGrid.h:210