EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eASTBeamPipe.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file eASTBeamPipe.cc
1 // ********************************************************************
2 //
3 // eASTBeamPipe.cc
4 // eAST Beam pipe component
5 //
6 // History
7 // May 8th, 2021 : first implementation
8 //
9 // ********************************************************************
10 
11 #include "eASTBeamPipe.hh"
12 
13 #include "G4VPhysicalVolume.hh"
14 #include "G4PVPlacement.hh"
15 #include "G4Transform3D.hh"
16 #include "G4LogicalVolume.hh"
17 #include "G4VSolid.hh"
18 #include "G4Region.hh"
19 #include "G4RegionStore.hh"
20 #include "G4GDMLParser.hh"
21 #include "G4GenericMessenger.hh"
22 #include "G4VisAttributes.hh"
23 #include "G4Version.hh"
24 #include "eASTRegionInformation.hh"
25 
26 eASTBeamPipe::eASTBeamPipe(G4String compName, G4int vl, const G4bool validate_gdml)
27  : eASTVDetectorComponent(compName,vl), m_validate_gdml (validate_gdml)
28 {;}
29 
31 {
32  if(messenger!=nullptr)
33  {
34  delete messenger;
35  messenger = nullptr;
36  }
37 }
38 
40 {
41  messenger = new G4GenericMessenger(this,commandDir,"Commands for Beampipe component");
42  auto envCmd = messenger->DeclareMethod("envelopeGdmlFile",&eASTBeamPipe::SetEnvGDML,
43  "Define the input envelope GDML file");
44  envCmd.SetToBeBroadcasted(false);
45  envCmd.SetStates(G4State_PreInit);
46  auto gdmlCmd = messenger->DeclareMethod("gdmlFile",&eASTBeamPipe::SetGDML,
47  "Define the input GDML file");
48  gdmlCmd.SetToBeBroadcasted(false);
49  gdmlCmd.SetStates(G4State_PreInit);
50  auto matCmd = messenger->DeclareMethod("materialFile",&eASTBeamPipe::SetMatFile,
51  "Define material definition file");
52  matCmd.SetToBeBroadcasted(false);
53  matCmd.SetStates(G4State_PreInit);
54 }
55 
56 void eASTBeamPipe::Construct(G4VPhysicalVolume* worldPhys)
57 {
58  if(gdmlFileName == "*NOTDEFINED*")
59  {
60  G4Exception("eASTBeamPipe::Construct","eASTBeamPipe000",
61  FatalException,"GDML file is not specified.");
62  }
63 
65 #if G4VERSION_NUMBER > 1100
66  // Taking care of potential volume-name duplication
67  parser.SetStripFlag(false);
68  parser.SetReverseSearch(true);
69 #endif
70  G4LogicalVolume* envelopeLog = nullptr;
71 
72  if(envGdmlFileName == "*NOTDEFINED*")
73  {
74  // Local world volume of the input GDML file is used as the envelope
76  auto tempWorld = parser.GetWorldVolume();
77  envelopeLog = tempWorld->GetLogicalVolume();
78  delete tempWorld;
79  }
80  else
81  {
82  // Envelope is read from a separate GDML file
84  auto tempWorld = parser.GetWorldVolume();
85  auto tempWorldLog = tempWorld->GetLogicalVolume();
86  auto tempWorldSolid = tempWorldLog->GetSolid();
87 
88  if(tempWorldLog->GetNoDaughters()>1)
89  {
90  G4ExceptionDescription ed;
91  ed << "Envelope GDML file <" << envGdmlFileName << "> has more than one volumes.\n"
92  << "We cannot use it as an envelope";
93  G4Exception("eASTBeamPipe::Construct","eASTBeamPipe001",FatalException,ed);
94  }
95 
96  auto envPhys = tempWorldLog->GetDaughter(0);
97  envelopeLog = envPhys->GetLogicalVolume();
98  delete envPhys;
99  delete tempWorld;
100  delete tempWorldLog;
101  delete tempWorldSolid;
102  parser.Clear();
103 
104  // Now we read the beampipe contents
106  auto tempEnv = parser.GetWorldVolume();
107  auto tempEnvLog = tempEnv->GetLogicalVolume();
108  auto tempEnvSolid = tempEnvLog->GetSolid();
109  G4int ndaughter = G4int(tempEnvLog->GetNoDaughters());
110  for(G4int idaughter=0;idaughter<ndaughter;idaughter++)
111  {
112  auto daughter = tempEnvLog->GetDaughter(idaughter);
113  if(daughter->GetName().find("Vacuumvolume")!=std::string::npos)
114  {
115  // skip vacuum volume
116  delete daughter->GetLogicalVolume()->GetSolid();
117  delete daughter->GetLogicalVolume();
118  delete daughter;
119  continue;
120  }
121  if(daughter->GetName().find("beryllium")!=std::string::npos)
122  {
123  // paint beryllium pipe red.
124  auto visBery = new G4VisAttributes(G4Colour(1.0,0.0,0.0));
125  daughter->GetLogicalVolume()->SetVisAttributes(visBery);
126  }
127  daughter->SetMotherLogical(envelopeLog);
128  envelopeLog->AddDaughter(daughter);
129  }
130  delete tempEnv;
131  delete tempEnvLog;
132  delete tempEnvSolid;
133  }
134 
135  envelopeLog->SetName(componentName+"_log");
136  auto visAtt = new G4VisAttributes(G4Colour(0.5,0.0,0.0));
137  visAtt->SetVisibility(false);
138  //visAtt->SetForceWireframe();
139  envelopeLog->SetVisAttributes(visAtt);
140  envelopeLog->GetSolid()->SetName(componentName+"_solid");
141 
142  pRegion = G4RegionStore::GetInstance()->FindOrCreateRegion(componentName+"_reg");
143  envelopeLog->SetRegion(pRegion);
144  pRegion->AddRootLogicalVolume(envelopeLog);
145 
146  auto regInfo = new eASTRegionInformation(componentName+"_regInfo");
147  regInfo->SetBeamPipe();
148  pRegion->SetUserInformation(regInfo);
149 
150  Locate(envelopeLog,worldPhys);
151 
152  if(materialToBeSet)
154 }
155 
156