Skip to content

Commit b76b1a6

Browse files
committed
Add detector masks to GlobalTrackID
1 parent 6b1a0c1 commit b76b1a6

3 files changed

Lines changed: 44 additions & 15 deletions

File tree

Common/MathUtils/include/MathUtils/detail/bitOps.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ inline int numberOfBitsSet(uint32_t x)
3636

3737
// recursive creation of bitmask
3838
template <typename T>
39-
constexpr int bit2Mask(T v)
39+
constexpr uint32_t bit2Mask(T v)
4040
{
4141
return 0x1 << v;
4242
}
4343

4444
template <typename T, typename... Args>
45-
constexpr int bit2Mask(T first, Args... args)
45+
constexpr uint32_t bit2Mask(T first, Args... args)
4646
{
4747
return (0x1 << first) | bit2Mask(args...);
4848
}

DataFormats/Reconstruction/include/ReconstructionDataFormats/GlobalTrackID.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define O2_GLOBAL_TRACK_ID
1717

1818
#include "CommonDataFormat/AbstractRef.h"
19+
#include "DetectorsCommonDataFormats/DetID.h"
1920
#include <iosfwd>
2021
#include <string>
2122
#include <array>
@@ -29,13 +30,15 @@ namespace dataformats
2930
class GlobalTrackID : public AbstractRef<25, 5, 2>
3031
{
3132
public:
33+
using DetID = o2::detectors::DetID;
34+
3235
enum Source : uint8_t { // provenance of the
3336
ITS, // standalone detectors
3437
TPC,
3538
TRD,
3639
TOF,
37-
PHS,
38-
CPV,
40+
PHS, // FIXME Not sure PHS ... FDD should be kept here, at the moment
41+
CPV, // they are here for completeness
3942
EMC,
4043
HMP,
4144
MFT,
@@ -55,22 +58,22 @@ class GlobalTrackID : public AbstractRef<25, 5, 2>
5558
//
5659
NSources
5760
};
58-
static constexpr std::array<std::string_view, NSources> SourceNames = {
59-
"ITS", "TPC", "TRD", "TOF", "PHS", "CPV", "EMC", "HMP", "MFT", "MCH", "MID", "ZDC", "FT0", "FV0", "FDD", // standalone tracks
60-
"ITSTPC", "TPCTOF", "TPCTRD", // 2-detector tracks
61-
"ITSTPCTRD", "ITSTPCTOF", "TPCTRDTOF", // 3-detector tracks
62-
"ITSTPCTRDTOF" // full barrel track
63-
//
64-
};
6561

62+
static const std::array<DetID::mask_t, NSources> DetectorMasks; // RS cannot be made constexpr since operator| is not constexpr
6663
using AbstractRef<25, 5, 2>::AbstractRef;
6764

68-
static auto getSourceName(int i) { return SourceNames[i]; }
69-
void print() const;
70-
std::string asString() const;
65+
static const auto getSourceMask(int i) { return DetectorMasks[i]; }
66+
static auto getSourceName(int i) { return DetID::getNames(getSourceMask(i)); }
67+
7168
auto getSourceName() const { return getSourceName(getSource()); }
69+
auto getSourceMask() const { return getSourceMask(getSource()); }
70+
bool includesDet(DetID id) const { return (getSourceMask() & DetID::getMask(id)).any(); }
71+
7272
operator int() const { return int(getIndex()); }
7373

74+
std::string asString() const;
75+
void print() const;
76+
7477
ClassDefNV(GlobalTrackID, 2);
7578
};
7679

DataFormats/Reconstruction/src/GlobalTrackID.cxx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,37 @@
1919
#include <bitset>
2020

2121
using namespace o2::dataformats;
22+
using DetID = o2::detectors::DetID;
23+
24+
const std::array<DetID::mask_t, GlobalTrackID::NSources> GlobalTrackID::DetectorMasks = {
25+
DetID::getMask(DetID::ITS),
26+
DetID::getMask(DetID::TPC),
27+
DetID::getMask(DetID::TRD),
28+
DetID::getMask(DetID::TOF),
29+
DetID::getMask(DetID::PHS),
30+
DetID::getMask(DetID::CPV),
31+
DetID::getMask(DetID::EMC),
32+
DetID::getMask(DetID::HMP),
33+
DetID::getMask(DetID::MFT),
34+
DetID::getMask(DetID::MCH),
35+
DetID::getMask(DetID::MID),
36+
DetID::getMask(DetID::ZDC),
37+
DetID::getMask(DetID::FT0),
38+
DetID::getMask(DetID::FV0),
39+
DetID::getMask(DetID::FDD),
40+
//
41+
DetID::getMask(DetID::ITS) | DetID::getMask(DetID::TPC),
42+
DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TOF),
43+
DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TRD),
44+
DetID::getMask(DetID::ITS) | DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TRD),
45+
DetID::getMask(DetID::ITS) | DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TOF),
46+
DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TRD) | DetID::getMask(DetID::TOF),
47+
DetID::getMask(DetID::ITS) | DetID::getMask(DetID::TPC) | DetID::getMask(DetID::TRD) | DetID::getMask(DetID::TOF)};
2248

2349
std::string GlobalTrackID::asString() const
2450
{
2551
std::bitset<NBitsFlags()> bits{getFlags()};
26-
return fmt::format("[{:d}/{:d}/{:s}]", getIndex(), getSource(), bits.to_string());
52+
return fmt::format("[{:s}/{:d}/{:s}]", getSourceName(), getIndex(), bits.to_string());
2753
}
2854

2955
std::ostream& o2::dataformats::operator<<(std::ostream& os, const o2::dataformats::GlobalTrackID& v)

0 commit comments

Comments
 (0)