Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
PHG4CylinderSubsystem.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file PHG4CylinderSubsystem.cc
1
#include "
PHG4CylinderSubsystem.h
"
2
#include "
PHG4CylinderDetector.h
"
3
#include "
PHG4CylinderDisplayAction.h
"
4
#include "
PHG4CylinderGeomContainer.h
"
5
#include "
PHG4CylinderGeomv1.h
"
6
#include "
PHG4CylinderSteppingAction.h
"
7
8
#include <phparameter/PHParameters.h>
9
10
#include <
g4main/PHG4DisplayAction.h
>
// for PHG4DisplayAction
11
#include <
g4main/PHG4HitContainer.h
>
12
#include <
g4main/PHG4SteppingAction.h
>
// for PHG4SteppingAction
13
#include <
g4main/PHG4Utils.h
>
14
15
#include <
phool/PHCompositeNode.h
>
16
#include <
phool/PHIODataNode.h
>
// for PHIODataNode
17
#include <
phool/PHNode.h
>
// for PHNode
18
#include <
phool/PHNodeIterator.h
>
// for PHNodeIterator
19
#include <
phool/PHObject.h
>
// for PHObject
20
#include <
phool/getClass.h
>
21
#include <
phool/recoConsts.h
>
22
23
#include <cmath>
// for NAN
24
#include <iostream>
// for operator<<, basic_ostream, endl
25
#include <sstream>
26
27
class
PHG4CylinderGeom
;
28
class
PHG4Detector
;
29
30
//_______________________________________________________________________
31
PHG4CylinderSubsystem::PHG4CylinderSubsystem
(
const
std::string
&na,
const
int
lyr)
32
:
PHG4DetectorSubsystem
(na, lyr)
33
{
34
m_ColorArray
.fill(NAN);
35
InitializeParameters
();
36
}
37
38
//_______________________________________________________________________
39
PHG4CylinderSubsystem::~PHG4CylinderSubsystem
()
40
{
41
delete
m_DisplayAction
;
42
}
43
44
//_______________________________________________________________________
45
int
PHG4CylinderSubsystem::InitRunSubsystem
(
PHCompositeNode
*
topNode
)
46
{
47
// create hit list only for active layers
48
double
detlength =
GetParams
()->
get_double_param
(
"length"
);
49
if
(!std::isfinite(detlength) &&
GetParams
()->
get_int_param
(
"lengthviarapidity"
))
50
{
51
GetParams
()->
set_double_param
(
"length"
,
PHG4Utils::GetLengthForRapidityCoverage
(
GetParams
()->
get_double_param
(
"radius"
) +
GetParams
()->
get_double_param
(
"thickness"
)) * 2);
52
detlength =
GetParams
()->
get_double_param
(
"length"
);
53
}
54
else
55
{
56
GetParams
()->
set_int_param
(
"lengthviarapidity"
, 0);
57
}
58
// use world material if material was not set so far
59
if
(
GetParams
()->
get_string_param
(
"material"
) ==
"WorldMaterial"
)
60
{
61
recoConsts
*rc =
recoConsts::instance
();
62
GetParams
()->
set_string_param
(
"material"
, rc->
get_StringFlag
(
"WorldMaterial"
));
63
}
64
// create display settings before detector
65
PHG4CylinderDisplayAction
*disp_action =
new
PHG4CylinderDisplayAction
(
Name
(),
GetParams
());
66
if
(std::isfinite(
m_ColorArray
[0]) &&
67
std::isfinite(
m_ColorArray
[1]) &&
68
std::isfinite(
m_ColorArray
[2]) &&
69
std::isfinite(
m_ColorArray
[3]))
70
{
71
disp_action->
SetColor
(
m_ColorArray
[0],
m_ColorArray
[1],
m_ColorArray
[2],
m_ColorArray
[3]);
72
}
73
m_DisplayAction
= disp_action;
74
75
// create detector
76
m_Detector
=
new
PHG4CylinderDetector
(
this
, topNode,
GetParams
(),
Name
(),
GetLayer
());
77
m_Detector
->
SuperDetector
(
SuperDetector
());
78
m_Detector
->
OverlapCheck
(
CheckOverlap
());
79
if
(
GetParams
()->
get_int_param
(
"active"
))
80
{
81
PHNodeIterator
iter(topNode);
82
PHCompositeNode
*dstNode =
dynamic_cast<
PHCompositeNode
*
>
(iter.
findFirst
(
"PHCompositeNode"
,
"DST"
));
83
PHCompositeNode
*runNode =
dynamic_cast<
PHCompositeNode
*
>
(iter.
findFirst
(
"PHCompositeNode"
,
"RUN"
));
84
85
std::string
nodename;
86
std::string
geonode;
87
if
(
SuperDetector
() !=
"NONE"
)
88
{
89
// create super detector subnodes
90
PHNodeIterator
iter_dst(dstNode);
91
PHCompositeNode
*superSubNode =
dynamic_cast<
PHCompositeNode
*
>
(iter_dst.
findFirst
(
"PHCompositeNode"
,
SuperDetector
()));
92
if
(!superSubNode)
93
{
94
superSubNode =
new
PHCompositeNode
(
SuperDetector
());
95
dstNode->
addNode
(superSubNode);
96
}
97
dstNode = superSubNode;
98
PHNodeIterator
iter_run(runNode);
99
superSubNode =
dynamic_cast<
PHCompositeNode
*
>
(iter_run.
findFirst
(
"PHCompositeNode"
,
SuperDetector
()));
100
if
(!superSubNode)
101
{
102
superSubNode =
new
PHCompositeNode
(
SuperDetector
());
103
runNode->
addNode
(superSubNode);
104
}
105
runNode = superSubNode;
106
107
nodename =
"G4HIT_"
+
SuperDetector
();
108
geonode =
"CYLINDERGEOM_"
+
SuperDetector
();
109
}
110
111
else
112
{
113
nodename =
"G4HIT_"
+
Name
();
114
geonode =
"CYLINDERGEOM_"
+
Name
();
115
}
116
PHG4HitContainer
*cylinder_hits = findNode::getClass<PHG4HitContainer>(
topNode
, nodename);
117
if
(!cylinder_hits)
118
{
119
dstNode->
addNode
(
new
PHIODataNode<PHObject>
(cylinder_hits =
new
PHG4HitContainer
(nodename), nodename,
"PHObject"
));
120
}
121
cylinder_hits->
AddLayer
(
GetLayer
());
122
PHG4CylinderGeomContainer
*geo = findNode::getClass<PHG4CylinderGeomContainer>(
topNode
, geonode);
123
if
(!geo)
124
{
125
geo =
new
PHG4CylinderGeomContainer
();
126
PHIODataNode<PHObject>
*newNode =
new
PHIODataNode<PHObject>
(geo, geonode,
"PHObject"
);
127
runNode->
addNode
(newNode);
128
}
129
PHG4CylinderGeom
*mygeom =
new
PHG4CylinderGeomv1
(
GetParams
()->
get_double_param
(
"radius"
),
GetParams
()->
get_double_param
(
"place_z"
) - detlength / 2.,
GetParams
()->
get_double_param
(
"place_z"
) + detlength / 2.,
GetParams
()->
get_double_param
(
"thickness"
));
130
geo->
AddLayerGeom
(
GetLayer
(), mygeom);
131
auto
*
tmp
=
new
PHG4CylinderSteppingAction
(
this
,
m_Detector
,
GetParams
());
132
tmp
->HitNodeName(nodename);
133
m_SteppingAction
=
tmp
;
134
}
135
else
if
(
GetParams
()->
get_int_param
(
"blackhole"
))
136
{
137
m_SteppingAction
=
new
PHG4CylinderSteppingAction
(
this
,
m_Detector
,
GetParams
());
138
}
139
if
(
m_SteppingAction
)
140
{
141
(
dynamic_cast<
PHG4CylinderSteppingAction
*
>
(
m_SteppingAction
))->SaveAllHits(
m_SaveAllHitsFlag
);
142
}
143
return
0;
144
}
145
146
//_______________________________________________________________________
147
int
PHG4CylinderSubsystem::process_event
(
PHCompositeNode
*
topNode
)
148
{
149
// pass top node to stepping action so that it gets
150
// relevant nodes needed internally
151
if
(
m_SteppingAction
)
152
{
153
m_SteppingAction
->
SetInterfacePointers
(topNode);
154
}
155
return
0;
156
}
157
158
void
PHG4CylinderSubsystem::SetDefaultParameters
()
159
{
160
set_default_double_param
(
"length"
, NAN);
161
set_default_double_param
(
"place_x"
, 0.);
162
set_default_double_param
(
"place_y"
, 0.);
163
set_default_double_param
(
"place_z"
, 0.);
164
set_default_double_param
(
"radius"
, NAN);
165
set_default_double_param
(
"steplimits"
, NAN);
166
set_default_double_param
(
"thickness"
, NAN);
167
set_default_double_param
(
"tmin"
, NAN);
168
set_default_double_param
(
"tmax"
, NAN);
169
set_default_double_param
(
"rot_x"
, 0.);
170
set_default_double_param
(
"rot_y"
, 0.);
171
set_default_double_param
(
"rot_z"
, 0.);
172
set_default_double_param
(
"start_phi_rad"
, 0.);
173
set_default_double_param
(
"delta_phi_rad"
, M_PI * 2);
174
set_default_int_param
(
"lengthviarapidity"
, 1);
175
set_default_int_param
(
"lightyield"
, 0);
176
set_default_int_param
(
"use_g4steps"
, 0);
177
178
// place holder, will be replaced by world material if not set by other means (macro)
179
set_default_string_param
(
"material"
,
"WorldMaterial"
);
180
}
181
182
PHG4Detector
*
183
PHG4CylinderSubsystem::GetDetector
()
const
184
{
185
return
m_Detector
;
186
}
187
188
void
PHG4CylinderSubsystem::Print
(
const
std::string
&what)
const
189
{
190
std::cout <<
Name
() <<
" Parameters: "
<< std::endl;
191
if
(!
BeginRunExecuted
())
192
{
193
std::cout <<
"Need to execute BeginRun() before parameter printout is meaningful"
<< std::endl;
194
std::cout <<
"To do so either run one or more events or on the command line execute: "
<< std::endl;
195
std::cout <<
"Fun4AllServer *se = Fun4AllServer::instance();"
<< std::endl;
196
std::cout <<
"PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");"
<< std::endl;
197
std::cout <<
"g4->InitRun(se->topNode());"
<< std::endl;
198
std::cout <<
"PHG4CylinderSubsystem *cyl = (PHG4CylinderSubsystem *) g4->getSubsystem(\""
<<
Name
() <<
"\");"
<< std::endl;
199
std::cout <<
"cyl->Print()"
<< std::endl;
200
return
;
201
}
202
GetParams
()->
Print
();
203
if
(
m_SteppingAction
)
204
{
205
m_SteppingAction
->
Print
(what);
206
}
207
return
;
208
}
coresoftware
blob
master
simulation
g4simulation
g4detectors
PHG4CylinderSubsystem.cc
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:12
using
1.8.2 with
sPHENIX GitHub integration