Skip to content

Commit 22b8799

Browse files
pillotaphecetche
authored andcommitted
speedup finding of used cluster combinations
1 parent e9d2649 commit 22b8799

2 files changed

Lines changed: 41 additions & 18 deletions

File tree

Detectors/MUON/MCH/Tracking/include/MCHTracking/TrackFinder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ class TrackFinder
9393
bool propagateCurrentParam(Track& track, int chamber);
9494

9595
bool areUsed(const Cluster& cl1, const Cluster& cl2, const std::vector<std::array<uint32_t, 4>>& usedClusters);
96-
void excludeClustersFromIdenticalTracks(const std::list<Track>::iterator& itTrack,
97-
std::unordered_map<int, std::unordered_set<uint32_t>>& excludedClusters,
98-
const std::list<Track>::iterator& itEndTrack);
96+
void excludeClustersFromIdenticalTracks(const std::array<uint32_t, 4>& currentClusters,
97+
const std::vector<std::array<uint32_t, 8>>& usedClusters,
98+
std::unordered_map<int, std::unordered_set<uint32_t>>& excludedClusters);
9999
void moveClusters(std::unordered_map<int, std::unordered_set<uint32_t>>& source, std::unordered_map<int, std::unordered_set<uint32_t>>& destination);
100100

101101
bool isCompatible(const TrackParam& param, const Cluster& cluster, TrackParam& paramAtCluster);

Detectors/MUON/MCH/Tracking/src/TrackFinder.cxx

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ void TrackFinder::findTrackCandidates()
257257
}
258258
}
259259

260+
// list the cluster combinations already used in stations 4 and 5
261+
std::vector<std::array<uint32_t, 8>> usedClusters(mTracks.size());
262+
int iTrack(0);
263+
for (const auto& track : mTracks) {
264+
for (const auto& param : track) {
265+
int iCl = 2 * (param.getClusterPtr()->getChamberId() - 6) + param.getClusterPtr()->getDEId() % 2;
266+
usedClusters[iTrack][iCl] = param.getClusterPtr()->uid;
267+
}
268+
++iTrack;
269+
}
270+
260271
auto itLastCandidateFromSt5 = mTracks.empty() ? mTracks.end() : std::prev(mTracks.end());
261272

262273
// then look for candidates on station 4
@@ -280,8 +291,13 @@ void TrackFinder::findTrackCandidates()
280291
// exluding those already attached to an identical candidate on station 4
281292
// (cases where both chambers of station 5 are fired should have been found in the first step)
282293
std::unordered_map<int, std::unordered_set<uint32_t>> excludedClusters{};
283-
if (itLastCandidateFromSt5 != mTracks.end()) {
284-
excludeClustersFromIdenticalTracks(itTrack, excludedClusters, std::next(itLastCandidateFromSt5));
294+
if (!usedClusters.empty()) {
295+
std::array<uint32_t, 4> currentClusters{};
296+
for (const auto& param : *itTrack) {
297+
int iCl = 2 * (param.getClusterPtr()->getChamberId() - 6) + param.getClusterPtr()->getDEId() % 2;
298+
currentClusters[iCl] = param.getClusterPtr()->uid;
299+
}
300+
excludeClustersFromIdenticalTracks(currentClusters, usedClusters, excludedClusters);
285301
}
286302
auto itFirstNewTrack = followTrackInChamber(itTrack, 8, 8, false, excludedClusters);
287303
auto itNewTrack = followTrackInChamber(itTrack, 9, 9, false, excludedClusters);
@@ -1484,20 +1500,27 @@ bool TrackFinder::areUsed(const Cluster& cl1, const Cluster& cl2, const std::vec
14841500
}
14851501

14861502
//_________________________________________________________________________________________________
1487-
void TrackFinder::excludeClustersFromIdenticalTracks(const std::list<Track>::iterator& itTrack,
1488-
std::unordered_map<int, std::unordered_set<uint32_t>>& excludedClusters,
1489-
const std::list<Track>::iterator& itEndTrack)
1503+
void TrackFinder::excludeClustersFromIdenticalTracks(const std::array<uint32_t, 4>& currentClusters,
1504+
const std::vector<std::array<uint32_t, 8>>& usedClusters,
1505+
std::unordered_map<int, std::unordered_set<uint32_t>>& excludedClusters)
14901506
{
1491-
/// Find tracks in the range [mTracks.begin(), itEndTrack[ that contain all the clusters of itTrack
1492-
/// and add the clusters that these tracks have on station 5 in the excludedClusters list
1493-
for (auto itTrack2 = mTracks.begin(); itTrack2 != itEndTrack; ++itTrack2) {
1494-
if (itTrack->getNClustersInCommon(*itTrack2) == itTrack->getNClusters()) {
1495-
for (auto itParam = itTrack2->rbegin(); itParam != itTrack2->rend(); ++itParam) {
1496-
const Cluster* cluster = itParam->getClusterPtr();
1497-
if (cluster->getChamberId() > 7) {
1498-
excludedClusters[cluster->getDEId()].emplace(cluster->uid);
1499-
} else {
1500-
break;
1507+
/// Find the combinations of usedClusters using all the currentClusters on station 4
1508+
/// and add the clusters from these combinations on station 5 in the excludedClusters list
1509+
1510+
for (const auto& clusters : usedClusters) {
1511+
1512+
bool identicalTrack(true);
1513+
for (int iCl = 0; iCl < 4; ++iCl) {
1514+
if (clusters[iCl] != currentClusters[iCl] && currentClusters[iCl] > 0) {
1515+
identicalTrack = false;
1516+
break;
1517+
}
1518+
}
1519+
1520+
if (identicalTrack) {
1521+
for (int iCl = 4; iCl < 8; ++iCl) {
1522+
if (clusters[iCl] > 0) {
1523+
excludedClusters[Cluster::getDEId(clusters[iCl])].emplace(clusters[iCl]);
15011524
}
15021525
}
15031526
}

0 commit comments

Comments
 (0)