Skip to content

Commit 5c2c20b

Browse files
shahor02sawenzel
authored andcommitted
Use new aggregated container/global index in vertexing
1 parent 2182f53 commit 5c2c20b

7 files changed

Lines changed: 42 additions & 120 deletions

File tree

DataFormats/Reconstruction/include/ReconstructionDataFormats/VtxTrackIndex.h

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
// or submit itself to any jurisdiction.
1010

1111
/// @file VtxTrackIndex.h
12-
/// \brief Index of track attached to vertx: index in its proper container, container source and flags
12+
/// \brief Extention of GlobalTrackID by flags relevant for verter-track association
1313
/// \author ruben.shahoyan@cern.ch
1414

1515
#ifndef O2_VERTEX_TRACK_INDEX
1616
#define O2_VERTEX_TRACK_INDEX
1717

18-
#include "CommonDataFormat/AbstractRef.h"
18+
#include "ReconstructionDataFormats/GlobalTrackID.h"
1919
#include <iosfwd>
2020
#include <string>
2121
#include <array>
@@ -26,46 +26,27 @@ namespace o2
2626
namespace dataformats
2727
{
2828

29-
class VtxTrackIndex : public AbstractRef<26, 3, 3>
29+
class VtxTrackIndex : public GlobalTrackID
3030
{
3131
public:
32-
enum Source : uint8_t { // provenance of the track
33-
TPCITS,
34-
ITS,
35-
TPC,
36-
NSources
37-
};
38-
static constexpr std::array<std::string_view, NSources> SourceNames = {
39-
"TPCITS",
40-
"ITS",
41-
"TPC"};
42-
4332
enum Flags : uint8_t {
4433
Contributor, // flag that it contributes to vertex fit
4534
Reserved, //
4635
Ambiguous, // flag that attachment is ambiguous
4736
NFlags
4837
};
4938

50-
using AbstractRef<26, 3, 3>::AbstractRef;
51-
52-
static constexpr std::string_view getSourceName(int i) { return SourceNames[i]; }
53-
void print() const;
54-
std::string asString() const;
55-
56-
operator auto() const { return AbstractRef<26, 3, 3>(); }
39+
using GlobalTrackID::GlobalTrackID;
5740

5841
bool isPVContributor() const { return testBit(Contributor); }
5942
void setPVContributor() { setBit(Contributor); }
6043

6144
bool isAmbiguous() const { return testBit(Ambiguous); }
6245
void setAmbiguous() { setBit(Ambiguous); }
6346

64-
ClassDefNV(VtxTrackIndex, 1);
47+
ClassDefNV(VtxTrackIndex, 2);
6548
};
6649

67-
std::ostream& operator<<(std::ostream& os, const o2::dataformats::VtxTrackIndex& v);
68-
6950
} // namespace dataformats
7051
} // namespace o2
7152

DataFormats/Reconstruction/src/VtxTrackIndex.cxx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// or submit itself to any jurisdiction.
1010

1111
/// @file VtxTrackIndex.h
12-
/// \brief Index of track attached to vertx: index in its proper container, container source and flags
12+
/// \brief Extention of GlobalTrackID by flags relevant for verter-track association
1313
/// \author ruben.shahoyan@cern.ch
1414

1515
#include "ReconstructionDataFormats/VtxTrackIndex.h"
@@ -19,21 +19,3 @@
1919
#include <bitset>
2020

2121
using namespace o2::dataformats;
22-
23-
std::string VtxTrackIndex::asString() const
24-
{
25-
std::bitset<NBitsFlags()> bits{getFlags()};
26-
return fmt::format("[{:d}/{:d}/{:s}]", getIndex(), getSource(), bits.to_string());
27-
}
28-
29-
std::ostream& o2::dataformats::operator<<(std::ostream& os, const o2::dataformats::VtxTrackIndex& v)
30-
{
31-
// stream itself
32-
os << v.asString();
33-
return os;
34-
}
35-
36-
void VtxTrackIndex::print() const
37-
{
38-
LOG(INFO) << asString();
39-
}

Detectors/GlobalTrackingWorkflow/src/SecondaryVertexingSpec.cxx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
/// @file SecondaryVertexingSpec.cxx
1212

