Analysis Software
Documentation for sPHENIX simulation software
 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
2 #include "PHG4CylinderDetector.h"
5 #include "PHG4CylinderGeomv1.h"
7 
8 #include <phparameter/PHParameters.h>
9 
10 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
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 //_______________________________________________________________________
32  : PHG4DetectorSubsystem(na, lyr)
33 {
34  m_ColorArray.fill(NAN);
36 }
37 
38 //_______________________________________________________________________
40 {
41  delete m_DisplayAction;
42 }
43 
44 //_______________________________________________________________________
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  {
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  {
62  GetParams()->set_string_param("material", rc->get_StringFlag("WorldMaterial"));
63  }
64  // create display settings before detector
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());
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);
134  }
135  else if (GetParams()->get_int_param("blackhole"))
136  {
138  }
139  if (m_SteppingAction)
140  {
141  (dynamic_cast<PHG4CylinderSteppingAction *>(m_SteppingAction))->SaveAllHits(m_SaveAllHitsFlag);
142  }
143  return 0;
144 }
145 
146 //_______________________________________________________________________
148 {
149  // pass top node to stepping action so that it gets
150  // relevant nodes needed internally
151  if (m_SteppingAction)
152  {
154  }
155  return 0;
156 }
157 
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 *
184 {
185  return m_Detector;
186 }
187 
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 }