Skip to content

Commit 458056d

Browse files
committed
MCCompLabel: suppress long64 cast op., add relation operators
Cast operator was interfering with more useful comparison operator, is getRawValue instead of cast. Added relation operators since some detector need the MC labels to be sortable
1 parent fe8c2ce commit 458056d

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

DataFormats/simulation/include/SimulationDataFormat/MCCompLabel.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,16 @@ class MCCompLabel
8686
return (tr1 == tr2) ? ((isCorrect() && other.isCorrect()) ? 1 : 0) : -1;
8787
}
8888

89-
// conversion operator
90-
operator ULong64_t() const { return mLabel; }
9189
// allow to retrieve bare label
9290
ULong64_t getRawValue() const { return mLabel; }
9391

9492
// comparison operator, compares only label, not eventual weight or correctness info
9593
bool operator==(const MCCompLabel& other) const { return (mLabel & maskFull) == (other.mLabel & maskFull); }
94+
bool operator!=(const MCCompLabel& other) const { return (mLabel & maskFull) != (other.mLabel & maskFull); }
95+
// relation operators needed for some sorting methods
96+
bool operator<(const MCCompLabel& other) const { return (mLabel & maskFull) < (other.mLabel & maskFull); }
97+
bool operator>(const MCCompLabel& other) const { return (mLabel & maskFull) > (other.mLabel & maskFull); }
98+
9699
// invalidate
97100
void unset() { mLabel = NotSet; }
98101
void setNoise() { mLabel = Noise; }
@@ -137,9 +140,10 @@ class MCCompLabel
137140
static constexpr int maxTrackID() { return maskTrackID; }
138141
ClassDefNV(MCCompLabel, 1);
139142
};
140-
} // namespace o2
141143

142-
std::ostream& operator<<(std::ostream& os, const o2::MCCompLabel& c);
144+
std::ostream& operator<<(std::ostream& os, MCCompLabel const& c);
145+
146+
} // namespace o2
143147

144148
namespace std
145149
{
@@ -149,7 +153,7 @@ struct hash<o2::MCCompLabel> {
149153
public:
150154
size_t operator()(o2::MCCompLabel const& label) const
151155
{
152-
return static_cast<uint64_t>(label);
156+
return label.getRawValue();
153157
}
154158
};
155159
} // namespace std

DataFormats/simulation/src/MCCompLabel.cxx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,11 @@
1414
#include <iostream>
1515
#include <cassert>
1616

17-
using namespace o2;
18-
19-
ClassImp(o2::MCCompLabel);
20-
21-
//_____________________________________________
22-
void MCCompLabel::print() const
17+
namespace o2
2318
{
24-
// print itself
25-
std::cout << (MCCompLabel) * this << std::endl;
26-
}
2719

2820
//_____________________________________________
29-
std::ostream& operator<<(std::ostream& os, const o2::MCCompLabel& c)
21+
std::ostream& operator<<(std::ostream& os, MCCompLabel const& c)
3022
{
3123
// stream itself
3224
if (c.isValid()) {
@@ -37,3 +29,12 @@ std::ostream& operator<<(std::ostream& os, const o2::MCCompLabel& c)
3729
}
3830
return os;
3931
}
32+
33+
//_____________________________________________
34+
void MCCompLabel::print() const
35+
{
36+
// print itself
37+
std::cout << (MCCompLabel) * this << std::endl;
38+
}
39+
40+
} // namespace o2

DataFormats/simulation/test/testMCCompLabel.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(MCCompLabel_test)
3131
MCCompLabel lb(std::abs(tr), ev, src, tr < 0);
3232
std::cout << "Input: [" << src << '/' << ev << '/'
3333
<< std::setw(6) << tr << ']' << std::endl;
34-
std::cout << "Encoded: " << lb << " (packed: " << ULong_t(lb) << ")" << std::endl;
34+
std::cout << "Encoded: " << lb << " (packed: " << lb.getRawValue() << ")" << std::endl;
3535
labelMap[lb] = tr;
3636
int trE, evE, srcE;
3737
bool fake;

Detectors/ITSMFT/ITS/macros/test/CheckClusterShape.C

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,11 @@ void CheckClusterShape(std::string digifile = "o2digi_its.root", std::string inp
259259
UInt_t layer = gman->getLayer(chipID);
260260

261261
Pixel pixels(ix, iz);
262-
if (clusters.find(labs[0]) == clusters.end()) {
262+
if (clusters.find(labs[0].getRawValue()) == clusters.end()) {
263263
Cluster c;
264-
clusters[labs[0]] = c;
264+
clusters[labs[0].getRawValue()] = c;
265265
}
266-
clusters[labs[0]].AddPixel(layer, pixels);
266+
clusters[labs[0].getRawValue()].AddPixel(layer, pixels);
267267
}
268268
AnalyzeClusters(nev, clusters, freqDist, cSizeDist);
269269
}

Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,12 @@ void Tracker::computeRoadsMClabels(const ROframe& event)
535535
count = 1;
536536

537537
const int cl1index{mPrimaryVertexContext->getClusters()[iCell + 1][currentCell.getSecondClusterIndex()].clusterId};
538-
auto& cl1labs{event.getClusterLabels(iCell + 1, cl1index)};
539-
const int secondMonteCarlo{cl1labs.getTrackID()};
538+
const auto& cl1labs{event.getClusterLabels(iCell + 1, cl1index)};
540539

541-
if (secondMonteCarlo == maxOccurrencesValue) {
540+
if (cl1labs == maxOccurrencesValue) {
542541
++count;
543542
} else {
544-
maxOccurrencesValue = secondMonteCarlo;
543+
maxOccurrencesValue = cl1labs;
545544
count = 1;
546545
isFakeRoad = true;
547546
}
@@ -550,23 +549,22 @@ void Tracker::computeRoadsMClabels(const ROframe& event)
550549
}
551550

552551
const int cl2index{mPrimaryVertexContext->getClusters()[iCell + 2][currentCell.getThirdClusterIndex()].clusterId};
553-
auto& cl2labs{event.getClusterLabels(iCell + 2, cl2index)};
554-
const int currentMonteCarlo = {cl2labs.getTrackID()};
552+
const auto& cl2labs{event.getClusterLabels(iCell + 2, cl2index)};
555553

556-
if (currentMonteCarlo == maxOccurrencesValue) {
554+
if (cl2labs == maxOccurrencesValue) {
557555
++count;
558556
} else {
559557
--count;
560558
isFakeRoad = true;
561559
}
562560

563561
if (count == 0) {
564-
maxOccurrencesValue = currentMonteCarlo;
562+
maxOccurrencesValue = cl2labs;
565563
count = 1;
566564
}
567565
}
568566

569-
mPrimaryVertexContext->setRoadLabel(iRoad, maxOccurrencesValue, isFakeRoad);
567+
mPrimaryVertexContext->setRoadLabel(iRoad, maxOccurrencesValue.getRawValue(), isFakeRoad);
570568
}
571569
}
572570

macro/CheckDigits_mft.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void CheckDigits_mft(Int_t nEvents = 1, Int_t nMuons = 10, TString mcEngine = "T
106106
for (auto& p : *hitArray) {
107107
if (p.GetDetectorID() != (Short_t)chipID)
108108
continue;
109-
if (p.GetTrackID() != (Int_t)lab)
109+
if (p.GetTrackID() != lab.getTrackID())
110110
continue;
111111

112112
auto locH = gman->getMatrixL2G(chipID) ^ (p.GetPos()); // inverse conversion from global to local

0 commit comments

Comments
 (0)