15#include <fmt/format.h>
25 , fFactor(0.5 * fNbins / fXYmax)
55 constexpr int nRays{3};
56 const bool bRadialRays{!std::isnan(zTarg)};
57 const auto scaleFactor{bRadialRays ? ((other.
fZref - zTarg) / (this->
fZref - zTarg)) : 1.F};
58 const auto binSize{2.F * scaleFactor * this->
fXYmax / this->
fNbins};
59 const auto stepSize{binSize /
static_cast<float>(nRays)};
62 float yBinOther{-this->
fXYmax * scaleFactor + stepSize * 0.5F};
65 for (
int iBinY{0}; iBinY < this->
fNbins; ++iBinY) {
66 float xBinOther{-this->
fXYmax * scaleFactor + stepSize * 0.5F};
67 for (
int iBinX{0}; iBinX < this->
fNbins; ++iBinX) {
69 float avgThickness{0};
70 for (
int iRayY{0}; iRayY < nRays; ++iRayY) {
71 for (
int iRayX{0}; iRayX < nRays; ++iRayX) {
72 avgThickness += other.
GetThicknessX0(xBinOther + iRayX * stepSize, yBinOther + iRayY * stepSize);
75 this->
fTable[iBinX + this->fNbins * iBinY] += (avgThickness / (nRays * nRays));
100 if (nGroups < 1 && nGroups >
fNbins) {
101 int nGroupsSet{nGroups};
102 nGroups = std::clamp(nGroups, 1,
fNbins);
103 LOG(warn) <<
"kf::MaterialMap::Rebin(): incorrect input parameter nGroups = " << nGroupsSet <<
" is set to "
107 int nBinsNew =
static_cast<int>(
static_cast<bool>(
fNbins % nGroups)) +
fNbins / nGroups;
108 std::vector<float> table(nBinsNew * nBinsNew);
109 for (
int iX{0}; iX < nBinsNew; ++iX) {
110 for (
int iY{0}; iY < nBinsNew; ++iY) {
113 int iOldXmin{iX * nGroups};
114 int iOldXmax{std::max((iX + 1) * nGroups,
fNbins)};
115 int iOldYmin{iY * nGroups};
116 int iOldYmax{std::max((iY + 1) * nGroups,
fNbins)};
117 for (
int iOldX{iOldXmin}; iOldX < iOldXmax; ++iOldX) {
118 for (
int iOldY{iOldYmin}; iOldY < iOldYmax; ++iOldY) {
123 table[iX + nBinsNew * iY] = value / nEntries;
126 fTable = std::move(table);
135 std::swap(fNbins, other.fNbins);
136 std::swap(fXYmax, other.fXYmax);
137 std::swap(fFactor, other.fFactor);
138 std::swap(fZref, other.fZref);
139 std::swap(fZmin, other.fZmin);
140 std::swap(fZmax, other.fZmax);
141 std::swap(fTable, other.fTable);
150 std::stringstream msg;
152 constexpr char indentCh =
'\t';
153 std::string indent(indentLevel, indentCh);
154 msg << format(
"zRef = {:<12} cm, range [{:<12}, {:<12}] cm, nBins = {:<8}, XYmax = {:<12} cm",
fZref,
fZmin,
fZmax,
157 msg << indent << indentCh <<
"\nContent(rebinned to 10 bins):\n";
160 mapTmp.Rebin(
fNbins / 10);
161 msg << indent << indentCh << setw(15) <<
"y [cm] \\ x [cm]" <<
' ';
162 for (
int iX{0}; iX < mapTmp.fNbins; ++iX) {
163 float xRef{-mapTmp.fXYmax + (mapTmp.fXYmax * (2 * iX + 1)) / mapTmp.fNbins};
164 msg << setw(10) << xRef <<
' ';
167 for (
int iY{0}; iY < mapTmp.fNbins; ++iY) {
168 float yRef{-mapTmp.fXYmax + (mapTmp.fXYmax * (2 * iY + 1)) / mapTmp.fNbins};
169 msg << indent << indentCh << setw(15) << yRef <<
' ';
170 for (
int iX{0}; iX < mapTmp.fNbins; ++iX) {
171 msg << setw(10) << mapTmp.fTable[iX + mapTmp.fNbins * iY] <<
' ';
185 std::stringstream aStream;
186 aStream <<
"MaterialMap: object cannot be initialized with non-positive nBins = " <<
fNbins;
187 throw std::logic_error(aStream.str());
191 std::stringstream aStream;
192 aStream <<
"MaterialMap: object cannot be initialized with non-positive XYmax = " <<
fXYmax <<
" [cm]";
193 throw std::logic_error(aStream.str());
197 std::stringstream aStream;
198 aStream <<
"MaterialMap: object cannot be initialized with inconsistent Z: min " <<
fZmin <<
" ref " <<
fZref
199 <<
" max " <<
fZmax <<
" [cm]";
200 throw std::logic_error(aStream.str());
Implementation selection for the SIMD utilities (VS or pseudo)
A map of station thickness in units of radiation length (X0) to the specific point in XY plane.
std::vector< float > fTable
Material budget table.
void Rebin(int factor)
Reduces number of bins by a given factor.
MaterialMap & operator=(const MaterialMap &other)=default
Copy assignment operator.
float fFactor
Util. var. for the conversion of point coordinates to row/column id.
int fNbins
Number of rows (== N columns) in the material budget table.
float fXYmax
Size of the station in x and y dimensions [cm].
float fZmax
Minimal Z of the collected material [cm].
float fZref
Reference Z of the collected material [cm].
MaterialMap()=default
Default constructor.
int GetBin(float x, float y) const
Gets bin index for (x,y). Returns -1 when outside of the map.
I GetThicknessX0(const I &x, const I &y) const
Gets material thickness in units of radiational length X0.
float fZmin
Minimal Z of the collected material [cm].
void Swap(MaterialMap &other) noexcept
Swap method.
void Add(const MaterialMap &other, float zTarg=defs::Undef< float >)
Adds material layer.
std::string ToString(int indentLevel=0, int verbose=1) const
String representation of the object.
void CheckConsistency() const
Checks the object consistency.