|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +/// \file MID/Simulation/src/TrackLabeler.cxx |
| 12 | +/// \brief Implementation of the TrackLabeler for MID |
| 13 | +/// \author Diego Stocco <Diego.Stocco at cern.ch> |
| 14 | +/// \date 01 March 2018 |
| 15 | +#include "MIDSimulation/TrackLabeler.h" |
| 16 | + |
| 17 | +namespace o2 |
| 18 | +{ |
| 19 | +namespace mid |
| 20 | +{ |
| 21 | + |
| 22 | +bool TrackLabeler::areBothSidesFired(const gsl::span<const MCClusterLabel>& labels) const |
| 23 | +{ |
| 24 | + /// Check if the BP and NBP were fired by some track |
| 25 | + bool isFiredBP = false, isFiredNBP = false; |
| 26 | + for (auto& label : labels) { |
| 27 | + if (label.isFiredBP()) { |
| 28 | + isFiredBP = true; |
| 29 | + } |
| 30 | + if (label.isFiredNBP()) { |
| 31 | + isFiredNBP = true; |
| 32 | + } |
| 33 | + } |
| 34 | + return isFiredBP && isFiredNBP; |
| 35 | +} |
| 36 | + |
| 37 | +std::vector<MCCompLabel> TrackLabeler::findLabels(const Track& track, const o2::dataformats::MCTruthContainer<MCClusterLabel>& inMCContainer) const |
| 38 | +{ |
| 39 | + /// Finds the track label from its associated clusters labels |
| 40 | + std::vector<MCCompLabel> allLabels; |
| 41 | + std::vector<int> counts; |
| 42 | + for (int ich = 0; ich < 4; ++ich) { |
| 43 | + auto icl = track.getClusterMatched(ich); |
| 44 | + if (icl < 0) { |
| 45 | + continue; |
| 46 | + } |
| 47 | + |
| 48 | + // First check if the BP and NBP were ever fired by a track |
| 49 | + // If they are, it means that the chamber was efficient |
| 50 | + bool bothFired = areBothSidesFired(inMCContainer.getLabels(icl)); |
| 51 | + |
| 52 | + for (auto& label : inMCContainer.getLabels(icl)) { |
| 53 | + // This track fired only one cathode |
| 54 | + bool oneFired = (!label.isFiredBP() || !label.isFiredNBP()); |
| 55 | + if (bothFired && oneFired) { |
| 56 | + // This condition means that the cluster was made from |
| 57 | + // a track in the BP and a different track in the NBP. |
| 58 | + // This happens when we have two tracks in the same column. |
| 59 | + // This means that the cluster is a fake one, so we discard it |
| 60 | + continue; |
| 61 | + } |
| 62 | + bool isNew = true; |
| 63 | + for (size_t idx = 0; idx < allLabels.size(); ++idx) { |
| 64 | + if (allLabels[idx] == label) { |
| 65 | + ++counts[idx]; |
| 66 | + isNew = false; |
| 67 | + break; |
| 68 | + } |
| 69 | + } |
| 70 | + if (isNew) { |
| 71 | + allLabels.emplace_back(label); |
| 72 | + counts.emplace_back(1); |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + std::vector<MCCompLabel> labels; |
| 78 | + |
| 79 | + for (size_t idx = 0; idx < allLabels.size(); ++idx) { |
| 80 | + if (counts[idx] >= 3) { |
| 81 | + labels.emplace_back(allLabels[idx]); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + return std::move(labels); |
| 86 | +} |
| 87 | + |
| 88 | +void TrackLabeler::process(gsl::span<const Cluster3D>& clusters, gsl::span<const Track>& tracks, const o2::dataformats::MCTruthContainer<MCClusterLabel>& inMCContainer) |
| 89 | +{ |
| 90 | + /// Applies labels to the tracks |
| 91 | + mMCTracksLabels.clear(); |
| 92 | + |
| 93 | + for (auto& track : tracks) { |
| 94 | + auto idx = &track - &tracks[0]; |
| 95 | + auto labels = findLabels(track, inMCContainer); |
| 96 | + if (labels.empty()) { |
| 97 | + labels.emplace_back(MCCompLabel()); |
| 98 | + } |
| 99 | + for (auto& label : labels) { |
| 100 | + mMCTracksLabels.addElement(idx, label); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + // For the moment we store all clusters |
| 105 | + // This can change if we decide to store only associated clusters |
| 106 | + mMCTrackClustersLabels.clear(); |
| 107 | + mMCTrackClustersLabels = inMCContainer; |
| 108 | +} |
| 109 | +} // namespace mid |
| 110 | +} // namespace o2 |
0 commit comments