delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
Event.cpp
Go to the documentation of this file.
1// EventWriter — implementation.
2//
3// Reads per-event scalars from the SKELANA / PHDST commons populated by PSBEG
4// and writes them into the Frame as named parameters under "<source>_EVT_*".
5// No bank walking — pure common-block reads.
6//
7// The parameters fall into three groups by origin, declared separately below:
8// values copied from the DST pilot record, values SKELANA counts or sums for
9// itself, and the beam spot, which comes from an external database rather
10// than from the DST at all.
11
14
15#include "phdst/functions.hpp" // IPHPIC
16#include "phdst/phciii.hpp"
17#include "phdst/uxcom.hpp" // IQ
18#include "phdst/uxlink.hpp" // LDTOP
19#include "skelana/pscbsp.hpp"
20#include "skelana/pscevt.hpp"
21
22#include <cstddef>
23#include <limits>
24#include <stdexcept>
25#include <string>
26
27// PHGEN BPILOT subroutine (current event's solenoid B in Tesla,
28// curvature-to-momentum factor in GeV/cm). No header wrapper.
29extern "C" void bpilot_(float* btesla, float* bgevcm);
30
31// DSTQID (dstana) returns the DST processing identifier as "YYLN": two-digit
32// year, DELANA processing letter, short/mini DST number. gfortran passes the
33// character length as a hidden trailing argument.
34extern "C" void dstqid_(char* tag, std::size_t len);
35
36namespace ph = phdst;
37namespace sk = skelana;
38
39namespace {
40std::string processingTag() {
41 char buf[4] = {};
42 dstqid_(buf, sizeof(buf));
43 std::string tag(buf, sizeof(buf));
44 tag.erase(tag.find_last_not_of(' ') + 1);
45 return tag;
46}
47
48// Refuse the event, naming it. A writer that throws aborts the job through the
49// harness's callback guard, which marks the partial output unpublishable.
50[[noreturn]] void refuse(const std::string& what) {
51 throw std::runtime_error(what + " (run " + std::to_string(ph::IIIRUN)
52 + ", event " + std::to_string(ph::IIIEVT) + ')');
53}
54
55// The beam energy has a failure mode SKELANA does not report: it substitutes a
56// value and carries on, and the substitute reaches the output looking like a
57// measurement. (The beam spot's is handled in internal/BeamSpotStatus.h.)
58void checkEventIsUsable() {
59 // Without the DANA pilot blocklet the centre-of-mass energy is not read but
60 // set to 91.250 GeV (skelana.car:2743-2748). That substitution cannot be
61 // recognised from the energy itself — 91.250 is also the true stored value
62 // for LEP1 simulation — so test for the blocklet.
63 if (ph::IPHPIC("DANA", 0) <= 0) {
64 refuse("DANA pilot blocklet absent, so the centre-of-mass energy would be "
65 "SKELANA's 91.250 GeV fallback rather than a stored value");
66 }
67
68 // EBEAM = ECMAS/2 is both a track cut and a denominator in SKELANA; at zero
69 // it rejects every charged track.
70 if (sk::ECMAS <= 0.f) {
71 refuse("centre-of-mass energy is " + std::to_string(sk::ECMAS) + " GeV");
72 }
73}
74} // namespace
75
76namespace delphi_edm4hep::event {
77
79 checkEventIsUsable();
80
81 constexpr float kCm2Mm = 10.0f;
82
83 // Pilot-record words, written when the DST was produced.
84 auto stored = parameters("EVT", Provenance::Transcribed);
85 stored("runNumber", ph::IIIRUN);
86 stored("eventNumber", ph::IIIEVT);
87 stored("fileSeq", ph::IIFILE);
88 stored("date", ph::IIIDAT); // yymmdd
89 stored("time", ph::IIITIM); // hhmmss
90 stored("fillNumber", ph::IIFILL);
91 stored("experiment", ph::IIIEXP);
92 stored("dstVersion", sk::ISVER);
93
94 // Era identifiers. The processing tag selects the calibration SKELANA uses —
95 // its first two characters pick the RICH refractive index — and the PXDST
96 // version selects between algorithm generations.
97 stored("dstProcessingTag", processingTag());
98 stored("pxdstVersion", ph::LDTOP > 0 ? ph::IQ(ph::LDTOP + 3) : 0);
99
100 // Centre-of-mass energy from the DANA pilot blocklet. SKELANA substitutes
101 // 91.250 GeV when that blocklet is absent, which at LEP2 would be wrong by
102 // more than a factor of two; check BeamSpotErrorCode and the energy itself
103 // before relying on it.
104 stored("ECMS", sk::ECMAS);
105
106 // Per-event solenoid field and the curvature-to-momentum factor, both from
107 // the pilot record. pT [GeV/c] = BFieldGevPerCm / |omega_DELPHI [1/cm]|.
108 float btesla = 0.f, bgevcm = 0.f;
109 bpilot_(&btesla, &bgevcm);
110 stored("BField", btesla);
111 stored("BFieldGevPerCm", bgevcm);
112
113 // Multiplicities and summed energies counted by SKELANA over the PA chain
114 // under cuts hard-coded in PSHEVT — a momentum, track-length, impact-
115 // parameter and polar-angle selection independent of IFLCUT and of the
116 // LVLOCK track selection. Two events with the same nCharged can therefore
117 // disagree with a count made from MAIN_Particles and LVLOCK.
118 auto counted = parameters("EVT", Provenance::Derived);
119 counted("hadronicTagTeam4", sk::IHAD4);
120 counted("nChargedTeam4", sk::NCTR4);
121 counted("nCharged", sk::NCTRK);
122 counted("nNeutral", sk::NNTRK);
123 counted("EChargedTotal", sk::ECHAR);
124 counted("ENeutralEM", sk::EMNEU);
125 counted("ENeutralHad", sk::EHNEU);
126
127 // Beam spot from the per-processing database under $DELPHI_DAT, selected by
128 // the DSTQID tag and looked up per run and file — not from the DST. For
129 // simulation it is instead the generated interaction point plus a Gaussian
130 // smear, so it follows the event rather than describing a beam. Without a
131 // usable entry (BeamSpotErrorCode 2) position and widths are NaN.
132 const bool usable = beamspot::positionUsable(sk::IERRBS);
133 auto bs = [&](float cm) {
134 return usable ? cm * kCm2Mm : std::numeric_limits<float>::quiet_NaN();
135 };
137 beamspot("BeamSpotX", bs(sk::XYZBS(1)));
138 beamspot("BeamSpotY", bs(sk::XYZBS(2)));
139 beamspot("BeamSpotZ", bs(sk::XYZBS(3)));
140 beamspot("BeamSpotSigmaX", bs(sk::DXYZBS(1)));
141 beamspot("BeamSpotSigmaY", bs(sk::DXYZBS(2)));
142 beamspot("BeamSpotSigmaZ", bs(sk::DXYZBS(3)));
143 beamspot("BeamSpotErrorCode", sk::IERRBS);
144}
145
146} // namespace delphi_edm4hep::event
void bpilot_(float *btesla, float *bgevcm)
void dstqid_(char *tag, std::size_t len)
ParameterGroup parameters(std::string_view bank, Provenance prov)
constexpr bool positionUsable(int errorCode)
Definition PaWalk.h:21