ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EICG4B0Detector.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EICG4B0Detector.cc
1 //____________________________________________________________________________..
2 //
3 // This is a working template for the G4 Construct() method which needs to be implemented
4 // We wedge a method between the G4 Construct() to enable volume hierarchies on the macro
5 // so here it is called ConstructMe() but there is no functional difference
6 // Currently this installs a simple G4Box solid, creates a logical volume from it
7 // and places it. Put your own detector in place (just make sure all active volumes
8 // get inserted into the m_PhysicalVolumesSet)
9 //
10 // Rather than using hardcoded values you should consider using the parameter class
11 // Parameter names and defaults are set in EICG4B0Subsystem::SetDefaultParameters()
12 // Only parameters defined there can be used (also to override in the macro)
13 // to avoids typos.
14 // IMPORTANT: parameters have no inherent units, there is a convention (cm/deg)
15 // but in any case you need to multiply them here with the correct CLHEP/G4 unit
16 //
17 // The place where you put your own detector is marked with
18 // //begin implement your own here://
19 // //end implement your own here://
20 // Do not forget to include the G4 includes for your volumes
21 //____________________________________________________________________________..
22 
23 #include "EICG4B0Detector.h"
24 //#include "EICG4B0SteppingAction.h"
25 //#include "EICG4B0Subsystem.h"
26 
27 #include <phparameter/PHParameters.h>
28 
29 #include <g4main/PHG4Detector.h>
30 #include <g4main/PHG4DisplayAction.h> // for PHG4DisplayAction
31 //#include <g4main/PHG4Subsystem.h>
32 
33 #include <TSystem.h>
34 #include <Geant4/G4Box.hh>
35 #include <Geant4/G4Color.hh>
36 #include <Geant4/G4LogicalVolume.hh>
37 #include <Geant4/G4Material.hh>
38 #include <Geant4/G4PVPlacement.hh>
39 #include <Geant4/G4RotationMatrix.hh>
40 #include <Geant4/G4SubtractionSolid.hh>
41 #include <Geant4/G4SystemOfUnits.hh>
42 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
43 #include <Geant4/G4Transform3D.hh> // for G4Transform3D
44 #include <Geant4/G4Tubs.hh>
45 #include <Geant4/G4Types.hh> // for G4double, G4int
46 #include <Geant4/G4UnionSolid.hh>
47 #include <Geant4/G4VPhysicalVolume.hh> // for G4VPhysicalVolume
48 #include <Geant4/G4VisAttributes.hh>
49 
50 #include <cmath>
51 #include <cstdlib>
52 #include <fstream>
53 #include <iostream>
54 #include <sstream>
55 #include <utility>
56 
57 class G4VSolid;
58 class PHCompositeNode;
59 
60 //____________________________________________________________________________..
62  PHCompositeNode *Node,
64  const std::string &dnam, const int lyr)
65  : PHG4Detector(subsys, Node, dnam)
66  , m_Params(parameters)
67  , m_Layer(lyr)
68 {
69 }
70 
71 //_______________________________________________________________
73 {
74  std::set<G4VPhysicalVolume *>::const_iterator iter = m_PhysicalVolumesSet.find(volume);
75  if (iter != m_PhysicalVolumesSet.end())
76  {
77  return 1;
78  }
79  return 0;
80 }
81 
83 {
84  if (IsInDetector(volume))
85  {
86  return 1;
87  }
88  return -1;
89 }
90 
91 //_______________________________________________________________
93 {
94  //begin implement your own here://
95  // Do not forget to multiply the parameters with their respective CLHEP/G4 unit !
96  if (Verbosity() > 0)
97  {
98  std::cout << "EICG4B0Detector: Begin Construction" << std::endl;
99  }
100 
101  std::cout << " !!! length = " << m_Params->get_double_param("length");
102  if (m_Params->get_double_param("spanningAngle") >= 360)
103  {
104  std::cout << " !!! No PACKMAN" << std::endl;
105  return;
106  }
107  //Print("ALL");
108 
109  G4VSolid *solid0 = new G4Tubs("EICG4B0Solid0",
110  0.,
111  m_Params->get_double_param("outer_radius") * cm,
112  m_Params->get_double_param("length") / 2. * cm,
113  m_Params->get_double_param("startAngle") * degree,
114  m_Params->get_double_param("spanningAngle") * degree);
115  G4VSolid *solidPipeHole = new G4Tubs("EICG4B0IonPipeSolid",
116  0.,
117  m_Params->get_double_param("pipe_hole_r") * cm,
118  m_Params->get_double_param("length") * cm,
119  0., 360. * degree);
120  G4VSolid *solidCableHole = new G4Tubs("EICG4B0CableSolid",
121  0.,
122  m_Params->get_double_param("cable_hole") * cm,
123  m_Params->get_double_param("length") * cm,
124  0., 360. * degree);
125  G4VSolid *solidPipeHole1 = new G4Box("EICG4B0PipeSolid1",
126  m_Params->get_double_param("pipe_hole") / 2. * cm,
127  m_Params->get_double_param("pipe_hole_r") * cm,
128  m_Params->get_double_param("length") * cm);
129  G4VSolid *solid1 = new G4Tubs("EICG4B0Solid1",
130  0.,
131  (m_Params->get_double_param("outer_radius") - m_Params->get_double_param("d_radius")) * cm,
132  m_Params->get_double_param("length") / 2. * cm,
133  (m_Params->get_double_param("startAngle") + m_Params->get_double_param("spanningAngle")) * degree,
134  (360 - m_Params->get_double_param("spanningAngle")) * degree);
135  G4UnionSolid *solid10 = new G4UnionSolid("EICG4B0Solid10", solid0, solid1);
136  //here we subtract two cilinders and one box from the detector volume to get an oval-shaped hole
137  G4SubtractionSolid *solids = new G4SubtractionSolid("EICG4B0Solid", solid10, solidPipeHole, 0, G4ThreeVector((m_Params->get_double_param("pipe_x") + m_Params->get_double_param("pipe_hole") / 2) * cm, m_Params->get_double_param("pipe_y") * cm, m_Params->get_double_param("pipe_z") * cm));
138  G4SubtractionSolid *solids1 = new G4SubtractionSolid("EICG4B0Solid", solids, solidPipeHole, 0, G4ThreeVector((m_Params->get_double_param("pipe_x") - m_Params->get_double_param("pipe_hole") / 2) * cm, m_Params->get_double_param("pipe_y") * cm, m_Params->get_double_param("pipe_z") * cm));
139  G4SubtractionSolid *solids2 = new G4SubtractionSolid("EICG4B0Solid", solids1, solidCableHole, 0, G4ThreeVector(m_Params->get_double_param("cable_x") * cm, m_Params->get_double_param("cable_y") * cm, m_Params->get_double_param("cable_z") * cm));
140  G4SubtractionSolid *solidB0 = new G4SubtractionSolid("EICG4B0Solid", solids2, solidPipeHole1, 0, G4ThreeVector(m_Params->get_double_param("pipe_x") * cm, m_Params->get_double_param("pipe_y") * cm, m_Params->get_double_param("pipe_z") * cm));
141  G4RotationMatrix *rotm = new G4RotationMatrix();
142  G4LogicalVolume *logical = new G4LogicalVolume(solidB0,
144  "EICG4B0Logical");
145 
146  G4VisAttributes *vis = new G4VisAttributes(G4Color(0.8, 0.4, 0.2, 1.0));
147  if (m_Params->get_string_param("material") == "G4_PbWO4") vis->SetColor(0.8, 0.4, 0.2, 1.0);
148  if (m_Params->get_string_param("material") == "G4_Cu") vis->SetColor(1., 0., 1., .5);
149  if (m_Params->get_string_param("material") == "G4_Si") vis->SetColor(1., 1., 0., .8);
150  vis->SetForceSolid(true);
151  logical->SetVisAttributes(vis);
152  rotm->rotateY(m_Params->get_double_param("rot_y") * deg);
153  // rotm->rotateY(0. * deg);
154 
155  G4VPhysicalVolume *phy = new G4PVPlacement(
156  rotm,
158  m_Params->get_double_param("place_y") * cm,
159  m_Params->get_double_param("place_z") * cm),
160  // G4ThreeVector(0. * cm,
161  // 0. * cm,
162  // 0. * cm),
163  logical, "EICG4B0", logicWorld, 0, false, OverlapCheck());
164  // add it to the list of placed volumes so the IsInDetector method
165  // picks them up
166  m_PhysicalVolumesSet.insert(phy);
167  // hard code detector id to detid
168  m_PhysicalVolumesDet.insert({phy, m_Params->get_double_param("detid") + 1});
169  // m_LogicalVolumesSet.insert(logical);
170  //end implement your own here://
171 
172  return;
173 }
174 //_______________________________________________________________
175 
176 //_______________________________________________________________
177 void EICG4B0Detector::Print(const std::string &what) const
178 {
179  std::cout << "EICG4B0 Detector:" << std::endl;
180  if (what == "ALL" || what == "VOLUME")
181  {
182  std::cout << "Version 0.1" << std::endl;
183  std::cout << "Parameters:" << std::endl;
184  m_Params->Print();
185  }
186  return;
187 }
188 
190 {
191  return m_Params;
192 }