1313
#include <vector>
14+
#include "ReconstructionDataFormats/GlobalTrackAccessor.h"
1415
#include "ReconstructionDataFormats/TrackTPCITS.h"
16+
#include "DataFormatsTPC/TrackTPC.h"
17+
#include "DataFormatsITS/TrackITS.h"
1518
#include "DetectorsBase/Propagator.h"
1619
#include "DetectorsBase/GeometryManager.h"
1720
#include "GlobalTrackingWorkflow/SecondaryVertexingSpec.h"
@@ -27,9 +30,6 @@ using GIndex = o2::dataformats::VtxTrackIndex;
2730
using VRef = o2::dataformats::VtxTrackRef;
2831
using PVertex = const o2::dataformats::PrimaryVertex;
2932
using V0 = o2::dataformats::V0;
30-
using TrackTPCITS = o2::dataformats::TrackTPCITS;
31-
using TrackITS = o2::its::TrackITS;
32-
using TrackTPC = o2::tpc::TrackTPC;
3333
using RRef = o2::dataformats::RangeReference<int, int>;
3434

3535
namespace o2
@@ -74,9 +74,12 @@ void SecondaryVertexingSpec::run(ProcessingContext& pc)
7474
std::vector<V0> v0s;
7575
std::vector<RRef> pv2v0ref;
7676

77-
mVertexer.process(pvertices, pvtxTracks, pvtxTrackRefs,
78-
tracksITSTPC, tracksITS, tracksTPC,
79-
v0s, pv2v0ref);
77+
o2::dataformats::GlobalTrackAccessor tracksPool;
78+
tracksPool.registerContainer(tracksITSTPC, GIndex::ITSTPC);
79+
tracksPool.registerContainer(tracksITS, GIndex::ITS);
80+
tracksPool.registerContainer(tracksTPC, GIndex::TPC);
81+
82+
mVertexer.process(pvertices, pvtxTracks, pvtxTrackRefs, tracksPool, v0s, pv2v0ref);
8083

8184
pc.outputs().snapshot(Output{"GLO", "V0s", 0, Lifetime::Timeframe}, v0s);
8285
pc.outputs().snapshot(Output{"GLO", "PVTX_V0REFS", 0, Lifetime::Timeframe}, pv2v0ref);

Detectors/Vertexing/include/DetectorsVertexing/SVertexer.h

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
#define O2_S_VERTEXER_H
1616

1717
#include "gsl/span"
18+
#include "ReconstructionDataFormats/GlobalTrackAccessor.h"
1819
#include "ReconstructionDataFormats/PrimaryVertex.h"
1920
#include "ReconstructionDataFormats/V0.h"
2021
#include "ReconstructionDataFormats/VtxTrackIndex.h"
2122
#include "ReconstructionDataFormats/VtxTrackRef.h"
22-
#include "ReconstructionDataFormats/TrackTPCITS.h"
23-
#include "DataFormatsTPC/TrackTPC.h"
24-
#include "DataFormatsITS/TrackITS.h"
2523
#include "CommonDataFormat/RangeReference.h"
2624
#include "DetectorsVertexing/DCAFitterN.h"
2725
#include "DetectorsVertexing/SVertexerParams.h"
@@ -41,57 +39,13 @@ class SVertexer
4139
using VRef = o2::dataformats::VtxTrackRef;
4240
using PVertex = const o2::dataformats::PrimaryVertex;
4341
using V0 = o2::dataformats::V0;
44-
using TrackTPCITS = o2::dataformats::TrackTPCITS;
45-
using TrackITS = o2::its::TrackITS;
46-
using TrackTPC = o2::tpc::TrackTPC;
4742
using RRef = o2::dataformats::RangeReference<int, int>;
4843

49-
// struct to access tracks and extra info from different sources
50-
struct TrackAccessor {
51-
static constexpr std::array<size_t, GIndex::NSources> sizes{sizeof(TrackTPCITS), sizeof(TrackITS), sizeof(TrackTPC)};
52-
std::array<const char*, GIndex::NSources> startOfSource{};
53-
std::array<std::vector<char>, GIndex::NSources> charges;
54-
55-
TrackAccessor(const gsl::span<const TrackTPCITS>& tpcits, const gsl::span<const TrackITS>& its, const gsl::span<const TrackTPC>& tpc)
56-
{
57-
if (tpcits.size()) {
58-
startOfSource[GIndex::TPCITS] = reinterpret_cast<const char*>(tpcits.data());
59-
auto& ch = charges[GIndex::TPCITS];
60-
ch.resize(tpcits.size());
61-
for (uint32_t ic = 0; ic < tpcits.size(); ic++) {
62-
ch[ic] = tpcits[ic].getCharge();
63-
}
64-
}
65-
if (its.size()) {
66-
startOfSource[GIndex::ITS] = reinterpret_cast<const char*>(its.data());
67-
auto& ch = charges[GIndex::ITS];
68-
ch.resize(its.size());
69-
for (uint32_t ic = 0; ic < its.size(); ic++) {
70-
ch[ic] = its[ic].getCharge();
71-
}
72-
}
73-
if (tpc.size()) {
74-
startOfSource[GIndex::TPC] = reinterpret_cast<const char*>(tpc.data());
75-
auto& ch = charges[GIndex::TPC];
76-
ch.resize(tpc.size());
77-
for (uint32_t ic = 0; ic < tpc.size(); ic++) {
78-
ch[ic] = tpc[ic].getCharge();
79-
}
80-
}
81-
}
82-
char getCharge(GIndex id) const { return getCharge(id.getSource(), id.getIndex()); }
83-
char getCharge(int src, int idx) const { return charges[src][idx]; }
84-
const o2::track::TrackParCov& getTrack(GIndex id) const { return getTrack(id.getSource(), id.getIndex()); }
85-
const o2::track::TrackParCov& getTrack(int src, int idx) const { return *reinterpret_cast<const o2::track::TrackParCov*>(startOfSource[src] + sizes[src] * idx); }
86-
};
87-
8844
void init();
8945
void process(const gsl::span<const PVertex>& vertices, // primary vertices
9046
const gsl::span<const GIndex>& trackIndex, // Global ID's for associated tracks
9147
const gsl::span<const VRef>& vtxRefs, // references from vertex to these track IDs
92-
const gsl::span<const TrackTPCITS>& tpcits, // global tracks
93-
const gsl::span<const TrackITS>& its, // ITS tracks
94-
const gsl::span<const TrackTPC>& tpc, // TPC tracks
48+
const o2d::GlobalTrackAccessor& tracksPool, // accessor to various tracks
9549
std::vector<V0>& v0s, // found V0s
9650
std::vector<RRef>& vtx2V0refs // references from PVertex to V0
9751
);

