File: | programs/Simulation/HDGeant/hitUPV.c |
Location: | line 74, column 7 |
Description: | Value stored to 'column' during its initialization is never read |
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/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 | /* register hits during tracking (from gustep) */ |
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; |
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_(); |
Value stored to 'column' during its initialization is never read | |
75 | /* |
76 | 'column' is not used in the current code. It distinguishes long |
77 | paddles (column=0) from short paddles to the left(column=1) or |
78 | right(column=2) of the beam hole. However, we assume that a pair |
79 | of short paddles is connected with a lightguide which has the light |
80 | propagation properties of a scintillator. In other words, a left and |
81 | right pair of short paddles form a long paddle which just happens |
82 | to have an insensitive to hits area in the middle but otherwise is identical |
83 | to a normal long paddle. If we later change our minds and start treating 3 |
84 | types of paddles differently, then 'column' is available for use. |
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 | /* post the hit to the truth tree */ |
95 | |
96 | if ((history == 0) && (pin[3] > THRESH_MEV5./1e3)) |
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 | /* post the hit to the hits tree, mark upvPaddle as hit */ |
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 | paddles->in[0].upvHits = hits = make_s_UpvHits(MAX_HITS100); |
137 | upv->upvPaddles = paddles; |
138 | paddleCount++; |
139 | } |
140 | else |
141 | { |
142 | s_UpstreamEMveto_t* upv = *twig; |
143 | hits = upv->upvPaddles->in[0].upvHits; |
144 | } |
145 | |
146 | if (hits != HDDM_NULL(void*)&hddm_s_nullTarget) |
147 | { |
148 | for (nhit = 0; nhit < hits->mult; nhit++) |
149 | { |
150 | if (hits->in[nhit].end == 0 && |
151 | fabs(hits->in[nhit].t - tleft) < TWO_HIT_RESOL50.) |
152 | { |
153 | break; |
154 | } |
155 | } |
156 | |
157 | if (nhit < hits->mult) /* merge with former hit */ |
158 | { |
159 | hits->in[nhit].t = |
160 | (hits->in[nhit].t * hits->in[nhit].E + tleft * dEleft) / |
161 | (hits->in[nhit].E + dEleft); |
162 | hits->in[nhit].E += dEleft; |
163 | } |
164 | else if (nhit < MAX_HITS100) /* create new hit, north end */ |
165 | { |
166 | hits->in[nhit].t = |
167 | (hits->in[nhit].t * hits->in[nhit].E + tleft * dEleft) / |
168 | (hits->in[nhit].E + dEleft); |
169 | hits->in[nhit].E += dEleft; |
170 | hits->in[nhit].end = 0; |
171 | hits->mult++; |
172 | } |
173 | else |
174 | { |
175 | fprintf(stderrstderr,"HDGeant error in hitUpstreamEMveto: "); |
176 | fprintf(stderrstderr,"max hit count %d exceeded, truncating!\n",MAX_HITS100); |
177 | } |
178 | } |
179 | |
180 | for (nhit = 0; nhit < hits->mult; nhit++) |
181 | { |
182 | if (hits->in[nhit].end == 1 && |
183 | fabs(hits->in[nhit].t - tright) < TWO_HIT_RESOL50.) |
184 | { |
185 | break; |
186 | } |
187 | } |
188 | |
189 | if (nhit < hits->mult) /* merge with former hit */ |
190 | { |
191 | hits->in[nhit].t = |
192 | (hits->in[nhit].t * hits->in[nhit].E + tright * dEright) / |
193 | (hits->in[nhit].E + dEright); |
194 | hits->in[nhit].E += dEright; |
195 | } |
196 | else if (nhit < MAX_HITS100) /* create new hit, south end */ |
197 | { |
198 | hits->in[nhit].t = |
199 | (hits->in[nhit].t * hits->in[nhit].E + tright * dEright) / |
200 | (hits->in[nhit].E + dEright); |
201 | hits->in[nhit].E += dEright; |
202 | hits->in[nhit].end = 1; |
203 | hits->mult++; |
204 | } |
205 | else |
206 | { |
207 | fprintf(stderrstderr,"HDGeant error in hitUpstreamEMveto: "); |
208 | fprintf(stderrstderr,"max hit count %d exceeded, truncating!\n",MAX_HITS100); |
209 | } |
210 | } |
211 | } |
212 | |
213 | /* entry point from fortran */ |
214 | |
215 | void hitupstreamemveto_(float* xin, float* xout, |
216 | float* pin, float* pout, float* dEsum, |
217 | int* track, int* stack, int* history, int* ipart) |
218 | { |
219 | hitUpstreamEMveto(xin,xout,pin,pout,*dEsum,*track,*stack,*history,*ipart); |
220 | } |
221 | |
222 | |
223 | |
224 | |
225 | /* pick and package the hits for shipping */ |
226 | |
227 | s_UpstreamEMveto_t* pickUpstreamEMveto () |
228 | { |
229 | s_UpstreamEMveto_t* box; |
230 | s_UpstreamEMveto_t* item; |
231 | |
232 | if ((paddleCount == 0) && (rowCount == 0) && (showerCount == 0)) |
233 | return HDDM_NULL(void*)&hddm_s_nullTarget; |
234 | |
235 | box = make_s_UpstreamEMveto(); |
236 | box->upvPaddles = make_s_UpvPaddles(paddleCount); |
237 | box->upvTruthShowers = make_s_UpvTruthShowers(showerCount); |
238 | while ((item = (s_UpstreamEMveto_t*) pickTwig(&upstreamEMvetoTree))) |
239 | { |
240 | s_UpvPaddles_t* paddles = item->upvPaddles; |
241 | int paddle; |
242 | s_UpvTruthShowers_t* showers = item->upvTruthShowers; |
243 | int shower; |
244 | |
245 | for (paddle=0; paddle < paddles->mult; ++paddle) |
246 | { |
247 | int m = box->upvPaddles->mult; |
248 | int mok = 0; |
249 | |
250 | s_UpvHits_t* hits = paddles->in[paddle].upvHits; |
251 | |
252 | /* compress out the hits below threshold */ |
253 | int i,iok; |
254 | for (iok=i=0; i < hits->mult; i++) |
255 | { |
256 | if (hits->in[i].E >= THRESH_MEV5./1e3) |
257 | { |
258 | if (iok < i) |
259 | { |
260 | hits->in[iok] = hits->in[i]; |
261 | } |
262 | ++iok; |
263 | ++mok; |
264 | } |
265 | } |
266 | if (iok) |
267 | { |
268 | hits->mult = iok; |
269 | } |
270 | else if (hits != HDDM_NULL(void*)&hddm_s_nullTarget) |
271 | { |
272 | paddles->in[paddle].upvHits = HDDM_NULL(void*)&hddm_s_nullTarget; |
273 | FREE(hits)free(hits); |
274 | } |
275 | |
276 | if (mok) |
277 | { |
278 | box->upvPaddles->in[m] = paddles->in[paddle]; |
279 | box->upvPaddles->mult++; |
280 | } |
281 | } |
282 | if (paddles != HDDM_NULL(void*)&hddm_s_nullTarget) |
283 | { |
284 | FREE(paddles)free(paddles); |
285 | } |
286 | |
287 | for (shower=0; shower < showers->mult; ++shower) |
288 | { |
289 | int m = box->upvTruthShowers->mult++; |
290 | box->upvTruthShowers->in[m] = showers->in[shower]; |
291 | } |
292 | if (showers != HDDM_NULL(void*)&hddm_s_nullTarget) |
293 | { |
294 | FREE(showers)free(showers); |
295 | } |
296 | FREE(item)free(item); |
297 | } |
298 | |
299 | paddleCount = showerCount = 0; |
300 | |
301 | if ((box->upvPaddles != HDDM_NULL(void*)&hddm_s_nullTarget) && |
302 | (box->upvPaddles->mult == 0)) |
303 | { |
304 | FREE(box->upvPaddles)free(box->upvPaddles); |
305 | box->upvPaddles = HDDM_NULL(void*)&hddm_s_nullTarget; |
306 | } |
307 | if ((box->upvTruthShowers != HDDM_NULL(void*)&hddm_s_nullTarget) && |
308 | (box->upvTruthShowers->mult == 0)) |
309 | { |
310 | FREE(box->upvTruthShowers)free(box->upvTruthShowers); |
311 | box->upvTruthShowers = HDDM_NULL(void*)&hddm_s_nullTarget; |
312 | } |
313 | if ((box->upvPaddles->mult == 0) && |
314 | (box->upvTruthShowers->mult == 0)) |
315 | { |
316 | FREE(box)free(box); |
317 | box = HDDM_NULL(void*)&hddm_s_nullTarget; |
318 | } |
319 | return box; |
320 | } |