DetectorConstruction changed in many ways. Cleaned the code a bit and redesigned the cone and tube part

This commit is contained in:
Gitea 2018-04-08 00:54:12 +02:00
parent b33956bee7
commit 50cad925d6
3 changed files with 69 additions and 58 deletions

View File

@ -26,6 +26,7 @@
#include "G4Tubs.hh"
#include "G4VPVParameterisation.hh"
#include "G4RotationMatrix.hh"
#include "G4PVReplica.hh"
class MedtechDetectorConstruction : public G4VUserDetectorConstruction
{

View File

@ -23,7 +23,7 @@ G4VPhysicalVolume* MedtechDetectorConstruction::Construct()
//Material Section
G4NistManager *manager = G4NistManager::Instance();
G4Material *air = manager -> FindOrBuildMaterial("G4_AIR");
G4Material *air = manager -> FindOrBuildMaterial("G4_Galactic");
G4Material *targetMaterial = manager -> FindOrBuildMaterial("G4_Pb");
G4Material *boxMaterial = manager -> FindOrBuildMaterial("G4_W");
G4Material *coneMaterial = manager -> FindOrBuildMaterial("G4_Fe");
@ -60,20 +60,25 @@ G4VPhysicalVolume* MedtechDetectorConstruction::Construct()
//End of Target box
//Water after screen
G4Box *solidWater = new G4Box("Water", 1*m, 1*m, 1*cm);
G4LogicalVolume *logicWater = new G4LogicalVolume(solidWater, waterMaterial, "Water", 0, 0, 0);
/*G4Box *solidWater = new G4Box("waterCell", 1*m, 1*m, 1*m);
G4LogicalVolume *logicWater = new G4LogicalVolume(solidWater, waterMaterial, "waterCell", 0, 0, 0);
G4PVPlacement *physicalWater = new G4PVPlacement(0, //no rotation
G4ThreeVector(0, 0, 1.2*m), //at (0,0,0)
logicWater, //it's logical volume
"Water", //it's name
logicWorld, //it's mother volume
false, //no boolean operations
0); //no particular field
0); //no particular field */
//Water after screen cells (parameterisation)
/*G4Box *solidWaterCell = new G4Box("Water", 1*m, 1*m, 1*cm);
G4VPhysicalVolume *logicWaterCell = new G4VPhysicalVolume(solidWaterCell, waterMaterial, "cellWater", 0, 0, 0);
G4VPVParameterisation waterCell = new G4VPVParameterisation("cellWater", logicWaterCell, physicalWater, logicWaterCell, false, 0, true);
*/
G4VPVParameterisation waterCell = new G4VPVParameterisation("cellWater", logicWaterCell, physicalWater, logicWaterCell, false, 0, true);*/
//G4VPhysicalVolume *waterCell = new G4PVReplica("waterCell", logicWater, logicWorld, kZAxis, 100, 1*cm, 0.);
//End of water after screen
//Collimator
@ -94,68 +99,73 @@ G4VPhysicalVolume* MedtechDetectorConstruction::Construct()
//Cone
G4double radius = parameter -> GetRadius();
G4double tube_size = parameter -> GetTubeSize();
G4double cone_size = parameter -> GetConeSize();
G4double move_z = 0; //place the first solid to the right place
G4double cone_placement = 0; //move cone to V(1,0,0)
G4double tube_size = parameter -> GetTubeSize() / 2;
G4double cone_size = parameter -> GetConeSize() / 2; //we need to substract by 2 for valid size
G4double move_in_z_to_zero = 0;
G4double cone_placement = 0; //used to determine where to place the solids
G4Cons *solidCone = 0;
G4Tubs *solidTube = 0;
G4UnionSolid *unionCone = 0;
G4LogicalVolume *logicCone = 0;
if(cone_size > 0 && tube_size != 0)
G4PVPlacement *physicalCone = 0;
if(cone_size > 0)
{
move_z = tube_size + cone_size;
cone_placement = 2*tube_size + cone_size+ 1;
cone_placement = abs(cone_size);
solidCone = new G4Cons("cone", 0, radius*cm, 0, 0, cone_size*cm, 0, 2*CLHEP::pi); //name, inside R -Z, outside, R -Z, inside R Z, outside R Z, half length in z, vmi, vmi
solidTube = new G4Tubs("tube", 0, radius*cm, tube_size*cm, 0, 2*CLHEP::pi); //name, inner R, outter R, Half length in Z, starting angle, angle of the segment in rad
unionCone = new G4UnionSolid("cone", solidCone, solidTube, 0, G4ThreeVector(0, 0, -move_z*cm));
logicCone = new G4LogicalVolume(unionCone, coneMaterial, "Cone", 0, 0, 0);
}
else if(cone_size == 0 && tube_size != 0)
{
cone_placement = tube_size + 1;
solidTube = new G4Tubs("tube", 0, radius*cm, tube_size*cm, 0, 2*CLHEP::pi); //name, inner R, outter R, Half length in Z, starting angle, angle of the segment in rad
logicCone = new G4LogicalVolume(solidTube, coneMaterial, "Cone", 0, 0, 0);
}
else if(cone_size < 0 && tube_size != 0)
{
if(cone_size > tube_size)
{
return 0;
}
else
{
G4RotationMatrix *rot = new G4RotationMatrix();
rot -> rotateX(180 * deg);
move_z = tube_size+cone_size;
cone_placement = tube_size + 1;
solidCone = new G4Cons("cone", 0, radius*cm, 0, 0, -cone_size*cm, 0, 2*CLHEP::pi); //name, inside R -Z, outside, R -Z, inside R Z, outside R Z, half length in z, vmi, vmi
solidTube = new G4Tubs("tube", 0, radius*cm, tube_size*cm, 0, 2*CLHEP::pi); //name, inner R, outter R, Half length in Z, starting angle, angle of the segment in rad
G4SubtractionSolid *subCone = new G4SubtractionSolid("Cone", solidTube, solidCone, rot, G4ThreeVector(0, 0, move_z*cm));
logicCone = new G4LogicalVolume(subCone, coneMaterial, "Cone", 0, 0, 0);
}
}
if(tube_size == 0)
{
cone_placement = cone_size + 1;
solidCone = new G4Cons("cone", 0, radius*cm, 0, 0, cone_size*cm, 0, 2*CLHEP::pi); //name, inside R -Z, outside, R -Z, inside R Z, outside R Z, half length in z, vmi, vmi
//move_in_z_to_zero = cone_size; //put the cone to zero
cone_placement = cone_size + 2*tube_size; //use tube size + threshold
logicCone = new G4LogicalVolume(solidCone, coneMaterial, "Cone", 0, 0, 0);
physicalCone = new G4PVPlacement(0,
G4ThreeVector(0, 0, cone_placement*cm),
logicCone,
"Cone",
logicWorld,
false,
0);
}
else if(cone_size < 0) //cone_size < 0
{
cone_placement = abs(cone_size) + 2*tube_size;
G4RotationMatrix *rot = new G4RotationMatrix();
rot -> rotateX(180 * deg);
solidCone = new G4Cons("cone", 0, radius*cm, 0, 0, -cone_size*cm, 0, 2*CLHEP::pi); //name, inside R -Z, outside, R -Z, inside R Z, outside R Z, half length in z, vmi, vmi
solidTube = new G4Tubs("tube", 0, radius*cm, -cone_size*cm, 0, 2*CLHEP::pi); //name, inner R, outter R, Half length in Z, starting angle, angle of the segment in rad
G4SubtractionSolid *Cone = new G4SubtractionSolid("Cone", solidTube, solidCone, rot, G4ThreeVector(0, 0, move_in_z_to_zero*cm));
logicCone = new G4LogicalVolume(Cone, coneMaterial, "Cone", 0, 0, 0);
physicalCone = new G4PVPlacement(0,
G4ThreeVector(0, 0, cone_placement*cm),
logicCone,
"Cone",
logicWorld,
false,
0);
}
//End of cone
//Tube
G4PVPlacement *fixTube = 0;
cone_placement = tube_size;
if(tube_size > 0)
{
G4Tubs *fixsolidTube = new G4Tubs("tube", 0, radius*cm, tube_size*cm, 0, 2*CLHEP::pi); //name, inner R, outter R, Half length in Z, starting angle, angle of the segment in rad
G4LogicalVolume *fixlogicalTube = new G4LogicalVolume(fixsolidTube, coneMaterial, "fixTube", 0, 0, 0);
fixTube = new G4PVPlacement(0,
G4ThreeVector(0, 0, cone_placement*cm),
fixlogicalTube,
"Cone",
logicWorld,
false,
0);
}
G4PVPlacement *physicalCone = new G4PVPlacement(0,
G4ThreeVector(0, 0, cone_placement*cm),
logicCone,
"Cone",
logicWorld,
false,
0);
return physicalWorld;
}

View File

@ -17,7 +17,7 @@ Parameters* Parameters::getInstance()
return instance;
}
Parameters::Parameters() : ParticleEnergy(6), hdegree(0), vdegree(0), box_size(10), tube_size(2), cone_size(2), radius(2)
Parameters::Parameters() : ParticleEnergy(6), hdegree(0), vdegree(0), box_size(10), tube_size(2), cone_size(2), radius(5)
{
}