EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eASTDetectorComponentGDML.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file eASTDetectorComponentGDML.cc
1 // ********************************************************************
2 //
3 // eASTDetectorComponentGDML.cc
4 // eAST Generic Detctor component from gdml file
5 //
6 // History
7 // October 25, 2021 : first implementation
8 //
9 // ********************************************************************
10 
12 
13 #include "G4VPhysicalVolume.hh"
14 #include "G4PVPlacement.hh"
15 #include "G4LogicalVolume.hh"
16 #include "G4VSolid.hh"
17 #include "G4Region.hh"
18 #include "G4RegionStore.hh"
19 #include "G4GDMLParser.hh"
20 #include "G4GenericMessenger.hh"
21 #include "G4VisAttributes.hh"
22 #include "G4Version.hh"
23 #include "eASTRegionInformation.hh"
24 
25 eASTDetectorComponentGDML::eASTDetectorComponentGDML(G4String compName, G4int vl, const G4bool validate_gdml)
26  : eASTVDetectorComponent(compName,vl), m_validate_gdml (validate_gdml)
27 {;}
28 
30 {
31  if(messenger!=nullptr)
32  {
33  delete messenger;
34  messenger = nullptr;
35  }
36 }
37 
39 {
40  messenger = new G4GenericMessenger(this,commandDir,"Commands for the component");
41  auto gdmlCmd = messenger->DeclareMethod("gdmlFile",&eASTDetectorComponentGDML::SetGDML,
42  "Define the input GDML file");
43  gdmlCmd.SetToBeBroadcasted(false);
44  gdmlCmd.SetStates(G4State_PreInit);
45  auto matCmd = messenger->DeclareMethod("materialFile",&eASTDetectorComponentGDML::SetMatFile,
46  "Define material definition file");
47  matCmd.SetToBeBroadcasted(false);
48  matCmd.SetStates(G4State_PreInit);
49 }
50 
51 void eASTDetectorComponentGDML::Construct(G4VPhysicalVolume* worldPhys)
52 {
53  if(gdmlFileName == "*NOTDEFINED*")
54  {
55  G4Exception("eASTDetectorComponentGDML::Construct","eASTDetectorComponentGDML000",
56  FatalException,"GDML file is not specified.");
57  }
58 
60 #if G4VERSION_NUMBER > 1100
61  // Taking care of potential volume-name duplication
62  parser.SetStripFlag(false);
63  parser.SetReverseSearch(true);
64 #endif
65  // Support structures will be placed directly to the world volume
66  // There is no envelope volume to be defined
67  // A region is created for this component and all volumes that consist
68  // of this component will share the same region.
69 
70  pRegion = G4RegionStore::GetInstance()->FindOrCreateRegion(componentName+"_reg");
71  auto regInfo = new eASTRegionInformation(componentName+"_regInfo");
72  regInfo->SetDetectorComponentGDML();
73  pRegion->SetUserInformation(regInfo);
74 
75  // Now we read the GDML contents
77  auto tempEnv = parser.GetWorldVolume();
78  auto tempEnvLog = tempEnv->GetLogicalVolume();
79  auto tempEnvSolid = tempEnvLog->GetSolid();
80  G4int ndaughter = G4int(tempEnvLog->GetNoDaughters());
81  auto visAtt = new G4VisAttributes(G4Colour(1.0,0.0,1.0));
82  // G4cerr << tempEnvLog->GetName() << " " << ndaughter << G4endl;
83 
84  for(G4int idaughter=0;idaughter<ndaughter;idaughter++)
85  {
86  auto daughter = tempEnvLog->GetDaughter(idaughter);
87  // std::string name = daughter->GetLogicalVolume()->GetName();
88  // name+="_" + std::to_string(idaughter);
89  // daughter->GetLogicalVolume()->SetName( name );
90  auto new_rmat = GetRotation();
91  if(new_rmat!=G4RotationMatrix())
92  {
93  auto prmat = const_cast<G4RotationMatrix*>(daughter->GetFrameRotation());
94  if(prmat==nullptr) prmat = new G4RotationMatrix();
95  *prmat *= new_rmat.inverse();
96  daughter->SetRotation(prmat);
97  }
98  auto tran = daughter->GetObjectTranslation();
99  tran += GetLocation();
100  daughter->SetTranslation(tran);
101  daughter->GetLogicalVolume()->SetVisAttributes(visAtt);
102  worldPhys->GetLogicalVolume()->AddDaughter(daughter);
103  daughter->SetMotherLogical(worldPhys->GetLogicalVolume());
104  daughter->GetLogicalVolume()->SetRegion(pRegion);
105  pRegion->AddRootLogicalVolume(daughter->GetLogicalVolume());
106  // G4cerr << daughter->GetLogicalVolume()->GetName() << G4endl;
107  // G4cerr << idaughter << G4endl;
108  for ( size_t i=0; i<daughter->GetLogicalVolume()->GetNoDaughters() ; i++ ){
109  auto dd = daughter->GetLogicalVolume()->GetDaughter(i);
110  // G4cerr << dd->GetName() << G4endl;
111  for ( size_t j=0; j<dd->GetLogicalVolume()->GetNoDaughters() ; j++ ){
112  auto ddd = dd->GetLogicalVolume()->GetDaughter(j);
113  std::string name3 = ddd->GetName();
114  // if ( name3.rfind("av",0) == 0 ){
115  // G4cerr << " " << name3 << G4endl;
116  // }
117  }
118  }
119  }
120  delete tempEnv;
121  delete tempEnvLog;
122  delete tempEnvSolid;
123 
124  if(materialToBeSet)
126 }
127 
128