EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BeamLineMagnetSubsystem.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BeamLineMagnetSubsystem.cc
5 
6 #include <g4detectors/PHG4DetectorSubsystem.h> // for PHG4DetectorSubsystem
7 
8 #include <phparameter/PHParameters.h>
9 
10 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
12 #include <g4main/PHG4SteppingAction.h> // for PHG4SteppingAction
13 
14 #include <phool/PHCompositeNode.h>
15 #include <phool/PHIODataNode.h> // for PHIODataNode
16 #include <phool/PHNode.h> // for PHNode
17 #include <phool/PHNodeIterator.h> // for PHNodeIterator
18 #include <phool/PHObject.h> // for PHObject
19 #include <phool/getClass.h>
20 
21 #include <iostream> // for operator<<, endl, basic_ostream
22 #include <set> // for set
23 
24 class PHG4Detector;
25 
26 //_______________________________________________________________________
27 BeamLineMagnetSubsystem::BeamLineMagnetSubsystem(const std::string &na, const int lyr)
28  : PHG4DetectorSubsystem(na, lyr)
29 {
31 }
32 
33 //_______________________________________________________________________
35 {
36  delete m_DisplayAction;
37 }
38 
39 //_______________________________________________________________________
41 {
42  PHNodeIterator iter(topNode);
43  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
44  // create display settings before detector
46  m_DisplayAction = displayaction;
47  /* create magnet */
48  m_Detector = new BeamLineMagnetDetector(this, topNode, GetParams(), Name(), GetLayer());
52  std::set<std::string> nodes;
53  if (GetParams()->get_int_param("active"))
54  {
55  PHNodeIterator dstIter(dstNode);
56  PHCompositeNode *DetNode = dstNode;
57  if (SuperDetector() != "NONE" || SuperDetector().empty())
58  {
59  // create super detector subnodes
60  PHNodeIterator iter_dst(dstNode);
61  DetNode = dynamic_cast<PHCompositeNode *>(iter_dst.findFirst("PHCompositeNode", SuperDetector()));
62  if (!DetNode)
63  {
64  DetNode = new PHCompositeNode(SuperDetector());
65  dstNode->addNode(DetNode);
66  }
67  }
68  // create hit output nodes
69  std::string detector_suffix = SuperDetector();
70  if (detector_suffix == "NONE")
71  {
72  detector_suffix = Name();
73  }
74 
75  m_HitNodeName = "G4HIT_" + detector_suffix;
76  nodes.insert(m_HitNodeName);
77  m_AbsorberNodeName = "G4HIT_ABSORBER_" + detector_suffix;
78  if (GetParams()->get_int_param("absorberactive"))
79  {
80  nodes.insert(m_AbsorberNodeName);
81  }
82  for (auto node : nodes)
83  {
84  PHG4HitContainer *g4_hits = findNode::getClass<PHG4HitContainer>(topNode, node);
85  if (!g4_hits)
86  {
87  g4_hits = new PHG4HitContainer(node);
88  DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, node, "PHObject"));
89  }
90  }
94  }
95  else if (GetParams()->get_int_param("blackhole"))
96  {
98  }
99  return 0;
100 }
101 
102 //_______________________________________________________________________
104 {
105  // pass top node to stepping action so that it gets
106  // relevant nodes needed internally
107  if (m_SteppingAction)
108  {
110  }
111  return 0;
112 }
113 
114 //_______________________________________________________________________
116 {
117  return m_Detector;
118 }
119 
121 {
122  set_default_string_param("magtype", "");
123 
124  set_default_double_param("field_x", 0.);
125  set_default_double_param("field_y", 0.);
126  set_default_double_param("field_z", 0.);
127  set_default_double_param("fieldgradient", 0.);
128 
129  set_default_double_param("field_global_position_x", 0.); // abs. position to world for field manager
130  set_default_double_param("field_global_position_y", 0.); // abs. position to world for field manager
131  set_default_double_param("field_global_position_z", 0.); // abs. position to world for field manager
132  set_default_double_param("field_global_rot_x", 0.); // abs. rotation to world for field manager
133  set_default_double_param("field_global_rot_y", 0.); // abs. rotation to world for field manager
134  set_default_double_param("field_global_rot_z", 0.); // abs. rotation to world for field manager
135 
136  set_default_double_param("length", 100);
137  set_default_double_param("place_x", 0.); // relative position to mother vol.
138  set_default_double_param("place_y", 0.); // relative position to mother vol.
139  set_default_double_param("place_z", 0.); // relative position to mother vol.
140  set_default_double_param("rot_x", 0.);
141  set_default_double_param("rot_y", 0.);
142  set_default_double_param("rot_z", 0.);
143  set_default_double_param("inner_radius", 4);
144  set_default_double_param("outer_radius", 100);
145  set_default_double_param("skin_thickness",0.); // Fe thickness before tracks are terminated
146 }
147 
148 void BeamLineMagnetSubsystem::Print(const std::string & /*what*/) const
149 {
150  std::cout << Name() << " Parameters: " << std::endl;
151  if (!BeginRunExecuted())
152  {
153  std::cout << "Need to execute BeginRun() before parameter printout is meaningful" << std::endl;
154  std::cout << "To do so either run one or more events or on the command line execute: " << std::endl;
155  std::cout << "Fun4AllServer *se = Fun4AllServer::instance();" << std::endl;
156  std::cout << "PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");" << std::endl;
157  std::cout << "g4->InitRun(se->topNode());" << std::endl;
158  std::cout << "BeamLineMagnetSubsystem *cyl = (PHG4BeamLineMagnetSubsystem *) g4->getSubsystem(\"" << Name() << "\");" << std::endl;
159  std::cout << "cyl->Print()" << std::endl;
160  return;
161  }
162  GetParams()->Print();
163  return;
164 }