EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dipole.c
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file dipole.c
1 //
2 // grep -v Bmod DipoleScanOutput.txt | awk -F"," '{ print $1 $2 $3 $5 $6 $7}' > DipoleScanOutput.essential.txt
3 //
4 // cc -I../../ayk/include -o dipole dipole.c ../../ayk/libayk.a -lm
5 // ./dipole
6 //
7 
8 #include <stdio.h>
9 #include <assert.h>
10 
11 #include <mgsystem.h>
12 
13 // Set this field be DipoleMap1.dat in PandaRoot notation;
14 #define _MAP_ID_ 1
15 
16 // Cell size of the output XYZ map in [cm];
17 #define _CELL_SIZE_ 2.5
18 
19 static double tesla2gs_fun(double val)
20 {
21  return val*1E4;
22 } // tesla2kgs_fun()
23 
24 void main( void )
25 {
26  // No conversion -> units will stay [cm] & [G] as in the original file;
27  t_ascii_coord xc = {_CARTESIAN_, 3, {'X', 'Y', 'Z'}, m2cm_fun};
28  t_ascii_coord fc = {_CARTESIAN_, 3, {'X', 'Y', 'Z'}, tesla2gs_fun};
29  char fname[FILENAME_MAX];
30 
31  snprintf(fname, FILENAME_MAX-1, "DipoleMap%d.dat", _MAP_ID_);
32 
33  {
34  FILE *fout = fopen(fname, "w");
35 
36  if (!fout)
37  {
38  printf("Failed to open '%s' for writing!\n", fname);
39  exit(-1);
40  } /*if*/
41 
42  // Import Brett's ASCII file;
43  t_mgrid *mgrid = import_ascii_field_map("./DipoleScanOutput.essential.txt",
44  "DID", &xc, &fc, 0);
45  assert(mgrid);
46 
47  {
48  t_3d_vector xx = {-37.5, 107.5, -10.0}, B;
49 
50  int ret = get_cartesian_field_value(mgrid, xx, B);
51  //printf("%3d: %f %f %f\n", ret, B[0], B[1], B[2]);
52 
53  // -0.375, 1.075, -0.1, 1.13853, 0.4719783, -1.322822, -2.209778, 2.618347
54  }
55 
56  {
57  unsigned iq, nodes[3] = {101, 101, 201};
58  float xmin[3] = { -125.0, -125.0, -250.0};
59  float xmax[3] = { 125.0, 125.0, 250.0};
60 
61  // Dump file header;
62  fprintf(fout, "Dipole\n");
63  fprintf(fout, "G\n");
64  for(iq=0; iq<3; iq++)
65  fprintf(fout, "%6.1f %6.1f %3d\n", xmin[iq], xmax[iq], nodes[iq]);
66 
67  // Loop through all the XYZ nodes and dump them to file;
68  {
69  int ret;
70  unsigned ix, iy, iz;
71 
72  for(ix=0; ix<nodes[_X_]; ix++)
73  for(iy=0; iy<nodes[_Y_]; iy++)
74  for(iz=0; iz<nodes[_Z_]; iz++)
75  {
76  t_3d_vector xx = {xmin[_X_] + ix*_CELL_SIZE_,
77  xmin[_Y_] + iy*_CELL_SIZE_,
78  xmin[_Z_] + iz*_CELL_SIZE_}, B;
79 
80  ret = get_cartesian_field_value(mgrid, xx, B);
81 
82  fprintf(fout, "%10.3f %10.3f %10.3f\n", B[0], B[1], B[2]);
83  } //for ix..iz
84  }
85  }
86  }
87 } // main()