delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
Mtpc.cpp
Go to the documentation of this file.
1// MtpcWriter — implementation. Runs in both passes.
2//
3// PA.MTPC v1.04+ layout (shortdes.txt MTPC p.41 / dst_content.txt p.26):
4// Q(LMTPC+1) label (= 7)
5// Q(LMTPC+2) dE/dx 80% truncated mean (MIP-normalised)
6// Q(LMTPC+3) sigma of the 80% truncated Landau
7// Q(LMTPC+4) dE/dx 65% truncated mean
8// Q(LMTPC+5) sigma 65%
9// Q(LMTPC+6) dE/dx integrated 80%
10// Q(LMTPC+7) npads + 100*sec_start + 10000*sec_end
11// Q(LMTPC+8) nwires + 1000*nhitwires + 1000000*method
12// Q(LMTPC+10) saturated + 1000*empty
13// Q(LMTPC+15) V0 pad-row pattern (16+4 bits)
14
16
18
19#include <edm4hep/MutableParticleID.h>
20#include <edm4hep/MutableRecDqdx.h>
21#include <edm4hep/ParticleIDCollection.h>
22#include <edm4hep/Quantity.h>
23#include <edm4hep/RecDqdxCollection.h>
24#include <edm4hep/ReconstructedParticleCollection.h>
25
26#include <cmath>
27#include <cstdint>
28
29namespace ph = phdst;
30
31namespace delphi_edm4hep::mtpc {
32
33namespace {
34constexpr std::int32_t kAlgoMtpcExt = 6;
35}
36
38{
39 edm4hep::ParticleIDCollection pid_col;
40 edm4hep::RecDqdxCollection dqdx_col;
41
42 pawalk::forEachPA([&](int lpa, int paIdx) {
43 const int lmtpc = pawalk::lphpa("MTPC", lpa);
44 if (lmtpc <= 0) return;
45 const auto particle = particleForPa(paIdx);
46 if (!particle) return;
47
48 const float dedx80 = ph::Q(lmtpc + 2);
49 const float sigma80 = ph::Q(lmtpc + 3);
50 const float dedx65 = ph::Q(lmtpc + 4);
51 const float sigma65 = ph::Q(lmtpc + 5);
52 const float dedx_int = ph::Q(lmtpc + 6);
53 const int p7 = static_cast<int>(std::lround(ph::Q(lmtpc + 7)));
54 const int p8 = static_cast<int>(std::lround(ph::Q(lmtpc + 8)));
55 const int p10 = static_cast<int>(std::lround(ph::Q(lmtpc + 10)));
56 const int padpat = static_cast<int>(std::lround(ph::Q(lmtpc + 15)));
57 const int nPads = p7 % 100;
58 const int nWires = p8 % 1000;
59 const int nSat = p10 % 1000;
60 const int nEmpty = p10 / 1000;
61
62 auto pid = pid_col.create();
63 pid.setAlgorithmType(kAlgoMtpcExt);
64 pid.addToParameters(dedx80);
65 pid.addToParameters(sigma80);
66 pid.addToParameters(dedx65);
67 pid.addToParameters(sigma65);
68 pid.addToParameters(dedx_int);
69 pid.addToParameters(static_cast<float>(nPads));
70 pid.addToParameters(static_cast<float>(nWires));
71 pid.addToParameters(static_cast<float>(nSat));
72 pid.addToParameters(static_cast<float>(nEmpty));
73 pid.addToParameters(static_cast<float>(padpat));
74 pid.setParticle(*particle);
75
76 // RecDqdx parallel: type=1 = TPC truncated mean.
77 auto dq = dqdx_col.create();
78 edm4hep::Quantity q;
79 q.type = 1;
80 q.value = dedx80;
81 q.error = sigma80;
82 dq.setDQdx(q);
83 // Link to the track via the fDST Particle's Particle->Track relation
84 // (set by MainHybrid, which runs before this writer). One track per
85 // charged MTPC PA.
86 for (const auto& trk : particle->getTracks()) { dq.setTrack(trk); break; }
87 });
88
89 put(std::move(pid_col), "MTPC", "dEdxExtended", Provenance::Transcribed);
90 put(std::move(dqdx_col), "MTPC", "dEdx_RecDqdx", Provenance::Transcribed);
91}
92
93} // namespace delphi_edm4hep::mtpc
std::optional< edm4hep::ReconstructedParticle > particleForPa(int paIdx) const
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