#include "Phantom.hh" #include "PhantomMessenger.hh" #include "G4PVPlacement.hh" #include "G4Sphere.hh" #include "G4Tubs.hh" #include "G4Box.hh" #include "G4SubtractionSolid.hh" #include "G4Ellipsoid.hh" #include "G4SystemOfUnits.hh" #include "G4VisAttributes.hh" Phantom::Phantom() { motherLV = 0; constructPhantom = false; constructCompensator = false; phantomPosition = G4ThreeVector(0.0*mm, 0.0*mm, 200.0*mm); phantomRotation = new G4RotationMatrix(); phantomName = "Rectangle"; //"Pacman"; materialDefinition = new MaterialDefinitions(); phantomMaterial = materialDefinition->GetMaterial("Water"); phantomMotherMaterial = materialDefinition->GetMaterial("Air"); ballMaterial = materialDefinition->GetMaterial("TungstenCarbide"); compensatorPosition = G4ThreeVector(0.0*mm, 0.0*mm, 100*mm); phantomMessenger = new PhantomMessenger(this); // set default values to the spherical phantom phantomSphereRadius = 3.75*cm; phantomSphere = 0; phantomSphereLV = 0; phantomSpherePV = 0; insert1radius = 0.75*cm; insert1length = 22.5*mm; SetSphericalPhantomInsert1Material("Brass"); insert2radius = 0.75*cm; insert2length = 22.5*mm; SetSphericalPhantomInsert2Material("Air"); insert3radius = 0.75*cm; insert3length = 22.5*mm; SetSphericalPhantomInsert3Material("Perspex1"); //setdefault values for ellipsoidal phantom phantomEllipsoidSemiX = 10.0*cm; phantomEllipsoidSemiY = 4.0*cm; phantomEllipsoidSemiZ = 4.5*cm; phantomEllipsoid = 0; phantomEllipsoidLV = 0; phantomEllipsoidPV = 0; // set default values to the Pacman phantom phantomPacmanRadius = 4.5*cm; phantomPacmanHalfZ = 5.0*cm; phantomPacmanSpanningAngle = 300.*deg; phantomPacman = 0; phantomPacmanLV = 0; phantomPacmanPV = 0; // default values for the rectangular phantom phantomRectangleSize = G4ThreeVector(10.0*cm, 10.0*cm, 4*mm); phantomRectangle = 0; phantomRectangleLV = 0; phantomRectanglePV = 0; } Phantom::~Phantom() { delete phantomMaterial; delete phantomSphere; delete phantomEllipsoid; delete phantomPacman; } void Phantom::ConstructPhantom(G4LogicalVolume* lv) { worldLV = lv; // setup a logical volume which will allow complex phantoms to be rotated later on // motherSphere = new G4Sphere("motherSphere", 0.0*cm, 7.5*cm, 0, CLHEP::twopi, 0, CLHEP::twopi); // motherLV = new G4LogicalVolume(motherSphere, phantomMotherMaterial, "PhantomMother"); //motherLV->SetVisAttributes(G4VisAttributes::Invisible); // motherPV = new G4PVPlacement(phantomRotation, phantomPosition, motherLV, "PhantomMother", worldLV, false, 0); if(phantomName == "Sphere") ConstructSphericalPhantom(); else if(phantomName == "Ellipsoid") ConstructEllipsoidalPhantom(); else if(phantomName == "Pacman") ConstructPacmanPhantom(); else if(phantomName == "Rectangle") ConstructRectangularPhantom(); else { G4cerr << "Phantom::ConstructPhantom(), " << phantomName << " does not exist" << G4endl; return; } G4cout << "Phantom::ConstructPhantom(), " << phantomName << " Constructed" << G4endl; } void Phantom::SetPhantomMaterial(G4String material) { G4Material* pttoMaterial = materialDefinition->GetMaterial(material); if (pttoMaterial) phantomMaterial = pttoMaterial; else { G4cout << "### Cannot find material " << material << G4endl; phantomMaterial = NULL; } } void Phantom::SetSphericalPhantomInsert1Material(G4String material) { G4Material* pttoMaterial = materialDefinition->GetMaterial(material); if (pttoMaterial) insert1material = pttoMaterial; else { G4cout << "### Cannot find material " << material << G4endl; insert1material = NULL; } } void Phantom::SetSphericalPhantomInsert2Material(G4String material) { G4Material* pttoMaterial = materialDefinition->GetMaterial(material); if (pttoMaterial) insert2material = pttoMaterial; else { G4cout << "### Cannot find material " << material << G4endl; insert2material = NULL; } } void Phantom::SetSphericalPhantomInsert3Material(G4String material) { G4Material* pttoMaterial = materialDefinition->GetMaterial(material); if (pttoMaterial) insert3material = pttoMaterial; else { G4cout << "### Cannot find material " << material << G4endl; insert3material = NULL; } } void Phantom::ConstructSphericalPhantom() { G4RotationMatrix* rot1 = new G4RotationMatrix(); rot1->rotateX(90*deg); G4RotationMatrix* rot2 = rot1; G4RotationMatrix* rot3 = rot1; phantomSphere = new G4Sphere("phantomSphere", 0.0*mm, phantomSphereRadius, 0, CLHEP::twopi, 0, CLHEP::twopi); phantomSphereLV = new G4LogicalVolume(phantomSphere, phantomMaterial, "Phantom"); //phantomSpherePV = new G4PVPlacement(0, G4ThreeVector(0,0,0), phantomSphereLV, "Phantom", motherLV, false, 0); phantomSpherePV = new G4PVPlacement(phantomRotation, phantomPosition, phantomSphereLV, "Phantom", worldLV, false, 0); G4Tubs* insert1 = new G4Tubs("insert1", 0.0*mm, insert1radius, insert1length/2.0, 0, CLHEP::twopi); G4LogicalVolume* insert1LV = new G4LogicalVolume(insert1,insert1material,"insert1"); G4ThreeVector insert1Pos = G4ThreeVector(0.0*mm,0.0*mm,phantomSphereRadius/2.0); G4VisAttributes* insert1Vis = new G4VisAttributes(G4Colour::Red()); insert1LV->SetVisAttributes(insert1Vis); new G4PVPlacement(rot1, insert1Pos, insert1LV, "insert1", phantomSphereLV, false, 0); G4Tubs* insert2 = new G4Tubs("insert2", 0.0*mm, insert2radius, insert2length/2.0, 0, CLHEP::twopi); G4LogicalVolume* insert2LV = new G4LogicalVolume(insert2,insert2material,"insert2"); G4VisAttributes* insert2Vis = new G4VisAttributes(G4Colour::Green()); insert2LV->SetVisAttributes(insert2Vis); G4ThreeVector insert2Pos = G4ThreeVector(-std::sqrt(3)*phantomSphereRadius/4.0, 0.0*mm, -phantomSphereRadius/4.0); new G4PVPlacement(rot2, insert2Pos, insert2LV, "insert2", phantomSphereLV, false, 0); G4Tubs* insert3 = new G4Tubs("insert3", 0.0*mm, insert3radius, insert3length/2.0, 0, CLHEP::twopi); G4LogicalVolume* insert3LV = new G4LogicalVolume(insert3,insert3material,"insert3"); G4VisAttributes* insert3Vis = new G4VisAttributes(G4Colour::Blue()); insert3LV->SetVisAttributes(insert3Vis); G4ThreeVector insert3Pos = G4ThreeVector(std::sqrt(3)*phantomSphereRadius/4.0, 0.0*mm, -phantomSphereRadius/4.0); new G4PVPlacement(rot3, insert3Pos, insert3LV, "insert3", phantomSphereLV, false, 0); G4Sphere* ball1 = new G4Sphere("ball1", 0.0*mm, 0.5*mm, 0, CLHEP::twopi,0, CLHEP::twopi); G4LogicalVolume* ball1LV = new G4LogicalVolume(ball1, ballMaterial, "ball1"); G4VisAttributes* ball1Vis = new G4VisAttributes(G4Colour::Black()); ball1LV->SetVisAttributes(ball1Vis); new G4PVPlacement(rot1, G4ThreeVector(10*mm,-28*mm,0.0*mm), ball1LV,"ball1",phantomSphereLV,false,0); G4Sphere* ball2 = new G4Sphere("ball2", 0.0*mm, 1.0*mm, 0, CLHEP::twopi,0, CLHEP::twopi); G4LogicalVolume* ball2LV = new G4LogicalVolume(ball2, ballMaterial, "ball2"); G4VisAttributes* ball2Vis = new G4VisAttributes(G4Colour::Black()); ball2LV->SetVisAttributes(ball2Vis); new G4PVPlacement(rot1, G4ThreeVector(-10*mm,-28*mm,0.0*mm), ball2LV,"ball2",phantomSphereLV,false,0); if(constructCompensator) { G4double boxHx,boxHy, boxHz; // for a sphere want box same size in all dimensions boxHx = boxHy = 6*cm; boxHz = phantomSphereRadius; G4Box* box = new G4Box("temp", boxHx, boxHy, boxHz); phantomCompensator = new G4SubtractionSolid("phantomCompensator", box, phantomSphere); phantomCompensatorLV = new G4LogicalVolume(phantomCompensator, phantomMaterial, "PhantomCompensator"); phantomCompensatorPV = new G4PVPlacement(0, compensatorPosition, phantomCompensatorLV, "PhantomCompensator", worldLV, false, 0); } } void Phantom::ConstructEllipsoidalPhantom() { phantomEllipsoid = new G4Ellipsoid("phantomEllipsoid", phantomEllipsoidSemiX, phantomEllipsoidSemiX, phantomEllipsoidSemiZ); phantomEllipsoidLV = new G4LogicalVolume(phantomEllipsoid, phantomMaterial, "Phantom"); phantomEllipsoidPV = new G4PVPlacement(0, G4ThreeVector(0,0,0), phantomEllipsoidLV, "Phantom", motherLV, false, 0); } void Phantom::ConstructPacmanPhantom() { phantomPacman = new G4Tubs("phantomPacman", 0.0*mm, phantomPacmanRadius, phantomPacmanHalfZ, 0, phantomPacmanSpanningAngle); phantomPacmanLV = new G4LogicalVolume(phantomPacman, phantomMaterial, "Phantom"); phantomPacmanPV = new G4PVPlacement(phantomRotation, phantomPosition, phantomPacmanLV, "Phantom", worldLV, false, 0); } void Phantom::ConstructRectangularPhantom() { phantomRectangle = new G4Box("phantomRectangle",phantomRectangleSize.x()/2.0, phantomRectangleSize.y()/2.0, phantomRectangleSize.z()/2.0); phantomRectangleLV = new G4LogicalVolume(phantomRectangle,phantomMaterial,"Phantom"); phantomRectanglePV = new G4PVPlacement(phantomRotation, phantomPosition, phantomRectangleLV, "Phantom", worldLV,false,0); }