Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
grkuta.cc
Go to the documentation of this file.
1 /*
2  This file was generated from the file grkuta.F from the GEANT3.2.1 package.
3  It was converted into C using the f2c program and the f2c.h header file
4  was pasted directly into it in place of the #include.
5 
6  This was done because it makes the DANA swimmer agree very closely with
7  the GEANT3 swimmer. It is not intended that this routine will survive in
8  this form, but will be converted to a method of DMagneticFieldStepper
9  in a more readable form.
10 
11  12/26/2006 -David Lawrence
12 */
13 
14 
15 
16 
17 /* grkuta.F -- translated by f2c (version 20061008).
18  You must link the resulting object file with libf2c:
19  on Microsoft Windows system, link with libf2c.lib;
20  on Linux or Unix systems, link with .../path/to/libf2c.a -lm
21  or, if you install libf2c.a in a standard place, with -lf2c -lm
22  -- in that order, at the end of the command line, as in
23  cc *.o -lf2c -lm
24  Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
25 
26  http://www.netlib.org/f2c/libf2c.zip
27 */
28 
29 /* f2c.h -- Standard Fortran to C header file */
30 
31 /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
32 
33  - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
34 
35 #ifndef F2C_INCLUDE
36 #define F2C_INCLUDE
37 
38 typedef long int integer;
39 typedef unsigned long int uinteger;
40 typedef char *address;
41 typedef short int shortint;
42 typedef float real;
43 typedef double doublereal;
44 typedef struct { real r, i; } complex;
45 typedef struct { doublereal r, i; } doublecomplex;
46 typedef long int logical;
47 typedef short int shortlogical;
48 typedef char logical1;
49 typedef char integer1;
50 #ifdef INTEGER_STAR_8 /* Adjust for integer*8. */
51 typedef long long longint; /* system-dependent */
52 typedef unsigned long long ulongint; /* system-dependent */
53 #define qbit_clear(a,b) ((a) & ~((ulongint)1 << (b)))
54 #define qbit_set(a,b) ((a) | ((ulongint)1 << (b)))
55 #endif
56 
57 #define TRUE_ (1)
58 #define FALSE_ (0)
59 
60 /* Extern is for use with -E */
61 #ifndef Extern
62 #define Extern extern
63 #endif
64 
65 /* I/O stuff */
66 
67 #ifdef f2c_i2
68 /* for -i2 */
69 typedef short flag;
70 typedef short ftnlen;
71 typedef short ftnint;
72 #else
73 typedef long int flag;
74 typedef long int ftnlen;
75 typedef long int ftnint;
76 #endif
77 
78 /*external read, write*/
79 typedef struct
83  char *cifmt;
85 } cilist;
86 
87 /*internal read, write*/
88 typedef struct
90  char *iciunit;
92  char *icifmt;
95 } icilist;
96 
97 /*open*/
98 typedef struct
101  char *ofnm;
103  char *osta;
104  char *oacc;
105  char *ofm;
107  char *oblnk;
108 } olist;
109 
110 /*close*/
111 typedef struct
114  char *csta;
115 } cllist;
116 
117 /*rewind, backspace, endfile*/
118 typedef struct
121 } alist;
122 
123 /* inquire */
124 typedef struct
127  char *infile;
129  ftnint *inex; /*parameters in standard's order*/
133  char *inname;
135  char *inacc;
137  char *inseq;
139  char *indir;
141  char *infmt;
143  char *inform;
145  char *inunf;
149  char *inblank;
151 } inlist;
152 
153 #define VOID void
154 
155 union Multitype { /* for multiple entry points */
159  /* longint j; */
164  };
165 
166 typedef union Multitype Multitype;
167 
168 /*typedef long int Long;*/ /* No longer used; formerly in Namelist */
169 
170 struct Vardesc { /* for Namelist */
171  char *name;
172  char *addr;
174  int type;
175  };
176 typedef struct Vardesc Vardesc;
177 
178 struct Namelist {
179  char *name;
181  int nvars;
182  };
183 typedef struct Namelist Namelist;
184 
185 #define loc_abs(x) ((x) >= 0 ? (x) : -(x))
186 #define dabs(x) (doublereal)loc_abs(x)
187 //#define min(a,b) ((a) <= (b) ? (a) : (b))
188 //#define max(a,b) ((a) >= (b) ? (a) : (b))
189 //#define dmin(a,b) (doublereal)min(a,b)
190 //#define dmax(a,b) (doublereal)max(a,b)
191 #define bit_test(a,b) ((a) >> (b) & 1)
192 #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
193 #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
194 
195 /* procedure parameter types for -A and -C++ */
196 
197 #define F2C_proc_par_types 1
198 #ifdef __cplusplus
199 typedef int /* Unknown procedure type */ (*U_fp)(...);
200 typedef shortint (*J_fp)(...);
201 typedef integer (*I_fp)(...);
202 typedef real (*R_fp)(...);
203 typedef doublereal (*D_fp)(...), (*E_fp)(...);
204 typedef /* Complex */ VOID (*C_fp)(...);
205 typedef /* Double Complex */ VOID (*Z_fp)(...);
206 typedef logical (*L_fp)(...);
207 typedef shortlogical (*K_fp)(...);
208 typedef /* Character */ VOID (*H_fp)(...);
209 typedef /* Subroutine */ int (*S_fp)(...);
210 #else
211 typedef int /* Unknown procedure type */ (*U_fp)();
212 typedef shortint (*J_fp)();
213 typedef integer (*I_fp)();
214 typedef real (*R_fp)();
215 typedef doublereal (*D_fp)(), (*E_fp)();
216 typedef /* Complex */ VOID (*C_fp)();
217 typedef /* Double Complex */ VOID (*Z_fp)();
218 typedef logical (*L_fp)();
219 typedef shortlogical (*K_fp)();
220 typedef /* Character */ VOID (*H_fp)();
221 typedef /* Subroutine */ int (*S_fp)();
222 #endif
223 /* E_fp is for real functions when -R is not specified */
224 typedef VOID C_f; /* complex function */
225 typedef VOID H_f; /* character function */
226 typedef VOID Z_f; /* double complex function */
227 typedef doublereal E_f; /* real function with -R not specified */
228 
229 /* undef any lower-case symbols that your C compiler predefines, e.g.: */
230 
231 #ifndef Skip_f2c_Undefs
232 #undef cray
233 #undef gcos
234 #undef mc68010
235 #undef mc68020
236 #undef mips
237 #undef pdp11
238 #undef sgi
239 #undef sparc
240 #undef sun
241 #undef sun2
242 #undef sun3
243 #undef sun4
244 #undef u370
245 #undef u3b
246 #undef u3b2
247 #undef u3b5
248 #undef unix
249 #undef vax
250 #endif
251 #endif
252 
253 
254 /* $Id: grkuta.F,v 1.1.1.1 1995/10/24 10:21:42 cernlib Exp $ */
255 
256 /* $Log: grkuta.F,v $ */
257 /* Revision 1.1.1.1 1995/10/24 10:21:42 cernlib */
258 /* Geant */
259 
261 //#include "cmath"
262 //using namespace std;
263 
264 /* Builtin functions */
265 extern "C" {double sqrt(double), sin(double);}
266 
267 /* #include "geant321/pilot.h" */
268 /* CMZ : 3.21/02 29/03/94 15.41.23 by S.Giani */
269 /* -- Author : */
270 /* Subroutine */ int grkuta_(double *charge, double *step, double *vect, double *vout, const DMagneticFieldMap *bfield)
271 {
272  /* System generated locals */
273  double d__1, d__2, d__3;
274  /*static*/ double equiv_2[3], equiv_5[3];
275 
276 
277  /* Local variables */
278  /*static*/ double a, b, c__;
279  /*static*/ /*double f[4];*/
280  /*static*/ double *f=&vout[7]; /* not that vout is decremented below so indexes start at 1 like FORTRAN */
281  /*static*/ double h__;
282  /*static*/ integer j;
283 #define x (equiv_2)
284 #define y (equiv_2 + 1)
285 #define z__ (equiv_2 + 2)
286  /*static*/ double f1, f2, f3, h2, f4, h4, g1, g2, g3, g4, g5, g6, at, bt,
287  ct, ph, hp, tl;
288 #define xt (equiv_5)
289 #define yt (equiv_5 + 1)
290 #define zt (equiv_5 + 2)
291  /*static*/ double ph2, cba, rho, est, tet, hxp[3], dxt, dyt, dzt, ang2;
292 #define xyz (equiv_2)
293  /*static*/ double rho1;
294  /*static*/ integer iter;
295  /*static*/ double cost;
296  /*static*/ integer ncut;
297  /*static*/ double pinv, rest, sint;
298 #define xyzt (equiv_5)
299  extern /* Subroutine */ int gufld_(double *, double *);
300  /*static*/ double hnorm, secxs[4], secys[4], seczs[4];
301 
302 /* . */
303 /* . ****************************************************************** */
304 /* . * * */
305 /* . * Runge-Kutta method for tracking a particle through a magnetic * */
306 /* . * field. Uses Nystroem algorithm (See Handbook Nat. Bur. of * */
307 /* . * Standards, procedure 25.5.20) * */
308 /* . * * */
309 /* . * Input parameters * */
310 /* . * CHARGE Particle charge * */
311 /* . * STEP Step size * */
312 /* . * VECT Initial co-ords,direction cosines,momentum * */
313 /* . * Output parameters * */
314 /* . * VOUT Output co-ords,direction cosines,momentum * */
315 /* . * User routine called * */
316 /* . * CALL GUFLD(X,F) * */
317 /* . * * */
318 /* . * ==>Called by : <USER>, GUSWIM * */
319 /* . * Authors R.Brun, M.Hansroul ********* * */
320 /* . * V.Perevoztchikov (CUT STEP implementation) * */
321 /* . * * */
322 /* . * * */
323 /* . ****************************************************************** */
324 /* . */
325 
326 /* . */
327 /* . ------------------------------------------------------------------ */
328 /* . */
329 /* This constant is for units CM,GEV/C and KGAUSS */
330 
331  /* Parameter adjustments */
332  --vout;
333  --vect;
334 
335  /* Function Body */
336  iter = 0;
337  ncut = 0;
338  for (j = 1; j <= 7; ++j) {
339  vout[j] = vect[j];
340 /* L10: */
341  }
342  pinv = *charge * 2.9979251e-3 / vect[7];
343  tl = 0.f;
344  h__ = *step;
345 
346 
347 L20:
348  rest = *step - tl;
349  if (loc_abs(h__) > loc_abs(rest)) {
350  h__ = rest;
351  }
352  //gufld_(&vout[1], f);
353  bfield->GetField(vout[1], vout[2], vout[3], f[0], f[1], f[2]);
354 
355 
356 /* Start of integration */
357 
358  *x = vout[1];
359  *y = vout[2];
360  *z__ = vout[3];
361  a = vout[4];
362  b = vout[5];
363  c__ = vout[6];
364 
365  h2 = h__ * .5;
366  h4 = h2 * .5;
367  ph = pinv * h__;
368  ph2 = ph * .5;
369  secxs[0] = (b * f[2] - c__ * f[1]) * ph2;
370  secys[0] = (c__ * f[0] - a * f[2]) * ph2;
371  seczs[0] = (a * f[1] - b * f[0]) * ph2;
372 /* Computing 2nd power */
373  d__1 = secxs[0];
374 /* Computing 2nd power */
375  d__2 = secys[0];
376 /* Computing 2nd power */
377  d__3 = seczs[0];
378  ang2 = d__1 * d__1 + d__2 * d__2 + d__3 * d__3;
379  if (ang2 > 9.86960440109) {
380  goto L40;
381  }
382  dxt = h2 * a + h4 * secxs[0];
383  dyt = h2 * b + h4 * secys[0];
384  dzt = h2 * c__ + h4 * seczs[0];
385  *xt = *x + dxt;
386  *yt = *y + dyt;
387  *zt = *z__ + dzt;
388 
389 /* Second intermediate point */
390 
391  est = loc_abs(dxt) + loc_abs(dyt) + loc_abs(dzt);
392  if (est > h__) {
393  goto L30;
394  }
395  //gufld_(xyzt, f);
396  bfield->GetField(xyzt[0], xyzt[1], xyzt[2], f[0], f[1], f[2]);
397  at = a + secxs[0];
398  bt = b + secys[0];
399  ct = c__ + seczs[0];
400 
401  secxs[1] = (bt * f[2] - ct * f[1]) * ph2;
402  secys[1] = (ct * f[0] - at * f[2]) * ph2;
403  seczs[1] = (at * f[1] - bt * f[0]) * ph2;
404  at = a + secxs[1];
405  bt = b + secys[1];
406  ct = c__ + seczs[1];
407  secxs[2] = (bt * f[2] - ct * f[1]) * ph2;
408  secys[2] = (ct * f[0] - at * f[2]) * ph2;
409  seczs[2] = (at * f[1] - bt * f[0]) * ph2;
410  dxt = h__ * (a + secxs[2]);
411  dyt = h__ * (b + secys[2]);
412  dzt = h__ * (c__ + seczs[2]);
413  *xt = *x + dxt;
414  *yt = *y + dyt;
415  *zt = *z__ + dzt;
416  at = a + secxs[2] * 2.;
417  bt = b + secys[2] * 2.;
418  ct = c__ + seczs[2] * 2.;
419 
420  est = loc_abs(dxt) + loc_abs(dyt) + loc_abs(dzt);
421  if (est > loc_abs(h__) * 2.f) {
422  goto L30;
423  }
424  //gufld_(xyzt, f);
425  bfield->GetField(xyzt[0], xyzt[1], xyzt[2], f[0], f[1], f[2]);
426 
427  *z__ += (c__ + (seczs[0] + seczs[1] + seczs[2]) * .33333333333333331) *
428  h__;
429  *y += (b + (secys[0] + secys[1] + secys[2]) * .33333333333333331) * h__;
430  *x += (a + (secxs[0] + secxs[1] + secxs[2]) * .33333333333333331) * h__;
431 
432  secxs[3] = (bt * f[2] - ct * f[1]) * ph2;
433  secys[3] = (ct * f[0] - at * f[2]) * ph2;
434  seczs[3] = (at * f[1] - bt * f[0]) * ph2;
435  a += (secxs[0] + secxs[3] + (secxs[1] + secxs[2]) * 2.) *
436  .33333333333333331;
437  b += (secys[0] + secys[3] + (secys[1] + secys[2]) * 2.) *
438  .33333333333333331;
439  c__ += (seczs[0] + seczs[3] + (seczs[1] + seczs[2]) * 2.) *
440  .33333333333333331;
441 
442  est = (d__1 = secxs[0] + secxs[3] - (secxs[1] + secxs[2]), loc_abs(d__1)) + (
443  d__2 = secys[0] + secys[3] - (secys[1] + secys[2]), loc_abs(d__2)) + (
444  d__3 = seczs[0] + seczs[3] - (seczs[1] + seczs[2]), loc_abs(d__3));
445 
446  if (est > 1e-4 && loc_abs(h__) > 1e-4f) {
447  goto L30;
448  }
449  ++iter;
450  ncut = 0;
451 /* If too many iterations, go to HELIX */
452  if (iter > 1992) {
453  goto L40;
454  }
455 
456  tl += h__;
457  if (est < 3.1250000000000001e-6) {
458  h__ *= 2.;
459  }
460  cba = 1. / sqrt(a * a + b * b + c__ * c__);
461  vout[1] = *x;
462  vout[2] = *y;
463  vout[3] = *z__;
464  vout[4] = cba * a;
465  vout[5] = cba * b;
466  vout[6] = cba * c__;
467  rest = *step - tl;
468  if (*step < 0.f) {
469  rest = -rest;
470  }
471  if (rest > dabs(*step) * 1e-5f) {
472  goto L20;
473  }
474 
475  goto L999;
476 
477 /* * CUT STEP */
478 L30:
479  ++ncut;
480 /* If too many cuts , go to HELIX */
481  if (ncut > 11) {
482  goto L40;
483  }
484  h__ *= .5;
485  goto L20;
486 
487 /* * ANGLE TOO BIG, USE HELIX */
488 L40:
489  f1 = f[0];
490  f2 = f[1];
491  f3 = f[2];
492 /* Computing 2nd power */
493  d__1 = f1;
494 /* Computing 2nd power */
495  d__2 = f2;
496 /* Computing 2nd power */
497  d__3 = f3;
498  f4 = sqrt(d__1 * d__1 + d__2 * d__2 + d__3 * d__3);
499  rho = -f4 * pinv;
500  tet = rho * *step;
501  if (tet != 0.f) {
502  hnorm = 1. / f4;
503  f1 *= hnorm;
504  f2 *= hnorm;
505  f3 *= hnorm;
506 
507  hxp[0] = f2 * vect[6] - f3 * vect[5];
508  hxp[1] = f3 * vect[4] - f1 * vect[6];
509  hxp[2] = f1 * vect[5] - f2 * vect[4];
510  hp = f1 * vect[4] + f2 * vect[5] + f3 * vect[6];
511 
512  rho1 = 1. / rho;
513  sint = sin(tet);
514 /* Computing 2nd power */
515  d__1 = sin(tet * .5);
516  cost = d__1 * d__1 * 2.;
517 
518  g1 = sint * rho1;
519  g2 = cost * rho1;
520  g3 = (tet - sint) * hp * rho1;
521  g4 = -cost;
522  g5 = sint;
523  g6 = cost * hp;
524  vout[1] = vect[1] + (g1 * vect[4] + g2 * hxp[0] + g3 * f1);
525  vout[2] = vect[2] + (g1 * vect[5] + g2 * hxp[1] + g3 * f2);
526  vout[3] = vect[3] + (g1 * vect[6] + g2 * hxp[2] + g3 * f3);
527  vout[4] = vect[4] + (g4 * vect[4] + g5 * hxp[0] + g6 * f1);
528  vout[5] = vect[5] + (g4 * vect[5] + g5 * hxp[1] + g6 * f2);
529  vout[6] = vect[6] + (g4 * vect[6] + g5 * hxp[2] + g6 * f3);
530 
531  } else {
532  vout[1] = vect[1] + *step * vect[4];
533  vout[2] = vect[2] + *step * vect[5];
534  vout[3] = vect[3] + *step * vect[6];
535 
536  }
537 
538 L999:
539  return 0;
540 } /* grkuta_ */
541 
542 #undef xyzt
543 #undef xyz
544 #undef zt
545 #undef yt
546 #undef xt
547 #undef z__
548 #undef y
549 #undef x
550 
551 
ftnint icirnum
Definition: grkuta.cc:94
char * oblnk
Definition: grkuta.cc:107
#define xt
void gufld_(float *x, float *f)
char * inblank
Definition: grkuta.cc:149
char * name
Definition: grkuta.cc:171
ftnint * inrecl
Definition: grkuta.cc:147
char * inacc
Definition: grkuta.cc:135
ftnlen inacclen
Definition: grkuta.cc:136
ftnlen inunflen
Definition: grkuta.cc:146
char * icifmt
Definition: grkuta.cc:92
ftnlen infilen
Definition: grkuta.cc:128
char * iciunit
Definition: grkuta.cc:90
VOID(* H_fp)()
Definition: grkuta.cc:220
doublereal(* D_fp)()
Definition: grkuta.cc:215
ftnint icirlen
Definition: grkuta.cc:93
char * infmt
Definition: grkuta.cc:141
#define y
ftnint ounit
Definition: grkuta.cc:100
flag icierr
Definition: grkuta.cc:89
char * infile
Definition: grkuta.cc:127
ftnlen * dims
Definition: grkuta.cc:173
Vardesc ** vars
Definition: grkuta.cc:180
#define VOID
Definition: grkuta.cc:153
VOID Z_f
Definition: grkuta.cc:226
ftnlen ofnmlen
Definition: grkuta.cc:102
ftnint cirec
Definition: grkuta.cc:84
ftnint * innum
Definition: grkuta.cc:131
doublereal(*)(* E_fp)()
Definition: grkuta.cc:215
ftnint * innamed
Definition: grkuta.cc:132
long int flag
Definition: grkuta.cc:73
real(* R_fp)()
Definition: grkuta.cc:214
flag ciend
Definition: grkuta.cc:82
char * csta
Definition: grkuta.cc:114
char * name
Definition: grkuta.cc:179
flag oerr
Definition: grkuta.cc:99
char * ofm
Definition: grkuta.cc:105
ftnlen indirlen
Definition: grkuta.cc:140
doublereal r
Definition: grkuta.cc:45
ftnint inunit
Definition: grkuta.cc:126
Definition: grkuta.cc:98
TF1 * f
Definition: FitGains.C:21
int type
Definition: grkuta.cc:174
char * oacc
Definition: grkuta.cc:104
flag cerr
Definition: grkuta.cc:112
TFile f1(fnam)
complex c
Definition: grkuta.cc:162
flag cierr
Definition: grkuta.cc:80
VOID C_f
Definition: grkuta.cc:224
TEllipse * e
ftnlen innamlen
Definition: grkuta.cc:134
flag iciend
Definition: grkuta.cc:91
real r
Definition: grkuta.cc:160
char * inname
Definition: grkuta.cc:133
Definition: grkuta.cc:79
integer1 g
Definition: grkuta.cc:156
shortint h
Definition: grkuta.cc:157
char * cifmt
Definition: grkuta.cc:83
Definition: grkuta.cc:118
#define loc_abs(x)
Definition: grkuta.cc:185
char * ofnm
Definition: grkuta.cc:101
char * inform
Definition: grkuta.cc:143
char * indir
Definition: grkuta.cc:139
doublecomplex z
Definition: grkuta.cc:163
VOID(* Z_fp)()
Definition: grkuta.cc:217
ftnint * inopen
Definition: grkuta.cc:130
ftnlen inseqlen
Definition: grkuta.cc:138
#define xyzt
char * inunf
Definition: grkuta.cc:145
#define yt
ftnint * inex
Definition: grkuta.cc:129
integer(* I_fp)()
Definition: grkuta.cc:213
int nvars
Definition: grkuta.cc:181
double doublereal
Definition: grkuta.cc:43
double sqrt(double)
ftnint informlen
Definition: grkuta.cc:144
doublereal E_f
Definition: grkuta.cc:227
ftnint * innrec
Definition: grkuta.cc:148
ftnlen infmtlen
Definition: grkuta.cc:142
double sin(double)
ftnlen inblanklen
Definition: grkuta.cc:150
char * addr
Definition: grkuta.cc:172
ftnint cunit
Definition: grkuta.cc:113
long int logical
Definition: grkuta.cc:46
short int shortint
Definition: grkuta.cc:41
shortint(* J_fp)()
Definition: grkuta.cc:212
char logical1
Definition: grkuta.cc:48
int grkuta_(double *CHARGE, double *STEP, double *VECT, double *VOUT, const DMagneticFieldMap *bfield)
Definition: grkuta.cc:270
#define zt
char * address
Definition: grkuta.cc:40
#define z__
ftnint aunit
Definition: grkuta.cc:120
char * osta
Definition: grkuta.cc:103
short int shortlogical
Definition: grkuta.cc:47
TF1 * f2
Definition: FitGains.C:28
float real
Definition: grkuta.cc:42
shortlogical(* K_fp)()
Definition: grkuta.cc:219
virtual void GetField(const DVector3 &pos, DVector3 &Bout) const =0
VOID H_f
Definition: grkuta.cc:225
long int ftnint
Definition: grkuta.cc:75
flag aerr
Definition: grkuta.cc:119
#define x
ftnint ciunit
Definition: grkuta.cc:81
logical(* L_fp)()
Definition: grkuta.cc:218
VOID(* C_fp)()
Definition: grkuta.cc:216
doublereal d
Definition: grkuta.cc:161
integer i
Definition: grkuta.cc:158
flag inerr
Definition: grkuta.cc:125
unsigned long int uinteger
Definition: grkuta.cc:39
long int ftnlen
Definition: grkuta.cc:74
ftnint orl
Definition: grkuta.cc:106
char integer1
Definition: grkuta.cc:49
real r
Definition: grkuta.cc:44
long int integer
Definition: grkuta.cc:38
char * inseq
Definition: grkuta.cc:137
#define dabs(x)
Definition: grkuta.cc:186
int(* S_fp)()
Definition: grkuta.cc:221