Skip to content

Commit 439fcfa

Browse files
committed
Proper track sampling for residuals extraction
1 parent be9daac commit 439fcfa

3 files changed

Lines changed: 36 additions & 15 deletions

File tree

Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCInterpolationSpec.cxx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/// @file TPCInterpolationSpec.cxx
1313

1414
#include <vector>
15+
#include <unordered_map>
1516

1617
#include "DataFormatsITS/TrackITS.h"
1718
#include "ReconstructionDataFormats/TrackTPCITS.h"
@@ -101,9 +102,16 @@ void TPCInterpolationDPL::run(ProcessingContext& pc)
101102
std::vector<o2::track::TrackParCov> seeds;
102103
std::vector<float> trkTimes;
103104
std::vector<GTrackID> gids;
105+
std::unordered_map<int, int> trkCounters;
106+
// make sure the map has entries for every possible track input type
107+
trkCounters.insert(std::make_pair<int, int>(GTrackID::Source::ITSTPCTRDTOF, 0));
108+
trkCounters.insert(std::make_pair<int, int>(GTrackID::Source::ITSTPCTRD, 0));
109+
trkCounters.insert(std::make_pair<int, int>(GTrackID::Source::ITSTPCTOF, 0));
110+
trkCounters.insert(std::make_pair<int, int>(GTrackID::Source::ITSTPC, 0));
111+
104112
bool processITSTPConly = mProcessITSTPConly; // so that the flag can be used inside the lambda
105113
// the creator goes from most complete track (ITS-TPC-TRD-TOF) to least complete one (ITS-TPC)
106-
auto creator = [&gidTables, &seeds, &trkTimes, &recoData, &processITSTPConly, &gids, &param](auto& _tr, GTrackID _origID, float t0, float tErr) {
114+
auto creator = [&gidTables, &seeds, &trkTimes, &recoData, &processITSTPConly, &gids, &param, &trkCounters](auto& _tr, GTrackID _origID, float t0, float tErr) {
107115
if constexpr (std::is_base_of_v<o2::track::TrackParCov, std::decay_t<decltype(_tr)>>) {
108116
bool trackGood = true;
109117
bool hasOuterPoint = false;
@@ -141,6 +149,7 @@ void TPCInterpolationDPL::run(ProcessingContext& pc)
141149
seeds.emplace_back(itsTrk->getParamOut()); // FIXME: should this not be a refit of the ITS track?
142150
gidTables.emplace_back(gidTable);
143151
gids.push_back(_origID);
152+
trkCounters[_origID.getSource()] += 1;
144153
}
145154
return true;
146155
} else {
@@ -155,7 +164,7 @@ void TPCInterpolationDPL::run(ProcessingContext& pc)
155164
// not yet implemented
156165
}
157166

158-
mInterpolation.process(recoData, gids, gidTables, seeds, trkTimes);
167+
mInterpolation.process(recoData, gids, gidTables, seeds, trkTimes, trkCounters);
159168
mTimer.Stop();
160169
LOGF(info, "TPC interpolation timing: Cpu: %.3e Real: %.3e s", mTimer.CpuTime(), mTimer.RealTime());
161170

Detectors/TPC/calibration/SpacePoints/include/SpacePoints/TrackInterpolation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class TrackInterpolation
173173
void init();
174174

175175
/// Main processing function
176-
void process(const o2::globaltracking::RecoContainer& inp, const std::vector<o2::dataformats::GlobalTrackID>& gids, const std::vector<o2::globaltracking::RecoContainer::GlobalIDSet>& gidTables, std::vector<o2::track::TrackParCov>& seeds, const std::vector<float>& trkTimes);
176+
void process(const o2::globaltracking::RecoContainer& inp, const std::vector<o2::dataformats::GlobalTrackID>& gids, const std::vector<o2::globaltracking::RecoContainer::GlobalIDSet>& gidTables, std::vector<o2::track::TrackParCov>& seeds, const std::vector<float>& trkTimes, const std::unordered_map<int, int>& trkCounters);
177177

178178
/// Extrapolate ITS-only track through TPC and store residuals to TPC clusters along the way
179179
/// \param seed index

Detectors/TPC/calibration/SpacePoints/src/TrackInterpolation.cxx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "DataFormatsTPC/VDriftCorrFact.h"
2828
#include <fairlogger/Logger.h>
2929
#include <set>
30+
#include <algorithm>
31+
#include <random>
3032

3133
using namespace o2::tpc;
3234
using GTrackID = o2::dataformats::GlobalTrackID;
@@ -55,7 +57,7 @@ void TrackInterpolation::init()
5557
LOG(info) << "Done initializing TrackInterpolation";
5658
}
5759

