Skip to content

Commit 9509ff5

Browse files
committed
ITS: add scaffolding for tuning of reco-parameters
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent babe031 commit 9509ff5

18 files changed

Lines changed: 1041 additions & 41 deletions

File tree

Detectors/ITSMFT/ITS/macros/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111

1212
add_subdirectory(EVE)
1313
add_subdirectory(test)
14+
add_subdirectory(tune)
1415
add_subdirectory(DCS)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
o2_add_test_root_macro(CheckTracklets.C
13+
PUBLIC_LINK_LIBRARIES O2::ITStracking
14+
LABELS its COMPILE_ONLY)

Detectors/ITSMFT/ITS/macros/tune/CheckTracklets.C

Lines changed: 714 additions & 0 deletions
Large diffs are not rendered by default.

Detectors/ITSMFT/ITS/tracking/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ o2_add_library(ITStracking
2121
src/IOUtils.cxx
2222
src/Tracker.cxx
2323
src/TrackerTraits.cxx
24+
src/TrackerTraitsMC.cxx
2425
src/TrackingConfigParam.cxx
2526
src/Vertexer.cxx
2627
src/VertexerTraits.cxx
28+
src/TuneExt.cxx
2729
PUBLIC_LINK_LIBRARIES
2830
O2::GPUCommon
2931
Microsoft.GSL::GSL
@@ -55,6 +57,7 @@ o2_target_root_dictionary(ITStracking
5557
include/ITStracking/Definitions.h
5658
include/ITStracking/FastMultEstConfig.h
5759
include/ITStracking/TrackingConfigParam.h
60+
include/ITStracking/TuneExt.h
5861
LINKDEF src/TrackingLinkDef.h)
5962

6063
if(CUDA_ENABLED OR HIP_ENABLED)

Detectors/ITSMFT/ITS/tracking/include/ITStracking/TrackerTraits.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ class TrackerTraits
8585
std::shared_ptr<tbb::task_arena> mTaskArena;
8686

8787
protected:
88-
o2::gpu::GPUChainITS* mChain = nullptr;
89-
TimeFrame<NLayers>* mTimeFrame;
90-
std::vector<TrackingParameters> mTrkParams;
88+
void createTrackletMC();
9189

92-
float mBz{-999.f};
90+
o2::gpu::GPUChainITS* mChain{nullptr};
91+
TimeFrame<NLayers>* mTimeFrame{nullptr};
92+
std::vector<TrackingParameters> mTrkParams;
93+
float mBz{constants::UnsetValue};
9394
};
9495

9596
} // namespace its
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
13+
#ifndef TRACKINGITSU_INCLUDE_TRACKERTRAITSMC_H_
14+
#define TRACKINGITSU_INCLUDE_TRACKERTRAITSMC_H_
15+
16+
#include "ITStracking/TrackerTraits.h"
17+
18+
namespace o2::its
19+
{
20+
21+
// This class faciliates the tuning of the reconstruction parameters.
22+
// Two modes are foreseen:
23+
// 1. Inspect and dump the artefacts the reconstrcution produces
24+
// 2. Run the same over MC truth
25+
// Both should faciliate finding sources of in-efficiency (c.f., missing links)
26+
// and allow to tune overall the imposed parameters in a consistent way.
27+
template <int NLayers>
28+
class TrackerTraitsMC : public TrackerTraits<NLayers>
29+
{
30+
public:
31+
TrackerTraitsMC() = default;
32+
~TrackerTraitsMC() override = default;
33+
34+
void computeLayerTracklets(const int iteration, int iVertex) override;
35+
void computeLayerCells(const int iteration) override;
36+
void findCellsNeighbours(const int iteration) override;
37+
void findRoads(const int iteration) override;
38+
39+
const char* getName() const noexcept override { return "TUNE"; }
40+
};
41+
42+
} // namespace o2::its
43+
44+
#endif /* TRACKINGITSU_INCLUDE_TRACKERTRAITSMC_H_ */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
/// Holder of auxiallary information used for tuning
13+
///
14+
15+
#include "ITStracking/Constants.h"
16+
#include "GPUCommonRtypes.h"
17+
18+
namespace o2::its
19+
{
20+
struct TrackletMC final {
21+
float tgl{constants::UnsetValue}; // tanLambda
22+
float phi{constants::UnsetValue}; // phi
23+
float rIn{constants::UnsetValue};
24+
float zIn{constants::UnsetValue};
25+
float phiIn{constants::UnsetValue};
26+
float rOut{constants::UnsetValue};
27+
float zOut{constants::UnsetValue};
28+
float phiOut{constants::UnsetValue};
29+
float dr{constants::UnsetValue};
30+
float dz{constants::UnsetValue};
31+
float dPhi{constants::UnsetValue};
32+
bool ok{false}; // truth
33+
/// below only metrics valid if ok
34+
bool prim{false}; // primary
35+
float dXY{constants::UnsetValue}; // transverse distance to event
36+
float dZ{constants::UnsetValue}; // longitudinal distance to event
37+
float deltaZEvent{constants::UnsetValue};
38+
float tglEvent{constants::UnsetValue};
39+
ClassDefNV(TrackletMC, 2);
40+
};
41+
42+
} // namespace o2::its

