1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | #include <stdlib.h> |
30 | #include <stdio.h> |
31 | #include <math.h> |
32 | |
33 | #include <HDDM/hddm_s.h> |
34 | #include <geant3.h> |
35 | #include <bintree.h> |
36 | #include <gid_map.h> |
37 | |
38 | extern s_HDDM_t* thisInputEvent; |
39 | |
40 | #define ATTEN_LENGTH150. 150. |
41 | #define C_EFFECTIVE19. 19. /* This assumes a single linear fiber path */ |
42 | #define THRESH_MEV5. 5. |
43 | #define TWO_HIT_RESOL50. 50. |
44 | #define MAX_HITS100 100 |
45 | |
46 | binTree_t* upstreamEMvetoTree = 0; |
47 | static int paddleCount = 0; |
48 | static int rowCount = 0; |
49 | static int showerCount = 0; |
50 | |
51 | |
52 | |
53 | |
54 | void hitUpstreamEMveto (float xin[4], float xout[4], |
55 | float pin[5], float pout[5], float dEsum, |
56 | int track, int stack, int history, int ipart) |
57 | { |
58 | float x[3], t; |
59 | float xlocal[3]; |
60 | float xupv[3]; |
61 | float zeroHat[] = {0,0,0}; |
62 | int nhit; |
63 | s_UpvHits_t* hits = 0; |
| 2 | | 'hits' initialized to a null pointer value | |
|
64 | |
65 | x[0] = (xin[0] + xout[0])/2; |
66 | x[1] = (xin[1] + xout[1])/2; |
67 | x[2] = (xin[2] + xout[2])/2; |
68 | t = (xin[3] + xout[3])/2 * 1e9; |
69 | transformCoord(x,"global",xlocal,"UPV")transformcoord_(x,"global",xlocal,"UPV",strlen("global"),strlen ("UPV")); |
70 | transformCoord(zeroHat,"local",xupv,"UPV")transformcoord_(zeroHat,"local",xupv,"UPV",strlen("local"),strlen ("UPV")); |
71 | |
72 | int layer = getlayer_wrapper_(); |
73 | int row = getrow_wrapper_(); |
74 | int column = getcolumn_wrapper_(); |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | float dxleft = xlocal[0]; |
88 | float dxright = -xlocal[0]; |
89 | float tleft = t + dxleft/C_EFFECTIVE19.; |
90 | float tright = t + dxright/C_EFFECTIVE19.; |
91 | float dEleft = dEsum * exp(-dxleft/ATTEN_LENGTH150.); |
92 | float dEright = dEsum * exp(-dxright/ATTEN_LENGTH150.); |
93 | |
94 | |
95 | |
96 | if ((history == 0) && (pin[3] > THRESH_MEV5./1e3)) |
| 3 | | Assuming 'history' is not equal to 0 | |
|
97 | { |
98 | int mark = (1<<30) + showerCount; |
99 | void** twig = getTwig(&upstreamEMvetoTree, mark); |
100 | if (*twig == 0) { |
101 | s_UpstreamEMveto_t* upv = *twig = make_s_UpstreamEMveto(); |
102 | s_UpvTruthShowers_t* showers = make_s_UpvTruthShowers(1); |
103 | int a = thisInputEvent->physicsEvents->in[0].reactions->in[0].vertices->in[0].products->mult; |
104 | showers->in[0].primary = (stack <= a); |
105 | showers->in[0].track = track; |
106 | showers->in[0].x = xin[0]; |
107 | showers->in[0].y = xin[1]; |
108 | showers->in[0].z = xin[2]; |
109 | showers->in[0].t = xin[3]*1e9; |
110 | showers->in[0].px = pin[0]*pin[4]; |
111 | showers->in[0].py = pin[1]*pin[4]; |
112 | showers->in[0].pz = pin[2]*pin[4]; |
113 | showers->in[0].E = pin[3]; |
114 | showers->in[0].ptype = ipart; |
115 | showers->in[0].trackID = make_s_TrackID(); |
116 | showers->in[0].trackID->itrack = gidGetId(track); |
117 | showers->mult = 1; |
118 | upv->upvTruthShowers = showers; |
119 | showerCount++; |
120 | } |
121 | } |
122 | |
123 | |
124 | |
125 | if (dEsum > 0) |
| |
126 | { |
127 | int mark = (layer<<16) + row; |
128 | void** twig = getTwig(&upstreamEMvetoTree, mark); |
129 | if (*twig == 0) |
| |
130 | { |
131 | s_UpstreamEMveto_t* upv = *twig = make_s_UpstreamEMveto(); |
132 | s_UpvPaddles_t* paddles = make_s_UpvPaddles(1); |
133 | paddles->mult = 1; |
134 | paddles->in[0].row = row; |
135 | paddles->in[0].layer = layer; |
136 | if (column == 0 || column == 1) |
| 6 | | Assuming 'column' is not equal to 0 | |
|
| 7 | | Assuming 'column' is not equal to 1 | |
|
| |
137 | { |
138 | paddles->in[0].upvHits = hits = make_s_UpvHits(MAX_HITS100); |
139 | } |
140 | upv->upvPaddles = paddles; |
141 | paddleCount++; |
142 | } |
143 | else |
144 | { |
145 | s_UpstreamEMveto_t* upv = *twig; |
146 | hits = upv->upvPaddles->in[0].upvHits; |
147 | } |
148 | |
149 | if (hits != HDDM_NULL(void*)&hddm_s_nullTarget) |
| |
150 | { |
151 | for (nhit = 0; nhit < hits->mult; nhit++) |
| 10 | | Access to field 'mult' results in a dereference of a null pointer (loaded from variable 'hits') |
|
152 | { |
153 | if (hits->in[nhit].end == 0 && |
154 | fabs(hits->in[nhit].t - tleft) < TWO_HIT_RESOL50.) |
155 | { |
156 | break; |
157 | } |
158 | } |
159 | |
160 | if (nhit < hits->mult) |
161 | { |
162 | hits->in[nhit].t = |
163 | (hits->in[nhit].t * hits->in[nhit].E + tleft * dEleft) / |
164 | (hits->in[nhit].E + dEleft); |
165 | hits->in[nhit].E += dEleft; |
166 | } |
167 | else if (nhit < MAX_HITS100) |
168 | { |
169 | hits->in[nhit].t = |
170 | (hits->in[nhit].t * hits->in[nhit].E + tleft * dEleft) / |
171 | (hits->in[nhit].E + dEleft); |
172 | hits->in[nhit].E += dEleft; |
173 | hits->in[nhit].end = 0; |
174 | hits->mult++; |
175 | } |
176 | else |
177 | { |
178 | fprintf(stderrstderr,"HDGeant error in hitUpstreamEMveto: "); |
179 | fprintf(stderrstderr,"max hit count %d exceeded, truncating!\n",MAX_HITS100); |
180 | } |
181 | } |
182 | |
183 | for (nhit = 0; nhit < hits->mult; nhit++) |
184 | { |
185 | if (hits->in[nhit].end == 1 && |
186 | fabs(hits->in[nhit].t - tright) < TWO_HIT_RESOL50.) |
187 | { |
188 | break; |
189 | } |
190 | } |
191 | |
192 | if (nhit < hits->mult) |
193 | { |
194 | hits->in[nhit].t = |
195 | (hits->in[nhit].t * hits->in[nhit].E + tright * dEright) / |
196 | (hits->in[nhit].E + dEright); |
197 | hits->in[nhit].E += dEright; |
198 | } |
199 | else if (nhit < MAX_HITS100) |
200 | { |
201 | hits->in[nhit].t = |
202 | (hits->in[nhit].t * hits->in[nhit].E + tright * dEright) / |
203 | (hits->in[nhit].E + dEright); |
204 | hits->in[nhit].E += dEright; |
205 | hits->in[nhit].end = 1; |
206 | hits->mult++; |
207 | } |
208 | else |
209 | { |
210 | fprintf(stderrstderr,"HDGeant error in hitUpstreamEMveto: "); |
211 | fprintf(stderrstderr,"max hit count %d exceeded, truncating!\n",MAX_HITS100); |
212 | } |
213 | } |
214 | } |
215 | |
216 | |
217 | |
218 | void hitupstreamemveto_(float* xin, float* xout, |
219 | float* pin, float* pout, float* dEsum, |
220 | int* track, int* stack, int* history, int* ipart) |
221 | { |
222 | hitUpstreamEMveto(xin,xout,pin,pout,*dEsum,*track,*stack,*history,*ipart); |
| 1 | Calling 'hitUpstreamEMveto' | |
|
223 | } |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | s_UpstreamEMveto_t* pickUpstreamEMveto () |
231 | { |
232 | s_UpstreamEMveto_t* box; |
233 | s_UpstreamEMveto_t* item; |
234 | |
235 | if ((paddleCount == 0) && (rowCount == 0) && (showerCount == 0)) |
236 | return HDDM_NULL(void*)&hddm_s_nullTarget; |
237 | |
238 | box = make_s_UpstreamEMveto(); |
239 | box->upvPaddles = make_s_UpvPaddles(paddleCount); |
240 | box->upvTruthShowers = make_s_UpvTruthShowers(showerCount); |
241 | while ((item = (s_UpstreamEMveto_t*) pickTwig(&upstreamEMvetoTree))) |
242 | { |
243 | s_UpvPaddles_t* paddles = item->upvPaddles; |
244 | int paddle; |
245 | s_UpvTruthShowers_t* showers = item->upvTruthShowers; |
246 | int shower; |
247 | |
248 | for (paddle=0; paddle < paddles->mult; ++paddle) |
249 | { |
250 | int m = box->upvPaddles->mult; |
251 | int mok = 0; |
252 | |
253 | s_UpvHits_t* hits = paddles->in[paddle].upvHits; |
254 | |
255 | |
256 | int i,iok; |
257 | for (iok=i=0; i < hits->mult; i++) |
258 | { |
259 | if (hits->in[i].E >= THRESH_MEV5./1e3) |
260 | { |
261 | if (iok < i) |
262 | { |
263 | hits->in[iok] = hits->in[i]; |
264 | } |
265 | ++iok; |
266 | ++mok; |
267 | } |
268 | } |
269 | if (iok) |
270 | { |
271 | hits->mult = iok; |
272 | } |
273 | else if (hits != HDDM_NULL(void*)&hddm_s_nullTarget) |
274 | { |
275 | paddles->in[paddle].upvHits = HDDM_NULL(void*)&hddm_s_nullTarget; |
276 | FREE(hits)free(hits); |
277 | } |
278 | |
279 | if (mok) |
280 | { |
281 | box->upvPaddles->in[m] = paddles->in[paddle]; |
282 | box->upvPaddles->mult++; |
283 | } |
284 | } |
285 | if (paddles != HDDM_NULL(void*)&hddm_s_nullTarget) |
286 | { |
287 | FREE(paddles)free(paddles); |
288 | } |
289 | |
290 | for (shower=0; shower < showers->mult; ++shower) |
291 | { |
292 | int m = box->upvTruthShowers->mult++; |
293 | box->upvTruthShowers->in[m] = showers->in[shower]; |
294 | } |
295 | if (showers != HDDM_NULL(void*)&hddm_s_nullTarget) |
296 | { |
297 | FREE(showers)free(showers); |
298 | } |
299 | FREE(item)free(item); |
300 | } |
301 | |
302 | paddleCount = showerCount = 0; |
303 | |
304 | if ((box->upvPaddles != HDDM_NULL(void*)&hddm_s_nullTarget) && |
305 | (box->upvPaddles->mult == 0)) |
306 | { |
307 | FREE(box->upvPaddles)free(box->upvPaddles); |
308 | box->upvPaddles = HDDM_NULL(void*)&hddm_s_nullTarget; |
309 | } |
310 | if ((box->upvTruthShowers != HDDM_NULL(void*)&hddm_s_nullTarget) && |
311 | (box->upvTruthShowers->mult == 0)) |
312 | { |
313 | FREE(box->upvTruthShowers)free(box->upvTruthShowers); |
314 | box->upvTruthShowers = HDDM_NULL(void*)&hddm_s_nullTarget; |
315 | } |
316 | if ((box->upvPaddles->mult == 0) && |
317 | (box->upvTruthShowers->mult == 0)) |
318 | { |
319 | FREE(box)free(box); |
320 | box = HDDM_NULL(void*)&hddm_s_nullTarget; |
321 | } |
322 | return box; |
323 | } |