Bug Summary

File:programs/Simulation/HDGeant/hitUPV.c
Location:line 93, column 9
Description:Value stored to 'zcenter' during its initialization is never read

Annotated Source Code

1/*
2 * hitUPV - registers hits for UPV - ao
3 *
4 *
5 * This is a part of the hits package for the
6 * HDGeant simulation program for Hall D.
7 *
8 *
9 * changes: Wed Jun 20 13:19:56 EDT 2007 B. Zihlmann
10 * add ipart to the function hitUpstreamEMveto
11 *
12 * Programmer's Notes:
13 * -------------------
14 * 1) In applying the attenuation to light propagating down to both ends
15 * of the modules, there has to be some point where the attenuation
16 * factor is 1. I chose it to be the midplane, so that in the middle
17 * of the paddle both ends see the unattenuated E values. Closer to
18 * either end, that end has a larger E value and the opposite end a
19 * lower E value than the actual deposition.
20 * 2) In applying the propagation delay to light propagating down to the
21 * ends of the modules, there has to be some point where the timing
22 * offset is 0. I chose it to be the midplane, so that for hits in
23 * the middle of the paddle the t values measure time-of-flight from
24 * the t=0 of the event. For hits closer to one end, that end sees
25 * a t value smaller than its true time-of-flight, and the other end
26 * sees a value correspondingly larger. The average is the true tof.
27 */
28
29#include <stdlib.h>
30#include <stdio.h>
31#include <math.h>
32
33#include <hddm_s.h>
34#include <geant3.h>
35#include <bintree.h>
36extern s_HDDM_t* thisInputEvent;
37
38#define ATTEN_LENGTH150. 150.
39#define C_EFFECTIVE19. 19. /* This assumes a single linear fiber path */
40#define THRESH_MEV5. 5.
41#define TWO_HIT_RESOL50. 50.
42#define MAX_HITS100 100
43
44binTree_t* upstreamEMvetoTree = 0;
45static int paddleCount = 0;
46static int rowCount = 0;
47static int showerCount = 0;
48
49
50/* register hits during tracking (from gustep) */
51
52void hitUpstreamEMveto (float xin[4], float xout[4],
53 float pin[5], float pout[5], float dEsum,
54 int track, int stack, int history, int ipart)
55{
56 float x[3], t;
57 float xlocal[3];
58 float xupv[3];
59 float zeroHat[] = {0,0,0};
60 int nhit;
61 s_UpvLeftHits_t* leftHits;
62 s_UpvRightHits_t* rightHits;
63
64 x[0] = (xin[0] + xout[0])/2;
65 x[1] = (xin[1] + xout[1])/2;
66 x[2] = (xin[2] + xout[2])/2;
67 t = (xin[3] + xout[3])/2 * 1e9;
68 transformCoord(x,"global",xlocal,"UPV")transformcoord_(x,"global",xlocal,"UPV",strlen("global"),strlen
("UPV"))
;
69 transformCoord(zeroHat,"local",xupv,"UPV")transformcoord_(zeroHat,"local",xupv,"UPV",strlen("local"),strlen
("UPV"))
;
70
71 int layer = getlayer_();
72 int row = getrow_();
73 int column = getcolumn_();
74 /*
75 'column' is not used in the current code. It distinguishes long
76 paddles (column=0) from short paddles to the left(column=1) or
77 right(column=2) of the beam hole. However, we assume that a pair
78 of short paddles is connected with a lightguide which has the light
79 propagation properties of a scintillator. In other words, a left and
80 right pair of short paddles form a long paddle which just happens
81 to have an insensitive to hits area in the middle but otherwise is identical
82 to a normal long paddle. If we later change our minds and start treating 3
83 types of paddles differently, then 'column' is available for use.
84 */
85
86 float dxleft = xlocal[0];
87 float dxright = -xlocal[0];
88 float tleft = t + dxleft/C_EFFECTIVE19.;
89 float tright = t + dxright/C_EFFECTIVE19.;
90 float dEleft = dEsum * exp(-dxleft/ATTEN_LENGTH150.);
91 float dEright = dEsum * exp(-dxright/ATTEN_LENGTH150.);
92 float ycenter = (fabs(xupv[1]) < 1e-4) ? 0 : xupv[1];
93 float zcenter = (fabs(xupv[2]) < 1e-4) ? 0 : xupv[2];
Value stored to 'zcenter' during its initialization is never read
94
95 /* post the hit to the truth tree */
96
97 if ((history == 0) && (pin[3] > THRESH_MEV5./1e3))
98 {
99 int mark = (1<<30) + showerCount;
100 void** twig = getTwig(&upstreamEMvetoTree, mark);
101 if (*twig == 0) {
102 s_UpstreamEMveto_t* upv = *twig = make_s_UpstreamEMveto();
103 s_UpvTruthShowers_t* showers = make_s_UpvTruthShowers(1);
104 int a = thisInputEvent->physicsEvents->in[0].reactions->in[0].vertices->in[0].products->mult;
105 showers->in[0].primary = (stack <= a);
106 showers->in[0].track = track;
107 showers->in[0].x = xin[0];
108 showers->in[0].y = xin[1];
109 showers->in[0].z = xin[2];
110 showers->in[0].t = xin[3]*1e9;
111 showers->in[0].px = pin[0]*pin[4];
112 showers->in[0].py = pin[1]*pin[4];
113 showers->in[0].pz = pin[2]*pin[4];
114 showers->in[0].E = pin[3];
115 showers->in[0].ptype = ipart;
116 showers->mult = 1;
117 upv->upvTruthShowers = showers;
118 showerCount++;
119 }
120 }
121
122 /* post the hit to the hits tree, mark upvPaddle as hit */
123
124 if (dEsum > 0)
125 {
126 int mark = (layer<<16) + row;
127 void** twig = getTwig(&upstreamEMvetoTree, mark);
128 if (*twig == 0)
129 {
130 s_UpstreamEMveto_t* upv = *twig = make_s_UpstreamEMveto();
131 s_UpvPaddles_t* paddles = make_s_UpvPaddles(1);
132 paddles->mult = 1;
133 paddles->in[0].row = row;
134 paddles->in[0].layer = layer;
135 leftHits = HDDM_NULL(void*)&hddm_s_nullTarget;
136 rightHits = HDDM_NULL(void*)&hddm_s_nullTarget;
137 if (column == 0 || column == 1)
138 {
139 paddles->in[0].upvLeftHits = leftHits
140 = make_s_UpvLeftHits(MAX_HITS100);
141 }
142 if (column == 0 || column == 1)
143 {
144 paddles->in[0].upvRightHits = rightHits
145 = make_s_UpvRightHits(MAX_HITS100);
146 }
147 upv->upvPaddles = paddles;
148 paddleCount++;
149 }
150 else
151 {
152 s_UpstreamEMveto_t* upv = *twig;
153 leftHits = upv->upvPaddles->in[0].upvLeftHits;
154 rightHits = upv->upvPaddles->in[0].upvRightHits;
155 }
156
157 if (leftHits != HDDM_NULL(void*)&hddm_s_nullTarget)
158 {
159 for (nhit = 0; nhit < leftHits->mult; nhit++)
160 {
161 if (fabs(leftHits->in[nhit].t - tleft) < TWO_HIT_RESOL50.)
162 {
163 break;
164 }
165 }
166
167 if (nhit < leftHits->mult) /* merge with former hit */
168 {
169 leftHits->in[nhit].t =
170 (leftHits->in[nhit].t * leftHits->in[nhit].E + tleft * dEleft)
171 / (leftHits->in[nhit].E += dEleft);
172 }
173 else if (nhit < MAX_HITS100) /* create new hit */
174 {
175 leftHits->in[nhit].t =
176 (leftHits->in[nhit].t * leftHits->in[nhit].E + tleft * dEleft)
177 / (leftHits->in[nhit].E += dEleft);
178 leftHits->mult++;
179 }
180 else
181 {
182 fprintf(stderrstderr,"HDGeant error in hitUpstreamEMveto: ");
183 fprintf(stderrstderr,"max hit count %d exceeded, truncating!\n",MAX_HITS100);
184 }
185 }
186
187 if (rightHits != HDDM_NULL(void*)&hddm_s_nullTarget)
188 {
189 for (nhit = 0; nhit < rightHits->mult; nhit++)
190 {
191 if (fabs(rightHits->in[nhit].t - tright) < TWO_HIT_RESOL50.)
192 {
193 break;
194 }
195 }
196
197 if (nhit < rightHits->mult) /* merge with former hit */
198 {
199 rightHits->in[nhit].t =
200 (rightHits->in[nhit].t * rightHits->in[nhit].E + tright * dEright)
201 / (rightHits->in[nhit].E += dEright);
202 }
203 else if (nhit < MAX_HITS100) /* create new hit */
204 {
205 rightHits->in[nhit].t =
206 (rightHits->in[nhit].t * rightHits->in[nhit].E + tright * dEright)
207 / (rightHits->in[nhit].E += dEright);
208 rightHits->mult++;
209 }
210 else
211 {
212 fprintf(stderrstderr,"HDGeant error in hitUpstreamEMveto: ");
213 fprintf(stderrstderr,"max hit count %d exceeded, truncating!\n",MAX_HITS100);
214 }
215 }
216 }
217}
218
219/* entry point from fortran */
220
221void hitupstreamemveto_(float* xin, float* xout,
222 float* pin, float* pout, float* dEsum,
223 int* track, int* stack, int* history, int* ipart)
224{
225 hitUpstreamEMveto(xin,xout,pin,pout,*dEsum,*track,*stack,*history,*ipart);
226}
227
228
229
230
231/* pick and package the hits for shipping */
232
233s_UpstreamEMveto_t* pickUpstreamEMveto ()
234{
235 s_UpstreamEMveto_t* box;
236 s_UpstreamEMveto_t* item;
237
238 if ((paddleCount == 0) && (rowCount == 0) && (showerCount == 0))
239 return HDDM_NULL(void*)&hddm_s_nullTarget;
240
241 box = make_s_UpstreamEMveto();
242 box->upvPaddles = make_s_UpvPaddles(paddleCount);
243 box->upvTruthShowers = make_s_UpvTruthShowers(showerCount);
244 while (item = (s_UpstreamEMveto_t*) pickTwig(&upstreamEMvetoTree))
245 {
246 s_UpvPaddles_t* paddles = item->upvPaddles;
247 int paddle;
248 s_UpvTruthShowers_t* showers = item->upvTruthShowers;
249 int shower;
250
251 for (paddle=0; paddle < paddles->mult; ++paddle)
252 {
253 int m = box->upvPaddles->mult;
254 int mok = 0;
255
256 s_UpvLeftHits_t* leftHits = paddles->in[paddle].upvLeftHits;
257 s_UpvRightHits_t* rightHits = paddles->in[paddle].upvRightHits;
258
259 /* compress out the hits below threshold */
260 int i,iok;
261 for (iok=i=0; i < leftHits->mult; i++)
262 {
263 if (leftHits->in[i].E >= THRESH_MEV5./1e3)
264 {
265 if (iok < i)
266 {
267 leftHits->in[iok] = leftHits->in[i];
268 }
269 ++iok;
270 ++mok;
271 }
272 }
273 if (iok)
274 {
275 leftHits->mult = iok;
276 }
277 else if (leftHits != HDDM_NULL(void*)&hddm_s_nullTarget)
278 {
279 paddles->in[paddle].upvLeftHits = HDDM_NULL(void*)&hddm_s_nullTarget;
280 FREE(leftHits)free(leftHits);
281 }
282
283 for (iok=i=0; i < rightHits->mult; i++)
284 {
285 if (rightHits->in[i].E >= THRESH_MEV5./1e3)
286 {
287 if (iok < i)
288 {
289 rightHits->in[iok] = rightHits->in[i];
290 }
291 ++iok;
292 ++mok;
293 }
294 }
295 if (iok)
296 {
297 rightHits->mult = iok;
298 }
299 else if (rightHits != HDDM_NULL(void*)&hddm_s_nullTarget)
300 {
301 paddles->in[0].upvRightHits = HDDM_NULL(void*)&hddm_s_nullTarget;
302 FREE(rightHits)free(rightHits);
303 }
304
305 if (mok)
306 {
307 box->upvPaddles->in[m] = paddles->in[paddle];
308 box->upvPaddles->mult++;
309 }
310 }
311 if (paddles != HDDM_NULL(void*)&hddm_s_nullTarget)
312 {
313 FREE(paddles)free(paddles);
314 }
315
316 for (shower=0; shower < showers->mult; ++shower)
317 {
318 int m = box->upvTruthShowers->mult++;
319 box->upvTruthShowers->in[m] = showers->in[shower];
320 }
321 if (showers != HDDM_NULL(void*)&hddm_s_nullTarget)
322 {
323 FREE(showers)free(showers);
324 }
325 FREE(item)free(item);
326 }
327
328 paddleCount = showerCount = 0;
329
330 if ((box->upvPaddles != HDDM_NULL(void*)&hddm_s_nullTarget) &&
331 (box->upvPaddles->mult == 0))
332 {
333 FREE(box->upvPaddles)free(box->upvPaddles);
334 box->upvPaddles = HDDM_NULL(void*)&hddm_s_nullTarget;
335 }
336 if ((box->upvTruthShowers != HDDM_NULL(void*)&hddm_s_nullTarget) &&
337 (box->upvTruthShowers->mult == 0))
338 {
339 FREE(box->upvTruthShowers)free(box->upvTruthShowers);
340 box->upvTruthShowers = HDDM_NULL(void*)&hddm_s_nullTarget;
341 }
342 if ((box->upvPaddles->mult == 0) &&
343 (box->upvTruthShowers->mult == 0))
344 {
345 FREE(box)free(box);
346 box = HDDM_NULL(void*)&hddm_s_nullTarget;
347 }
348 return box;
349}