Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Example03Subsystem.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Example03Subsystem.cc
1 #include "G4Example03Subsystem.h"
2 
3 #include "G4Example03Detector.h"
6 
7 #include <phparameter/PHParameters.h>
8 
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 isfinite
20 
21 using namespace std;
22 
23 //_______________________________________________________________________
25  : PHG4DetectorSubsystem(name)
26  , m_Detector(nullptr)
27  , m_SteppingAction(nullptr)
28  , m_DisplayAction(nullptr)
29 {
30  // call base class method which will set up parameter infrastructure
31  // and call our SetDefaultParameters() method
33 }
34 
35 //_______________________________________________________________________
37 {
38  delete m_DisplayAction;
39 }
40 
41 //_______________________________________________________________________
43 {
44  PHNodeIterator iter(topNode);
45  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
47  if (isfinite(m_ColorArray[0]) &&
48  isfinite(m_ColorArray[1]) &&
49  isfinite(m_ColorArray[2]) &&
50  isfinite(m_ColorArray[3]))
51  {
52  disp_action->SetColor(m_ColorArray[0], m_ColorArray[1], m_ColorArray[2], m_ColorArray[3]);
53  }
54  m_DisplayAction = disp_action;
55  PHNodeIterator dstIter(dstNode);
56  if (GetParams()->get_int_param("active"))
57  {
58  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", Name()));
59  if (!DetNode)
60  {
61  DetNode = new PHCompositeNode(Name());
62  dstNode->addNode(DetNode);
63  }
64  string g4hitnodename = "G4HIT_" + Name();
65  PHG4HitContainer *g4_hits = findNode::getClass<PHG4HitContainer>(DetNode, g4hitnodename);
66  if (!g4_hits)
67  {
68  g4_hits = new PHG4HitContainer(g4hitnodename);
69  DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, g4hitnodename, "PHObject"));
70  }
71  }
72  // create detector
73  m_Detector = new G4Example03Detector(this, topNode, GetParams(), Name());
75  // create stepping action if detector is active
76  if (GetParams()->get_int_param("active"))
77  {
79  }
80  return 0;
81 }
82 
83 //_______________________________________________________________________
85 {
86  // pass top node to stepping action so that it gets
87  // relevant nodes needed internally
88  if (m_SteppingAction)
89  {
91  }
92  return 0;
93 }
94 
95 void G4Example03Subsystem::Print(const string &what) const
96 {
97  if (m_Detector)
98  {
99  m_Detector->Print(what);
100  }
101  return;
102 }
103 
104 //_______________________________________________________________________
106 {
107  return m_Detector;
108 }
109 
111 {
112  // sizes are in cm
113  // angles are in deg
114  // units will be converted to G4 units when used
115  set_default_double_param("place_x", 0.);
116  set_default_double_param("place_y", 0.);
117  set_default_double_param("place_z", 0.);
118  set_default_double_param("rot_x", 0.);
119  set_default_double_param("rot_y", 0.);
120  set_default_double_param("rot_z", 0.);
121  set_default_double_param("size_x", 20.);
122  set_default_double_param("size_y", 20.);
123  set_default_double_param("size_z", 20.);
124 
125  set_default_string_param("material", "G4_Galactic");
126 }