Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
264 changes: 211 additions & 53 deletions Detectors/ITSMFT/ITS/macros/test/CheckSquasher.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <DetectorsCommonDataFormats/DetectorNameConf.h>
#include <SimulationDataFormat/MCCompLabel.h>
#include <SimulationDataFormat/MCTruthContainer.h>
#include <ITSMFTReconstruction/ChipMappingITS.h>
#include <CCDB/BasicCCDBManager.h>

#include <TFile.h>
Expand All @@ -32,17 +33,38 @@
#include <gsl/gsl>
#endif

void getClusterPatterns(std::vector<o2::itsmft::ClusterPattern>& pattVec, std::vector<o2::itsmft::CompClusterExt>* ITSclus, std::vector<unsigned char>* ITSpatt, o2::itsmft::TopologyDictionary& mdict);
static bool invPal = false;
void getClusterPatterns(std::vector<o2::itsmft::ClusterPattern>& pattVec,
std::vector<o2::itsmft::CompClusterExt>* ITSclus,
std::vector<unsigned char>* ITSpatt,
o2::itsmft::TopologyDictionary& mdict);

void CheckSquasher(const uint chipId = 0, const uint startingROF = 0, const unsigned int nRofs = 3, const string fname = "o2clus_its.root")
void drawClustersInChipInRof(const uint chipId,
gsl::span<const o2::itsmft::CompClusterExt> clustersInFrame,
gsl::span<const o2::itsmft::ClusterPattern> patternsInFrame,
TH2D* hHitMapsVsFrame,
TH2D* hHitMapSuperimposed = nullptr);

void drawClustersInStaveInRof(const int staveId,
const int layerId,
gsl::span<const o2::itsmft::CompClusterExt> clustersInFrame,
gsl::span<const o2::itsmft::ClusterPattern> patternsInFrame,
TH2D* hHitMapsVsFrame);

void CheckSquasher1(const uint chipId = 0, const uint startingROF = 0, const uint nRofs = 3, bool showSuperimposed = false, const string fname = "o2clus_its.root")
{
TColor::InvertPalette();
if (!invPal) {
TColor::InvertPalette();
invPal = true;
}

gStyle->SetOptStat(0);
// Geometry
auto& cc = o2::ccdb::BasicCCDBManager::instance();
cc.setTimestamp(o2::ccdb::getCurrentTimestamp());
auto* gman = cc.get<o2::its::GeometryTGeo>("ITS/Config/Geometry");
gman->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L, o2::math_utils::TransformType::L2G));

// Topology dictionary
auto mdict = cc.get<o2::itsmft::TopologyDictionary>("ITS/Calib/ClusterDictionary");
auto fITSclus = TFile::Open(fname.data(), "r");
Expand Down Expand Up @@ -78,55 +100,7 @@ void CheckSquasher(const uint chipId = 0, const uint startingROF = 0, const unsi
const auto& rof = (*ITSrof)[startingROF + iR];
auto clustersInFrame = rof.getROFData(*ITSclus);
auto patternsInFrame = rof.getROFData(pattVec);
// auto pattIt = ITSpatt->cbegin();

for (unsigned int clusInd{0}; clusInd < clustersInFrame.size(); clusInd++) {
const auto& clus = clustersInFrame[clusInd];
auto sID = clus.getSensorID();

if (sID == chipId) {
LOGP(info, "Processing cluster {}", clusInd);
clus.print();

// auto labels = clusLabArr->getLabels(clusInd);
// extract pattern info
auto col = clus.getCol();
auto row = clus.getRow();

std::cout << patternsInFrame[clusInd];

std::cout << std::endl;
int ic = 0, ir = 0;

auto colSpan = patternsInFrame[clusInd].getColumnSpan();
auto rowSpan = patternsInFrame[clusInd].getRowSpan();
auto nBits = rowSpan * colSpan;

for (int i = 2; i < patternsInFrame[clusInd].getUsedBytes() + 2; i++) {
unsigned char tempChar = patternsInFrame[clusInd].getByte(i);
int s = 128; // 0b10000000
while (s > 0) {
if ((tempChar & s) != 0) // checking active pixels
{
hHitMapsVsFrame[iR]->Fill(col + ic, row + ir);
hHitMapSuperimposed->Fill(col + ic, row + ir);
}
ic++;
s >>= 1;
if ((ir + 1) * ic == nBits) {
break;
}
if (ic == colSpan) {
ic = 0;
ir++;
}
if ((ir + 1) * ic == nBits) {
break;
}
}
}
}
}
drawClustersInChipInRof(chipId, clustersInFrame, patternsInFrame, hHitMapsVsFrame[iR], hHitMapSuperimposed);
}
auto canvas = new TCanvas(Form("chip%d", chipId), Form("chip%d", chipId), nRofs * 1000, 600);
auto canvasSuperimposition = new TCanvas(Form("chip%d_superimposed", chipId), Form("chip%d_superimposed", chipId), 600, 600);
Expand All @@ -141,7 +115,81 @@ void CheckSquasher(const uint chipId = 0, const uint startingROF = 0, const unsi
canvasSuperimposition->cd();
gPad->SetGridx();
gPad->SetGridy();
hHitMapSuperimposed->Draw("colz");
if (showSuperimposed) {
hHitMapSuperimposed->Draw("colz");
} else {
delete canvasSuperimposition;
}
}

