2 changes: 2 additions & 0 deletions examples/basic/B1/exampleB1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "G4SteppingVerbose.hh"
#include "G4UImanager.hh"
#include "QBBC.hh"
#include "G4ParallelWorldPhysics.hh"

#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
Expand Down Expand Up @@ -71,6 +72,7 @@ int main(int argc,char** argv)
// Physics list
G4VModularPhysicsList* physicsList = new QBBC;
physicsList->SetVerboseLevel(1);
physicsList->RegisterPhysics(new G4ParallelWorldPhysics{"MyParallelWorld"});
runManager->SetUserInitialization(physicsList);

// User action initialization
Expand Down
2 changes: 2 additions & 0 deletions examples/basic/B1/include/DetectorConstruction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "G4VUserDetectorConstruction.hh"
#include "globals.hh"
#include "my_parallel_world.hh"

class G4VPhysicalVolume;
class G4LogicalVolume;
Expand All @@ -53,6 +54,7 @@ class DetectorConstruction : public G4VUserDetectorConstruction

protected:
G4LogicalVolume* fScoringVolume = nullptr;
MyParallelWorld fParallelWorld{};
};

}
Expand Down
32 changes: 32 additions & 0 deletions examples/basic/B1/include/my_parallel_world.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef NUSIM_LIBNUSIM_GEANT4_SCORING_MY_PARALLEL_WORLD_H
#define NUSIM_LIBNUSIM_GEANT4_SCORING_MY_PARALLEL_WORLD_H

#include "G4LogicalVolume.hh"
#include "G4VUserParallelWorld.hh"

/// A material-less volume that does not interact with the particles but can track their passage.
class MyParallelWorld final : public G4VUserParallelWorld {
public:
/// Constructor.
MyParallelWorld();

MyParallelWorld(const MyParallelWorld& other) = delete;
/// Move constructor (to enable emplace_back).
MyParallelWorld(MyParallelWorld&& other) = default;
MyParallelWorld& operator=(const MyParallelWorld& other) = delete;
MyParallelWorld& operator=(MyParallelWorld&& other) = delete;

/// Destructor.
~MyParallelWorld() final = default;

/// Callback used by Geant4 to build the detector volume.
void Construct() final;
/// Callback used by Geant4 to initialize and set the sensitive detector.
void ConstructSD() final;

private:
/// Pointer to the parallel world logical volume.
G4LogicalVolume* m_lv = nullptr;
};

#endif // NUSIM_LIBNUSIM_GEANT4_SCORING_MY_PARALLEL_WORLD_H
13 changes: 0 additions & 13 deletions examples/basic/B1/run1.mac
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@
/control/verbose 2
/run/verbose 2
/event/verbose 0
/tracking/verbose 1
#
# gamma 6 MeV to the direction (0.,0.,1.)
#
/gun/particle gamma
/gun/energy 6 MeV
#
/run/beamOn 5
#
# proton 210 MeV to the direction (0.,0.,1.)
#
/gun/particle proton
/gun/energy 210 MeV
/tracking/verbose 2
#
/run/beamOn 1
41 changes: 7 additions & 34 deletions examples/basic/B1/src/DetectorConstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ namespace B1
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

DetectorConstruction::DetectorConstruction()
{}
{
RegisterParallelWorld(&fParallelWorld);
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

Expand Down Expand Up @@ -116,35 +118,7 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
0, //copy number
checkOverlaps); //overlaps checking

//
// Shape 1
//
G4Material* shape1_mat = nist->FindOrBuildMaterial("G4_A-150_TISSUE");
G4ThreeVector pos1 = G4ThreeVector(0, 2*cm, -7*cm);

// Conical section shape
G4double shape1_rmina = 0.*cm, shape1_rmaxa = 2.*cm;
G4double shape1_rminb = 0.*cm, shape1_rmaxb = 4.*cm;
G4double shape1_hz = 3.*cm;
G4double shape1_phimin = 0.*deg, shape1_phimax = 360.*deg;
G4Cons* solidShape1 =
new G4Cons("Shape1",
shape1_rmina, shape1_rmaxa, shape1_rminb, shape1_rmaxb, shape1_hz,
shape1_phimin, shape1_phimax);

