Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:15

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 // Hadrontherapy advanced example for Geant4
0027 // See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
0028 
0029 #ifndef HadrontherapyDetectorConstruction_H
0030 #define HadrontherapyDetectorConstruction_H 1
0031 
0032 #include "G4Box.hh"
0033 #include "globals.hh"
0034 #include "G4VisAttributes.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4UnitsTable.hh"
0037 #include "HadrontherapyDetectorROGeometry.hh"
0038 
0039 class G4VPhysicalVolume;
0040 class G4LogicalVolume;
0041 class G4PVPlacement;
0042 class HadrontherapyDetectorROGeometry;
0043 class HadrontherapyDetectorMessenger;
0044 class HadrontherapyDetectorSD;
0045 class HadrontherapyMatrix;
0046 class HadrontherapyLet;
0047 
0048 class HadrontherapyDetectorConstruction
0049 {
0050 public:
0051     
0052     HadrontherapyDetectorConstruction(G4VPhysicalVolume*);
0053     
0054     ~HadrontherapyDetectorConstruction();
0055     
0056 public:
0057     static HadrontherapyDetectorConstruction* GetInstance();
0058     void InitializeDetectorROGeometry(HadrontherapyDetectorROGeometry*,
0059                                       G4ThreeVector detectorToWorldPosition);
0060     G4VPhysicalVolume* motherPhys;
0061     HadrontherapyDetectorSD*         detectorSD; // Pointer to sensitive detector
0062     
0063     //////////////////////////
0064     void VirtualLayer(G4bool Varbool);
0065     G4bool NewSource;
0066     void SetVirtualLayerPosition(G4ThreeVector);
0067     G4ThreeVector VirtualLayerPosition;
0068     
0069     //////////////////////////
0070 private:
0071     
0072     void ConstructPhantom();
0073     void ConstructDetector();
0074     void ParametersCheck();
0075     void CheckOverlaps();
0076     
0077 public:
0078     // Get detector position relative to WORLD
0079     inline G4ThreeVector GetDetectorToWorldPosition()
0080     {
0081         return phantomPosition + detectorPosition;
0082     }
0083     /////////////////////////////////////////////////////////////////////////////
0084     // Get displacement between phantom and detector by detector position (center of), phantom (center of) and detector sizes
0085     inline G4ThreeVector GetDetectorToPhantomPosition()
0086     {
0087         return G4ThreeVector(phantomSizeX/2 - detectorSizeX/2 + detectorPosition.getX(),
0088                              phantomSizeY/2 - detectorSizeY/2 + detectorPosition.getY(),
0089                              phantomSizeZ/2 - detectorSizeZ/2 + detectorPosition.getZ()
0090                              );
0091     }
0092     
0093     /////////////////////////////////////////////////////////////////////////////
0094     // Calculate (and set) detector position by displacement, phantom and detector sizes
0095     inline void SetDetectorPosition()
0096     {
0097         // Adjust detector position
0098         detectorPosition.setX(detectorToPhantomPosition.getX() - phantomSizeX/2 + detectorSizeX/2);
0099         detectorPosition.setY(detectorToPhantomPosition.getY() - phantomSizeY/2 + detectorSizeY/2);
0100         detectorPosition.setZ(detectorToPhantomPosition.getZ() - phantomSizeZ/2 + detectorSizeZ/2);
0101         
0102         
0103     }
0104     /////////////////////////////////////////////////////////////////////////////
0105     // Check whether detector is inside phantom
0106     inline bool IsInside(G4double detectorX,
0107                          G4double detectorY,
0108                          G4double detectorZ,
0109                          G4double phantomX,
0110                          G4double phantomY,
0111                          G4double phantomZ,
0112                          G4ThreeVector pos)
0113     {
0114         // Dimensions check... X Y and Z
0115         // Firstly check what dimension we are modifying
0116         {
0117             if (detectorX > phantomX)
0118             {
0119                 G4cout << "Error: Detector X dimension must be smaller or equal to the correspondent of the phantom" << G4endl;
0120                 return false;
0121             }
0122             if ( (phantomX - detectorX) < pos.getX())
0123             {
0124                 G4cout << "Error: X dimension doesn't fit with detector to phantom relative position" << G4endl;
0125                 return false;
0126             }
0127         }
0128         
0129         {
0130             if (detectorY > phantomY)
0131             {
0132                 G4cout << "Error: Detector Y dimension must be smaller or equal to the correspondent of the phantom" << G4endl;
0133                 return false;
0134             }
0135             if ( (phantomY - detectorY) < pos.getY())
0136             {
0137                 G4cout << "Error: Y dimension doesn't fit with detector to phantom relative position" << G4endl;
0138                 return false;
0139             }
0140         }
0141         
0142         {
0143             if (detectorZ > phantomZ)
0144             {
0145                 G4cout << "Error: Detector Z dimension must be smaller or equal to the correspondent of the phantom" << G4endl;
0146                 return false;
0147             }
0148             if ( (phantomZ - detectorZ) < pos.getZ())
0149             {
0150                 G4cout << "Error: Z dimension doesn't fit with detector to phantom relative position" << G4endl;
0151                 return false;
0152             }
0153         }
0154         
0155         return true;
0156     }
0157     /////////////////////////////////////////////////////////////////////////////
0158     
0159     G4bool  SetPhantomMaterial(G4String material);
0160     void SetVoxelSize(G4double sizeX, G4double sizeY, G4double sizeZ);
0161     void SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ);
0162     void SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ);
0163     void SetPhantomPosition(G4ThreeVector);
0164     void SetDetectorToPhantomPosition(G4ThreeVector DetectorToPhantomPosition);
0165     void UpdateGeometry();
0166     void PrintParameters();
0167     G4LogicalVolume* GetDetectorLogicalVolume(){ return detectorLogicalVolume;}
0168     
0169 private:
0170     static HadrontherapyDetectorConstruction* instance;
0171     HadrontherapyDetectorMessenger* detectorMessenger;
0172     
0173     G4VisAttributes* skyBlue;
0174     G4VisAttributes* red;
0175     
0176     HadrontherapyDetectorROGeometry* detectorROGeometry; // Pointer to ROGeometry
0177     HadrontherapyMatrix*             matrix;
0178     HadrontherapyLet*                let;
0179     
0180     G4Box *phantom , *detector;
0181     G4LogicalVolume *phantomLogicalVolume, *detectorLogicalVolume;
0182     G4VPhysicalVolume *phantomPhysicalVolume, *detectorPhysicalVolume;
0183     
0184     G4Box* solidVirtualLayer;
0185     G4LogicalVolume* logicVirtualLayer;
0186     G4VPhysicalVolume*  physVirtualLayer;
0187     
0188     G4double phantomSizeX;
0189     G4double phantomSizeY;
0190     G4double phantomSizeZ;
0191     
0192     G4double detectorSizeX;
0193     G4double detectorSizeY;
0194     G4double detectorSizeZ;
0195     
0196     G4ThreeVector phantomPosition, detectorPosition, detectorToPhantomPosition; //  phantom center, detector center, detector to phantom relative position
0197     
0198     G4double sizeOfVoxelAlongX;
0199     G4double sizeOfVoxelAlongY;
0200     G4double sizeOfVoxelAlongZ;
0201     
0202     G4int numberOfVoxelsAlongX;
0203     G4int numberOfVoxelsAlongY;
0204     G4int numberOfVoxelsAlongZ;
0205     
0206     G4double volumeOfVoxel, massOfVoxel;
0207     
0208     G4Material *phantomMaterial, *detectorMaterial;
0209     G4Region* aRegion;
0210 };
0211 #endif