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 position_respect_to_WORLD); |
---|
59 | |
---|
60 | public: |
---|
61 | // Get detector position relative to WORLD |
---|
62 | inline G4ThreeVector GetDetectorToWorldPosition() |
---|
63 | { |
---|
64 | return phantomPosition + detectorPosition; |
---|
65 | } |
---|
66 | ///////////////////////////////////////////////////////////////////////////// |
---|
67 | // Get displacement between phantom and detector by detector position, phantom and detector sizes |
---|
68 | inline G4ThreeVector GetDetectorToPhantomPosition() |
---|
69 | { |
---|
70 | return G4ThreeVector(phantomSizeX - detectorSizeX + detectorPosition.getX(), |
---|
71 | phantomSizeY - detectorSizeY + detectorPosition.getY(), |
---|
72 | phantomSizeZ - detectorSizeZ + detectorPosition.getZ() |
---|
73 | ); |
---|
74 | } |
---|
75 | |
---|
76 | ///////////////////////////////////////////////////////////////////////////// |
---|
77 | // Calculate (and set) detector position by displacement, phantom and detector sizes |
---|
78 | inline void SetDetectorPosition() |
---|
79 | { |
---|
80 | // Adjust detector position |
---|
81 | detectorPosition.setX(detectorToPhantomPosition.getX() - phantomSizeX + detectorSizeX); |
---|
82 | detectorPosition.setY(detectorToPhantomPosition.getY() - phantomSizeY + detectorSizeY); |
---|
83 | detectorPosition.setZ(detectorToPhantomPosition.getZ() - phantomSizeZ + detectorSizeZ); |
---|
84 | |
---|
85 | if (detectorPhysicalVolume) detectorPhysicalVolume -> SetTranslation(detectorPosition); |
---|
86 | } |
---|
87 | ///////////////////////////////////////////////////////////////////////////// |
---|
88 | // Check whether detector is inside phantom |
---|
89 | inline bool IsInside(G4double detectorHalfX, |
---|
90 | G4double detectorHalfY, |
---|
91 | G4double detectorHalfZ, |
---|
92 | G4double phantomHalfX, |
---|
93 | G4double phantomHalfY, |
---|
94 | G4double phantomHalfZ, |
---|
95 | G4ThreeVector detectorToPhantomPosition) |
---|
96 | { |
---|
97 | // Dimensions check... X Y and Z |
---|
98 | // Firstly check what dimension we are modifying |
---|
99 | if (detectorHalfX > 0. && phantomHalfX > 0. && detectorToPhantomPosition.getX() >=0.) |
---|
100 | { |
---|
101 | if (detectorHalfX > phantomHalfX) |
---|
102 | { |
---|
103 | G4cout << "Error: Detector X dimension must be smaller or equal to the corrispondent of the phantom" << G4endl; |
---|
104 | return false; |
---|
105 | } |
---|
106 | if ( 2*(phantomHalfX - detectorHalfX) < detectorToPhantomPosition.getX()) |
---|
107 | { |
---|
108 | G4cout << "Error: X dimension doesn't fit with detector to phantom relative position" << G4endl; |
---|
109 | return false; |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | if (detectorHalfY > 0. && phantomHalfY > 0.&& detectorToPhantomPosition.getY() >=0.) |
---|
114 | { |
---|
115 | if (detectorHalfY > phantomHalfY) |
---|
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 ( 2*(phantomHalfY - detectorHalfY) < 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 | if (detectorHalfZ > 0. && phantomHalfZ > 0.&& detectorToPhantomPosition.getZ() >=0.) |
---|
128 | { |
---|
129 | if (detectorHalfZ > phantomHalfZ) |
---|
130 | { |
---|
131 | G4cout << "Error: Detector Z dimension must be smaller or equal to the corrispondent of the phantom" << G4endl; |
---|
132 | return false; |
---|
133 | } |
---|
134 | if ( 2*(phantomHalfZ - detectorHalfZ) < detectorToPhantomPosition.getZ()) |
---|
135 | { |
---|
136 | G4cout << "Error: Z dimension doesn't fit with detector to phantom relative position" << G4endl; |
---|
137 | return false; |
---|
138 | } |
---|
139 | } |
---|
140 | /* |
---|
141 | G4cout << "Displacement between Phantom and Detector is: "; |
---|
142 | G4cout << "DX= "<< G4BestUnit(detectorToPhantomPosition.getX(),"Length") << |
---|
143 | "DY= "<< G4BestUnit(detectorToPhantomPosition.getY(),"Length") << |
---|
144 | "DZ= "<< G4BestUnit(detectorToPhantomPosition.getZ(),"Length") << G4endl; |
---|
145 | */ |
---|
146 | return true; |
---|
147 | } |
---|
148 | ///////////////////////////////////////////////////////////////////////////// |
---|
149 | |
---|
150 | G4bool SetNumberOfVoxelBySize(G4double sizeX, G4double sizeY, G4double sizeZ); |
---|
151 | G4bool SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ); |
---|
152 | G4bool SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ); |
---|
153 | G4bool SetPhantomPosition(G4ThreeVector); |
---|
154 | G4bool SetDetectorToPhantomPosition(G4ThreeVector DetectorToPhantomPosition); |
---|
155 | G4LogicalVolume* GetDetectorLogicalVolume(){ return detectorLogicalVolume;} |
---|
156 | |
---|
157 | |
---|
158 | private: |
---|
159 | |
---|
160 | HadrontherapyDetectorMessenger* detectorMessenger; |
---|
161 | |
---|
162 | G4VisAttributes* skyBlue; |
---|
163 | G4VisAttributes* red; |
---|
164 | |
---|
165 | G4VPhysicalVolume* motherPhys; |
---|
166 | |
---|
167 | HadrontherapyDetectorSD* detectorSD; // Pointer to sensitive detector |
---|
168 | HadrontherapyDetectorROGeometry* detectorROGeometry; // Pointer to ROGeometry |
---|
169 | HadrontherapyMatrix* matrix; |
---|
170 | |
---|
171 | G4VPhysicalVolume* phantomPhysicalVolume; |
---|
172 | G4LogicalVolume* phantomLogicalVolume; |
---|
173 | G4LogicalVolume* detectorLogicalVolume; |
---|
174 | G4VPhysicalVolume* detectorPhysicalVolume; |
---|
175 | |
---|
176 | G4double phantomSizeX; |
---|
177 | G4double phantomSizeY; |
---|
178 | G4double phantomSizeZ; |
---|
179 | |
---|
180 | G4double detectorSizeX; |
---|
181 | G4double detectorSizeY; |
---|
182 | G4double detectorSizeZ; |
---|
183 | |
---|
184 | G4ThreeVector phantomPosition, detectorPosition, detectorToPhantomPosition; // phantom center, detector center, detector to phantom relative position |
---|
185 | |
---|
186 | G4double sizeOfVoxelAlongX; |
---|
187 | G4double sizeOfVoxelAlongY; |
---|
188 | G4double sizeOfVoxelAlongZ; |
---|
189 | |
---|
190 | G4int numberOfVoxelsAlongX; |
---|
191 | G4int numberOfVoxelsAlongY; |
---|
192 | G4int numberOfVoxelsAlongZ; |
---|
193 | |
---|
194 | G4Box* phantom; |
---|
195 | G4Box* detector; |
---|
196 | |
---|
197 | }; |
---|
198 | #endif |
---|