EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eASTDetectorConstruction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file eASTDetectorConstruction.cc
1 // ********************************************************************
2 //
3 // eASTDetectorConstruction.cc
4 // eAST detector construction class.
5 // This class also takes care of several utility methods on geometry
6 //
7 // History
8 // September 8th, 2020 : first implementation
9 //
10 // ********************************************************************
11 
13 
16 #include "eASTMagneticField.hh"
17 
18 #include "G4RunManager.hh"
19 #include "G4VPhysicalVolume.hh"
20 #include "G4PVPlacement.hh"
21 #include "G4LogicalVolume.hh"
22 #include "G4Box.hh"
23 #include "G4NistManager.hh"
24 #include "G4Material.hh"
25 #include "G4VisAttributes.hh"
26 #include "G4Region.hh"
27 #include "G4RegionStore.hh"
28 #include "eASTRegionInformation.hh"
29 #include <algorithm>
30 
33 {
34  if(instance==nullptr)
36  return instance;
37 }
38 
40 {
41  if(instance!=nullptr)
42  {
43  G4Exception("eASTDetectorConstruction::eASTDetectorConstruction()",
44  "eAST01230", FatalException,
45  "eASTDetectorConstruction is constructed twice!!");
46  }
47  instance = this;
49 }
50 
52 {
53  for(auto comp : components)
54  { delete comp.second; }
55  components.clear();
56  delete messenger;
57  instance = nullptr;
58 }
59 
61  (G4String compName, eASTVDetectorComponent* comp)
62 {
63  components[compName] = comp;
64 }
65 
67 {
68  if(fWorld==nullptr)
69  {
70  if(components.empty())
71  {
72  G4Exception("eASTDetectorConstruction::Construct()",
73  "eAST01231", FatalException,
74  "No detector component is registered. Nothing to construct!!");
75  }
76 
77  auto worldBox = new G4Box("worldBox",50.*CLHEP::m,50.*CLHEP::m,150.*CLHEP::m);
78  auto air = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR");
79  auto worldLog = new G4LogicalVolume(worldBox,air,"worldLog");
80  auto visAtt = new G4VisAttributes(G4Colour(0.5,0.5,0.5));
81  //visAtt->SetVisibility(false);
82  visAtt->SetForceWireframe();
83  worldLog->SetVisAttributes(visAtt);
84  fWorld = new G4PVPlacement(0,G4ThreeVector(),worldLog,"worldPhys",0,0,0);
85 
86  auto worldDefRegion = G4RegionStore::GetInstance()
87  ->GetRegion("DefaultRegionForTheWorld");
88  auto worldDefRegionInfo = new eASTRegionInformation("world_RegInfo");
89  worldDefRegionInfo->SetExperimentalHall();
90  worldDefRegion->SetUserInformation(worldDefRegionInfo);
91 
92  for(auto comp : components)
93  {
94  G4cout << "##### Constructing " << comp.first << "........." << G4endl;
95  comp.second->Construct(fWorld);
96  }
97 
98  // now construct component-specific user run action for master thread
99  // this should be done after all components are constructed
100  for(auto comp : components)
101  {
102  comp.second->ConstructActionForMaster();
103  }
104  }
105 
106  return fWorld;
107 }
108 
109 #include "G4AutoLock.hh"
110 namespace
111 {
112  G4Mutex constructSDandFieldMutex = G4MUTEX_INITIALIZER;
113 }
114 
116 {
117  G4AutoLock l(&constructSDandFieldMutex);
118  for(auto comp : components)
119  {
120  comp.second->ConstructSD();
121  comp.second->ConstructActions();
122  }
123 
124  G4cout << "##### Activating magnetic field........." << G4endl;
125  if (fField) {
126  fField->Activate();
127  }
128 }
129 
130 #include "G4UnitsTable.hh"
131 #include "G4VSolid.hh"
132 #include "G4SolidStore.hh"
134 {
135  G4cout << "*********** List of registered solids *************" << G4endl;
136  auto store = G4SolidStore::GetInstance();
137  auto itr = store->begin();
138  for(;itr!=store->end();itr++)
139  {
140  switch(lvl)
141  {
142  case 0:
143  G4cout << (*itr)->GetName() << G4endl;
144  break;
145  case 1:
146  G4cout << (*itr)->GetName()
147  << "\t volume = " << G4BestUnit((*itr)->GetCubicVolume(),"Volume")
148  << "\t surface = " << G4BestUnit((*itr)->GetSurfaceArea(),"Surface")
149  << G4endl;
150  break;
151  default:
152  (*itr)->DumpInfo();
153  break;
154  }
155  }
156 }
157 
158 #include "G4LogicalVolume.hh"
159 #include "G4LogicalVolumeStore.hh"
160 #include "G4Material.hh"
161 #include "G4VSensitiveDetector.hh"
163 {
164  G4cout << "*********** List of registered logical volumes *************" << G4endl;
165  auto store = G4LogicalVolumeStore::GetInstance();
166  auto itr = store->begin();
167  for(;itr!=store->end();itr++)
168  {
169  G4cout << (*itr)->GetName() << "\t Solid = " << (*itr)->GetSolid()->GetName();
170  if((*itr)->GetMaterial())
171  { G4cout << "\t Material = " << (*itr)->GetMaterial()->GetName() << G4endl; }
172  else
173  { G4cout << "\t Material : not defined " << G4endl; }
174  if(lvl<1) continue;
175  G4cout << "\t region = ";
176  if((*itr)->GetRegion())
177  { G4cout << (*itr)->GetRegion()->GetName(); }
178  else
179  { G4cout << "not defined"; }
180  G4cout << "\t sensitive detector = ";
181  if((*itr)->GetSensitiveDetector())
182  { G4cout << (*itr)->GetSensitiveDetector()->GetName(); }
183  else
184  { G4cout << "not defined"; }
185  G4cout << G4endl;
186  G4cout << "\t daughters = " << (*itr)->GetNoDaughters();
187  if((*itr)->GetNoDaughters()>0)
188  {
189  switch((*itr)->CharacteriseDaughters())
190  {
191  case kNormal:
192  G4cout << " (placement)"; break;
193  case kReplica:
194  G4cout << " (replica : " << (*itr)->GetDaughter(0)->GetMultiplicity() << ")"; break;
195  case kParameterised:
196  G4cout << " (parameterized : " << (*itr)->GetDaughter(0)->GetMultiplicity() << ")"; break;
197  default:
198  ;
199  }
200  }
201  G4cout << G4endl;
202  if(lvl<2) continue;
203  if((*itr)->GetMaterial())
204  { G4cout << "\t weight = " << G4BestUnit((*itr)->GetMass(),"Mass") << G4endl; }
205  else
206  { G4cout << "\t weight : not available" << G4endl; }
207  }
208 }
209 
210 #include "G4VPhysicalVolume.hh"
211 #include "G4PhysicalVolumeStore.hh"
213 {
214  G4cout << "*********** List of registered physical volumes *************" << G4endl;
215  auto store = G4PhysicalVolumeStore::GetInstance();
216  auto itr = store->begin();
217  for(;itr!=store->end();itr++)
218  {
219  switch(lvl)
220  {
221  case 0:
222  G4cout << (*itr)->GetName() << G4endl;
223  break;
224  case 1:
225  G4cout << (*itr)->GetName()
226  << "\t logical volume = " << (*itr)->GetLogicalVolume()->GetName()
227  << "\t mother logical = ";
228  if((*itr)->GetMotherLogical())
229  { G4cout << (*itr)->GetMotherLogical()->GetName(); }
230  else
231  { G4cout << "not defined"; }
232  G4cout << G4endl;
233  break;
234  default:
235  G4cout << (*itr)->GetName()
236  << "\t logical volume = " << (*itr)->GetLogicalVolume()->GetName()
237  << "\t mother logical = ";
238  if((*itr)->GetMotherLogical())
239  { G4cout << (*itr)->GetMotherLogical()->GetName(); }
240  else
241  { G4cout << "not defined"; }
242  G4cout << "\t type = ";
243  switch((*itr)->VolumeType())
244  {
245  case kNormal:
246  G4cout << "placement"; break;
247  case kReplica:
248  G4cout << "replica"; break;
249  case kParameterised:
250  G4cout << "parameterized"; break;
251  default:
252  ;
253  }
254  G4cout << G4endl;
255  }
256  }
257 }
258 
259 G4bool eASTDetectorConstruction::CheckOverlap(G4String& physVolName, G4int nSpots,
260  G4int maxErr, G4double tol)
261 {
262  G4cout << "*********** Checking overlap for <" << physVolName << "> *************" << G4endl;
263  G4bool checkAll = (physVolName=="**ALL**");
264  auto store = G4PhysicalVolumeStore::GetInstance();
265  auto itr = store->begin();
266  G4VPhysicalVolume* physVol = nullptr;
267  for(;itr!=store->end();itr++)
268  {
269  if(checkAll || (*itr)->GetName()==physVolName)
270  {
271  physVol = (*itr);
272  physVol->CheckOverlaps(nSpots,tol,true,maxErr);
273  if(!checkAll) break;
274  }
275  }
276  return (physVol!=nullptr);
277 }
278 
279 #include "G4Region.hh"
280 #include "G4RegionStore.hh"
281 #include "G4RunManagerKernel.hh"
283 {
284  if(lvl==2)
285  {
286  G4RunManagerKernel::GetRunManagerKernel()->DumpRegion();
287  return;
288  }
289  G4cout << "*********** List of registered regions *************" << G4endl;
290  auto store = G4RegionStore::GetInstance();
291  auto itr = store->begin();
292  for(;itr!=store->end();itr++)
293  {
294  G4cout << (*itr)->GetName();
295  if((*itr)->GetWorldPhysical())
296  {
297  G4cout << "\t in the world volume <" << (*itr)->GetWorldPhysical()->GetName() << "> ";
298  if((*itr)->IsInMassGeometry()) G4cout << "-- mass world";
299  if((*itr)->IsInParallelGeometry()) G4cout << "-- parallel world";
300  }
301  else
302  { G4cout << " -- is not associated to any world."; }
303  G4cout << G4endl;
304  if(lvl==0) continue;
305  G4cout << "\t\t Root logical volume(s) : ";
306  size_t nRootLV = (*itr)->GetNumberOfRootVolumes();
307  std::vector<G4LogicalVolume*>::iterator lvItr = (*itr)->GetRootLogicalVolumeIterator();
308  for(size_t j=0;j<nRootLV;j++)
309  { G4cout << (*lvItr)->GetName() << " "; lvItr++; }
310  G4cout << G4endl;
311  G4cout << "\t\t Pointers : G4VUserRegionInformation[" << (*itr)->GetUserInformation()
312  << "], G4UserLimits[" << (*itr)->GetUserLimits()
313  << "], G4FastSimulationManager[" << (*itr)->GetFastSimulationManager()
314  << "], G4UserSteppingAction[" << (*itr)->GetRegionalSteppingAction() << "]" << G4endl;
315  }
316 }
317 
318 #include "G4MaterialTable.hh"
320 {
321  auto materialTable = G4Material::GetMaterialTable();
322  auto matItr = materialTable->begin();
323  G4cout << "*********** List of instantiated materials **************" << G4endl;
324  G4int i = 0;
325  for(;matItr!=materialTable->end();matItr++)
326  {
327  G4cout << (*matItr)->GetName() << "\t";
328  if(++i%5==0) G4cout << G4endl;
329  }
330  G4cout << G4endl;
331 }
332 
333 G4bool eASTDetectorConstruction::ListMaterial(G4String& matName)
334 {
335  auto materialTable = G4Material::GetMaterialTable();
336  auto matItr = materialTable->begin();
337  for(;matItr!=materialTable->end();matItr++)
338  {
339  if((*matItr)->GetName()==matName)
340  {
341  G4cout << *matItr << G4endl;
342  return true;
343  }
344  }
345  return false;
346 }
347 
348 #include "G4NistManager.hh"
350 {
351  auto nameVec = G4NistManager::Instance()->GetNistMaterialNames();
352  auto itr = nameVec.begin();
353  G4int i = 0;
354  for(;itr!=nameVec.end();itr++)
355  {
356  G4cout << std::setw(26) << *itr;
357  if(++i%3==0) G4cout << G4endl;
358  }
359  G4cout << G4endl;
360 }
361 
363 {
364  auto mat = G4NistManager::Instance()->FindOrBuildMaterial(matName);
365  return (mat!=nullptr);
366 }
367 
369 {
370  auto store = G4LogicalVolumeStore::GetInstance();
371  std::vector<G4LogicalVolume*>::iterator itr = store->begin();
372  for(;itr!=store->end();itr++)
373  {
374  if((*itr)->GetName()==logVol)
375  {
376  G4cout << "Logical volume <" << (*itr)->GetName() << "> is made of <"
377  << (*itr)->GetMaterial()->GetName() << ">" << G4endl;
378  return true;
379  }
380  }
381  return false;
382 }
383 
384 G4int eASTDetectorConstruction::SetMaterial(G4String& logVolName,G4String& matName)
385 {
386  G4LogicalVolume* logVol = nullptr;
387  G4Material* mat = nullptr;
388 
389  auto store = G4LogicalVolumeStore::GetInstance();
390  auto itr = store->begin();
391  for(;itr!=store->end();itr++)
392  {
393  if(((*itr)->GetName()).find(logVolName)!=std::string::npos)
394  {
395  logVol = *itr;
396  break;
397  }
398  }
399 
400  auto materialTable = G4Material::GetMaterialTable();
401  auto matItr = materialTable->begin();
402  for(;matItr!=materialTable->end();matItr++)
403  {
404  if((*matItr)->GetName()==matName)
405  {
406  mat = *matItr;
407  break;
408  }
409  }
410 
411  G4int retVal = 0;
412  if(!logVol && !mat)
413  { retVal = 3; }
414  else if(!logVol)
415  { retVal = 1; }
416  else if(!mat)
417  { retVal = 2; }
418  else
419  { logVol->SetMaterial(mat); }
420 
421  return retVal;
422 }
423 
424