Skip to content

Commit 8d8ce54

Browse files
committed
Add Layer/Stave dump for checking clusters in IB
1 parent 5c52a4b commit 8d8ce54

File tree

1 file changed

+211
-53
lines changed

1 file changed

+211
-53
lines changed

Detectors/ITSMFT/ITS/macros/test/CheckSquasher.C

Lines changed: 211 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <DetectorsCommonDataFormats/DetectorNameConf.h>
1919
#include <SimulationDataFormat/MCCompLabel.h>
2020
#include <SimulationDataFormat/MCTruthContainer.h>
21+
#include <ITSMFTReconstruction/ChipMappingITS.h>
2122
#include <CCDB/BasicCCDBManager.h>
2223

2324
#include <TFile.h>
@@ -32,17 +33,38 @@
3233
#include <gsl/gsl>
3334
#endif
3435

35-
void getClusterPatterns(std::vector<o2::itsmft::ClusterPattern>& pattVec, std::vector<o2::itsmft::CompClusterExt>* ITSclus, std::vector<unsigned char>* ITSpatt, o2::itsmft::TopologyDictionary& mdict);
36+
static bool invPal = false;
37+
void getClusterPatterns(std::vector<o2::itsmft::ClusterPattern>& pattVec,
38+
std::vector<o2::itsmft::CompClusterExt>* ITSclus,
39+
std::vector<unsigned char>* ITSpatt,
40+
o2::itsmft::TopologyDictionary& mdict);
3641

