Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-02 08:02:52

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // --------------------------------------------------------------
0027 //                 GEANT 4 - Brachytherapy example
0028 // --------------------------------------------------------------
0029 //
0030 // Code developed by: S. Guatelli, D. Cutajar, A. Le
0031 // Past developers: S. Agostinelli, F. Foppiano, S. Garelli , M. Tropeano
0032 //
0033 //
0034 //    ****************************************
0035 //    *                                      *
0036 //    *    BrachyDetectorConstruction.cc     *
0037 //    *                                      *
0038 //    ****************************************
0039 //
0040 #include "BrachyFactoryLeipzig.hh"
0041 #include "BrachyFactoryTG186.hh"
0042 #include "BrachyFactoryI.hh"
0043 #include "BrachyFactoryFlexi.hh"
0044 #include "BrachyFactoryOncura6711.hh"
0045 #include "BrachyDetectorMessenger.hh"
0046 #include "BrachyDetectorConstruction.hh"
0047 #include "G4SystemOfUnits.hh"
0048 #include "G4CSGSolid.hh"
0049 #include "G4MaterialPropertyVector.hh"
0050 #include "G4SDManager.hh"
0051 #include "G4RunManager.hh"
0052 #include "G4Box.hh"
0053 #include "G4LogicalVolume.hh"
0054 #include "G4ThreeVector.hh"
0055 #include "G4PVPlacement.hh"
0056 #include "globals.hh"
0057 #include "G4MaterialTable.hh"
0058 #include "G4TransportationManager.hh"
0059 #include "G4Colour.hh"
0060 #include "G4UserLimits.hh"
0061 #include "G4VisAttributes.hh"
0062 #include "G4NistManager.hh"
0063 
0064 BrachyDetectorConstruction::BrachyDetectorConstruction(): 
0065   fFactory(nullptr), fWorld(nullptr), fWorldLog(nullptr), fWorldPhys(nullptr),
0066   fPhantom(nullptr), fPhantomLog(nullptr), fPhantomPhys(nullptr),
0067   fDetectorChoice(0)
0068 {
0069  // Define the messenger of the Detector component
0070  fDetectorMessenger = new BrachyDetectorMessenger(this);
0071 
0072  // Define half size of the phantom along the x, y, z axis
0073  fPhantomSizeX = 15.*cm;
0074  fPhantomSizeY = 15.*cm;
0075  fPhantomSizeZ = 15.*cm;
0076  
0077  // Define the sizes of the World volume containing the phantom
0078  fWorldSizeX = 4.0*m;
0079  fWorldSizeY = 4.0*m;
0080  fWorldSizeZ = 4.0*m;
0081 
0082   // Define the Flexi source as default source modelled in the geometry
0083  fFactory = new BrachyFactoryFlexi();
0084 }
0085 
0086 BrachyDetectorConstruction::~BrachyDetectorConstruction()
0087 { 
0088   delete fDetectorMessenger; 
0089   delete fFactory;
0090 }
0091 
0092 G4VPhysicalVolume* BrachyDetectorConstruction::Construct()
0093 {
0094  // Model the phantom (water box)
0095  ConstructPhantom();
0096 
0097  // Model the source in the phantom
0098  fFactory -> CreateSource(fPhantomPhys);
0099 
0100  return fWorldPhys;
0101 }
0102 
0103 void BrachyDetectorConstruction::SwitchBrachytherapicSeed()
0104 {
0105   // Change the source in the water phantom
0106   fFactory -> CleanSource();
0107   G4cout << "Old brachy source is deleted ..." << G4endl;
0108   delete fFactory;
0109 
0110   switch(fDetectorChoice)
0111   { 
0112    case 1:
0113       fFactory = new BrachyFactoryI();
0114       break;
0115    case 2:
0116       fFactory = new BrachyFactoryLeipzig();
0117       break;
0118    case 3:
0119       fFactory = new BrachyFactoryTG186();
0120       break;
0121    case 4:
0122       fFactory = new BrachyFactoryFlexi();
0123       break;
0124    case 5:
0125       fFactory = new BrachyFactoryOncura6711();
0126       break;
0127    default:
0128       fFactory = new BrachyFactoryFlexi();
0129       break;
0130    }
0131 
0132   fFactory -> CreateSource(fPhantomPhys);
0133   G4cout << "New brachy source is created ..." << G4endl;
0134 
0135   // Notify run manager that the new geometry has been built
0136   G4RunManager::GetRunManager() -> GeometryHasBeenModified();
0137 }
0138 
0139 void BrachyDetectorConstruction::SelectBrachytherapicSeed(G4String val)
0140 {
0141     if (val == "Iodine") 
0142         fDetectorChoice = 1;
0143         else
0144         {
0145             if(val=="Leipzig") 
0146                 fDetectorChoice = 2;
0147                 else
0148                 {
0149                     if(val=="TG186") 
0150                         fDetectorChoice = 3;
0151                         else
0152                         { 
0153                             if(val=="Flexi") 
0154                                 fDetectorChoice = 4;
0155                                 else
0156                                 {
0157                                     if(val=="Oncura") 
0158                                          fDetectorChoice = 5;
0159                                         else 
0160                                             G4cout << val <<  "is not available!!!!"  << G4endl;  
0161                                 }            
0162                         }
0163         }       
0164   }
0165  G4cout << "Now the brachy source is " << val << G4endl;
0166 }
0167 
0168 void BrachyDetectorConstruction::ConstructPhantom()
0169 {
0170   // Model the water phantom 
0171 
0172   // Define the light blue color
0173   G4Colour  lblue   (0.0, 0.0, .75);
0174   
0175    //Get nist material manager
0176   G4NistManager* nist = G4NistManager::Instance();
0177   G4Material* air = nist -> FindOrBuildMaterial("G4_AIR");
0178   G4Material* water = nist -> FindOrBuildMaterial("G4_WATER");
0179 
0180   // World volume
0181   fWorld = new G4Box("World", fWorldSizeX, fWorldSizeY, fWorldSizeZ);
0182   fWorldLog = new G4LogicalVolume(fWorld,air,"WorldLog",nullptr,nullptr,nullptr);
0183   fWorldPhys = new G4PVPlacement(nullptr,G4ThreeVector(),"WorldPhys",fWorldLog,nullptr,false,0);
0184 
0185   // Water Box
0186   fPhantom = new G4Box("Phantom", fPhantomSizeX, fPhantomSizeY, fPhantomSizeZ);
0187 
0188   // Logical volume
0189   fPhantomLog = new G4LogicalVolume(fPhantom,water,"PhantomLog",nullptr,nullptr,nullptr);
0190 
0191   // Physical volume
0192   fPhantomPhys = new G4PVPlacement(nullptr,G4ThreeVector(), // Position: rotation and translation
0193                                   "PhantomPhys", // Name
0194                                   fPhantomLog, // Associated logical volume
0195                                   fWorldPhys, // Mother volume
0196                                   false,0);
0197 
0198   fWorldLog -> SetVisAttributes (G4VisAttributes::GetInvisible());
0199 
0200   // Visualization attributes of the phantom
0201   auto simpleBoxVisAtt = new G4VisAttributes(lblue);
0202   simpleBoxVisAtt -> SetVisibility(true);
0203   simpleBoxVisAtt -> SetForceWireframe(true);
0204   fPhantomLog -> SetVisAttributes(simpleBoxVisAtt);
0205 }
0206 
0207 void BrachyDetectorConstruction::PrintDetectorParameters()
0208 {
0209   G4cout << "----------------" << G4endl
0210          << "the phantom is a water box whose size is: " << G4endl
0211          << fPhantomSizeX *2./cm
0212          << " cm * "
0213          << fPhantomSizeY *2./cm
0214          << " cm * "
0215          << fPhantomSizeZ *2./cm
0216          << " cm" << G4endl
0217          << "The phantom is made of "
0218          << fPhantomLog -> GetMaterial() -> GetName() <<G4endl
0219          << "the source is at the center of the phantom" << G4endl
0220          << "----------------"
0221          << G4endl;
0222 }
0223 
0224 void BrachyDetectorConstruction::SetPhantomMaterial(G4String materialChoice)
0225 {
0226   // Method to change the material of the phantom
0227  
0228   G4NistManager* nist = G4NistManager::Instance();
0229 
0230   // Search the material by its name
0231   G4Material* pttoMaterial =  nist -> FindOrBuildMaterial(materialChoice);
0232 
0233   if (pttoMaterial)
0234   {
0235     fPhantomLog -> SetMaterial(pttoMaterial);
0236     PrintDetectorParameters();
0237   } else  G4cout << "WARNING: material '" << materialChoice << "' not available!" << G4endl;
0238 }