Detectors/ITSMFT/ITS/tracking/src/TrackerTraits.cxx

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -223,26 +223,7 @@ void TrackerTraits<NLayers>::computeLayerTracklets(const int iteration, int iVer
223223

224224
/// Create tracklets labels
225225
if (mTimeFrame->hasMCinformation() && mTrkParams[iteration].CreateArtefactLabels) {
226-
tbb::parallel_for(0, static_cast<int>(topology.nTransitions), [&](const int transitionId) {
227-
const auto& transition = topology.getTransition(transitionId);
228-
for (auto& trk : mTimeFrame->getTracklets()[transitionId]) {
229-
MCCompLabel label;
230-
int currentId{mTimeFrame->getClusters()[transition.fromLayer][trk.firstClusterIndex].clusterId};
231-
int nextId{mTimeFrame->getClusters()[transition.toLayer][trk.secondClusterIndex].clusterId};
232-
for (const auto& lab1 : mTimeFrame->getClusterLabels(transition.fromLayer, currentId)) {
233-
for (const auto& lab2 : mTimeFrame->getClusterLabels(transition.toLayer, nextId)) {
234-
if (lab1 == lab2 && lab1.isValid()) {
235-
label = lab1;
236-
break;
237-
}
238-
}
239-
if (label.isValid()) {
240-
break;
241-
}
242-
}
243-
mTimeFrame->getTrackletsLabel(transitionId).emplace_back(label);
244-
}
245-
});
226+
createTrackletMC();
246227
}
247228
});
248229
}
@@ -907,6 +888,32 @@ void TrackerTraits<NLayers>::markTracks(int iteration)
907888
}
908889
}
909890

