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 m_id_{}, b_id_{};
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.m_id_ = 0;
34 c.b_id_ = 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> m_id_{}, b_id_{};
51 ap_int<12> amp_{}, time_{}; // TrigTime;
52};
53
54inline void clearHit(Hit& c) {
55 c.m_id_ = 0;
56 c.b_id_ = -1;
57 c.amp_ = 0;
58 c.time_ = 0; // c.TrigTime=0.0;
59}
60
61inline void cpyHit(Hit& c1, Hit& c2) {
62 c1.m_id_ = c2.m_id_;
63 c1.b_id_ = c2.b_id_;
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_.b_id_ < 0 || c.sec_.b_id_ < 0) {
90 c.cent_ = (ap_int<12>)(0);
91 return;
92 }
93
94 // Perform the centroid calculation if all checks passed
95 c.cent_ = (ap_int<12>)(10.0f *
96 ((float)(c.seed_.amp_ * c.seed_.b_id_ +
97 c.sec_.amp_ * c.sec_.b_id_)) /
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