Not able to see photons in my visualization

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

_Geant4 Version: 4.11.1
_Operating System: Windows 10
_Compiler/Version: Visual Studio 17.11
_CMake Version: 3.30.11


Hello everyone,
I cannot see any photon interaction in the visualization when running my code.

Here are my main.cc & PhysicsLists.cc

#include <iostream>

#include "G4RunManager.hh"
#include "G4MTRunManager.hh"
#include "G4UImanager.hh"
#include "G4VisManager.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"

#include "PMPhysicsList.hh"
#include "PMDetectorConstruction.hh"
#include "PMActionInitialization.hh"

int main(int argc, char** argv)
{
    G4UIExecutive *ui = new G4UIExecutive(argc, argv);

    #ifdef G4MULTITHREADED
        G4MTRunManager *runManager = new G4MTRunManager;
    #else
        G4RunManager *runManger = new G4RunManager;
    #endif

    // Physics list
    runManager->SetUserInitialization(new PMPhysicsList());

    // Detector construction
    runManager->SetUserInitialization(new PMDetectorConstruction());

    // Action initialization
    runManager->SetUserInitialization(new PMActionInitialization());

    G4VisManager *visManager = new G4VisExecutive();
    visManager->Initialize();

    G4UImanager *UImanager = G4UImanager::GetUIpointer();

    UImanager->ApplyCommand("/control/execute vis.mac");

    ui->SessionStart();

    return 0;
}

Blockquote

#include "PMPhysicsList.hh"
#include "G4EmStandardPhysics_option4.hh"
#include "G4OpticalPhysics.hh"

PMPhysicsList::PMPhysicsList()
{
    //EM Physics
    RegisterPhysics(new G4EmStandardPhysics());
    RegisterPhysics(new G4EmStandardPhysics_option4());
    RegisterPhysics(new G4OpticalPhysics());
}

PMPhysicsList::~PMPhysicsList()
{
}

Also I use the followin macro file:

/run/initialize

/vis/open OGL 800x800-0+0
#/vis/open VRML2FILE

/vis/viewer/set/viewpointVector 1 1 1
/vis/viewer/set/autoRefresh true

/vis/drawVolume

/vis/scene/add/trajectories smooth
/vis/scene/endOfEventAction accumulate
#/vis/scene/add/scale 10 cm
#/vis/scene/add/axes
#/vis/scene/add/eventID

# Define particle source
/gun/particle gamma
/gun/energy 10 MeV

# Set the initial position of the particle gun if needed
/gun/position 0 0 -0.25 m

# Set the direction of the particle gun (pointing along the z-axis)
/gun/direction 0 0 1

# Set the number of particles to be shot
/run/beamOn 100

I appreciate your help and guidance.

What exactly do you see?

Are photons interacting? Investigate with /tracking/verbose 2.

Thank you for your response. I tried /tracking/verbose 2 and got nothing regarding photon visualization (please see the attached photo). I believe photons are interacting.

I use the following macro file:

/run/initialize

/vis/open OGL 800x800-0+0
#/vis/open VRML2FILE

/vis/viewer/set/viewpointVector 1 1 1
/vis/viewer/set/autoRefresh true

/vis/drawVolume

/vis/scene/add/trajectories smooth
/vis/scene/endOfEventAction accumulate
#/vis/scene/add/scale 10 cm
#/vis/scene/add/axes
#/vis/scene/add/eventID

/tracking/verbose 2

# Define particle source
/gun/particle gamma
/gun/energy 0.511 MeV

# Set the initial position of the particle gun if needed
/gun/position 0 0 -0.25 m

# Set the direction of the particle gun (pointing along the z-axis)
/gun/direction 0 0 1

# Set the number of particles to be shot
/run/beamOn 10

I cannot identify where my mistake is.

There are no optical photons listed in that tracking output, though depending on the exact dimensions of that setup and the materials they’re constructed from, I’d expect to see the other gamma/electron tracks displayed.

Can you share the code for PMDetectorConstruction and PMActionInitialization please?

Thank you for your response. Here are the files:

#include "PMDetectorConstruction.hh"
#include "G4VUserDetectorConstruction.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4Tubs.hh" 
#include "G4PVPlacement.hh"
#include "G4NistManager.hh"
#include "G4SystemOfUnits.hh"
#include "G4VisAttributes.hh"
#include "G4Colour.hh"

PMDetectorConstruction::PMDetectorConstruction()
{
}

PMDetectorConstruction::~PMDetectorConstruction()
{
}

