Here are code snippets from the construction.cc of the gold block.
G4VPhysicalVolume* MyDetectorConstruction::Construct() {
G4NistManager* nist = G4NistManager::Instance();
// Define materials
G4Material* gold = nist->FindOrBuildMaterial("G4_Au");
G4Material* worldMat = nist->FindOrBuildMaterial("G4_Galactic");
G4Material* silicon = nist->FindOrBuildMaterial("G4_Si");
// Define world volume
G4double xWorld = 1 * m;
G4double yWorld = 1 * m;
G4double zWorld = 1 * m;
G4Box* solidWorld = new G4Box("solidWorld", xWorld, yWorld, zWorld);
G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, worldMat, "logicWorld");
G4VPhysicalVolume* physWorld = new G4PVPlacement(0, G4ThreeVector(0., 0., 0.), logicWorld, "physWorld", 0, false, 0, true);
// Add a step limiter to the vacuum (world volume)
G4double maxStepVacuum = 0.1 * mm; // Set a maximum step size for the vacuum
logicWorld->SetUserLimits(new G4UserLimits(maxStepVacuum));
// Place the gold block
G4Box* solidGoldBlock = new G4Box("solidGoldBlock", goldBlockWidth / 2, goldBlockThickness / 2, goldBlockHeight / 2);
G4LogicalVolume* logicGoldBlock = new G4LogicalVolume(solidGoldBlock, gold, "logicGoldBlock");
new G4PVPlacement(0, G4ThreeVector(0., -goldBlockThickness / 2, 0.), logicGoldBlock, "physGoldBlock", logicWorld, false, 0, true);
// Add a step limiter to the gold block
G4double maxStepGold = 0.00001 * mm; // Set a maximum step size for the gold block
logicGoldBlock->SetUserLimits(new G4UserLimits(maxStepGold));
// Place the detector
G4Tubs* siliconDetector = new G4Tubs("siliconDetector", 0, detectorRadius, detectorThickness / 2, 0, 2 * M_PI);
logicDetector = new G4LogicalVolume(siliconDetector, silicon, "logicDetector");
new G4PVPlacement(0, G4ThreeVector(0., 0., -detectorZPosition), logicDetector, "physDetector", logicWorld, false, 0, true);
return physWorld;
}
And here is part of the generator.cc
MyPrimaryGenerator::MyPrimaryGenerator()
{
fParticleGun = new G4ParticleGun(1); // Initialize particle gun with 1 particle per event
G4ProductionCutsTable::GetProductionCutsTable()->SetEnergyRange(0.1 * eV, 100 * GeV);
G4double lowEnergyCut = 0.1 * keV;
G4ProductionCuts* cuts = new G4ProductionCuts();
cuts->SetProductionCut(lowEnergyCut, "gamma");
cuts->SetProductionCut(lowEnergyCut, "e-");
cuts->SetProductionCut(lowEnergyCut, "e+");
cuts->SetProductionCut(lowEnergyCut, "proton");
G4Region* region = G4RegionStore::GetInstance()->GetRegion("DefaultRegionForTheWorld");
region->SetProductionCuts(cuts);
}
MyPrimaryGenerator::~MyPrimaryGenerator()
{
delete fParticleGun;
}
void MyPrimaryGenerator::GeneratePrimaries(G4Event* anEvent)
{
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
// Generate a proton
G4String particleName = "proton";
G4ParticleDefinition* particle = particleTable->FindParticle(particleName);
// Calculate the starting position based on the event ID
G4int eventID = anEvent->GetEventID();
G4double angle = eventID * (5.0 / 100.0) * deg; // Increment angle from 0 to 5 degrees over 100 events
if (angle > 5.0 * deg) {
angle = 5.0 * deg;
}
// Set the particle's starting position
G4double yStart = 0.001 * m + std::tan(angle) * 1.0 * m; // Offset in y-axis based on angle
G4ThreeVector pos(0.0 * m, yStart, 0.1 * m); // start position
fParticleGun->SetParticlePosition(pos);
// Set the momentum direction to point toward the origin
G4ThreeVector mom(0.0, -yStart, -0.1 * m); // Momentum direction toward the origin
mom = mom.unit(); // Normalize the momentum vector
fParticleGun->SetParticleMomentumDirection(mom);
// Set the particle energy
fParticleGun->SetParticleMomentum(1300 * keV);
// Set the particle definition
fParticleGun->SetParticleDefinition(particle);
// Generate the primary vertex
fParticleGun->GeneratePrimaryVertex(anEvent);
}
I am trying to recreate this paper.