delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
PidExtrasSdst.cpp
Go to the documentation of this file.
1// PidExtrasSdstWriter — pass-1 implementation.
2//
3// Headers (skelana/*.hpp): pschdn (KHAIDN 1..4 + KHAIDT 1..4),
4// pschdr (KHAIDR 1..6), pschde (KHAIDE 1..6), pschdc (KHAIDC 1..6),
5// pscdex (QDEDX(6)=VD dE/dx, KDEDX(7)=n VD hits), pscpi0 (26 fields,
6// int at 5/6/20/21/23, float elsewhere).
7
9
10#include "phdst/uxcom.hpp" // IQ
11#include "phdst/uxlink.hpp" // LDTOP
12#include "skelana/pscdex.hpp"
13#include "skelana/pschdc.hpp"
14#include "skelana/pschde.hpp"
15#include "skelana/pschdn.hpp"
16#include "skelana/pschdr.hpp"
17#include "skelana/pscpi0.hpp"
18#include "skelana/pscvec.hpp" // LVPART, NVECP, NCVECP
19
20#include <edm4hep/MutableParticleID.h>
21#include <edm4hep/ParticleIDCollection.h>
22
23#include <algorithm>
24#include <cstdint>
25#include <initializer_list>
26
27namespace ph = phdst;
28namespace sk = skelana;
29
31
32namespace {
33
34// algorithmType constants; 1..7 and 111 are assigned in ParticleId.cpp.
35constexpr std::int32_t kAlgoDedxVD = 7;
36constexpr std::int32_t kAlgoXnewtag = 41;
37constexpr std::int32_t kAlgoXnewpro = 42;
38constexpr std::int32_t kAlgoRprodo = 43;
39constexpr std::int32_t kAlgoRprode = 44;
40constexpr std::int32_t kAlgoRproco = 45;
41constexpr std::int32_t kAlgoPi0 = 111;
42
43// Value left in a tag SKELANA had no information for.
44constexpr int kNoTag = -1;
45
46// PXDST version at or above which SKELANA runs RPRODE in place of RPRODO.
47constexpr int kRprodeMinPxdst = 333;
48
49// PSCPI0 fields stored as integers (1-based field index); the rest float.
50bool pi0FieldIsInt(int f) {
51 return f == 5 || f == 6 || f == 20 || f == 21 || f == 23;
52}
53
54} // namespace
55
57{
58 // RPRODE superseded RPRODO at PXDST version 333. Both fill KHAIDE; SKELANA
59 // runs whichever matches the version word of the event, so the collection is
60 // named for the one that ran.
61 const bool rprode = ph::LDTOP > 0
62 && ph::IQ(ph::LDTOP + 3) >= kRprodeMinPxdst;
63
64 edm4hep::ParticleIDCollection xnewtagCol, xnewproCol, dedxCol, rprocoCol,
65 dedxVdCol, pi0Col;
66
67 // Emitted on every event, filled or not, so that the collection set of the
68 // output is the same in every event.
69 auto putAll = [&] {
70 put(std::move(xnewtagCol), "XNEWTAG", "RichTags", Provenance::Derived);
71 put(std::move(xnewproCol), "XNEWPRO", "RichTags", Provenance::Derived);
72 put(std::move(dedxCol), rprode ? "RPRODE" : "RPRODO", "DedxTags",
74 put(std::move(rprocoCol), "RPROCO", "CombinedTags", Provenance::Derived);
75 put(std::move(dedxVdCol), "HAID", "dEdxVD", Provenance::Transcribed);
76 put(std::move(pi0Col), "PHOT", "Pi0ID", Provenance::Transcribed);
77 };
78
79 if (!ctx_.tracking) { putAll(); return; }
80 const auto& tracking = *ctx_.tracking;
81
82 // Attach a PID row to the Particle built from the same VECP slot.
83 auto bind = [&](edm4hep::MutableParticleID pid, int i) {
84 if (i >= static_cast<int>(tracking.vecp_to_particle.size())) return;
85 const int p = tracking.vecp_to_particle[i];
86 if (p >= 0) pid.setParticle(tracking.particle_handles[p]);
87 };
88
89 // Add one row of tags for track i. SKELANA leaves -1 in every tag it had no
90 // information for, so a row with nothing but -1 carries no result and is
91 // dropped.
92 auto putTags = [&](edm4hep::ParticleIDCollection& coll, std::int32_t algo,
93 std::initializer_list<int> tags, int i) {
94 if (std::all_of(tags.begin(), tags.end(),
95 [](int t) { return t == kNoTag; })) return;
96 auto pid = coll.create();
97 pid.setAlgorithmType(algo);
98 for (int t : tags) pid.addToParameters(static_cast<float>(t));
99 bind(pid, i);
100 };
101
102 // PSCVEC orders charged particles first; these commons are charged-only.
103 for (int i = sk::LVPART; i <= sk::NCVECP; ++i) {
104 if (i >= static_cast<int>(tracking.vecp_to_particle.size())) break;
105 if (tracking.vecp_to_particle[i] < 0) continue;
106
107 // RICH gas and liquid tags from the Cherenkov angle, photon count and
108 // quality flag, with no outer-detector or FCB requirement. KHAIDT holds
109 // the track-quality acceptance belonging to each KHAIDN tag.
110 putTags(xnewtagCol, kAlgoXnewtag,
111 {sk::KHAIDN(1, i), sk::KHAIDN(2, i), sk::KHAIDN(3, i), sk::KHAIDN(4, i),
112 sk::KHAIDT(1, i), sk::KHAIDT(2, i), sk::KHAIDT(3, i), sk::KHAIDT(4, i)}, i);
113
114 // RICH tags from the RIBMEAN gas and liquid probabilities, with no
115 // tracking requirement. KHAIDR(6) is a selection flag: bit 1 liquid OK,
116 // bit 2 gas OK.
117 putTags(xnewproCol, kAlgoXnewpro,
118 {sk::KHAIDR(1, i), sk::KHAIDR(2, i), sk::KHAIDR(3, i),
119 sk::KHAIDR(4, i), sk::KHAIDR(5, i), sk::KHAIDR(6, i)}, i);
120
121 // Tags from the TPC dE/dx probabilities. KHAIDE(6) is 1 when the track had
122 // more than 30 TPC wires and sat within 2.5 s.d. of a hypothesis.
123 putTags(dedxCol, rprode ? kAlgoRprode : kAlgoRprodo,
124 {sk::KHAIDE(1, i), sk::KHAIDE(2, i), sk::KHAIDE(3, i),
125 sk::KHAIDE(4, i), sk::KHAIDE(5, i), sk::KHAIDE(6, i)}, i);
126
127 // Tags from the RICH and dE/dx probabilities combined. KHAIDC(6) is the
128 // selection flag of both: bit 1 liquid OK, bit 2 gas OK, bit 3 TPC OK.
129 putTags(rprocoCol, kAlgoRproco,
130 {sk::KHAIDC(1, i), sk::KHAIDC(2, i), sk::KHAIDC(3, i),
131 sk::KHAIDC(4, i), sk::KHAIDC(5, i), sk::KHAIDC(6, i)}, i);
132
133 // VD-only dE/dx, distinct from the TPC dE/dx in sDST_HAID_dEdx.
134 const int nVD = sk::KDEDX(7, i);
135 if (nVD > 0) {
136 auto pid = dedxVdCol.create();
137 pid.setAlgorithmType(kAlgoDedxVD);
138 pid.addToParameters(sk::QDEDX(6, i)); // VD dE/dx
139 pid.addToParameters(static_cast<float>(nVD)); // n VD hits
140 bind(pid, i);
141 }
142 }
143
144 // π⁰→γγ HPCANA fit — scan the full VECP range; emit where a fit exists.
145 if (sk::NPI0 > 0) {
146 for (int i = sk::LVPART; i <= sk::NVECP; ++i) {
147 if (i >= static_cast<int>(tracking.vecp_to_particle.size())) break;
148 if (tracking.vecp_to_particle[i] < 0) continue;
149 if (sk::QPI0(1, i) <= 0.f) continue; // no fit mass
150 auto pid = pi0Col.create();
151 pid.setAlgorithmType(kAlgoPi0);
152 for (int f = 1; f <= 26; ++f) {
153 pid.addToParameters(pi0FieldIsInt(f)
154 ? static_cast<float>(sk::KPI0(f, i))
155 : sk::QPI0(f, i));
156 }
157 bind(pid, i);
158 }
159 }
160
161 putAll();
162}
163
164} // namespace delphi_edm4hep::pid_extras_sdst
const Coll & put(Coll &&coll, std::string_view bank, std::string_view readable, Provenance prov)
Definition PaWalk.h:21