Skip to content

Commit f957e94

Browse files
author
Marcello Di Costanzo
committed
First draft of IOTOF clusterizer interface
1 parent 77c2fc3 commit f957e94

20 files changed

Lines changed: 984 additions & 13 deletions

File tree

Detectors/Upgrades/ALICE3/IOTOF/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
add_subdirectory(base)
1313
add_subdirectory(simulation)
1414
add_subdirectory(DataFormatsIOTOF)
15+
add_subdirectory(reconstruction)
1516
add_subdirectory(workflow)
1617
add_subdirectory(macros)

Detectors/Upgrades/ALICE3/IOTOF/DataFormatsIOTOF/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
o2_add_library(DataFormatsIOTOF
1313
SOURCES src/Digit.cxx
1414
# SOURCES src/MCLabel.cxx
15-
# SOURCES src/Cluster.cxx
15+
SOURCES src/Cluster.cxx
1616
PUBLIC_LINK_LIBRARIES O2::DataFormatsITSMFT)
1717

1818
o2_target_root_dictionary(DataFormatsIOTOF
1919
HEADERS include/DataFormatsIOTOF/Digit.h
2020
# HEADERS include/DataFormatsIOTOF/MCLabel.h
21-
# HEADERS include/DataFormatsIOTOF/Cluster.h
21+
HEADERS include/DataFormatsIOTOF/Cluster.h
2222
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2019-2026 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+
12+
#ifndef ALICEO2_DATAFORMATSIOTOF_CLUSTER_H
13+
#define ALICEO2_DATAFORMATSIOTOF_CLUSTER_H
14+
15+
#include <Rtypes.h>
16+
#include <cstdint>
17+
#include <string>
18+
19+
namespace o2::iotof
20+
{
21+
22+
struct Cluster {
23+
uint16_t chipID = 0;
24+
uint16_t row = 0;
25+
uint16_t col = 0;
26+
uint16_t size = 1;
27+
int16_t subDetID = -1;
28+
int16_t layer = -1;
29+
int16_t disk = -1;
30+
float xCoord = 0.f;
31+
float yCoord = 0.f;
32+
float zCoord = 0.f;
33+
34+
std::string asString() const;
35+
36+
ClassDefNV(Cluster, 1);
37+
};
38+
39+
} // namespace o2::iotof
40+
41+
#endif
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2019-2026 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+
12+
#include "DataFormatsIOTOF/Cluster.h"
13+
#include <sstream>
14+
15+
ClassImp(o2::iotof::Cluster);
16+
17+
namespace o2::iotof
18+
{
19+
20+
std::string Cluster::asString() const
21+
{
22+
std::ostringstream stream;
23+
stream << "chip=" << chipID << " row=" << row << " col=" << col << " size=" << size
24+
<< " subDet=" << subDetID << " layer=" << layer << " disk=" << disk;
25+
return stream.str();
26+
}
27+
28+
} // namespace o2::iotof

Detectors/Upgrades/ALICE3/IOTOF/DataFormatsIOTOF/src/DataFormatsIOTOFLinkDef.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#pragma link C++ class o2::iotof::Digit + ;
1919
#pragma link C++ class std::vector < o2::iotof::Digit> + ;
2020

21+
#pragma link C++ class o2::iotof::Cluster + ;
22+
#pragma link C++ class std::vector < o2::iotof::Cluster> + ;
23+
2124
#pragma link C++ class o2::iotof::McLabelRef + ;
2225
#pragma link C++ class std::vector < o2::iotof::McLabelRef> + ;
2326

Detectors/Upgrades/ALICE3/IOTOF/base/src/GeometryTGeo.cxx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ int GeometryTGeo::getIOTOFChipIndex(int lay, int sta, int mod, int chip) const
158158

159159
bool GeometryTGeo::getIOTOFChipId(int index, int& lay, int& sta, int& mod, int& chip) const
160160
{
161-
lay = getIOTOFLayer(index);
162-
index -= getIOTOFFirstChipIndex(lay);
161+
lay = getIOTOFLayer(index); // Get IOTOF layer
162+
index -= getIOTOFFirstChipIndex(lay); // Get index relative to layer
163163
sta = mNumberOfStavesIOTOF[lay] > 0 ? index / mNumberOfChipsPerStaveIOTOF[lay] : -1;
164164
index %= mNumberOfChipsPerStaveIOTOF[lay];
165165
mod = mNumberOfModulesIOTOF[lay] > 0 ? index / mNumberOfChipsPerModuleIOTOF[lay] : -1;
@@ -284,13 +284,14 @@ void GeometryTGeo::Build(int loadTrans)
284284
mLastChipIndex[j] = numberOfChips - 1;
285285
}
286286

287-
LOG(info) << "numberOfChipsITOF = " << mNumberOfChipsIOTOF[0] << ", numberOfChipsOTOF = " << mNumberOfChipsIOTOF[1] << ", numberOfChips = " << numberOfChips << ", mNumberOfChipesPerStaveITOF" << mNumberOfChipsPerStaveIOTOF[0];
287+
LOG(info) << "[GeometryTGeo] numberOfChipsITOF = " << mNumberOfChipsIOTOF[0] << ", numberOfChipsOTOF = " << mNumberOfChipsIOTOF[1] << ", numberOfChips = " << numberOfChips << ", mNumberOfChipesPerStaveITOF" << mNumberOfChipsPerStaveIOTOF[0];
288288

289289
setSize(numberOfChips);
290290
defineSensors();
291291
fillTrackingFramesCache();
292292
fillMatrixCache(loadTrans);
293-
// fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G));
293+
// LOG(info) << "[GeometryTGeo] Filling matrix cache";
294+
// fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G));
294295
}
295296

