Skip to content

Commit 029c30b

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

File tree

2 files changed

+53
-45
lines changed

2 files changed

+53
-45
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,25 @@ void LoadRespFunc()
5757
std::string AptsFile = "$(O2_ROOT)/share/Detectors/Upgrades/ITS3/data/ITS3ChipResponseData/APTSResponseData.root";
5858
std::string AlpideFile = "$(O2_ROOT)/share/Detectors/ITSMFT/data/AlpideResponseData/AlpideResponseData.root";
5959

60-
std::cout<<"=====================\n";
60+
std::cout << "=====================\n";
6161
LOGP(info, "ALPIDE Vbb=0V response");
6262
mAlpSimResp0 = loadResponse(AlpideFile, "response0"); // Vbb=0V
6363
mAlpSimResp0->computeCentreFromData();
6464
mAlpSimResp0->print();
6565
LOGP(info, "Response Centre {}", mAlpSimResp0->getRespCentreDep());
66-
std::cout<<"=====================\n";
66+
std::cout << "=====================\n";
6767
LOGP(info, "ALPIDE Vbb=-3V response");
6868
mAlpSimResp1 = loadResponse(AlpideFile, "response1"); // Vbb=-3V
6969
mAlpSimResp1->computeCentreFromData();
7070
mAlpSimResp1->print();
7171
LOGP(info, "Response Centre {}", mAlpSimResp1->getRespCentreDep());
72-
std::cout<<"=====================\n";
72+
std::cout << "=====================\n";
7373
LOGP(info, "APTS response");
7474
mAptSimResp1 = loadResponse(AptsFile, "response1"); // APTS
7575
mAptSimResp1->computeCentreFromData();
7676
mAptSimResp1->print();
7777
LOGP(info, "Response Centre {}", mAptSimResp1->getRespCentreDep());
78-
std::cout<<"=====================\n";
78+
std::cout << "=====================\n";
7979
}
8080

8181
std::vector<float> getCollectionSeediciencies(o2::its3::ChipSimResponse* resp,
@@ -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: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,61 +25,66 @@ void ChipSimResponse::initData(int tableNumber, std::string dataPath, const bool
2525

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

3133
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);
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);
3845
}
3946

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-
}
47+
struct Bin {
48+
float z0, z1, q0, q1, dq;
49+
};
50+
std::vector<Bin> bins;
51+
bins.reserve(zVec.size() - 1);
5152

52-
struct BinInfo { float z0, z1, q0, q1, dq; };
53-
std::vector<BinInfo> bins;
5453
float totQ = 0.f;
5554
for (size_t i = 0; i + 1 < zVec.size(); ++i) {
5655
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;
56+
float q0 = effVec[i], q1 = effVec[i + 1];
57+
float dq = 0.5f * (q0 + q1) * (z1 - z0);
6058
bins.push_back({z0, z1, q0, q1, dq});
6159
totQ += dq;
6260
}
63-
if (totQ <= 0.f) { mRespCentreDep = 0.f; return; }
61+
62+
if (totQ <= 0.f) {
63+
mRespCentreDep = mDptMin;
64+
return;
65+
}
6466

6567
float halfQ = 0.5f * totQ;
6668
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);
69+
for (auto& b : bins) {
70+
if (cumQ + b.dq < halfQ) {
71+
cumQ += b.dq;
72+
continue;
73+
}
7074
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 slope = (b.q1 - b.q0) / dz;
76+
float disc = b.q0 * b.q0 - 2.f * slope * (cumQ - halfQ);
77+
7578
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+
if (disc >= 0.f && std::abs(slope) > 1e-6f) {
80+
x = (-b.q0 + std::sqrt(disc)) / slope;
81+
} else {
7982
x = (halfQ - cumQ) / b.q0;
83+
}
8084
x = std::clamp(x, 0.f, dz);
8185
mRespCentreDep = b.z0 + x;
8286
return;
8387
}
88+
8489
mRespCentreDep = mDptMax;
8590
}

0 commit comments

Comments
 (0)