ECCE @ EIC 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 using namespace std;
31 
32 //_______________________________________________________________________
33 PHG4CylinderSubsystem::PHG4CylinderSubsystem(const std::string &na, const int lyr)
34  : PHG4DetectorSubsystem(na, lyr)
35 {
36  m_ColorArray.fill(NAN);
38 }
39 
40 //_______________________________________________________________________
42 {
43  delete m_DisplayAction;
44 }
45 
46 //_______________________________________________________________________
48 {
49  // create hit list only for active layers
50  double detlength = GetParams()->get_double_param("length");
51  if (!isfinite(detlength) && GetParams()->get_int_param("lengthviarapidity"))
52  {
54  detlength = GetParams()->get_double_param("length");
55  }
56  else
57  {
58  GetParams()->set_int_param("lengthviarapidity", 0);
59  }
60  // use world material if material was not set so far
61  if (GetParams()->get_string_param("material") == "WorldMaterial")
62  {
64  GetParams()->set_string_param("material", rc->get_StringFlag("WorldMaterial"));
65  }
66  // create display settings before detector
68  if (isfinite(m_ColorArray[0]) &&
69  isfinite(m_ColorArray[1]) &&
70  isfinite(m_ColorArray[2]) &&
72  {
73  disp_action->SetColor(m_ColorArray[0], m_ColorArray[1], m_ColorArray[2], m_ColorArray[3]);
74  }
75  m_DisplayAction = disp_action;
76 
77  // create detector
78  m_Detector = new PHG4CylinderDetector(this, topNode, GetParams(), Name(), GetLayer());
81  if (GetParams()->get_int_param("active"))
82  {
83  PHNodeIterator iter(topNode);
84  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
85  PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "RUN"));
86 
87  string nodename;
88  string geonode;
89  if (SuperDetector() != "NONE")
90  {
91  // create super detector subnodes
92  PHNodeIterator iter_dst(dstNode);
93  PHCompositeNode *superSubNode = dynamic_cast<PHCompositeNode *>(iter_dst.findFirst("PHCompositeNode", SuperDetector()));
94  if (!superSubNode)
95  {
96  superSubNode = new PHCompositeNode(SuperDetector());
97  dstNode->addNode(superSubNode);
98  }
99  dstNode = superSubNode;
100  PHNodeIterator iter_run(runNode);
101  superSubNode = dynamic_cast<PHCompositeNode *>(iter_run.findFirst("PHCompositeNode", SuperDetector()));
102  if (!superSubNode)
103  {
104  superSubNode = new PHCompositeNode(SuperDetector());
105  runNode->addNode(superSubNode);
106  }
107  runNode = superSubNode;
108 
109  nodename = "G4HIT_" + SuperDetector();
110  geonode = "CYLINDERGEOM_" + SuperDetector();
111  }
112 
113  else
114  {
115  nodename = "G4HIT_" + Name();
116  geonode = "CYLINDERGEOM_" + Name();
117  }
118  PHG4HitContainer *cylinder_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename);
119  if (!cylinder_hits)
120  {
121  dstNode->addNode(new PHIODataNode<PHObject>(cylinder_hits = new PHG4HitContainer(nodename), nodename, "PHObject"));
122  }
123  cylinder_hits->AddLayer(GetLayer());
124  PHG4CylinderGeomContainer *geo = findNode::getClass<PHG4CylinderGeomContainer>(topNode, geonode);
125  if (!geo)
126  {
127  geo = new PHG4CylinderGeomContainer();
128  PHIODataNode<PHObject> *newNode = new PHIODataNode<PHObject>(geo, geonode, "PHObject");
129  runNode->addNode(newNode);
130  }
131  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"));
132  geo->AddLayerGeom(GetLayer(), mygeom);
133  auto *tmp = new PHG4CylinderSteppingAction(this, m_Detector, GetParams());
134  tmp->HitNodeName(nodename);
136  }
137  else if (GetParams()->get_int_param("blackhole"))
138  {
140  }
141  if (m_SteppingAction)
142  {
143  (dynamic_cast<PHG4CylinderSteppingAction *>(m_SteppingAction))->SaveAllHits(m_SaveAllHitsFlag);
144  }
145  return 0;
146 }
147 
148 //_______________________________________________________________________
150 {
151  // pass top node to stepping action so that it gets
152  // relevant nodes needed internally
153  if (m_SteppingAction)
154  {
156  }
157  return 0;
158 }
159 
161 {
162  set_default_double_param("length", NAN);
163  set_default_double_param("place_x", 0.);
164  set_default_double_param("place_y", 0.);
165  set_default_double_param("place_z", 0.);
166  set_default_double_param("radius", NAN);
167  set_default_double_param("steplimits", NAN);
168  set_default_double_param("thickness", NAN);
169  set_default_double_param("tmin", NAN);
170  set_default_double_param("tmax", NAN);
171  set_default_double_param("rot_x", 0.);
172  set_default_double_param("rot_y", 0.);
173  set_default_double_param("rot_z", 0.);
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 
188 void PHG4CylinderSubsystem::Print(const string &what) const
189 {
190  cout << Name() << " Parameters: " << endl;
191  if (!BeginRunExecuted())
192  {
193  cout << "Need to execute BeginRun() before parameter printout is meaningful" << endl;
194  cout << "To do so either run one or more events or on the command line execute: " << endl;
195  cout << "Fun4AllServer *se = Fun4AllServer::instance();" << endl;
196  cout << "PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");" << endl;
197  cout << "g4->InitRun(se->topNode());" << endl;
198  cout << "PHG4CylinderSubsystem *cyl = (PHG4CylinderSubsystem *) g4->getSubsystem(\"" << Name() << "\");" << endl;
199  cout << "cyl->Print()" << endl;
200  return;
201  }
202  GetParams()->Print();
203  if (m_SteppingAction)
204  {
205  m_SteppingAction->Print(what);
206  }
207  return;
208 }