15#include <fmt/format.h>
40 constexpr int nRays{3};
41 const bool bRadialRays{!std::isnan(zTarg)};
42 const auto scaleFactor{bRadialRays ? ((other.
fZref - zTarg) / (this->
fZref - zTarg)) : 1.F};
43 const auto binSize{2.F * scaleFactor * this->
fXYmax / this->
fNbins};
44 const auto stepSize{binSize /
static_cast<float>(nRays)};
47 float yBinOther{-this->
fXYmax * scaleFactor + stepSize * 0.5F};
50 for (
int iBinY{0}; iBinY < this->
fNbins; ++iBinY) {
51 float xBinOther{-this->
fXYmax * scaleFactor + stepSize * 0.5F};
52 for (
int iBinX{0}; iBinX < this->fNbins; ++iBinX) {
54 float avgThickness{0};
55 for (
int iRayY{0}; iRayY < nRays; ++iRayY) {
56 for (
int iRayX{0}; iRayX < nRays; ++iRayX) {
57 avgThickness += other.
GetThicknessX0(xBinOther + iRayX * stepSize, yBinOther + iRayY * stepSize);
60 this->
fTable[iBinX + this->fNbins * iBinY] += (avgThickness / (nRays * nRays));
85 if (nGroups < 1 && nGroups >
fNbins) {
86 int nGroupsSet{nGroups};
87 nGroups = std::clamp(nGroups, 1,
fNbins);
88 LOG(warn) <<
"kf::MaterialMap::Rebin(): incorrect input parameter nGroups = " << nGroupsSet <<
" is set to "
92 int nBinsNew =
static_cast<int>(
static_cast<bool>(
fNbins % nGroups)) +
fNbins / nGroups;
93 std::vector<float> table(nBinsNew * nBinsNew);
94 for (
int iX{0}; iX < nBinsNew; ++iX) {
95 for (
int iY{0}; iY < nBinsNew; ++iY) {
98 int iOldXmin{iX * nGroups};
99 int iOldXmax{std::max((iX + 1) * nGroups,
fNbins)};
100 int iOldYmin{iY * nGroups};
101 int iOldYmax{std::max((iY + 1) * nGroups,
fNbins)};
102 for (
int iOldX{iOldXmin}; iOldX < iOldXmax; ++iOldX) {
103 for (
int iOldY{iOldYmin}; iOldY < iOldYmax; ++iOldY) {
108 table[iX + nBinsNew * iY] = value / nEntries;
111 fTable = std::move(table);
122 std::stringstream msg;
124 constexpr char indentCh =
'\t';
125 std::string indent(indentLevel, indentCh);
126 msg << format(
"zRef = {:<12} cm, range [{:<12}, {:<12}] cm, nBins = {:<8}, XYmax = {:<12} cm",
fZref,
fZmin,
fZmax,
129 msg << indent << indentCh <<
"\nContent(rebinned to 10 bins):\n";
132 mapTmp.Rebin(
fNbins / 10);
133 msg << indent << indentCh << setw(15) <<
"y [cm] \\ x [cm]" <<
' ';
134 for (
int iX{0}; iX < mapTmp.fNbins; ++iX) {
135 float xRef{-mapTmp.fXYmax + (mapTmp.fXYmax * (2 * iX + 1)) / mapTmp.fNbins};
136 msg << setw(10) << xRef <<
' ';
139 for (
int iY{0}; iY < mapTmp.fNbins; ++iY) {
140 float yRef{-mapTmp.fXYmax + (mapTmp.fXYmax * (2 * iY + 1)) / mapTmp.fNbins};
141 msg << indent << indentCh << setw(15) << yRef <<
' ';
142 for (
int iX{0}; iX < mapTmp.fNbins; ++iX) {
143 msg << setw(10) << mapTmp.fTable[iX + mapTmp.fNbins * iY] <<
' ';
157 std::stringstream aStream;
158 aStream <<
"MaterialMap: object cannot be initialized with non-positive nBins = " <<
fNbins;
159 throw std::logic_error(aStream.str());
163 std::stringstream aStream;
164 aStream <<
"MaterialMap: object cannot be initialized with non-positive XYmax = " <<
fXYmax <<
" [cm]";
165 throw std::logic_error(aStream.str());
169 std::stringstream aStream;
170 aStream <<
"MaterialMap: object cannot be initialized with inconsistent Z: min " <<
fZmin <<
" ref " <<
fZref
171 <<
" max " <<
fZmax <<
" [cm]";
172 throw std::logic_error(aStream.str());
Implementation selection for the SIMD utilities (VS or pseudo)
MaterialMap()=default
Default constructor.
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.
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 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.