G4VPhysicalVolume *PMDetectorConstruction::Construct()
{
    // Define materials

    G4NistManager* nist = G4NistManager::Instance();
    G4Material* worldMat = nist->FindOrBuildMaterial("G4_AIR");
    G4Material* leadMat = nist->FindOrBuildMaterial("G4_Pb");
    G4Material* NaIMat = nist->FindOrBuildMaterial("G4_SODIUM_IODIDE");
    G4Material* CrBi = new G4Material("CrBi", 8.55 * g / cm3, 2);
    CrBi->AddElement(nist->FindOrBuildElement("Cr"), 1);
    CrBi->AddElement(nist->FindOrBuildElement("Bi"), 1);
    

    // World volume
    G4Box* solidWorld = new G4Box("solidWorld", 0.25 * m, 0.25 * m, 0.25 * m); //World volume
    G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, worldMat, "logicWorld"); //Mother volume
    G4VPhysicalVolume* physWorld = new G4PVPlacement(0, G4ThreeVector(0., 0., 0.), logicWorld, "physWorld", 0, false, 0, true); //Daughter volume

    // Set visibility of the world volume to false
    //logicWorld->SetVisAttributes(G4VisAttributes::GetInvisible());


     // Collimator 1 next to source
    G4double collimatorInnerRadius = 1. * cm;
    G4double collimatorOuterRadius = 10 * cm; // 20 cm / 2
    G4double collimatorHalfLengthZ = 2.5 * cm; // 5 cm / 2
    G4Tubs* solidCollimator = new G4Tubs("solidCollimator", collimatorInnerRadius, collimatorOuterRadius, collimatorHalfLengthZ, 0., 2 * 3.14159265359);
    G4ThreeVector collimatorPos(0., 0., -0.10 * m);
    G4LogicalVolume* logicCollimator = new G4LogicalVolume(solidCollimator, leadMat, "logicCollimator");
    new G4PVPlacement(0, collimatorPos, logicCollimator, "physCollimator", logicWorld, false, 0, true);

    // Set visualization attributes for the Collimator1
    G4VisAttributes* CollAttr = new G4VisAttributes(G4Colour(0.5, 0.5, 0.5));
    CollAttr->SetVisibility(true);
    //CollAttr->SetForceWireframe(false);
    CollAttr->SetForceSolid(true); // Render as solid
    logicCollimator->SetVisAttributes(CollAttr);

    // Sample 

    G4double sampleInnerRadius = 0.0 * cm;
    G4double sampleOuterRadius = 5. * cm;
    G4double sampleThickness = 1. * cm; 
    G4Tubs* solidSample = new G4Tubs("solidSample", sampleInnerRadius, sampleOuterRadius, sampleThickness, 0., 2 * 3.14159265359);
    G4ThreeVector samplePos(0., 0., 0.);
    G4LogicalVolume* logicSample = new G4LogicalVolume(solidSample, CrBi, "logicSample");
    new G4PVPlacement(0, samplePos, logicSample, "physSample", logicWorld, false, 0, true);

    // Set visualization attributes for the Sample
    G4VisAttributes* SampleAttr = new G4VisAttributes(G4Colour(0., 1., 0.));
    SampleAttr->SetVisibility(true);
    //SampleAttr->SetForceWireframe(false);
    SampleAttr->SetForceSolid(true); // Render as solid
    logicSample->SetVisAttributes(SampleAttr);
    

    
        // Collimator 2 next to the detector
    G4double collimatorInnerRadius2 = 7.5 * cm;
    G4double collimatorOuterRadius2 = 10 * cm; // 20 cm / 2
    G4double collimatorHalfLengthZ2 = 2.5 * cm; // 5 cm / 2
    G4Tubs* solidCollimator2 = new G4Tubs("solidCollimator2", collimatorInnerRadius2, collimatorOuterRadius2, collimatorHalfLengthZ2, 0., 2 * 3.14159265359);
    G4ThreeVector collimatorPos2(0., 0., 0.225 * m);
    G4LogicalVolume* logicCollimator2 = new G4LogicalVolume(solidCollimator2, leadMat, "logicCollimator2");
    new G4PVPlacement(0, collimatorPos2, logicCollimator2, "physCollimator2", logicWorld, false, 0, true);

    // Set visualization attributes for the Collimator2
    G4VisAttributes* CollyAttr2 = new G4VisAttributes(G4Colour(0.5, 0.5, 0.5));
    CollyAttr2->SetVisibility(true);
    //CollyAttr->SetForceWireframe(false);
    CollyAttr2->SetForceSolid(true);
    logicCollimator2->SetVisAttributes(CollyAttr2);


    // NaI Detector
    G4double NaIRadius = 7.5 * cm;
    G4double NaIHalfLengthZ = 2.5 * cm;
    G4Tubs* solidNaI = new G4Tubs("solidNaI", 0., NaIRadius, NaIHalfLengthZ, 0., 2 * 3.14159265359);
    G4ThreeVector NaIPos(0., 0., 0.225 * m);
    G4LogicalVolume* logicNaI = new G4LogicalVolume(solidNaI, NaIMat, "logicNaI");
    new G4PVPlacement(0, NaIPos, logicNaI, "physNaI", logicWorld, false, 0, true);


    // Set visualization attributes for the NaI Detector
    G4VisAttributes* DetectorAttr = new G4VisAttributes(G4Colour(1., 0., 0.)); //The order is Red, green, blue
    DetectorAttr->SetVisibility(true);
    //DetectorAttr->SetForceWireframe(false);
    DetectorAttr->SetForceSolid(true);
    logicNaI->SetVisAttributes(DetectorAttr);

    // Source
    G4double SourceRadius = 2. * cm;
    G4double SourceHalfLengthZ = 2. * cm;
    G4Tubs* solidSource = new G4Tubs("soliSource", 0., SourceRadius, SourceHalfLengthZ, 0., 2 * 3.14159265359);
    G4ThreeVector SourcePos(0., 0., -0.225 * m);
    G4LogicalVolume* logicSource = new G4LogicalVolume(solidSource, worldMat, "logicSource");
    new G4PVPlacement(0, SourcePos, logicSource, "physSource", logicWorld, false, 0, true);


    // Set visualization attributes for the Source
    G4VisAttributes* SourceAttr = new G4VisAttributes(G4Colour(0., 0., 1.)); //The order is Red, green, blue
    SourceAttr->SetVisibility(true);
    //DetectorAttr->SetForceWireframe(false);
    SourceAttr->SetForceSolid(true);
    logicSource->SetVisAttributes(SourceAttr);


    return physWorld;
}
#ifndef PMDETECTORCONSTRUCTION_HH
#define PMDETECTORCONSTRUCTION_HH