891+
template <int NLayers>
892+
void TrackerTraits<NLayers>::createTrackletMC()
893+
{
894+
const auto topology = mTimeFrame->getTrackingTopologyView();
895+
tbb::parallel_for(0, static_cast<int>(topology.nTransitions), [&](const int transitionId) {
896+
const auto& transition = topology.getTransition(transitionId);
897+
for (auto& trk : mTimeFrame->getTracklets()[transitionId]) {
898+
MCCompLabel label;
899+
int currentId{mTimeFrame->getClusters()[transition.fromLayer][trk.firstClusterIndex].clusterId};
900+
int nextId{mTimeFrame->getClusters()[transition.toLayer][trk.secondClusterIndex].clusterId};
901+
for (const auto& lab1 : mTimeFrame->getClusterLabels(transition.fromLayer, currentId)) {
902+
for (const auto& lab2 : mTimeFrame->getClusterLabels(transition.toLayer, nextId)) {
903+
if (lab1 == lab2 && lab1.isValid()) {
904+
label = lab1;
905+
break;
906+
}
907+
}
908+
if (label.isValid()) {
909+
break;
910+
}
911+
}
912+
mTimeFrame->getTrackletsLabel(transitionId).emplace_back(label);
913+
}
914+
});
915+
}
916+
910917
template <int NLayers>
911918
void TrackerTraits<NLayers>::setBz(float bz)
912919
{
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
13+
#include <algorithm>
14+
#include <cmath>
15+
#include <format>
16+
#include <limits>
17+
18+
#include "ITStracking/TrackerTraitsMC.h"
19+
#include "ITStracking/TuneExt.h"
20+
#include "CommonUtils/TreeStreamRedirector.h"
21+
#include "CommonConstants/MathConstants.h"
22+
#include "Steer/MCKinematicsReader.h"
23+
24+
#include "Framework/Logger.h"
25+
26+
namespace o2::its
27+
{
28+
29+
static o2::utils::TreeStreamRedirector* gDBG{nullptr};
30+
static o2::steer::MCKinematicsReader* gMCReader{nullptr};
31+
32+
template <int NLayers>
33+
void TrackerTraitsMC<NLayers>::computeLayerTracklets(const int iteration, int iVertex)
34+
{
35+
if (!gDBG) {
36+
gDBG = new o2::utils::TreeStreamRedirector("its_tune.root");
37+
}
38+
if (!gMCReader) {
39+
gMCReader = new o2::steer::MCKinematicsReader("collisioncontext.root");
40+
}
41+
42+
// Create all tracklets we find in this iteration and dump them.
43+
const std::string treeName = std::format("trklt_{}", iteration);
44+
TrackerTraits<NLayers>::computeLayerTracklets(iteration, iVertex);
45+
this->createTrackletMC();
46+
const auto topology = this->mTimeFrame->getTrackingTopologyView();
47+
for (int transitionId{0}; transitionId < topology.nTransitions; ++transitionId) {
48+
const auto& transition = topology.getTransition(transitionId);
49+
for (int iTrklt{0}; iTrklt < this->mTimeFrame->getTracklets()[transitionId].size(); ++iTrklt) {
50+
const auto& lbl = this->mTimeFrame->getTrackletsLabel(transitionId)[iTrklt];
51+
const auto trklt = this->mTimeFrame->getTracklets()[transitionId][iTrklt];
52+
const auto& firstCluster = this->mTimeFrame->getClusters()[transition.fromLayer][trklt.firstClusterIndex];
53+
const auto& secondCluster = this->mTimeFrame->getClusters()[transition.toLayer][trklt.secondClusterIndex];
54+
const float deltaPhi = std::abs(firstCluster.phi - secondCluster.phi);
55+
TrackletMC trkltMC{
56+
.tgl = trklt.tanLambda,
57+
.phi = trklt.phi,
58+
.rIn = firstCluster.radius,
59+
.zIn = firstCluster.zCoordinate,
60+
.phiIn = firstCluster.phi,
61+
.rOut = secondCluster.radius,
62+
.zOut = secondCluster.zCoordinate,
63+
.phiOut = secondCluster.phi,
64+
.dr = secondCluster.radius - firstCluster.radius,
65+
.dz = secondCluster.zCoordinate - firstCluster.zCoordinate,
66+
.dPhi = std::min(deltaPhi, static_cast<float>(o2::constants::math::TwoPI) - deltaPhi),
67+
.ok = lbl.isValid(),
68+
};
69+
float dcaXY = std::numeric_limits<float>::max(), dcaZ = std::numeric_limits<float>::max();
70+
if (lbl.isValid()) {
71+
const auto& eve = gMCReader->getMCEventHeader(lbl.getSourceID(), lbl.getEventID());
72+
const float dx = secondCluster.xCoordinate - firstCluster.xCoordinate;
73+
const float dy = secondCluster.yCoordinate - firstCluster.yCoordinate;
74+
const float dz = secondCluster.zCoordinate - firstCluster.zCoordinate;
75+
trkltMC.tglEvent = (firstCluster.zCoordinate - eve.GetZ()) / firstCluster.radius;
76+
trkltMC.deltaZEvent = std::abs((trkltMC.tglEvent * (secondCluster.radius - firstCluster.radius)) + firstCluster.zCoordinate - secondCluster.zCoordinate);
77+
const float dxy2 = math_utils::hypot(dx, dy);
78+
if (dxy2 > constants::Tolerance) {
79+
const float t = ((eve.GetX() - firstCluster.xCoordinate) * dx + (eve.GetY() - firstCluster.yCoordinate) * dy) / dxy2;
80+
const float xAtDCA = firstCluster.xCoordinate + t * dx;
81+
const float yAtDCA = firstCluster.yCoordinate + t * dy;
82+
const float zAtDCA = firstCluster.zCoordinate + t * dz;
83+
const float curDCAx = xAtDCA - eve.GetX();
84+
const float curDCAy = yAtDCA - eve.GetY();
85+
dcaXY = math_utils::hypot(curDCAx, curDCAy);
86+
dcaZ = zAtDCA - eve.GetZ();
87+
trkltMC.dXY = dcaXY;
88+
trkltMC.dZ = dcaZ;
89+
}
90+
const auto* mcTrk = gMCReader->getTrack(lbl);
91+
if (mcTrk) {
92+
trkltMC.prim = mcTrk->isPrimary();
93+
}
94+
}
95+
(*gDBG) << treeName.c_str()
96+
<< "from=" << transition.fromLayer
97+
<< "to=" << transition.toLayer
98+
<< "trklt=" << trkltMC
99+
<< "\n";
100+
}
101+
}
102+
}
103+
104+
template <int NLayers>
105+
void TrackerTraitsMC<NLayers>::computeLayerCells(const int iteration)
106+
{
107+
TrackerTraits<NLayers>::computeLayerCells(iteration);
108+
}
109+
110+
template <int NLayers>
111+
void TrackerTraitsMC<NLayers>::findCellsNeighbours(const int iteration)
112+
{
113+
TrackerTraits<NLayers>::findCellsNeighbours(iteration);
114+
}
115+
116+
template <int NLayers>
117+
void TrackerTraitsMC<NLayers>::findRoads(const int iteration)
118+
{
119+
TrackerTraits<NLayers>::findRoads(iteration);
120+
121+
if (this->mTrkParams.size() - 1 == iteration) {
122+
gDBG->Close();
123+
}
124+
}
125+
126+
template class TrackerTraitsMC<7>;
127+
128+
} // namespace o2::its

Detectors/ITSMFT/ITS/tracking/src/TrackingLinkDef.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::its::Tracklet + ;
1919
#pragma link C++ class std::vector < o2::its::Tracklet> + ;
2020

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

0 commit comments

Comments
 (0)