Skip to content

Commit fea8418

Browse files
dstoccosawenzel
authored andcommitted
Tracks labeler for MID
1 parent 109e0a9 commit fea8418

File tree

3 files changed

+163
-0
lines changed

3 files changed

+163
-0
lines changed

Detectors/MUON/MID/Simulation/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set(SRCS
1919
src/MCLabel.cxx
2020
src/PreClusterLabeler.cxx
2121
src/Stepper.cxx
22+
src/TrackLabeler.cxx
2223
)
2324

2425
set(HEADERS
@@ -36,6 +37,7 @@ set(HEADERS
3637
include/${MODULE_NAME}/MCClusterLabel.h
3738
include/${MODULE_NAME}/MCLabel.h
3839
include/${MODULE_NAME}/Stepper.h
40+
include/${MODULE_NAME}/TrackLabeler.h
3941
)
4042

4143
set(LINKDEF src/MIDSimulationLinkDef.h)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 MIDSimulation/TrackLabeler.h
12+
/// \brief Tracks labeler for MID
13+
/// \author Diego Stocco <Diego.Stocco at cern.ch>
14+
/// \date 07 June 2019
15+
#ifndef O2_MID_TRACKLABELER_H
16+
#define O2_MID_TRACKLABELER_H
17+
18+
#include <vector>
19+
#include <gsl/gsl>
20+
#include "SimulationDataFormat/MCTruthContainer.h"
21+
#include "SimulationDataFormat/MCCompLabel.h"
22+
#include "DataFormatsMID/Track.h"
23+
#include "DataFormatsMID/Cluster3D.h"
24+
#include "MIDSimulation/MCClusterLabel.h"
25+
26+
namespace o2
27+
{
28+
namespace mid
29+
{
30+
class TrackLabeler
31+
{
32+
public:
33+
void process(gsl::span<const Cluster3D>& clusters, gsl::span<const Track>& tracks, const o2::dataformats::MCTruthContainer<MCClusterLabel>& inMCContainer);
34+
35+
/// Returns the tracks labels
36+
const o2::dataformats::MCTruthContainer<MCCompLabel>& getTracksLabels() { return mMCTracksLabels; }
37+
38+
/// Returns the cluster labels
39+
const o2::dataformats::MCTruthContainer<MCClusterLabel>& getTrackClustersLabels() { return mMCTrackClustersLabels; }
40+
41+
private:
42+
bool areBothSidesFired(const gsl::span<const MCClusterLabel>& labels) const;
43+
std::vector<MCCompLabel> findLabels(const Track& track, const o2::dataformats::MCTruthContainer<MCClusterLabel>& inMCContainer) const;
44+
45+
o2::dataformats::MCTruthContainer<MCCompLabel> mMCTracksLabels; ///< Track labels
46+
o2::dataformats::MCTruthContainer<MCClusterLabel> mMCTrackClustersLabels; ///< Cluster labels
47+
};
48+
} // namespace mid
49+
} // namespace o2
50+
51+
#endif /* O2_MID_TRACKLABELER_H */
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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

Comments
 (0)