EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eASTVDetectorComponent.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file eASTVDetectorComponent.cc
1 // ********************************************************************
2 //
3 // eASTVDetectorComponent.cc
4 // the abstract base class of eAST detector component
5 //
6 // History
7 // May 8th, 2021 : first implementation
8 //
9 // ********************************************************************
10 
12 #include "G4VPhysicalVolume.hh"
13 #include "G4PVPlacement.hh"
14 #include "G4Region.hh"
18 #include "G4UImanager.hh"
19 #include "G4Tokenizer.hh"
20 #include "G4Version.hh"
21 #include <fstream>
22 
24 : componentName(compName), verboseLevel(vl)
25 {
26  baseMessenger = new eASTDetectorComponentMessenger(this,compName);
27  commandDir = "/eAST/component/" + compName + "/";
29 }
30 
32 { delete baseMessenger; }
33 
35 {
36  verboseLevel = vl;
38  SetUp();
40 }
41 
42 void eASTVDetectorComponent::Locate(G4LogicalVolume* compLogVol,
43  G4VPhysicalVolume* worldPhys)
44 {
45  pEnvelopePhys = new G4PVPlacement(G4Transform3D(fRotation,fPosition),compLogVol,
46  componentName+"_phys",worldPhys->GetLogicalVolume(),0,0,0);
47 }
48 
49 G4String eASTVDetectorComponent::LocateDataFile( const G4String fn ) const
50 {
51  if ( verboseLevel > 0 ) G4cout << "LocateDataFile: Searching for " << fn
52  << " in " << G4UImanager::GetUIpointer()->GetMacroSearchPath()
53  << G4endl;
54 
55  if(fn == "*NOTDEFINED*"){
56  // Do nothing, let implementations decide
57  if ( verboseLevel > 0 ) G4cout << "LocateDataFile: Returning " << fn << G4endl;
58  return fn;
59  }
60 
61  auto UImanager = G4UImanager::GetUIpointer();
62  auto ret = UImanager->FindMacroPath(fn);
63  if ( verboseLevel > 0 ) G4cout << "LocateDataFile: Returning " << ret << G4endl;
64  return ret;
65 }
66 
68 {
69  enum { BUFSIZE = 128 };
70  char line[BUFSIZE];
71  std::ifstream matFile;
72  matFile.open(fileName,std::ios::in);
73  if(matFile.fail())
74  {
75  G4ExceptionDescription ed;
76  ed << "Material definition file <" << fileName << "> couldn't be opened.";
77  G4Exception("eASTBeamPipe::Construct","eASTBeamPipe001",
78  JustWarning,ed);
79  }
80  else
81  {
82  if(verboseLevel>0)
83  { G4cout << "Reading material definition file <" << fileName << ">..." << G4endl;}
84  while(!(matFile.eof()))
85  {
86  matFile.getline(line,BUFSIZE);
87  if(line[0]=='#') continue;
88  G4Tokenizer next(line);
89  G4String logVolName = next();
90  G4String matName = next();
91 #if G4VERSION_NUMBER < 1100
92  if(logVolName.isNull() || matName.isNull()) continue;
93 #else
94  if(logVolName.empty() || matName.empty()) continue;
95 #endif
96  G4String cmd = "/eAST/material/create " + matName;
97  G4UImanager::GetUIpointer()->ApplyCommand(cmd);
98  cmd = "/eAST/material/set " + logVolName + " " + matName;
99  G4UImanager::GetUIpointer()->ApplyCommand(cmd);
100  }
101  }
102  matFile.close();
103 }
104 
107 
110 
111 void eASTVDetectorComponent::RegisterUserAction(G4UserStackingAction* ua)
113 
114 void eASTVDetectorComponent::RegisterUserAction(G4UserTrackingAction* ua)
116 
117 void eASTVDetectorComponent::RegisterUserAction(G4UserSteppingAction* ua)
118 { if(CheckRegion()) pRegion->SetRegionalSteppingAction(ua); }
119 
121 {
122  if(pRegion==nullptr)
123  {
124  G4ExceptionDescription ed;
125  ed << "Component <" << componentName << "> does not have a valid G4Region pointer.";
126  G4Exception("eASTVDetectorComponent::RegisterUserAction()","eASTComp0001",
127  FatalException,ed);
128  return false;
129  }
130  return true;
131 }
132 
133