58-
void TrackInterpolation::process(const o2::globaltracking::RecoContainer& inp, const std::vector<GTrackID>& gids, const std::vector<o2::globaltracking::RecoContainer::GlobalIDSet>& gidTables, std::vector<o2::track::TrackParCov>& seeds, const std::vector<float>& trkTimes)
60+
void TrackInterpolation::process(const o2::globaltracking::RecoContainer& inp, const std::vector<GTrackID>& gids, const std::vector<o2::globaltracking::RecoContainer::GlobalIDSet>& gidTables, std::vector<o2::track::TrackParCov>& seeds, const std::vector<float>& trkTimes, const std::unordered_map<int, int>& trkCounters)
5961
{
6062
// main processing function
6163

@@ -80,11 +82,29 @@ void TrackInterpolation::process(const o2::globaltracking::RecoContainer& inp, c
8082
mTrackData.reserve(nSeeds);
8183
mClRes.reserve(nSeeds * param::NPadRows);
8284

85+
// In case we have more input tracks available than are required per TF
86+
// we want to sample them. But we still prefer global ITS-TPC-TRD-TOF tracks
87+
// over ITS-TPC-TRD tracks and so on. So we have to shuffle the indices
88+
// in blocks.
89+
// The input GIDs are sorted. ITS-TPC-TRD-TOF are first followed by ITS-TPC-TRD,
90+
// ITS-TPC-TOF and ITS-TPC
91+
std::random_device rd;
92+
std::mt19937 g(rd());
93+
std::vector<int> trackIndices(nSeeds);
94+
std::iota(trackIndices.begin(), trackIndices.end(), 0);
95+
std::shuffle(trackIndices.begin(), trackIndices.begin() + trkCounters.at(GTrackID::Source::ITSTPCTRDTOF), g);
96+
int nTracks = trkCounters.at(GTrackID::Source::ITSTPCTRDTOF);
97+
std::shuffle(trackIndices.begin() + nTracks, trackIndices.begin() + nTracks + trkCounters.at(GTrackID::Source::ITSTPCTRD), g);
98+
nTracks += trkCounters.at(GTrackID::Source::ITSTPCTRD);
99+
std::shuffle(trackIndices.begin() + nTracks, trackIndices.begin() + nTracks + trkCounters.at(GTrackID::Source::ITSTPCTOF), g);
100+
nTracks += trkCounters.at(GTrackID::Source::ITSTPCTOF);
101+
std::shuffle(trackIndices.begin() + nTracks, trackIndices.begin() + nTracks + trkCounters.at(GTrackID::Source::ITSTPC), g);
102+
83103
for (int iSeed = 0; iSeed < nSeeds; ++iSeed) {
84-
if (gids[iSeed].includesDet(DetID::TRD) || gids[iSeed].includesDet(DetID::TOF)) {
85-
interpolateTrack(iSeed);
104+
if (gids[trackIndices[iSeed]].includesDet(DetID::TRD) || gids[trackIndices[iSeed]].includesDet(DetID::TOF)) {
105+
interpolateTrack(trackIndices[iSeed]);
86106
} else {
87-
extrapolateTrack(iSeed);
107+
extrapolateTrack(trackIndices[iSeed]);
88108
}
89109
if (mMaxTracksPerTF >= 0 && mTrackDataCompact.size() >= mMaxTracksPerTF) {
90110
LOG(info) << "Maximum number of tracks per TF reached. Skipping the remaining " << nSeeds - iSeed << " tracks.";
@@ -277,14 +297,6 @@ void TrackInterpolation::interpolateTrack(int iSeed)
277297
trackData.nTrkltsTRD = gidTable[GTrackID::TRD].isIndexSet() ? mRecoCont->getITSTPCTRDTrack<o2::trd::TrackTRD>(gidTable[GTrackID::ITSTPCTRD]).getNtracklets() : 0;
278298
trackData.clAvailTOF = gidTable[GTrackID::TOF].isIndexSet() ? 1 : 0;
279299

280-
/*
281-
// FIXME
282-
283-
Calculate number of tracks required per TF based on calibration slot length
284-
In case too many tracks available, use std::sample algorithm to take random sample of input tracks
285-
(make sure to use first most global tracks, then ITS-TPC-TRD, then ITS-TPC-TOF)
286-
*/
287-
288300
TrackParams params; // for refitted track parameters and flagging rejected clusters
289301
if (validateTrack(trackData, params, clusterResiduals)) {
290302
// track is good

0 commit comments

Comments
 (0)