ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BeastMagnetDetector.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BeastMagnetDetector.cc
1 #include "BeastMagnetDetector.h"
2 
4 
5 #include <phparameter/PHParameters.h>
6 
7 #include <g4main/PHG4Detector.h>
8 #include <g4main/PHG4Subsystem.h>
9 
10 #include <TSystem.h>
11 #include <Geant4/G4AssemblyVolume.hh>
12 #include <Geant4/G4Color.hh>
13 #include <Geant4/G4GDMLParser.hh>
14 #include <Geant4/G4GDMLReadStructure.hh> // for G4GDMLReadStructure
15 #include <Geant4/G4LogicalVolume.hh>
16 #include <Geant4/G4LogicalVolumeStore.hh>
17 #include <Geant4/G4Material.hh>
18 #include <Geant4/G4PVPlacement.hh>
19 #include <Geant4/G4SolidStore.hh>
20 #include <Geant4/G4SystemOfUnits.hh>
21 #include <Geant4/G4VisAttributes.hh>
22 
23 #include <cmath>
24 #include <iostream>
25 #include <memory>
26 
27 class G4VSolid;
28 class PHCompositeNode;
29 
30 using namespace std;
31 
32 //____________________________________________________________________________..
34  PHCompositeNode *Node,
36  const std::string &dnam)
37  : PHG4Detector(subsys, Node, dnam)
38  , m_DisplayAction(dynamic_cast<BeastMagnetDisplayAction *>(subsys->GetDisplayAction()))
39  , m_Params(parameters)
40  , m_GDMPath(parameters->get_string_param("GDMPath"))
41  , m_TopVolName(parameters->get_string_param("TopVolName"))
42  , m_AbsorberActive(parameters->get_int_param("absorberactive"))
43 {
44 }
45 
46 //_______________________________________________________________
48 {
49  set<G4VPhysicalVolume *>::const_iterator iter = m_PhysicalVolumesSet.find(volume);
50  if (iter != m_PhysicalVolumesSet.end())
51  {
52  return 1;
53  }
54  return 0;
55 }
56 
57 //_______________________________________________________________
59 {
60  unique_ptr<G4GDMLReadStructure> reader(new G4GDMLReadStructure());
61  G4GDMLParser gdmlParser(reader.get());
62  gdmlParser.SetOverlapCheck(OverlapCheck());
63  gdmlParser.Read(m_GDMPath, false);
64 
65  // alright the reader just puts everything into G4 Stores - endless fun
66  // print the show out, first solids:
67  // for (auto i=G4SolidStore::GetInstance()->begin(); i!=G4SolidStore::GetInstance()->end(); ++i)
68  // cout << "solid vol name: " << (*i)->GetName() << endl;
69  // for (auto i=G4LogicalVolumeStore::GetInstance()->begin(); i!=G4LogicalVolumeStore::GetInstance()->end(); i++)
70  // cout << "logvol name " << (*i)->GetName() << endl;
71 
72  G4AssemblyVolume *avol = reader->GetAssembly(m_TopVolName);
73  if (!avol)
74  {
75  cout << "not found" << endl;
76  }
77 
79  G4ThreeVector g4vec;
80  avol->MakeImprint(logicWorld, g4vec, Rot, 0, OverlapCheck());
81  vector<G4VPhysicalVolume *>::iterator it = avol->GetVolumesIterator();
82  for (unsigned int i = 0; i < avol->TotalImprintedVolumes(); i++)
83  {
84  InsertVolumes(*it);
85  ++it;
86  }
87 
88  return;
89 }
90 
92 {
93  G4LogicalVolume *logvol = physvol->GetLogicalVolume();
95  m_PhysicalVolumesSet.insert(physvol);
96  // G4 10.06 returns unsigned int for GetNoDaughters()
97  // lower version return int, need to cast to avoid compiler error
98  for (int i = 0; i < (int) logvol->GetNoDaughters(); ++i)
99  {
100  G4VPhysicalVolume *physvol = logvol->GetDaughter(i);
101  // here we decide which volumes are active
102  InsertVolumes(physvol);
103  }
104  return;
105 }
106 
107 //_______________________________________________________________
108 void BeastMagnetDetector::Print(const std::string &what) const
109 {
110  cout << "BeastMagnet Detector:" << endl;
111  if (what == "ALL" || what == "VOLUME")
112  {
113  cout << "Version 0.1" << endl;
114  cout << "Parameters:" << endl;
115  m_Params->Print();
116  }
117  return;
118 }