37-
void CheckSquasher(const uint chipId = 0, const uint startingROF = 0, const unsigned int nRofs = 3, const string fname = "o2clus_its.root")
42+
void drawClustersInChipInRof(const uint chipId,
43+
gsl::span<const o2::itsmft::CompClusterExt> clustersInFrame,
44+
gsl::span<const o2::itsmft::ClusterPattern> patternsInFrame,
45+
TH2D* hHitMapsVsFrame,
46+
TH2D* hHitMapSuperimposed = nullptr);
47+
48+
void drawClustersInStaveInRof(const int staveId,
49+
const int layerId,
50+
gsl::span<const o2::itsmft::CompClusterExt> clustersInFrame,
51+
gsl::span<const o2::itsmft::ClusterPattern> patternsInFrame,
52+
TH2D* hHitMapsVsFrame);
53+
54+
void CheckSquasher1(const uint chipId = 0, const uint startingROF = 0, const uint nRofs = 3, bool showSuperimposed = false, const string fname = "o2clus_its.root")
3855
{
39-
TColor::InvertPalette();
56+
if (!invPal) {
57+
TColor::InvertPalette();
58+
invPal = true;
59+
}
60+
4061
gStyle->SetOptStat(0);
4162
// Geometry
4263
auto& cc = o2::ccdb::BasicCCDBManager::instance();
4364
cc.setTimestamp(o2::ccdb::getCurrentTimestamp());
4465
auto* gman = cc.get<o2::its::GeometryTGeo>("ITS/Config/Geometry");
4566
gman->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L, o2::math_utils::TransformType::L2G));
67+
4668
// Topology dictionary
4769
auto mdict = cc.get<o2::itsmft::TopologyDictionary>("ITS/Calib/ClusterDictionary");
4870
auto fITSclus = TFile::Open(fname.data(), "r");
@@ -78,55 +100,7 @@ void CheckSquasher(const uint chipId = 0, const uint startingROF = 0, const unsi
78100
const auto& rof = (*ITSrof)[startingROF + iR];
79101
auto clustersInFrame = rof.getROFData(*ITSclus);
80102
auto patternsInFrame = rof.getROFData(pattVec);
81-
// auto pattIt = ITSpatt->cbegin();
82-
83-
for (unsigned int clusInd{0}; clusInd < clustersInFrame.size(); clusInd++) {
84-
const auto& clus = clustersInFrame[clusInd];
85-
auto sID = clus.getSensorID();
86-
87-
if (sID == chipId) {
88-
LOGP(info, "Processing cluster {}", clusInd);
89-
clus.print();
90-
91-
// auto labels = clusLabArr->getLabels(clusInd);
92-
// extract pattern info
93-
auto col = clus.getCol();
94-
auto row = clus.getRow();
95-
96-
std::cout << patternsInFrame[clusInd];
97-
98-
std::cout << std::endl;
99-
int ic = 0, ir = 0;
100-
101-
auto colSpan = patternsInFrame[clusInd].getColumnSpan();
102-
auto rowSpan = patternsInFrame[clusInd].getRowSpan();
103-
auto nBits = rowSpan * colSpan;
104-
105-
for (int i = 2; i < patternsInFrame[clusInd].getUsedBytes() + 2; i++) {
106-
unsigned char tempChar = patternsInFrame[clusInd].getByte(i);
107-
int s = 128; // 0b10000000
108-
while (s > 0) {
109-
if ((tempChar & s) != 0) // checking active pixels
110-
{
111-
hHitMapsVsFrame[iR]->Fill(col + ic, row + ir);
112-
hHitMapSuperimposed->Fill(col + ic, row + ir);
113-
}
114-
ic++;
115-
s >>= 1;
116-
if ((ir + 1) * ic == nBits) {
117-
break;
118-
}
119-
if (ic == colSpan) {
120-
ic = 0;
121-
ir++;
122-
}
123-
if ((ir + 1) * ic == nBits) {
124-
break;
125-
}
126-
}
127-
}
128-
}
129-
}
103+
drawClustersInChipInRof(chipId, clustersInFrame, patternsInFrame, hHitMapsVsFrame[iR], hHitMapSuperimposed);
130104
}
131105
auto canvas = new TCanvas(Form("chip%d", chipId), Form("chip%d", chipId), nRofs * 1000, 600);
132106
auto canvasSuperimposition = new TCanvas(Form("chip%d_superimposed", chipId), Form("chip%d_superimposed", chipId), 600, 600);
@@ -141,7 +115,81 @@ void CheckSquasher(const uint chipId = 0, const uint startingROF = 0, const unsi
141115
canvasSuperimposition->cd();
142116
gPad->SetGridx();
143117
gPad->SetGridy();
144-
hHitMapSuperimposed->Draw("colz");
118+
if (showSuperimposed) {
119+
hHitMapSuperimposed->Draw("colz");
120+
} else {
121+
delete canvasSuperimposition;
122+
}
123+
}
124+
125+
void CheckSquasher(const int staveId, const uint layerId, const uint startingROF = 0, const uint nRofs = 3, const string fname = "o2clus_its.root")
126+
{
127+
std::array<int, 3> staves{12, 14, 16};
128+
if (!invPal) {
129+
TColor::InvertPalette();
130+
invPal = true;
131+
}
132+
133+
gStyle->SetOptStat(0);
134+
// Geometry
135+
auto& cc = o2::ccdb::BasicCCDBManager::instance();
136+
cc.setTimestamp(o2::ccdb::getCurrentTimestamp());
137+
auto* gman = cc.get<o2::its::GeometryTGeo>("ITS/Config/Geometry");
138+
gman->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L, o2::math_utils::TransformType::L2G));
139+
140+
// Topology dictionary
141+
auto mdict = cc.get<o2::itsmft::TopologyDictionary>("ITS/Calib/ClusterDictionary");
142+
auto fITSclus = TFile::Open(fname.data(), "r");
143+
auto treeITSclus = (TTree*)fITSclus->Get("o2sim");
144+
145+
std::vector<o2::itsmft::CompClusterExt>* ITSclus = nullptr;
146+
std::vector<o2::itsmft::ROFRecord>* ITSrof = nullptr;
147+
std::vector<unsigned char>* ITSpatt = nullptr;
148+
o2::dataformats::MCTruthContainer<o2::MCCompLabel>* clusLabArr = nullptr;
149+
150+
treeITSclus->SetBranchAddress("ITSClusterComp", &ITSclus);
151+
treeITSclus->SetBranchAddress("ITSClustersROF", &ITSrof);
152+
treeITSclus->SetBranchAddress("ITSClusterPatt", &ITSpatt);
153+
154+
auto clSpan = gsl::span(ITSclus->data(), ITSclus->size());
155+
std::vector<TH2D*> hHitMapsVsFrame(nRofs);
156+
TH2D* hHitMapSuperimposed = nullptr;
157+
std::vector<TH2D*> hHitMapStaves;
158+
hHitMapStaves.resize(staveId < 0 ? staves[layerId] : 1);
159+
for (int iStave{0}; iStave < (staveId < 0 ? staves[layerId] : 1); ++iStave) {
160+
hHitMapStaves[staveId < 0 ? iStave : 0] = new TH2D(Form("stave_%d", staveId < 0 ? iStave : staveId), "", 1024 * 9, -0.5, 1023.5 * 9, 512, -0.5, 511.5);
161+
}
162+
163+
treeITSclus->GetEvent(0);
164+
LOGP(info, "there are {} rofs in this TF", ITSrof->size());
165+
166+
// Get patterns
167+
std::vector<o2::itsmft::ClusterPattern> pattVec;
168+
getClusterPatterns(pattVec, ITSclus, ITSpatt, *mdict);
169+
170+
for (unsigned int iR{0}; iR < nRofs; iR++) {
171+
LOGP(info, " ===============\n \tProcessing rof {} \n\t===============", iR + startingROF);
172+
// work on data
173+
const auto& rof = (*ITSrof)[startingROF + iR];
174+
auto clustersInFrame = rof.getROFData(*ITSclus);
175+
auto patternsInFrame = rof.getROFData(pattVec);
176+
for (int iStave{0}; iStave < (staveId < 0 ? staves[layerId] : 1); ++iStave) {
177+
drawClustersInStaveInRof(staveId < 0 ? iStave : staveId, layerId, clustersInFrame, patternsInFrame, hHitMapStaves[staveId < 0 ? iStave : 0]);
178+
}
179+
}
180+
181+
auto canvas = new TCanvas(Form("stave%d", staveId), Form("stave%d", staveId), 9 * 1000, (staveId < 0 ? staves[layerId] : 1) * 1000);
182+
if (staveId < 0) {
183+
canvas->Divide(1, staves[layerId]);
184+
}
185+
for (int iStave{0}; iStave < (staveId < 0 ? staves[layerId] : 1); ++iStave) {
186+
if (staveId < 0) {
187+
canvas->cd(iStave + 1);
188+
}
189+
gPad->SetGridx();
190+
gPad->SetGridy();
191+
hHitMapStaves[staveId < 0 ? iStave : 0]->Draw("colz");
192+
}
145193
}
146194

