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] [ 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/brachytherapy/src/BrachyDetectorConstruction.cc (Version 11.3.0) and /examples/advanced/brachytherapy/src/BrachyDetectorConstruction.cc (Version 7.1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 // -------------------------------------------     23 // --------------------------------------------------------------
 27 //                 GEANT 4 - Brachytherapy exa     24 //                 GEANT 4 - Brachytherapy example
 28 // -------------------------------------------     25 // --------------------------------------------------------------
 29 //                                                 26 //
 30 // Code developed by: S. Guatelli, D. Cutajar, <<  27 // Code developed by:
 31 // Past developers: S. Agostinelli, F. Foppian <<  28 // S. Agostinelli, F. Foppiano, S. Garelli , M. Tropeano, S.Guatelli
 32 //                                                 29 //
 33 //                                                 30 //
 34 //    ****************************************     31 //    ****************************************
 35 //    *                                      *     32 //    *                                      *
 36 //    *    BrachyDetectorConstruction.cc     *     33 //    *    BrachyDetectorConstruction.cc     *
 37 //    *                                      *     34 //    *                                      *
 38 //    ****************************************     35 //    ****************************************
 39 //                                                 36 //
 40 #include "BrachyFactoryLeipzig.hh"             <<  37 // $Id: BrachyDetectorConstruction.cc,v 1.26 2004/11/24 09:53:05 guatelli Exp $
 41 #include "BrachyFactoryTG186.hh"               <<  38 // GEANT4 tag $Name: geant4-07-01 $
 42 #include "BrachyFactoryI.hh"                   <<  39 //
 43 #include "BrachyFactoryFlexi.hh"               <<  40 #include "BrachyPhantomROGeometry.hh"
 44 #include "BrachyFactoryOncura6711.hh"          <<  41 #include "BrachyPhantomSD.hh"
 45 #include "BrachyDetectorMessenger.hh"              42 #include "BrachyDetectorMessenger.hh"
 46 #include "BrachyDetectorConstruction.hh"           43 #include "BrachyDetectorConstruction.hh"
 47 #include "G4SystemOfUnits.hh"                  << 
 48 #include "G4CSGSolid.hh"                           44 #include "G4CSGSolid.hh"
                                                   >>  45 #include "G4Sphere.hh"
 49 #include "G4MaterialPropertyVector.hh"             46 #include "G4MaterialPropertyVector.hh"
 50 #include "G4SDManager.hh"                          47 #include "G4SDManager.hh"
                                                   >>  48 #include "G4SubtractionSolid.hh"
 51 #include "G4RunManager.hh"                         49 #include "G4RunManager.hh"
                                                   >>  50 #include "G4MaterialPropertiesTable.hh"
                                                   >>  51 #include "G4Material.hh"
 52 #include "G4Box.hh"                                52 #include "G4Box.hh"
                                                   >>  53 #include "G4Tubs.hh"
 53 #include "G4LogicalVolume.hh"                      54 #include "G4LogicalVolume.hh"
 54 #include "G4ThreeVector.hh"                        55 #include "G4ThreeVector.hh"
 55 #include "G4PVPlacement.hh"                        56 #include "G4PVPlacement.hh"
 56 #include "globals.hh"                              57 #include "globals.hh"
 57 #include "G4MaterialTable.hh"                      58 #include "G4MaterialTable.hh"
                                                   >>  59 #include "Randomize.hh"  
                                                   >>  60 #include "G4RunManager.hh"
                                                   >>  61 #include "G4Element.hh"
                                                   >>  62 #include "G4ElementTable.hh"
                                                   >>  63 #include "G4PVParameterised.hh"
                                                   >>  64 #include "G4Transform3D.hh"
                                                   >>  65 #include "G4RotationMatrix.hh"
                                                   >>  66 #include "G4FieldManager.hh"
 58 #include "G4TransportationManager.hh"              67 #include "G4TransportationManager.hh"
                                                   >>  68 #include "G4SDManager.hh"
 59 #include "G4Colour.hh"                             69 #include "G4Colour.hh"
 60 #include "G4UserLimits.hh"                         70 #include "G4UserLimits.hh"
                                                   >>  71 #include "G4UnionSolid.hh"
 61 #include "G4VisAttributes.hh"                      72 #include "G4VisAttributes.hh"
 62 #include "G4NistManager.hh"                    <<  73 #include "G4Colour.hh"
                                                   >>  74 #include "BrachyMaterial.hh"
                                                   >>  75 #include "BrachyFactoryLeipzig.hh"
                                                   >>  76 #include "BrachyFactoryIr.hh"
                                                   >>  77 #include "BrachyFactoryI.hh"
                                                   >>  78 
                                                   >>  79 BrachyDetectorConstruction::BrachyDetectorConstruction(G4String &SDName)
                                                   >>  80 : detectorChoice(0), phantomSD(0), phantomROGeometry(0), factory(0),
                                                   >>  81   World(0), WorldLog(0), WorldPhys(0),
                                                   >>  82   Phantom(0), PhantomLog(0), PhantomPhys(0),
                                                   >>  83   phantomAbsorberMaterial(0)
                                                   >>  84 {
                                                   >>  85   phantomDimensionX=15.*cm ;
                                                   >>  86   phantomDimensionY=15.*cm;
                                                   >>  87   phantomDimensionZ=15.*cm;
 63                                                    88 
 64 BrachyDetectorConstruction::BrachyDetectorCons <<  89   numberOfVoxelsAlongX=300;
 65   fFactory(nullptr), fWorld(nullptr), fWorldLo <<  90   numberOfVoxelsAlongZ=300;
 66   fPhantom(nullptr), fPhantomLog(nullptr), fPh << 
 67   fDetectorChoice(0)                           << 
 68 {                                              << 
 69  // Define the messenger of the Detector compo << 
 70  fDetectorMessenger = new BrachyDetectorMessen << 
 71                                                << 
 72  // Define half size of the phantom along the  << 
 73  fPhantomSizeX = 15.*cm;                       << 
 74  fPhantomSizeY = 15.*cm;                       << 
 75  fPhantomSizeZ = 15.*cm;                       << 
 76                                                << 
 77  // Define the sizes of the World volume conta << 
 78  fWorldSizeX = 4.0*m;                          << 
 79  fWorldSizeY = 4.0*m;                          << 
 80  fWorldSizeZ = 4.0*m;                          << 
 81                                                    91 
 82   // Define the Flexi source as default source <<  92   ComputeDimVoxel();
 83  fFactory = new BrachyFactoryFlexi();          <<  93 
                                                   >>  94   Worldx = 4.0*m;
                                                   >>  95   Worldy = 4.0*m;
                                                   >>  96   Worldz = 4.0*m;
                                                   >>  97 
                                                   >>  98   sensitiveDetectorName = SDName;
                                                   >>  99 
                                                   >> 100   detectorMessenger = new BrachyDetectorMessenger(this);
                                                   >> 101 
                                                   >> 102   factory = new BrachyFactoryIr();
                                                   >> 103 
                                                   >> 104   pMaterial = new BrachyMaterial();
 84 }                                                 105 }
 85                                                   106 
                                                   >> 107 
 86 BrachyDetectorConstruction::~BrachyDetectorCon    108 BrachyDetectorConstruction::~BrachyDetectorConstruction()
 87 {                                                 109 { 
 88   delete fDetectorMessenger;                   << 110   delete pMaterial;
 89   delete fFactory;                             << 111   delete factory;
                                                   >> 112   delete detectorMessenger;
                                                   >> 113   if (phantomROGeometry) delete phantomROGeometry;
 90 }                                                 114 }
 91                                                   115 
 92 G4VPhysicalVolume* BrachyDetectorConstruction:    116 G4VPhysicalVolume* BrachyDetectorConstruction::Construct()
 93 {                                                 117 {
 94  // Model the phantom (water box)              << 118   pMaterial -> DefineMaterials();
 95  ConstructPhantom();                           << 119   ConstructPhantom();
 96                                                << 120   factory -> CreateSource(PhantomPhys); //Build the source inside the phantom
 97  // Model the source in the phantom            << 121   ConstructSensitiveDetector();
 98  fFactory -> CreateSource(fPhantomPhys);       << 
 99                                                   122 
100  return fWorldPhys;                            << 123   return WorldPhys;
101 }                                                 124 }
102                                                   125 
103 void BrachyDetectorConstruction::SwitchBrachyt    126 void BrachyDetectorConstruction::SwitchBrachytherapicSeed()
104 {                                                 127 {
105   // Change the source in the water phantom    << 128   factory -> CleanSource();
106   fFactory -> CleanSource();                   << 
107   G4cout << "Old brachy source is deleted ..." << 
108   delete fFactory;                             << 
109                                                   129 
110   switch(fDetectorChoice)                      << 130   delete factory;
                                                   >> 131   switch(detectorChoice)
111   {                                               132   { 
112    case 1:                                     << 133     case 1:
113       fFactory = new BrachyFactoryI();         << 134       factory = new BrachyFactoryI();
114       break;                                   << 
115    case 2:                                     << 
116       fFactory = new BrachyFactoryLeipzig();   << 
117       break;                                      135       break;
118    case 3:                                     << 136     case 2:
119       fFactory = new BrachyFactoryTG186();     << 137       factory = new BrachyFactoryLeipzig();
120       break;                                      138       break;
121    case 4:                                     << 139     case 3:
122       fFactory = new BrachyFactoryFlexi();     << 140       factory = new BrachyFactoryIr();
                                                   >> 141       break;   
                                                   >> 142     default:
                                                   >> 143       factory = new BrachyFactoryIr();
123       break;                                      144       break;
124    case 5:                                     << 145   }
125       fFactory = new BrachyFactoryOncura6711() << 146   factory -> CreateSource(PhantomPhys);
126       break;                                   << 
127    default:                                    << 
128       fFactory = new BrachyFactoryFlexi();     << 
129       break;                                   << 
130    }                                           << 
131                                                << 
132   fFactory -> CreateSource(fPhantomPhys);      << 
133   G4cout << "New brachy source is created ..." << 
134                                                   147 
135   // Notify run manager that the new geometry     148   // Notify run manager that the new geometry has been built
136   G4RunManager::GetRunManager() -> GeometryHas << 149   G4RunManager::GetRunManager() -> DefineWorldVolume( WorldPhys );
137 }                                                 150 }
138                                                   151 
139 void BrachyDetectorConstruction::SelectBrachyt    152 void BrachyDetectorConstruction::SelectBrachytherapicSeed(G4String val)
140 {                                                 153 {
141   if (val == "Iodine")                         << 154   if(val=="Iodium") 
142     fDetectorChoice = 1;                       << 155   {
143       else                                     << 156    detectorChoice = 1;
144       {                                        << 
145           if(val=="Leipzig")                   << 
146             fDetectorChoice = 2;               << 
147             else                               << 
148             {                                  << 
149                 if(val=="TG186")               << 
150                   fDetectorChoice = 3;         << 
151                   else                         << 
152                   {                            << 
153                 if(val=="Flexi")               << 
154                   fDetectorChoice = 4;         << 
155                   else                         << 
156                   {                            << 
157                     if(val=="Oncura")          << 
158                        fDetectorChoice = 5;    << 
159                                 else           << 
160                                   G4cout << va << 
161                   }                            << 
162                   }                            << 
163         }                                      << 
164   }                                               157   }
165  G4cout << "Now the brachy source is " << val  << 158   else
                                                   >> 159   {
                                                   >> 160     if(val=="Leipzig")
                                                   >> 161     {
                                                   >> 162       detectorChoice = 2;
                                                   >> 163     }
                                                   >> 164     else
                                                   >> 165     {
                                                   >> 166       if(val=="Iridium")
                                                   >> 167       {
                                                   >> 168         detectorChoice = 3;
                                                   >> 169       }
                                                   >> 170     }
                                                   >> 171   }
                                                   >> 172   G4cout << "Now the source is " << val << G4endl;
166 }                                                 173 }
167                                                   174 
168 void BrachyDetectorConstruction::ConstructPhan    175 void BrachyDetectorConstruction::ConstructPhantom()
169 {                                                 176 {
170   // Model the water phantom                   << 
171                                                << 
172   // Define the light blue color               << 
173   G4Colour  lblue   (0.0, 0.0, .75);              177   G4Colour  lblue   (0.0, 0.0, .75);
174                                                << 
175    //Get nist material manager                 << 
176   G4NistManager* nist = G4NistManager::Instanc << 
177   G4Material* air = nist -> FindOrBuildMateria << 
178   G4Material* water = nist -> FindOrBuildMater << 
179                                                   178 
180   // World volume                              << 179   G4Material* air = pMaterial -> GetMat("Air") ;
181   fWorld = new G4Box("World", fWorldSizeX, fWo << 180   G4Material* water = pMaterial -> GetMat("Water");
182   fWorldLog = new G4LogicalVolume(fWorld,air," << 
183   fWorldPhys = new G4PVPlacement(nullptr,G4Thr << 
184                                                   181 
185   // Water Box                                 << 182   ComputeDimVoxel();
186   fPhantom = new G4Box("Phantom", fPhantomSize << 
187                                                   183 
188   // Logical volume                            << 184   // World volume
189   fPhantomLog = new G4LogicalVolume(fPhantom,w << 185   World = new G4Box("World",Worldx,Worldy,Worldz);
                                                   >> 186   WorldLog = new G4LogicalVolume(World,air,"WorldLog",0,0,0);
                                                   >> 187   WorldPhys = new G4PVPlacement(0,G4ThreeVector(),
                                                   >> 188                                 "WorldPhys",WorldLog,0,false,0);
190                                                   189 
191   // Physical volume                           << 190   // Water Box
192   fPhantomPhys = new G4PVPlacement(nullptr,G4T << 191   Phantom = new G4Box("Phantom",phantomDimensionX,phantomDimensionY,
193                                   "PhantomPhys << 192                        phantomDimensionZ);
194                                   fPhantomLog, << 193   PhantomLog = new G4LogicalVolume(Phantom,water,"PhantomLog",0,0,0);
195                                   fWorldPhys,  << 194   PhantomPhys = new G4PVPlacement(0,G4ThreeVector(),
196                                   false,0);    << 195                                   "PhantomPhys",PhantomLog,
                                                   >> 196                                   WorldPhys,false,0); 
197                                                   197 
198   fWorldLog -> SetVisAttributes (G4VisAttribut << 198   WorldLog -> SetVisAttributes (G4VisAttributes::Invisible);
199                                                   199 
200   // Visualization attributes of the phantom   << 200   G4VisAttributes* simpleBoxVisAtt = new G4VisAttributes(lblue);
201   auto simpleBoxVisAtt = new G4VisAttributes(l << 
202   simpleBoxVisAtt -> SetVisibility(true);         201   simpleBoxVisAtt -> SetVisibility(true);
203   simpleBoxVisAtt -> SetForceWireframe(true);     202   simpleBoxVisAtt -> SetForceWireframe(true);
204   fPhantomLog -> SetVisAttributes(simpleBoxVis << 203 
                                                   >> 204   PhantomLog -> SetVisAttributes(simpleBoxVisAtt);
                                                   >> 205 }
                                                   >> 206 
                                                   >> 207 void  BrachyDetectorConstruction::ConstructSensitiveDetector()
                                                   >> 208 // Sensitive Detector and ReadOut geometry definition
                                                   >> 209 { 
                                                   >> 210   G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
                                                   >> 211 
                                                   >> 212   if(!phantomSD)
                                                   >> 213   {
                                                   >> 214     phantomSD = new BrachyPhantomSD(sensitiveDetectorName);
                                                   >> 215     G4String ROGeometryName = "PhantomROGeometry";
                                                   >> 216     phantomROGeometry = new BrachyPhantomROGeometry(ROGeometryName,
                                                   >> 217                                 phantomDimensionX,phantomDimensionZ,
                                                   >> 218                                 numberOfVoxelsAlongX,numberOfVoxelsAlongZ);
                                                   >> 219     phantomROGeometry -> BuildROGeometry();
                                                   >> 220     phantomSD -> SetROgeometry(phantomROGeometry);
                                                   >> 221     pSDManager -> AddNewDetector(phantomSD);
                                                   >> 222     PhantomLog -> SetSensitiveDetector(phantomSD);
                                                   >> 223   }
205 }                                                 224 }
206                                                   225 
207 void BrachyDetectorConstruction::PrintDetector    226 void BrachyDetectorConstruction::PrintDetectorParameters()
208 {                                                 227 {
209   G4cout << "----------------" << G4endl       << 228   G4cout << "-----------------------------------------------------------------------"
210          << "the phantom is a water box whose  << 229          << G4endl
211          << fPhantomSizeX *2./cm               << 230          << "the detector is a  box whose size is: " << G4endl
                                                   >> 231          << phantomDimensionX/cm
212          << " cm * "                              232          << " cm * "
213          << fPhantomSizeY *2./cm               << 233          << phantomDimensionY/cm
214          << " cm * "                              234          << " cm * "
215          << fPhantomSizeZ *2./cm               << 235          << phantomDimensionZ/cm
216          << " cm" << G4endl                       236          << " cm" << G4endl
217          << "The phantom is made of "          << 237          << "numVoxel: "
218          << fPhantomLog -> GetMaterial() -> Ge << 238          << numberOfVoxelsAlongX <<G4endl
219          << "the source is at the center of th << 239          << "dim voxel: "
220          << "----------------"                 << 240          << dimVoxel/mm
                                                   >> 241          << "mm" << G4endl 
                                                   >> 242          << "material of the box : "
                                                   >> 243          << phantomAbsorberMaterial->GetName() <<G4endl
                                                   >> 244          << "the source is at the center  of the detector" << G4endl
                                                   >> 245          << "-------------------------------------------------------------------------"
221          << G4endl;                               246          << G4endl;
222 }                                                 247 }
223                                                   248 
                                                   >> 249 
224 void BrachyDetectorConstruction::SetPhantomMat    250 void BrachyDetectorConstruction::SetPhantomMaterial(G4String materialChoice)
225 {                                                 251 {
226   // Method to change the material of the phan << 252   // search the material by its name   
227                                                << 253   G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);     
228   G4NistManager* nist = G4NistManager::Instanc << 
229                                                << 
230   // Search the material by its name           << 
231   G4Material* pttoMaterial =  nist -> FindOrBu << 
232                                                << 
233   if (pttoMaterial)                               254   if (pttoMaterial)
234   {                                               255   {
235     fPhantomLog -> SetMaterial(pttoMaterial);  << 256     phantomAbsorberMaterial = pttoMaterial;
                                                   >> 257     PhantomLog -> SetMaterial(pttoMaterial); 
236     PrintDetectorParameters();                    258     PrintDetectorParameters();
237   } else  G4cout << "WARNING: material '" << m << 259   } 
                                                   >> 260   else
                                                   >> 261     G4cout << "WARNING: material '" << materialChoice
                                                   >> 262            << "' not available!" << G4endl;            
238 }                                                 263 }
239                                                   264