EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
star.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file star.C
1 //
2 // On eic000* nodes execute something like
3 //
4 // source ~fisyak/.cshrc
5 //
6 // and then under ROOT:
7 //
8 // root.exe [0] gSystem->Load("StarMagField");
9 // root.exe [1] .x star.C+
10 //
11 
12 #include <TROOT.h>
13 #include <TSystem.h>
14 #include <TClassTable.h>
15 
16 #include <StarMagField.h>
17 
18 #include <cstdio>
19 
20 // Set this field be SolenoidMap6.dat in PandaRoot notation; NB: will need
21 // to modify the codes in order to be able to use it in the reconstruction;
22 #define _MAP_ID_ 6
23 
24 // Cell size of the output XYZ map in [cm]; would be better to use 2cm cell,
25 // but PandaRoot interface does not allow RZ-fields while 3D map file becomes
26 // prohibitively large;
27 #define _CELL_SIZE_ (float(4.0))
28 
29 void star()
30 {
31  new StarMagField();
32 
33  char fname[FILENAME_MAX];
34  snprintf(fname, FILENAME_MAX-1, "SolenoidMap%d.dat", _MAP_ID_);
35  FILE *fout = fopen(fname, "w");
36  if (!fout) {
37  printf("Failed to open '%s' for writing!\n", fname);
38  exit(-1);
39  } //if
40 
41  unsigned nodes[3] = {101, 101, 401};
42  float xmin[3] = { 0.0, 0.0, -800.0};
43  float xmax[3] = { 400.0, 400.0, 800.0};
44 
45  // Dump file header;
46  fprintf(fout, "Solenoid\n");
47  fprintf(fout, "G\n");
48  for(unsigned iq=0; iq<3; iq++)
49  fprintf(fout, "%6.1f %6.1f %3d\n", xmin[iq], xmax[iq], nodes[iq]);
50 
51  // Loop through all the XYZ nodes and dump them to file;
52  for(unsigned ix=0; ix<nodes[0]; ix++)
53  for(unsigned iy=0; iy<nodes[1]; iy++)
54  for(unsigned iz=0; iz<nodes[2]; iz++) {
55  Float_t xx[3] = {xmin[0] + ix*_CELL_SIZE_,
56  xmin[1] + iy*_CELL_SIZE_,
57  xmin[2] + iz*_CELL_SIZE_}, B[3];
58 
59  StarMagField::Instance()->BField(xx,B);
60 
61  // Convert [Gs];
62  for(unsigned iq=0; iq<3; iq++)
63  B[iq] *= 1000.;
64 
65  fprintf(fout, "%10.3f %10.3f %10.3f\n", B[0], B[1], B[2]);
66  } //for ix..iz
67 
68  fclose(fout);
69 }
70