EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
phenix.c
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file phenix.c
1 //
2 // cc -o phenix -I./include/ phenix.c ./libayk.a -lm
3 // ./phenix
4 //
5 
6 #include <stdio.h>
7 #include <assert.h>
8 
9 #include <mgsystem.h>
10 
11 // Set this field be SolenoidMap3.dat in PandaRoot notation;
12 //@@@#define _MAP_ID_ 3
13 // Set this field be SolenoidMap5.dat in PandaRoot notation;
14 #define _MAP_ID_ 5
15 
16 #if _OLD_
17 // Cell size of the output XYZ map in [cm];
18 #define _CELL_SIZE_ 3.0
19 #else
20 #define _CELL_SIZE_ 1.0
21 #endif
22 
23 void main( void )
24 {
25  // No conversion -> units will stay [cm] & [G] as in the original file;
26  t_ascii_coord xc = {_CYLINDRICAL_, 2, {'R', 'Z'}, 0};
27  t_ascii_coord fc = {_CYLINDRICAL_, 2, {'R', 'Z'}, 0};
28  char fname[FILENAME_MAX];
29 
30  snprintf(fname, FILENAME_MAX-1, "SolenoidMap%d.dat", _MAP_ID_);
31 
32  {
33  FILE *fout = fopen(fname, "w");
34 
35  if (!fout)
36  {
37  printf("Failed to open '%s' for writing!\n", fname);
38  exit(-1);
39  } /*if*/
40 
41  // Import ASCII file;
42  t_mgrid *mgrid = import_ascii_field_map("/home/ayk/FairRoot/eicroot/input/BABAR_V11_GridOut_ePHENIX.SF7",
43  // 34: skip that many lines at the beginning;
44  "PHENIX", &xc, &fc, 34);
45  assert(mgrid);
46 
47  {
48  //t_3d_vector xx = {36., 0., -200.}, 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  // 36.0000 -200.000 -1.178013E+03 8.388588E+03 8.470899E+03 1.509369E+05 6.849402E-02 6.849402E-02 2.939451E-04
54  }
55 
56 #if _OLD_
57  // Figure out limits and construct field map frame;
58  {
59  unsigned nodes[3];
60  t_mgrid_direction *dirR = mgrid->dir + _R_, *dirZ = mgrid->dir + _Z_;
61  float xmin[3] = { 0.0, 0.0, dirZ->min}, step[3];
62  float xmax[3] = {dirR->max, dirR->max, dirZ->max};
63  printf("%f %f %f %f\n", dirR->min, dirR->max, dirZ->min, dirZ->max);
64 
65  {
66  unsigned iq;
67 
68  // Number of nodes (well, in fact cells) and the actual step size;
69  for(iq=0; iq<3; iq++)
70  {
71  nodes[iq] = (int)rint((xmax[iq] - xmin[iq])/_CELL_SIZE_);
72 
73  // The actual step size;
74  step[iq] = (xmax[iq] - xmin[iq])/nodes[iq];
75  } //for iq
76 
77  // Dump file header;
78  fprintf(fout, "Solenoid\n");
79  fprintf(fout, "G\n");
80  for(iq=0; iq<3; iq++)
81  fprintf(fout, "%6.1f %6.1f %3d\n", xmin[iq], xmax[iq], nodes[iq]);
82 
83  // Loop through all the XYZ nodes and dump them to file;
84  {
85  int ret;
86  unsigned ix, iy, iz;
87 
88  // Do not care about one-off problem (anyway grid was imported with
89  // half-cell off limits, and also RZ->XYZ will introduce additional
90  // interpolation errors; may want to do better later;
91  for(ix=0; ix<=nodes[_X_]; ix++)
92  for(iy=0; iy<=nodes[_Y_]; iy++)
93  for(iz=0; iz<=nodes[_Z_]; iz++)
94  {
95  t_3d_vector xx = {xmin[_X_] + ix*step[_X_],
96  xmin[_Y_] + iy*step[_Y_],
97  xmin[_Z_] + iz*step[_Z_]}, B;
98 
99  ret = get_cartesian_field_value(mgrid, xx, B);
100 
101  fprintf(fout, "%10.3f %10.3f %10.3f\n", 2.*B[0], 2.*B[1], 2.*B[2]);
102  } //for ix..iz
103  }
104  }
105  }
106 #else
107  {
108  unsigned iq, nodes[3] = {101, 101, 401};
109  //@@@float xmin[3] = { 0.0, 0.0, -50.0};
110  //@@@float xmax[3] = { 100.0, 100.0, 350.0};
111  float xmin[3] = { 0.0, 0.0, -200.0};
112  float xmax[3] = { 100.0, 100.0, 200.0};
113 
114  // Dump file header;
115  fprintf(fout, "Solenoid\n");
116  fprintf(fout, "G\n");
117  for(iq=0; iq<3; iq++)
118  fprintf(fout, "%6.1f %6.1f %3d\n", xmin[iq], xmax[iq], nodes[iq]);
119 
120  // Loop through all the XYZ nodes and dump them to file;
121  {
122  int ret;
123  unsigned ix, iy, iz;
124 
125  for(ix=0; ix<nodes[_X_]; ix++)
126  for(iy=0; iy<nodes[_Y_]; iy++)
127  for(iz=0; iz<nodes[_Z_]; iz++)
128  {
129  t_3d_vector xx = {xmin[_X_] + ix*_CELL_SIZE_,
130  xmin[_Y_] + iy*_CELL_SIZE_,
131  xmin[_Z_] + iz*_CELL_SIZE_}, B;
132 
133  ret = get_cartesian_field_value(mgrid, xx, B);
134 
135  fprintf(fout, "%10.3f %10.3f %10.3f\n", B[0], B[1], B[2]);
136  } //for ix..iz
137  }
138  }
139 #endif
140  }
141 } // main()