Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4_IR_EIC.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4_IR_EIC.C
1 
2 void IRInit() {
3 
4 }
5 
6 double IRSetup(PHG4Reco* g4Reco,
7  const int absorberactive = 1,
8  int verbosity = 0) {
9 
10  /* Increase world size to fit extended IR magnets */
11  g4Reco->SetWorldSizeZ(25000);
12 
13  /* Define outer radius for all extneded IR magnets */
14  double ir_magnet_outer_radius = 50;
15 
16  /* Read IR configuration file- this needs to go somewhere else using parameters and a .root file to store them*/
17  // string irfile = "../input_ir/magnet_quad_test.dat";
18  // string irfile = "../input_ir/magnet_dipole_test.dat";
19  // string irfile = "../input_ir/linac-ring-proton-magnets-Version3.01-21apr2016.dat";
20  string irfile = "../input_ir/proton-magnets-250GeV-opt2.dat";
21  // string irfile = "../input_ir/updated-magnets-2017.dat";
22 
23  ifstream irstream(irfile.c_str());
24 
25  while(!irstream.eof()){
26  string str;
27  getline(irstream, str);
28  if(str[0] == '#') continue; //for comments
29  stringstream ss(str);
30 
31  string name;
32  double center_z, center_x, center_y, aperture_radius, length, angle, B, gradient;
33 
34  ss >> name >> center_z >> center_x >> center_y >> aperture_radius >> length >> angle >> B >> gradient;
35 
36  if ( name == "" ) continue; //for empty lines
37 
38  /* convert units from m to cm */
39  center_x *= 100;
40  center_y *= 100;
41  center_z *= 100;
42  aperture_radius *= 100;
43  length *= 100;
44 
45  /* convert angle from millirad to degrees */
46  angle = (angle / 1000.) * (180./TMath::Pi());
47 
48  /* Place IR component */
49  cout << "New IR component: " << name << " at x = " << center_x << ", y = " << center_y << ", z = " << center_z << ", angle = " << angle << endl;
50 
51  string volname = "IRMAGNET_";
52  volname.append(name);
53 
54  PHG4BeamlineMagnetSubsystem *ir_magnet_i = new PHG4BeamlineMagnetSubsystem(volname, 0);
55  ir_magnet_i->set_int_param("lengthviarapidity",0);
56  ir_magnet_i->set_double_param("length",length);
57  ir_magnet_i->set_double_param("radius",aperture_radius);
58  ir_magnet_i->set_double_param("thickness", ir_magnet_outer_radius - aperture_radius);
59  ir_magnet_i->set_double_param("place_x",center_x);
60  ir_magnet_i->set_double_param("place_y",center_y);
61  ir_magnet_i->set_double_param("place_z",center_z);
62  ir_magnet_i->set_double_param("rot_y",angle);
63  ir_magnet_i->set_string_param("material","G4_Galactic"); // magnet yoke material is 'vacuum'
64  // ir_magnet_i->set_string_param("material","G4_Fe"); // magnet yoke material is 'iron'
65 
66  if ( B != 0 && gradient == 0.0 )
67  {
68  ir_magnet_i->set_string_param("magtype","dipole");
69  ir_magnet_i->set_double_param("field_y",B);
70  }
71  else if ( B == 0 && gradient != 0.0 )
72  {
73  ir_magnet_i->set_string_param("magtype","quadrupole");
74  ir_magnet_i->set_double_param("fieldgradient",gradient);
75  }
76  else if ( B == 0 && gradient == 0.0 )
77  {
78  ir_magnet_i->set_string_param("magtype","dipole");
79  ir_magnet_i->set_double_param("fieldgradient",0);
80  ir_magnet_i->set_double_param("field_y",0);
81  }
82  else
83  {
84  cout << "Error in G4_IR_EIC: Could not identify magnet type. Abort." << endl;
85  return 1;
86  }
87 
88  ir_magnet_i->SetActive(false);
89  ir_magnet_i->OverlapCheck(overlapcheck);
90  g4Reco->registerSubsystem(ir_magnet_i);
91  }
92 
93  return 0;
94 }