Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:44

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 /// \file medical/DICOM/include/DicomDetectorConstruction.hh
0028 /// \brief Definition of the DicomDetectorConstruction class
0029 //
0030 
0031 #ifndef DicomDetectorConstruction_h
0032 #define DicomDetectorConstruction_h 1
0033 
0034 #include "DicomPhantomZSliceHeader.hh"
0035 
0036 #include "G4ThreeVector.hh"
0037 #include "G4VUserDetectorConstruction.hh"
0038 #include "globals.hh"
0039 
0040 #include <map>
0041 #include <set>
0042 
0043 class G4Material;
0044 class G4Box;
0045 class G4LogicalVolume;
0046 class DicomPhantomZSliceMerged;
0047 
0048 //*******************************************************
0049 /// Dicom detector construction
0050 ///
0051 ///      - Start the building of the geometry
0052 ///      - Initialisation of materials
0053 ///      - Creation of the world
0054 ///      - Reading of the DICOM data
0055 ///
0056 /// History: 30.11.07  First version
0057 /// \author  P. Arce
0058 //*******************************************************
0059 
0060 struct matInfo
0061 {
0062     G4double fSumdens;
0063     G4int fNvoxels;
0064     G4int fId;
0065 };
0066 
0067 class DicomDetectorConstruction : public G4VUserDetectorConstruction
0068 {
0069   public:
0070     DicomDetectorConstruction();
0071     ~DicomDetectorConstruction();
0072 
0073     virtual G4VPhysicalVolume* Construct();
0074     // trigger the construction of the geometry
0075 
0076     G4int GetTotalVoxels() const;
0077 
0078   protected:
0079     void InitialisationOfMaterials();
0080     // create the original materials
0081 
0082     void ReadPhantomData();
0083     void ReadPhantomDataNew();
0084     // read the DICOM files describing the phantom
0085     void ReadVoxelDensities(std::ifstream& fin);
0086 
0087     void ReadPhantomDataFile(const G4String& fname);
0088     // read one of the DICOM files describing the phantom
0089     // (usually one per Z slice).
0090     //  Build a DicomPhantomZSliceHeader for each file
0091 
0092     void MergeZSliceHeaders();
0093     // merge the slice headers of all the files
0094 
0095     G4Material* BuildMaterialWithChangingDensity(const G4Material* origMate, G4float density,
0096                                                  G4String newMateName);
0097     // build a new material if the density of the voxel is different
0098     // to the other voxels
0099 
0100     void ConstructPhantomContainer();
0101     void ConstructPhantomContainerNew();
0102     virtual void ConstructPhantom() = 0;
0103     // construct the phantom volumes.
0104     //  This method should be implemented for each of the derived classes
0105 
0106     void SetScorer(G4LogicalVolume* voxel_logic);
0107 
0108     virtual void ConstructSDandField();
0109 
0110   protected:
0111     G4Material* fAir;
0112 
0113     // World ...
0114     G4Box* fWorld_solid;
0115     G4LogicalVolume* fWorld_logic;
0116     G4VPhysicalVolume* fWorld_phys;
0117 
0118     G4Box* fContainer_solid;
0119     G4LogicalVolume* fContainer_logic;
0120     G4VPhysicalVolume* fContainer_phys;
0121 
0122     G4int fNoFiles;  // number of DICOM files
0123     std::vector<G4Material*> fOriginalMaterials;  // list of original materials
0124     std::vector<G4Material*> fMaterials;
0125     // list of new materials created to distinguish different density
0126     //  voxels that have the same original materials
0127     size_t* fMateIDs;  // index of material of each voxel
0128     // unsigned int* fMateIDs; // index of material of each voxel
0129 
0130     std::map<G4int, G4double> fDensityDiffs;
0131     // Density difference to distinguish material for each original
0132     // material (by index)
0133 
0134     std::vector<DicomPhantomZSliceHeader*> fZSliceHeaders;
0135     // list of z slice header (one per DICOM files)
0136     DicomPhantomZSliceHeader* fZSliceHeaderMerged;
0137     // z slice header resulted from merging all z slice headers
0138 
0139     G4int fNoVoxelsX, fNoVoxelsY, fNoVoxelsZ;
0140     G4double fVoxelHalfDimX, fVoxelHalfDimY, fVoxelHalfDimZ;
0141     G4double fMinX, fMinY, fMinZ;  // minimum extension of voxels (position wall)
0142     G4double fMaxX, fMaxY, fMaxZ;  // maximum extension of voxels (position wall)
0143 
0144     std::map<G4int, G4Material*> fPhantomMaterialsOriginal;
0145     // map numberOfMaterial to G4Material. They are the list of materials as
0146     // built from .geom file
0147 
0148     DicomPhantomZSliceMerged* fMergedSlices;
0149 
0150     std::set<G4LogicalVolume*> fScorers;
0151 
0152     G4bool fConstructed;
0153 };
0154 
0155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0156 
0157 inline G4int DicomDetectorConstruction::GetTotalVoxels() const
0158 {
0159   return fNoVoxelsX * fNoVoxelsY * fNoVoxelsZ;
0160 }
0161 
0162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0163 
0164 #endif