delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
HcalFdst.cpp
Go to the documentation of this file.
1// HcalFdstWriter — pass-2 implementation.
2//
3// PA.HCAL bank (hacfixxx.car line 805), per shower at show_ofs:
4// +1 len
5// +3 E (shower-level, GeV)
6// +4..+6 X, Y, Z (shower-level centroid, cm)
7// +10 NLAY (number of layers with hits)
8// +11 LAYPAT (layer-hit-pattern bits)
9// +11+1..+11+2*NLAY per-layer (E + ncells+1000*layer)
10// locw = +11+NLAY*2 start of tower block:
11// locw+1 NTD (number of towers)
12// locw+2*k+2 TDAM (tower energy, GeV)
13// locw+2*k+3 LAYLUV (LAY*10000 + JU*100 + JV)
14
16
18
19#include <edm4hep/CalorimeterHitCollection.h>
20#include <edm4hep/MutableCalorimeterHit.h>
21
22#include <cmath>
23#include <cstdint>
24
25namespace ph = phdst;
26
28
29namespace {
30constexpr float kCm2Mm = 10.f;
31}
32
34{
35 edm4hep::CalorimeterHitCollection tow_col;
36
37 pawalk::forEachPA([&](int lpa, int /*paIdx*/) {
38 const int lhcal = pawalk::lphpa("HCAL", lpa);
39 if (lhcal <= 0) return;
40 const int nsh = static_cast<int>(std::lround(ph::Q(lhcal + 2)));
41 if (nsh <= 0) return;
42
43 int show_ofs = lhcal + 2;
44 for (int ish = 0; ish < nsh; ++ish) {
45 const int len = static_cast<int>(std::lround(ph::Q(show_ofs + 1)));
46 const float X = ph::Q(show_ofs + 4);
47 const float Y = ph::Q(show_ofs + 5);
48 const float Z = ph::Q(show_ofs + 6);
49 const int nlay = static_cast<int>(std::lround(ph::Q(show_ofs + 10)));
50
51 if (nlay < 1 || nlay > 10 || len < 11 + 2 * nlay + 1) {
52 if (len <= 0) break;
53 show_ofs += len;
54 continue;
55 }
56
57 const int locw = show_ofs + 11 + nlay * 2;
58 const int ntd = static_cast<int>(std::lround(ph::Q(locw + 1)));
59 if (ntd > 0 && ntd < 1000 &&
60 len >= (locw - show_ofs) + 1 + 2 * ntd) {
61 for (int k = 0; k < ntd; ++k) {
62 const float tdam = ph::Q(locw + 2 + 2 * k);
63 const int pkd = static_cast<int>(std::lround(ph::Q(locw + 3 + 2 * k)));
64 const int lay = pkd / 10000;
65 auto hit = tow_col.create();
66 hit.setEnergy(tdam);
67 hit.setEnergyError(0.f);
68 hit.setTime(0.f);
69 hit.setType(lay); // LAY (1..7)
70 hit.setCellID(static_cast<std::uint64_t>(pkd)); // full packed
71 hit.setPosition({
72 X * kCm2Mm, Y * kCm2Mm, Z * kCm2Mm,
73 });
74 }
75 }
76
77 if (len <= 0) break;
78 show_ofs += len;
79 }
80 });
81
82 put(std::move(tow_col), "HCAL", "Towers", Provenance::Transcribed);
83}
84
85} // namespace delphi_edm4hep::hcal_fdst
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