EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
htclib.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file htclib.h
1 /* ----------------------------------------------------------------- */
2 /* htclib.h */
3 /* */
4 /* HTC library code definitions. */
5 /* */
6 /* A.Kisselev, PNPI, St.Petersburg, Russia. */
7 /* e-mail: kisselev@hermes.desy.de */
8 /* ----------------------------------------------------------------- */
9 
10 // Unify later!!!!!!!!!!!;
11 #define _SX_ 2
12 #define _SY_ 3
13 #define _QP_ 4
14 
15 // Comment this out if want to use usual ~(1. + 0.038*log(X/X0)) Coulomb formula;
16 #define _USE_GEANT3_MOLIERE_CHC_
17 
18 #include <ayk.h>
19 #include <Mgrid.h>
20 
21 #define f2cFortran
22 #define CFSUBASFUN
23 #include <cfortran.h>
24 
25 #ifndef _HTC_LIB_
26 #define _HTC_LIB_
27 
28 // Positive/negative charges;
29 #define _POSITIVE_ 0
30 #define _NEGATIVE_ 1
31 
32 extern char XYZ[3];
33 
34 #define _RETURN_(ret, message) { if (message) printf(message); return(ret); }
35 #define _TERMINATE_(ret, message) { printf(message); exit (ret); }
36 
37 //#ifdef _USE_CERNLIB_
38 //#ifdef CFSUBASFUN
39 PROTOCCALLSFFUN4(INT,DSINV,dsinv,INT,DOUBLEV,INT,PINT)
40 PROTOCCALLSFFUN5(INT,DINV, dinv, INT, DOUBLEV, INT, INTV, PINT)
41 //#endif
42 
43 #define DSINV(N,A,IDIM,IFAIL) \
44  CCALLSFSUB4(DSINV,dsinv,INT,DOUBLEV,INT,PINT,N,A,IDIM,IFAIL)
45 #define DINV(N, A, IDIM, IR, IFAIL) \
46  CCALLSFSUB5(DINV, dinv, INT, DOUBLEV, INT, INTV, PINT, N, A, IDIM, IR, IFAIL)
47 
49 #define PROB(X,N) CCALLSFFUN2(PROB,prob_htc,FLOAT,INT,X,N)
50 //#endif
51 
52 // Increase and recompile if ever not enough;
53 #define _CMD_LINE_VARIABLE_NUM_MAX_ 10
54 
55 typedef struct {
56  // Pattern names; prefer to have suffices for sompleteness as well;
57  char *prefix, *suffix;
58 
59  // Address of respective variable;
60  double *addr;
61 
62  // Some more or less sane limits; let them be double?;
63  double min, max;
64 
65  // Pattern length; calculate once;
66  int plen;
67 
68  // Well, one change allowed, naturally; keep track on that;
69  int _assigned;
70 
71  //
72  // Do not change parameter order above this line;
73  //
75 
76 typedef struct {
77  // Actual number of variables (<= _CMD_LINE_VARIABLE_NUM_MAX_);
79 
80  // Array of keys;
82 
83 
84  // Do not change parameter order above this line;
85 
86 
88 
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
92  int check_prefix(char *str, char *prefix);
93  int check_and_remove_suffix(char *ptr, char *suffix);
94  int assign_dimensional_value(char *string, char *suffix,
95  double *value, double scale);
97 
98  int redirect_fortran_output(char *std_out, char *std_err);
99 #ifdef __cplusplus
100 }
101 #endif
102 
103 #define G3ZEBRA(P1) CCALLSFSUB1(G3ZEBRA, g3zebra, INT, P1)
104 PROTOCCALLSFFUN1(INT,G3ZEBRA, g3zebra, INT)
105 
106 #define G3INIT() CCALLSFSUB0(G3INIT, g3init)
107 PROTOCCALLSFFUN0(INT,G3INIT, g3init)
108 #define G3ZINIT() CCALLSFSUB0(G3ZINIT, g3zinit)
109 PROTOCCALLSFFUN0(INT,G3ZINIT, g3zinit)
110 #define G3PHYSI() CCALLSFSUB0(G3PHYSI, g3physi)
111 PROTOCCALLSFFUN0(INT,G3PHYSI, g3physi)
112 
113 #define G3DRELX(A,Z,DENS,T,HMASS,DEDX) \
114  CCALLSFSUB6(G3DRELX,g3drelx,FLOAT,FLOAT,FLOAT,FLOAT,FLOAT,PFLOAT,A,Z,DENS,T,HMASS,DEDX)
115 PROTOCCALLSFFUN6(INT,G3DRELX,g3drelx,FLOAT,FLOAT,FLOAT,FLOAT,FLOAT,PFLOAT)
116 
117 #define G3PROBI(NLMAT,WMAT,AAA,ZZZ,DENS,POTL,FAC,C,X0,X1,AA) \
118  CCALLSFSUB11(G3PROBI,g3probi,INT,FLOATV,FLOATV,FLOATV,FLOAT, \
119  PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE,NLMAT,WMAT,AAA,ZZZ,DENS,POTL,FAC,C,X0,X1,AA)
120 PROTOCCALLSFFUN11(INT,G3PROBI,g3probi,INT,FLOATV,FLOATV,FLOATV,FLOAT, \
121  PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE)
122 
123 #define G3MOLI(P1, P2, P3, P4, P5, P6, P7) \
124  CCALLSFSUB7(G3MOLI, g3moli, FLOATV, FLOATV, FLOATV, INT, FLOAT, PFLOAT, PFLOAT, \
125  P1, P2, P3, P4, P5, P6, P7)
126 PROTOCCALLSFFUN7(INT,G3MOLI, g3moli, FLOATV, FLOATV, FLOATV, INT, FLOAT, PFLOAT, PFLOAT)
127 
128 #if 0
129 #define GZEBRA(P1) CCALLSFSUB1(GZEBRA, gzebra, INT, P1)
130 #define GINIT() CCALLSFSUB0(GINIT, ginit)
131 #define GZINIT() CCALLSFSUB0(GZINIT, gzinit)
132 #define GPART() CCALLSFSUB0(GPART, gpart)
133 #define GPHYSI() CCALLSFSUB0(GPHYSI, gphysi)
134 
135 #define GMOLI(P1, P2, P3, P4, P5, P6, P7) \
136  CCALLSFSUB7(GMOLI, gmoli, FLOATV, FLOATV, FLOATV, INT, FLOAT, PFLOAT, PFLOAT, \
137  P1, P2, P3, P4, P5, P6, P7)
138 
139 #define GDRELX(A,Z,DENS,T,HMASS,DEDX) \
140  CCALLSFSUB6(GDRELX,gdrelx,FLOAT,FLOAT,FLOAT,FLOAT,FLOAT,PFLOAT,A,Z,DENS,T,HMASS,DEDX)
141 #define G3DRELX(A,Z,DENS,T,HMASS,DEDX) \
142  CCALLSFSUB6(G3DRELX,g3drelx,FLOAT,FLOAT,FLOAT,FLOAT,FLOAT,PFLOAT,A,Z,DENS,T,HMASS,DEDX)
143 #define GDRELP(A,Z,DENS,T,DEDX) \
144  CCALLSFSUB5(GDRELP,gdrelp,FLOAT,FLOAT,FLOAT,FLOAT,PFLOAT,A,Z,DENS,T,DEDX)
145 
146 #if 1
147 // These routines have a different interface than original CERNLIB ones,
148 // just because I had to decouple them from the source common blocks;
149 #define GDRELE(EEL,CHARGE,POTL,FAC,C,X0,X1,AA,DEDX) \
150  CCALLSFSUB9(GDRELE,gdrele,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,PDOUBLE, \
151  EEL,CHARGE,POTL,FAC,C,X0,X1,AA,DEDX)
152 #define GPROBI(NLMAT,WMAT,AAA,ZZZ,DENS,POTL,FAC,C,X0,X1,AA) \
153  CCALLSFSUB11(GPROBI,gprobi,INT,FLOATV,FLOATV,FLOATV,FLOAT, \
154  PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE,NLMAT,WMAT,AAA,ZZZ,DENS,POTL,FAC,C,X0,X1,AA)
155 
156 #define GBRELA(NLMAT,WMAT,AAA,ZZZ,AAVG,ZAVG,DENS,EEL,CHARGE,DEDX) \
157  CCALLSFSUB10(GBRELA,gbrela,INT,FLOATV,FLOATV,FLOATV,FLOAT,FLOAT,FLOAT,DOUBLE,DOUBLE,PDOUBLE, \
158  NLMAT,WMAT,AAA,ZZZ,AAVG,ZAVG,DENS,EEL,CHARGE,DEDX)
159 #endif
160 
161 #ifdef CFSUBASFUN
162 PROTOCCALLSFFUN7(INT,GMOLI, gmoli, FLOATV, FLOATV, FLOATV, INT, FLOAT, PFLOAT, PFLOAT)
163 PROTOCCALLSFFUN11(INT,GPROBI,gprobi,INT,FLOATV,FLOATV,FLOATV,FLOAT, \
164  PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE,PDOUBLE)
165 PROTOCCALLSFFUN6(INT,GDRELX,gdrelx,FLOAT,FLOAT,FLOAT,FLOAT,FLOAT,PFLOAT)
166 PROTOCCALLSFFUN6(INT,G3DRELX,g3drelx,FLOAT,FLOAT,FLOAT,FLOAT,FLOAT,PFLOAT)
167 PROTOCCALLSFFUN9(INT,GDRELE,gdrele,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,DOUBLE,PDOUBLE)
168 PROTOCCALLSFFUN10(INT,GBRELA,gbrela,INT,FLOATV,FLOATV,FLOATV,FLOAT,FLOAT,FLOAT,DOUBLE,DOUBLE,PDOUBLE)
169 PROTOCCALLSFFUN0(INT,GPHYSI, gphysi)
170 PROTOCCALLSFFUN0(INT,GPART, gpart)
171 PROTOCCALLSFFUN0(INT,GINIT, ginit)
172 PROTOCCALLSFFUN0(INT,GZINIT, gzinit)
173 PROTOCCALLSFFUN1(INT,GZEBRA, gzebra, INT)
174 #endif
175 #endif
176 
177 typedef struct {
178  char name[5];
179 
180  // Byte ordering will be different on different platforms
181  // therefore do not want to create union; well, in fact
182  // I'm not going to port it to any other platform than Linux:-)
183  int id;
185 
186 // Prefer to specify dE/dx losses model explicitely;
187 #define _DEDX_HADRON_ 0
188 #define _DEDX_ELECTRON_ 1
189 
190 typedef struct {
191  // Some name like "Pi+";
192  char *name;
193 
194  // GEANT3 & GEANT4 identifiers;
195  int geant3, geant4;
196 } t_particle;
197 
199  // Group name (like "pion" for both Pi+ & Pi-); Kalman filter
200  // requires particle hypothesis, for instance, and it is natural
201  // to give just "pion" from the command line assuming that a proper
202  // charge sign will be picked up;
203  char *grname;
204 
205  // Yes, assume mass is the same; actually GEANT4 identifiers are
206  // also the same up to a sign;
207  double mass;
208 
209  // See 2 possible options above;
211 
212  // +/- charges; yes, no neutral particles assumed for now;
214 };
215 
217 extern int particle_group_num;
218 
219 #ifdef __cplusplus
220 extern "C" {
221 #endif
222  t_particle *get_particle_by_name(const char *name);
223  t_particle_group *get_particle_group_by_name(const char *name);
224 #ifdef __cplusplus
225 }
226 #endif
227 
228 // Different head node initialization modes;
229 #define _USE_XF_ 0
230 #define _USE_XS_ 1
231 #define _USE_00_ 2
232 
233 // Never change these numbers if use them as array indices!;
234 #define _RK_ORDER_2_ 0
235 #define _RK_ORDER_4_ 1
236 #define _RK_ORDER_5_ 2
237 
238 extern double _drv_steps[4];
239 
240 // If this bit is not set, only gaps between nodes with non-linear
241 // transport will be filled by intermediate ones;
242 //#define _FILL_ALL_GAPS_ 0x0001
243 
244 // HERMES: TARGET/FRINGE/SPEC, right?; if ever becomes too small,
245 // modify and recompile;
246 #define _FIELD_AREA_NUM_MAX_ 3
247 
249 
250 // For steps less than this number use just 2-d (or 4-th?) order Runge-Kutta;
251 #define _RK_SMALL_STEP_DEFAULT_ (2.0)
252 
253 // Light velocity --> cm/s; @@@MM@@@
254 #define _LIGHT_SPEED_ (299792458E2)
255 
257 
258 // Yes, it's a bad idea to make such variables global; fix later;
259 extern double a2, a3, a4, a5, a6;
260 
261 #ifdef __cplusplus
262 extern "C" {
263 #endif
264  int parse_htc_interpolation_string(char *string, t_htc_interpolation *htci);
265 
266  int runge_kutta_fun(int argc, char **argv);
267 #ifdef __cplusplus
268 }
269 #endif
270 
271 #define _INTERPOLATION_PREFIX_ "interpolation="
272 
273 #define _RK_HERMES_ 0
274 #define _RK_HERA_B_ 1
275 
276 extern int RK_flavor;
277 
279 extern int RK_small_step_order;
280 
281 #endif