delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
VdHits.cpp
Go to the documentation of this file.
1// VdHitsWriter — pass-1 implementation.
2//
3// PSCVDU: NVDUN unassociated hits, KVDUN/QVDUN(i, n), i=1..5.
4// PSCVDA: per track j (1..MTRACK) NASHT(j) hits, KVDAS/QVDAS(i, j, n).
5// Field i: 1=module#(sign of Z), 2=localX/Z, 3=R(−R if R-Z), 4=RPhi/Z,
6// 5=signal/noise. Position kept cylindrical-mixed (R, slot2, slot4)×10mm.
7
9
10#include <algorithm>
11
12#include "skelana/pscvda.hpp"
13#include "skelana/pscvdu.hpp"
14#include "skelana/pscvec.hpp" // NCVECP (charged-track count)
15
16#include <edm4hep/MutableTrackerHit3D.h>
17#include <edm4hep/TrackerHit3DCollection.h>
18#include <podio/UserDataCollection.h>
19
20#include <cstdint>
21
22namespace sk = skelana;
23
25
26namespace {
27constexpr double kCm2Mm = 10.0;
28
29// Fill a TrackerHit3D from the 5 VD-hit fields (module#, slot2, R, slot4,
30// S/N). Position is the cylindrical-mixed (R, slot2, slot4) triple ×10mm.
31void fillHit(edm4hep::MutableTrackerHit3D hit,
32 int module_signed, float slot2, float R, float slot4, float sn) {
33 hit.setCellID(static_cast<std::uint64_t>(
34 static_cast<std::int64_t>(module_signed)));
35 hit.setType(R < 0.f ? 1 : 0); // R-Z measurement flag
36 hit.setEDep(sn); // signal/noise (no dedicated slot)
37 hit.setPosition({ R * kCm2Mm, slot2 * kCm2Mm, slot4 * kCm2Mm });
38}
39} // namespace
40
42{
43 edm4hep::TrackerHit3DCollection pointsCol; // PSCVDU, unassociated
44 edm4hep::TrackerHit3DCollection hitsCol; // PSCVDA, associated
45 Output out;
46
47 // ---- Unassociated (PSCVDU) ----
48 for (int n = 1; n <= sk::NVDUN; ++n) {
49 fillHit(pointsCol.create(),
50 sk::KVDUN(sk::IVDUMOD, n), sk::QVDUN(sk::IVDUXLC, n),
51 sk::QVDUN(sk::IVDURCO, n), sk::QVDUN(sk::IVDURPH, n),
52 sk::QVDUN(sk::IVDUSTN, n));
53 }
54
55 // ---- Associated (PSCVDA), per charged track j ----
56 // Hits are grouped by the SKELANA charged-track ordinal and handed to
57 // TrackingWriter, which links them onto the track built from the same
58 // ordinal. Keying by the ordinal rather than by an emitted-particle index
59 // is what lets this run BEFORE the track writer: a track is only mutable
60 // while its own writer holds it.
61 //
62 // PSCVDA is per CHARGED track; bound j to the charged-track count (NCVECP),
63 // not the MTRACK array maximum -- stale NASHT slots past the populated
64 // tracks would otherwise emit hits belonging to nothing. The inner loop
65 // clamps to NHIT.
66 const int ntrk = std::min(sk::NCVECP, static_cast<int>(skelana::MTRACK));
67 out.vecp_to_hits.assign(static_cast<std::size_t>(std::max(0, ntrk) + 1), {});
68 for (int j = 1; j <= ntrk; ++j) {
69 const int nhit = sk::NASHT(j);
70 if (nhit <= 0) continue;
71 for (int n = 1; n <= nhit && n <= sk::NHIT; ++n) {
72 auto hit = hitsCol.create();
73 fillHit(hit,
74 sk::KVDAS(sk::IVDAMOD, j, n), sk::QVDAS(sk::IVDAXLC, j, n),
75 sk::QVDAS(sk::IVDARCO, j, n), sk::QVDAS(sk::IVDARPH, j, n),
76 sk::QVDAS(sk::IVDASTN, j, n));
77 out.vecp_to_hits[static_cast<std::size_t>(j)].push_back(hit);
78 }
79 }
80
81 put(std::move(pointsCol), "TDVD", "VDPoints", Provenance::Transcribed);
82 put(std::move(hitsCol), "TDVD", "VDHits", Provenance::Transcribed);
83 ctx_.vd_hits = std::move(out);
84}
85
86} // namespace delphi_edm4hep::vd_hits
const Coll & put(Coll &&coll, std::string_view bank, std::string_view readable, Provenance prov)
std::vector< std::vector< edm4hep::TrackerHit3D > > vecp_to_hits
Definition VdHitData.h:22