EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4ForwardHcalSubsystem.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4ForwardHcalSubsystem.cc
2 
6 
7 #include <phparameter/PHParameters.h>
8 
9 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
11 #include <g4main/PHG4SteppingAction.h> // for PHG4SteppingAction
12 #include <g4main/PHG4Subsystem.h> // for PHG4Subsystem
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 
22 #include <TSystem.h>
23 
24 #include <set> // for set
25 #include <sstream>
26 
27 class PHG4Detector;
28 
29 //_______________________________________________________________________
30 PHG4ForwardHcalSubsystem::PHG4ForwardHcalSubsystem(const std::string& name, const int lyr)
31  : PHG4DetectorSubsystem(name, lyr)
32 {
34 }
35 
36 //_______________________________________________________________________
38 {
39  delete m_DisplayAction;
40 }
41 
42 //_______________________________________________________________________
44 {
45  PHNodeIterator iter(topNode);
46  PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
47 
48  // create display settings before detector
50  // create detector
51  m_Detector = new PHG4ForwardHcalDetector(this, topNode, GetParams(), Name());
55 
56  std::set<std::string> nodes;
57  if (GetParams()->get_int_param("active"))
58  {
59  PHNodeIterator dstIter(dstNode);
60  PHCompositeNode* DetNode = dstNode;
61  if (SuperDetector() != "NONE")
62  {
63  DetNode = dynamic_cast<PHCompositeNode*>(dstIter.findFirst("PHCompositeNode", SuperDetector()));
64  if (!DetNode)
65  {
66  DetNode = new PHCompositeNode(SuperDetector());
67  dstNode->addNode(DetNode);
68  }
69  }
70  // create hit output nodes
71  std::string detector_suffix = SuperDetector();
72  if (detector_suffix == "NONE")
73  {
74  detector_suffix = Name();
75  }
76  m_HitNodeName = "G4HIT_" + detector_suffix;
77  nodes.insert(m_HitNodeName);
78  m_AbsorberNodeName = "G4HIT_ABSORBER_" + detector_suffix;
79  if (GetParams()->get_int_param("absorberactive"))
80  {
81  nodes.insert(m_AbsorberNodeName);
82  }
83  m_SupportNodeName = "G4HIT_SUPPORT_" + detector_suffix;
84  if (GetParams()->get_int_param("supportactive"))
85  {
86  nodes.insert(m_SupportNodeName);
87  }
88  for (auto thisnode : nodes)
89  {
90  PHG4HitContainer* g4_hits = findNode::getClass<PHG4HitContainer>(topNode, thisnode);
91  if (!g4_hits)
92  {
93  g4_hits = new PHG4HitContainer(thisnode);
94  DetNode->addNode(new PHIODataNode<PHObject>(g4_hits, thisnode, "PHObject"));
95  }
96  }
97  // create stepping action
102  m_SteppingAction = tmp;
103  }
104 
105  return 0;
106 }
107 
108 //_______________________________________________________________________
110 {
111  // pass top node to stepping action so that it gets
112  // relevant nodes needed internally
113  if (m_SteppingAction)
114  {
116  }
117  return 0;
118 }
119 
120 //_______________________________________________________________________
122 {
123  return m_Detector;
124 }
125 
127 {
128  set_default_double_param("place_x", 0.);
129  set_default_double_param("place_y", 0.);
130  set_default_double_param("place_z", 400.);
131  set_default_double_param("tower_dx", 10.);
132  set_default_double_param("tower_dy", 10.);
133  set_default_double_param("tower_dz", 100.);
134  set_default_double_param("dz", 100.);
135  set_default_double_param("rMin1", 5.);
136  set_default_double_param("rMax1", 262.);
137  set_default_double_param("rMin2", 5.);
138  set_default_double_param("rMax2", 336.9);
139  set_default_double_param("wls_dw", 0.3);
140  set_default_double_param("support_dw", 0.2);
141  set_default_double_param("rot_x", 0.);
142  set_default_double_param("rot_y", 0.);
143  set_default_double_param("rot_z", 0.);
144  set_default_double_param("xoffset", 0.);
145  set_default_double_param("yoffset", 0.);
146  set_default_double_param("thickness_absorber", 2.);
147  set_default_double_param("thickness_scintillator", 0.231);
148  set_default_int_param("absorber_FeTungsten", 0);
149 
150  std::ostringstream mappingfilename;
151  const char* calibroot = getenv("CALIBRATIONROOT");
152  if (calibroot)
153  {
154  mappingfilename << calibroot;
155  }
156  else
157  {
158  std::cout << "no CALIBRATIONROOT environment variable" << std::endl;
159  gSystem->Exit(1);
160  }
161 
162  mappingfilename << "/ForwardHcal/mapping/towerMap_FHCAL_v005.txt";
163  set_default_string_param("mapping_file", mappingfilename.str());
164  set_default_string_param("mapping_file_md5", PHG4Utils::md5sum(mappingfilename.str()));
165  set_default_string_param("scintillator", "G4_POLYSTYRENE");
166  set_default_string_param("absorber", "G4_Fe");
167  set_default_string_param("support", "G4_Fe");
168 
169  return;
170 }
171 
173 {
174  set_string_param("mapping_file", filename);
175  set_string_param("mapping_file_md5", PHG4Utils::md5sum(get_string_param("mapping_file")));
176 }
177 
178 void PHG4ForwardHcalSubsystem::Print(const std::string& what) const
179 {
180  std::cout << Name() << " Parameters: " << std::endl;
181  if (!BeginRunExecuted())
182  {
183  std::cout << "Need to execute BeginRun() before parameter printout is meaningful" << std::endl;
184  std::cout << "To do so either run one or more events or on the command line execute: " << std::endl;
185  std::cout << "Fun4AllServer *se = Fun4AllServer::instance();" << std::endl;
186  std::cout << "PHG4Reco *g4 = (PHG4Reco *) se->getSubsysReco(\"PHG4RECO\");" << std::endl;
187  std::cout << "g4->InitRun(se->topNode());" << std::endl;
188  std::cout << "PHG4ForwardHcalSubsystem *fhcal = (PHG4ForwardHcalSubsystem *) g4->getSubsystem(\"" << Name() << "\");" << std::endl;
189  std::cout << "fhcal->Print()" << std::endl;
190  return;
191  }
192  GetParams()->Print();
193  if (m_SteppingAction)
194  {
195  m_SteppingAction->Print(what);
196  }
197  return;
198 }