#include "G4VUserDetectorConstruction.hh"



class PMDetectorConstruction : public G4VUserDetectorConstruction
{
public:
    PMDetectorConstruction();
    virtual ~PMDetectorConstruction();

    virtual G4VPhysicalVolume *Construct();
};

#endif
#include "PMActionInitialization.hh"

PMActionInitialization::PMActionInitialization()
{}

PMActionInitialization::~PMActionInitialization()
{}

void PMActionInitialization::BuildForMaster() const
{}

void PMActionInitialization::Build() const
{
    PMPrimaryGenerator *generator = new PMPrimaryGenerator();
    SetUserAction(generator);
}
#ifndef PMACTIONINITIALIZATION_HH
#define PMACTIONINITIALIZATION_HH

#include "G4VUserActionInitialization.hh"

#include "PMPrimaryGenerator.hh"

class PMActionInitialization : public G4VUserActionInitialization
{
public:
    PMActionInitialization();
    ~PMActionInitialization();

    virtual void BuildForMaster() const;
    virtual void Build() const;
};

#endif

@OdaiSuad
These are the properties you must add in your geant4 code (PMDetectorConstruction)then only you can see the optical photons
(1) refractive index
(2) optical_yield (optical photons produced per MeV of energy deposited), or you can add range of optical photons produced per energy deposited
(3) emission spectrum
(4) absorption length
(5) optical decay times
(6) resolution scale

@OdaiSuad apologies for not replying sooner - I think the previous message may hold the answer, but just to check that visualisation itself is functioning, maybe try:

/gun/particle geantino
/gun/energy 0.511 MeV

This will shoot dummy particles that will not interact with the detector, but should still be visualised.

I apologize; could you please explain more? I don’t understand what I should do. Thanks in advance.

Thank you for your assistance and unwavering support. I have fired a 15 MeV geantino, but there is nothing visible in the geometry. Please see the attached screenshot.

I apologize for not understanding the previous message regarding what to add to the detector construction.

Could you try building example B1 and running that please (if you haven’t done so in this installation already)? Just try executing /run/beamOn 10 in the UI and see if tracks appear in the visualisation.

This will just help to see if there’s a problem on the system, or somewhere in Geant4/the application.

So many thanks. I executed the B1 example and used the built-in macros, obtaining the results shown in the attached screenshot.

Thanks @OdaiSuad, that’s good as it shows tracks can be visualised, so the install of Geant4 and the system graphics drivers appear fine.

Could you upload the full code for the application along with build scripts and macros please (or its home of GitHub or other hosting system)?

Thank you very much for your reply.

Attached is the full code for your reference. I would like to mention that the original code was obtained from (GitHub - MustafaSchmidt/geant4-11-tutorial), and I have made some modifications to suit my requirements.

Here is the updated code:
PMActionInitialization.cc (339 Bytes)
PMDetectorConstruction.cc (5.5 KB)
PMPhysicsList.cc (339 Bytes)
PMPrimaryGenerator.cc (962 Bytes)
sim.cc (1.0 KB)
CMakeLists.txt (469 Bytes)
PMActionInitialization.hh (367 Bytes)
PMDetectorConstruction.hh (314 Bytes)
PMPrimaryGenerator.hh (457 Bytes)

PMPhysicsList.hh (238 Bytes)

vis.mac.txt (620 Bytes)

Thanks - will try it out, but am going to need a few days to find the time.

1 Like