Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4MvtxSubsystem.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4MvtxSubsystem.cc
1 #include "PHG4MvtxSubsystem.h"
2 
3 #include "PHG4MvtxDefs.h"
4 #include "PHG4MvtxDetector.h"
7 
8 #include <mvtx/SegmentationAlpide.h> // for Alpide constants
9 
10 #include <phparameter/PHParameters.h>
11 #include <phparameter/PHParametersContainer.h>
12 
13 #include <g4detectors/PHG4DetectorGroupSubsystem.h> // for PHG4DetectorGrou...
14 
15 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
17 #include <g4main/PHG4SteppingAction.h> // for PHG4SteppingAction
18 
19 #include <phool/PHCompositeNode.h>
20 #include <phool/PHIODataNode.h> // for PHIODataNode
21 #include <phool/PHNode.h> // for PHNode
22 #include <phool/PHNodeIterator.h> // for PHNodeIterator
23 #include <phool/PHObject.h> // for PHObject
24 #include <phool/getClass.h>
25 #include <phool/phool.h> // for PHWHERE
26 
27 #include <cstdlib> // for getenv
28 #include <iostream> // for operator<<, basi...
29 #include <set> // for _Rb_tree_const_i...
30 #include <sstream>
31 #include <utility> // for pair
32 
33 class PHG4Detector;
34 
35 //_______________________________________________________________________
38  , n_layers(_n_layers)
39  , detector_type(name)
40 {
41  for (unsigned int iLyr = 0; iLyr < n_layers; ++iLyr)
42  {
43  AddDetId(iLyr);
44  }
45 
47 
48  // put the layers into name so we get unique names
49  // for multiple layers
50  Name(name);
51  SuperDetector(name);
52 }
53 
54 //_______________________________________________________________________
56 {
57  delete m_DisplayAction;
58 }
59 
60 //_______________________________________________________________________
62 {
63  if (Verbosity() > 0)
64  {
65  std::cout << "PHG4MvtxSubsystem::Init started" << std::endl;
66  }
67 
68  PHNodeIterator iter(topNode);
69  PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
70 
71  // create display settings before detector (detector adds its volumes to it)
73  // create detector
74  // These values are set from the calling macro using the setters defined in the .h file
75  if (Verbosity())
76  {
77  std::cout << " create Mvtx detector with " << n_layers << " layers." << std::endl;
78  }
79  m_Detector = new PHG4MvtxDetector(this, topNode, GetParamsContainer(), Name());
84  if (Verbosity())
85  {
86  std::cout << " ------ created detector " << Name() << std::endl;
88  }
89  // loop all layer to find atleast one active layer
90  int active = 0;
91  int supportactive = 0;
92  int blackhole = 0;
93  for (std::set<int>::const_iterator parContainerIter = GetDetIds().first; parContainerIter != GetDetIds().second; ++parContainerIter)
94  {
95  if (active || GetParamsContainer()->GetParameters(*parContainerIter)->get_int_param("active"))
96  {
97  active = 1;
98  }
99  if (supportactive || GetParamsContainer()->GetParameters(*parContainerIter)->get_int_param("supportactive"))
100  {
101  supportactive = 1;
102  }
103  if (blackhole || GetParamsContainer()->GetParameters(*parContainerIter)->get_int_param("blackhole"))
104  {
105  blackhole = 1;
106  }
107  }
108  if (active)
109  {
110  std::set<std::string> nodes;
111  PHNodeIterator dstIter(dstNode);
112  PHCompositeNode* detNode = dstNode;
113  if (SuperDetector() != "NONE" && !SuperDetector().empty())
114  {
115  detNode = dynamic_cast<PHCompositeNode*>(dstIter.findFirst("PHCompositeNode", SuperDetector()));
116  if (!detNode)
117  {
118  detNode = new PHCompositeNode(SuperDetector());
119  dstNode->addNode(detNode);
120  }
121  }
122 
123  std::string detector_suffix = SuperDetector();
124  if (detector_suffix == "NONE" || detector_suffix.empty())
125  {
126  detector_suffix = Name();
127  }
128 
129  m_HitNodeName = "G4HIT_" + detector_suffix;
130  nodes.insert(m_HitNodeName);
131  m_SupportNodeName = "G4HIT_SUPPORT_" + detector_suffix;
132  if (supportactive)
133  {
134  nodes.insert(m_SupportNodeName);
135  }
136  for (const auto& nodename : nodes)
137  {
138  PHG4HitContainer* g4_hits = findNode::getClass<PHG4HitContainer>(topNode, nodename);
139  if (!g4_hits)
140  {
141  g4_hits = new PHG4HitContainer(nodename);
142  if (Verbosity())
143  {
144  std::cout << PHWHERE << "creating hits node " << nodename << std::endl;
145  }
146  detNode->addNode(new PHIODataNode<PHObject>(g4_hits, nodename, "PHObject"));
147  }
148  }
149 
150  // create stepping action
155  }
156  else
157  {
158  if (blackhole)
159  {
161  }
162  }
163  return 0;
164 }
165 
166 //_______________________________________________________________________
168 {
169  // pass top node to stepping action so that it gets
170  // relevant nodes needed internally
171  if (m_SteppingAction)
172  {
174  }
175  return 0;
176 }
177 
178 //_______________________________________________________________________
180 {
181  return m_Detector;
182 }
183 
184 //_______________________________________________________________________
186 {
187  for (std::set<int>::const_iterator lyr_it = GetDetIds().first; lyr_it != GetDetIds().second; ++lyr_it)
188  {
189  const int& ilyr = *lyr_it;
190  const double rLr = PHG4MvtxDefs::mvtxdat[ilyr][PHG4MvtxDefs::kRmd];
192 
193  set_default_int_param(ilyr, "active", 1); // non-automatic initialization in PHG4DetectorGroupSubsystem
194  set_default_int_param(ilyr, "layer", ilyr);
196 
197  set_default_double_param(ilyr, "layer_nominal_radius", rLr);
198  set_default_double_param(ilyr, "phitilt", turbo);
200  set_default_string_param(ilyr, "material", "G4_AIR"); // default - almost nothing
201  }
202 
203  set_default_string_param(PHG4MvtxDefs::GLOBAL, "stave_geometry_file", "ITS.gdml"); // default - almost nothing
204  char* calibrationsroot = getenv("CALIBRATIONROOT");
205  std::string end_wheels_sideS = "ITS_ibEndWheelSideA.gdml";
206  std::string end_wheels_sideN = "ITS_ibEndWheelSideC.gdml";
207  if (calibrationsroot != nullptr)
208  {
209  end_wheels_sideS = std::string(calibrationsroot) + std::string("/Tracking/geometry/") + end_wheels_sideS;
210  end_wheels_sideN = std::string(calibrationsroot) + std::string("/Tracking/geometry/") + end_wheels_sideN;
211  }
212 }