void CheckSquasher(const int staveId, const uint layerId, const uint startingROF = 0, const uint nRofs = 3, const string fname = "o2clus_its.root")
{
std::array<int, 3> staves{12, 14, 16};
if (!invPal) {
TColor::InvertPalette();
invPal = true;
}

gStyle->SetOptStat(0);
// Geometry
auto& cc = o2::ccdb::BasicCCDBManager::instance();
cc.setTimestamp(o2::ccdb::getCurrentTimestamp());
auto* gman = cc.get<o2::its::GeometryTGeo>("ITS/Config/Geometry");
gman->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L, o2::math_utils::TransformType::L2G));

// Topology dictionary
auto mdict = cc.get<o2::itsmft::TopologyDictionary>("ITS/Calib/ClusterDictionary");
auto fITSclus = TFile::Open(fname.data(), "r");
auto treeITSclus = (TTree*)fITSclus->Get("o2sim");

std::vector<o2::itsmft::CompClusterExt>* ITSclus = nullptr;
std::vector<o2::itsmft::ROFRecord>* ITSrof = nullptr;
std::vector<unsigned char>* ITSpatt = nullptr;
o2::dataformats::MCTruthContainer<o2::MCCompLabel>* clusLabArr = nullptr;

treeITSclus->SetBranchAddress("ITSClusterComp", &ITSclus);
treeITSclus->SetBranchAddress("ITSClustersROF", &ITSrof);
treeITSclus->SetBranchAddress("ITSClusterPatt", &ITSpatt);

auto clSpan = gsl::span(ITSclus->data(), ITSclus->size());
std::vector<TH2D*> hHitMapsVsFrame(nRofs);
TH2D* hHitMapSuperimposed = nullptr;
std::vector<TH2D*> hHitMapStaves;
hHitMapStaves.resize(staveId < 0 ? staves[layerId] : 1);
for (int iStave{0}; iStave < (staveId < 0 ? staves[layerId] : 1); ++iStave) {
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);
}

treeITSclus->GetEvent(0);
LOGP(info, "there are {} rofs in this TF", ITSrof->size());

// Get patterns
std::vector<o2::itsmft::ClusterPattern> pattVec;
getClusterPatterns(pattVec, ITSclus, ITSpatt, *mdict);

for (unsigned int iR{0}; iR < nRofs; iR++) {
LOGP(info, " ===============\n \tProcessing rof {} \n\t===============", iR + startingROF);
// work on data
const auto& rof = (*ITSrof)[startingROF + iR];
auto clustersInFrame = rof.getROFData(*ITSclus);
auto patternsInFrame = rof.getROFData(pattVec);
for (int iStave{0}; iStave < (staveId < 0 ? staves[layerId] : 1); ++iStave) {
drawClustersInStaveInRof(staveId < 0 ? iStave : staveId, layerId, clustersInFrame, patternsInFrame, hHitMapStaves[staveId < 0 ? iStave : 0]);
}
}

auto canvas = new TCanvas(Form("stave%d", staveId), Form("stave%d", staveId), 9 * 1000, (staveId < 0 ? staves[layerId] : 1) * 1000);
if (staveId < 0) {
canvas->Divide(1, staves[layerId]);
}
for (int iStave{0}; iStave < (staveId < 0 ? staves[layerId] : 1); ++iStave) {
if (staveId < 0) {
canvas->cd(iStave + 1);
}
gPad->SetGridx();
gPad->SetGridy();
hHitMapStaves[staveId < 0 ? iStave : 0]->Draw("colz");
}
}

