File: | programs/Simulation/HDGeant/hitCCal.c |
Location: | line 174, column 14 |
Description: | Value stored to 'column' during its initialization is never read |
1 | /* |
2 | * hitCCal - registers hits for Compton calorimeter |
3 | * |
4 | * This is a part of the hits package for the |
5 | * HDGeant simulation program for Hall D. |
6 | * |
7 | * version 1.0 -Richard Jones July 16, 2001 |
8 | * |
9 | */ |
10 | |
11 | #include <stdlib.h> |
12 | #include <stdio.h> |
13 | #include <math.h> |
14 | |
15 | |
16 | #include <hddm_s.h> |
17 | #include <geant3.h> |
18 | #include <bintree.h> |
19 | extern s_HDDM_t* thisInputEvent; |
20 | |
21 | #define ATTEN_LENGTH60. 60. //effective attenuation length in PbWO |
22 | #define C_EFFECTIVE13. 13. //effective speed of light in PbWO |
23 | #define WIDTH_OF_BLOCK2. 2. //cm |
24 | #define LENGTH_OF_BLOCK18. 18. //cm |
25 | #define TWO_HIT_RESOL75. 75. //ns |
26 | #define MAX_HITS100 100 |
27 | #define THRESH_MEV20. 20. |
28 | #define CENTRAL_ROW8 8 |
29 | #define CENTRAL_COLUMN8 8 |
30 | |
31 | |
32 | binTree_t* ComptonCalTree = 0; |
33 | static int blockCount = 0; |
34 | static int showerCount = 0; |
35 | |
36 | |
37 | /* register hits during tracking (from gustep) */ |
38 | |
39 | void hitComptonEMcal (float xin[4], float xout[4], |
40 | float pin[5], float pout[5], float dEsum, |
41 | int track, int stack, int history, int ipart) |
42 | { |
43 | float x[3], t; |
44 | float xccal[3]; |
45 | float zeroHat[] = {0,0,0}; |
46 | |
47 | x[0] = (xin[0] + xout[0])/2; |
48 | x[1] = (xin[1] + xout[1])/2; |
49 | x[2] = (xin[2] + xout[2])/2; |
50 | t = (xin[3] + xout[3])/2 * 1e9; |
51 | transformCoord(x,"global",xccal,"CCAL")transformcoord_(x,"global",xccal,"CCAL",strlen("global"),strlen ("CCAL")); |
52 | |
53 | /* post the hit to the truth tree */ |
54 | |
55 | if ((history == 0) && (pin[3] > THRESH_MEV20./1e3)) |
56 | { |
57 | s_CcalTruthShowers_t* showers; |
58 | int mark = (1<<30) + showerCount; |
59 | void** twig = getTwig(&ComptonCalTree, mark); |
60 | if (*twig == 0) |
61 | { |
62 | s_ComptonEMcal_t* cal = *twig = make_s_ComptonEMcal(); |
63 | cal->ccalTruthShowers = showers = make_s_CcalTruthShowers(1); |
64 | int a = thisInputEvent->physicsEvents->in[0].reactions->in[0].vertices->in[0].products->mult; |
65 | showers->in[0].primary = (stack <= a); |
66 | showers->in[0].track = track; |
67 | showers->in[0].t = xin[3]*1e9; |
68 | showers->in[0].x = xin[0]; |
69 | showers->in[0].y = xin[1]; |
70 | showers->in[0].z = xin[2]; |
71 | showers->in[0].px = pin[0]*pin[4]; |
72 | showers->in[0].py = pin[1]*pin[4]; |
73 | showers->in[0].pz = pin[2]*pin[4]; |
74 | showers->in[0].E = pin[3]; |
75 | showers->in[0].ptype = ipart; |
76 | showers->mult = 1; |
77 | showerCount++; |
78 | } |
79 | } |
80 | |
81 | /* post the hit to the hits tree, mark block as hit */ |
82 | |
83 | if (dEsum > 0) |
84 | { |
85 | int nhit; |
86 | s_CcalTruthHits_t* hits; |
87 | int row = getrow_(); |
88 | int column = getcolumn_(); |
89 | |
90 | float dist = 0.5*LENGTH_OF_BLOCK18.-xccal[2]; |
91 | float dEcorr = dEsum * exp(-dist/ATTEN_LENGTH60.); |
92 | float tcorr = t + dist/C_EFFECTIVE13.; |
93 | int mark = ((row+1)<<16) + (column+1); |
94 | void** twig = getTwig(&ComptonCalTree, mark); |
95 | if (*twig == 0) |
96 | { |
97 | s_ComptonEMcal_t* cal = *twig = make_s_ComptonEMcal(); |
98 | s_CcalBlocks_t* blocks = make_s_CcalBlocks(1); |
99 | blocks->mult = 1; |
100 | blocks->in[0].row = row; |
101 | blocks->in[0].column = column; |
102 | blocks->in[0].ccalTruthHits = hits = make_s_CcalTruthHits(MAX_HITS100); |
103 | cal->ccalBlocks = blocks; |
104 | blockCount++; |
105 | } |
106 | else |
107 | { |
108 | s_ComptonEMcal_t* cal = *twig; |
109 | hits = cal->ccalBlocks->in[0].ccalTruthHits; |
110 | } |
111 | |
112 | for (nhit = 0; nhit < hits->mult; nhit++) |
113 | { |
114 | if (fabs(hits->in[nhit].t - tcorr) < TWO_HIT_RESOL75.) |
115 | { |
116 | break; |
117 | } |
118 | } |
119 | if (nhit < hits->mult) /* merge with former hit */ |
120 | { |
121 | hits->in[nhit].t = |
122 | (hits->in[nhit].t * hits->in[nhit].E + tcorr*dEcorr) |
123 | / (hits->in[nhit].E += dEcorr); |
124 | } |
125 | else if (nhit < MAX_HITS100) /* create new hit */ |
126 | { |
127 | hits->in[nhit].t = tcorr; |
128 | hits->in[nhit].E = dEcorr; |
129 | hits->mult++; |
130 | } |
131 | else |
132 | { |
133 | fprintf(stderrstderr,"HDGeant error in hitComptonEMcal: "); |
134 | fprintf(stderrstderr,"max hit count %d exceeded, truncating!\n",MAX_HITS100); |
135 | exit(2); |
136 | } |
137 | } |
138 | } |
139 | |
140 | /* entry point from fortran */ |
141 | |
142 | void hitcomptonemcal_(float* xin, float* xout, |
143 | float* pin, float* pout, float* dEsum, |
144 | int* track, int* stack, int* history, int* ipart) |
145 | { |
146 | hitComptonEMcal(xin,xout,pin,pout,*dEsum,*track,*stack,*history, *ipart); |
147 | } |
148 | |
149 | |
150 | /* pick and package the hits for shipping */ |
151 | |
152 | s_ComptonEMcal_t* pickComptonEMcal () |
153 | { |
154 | s_ComptonEMcal_t* box; |
155 | s_ComptonEMcal_t* item; |
156 | |
157 | if ((blockCount == 0) && (showerCount == 0)) |
158 | { |
159 | return HDDM_NULL(void*)&hddm_s_nullTarget; |
160 | } |
161 | |
162 | box = make_s_ComptonEMcal(); |
163 | box->ccalBlocks = make_s_CcalBlocks(blockCount); |
164 | box->ccalTruthShowers = make_s_CcalTruthShowers(showerCount); |
165 | while (item = (s_ComptonEMcal_t*) pickTwig(&ComptonCalTree)) |
166 | { |
167 | s_CcalBlocks_t* blocks = item->ccalBlocks; |
168 | int block; |
169 | s_CcalTruthShowers_t* showers = item->ccalTruthShowers; |
170 | int shower; |
171 | for (block=0; block < blocks->mult; ++block) |
172 | { |
173 | int row = blocks->in[block].row; |
174 | int column = blocks->in[block].column; |
Value stored to 'column' during its initialization is never read | |
175 | s_CcalTruthHits_t* hits = blocks->in[block].ccalTruthHits; |
176 | |
177 | if (hits) |
178 | { |
179 | int m = box->ccalBlocks->mult; |
180 | |
181 | /* compress out the hits below threshold */ |
182 | int i,iok; |
183 | for (iok=i=0; i < hits->mult; i++) |
184 | { |
185 | if (hits->in[i].E >= THRESH_MEV20./1e3) |
186 | { |
187 | if (iok < i) |
188 | { |
189 | hits->in[iok] = hits->in[i]; |
190 | } |
191 | ++iok; |
192 | } |
193 | } |
194 | if (iok) |
195 | { |
196 | hits->mult = iok; |
197 | box->ccalBlocks->in[m] = blocks->in[block]; |
198 | box->ccalBlocks->mult++; |
199 | } |
200 | else if (hits != HDDM_NULL(void*)&hddm_s_nullTarget) |
201 | { |
202 | FREE(hits)free(hits); |
203 | } |
204 | } |
205 | else if (hits != HDDM_NULL(void*)&hddm_s_nullTarget) |
206 | { |
207 | FREE(hits)free(hits); |
208 | } |
209 | } |
210 | |
211 | for (shower=0; shower < showers->mult; ++shower) |
212 | { |
213 | int m = box->ccalTruthShowers->mult++; |
214 | box->ccalTruthShowers->in[m] = showers->in[shower]; |
215 | } |
216 | if (blocks != HDDM_NULL(void*)&hddm_s_nullTarget) |
217 | { |
218 | FREE(blocks)free(blocks); |
219 | } |
220 | if (showers != HDDM_NULL(void*)&hddm_s_nullTarget) |
221 | { |
222 | FREE(showers)free(showers); |
223 | } |
224 | FREE(item)free(item); |
225 | } |
226 | |
227 | blockCount = showerCount = 0; |
228 | |
229 | if ((box->ccalBlocks != HDDM_NULL(void*)&hddm_s_nullTarget) && |
230 | (box->ccalBlocks->mult == 0)) |
231 | { |
232 | FREE(box->ccalBlocks)free(box->ccalBlocks); |
233 | box->ccalBlocks = HDDM_NULL(void*)&hddm_s_nullTarget; |
234 | } |
235 | if ((box->ccalTruthShowers != HDDM_NULL(void*)&hddm_s_nullTarget) && |
236 | (box->ccalTruthShowers->mult == 0)) |
237 | { |
238 | FREE(box->ccalTruthShowers)free(box->ccalTruthShowers); |
239 | box->ccalTruthShowers = HDDM_NULL(void*)&hddm_s_nullTarget; |
240 | } |
241 | if ((box->ccalBlocks->mult == 0) && |
242 | (box->ccalTruthShowers->mult == 0)) |
243 | { |
244 | FREE(box)free(box); |
245 | box = HDDM_NULL(void*)&hddm_s_nullTarget; |
246 | } |
247 | return box; |
248 | } |