Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:16: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 // Code developed by:
0027 // S.Guatelli, M. Large and A. Malaroda, University of Wollongong
0028 //
0029 // Code based on the Geant4 extended example DICOM
0030 //
0031 // 
0032 
0033 #include "ICRP110PhantomNestedParameterisation.hh"
0034 #include "G4VPhysicalVolume.hh"
0035 #include "G4VTouchable.hh"
0036 #include "G4ThreeVector.hh"
0037 #include "G4Box.hh"
0038 #include "G4LogicalVolume.hh"
0039 #include "G4Material.hh"
0040 #include "G4VisAttributes.hh"
0041 #include "G4VVisManager.hh"
0042 
0043 ICRP110PhantomNestedParameterisation::
0044 ICRP110PhantomNestedParameterisation(const G4ThreeVector& halfVoxelSize,
0045                                    std::vector<G4Material*>& mat,
0046                                   G4int fnX_, G4int fnY_, G4int fnZ_)
0047 :
0048   fdX(halfVoxelSize.x()), fdY(halfVoxelSize.y()), fdZ(halfVoxelSize.z()), 
0049   fnX(fnX_), fnY(fnY_), fnZ(fnZ_), // number of voxels along X, Y and Z
0050   fMaterials(mat), // vector of defined materials
0051   fMaterialIndices(nullptr) // vector which associates MaterialID to voxels
0052 {
0053  ReadColourData();//Define the color of each material
0054                   // from ColourMap.dat
0055 }
0056 
0057 ICRP110PhantomNestedParameterisation::~ICRP110PhantomNestedParameterisation()
0058 {}
0059  
0060 void ICRP110PhantomNestedParameterisation::ReadColourData()
0061 {
0062     // By default the tissues are not visible. Then
0063     // the visualisation attributes are defined based on 
0064     // ColourMap.dat 
0065     auto blankAtt = new G4VisAttributes;
0066     blankAtt->SetVisibility( FALSE );
0067     fColours["Default"] = blankAtt;
0068 
0069     G4String colourFile = "ColourMap.dat";
0070     G4cout << "Phantom Material Colours set via ColourMap.dat data file " << G4endl;
0071 
0072     std::ifstream fin(colourFile.c_str());
0073     G4int nMate;
0074     G4String mateName;
0075     G4double cred, cgreen, cblue, copacity;
0076     fin >> nMate;
0077     G4VisAttributes* visAtt=nullptr;
0078     
0079     for( G4int ii = 0; ii < nMate; ii++ ){
0080         fin >> mateName >> cred >> cgreen >> cblue >> copacity;
0081         G4Colour colour( cred, cgreen, cblue, copacity );
0082         visAtt = new G4VisAttributes( colour );
0083         visAtt->SetForceSolid(true);
0084         fColours[mateName] = visAtt;
0085        // G4cout << mateName << " colour set :  "  << colour << G4endl;
0086     }
0087 }
0088 
0089 void ICRP110PhantomNestedParameterisation::
0090 SetNoVoxel( G4int nx, G4int ny, G4int nz )
0091 {
0092   fnX = nx;
0093   fnY = ny;
0094   fnZ = nz;
0095 }
0096 
0097 G4Material* ICRP110PhantomNestedParameterisation::
0098 ComputeMaterial(G4VPhysicalVolume* physVol, const G4int iz,
0099                 const G4VTouchable* parentTouch)
0100 {
0101     // protection for initialization and vis at idle state
0102     //
0103     if(parentTouch == nullptr)
0104         return fMaterials[0];
0105   
0106     // Copy number of voxels.
0107     // Copy number of X and Y are obtained from replication number.
0108     // Copy number of Z is the copy number of current voxel.
0109     
0110     G4int ix = parentTouch -> GetReplicaNumber(0);
0111     G4int iy = parentTouch -> GetReplicaNumber(1);
0112 
0113     G4int copyID = ix + fnX*iy + fnX*fnY*iz;
0114     //G4cout << "ix: "<< ix << ", iy: " << iy << ", iz:" << iz<< G4endl;
0115     //G4cout << "copyID from the Nested Param: "<< copyID << G4endl;
0116     
0117     //The copyID identifies the voxel    
0118     std::size_t matIndex = GetMaterialIndex(copyID); 
0119     G4Material* mate = fMaterials[matIndex];
0120    
0121     if(true && physVol && G4VVisManager::GetConcreteInstance()) {
0122         G4String mateName = fMaterials.at(matIndex)->GetName();
0123         std::string::size_type iuu = mateName.find("__");
0124      
0125         if( iuu != std::string::npos ) {
0126             mateName = mateName.substr( 0, iuu ); // Associate material
0127         }
0128 
0129         if(0 < fColours.count(mateName)) {
0130             physVol -> GetLogicalVolume() ->
0131             SetVisAttributes(fColours.find(mateName)->second);
0132         } 
0133         else {
0134             physVol->GetLogicalVolume() ->
0135             SetVisAttributes(fColours.begin() ->second); // Associate color
0136         }
0137     }
0138     physVol -> GetLogicalVolume()->SetMaterial(mate);
0139      
0140     return mate;
0141 }
0142 
0143 G4int ICRP110PhantomNestedParameterisation::GetMaterialIndex( G4int copyNo ) const
0144 {
0145     return fMaterialIndices[copyNo];
0146 }
0147 
0148 G4int ICRP110PhantomNestedParameterisation::GetNumberOfMaterials() const
0149 {
0150     return fMaterials.size();
0151 }
0152 
0153 G4Material* ICRP110PhantomNestedParameterisation::GetMaterial(G4int i) const
0154 {
0155     return fMaterials[i];
0156 }
0157 
0158 void ICRP110PhantomNestedParameterisation::
0159 ComputeTransformation(const G4int copyNo, G4VPhysicalVolume* physVol) const
0160 {
0161     // Position of voxels.
0162     // x and y positions are already defined in DetectorConstruction by using
0163     // replicated volume. Hre we define the position along the z axis of voxels.
0164 
0165     physVol -> SetTranslation(G4ThreeVector(0.,0.,(2.*static_cast<double>(copyNo)
0166                                                 +1.)*fdZ - fdZ*fnZ)); 
0167 }
0168 
0169 void ICRP110PhantomNestedParameterisation::
0170 ComputeDimensions( G4Box& box, const G4int, const G4VPhysicalVolume* ) const
0171 {
0172     box.SetXHalfLength(fdX);
0173     box.SetYHalfLength(fdY);
0174     box.SetZHalfLength(fdZ);
0175 }