00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "globals.hh"
00032 #include "G3toG4BuildTree.hh"
00033 #include "G3RotTable.hh"
00034 #include "G3MedTable.hh"
00035 #include "G3VolTable.hh"
00036 #include "G3SensVolVector.hh"
00037 #include "G3Pos.hh"
00038 #include "G4LogicalVolume.hh"
00039 #include "G4PVPlacement.hh"
00040 #include "G4ReflectionFactory.hh"
00041 #include "G4Transform3D.hh"
00042
00043 void G3toG4BuildTree(G3VolTableEntry* curVTE, G3VolTableEntry* motherVTE)
00044 {
00045 G3toG4BuildLVTree(curVTE, motherVTE);
00046 G3toG4BuildPVTree(curVTE);
00047 }
00048
00049 void G3toG4BuildLVTree(G3VolTableEntry* curVTE, G3VolTableEntry* motherVTE)
00050 {
00051
00052 if (curVTE->GetSolid()) {
00053 G4LogicalVolume* curLog = curVTE->GetLV();
00054 if (!curLog) {
00055
00056
00057
00058
00059 G4Material* material = 0;
00060 G3MedTableEntry* mte = G3Med.get(curVTE->GetNmed());
00061 if (mte) material = mte->GetMaterial();
00062 if (!material) {
00063 G4String err_message = "VTE " + curVTE->GetName()
00064 + " has not defined material!!";
00065 G4Exception("G3toG4BuildLVTree()", "G3toG40001",
00066 FatalException, err_message);
00067 return;
00068 }
00069
00070
00071 curLog =
00072 new G4LogicalVolume(curVTE->GetSolid(), material, curVTE->GetName());
00073 curVTE->SetLV(curLog);
00074
00075
00076
00077 if (mte->GetISVOL()) G3SensVol.push_back(curLog);
00078 }
00079 }
00080 else {
00081 if ( !(curVTE->GetDivision() && motherVTE->GetMasterClone() == motherVTE &&
00082 motherVTE->GetNoClones()>1)) {
00083
00084
00085
00086 G4String err_message = "VTE " + curVTE->GetName()
00087 + " has not defined solid!!";
00088 G4Exception("G3toG4BuildLVTree()", "G3toG40002",
00089 FatalException, err_message);
00090 return;
00091 }
00092 }
00093
00094
00095 G4int Ndau = curVTE->GetNoDaughters();
00096 for (int Idau=0; Idau<Ndau; Idau++){
00097 G3toG4BuildLVTree(curVTE->GetDaughter(Idau), curVTE);
00098 }
00099 }
00100
00101 void G3toG4BuildPVTree(G3VolTableEntry* curVTE)
00102 {
00103
00104 if (curVTE->GetSolid()) {
00105 G4LogicalVolume* curLog = curVTE->GetLV();
00106
00107
00108 for (G4int i=0; i<curVTE->NPCopies(); i++){
00109
00110 G3Pos* theG3Pos = curVTE->GetG3PosCopy(i);
00111 if (theG3Pos) {
00112
00113
00114 for (G4int im=0; im<curVTE->GetNoMothers(); im++) {
00115
00116 G3VolTableEntry* motherVTE = curVTE->GetMother(im);
00117 if (theG3Pos->GetMotherName() == motherVTE->GetMasterClone()->GetName()) {
00118
00119
00120 G4LogicalVolume* mothLV=0;
00121 G4String motherName = motherVTE->GetName();
00122 if (!curVTE->FindMother(motherName)) continue;
00123 if (curVTE->FindMother(motherName)->GetName() != motherName) {
00124
00125 G4String err_message =
00126 "G3toG4BuildTree: Inconsistent mother <-> daughter !!";
00127 G4Exception("G3toG4BuildPVTree()", "G3toG40003",
00128 FatalException, err_message);
00129 return;
00130 }
00131 mothLV = motherVTE->GetLV();
00132
00133
00134
00135 G4int copyNo = theG3Pos->GetCopy() - 1;
00136
00137
00138
00139 if (mothLV != 0) {
00140
00141
00142 G4int irot = theG3Pos->GetIrot();
00143 G4RotationMatrix* theMatrix = 0;
00144 if (irot>0) theMatrix = G3Rot.Get(irot);
00145 G4Rotate3D rotation;
00146 if (theMatrix) {
00147 rotation = G4Rotate3D(*theMatrix);
00148 }
00149
00150 #ifndef G3G4_NO_REFLECTION
00151 G4Translate3D translation(*(theG3Pos->GetPos()));
00152 G4Transform3D transform3D = translation * (rotation.inverse());
00153
00154 G4ReflectionFactory::Instance()
00155 ->Place(transform3D,
00156 curVTE->GetName(),
00157 curLog,
00158 mothLV,
00159 false,
00160 copyNo);
00161 #else
00162 new G4PVPlacement(theMatrix,
00163 *(theG3Pos->GetPos()),
00164 curLog,
00165 curVTE->GetName(),
00166 mothLV,
00167 0,
00168 copyNo);
00169 #endif
00170
00171
00172 #ifdef G3G4DEBUG
00173 G4cout << "PV: " << i << "th copy of " << curVTE->GetName()
00174 << " in " << motherVTE->GetName() << " copyNo: "
00175 << copyNo << " irot: " << irot << " pos: "
00176 << *(theG3Pos->GetPos()) << G4endl;
00177 #endif
00178 }
00179 }
00180 }
00181
00182 curVTE->ClearG3PosCopy(i);
00183 i--;
00184 }
00185 }
00186
00187
00188 if (curVTE->GetDivision()) {
00189 curVTE->GetDivision()->CreatePVReplica();
00190
00191 #ifdef G3G4DEBUG
00192 G4cout << "CreatePVReplica: " << curVTE->GetName()
00193 << " in " << curVTE->GetMother()->GetName() << G4endl;
00194 #endif
00195
00196
00197 curVTE->ClearDivision();
00198 }
00199 }
00200
00201
00202 G4int Ndau = curVTE->GetNoDaughters();
00203 for (int Idau=0; Idau<Ndau; Idau++){
00204 G3toG4BuildPVTree(curVTE->GetDaughter(Idau));
00205 }
00206 }
00207