EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4TRDSubsystem.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4TRDSubsystem.cc
1 #include "PHG4TRDSubsystem.h"
2 #include "PHG4TRDDetector.h"
4 
5 #include <phparameter/PHParameters.h>
6 
7 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
9 #include <g4main/PHG4SteppingAction.h> // for PHG4SteppingAction
10 #include <g4main/PHG4Utils.h>
11 
12 #include <phool/PHCompositeNode.h>
13 #include <phool/PHIODataNode.h> // for PHIODataNode
14 #include <phool/PHNode.h> // for PHNode
15 #include <phool/PHNodeIterator.h> // for PHNodeIterator
16 #include <phool/PHObject.h> // for PHObject
17 #include <phool/getClass.h>
18 #include <phool/recoConsts.h>
19 
20 #include <boost/foreach.hpp>
21 
22 #include <cmath> // for NAN
23 #include <iostream> // for operator<<, basic_ostream, endl
24 #include <sstream>
25 
26 class PHG4Detector;
27 class PHG4SteppingAction;
28 
29 using namespace std;
30 
31 PHG4TRDSubsystem::PHG4TRDSubsystem(const std::string &na, const int lyr)
32  : PHG4DetectorSubsystem(na, lyr)
33  , m_Detector(nullptr)
34  , m_SteppingAction(nullptr)
35 {
37 }
38 
40 {
41 }
42 
43 //_______________________________________________________________________
45 {
46  PHNodeIterator iter(topNode);
47  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
48  // create detector
49  m_Detector = new PHG4TRDDetector(this, topNode, GetParams(), Name(), GetLayer());
52  /*
53  string nodename;
54  nodename = "G4HIT_" + SuperDetector();
55  string nodes;
56 
57  if (GetParams()->get_int_param("active"))
58  {
59  PHG4HitContainer *TRD_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename);
60 
61  if (!TRD_hits)
62  {
63  //dstNode->addNode(new PHIODataNode<PHObject>(TRD_hits = new PHG4HitContainer(nodename), nodename, "PHObject"));
64  TRD_hits = new PHG4HitContainer(nodename);
65  PHIODataNode<PHObject>* hitNode = new PHIODataNode<PHObject>(TRD_hits, nodename, "PHObject");
66  dstNode->addNode(hitNode);
67  // nodes.insert(nodename);
68  }
69 */
70 
71  set<string> nodes;
72  if (GetParams()->get_int_param("active"))
73  {
74  PHNodeIterator dstIter(dstNode);
75  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", SuperDetector()));
76  if (!DetNode)
77  {
78  DetNode = new PHCompositeNode(SuperDetector());
79  dstNode->addNode(DetNode);
80  }
81 
82  ostringstream nodename;
83  if (SuperDetector() != "NONE")
84  {
85  nodename << "G4HIT_" << SuperDetector();
86  }
87  else
88  {
89  nodename << "G4HIT_" << Name();
90  }
91  nodes.insert(nodename.str());
92  if (GetParams()->get_int_param("absorberactive"))
93  {
94  nodename.str("");
95  if (SuperDetector() != "NONE")
96  {
97  nodename << "G4HIT_ACTIVEGAS_" << SuperDetector();
98  }
99  else
100  {
101  nodename << "G4HIT_ACTIVEGAS_" << Name();
102  }
103  nodes.insert(nodename.str());
104  }
105 
106  BOOST_FOREACH (string node, nodes)
107  {
108  PHG4HitContainer *g4_hits = findNode::getClass<PHG4HitContainer>(topNode, node.c_str());
109  if (!g4_hits)
110  {
111  g4_hits = new PHG4HitContainer(node);
112  DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, node.c_str(), "PHObject"));
113  }
114  }
115  //Stepping action
116  /*
117  auto *tmp = new PHG4TRDSteppingAction(this, m_Detector, GetParams());
118  tmp->HitNodeName(nodename);
119  m_SteppingAction = tmp;
120  }
121  else if (GetParams()->get_int_param("blackhole"))
122  {
123  m_SteppingAction = new PHG4TRDSteppingAction(this, m_Detector, GetParams());
124  }
125 
126  if (m_SteppingAction)
127  {
128  (dynamic_cast<PHG4TRDSteppingAction *>(m_SteppingAction))->SaveAllHits(m_SaveAllHitsFlag);
129  }
130 */
132  }
133  else
134  {
135  // if this is a black hole it does not have to be active
136  if (GetParams()->get_int_param("blackhole"))
137  {
139  }
140  }
141 
142  return 0;
143 }
144 
146 {
147  // pass top node to stepping action so that it gets
148  // relevant nodes needed internally
149  if (m_SteppingAction)
150  {
152  }
153  return 0;
154 }
155 
157 {
158  set_default_double_param("ThicknessZ", 35.);
159  set_default_double_param("RIn", 20.);
160  set_default_double_param("ROut", 200.);
161  set_default_double_param("PosZ", 30.);
162  set_default_double_param("det_RIn", 20.);
163  set_default_double_param("det_ROut", 200.);
164  set_default_int_param("use_g4steps", 1);
165 
166  // place holder, will be replaced by world material if not set by other means (macro)
167  set_default_string_param("material", "G4_AIR");
168 }
169 
171 {
172  return m_Detector;
173 }
174 
175 void PHG4TRDSubsystem::Print(const string &what) const
176 {
177  cout << Name() << " Parameters: " << endl;
178  if (!BeginRunExecuted())
179  {
180  cout << "Need to execute BeginRun() before parameter printout is meaningful" << endl;
181  cout << "To do so either run one or more events or on the command line execute: " << endl;
182  cout << "Fun4AllServer *se = Fun4AllServer::instance();" << endl;
183  cout << "PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");" << endl;
184  cout << "g4->InitRun(se->topNode());" << endl;
185  cout << "PHG4TRDSubsystem *trd = (PHG4TRDSubsystem *) g4->getSubsystem(\"" << Name() << "\");" << endl;
186  cout << "trd->Print()" << endl;
187  return;
188  }
189  GetParams()->Print();
190  if (m_SteppingAction)
191  {
192  m_SteppingAction->Print(what);
193  }
194  return;
195 }