EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
runge-kutta.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file runge-kutta.cxx
1 /* -------------------------------------------------------------------------- */
2 /* runge-kutta.c */
3 /* */
4 /* My private Runge-Kutta test code. */
5 /* */
6 /* A.Kisselev, PNPI, St.Petersburg, Russia. */
7 /* e-mail: kisselev@hermes.desy.de */
8 /* -------------------------------------------------------------------------- */
9 
10 #include <cassert>
11 #include <cstdlib>
12 
13 #include <htclib.h>
14 #include <TrKalmanFilter.h>
15 
16 // 0.: no restriction per default;
19 
22 
23 // An ugly way to record situations of no field available;
25 
26 // Can be changed from the command line to old-style code borrowed from HERA-B;
28 
29 // Perhaps tune limits later (or allow certain flexibility to modify them);
30 // also it may be wise to have these arrays detector-specific; @@@MM@@@
31 //
32 // Ok, as of 2012/11/28 so initialize 'plen' and '_assigned' fields and make
33 // both Jan and compiler happy;
35  {3,
36  {{(char*)"cell-width-max=", (char*)"cm", &RK_cell_width_max, 2.0, 10.0, 0, 0},
37  {(char*)"fixed-cell-width=", (char*)"cm", &RK_fixed_cell_width, 2.0, 10.0, 0, 0},
38  {(char*)"small-step-limit=", (char*)"cm", &RK_small_step_limit, 0.1, 100.0, 0, 0}}};
39 
40 #define _SMALL_STEP_ORDER_PREFIX_ "small-step-order="
41 
42 /* ========================================================================== */
43 
45 {
46  int ret = 0;
47 
48  if (!htci) return -1;
49 
50  // Duplicate sanity check, sorry;
51  if (check_prefix(string, (char*)_INTERPOLATION_PREFIX_)) return -1;
52 
53  {
54  char *ptr = strdup(string + strlen(_INTERPOLATION_PREFIX_));
55 
56  if (!ptr) return -1;
57 
58  // 2 predefined keys;
59  if (!strcmp(ptr, "off"))
60  htci->mode = _MODE_OFF_;
61  else
62  if (!strcmp(ptr, "hrc"))
63  htci->mode = _MODE_HRC_;
64  else
65  {
66  // Parse AxBxC string;
67  int iq;
68  char *qptr = ptr;
69 
70  htci->mode = _MODE_ADIM_;
71 
72  for(iq=0; iq<3; iq++)
73  {
74  char *x = strchr(qptr, 'x');
75 
76  if ((iq < 2 && !x) || (iq == 2 && x))
77  {
78  ret = -1;
79  break;
80  } /*if*/
81 
82  if (x) *x = 0;
83 
84  htci->adim[iq] = atoi(qptr);
85  if (htci->adim[iq] <= 0 || htci->adim[iq] > 4)
86  {
87  ret = -1;
88  break;
89  } /*if*/
90 
91  if (x) qptr = x + 1;
92  } /*for iq*/
93  } /*if*/
94 
95  free(ptr);
96  }
97 
98  return ret;
99 } /* parse_htc_interpolation_string */
100 
101 /* -------------------------------------------------------------------------- */
102 
103 int runge_kutta_fun(int argc, char **argv)
104 {
105  // Well, first key is mode;
106  if (!strcmp(argv[0], "mode=hermes"))
107  // This is actually the default;
109  else
110  if (!strcmp(argv[0], "mode=hera-b"))
111  {
112  // Yes, no modifiers for this case;
113  if (argc != 1) return -1;
114 
116 
117  return 0;
118  }
119  else
120  return -1;
121 
122  // Parse other keys in case of HERMES mode;
123  for(int ik=1; ik<argc; ik++)
124  {
125  char *ptr = argv[ik];
126 
127  if (!check_prefix(ptr, (char*)_INTERPOLATION_PREFIX_))
128  {
129  if (parse_htc_interpolation_string(ptr, &RK_htci))
130  _RETURN_(-1, "'--runge-kutta': failed to parse interpolation string!\n");
131  if (RK_htci.mode == _MODE_ADIM_ && RK_htci.adim[_Z_] != 1)
132  _RETURN_(-1, "'--runge-kutta': only (1..4)x(1..4)x(1) modes alowed!\n");
133  }
134  else
135  if (!check_prefix(ptr, (char*)_SMALL_STEP_ORDER_PREFIX_))
136  {
137  switch(atoi(ptr + strlen(_SMALL_STEP_ORDER_PREFIX_)))
138  {
139  case 2:
141  break;
142  case 4:
144  break;
145  default:
146  return -1;
147  } /*switch*/
148  }
149  else
150  {
151  // Eventually try to call standardized parser; yes, this all looks
152  // rather messy;
153  if (cmd_line_variable_parser(ptr, &RK_array))
154  {
155  printf("'--runge-kutta': unknown config key: '%s'!\n", ptr);
156  return -1;
157  } /*if*/
158  } /*if*/
159  } /*for ik*/
160 
161  return 0;
162 } /* runge_kutta_fun */
163 
164 /* ========================================================================== */