Project
Loading...
Searching...
No Matches
MCCompLabel.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef ALICEO2_MCCOMPLABEL_H
13#define ALICEO2_MCCOMPLABEL_H
14
15#include <cstdint>
16#include "GPUCommonRtypes.h"
17#include <string>
18
19namespace o2
20{
21// Composed Label to encode MC track id, event it comes from and the source (file)
22
24{
25 private:
26 static constexpr uint64_t ul0x1 = 0x1;
27 static constexpr uint64_t NotSet = 0xffffffffffffffff;
28 static constexpr uint64_t Noise = 0xfffffffffffffffe;
29 static constexpr uint64_t Fake = ul0x1 << 63;
30 static constexpr int NReservedBits = 1;
31
32 uint64_t mLabel = NotSet;
33
34 public:
35 // number of bits reserved for MC track ID, DON'T modify this, since the
36 // track ID might be negative
37 static constexpr int nbitsTrackID = 31; // number of bits reserved for MC track ID
38 static constexpr int nbitsEvID = 19; // number of bits reserved for MC event ID
39 static constexpr int nbitsSrcID = 8; // number of bits reserved for MC source ID
40 // the rest of the bits is reserved at the moment
41
42 // check if the fields are defined consistently
43 static_assert(nbitsTrackID + nbitsEvID + nbitsSrcID <= sizeof(uint64_t) * 8 - NReservedBits,
44 "Fields cannot be stored in 64 bits");
45
46 // mask to extract MC track ID
47 static constexpr uint64_t maskTrackID = (ul0x1 << nbitsTrackID) - 1;
48 // mask to extract MC track ID
49 static constexpr uint64_t maskEvID = (ul0x1 << nbitsEvID) - 1;
50 // mask to extract MC track ID
51 static constexpr uint64_t maskSrcID = (ul0x1 << nbitsSrcID) - 1;
52 // mask for all used fields
53 static constexpr uint64_t maskFull = (ul0x1 << (nbitsTrackID + nbitsEvID + nbitsSrcID)) - 1;
54
55 MCCompLabel(int trackID, int evID, int srcID, bool fake = false) { set(trackID, evID, srcID, fake); }
56 MCCompLabel(bool noise = false)
57 {
58 if (noise) {
59 mLabel = Noise;
60 } else {
61 mLabel = NotSet;
62 }
63 }
64 ~MCCompLabel() = default;
65
66 // check if label was assigned
67 bool isSet() const { return mLabel != NotSet; }
68 // check if label was not assigned
69 bool isEmpty() const { return mLabel == NotSet; }
70 // check if label comes from QED contrib
71 bool isQED() const { return getSourceID() == 99; }
72 // check if label corresponds to real particle (for the moment QED is not included)
73 bool isNoise() const { return mLabel == Noise || isQED(); }
74 // check if label was assigned as for correctly identified particle
75 bool isValid() const { return isSet() && !isNoise(); }
76
77 // check if label was assigned as for incorrectly identified particle or not set or noise
78 bool isFake() const { return mLabel & Fake; }
79 // check if label was assigned as for correctly identified particle
80 bool isCorrect() const { return !isFake(); }
81
82 // return 1 if the tracks are the same and correctly identified
83 // 0 if the tracks are the same but at least one of them is fake
84 // -1 otherwhise
85 int compare(const MCCompLabel& other) const
86 {
87 if (getEventID() != other.getEventID() || getSourceID() != other.getSourceID()) {
88 return -1;
89 }
90 int tr1 = getTrackID(), tr2 = other.getTrackID();
91 return (tr1 == tr2) ? ((isCorrect() && other.isCorrect()) ? 1 : 0) : -1;
92 }
93
94 // allow to retrieve bare label
95 uint64_t getRawValue() const { return mLabel; }
96
97 // comparison operator, compares only label, not eventual weight or correctness info
98 bool operator==(const MCCompLabel& other) const { return (mLabel & maskFull) == (other.mLabel & maskFull); }
99 bool operator!=(const MCCompLabel& other) const { return (mLabel & maskFull) != (other.mLabel & maskFull); }
100 // relation operators needed for some sorting methods
101 bool operator<(const MCCompLabel& other) const { return (mLabel & maskFull) < (other.mLabel & maskFull); }
102 bool operator>(const MCCompLabel& other) const { return (mLabel & maskFull) > (other.mLabel & maskFull); }
103
104 // invalidate
105 void unset() { mLabel = NotSet; }
106 void setNoise() { mLabel = Noise; }
107 void setFakeFlag(bool v = true)
108 {
109 if (v) {
110 mLabel |= Fake;
111 } else {
112 mLabel &= ~Fake;
113 }
114 }
115
116 void set(unsigned int trackID, int evID, int srcID, bool fake)
117 {
119 mLabel = (maskTrackID & static_cast<uint64_t>(trackID)) |
120 (maskEvID & static_cast<uint64_t>(evID)) << nbitsTrackID |
121 (maskSrcID & static_cast<uint64_t>(srcID)) << (nbitsTrackID + nbitsEvID);
122 if (fake) {
123 setFakeFlag();
124 }
125 }
126
127 int getTrackID() const { return static_cast<int>(mLabel & maskTrackID); }
128 int getTrackIDSigned() const { return isFake() ? -getTrackID() : getTrackID(); }
129 int getEventID() const { return (mLabel >> nbitsTrackID) & maskEvID; }
130 int getSourceID() const { return (mLabel >> (nbitsTrackID + nbitsEvID)) & maskSrcID; }
131 uint64_t getTrackEventSourceID() const { return static_cast<uint64_t>(mLabel & maskFull); }
132 void get(int& trackID, int& evID, int& srcID, bool& fake) const
133 {
135 trackID = getTrackID();
136 evID = getEventID();
137 srcID = getSourceID();
138 fake = isFake();
139 }
140
141 void print() const;
142 std::string asString() const;
143
144 static constexpr int maxSourceID() { return maskSrcID; }
145 static constexpr int maxEventID() { return maskEvID; }
146 static constexpr int maxTrackID() { return maskTrackID; }
148};
149
150std::ostream& operator<<(std::ostream& os, MCCompLabel const& c);
151
152} // namespace o2
153
154namespace std
155{
156// defining std::hash for MCCompLabel in order to be used with unordered_maps
157template <>
158struct hash<o2::MCCompLabel> {
159 public:
160 size_t operator()(o2::MCCompLabel const& label) const
161 {
162 return label.getRawValue();
163 }
164};
165} // namespace std
166
167#endif
uint32_t c
Definition RawData.h:2
uint64_t getRawValue() const
Definition MCCompLabel.h:95
static constexpr int maxTrackID()
bool operator==(const MCCompLabel &other) const
Definition MCCompLabel.h:98
static constexpr int maxSourceID()
bool isFake() const
Definition MCCompLabel.h:78
void setFakeFlag(bool v=true)
bool operator!=(const MCCompLabel &other) const
Definition MCCompLabel.h:99
ClassDefNV(MCCompLabel, 1)
static constexpr uint64_t maskTrackID
Definition MCCompLabel.h:47
MCCompLabel(bool noise=false)
Definition MCCompLabel.h:56
int getTrackIDSigned() const
void get(int &trackID, int &evID, int &srcID, bool &fake) const
static constexpr int nbitsTrackID
Definition MCCompLabel.h:37
static constexpr uint64_t maskSrcID
Definition MCCompLabel.h:51
bool isCorrect() const
Definition MCCompLabel.h:80
bool isNoise() const
Definition MCCompLabel.h:73
uint64_t getTrackEventSourceID() const
bool isQED() const
Definition MCCompLabel.h:71
MCCompLabel(int trackID, int evID, int srcID, bool fake=false)
Definition MCCompLabel.h:55
int getTrackID() const
static constexpr int nbitsEvID
Definition MCCompLabel.h:38
bool operator>(const MCCompLabel &other) const
bool isSet() const
Definition MCCompLabel.h:67
static constexpr int maxEventID()
~MCCompLabel()=default
void set(unsigned int trackID, int evID, int srcID, bool fake)
void print() const
static constexpr int nbitsSrcID
Definition MCCompLabel.h:39
bool operator<(const MCCompLabel &other) const
int getSourceID() const
int getEventID() const
static constexpr uint64_t maskEvID
Definition MCCompLabel.h:49
bool isEmpty() const
Definition MCCompLabel.h:69
bool isValid() const
Definition MCCompLabel.h:75
int compare(const MCCompLabel &other) const
Definition MCCompLabel.h:85
std::string asString() const
static constexpr uint64_t maskFull
Definition MCCompLabel.h:53
const GLdouble * v
Definition glcorearb.h:832
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::ostream & operator<<(std::ostream &stream, o2::InteractionRecord const &ir)
Defining DataPointCompositeObject explicitly as copiable.
size_t operator()(o2::MCCompLabel const &label) const
VectorOfTObjectPtrs other