|
| 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 | + |
| 14 | +#ifndef ALICEO2_TPCCLUSSELECTOR_H |
| 15 | +#define ALICEO2_TPCCLUSSELECTOR_H |
| 16 | + |
| 17 | +#include <vector> |
| 18 | +#include <array> |
| 19 | +#include <Rtypes.h> |
| 20 | + |
| 21 | +namespace o2::tpc |
| 22 | +{ |
| 23 | +class ClusterNativeAccess; |
| 24 | + |
| 25 | +class TPCClusSelector |
| 26 | +{ |
| 27 | + // helper to select TPC cluster matching to certain timebin and optionally pads range |
| 28 | + // example of usage: |
| 29 | + /* |
| 30 | + TPCClusSelector clSel; |
| 31 | + o2::tpc::ClusterNativeHelper::Reader tcpClusterReader; |
| 32 | + tcpClusterReader.init(native_clusters_file.c_str()); |
| 33 | + o2::tpc::ClusterNativeAccess tpcClusterIdxStruct; |
| 34 | + std::unique_ptr<o2::tpc::ClusterNative[]> tpcClusterBuffer; ///< buffer for clusters in tpcClusterIdxStruct |
| 35 | + o2::tpc::ClusterNativeHelper::ConstMCLabelContainerViewWithBuffer tpcClusterMCBuffer; ///< buffer for mc labels |
| 36 | +
|
| 37 | + tcpClusterReader.read(iTF); |
| 38 | + tcpClusterReader.fillIndex(tpcClusterIdxStruct, tpcClusterBuffer, tpcClusterMCBuffer); |
| 39 | +
|
| 40 | + clSel.fill(tpcClusterIdxStruct); // Create sorted index |
| 41 | + // to get i-th cluster in orderer timebins: |
| 42 | + const auto& clus = tpcClusterIdxStruct.clusters[sector][row][ clSel.getIndex(sector, row, i)]; |
| 43 | +
|
| 44 | + // to get sorted indices range of clusters in the tbmin:tbmax range |
| 45 | + auto rng = clSel.findClustersRange(sector, row, tbmin, tbmax, tpcClusterIdxStruct); |
| 46 | + if (rng.first>rng.second) { // nothing is found } |
| 47 | + const auto& cln = tpcClusterIdxStruct.clusters[sector][row][clSel.getIndex(sector, row, rng.first )]; /... |
| 48 | +
|
| 49 | + // to get number of clusters in tbmin:tbmax, padmin:padmax range (and optionally get the list) |
| 50 | + std::vector<int> cllist; // optional list |
| 51 | + int nfnd = clSel.findClustersEntries(sector, row, tbmin, tbmax, padmin, padmax, tpcClusterIdxStruct, &cllist); |
| 52 | + for (int i=0;i<nfnd;i++) { |
| 53 | + const auto& cln = tpcClusterIdxStruct.clusters[sector][row][cllist[i]]; /... direct indices! |
| 54 | + } |
| 55 | + */ |
| 56 | + |
| 57 | + public: |
| 58 | + void clear() |
| 59 | + { |
| 60 | + for (auto& s : mSectors) |
| 61 | + s.clear(); |
| 62 | + } |
| 63 | + size_t getIndex(int sec, int row, uint32_t icl) const { return mSectors[sec].rows[row][icl]; } |
| 64 | + |
| 65 | + std::pair<int, int> findClustersRange(int sec, int row, float tbmin, float tbmax, const o2::tpc::ClusterNativeAccess& tpcClusterIdxStruct); |
| 66 | + int findClustersEntries(int sec, int row, float tbmin, float tbmax, float padmin, float padmax, const o2::tpc::ClusterNativeAccess& tpcClusterIdxStruct, std::vector<int>* clIDDirect = nullptr); |
| 67 | + void fill(const o2::tpc::ClusterNativeAccess& tpcClusterIdxStruct); |
| 68 | + |
| 69 | + int getNThreads() const { return mNThreads; } |
| 70 | + void setNThreads(int n); |
| 71 | + |
| 72 | + private: |
| 73 | + struct Sector { |
| 74 | + static constexpr int NRows = 152; |
| 75 | + std::array<std::vector<uint16_t>, NRows> rows; |
| 76 | + void clear() |
| 77 | + { |
| 78 | + for (auto& r : rows) |
| 79 | + r.clear(); |
| 80 | + } |
| 81 | + }; |
| 82 | + |
| 83 | + static constexpr int NSectors = 36; |
| 84 | + std::array<Sector, NSectors> mSectors{}; |
| 85 | + int mNThreads = 1; |
| 86 | + |
| 87 | + ClassDefNV(TPCClusSelector, 1); |
| 88 | +}; |
| 89 | + |
| 90 | +} // namespace o2::tpc |
| 91 | + |
| 92 | +#endif |
0 commit comments