296297
void GeometryTGeo::defineSensors()

Detectors/Upgrades/ALICE3/IOTOF/macros/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ o2_add_test_root_macro(CheckDigitsIOTOF.C
2525
O2::DetectorsBase
2626
O2::Steer
2727
LABELS iotof COMPILE_ONLY)
28+
29+
o2_add_test_root_macro(CheckClustersIOTOF.C
30+
LABELS iotof COMPILE_ONLY)
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
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+
12+
/// \file CheckClustersIOTOF.C
13+
/// \brief Simple macro to create clusters from TF3 digits
14+
15+
#if !defined(__CLING__) || defined(__ROOTCLING__)
16+
#include <TCanvas.h>
17+
#include <TFile.h>
18+
#include <TH1F.h>
19+
#include <TNtuple.h>
20+
#include <TTree.h>
21+
#include <TStyle.h>
22+
23+
#include "IOTOFSimulation/Segmentation.h"
24+
#include "IOTOFBase/IOTOFBaseParam.h"
25+
#include "IOTOFBase/GeometryTGeo.h"
26+
#include "DataFormatsIOTOF/Digit.h"
27+
#include "DataFormatsIOTOF/Cluster.h"
28+
#include "MathUtils/Utils.h"
29+
#include "SimulationDataFormat/ConstMCTruthContainer.h"
30+
#include "SimulationDataFormat/IOMCTruthContainerView.h"
31+
#include "SimulationDataFormat/MCCompLabel.h"
32+
#include "DetectorsBase/GeometryManager.h"
33+
34+
#include "DataFormatsITSMFT/ROFRecord.h"
35+
36+
#endif
37+
38+
#define ENABLE_UPGRADES
39+
40+
void CheckClustersIOTOF(std::string digiFilePath = "tf3digits.root", std::string clsFilePath = "tf3clusters.root", std::string inputGeomPath = "o2sim_geometry.root")
41+
{
42+
gStyle->SetPalette(55);
43+
44+
using namespace o2::base;
45+
using namespace o2::iotof;
46+
47+
using o2::iotof::Digit;
48+
using o2::iotof::Cluster;
49+
50+
o2::conf::ConfigurableParam::updateFromString("IOTOFBase.segmentedInnerTOF=true;IOTOFBase.segmentedOuterTOF=true;IOTOFBase.enableForwardTOF=false;IOTOFBase.enableBackwardTOF=false");
51+
52+
auto segGeom = o2::iotof::Segmentation::Instance();
53+
54+
// Geometry
55+
o2::base::GeometryManager::loadGeometry(inputGeomPath);
56+
auto* tofGeo = o2::iotof::GeometryTGeo::Instance();
57+
tofGeo->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G));
58+
59+
// Digits
60+
TFile* digiFile = TFile::Open(digiFilePath.data());
61+
TTree* digiTree = (TTree*)digiFile->Get("o2sim");
62+
std::vector<o2::iotof::Digit>* digitsArray{nullptr};
63+
digiTree->SetBranchAddress("TF3Digit", &digitsArray);
64+
std::vector<o2::itsmft::ROFRecord>* digiRofRecordsArr{nullptr};
65+
digiTree->SetBranchAddress("TF3DigitROF", &digiRofRecordsArr);
66+
auto& digiRofArr = *digiRofRecordsArr;
67+
o2::dataformats::IOMCTruthContainerView* digiPlabelsArr{nullptr};
68+
digiTree->SetBranchAddress("TF3DigitMCTruth", &digiPlabelsArr);
69+
digiTree->GetEntry(0);
70+
71+
// Clusters
72+
TFile* clsFile = TFile::Open(clsFilePath.data());
73+
TTree* clsTree = (TTree*)clsFile->Get("o2sim");
74+
std::vector<o2::iotof::Cluster>* clsArray{nullptr};
75+
clsTree->SetBranchAddress("TF3ClusterComp", &clsArray);
76+
std::vector<o2::itsmft::ROFRecord>* clsRofRecordsArr{nullptr};
77+
clsTree->SetBranchAddress("TF3ClusterROF", &clsRofRecordsArr);
78+
auto& clsRofArr = *clsRofRecordsArr;
79+
o2::dataformats::IOMCTruthContainerView* clsPlabelsArr{nullptr};
80+
clsTree->SetBranchAddress("TF3ClusterMCTruth", &clsPlabelsArr);
81+
clsTree->GetEntry(0);
82+
83+
// Start script
84+
o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel> labels;
85+
clsPlabelsArr->copyandflatten(labels);
86+
87+
auto clsTuple = new TNtuple("clsTuple", "clsTuple", "chip_id:x:y:z:subdet_id:row:col");
88+
clsTuple->SetDirectory(nullptr);
89+
90+
TH1F* histXCoordCls = new TH1F("histXCoordCls", "histXCoordCls", 8000, -100, 100);
91+
TH1F* histYCoordCls = new TH1F("histYCoordCls", "histYCoordCls", 8000, -100, 100);
92+
TH1F* histZCoordCls = new TH1F("histZCoordCls", "histZCoordCls", 28000, -400, 400);
93+
TH1F* histXCoordDigit = new TH1F("histXCoordDigit", "histXCoordDigit", 8000, -100, 100);
94+
TH1F* histYCoordDigit = new TH1F("histYCoordDigit", "histYCoordDigit", 8000, -100, 100);
95+
TH1F* histZCoordDigit = new TH1F("histZCoordDigit", "histZCoordDigit", 28000, -400, 400);
96+
97+
// LOOP on : ROFRecord array
98+
for (unsigned int iROF = 0; iROF < clsRofArr.size(); ++iROF) {
99+
100+
const unsigned int rofIndex = clsRofArr[iROF].getFirstEntry();
101+
const unsigned int rofNEntries = clsRofArr[iROF].getNEntries();
102+
103+
// LOOP on : digits array
104+
for (unsigned int iDigit = rofIndex; iDigit < rofIndex + rofNEntries; iDigit++) {
105+
if (iDigit % 1000 == 0) {
106+
std::cout << "Reading digit " << iDigit << " / " << digitsArray->size() << std::endl;
107+
}
108+
109+
Int_t iRow = (*digitsArray)[iDigit].getRow();
110+
Int_t iCol = (*digitsArray)[iDigit].getColumn();
111+
Int_t iDetID = (*digitsArray)[iDigit].getChipIndex();
112+
Int_t chipID = (*digitsArray)[iDigit].getChipIndex();
113+
Int_t subDetID = tofGeo->getIOTOFLayer(iDetID);
114+
115+
Float_t x{0.f}, y{0.f}, z{0.f};
116+
if (subDetID >= 0) {
117+
segGeom->detectorToLocal(iRow, iCol, x, z, subDetID);
118+
}
119+
120+
o2::math_utils::Point3D<float> localDigitCoord(x, y, z); // local Digit
121+
122+
const auto globalDigitCoord = tofGeo->getMatrixL2G(chipID)(localDigitCoord); // convert to global
123+
histXCoordDigit->Fill(globalDigitCoord.X());
124+
histYCoordDigit->Fill(globalDigitCoord.Y());
125+
histZCoordDigit->Fill(globalDigitCoord.Z());
126+
} // end loop on digits array
127+
128+
129+
// LOOP on : clusters array
130+
for (unsigned int iCls = rofIndex; iCls < rofIndex + rofNEntries; iCls++) {
131+
if (iCls % 1000 == 0) {
132+
std::cout << "Reading cluster " << iCls << " / " << clsArray->size() << std::endl;
133+
}
134+
135+
Int_t iRow = (*clsArray)[iCls].row;
136+
Int_t iCol = (*clsArray)[iCls].col;
137+
Int_t chipID = (*clsArray)[iCls].chipID;
138+
Int_t subDetID = tofGeo->getIOTOFLayer(chipID);
139+
140+
Float_t x = 0.f, y = 0.f, z = 0.f;
141+
if (subDetID >= 0) {
142+
segGeom->detectorToLocal(iRow, iCol, x, z, subDetID);
143+
}
144+
145+
o2::math_utils::Point3D<float> localClsCoords(x, y, z); // local Digit
146+
const auto globalClsCoords = tofGeo->getMatrixL2G(chipID)(localClsCoords); // convert to global
147+
std::cout << "Cluster " << iCls << ": chipID = " << chipID << ", X=" << globalClsCoords.x() << ", Y=" << globalClsCoords.y() << ", Z=" << globalClsCoords.z() << std::endl;
148+
clsTuple->Fill((*clsArray)[iCls].chipID,
149+
globalClsCoords.x(),
150+
globalClsCoords.y(),
151+
globalClsCoords.z(),
152+
(*clsArray)[iCls].subDetID,
153+
(*clsArray)[iCls].row,
154+
(*clsArray)[iCls].col);
155+
histXCoordCls->Fill(globalClsCoords.x());
156+
histYCoordCls->Fill(globalClsCoords.y());
157+
histZCoordCls->Fill(globalClsCoords.z());
158+
} // end loop on clusters array
159+
160+
} // end loop on ROFRecords
161+
162+
std::cout << "Cluster array size: " << clsTuple->GetEntries() << std::endl;
163+
164+
// cluster maps in the xy and yz planes
165+
auto canvXY = new TCanvas("canvXY", "", 1600, 800);
166+
canvXY->Divide(2, 1);
167+
canvXY->cd(1);
168+
clsTuple->Draw("y:x>>h_y_vs_x_IOTOF(1000, -100, 100, 1000, -100, 100)", "", "colz");
169+
canvXY->cd(2);
170+
clsTuple->Draw("y:z>>h_y_vs_z_IOTOF(1000, -400, 400, 1000, -100, 100)", "", "colz");
171+
canvXY->SaveAs("clusters_digits_y_vs_x_vs_z.pdf");
172+
173+
// z distributions
174+
auto canvZ = new TCanvas("canvZ", "", 800, 800);
175+
canvZ->cd();
176+
clsTuple->Draw("z>>h_z_IOTOF(500, -70, 70)", "");
177+
canvZ->SaveAs("clusters_digits_z.pdf");
178+
179+
TFile* outFile = new TFile("CheckClusters.root", "RECREATE");
180+
// Save all columns of the tuple as hists
181+
clsTuple->Write();
182+
histXCoordCls->Write();
183+
histYCoordCls->Write();
184+
histZCoordCls->Write();
185+
histXCoordDigit->Write();
186+
histYCoordDigit->Write();
187+
histZCoordDigit->Write();
188+
outFile->Write();
189+
outFile->Close();
190+
191+
}

