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)
56 {
57 // a negative trackID means no MC particle is attached to this signal;
58 // the label stays unset rather than encoding a track that does not exist
59 if (trackID >= 0) {
60 set(trackID, evID, srcID, fake);
61 }
62 }
63 MCCompLabel(bool noise = false)
64 {
65 if (noise) {
66 mLabel = Noise;
67 } else {
68 mLabel = NotSet;
69 }
70 }
71 ~MCCompLabel() = default;
72
73 // check if label was assigned
74 bool isSet() const { return mLabel != NotSet; }
75 // check if label was not assigned
76 bool isEmpty() const { return mLabel == NotSet; }
77 // check if label comes from QED contrib
78 bool isQED() const { return getSourceID() == 99; }
79 // check if label corresponds to real particle (for the moment QED is not included)
80 bool isNoise() const { return mLabel == Noise || isQED(); }
81 // check if label was assigned as for correctly identified particle
82 bool isValid() const { return isSet() && !isNoise(); }
83
84 // check if label was assigned as for incorrectly identified particle or not set or noise
85 bool isFake() const { return mLabel & Fake; }
86 // check if label was assigned as for correctly identified particle
87 bool isCorrect() const { return !isFake(); }
88
89 // return 1 if the tracks are the same and correctly identified
90 // 0 if the tracks are the same but at least one of them is fake
91 // -1 otherwhise
92 int compare(const MCCompLabel& other) const
93 {
94 if (getEventID() != other.getEventID() || getSourceID() != other.getSourceID()) {
95 return -1;
96 }
97 int tr1 = getTrackID(), tr2 = other.getTrackID();
98 return (tr1 == tr2) ? ((isCorrect() && other.isCorrect()) ? 1 : 0) : -1;
99 }
100
101 // allow to retrieve bare label
102 uint64_t getRawValue() const { return mLabel; }
103
104 // comparison operator, compares only label, not eventual weight or correctness info
105 bool operator==(const MCCompLabel& other) const { return (mLabel & maskFull) == (other.mLabel & maskFull); }
106 bool operator!=(const MCCompLabel& other) const { return (mLabel & maskFull) != (other.mLabel & maskFull); }
107 // relation operators needed for some sorting methods
108 bool operator<(const MCCompLabel& other) const { return (mLabel & maskFull) < (other.mLabel & maskFull); }
109 bool operator>(const MCCompLabel& other) const { return (mLabel & maskFull) > (other.mLabel & maskFull); }
110
111 // invalidate
112 void unset() { mLabel = NotSet; }
113 void setNoise() { mLabel = Noise; }
114 void setFakeFlag(bool v = true)
115 {
116 if (v) {
117 mLabel |= Fake;
118 } else {
119 mLabel &= ~Fake;
120 }
121 }
122
123 void set(unsigned int trackID, int evID, int srcID, bool fake)
124 {
126 mLabel = (maskTrackID & static_cast<uint64_t>(trackID)) |
127 (maskEvID & static_cast<uint64_t>(evID)) << nbitsTrackID |
128 (maskSrcID & static_cast<uint64_t>(srcID)) << (nbitsTrackID + nbitsEvID);
129 if (fake) {
130 setFakeFlag();
131 }
132 }
133
134 int getTrackID() const { return static_cast<int>(mLabel & maskTrackID); }
135 int getTrackIDSigned() const { return isFake() ? -getTrackID() : getTrackID(); }
136 int getEventID() const { return (mLabel >> nbitsTrackID) & maskEvID; }
137 int getSourceID() const { return (mLabel >> (nbitsTrackID + nbitsEvID)) & maskSrcID; }
138 uint64_t getTrackEventSourceID() const { return static_cast<uint64_t>(mLabel & maskFull); }
139 void get(int& trackID, int& evID, int& srcID, bool& fake) const
140 {
142 trackID = getTrackID();
143 evID = getEventID();
144 srcID = getSourceID();
145 fake = isFake();
146 }
147
148 void print() const;
149 std::string asString() const;
150
151 static constexpr int maxSourceID() { return maskSrcID; }
152 static constexpr int maxEventID() { return maskEvID; }
153 static constexpr int maxTrackID() { return maskTrackID; }
155};
156
157std::ostream& operator<<(std::ostream& os, MCCompLabel const& c);
158
159} // namespace o2
160
161namespace std
162{
163// defining std::hash for MCCompLabel in order to be used with unordered_maps
164template <>
165struct hash<o2::MCCompLabel> {
166 public:
167 size_t operator()(o2::MCCompLabel const& label) const
168 {
169 return label.getRawValue();
170 }
171};
172} // namespace std
173
174#endif
uint32_t hash
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
uint32_t c
Definition RawData.h:2
uint64_t getRawValue() const
static constexpr int maxTrackID()
bool operator==(const MCCompLabel &other) const
static constexpr int maxSourceID()
bool isFake() const
Definition MCCompLabel.h:85
void setFakeFlag(bool v=true)
bool operator!=(const MCCompLabel &other) const
ClassDefNV(MCCompLabel, 1)
static constexpr uint64_t maskTrackID
Definition MCCompLabel.h:47
MCCompLabel(bool noise=false)
Definition MCCompLabel.h:63
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:87
bool isNoise() const
Definition MCCompLabel.h:80
uint64_t getTrackEventSourceID() const
bool isQED() const
Definition MCCompLabel.h:78
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:74
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:76
bool isValid() const
Definition MCCompLabel.h:82
int compare(const MCCompLabel &other) const
Definition MCCompLabel.h:92
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)
size_t operator()(o2::MCCompLabel const &label) const
VectorOfTObjectPtrs other