Skip to content

Commit 3bc6c87

Browse files
authored
Restore table filled per track with vector of compatible collisions (#2346)
1 parent f4f4377 commit 3bc6c87

2 files changed

Lines changed: 63 additions & 13 deletions

File tree

Common/DataModel/CollisionAssociation.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ namespace o2::aod
2222

2323
namespace track_association
2424
{
25-
DECLARE_SOA_INDEX_COLUMN(Collision, collision); //! Collision index
26-
DECLARE_SOA_INDEX_COLUMN(Track, track); //! Track index
25+
DECLARE_SOA_INDEX_COLUMN(Collision, collision); //! Collision index
26+
DECLARE_SOA_INDEX_COLUMN(Track, track); //! Track index
27+
DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN(CompatibleColl, compatibleColl); //! Array of collision indices
2728
} // namespace track_association
2829

2930
DECLARE_SOA_TABLE(TrackAssoc, "AOD", "TRACKASSOC", //! Table for track-to-collision association for e.g. HF vertex finding - tracks can appear for several collisions
3031
track_association::CollisionId,
3132
track_association::TrackId);
33+
34+
DECLARE_SOA_TABLE(TrackCompColls, "AOD", "TRACKCOMPCOLLS", //! Table with vectors of collision indices stored per track
35+
track_association::CompatibleCollIds);
3236
} // namespace o2::aod
3337

3438
#endif // COMMON_DATAMODEL_COLLISIONASSOCIATION_H_

Common/TableProducer/trackToCollisionAssociator.cxx

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ using namespace o2::aod;
3030

3131
struct TrackToCollisionAssociation {
3232
Produces<TrackAssoc> association;
33+
Produces<TrackCompColls> reverseIndices;
3334

3435
Configurable<float> nSigmaForTimeCompat{"nSigmaForTimeCompat", 4.f, "number of sigmas for time compatibility"};
3536
Configurable<float> timeMargin{"timeMargin", 0.f, "time margin in ns added to uncertainty because of uncalibrated TPC"};
3637
Configurable<bool> applyMinimalTrackSelForRun2{"applyMinimalTrackSelForRun2", false, "flag to apply minimal track selection for Run 2 in case of standard association"};
3738
Configurable<bool> applyIsGlobalTrackWoDCA{"applyIsGlobalTrackWoDCA", true, "flag to apply global track w/o DCA selection"};
3839
Configurable<bool> usePVAssociation{"usePVAssociation", true, "if the track is a PV contributor, use the collision time for it"};
3940
Configurable<bool> includeUnassigned{"includeUnassigned", false, "consider also tracks which are not assigned to any collision"};
41+
Configurable<bool> fillTableOfCollIdsPerTrack{"fillTableOfCollIdsPerTrack", false, "fill additional table with vector of collision ids per track"};
4042

4143
Filter trackFilter = (applyIsGlobalTrackWoDCA == false) || requireGlobalTrackWoDCAInFilter();
4244
using TracksWithSel = soa::Join<Tracks, TracksExtra, TrackSelection>;
@@ -54,6 +56,7 @@ struct TrackToCollisionAssociation {
5456
}
5557

5658
void processAssocWithTime(Collisions const& collisions,
59+
TracksWithSel const& tracksUnfiltered,
5760
TracksWithSelFilter const& tracks,
5861
AmbiguousTracks const& ambiguousTracks,
5962
BCs const& bcs)
@@ -73,6 +76,9 @@ struct TrackToCollisionAssociation {
7376
}
7477
}
7578

