delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
PaWalk.h
Go to the documentation of this file.
1// PaWalk.h — internal header (not exported).
2//
3// Helpers for walking the per-event PA chain (LDTOP-1 -> per-PV -> per-PA)
4// and looking up named PA sub-banks via the SKELANA LPHPA Fortran function.
5// Used by Tracking, Calorimeter, ParticleId — wherever bank-level reads
6// are needed.
7//
8// Intentionally NOT in include/delphi_edm4hep/: these are implementation
9// details that touch the PHDST commons directly. Public callers go
10// through the per-domain entry points.
11
12#pragma once
13
14#include "phdst/functions.hpp"
15#include "phdst/uxcom.hpp"
16#include "phdst/uxlink.hpp"
17
18#include <cmath>
19#include <cstring>
20
21namespace phdst {
22 // Fortran "integer function iphreq(nump)". Returns auxiliary info
23 // (typically the length of the last-resolved PA sub-bank) set by the
24 // most recent LPHPA/LPHPAN call. NUMP=1 → bank length in words.
25 extern "C" int iphreq_(int* nump);
26}
27
29
30// SKELANA LPHPA wrapper: get the L-address of a named PA sub-bank.
31// Returns 0 if the sub-bank isn't present in this PA. `nump` defaults
32// to 0 (the standard "first occurrence" lookup that matches the
33// long-form `Q(LPHPA('NAME', lpa) + N)` idiom in the legacy converter).
34inline int lphpa(const char* iddp, int lpa, int nump = 0) {
35 int lpa_arg = lpa;
36 int nump_arg = nump;
37 return phdst::lphpa_(iddp, &lpa_arg, &nump_arg, std::strlen(iddp));
38}
39
40// IPHREQ wrapper: bank length of the most-recent LPHPA result (in
41// words). Pass nump=1 for the standard length query.
42inline int iphreq(int nump = 1) {
43 int n = nump;
44 return phdst::iphreq_(&n);
45}
46
47// Charge from PA.MAIN word +8 (the DELPHI charge code: 1 positive,
48// 2 negative); 0 for neutral or undefined. Used to restore the sign of
49// momentum words DELPHI stores unsigned.
50inline int trueCharge(int lpa) {
51 const int lmain = lphpa("MAIN", lpa);
52 if (lmain <= 0) return 0;
53 const int code = static_cast<int>(std::lround(phdst::Q(lmain + 8)));
54 if (code == 1) return +1;
55 if (code == 2) return -1;
56 return 0;
57}
58
59// Walk every PA in the current event. Calls `fn(lpa, paIdx)` for each
60// PA where `lpa` is the ZEBRA L-address of the PA bank and `paIdx` is
61// a 0-based running counter across all PVs (does NOT reset per PV).
62//
63// The same PA ordering is used by every domain — so the paIdx -> Particle
64// mapping in tracking::Output (`pa_to_particle`) is shared across
65// Tracking, Calorimeter, and ParticleId.
66template <class F>
67void forEachPA(F&& fn) {
68 const int LDTOP = phdst::LDTOP;
69 if (LDTOP <= 0) return;
70 int paIdx = 0;
71 for (int lpv = phdst::LQ(LDTOP - 1); lpv > 0; lpv = phdst::LQ(lpv)) {
72 for (int lpa = phdst::LQ(lpv - 1); lpa > 0;
73 lpa = phdst::LQ(lpa), ++paIdx) {
74 fn(lpa, paIdx);
75 }
76 }
77}
78
79} // namespace delphi_edm4hep::pawalk
void forEachPA(F &&fn)
Definition PaWalk.h:67
int trueCharge(int lpa)
Definition PaWalk.h:50
int lphpa(const char *iddp, int lpa, int nump=0)
Definition PaWalk.h:34
int iphreq(int nump=1)
Definition PaWalk.h:42
Definition PaWalk.h:21
int iphreq_(int *nump)