delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
PaPidExtras.cpp
Go to the documentation of this file.
1// PaPidExtrasWriter — implementation. Runs in both passes.
2//
3// Bank layouts (verified against the legacy delphi_fdst_pad_dump readers):
4//
5// PA.MU (label 4):
6// +2 detector id (14=MUB, 17=MUS, 30=MUF)
7// +3 nlay +4 ndof +5 chi2 (global)
8// +6 x_first +7 y_first +8 hit_pattern (MUB bitmask)
9// +9 chi2_alone +10 x_extrap +11 y_extrap
10// +12 theta_extrap +13 phi_extrap
11//
12// PA.EL (label 5): header only
13// +2 packed = shower_len + 100*detector_id -> det = Q(+2)/100
14// +3 packed = shower_num + 10*length -> nshow = Q(+3)/10
15//
16// PA.TDID (label 17): fixed 26 words
17// +2 jet_sector (signed)
18// +3..+26 24 raw drift times -> aggregate (n_valid>0, sum)
19
21
23
24#include <edm4hep/MutableParticleID.h>
25#include <edm4hep/ParticleIDCollection.h>
26#include <edm4hep/ReconstructedParticleCollection.h>
27
28#include <cmath>
29#include <cstdint>
30
31namespace ph = phdst;
32
34
35namespace {
36constexpr std::int32_t kAlgoMu = 4;
37constexpr std::int32_t kAlgoEl = 5;
38constexpr std::int32_t kAlgoTdid = 17;
39} // namespace
40
42{
43 edm4hep::ParticleIDCollection muCol;
44 edm4hep::ParticleIDCollection elCol;
45 edm4hep::ParticleIDCollection tdidCol;
46
47
48 pawalk::forEachPA([&](int lpa, int paIdx) {
49 const auto particle = particleForPa(paIdx);
50 if (!particle) return;
51
52 // ---- PA.MU (muon-chamber refit summary) ----
53 if (const int lmu = pawalk::lphpa("MU", lpa); lmu > 0) {
54 auto pid = muCol.create();
55 pid.setAlgorithmType(kAlgoMu);
56 for (int off = 2; off <= 13; ++off) pid.addToParameters(ph::Q(lmu + off));
57 pid.setParticle(*particle);
58 }
59
60 // ---- PA.EL (electron extra-module header) ----
61 if (const int lel = pawalk::lphpa("EL", lpa); lel > 0) {
62 const int det = static_cast<int>(std::lround(ph::Q(lel + 2))) / 100;
63 const int nshow = static_cast<int>(std::lround(ph::Q(lel + 3))) / 10;
64 auto pid = elCol.create();
65 pid.setAlgorithmType(kAlgoEl);
66 pid.addToParameters(static_cast<float>(det));
67 pid.addToParameters(static_cast<float>(nshow));
68 pid.setParticle(*particle);
69 }
70
71 // ---- PA.TDID (ID drift-time calibration) ----
72 if (const int ltdid = pawalk::lphpa("TDID", lpa); ltdid > 0) {
73 const float jet_sector = ph::Q(ltdid + 2);
74 int n_valid = 0;
75 float drift_sum = 0.f;
76 for (int k = 0; k < 24; ++k) {
77 const float d = ph::Q(ltdid + 3 + k);
78 if (d > 0.f) { ++n_valid; drift_sum += d; }
79 }
80 auto pid = tdidCol.create();
81 pid.setAlgorithmType(kAlgoTdid);
82 pid.addToParameters(jet_sector);
83 pid.addToParameters(static_cast<float>(n_valid));
84 pid.addToParameters(drift_sum);
85 pid.setParticle(*particle);
86 }
87 });
88
89 put(std::move(muCol), "MU", "MuonChambers", Provenance::Transcribed);
90 put(std::move(elCol), "EL", "ElectronExtra", Provenance::Transcribed);
91 put(std::move(tdidCol), "TDID", "DriftCalib", Provenance::Transcribed);
92}
93
94} // namespace delphi_edm4hep::pa_pid_extras
std::optional< edm4hep::ReconstructedParticle > particleForPa(int paIdx) const
const Coll & put(Coll &&coll, std::string_view bank, std::string_view readable, Provenance prov)
void forEachPA(F &&fn)
Definition PaWalk.h:67
int lphpa(const char *iddp, int lpa, int nump=0)
Definition PaWalk.h:34
Definition PaWalk.h:21