Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // >> 24 // $Id: G3toG4BuildTree.cc,v 1.19 2005/05/26 14:18:11 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-07-01 $ 27 // 26 // 28 // modified by I. Hrivnacova, 2.8.99 27 // modified by I. Hrivnacova, 2.8.99 29 28 30 #include "globals.hh" 29 #include "globals.hh" 31 #include "G3toG4BuildTree.hh" 30 #include "G3toG4BuildTree.hh" 32 #include "G3RotTable.hh" 31 #include "G3RotTable.hh" 33 #include "G3MedTable.hh" 32 #include "G3MedTable.hh" 34 #include "G3VolTable.hh" 33 #include "G3VolTable.hh" 35 #include "G3SensVolVector.hh" 34 #include "G3SensVolVector.hh" 36 #include "G3Pos.hh" 35 #include "G3Pos.hh" 37 #include "G4LogicalVolume.hh" 36 #include "G4LogicalVolume.hh" 38 #include "G4PVPlacement.hh" 37 #include "G4PVPlacement.hh" 39 #include "G4ReflectionFactory.hh" 38 #include "G4ReflectionFactory.hh" 40 #include "G4Transform3D.hh" 39 #include "G4Transform3D.hh" 41 40 42 void G3toG4BuildTree(G3VolTableEntry* curVTE, 41 void G3toG4BuildTree(G3VolTableEntry* curVTE, G3VolTableEntry* motherVTE) 43 { 42 { 44 G3toG4BuildLVTree(curVTE, motherVTE); 43 G3toG4BuildLVTree(curVTE, motherVTE); 45 G3toG4BuildPVTree(curVTE); 44 G3toG4BuildPVTree(curVTE); 46 } 45 } 47 46 48 void G3toG4BuildLVTree(G3VolTableEntry* curVTE 47 void G3toG4BuildLVTree(G3VolTableEntry* curVTE, G3VolTableEntry* motherVTE) 49 { 48 { 50 // check existence of the solid 49 // check existence of the solid 51 if (curVTE->GetSolid()) { 50 if (curVTE->GetSolid()) { 52 G4LogicalVolume* curLog = curVTE->GetLV(); 51 G4LogicalVolume* curLog = curVTE->GetLV(); 53 if (!curLog) { 52 if (!curLog) { 54 // skip creating logical volume 53 // skip creating logical volume 55 // in case it already exists 54 // in case it already exists 56 55 57 // material 56 // material 58 G4Material* material = 0; 57 G4Material* material = 0; 59 G3MedTableEntry* mte = G3Med.get(curVTE- 58 G3MedTableEntry* mte = G3Med.get(curVTE->GetNmed()); 60 if (mte) material = mte->GetMaterial(); 59 if (mte) material = mte->GetMaterial(); 61 if (!material) { 60 if (!material) { 62 G4String err_message = "VTE " + curVTE << 61 G4Exception("VTE " + curVTE->GetName() + " has not defined material!!"); 63 + " has not defin << 64 G4Exception("G3toG4BuildLVTree()", "G3 << 65 FatalException, err_messag << 66 return; << 67 } 62 } 68 63 69 // logical volume 64 // logical volume 70 curLog = 65 curLog = 71 new G4LogicalVolume(curVTE->GetSolid() 66 new G4LogicalVolume(curVTE->GetSolid(), material, curVTE->GetName()); 72 curVTE->SetLV(curLog); 67 curVTE->SetLV(curLog); 73 68 74 // insert logical volume to G3SensVol ve 69 // insert logical volume to G3SensVol vector 75 // in case it is sensitive 70 // in case it is sensitive 76 if (mte->GetISVOL()) G3SensVol.push_back 71 if (mte->GetISVOL()) G3SensVol.push_back(curLog); 77 } 72 } 78 } 73 } 79 else { 74 else { 80 if ( !(curVTE->GetDivision() && motherVTE- 75 if ( !(curVTE->GetDivision() && motherVTE->GetMasterClone() == motherVTE && 81 motherVTE->GetNoClones()>1)) { 76 motherVTE->GetNoClones()>1)) { 82 // ignore dummy vte's 77 // ignore dummy vte's 83 // (this should be the only case when th 78 // (this should be the only case when the vte is dummy but 84 // is present in mother <-> daughters tr 79 // is present in mother <-> daughters tree 85 G4String err_message = "VTE " + curVTE-> << 80 G4Exception("VTE " + curVTE->GetName() + " has not defined solid!!"); 86 + " has not defined << 87 G4Exception("G3toG4BuildLVTree()", "G3to << 88 FatalException, err_message) << 89 return; << 90 } 81 } 91 } 82 } 92 83 93 // process daughters 84 // process daughters 94 G4int Ndau = curVTE->GetNoDaughters(); 85 G4int Ndau = curVTE->GetNoDaughters(); 95 for (int Idau=0; Idau<Ndau; Idau++){ 86 for (int Idau=0; Idau<Ndau; Idau++){ 96 G3toG4BuildLVTree(curVTE->GetDaughter(Idau 87 G3toG4BuildLVTree(curVTE->GetDaughter(Idau), curVTE); 97 } 88 } 98 } 89 } 99 90 100 void G3toG4BuildPVTree(G3VolTableEntry* curVTE 91 void G3toG4BuildPVTree(G3VolTableEntry* curVTE) 101 { 92 { 102 // check existence of the solid 93 // check existence of the solid 103 if (curVTE->GetSolid()) { 94 if (curVTE->GetSolid()) { 104 G4LogicalVolume* curLog = curVTE->GetLV(); 95 G4LogicalVolume* curLog = curVTE->GetLV(); 105 96 106 // positions in motherVTE 97 // positions in motherVTE 107 for (G4int i=0; i<curVTE->NPCopies(); i++) 98 for (G4int i=0; i<curVTE->NPCopies(); i++){ 108 99 109 G3Pos* theG3Pos = curVTE->GetG3PosCopy(i 100 G3Pos* theG3Pos = curVTE->GetG3PosCopy(i); 110 if (theG3Pos) { 101 if (theG3Pos) { 111 102 112 // loop over all mothers 103 // loop over all mothers 113 for (G4int im=0; im<curVTE->GetNoMothe 104 for (G4int im=0; im<curVTE->GetNoMothers(); im++) { 114 105 115 G3VolTableEntry* motherVTE = curVTE- 106 G3VolTableEntry* motherVTE = curVTE->GetMother(im); 116 if (theG3Pos->GetMotherName() == mot 107 if (theG3Pos->GetMotherName() == motherVTE->GetMasterClone()->GetName()) { 117 108 118 // get mother logical volume 109 // get mother logical volume 119 G4LogicalVolume* mothLV=0; 110 G4LogicalVolume* mothLV=0; 120 G4String motherName = motherVTE->G << 111 if (motherVTE) { 121 if (!curVTE->FindMother(motherName << 112 G4String motherName = motherVTE->GetName(); 122 if (curVTE->FindMother(motherName) << 113 if (!curVTE->FindMother(motherName)) continue; 123 // check consistency - tbr << 114 if (curVTE->FindMother(motherName)->GetName() != motherName) { 124 G4String err_message = << 115 // check consistency - tbr 125 "G3toG4BuildTree: Incon << 116 G4Exception("G3toG4BuildTree: Inconsistent mother <-> daughter !!"); 126 G4Exception("G3toG4BuildPVTree() << 117 } 127 FatalException, err_ << 118 mothLV = motherVTE->GetLV(); 128 return; << 119 } 129 } << 120 else { 130 mothLV = motherVTE->GetLV(); << 121 mothLV = 0; >> 122 } 131 123 132 // copy number 124 // copy number 133 // (in G3 numbering starts from 1 125 // (in G3 numbering starts from 1 but in G4 from 0) 134 G4int copyNo = theG3Pos->GetCopy() 126 G4int copyNo = theG3Pos->GetCopy() - 1; 135 127 136 // position it if not top-level vo 128 // position it if not top-level volume 137 129 138 if (mothLV != 0) { 130 if (mothLV != 0) { 139 131 140 // transformation 132 // transformation 141 G4int irot = theG3Pos->GetIrot() 133 G4int irot = theG3Pos->GetIrot(); 142 G4RotationMatrix* theMatrix = 0; 134 G4RotationMatrix* theMatrix = 0; 143 if (irot>0) theMatrix = G3Rot.Ge 135 if (irot>0) theMatrix = G3Rot.Get(irot); 144 G4Rotate3D rotation; 136 G4Rotate3D rotation; 145 if (theMatrix) { 137 if (theMatrix) { 146 rotation = G4Rotate3D(*theMatrix); 138 rotation = G4Rotate3D(*theMatrix); 147 } 139 } 148 140 149 #ifndef G3G4_NO_REFLECTION 141 #ifndef G3G4_NO_REFLECTION 150 G4Translate3D translation(*(theG 142 G4Translate3D translation(*(theG3Pos->GetPos())); 151 G4Transform3D transform3D = translatio 143 G4Transform3D transform3D = translation * (rotation.inverse()); 152 144 153 G4ReflectionFactory::Instance() 145 G4ReflectionFactory::Instance() 154 ->Place(transform3D, // transf 146 ->Place(transform3D, // transformation 155 curVTE->GetName(), // PV nam 147 curVTE->GetName(), // PV name 156 curLog, // its logical volume 148 curLog, // its logical volume 157 mothLV, // mother logical vol 149 mothLV, // mother logical volume 158 false, // only 150 false, // only 159 copyNo); // copy 151 copyNo); // copy 160 #else 152 #else 161 new G4PVPlacement(theMatrix, 153 new G4PVPlacement(theMatrix, // rotation matrix 162 *(theG3Pos->GetP 154 *(theG3Pos->GetPos()), // its position 163 curLog, 155 curLog, // its LogicalVolume 164 curVTE->GetName( 156 curVTE->GetName(), // PV name 165 mothLV, 157 mothLV, // Mother LV 166 0, 158 0, // only 167 copyNo); 159 copyNo); // copy 168 #endif 160 #endif 169 161 170 // verbose 162 // verbose 171 #ifdef G3G4DEBUG 163 #ifdef G3G4DEBUG 172 G4cout << "PV: " << i << "th copy of 164 G4cout << "PV: " << i << "th copy of " << curVTE->GetName() 173 << " in " << motherVTE->GetName( 165 << " in " << motherVTE->GetName() << " copyNo: " 174 << copyNo << " irot: " << irot << 166 << copyNo << " irot: " << irot << " pos: " 175 << *(theG3Pos->GetPos()) << G4endl; 167 << *(theG3Pos->GetPos()) << G4endl; 176 #endif 168 #endif 177 } 169 } 178 } 170 } 179 } 171 } 180 // clear this position 172 // clear this position 181 curVTE->ClearG3PosCopy(i); 173 curVTE->ClearG3PosCopy(i); 182 i--; 174 i--; 183 } 175 } 184 } 176 } 185 177 186 // divisions 178 // divisions 187 if (curVTE->GetDivision()) { 179 if (curVTE->GetDivision()) { 188 curVTE->GetDivision()->CreatePVReplica() 180 curVTE->GetDivision()->CreatePVReplica(); 189 // verbose 181 // verbose 190 #ifdef G3G4DEBUG 182 #ifdef G3G4DEBUG 191 G4cout << "CreatePVReplica: " << curVTE->Get 183 G4cout << "CreatePVReplica: " << curVTE->GetName() 192 << " in " << curVTE->GetMother()->G 184 << " in " << curVTE->GetMother()->GetName() << G4endl; 193 #endif 185 #endif 194 186 195 // clear this divison 187 // clear this divison 196 curVTE->ClearDivision(); 188 curVTE->ClearDivision(); 197 } 189 } 198 } 190 } 199 191 200 // process daughters 192 // process daughters 201 G4int Ndau = curVTE->GetNoDaughters(); 193 G4int Ndau = curVTE->GetNoDaughters(); 202 for (int Idau=0; Idau<Ndau; Idau++){ 194 for (int Idau=0; Idau<Ndau; Idau++){ 203 G3toG4BuildPVTree(curVTE->GetDaughter(Idau 195 G3toG4BuildPVTree(curVTE->GetDaughter(Idau)); 204 } 196 } 205 } 197 } 206 198 207 199