forked from sPHENIX-Collaboration/g4exampledetector
/
G4Example03Subsystem.cc
126 lines (112 loc) · 3.93 KB
/
G4Example03Subsystem.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "G4Example03Subsystem.h"
#include "G4Example03Detector.h"
#include "G4Example03DisplayAction.h"
#include "G4Example03SteppingAction.h"
#include <phparameter/PHParameters.h>
#include <g4main/PHG4HitContainer.h>
#include <g4main/PHG4SteppingAction.h> // for PHG4SteppingAction
#include <phool/PHCompositeNode.h>
#include <phool/PHIODataNode.h> // for PHIODataNode
#include <phool/PHNode.h> // for PHNode
#include <phool/PHNodeIterator.h> // for PHNodeIterator
#include <phool/PHObject.h> // for PHObject
#include <phool/getClass.h>
#include <cmath> // for isfinite
using namespace std;
//_______________________________________________________________________
G4Example03Subsystem::G4Example03Subsystem(const std::string &name)
: PHG4DetectorSubsystem(name)
, m_Detector(nullptr)
, m_SteppingAction(nullptr)
, m_DisplayAction(nullptr)
{
// call base class method which will set up parameter infrastructure
// and call our SetDefaultParameters() method
InitializeParameters();
}
//_______________________________________________________________________
G4Example03Subsystem::~G4Example03Subsystem()
{
delete m_DisplayAction;
}
//_______________________________________________________________________
int G4Example03Subsystem::InitRunSubsystem(PHCompositeNode *topNode)
{
PHNodeIterator iter(topNode);
PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
G4Example03DisplayAction *disp_action = new G4Example03DisplayAction(Name(), GetParams());
if (isfinite(m_ColorArray[0]) &&
isfinite(m_ColorArray[1]) &&
isfinite(m_ColorArray[2]) &&
isfinite(m_ColorArray[3]))
{
disp_action->SetColor(m_ColorArray[0], m_ColorArray[1], m_ColorArray[2], m_ColorArray[3]);
}
m_DisplayAction = disp_action;
PHNodeIterator dstIter(dstNode);
if (GetParams()->get_int_param("active"))
{
PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", Name()));
if (!DetNode)
{
DetNode = new PHCompositeNode(Name());
dstNode->addNode(DetNode);
}
string g4hitnodename = "G4HIT_" + Name();
PHG4HitContainer *g4_hits = findNode::getClass<PHG4HitContainer>(DetNode, g4hitnodename);
if (!g4_hits)
{
g4_hits = new PHG4HitContainer(g4hitnodename);
DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, g4hitnodename, "PHObject"));
}
}
// create detector
m_Detector = new G4Example03Detector(this, topNode, GetParams(), Name());
m_Detector->OverlapCheck(CheckOverlap());
// create stepping action if detector is active
if (GetParams()->get_int_param("active"))
{
m_SteppingAction = new G4Example03SteppingAction(m_Detector, GetParams());
}
return 0;
}
//_______________________________________________________________________
int G4Example03Subsystem::process_event(PHCompositeNode *topNode)
{
// pass top node to stepping action so that it gets
// relevant nodes needed internally
if (m_SteppingAction)
{
m_SteppingAction->SetInterfacePointers(topNode);
}
return 0;
}
void G4Example03Subsystem::Print(const string &what) const
{
if (m_Detector)
{
m_Detector->Print(what);
}
return;
}
//_______________________________________________________________________
PHG4Detector *G4Example03Subsystem::GetDetector(void) const
{
return m_Detector;
}
void G4Example03Subsystem::SetDefaultParameters()
{
// sizes are in cm
// angles are in deg
// units will be converted to G4 units when used
set_default_double_param("place_x", 0.);
set_default_double_param("place_y", 0.);
set_default_double_param("place_z", 0.);
set_default_double_param("rot_x", 0.);
set_default_double_param("rot_y", 0.);
set_default_double_param("rot_z", 0.);
set_default_double_param("size_x", 20.);
set_default_double_param("size_y", 20.);
set_default_double_param("size_z", 20.);
set_default_string_param("material", "G4_Galactic");
}