Fork me on GitHub

source: svn/trunk/src/BFieldProp.cc@ 274

Last change on this file since 274 was 270, checked in by severine ovyn, 16 years ago

remove double GEN pfff

File size: 18.8 KB
Line 
1/***********************************************************************
2** **
3** /----------------------------------------------\ **
4** | Delphes, a framework for the fast simulation | **
5** | of a generic collider experiment | **
6** \----------------------------------------------/ **
7** **
8** **
9** This package uses: **
10** ------------------ **
11** FastJet algorithm: Phys. Lett. B641 (2006) [hep-ph/0512210] **
12** Hector: JINST 2:P09005 (2007) [physics.acc-ph:0707.1198v2] **
13** FROG: [hep-ex/0901.2718v1] **
14** **
15** ------------------------------------------------------------------ **
16** **
17** Main authors: **
18** ------------- **
19** **
20** Severine Ovyn Xavier Rouby **
21** severine.ovyn@uclouvain.be xavier.rouby@cern **
22** **
23** Center for Particle Physics and Phenomenology (CP3) **
24** Universite catholique de Louvain (UCL) **
25** Louvain-la-Neuve, Belgium **
26** **
27** Copyright (C) 2008-2009, **
28** All rights reserved. **
29** **
30***********************************************************************/
31
32#include "BFieldProp.h"
33#include<cmath>
34using namespace std;
35
36
37//------------------------------------------------------------------------------
38extern const float UNDEFINED;
39
40TrackPropagation::TrackPropagation(){
41 DET = new RESOLution();
42 init();
43}
44
45TrackPropagation::TrackPropagation(const string& DetDatacard){
46 DET = new RESOLution();
47 DET->ReadDataCard(DetDatacard);
48 init();
49}
50
51TrackPropagation::TrackPropagation(const RESOLution* DetDatacard){
52 DET= new RESOLution(*DetDatacard);
53 init();
54}
55
56TrackPropagation::TrackPropagation(const TrackPropagation & tp){
57 MAXITERATION = tp.MAXITERATION;
58 DET = new RESOLution(*(tp.DET));
59 R_max = tp.R_max; z_max = tp.z_max;
60 B_x = tp.B_x; B_y = tp.B_y; B_z = tp.B_z;
61 q = tp.q; phi_0 = tp.phi_0;
62 gammam= tp.gammam; omega = tp.omega;
63 r = tp.r; rr = tp.rr;
64 x_c = tp.x_c; y_c = tp.y_c;
65 R_c = tp.R_c; Phi_c = tp.Phi_c;
66 t = tp.t; t_z = tp.t_z; t_T = tp.t_T;
67 x_t = tp.x_t; y_t = tp.y_t; z_t = tp.z_t;
68 R_t = tp.R_t; Phi_t = tp.Phi_t;
69 Theta_t=tp.Theta_t; Eta_t = tp.Eta_t;
70 Px_t = tp.Px_t; Py_t = tp.Py_t; Pz_t = tp.Pz_t;
71 PT_t = tp.PT_t; p_t = tp.p_t; E_t = tp.E_t;
72 loop_overflow_counter = tp.loop_overflow_counter;
73}
74
75TrackPropagation& TrackPropagation::operator=(const TrackPropagation & tp) {
76 if(this==&tp) return *this;
77 MAXITERATION = tp.MAXITERATION;
78 DET = new RESOLution(*(tp.DET));
79 R_max = tp.R_max; z_max = tp.z_max;
80 B_x = tp.B_x; B_y = tp.B_y; B_z = tp.B_z;
81 q = tp.q; phi_0 = tp.phi_0;
82 gammam= tp.gammam; omega = tp.omega;
83 r = tp.r; rr = tp.rr;
84 x_c = tp.x_c; y_c = tp.y_c;
85 R_c = tp.R_c; Phi_c = tp.Phi_c;
86 t = tp.t; t_z = tp.t_z; t_T = tp.t_T;
87 x_t = tp.x_t; y_t = tp.y_t; z_t = tp.z_t;
88 R_t = tp.R_t; Phi_t = tp.Phi_t;
89 Theta_t=tp.Theta_t; Eta_t = tp.Eta_t;
90 Px_t = tp.Px_t; Py_t = tp.Py_t; Pz_t = tp.Pz_t;
91 PT_t = tp.PT_t; p_t = tp.p_t; E_t = tp.E_t;
92 loop_overflow_counter = tp.loop_overflow_counter;
93 return *this;
94}
95
96void TrackPropagation::init() {
97 MAXITERATION = 10000;
98 q= UNDEFINED; phi_0= UNDEFINED; gammam= UNDEFINED; omega=UNDEFINED; r=UNDEFINED;
99 x_c=UNDEFINED; y_c=UNDEFINED; R_c=UNDEFINED; Phi_c=UNDEFINED;
100 rr=UNDEFINED; t=UNDEFINED; t_z=UNDEFINED; t_T=UNDEFINED;
101 x_t=UNDEFINED; y_t=UNDEFINED; z_t=UNDEFINED;
102 R_t=UNDEFINED; Phi_t=UNDEFINED; Theta_t=UNDEFINED; Eta_t=UNDEFINED;
103 Px_t=UNDEFINED; Py_t=UNDEFINED; Pz_t=UNDEFINED; PT_t=UNDEFINED; p_t=UNDEFINED; E_t=UNDEFINED;
104
105 // DET has been initialised in the constructors
106 // magnetic field parameters
107 R_max = DET->TRACK_radius;
108 z_max = DET->TRACK_length/2.;
109 B_x = DET->TRACK_bfield_x;
110 B_y = DET->TRACK_bfield_y;
111 B_z = DET->TRACK_bfield_z;
112
113 loop_overflow_counter=0;
114}
115
116
117
118void TrackPropagation::Propagation(const TRootGenParticle *Part,TLorentzVector &momentum) {
119
120 q = ChargeVal(Part->PID);
121 if(q==0) return;
122
123 if(R_max ==0) { cout << "ERROR: magnetic field has no lateral extention\n"; return;}
124 if(z_max==0) { cout << "ERROR: magnetic field has no longitudinal extention\n"; return;}
125
126 if (B_x== 0 && B_y== 0) { // faster if only B_z
127 if (B_z==0) return; // nothing to do
128
129 // initial conditions:
130 // p_X0 = Part->Px, p_Y0 = Part->Py, p_Z0 = Part->Pz, p_T0 = Part->PT;
131 // X_0 = Part->X, Y_0 = Part->Y, Z_0 = Part->Z;
132
133 // 1. initial transverse momentum p_{T0} : Part->PT
134 // initial transverse momentum direction \phi_0 = -atan(p_X0/p_Y0)
135 // relativistic gamma : gamma = E/mc² ; gammam = gamma \times m
136 // giration frequency \omega = q/(gamma m) B_z
137 // helix radius r = p_T0 / (omega gamma m)
138 phi_0 = -atan2(Part->Px,Part->Py);
139 gammam = Part->E; // here c==1
140 //cout << "gammam" << gammam << "\t gamma" << gammam/Part->M << endl;
141 omega = q * B_z /gammam;
142 r = Part->PT / (omega * gammam);
143
144 // 2. Helix parameters : center coordinates in transverse plane
145 // x_c = x_0 - r*cos(phi_0) and y_c = y_0 - r*sin(phi_0)
146 // R_c = \sqrt{x_c² + y_c²} and \Phi_c = atan{y_c/x_c}
147 x_c = Part->X - r*cos(phi_0); /// TEST !!
148 y_c = Part->Y - r*sin(phi_0);
149 R_c = sqrt(pow(x_c,2.) + pow(y_c,2.) );
150 Phi_c = atan2(y_c,x_c);
151
152 // 3. time evaluation t = min(t_T, t_z)
153 // t_T : time to exit from the sides
154 // t_T= [ Phi_c - phi_0 + atan( (R_max^2 - (R_c^2 + r^2))/(2rR_c) ) ]/omega
155 // t_z : time to exit from the front or the back
156 // t_z = gamma * m /p_z0 \times (-z_0 + z_max * sign(p_z0))
157 rr = sqrt( pow(R_c,2.) + pow(r,2.) ); // temp variable
158 t_T=0;
159 int sign_pz= (Part->Pz >0) ? 1 : -1;
160 t_z = gammam / Part->Pz * (-Part->Z + z_max*sign_pz ) ;
161 if ( fabs(R_c - r) > R_max || R_c + r < R_max ) t = t_z;
162 else {
163 t_T = (Phi_c - phi_0 + atan2( (R_max + rr)*(R_max - rr) , 2*r*R_c ) ) / omega;
164 t = min(t_T,t_z);
165 }
166
167 // 4. position in terms of x(t), y(t), z(t)
168 // x(t) = x_c + r cos (omega t + phi_0)
169 // y(t) = y_c + r sin (omega t + phi_0)
170 // z(t) = z_0 + (p_Z0/gammam) t
171 x_t = x_c + r * cos(omega * t + phi_0);
172 y_t = y_c + r * sin(omega * t + phi_0);
173 z_t = Part->Z + Part->Pz / gammam * t;
174
175 // 5. position in terms of Theta(t), Phi(t), R(t), Eta(t)
176 // R(t) = sqrt(x(t)² + y(t)²)
177 // Phi(t) = atan(y(t)/x(t))
178 // Theta(t) = atan(R(t)/z(t))
179 // Eta(t) = -ln tan (Theta(t)/2)
180 R_t = sqrt( pow(x_t,2.) + pow(y_t,2.) );
181 Phi_t = atan2( y_t, x_t);
182 if(R_t>0) {
183 Theta_t = acos( z_t / sqrt(z_t*z_t+ R_t*R_t));
184 Eta_t = - log(tan(Theta_t/2.));
185 } else{
186 Theta_t=0; Eta_t = 9999;
187 }
188
189 Px_t = - Part->PT * sin(omega*t + phi_0);
190 Py_t = Part->PT * cos(omega*t + phi_0);
191 Pz_t = Part->Pz;
192 PT_t = sqrt(Px_t*Px_t + Py_t*Py_t);
193 p_t = sqrt(PT_t*PT_t + Pz_t*Pz_t);
194 E_t=sqrt(Part->M*Part->M +p_t);
195 //if(p_t != fabs(Pz_t) ) Eta_t = log( (p_t+Pz_t)/(p_t-Pz_t) )/2.;
196 //if(p_t>0) Theta_t = acos(Pz_t/p_t);
197 momentum.SetPxPyPzE(Px_t,Py_t,Pz_t,E_t);
198
199// test zone ---
200/*
201 cout << cos(atan(R_t/z_t)) << "\t" << cos(Theta_t) << "\t" << cos(momentum.Theta()) << "\t" << Pz_t/temp_p << endl;
202 double Eta_t1 = log( (E+Pz_t)/(E-Pz_t) )/2.;
203 double Eta_t2 = log( (temp_p+Pz_t)/(temp_p-Pz_t) )/2.;
204 if(0 && fabs(Eta_t -Eta_t2)>1e-310) {
205 cout << "ERROR-BUG: Eta_t != Eta_t2\n";
206 cout << "Eta_t= " << Eta_t << "\t Eta_t1= " << Eta_t1 << "\t Eta_t2= " << Eta_t2 << endl;
207 }
208
209 double R_t2 = sqrt( pow(R_c,2.) + pow(r,2.) + 2*r*R_c*cos(phi_0 + omega*t - Phi_c) ); // cross-check
210 if(fabs(R_t - R_t2) > 1e-7)
211 cout << "ERROR-BUG: R_t != R_t2: R_t=" << R_t << " R_t2=" << R_t2 << " R_t - R_t2 =" << R_t - R_t2 << endl;
212 if( fabs(E - gammam) > 1e-3 ) {
213 cout << "ERROR-BUG: energy is not conserved in src/BFieldProp.cc\n";
214 cout << "E - momentum.E() = " << fabs(E - momentum.E()) << " gammam - E " << fabs(gammam -E) << endl; }
215 if( fabs(PT_t - Part->PT) > 1e-10 ) {
216 cout << "ERROR-BUG: PT is not conversed in src/BFieldProp.cc. ";
217 cout << "(at " << 100*(PT_t - Part->PT) << "%)\n";
218 }
219 if(momentum.Pz() != Pz_t)
220 cout << "ERROR-BUG: Pz is not conserved in src/BFieldProp.cc\n";
221
222 double temp_p0=sqrt(Part->PT*Part->PT + Part->Pz*Part->Pz);
223 if(fabs( (temp_p-temp_p0)*(temp_p+temp_p0) )>1e-10 ) {
224 cout << "ERROR-BUG: momentum |vec{p}| is not conserved in src/BFieldProp.cc\n";
225 cout << temp_p << "\t" << temp_p0 << endl;
226 }
227
228 // if x_c == y_c ==0 (set it by hand!), easy cross-check
229 //cout << "tan(phi_p)= " << momentum.Py()/momentum.Px() << "\t -1/tan(phi_x)= " << -x_t/y_t << endl;
230*/
231
232 } else { // if B_x or B_y are non zero: longer computation
233
234 float Xvertex1 = Part->X;
235 float Yvertex1 = Part->Y;
236 float Zvertex1 = Part->Z;
237
238 //out of tracking coverage?
239 if(sqrt(Xvertex1*Xvertex1+Yvertex1*Yvertex1) > R_max){return;}
240 if(fabs(Zvertex1) > z_max){return;}
241
242 double px = Part->Px / 0.003;
243 double py = Part->Py / 0.003;
244 double pz = Part->Pz / 0.003;
245 double pt = Part->PT / 0.003; // sqrt(px*px+py*py);
246 double p = sqrt(pz*pz + pt*pt); //sqrt(px*px+py*py+pz*pz);
247
248 double M = Part->M;
249 double vx = px/M;
250 double vy = py/M;
251 double vz = pz/M;
252 double qm = q/M;
253
254 double ax = qm*(B_z*vy - B_y*vz);
255 double ay = qm*(B_x*vz - B_z*vx);
256 double az = qm*(B_y*vx - B_x*vy);
257 double dt = 1/p;
258 if(pt<266 && vz < 0.0012) dt = fabs(0.001/vz); // ?????
259
260 double xold=Xvertex1; double x=xold;
261 double yold=Yvertex1; double y=yold;
262 double zold=Zvertex1; double z=zold;
263
264 double VTold = pt/M; //=sqrt(vx*vx+vy*vy);
265
266 unsigned int k = 0;
267 double VTratio=0;
268 double R_max2 = R_max*R_max;
269 double r2=0; // will be x*x+y*y
270
271 while(k < MAXITERATION){
272 k++;
273
274 vx += ax*dt;
275 vy += ay*dt;
276 vz += az*dt;
277
278 VTratio = VTold/sqrt(vx*vx+vy*vy);
279 vx *= VTratio;
280 vy *= VTratio;
281
282 ax = qm*(B_z*vy - B_y*vz);
283 ay = qm*(B_x*vz - B_z*vx);
284 az = qm*(B_y*vx - B_x*vy);
285
286 x += vx*dt;
287 y += vy*dt;
288 z += vz*dt;
289 r2 = x*x + y*y;
290
291 if( r2 > R_max2 ){
292 x /= r2/R_max2;
293 y /= r2/R_max2;
294 break;
295 }
296 if( fabs(z)>z_max)break;
297
298 xold = x;
299 yold = y;
300 zold = z;
301 } // while loop
302
303 if(k == MAXITERATION) loop_overflow_counter++;
304 //cout << "too short loop in " << loop_overflow_counter << " cases" << endl;
305
306 if(x!=0 && y!=0 && z!=0) {
307 float Theta = atan2(sqrt(r2),z);
308 double eta = -log(tan(Theta/2.));
309 double phi = atan2(y,x);
310 momentum.SetPtEtaPhiE(Part->PT,eta,phi,Part->E);
311 }
312
313 } // if b_x or b_y non zero
314}
315
316
317
318void TrackPropagation::bfield(TRootGenParticle *Part) {
319
320 // initialisation, valid for z_max==0, R_max==0 and q==0
321 Part->EtaCalo = Part->Eta;
322 Part->PhiCalo = Part->Phi;//-atan2(Part->Px,Part->Py);
323
324 if (!DET->FLAG_bfield ) return;
325
326 q = ChargeVal(Part->PID);
327 if(q==0) return;
328 if(R_max ==0) { cout << "ERROR: magnetic field has no lateral extention\n"; return;}
329 if(z_max==0) { cout << "ERROR: magnetic field has no longitudinal extention\n"; return;}
330
331 if (B_x== 0 && B_y== 0) { // faster if only B_z
332 if (B_z==0) return; // nothing to do
333
334 // initial conditions:
335 // p_X0 = Part->Px, p_Y0 = Part->Py, p_Z0 = Part->Pz, p_T0 = Part->PT;
336 // X_0 = Part->X, Y_0 = Part->Y, Z_0 = Part->Z;
337
338 // 1. initial transverse momentum p_{T0} : Part->PT
339 // initial transverse momentum direction \phi_0 = -atan(p_X0/p_Y0)
340 // relativistic gamma : gamma = E/mc² ; gammam = gamma \times m
341 // giration frequency \omega = q/(gamma m) B_z
342 // helix radius r = p_T0 / (omega gamma m)
343 phi_0 = -atan2(Part->Px,Part->Py);
344 gammam = Part->E; // here c==1
345 //cout << "gammam" << gammam << "\t gamma" << gammam/Part->M << endl;
346 omega = q * B_z /gammam;
347 r = Part->PT / (omega * gammam);
348
349 // 2. Helix parameters : center coordinates in transverse plane
350 // x_c = x_0 - r*cos(phi_0) and y_c = y_0 - r*sin(phi_0)
351 // R_c = \sqrt{x_c² + y_c²} and \Phi_c = atan{y_c/x_c}
352 x_c = Part->X - r*cos(phi_0); /// TEST !!
353 y_c = Part->Y - r*sin(phi_0);
354 R_c = sqrt(pow(x_c,2.) + pow(y_c,2.) );
355 Phi_c = atan2(y_c,x_c);
356
357 // 3. time evaluation t = min(t_T, t_z)
358 // t_T : time to exit from the sides
359 // t_T= [ Phi_c - phi_0 + atan( (R_max^2 - (R_c^2 + r^2))/(2rR_c) ) ]/omega
360 // t_z : time to exit from the front or the back
361 // t_z = gamma * m /p_z0 \times (-z_0 + z_max * sign(p_z0))
362 rr = sqrt( pow(R_c,2.) + pow(r,2.) ); // temp variable
363 t_T=0;
364 int sign_pz= (Part->Pz >0) ? 1 : -1;
365 t_z = gammam / Part->Pz * (-Part->Z + z_max*sign_pz ) ;
366 if ( fabs(R_c - r) > R_max || R_c + r < R_max ) t = t_z;
367 else {
368 t_T = (Phi_c - phi_0 + atan2( (R_max + rr)*(R_max - rr) , 2*r*R_c ) ) / omega;
369 t = min(t_T,t_z);
370 }
371
372 // 4. position in terms of x(t), y(t), z(t)
373 // x(t) = x_c + r cos (omega t + phi_0)
374 // y(t) = y_c + r sin (omega t + phi_0)
375 // z(t) = z_0 + (p_Z0/gammam) t
376 x_t = x_c + r * cos(omega * t + phi_0);
377 y_t = y_c + r * sin(omega * t + phi_0);
378 z_t = Part->Z + Part->Pz / gammam * t;
379
380 // 5. position in terms of Theta(t), Phi(t), R(t), Eta(t)
381 // R(t) = sqrt(x(t)² + y(t)²)
382 // Phi(t) = atan(y(t)/x(t))
383 // Theta(t) = atan(R(t)/z(t))
384 // Eta(t) = -ln tan (Theta(t)/2)
385 R_t = sqrt( pow(x_t,2.) + pow(y_t,2.) );
386 Phi_t = atan2( y_t, x_t);
387 if(R_t>0) {
388 Theta_t = acos( z_t / sqrt(z_t*z_t+ R_t*R_t));
389 Eta_t = - log(tan(Theta_t/2.));
390 } else{
391 Theta_t=0; Eta_t = UNDEFINED;
392 }
393/* Not needed here. but these formulae are correct -------
394 Px_t = - Part->PT * sin(omega*t + phi_0);
395 Py_t = Part->PT * cos(omega*t + phi_0);
396 Pz_t = Part->Pz;
397 PT_t = sqrt(Px_t*Px_t + Py_t*Py_t);
398 p_t = sqrt(PT_t*PT_t + Pz_t*Pz_t);
399 E_t=sqrt(Part->M*Part->M +p_t);
400 //if(p_t != fabs(Pz_t) ) Eta_t = log( (p_t+Pz_t)/(p_t-Pz_t) )/2.;
401 //if(p_t>0) Theta_t = acos(Pz_t/p_t);
402 momentum.SetPxPyPzE(Px_t,Py_t,Pz_t,E_t);
403*/
404 Part->EtaCalo = Eta_t;
405 Part->PhiCalo = Phi_t;
406 return;
407// test zone ---
408/*
409 cout << cos(atan(R_t/z_t)) << "\t" << cos(Theta_t) << "\t" << cos(momentum.Theta()) << "\t" << Pz_t/temp_p << endl;
410 double Eta_t1 = log( (E+Pz_t)/(E-Pz_t) )/2.;
411 double Eta_t2 = log( (temp_p+Pz_t)/(temp_p-Pz_t) )/2.;
412 if(0 && fabs(Eta_t -Eta_t2)>1e-310) {
413 cout << "ERROR-BUG: Eta_t != Eta_t2\n";
414 cout << "Eta_t= " << Eta_t << "\t Eta_t1= " << Eta_t1 << "\t Eta_t2= " << Eta_t2 << endl;
415 }
416
417 double R_t2 = sqrt( pow(R_c,2.) + pow(r,2.) + 2*r*R_c*cos(phi_0 + omega*t - Phi_c) ); // cross-check
418 if(fabs(R_t - R_t2) > 1e-7)
419 cout << "ERROR-BUG: R_t != R_t2: R_t=" << R_t << " R_t2=" << R_t2 << " R_t - R_t2 =" << R_t - R_t2 << endl;
420 if( fabs(E - gammam) > 1e-3 ) {
421 cout << "ERROR-BUG: energy is not conserved in src/BFieldProp.cc\n";
422 cout << "E - momentum.E() = " << fabs(E - momentum.E()) << " gammam - E " << fabs(gammam -E) << endl; }
423 if( fabs(PT_t - Part->PT) > 1e-10 ) {
424 cout << "ERROR-BUG: PT is not conversed in src/BFieldProp.cc. ";
425 cout << "(at " << 100*(PT_t - Part->PT) << "%)\n";
426 }
427 if(momentum.Pz() != Pz_t)
428 cout << "ERROR-BUG: Pz is not conserved in src/BFieldProp.cc\n";
429
430 double temp_p0=sqrt(Part->PT*Part->PT + Part->Pz*Part->Pz);
431 if(fabs( (temp_p-temp_p0)*(temp_p+temp_p0) )>1e-10 ) {
432 cout << "ERROR-BUG: momentum |vec{p}| is not conserved in src/BFieldProp.cc\n";
433 cout << temp_p << "\t" << temp_p0 << endl;
434 }
435
436 // if x_c == y_c ==0 (set it by hand!), easy cross-check
437 //cout << "tan(phi_p)= " << momentum.Py()/momentum.Px() << "\t -1/tan(phi_x)= " << -x_t/y_t << endl;
438*/
439
440 } else { // if B_x or B_y are non zero: longer computation
441//cout << "bfield de loic\n";
442 float Xvertex1 = Part->X;
443 float Yvertex1 = Part->Y;
444 float Zvertex1 = Part->Z;
445
446 //out of tracking coverage?
447 if(sqrt(Xvertex1*Xvertex1+Yvertex1*Yvertex1) > R_max){return;}
448 if(fabs(Zvertex1) > z_max){return;}
449
450 double px = Part->Px / 0.003;
451 double py = Part->Py / 0.003;
452 double pz = Part->Pz / 0.003;
453 double pt = Part->PT / 0.003; // sqrt(px*px+py*py);
454 double p = sqrt(pz*pz + pt*pt); //sqrt(px*px+py*py+pz*pz);
455
456 double M = Part->M;
457 double vx = px/M;
458 double vy = py/M;
459 double vz = pz/M;
460 double qm = q/M;
461
462 double ax = qm*(B_z*vy - B_y*vz);
463 double ay = qm*(B_x*vz - B_z*vx);
464 double az = qm*(B_y*vx - B_x*vy);
465 double dt = 1/p;
466 if(pt<266 && vz < 0.0012) dt = fabs(0.001/vz); // ?????
467
468 double xold=Xvertex1; double x=xold;
469 double yold=Yvertex1; double y=yold;
470 double zold=Zvertex1; double z=zold;
471
472 double VTold = pt/M; //=sqrt(vx*vx+vy*vy);
473
474 unsigned int k = 0;
475 double VTratio=0;
476 double R_max2 = R_max*R_max;
477 double r2=0; // will be x*x+y*y
478
479 while(k < MAXITERATION){
480 k++;
481
482 vx += ax*dt;
483 vy += ay*dt;
484 vz += az*dt;
485
486 VTratio = VTold/sqrt(vx*vx+vy*vy);
487 vx *= VTratio;
488 vy *= VTratio;
489
490 ax = qm*(B_z*vy - B_y*vz);
491 ay = qm*(B_x*vz - B_z*vx);
492 az = qm*(B_y*vx - B_x*vy);
493
494 x += vx*dt;
495 y += vy*dt;
496 z += vz*dt;
497 r2 = x*x + y*y;
498
499 if( r2 > R_max2 ){
500 x /= r2/R_max2;
501 y /= r2/R_max2;
502 break;
503 }
504 if( fabs(z)>z_max)break;
505
506 xold = x;
507 yold = y;
508 zold = z;
509 } // while loop
510
511 if(k == MAXITERATION) loop_overflow_counter++;
512 //cout << "too short loop in " << loop_overflow_counter << " cases" << endl;
513 float Theta=0;
514 if(x!=0 && y!=0 && z!=0) {
515 Theta = atan2(sqrt(r2),z);
516 Part->EtaCalo = -log(tan(Theta/2.));
517 Part->PhiCalo = atan2(y,x);
518 //momentum.SetPtEtaPhiE(Part->PT,eta,phi,Part->E);
519 }
520 } // if b_x or b_y non zero
521}
Note: See TracBrowser for help on using the repository browser.