Analysis Software
Documentation for sPHENIX simulation 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
2 
6 #include "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 //_______________________________________________________________________
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 
53  if (GetParams()->get_int_param("active"))
54  {
55  std::set<std::string> nodes;
56  PHNodeIterator dstIter(dstNode);
57  PHCompositeNode *DetNode = dstNode;
58  if (SuperDetector() != "NONE" || SuperDetector().empty())
59  {
60  // create super detector subnodes
61  PHNodeIterator iter_dst(dstNode);
62  DetNode = dynamic_cast<PHCompositeNode *>(iter_dst.findFirst("PHCompositeNode", SuperDetector()));
63  if (!DetNode)
64  {
65  DetNode = new PHCompositeNode(SuperDetector());
66  dstNode->addNode(DetNode);
67  }
68  }
69  // create hit output nodes
70  std::string detector_suffix = SuperDetector();
71  if (detector_suffix == "NONE")
72  {
73  detector_suffix = Name();
74  }
75 
76  m_HitNodeName = "G4HIT_" + detector_suffix;
77  nodes.insert(m_HitNodeName);
78  m_AbsorberNodeName = "G4HIT_ABSORBER_" + detector_suffix;
79  if (GetParams()->get_int_param("absorberactive"))
80  {
81  nodes.insert(m_AbsorberNodeName);
82  }
83  for (const auto &node : nodes)
84  {
85  PHG4HitContainer *g4_hits = findNode::getClass<PHG4HitContainer>(topNode, node);
86  if (!g4_hits)
87  {
88  g4_hits = new PHG4HitContainer(node);
89  DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, node, "PHObject"));
90  }
91  }
95  }
96  else if (GetParams()->get_int_param("blackhole"))
97  {
99  }
100  return 0;
101 }
102 
103 //_______________________________________________________________________
105 {
106  // pass top node to stepping action so that it gets
107  // relevant nodes needed internally
108  if (m_SteppingAction)
109  {
111  }
112  return 0;
113 }
114 
115 //_______________________________________________________________________
117 {
118  return m_Detector;
119 }
120 
122 {
123  set_default_string_param("magtype", "");
124 
125  set_default_double_param("field_x", 0.);
126  set_default_double_param("field_y", 0.);
127  set_default_double_param("field_z", 0.);
128  set_default_double_param("fieldgradient", 0.);
129 
130  set_default_double_param("field_global_position_x", 0.); // abs. position to world for field manager
131  set_default_double_param("field_global_position_y", 0.); // abs. position to world for field manager
132  set_default_double_param("field_global_position_z", 0.); // abs. position to world for field manager
133  set_default_double_param("field_global_rot_x", 0.); // abs. rotation to world for field manager
134  set_default_double_param("field_global_rot_y", 0.); // abs. rotation to world for field manager
135  set_default_double_param("field_global_rot_z", 0.); // abs. rotation to world for field manager
136 
137  set_default_double_param("length", 100);
138  set_default_double_param("place_x", 0.); // relative position to mother vol.
139  set_default_double_param("place_y", 0.); // relative position to mother vol.
140  set_default_double_param("place_z", 0.); // relative position to mother vol.
141  set_default_double_param("rot_x", 0.);
142  set_default_double_param("rot_y", 0.);
143  set_default_double_param("rot_z", 0.);
144  set_default_double_param("inner_radius", 4);
145  set_default_double_param("outer_radius", 100);
146  set_default_double_param("skin_thickness", 0.); // Fe thickness before tracks are terminated
147 }
148 
149 void BeamLineMagnetSubsystem::Print(const std::string & /*what*/) const
150 {
151  std::cout << Name() << " Parameters: " << std::endl;
152  if (!BeginRunExecuted())
153  {
154  std::cout << "Need to execute BeginRun() before parameter printout is meaningful" << std::endl;
155  std::cout << "To do so either run one or more events or on the command line execute: " << std::endl;
156  std::cout << "Fun4AllServer *se = Fun4AllServer::instance();" << std::endl;
157  std::cout << "PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");" << std::endl;
158  std::cout << "g4->InitRun(se->topNode());" << std::endl;
159  std::cout << "BeamLineMagnetSubsystem *cyl = (PHG4BeamLineMagnetSubsystem *) g4->getSubsystem(\"" << Name() << "\");" << std::endl;
160  std::cout << "cyl->Print()" << std::endl;
161  return;
162  }
163  GetParams()->Print();
164  return;
165 }