79+
// define vector of vectors to store indices of compatible collisions per track
80+
std::vector<std::unique_ptr<std::vector<int>>> collsPerTrack(tracksUnfiltered.size());
81+
7682
// loop over collisions to find time-compatible tracks
7783
auto trackBegin = tracks.begin();
7884
constexpr auto bOffsetMax = 241; // 6 mus (ITS)
@@ -128,29 +134,69 @@ struct TrackToCollisionAssociation {
128134
const auto trackIdx = track.globalIndex();
129135
LOGP(debug, "Filling track id {} for coll id {}", trackIdx, collIdx);
130136
association(collIdx, trackIdx);
137+
if (fillTableOfCollIdsPerTrack) {
138+
if (collsPerTrack[trackIdx] == nullptr) {
139+
collsPerTrack[trackIdx] = std::make_unique<std::vector<int>>();
140+
}
141+
collsPerTrack[trackIdx].get()->push_back(collIdx);
142+
}
143+
}
144+
}
145+
}
146+
147+
// create reverse index track to collisions if enabled
148+
if (fillTableOfCollIdsPerTrack) {
149+
std::vector<int> empty{};
150+
for (const auto& track : tracksUnfiltered) {
151+
152+
const auto trackId = track.globalIndex();
153+
if (collsPerTrack[trackId] == nullptr) {
154+
reverseIndices(empty);
155+
} else {
156+
// for (const auto& collId : *collsPerTrack[trackId]) {
157+
// LOGP(info, " -> Coll id {}", collId);
158+
// }
159+
reverseIndices(*collsPerTrack[trackId].get());
131160
}
132161
}
133162
}
134163
}
135164

136165
PROCESS_SWITCH(TrackToCollisionAssociation, processAssocWithTime, "Use track-to-collision association based on time", false);
137166

138-
void processStandardAssoc(Collision const& collision,
139-
TracksWithSel const& tracksPerCollision)
167+
Preslice<TracksWithSel> tracksPerCollisions = aod::track::collisionId;
168+
169+
void processStandardAssoc(Collisions const& collisions,
170+
TracksWithSel const& tracks)
140171
{
141172
// we do it for all tracks, to be compatible with Run 2 analyses
142-
for (const auto& track : tracksPerCollision) {
143-
bool hasGoodQuality = true;
144-
if (applyIsGlobalTrackWoDCA && !track.isGlobalTrackWoDCA()) {
145-
hasGoodQuality = false;
146-
} else if (applyMinimalTrackSelForRun2) {
147-
unsigned char itsClusterMap = track.itsClusterMap();
148-
if (!(track.tpcNClsFound() >= 50 && track.flags() & o2::aod::track::ITSrefit && track.flags() & o2::aod::track::TPCrefit && (TESTBIT(itsClusterMap, 0) || TESTBIT(itsClusterMap, 1)))) {
173+
for (const auto& collision : collisions) {
174+
auto tracksThisCollision = tracks.sliceBy(tracksPerCollisions, collision.globalIndex());
175+
for (const auto& track : tracksThisCollision) {
176+
bool hasGoodQuality = true;
177+
if (applyIsGlobalTrackWoDCA && !track.isGlobalTrackWoDCA()) {
149178
hasGoodQuality = false;
179+
} else if (applyMinimalTrackSelForRun2) {
180+
unsigned char itsClusterMap = track.itsClusterMap();
181+
if (!(track.tpcNClsFound() >= 50 && track.flags() & o2::aod::track::ITSrefit && track.flags() & o2::aod::track::TPCrefit && (TESTBIT(itsClusterMap, 0) || TESTBIT(itsClusterMap, 1)))) {
182+
hasGoodQuality = false;
183+
}
184+
}
185+
if (hasGoodQuality) {
186+
association(collision.globalIndex(), track.globalIndex());
150187
}
151188
}
152-
if (hasGoodQuality) {
153-
association(collision.globalIndex(), track.globalIndex());
189+
}
190+
191+
// create reverse index track to collisions if enabled
192+
std::vector<int> empty{};
193+
if (fillTableOfCollIdsPerTrack) {
194+
for (const auto& track : tracks) {
195+
if (track.has_collision()) {
196+
reverseIndices(std::vector<int>{track.collisionId()});
197+
} else {
198+
reverseIndices(empty);
199+
}
154200
}
155201
}
156202
}

0 commit comments

Comments
 (0)