Skip to content

Commit e988e69

Browse files
committed
should use the total eff but not only seed
1 parent fb4c608 commit e988e69

File tree

2 files changed

+64
-60
lines changed

2 files changed

+64
-60
lines changed

Detectors/Upgrades/ITS3/macros/test/CheckChipResponseFile.C

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ std::vector<float> getCollectionSeediciencies(o2::its3::ChipSimResponse* resp,
8585
bool flipRow = false, flipCol = false;
8686
for (auto depth : depths) {
8787
auto rspmat = resp->getResponse(0.0, 0.0,
88-
um2cm(depth) + resp->getDepthMin() + 1.e-9,
88+
um2cm(depth) + 1.e-9,
8989
flipRow, flipCol);
9090
seed.push_back(rspmat ? rspmat->getValue(2, 2) : 0.f);
9191
}
@@ -99,7 +99,7 @@ std::vector<float> getShareValues(o2::its3::ChipSimResponse* resp,
9999
bool flipRow = false, flipCol = false;
100100
for (auto depth : depths) {
101101
auto rspmat = resp->getResponse(0.0, 0.0,
102-
um2cm(depth) + resp->getDepthMin() + 1.e-9,
102+
um2cm(depth) + 1.e-9,
103103
flipRow, flipCol);
104104
float s = 0;
105105
int npix = resp->getNPix();
@@ -121,7 +121,7 @@ std::vector<float> getEffValues(o2::its3::ChipSimResponse* resp,
121121
bool flipRow = false, flipCol = false;
122122
for (auto depth : depths) {
123123
auto rspmat = resp->getResponse(0.0, 0.0,
124-
um2cm(depth) + resp->getDepthMin() + 1.e-9,
124+
um2cm(depth) + 1.e-9,
125125
flipRow, flipCol);
126126
float s = 0;
127127
int npix = resp->getNPix();
@@ -140,9 +140,12 @@ void CheckChipResponseFile()
140140
LoadRespFunc();
141141
LOG(info) << "Response function loaded" << std::endl;
142142

143-
std::vector<float> vecDepth(50);
144-
for (int i = 0; i < 50; ++i)
145-
vecDepth[i] = i;
143+
std::vector<float> vecDepth;
144+
int numPoints = 100;
145+
for (int i = 0; i < numPoints; ++i) {
146+
float value = -50 + i * (100.0f / (numPoints - 1));
147+
vecDepth.push_back(value);
148+
}
146149

147150
int colors[] = {kOrange + 7, kRed + 1, kAzure + 4};
148151
struct RespInfo {
@@ -156,7 +159,7 @@ void CheckChipResponseFile()
156159
{mAlpSimResp1, "ALPIDE Vbb=-3V", colors[2]}};
157160

158161
TCanvas* c1 = new TCanvas("c1", "c1", 800, 600);
159-
TH1* frame = c1->DrawFrame(-1, -0.049, 50, 1.049);
162+
TH1* frame = c1->DrawFrame(-50, -0.049, 50, 1.049);
160163
frame->SetTitle(";Depth(um);Charge Collection Seed / Share / Eff");
161164
TLegend* leg = new TLegend(0.15, 0.5, 0.4, 0.85);
162165
leg->SetFillStyle(0);

Detectors/Upgrades/ITS3/simulation/src/ChipSimResponse.cxx

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,61 +25,62 @@ void ChipSimResponse::initData(int tableNumber, std::string dataPath, const bool
2525

2626
void ChipSimResponse::computeCentreFromData()
2727
{
28-
std::vector<float> zVec, qVec;
29-
const int npix = o2::itsmft::AlpideRespSimMat::getNPix();
28+
const int npix = o2::itsmft::AlpideRespSimMat::getNPix();
29+
std::vector<float> zVec, effVec;
30+
zVec.reserve(mNBinDpt);
31+
effVec.reserve(mNBinDpt);
3032

31-
for (int iz = 0; iz < mNBinDpt; ++iz) {
32-
size_t bin = iz + mNBinDpt * (0 + mNBinRow * 0);
33-
const auto& mat = mData[bin];
34-
float val = mat.getValue(npix / 2, npix / 2);
35-
float gz = mDptMin + iz / mStepInvDpt;
36-
zVec.push_back(gz);
37-
qVec.push_back(val);
38-
}
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+
zVec.push_back(z);
42+
effVec.push_back(sum);
43+
}
3944

40-
std::vector<std::pair<float, float>> zqPairs;
41-
for (size_t i = 0; i < zVec.size(); ++i) {
42-
zqPairs.emplace_back(zVec[i], qVec[i]);
43-
}
44-
std::sort(zqPairs.begin(), zqPairs.end());
45-
zVec.clear();
46-
qVec.clear();
47-
for (auto& p : zqPairs) {
48-
zVec.push_back(p.first);
49-
qVec.push_back(p.second);
50-
}
45+
struct Bin { float z0, z1, q0, q1, dq; };
46+
std::vector<Bin> bins;
47+
bins.reserve(zVec.size() - 1);
5148

52-
struct BinInfo { float z0, z1, q0, q1, dq; };
53-
std::vector<BinInfo> bins;
54-
float totQ = 0.f;
55-
for (size_t i = 0; i + 1 < zVec.size(); ++i) {
56-
float z0 = zVec[i], z1 = zVec[i + 1];
57-
float q0 = qVec[i], q1 = qVec[i + 1];
58-
float dz = z1 - z0;
59-
float dq = 0.5f * (q0 + q1) * dz;
60-
bins.push_back({z0, z1, q0, q1, dq});
61-
totQ += dq;
62-
}
63-
if (totQ <= 0.f) { mRespCentreDep = 0.f; return; }
49+
float totQ = 0.f;
50+
for (size_t i = 0; i + 1 < zVec.size(); ++i) {
51+
float z0 = zVec[i], z1 = zVec[i + 1];
52+
float q0 = effVec[i], q1 = effVec[i + 1];
53+
float dq = 0.5f * (q0 + q1) * (z1 - z0);
54+
bins.push_back({z0, z1, q0, q1, dq});
55+
totQ += dq;
56+
}
6457

65-
float halfQ = 0.5f * totQ;
66-
float cumQ = 0.f;
67-
for (const auto& b : bins) {
68-
if (cumQ + b.dq < halfQ) { cumQ += b.dq; continue; }
69-
float qSlope = (b.q1 - b.q0) / (b.z1 - b.z0);
70-
float dz = b.z1 - b.z0;
71-
float A = qSlope * 0.5f;
72-
float B = b.q0;
73-
float C = cumQ - halfQ;
74-
float disc = B * B - 4.f * A * C;
75-
float x;
76-
if (disc >= 0.f && std::abs(A) > 1.e-12f)
77-
x = (-B + std::sqrt(disc)) / (2.f * A);
78-
else
79-
x = (halfQ - cumQ) / b.q0;
80-
x = std::clamp(x, 0.f, dz);
81-
mRespCentreDep = b.z0 + x;
82-
return;
83-
}
84-
mRespCentreDep = mDptMax;
58+
if (totQ <= 0.f) {
59+
mRespCentreDep = mDptMin;
60+
return;
61+
}
62+
63+
float halfQ = 0.5f * totQ;
64+
float cumQ = 0.f;
65+
for (auto& b : bins) {
66+
if (cumQ + b.dq < halfQ) {
67+
cumQ += b.dq;
68+
continue;
69+
}
70+
float dz = b.z1 - b.z0;
71+
float slope = (b.q1 - b.q0) / dz;
72+
float disc = b.q0 * b.q0 - 2.f * slope * (cumQ - halfQ);
73+
74+
float x;
75+
if (disc >= 0.f && std::abs(slope) > 1e-12f) {
76+
x = (-b.q0 + std::sqrt(disc)) / slope;
77+
} else {
78+
x = (halfQ - cumQ) / b.q0;
79+
}
80+
x = std::clamp(x, 0.f, dz);
81+
mRespCentreDep = b.z0 + x;
82+
return;
83+
}
84+
85+
mRespCentreDep = mDptMax;
8586
}

0 commit comments

Comments
 (0)