Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HadrontherapyDetectorConstruction.hh
Go to the documentation of this file.
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 // This is the *BASIC* version of Hadrontherapy, a Geant4-based application
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 //
34 
35 #ifndef HadrontherapyDetectorConstruction_H
36 #define HadrontherapyDetectorConstruction_H 1
37 
38 #include "G4Box.hh"
39 #include "globals.hh"
40 #include "G4VisAttributes.hh"
41 #include "G4LogicalVolume.hh"
42 #include "G4UnitsTable.hh"
43 
44 class G4VPhysicalVolume;
45 class G4LogicalVolume;
50 
52 {
53 public:
54 
56 
58 
59 
60 private:
61 
62  void ConstructPhantom();
63  void ConstructDetector();
64  void ConstructSensitiveDetector(G4ThreeVector positionToWORLD);
65  void ParametersCheck();
66 
67 public:
68 // Get detector position relative to WORLD
70  {
71  return phantomPosition + detectorPosition;
72  }
74 // Get displacement between phantom and detector by detector position (center of), phantom (center of) and detector sizes
76 {
77  return G4ThreeVector(phantomSizeX/2 - detectorSizeX/2 + detectorPosition.getX(),
78  phantomSizeY/2 - detectorSizeY/2 + detectorPosition.getY(),
79  phantomSizeZ/2 - detectorSizeZ/2 + detectorPosition.getZ()
80  );
81 }
82 
84 // Calculate (and set) detector position by displacement, phantom and detector sizes
85 inline void SetDetectorPosition()
86  {
87  // Adjust detector position
88  detectorPosition.setX(detectorToPhantomPosition.getX() - phantomSizeX/2 + detectorSizeX/2);
89  detectorPosition.setY(detectorToPhantomPosition.getY() - phantomSizeY/2 + detectorSizeY/2);
90  detectorPosition.setZ(detectorToPhantomPosition.getZ() - phantomSizeZ/2 + detectorSizeZ/2);
91 
92  //G4cout << "*************** DetectorToPhantomPosition " << detectorToPhantomPosition/cm << "\n";
93  //G4cout << "*************** DetectorPosition " << detectorPosition/cm << "\n";
94  }
96 // Check whether detector is inside phantom
97 inline bool IsInside(G4double detectorX,
98  G4double detectorY,
99  G4double detectorZ,
100  G4double phantomX,
101  G4double phantomY,
102  G4double phantomZ,
103  G4ThreeVector pos)
104 {
105 // Dimensions check... X Y and Z
106 // Firstly check what dimension we are modifying
107  {
108  if (detectorX > phantomX)
109  {
110  G4cout << "Error: Detector X dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
111  return false;
112  }
113  if ( (phantomX - detectorX) < pos.getX())
114  {
115  G4cout << "Error: X dimension doesn't fit with detector to phantom relative position" << G4endl;
116  return false;
117  }
118  }
119 
120  {
121  if (detectorY > phantomY)
122  {
123  G4cout << "Error: Detector Y dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
124  return false;
125  }
126  if ( (phantomY - detectorY) < pos.getY())
127  {
128  G4cout << "Error: Y dimension doesn't fit with detector to phantom relative position" << G4endl;
129  return false;
130  }
131  }
132 
133  {
134  if (detectorZ > phantomZ)
135  {
136  G4cout << "Error: Detector Z dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
137  return false;
138  }
139  if ( (phantomZ - detectorZ) < pos.getZ())
140  {
141  G4cout << "Error: Z dimension doesn't fit with detector to phantom relative position" << G4endl;
142  return false;
143  }
144  }
145 
146  return true;
147 }
149 
151  void SetVoxelSize(G4double sizeX, G4double sizeY, G4double sizeZ);
152  void SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ);
153  void SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ);
155  void SetDetectorToPhantomPosition(G4ThreeVector DetectorToPhantomPosition);
156  void UpdateGeometry();
157  void PrintParameters();
158  G4LogicalVolume* GetDetectorLogicalVolume(){ return detectorLogicalVolume;}
159 
160 
161 private:
162 
163  HadrontherapyDetectorMessenger* detectorMessenger;
164 
165  G4VisAttributes* skyBlue;
166  G4VisAttributes* red;
167 
168  G4VPhysicalVolume* motherPhys;
169 
170  HadrontherapyDetectorSD* detectorSD; // Pointer to sensitive detector
171  HadrontherapyDetectorROGeometry* detectorROGeometry; // Pointer to ROGeometry
172  HadrontherapyMatrix* matrix;
173 
174  G4Box *phantom , *detector;
175  G4LogicalVolume *phantomLogicalVolume, *detectorLogicalVolume;
176  G4VPhysicalVolume *phantomPhysicalVolume, *detectorPhysicalVolume;
177 
178  G4double phantomSizeX;
179  G4double phantomSizeY;
180  G4double phantomSizeZ;
181 
182  G4double detectorSizeX;
183  G4double detectorSizeY;
184  G4double detectorSizeZ;
185 
186  G4ThreeVector phantomPosition, detectorPosition, detectorToPhantomPosition; // phantom center, detector center, detector to phantom relative position
187 
188  G4double sizeOfVoxelAlongX;
189  G4double sizeOfVoxelAlongY;
190  G4double sizeOfVoxelAlongZ;
191 
192  G4int numberOfVoxelsAlongX;
193  G4int numberOfVoxelsAlongY;
194  G4int numberOfVoxelsAlongZ;
195 
196  G4double volumeOfVoxel, massOfVoxel;
197 
198  G4Material *phantomMaterial, *detectorMaterial;
199  G4Region* aRegion;
200 };
201 #endif