147195
void getClusterPatterns(std::vector<o2::itsmft::ClusterPattern>& pattVec, std::vector<o2::itsmft::CompClusterExt>* ITSclus, std::vector<unsigned char>* ITSpatt, o2::itsmft::TopologyDictionary& mdict)
@@ -168,3 +216,113 @@ void getClusterPatterns(std::vector<o2::itsmft::ClusterPattern>& pattVec, std::v
168216
pattVec.push_back(patt);
169217
}
170218
}
219+
220+
void drawClustersInChipInRof(const uint chipId,
221+
gsl::span<const o2::itsmft::CompClusterExt> clustersInFrame,
222+
gsl::span<const o2::itsmft::ClusterPattern> patternsInFrame,
223+
TH2D* hHitMapsVsFrame,
224+
TH2D* hHitMapSuperimposed)
225+
{
226+
for (unsigned int clusInd{0}; clusInd < clustersInFrame.size(); clusInd++) {
227+
const auto& clus = clustersInFrame[clusInd];
228+
auto sID = clus.getSensorID();
229+
230+
if (sID == chipId) {
231+
LOGP(info, "Processing cluster {}", clusInd);
232+
clus.print();
233+
234+
// extract pattern info
235+
auto col = clus.getCol();
236+
auto row = clus.getRow();
237+
238+
std::cout << patternsInFrame[clusInd];
239+
240+
std::cout << std::endl;
241+
int ic = 0, ir = 0;
242+
243+
auto colSpan = patternsInFrame[clusInd].getColumnSpan();
244+
auto rowSpan = patternsInFrame[clusInd].getRowSpan();
245+
auto nBits = rowSpan * colSpan;
246+
247+
for (int i = 2; i < patternsInFrame[clusInd].getUsedBytes() + 2; i++) {
248+
unsigned char tempChar = patternsInFrame[clusInd].getByte(i);
249+
int s = 128; // 0b10000000
250+
while (s > 0) {
251+
if ((tempChar & s) != 0) // checking active pixels
252+
{
253+
hHitMapsVsFrame->Fill(col + ic, row + ir);
254+
hHitMapSuperimposed == nullptr ?: hHitMapSuperimposed->Fill(col + ic, row + ir);
255+
}
256+
ic++;
257+
s >>= 1;
258+
if ((ir + 1) * ic == nBits) {
259+
break;
260+
}
261+
if (ic == colSpan) {
262+
ic = 0;
263+
ir++;
264+
}
265+
if ((ir + 1) * ic == nBits) {
266+
break;
267+
}
268+
}
269+
}
270+
}
271+
}
272+
}
273+
274+
void drawClustersInStaveInRof(const int staveId,
275+
const int layerId,
276+
gsl::span<const o2::itsmft::CompClusterExt> clustersInFrame,
277+
gsl::span<const o2::itsmft::ClusterPattern> patternsInFrame,
278+
TH2D* hHitMapsVsFrame)
279+
{
280+
o2::itsmft::ChipMappingITS chipMapping;
281+
int lay, sta, ssta, mod, chipInMod;
282+
std::array<int, 9> sensorIDs; // sIDs in the staves of the IB.
283+
for (unsigned int clusInd{0}; clusInd < clustersInFrame.size(); clusInd++) {
284+
const auto& clus = clustersInFrame[clusInd];
285+
auto sID = clus.getSensorID();
286+
287+
chipMapping.expandChipInfoHW(sID, lay, sta, ssta, mod, chipInMod);
288+
289+
if (sta == staveId && lay == layerId) {
290+
// extract pattern info
291+
auto col = clus.getCol();
292+
auto row = clus.getRow();
293+
294+
int ic = 0, ir = 0;
295+
296+
auto colSpan = patternsInFrame[clusInd].getColumnSpan();
297+
auto rowSpan = patternsInFrame[clusInd].getRowSpan();
298+
auto nBits = rowSpan * colSpan;
299+
300+
for (int i = 2; i < patternsInFrame[clusInd].getUsedBytes() + 2; i++) {
301+
unsigned char tempChar = patternsInFrame[clusInd].getByte(i);
302+
int s = 128; // 0b10000000
303+
while (s > 0) {
304+
if ((tempChar & s) != 0) // checking active pixels
305+
{
306+
// Normalize the chip ID to be within the range [0, 8]
307+
int normalizedChipID = sID % 9; // Hardcode for the ITS IB
308+
double x = col + ic + normalizedChipID * 1024;
309+
double y = row + ir;
310+
hHitMapsVsFrame->Fill(x, y);
311+
}
312+
ic++;
313+
s >>= 1;
314+
if ((ir + 1) * ic == nBits) {
315+
break;
316+
}
317+
if (ic == colSpan) {
318+
ic = 0;
319+
ir++;
320+
}
321+
if ((ir + 1) * ic == nBits) {
322+
break;
323+
}
324+
}
325+
}
326+
}
327+
}
328+
}

0 commit comments

Comments
 (0)