Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/examples/extended/medical/DICOM/src/DicomDetectorConstruction.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/extended/medical/DICOM/src/DicomDetectorConstruction.cc (Version 11.3.0) and /examples/extended/medical/DICOM/src/DicomDetectorConstruction.cc (Version 9.4.p2)


  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 //                                             << 
 27 /// \file  medical/DICOM/src/DicomDetectorCons << 
 28 /// \brief Implementation of the DicomDetector << 
 29 //                                             << 
 30                                                    26 
 31 #include "DicomDetectorConstruction.hh"        <<  27 #include "globals.hh"
 32                                                << 
 33 #include "CLHEP/Units/SystemOfUnits.h"         << 
 34 #include "DicomHandler.hh"                     << 
 35 #include "DicomPhantomZSliceHeader.hh"         << 
 36                                                    28 
 37 #include "G4Box.hh"                                29 #include "G4Box.hh"
 38 #include "G4Element.hh"                        << 
 39 #include "G4LogicalVolume.hh"                      30 #include "G4LogicalVolume.hh"
 40 #include "G4Material.hh"                       <<  31 #include "G4VPhysicalVolume.hh"
 41 #include "G4NistManager.hh"                    << 
 42 #include "G4PVPlacement.hh"                        32 #include "G4PVPlacement.hh"
 43 #include "G4PhysicalConstants.hh"              <<  33 #include "G4Material.hh"
                                                   >>  34 #include "G4Element.hh"
 44 #include "G4UIcommand.hh"                          35 #include "G4UIcommand.hh"
 45 #include "G4VPhysicalVolume.hh"                << 
 46 #include "globals.hh"                          << 
 47                                                << 
 48 #ifdef G4_DCMTK                                << 
 49 #  include "DicomFileMgr.hh"                   << 
 50 #endif                                         << 
 51 #include "G4VisAttributes.hh"                  << 
 52                                                    36 
 53 using CLHEP::cm3;                              <<  37 #include "DicomDetectorConstruction.hh"
 54 using CLHEP::g;                                <<  38 #include "DicomPhantomZSliceHeader.hh"
 55 using CLHEP::m;                                << 
 56 using CLHEP::mg;                               << 
 57 using CLHEP::mole;                             << 
 58 using CLHEP::perCent;                          << 
 59                                                    39 
 60 //....oooOO0OOooo........oooOO0OOooo........oo <<  40 //-------------------------------------------------------------
 61 DicomDetectorConstruction::DicomDetectorConstr     41 DicomDetectorConstruction::DicomDetectorConstruction()
 62   : G4VUserDetectorConstruction(),             <<  42 {
 63     fAir(0),                                   <<  43 }
 64                                                << 
 65     fWorld_solid(0),                           << 
 66     fWorld_logic(0),                           << 
 67     fWorld_phys(0),                            << 
 68                                                << 
 69     fContainer_solid(0),                       << 
 70     fContainer_logic(0),                       << 
 71     fContainer_phys(0),                        << 
 72                                                << 
 73     fNoFiles(0),                               << 
 74     fMateIDs(0),                               << 
 75                                                << 
 76     fZSliceHeaderMerged(0),                    << 
 77                                                << 
 78     fNoVoxelsX(0),                             << 
 79     fNoVoxelsY(0),                             << 
 80     fNoVoxelsZ(0),                             << 
 81     fVoxelHalfDimX(0),                         << 
 82     fVoxelHalfDimY(0),                         << 
 83     fVoxelHalfDimZ(0),                         << 
 84                                                << 
 85     fConstructed(false)                        << 
 86 {}                                             << 
 87                                                    44 
 88 //....oooOO0OOooo........oooOO0OOooo........oo <<  45 //-------------------------------------------------------------
 89 DicomDetectorConstruction::~DicomDetectorConst <<  46 DicomDetectorConstruction::~DicomDetectorConstruction()
                                                   >>  47 {
                                                   >>  48 }
 90                                                    49 
 91 //....oooOO0OOooo........oooOO0OOooo........oo <<  50 //-------------------------------------------------------------
 92 G4VPhysicalVolume* DicomDetectorConstruction::     51 G4VPhysicalVolume* DicomDetectorConstruction::Construct()
 93 {                                                  52 {
 94   if (!fConstructed || fWorld_phys == 0) {     <<  53   InitialisationOfMaterials();
 95     fConstructed = true;                       << 
 96     InitialisationOfMaterials();               << 
 97                                                    54 
 98     //----- Build world                        <<  55   //----- Build world
 99     G4double worldXDimension = 1. * m;         <<  56   G4double worldXDimension = 1.*m;
100     G4double worldYDimension = 1. * m;         <<  57   G4double worldYDimension = 1.*m;
101     G4double worldZDimension = 1. * m;         <<  58   G4double worldZDimension = 1.*m;
102                                                    59 
103     fWorld_solid = new G4Box("WorldSolid", wor <<  60   world_solid = new G4Box( "WorldSolid",
                                                   >>  61                           worldXDimension,
                                                   >>  62                           worldYDimension,
                                                   >>  63                           worldZDimension );
104                                                    64 
105     fWorld_logic = new G4LogicalVolume(fWorld_ <<  65   world_logic = new G4LogicalVolume( world_solid, 
                                                   >>  66                                     air, 
                                                   >>  67                                     "WorldLogical", 
                                                   >>  68                                     0, 0, 0 );
106                                                    69 
107     fWorld_phys = new G4PVPlacement(0, G4Three <<  70   world_phys = new G4PVPlacement( 0,
                                                   >>  71                                   G4ThreeVector(0,0,0),
                                                   >>  72                                   "World",
                                                   >>  73                                   world_logic,
                                                   >>  74                                   0,
                                                   >>  75                                   false,
                                                   >>  76                                   0 );
108                                                    77 
109     fWorld_logic->SetVisAttributes(G4VisAttrib <<  78   ReadPhantomData();
110                                                    79 
111 #ifdef G4_DCMTK                                <<  80   ConstructPhantomContainer();
112     ReadPhantomDataNew();                      <<  81   ConstructPhantom();
113     ConstructPhantomContainerNew();            << 
114 #else                                          << 
115     ReadPhantomData();                         << 
116     ConstructPhantomContainer();               << 
117 #endif                                         << 
118                                                    82 
119     ConstructPhantom();                        <<  83   return world_phys;
120   }                                            << 
121   return fWorld_phys;                          << 
122 }                                                  84 }
123                                                    85 
124 //....oooOO0OOooo........oooOO0OOooo........oo <<  86 
                                                   >>  87 //-------------------------------------------------------------
125 void DicomDetectorConstruction::Initialisation     88 void DicomDetectorConstruction::InitialisationOfMaterials()
126 {                                                  89 {
127   // Creating elements :                           90   // Creating elements :
128   G4double z, a, density;                          91   G4double z, a, density;
129   G4String name, symbol;                           92   G4String name, symbol;
130                                                    93 
131   G4Element* elC = new G4Element(name = "Carbo <<  94   G4Element* elC = new G4Element( name = "Carbon",
132   G4Element* elH = new G4Element(name = "Hydro <<  95                                   symbol = "C",
133   G4Element* elN = new G4Element(name = "Nitro <<  96                                   z = 6.0, a = 12.011 * g/mole );
134   G4Element* elO = new G4Element(name = "Oxyge <<  97   G4Element* elH = new G4Element( name = "Hydrogen",
135   G4Element* elNa =                            <<  98           symbol = "H",
136     new G4Element(name = "Sodium", symbol = "N <<  99           z = 1.0, a = 1.008  * g/mole );
137   G4Element* elMg =                            << 100   G4Element* elN = new G4Element( name = "Nitrogen",
138     new G4Element(name = "Magnesium", symbol = << 101           symbol = "N",
139   G4Element* elP =                             << 102           z = 7.0, a = 14.007 * g/mole );
140     new G4Element(name = "Phosphorus", symbol  << 103   G4Element* elO = new G4Element( name = "Oxygen",
141   G4Element* elS = new G4Element(name = "Sulfu << 104                                   symbol = "O",
142   G4Element* elCl =                            << 105                                   z = 8.0, a = 16.00  * g/mole );
143     new G4Element(name = "Chlorine", symbol =  << 106   G4Element* elNa = new G4Element( name = "Sodium",
144   G4Element* elK =                             << 107                                    symbol = "Na",
145     new G4Element(name = "Potassium", symbol = << 108                                    z= 11.0, a = 22.98977* g/mole );
146                                                << 109   G4Element* elS = new G4Element( name = "Sulfur",
147   G4Element* elFe = new G4Element(name = "Iron << 110                                   symbol = "S",
148                                                << 111                                   z = 16.0,a = 32.065* g/mole );
149   G4Element* elCa = new G4Element(name = "Calc << 112   G4Element* elCl = new G4Element( name = "Chlorine",
150                                                << 113                                    symbol = "P",
151   G4Element* elZn = new G4Element(name = "Zinc << 114                                    z = 17.0, a = 35.453* g/mole );
                                                   >> 115   G4Element* elK = new G4Element( name = "Potassium",
                                                   >> 116                                   symbol = "P",
                                                   >> 117                                   z = 19.0, a = 30.0983* g/mole );
                                                   >> 118   G4Element* elP = new G4Element( name = "Phosphorus",
                                                   >> 119                                   symbol = "P",
                                                   >> 120                                   z = 30.0, a = 30.973976* g/mole );
                                                   >> 121   G4Element* elFe = new G4Element( name = "Iron",
                                                   >> 122                                    symbol = "Fe",
                                                   >> 123                                    z = 26, a = 56.845* g/mole );
                                                   >> 124   G4Element* elMg = new G4Element( name = "Magnesium",
                                                   >> 125                                    symbol = "Mg",
                                                   >> 126                                    z = 12.0, a = 24.3050* g/mole );
                                                   >> 127   G4Element* elCa = new G4Element( name="Calcium",
                                                   >> 128                                    symbol = "Ca",
                                                   >> 129                                    z = 20.0, a = 40.078* g/mole );
152                                                   130 
153   // Creating Materials :                         131   // Creating Materials :
154   G4int numberofElements;                         132   G4int numberofElements;
155                                                   133 
156   // Air                                          134   // Air
157   fAir = new G4Material("Air", 1.290 * mg / cm << 135   air = new G4Material( "Air",
158   fAir->AddElement(elN, 0.7);                  << 136                         1.290*mg/cm3,
159   fAir->AddElement(elO, 0.3);                  << 137                         numberofElements = 2 );
160                                                << 138   air->AddElement(elN, 0.7);
161   // Soft tissue (ICRP - NIST)                 << 139   air->AddElement(elO, 0.3); 
162   G4Material* softTissue = new G4Material("Sof << 
163   softTissue->AddElement(elH, 10.4472 * perCen << 
164   softTissue->AddElement(elC, 23.219 * perCent << 
165   softTissue->AddElement(elN, 2.488 * perCent) << 
166   softTissue->AddElement(elO, 63.0238 * perCen << 
167   softTissue->AddElement(elNa, 0.113 * perCent << 
168   softTissue->AddElement(elMg, 0.0113 * perCen << 
169   softTissue->AddElement(elP, 0.113 * perCent) << 
170   softTissue->AddElement(elS, 0.199 * perCent) << 
171   softTissue->AddElement(elCl, 0.134 * perCent << 
172   softTissue->AddElement(elK, 0.199 * perCent) << 
173   softTissue->AddElement(elCa, 0.023 * perCent << 
174   softTissue->AddElement(elFe, 0.005 * perCent << 
175   softTissue->AddElement(elZn, 0.003 * perCent << 
176                                                   140 
177   //  Lung Inhale                                 141   //  Lung Inhale
178   G4Material* lunginhale =                     << 142   G4Material* lunginhale = new G4Material( "LungInhale", 
179     new G4Material("LungInhale", density = 0.2 << 143                                density = 0.217*g/cm3, 
180   lunginhale->AddElement(elH, 0.103);          << 144                                numberofElements = 9);
181   lunginhale->AddElement(elC, 0.105);          << 145   lunginhale->AddElement(elH,0.103);
182   lunginhale->AddElement(elN, 0.031);          << 146   lunginhale->AddElement(elC,0.105);
183   lunginhale->AddElement(elO, 0.749);          << 147   lunginhale->AddElement(elN,0.031);
184   lunginhale->AddElement(elNa, 0.002);         << 148   lunginhale->AddElement(elO,0.749);
185   lunginhale->AddElement(elP, 0.002);          << 149   lunginhale->AddElement(elNa,0.002);
186   lunginhale->AddElement(elS, 0.003);          << 150   lunginhale->AddElement(elP,0.002);
187   lunginhale->AddElement(elCl, 0.002);         << 151   lunginhale->AddElement(elS,0.003);
188   lunginhale->AddElement(elK, 0.003);          << 152   lunginhale->AddElement(elCl,0.002);
                                                   >> 153   lunginhale->AddElement(elK,0.003);
189                                                   154 
190   // Lung exhale                                  155   // Lung exhale
191   G4Material* lungexhale =                     << 156   G4Material* lungexhale = new G4Material( "LungExhale", 
192     new G4Material("LungExhale", density = 0.5 << 157                                density = 0.508*g/cm3, 
193   lungexhale->AddElement(elH, 0.103);          << 158                                numberofElements = 9 );
194   lungexhale->AddElement(elC, 0.105);          << 159   lungexhale->AddElement(elH,0.103);
195   lungexhale->AddElement(elN, 0.031);          << 160   lungexhale->AddElement(elC,0.105);
196   lungexhale->AddElement(elO, 0.749);          << 161   lungexhale->AddElement(elN,0.031);
197   lungexhale->AddElement(elNa, 0.002);         << 162   lungexhale->AddElement(elO,0.749);
198   lungexhale->AddElement(elP, 0.002);          << 163   lungexhale->AddElement(elNa,0.002);
199   lungexhale->AddElement(elS, 0.003);          << 164   lungexhale->AddElement(elP,0.002);
200   lungexhale->AddElement(elCl, 0.002);         << 165   lungexhale->AddElement(elS,0.003);
201   lungexhale->AddElement(elK, 0.003);          << 166   lungexhale->AddElement(elCl,0.002);
                                                   >> 167   lungexhale->AddElement(elK,0.003);
202                                                   168 
203   // Adipose tissue                               169   // Adipose tissue
204   G4Material* adiposeTissue =                  << 170   G4Material* adiposeTissue = new G4Material( "AdiposeTissue", 
205     new G4Material("AdiposeTissue", density =  << 171                                   density = 0.967*g/cm3, 
206   adiposeTissue->AddElement(elH, 0.114);       << 172                                   numberofElements = 7);
207   adiposeTissue->AddElement(elC, 0.598);       << 173   adiposeTissue->AddElement(elH,0.114);
208   adiposeTissue->AddElement(elN, 0.007);       << 174   adiposeTissue->AddElement(elC,0.598);
209   adiposeTissue->AddElement(elO, 0.278);       << 175   adiposeTissue->AddElement(elN,0.007);
210   adiposeTissue->AddElement(elNa, 0.001);      << 176   adiposeTissue->AddElement(elO,0.278);
211   adiposeTissue->AddElement(elS, 0.001);       << 177   adiposeTissue->AddElement(elNa,0.001);
212   adiposeTissue->AddElement(elCl, 0.001);      << 178   adiposeTissue->AddElement(elS,0.001);
213                                                << 179   adiposeTissue->AddElement(elCl,0.001);
214   // Brain (ICRP - NIST)                       << 
215   G4Material* brainTissue = new G4Material("Br << 
216   brainTissue->AddElement(elH, 11.0667 * perCe << 
217   brainTissue->AddElement(elC, 12.542 * perCen << 
218   brainTissue->AddElement(elN, 1.328 * perCent << 
219   brainTissue->AddElement(elO, 73.7723 * perCe << 
220   brainTissue->AddElement(elNa, 0.1840 * perCe << 
221   brainTissue->AddElement(elMg, 0.015 * perCen << 
222   brainTissue->AddElement(elP, 0.356 * perCent << 
223   brainTissue->AddElement(elS, 0.177 * perCent << 
224   brainTissue->AddElement(elCl, 0.236 * perCen << 
225   brainTissue->AddElement(elK, 0.31 * perCent) << 
226   brainTissue->AddElement(elCa, 0.009 * perCen << 
227   brainTissue->AddElement(elFe, 0.005 * perCen << 
228   brainTissue->AddElement(elZn, 0.001 * perCen << 
229                                                   180 
230   // Breast                                       181   // Breast
231   G4Material* breast = new G4Material("Breast" << 182   G4Material* breast = new G4Material( "Breast", 
232   breast->AddElement(elH, 0.109);              << 183                            density = 0.990*g/cm3, 
233   breast->AddElement(elC, 0.506);              << 184                            numberofElements = 8 );
234   breast->AddElement(elN, 0.023);              << 185   breast->AddElement(elH,0.109);
235   breast->AddElement(elO, 0.358);              << 186   breast->AddElement(elC,0.506);
236   breast->AddElement(elNa, 0.001);             << 187   breast->AddElement(elN,0.023);
237   breast->AddElement(elP, 0.001);              << 188   breast->AddElement(elO,0.358);
238   breast->AddElement(elS, 0.001);              << 189   breast->AddElement(elNa,0.001);
239   breast->AddElement(elCl, 0.001);             << 190   breast->AddElement(elP,0.001);
240                                                << 191   breast->AddElement(elS,0.001);
241   // Spinal Disc                               << 192   breast->AddElement(elCl,0.001); 
242   G4Material* spinalDisc = new G4Material("Spi << 193 
243   spinalDisc->AddElement(elH, 9.60 * perCent); << 194    // Water
244   spinalDisc->AddElement(elC, 9.90 * perCent); << 195   G4Material* water = new G4Material( "Water", 
245   spinalDisc->AddElement(elN, 2.20 * perCent); << 196                             density = 1.0*g/cm3, 
246   spinalDisc->AddElement(elO, 74.40 * perCent) << 197                             numberofElements = 2 );
247   spinalDisc->AddElement(elNa, 0.50 * perCent) << 198   water->AddElement(elH,0.112);
248   spinalDisc->AddElement(elP, 2.20 * perCent); << 199   water->AddElement(elO,0.888);     
249   spinalDisc->AddElement(elS, 0.90 * perCent); << 
250   spinalDisc->AddElement(elCl, 0.30 * perCent) << 
251                                                << 
252   // Water                                     << 
253   G4Material* water = new G4Material("Water",  << 
254   water->AddElement(elH, 0.112);               << 
255   water->AddElement(elO, 0.888);               << 
256                                                   200 
257   // Muscle                                       201   // Muscle
258   G4Material* muscle = new G4Material("Muscle" << 202   G4Material* muscle = new G4Material( "Muscle", 
259   muscle->AddElement(elH, 0.102);              << 203                            density = 1.061*g/cm3, 
260   muscle->AddElement(elC, 0.143);              << 204                            numberofElements = 9 );
261   muscle->AddElement(elN, 0.034);              << 205   muscle->AddElement(elH,0.102);
262   muscle->AddElement(elO, 0.710);              << 206   muscle->AddElement(elC,0.143);
263   muscle->AddElement(elNa, 0.001);             << 207   muscle->AddElement(elN,0.034);
264   muscle->AddElement(elP, 0.002);              << 208   muscle->AddElement(elO,0.710);
265   muscle->AddElement(elS, 0.003);              << 209   muscle->AddElement(elNa,0.001);
266   muscle->AddElement(elCl, 0.001);             << 210   muscle->AddElement(elP,0.002);
267   muscle->AddElement(elK, 0.004);              << 211   muscle->AddElement(elS,0.003);
                                                   >> 212   muscle->AddElement(elCl,0.001);
                                                   >> 213   muscle->AddElement(elK,0.004);       
268                                                   214 
269   // Liver                                        215   // Liver
270   G4Material* liver = new G4Material("Liver",  << 216   G4Material* liver = new G4Material( "Liver", 
271   liver->AddElement(elH, 0.102);               << 217                           density = 1.071*g/cm3, 
272   liver->AddElement(elC, 0.139);               << 218                           numberofElements = 9);
273   liver->AddElement(elN, 0.030);               << 219   liver->AddElement(elH,0.102);
274   liver->AddElement(elO, 0.716);               << 220   liver->AddElement(elC,0.139);
275   liver->AddElement(elNa, 0.002);              << 221   liver->AddElement(elN,0.030);
276   liver->AddElement(elP, 0.003);               << 222   liver->AddElement(elO,0.716);
277   liver->AddElement(elS, 0.003);               << 223   liver->AddElement(elNa,0.002);
278   liver->AddElement(elCl, 0.002);              << 224   liver->AddElement(elP,0.003);
279   liver->AddElement(elK, 0.003);               << 225   liver->AddElement(elS,0.003);
280                                                << 226   liver->AddElement(elCl,0.002);
281   // Tooth Dentin                              << 227   liver->AddElement(elK,0.003); 
282   G4Material* toothDentin = new G4Material("To << 228  
283   toothDentin->AddElement(elH, 2.67 * perCent) << 229   // Trabecular Bone 
284   toothDentin->AddElement(elC, 12.77 * perCent << 230   G4Material* trabecularBone = new G4Material( "TrabecularBone", 
285   toothDentin->AddElement(elN, 4.27 * perCent) << 231            density = 1.159*g/cm3, 
286   toothDentin->AddElement(elO, 40.40 * perCent << 232            numberofElements = 12 );
287   toothDentin->AddElement(elNa, 0.65 * perCent << 233   trabecularBone->AddElement(elH,0.085);
288   toothDentin->AddElement(elMg, 0.59 * perCent << 234   trabecularBone->AddElement(elC,0.404);
289   toothDentin->AddElement(elP, 11.86 * perCent << 235   trabecularBone->AddElement(elN,0.058);
290   toothDentin->AddElement(elCl, 0.04 * perCent << 236   trabecularBone->AddElement(elO,0.367);
291   toothDentin->AddElement(elCa, 26.74 * perCen << 237   trabecularBone->AddElement(elNa,0.001);
292   toothDentin->AddElement(elZn, 0.01 * perCent << 238   trabecularBone->AddElement(elMg,0.001);
293                                                << 239   trabecularBone->AddElement(elP,0.034);
294   // Trabecular Bone                           << 240   trabecularBone->AddElement(elS,0.002);
295   G4Material* trabecularBone =                 << 241   trabecularBone->AddElement(elCl,0.002);
296     new G4Material("TrabecularBone", density = << 242   trabecularBone->AddElement(elK,0.001);
297   trabecularBone->AddElement(elH, 0.085);      << 243   trabecularBone->AddElement(elCa,0.044);
298   trabecularBone->AddElement(elC, 0.404);      << 244   trabecularBone->AddElement(elFe,0.001);
299   trabecularBone->AddElement(elN, 0.058);      << 245   
300   trabecularBone->AddElement(elO, 0.367);      << 
301   trabecularBone->AddElement(elNa, 0.001);     << 
302   trabecularBone->AddElement(elMg, 0.001);     << 
303   trabecularBone->AddElement(elP, 0.034);      << 
304   trabecularBone->AddElement(elS, 0.002);      << 
305   trabecularBone->AddElement(elCl, 0.002);     << 
306   trabecularBone->AddElement(elK, 0.001);      << 
307   trabecularBone->AddElement(elCa, 0.044);     << 
308   trabecularBone->AddElement(elFe, 0.001);     << 
309                                                << 
310   // Trabecular bone used in the DICOM Head    << 
311                                                << 
312   G4Material* trabecularBone_head =            << 
313     new G4Material("TrabecularBone_HEAD", 1.18 << 
314   trabecularBone_head->AddElement(elH, 8.50 *  << 
315   trabecularBone_head->AddElement(elC, 40.40 * << 
316   trabecularBone_head->AddElement(elN, 2.80 *  << 
317   trabecularBone_head->AddElement(elO, 36.70 * << 
318   trabecularBone_head->AddElement(elNa, 0.10 * << 
319   trabecularBone_head->AddElement(elMg, 0.10 * << 
320   trabecularBone_head->AddElement(elP, 3.40 *  << 
321   trabecularBone_head->AddElement(elS, 0.20 *  << 
322   trabecularBone_head->AddElement(elCl, 0.20 * << 
323   trabecularBone_head->AddElement(elK, 0.10 *  << 
324   trabecularBone_head->AddElement(elCa, 7.40 * << 
325   trabecularBone_head->AddElement(elFe, 0.10 * << 
326                                                << 
327   // Dense Bone                                   246   // Dense Bone
328   G4Material* denseBone =                      << 247   G4Material* denseBone = new G4Material( "DenseBone", 
329     new G4Material("DenseBone", density = 1.57 << 248                               density = 1.575*g/cm3, 
330   denseBone->AddElement(elH, 0.056);           << 249                               numberofElements = 11 );
331   denseBone->AddElement(elC, 0.235);           << 250   denseBone->AddElement(elH,0.056);
332   denseBone->AddElement(elN, 0.050);           << 251   denseBone->AddElement(elC,0.235);
333   denseBone->AddElement(elO, 0.434);           << 252   denseBone->AddElement(elN,0.050);
334   denseBone->AddElement(elNa, 0.001);          << 253   denseBone->AddElement(elO,0.434);
335   denseBone->AddElement(elMg, 0.001);          << 254   denseBone->AddElement(elNa,0.001);
336   denseBone->AddElement(elP, 0.072);           << 255   denseBone->AddElement(elMg,0.001);
337   denseBone->AddElement(elS, 0.003);           << 256   denseBone->AddElement(elP,0.072);
338   denseBone->AddElement(elCl, 0.001);          << 257   denseBone->AddElement(elS,0.003);
339   denseBone->AddElement(elK, 0.001);           << 258   denseBone->AddElement(elCl,0.001);
340   denseBone->AddElement(elCa, 0.146);          << 259   denseBone->AddElement(elK,0.001);
341                                                << 260   denseBone->AddElement(elCa,0.146);
342   // Cortical Bone (ICRP - NIST)               << 261   
343   G4Material* corticalBone = new G4Material("C << 262   //----- Put the materials in a vector
344   corticalBone->AddElement(elH, 4.7234 * perCe << 263   fOriginalMaterials.push_back(air); // rho = 0.00129
345   corticalBone->AddElement(elC, 14.4330 * perC << 264   fOriginalMaterials.push_back(lunginhale); // rho = 0.217
346   corticalBone->AddElement(elN, 4.199 * perCen << 265   fOriginalMaterials.push_back(lungexhale); // rho = 0.508
347   corticalBone->AddElement(elO, 44.6096 * perC << 266   fOriginalMaterials.push_back(adiposeTissue); // rho = 0.967
348   corticalBone->AddElement(elMg, 0.22 * perCen << 267   fOriginalMaterials.push_back(breast ); // rho = 0.990
349   corticalBone->AddElement(elP, 10.497 * perCe << 268   fOriginalMaterials.push_back(water); // rho = 1.018
350   corticalBone->AddElement(elS, 0.315 * perCen << 269   fOriginalMaterials.push_back(muscle); // rho = 1.061
351   corticalBone->AddElement(elCa, 20.993 * perC << 270   fOriginalMaterials.push_back(liver); // rho = 1.071
352   corticalBone->AddElement(elZn, 0.01 * perCen << 271   fOriginalMaterials.push_back(trabecularBone); // rho = 1.159
353                                                << 272   fOriginalMaterials.push_back(denseBone); // rho = 1.575
354   // Tooth enamel                              << 
355   G4Material* toothEnamel = new G4Material("To << 
356   toothEnamel->AddElement(elH, 0.95 * perCent) << 
357   toothEnamel->AddElement(elC, 1.11 * perCent) << 
358   toothEnamel->AddElement(elN, 0.23 * perCent) << 
359   toothEnamel->AddElement(elO, 41.66 * perCent << 
360   toothEnamel->AddElement(elNa, 0.79 * perCent << 
361   toothEnamel->AddElement(elMg, 0.23 * perCent << 
362   toothEnamel->AddElement(elP, 18.71 * perCent << 
363   toothEnamel->AddElement(elCl, 0.34 * perCent << 
364   toothEnamel->AddElement(elCa, 35.97 * perCen << 
365   toothEnamel->AddElement(elZn, 0.02 * perCent << 
366                                                << 
367 #ifdef DICOM_USE_HEAD                          << 
368   //----- Put the materials in a vector HEAD P << 
369   fOriginalMaterials.push_back(fAir);  // 0.00 << 
370   fOriginalMaterials.push_back(softTissue);  / << 
371   fOriginalMaterials.push_back(brainTissue);   << 
372   fOriginalMaterials.push_back(spinalDisc);  / << 
373   fOriginalMaterials.push_back(trabecularBone_ << 
374   fOriginalMaterials.push_back(toothDentin);   << 
375   fOriginalMaterials.push_back(corticalBone);  << 
376   fOriginalMaterials.push_back(toothEnamel);   << 
377   G4cout << "The materials of the DICOM Head h << 
378 #else                                          << 
379   fOriginalMaterials.push_back(fAir);  // rho  << 
380   fOriginalMaterials.push_back(lunginhale);  / << 
381   fOriginalMaterials.push_back(lungexhale);  / << 
382   fOriginalMaterials.push_back(adiposeTissue); << 
383   fOriginalMaterials.push_back(breast);  // rh << 
384   fOriginalMaterials.push_back(water);  // rho << 
385   fOriginalMaterials.push_back(muscle);  // rh << 
386   fOriginalMaterials.push_back(liver);  // rho << 
387   fOriginalMaterials.push_back(trabecularBone) << 
388   fOriginalMaterials.push_back(denseBone);  // << 
389   G4cout << "Default materials of the DICOM Ex << 
390 #endif                                         << 
391 }                                              << 
392                                                << 
393 //....oooOO0OOooo........oooOO0OOooo........oo << 
394 void DicomDetectorConstruction::ReadPhantomDat << 
395 {                                              << 
396 #ifdef G4_DCMTK                                << 
397   G4String fileName = DicomFileMgr::GetInstanc << 
398                                                << 
399   std::ifstream fin(fileName);                 << 
400   std::vector<G4String> wl;                    << 
401   G4int nMaterials;                            << 
402   fin >> nMaterials;                           << 
403   G4String mateName;                           << 
404   G4int nmate;                                 << 
405   for (G4int ii = 0; ii < nMaterials; ++ii) {  << 
406     fin >> nmate;                              << 
407     fin >> mateName;                           << 
408     if (mateName[0] == '"' && mateName[mateNam << 
409       mateName = mateName.substr(1, mateName.l << 
410     }                                          << 
411     G4cout << "GmReadPhantomG4Geometry::ReadPh << 
412            << " mate " << mateName << G4endl;  << 
413     if (ii != nmate)                           << 
414       G4Exception("GmReadPhantomG4Geometry::Re << 
415                   FatalErrorInArgument,        << 
416                   "Material number should be i << 
417                                                << 
418     G4Material* mate = 0;                      << 
419     const G4MaterialTable* matTab = G4Material << 
420     for (auto matite = matTab->cbegin(); matit << 
421       if ((*matite)->GetName() == mateName) {  << 
422         mate = *matite;                        << 
423       }                                        << 
424     }                                          << 
425     if (mate == 0) {                           << 
426       mate = G4NistManager::Instance()->FindOr << 
427     }                                          << 
428     if (!mate)                                 << 
429       G4Exception("GmReadPhantomG4Geometry::Re << 
430                   FatalErrorInArgument, ("Mate << 
431     fPhantomMaterialsOriginal[nmate] = mate;   << 
432   }                                            << 
433                                                << 
434   fin >> fNoVoxelsX >> fNoVoxelsY >> fNoVoxels << 
435   G4cout << "GmReadPhantomG4Geometry::ReadPhan << 
436          << fNoVoxelsY << " " << fNoVoxelsZ << << 
437   fin >> fMinX >> fMaxX;                       << 
438   fin >> fMinY >> fMaxY;                       << 
439   fin >> fMinZ >> fMaxZ;                       << 
440   fVoxelHalfDimX = (fMaxX - fMinX) / fNoVoxels << 
441   fVoxelHalfDimY = (fMaxY - fMinY) / fNoVoxels << 
442   fVoxelHalfDimZ = (fMaxZ - fMinZ) / fNoVoxels << 
443 #  ifdef G4VERBOSE                             << 
444   G4cout << " Extension in X " << fMinX << " " << 
445          << " " << fMaxY << G4endl << " Extens << 
446 #  endif                                       << 
447                                                << 
448   fMateIDs = new size_t[fNoVoxelsX * fNoVoxels << 
449   for (G4int iz = 0; iz < fNoVoxelsZ; ++iz) {  << 
450     for (G4int iy = 0; iy < fNoVoxelsY; ++iy)  << 
451       for (G4int ix = 0; ix < fNoVoxelsX; ++ix << 
452         G4int mateID;                          << 
453         fin >> mateID;                         << 
454         G4int nnew = ix + (iy)*fNoVoxelsX + (i << 
455         if (mateID < 0 || mateID >= nMaterials << 
456           G4Exception("GmReadPhantomG4Geometry << 
457                       FatalException,          << 
458                       G4String("It should be b << 
459                                + G4UIcommand:: << 
460                                + G4UIcommand:: << 
461                         .c_str());             << 
462         }                                      << 
463         fMateIDs[nnew] = mateID;               << 
464       }                                        << 
465     }                                          << 
466   }                                            << 
467                                                   273 
468   ReadVoxelDensities(fin);                     << 
469                                                << 
470   fin.close();                                 << 
471 #endif                                         << 
472 }                                                 274 }
473                                                   275 
474 //....oooOO0OOooo........oooOO0OOooo........oo << 
475 void DicomDetectorConstruction::ReadVoxelDensi << 
476 {                                              << 
477   G4String stemp;                              << 
478   std::map<G4int, std::pair<G4double, G4double << 
479   std::map<G4int, std::pair<G4double, G4double << 
480   for (G4int ii = 0; ii < G4int(fPhantomMateri << 
481     densiMinMax[ii] = std::pair<G4double, G4do << 
482   }                                            << 
483                                                << 
484   char* part = std::getenv("DICOM_CHANGE_MATER << 
485   G4double densityDiff = -1.;                  << 
486   if (part) densityDiff = G4UIcommand::Convert << 
487                                                << 
488   std::map<G4int, G4double> densityDiffs;      << 
489   for (G4int ii = 0; ii < G4int(fPhantomMateri << 
490     densityDiffs[ii] = densityDiff;  // curren << 
491   }                                            << 
492   //  densityDiffs[0] = 0.0001; //air          << 
493                                                   276 
494   //--- Calculate the average material density << 277 //-------------------------------------------------------------
495   std::map<std::pair<G4Material*, G4int>, matI << 
496                                                << 
497   //---- Read the material densities           << 
498   G4double dens;                               << 
499   for (G4int iz = 0; iz < fNoVoxelsZ; ++iz) {  << 
500     for (G4int iy = 0; iy < fNoVoxelsY; ++iy)  << 
501       for (G4int ix = 0; ix < fNoVoxelsX; ++ix << 
502         fin >> dens;                           << 
503         G4int copyNo = ix + (iy)*fNoVoxelsX +  << 
504                                                << 
505         if (densityDiff != -1.) continue;      << 
506                                                << 
507         //--- store the minimum and maximum de << 
508         mpite = densiMinMax.find(G4int(fMateID << 
509         if (dens < (*mpite).second.first) (*mp << 
510         if (dens > (*mpite).second.second) (*m << 
511         //--- Get material from original list  << 
512         G4int mateID = G4int(fMateIDs[copyNo]) << 
513         std::map<G4int, G4Material*>::const_it << 
514                                                << 
515         //--- Check if density is equal to the << 
516         if (std::fabs(dens - (*imite).second-> << 
517           continue;                            << 
518                                                << 
519         //--- Build material name with fPhanto << 
520         G4int densityBin = (G4int(dens / densi << 
521                                                << 
522         G4String mateName = (*imite).second->G << 
523         //--- Look if it is the first voxel wi << 
524         std::pair<G4Material*, G4int> matdens( << 
525                                                << 
526         auto mppite = newMateDens.find(matdens << 
527         if (mppite != newMateDens.cend()) {    << 
528           matInfo* mi = (*mppite).second;      << 
529           mi->fSumdens += dens;                << 
530           mi->fNvoxels++;                      << 
531           fMateIDs[copyNo] = fPhantomMaterials << 
532         }                                      << 
533         else {                                 << 
534           matInfo* mi = new matInfo;           << 
535           mi->fSumdens = dens;                 << 
536           mi->fNvoxels = 1;                    << 
537           mi->fId = G4int(newMateDens.size() + << 
538           newMateDens[matdens] = mi;           << 
539           fMateIDs[copyNo] = fPhantomMaterials << 
540         }                                      << 
541       }                                        << 
542     }                                          << 
543   }                                            << 
544                                                << 
545   if (densityDiff != -1.) {                    << 
546     for (mpite = densiMinMax.begin(); mpite != << 
547 #ifdef G4VERBOSE                               << 
548       G4cout << "DicomDetectorConstruction::Re << 
549              << " ORIG MATERIALS DENSITY " <<  << 
550              << " MAX " << (*mpite).second.sec << 
551 #endif                                         << 
552     }                                          << 
553   }                                            << 
554                                                << 
555   //----- Build the list of phantom materials  << 
556   //--- Add original materials                 << 
557   for (auto mimite = fPhantomMaterialsOriginal << 
558        ++mimite)                               << 
559   {                                            << 
560     fMaterials.push_back((*mimite).second);    << 
561   }                                            << 
562   //                                           << 
563   //---- Build and add new materials           << 
564   for (auto mppite = newMateDens.cbegin(); mpp << 
565     G4double averdens = (*mppite).second->fSum << 
566     G4double saverdens = G4int(1000.001 * aver << 
567 #ifndef G4VERBOSE                              << 
568     G4cout << "DicomDetectorConstruction::Read << 
569            << saverdens << " -> " << G4int(100 << 
570            << " " << G4int(1000 * averdens) /  << 
571 #endif                                         << 
572                                                << 
573     G4String mateName =                        << 
574       ((*mppite).first).first->GetName() + "_" << 
575     fMaterials.push_back(                      << 
576       BuildMaterialWithChangingDensity((*mppit << 
577   }                                            << 
578 }                                              << 
579                                                << 
580 //....oooOO0OOooo........oooOO0OOooo........oo << 
581 void DicomDetectorConstruction::ReadPhantomDat    278 void DicomDetectorConstruction::ReadPhantomData()
582 {                                                 279 {
583   G4String dataFile = DicomHandler::GetDicomDa << 280   std::ifstream finDF("Data.dat");
584   std::ifstream finDF(dataFile.c_str());       << 
585   G4String fname;                                 281   G4String fname;
586                                                << 282   if(finDF.good() != 1 ) {
587   if (finDF.good() != 1) {                     << 283     G4Exception(" DicomDetectorConstruction::ReadPhantomData.  Problem reading data file: Data.dat");
588     G4String descript = "Problem reading data  << 
589     G4Exception(" DicomDetectorConstruction::R << 
590   }                                               284   }
591                                                   285 
592   G4int compression;                              286   G4int compression;
593   finDF >> compression;  // not used here      << 287   finDF >> compression; // not used here
594   finDF >> fNoFiles;                           << 
595                                                   288 
596   for (G4int i = 0; i < fNoFiles; ++i) {       << 289   finDF >> fNoFiles;
                                                   >> 290   for(G4int i = 0; i < fNoFiles; i++ ) {    
597     finDF >> fname;                               291     finDF >> fname;
598                                                << 
599     //--- Read one data file                      292     //--- Read one data file
600     fname += ".g4dcm";                            293     fname += ".g4dcm";
601                                                << 
602     ReadPhantomDataFile(fname);                   294     ReadPhantomDataFile(fname);
603   }                                               295   }
604                                                   296 
605   //----- Merge data headers                   << 297   //----- Merge data headers 
606   MergeZSliceHeaders();                           298   MergeZSliceHeaders();
                                                   >> 299 
607   finDF.close();                                  300   finDF.close();
                                                   >> 301 
608 }                                                 302 }
609                                                   303 
610 //....oooOO0OOooo........oooOO0OOooo........oo << 304 //-------------------------------------------------------------
611 void DicomDetectorConstruction::ReadPhantomDat    305 void DicomDetectorConstruction::ReadPhantomDataFile(const G4String& fname)
612 {                                                 306 {
613   G4cout << " DicomDetectorConstruction::ReadP << 
614          << G4endl;  // GDEB                   << 
615                                                << 
616 #ifdef G4VERBOSE                                  307 #ifdef G4VERBOSE
617   G4cout << " DicomDetectorConstruction::ReadP    308   G4cout << " DicomDetectorConstruction::ReadPhantomDataFile opening file " << fname << G4endl;
618 #endif                                         << 309 #endif 
619                                                << 
620   std::ifstream fin(fname.c_str(), std::ios_ba    310   std::ifstream fin(fname.c_str(), std::ios_base::in);
621   if (!fin.is_open()) {                        << 311   if( !fin.is_open() ) {
622     G4Exception("DicomDetectorConstruction::Re << 312     G4Exception("DicomDetectorConstruction::ReadPhantomDataFile. File not found " + fname );
623                 G4String("File not found " + f << 
624   }                                               313   }
625   //----- Define density differences (maximum  << 314   //----- Define density differences (maximum density difference to create a new material)
626   // a new material)                           << 315   char* part = getenv( "DICOM_CHANGE_MATERIAL_DENSITY" );
627   char* part = std::getenv("DICOM_CHANGE_MATER << 
628   G4double densityDiff = -1.;                     316   G4double densityDiff = -1.;
629   if (part) densityDiff = G4UIcommand::Convert << 317   if( part ) densityDiff = G4UIcommand::ConvertToDouble(part);
630   if (densityDiff != -1.) {                    << 318   std::map<G4int,G4double>  fDensityDiffs; // to be able to use a different densityDiff for each material
631     for (unsigned int ii = 0; ii < fOriginalMa << 319   if( densityDiff != -1. ) {
632       fDensityDiffs[ii] = densityDiff;  // cur << 320     for( unsigned int ii = 0; ii < fOriginalMaterials.size(); ii++ ){
633       // same difference                       << 321       fDensityDiffs[ii] = densityDiff; //currently all materials with same difference
634     }                                          << 322     }
635   }                                            << 323   }else {
636   else {                                       << 324     if( fMaterials.size() == 0 ) { // do it only for first slice
637     if (fMaterials.size() == 0) {  // do it on << 325       for( unsigned int ii = 0; ii < fOriginalMaterials.size(); ii++ ){
638       for (unsigned int ii = 0; ii < fOriginal << 326   fMaterials.push_back( fOriginalMaterials[ii] );
639         fMaterials.push_back(fOriginalMaterial << 
640       }                                           327       }
641     }                                             328     }
642   }                                               329   }
643                                                << 330   
644   //----- Read data header                        331   //----- Read data header
645   DicomPhantomZSliceHeader* sliceHeader = new  << 332   DicomPhantomZSliceHeader* sliceHeader = new DicomPhantomZSliceHeader( fin );
646   fZSliceHeaders.push_back(sliceHeader);       << 333   fZSliceHeaders.push_back( sliceHeader );
647                                                << 334   
648   //----- Read material indices                   335   //----- Read material indices
649   G4int nVoxels = sliceHeader->GetNoVoxels();     336   G4int nVoxels = sliceHeader->GetNoVoxels();
650                                                << 337     
651   //--- If first slice, initiliaze fMateIDs       338   //--- If first slice, initiliaze fMateIDs
652   if (fZSliceHeaders.size() == 1) {            << 339   if( fZSliceHeaders.size() == 1 ) {
653     // fMateIDs = new unsigned int[fNoFiles*nV << 340     //fMateIDs = new unsigned int[fNoFiles*nVoxels];
654     fMateIDs = new size_t[fNoFiles * nVoxels]; << 341     fMateIDs = new size_t[fNoFiles*nVoxels];
                                                   >> 342 
655   }                                               343   }
656                                                   344 
657   unsigned int mateID;                            345   unsigned int mateID;
658   // number of voxels from previously read sli << 346   G4int voxelCopyNo = (fZSliceHeaders.size()-1)*nVoxels; // number of voxels from previously read slices
659   G4int voxelCopyNo = G4int((fZSliceHeaders.si << 347   for( G4int ii = 0; ii < nVoxels; ii++, voxelCopyNo++ ){
660   for (G4int ii = 0; ii < nVoxels; ++ii, voxel << 
661     fin >> mateID;                                348     fin >> mateID;
662     fMateIDs[voxelCopyNo] = mateID;               349     fMateIDs[voxelCopyNo] = mateID;
663   }                                               350   }
664                                                   351 
665   //----- Read material densities and build ne << 352   //----- Read material densities and build new materials if two voxels have same material but its density is in a different density interval (size of density intervals defined by densityDiff)
666   //  same material but its density is in a di << 
667   // (size of density intervals defined by den << 
668   G4double density;                               353   G4double density;
669   // number of voxels from previously read sli << 354   voxelCopyNo = (fZSliceHeaders.size()-1)*nVoxels; // number of voxels from previously read slices
670   voxelCopyNo = G4int((fZSliceHeaders.size() - << 355   for( G4int ii = 0; ii < nVoxels; ii++, voxelCopyNo++ ){
671   for (G4int ii = 0; ii < nVoxels; ++ii, voxel << 
672     fin >> density;                               356     fin >> density;
673                                                   357 
674     //-- Get material from list of original ma    358     //-- Get material from list of original materials
675     mateID = unsigned(fMateIDs[voxelCopyNo]);  << 359     int mateID = fMateIDs[voxelCopyNo];
676     G4Material* mateOrig = fOriginalMaterials[ << 360     G4Material* mateOrig  = fOriginalMaterials[mateID];
677                                                   361 
678     //-- Get density bin: middle point of the  << 362     //-- Get density bin: middle point of the bin in which the current density is included 
679     // density is included                     << 
680     G4String newMateName = mateOrig->GetName()    363     G4String newMateName = mateOrig->GetName();
681     G4float densityBin = 0.;                   << 364     float densityBin = 0.;
682     if (densityDiff != -1.) {                  << 365    if( densityDiff != -1.) {
683       densityBin = G4float(fDensityDiffs[mateI << 366      densityBin = fDensityDiffs[mateID] * (G4int(density/fDensityDiffs[mateID])+0.5);
684       //-- Build the new material name         << 367      //-- Build the new material name 
685       newMateName += G4UIcommand::ConvertToStr    368       newMateName += G4UIcommand::ConvertToString(densityBin);
686     }                                             369     }
687                                                   370 
688     //-- Look if a material with this name is  << 371     //-- Look if a material with this name is already created (because a previous voxel was already in this density bin)
689     //  (because a previous voxel was already  << 
690     unsigned int im;                              372     unsigned int im;
691     for (im = 0; im < fMaterials.size(); ++im) << 373     for( im = 0; im < fMaterials.size(); im++ ){
692       if (fMaterials[im]->GetName() == newMate << 374       if( fMaterials[im]->GetName() == newMateName ) {
693         break;                                 << 375   break;
694       }                                           376       }
695     }                                             377     }
696     //-- If material is already created use in    378     //-- If material is already created use index of this material
697     if (im != fMaterials.size()) {             << 379     if( im != fMaterials.size() ) {
698       fMateIDs[voxelCopyNo] = im;                 380       fMateIDs[voxelCopyNo] = im;
699       //-- else, create the material           << 381     //-- else, create the material 
700     }                                          << 382     } else {
701     else {                                     << 383       if( densityDiff != -1.) {
702       if (densityDiff != -1.) {                << 384   fMaterials.push_back( BuildMaterialWithChangingDensity( mateOrig, densityBin, newMateName ) );
703         fMaterials.push_back(BuildMaterialWith << 385   fMateIDs[voxelCopyNo] = fMaterials.size()-1;
704         fMateIDs[voxelCopyNo] = fMaterials.siz << 386       } else {
705       }                                        << 387   G4cerr << " im " << im << " < " << fMaterials.size() << " name " << newMateName << G4endl;
706       else {                                   << 388   G4Exception("Wrong index in material"); //it should never reach here
707         G4cerr << " im " << im << " < " << fMa << 
708         G4Exception("DicomDetectorConstruction << 
709                     "Wrong index in material") << 
710       }                                           389       }
711     }                                             390     }
712   }                                               391   }
                                                   >> 392 
713 }                                                 393 }
714                                                   394 
715 //....oooOO0OOooo........oooOO0OOooo........oo << 395 
                                                   >> 396 //-------------------------------------------------------------
716 void DicomDetectorConstruction::MergeZSliceHea    397 void DicomDetectorConstruction::MergeZSliceHeaders()
717 {                                                 398 {
718   //----- Images must have the same dimension  << 399   //----- Images must have the same dimension ... 
719   fZSliceHeaderMerged = new DicomPhantomZSlice << 400   fZSliceHeaderMerged = new DicomPhantomZSliceHeader( *fZSliceHeaders[0] );
720   for (unsigned int ii = 1; ii < fZSliceHeader << 401   for( unsigned int ii = 1; ii < fZSliceHeaders.size(); ii++ ) {
721     *fZSliceHeaderMerged += *fZSliceHeaders[ii    402     *fZSliceHeaderMerged += *fZSliceHeaders[ii];
722   }                                            << 403   };
723 }                                                 404 }
724                                                   405 
725 //....oooOO0OOooo........oooOO0OOooo........oo << 406 //-------------------------------------------------------------
726 G4Material* DicomDetectorConstruction::BuildMa << 407 G4Material* DicomDetectorConstruction::BuildMaterialWithChangingDensity( const G4Material* origMate, float density, G4String newMateName )
727                                                << 
728                                                << 
729 {                                                 408 {
730   //----- Copy original material, but with new    409   //----- Copy original material, but with new density
731   G4int nelem = G4int(origMate->GetNumberOfEle << 410   G4int nelem = origMate->GetNumberOfElements();
732   G4Material* mate =                           << 411   G4Material* mate = new G4Material( newMateName, density*g/cm3, nelem, kStateUndefined, STP_Temperature );
733     new G4Material(newMateName, density * g /  << 
734                                                   412 
735   for (G4int ii = 0; ii < nelem; ++ii) {       << 413   for( G4int ii = 0; ii < nelem; ii++ ){
736     G4double frac = origMate->GetFractionVecto    414     G4double frac = origMate->GetFractionVector()[ii];
737     G4Element* elem = const_cast<G4Element*>(o    415     G4Element* elem = const_cast<G4Element*>(origMate->GetElement(ii));
738     mate->AddElement(elem, frac);              << 416     mate->AddElement( elem, frac );
739   }                                               417   }
740                                                   418 
741   return mate;                                    419   return mate;
742 }                                                 420 }
743                                                   421 
744 //....oooOO0OOooo........oooOO0OOooo........oo << 422 //-----------------------------------------------------------------------
745 void DicomDetectorConstruction::ConstructPhant    423 void DicomDetectorConstruction::ConstructPhantomContainer()
746 {                                                 424 {
747   //---- Extract number of voxels and voxel di    425   //---- Extract number of voxels and voxel dimensions
748   fNoVoxelsX = fZSliceHeaderMerged->GetNoVoxel << 426   nVoxelX = fZSliceHeaderMerged->GetNoVoxelX();
749   fNoVoxelsY = fZSliceHeaderMerged->GetNoVoxel << 427   nVoxelY = fZSliceHeaderMerged->GetNoVoxelY();
750   fNoVoxelsZ = fZSliceHeaderMerged->GetNoVoxel << 428   nVoxelZ = fZSliceHeaderMerged->GetNoVoxelZ();
751                                                << 429 
752   fVoxelHalfDimX = fZSliceHeaderMerged->GetVox << 430   voxelHalfDimX = fZSliceHeaderMerged->GetVoxelHalfX();
753   fVoxelHalfDimY = fZSliceHeaderMerged->GetVox << 431   voxelHalfDimY = fZSliceHeaderMerged->GetVoxelHalfY();
754   fVoxelHalfDimZ = fZSliceHeaderMerged->GetVox << 432   voxelHalfDimZ = fZSliceHeaderMerged->GetVoxelHalfZ();
755 #ifdef G4VERBOSE                                  433 #ifdef G4VERBOSE
756   G4cout << " fNoVoxelsX " << fNoVoxelsX << "  << 434   G4cout << " nVoxelX " << nVoxelX << " voxelHalfDimX " << voxelHalfDimX <<G4endl;
757   G4cout << " fNoVoxelsY " << fNoVoxelsY << "  << 435   G4cout << " nVoxelY " << nVoxelY << " voxelHalfDimY " << voxelHalfDimY <<G4endl;
758   G4cout << " fNoVoxelsZ " << fNoVoxelsZ << "  << 436   G4cout << " nVoxelZ " << nVoxelZ << " voxelHalfDimZ " << voxelHalfDimZ <<G4endl;
759   G4cout << " totalPixels " << fNoVoxelsX * fN << 437   G4cout << " totalPixels " << nVoxelX*nVoxelY*nVoxelZ <<  G4endl;
760 #endif                                            438 #endif
761                                                   439 
762   //----- Define the volume that contains all     440   //----- Define the volume that contains all the voxels
763   fContainer_solid = new G4Box("phantomContain << 441   container_solid = new G4Box("phantomContainer",nVoxelX*voxelHalfDimX,nVoxelY*voxelHalfDimY,nVoxelZ*voxelHalfDimZ);
764                                fNoVoxelsY * fV << 442   container_logic = 
765   fContainer_logic =                           << 443     new G4LogicalVolume( container_solid, 
766     new G4LogicalVolume(fContainer_solid,      << 444        fMaterials[0],  //the material is not important, it will be fully filled by the voxels
767                         // the material is not << 445        "phantomContainer", 
768                         fMaterials[0], "phanto << 446        0, 0, 0 );
769   //--- Place it on the world                     447   //--- Place it on the world
770   G4double fOffsetX = (fZSliceHeaderMerged->Ge << 448   G4double offsetX = (fZSliceHeaderMerged->GetMaxX() + fZSliceHeaderMerged->GetMinX() ) /2.;
771   G4double fOffsetY = (fZSliceHeaderMerged->Ge << 449   G4double offsetY = (fZSliceHeaderMerged->GetMaxY() + fZSliceHeaderMerged->GetMinY() ) /2.;
772   G4double fOffsetZ = (fZSliceHeaderMerged->Ge << 450   G4double offsetZ = (fZSliceHeaderMerged->GetMaxZ() + fZSliceHeaderMerged->GetMinZ() ) /2.;
773   G4ThreeVector posCentreVoxels(fOffsetX, fOff << 451   G4ThreeVector posCentreVoxels(offsetX,offsetY,offsetZ);
774 #ifdef G4VERBOSE                                  452 #ifdef G4VERBOSE
775   G4cout << " placing voxel container volume a    453   G4cout << " placing voxel container volume at " << posCentreVoxels << G4endl;
776 #endif                                            454 #endif
777   fContainer_phys = new G4PVPlacement(0,  // r << 455   container_phys = 
778                                       posCentr << 456     new G4PVPlacement(0,  // rotation
779                                       fContain << 457           posCentreVoxels,
780                                       "phantom << 458           container_logic,     // The logic volume
781                                       fWorld_l << 459           "phantomContainer",  // Name
782                                       false,   << 460           world_logic,  // Mother
783                                       1);  //  << 461           false,           // No op. bool.
784 }                                              << 462           1);              // Copy number
785                                                << 
786 //....oooOO0OOooo........oooOO0OOooo........oo << 
787 void DicomDetectorConstruction::ConstructPhant << 
788 {                                              << 
789 #ifdef G4_DCMTK                                << 
790   //---- Extract number of voxels and voxel di << 
791 #  ifdef G4VERBOSE                             << 
792   G4cout << " fNoVoxelsX " << fNoVoxelsX << "  << 
793   G4cout << " fNoVoxelsY " << fNoVoxelsY << "  << 
794   G4cout << " fNoVoxelsZ " << fNoVoxelsZ << "  << 
795   G4cout << " totalPixels " << fNoVoxelsX * fN << 
796 #  endif                                       << 
797                                                << 
798   //----- Define the volume that contains all  << 
799   fContainer_solid = new G4Box("phantomContain << 
800                                fNoVoxelsY * fV << 
801   fContainer_logic =                           << 
802     new G4LogicalVolume(fContainer_solid,      << 
803                         // the material is not << 
804                         fMaterials[0], "phanto << 
805                                                   463 
806   G4ThreeVector posCentreVoxels((fMinX + fMaxX << 
807 #  ifdef G4VERBOSE                             << 
808   G4cout << " placing voxel container volume a << 
809 #  endif                                       << 
810   fContainer_phys = new G4PVPlacement(0,  // r << 
811                                       posCentr << 
812                                       fContain << 
813                                       "phantom << 
814                                       fWorld_l << 
815                                       false,   << 
816                                       1);  //  << 
817 #endif                                         << 
818 }                                                 464 }
819                                                   465 
                                                   >> 466 
                                                   >> 467 #include "G4SDManager.hh"
820 #include "G4MultiFunctionalDetector.hh"           468 #include "G4MultiFunctionalDetector.hh"
821 #include "G4PSDoseDeposit.hh"                     469 #include "G4PSDoseDeposit.hh"
822 #include "G4PSDoseDeposit3D.hh"                << 
823 #include "G4SDManager.hh"                      << 
824                                                   470 
825 //....oooOO0OOooo........oooOO0OOooo........oo << 471 //-------------------------------------------------------------
826 void DicomDetectorConstruction::SetScorer(G4Lo    472 void DicomDetectorConstruction::SetScorer(G4LogicalVolume* voxel_logic)
827 {                                                 473 {
828 #ifdef G4VERBOSE                               << 
829   G4cout << "\t SET SCORER : " << voxel_logic- << 
830 #endif                                         << 
831                                                << 
832   fScorers.insert(voxel_logic);                << 
833 }                                              << 
834                                                << 
835 //....oooOO0OOooo........oooOO0OOooo........oo << 
836                                                << 
837 void DicomDetectorConstruction::ConstructSDand << 
838 {                                              << 
839 #ifdef G4VERBOSE                               << 
840   G4cout << "\t CONSTRUCT SD AND FIELD" << G4e << 
841 #endif                                         << 
842                                                << 
843   // G4SDManager* SDman = G4SDManager::GetSDMp << 
844                                                << 
845   // SDman->SetVerboseLevel(1);                << 
846                                                   474 
                                                   >> 475   G4SDManager* SDman = G4SDManager::GetSDMpointer();
847   //                                              476   //
848   // Sensitive Detector Name                      477   // Sensitive Detector Name
849   G4String concreteSDname = "phantomSD";          478   G4String concreteSDname = "phantomSD";
850   std::vector<G4String> scorer_names;          << 479 
851   scorer_names.push_back(concreteSDname);      << 
852   //------------------------                      480   //------------------------
853   // MultiFunctionalDetector                      481   // MultiFunctionalDetector
854   //------------------------                      482   //------------------------
855   //                                              483   //
856   // Define MultiFunctionalDetector with name.    484   // Define MultiFunctionalDetector with name.
857   // declare MFDet as a MultiFunctionalDetecto << 
858   G4MultiFunctionalDetector* MFDet = new G4Mul    485   G4MultiFunctionalDetector* MFDet = new G4MultiFunctionalDetector(concreteSDname);
859   G4SDManager::GetSDMpointer()->AddNewDetector << 486   SDman->AddNewDetector( MFDet );                 // Register SD to SDManager
860   char* nest = std::getenv("DICOM_NESTED_PARAM << 487 
861   if (nest && G4String(nest) == "1") {         << 488   voxel_logic->SetSensitiveDetector(MFDet);
862     G4VPrimitiveScorer* dosedep = new G4PSDose << 489 
863       "DoseDeposit", fNoVoxelsZ, fNoVoxelsY, f << 490   G4PSDoseDeposit*   scorer = new G4PSDoseDeposit("DoseDeposit");  
864     // - the last 3 arguments correspond to th << 491   MFDet->RegisterPrimitive(scorer);
865     MFDet->RegisterPrimitive(dosedep);         << 
866   }                                            << 
867   else {                                       << 
868     G4VPrimitiveScorer* dosedep = new G4PSDose << 
869     MFDet->RegisterPrimitive(dosedep);         << 
870   }                                            << 
871                                                   492 
872   for (auto ite = fScorers.cbegin(); ite != fS << 
873     SetSensitiveDetector(*ite, MFDet);         << 
874   }                                            << 
875 }                                                 493 }
                                                   >> 494 
876                                                   495