Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PHG4SquareTubeDetector.cc
Go to the documentation of this file.
2 
3 #include <phparameter/PHParameters.h>
4 
5 #include <g4main/PHG4Utils.h>
6 
7 
9 #include <phool/PHIODataNode.h>
10 #include <phool/getClass.h>
11 
12 #include <Geant4/G4Box.hh>
13 #include <Geant4/G4Tubs.hh>
14 #include <Geant4/G4SubtractionSolid.hh>
15 #include <Geant4/G4Colour.hh>
16 #include <Geant4/G4LogicalVolume.hh>
17 #include <Geant4/G4Material.hh>
18 #include <Geant4/G4PVPlacement.hh>
19 #include <Geant4/G4SystemOfUnits.hh>
20 #include <Geant4/G4UserLimits.hh>
21 #include <Geant4/G4VisAttributes.hh>
22 
23 #include <sstream>
24 
25 using namespace std;
26 
27 //_______________________________________________________________
28 PHG4SquareTubeDetector::PHG4SquareTubeDetector( PHCompositeNode *Node, PHParameters *parameters, const std::string &dnam, const int lyr):
29  PHG4Detector(Node, dnam),
30  params(parameters),
31  block_physi(nullptr),
32  layer(lyr)
33 {}
34 
35 //_______________________________________________________________
36 bool PHG4SquareTubeDetector::IsInBlock(G4VPhysicalVolume * volume) const
37 {
38  if (volume == block_physi)
39  {
40  return true;
41  }
42  return false;
43 }
44 
45 namespace {
46 G4VPhysicalVolume* PlaceHollowdBox(
47  G4LogicalVolume *mother,
48  G4UserLimits *g4userlimits,
49  bool overlapcheck,
50  const std::string& name,
51  G4Material *mat_inner,
52  double x_inner,
53  double y_inner,
54  double z_inner,
55  G4ThreeVector d_inner,
56  G4Material *mat_outer,
57  double x_outer,
58  double y_outer,
59  double z_outer,
60  G4ThreeVector d_outer
61  )
62  {
63  G4VPhysicalVolume* ret = nullptr;
64 
65  G4VSolid *all_solid = new G4Box((name+"_all").c_str(),
66  x_outer/2,
67  y_outer/2,
68  z_outer/2);
69 
70  G4VSolid *inner_solid = new G4Box((name+"_inner").c_str(),
71  x_inner/2,
72  y_inner/2,
73  z_inner/2+0.0001*cm);
74 
75  G4VSolid * outer_solid = new G4SubtractionSolid((name+"_outer").c_str(),
76  all_solid,
77  inner_solid,
78  0,
79  d_inner - d_outer
80  );
81 
82  G4VisAttributes *vis_outer = new G4VisAttributes();
83  PHG4Utils::SetColour(vis_outer, mat_outer->GetName());
84  vis_outer->SetVisibility(true);
85  vis_outer->SetForceSolid(true);
86 
87  G4LogicalVolume *outer_logic = new G4LogicalVolume(outer_solid,
88  mat_outer,
89  (name+"_outer").c_str(),
90  nullptr, nullptr, g4userlimits);
91 
92  outer_logic->SetVisAttributes(vis_outer);
93 
94  ret = new G4PVPlacement(
95  0,
96  d_outer,
97  outer_logic,
98  (name+"_outer").c_str(),
99  mother, 0, false, overlapcheck);
100 
101  return ret;
102  }
103 
104 G4VPhysicalVolume* PlaceCircleHollowdBox(
105  G4LogicalVolume *mother,
106  G4UserLimits *g4userlimits,
107  bool overlapcheck,
108  const std::string& name,
109  G4Material *mat_inner,
110  double diam_inner,
111  double z_inner,
112  G4ThreeVector d_inner,
113  G4Material *mat_outer,
114  double x_outer,
115  double y_outer,
116  double z_outer,
117  G4ThreeVector d_outer
118  )
119  {
120  G4VPhysicalVolume* ret = nullptr;
121 
122  G4VSolid *all_solid = new G4Box((name+"_all").c_str(),
123  x_outer/2,
124  y_outer/2,
125  z_outer/2);
126 
127  G4VSolid *inner_solid = new G4Tubs((name+"inner").c_str(),
128  0, diam_inner/2., z_inner/2.+0.0001*cm,
129  -0.0001*CLHEP::twopi, CLHEP::twopi);
130 
131  G4VSolid * outer_solid = new G4SubtractionSolid((name+"_outer").c_str(),
132  all_solid,
133  inner_solid,
134  0,
135  d_inner - d_outer
136  );
137 
138  G4VisAttributes *vis_outer = new G4VisAttributes();
139  PHG4Utils::SetColour(vis_outer, mat_outer->GetName());
140  vis_outer->SetVisibility(true);
141  vis_outer->SetForceSolid(true);
142 
143  G4LogicalVolume *outer_logic = new G4LogicalVolume(outer_solid,
144  mat_outer,
145  (name+"_outer").c_str(),
146  nullptr, nullptr, g4userlimits);
147 
148  outer_logic->SetVisAttributes(vis_outer);
149 
150  ret = new G4PVPlacement(
151  0,
152  d_outer,
153  outer_logic,
154  (name+"_outer").c_str(),
155  mother, 0, false, overlapcheck);
156 
157  return ret;
158  }
159 }
160 //_______________________________________________________________
161 void PHG4SquareTubeDetector::Construct( G4LogicalVolume* logicWorld )
162 {
163  double place_x = params->get_double_param("place_x")*cm;
164  double place_y = params->get_double_param("place_y")*cm;
165  double place_z = params->get_double_param("place_z")*cm;
166 
167  double inner_place_x = params->get_double_param("inner_place_x")*cm;
168  double inner_place_y = params->get_double_param("inner_place_y")*cm;
169 
170  double size_x = params->get_double_param("size_x")*cm;
171  double size_y = params->get_double_param("size_y")*cm;
172  double size_z = params->get_double_param("size_z")*cm;
173  double inner_size_x = params->get_double_param("inner_size_x")*cm;
174  double inner_size_y = params->get_double_param("inner_size_y")*cm;
175 
176  double steplimits = params->get_double_param("steplimits") * cm;
177 
178  G4UserLimits *g4userlimits = nullptr;
179  if (isfinite(steplimits))
180  {
181  g4userlimits = new G4UserLimits(steplimits);
182  }
183 
184  if(params->get_string_param("hole_type")=="rectangular") {
185  block_physi = PlaceHollowdBox(
186  logicWorld,
187  g4userlimits,
188  overlapcheck,
189  GetName(),
190 
191  0,
192  inner_size_x, inner_size_y, size_z,
193  G4ThreeVector(place_x+inner_place_x,place_y+inner_place_y,place_z),
194 
195  G4Material::GetMaterial(params->get_string_param("material")),
196  size_x, size_y, size_z,
197  G4ThreeVector(place_x, place_y, place_z)
198  );
199  }
200 
201  if(params->get_string_param("hole_type")=="circle") {
202  block_physi = PlaceCircleHollowdBox(
203  logicWorld,
204  g4userlimits,
205  overlapcheck,
206  GetName(),
207 
208  0,
209  params->get_double_param("inner_diameter")*cm, size_z,
210  G4ThreeVector(place_x+inner_place_x,place_y+inner_place_y,place_z),
211 
212  G4Material::GetMaterial(params->get_string_param("material")),
213  size_x, size_y, size_z,
214  G4ThreeVector(place_x, place_y, place_z)
215  );
216  }
217 }
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
double get_double_param(const std::string &name) const
std::string get_string_param(const std::string &name) const
virtual void Construct(G4LogicalVolume *world)
construct
static void SetColour(G4VisAttributes *att, const std::string &mat)
Definition: PHG4Utils.cc:75
bool IsInBlock(G4VPhysicalVolume *) const
base class for phenix detector creation
Definition: PHG4Detector.h:13
const double twopi
virtual std::string GetName() const
Definition: PHG4Detector.h:51
PHG4SquareTubeDetector(PHCompositeNode *Node, PHParameters *parameters, const std::string &dnam="BLOCK", const int lyr=0)
constructor