CbmRoot
Loading...
Searching...
No Matches
LitMaterialGrid.h
Go to the documentation of this file.
1/* Copyright (C) 2013 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
12#ifndef LITMATERIALGRID_H_
13#define LITMATERIALGRID_H_
14
15#include "LitTypes.h"
16
17#include <iomanip>
18#include <sstream>
19#include <string>
20#include <vector>
21
22using std::ostream;
23using std::right;
24using std::setfill;
25using std::setw;
26using std::string;
27using std::stringstream;
28using std::vector;
29
30namespace lit
31{
32 namespace parallel
33 {
34
45 public:
50 // fscal GetZ() const { return fZ; }
51
56 // void SetZ(fscal Z) { fZ = Z; }
57
74 void SetMaterial(const vector<vector<fscal>>& material, fscal xmin, fscal xmax, fscal ymin, fscal ymax,
75 int nofBinsX, int nofBinsY)
76 {
77 fMaterial = material;
78 fXMin = xmin;
79 fXMax = xmax;
80 fYMin = ymin;
81 fYMax = ymax;
82 fNofBinsX = nofBinsX;
83 fNofBinsY = nofBinsY;
84 fBinSizeX = ((xmax - xmin) / nofBinsX);
85 fBinSizeY = ((ymax - ymin) / nofBinsY);
86 }
87
95 {
96 // Check bound conditions and if out of bounds return zero.
97 // Can be removed considering performance!
99 // std::cout << "LitMaterialGrid::GetMaterial: out of bounds x=" << x << " y=" << y << std::endl;
100 return 0.;
101 }
102 // Calculate bin indices for X and Y
103 short ix = short((x - fXMin) / fBinSizeX);
104 short iy = short((y - fYMin) / fBinSizeY);
105
106 // Check bound conditions and if out of bounds return zero.
107 // Can be removed considering performance!
108 if (ix < 0 || iy < 0 || ix >= fNofBinsX - 1 || iy >= fNofBinsY - 1) {
109 // std::cout << "LitMaterialGrid::GetMaterial: out of bounds ix=" << ix << " iy=" << iy << std::endl;
110 return 0.;
111 }
112
113 return fMaterial[ix][iy];
114
115
116 // Implementation based on the weighted mean of material thicknesses.
117
118
119 // // Material thickness on the bin nodes
120 // const fscal v1 = fMaterial[ix ][iy];
121 // const fscal v2 = fMaterial[ix+1][iy];
122 // const fscal v3 = fMaterial[ix ][iy+1];
123 // const fscal v4 = fMaterial[ix+1][iy+1];
124 // // Calculate weights depending on the distance to the bin nodes
125 // fscal dx1 = (x - ix * fBinSizeX - fXMin);
126 // fscal dx2 = (x - (ix + 1) * fBinSizeX - fXMin);
127 // fscal dy1 = (y - iy * fBinSizeY - fYMin);
128 // fscal dy2 = (y - (iy + 1) * fBinSizeY - fYMin);
129 // fscal w1 = 1./(dx1 * dx1 + dy1 * dy1);
130 // fscal w2 = 1./(dx2 * dx2 + dy1 * dy1);
131 // fscal w3 = 1./(dx1 * dx1 + dy2 * dy2);
132 // fscal w4 = 1./(dx2 * dx2 + dy2 * dy2);
133 // fscal wsum = w1 + w2 + w3 + w4;
140 // if (wsum == 0.) { // Can be removed considering performance!
141 // return 0.;
142 // }
143 // // Calculate output weighted mean material thickness
144 // return (w1 * v1 + w2 * v2 + w3 * v3 + w4 * v4) / wsum;
145 }
146
154 {
155 fvec v;
156 // Get material thickness for each packed value
157 for (size_t i = 0; i < fvec::size(); i++) {
158 v[i] = GetMaterial(x[i], y[i]);
159 }
160 return v;
161 }
162
166 bool IsEmpty() const { return fMaterial.empty(); }
167
172 string ToString() const
173 {
174 stringstream ss;
175 ss << "LitMaterialGrid:" /*Z=" << fZ*/ << " Xmin=" << fXMin << " Xmax=" << fXMax << " Ymin=" << fYMin
176 << " Ymax=" << fYMax << " nofBinsX=" << fNofBinsX << " nofBinsY=" << fNofBinsY << " binSizeX=" << fBinSizeX
177 << " binSizeY=" << fBinSizeY << " material.size=" << fMaterial.size();
178 if (fNofBinsX > 0 && fNofBinsY > 0) {
179 unsigned int stepX = fNofBinsX / 10;
180 unsigned int stepY = fNofBinsY / 10;
181 ss << "\nGrid: stepX=" << stepX << " stepY=" << stepY << "\n";
182 for (unsigned int i = 0; i < 11; i++) {
183 for (unsigned int j = 0; j < 11; j++) {
184 if (i < 10 && j < 10) ss << right << setfill(' ') << setw(10) << fMaterial[i * stepX][j * stepY] << " ";
185 if (j == 10 && i != 10)
186 ss << right << setfill(' ') << setw(10) << fMaterial[i * stepX][fNofBinsY - 1] << " ";
187 if (i == 10 && j != 10)
188 ss << right << setfill(' ') << setw(10) << fMaterial[fNofBinsX - 1][j * stepY] << " ";
189 if (i == 10 && j == 10)
190 ss << right << setfill(' ') << setw(10) << fMaterial[fNofBinsX - 1][fNofBinsY - 1] << " ";
191 }
192 ss << "\n";
193 }
194 }
195 return ss.str();
196 }
197
202 friend ostream& operator<<(ostream& strm, const LitMaterialGrid& grid)
203 {
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;
221
222 } // namespace parallel
223} // namespace lit
224
225
226#endif /* LITMATERIALGRID_H_ */
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
Header files for SSE operations.
Class stores a grid of material thickness in silicon equivalent.
bool IsEmpty() const
Check if material was set.
vector< vector< fscal > > fMaterial
fscal GetMaterial(fscal x, fscal y) const
Return material thickness in silicon equivalent for (X, Y) position (scalar version).
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.
string ToString() const
Return string representation of the class.
friend ostream & operator<<(ostream &strm, const LitMaterialGrid &grid)
Operator << for convenient output to ostream.
fvec GetMaterialValue(fvec x, fvec y) const
Return material thickness in silicon equivalent for (X, Y) position (SIMD version).
class lit::parallel::LitDetectorLayout _fvecalignment