G4LogicalVolume* logicShape1 =
new G4LogicalVolume(solidShape1, //its solid
shape1_mat, //its material
"Shape1"); //its name

new G4PVPlacement(0, //no rotation
pos1, //at position
logicShape1, //its logical volume
"Shape1", //its name
logicEnv, //its mother volume
false, //no boolean operation
0, //copy number
checkOverlaps); //overlaps checking

//
// Shape 2
Expand All @@ -154,12 +128,11 @@ G4VPhysicalVolume* DetectorConstruction::Construct()

// Trapezoid shape
G4double shape2_dxa = 12*cm, shape2_dxb = 12*cm;
G4double shape2_dya = 10*cm, shape2_dyb = 16*cm;
G4double shape2_dz = 6*cm;
G4Trd* solidShape2 =
new G4Trd("Shape2", //its name
0.5*shape2_dxa, 0.5*shape2_dxb,
0.5*shape2_dya, 0.5*shape2_dyb, 0.5*shape2_dz); //its size
G4Box* solidShape2 =
new G4Box("Shape2", //its name
0.5*shape2_dxa, 0.5*shape2_dxb, 0.5*shape2_dz);


G4LogicalVolume* logicShape2 =
new G4LogicalVolume(solidShape2, //its solid
Expand Down
6 changes: 3 additions & 3 deletions examples/basic/B1/src/PrimaryGeneratorAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ PrimaryGeneratorAction::PrimaryGeneratorAction()
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4String particleName;
G4ParticleDefinition* particle
= particleTable->FindParticle(particleName="gamma");
= particleTable->FindParticle(particleName="geantino");
fParticleGun->SetParticleDefinition(particle);
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
fParticleGun->SetParticleEnergy(6.*MeV);
Expand Down Expand Up @@ -101,8 +101,8 @@ void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
}

G4double size = 0.8;
G4double x0 = size * envSizeXY * (G4UniformRand()-0.5);
G4double y0 = size * envSizeXY * (G4UniformRand()-0.5);
G4double x0 = 0.0;
G4double y0 = 0.0;
G4double z0 = -0.5 * envSizeZ;

fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
Expand Down
51 changes: 51 additions & 0 deletions examples/basic/B1/src/my_parallel_world.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "my_parallel_world.hh"

#include "G4Box.hh"
#include "G4PVPlacement.hh"
#include "G4SystemOfUnits.hh"

#include <ostream>
#include <string>
#include <thread>
#include <utility>

MyParallelWorld::MyParallelWorld() :
G4VUserParallelWorld{"MyParallelWorld"}
{
}

void MyParallelWorld::Construct()
{
auto* ghost_world = GetWorld()->GetLogicalVolume();

const double shift = 0;
G4ThreeVector pos2 = G4ThreeVector(0+shift, -1*cm+shift, 7*cm+shift);

// Trapezoid shape
G4double shape2_dxa = 12*cm, shape2_dxb = 12*cm;
// G4double shape2_dya = 10*cm, shape2_dyb = 16*cm;
G4double shape2_dz = 6*cm;
G4Box* solidShape2 =
new G4Box("Shape2_ghost", //its name
0.5*shape2_dxa, 0.5*shape2_dxb, 0.5*shape2_dz);


G4LogicalVolume* logicShape2 =
new G4LogicalVolume(solidShape2, //its solid
nullptr, //its material
"Shape2_ghost"); //its name

new G4PVPlacement(0, //no rotation
pos2, //at position
logicShape2, //its logical volume
"Shape2_ghost", //its name
ghost_world, //its mother volume
false, //no boolean operation
0, //copy number
false); //overlaps checking

}

void MyParallelWorld::ConstructSD()
{
}