Skip to content

Commit 0906169

Browse files
committed
ITS: add tracklet tuning
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 70f2477 commit 0906169

8 files changed

Lines changed: 564 additions & 24 deletions

File tree

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

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

Detectors/ITSMFT/ITS/tracking/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ o2_add_library(ITStracking
2525
src/TrackingConfigParam.cxx
2626
src/Vertexer.cxx
2727
src/VertexerTraits.cxx
28+
src/TuneExt.cxx
2829
PUBLIC_LINK_LIBRARIES
2930
O2::GPUCommon
3031
Microsoft.GSL::GSL
@@ -56,6 +57,7 @@ o2_target_root_dictionary(ITStracking
5657
include/ITStracking/Definitions.h
5758
include/ITStracking/FastMultEstConfig.h
5859
include/ITStracking/TrackingConfigParam.h
60+
include/ITStracking/TuneExt.h
5961
LINKDEF src/TrackingLinkDef.h)
6062

6163
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
bool ok{false}; // truth
24+
/// below only metrics valid if ok
25+
bool prim{false}; // primary
26+
float dXY{constants::UnsetValue}; // transverse distance to event
27+
float dZ{constants::UnsetValue}; // longitudinal distance to event
28+
ClassDefNV(TrackletMC, 1);
29+
};
30+
31+
} // 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
{

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,81 @@
1010
// or submit itself to any jurisdiction.
1111
///
1212

13+
#include <format>
14+
#include <cmath>
15+
#include <limits>
16+
1317
#include "ITStracking/TrackerTraitsMC.h"
18+
#include "ITStracking/TuneExt.h"
19+
#include "CommonUtils/TreeStreamRedirector.h"
20+
#include "Steer/MCKinematicsReader.h"
1421

1522
#include "Framework/Logger.h"
1623

1724
namespace o2::its
1825
{
1926

27+
static o2::utils::TreeStreamRedirector* gDBG{nullptr};
28+
static o2::steer::MCKinematicsReader* gMCReader{nullptr};
29+
2030
template <int NLayers>
2131
void TrackerTraitsMC<NLayers>::computeLayerTracklets(const int iteration, int iVertex)
2232
{
33+
if (!gDBG) {
34+
gDBG = new o2::utils::TreeStreamRedirector("its_tune.root");
35+
}
36+
if (!gMCReader) {
37+
gMCReader = new o2::steer::MCKinematicsReader("collisioncontext.root");
38+
}
39+
40+
// Create all tracklets we find in this iteration and dump them.
41+
const std::string treeName = std::format("trklt_{}", iteration);
2342
TrackerTraits<NLayers>::computeLayerTracklets(iteration, iVertex);
43+
this->createTrackletMC();
44+
const auto topology = this->mTimeFrame->getTrackingTopologyView();
45+
for (int transitionId{0}; transitionId < topology.nTransitions; ++transitionId) {
46+
const auto& transition = topology.getTransition(transitionId);
47+
for (int iTrklt{0}; iTrklt < this->mTimeFrame->getTracklets()[transitionId].size(); ++iTrklt) {
48+
const auto& lbl = this->mTimeFrame->getTrackletsLabel(transitionId)[iTrklt];
49+
const auto trklt = this->mTimeFrame->getTracklets()[transitionId][iTrklt];
50+
TrackletMC trkltMC{
51+
.tgl = trklt.tanLambda,
52+
.phi = trklt.phi,
53+
.ok = lbl.isValid(),
54+
};
55+
float dcaXY = std::numeric_limits<float>::max(), dcaZ = std::numeric_limits<float>::max();
56+
if (lbl.isValid()) {
57+
const auto& eve = gMCReader->getMCEventHeader(lbl.getSourceID(), lbl.getEventID());
58+
const auto& firstCluster = this->mTimeFrame->getClusters()[transition.fromLayer][trklt.firstClusterIndex];
59+
const auto& secondCluster = this->mTimeFrame->getClusters()[transition.toLayer][trklt.secondClusterIndex];
60+
const float dx = secondCluster.xCoordinate - firstCluster.xCoordinate;
61+
const float dy = secondCluster.yCoordinate - firstCluster.yCoordinate;
62+
const float dz = secondCluster.zCoordinate - firstCluster.zCoordinate;
63+
const float dxy2 = math_utils::hypot(dx, dy);
64+
if (dxy2 > constants::Tolerance) {
65+
const float t = ((eve.GetX() - firstCluster.xCoordinate) * dx + (eve.GetY() - firstCluster.yCoordinate) * dy) / dxy2;
66+
const float xAtDCA = firstCluster.xCoordinate + t * dx;
67+
const float yAtDCA = firstCluster.yCoordinate + t * dy;
68+
const float zAtDCA = firstCluster.zCoordinate + t * dz;
69+
const float curDCAx = xAtDCA - eve.GetX();
70+
const float curDCAy = yAtDCA - eve.GetY();
71+
dcaXY = math_utils::hypot(curDCAx, curDCAy);
72+
dcaZ = zAtDCA - eve.GetZ();
73+
trkltMC.dXY = dcaXY;
74+
trkltMC.dZ = dcaZ;
75+
}
76+
const auto* mcTrk = gMCReader->getTrack(lbl);
77+
if (mcTrk) {
78+
trkltMC.prim = mcTrk->isPrimary();
79+
}
80+
}
81+
(*gDBG) << treeName.c_str()
82+
<< "from=" << transition.fromLayer
83+
<< "to=" << transition.toLayer
84+
<< "trklt=" << trkltMC
85+
<< "\n";
86+
}
87+
}
2488
}
2589

2690
template <int NLayers>
@@ -39,6 +103,10 @@ template <int NLayers>
39103
void TrackerTraitsMC<NLayers>::findRoads(const int iteration)
40104
{
41105
TrackerTraits<NLayers>::findRoads(iteration);
106+
107+
if (this->mTrkParams.size() - 1 == iteration) {
108+
gDBG->Close();
109+
}
42110
}
43111

44112
template class TrackerTraitsMC<7>;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 "ITStracking/TuneExt.h"
13+
ClassImp(o2::its::TrackletMC);

0 commit comments

Comments
 (0)