LDMX Software
objdef.h
1#ifndef OBJDEF_H
2#define OBJDEF_H
3
4#include "ap_int.h"
5#define NTIMES 5
6#define NHITS 25
7#define NCLUS 25
8#define NCHAN 50
9#define NTRK 10
10#define W = 10
11
12#define NCENT 99
13
14#define NDIGIS 14
15#define COMBO 9
16
17// 2*NCHAN*NTIMES are the number of bytes per event plus 4+4+4+3+1 bytes for the
18// header
19
20#define NSAMPLES 6
21
22// NSAMPLES/8 is the number of 64 bit words
23
24#define NWORDS 72
25
26struct Digi {
27 int mID{}, bID{};
28 int adc0{}, adc1{}, adc2{}, adc3{}, adc4{}, adc5{};
29 int tdc0{}, tdc1{}, tdc2{}, tdc3{}, tdc4{}, tdc5{};
30};
31
32inline void clearDigi(Digi& c) {
33 c.mID = 0;
34 c.bID = 0;
35 c.adc0 = 0;
36 c.adc1 = 0;
37 c.adc2 = 0;
38 c.adc3 = 0;
39 c.adc4 = 0;
40 c.adc5 = 0;
41 c.tdc0 = 0;
42 c.tdc1 = 0;
43 c.tdc2 = 0;
44 c.tdc3 = 0;
45 c.tdc4 = 0;
46 c.tdc5 = 0;
47}
48
49struct Hit {
50 ap_int<12> mID{}, bID{};
51 ap_int<12> Amp{}, Time{}; // TrigTime;
52};
53
54inline void clearHit(Hit& c) {
55 c.mID = 0;
56 c.bID = -1;
57 c.Amp = 0;
58 c.Time = 0; // c.TrigTime=0.0;
59}
60
61inline void cpyHit(Hit& c1, Hit& c2) {
62 c1.mID = c2.mID;
63 c1.bID = c2.bID;
64 c1.Amp = c2.Amp;
65 c1.Time = c2.Time;
66}
67
68struct Cluster {
69 Hit Seed{};
70 Hit Sec{};
71 ap_int<12> Cent{};
72 // int nhits, mID, SeedID;
73 // float CentX, CentY, CentZ, Amp, Time, TrigTime;
74};
75
76inline void clearClus(Cluster& c) {
77 clearHit(c.Seed);
78 clearHit(c.Sec);
79 c.Cent = (ap_int<12>)(0); // clearHit(c.For);
80}
81
82inline void calcCent(Cluster& c) {
83 // Check if Seed and Sec amplitudes are valid
84 if (c.Seed.Amp <= 0 || c.Sec.Amp <= 0) {
85 c.Cent = (ap_int<12>)(0);
86 return;
87 }
88
89 if (c.Seed.bID < 0 || c.Sec.bID < 0) {
90 c.Cent = (ap_int<12>)(0);
91 return;
92 }
93
94 // Perform the centroid calculation if all checks passed
95 c.Cent =
96 (ap_int<12>)(10.0f *
97 ((float)(c.Seed.Amp * c.Seed.bID + c.Sec.Amp * c.Sec.bID)) /
98 ((float)(c.Seed.Amp + c.Sec.Amp)));
99}
100
101inline void cpyCluster(Cluster& c1, Cluster& c2) {
102 cpyHit(c1.Seed, c2.Seed);
103 cpyHit(c1.Sec, c2.Sec);
104}
105
106struct Track {
107 Cluster Pad1{};
108 Cluster Pad2{};
109 Cluster Pad3{};
110 ap_int<12> resid{};
111};
112
113inline void clearTrack(Track& c) {
114 clearClus(c.Pad1);
115 clearClus(c.Pad2);
116 clearClus(c.Pad3);
117 c.resid = 5000;
118}
119
120inline ap_int<12> calcTCent(Track& c) {
121 calcCent(c.Pad1);
122 calcCent(c.Pad2);
123 calcCent(c.Pad3);
124
125 float one = (float)c.Pad1.Cent;
126 float two = (float)c.Pad2.Cent;
127 float three = (float)c.Pad3.Cent;
128 float mean = (one + two + three) / 3.0;
129 ap_int<12> Cent = (ap_int<12>)((int)(mean));
130 return Cent;
131}
132
133inline void calcResid(Track& c) {
134 calcCent(c.Pad1);
135 calcCent(c.Pad2);
136 calcCent(c.Pad3);
137 float one = (float)c.Pad1.Cent;
138 float two = (float)c.Pad2.Cent;
139 float three = (float)c.Pad3.Cent;
140 float mean = (one + two + three) / 3.0;
141 c.resid = (ap_int<12>)((int)(((one - mean) * (one - mean) +
142 (two - mean) * (two - mean) +
143 (three - mean) * (three - mean)) /
144 3.0));
145}
146
147inline void cpyTrack(Track& c1, Track& c2) {
148 cpyCluster(c1.Pad1, c2.Pad1);
149 cpyCluster(c1.Pad2, c2.Pad2);
150 cpyCluster(c1.Pad3, c2.Pad3);
151 c1.resid = c2.resid;
152}
153
154#endif
Definition objdef.h:26
Definition objdef.h:49
Sign Arbitrary Precision Type.
Definition ap_int.h:28