EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4ECAPToFSubsystem.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4ECAPToFSubsystem.cc
1 #include "PHG4ECAPToFSubsystem.h"
2 #include "PHG4ECAPToFDetector.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 <cmath> // for NAN
21 #include <iostream> // for operator<<, basic_ostream, std::endl
22 #include <sstream>
23 
24 class PHG4Detector;
25 class PHG4SteppingAction;
26 
27 PHG4ECAPToFSubsystem::PHG4ECAPToFSubsystem(const std::string &na, const int lyr)
28  : PHG4DetectorSubsystem(na, lyr)
29  , m_Detector(nullptr)
30  , m_SteppingAction(nullptr)
31 {
33 }
34 
36 {
37 }
38 
39 //_______________________________________________________________________
41 {
42  PHNodeIterator iter(topNode);
43  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
44  // create detector
45  m_Detector = new PHG4ECAPToFDetector(this, topNode, GetParams(), Name(), GetLayer());
48  /*
49  string nodename;
50  nodename = "G4HIT_" + SuperDetector();
51  string nodes;
52 
53  if (GetParams()->get_int_param("active"))
54  {
55  PHG4HitContainer *ECAPToF_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename);
56 
57  if (!ECAPToF_hits)
58  {
59  //dstNode->addNode(new PHIODataNode<PHObject>(ECAPToF_hits = new PHG4HitContainer(nodename), nodename, "PHObject"));
60  ECAPToF_hits = new PHG4HitContainer(nodename);
61  PHIODataNode<PHObject>* hitNode = new PHIODataNode<PHObject>(ECAPToF_hits, nodename, "PHObject");
62  dstNode->addNode(hitNode);
63  // nodes.insert(nodename);
64  }
65  */
66 
67  std::set<std::string> nodes;
68  if (GetParams()->get_int_param("active"))
69  {
70  PHNodeIterator dstIter(dstNode);
71  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstIter.findFirst("PHCompositeNode", SuperDetector()));
72  if (!DetNode)
73  {
74  DetNode = new PHCompositeNode(SuperDetector());
75  dstNode->addNode(DetNode);
76  }
77 
78  std::ostringstream nodename;
79  if (SuperDetector() != "NONE")
80  {
81  nodename << "G4HIT_" << SuperDetector();
82  }
83  else
84  {
85  nodename << "G4HIT_" << Name();
86  }
87  nodes.insert(nodename.str());
88  if (GetParams()->get_int_param("absorberactive"))
89  {
90  nodename.str("");
91  if (SuperDetector() != "NONE")
92  {
93  nodename << "G4HIT_ACTIVEGAS_" << SuperDetector();
94  }
95  else
96  {
97  nodename << "G4HIT_ACTIVEGAS_" << Name();
98  }
99  nodes.insert(nodename.str());
100  }
101 
102  for (std::string node : nodes)
103  {
104  PHG4HitContainer *g4_hits = findNode::getClass<PHG4HitContainer>(topNode, node.c_str());
105  if (!g4_hits)
106  {
107  g4_hits = new PHG4HitContainer(node);
108  DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, node.c_str(), "PHObject"));
109  }
110  }
111  //Stepping action
112  /*
113  auto *tmp = new PHG4ECAPToFSteppingAction(this, m_Detector, GetParams());
114  tmp->HitNodeName(nodename);
115  m_SteppingAction = tmp;
116  }
117  else if (GetParams()->get_int_param("blackhole"))
118  {
119  m_SteppingAction = new PHG4ECAPToFSteppingAction(this, m_Detector, GetParams());
120  }
121 
122  if (m_SteppingAction)
123  {
124  (dynamic_cast<PHG4ECAPToFSteppingAction *>(m_SteppingAction))->SaveAllHits(m_SaveAllHitsFlag);
125  }
126  */
128  }
129  else
130  {
131  // if this is a black hole it does not have to be active
132  if (GetParams()->get_int_param("blackhole"))
133  {
135  }
136  }
137 
138  return 0;
139 }
140 
142 {
143  // pass top node to stepping action so that it gets
144  // relevant nodes needed internally
145  if (m_SteppingAction)
146  {
148  }
149  return 0;
150 }
151 
153 {
154  set_default_int_param("n_fgas_layer", 6);
155  set_default_int_param("n_bgas_layer", 6);
156  set_default_double_param("gas_gap", 0.04);
157  set_default_double_param("glass_thick", 0.022);
158  set_default_double_param("Carbon_thick", 0.01);
159  set_default_double_param("pcb_thick", 0.04);
160  set_default_double_param("cu_thick", 0.01);
161  set_default_double_param("honeycomb_thick", 0.075);
162  set_default_double_param("mylar_thick", 0.01);
163  set_default_double_param("Rin", 5.);
164  set_default_double_param("Rout", 168.0);
165  set_default_double_param("z_begin", 72.0);
166  set_default_int_param("use_g4steps", 1);
167 
168  // place holder, will be replaced by world material if not set by other means (macro)
169  set_default_string_param("material", "G4_AIR");
170 }
171 
173 {
174  return m_Detector;
175 }
176 
177 void PHG4ECAPToFSubsystem::Print(const std::string &what) const
178 {
179  std::cout << Name() << " Parameters: " << std::endl;
180  if (!BeginRunExecuted())
181  {
182  std::cout << "Need to execute BeginRun() before parameter printout is meaningful" << std::endl;
183  std::cout << "To do so either run one or more events or on the command line execute: " << std::endl;
184  std::cout << "Fun4AllServer *se = Fun4AllServer::instance();" << std::endl;
185  std::cout << "PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");" << std::endl;
186  std::cout << "g4->InitRun(se->topNode());" << std::endl;
187  std::cout << "PHG4ECAPToFSubsystem *trd = (PHG4ECAPToFSubsystem *) g4->getSubsystem(\"" << Name() << "\");" << std::endl;
188  std::cout << "trd->Print()" << std::endl;
189  return;
190  }
191  GetParams()->Print();
192  if (m_SteppingAction)
193  {
194  m_SteppingAction->Print(what);
195  }
196  return;
197 }