EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4LBLVtxDetector.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4LBLVtxDetector.cc
1 #include "G4LBLVtxDetector.h"
2 
4 
5 #include <g4main/PHG4Detector.h> // for PHG4Detector
6 #include <g4main/PHG4Subsystem.h>
7 #include "g4main/PHG4DisplayAction.h" // for PHG4DisplayAction
8 
9 #include <phparameter/PHParameters.h>
10 
11 #include <TSystem.h>
12 
13 #include <Geant4/G4GDMLParser.hh>
14 #include <Geant4/G4GDMLReadStructure.hh> // for G4GDMLReadStructure
15 #include <Geant4/G4LogicalVolume.hh>
16 #include <Geant4/G4PVPlacement.hh>
17 #include <Geant4/G4RotationMatrix.hh> // for G4RotationMatrix
18 #include <Geant4/G4String.hh> // for G4String
19 #include <Geant4/G4SystemOfUnits.hh>
20 #include <Geant4/G4ThreeVector.hh> // for G4ThreeVector
21 #include <Geant4/G4VPhysicalVolume.hh> // for G4VPhysicalVolume
22 
23 #include <iostream> // for operator<<, basic_ostream
24 #include <memory>
25 
26 using namespace std;
27 
29  : PHG4Detector(subsys, Node, dnam)
30  , m_DisplayAction(dynamic_cast<G4LBLVtxDisplayAction*>(subsys->GetDisplayAction()))
31  , m_GDMPath(parameters->get_string_param("GDMPath"))
32  , m_TopVolName(parameters->get_string_param("TopVolName"))
33  , m_placeX(parameters->get_double_param("place_x") * cm)
34  , m_placeY(parameters->get_double_param("place_y") * cm)
35  , m_placeZ(parameters->get_double_param("place_z") * cm)
36  , m_rotationX(parameters->get_double_param("rot_x") * degree)
37  , m_rotationY(parameters->get_double_param("rot_y") * degree)
38  , m_rotationZ(parameters->get_double_param("rot_z") * degree)
39  , m_Active(parameters->get_int_param("active"))
40  , m_AbsorberActive(parameters->get_int_param("absorberactive"))
41 {
42  m_ActiveVolName.insert("TopFilament");
43  m_ActiveVolName.insert("CarbonFleeceBottom");
44 }
45 
47 {
48 }
49 
50 void G4LBLVtxDetector::Print(const std::string& what) const
51 {
52  cout << "G4LBLVtxDetector::" << GetName() << " - import " << m_TopVolName << " from " << m_GDMPath << " with shift "
53  << m_placeX << ","
54  << m_placeY << ","
55  << m_placeZ << "cm and rotation "
56  << m_rotationX << ","
57  << m_rotationY << ","
58  << m_rotationZ << "rad" << endl;
59 }
60 
61 void G4LBLVtxDetector::ConstructMe(G4LogicalVolume* logicWorld)
62 {
63  if (Verbosity() > 0)
64  {
65  cout << " G4LBLVtxDetector::Construct:";
66  Print();
67  }
68 
69  //===================================
70  // Import the stave physical volume here
71  //===================================
72 
73  // import the staves from the geometry file
74  unique_ptr<G4GDMLReadStructure> reader(new G4GDMLReadStructure());
75  G4GDMLParser gdmlParser(reader.get());
76  gdmlParser.SetOverlapCheck(OverlapCheck());
77  gdmlParser.Read(m_GDMPath, OverlapCheck());
78 
79  G4LogicalVolume* vol = reader->GetVolume(m_TopVolName);
80 
81  if (!vol)
82  {
83  cout << "G4LBLVtxDetector::Construct - Fatal Error - failed to find G4LogicalVolume " << m_TopVolName << " - Print: ";
84  Print();
85  gSystem->Exit(1);
86  }
87  PHG4Subsystem* mysys = GetMySubsystem();
88  mysys->SetLogicalVolume(vol);
89 
90  G4RotationMatrix* rotm = new G4RotationMatrix();
91  rotm->rotateX(m_rotationX);
92  rotm->rotateY(m_rotationY);
93  rotm->rotateZ(m_rotationZ);
94  G4ThreeVector placeVec(m_placeX, m_placeY, m_placeZ);
95 
96  G4VPhysicalVolume* phys = new G4PVPlacement(rotm, placeVec,
97  vol,
98  G4String(GetName().c_str()),
99  logicWorld, false, 0, OverlapCheck());
100  SetActiveVolumes(phys);
101 }
102 
103 void G4LBLVtxDetector::SetActiveVolumes(G4VPhysicalVolume* physvol)
104 {
105  G4LogicalVolume* logvol = physvol->GetLogicalVolume();
106  if (logvol->GetNoDaughters() == 0) // add only if no other volumes inside
107  {
108  m_DisplayAction->AddLogVolume(logvol);
109  string test(physvol->GetName());
110  int added_to_active = 0;
111  for (set<std::string>::const_iterator iter = m_ActiveVolName.begin();
112  iter != m_ActiveVolName.end(); ++iter)
113  {
114  // cout << "checking " << test << " for " << *iter << endl;
115  if (test.find(*iter) != string::npos)
116  {
117  // cout << "Adding " << physvol->GetName() << endl;
118  m_ActivePhysVolumeMap.insert(physvol);
119  added_to_active = 1;
120  }
121  }
122  if (!added_to_active)
123  {
124  m_PassivePhysVolumeMap.insert(physvol);
125  }
126  }
127  else
128  {
129  for (unsigned int i = 0; i < (unsigned int) logvol->GetNoDaughters(); ++i)
130  {
131  G4VPhysicalVolume* physvol = logvol->GetDaughter(i);
132  // here we decide which volumes are active
133  SetActiveVolumes(physvol);
134  }
135  }
136  return;
137 }
138 
139 int G4LBLVtxDetector::IsInDetector(G4VPhysicalVolume* physvol) const
140 {
141  if (m_Active)
142  {
143  if (m_ActivePhysVolumeMap.find(physvol) != m_ActivePhysVolumeMap.end())
144  {
145  return 1;
146  }
147  }
148  if (m_AbsorberActive)
149  {
150  if (m_PassivePhysVolumeMap.find(physvol) != m_PassivePhysVolumeMap.end())
151  {
152  return -1;
153  }
154  }
155  return 0;
156 }