|
| 1 | +// Copyright 2019-2020 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 | +// helper class for TPC clusters selection |
| 13 | +#include "GlobalTrackingStudy/TPCClusSelector.h" |
| 14 | +#include "DataFormatsTPC/ClusterNativeHelper.h" |
| 15 | +#include "Framework/Logger.h" |
| 16 | +#include <numeric> |
| 17 | +#ifdef WITH_OPENMP |
| 18 | +#include <omp.h> |
| 19 | +#endif |
| 20 | + |
| 21 | +using namespace o2::tpc; |
| 22 | + |
| 23 | +void TPCClusSelector::setNThreads(int n) |
| 24 | +{ |
| 25 | +#ifndef WITH_OPENMP |
| 26 | + if (n > 1) { |
| 27 | + LOGP(warn, "No OpenMP"); |
| 28 | + } |
| 29 | + n = 1; |
| 30 | +#endif |
| 31 | + mNThreads = n; |
| 32 | +} |
| 33 | + |
| 34 | +std::pair<int, int> TPCClusSelector::findClustersRange(int sec, int row, float tbmin, float tbmax, const o2::tpc::ClusterNativeAccess& tpcClusterIdxStruct) |
| 35 | +{ |
| 36 | + // find sorted indices of clusters in the [tbmin:tbmax] range, if not found, return {-1,-2} |
| 37 | + const auto& vidx = mSectors[sec].rows[row]; |
| 38 | + const auto* clarr = tpcClusterIdxStruct.clusters[sec][row]; |
| 39 | + // use binary search to find 1st cluster with time >= tb |
| 40 | + int ncl = vidx.size(), left = 0, right = ncl; |
| 41 | + while (left < right) { |
| 42 | + int mid = left + (right - left) / 2; |
| 43 | + if (clarr[vidx[mid]].getTime() < tbmin) { |
| 44 | + left = mid + 1; |
| 45 | + } else { |
| 46 | + right = mid; |
| 47 | + } |
| 48 | + } |
| 49 | + if (left == ncl || clarr[vidx[left]].getTime() > tbmax) { |
| 50 | + return {-1, -2}; // all clusters have time < tbmin or no clusters in the range [tbmin:tbmax] |
| 51 | + } |
| 52 | + int idmin = left, idmax = left, idtst = idmin; |
| 53 | + // look at smaller times |
| 54 | + while (++idtst < ncl && clarr[vidx[idtst]].getTime() <= tbmax) { |
| 55 | + idmax = idtst; |
| 56 | + } |
| 57 | + return {idmin, idmax}; |
| 58 | +} |
| 59 | + |
| 60 | +int TPCClusSelector::findClustersEntries(int sec, int row, float tbmin, float tbmax, float padmin, float padmax, const o2::tpc::ClusterNativeAccess& tpcClusterIdxStruct, std::vector<int>* clIDDirect) |
| 61 | +{ |
| 62 | + // find direct cluster indices for tbmin:tbmas / padmin/padmax range, fill clIDDirect vector if provided |
| 63 | + const auto& vidx = mSectors[sec].rows[row]; |
| 64 | + const auto* clarr = tpcClusterIdxStruct.clusters[sec][row]; |
| 65 | + // use binary search to find 1st cluster with time >= tb |
| 66 | + int ncl = vidx.size(), left = 0, right = ncl; |
| 67 | + if (clIDDirect) { |
| 68 | + clIDDirect->clear(); |
| 69 | + } |
| 70 | + while (left < right) { |
| 71 | + int mid = left + (right - left) / 2; |
| 72 | + if (clarr[vidx[mid]].getTime() < tbmin) { |
| 73 | + left = mid + 1; |
| 74 | + } else { |
| 75 | + right = mid; |
| 76 | + } |
| 77 | + } |
| 78 | + if (left == ncl || clarr[vidx[left]].getTime() > tbmax) { |
| 79 | + return 0; // all clusters have time < tbmin or no clusters in the range [tbmin:tbmax] |
| 80 | + } |
| 81 | + int nclf = 0; |
| 82 | + while (left < ncl) { |
| 83 | + const auto& cl = clarr[vidx[left]]; |
| 84 | + if (cl.getTime() > tbmax) { |
| 85 | + break; |
| 86 | + } |
| 87 | + if (cl.getPad() >= padmin && cl.getPad() <= padmax) { |
| 88 | + nclf++; |
| 89 | + if (clIDDirect) { |
| 90 | + clIDDirect->push_back(vidx[left]); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + return nclf; |
| 95 | +} |
| 96 | + |
| 97 | +void TPCClusSelector::fill(const o2::tpc::ClusterNativeAccess& tpcClusterIdxStruct) |
| 98 | +{ |
| 99 | + for (int is = 0; is < NSectors; is++) { |
| 100 | + auto& sect = mSectors[is]; |
| 101 | +#ifdef WITH_OPENMP |
| 102 | +#pragma omp parallel for schedule(dynamic) num_threads(mNThreads) |
| 103 | +#endif |
| 104 | + for (int ir = 0; ir < Sector::NRows; ir++) { |
| 105 | + size_t ncl = tpcClusterIdxStruct.nClusters[is][ir]; |
| 106 | + if (ncl >= 0xffff) { |
| 107 | + LOGP(error, "Row {} of sector {} has {} clusters, truncating to {}", ir, is, ncl, int(0xffff)); |
| 108 | + ncl = 0xffff; |
| 109 | + } |
| 110 | + auto& rowidx = sect.rows[ir]; |
| 111 | + rowidx.resize(ncl); |
| 112 | + std::iota(rowidx.begin(), rowidx.end(), 0); |
| 113 | + const auto* clus = tpcClusterIdxStruct.clusters[is][ir]; // C array of clusters |
| 114 | + std::sort(rowidx.begin(), rowidx.end(), [&](size_t a, size_t b) { return clus[a].getTime() < clus[b].getTime(); }); |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments