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