Skip to content

Commit

Permalink
MCCompLabel: suppress long64 cast op., add relation operators
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shahoian authored and shahor02 committed Feb 3, 2021
1 parent fe8c2ce commit 458056d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ class MCCompLabel
return (tr1 == tr2) ? ((isCorrect() && other.isCorrect()) ? 1 : 0) : -1;
}

// conversion operator
operator ULong64_t() const { return mLabel; }
// allow to retrieve bare label
ULong64_t getRawValue() const { return mLabel; }

// comparison operator, compares only label, not eventual weight or correctness info
bool operator==(const MCCompLabel& other) const { return (mLabel & maskFull) == (other.mLabel & maskFull); }
bool operator!=(const MCCompLabel& other) const { return (mLabel & maskFull) != (other.mLabel & maskFull); }
// relation operators needed for some sorting methods
bool operator<(const MCCompLabel& other) const { return (mLabel & maskFull) < (other.mLabel & maskFull); }
bool operator>(const MCCompLabel& other) const { return (mLabel & maskFull) > (other.mLabel & maskFull); }

// invalidate
void unset() { mLabel = NotSet; }
void setNoise() { mLabel = Noise; }
Expand Down Expand Up @@ -137,9 +140,10 @@ class MCCompLabel
static constexpr int maxTrackID() { return maskTrackID; }
ClassDefNV(MCCompLabel, 1);
};
} // namespace o2

std::ostream& operator<<(std::ostream& os, const o2::MCCompLabel& c);
std::ostream& operator<<(std::ostream& os, MCCompLabel const& c);

} // namespace o2

namespace std
{
Expand All @@ -149,7 +153,7 @@ struct hash<o2::MCCompLabel> {
public:
size_t operator()(o2::MCCompLabel const& label) const
{
return static_cast<uint64_t>(label);
return label.getRawValue();
}
};
} // namespace std
Expand Down
21 changes: 11 additions & 10 deletions DataFormats/simulation/src/MCCompLabel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@
#include <iostream>
#include <cassert>

using namespace o2;

ClassImp(o2::MCCompLabel);

//_____________________________________________
void MCCompLabel::print() const
namespace o2
{
// print itself
std::cout << (MCCompLabel) * this << std::endl;
}

//_____________________________________________
std::ostream& operator<<(std::ostream& os, const o2::MCCompLabel& c)
std::ostream& operator<<(std::ostream& os, MCCompLabel const& c)
{
// stream itself
if (c.isValid()) {
Expand All @@ -37,3 +29,12 @@ std::ostream& operator<<(std::ostream& os, const o2::MCCompLabel& c)
}
return os;
}

//_____________________________________________
void MCCompLabel::print() const
{
// print itself
std::cout << (MCCompLabel) * this << std::endl;
}

} // namespace o2
2 changes: 1 addition & 1 deletion DataFormats/simulation/test/testMCCompLabel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(MCCompLabel_test)
MCCompLabel lb(std::abs(tr), ev, src, tr < 0);
std::cout << "Input: [" << src << '/' << ev << '/'
<< std::setw(6) << tr << ']' << std::endl;
std::cout << "Encoded: " << lb << " (packed: " << ULong_t(lb) << ")" << std::endl;
std::cout << "Encoded: " << lb << " (packed: " << lb.getRawValue() << ")" << std::endl;
labelMap[lb] = tr;
int trE, evE, srcE;
bool fake;
Expand Down
6 changes: 3 additions & 3 deletions Detectors/ITSMFT/ITS/macros/test/CheckClusterShape.C
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ void CheckClusterShape(std::string digifile = "o2digi_its.root", std::string inp
UInt_t layer = gman->getLayer(chipID);

Pixel pixels(ix, iz);
if (clusters.find(labs[0]) == clusters.end()) {
if (clusters.find(labs[0].getRawValue()) == clusters.end()) {
Cluster c;
clusters[labs[0]] = c;
clusters[labs[0].getRawValue()] = c;
}
clusters[labs[0]].AddPixel(layer, pixels);
clusters[labs[0].getRawValue()].AddPixel(layer, pixels);
}
AnalyzeClusters(nev, clusters, freqDist, cSizeDist);
}
Expand Down
16 changes: 7 additions & 9 deletions Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,12 @@ void Tracker::computeRoadsMClabels(const ROframe& event)
count = 1;

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

if (secondMonteCarlo == maxOccurrencesValue) {
if (cl1labs == maxOccurrencesValue) {
++count;
} else {
maxOccurrencesValue = secondMonteCarlo;
maxOccurrencesValue = cl1labs;
count = 1;
isFakeRoad = true;
}
Expand All @@ -550,23 +549,22 @@ void Tracker::computeRoadsMClabels(const ROframe& event)
}

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

if (currentMonteCarlo == maxOccurrencesValue) {
if (cl2labs == maxOccurrencesValue) {
++count;
} else {
--count;
isFakeRoad = true;
}

if (count == 0) {
maxOccurrencesValue = currentMonteCarlo;
maxOccurrencesValue = cl2labs;
count = 1;
}
}

mPrimaryVertexContext->setRoadLabel(iRoad, maxOccurrencesValue, isFakeRoad);
mPrimaryVertexContext->setRoadLabel(iRoad, maxOccurrencesValue.getRawValue(), isFakeRoad);
}
}

Expand Down
2 changes: 1 addition & 1 deletion macro/CheckDigits_mft.C
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void CheckDigits_mft(Int_t nEvents = 1, Int_t nMuons = 10, TString mcEngine = "T
for (auto& p : *hitArray) {
if (p.GetDetectorID() != (Short_t)chipID)
continue;
if (p.GetTrackID() != (Int_t)lab)
if (p.GetTrackID() != lab.getTrackID())
continue;

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

0 comments on commit 458056d

Please sign in to comment.