delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
Tdha.cpp
Go to the documentation of this file.
1// TdhaWriter — implementation. Runs in both passes.
2//
3// PA.TDHA (label 11) layout (longdes §3.04, verified vs the legacy
4// delphi_fdst_pad_dump TDHA reader):
5// +2 nlay (number of HCAL layers)
6// per-layer record (variable, first at ofs=ltdha+2):
7// +1 layer_len +2 lnum +3 loc (0=barrel,1=endcap)
8// +4 X/R +5 Y/Rφ +6 Z (extrap coords)
9// +9 ntd (n associated TDs in this layer)
10// per-TD (4 words, TD it at base=ofs+9+4*it):
11// base+1 X/R, base+2 Y/Rφ, base+3 Z, base+4 energy
12// next layer at ofs += layer_len.
13
15
17
18#include <edm4hep/CalorimeterHitCollection.h>
19#include <edm4hep/MutableCalorimeterHit.h>
20
21#include <cmath>
22#include <cstdint>
23
24namespace ph = phdst;
25
26namespace delphi_edm4hep::tdha {
27
28namespace {
29constexpr float kCm2Mm = 10.f;
30constexpr int kMaxLayerLen = 200;
31constexpr int kMaxNtd = 200;
32} // namespace
33
35{
36 edm4hep::CalorimeterHitCollection col;
37
38 pawalk::forEachPA([&](int lpa, int /*paIdx*/) {
39 const int ltdha = pawalk::lphpa("TDHA", lpa);
40 if (ltdha <= 0) return;
41 const int nlay = static_cast<int>(std::lround(ph::Q(ltdha + 2)));
42 if (nlay <= 0) return;
43
44 int ofs = ltdha + 2;
45 for (int il = 0; il < nlay && ofs > ltdha; ++il) {
46 const int layer_len = static_cast<int>(std::lround(ph::Q(ofs + 1)));
47 if (layer_len <= 0 || layer_len > kMaxLayerLen) break;
48 const int lnum = static_cast<int>(std::lround(ph::Q(ofs + 2)));
49 const int loc = static_cast<int>(std::lround(ph::Q(ofs + 3)));
50 const int ntd = static_cast<int>(std::lround(ph::Q(ofs + 9)));
51
52 if (ntd > 0 && ntd < kMaxNtd) {
53 for (int it = 0; it < ntd; ++it) {
54 const int base = ofs + 9 + 4 * it;
55 const float c1 = ph::Q(base + 1); // X (endcap) / R (barrel)
56 const float c2 = ph::Q(base + 2); // Y (endcap) / Rφ (barrel)
57 const float z = ph::Q(base + 3);
58 const float e = ph::Q(base + 4);
59
60 float x = c1, y = c2;
61 if (loc == 0 && c1 > 0.f) { // barrel: R/Rφ → cartesian
62 const float phi = c2 / c1;
63 x = c1 * std::cos(phi);
64 y = c1 * std::sin(phi);
65 }
66
67 auto hit = col.create();
68 hit.setEnergy(e);
69 hit.setEnergyError(0.f);
70 hit.setTime(0.f); // no per-hit time at DST level
71 hit.setType(lnum); // HCAL layer number
72 hit.setCellID(static_cast<std::uint64_t>(loc));
73 hit.setPosition({ x * kCm2Mm, y * kCm2Mm, z * kCm2Mm });
74 }
75 }
76 ofs += layer_len;
77 }
78 });
79
80 put(std::move(col), "TDHA", "HcalTimeHits", Provenance::Transcribed);
81}
82
83} // namespace delphi_edm4hep::tdha
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