Geant4  10.03.p03
 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 // Hadrontherapy advanced example for Geant4
27 // See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
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"
38 
39 class G4VPhysicalVolume;
40 class G4LogicalVolume;
41 class G4PVPlacement;
46 class HadrontherapyLet;
47 
49 {
50 public:
51 
53 
55 
56 public:
59  G4ThreeVector detectorToWorldPosition);
61  HadrontherapyDetectorSD* detectorSD; // Pointer to sensitive detector
62 
63 private:
64 
65  void ConstructPhantom();
66  void ConstructDetector();
67  void ParametersCheck();
68  void CheckOverlaps();
69 
70 public:
71 // Get detector position relative to WORLD
73  {
74  return phantomPosition + detectorPosition;
75  }
77 // Get displacement between phantom and detector by detector position (center of), phantom (center of) and detector sizes
79 {
80  return G4ThreeVector(phantomSizeX/2 - detectorSizeX/2 + detectorPosition.getX(),
81  phantomSizeY/2 - detectorSizeY/2 + detectorPosition.getY(),
82  phantomSizeZ/2 - detectorSizeZ/2 + detectorPosition.getZ()
83  );
84 }
85 
87 // Calculate (and set) detector position by displacement, phantom and detector sizes
88 inline void SetDetectorPosition()
89  {
90  // Adjust detector position
91  detectorPosition.setX(detectorToPhantomPosition.getX() - phantomSizeX/2 + detectorSizeX/2);
92  detectorPosition.setY(detectorToPhantomPosition.getY() - phantomSizeY/2 + detectorSizeY/2);
93  detectorPosition.setZ(detectorToPhantomPosition.getZ() - phantomSizeZ/2 + detectorSizeZ/2);
94 
95 
96  }
98 // Check whether detector is inside phantom
99 inline bool IsInside(G4double detectorX,
100  G4double detectorY,
101  G4double detectorZ,
102  G4double phantomX,
103  G4double phantomY,
104  G4double phantomZ,
106 {
107 // Dimensions check... X Y and Z
108 // Firstly check what dimension we are modifying
109  {
110  if (detectorX > phantomX)
111  {
112  G4cout << "Error: Detector X dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
113  return false;
114  }
115  if ( (phantomX - detectorX) < pos.getX())
116  {
117  G4cout << "Error: X dimension doesn't fit with detector to phantom relative position" << G4endl;
118  return false;
119  }
120  }
121 
122  {
123  if (detectorY > phantomY)
124  {
125  G4cout << "Error: Detector Y dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
126  return false;
127  }
128  if ( (phantomY - detectorY) < pos.getY())
129  {
130  G4cout << "Error: Y dimension doesn't fit with detector to phantom relative position" << G4endl;
131  return false;
132  }
133  }
134 
135  {
136  if (detectorZ > phantomZ)
137  {
138  G4cout << "Error: Detector Z dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
139  return false;
140  }
141  if ( (phantomZ - detectorZ) < pos.getZ())
142  {
143  G4cout << "Error: Z dimension doesn't fit with detector to phantom relative position" << G4endl;
144  return false;
145  }
146  }
147 
148  return true;
149 }
151 
153  void SetVoxelSize(G4double sizeX, G4double sizeY, G4double sizeZ);
154  void SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ);
155  void SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ);
157  void SetDetectorToPhantomPosition(G4ThreeVector DetectorToPhantomPosition);
158  void UpdateGeometry();
159  void PrintParameters();
160  G4LogicalVolume* GetDetectorLogicalVolume(){ return detectorLogicalVolume;}
161 
162 private:
163  static HadrontherapyDetectorConstruction* instance;
164  HadrontherapyDetectorMessenger* detectorMessenger;
165 
166  G4VisAttributes* skyBlue;
167  G4VisAttributes* red;
168 
169  HadrontherapyDetectorROGeometry* detectorROGeometry; // Pointer to ROGeometry
170  HadrontherapyMatrix* matrix;
171  HadrontherapyLet* let;
172 
173  G4Box *phantom , *detector;
174  G4LogicalVolume *phantomLogicalVolume, *detectorLogicalVolume;
175  G4VPhysicalVolume *phantomPhysicalVolume, *detectorPhysicalVolume;
176 
177  G4double phantomSizeX;
178  G4double phantomSizeY;
179  G4double phantomSizeZ;
180 
181  G4double detectorSizeX;
182  G4double detectorSizeY;
183  G4double detectorSizeZ;
184 
185  G4ThreeVector phantomPosition, detectorPosition, detectorToPhantomPosition; // phantom center, detector center, detector to phantom relative position
186 
187  G4double sizeOfVoxelAlongX;
188  G4double sizeOfVoxelAlongY;
189  G4double sizeOfVoxelAlongZ;
190 
191  G4int numberOfVoxelsAlongX;
192  G4int numberOfVoxelsAlongY;
193  G4int numberOfVoxelsAlongZ;
194 
195  G4double volumeOfVoxel, massOfVoxel;
196 
197  G4Material *phantomMaterial, *detectorMaterial;
198  G4Region* aRegion;
199 };
200 #endif
void SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ)
CLHEP::Hep3Vector G4ThreeVector
Definition: G4Box.hh:64
double getY() const
static HadrontherapyDetectorConstruction * GetInstance()
void SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ)
int G4int
Definition: G4Types.hh:78
void setY(double)
void setZ(double)
void setX(double)
string material
Definition: eplot.py:19
double getX() const
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
void SetDetectorToPhantomPosition(G4ThreeVector DetectorToPhantomPosition)
bool IsInside(G4double detectorX, G4double detectorY, G4double detectorZ, G4double phantomX, G4double phantomY, G4double phantomZ, G4ThreeVector pos)
double getZ() const
#define G4endl
Definition: G4ios.hh:61
void InitializeDetectorROGeometry(HadrontherapyDetectorROGeometry *, G4ThreeVector detectorToWorldPosition)
double G4double
Definition: G4Types.hh:76
void SetVoxelSize(G4double sizeX, G4double sizeY, G4double sizeZ)
static const G4double pos