Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // Hadrontherapy advanced example for Geant4 << 26 // This is the *BASIC* version of Hadrontherapy, a Geant4-based application 27 // See more at: https://twiki.cern.ch/twiki/bi << 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy >> 28 // >> 29 // Visit the Hadrontherapy web site (http://www.lns.infn.it/link/Hadrontherapy) to request >> 30 // the *COMPLETE* version of this program, together with its documentation; >> 31 // Hadrontherapy (both basic and full version) are supported by the Italian INFN >> 32 // Institute in the framework of the MC-INFN Group >> 33 // 28 34 29 #ifndef HadrontherapyDetectorConstruction_H 35 #ifndef HadrontherapyDetectorConstruction_H 30 #define HadrontherapyDetectorConstruction_H 1 36 #define HadrontherapyDetectorConstruction_H 1 31 37 32 #include "G4Box.hh" 38 #include "G4Box.hh" 33 #include "globals.hh" 39 #include "globals.hh" 34 #include "G4VisAttributes.hh" 40 #include "G4VisAttributes.hh" 35 #include "G4LogicalVolume.hh" 41 #include "G4LogicalVolume.hh" 36 #include "G4UnitsTable.hh" 42 #include "G4UnitsTable.hh" 37 #include "HadrontherapyDetectorROGeometry.hh" << 38 43 39 class G4VPhysicalVolume; 44 class G4VPhysicalVolume; 40 class G4LogicalVolume; 45 class G4LogicalVolume; 41 class G4PVPlacement; << 42 class HadrontherapyDetectorROGeometry; 46 class HadrontherapyDetectorROGeometry; 43 class HadrontherapyDetectorMessenger; 47 class HadrontherapyDetectorMessenger; 44 class HadrontherapyDetectorSD; 48 class HadrontherapyDetectorSD; 45 class HadrontherapyMatrix; 49 class HadrontherapyMatrix; 46 class HadrontherapyLet; << 47 50 48 class HadrontherapyDetectorConstruction << 51 class HadrontherapyDetectorConstruction 49 { 52 { 50 public: 53 public: 51 << 54 52 HadrontherapyDetectorConstruction(G4VPhysi << 55 HadrontherapyDetectorConstruction(G4VPhysicalVolume*); 53 << 56 54 ~HadrontherapyDetectorConstruction(); << 57 ~HadrontherapyDetectorConstruction(); 55 << 58 56 public: << 59 57 static HadrontherapyDetectorConstruction* << 60 private: 58 void InitializeDetectorROGeometry(Hadronth << 61 59 G4ThreeV << 62 void ConstructPhantom(); 60 G4VPhysicalVolume* motherPhys; << 63 void ConstructDetector(); 61 HadrontherapyDetectorSD* detectorS << 64 void ConstructSensitiveDetector(G4ThreeVector positionToWORLD); 62 << 65 void ParametersCheck(); 63 ////////////////////////// << 66 64 void VirtualLayer(G4bool Varbool); << 67 public: 65 G4bool NewSource; << 68 // Get detector position relative to WORLD 66 void SetVirtualLayerPosition(G4ThreeVector << 69 inline G4ThreeVector GetDetectorToWorldPosition() 67 G4ThreeVector VirtualLayerPosition; << 70 { 68 << 71 return phantomPosition + detectorPosition; 69 ////////////////////////// << 72 } 70 private: << 73 ///////////////////////////////////////////////////////////////////////////// 71 << 74 // Get displacement between phantom and detector by detector position (center of), phantom (center of) and detector sizes 72 void ConstructPhantom(); << 75 inline G4ThreeVector GetDetectorToPhantomPosition() 73 void ConstructDetector(); << 76 { 74 void ParametersCheck(); << 77 return G4ThreeVector(phantomSizeX/2 - detectorSizeX/2 + detectorPosition.getX(), 75 void CheckOverlaps(); << 78 phantomSizeY/2 - detectorSizeY/2 + detectorPosition.getY(), 76 << 79 phantomSizeZ/2 - detectorSizeZ/2 + detectorPosition.getZ() 77 public: << 80 ); 78 // Get detector position relative to WORLD << 81 } 79 inline G4ThreeVector GetDetectorToWorldPos << 82 80 { << 83 ///////////////////////////////////////////////////////////////////////////// 81 return phantomPosition + detectorPosit << 84 // Calculate (and set) detector position by displacement, phantom and detector sizes 82 } << 85 inline void SetDetectorPosition() 83 ////////////////////////////////////////// << 86 { 84 // Get displacement between phantom and de << 87 // Adjust detector position 85 inline G4ThreeVector GetDetectorToPhantomP << 88 detectorPosition.setX(detectorToPhantomPosition.getX() - phantomSizeX/2 + detectorSizeX/2); 86 { << 89 detectorPosition.setY(detectorToPhantomPosition.getY() - phantomSizeY/2 + detectorSizeY/2); 87 return G4ThreeVector(phantomSizeX/2 - << 90 detectorPosition.setZ(detectorToPhantomPosition.getZ() - phantomSizeZ/2 + detectorSizeZ/2); 88 phantomSizeY/2 - << 91 89 phantomSizeZ/2 - << 92 //G4cout << "*************** DetectorToPhantomPosition " << detectorToPhantomPosition/cm << "\n"; 90 ); << 93 //G4cout << "*************** DetectorPosition " << detectorPosition/cm << "\n"; 91 } << 94 } 92 << 95 ///////////////////////////////////////////////////////////////////////////// 93 ////////////////////////////////////////// << 96 // Check whether detector is inside phantom 94 // Calculate (and set) detector position b << 97 inline bool IsInside(G4double detectorX, 95 inline void SetDetectorPosition() << 98 G4double detectorY, 96 { << 99 G4double detectorZ, 97 // Adjust detector position << 100 G4double phantomX, 98 detectorPosition.setX(detectorToPhanto << 101 G4double phantomY, 99 detectorPosition.setY(detectorToPhanto << 102 G4double phantomZ, 100 detectorPosition.setZ(detectorToPhanto << 103 G4ThreeVector detectorToPhantomPosition) 101 << 104 { 102 << 105 // Dimensions check... X Y and Z 103 } << 106 // Firstly check what dimension we are modifying 104 ////////////////////////////////////////// << 107 { 105 // Check whether detector is inside phanto << 108 if (detectorX > phantomX) 106 inline bool IsInside(G4double detectorX, << 109 { 107 G4double detectorY, << 110 G4cout << "Error: Detector X dimension must be smaller or equal to the corrispondent of the phantom" << G4endl; 108 G4double detectorZ, << 111 return false; 109 G4double phantomX, << 112 } 110 G4double phantomY, << 113 if ( (phantomX - detectorX) < detectorToPhantomPosition.getX()) 111 G4double phantomZ, << 114 { 112 G4ThreeVector pos) << 115 G4cout << "Error: X dimension doesn't fit with detector to phantom relative position" << G4endl; 113 { << 116 return false; 114 // Dimensions check... X Y and Z << 117 } 115 // Firstly check what dimension we are << 118 } 116 { << 119 117 if (detectorX > phantomX) << 120 { 118 { << 121 if (detectorY > phantomY) 119 G4cout << "Error: Detector X d << 122 { 120 return false; << 123 G4cout << "Error: Detector Y dimension must be smaller or equal to the corrispondent of the phantom" << G4endl; 121 } << 124 return false; 122 if ( (phantomX - detectorX) < pos. << 125 } 123 { << 126 if ( (phantomY - detectorY) < detectorToPhantomPosition.getY()) 124 G4cout << "Error: X dimension << 127 { 125 return false; << 128 G4cout << "Error: Y dimension doesn't fit with detector to phantom relative position" << G4endl; 126 } << 129 return false; 127 } << 130 } 128 << 131 } 129 { << 132 130 if (detectorY > phantomY) << 133 { 131 { << 134 if (detectorZ > phantomZ) 132 G4cout << "Error: Detector Y d << 135 { 133 return false; << 136 G4cout << "Error: Detector Z dimension must be smaller or equal to the corrispondent of the phantom" << G4endl; 134 } << 137 return false; 135 if ( (phantomY - detectorY) < pos. << 138 } 136 { << 139 if ( (phantomZ - detectorZ) < detectorToPhantomPosition.getZ()) 137 G4cout << "Error: Y dimension << 140 { 138 return false; << 141 G4cout << "Error: Z dimension doesn't fit with detector to phantom relative position" << G4endl; 139 } << 142 return false; 140 } << 143 } 141 << 144 } 142 { << 145 143 if (detectorZ > phantomZ) << 146 return true; 144 { << 147 } 145 G4cout << "Error: Detector Z d << 148 ///////////////////////////////////////////////////////////////////////////// 146 return false; << 149 147 } << 150 G4bool SetPhantomMaterial(G4String material); 148 if ( (phantomZ - detectorZ) < pos. << 151 void SetVoxelSize(G4double sizeX, G4double sizeY, G4double sizeZ); 149 { << 152 void SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ); 150 G4cout << "Error: Z dimension << 153 void SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ); 151 return false; << 154 void SetPhantomPosition(G4ThreeVector); 152 } << 155 void SetDetectorToPhantomPosition(G4ThreeVector DetectorToPhantomPosition); 153 } << 156 void UpdateGeometry(); 154 << 157 void PrintParameters(); 155 return true; << 158 G4LogicalVolume* GetDetectorLogicalVolume(){ return detectorLogicalVolume;} 156 } << 159 157 ////////////////////////////////////////// << 160 158 << 159 G4bool SetPhantomMaterial(G4String materi << 160 void SetVoxelSize(G4double sizeX, G4double << 161 void SetDetectorSize(G4double sizeX, G4dou << 162 void SetPhantomSize(G4double sizeX, G4doub << 163 void SetPhantomPosition(G4ThreeVector); << 164 void SetDetectorToPhantomPosition(G4ThreeV << 165 void UpdateGeometry(); << 166 void PrintParameters(); << 167 G4LogicalVolume* GetDetectorLogicalVolume( << 168 << 169 private: 161 private: 170 static HadrontherapyDetectorConstruction* << 162 171 HadrontherapyDetectorMessenger* detectorMe << 163 HadrontherapyDetectorMessenger* detectorMessenger; 172 << 164 173 G4VisAttributes* skyBlue; << 165 G4VisAttributes* skyBlue; 174 G4VisAttributes* red; << 166 G4VisAttributes* red; 175 << 167 176 HadrontherapyDetectorROGeometry* detectorR << 168 G4VPhysicalVolume* motherPhys; 177 HadrontherapyMatrix* matrix; << 169 178 HadrontherapyLet* let; << 170 HadrontherapyDetectorSD* detectorSD; // Pointer to sensitive detector 179 << 171 HadrontherapyDetectorROGeometry* detectorROGeometry; // Pointer to ROGeometry 180 G4Box *phantom , *detector; << 172 HadrontherapyMatrix* matrix; 181 G4LogicalVolume *phantomLogicalVolume, *de << 173 182 G4VPhysicalVolume *phantomPhysicalVolume, << 174 G4Box *phantom , *detector; 183 << 175 G4LogicalVolume *phantomLogicalVolume, *detectorLogicalVolume; 184 G4Box* solidVirtualLayer; << 176 G4VPhysicalVolume *phantomPhysicalVolume, *detectorPhysicalVolume; 185 G4LogicalVolume* logicVirtualLayer; << 177 186 G4VPhysicalVolume* physVirtualLayer; << 178 G4double phantomSizeX; 187 << 179 G4double phantomSizeY; 188 G4double phantomSizeX; << 180 G4double phantomSizeZ; 189 G4double phantomSizeY; << 181 190 G4double phantomSizeZ; << 182 G4double detectorSizeX; 191 << 183 G4double detectorSizeY; 192 G4double detectorSizeX; << 184 G4double detectorSizeZ; 193 G4double detectorSizeY; << 185 194 G4double detectorSizeZ; << 186 G4ThreeVector phantomPosition, detectorPosition, detectorToPhantomPosition; // phantom center, detector center, detector to phantom relative position 195 << 187 196 G4ThreeVector phantomPosition, detectorPos << 188 G4double sizeOfVoxelAlongX; 197 << 189 G4double sizeOfVoxelAlongY; 198 G4double sizeOfVoxelAlongX; << 190 G4double sizeOfVoxelAlongZ; 199 G4double sizeOfVoxelAlongY; << 191 200 G4double sizeOfVoxelAlongZ; << 192 G4int numberOfVoxelsAlongX; 201 << 193 G4int numberOfVoxelsAlongY; 202 G4int numberOfVoxelsAlongX; << 194 G4int numberOfVoxelsAlongZ; 203 G4int numberOfVoxelsAlongY; << 195 204 G4int numberOfVoxelsAlongZ; << 196 G4double volumeOfVoxel, massOfVoxel; 205 << 197 206 G4double volumeOfVoxel, massOfVoxel; << 198 G4Material *phantomMaterial, *detectorMaterial; 207 << 199 G4Region* aRegion; 208 G4Material *phantomMaterial, *detectorMate << 209 G4Region* aRegion; << 210 }; 200 }; 211 #endif 201 #endif 212 202