Project
Loading...
Searching...
No Matches
ChipSimResponse.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13#include <vector>
14#include <algorithm>
15
16using namespace o2::its3;
17
19
20void ChipSimResponse::initData(int tableNumber, std::string dataPath, const bool quiet)
21{
22 AlpideSimResponse::initData(tableNumber, dataPath, quiet);
24}
25
27{
29 std::vector<float> zVec, effVec;
30 zVec.reserve(mNBinDpt);
31 effVec.reserve(mNBinDpt);
32
33 for (int iz = 0; iz < mNBinDpt; ++iz) {
34 int rev = mNBinDpt - 1 - iz;
35 float z = mDptMin + iz / mStepInvDpt;
36 float sum = 0.f;
37 const auto& mat = mData[rev];
38 for (int ix = 0; ix < npix; ++ix) {
39 for (int iy = 0; iy < npix; ++iy) {
40 sum += mat.getValue(ix, iy);
41 }
42 }
43 zVec.push_back(z);
44 effVec.push_back(sum);
45 }
46
47 struct Bin {
48 float z0, z1, q0, q1, dq;
49 };
50 std::vector<Bin> bins;
51 bins.reserve(zVec.size() - 1);
52
53 float totQ = 0.f;
54 for (size_t i = 0; i + 1 < zVec.size(); ++i) {
55 float z0 = zVec[i], z1 = zVec[i + 1];
56 float q0 = effVec[i], q1 = effVec[i + 1];
57 float dq = 0.5f * (q0 + q1) * (z1 - z0);
58 bins.push_back({z0, z1, q0, q1, dq});
59 totQ += dq;
60 }
61
62 if (totQ <= 0.f) {
63 mRespCentreDep = mDptMin;
64 return;
65 }
66
67 float halfQ = 0.5f * totQ;
68 float cumQ = 0.f;
69 for (auto& b : bins) {
70 if (cumQ + b.dq < halfQ) {
71 cumQ += b.dq;
72 continue;
73 }
74 float dz = b.z1 - b.z0;
75 float slope = (b.q1 - b.q0) / dz;
76 float disc = b.q0 * b.q0 - 2.f * slope * (cumQ - halfQ);
77
78 float x;
79 if (disc >= 0.f && std::abs(slope) > 1e-6f) {
80 x = (-b.q0 + std::sqrt(disc)) / slope;
81 } else {
82 x = (halfQ - cumQ) / b.q0;
83 }
84 x = std::clamp(x, 0.f, dz);
85 mRespCentreDep = b.z0 + x;
86 return;
87 }
88
89 mRespCentreDep = mDptMax;
90}
std::vector< double > sum
int32_t i
ClassImp(o2::its3::ChipSimResponse)
bounded_vector< float > bins
uint16_t slope
Definition RawData.h:1
void initData(int tableNumber, std::string dataPath, const bool quiet=true)
static int constexpr getNPix()
number of pixels in the quadrant
int mNBinDpt
number of bins in Y(row direction)
std::vector< AlpideRespSimMat > mData
inverse step of the Dpt grid
float mDptMin
upper boundary of Row
float mStepInvDpt
inverse step of the Row grid
float mDptMax
lower boundary of Dpt
GLint GLenum GLint x
Definition glcorearb.h:403
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843