delphi-edm4hep
DELPHI SDST/FDST -> EDM4hep converter
Loading...
Searching...
No Matches
HpcPadDecoder.h
Go to the documentation of this file.
1// C++ transcription of DELPHI's PXHGET subroutine (Fortran source:
2// /cvmfs/delphi.cern.ch/.../dstana/161018/src/car/pxdst34.car:17828).
3//
4// PXHGET unpacks the 3-word per-pad HPC cluster record that PXHPUT packs
5// at EMCA bank construction time. Each per-pad record is 3 REAL*4 words
6// but the contents are integer bits (Fortran EQUIVALENCE INTG/REAL).
7// Decoded outputs: (E, layer, X, Y, Z, sigma_z) in GeV / [1..10] / cm.
8//
9// Originally lifted verbatim from ild/hpc_pad_decoder.hpp (legacy).
10
11#pragma once
12
13#include <cmath>
14#include <cstdint>
15
17
18inline void padDecode(std::int32_t i1, std::int32_t i2, std::int32_t i3,
19 float w1, float w2, float w3,
20 float& E, int& layer,
21 float& X, float& Y, float& Z, float& sigZ) {
22 // PXHGET runtime decision: bit-interpretation if INTG in [0, 1e7];
23 // else "old" format with NINT of the REAL value.
24 int IPACK1, IPACK2, IPACK3;
25 if (i1 < 0 || i1 > 10000000) {
26 IPACK1 = static_cast<int>(std::lround(w1));
27 IPACK2 = static_cast<int>(std::lround(w2));
28 IPACK3 = static_cast<int>(std::lround(w3));
29 } else {
30 IPACK1 = i1;
31 IPACK2 = i2;
32 IPACK3 = i3;
33 }
34 constexpr float FR = 5.f, FP = 512.f, FZ = 8.f;
35
36 const int IE = IPACK1 / 64;
37 const int IN = IPACK1 - 64 * IE;
38 int N = IN - 30;
39 if (N < 1 || N > 10) N = -1;
40 layer = N;
41 E = IE / 1000.f;
42
43 const int IR = IPACK2 / 4096;
44 const int IP = IPACK2 - 4096 * IR;
45 const float R = (IR + 205.f * FR) / FR;
46 const float phi = IP / FP;
47 X = R * std::cos(phi);
48 Y = R * std::sin(phi);
49
50 const int IZ = IPACK3 / 256;
51 const int IW = IPACK3 - 256 * IZ;
52 Z = (IZ - 260.f * FZ) / FZ;
53 sigZ = IW / 10.f;
54}
55
56} // namespace delphi_edm4hep::hpc
void padDecode(std::int32_t i1, std::int32_t i2, std::int32_t i3, float w1, float w2, float w3, float &E, int &layer, float &X, float &Y, float &Z, float &sigZ)