Link two variable from DetectorConstruction to PrimaryGenerationAction

Hi,

I build a simulation in GEANT4 where the geometry is build as a function of the radius r1 :

namespace B3
{

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

DetectorConstruction::DetectorConstruction()
{ }

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

DetectorConstruction::~DetectorConstruction()
{ }

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

G4VPhysicalVolume* DetectorConstruction::Construct()
{

/*

Tutta la geometria è definita in funzione di r1, in questo modo è possibile come variano 
le prestazioni in funzione di tale parametro.

*/

G4double r1 = 2.25*cm;                  //raggio sfera analizzatrice
G4double r2 = r1*2+r1/4.5;             //raggio cilindro
G4double hz = r1*2+r1/4.5;            //altezza cilindro
G4double a  = r1-r1/1.8;                 //altezza condotto 
G4double l  = r2-r1-a;                     //lughezza condotto
G4double d  = r1/18;                      //larghezza condotto
G4double world_sizeXY = 2*r2;     //World size XY

[...]

In a similar way, the position of source is linked to this parameter r1:


namespace B3 {

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

    PrimaryGeneratorAction::PrimaryGeneratorAction() {

        fParticleGun = new G4ParticleGun(1);

        fRandomDirection = false;
        fPolarized = false;
        fPolarization = 0.;

        // default particle kinematic
        G4ParticleTable * particleTable = G4ParticleTable::GetParticleTable();
        G4ParticleDefinition * particle = particleTable -> FindParticle("opticalphoton");

        fParticleGun -> SetParticleDefinition(particle);

    }

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

    PrimaryGeneratorAction::~PrimaryGeneratorAction() {
        delete fParticleGun;
    }

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

    void PrimaryGeneratorAction::GeneratePrimaries(G4Event * anEvent) {


        G4double r1 = 2.25*cm;                    //raggio sfera analizzatrice
        G4double r2 = r1*2+r1/4.5;                //raggio cilindro
        G4double a  = r1-r1/1.8;                  //altezza condotto 
        G4double d  = r1/18;                      //larghezza condotto


        G4double x0 = r2-d;
        G4double z0 = 0 * cm; 
        G4double y0 = a;

        /*

        La distribuzione angolare fibra NA = n_liquido sin(theta) ---> sin(theta) = 0.22/1.33 --> theta = 9.5° circa 10°, cono di apertura
        da cui 180° - 10° = 170° --> 170°/2 = 85°. Da 0° a 85° non spara, tra 85° e 95° si, tra 95° e 180° no
        per cui, il cos(85°) = 0.087. Il generatore di cos theta deve oscillare tra +/- 0.087. Invece phi oscilla tra 3.054 - 3.054 rad = 185° - 175°.
        
        */

        G4double n = 0.087; // n= 1 se vuoi una distribuzione sferica
        
        G4double cosTheta = 2 * (n) * G4UniformRand() - 1 * (n);
        G4double phi = (G4UniformRand()*0.175 +3.054)*rad;      
        G4double sinTheta = std::sqrt(1. - cosTheta * cosTheta);

        //Bisogna stare attenti, GEANT4 definisce a modo suo gli assi, non secondi gli standard comuni.

        G4double ux = sinTheta * std::cos(phi);
        G4double uz = sinTheta * std::sin(phi);
        G4double uy = cosTheta;

        fParticleGun -> SetParticleMomentumDirection(G4ThreeVector(ux,uy,uz)); 
        fParticleGun -> SetParticlePosition(G4ThreeVector(x0, y0, z0));

[...]

How can I link the two different r1?

Maybe I can use the pointer of Detectorconstruction.cc in order tu use all the variable defined there, but… I don’t know how to do this.

Thank for the help.

-SM

You can follow what is done in electromagnetic, eg. TestEm1

  • in the main, pass a DetectorConstruction* pointer to ActionInitialization
  • in ActionInitialization.cc, propagate this pointer to PrimaryGeneratorAction
    Do not forget to modify PrimaryGeneratorAction.hh accordingly
  • in DetectorConstruction, make r1 as a data member. Add a public Getr1() function
  • then, in PrimaryGeneratorAction :
    G4double r1 = fDetector->Getr1();
1 Like

Thanks for the reply but seems arabic to me (I’m a new user). There is an easy way to do it?