void getClusterPatterns(std::vector<o2::itsmft::ClusterPattern>& pattVec, std::vector<o2::itsmft::CompClusterExt>* ITSclus, std::vector<unsigned char>* ITSpatt, o2::itsmft::TopologyDictionary& mdict)
Expand All @@ -168,3 +216,113 @@ void getClusterPatterns(std::vector<o2::itsmft::ClusterPattern>& pattVec, std::v
pattVec.push_back(patt);
}
}

void drawClustersInChipInRof(const uint chipId,
gsl::span<const o2::itsmft::CompClusterExt> clustersInFrame,
gsl::span<const o2::itsmft::ClusterPattern> patternsInFrame,
TH2D* hHitMapsVsFrame,
TH2D* hHitMapSuperimposed)
{
for (unsigned int clusInd{0}; clusInd < clustersInFrame.size(); clusInd++) {
const auto& clus = clustersInFrame[clusInd];
auto sID = clus.getSensorID();

if (sID == chipId) {
LOGP(info, "Processing cluster {}", clusInd);
clus.print();

// extract pattern info
auto col = clus.getCol();
auto row = clus.getRow();

std::cout << patternsInFrame[clusInd];

std::cout << std::endl;
int ic = 0, ir = 0;

auto colSpan = patternsInFrame[clusInd].getColumnSpan();
auto rowSpan = patternsInFrame[clusInd].getRowSpan();
auto nBits = rowSpan * colSpan;

for (int i = 2; i < patternsInFrame[clusInd].getUsedBytes() + 2; i++) {
unsigned char tempChar = patternsInFrame[clusInd].getByte(i);
int s = 128; // 0b10000000
while (s > 0) {
if ((tempChar & s) != 0) // checking active pixels
{
hHitMapsVsFrame->Fill(col + ic, row + ir);
hHitMapSuperimposed == nullptr ?: hHitMapSuperimposed->Fill(col + ic, row + ir);
}
ic++;
s >>= 1;
if ((ir + 1) * ic == nBits) {
break;
}
if (ic == colSpan) {
ic = 0;
ir++;
}
if ((ir + 1) * ic == nBits) {
break;
}
}
}
}
}
}

void drawClustersInStaveInRof(const int staveId,
const int layerId,
gsl::span<const o2::itsmft::CompClusterExt> clustersInFrame,
gsl::span<const o2::itsmft::ClusterPattern> patternsInFrame,
TH2D* hHitMapsVsFrame)
{
o2::itsmft::ChipMappingITS chipMapping;
int lay, sta, ssta, mod, chipInMod;
std::array<int, 9> sensorIDs; // sIDs in the staves of the IB.
for (unsigned int clusInd{0}; clusInd < clustersInFrame.size(); clusInd++) {
const auto& clus = clustersInFrame[clusInd];
auto sID = clus.getSensorID();

chipMapping.expandChipInfoHW(sID, lay, sta, ssta, mod, chipInMod);

if (sta == staveId && lay == layerId) {
// extract pattern info
auto col = clus.getCol();
auto row = clus.getRow();

int ic = 0, ir = 0;

auto colSpan = patternsInFrame[clusInd].getColumnSpan();
auto rowSpan = patternsInFrame[clusInd].getRowSpan();
auto nBits = rowSpan * colSpan;

for (int i = 2; i < patternsInFrame[clusInd].getUsedBytes() + 2; i++) {
unsigned char tempChar = patternsInFrame[clusInd].getByte(i);
int s = 128; // 0b10000000
while (s > 0) {
if ((tempChar & s) != 0) // checking active pixels
{
// Normalize the chip ID to be within the range [0, 8]
int normalizedChipID = sID % 9; // Hardcode for the ITS IB
double x = col + ic + normalizedChipID * 1024;
double y = row + ir;
hHitMapsVsFrame->Fill(x, y);
}
ic++;
s >>= 1;
if ((ir + 1) * ic == nBits) {
break;
}
if (ic == colSpan) {
ic = 0;
ir++;
}
if ((ir + 1) * ic == nBits) {
break;
}
}
}
}
}
}
Loading