Detectors/Vertexing/src/PVertexer.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int PVertexer::process(gsl::span<const o2d::TrackTPCITS> tracksITSTPC, gsl::span
8787
vertices.push_back(vtx);
8888
int it = v2tRefsLoc[i].getFirstEntry(), itEnd = it + v2tRefsLoc[i].getEntries(), dest0 = vertexTrackIDs.size();
8989
for (; it < itEnd; it++) {
90-
auto& gid = vertexTrackIDs.emplace_back(vertexTrackIDsLoc[it], GIndex::TPCITS);
90+
auto& gid = vertexTrackIDs.emplace_back(vertexTrackIDsLoc[it], GIndex::ITSTPC);
9191
gid.setPVContributor();
9292
}
9393
v2tRefs.emplace_back(dest0, v2tRefsLoc[i].getEntries());

Detectors/Vertexing/src/SVertexer.cxx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414

1515
#include "DetectorsVertexing/SVertexer.h"
1616
#include "DetectorsBase/Propagator.h"
17+
#include "ReconstructionDataFormats/TrackTPCITS.h"
18+
#include "DataFormatsTPC/TrackTPC.h"
19+
#include "DataFormatsITS/TrackITS.h"
1720

1821
using namespace o2::vertexing;
1922

2023
using PID = o2::track::PID;
24+
using TrackTPCITS = o2::dataformats::TrackTPCITS;
25+
using TrackITS = o2::its::TrackITS;
26+
using TrackTPC = o2::tpc::TrackTPC;
2127

2228
void SVertexer::init()
2329
{
@@ -51,9 +57,7 @@ void SVertexer::init()
5157
void SVertexer::process(const gsl::span<const PVertex>& vertices, // primary vertices
5258
const gsl::span<const GIndex>& trackIndex, // Global ID's for associated tracks
5359
const gsl::span<const VRef>& vtxRefs, // references from vertex to these track IDs
54-
const gsl::span<const TrackTPCITS>& tpcits, // global tracks
55-
const gsl::span<const TrackITS>& its, // ITS tracks
56-
const gsl::span<const TrackTPC>& tpc, // TPC tracks
60+
const o2d::GlobalTrackAccessor& tracksPool, // accessor to various tracks
5761
std::vector<V0>& v0s, // found V0s
5862
std::vector<RRef>& vtx2V0refs // references from PVertex to V0
5963
)
@@ -62,17 +66,17 @@ void SVertexer::process(const gsl::span<const PVertex>& vertices, // primary v
6266
std::vector<V0> v0sTmp(1); // 1st one is dummy!
6367
std::vector<int> v0sIdx; // id's in v0sTmp used attached to p.vertices
6468
std::vector<RRef> pv2v0sRefs; // p.vertex to v0 index references
69+
std::vector<char> selQ(trackIndex.size(), 0);
6570

66-
TrackAccessor tracksPool(tpcits, its, tpc);
67-
68-
auto rejectTrack = [&tracksPool](GIndex id, char wantCharge) {
69-
if (id.isPVContributor()) {
70-
return true;
71-
}
72-
auto s = id.getSource();
73-
return (s != GIndex::TPCITS && s != GIndex::ITS) || tracksPool.getCharge(id) != wantCharge;
71+
auto selTrack = [&tracksPool, &trackIndex](int i) -> char {
72+
auto id = trackIndex[i];
73+
return id.isPVContributor() || (id.getSource() != GIndex::ITSTPC && id.getSource() != GIndex::ITS) ? 0 : tracksPool.get(id).getCharge();
7474
};
7575

76+
for (size_t i = 0; i < trackIndex.size(); i++) {
77+
selQ[i] = selTrack(i);
78+
}
79+
7680
int nv = vertices.size();
7781
size_t countTot = 0, countTotUnique = 0;
7882
for (int iv = 0; iv < nv; iv++) {
@@ -85,25 +89,23 @@ void SVertexer::process(const gsl::span<const PVertex>& vertices, // primary v
8589
}
8690
//
8791
const auto& vtref = vtxRefs[iv];
88-
//LOG(INFO) << "P.Vertex " << iv << pv;
89-
//LOG(INFO) << "P.V. -> tracks " << vtref;
9092
//
9193
int first = vtref.getFirstEntry();
9294
int last = first + vtref.getEntries();
9395
size_t count = 0, countUnique = 0;
9496
for (int ipos = first; ipos < last; ipos++) {
95-
auto idpos = trackIndex[ipos];
96-
if (rejectTrack(idpos, 1)) { // skip at the moment TPC only tracks
97+
if (selQ[ipos] != 1) {
9798
continue;
9899
}
100+
auto idpos = trackIndex[ipos];
99101
bool ambiguousPos = idpos.isAmbiguous(); // is this track compatible also with other vertex?
100-
const auto& trPos = tracksPool.getTrack(idpos);
102+
const auto& trPos = tracksPool.get(idpos);
101103

102104
for (int ineg = first; ineg < last; ineg++) {
103-
auto idneg = trackIndex[ineg];
104-
if (rejectTrack(idneg, -1)) { // skip at the moment TPC only tracks
105+
if (selQ[ineg] != -1) {
105106
continue;
106107
}
108+
auto idneg = trackIndex[ineg];
107109
count++;
108110
bool accept = false, newPair = true, ambiguousV0 = ambiguousPos && idneg.isAmbiguous(); // V0 is ambiguous if both tracks are compatible with other vertices
109111
uint64_t idPosNeg = getPairIdx(idpos, idneg);
@@ -120,7 +122,7 @@ void SVertexer::process(const gsl::span<const PVertex>& vertices, // primary v
120122
}
121123
}
122124
if (newPair) {
123-
auto trNeg = tracksPool.getTrack(idneg);
125+
auto trNeg = tracksPool.get(idneg);
124126
// LOG(INFO) << "0: " << idpos << " " << tr0.o2::track::TrackPar::asString();
125127
// LOG(INFO) << "1: " << idneg << " " << tr1.o2::track::TrackPar::asString();
126128
int nCand = mFitter2Prong.process(trPos, trNeg);

Detectors/Vertexing/src/VertexTrackMatcher.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void VertexTrackMatcher::process(const gsl::span<const PVertex>& vertices,
9999
memset(idTPC.data(), 0, sizeof(int) * idTPC.size());
100100
memset(flgITS.data(), 0, sizeof(int) * flgITS.size());
101101
std::array<std::vector<int>*, GIndex::NSources> vptr;
102-
vptr[GIndex::TPCITS] = &idTPCITS;
102+
vptr[GIndex::ITSTPC] = &idTPCITS;
103103
vptr[GIndex::ITS] = &flgITS;
104104
vptr[GIndex::TPC] = &idTPC;
105105
int nv = vertices.size();
@@ -114,7 +114,7 @@ void VertexTrackMatcher::process(const gsl::span<const PVertex>& vertices,
114114
for (int iv = 0; iv < nv; iv++) {
115115
int srcStart[GIndex::NSources + 1];
116116
int entry = trackIndex.size();
117-
srcStart[GIndex::TPCITS] = entry;
117+
srcStart[GIndex::ITSTPC] = entry;
118118
for (int is = 1; is < GIndex::NSources; is++) {
119119
srcStart[is] = -1;
120120
}
@@ -179,7 +179,7 @@ void VertexTrackMatcher::attachTPCITS(TmpMap& tmpMap, const gsl::span<const Trac
179179
} else if (trcT.getTimeStamp() > maxTime) {
180180
break;
181181
} else if (compatibleTimes(vtxT, trcT)) {
182-
tmpMap[ivtCurr].emplace_back(idTPCITS[itr], GIndex::TPCITS);
182+
tmpMap[ivtCurr].emplace_back(idTPCITS[itr], GIndex::ITSTPC);
183183
}
184184
itr++;
185185
}

0 commit comments

Comments
 (0)