delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
BtagCheckDomains.h
Go to the documentation of this file.
1// BtagCheckDomains.h -- pure domain predicates used by delphi_btag_check.
2//
3// Keep these independent of podio/EDM4hep so the corruption boundaries can be
4// unit-tested without opening a ROOT file.
5
6#pragma once
7
8#include <cmath>
9#include <cstddef>
10#include <cstdint>
11#include <string_view>
12
14
15inline constexpr int kPrimaryVertexAlgorithmType = 3;
16inline constexpr int kMaxTracks = 100;
17inline constexpr int kMaxPrimaryVertexNdf = 2 * kMaxTracks;
18inline constexpr std::int32_t kMaxVdHits = 6;
19inline constexpr std::int32_t kMaxVdLayers = 3;
20// AABTAG array caps, from AabtagCommons.h: NJET <= 10 jets, and INSV holds a
21// secondary-vertex hypothesis index (<= 20) optionally offset by 100.
22inline constexpr std::int32_t kMaxJets = 10;
23inline constexpr std::int32_t kMaxSvHypotheses = 20;
24inline constexpr std::int32_t kMaxInsv = kMaxSvHypotheses + 100;
25
26/// Slot layout of the `AABTAG_TrackTag` `parameters` VectorMember.
27///
28/// Every slot here that refers to the primary vertex means AABTAG's own,
29/// emitted as `AABTAG_PrimaryVertex`, not `PV_PrimaryVertex`.
30///
31/// EDM4hep types `parameters` as a bare float vector, so slot meanings and
32/// units are convention: declared once here, appended in this order by
33/// `Btag.cpp`, read by name by `delphi_btag_check`, with `kTrCount` keeping
34/// the two in step. Slots [0..10] come from AABTGS / AASIGN, [11..21] from
35/// AAJETS / AASCND / AAJESV; the DELPHI mnemonic locates each in
36/// `aabtagxx.car`. Unmarked slots are dimensionless.
37///
38/// @collection{AABTAG_TrackTag}
39enum TrackTagIndex : std::size_t {
40 kTrProb = 0, ///< `TRPR` lifetime probability
41 kTrProbZ, ///< `TRPRZ` the same, using z
42 kTrChi2Vd, ///< `CHI2VD` chi2 of the VD hits on the track
43 kTrChi2Tr, ///< `CHI2TR` track-to-vertex chi2; NaN unless #kTrAttached
44 kTrMomentum, ///< `PMOM` track momentum, GeV
45 kTrNVdp, ///< `NVDP` VD hits
46 kTrNVdpz, ///< `NVDPZ` of which carry z
47 kTrNLay, ///< `NLAY` VD layers touched
48 kTrNLayz, ///< `NLAYZ` of which carry z
49 kTrIsrt, ///< `ISRT` 0 if the track was not used by the tag
50 kTrAttached, ///< 1 if AABTAG attached the track to its primary vertex
51 kTrIjet, ///< `IJET` `AABTAG_CombinedTagRow` row, 1-based
52 kTrIthr, ///< `ITHR` thrust hemisphere (1 or 2)
53 kTrPhivSign, ///< sign of `PHIV`, exactly +1 or -1; the sign of the
54 ///< impact parameter, valid on every row
55 kTrPhivDist, ///< `PHIV` as a length: signed distance along the jet axis
56 ///< from AABTAG's primary vertex to the track's point of
57 ///< closest approach to that axis, mm; NaN on exactly the
58 ///< rows where #kTrDistj is NaN, where AASGNT left only a sign
59 kTrRpdt, ///< `RPDT` track rapidity with respect to its jet
60 kTrDistj, ///< `DISTJ` 3-D track-jet distance, mm; NaN if not computed
61 kTrErrtj, ///< `ERRTJ` error on #kTrDistj, mm; NaN on the same rows
62 kTrInsv, ///< `INSV` SV hypothesis using the track (+100 flags)
63 kTrIst, ///< `IST` track-quality code (AASTRK / AASLCT / AAIMPC)
64 kTrIjsv, ///< `IJSV` jet after the SV redefinition
65 kTrIlund, ///< `ILUND` index into LUTHRU's JETSET record, which is not
66 ///< shipped: only != 0 is meaningful, saying the track
67 ///< entered the thrust and oblateness calculation
68 kTrCount ///< number of slots; the expected `parameters` size
69};
70
71inline bool isSelectedPayloadName(std::string_view name,
72 std::string_view source) {
73 if (!name.starts_with(source)) return false;
74 name.remove_prefix(source.size());
75 return name.starts_with("_BTG_") || name.starts_with("_AABTAG_");
76}
77
78inline bool isFinite(float value) { return std::isfinite(value); }
79inline bool isFinite(double value) { return std::isfinite(value); }
80
81inline bool isPositiveFinite(float value) {
82 return isFinite(value) && value > 0.f;
83}
84
85inline bool isNonnegativeFinite(float value) {
86 return isFinite(value) && value >= 0.f;
87}
88
89inline bool isSensiblePrimaryVertexNdf(int value) {
90 return value >= 0 && value <= kMaxPrimaryVertexNdf;
91}
92
93// ISRT is a nonnegative DELPHI category code, not a boolean. Values such as
94// 101/201 are present in valid v94c output.
95inline bool isValidUsedForTag(std::int32_t value) { return value >= 0; }
96
97inline bool isValidAttachedFlag(std::int32_t value) {
98 return value == 0 || value == 1;
99}
100
101// A jet index, or 0 where AABTAG assigned none.
102inline bool isValidJetIndex(std::int32_t value) {
103 return value >= 0 && value <= kMaxJets;
104}
105
106// ITHR is 1 or 2, or 0 before AATHRS has assigned a hemisphere.
107inline bool isValidHemisphere(std::int32_t value) {
108 return value >= 0 && value <= 2;
109}
110
111// INSV is +-hypothesis, optionally +-100 to flag a track used in the fit.
112inline bool isValidInsv(std::int32_t value) {
113 const auto wide = static_cast<std::int64_t>(value);
114 return (wide < 0 ? -wide : wide) <= static_cast<std::int64_t>(kMaxInsv);
115}
116
117// Every value IST takes in aabtagxx.car: AASTRK's initial -99; AASLCT's -90 /
118// -99 / -98 and its 99 for a track outside the user list; AAIMPC's 10; and
119// AAK0LS's V0 daughter codes. Listed from the assignment sites rather than
120// from observed data, so a value outside this set really is corruption.
121inline bool isValidTrackStatus(std::int32_t value) {
122 switch (value) {
123 case -99: case -98: case -90: case 10:
124 case 99: case 200: case 300: case 400:
125 return true;
126 default:
127 return false;
128 }
129}
130
131// The sign slot is exactly +-1 by construction, on every row.
132inline bool isUnitSign(float value) { return value == 1.f || value == -1.f; }
133
134// PHIV's length and the track-jet distance are a measurement or a placeholder
135// together: AASGNT fills or abandons them in the same branch, so a row where
136// one is NaN and the other is not means the pair has come apart.
137inline bool isConsistentPlaceholder(float phivDist, float distj) {
138 return std::isnan(phivDist) == std::isnan(distj);
139}
140
141// The legacy VD count arrays may be negated to mark a rejected track. Avoid
142// abs(INT_MIN) overflow by widening before taking the magnitude.
143inline bool isValidSignedCount(std::int32_t value, std::int32_t maximum) {
144 const auto wide = static_cast<std::int64_t>(value);
145 const auto magnitude = wide < 0 ? -wide : wide;
146 return magnitude <= static_cast<std::int64_t>(maximum);
147}
148
149} // namespace delphi_edm4hep::btag::check
bool isValidAttachedFlag(std::int32_t value)
constexpr int kPrimaryVertexAlgorithmType
bool isValidHemisphere(std::int32_t value)
constexpr std::int32_t kMaxVdLayers
constexpr std::int32_t kMaxInsv
bool isSelectedPayloadName(std::string_view name, std::string_view source)
bool isNonnegativeFinite(float value)
bool isValidSignedCount(std::int32_t value, std::int32_t maximum)
constexpr std::int32_t kMaxVdHits
constexpr std::int32_t kMaxJets
constexpr std::int32_t kMaxSvHypotheses
bool isValidJetIndex(std::int32_t value)
bool isConsistentPlaceholder(float phivDist, float distj)
bool isValidUsedForTag(std::int32_t value)
bool isValidInsv(std::int32_t value)
bool isValidTrackStatus(std::int32_t value)
bool isSensiblePrimaryVertexNdf(int value)
@ kTrInsv
INSV SV hypothesis using the track (+100 flags)
@ kTrIthr
ITHR thrust hemisphere (1 or 2)
@ kTrProbZ
TRPRZ the same, using z
@ kTrIsrt
ISRT 0 if the track was not used by the tag
@ kTrErrtj
ERRTJ error on kTrDistj, mm; NaN on the same rows
@ kTrAttached
1 if AABTAG attached the track to its primary vertex
@ kTrChi2Tr
CHI2TR track-to-vertex chi2; NaN unless kTrAttached
@ kTrProb
TRPR lifetime probability
@ kTrCount
number of slots; the expected parameters size
@ kTrNLayz
NLAYZ of which carry z
@ kTrIjsv
IJSV jet after the SV redefinition
@ kTrChi2Vd
CHI2VD chi2 of the VD hits on the track
@ kTrIst
IST track-quality code (AASTRK / AASLCT / AAIMPC)
@ kTrNLay
NLAY VD layers touched
@ kTrRpdt
RPDT track rapidity with respect to its jet
@ kTrDistj
DISTJ 3-D track-jet distance, mm; NaN if not computed
@ kTrMomentum
PMOM track momentum, GeV
@ kTrNVdpz
NVDPZ of which carry z
@ kTrIjet
IJET AABTAG_CombinedTagRow row, 1-based
bool isPositiveFinite(float value)