EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Example02Subsystem.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Example02Subsystem.cc
1 #include "G4Example02Subsystem.h"
2 
3 #include "G4Example02Detector.h"
5 
6 #include <phparameter/PHParameters.h>
7 
9 #include <g4main/PHG4SteppingAction.h> // for PHG4SteppingAction
10 
11 #include <phool/PHCompositeNode.h>
12 #include <phool/PHIODataNode.h> // for PHIODataNode
13 #include <phool/PHNode.h> // for PHNode
14 #include <phool/PHNodeIterator.h> // for PHNodeIterator
15 #include <phool/PHObject.h> // for PHObject
16 #include <phool/getClass.h>
17 
18 using namespace std;
19 
20 //_______________________________________________________________________
22  : PHG4DetectorSubsystem(name)
23  , m_Detector(nullptr)
24  , m_SteppingAction(nullptr)
25 {
26  // call base class method which will set up parameter infrastructure
27  // and call our SetDefaultParameters() method
29 }
30 
31 //_______________________________________________________________________
33 {
34  PHNodeIterator iter(topNode);
35  PHCompositeNode *dstNode =
36  dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
37  PHNodeIterator dstIter(dstNode);
38  if (GetParams()->get_int_param("active"))
39  {
40  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", Name()));
41  if (!DetNode)
42  {
43  DetNode = new PHCompositeNode(Name());
44  dstNode->addNode(DetNode);
45  }
46  string g4hitnodename = "G4HIT_" + Name();
47  PHG4HitContainer *g4_hits = findNode::getClass<PHG4HitContainer>(DetNode, g4hitnodename);
48  if (!g4_hits)
49  {
50  g4_hits = new PHG4HitContainer(g4hitnodename);
51  DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, g4hitnodename, "PHObject"));
52  }
53  }
54  // create detector
55  m_Detector = new G4Example02Detector(this, topNode, GetParams(), Name());
57  // create stepping action if detector is active
58  if (GetParams()->get_int_param("active"))
59  {
61  }
62  return 0;
63 }
64 
65 //_______________________________________________________________________
67 {
68  // pass top node to stepping action so that it gets
69  // relevant nodes needed internally
70  if (m_SteppingAction)
71  {
73  }
74  return 0;
75 }
76 
77 void G4Example02Subsystem::Print(const string &what) const
78 {
79  if (m_Detector)
80  {
81  m_Detector->Print(what);
82  }
83  return;
84 }
85 
86 //_______________________________________________________________________
88 {
89  return m_Detector;
90 }
91 
93 {
94  // sizes are in cm
95  // angles are in deg
96  // units will be converted to G4 units when used
97  set_default_double_param("place_x", 0.);
98  set_default_double_param("place_y", 0.);
99  set_default_double_param("place_z", 0.);
100  set_default_double_param("rot_x", 0.);
101  set_default_double_param("rot_y", 0.);
102  set_default_double_param("rot_z", 0.);
103  set_default_double_param("size_x", 20.);
104  set_default_double_param("size_y", 20.);
105  set_default_double_param("size_z", 20.);
106 
107  set_default_string_param("material", "G4_Galactic");
108 }