1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | #include <math.h> |
8 | #include <DVector3.h> |
9 | |
10 | using namespace std; |
11 | |
12 | #include "DFCALShower_factory.h" |
13 | #include "DFCALGeometry.h" |
14 | |
15 | #include "DFCALHit.h" |
16 | #include <JANA/JEvent.h> |
17 | #include <JANA/JApplication.h> |
18 | using namespace jana; |
19 | |
20 | |
21 | |
22 | |
23 | DFCALShower_factory::DFCALShower_factory() |
24 | { |
25 | |
26 | |
27 | |
28 | SHOWER_ENERGY_THRESHOLD = 50*k_MeV; |
29 | |
30 | NON_LIN_COEF_A = 0.439287; |
31 | NON_LIN_COEF_B = 0.503378; |
32 | NON_LIN_COEF_C = 1.80842; |
33 | NON_LIN_COEF_alfa = 1+0.0724789; |
34 | |
35 | |
36 | SHOWER_TIMING_WINDOW = 5.0; |
37 | |
38 | |
39 | |
40 | FCAL_RADIATION_LENGTH = 3.1; |
41 | FCAL_CRITICAL_ENERGY = 0.035; |
42 | FCAL_SHOWER_OFFSET = 1.0; |
43 | |
44 | gPARMS->SetDefaultParameter("FCAL:SHOWER_ENERGY_THRESHOLD", SHOWER_ENERGY_THRESHOLD); |
45 | |
46 | gPARMS->SetDefaultParameter("FCAL:NON_LIN_COEF_A", NON_LIN_COEF_A); |
47 | gPARMS->SetDefaultParameter("FCAL:NON_LIN_COEF_B", NON_LIN_COEF_B); |
48 | gPARMS->SetDefaultParameter("FCAL:NON_LIN_COEF_C", NON_LIN_COEF_C); |
49 | gPARMS->SetDefaultParameter("FCAL:NON_LIN_COEF_alfa", NON_LIN_COEF_alfa); |
50 | |
51 | gPARMS->SetDefaultParameter("FCAL:SHOWER_TIMING_WINDOW", SHOWER_TIMING_WINDOW); |
52 | |
53 | gPARMS->SetDefaultParameter("FCAL:FCAL_RADIATION_LENGTH", FCAL_RADIATION_LENGTH); |
54 | gPARMS->SetDefaultParameter("FCAL:FCAL_CRITICAL_ENERGY", FCAL_CRITICAL_ENERGY); |
55 | gPARMS->SetDefaultParameter("FCAL:FCAL_SHOWER_OFFSET", FCAL_SHOWER_OFFSET); |
56 | |
57 | } |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | jerror_t DFCALShower_factory::brun(JEventLoop *loop, int runnumber) |
64 | { |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | FCAL_C_EFFECTIVE=15.; |
78 | map<string, double> fcal_parms; |
79 | loop->GetCalib("FCAL/fcal_parms", fcal_parms); |
80 | if (fcal_parms.find("FCAL_C_EFFECTIVE")!=fcal_parms.end()){ |
81 | FCAL_C_EFFECTIVE = fcal_parms["FCAL_C_EFFECTIVE"]; |
82 | if(debug_level>0)jout<<"FCAL_C_EFFECTIVE = "<<FCAL_C_EFFECTIVE<<endl; |
83 | } else { |
84 | jerr<<"Unable to get FCAL_C_EFFECTIVE from FCAL/fcal_parms in Calib database!"<<endl; |
85 | } |
86 | |
87 | m_zTarget=65.0*k_cm; |
88 | DApplication *dapp = dynamic_cast<DApplication*>(loop->GetJApplication()); |
89 | if (dapp) { |
90 | const DGeometry *geom = dapp->GetDGeometry(runnumber); |
91 | geom->GetTargetZ(m_zTarget); |
92 | } |
93 | |
94 | return NOERROR; |
95 | } |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | jerror_t DFCALShower_factory::evnt(JEventLoop *eventLoop, int eventnumber) |
102 | { |
103 | vector<const DFCALCluster*> fcalClusters; |
104 | eventLoop->Get(fcalClusters); |
105 | |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | |
115 | if(fcalClusters.size()<1)return NOERROR; |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | |
154 | |
155 | |
156 | |
157 | |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | |
183 | |
184 | |
185 | |
186 | |
187 | |
188 | |
189 | |
190 | for( vector< const DFCALCluster* >::const_iterator clItr = fcalClusters.begin(); |
191 | clItr != fcalClusters.end(); ++clItr ){ |
192 | |
193 | DFCALShower* fcalShower = makeFcalShower( *clItr ); |
194 | |
195 | |
196 | |
197 | |
198 | |
199 | |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | DVector3 pos = fcalShower->getPosition(); |
206 | DVector3 vertex(0.0, 0.0, m_zTarget); |
207 | double dist1 = (pos-vertex).Mag(); |
208 | double dist2 = DFCALGeometry::fcalFaceZ() + DFCALGeometry::blockLength() - pos.Z(); |
209 | double expected_time = dist1/SPEED_OF_LIGHT29.9792 + dist2/FCAL_C_EFFECTIVE; |
210 | |
211 | if ( fcalShower->getEnergy() <= 0 ) { |
212 | cout << "Deleting fcalShower " << endl; |
213 | delete fcalShower; |
214 | continue; |
215 | } else if ( fabs(fcalShower->getTime() - expected_time) > SHOWER_TIMING_WINDOW ){ |
216 | delete fcalShower; |
217 | continue; |
218 | } else { |
219 | _data.push_back(fcalShower); |
220 | } |
221 | |
222 | } |
223 | |
224 | return NOERROR; |
225 | } |
226 | |
227 | |
228 | |
229 | |
230 | |
231 | DFCALShower* DFCALShower_factory::makeFcalShower( const DFCALCluster* cluster ) |
232 | { |
233 | |
234 | |
235 | |
236 | |
237 | |
238 | |
239 | DVector3 target(0.0, 0.0, m_zTarget); |
240 | |
241 | double cTime = cluster->getTime(); |
242 | |
243 | double errX = cluster->getRMS_x(); |
244 | double errY = cluster->getRMS_y(); |
245 | double errZ; |
246 | |
247 | |
248 | double Ecorrected; |
249 | DVector3 pos_corrected; |
250 | GetCorrectedEnergyAndPosition( cluster , Ecorrected, pos_corrected, errZ, &target); |
| 1 | Calling 'GetCorrectedEnergyAndPosition' | |
|
| 17 | | Returning from 'GetCorrectedEnergyAndPosition' | |
|
251 | |
252 | |
253 | |
254 | DFCALShower* shower = new DFCALShower; |
255 | |
256 | shower->setEnergy( Ecorrected ); |
257 | shower->setPosition( pos_corrected ); |
258 | shower->setPosError( errX, errY, errZ ); |
| 18 | | Function call argument is an uninitialized value |
|
259 | shower->setTime ( cTime ); |
260 | |
261 | shower->AddAssociatedObject(cluster); |
262 | |
263 | return shower; |
264 | } |
265 | |
266 | |
267 | |
268 | |
269 | |
270 | |
271 | void DFCALShower_factory::GetCorrectedEnergyAndPosition(const DFCALCluster* cluster, double &Ecorrected, DVector3 &pos_corrected, double &errZ, const DVector3 *vertex) |
272 | { |
273 | |
274 | int MAXITER = 1000; |
275 | |
276 | DVector3 posInCal = cluster->getCentroid(); |
| |
| 3 | | Returning from 'getCentroid' | |
|
277 | float x0 = posInCal.Px(); |
| |
| |
278 | float y0 = posInCal.Py(); |
| |
| |
279 | |
280 | double Eclust = cluster->getEnergy(); |
| |
| 9 | | Returning from 'getEnergy' | |
|
281 | |
282 | double A = NON_LIN_COEF_A; |
283 | double B = NON_LIN_COEF_B; |
284 | double C = NON_LIN_COEF_C; |
285 | double alfa = NON_LIN_COEF_alfa; |
286 | |
287 | |
288 | double Egamma = 0.; |
289 | |
290 | if ( A > 0 ) { |
| |
291 | |
292 | Egamma = Eclust/A; |
293 | |
294 | for ( int niter=0; 1; niter++) { |
| 11 | | Loop condition is true. Entering loop body | |
|
295 | |
296 | double energy = Egamma; |
297 | double non_lin_part = pow(Egamma,1+alfa)/(B+C*Egamma); |
298 | Egamma = Eclust/A - non_lin_part; |
299 | if ( fabs( (Egamma-energy)/energy ) < 0.001 ) { |
| |
300 | |
301 | break; |
| 13 | | Execution continues on line 324 | |
|
302 | |
303 | } |
304 | else if ( niter > MAXITER ) { |
305 | |
306 | cout << " Iteration failed for cluster energy " << Eclust << endl; |
307 | Egamma = 0; |
308 | |
309 | break; |
310 | |
311 | } |
312 | |
313 | } |
314 | |
315 | } |
316 | else { |
317 | |
318 | cout << "Warning: DFCALShower : parameter A" << A << " is not valid" << endl; |
319 | } |
320 | |
321 | |
322 | |
323 | |
324 | if ( Egamma > 0 ) { |
| |
325 | float xV = vertex->X(); |
326 | float yV = vertex->Y(); |
327 | float zV = vertex->Z(); |
328 | |
329 | |
330 | double z0 = DFCALGeometry::fcalFaceZ() - zV; |
331 | double zMax = (FCAL_RADIATION_LENGTH*( |
332 | FCAL_SHOWER_OFFSET + log(Egamma/FCAL_CRITICAL_ENERGY))); |
333 | double zed = z0; |
334 | double zed1 = z0 + zMax; |
335 | |
336 | double r0 = sqrt( (x0-xV)*(x0-xV) + (y0-yV)*(y0-yV) ); |
337 | |
338 | int niter; |
339 | for ( niter=0; niter<100; niter++) { |
340 | |
341 | double tt = r0/zed1; |
342 | zed = z0 + zMax/sqrt( 1 + tt*tt ); |
343 | if ( fabs( (zed-zed1) ) < 0.001) { |
344 | break; |
345 | } |
346 | zed1 = zed; |
347 | } |
348 | |
349 | posInCal.SetZ( zed + zV ); |
350 | errZ = zed - zed1; |
351 | } |
352 | |
353 | Ecorrected = Egamma; |
354 | pos_corrected = posInCal; |
| |
| 16 | | Returning from 'operator=' | |
|
355 | } |
356 | |
357 | |
358 | |