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 | // |
---|
26 | // HadrontherapyDetectorConstruction.hh; |
---|
27 | // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy// |
---|
28 | |
---|
29 | #ifndef HadrontherapyDetectorConstruction_H |
---|
30 | #define HadrontherapyDetectorConstruction_H 1 |
---|
31 | |
---|
32 | #include "G4Box.hh" |
---|
33 | #include "globals.hh" |
---|
34 | #include "G4VisAttributes.hh" |
---|
35 | #include "G4LogicalVolume.hh" |
---|
36 | #include "G4UnitsTable.hh" |
---|
37 | |
---|
38 | class G4VPhysicalVolume; |
---|
39 | class G4LogicalVolume; |
---|
40 | class HadrontherapyDetectorROGeometry; |
---|
41 | class HadrontherapyDetectorMessenger; |
---|
42 | class HadrontherapyDetectorSD; |
---|
43 | class HadrontherapyMatrix; |
---|
44 | |
---|
45 | class HadrontherapyDetectorConstruction |
---|
46 | { |
---|
47 | public: |
---|
48 | |
---|
49 | HadrontherapyDetectorConstruction(G4VPhysicalVolume*); |
---|
50 | |
---|
51 | ~HadrontherapyDetectorConstruction(); |
---|
52 | |
---|
53 | |
---|
54 | private: |
---|
55 | |
---|
56 | void ConstructPhantom(); |
---|
57 | void ConstructDetector(); |
---|
58 | void ConstructSensitiveDetector(G4ThreeVector positionToWORLD); |
---|
59 | void ParametersCheck(); |
---|
60 | |
---|
61 | public: |
---|
62 | // Get detector position relative to WORLD |
---|
63 | inline G4ThreeVector GetDetectorToWorldPosition() |
---|
64 | { |
---|
65 | return phantomPosition + detectorPosition; |
---|
66 | } |
---|
67 | ///////////////////////////////////////////////////////////////////////////// |
---|
68 | // Get displacement between phantom and detector by detector position (center of), phantom (center of) and detector sizes |
---|
69 | inline G4ThreeVector GetDetectorToPhantomPosition() |
---|
70 | { |
---|
71 | return G4ThreeVector(phantomSizeX/2 - detectorSizeX/2 + detectorPosition.getX(), |
---|
72 | phantomSizeY/2 - detectorSizeY/2 + detectorPosition.getY(), |
---|
73 | phantomSizeZ/2 - detectorSizeZ/2 + detectorPosition.getZ() |
---|
74 | ); |
---|
75 | } |
---|
76 | |
---|
77 | ///////////////////////////////////////////////////////////////////////////// |
---|
78 | // Calculate (and set) detector position by displacement, phantom and detector sizes |
---|
79 | inline void SetDetectorPosition() |
---|
80 | { |
---|
81 | // Adjust detector position |
---|
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); |
---|
85 | |
---|
86 | //G4cout << "*************** DetectorToPhantomPosition " << detectorToPhantomPosition/cm << "\n"; |
---|
87 | //G4cout << "*************** DetectorPosition " << detectorPosition/cm << "\n"; |
---|
88 | } |
---|
89 | ///////////////////////////////////////////////////////////////////////////// |
---|
90 | // Check whether detector is inside phantom |
---|
91 | inline bool IsInside(G4double detectorX, |
---|
92 | G4double detectorY, |
---|
93 | G4double detectorZ, |
---|
94 | G4double phantomX, |
---|
95 | G4double phantomY, |
---|
96 | G4double phantomZ, |
---|
97 | G4ThreeVector detectorToPhantomPosition) |
---|
98 | { |
---|
99 | // Dimensions check... X Y and Z |
---|
100 | // Firstly check what dimension we are modifying |
---|
101 | { |
---|
102 | if (detectorX > phantomX) |
---|
103 | { |
---|
104 | G4cout << "Error: Detector X dimension must be smaller or equal to the corrispondent of the phantom" << G4endl; |
---|
105 | return false; |
---|
106 | } |
---|
107 | if ( (phantomX - detectorX) < detectorToPhantomPosition.getX()) |
---|
108 | { |
---|
109 | G4cout << "Error: X dimension doesn't fit with detector to phantom relative position" << G4endl; |
---|
110 | return false; |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | { |
---|
115 | if (detectorY > phantomY) |
---|
116 | { |
---|
117 | G4cout << "Error: Detector Y dimension must be smaller or equal to the corrispondent of the phantom" << G4endl; |
---|
118 | return false; |
---|
119 | } |
---|
120 | if ( (phantomY - detectorY) < detectorToPhantomPosition.getY()) |
---|
121 | { |
---|
122 | G4cout << "Error: Y dimension doesn't fit with detector to phantom relative position" << G4endl; |
---|
123 | return false; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | { |
---|
128 | if (detectorZ > phantomZ) |
---|
129 | { |
---|
130 | G4cout << "Error: Detector Z dimension must be smaller or equal to the corrispondent of the phantom" << G4endl; |
---|
131 | return false; |
---|
132 | } |
---|
133 | if ( (phantomZ - detectorZ) < detectorToPhantomPosition.getZ()) |
---|
134 | { |
---|
135 | G4cout << "Error: Z dimension doesn't fit with detector to phantom relative position" << G4endl; |
---|
136 | return false; |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | return true; |
---|
141 | } |
---|
142 | ///////////////////////////////////////////////////////////////////////////// |
---|
143 | |
---|
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(); |
---|
152 | G4LogicalVolume* GetDetectorLogicalVolume(){ return detectorLogicalVolume;} |
---|
153 | |
---|
154 | |
---|
155 | private: |
---|
156 | |
---|
157 | HadrontherapyDetectorMessenger* detectorMessenger; |
---|
158 | |
---|
159 | G4VisAttributes* skyBlue; |
---|
160 | G4VisAttributes* red; |
---|
161 | |
---|
162 | G4VPhysicalVolume* motherPhys; |
---|
163 | |
---|
164 | HadrontherapyDetectorSD* detectorSD; // Pointer to sensitive detector |
---|
165 | HadrontherapyDetectorROGeometry* detectorROGeometry; // Pointer to ROGeometry |
---|
166 | HadrontherapyMatrix* matrix; |
---|
167 | |
---|
168 | G4Box *phantom , *detector; |
---|
169 | G4LogicalVolume *phantomLogicalVolume, *detectorLogicalVolume; |
---|
170 | G4VPhysicalVolume *phantomPhysicalVolume, *detectorPhysicalVolume; |
---|
171 | |
---|
172 | G4double phantomSizeX; |
---|
173 | G4double phantomSizeY; |
---|
174 | G4double phantomSizeZ; |
---|
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 | |
---|
186 | G4int numberOfVoxelsAlongX; |
---|
187 | G4int numberOfVoxelsAlongY; |
---|
188 | G4int numberOfVoxelsAlongZ; |
---|
189 | |
---|
190 | G4double volumeOfVoxel, massOfVoxel; |
---|
191 | |
---|
192 | G4Material *phantomMaterial, *detectorMaterial; |
---|
193 | G4Region* aRegion; |
---|
194 | }; |
---|
195 | #endif |
---|