Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/examples/advanced/hadrontherapy/src/HadrontherapyDetectorConstruction.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/hadrontherapy/src/HadrontherapyDetectorConstruction.cc (Version 11.3.0) and /examples/advanced/hadrontherapy/src/HadrontherapyDetectorConstruction.cc (Version 9.1.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // Hadrontherapy advanced example for Geant4   <<  26 // $Id: HadrontherapyDetectorConstruction.cc; Version 4.0 May 2005
 27 // See more at: https://twiki.cern.ch/twiki/bi <<  27 // ----------------------------------------------------------------------------
                                                   >>  28 //                 GEANT 4 - Hadrontherapy example
                                                   >>  29 // ----------------------------------------------------------------------------
                                                   >>  30 // Code developed by:
                                                   >>  31 //
                                                   >>  32 // G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
                                                   >>  33 // 
                                                   >>  34 // (a) Laboratori Nazionali del Sud 
                                                   >>  35 //     of the INFN, Catania, Italy
                                                   >>  36 // (b) INFN Section of Genova, Genova, Italy
                                                   >>  37 // 
                                                   >>  38 // * cirrone@lns.infn.it
                                                   >>  39 // ----------------------------------------------------------------------------
 28                                                    40 
 29 #include "G4UnitsTable.hh"                     << 
 30 #include "G4SDManager.hh"                          41 #include "G4SDManager.hh"
 31 #include "G4RunManager.hh"                         42 #include "G4RunManager.hh"
 32 #include "G4GeometryManager.hh"                << 
 33 #include "G4SolidStore.hh"                     << 
 34 #include "G4PhysicalVolumeStore.hh"            << 
 35 #include "G4LogicalVolumeStore.hh"             << 
 36 #include "G4Box.hh"                                43 #include "G4Box.hh"
 37 #include "G4LogicalVolume.hh"                      44 #include "G4LogicalVolume.hh"
 38 #include "G4ThreeVector.hh"                        45 #include "G4ThreeVector.hh"
 39 #include "G4PVPlacement.hh"                        46 #include "G4PVPlacement.hh"
 40 #include "globals.hh"                              47 #include "globals.hh"
 41 #include "G4Transform3D.hh"                        48 #include "G4Transform3D.hh"
 42 #include "G4RotationMatrix.hh"                     49 #include "G4RotationMatrix.hh"
 43 #include "G4Colour.hh"                             50 #include "G4Colour.hh"
 44 #include "G4UserLimits.hh"                         51 #include "G4UserLimits.hh"
 45 #include "G4UnitsTable.hh"                     << 
 46 #include "G4VisAttributes.hh"                      52 #include "G4VisAttributes.hh"
 47 #include "G4NistManager.hh"                    <<  53 #include "HadrontherapyPhantomROGeometry.hh"
 48 #include "HadrontherapyDetectorConstruction.hh << 
 49 #include "HadrontherapyDetectorROGeometry.hh"  << 
 50 #include "HadrontherapyDetectorMessenger.hh"       54 #include "HadrontherapyDetectorMessenger.hh"
 51 #include "HadrontherapyDetectorSD.hh"          <<  55 #include "HadrontherapyPhantomSD.hh"
 52 #include "HadrontherapyMatrix.hh"              <<  56 #include "HadrontherapyDetectorConstruction.hh"
 53 #include "HadrontherapyLet.hh"                 <<  57 #include "HadrontherapyMaterial.hh"
 54 #include "PassiveProtonBeamLine.hh"            <<  58 #include "HadrontherapyBeamLine.hh"
 55 #include "BESTPassiveProtonBeamLine.hh"        <<  59 #include "HadrontherapyModulator.hh"
 56 #include "HadrontherapyMatrix.hh"              <<  60 
 57                                                <<  61 HadrontherapyDetectorConstruction::HadrontherapyDetectorConstruction()
 58 #include "HadrontherapyRBE.hh"                 <<  62   : phantomSD(0), phantomROGeometry(0), beamLine(0), modulator(0),
 59 #include "G4SystemOfUnits.hh"                  <<  63     physicalTreatmentRoom(0),
 60                                                <<  64     patientPhysicalVolume(0), 
 61 #include <cmath>                               <<  65     phantomLogicalVolume(0), 
 62                                                <<  66     phantomPhysicalVolume(0)
 63                                                <<  67 {
 64                                                <<  68   // Messenger to change parameters of the geometry
 65 HadrontherapyDetectorConstruction* Hadronthera <<  69   detectorMessenger = new HadrontherapyDetectorMessenger(this);
 66 ////////////////////////////////////////////// <<  70 
 67 HadrontherapyDetectorConstruction::Hadronthera <<  71   material = new HadrontherapyMaterial();
 68 : motherPhys(physicalTreatmentRoom), // pointe <<  72 
 69 detectorSD(0), detectorROGeometry(0), matrix(0 <<  73   // Phantom sizes
 70 phantom(0), detector(0),                       <<  74   phantomSizeX = 20.*mm;
 71 phantomLogicalVolume(0), detectorLogicalVolume <<  75   phantomSizeY = 20.*mm;
 72 phantomPhysicalVolume(0), detectorPhysicalVolu <<  76   phantomSizeZ = 20.*mm;
 73 aRegion(0)                                     <<  77 
 74 {                                              <<  78   // Number of the phantom voxels  
 75                                                <<  79   numberOfVoxelsAlongX = 200;
 76                                                <<  80   numberOfVoxelsAlongY = 200;
 77     /* NOTE! that the HadrontherapyDetectorCon <<  81   numberOfVoxelsAlongZ = 200;
 78      * does NOT inherit from G4VUserDetectorCo << 
 79      * So the Construct() mandatory virtual me << 
 80      * like the passiveProtonBeamLIne, ...     << 
 81      */                                        << 
 82                                                << 
 83     // Messenger to change parameters of the p << 
 84     detectorMessenger = new HadrontherapyDetec << 
 85                                                << 
 86     // Default detector voxels size            << 
 87     // 200 slabs along the beam direction (X)  << 
 88     sizeOfVoxelAlongX = 200 *um;               << 
 89     sizeOfVoxelAlongY = 4 *cm;                 << 
 90     sizeOfVoxelAlongZ = 4 *cm;                 << 
 91                                                << 
 92     // Define here the material of the water p << 
 93     SetPhantomMaterial("G4_WATER");            << 
 94     // Construct geometry (messenger commands) << 
 95     // SetDetectorSize(4.*cm, 4.*cm, 4.*cm);   << 
 96     SetDetectorSize(4. *cm, 4. *cm, 4. *cm);   << 
 97     SetPhantomSize(40. *cm, 40. *cm, 40. *cm); << 
 98                                                << 
 99     SetPhantomPosition(G4ThreeVector(20. *cm,  << 
100     SetDetectorToPhantomPosition(G4ThreeVector << 
101     SetDetectorPosition();                     << 
102     //GetDetectorToWorldPosition();            << 
103                                                << 
104     // Write virtual parameters to the real on << 
105     UpdateGeometry();                          << 
106                                                << 
107                                                << 
108                                                << 
109 }                                                  82 }
110                                                    83 
111 ////////////////////////////////////////////// << 
112 HadrontherapyDetectorConstruction::~Hadronther     84 HadrontherapyDetectorConstruction::~HadrontherapyDetectorConstruction()
113 {                                              <<  85 { 
114     delete detectorROGeometry;                 <<  86   delete material;
115     delete matrix;                             <<  87   if (phantomROGeometry) delete phantomROGeometry;  
116     delete detectorMessenger;                  <<  88   delete detectorMessenger;
117 }                                              <<  89 }
118                                                <<  90 
119 ////////////////////////////////////////////// <<  91 G4VPhysicalVolume* HadrontherapyDetectorConstruction::Construct()
120 HadrontherapyDetectorConstruction* Hadronthera <<  92 {  
121 {                                              <<  93   // Define the materials of the experimental set-up
122     return instance;                           <<  94   material -> DefineMaterials();
                                                   >>  95   
                                                   >>  96   // Define the geometry components
                                                   >>  97   ConstructBeamLine();
                                                   >>  98   ConstructPhantom();
                                                   >>  99   
                                                   >> 100   // Set the sensitive detector where the energy deposit is collected
                                                   >> 101   ConstructSensitiveDetector();
                                                   >> 102  
                                                   >> 103   return physicalTreatmentRoom;
                                                   >> 104 }
                                                   >> 105 
                                                   >> 106 void HadrontherapyDetectorConstruction::ConstructBeamLine()
                                                   >> 107 { 
                                                   >> 108   G4Material* air = material -> GetMat("Air") ;
                                                   >> 109   G4Material* water = material -> GetMat("Water");
                                                   >> 110 
                                                   >> 111   // ---------------------
                                                   >> 112   // Treatment room - World volume
                                                   >> 113   //---------------------
                                                   >> 114 
                                                   >> 115   // Treatment room sizes
                                                   >> 116   const G4double worldX = 400.0 *cm;
                                                   >> 117   const G4double worldY = 400.0 *cm;
                                                   >> 118   const G4double worldZ = 400.0 *cm;
                                                   >> 119 
                                                   >> 120   G4Box* treatmentRoom = new G4Box("TreatmentRoom",worldX,worldY,worldZ);
                                                   >> 121 
                                                   >> 122   G4LogicalVolume* logicTreatmentRoom = new G4LogicalVolume(treatmentRoom, 
                                                   >> 123                                                             air, 
                                                   >> 124                                                             "logicTreatmentRoom", 
                                                   >> 125                   0,0,0);
                                                   >> 126 
                                                   >> 127 
                                                   >> 128 
                                                   >> 129   physicalTreatmentRoom = new G4PVPlacement(0,
                                                   >> 130               G4ThreeVector(),
                                                   >> 131               "physicalTreatmentRoom", 
                                                   >> 132               logicTreatmentRoom, 
                                                   >> 133               0,false,0);
                                                   >> 134 
                                                   >> 135   G4double maxStepTreatmentRoom = 0.1 *mm;
                                                   >> 136   logicTreatmentRoom -> SetUserLimits(new G4UserLimits(maxStepTreatmentRoom));
                                                   >> 137 
                                                   >> 138   // The treatment room is invisible in the Visualisation
                                                   >> 139   logicTreatmentRoom -> SetVisAttributes (G4VisAttributes::Invisible);
                                                   >> 140  
                                                   >> 141   beamLine = new HadrontherapyBeamLine(physicalTreatmentRoom);
                                                   >> 142   beamLine -> HadrontherapyBeamLineSupport();
                                                   >> 143   beamLine -> HadrontherapyBeamScatteringFoils();
                                                   >> 144   beamLine -> HadrontherapyBeamCollimators();
                                                   >> 145   beamLine -> HadrontherapyBeamMonitoring();
                                                   >> 146   beamLine -> HadrontherapyBeamNozzle();
                                                   >> 147   beamLine -> HadrontherapyBeamFinalCollimator();
                                                   >> 148 
                                                   >> 149   modulator = new HadrontherapyModulator();
                                                   >> 150   modulator -> BuildModulator(physicalTreatmentRoom);
                                                   >> 151 
                                                   >> 152   // Patient - Mother volume of the phantom
                                                   >> 153   G4Box* patient = new G4Box("patient",20 *cm, 20 *cm, 20 *cm);
                                                   >> 154 
                                                   >> 155   G4LogicalVolume* patientLogicalVolume = new G4LogicalVolume(patient,
                                                   >> 156                     water, 
                                                   >> 157                     "patientLog", 0, 0, 0);
                                                   >> 158 
                                                   >> 159   patientPhysicalVolume = new G4PVPlacement(0,G4ThreeVector(0., 0., 0.),
                                                   >> 160               "patientPhys",
                                                   >> 161               patientLogicalVolume,
                                                   >> 162               physicalTreatmentRoom,
                                                   >> 163               false,0);
                                                   >> 164  
                                                   >> 165   // Visualisation attributes of the patient 
                                                   >> 166   G4VisAttributes * redWire = new G4VisAttributes(G4Colour(1. ,0. ,0.));
                                                   >> 167   redWire -> SetVisibility(true);
                                                   >> 168   redWire -> SetForceWireframe(true);
                                                   >> 169   patientLogicalVolume -> SetVisAttributes(redWire); 
123 }                                                 170 }
124                                                   171 
125 ////////////////////////////////////////////// << 
126 // ConstructPhantom() is the method that const << 
127 // (or water phantom) in the usual Medical phy << 
128 // A water phantom can be considered a good ap << 
129 void HadrontherapyDetectorConstruction::Constr    172 void HadrontherapyDetectorConstruction::ConstructPhantom()
130 {                                                 173 {
131     // Definition of the solid volume of the P << 174   G4Colour  lightBlue   (0.0, 0.0, .75);
132     phantom = new G4Box("Phantom",             << 
133                         phantomSizeX/2,        << 
134                         phantomSizeY/2,        << 
135                         phantomSizeZ/2);       << 
136                                                << 
137     // Definition of the logical volume of the << 
138     phantomLogicalVolume = new G4LogicalVolume << 
139                                                << 
140                                                << 
141                                                << 
142     // Definition of the physics volume of the << 
143     phantomPhysicalVolume = new G4PVPlacement( << 
144                                                << 
145                                                << 
146                                                << 
147                                                << 
148                                                << 
149                                                << 
150                                                << 
151     // Visualisation attributes of the phantom << 
152     red = new G4VisAttributes(G4Colour(255/255 << 
153     red -> SetVisibility(true);                << 
154     red -> SetForceSolid(true);                << 
155     red -> SetForceWireframe(true);            << 
156     phantomLogicalVolume -> SetVisAttributes(r << 
157 }                                              << 
158                                                << 
159 ////////////////////////////////////////////// << 
160 // ConstructDetector() is the method the recon << 
161 // inside the water phantom. It is a volume, l << 
162 //                                             << 
163 //           **************************        << 
164 //           *    water phantom       *        << 
165 //           *                        *        << 
166 //           *                        *        << 
167 //           *---------------         *        << 
168 //  Beam     *              -         *        << 
169 //  ----->   * detector     -         *        << 
170 //           *              -         *        << 
171 //           *---------------         *        << 
172 //           *                        *        << 
173 //           *                        *        << 
174 //           *                        *        << 
175 //           **************************        << 
176 //                                             << 
177 // The detector can be dived in slices or voxe << 
178 // and inside it different quantities (dose di << 
179 // can be stored.                              << 
180 void HadrontherapyDetectorConstruction::Constr << 
181                                                   175 
182 {                                              << 176   G4Material* water = material -> GetMat("Water");
183     // Definition of the solid volume of the D << 
184     detector = new G4Box("Detector",           << 
185                                                << 
186                          phantomSizeX/2,       << 
187                                                << 
188                          phantomSizeY/2,       << 
189                                                << 
190                          phantomSizeZ/2);      << 
191                                                << 
192     // Definition of the logic volume of the P << 
193     detectorLogicalVolume = new G4LogicalVolum << 
194                                                << 
195                                                << 
196                                                << 
197     // Definition of the physical volume of th << 
198     detectorPhysicalVolume = new G4PVPlacement << 
199                                                << 
200                                                << 
201                                                << 
202                                                << 
203                                                << 
204                                                << 
205     // Visualisation attributes of the detecto << 
206     skyBlue = new G4VisAttributes( G4Colour(13 << 
207     skyBlue -> SetVisibility(true);            << 
208     skyBlue -> SetForceSolid(true);            << 
209     //skyBlue -> SetForceWireframe(true);      << 
210     detectorLogicalVolume -> SetVisAttributes( << 
211                                                << 
212     // **************                          << 
213     // **************                          << 
214     // Cut per Region                          << 
215     // **************                          << 
216     //                                         << 
217     // A smaller cut is fixed in the phantom t << 
218     // required accuracy                       << 
219     if (!aRegion)                              << 
220     {                                          << 
221         aRegion = new G4Region("DetectorLog"); << 
222         detectorLogicalVolume -> SetRegion(aRe << 
223         aRegion->AddRootLogicalVolume( detecto << 
224     }                                          << 
225 }                                              << 
226                                                   177 
227 ////////////////////////////////////////////// << 178   //ComputeVoxelSize();
228 void HadrontherapyDetectorConstruction::Initia << 
229                                                << 
230                                                << 
231                                                << 
232 {                                              << 
233     RO->Initialize(detectorToWorldPosition,    << 
234                    detectorSizeX/2,            << 
235                    detectorSizeY/2,            << 
236                    detectorSizeZ/2,            << 
237                    numberOfVoxelsAlongX,       << 
238                    numberOfVoxelsAlongY,       << 
239                    numberOfVoxelsAlongZ);      << 
240 }                                              << 
241 void HadrontherapyDetectorConstruction::Virtua << 
242 {                                              << 
243                                                << 
244     //Virtual  plane                           << 
245     VirtualLayerPosition = G4ThreeVector(0*cm, << 
246     NewSource= Varbool;                        << 
247     if(NewSource == true)                      << 
248     {                                          << 
249        // std::cout<<"trr"<<std::endl;         << 
250         G4Material* airNist =  G4NistManager:: << 
251                                                << 
252         solidVirtualLayer = new G4Box("Virtual << 
253                                       1.*um,   << 
254                                       20.*cm,  << 
255                                       40.*cm); << 
256                                                << 
257         logicVirtualLayer = new G4LogicalVolum << 
258                                                << 
259                                                << 
260                                                << 
261                                                << 
262         physVirtualLayer= new G4PVPlacement(0, << 
263                                             "V << 
264                                             lo << 
265                                             mo << 
266                                             fa << 
267                                             0) << 
268                                                << 
269         logicVirtualLayer -> SetVisAttributes( << 
270     }                                          << 
271                                                << 
272                                                << 
273                                                << 
274                                                << 
275 }                                              << 
276                                                   179 
                                                   >> 180   //----------------------
                                                   >> 181   // Water phantom  
                                                   >> 182   //----------------------
                                                   >> 183   G4Box* phantom = new G4Box("Phantom",phantomSizeX,phantomSizeY,phantomSizeZ);
                                                   >> 184 
                                                   >> 185   phantomLogicalVolume = new G4LogicalVolume(phantom,
                                                   >> 186                water,
                                                   >> 187                "PhantomLog",
                                                   >> 188                0,0,0);
                                                   >> 189 
                                                   >> 190   // Fixing the max step allowed in the phantom
                                                   >> 191   G4double maxStep = 0.01 *mm;
                                                   >> 192   phantomLogicalVolume -> SetUserLimits(new G4UserLimits(maxStep));
                                                   >> 193 
                                                   >> 194   G4double phantomXtranslation = -180.*mm;
                                                   >> 195   phantomPhysicalVolume = new G4PVPlacement(0,
                                                   >> 196               G4ThreeVector(phantomXtranslation, 0.0 *mm, 0.0 *mm),
                                                   >> 197               "PhantomPhys",
                                                   >> 198               phantomLogicalVolume,
                                                   >> 199               patientPhysicalVolume,
                                                   >> 200               false,0);
                                                   >> 201  
                                                   >> 202   // Visualisation attributes of the phantom
                                                   >> 203   G4VisAttributes* simpleBoxVisAttributes = new G4VisAttributes(lightBlue);
                                                   >> 204   simpleBoxVisAttributes -> SetVisibility(true);
                                                   >> 205   simpleBoxVisAttributes -> SetForceSolid(true);
                                                   >> 206   phantomLogicalVolume -> SetVisAttributes(simpleBoxVisAttributes);
                                                   >> 207 
                                                   >> 208   // **************
                                                   >> 209   // Cut per Region
                                                   >> 210   // **************
                                                   >> 211   
                                                   >> 212   // A smaller cut is fixed in the phantom to calculate the energy deposit with the
                                                   >> 213   // required accuracy 
                                                   >> 214   G4Region* aRegion = new G4Region("PhantomLog");
                                                   >> 215   phantomLogicalVolume -> SetRegion(aRegion);
                                                   >> 216   aRegion -> AddRootLogicalVolume(phantomLogicalVolume);
                                                   >> 217 }
                                                   >> 218 
                                                   >> 219 void  HadrontherapyDetectorConstruction::ConstructSensitiveDetector()
                                                   >> 220 {  
                                                   >> 221   // Sensitive Detector and ReadOut geometry definition
                                                   >> 222   G4SDManager* sensitiveDetectorManager = G4SDManager::GetSDMpointer();
277                                                   223 
278 ////////////////////////////////////////////// << 224   G4String sensitiveDetectorName = "Phantom"; 
279 void  HadrontherapyDetectorConstruction::Param << 
280 {                                              << 
281     // Check phantom/detector sizes & relative << 
282     if (!IsInside(detectorSizeX,               << 
283                   detectorSizeY,               << 
284                   detectorSizeZ,               << 
285                   phantomSizeX,                << 
286                   phantomSizeY,                << 
287                   phantomSizeZ,                << 
288                   detectorToPhantomPosition    << 
289                   ))                           << 
290         G4Exception("HadrontherapyDetectorCons << 
291                                                << 
292     // Check Detector sizes respect to the vox << 
293                                                << 
294     if ( detectorSizeX < sizeOfVoxelAlongX) {  << 
295         G4Exception("HadrontherapyDetectorCons << 
296     }                                          << 
297     if ( detectorSizeY < sizeOfVoxelAlongY) {  << 
298         G4Exception(" HadrontherapyDetectorCon << 
299     }                                          << 
300     if ( detectorSizeZ < sizeOfVoxelAlongZ) {  << 
301         G4Exception(" HadrontherapyDetectorCon << 
302     }                                          << 
303 }                                              << 
304                                                   225 
305 ////////////////////////////////////////////// << 226   if(!phantomSD)
306 G4bool HadrontherapyDetectorConstruction::SetP << 
307 {                                              << 
308                                                << 
309     if (G4Material* pMat = G4NistManager::Inst << 
310     {                                          << 
311         phantomMaterial  = pMat;               << 
312         detectorMaterial = pMat;               << 
313         if (detectorLogicalVolume && phantomLo << 
314         {                                      << 
315             detectorLogicalVolume -> SetMateri << 
316             phantomLogicalVolume ->  SetMateri << 
317                                                << 
318             G4RunManager::GetRunManager() -> P << 
319             G4RunManager::GetRunManager() -> G << 
320             G4cout << "The material of Phantom << 
321         }                                      << 
322     }                                          << 
323     else                                       << 
324     {                                             227     {
325         G4cout << "WARNING: material \"" << ma << 228       // The sensitive detector is instantiated
326         " table [located in $G4INSTALL/source/ << 229       phantomSD = new HadrontherapyPhantomSD(sensitiveDetectorName);
327         G4cout << "Use command \"/parameter/ni << 230       
328         return false;                          << 231       // The Read Out Geometry is instantiated
                                                   >> 232       G4String ROGeometryName = "PhantomROGeometry";
                                                   >> 233       phantomROGeometry = new HadrontherapyPhantomROGeometry(ROGeometryName,
                                                   >> 234                    phantomSizeX,
                                                   >> 235                    phantomSizeY,
                                                   >> 236                    phantomSizeZ,
                                                   >> 237                    numberOfVoxelsAlongX,
                                                   >> 238                    numberOfVoxelsAlongY,
                                                   >> 239                    numberOfVoxelsAlongZ);
                                                   >> 240       phantomROGeometry -> BuildROGeometry();
                                                   >> 241       phantomSD -> SetROgeometry(phantomROGeometry);
                                                   >> 242       sensitiveDetectorManager -> AddNewDetector(phantomSD);
                                                   >> 243       phantomLogicalVolume -> SetSensitiveDetector(phantomSD);
329     }                                             244     }
330                                                << 
331     return true;                               << 
332 }                                                 245 }
333 ////////////////////////////////////////////// << 246 
334 void HadrontherapyDetectorConstruction::SetPha << 247 void HadrontherapyDetectorConstruction::SetModulatorAngle(G4double value)
335 {                                              << 248 {  
336     if (sizeX > 0.) phantomSizeX = sizeX;      << 249   modulator -> SetModulatorAngle(value);
337     if (sizeY > 0.) phantomSizeY = sizeY;      << 250   G4RunManager::GetRunManager() -> GeometryHasBeenModified();
338     if (sizeZ > 0.) phantomSizeZ = sizeZ;      << 
339 }                                                 251 }
340                                                   252 
341 ////////////////////////////////////////////// << 253 void HadrontherapyDetectorConstruction::SetRangeShifterXPosition(G4double value)
342 void HadrontherapyDetectorConstruction::SetDet << 
343 {                                                 254 {
344     if (sizeX > 0.) {detectorSizeX = sizeX;}   << 255   beamLine -> SetRangeShifterXPosition(value);
345     if (sizeY > 0.) {detectorSizeY = sizeY;}   << 256   G4RunManager::GetRunManager() -> GeometryHasBeenModified();
346     if (sizeZ > 0.) {detectorSizeZ = sizeZ;}   << 
347     SetVoxelSize(sizeOfVoxelAlongX, sizeOfVoxe << 
348 }                                                 257 }
349                                                   258 
350 ////////////////////////////////////////////// << 259 void HadrontherapyDetectorConstruction::SetRangeShifterXSize(G4double value)
351 void HadrontherapyDetectorConstruction::SetVox << 
352 {                                                 260 {
353     if (sizeX > 0.) {sizeOfVoxelAlongX = sizeX << 261   beamLine -> SetRangeShifterXSize(value);
354     if (sizeY > 0.) {sizeOfVoxelAlongY = sizeY << 262   G4RunManager::GetRunManager() -> GeometryHasBeenModified();
355     if (sizeZ > 0.) {sizeOfVoxelAlongZ = sizeZ << 
356 }                                                 263 }
357                                                   264 
358 ////////////////////////////////////////////// << 265 void HadrontherapyDetectorConstruction::SetFirstScatteringFoilSize(G4double value)
359 void HadrontherapyDetectorConstruction::SetPha << 
360 {                                                 266 {
361     phantomPosition = pos;                     << 267   beamLine -> SetFirstScatteringFoilXSize(value);  
                                                   >> 268   G4RunManager::GetRunManager() -> GeometryHasBeenModified();
362 }                                                 269 }
363                                                   270 
364 ////////////////////////////////////////////// << 271 void HadrontherapyDetectorConstruction::SetSecondScatteringFoilSize(G4double value)
365 void HadrontherapyDetectorConstruction::SetDet << 
366 {                                                 272 {
367     detectorToPhantomPosition = displ;         << 273   beamLine -> SetSecondScatteringFoilXSize(value);
                                                   >> 274   G4RunManager::GetRunManager() -> GeometryHasBeenModified();
368 }                                                 275 }
369                                                   276 
370 void HadrontherapyDetectorConstruction::SetVir << 277 void HadrontherapyDetectorConstruction::SetOuterRadiusStopper(G4double value)
371 {                                                 278 {
372                                                << 279   beamLine -> SetOuterRadiusStopper(value); 
373     VirtualLayerPosition = position;           << 280   G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 
374     physVirtualLayer->SetTranslation(VirtualLa << 
375                                                << 
376 }                                                 281 }
377 ////////////////////////////////////////////// << 282 
378 void HadrontherapyDetectorConstruction::Update << 283 void HadrontherapyDetectorConstruction::SetInnerRadiusFinalCollimator(G4double value)
379 {                                              << 
380     /*                                         << 
381      * Check parameters consistency            << 
382      */                                        << 
383     ParametersCheck();                         << 
384                                                << 
385     G4GeometryManager::GetInstance() -> OpenGe << 
386     if (phantom)                               << 
387     {                                          << 
388         phantom -> SetXHalfLength(phantomSizeX << 
389         phantom -> SetYHalfLength(phantomSizeY << 
390         phantom -> SetZHalfLength(phantomSizeZ << 
391                                                << 
392         phantomPhysicalVolume -> SetTranslatio << 
393     }                                          << 
394     else   ConstructPhantom();                 << 
395                                                << 
396                                                << 
397     // Get the center of the detector          << 
398     SetDetectorPosition();                     << 
399     if (detector)                              << 
400     {                                          << 
401                                                << 
402         detector -> SetXHalfLength(detectorSiz << 
403         detector -> SetYHalfLength(detectorSiz << 
404         detector -> SetZHalfLength(detectorSiz << 
405                                                << 
406         detectorPhysicalVolume -> SetTranslati << 
407     }                                          << 
408     else    ConstructDetector();               << 
409                                                << 
410     //std::cout<<NewSource<<std::endl;         << 
411     /*if(NewSource)                            << 
412      {                                         << 
413      std::cout<<"via"<<std::endl;              << 
414      }*/                                       << 
415                                                << 
416                                                << 
417     // std::cout<<"i"<<std::endl;              << 
418     // std::cout<<VirtualLayerPosition<<std::e << 
419     // physVirtualLayer->SetTranslation(Virtua << 
420                                                << 
421                                                << 
422                                                << 
423                                                << 
424                                                << 
425     // Round to nearest integer number of voxe << 
426                                                << 
427     numberOfVoxelsAlongX = G4lrint(detectorSiz << 
428     sizeOfVoxelAlongX = ( detectorSizeX / numb << 
429     numberOfVoxelsAlongY = G4lrint(detectorSiz << 
430     sizeOfVoxelAlongY = ( detectorSizeY / numb << 
431     numberOfVoxelsAlongZ = G4lrint(detectorSiz << 
432     sizeOfVoxelAlongZ = ( detectorSizeZ / numb << 
433     PassiveProtonBeamLine *ppbl= (PassiveProto << 
434                                                << 
435     G4RunManager::GetRunManager()->GetUserDete << 
436                                                << 
437     HadrontherapyDetectorROGeometry* RO = (Had << 
438                                                << 
439     //Set parameters, either for the Construct << 
440     RO->Initialize(GetDetectorToWorldPosition( << 
441                    detectorSizeX/2,            << 
442                    detectorSizeY/2,            << 
443                    detectorSizeZ/2,            << 
444                    numberOfVoxelsAlongX,       << 
445                    numberOfVoxelsAlongY,       << 
446                    numberOfVoxelsAlongZ);      << 
447                                                << 
448     //This method below has an effect only if  << 
449     RO->UpdateROGeometry();                    << 
450                                                << 
451                                                << 
452                                                << 
453     volumeOfVoxel = sizeOfVoxelAlongX * sizeOf << 
454     massOfVoxel = detectorMaterial -> GetDensi << 
455     //  This will clear the existing matrix (t << 
456     matrix = HadrontherapyMatrix::GetInstance( << 
457                                                << 
458                                                << 
459                                                << 
460                                                << 
461                                                << 
462     // Initialize RBE                          << 
463     HadrontherapyRBE::CreateInstance(numberOfV << 
464                                                << 
465     // Comment out the line below if let calcu << 
466     // Initialize LET with energy of primaries << 
467     if ( (let = HadrontherapyLet::GetInstance( << 
468     {                                          << 
469         HadrontherapyLet::GetInstance() -> Ini << 
470     }                                          << 
471                                                << 
472                                                << 
473     // Initialize analysis                     << 
474     // Inform the kernel about the new geometr << 
475     G4RunManager::GetRunManager() -> GeometryH << 
476     G4RunManager::GetRunManager() -> PhysicsHa << 
477                                                << 
478     PrintParameters();                         << 
479                                                << 
480     // CheckOverlaps();                        << 
481 }                                              << 
482                                                << 
483 ////////////////////////////////////////////// << 
484 //Check of the geometry                        << 
485 ////////////////////////////////////////////// << 
486 void HadrontherapyDetectorConstruction::CheckO << 
487 {                                                 284 {
488     G4PhysicalVolumeStore* thePVStore = G4Phys << 285   beamLine -> SetInnerRadiusFinalCollimator(value);
489     G4cout << thePVStore->size() << " physical << 286   G4RunManager::GetRunManager() -> GeometryHasBeenModified();
490     G4bool overlapFlag = false;                << 
491     G4int res=1000;                            << 
492     G4double tol=0.; //tolerance               << 
493     for (size_t i=0;i<thePVStore->size();i++)  << 
494     {                                          << 
495         //overlapFlag = (*thePVStore)[i]->Chec << 
496         overlapFlag = (*thePVStore)[i]->CheckO << 
497     if (overlapFlag)                           << 
498         G4cout << "Check: there are overlappin << 
499 }                                                 287 }
500                                                   288 
501 ////////////////////////////////////////////// << 289 void HadrontherapyDetectorConstruction::SetRSMaterial(G4String materialChoice)
502 void HadrontherapyDetectorConstruction::PrintP << 
503 {                                                 290 {
504                                                << 291   beamLine -> SetRSMaterial(materialChoice);
505     G4cout << "The (X,Y,Z) dimensions of the p << 
506     G4BestUnit( phantom -> GetXHalfLength()*2. << 
507     G4BestUnit( phantom -> GetYHalfLength()*2. << 
508     G4BestUnit( phantom -> GetZHalfLength()*2. << 
509                                                << 
510     G4cout << "The (X,Y,Z) dimensions of the d << 
511     G4BestUnit( detector -> GetXHalfLength()*2 << 
512     G4BestUnit( detector -> GetYHalfLength()*2 << 
513     G4BestUnit( detector -> GetZHalfLength()*2 << 
514                                                << 
515     G4cout << "Displacement between Phantom an << 
516     G4cout << "DX= "<< G4BestUnit(phantomPosit << 
517     "DY= "<< G4BestUnit(phantomPosition.getY() << 
518     "DZ= "<< G4BestUnit(phantomPosition.getZ() << 
519                                                << 
520     G4cout << "The (X,Y,Z) sizes of the Voxels << 
521     G4BestUnit(sizeOfVoxelAlongX, "Length")  < << 
522     G4BestUnit(sizeOfVoxelAlongY, "Length")  < << 
523     G4BestUnit(sizeOfVoxelAlongZ, "Length") << << 
524                                                << 
525     G4cout << "The number of Voxels along (X,Y << 
526     numberOfVoxelsAlongX  << ',' <<            << 
527     numberOfVoxelsAlongY  <<','  <<            << 
528     numberOfVoxelsAlongZ  << ')' << G4endl;    << 
529 }                                                 292 }
                                                   >> 293 
530                                                   294 
531                                                   295 
532                                                   296