Detectors/Upgrades/ALICE3/IOTOF/macros/CheckDigitsIOTOF.C

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ void CheckDigitsIOTOF(std::string digifile = "tf3digits.root", std::string hitfi
146146
plabelsArr->copyandflatten(labels);
147147

148148
// LOOP on : ROFRecord array
149+
TH1F* histXCoord = new TH1F("histXCoord", "histXCoord", 8000, -100, 100);
150+
TH1F* histYCoord = new TH1F("histYCoord", "histYCoord", 8000, -100, 100);
151+
TH1F* histZCoord = new TH1F("histZCoord", "histZCoord", 28000, -400, 400);
149152
for (unsigned int iROF = 0; iROF < rofArr.size(); ++iROF) {
150153

151154
const unsigned int rofIndex = rofArr[iROF].getFirstEntry();
@@ -227,8 +230,11 @@ void CheckDigitsIOTOF(std::string digifile = "tf3digits.root", std::string hitfi
227230
locH.X(), locH.Z(), /// x and z of the hit in the local reference frame: hit global position -> hit local position
228231
xlc, zlc, /// x and z of the hit in the local frame: hit global position -> hit local position -> detector position (row, col) -> local position
229232
locHS.X() - locD.X(), locHS.Z() - locD.Z()); /// difference in x and z between the hit and the digit in the local frame
233+
histXCoord->Fill(gloD.X());
234+
histYCoord->Fill(gloD.Y());
235+
histZCoord->Fill(gloD.Z());
230236
nt2->Fill(chipID, gloD.Z(), locHS.X() - locHE.X(), locHS.Z() - locHE.Z()); /// differences between local hit start and hit end positions
231-
237+
std::cout << "Digit " << iDigit << ": chipID = " << chipID << ", X=" << gloD.X() << ", Y=" << gloD.Y() << ", Z=" << gloD.Z() << std::endl;
232238
} // end loop on digits array
233239

234240
} // end loop on ROFRecords
@@ -293,4 +299,11 @@ void CheckDigitsIOTOF(std::string digifile = "tf3digits.root", std::string hitfi
293299

294300
f->Write();
295301
f->Close();
302+
303+
TFile* outFile = new TFile("CheckDigitsHists.root", "RECREATE");
304+
outFile->cd();
305+
histXCoord->Write();
306+
histYCoord->Write();
307+
histZCoord->Write();
308+
outFile->Close();
296309
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
12+
o2_add_library(IOTOFReconstruction
13+
TARGETVARNAME targetName
14+
SOURCES src/Clusterer.cxx
15+
PUBLIC_LINK_LIBRARIES
16+
Microsoft.GSL::GSL
17+
# O2::DataFormatsITSMFT
18+
O2::DataFormatsIOTOF
19+
O2::IOTOFBase
20+
O2::IOTOFSimulation
21+
# O2::SimulationDataFormat
22+
# nlohmann_json::nlohmann_json
23+
)

0 commit comments

Comments
 (0)