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