ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4JLeicBeamLineMagnetSubsystem.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4JLeicBeamLineMagnetSubsystem.cc
5 
6 #include <phparameter/PHParameters.h>
7 
8 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
10 #include <g4main/PHG4SteppingAction.h> // for PHG4SteppingAction
11 
12 #include <phool/PHCompositeNode.h>
13 #include <phool/PHIODataNode.h> // for PHIODataNode
14 #include <phool/PHNode.h> // for PHNode
15 #include <phool/PHNodeIterator.h> // for PHNodeIterator
16 #include <phool/PHObject.h> // for PHObject
17 #include <phool/getClass.h>
18 
19 #include <cmath> // for NAN
20 #include <iostream> // for operator<<, endl, basic_ostream
21 
22 class PHCompositeNode;
23 class PHG4Detector;
24 
25 using namespace std;
26 
27 //_______________________________________________________________________
29  : PHG4DetectorSubsystem(na, lyr)
30  , m_Detector(nullptr)
31  , m_SteppingAction(nullptr)
32  , m_DisplayAction(nullptr)
33 {
35 }
36 
37 //_______________________________________________________________________
39 {
40  delete m_DisplayAction;
41 }
42 
43 //_______________________________________________________________________
45 {
46  PHNodeIterator iter(topNode);
47  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
48  PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "RUN"));
49 
50  // create display settings before detector
52  m_DisplayAction = displayaction;
53  /* create magnet */
54  m_Detector = new G4JLeicBeamLineMagnetDetector(this, topNode, GetParams(), Name(), GetLayer());
57  set<string> nodes;
58  if (GetParams()->get_int_param("active"))
59  {
60  PHNodeIterator dstIter(dstNode);
61  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", SuperDetector()));
62  if (!DetNode)
63  {
64  DetNode = new PHCompositeNode(SuperDetector());
65  dstNode->addNode(DetNode);
66  }
67 
68  ostringstream nodename;
69  if (SuperDetector() != "NONE")
70  {
71  // create super detector subnodes
72  PHNodeIterator iter_dst(dstNode);
73  PHCompositeNode *superSubNode = dynamic_cast<PHCompositeNode *>(iter_dst.findFirst("PHCompositeNode", SuperDetector()));
74  if (!superSubNode)
75  {
76  superSubNode = new PHCompositeNode(SuperDetector());
77  dstNode->addNode(superSubNode);
78  }
79  dstNode = superSubNode;
80  PHNodeIterator iter_run(runNode);
81  superSubNode = dynamic_cast<PHCompositeNode *>(iter_run.findFirst("PHCompositeNode", SuperDetector()));
82  if (!superSubNode)
83  {
84  superSubNode = new PHCompositeNode(SuperDetector());
85  runNode->addNode(superSubNode);
86  }
87  runNode = superSubNode;
88 
89  nodename << "G4HIT_" << SuperDetector();
90  }
91  else
92  {
93  nodename << "G4HIT_" << Name();
94  }
95  nodes.insert(nodename.str());
96  if (GetParams()->get_int_param("absorberactive"))
97  {
98  nodename.str("");
99  if (SuperDetector() != "NONE")
100  {
101  nodename << "G4HIT_ABSORBER_" << SuperDetector();
102  }
103  else
104  {
105  nodename << "G4HIT_ABSORBER_" << Name();
106  }
107  nodes.insert(nodename.str());
108  }
109  for (auto node : nodes)
110  {
111  PHG4HitContainer *g4_hits = findNode::getClass<PHG4HitContainer>(topNode, node);
112  if (!g4_hits)
113  {
114  g4_hits = new PHG4HitContainer(node);
115  DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, node, "PHObject"));
116  }
117  }
118 
120  }
121  else if (GetParams()->get_int_param("blackhole"))
122  {
124  }
125 
126  return 0;
127 }
128 
129 //_______________________________________________________________________
131 {
132  // pass top node to stepping action so that it gets
133  // relevant nodes needed internally
134  if (m_SteppingAction)
135  {
137  }
138  return 0;
139 }
140 
141 //_______________________________________________________________________
143 {
144  return m_Detector;
145 }
146 
148 {
149  set_default_string_param("magtype", "");
150 
151  set_default_double_param("field_x", 0.);
152  set_default_double_param("field_y", 0.);
153  set_default_double_param("field_z", 0.);
154  set_default_double_param("fieldgradient", 0.);
155 
156  set_default_double_param("length", 100);
157  set_default_double_param("place_x", 0.);
158  set_default_double_param("place_y", 0.);
159  set_default_double_param("place_z", 0.);
160  set_default_double_param("rot_x", 0.);
161  set_default_double_param("rot_y", 0.);
162  set_default_double_param("rot_z", 0.);
163  set_default_double_param("inner_radius", 4);
164  set_default_double_param("outer_radius", 100);
165 }
166 
167 void G4JLeicBeamLineMagnetSubsystem::Print(const string& what) const
168 {
169  cout << Name() << " Parameters: " << endl;
170  if (!BeginRunExecuted())
171  {
172  cout << "Need to execute BeginRun() before parameter printout is meaningful" << endl;
173  cout << "To do so either run one or more events or on the command line execute: " << endl;
174  cout << "Fun4AllServer *se = Fun4AllServer::instance();" << endl;
175  cout << "PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");" << endl;
176  cout << "g4->InitRun(se->topNode());" << endl;
177  cout << "G4JLeicBeamLineMagnetSubsystem *cyl = (PHG4BeamLineMagnetSubsystem *) g4->getSubsystem(\"" << Name() << "\");" << endl;
178  cout << "cyl->Print()" << endl;
179  return;
180  }
181  GetParams()->Print();
182  return;
183 }