40 const std::string newDataPath = dataPath +
"Vbb-0.0V";
42 }
else if (tableNumber == 1)
44 const std::string newDataPath = dataPath +
"Vbb-3.0V";
49 cout <<
"Object already initialized" << endl;
54 const float kTiny = 1e-6;
57 if (mDataPath.length() && mDataPath.back() !=
'/') {
58 mDataPath.push_back(
'/');
60 mDataPath = gSystem->ExpandPathName(mDataPath.data());
61 string inpfname = mDataPath + mGridColName;
62 std::ifstream inpGrid;
65 inpGrid.open(inpfname, std::ifstream::in);
67 LOG(fatal) <<
"Failed to open file " << inpfname;
70 while (inpGrid >> mStepInvCol && inpGrid.good()) {
74 if (!mNBinCol || mStepInvCol < kTiny) {
75 LOG(fatal) <<
"Failed to read X(col) binning from " << inpfname;
77 mMaxBinCol = mNBinCol - 1;
78 mStepInvCol = mMaxBinCol / mStepInvCol;
82 inpfname = mDataPath + mGridRowName;
83 inpGrid.open(inpfname, std::ifstream::in);
85 LOG(fatal) <<
"Failed to open file " << inpfname;
88 while (inpGrid >> mStepInvRow && inpGrid.good()) {
91 if (!mNBinRow || mStepInvRow < kTiny) {
92 LOG(fatal) <<
"Failed to read Y(row) binning from " << inpfname;
94 mMaxBinRow = mNBinRow - 1;
95 mStepInvRow = mMaxBinRow / mStepInvRow;
101 float val, gx, gy, gz;
102 int lost, untrck, dead, nele;
108 for (
int ix = 0; ix < mNBinCol; ix++) {
109 for (
int iy = 0; iy < mNBinRow; iy++) {
110 inpfname = composeDataName(ix, iy);
111 inpGrid.open(inpfname, std::ifstream::in);
112 if (inpGrid.fail()) {
113 LOG(fatal) <<
"Failed to open file " << inpfname;
118 dataSize = mNBinCol * mNBinRow * mNBinDpt;
120 }
else if (nz != mNBinDpt) {
121 LOG(fatal) <<
"Mismatch in Nz slices of bin X(col): " << ix <<
" Y(row): " << iy
122 <<
" wrt bin 0,0. File " << inpfname;
126 for (
int iz = 0; iz < nz; iz++) {
129 std::array<float, AlpideRespSimMat::MatSize>* arr = mat.
getArray();
130 for (
int ip = 0; ip < npix * npix; ip++) {
135 inpGrid >> lost >> dead >> untrck >> nele >> gx >> gy >> gz;
138 LOG(fatal) <<
"Failed reading data for depth(Z) slice " << iz <<
" from "
142 LOG(fatal) <<
"Wrong normalization Nele=" << nele <<
"for depth(Z) slice "
143 << iz <<
" from " << inpfname;
146 if (mDptMax < -1e9) {
154 float norm = 1.f / nele;
155 for (
int ip = npix * npix; ip--;) {
158 mData.push_back(mat);
168 LOG(fatal) <<
"Mismatch between expected " <<
dataSize <<
" and loaded " << mData.size()
169 <<
" number of bins";
179 mStepInvDpt = (mNBinDpt - 1) / (mDptMax - mDptMin);
180 mDptMin -= 0.5 / mStepInvDpt;
181 mDptMax += 0.5 / mStepInvDpt;
182 mDptShift = 0.5 * (mDptMax + mDptMin);
194 printf(
"Alpide response object of %zu matrices to map chagre in xyz to %dx%d pixels\n",
196 printf(
"X(col) range: %+e : %+e | step: %e | Nbins: %d\n", 0.f, mColMax, 1.f / mStepInvCol, mNBinCol);
197 printf(
"Y(row) range: %+e : %+e | step: %e | Nbins: %d\n", 0.f, mRowMax, 1.f / mStepInvRow, mNBinRow);
198 printf(
"Z(dpt) range: %+e : %+e | step: %e | Nbins: %d\n", mDptMin, mDptMax, 1.f / mStepInvDpt, mNBinDpt);
210 size_t size = snprintf(
nullptr, 0, mColRowDataFmt.data(), vcol, vrow) + 1;
224 LOG(fatal) <<
"response object is not initialized";
226 bool flipCol =
false, flipRow =
true;
227 if (vDepth < mDptMin || vDepth > mDptMax) {
234 if (vCol > mColMax) {
241 if (vRow > mRowMax) {
245 size_t bin = getDepthBin(vDepth) + mNBinDpt * (getRowBin(vRow) + mNBinRow * getColBin(vCol));
246 if (bin >= mData.size()) {
248 LOG(fatal) <<
"requested bin " << bin <<
"row/col/depth: " << getRowBin(vRow) <<
":" << getColBin(vCol)
249 <<
":" << getDepthBin(vDepth) <<
")"
250 <<
">= maxBin " << mData.size()
251 <<
" for X(row)=" << vRow <<
" Z(col)=" << vCol <<
" Y(depth)=" << vDepth;
255 dest.
adopt(mData[bin], flipRow, flipCol);