Messengers not updating geometry

Geometry and simulation work fine when adjusting parameters from the source code.
However, when updating geometries via UI messengers or batch code, it doesn’t work.

Below is an example of what it looks like upon the first run, with default parameters set in the source code.
image

Below is an example of the number of detector columns set to 5 (originally set to 10 in c++ code) via UI messenger commands, and then breaks.
image

Below is my construction.cc code, where I determine my messengers.

#include "construction.hh"


MyDetectorConstruction::MyDetectorConstruction()
{

    nCols = 10;
    nRows = 10;

    xWorld = 0.05*m;
    yWorld = 0.05*m;
    zWorld = 0.05*m;

    xRadiator1 = 0.02*m;
    yRadiator1 = 0.02*m;
    zRadiator1 = 0.0025*m;
    dRadiator1 = 0.03*m;

    xRadiator2 = 0.02*m;
    yRadiator2 = 0.02*m;
    zRadiator2 = 0.005*m;
    dRadiator2 = 0.007*m;

    xDet = 0.02*m;
    yDet = 0.02*m;

    mRadiator1 = 2; // 1 = water, 2 = aerogel
    mRadiator2 = 3; // 3 = glass
    mWorld = 4; // 4 = air

    xPixel = xDet/nRows;
    yPixel = yDet/nCols;
    zPixel = 0.001*m;

    

    dMessenger = new G4GenericMessenger(this, "/detector/", "Detector Construction");
    wMessenger = new G4GenericMessenger(this, "/world/", "World Construction");
    r1Messenger = new G4GenericMessenger(this, "/Radiator1/", "Radiator1 Construction");
    r2Messenger = new G4GenericMessenger(this, "/Radiator2/", "Radiator2 Construction");
    mMessenger = new G4GenericMessenger(this, "/materials/", "Materials");

    dMessenger->DeclareProperty("Columns", nCols, "Number of columns");
    dMessenger->DeclareProperty("Rows", nRows, "Number of rows");
    dMessenger->DeclareProperty("XDetector", xDet, "X length of detector");
    dMessenger->DeclareProperty("YDetector", yDet, "Y length of detector");

    wMessenger->DeclareProperty("xWorld", xWorld, "X length of world");
    wMessenger->DeclareProperty("yWorld", yWorld, "Y length of world");
    wMessenger->DeclareProperty("zWorld", zWorld, "Z length of world");

    r1Messenger->DeclareProperty("xRadiator1", xRadiator1, "X length of Radiator1");
    r1Messenger->DeclareProperty("yRadiator1", yRadiator1, "Y length of Radiator1");
    r1Messenger->DeclareProperty("zRadiator1", zRadiator1, "Z length of Radiator1");
    r1Messenger->DeclareProperty("dRadiator1", dRadiator1, "Distance from Radiator1 to detectors");


    r2Messenger->DeclareProperty("xRadiator2", xRadiator2, "X length of Radiator2");
    r2Messenger->DeclareProperty("yRadiator2", yRadiator2, "Y length of Radiator2");
    r2Messenger->DeclareProperty("zRadiator2", zRadiator2, "Z length of Radiator2");
    r2Messenger->DeclareProperty("dRadiator2", dRadiator2, "Distance from Radiator2 to detectors");



    mMessenger->DeclareProperty("mRadiator1", mRadiator1, "Radiator 1 material");
    mMessenger->DeclareProperty("mRadiator2", mRadiator2, "Radiator 2 material");
    mMessenger->DeclareProperty("mWorld", mWorld, "World material");


    DefineMaterials();

}

MyDetectorConstruction::~MyDetectorConstruction()
{}

void MyDetectorConstruction::DefineMaterials()
{
    G4NistManager *nist = G4NistManager::Instance();  //the geant4 nist material database

	SiO2 = new G4Material("SiO2", 2.201*g/cm3, 2); //defining the silicone dioxide material object
	SiO2->AddElement(nist->FindOrBuildElement("Si"), 1);  //adding the silicone element to the object
	SiO2->AddElement(nist->FindOrBuildElement("O"), 2); //adding the oxygen element to the object

	H2O = new G4Material("H2O", 1.000*g/cm3, 2); //defining h20 material object
	H2O->AddElement(nist->FindOrBuildElement("H"), 2); //adding the hydrogen element to object
	H2O->AddElement(nist->FindOrBuildElement("O"), 1); //adding the oxygen element to object

	C = nist->FindOrBuildElement("C"); //creating the carbon material object

	B2O3 = new G4Material("B2O3", 2.46*g/cm3, 2);
	B2O3->AddElement(nist->FindOrBuildElement("B"), 2);
	B2O3->AddElement(nist->FindOrBuildElement("O"), 3);

	G4double energy[2] = {1.239841939*eV/0.9, 1.239841939*eV/0.2}; //momentum of photons usng conversion factor *eV / wavlength of red light and blue light

	G4double rindexAerogel[2] = {1.1, 1.1}; //refractive index of aerogel
	G4double rindexAir[2] = {1.0, 1.0}; //refractive index of the world volume (air)
	G4double rindexWater[2] = {1.333, 1.333}; //refractive index of the world volume (water)
	G4double rindexGlass[2] = {1.5, 1.5}; //refractive index of glass


    if(mRadiator1 == 1)
    {
        radiatorMat1 = nist->FindOrBuildMaterial("G4_WATER"); //createing the radiator material (water)
	    mptRadiator1 = new G4MaterialPropertiesTable(); //creating properites object for water
	    mptRadiator1->AddProperty("RINDEX", energy, rindexWater, 2); //adding property to object
	    radiatorMat1->SetMaterialPropertiesTable(mptRadiator1); //assigning properties object to radiator material object

    }
    if(mRadiator1 == 2)
    {

        radiatorMat1 = new G4Material("Aerogel", 0.200*g/cm3, 3); //creating the aerogel material object
	    radiatorMat1->AddMaterial(SiO2, 62.5*perCent);  //adding the silione dioxide material to aerogel object
	    radiatorMat1->AddMaterial(H2O, 37.4*perCent);  //adding the h20 material to aergoel object
	    radiatorMat1->AddElement(C, 0.1*perCent);  //adding the carbon material to aerogel object
	    mptRadiator1 = new G4MaterialPropertiesTable(); //creating aerogel material properties object
	    mptRadiator1->AddProperty("RINDEX", energy, rindexAerogel, 2); //adding property to this object
	    radiatorMat1->SetMaterialPropertiesTable(mptRadiator1); //assigning the Aergoel object the properties from the previous object created

    }
    if(mRadiator2 == 3)
    {

        radiatorMat2 = new G4Material("Glass", 2.23*g/cm3,2);//Creating glass
	    radiatorMat2->AddMaterial(SiO2, 70*perCent);
	    radiatorMat2->AddMaterial(B2O3, 30*perCent);
	    mptRadiator2 = new G4MaterialPropertiesTable(); //Creating glass material properties table
        mptRadiator2->AddProperty("RINDEX", energy, rindexGlass, 2); //adding property to this object

	    radiatorMat2->SetMaterialPropertiesTable(mptRadiator2); //setting material properties
    }


     if(mWorld == 4)
    {
        worldMat = nist->FindOrBuildMaterial("G4_AIR"); //createing the world material (air)
	    mptWorld = new G4MaterialPropertiesTable(); //creating properites object for air
	    mptWorld->AddProperty("RINDEX", energy, rindexAir, 2); //adding property to object
	    worldMat->SetMaterialPropertiesTable(mptWorld); //assigning properties object to world material object

    }



}

G4VPhysicalVolume *MyDetectorConstruction::Construct()
{

	G4Box *solidWorld = new G4Box("solidWorld", xWorld, yWorld, zWorld); //setting up world volume as a box

	G4LogicalVolume *logicWorld = new G4LogicalVolume(solidWorld, worldMat, "logicWorld"); //creating the world as dimensions from box and material

	G4VPhysicalVolume *physWorld = new G4PVPlacement(0, G4ThreeVector(0., 0., 0.), logicWorld, "physWorld", 0, false, 0, true); //placing the world into geant 4 sim



	G4Box *solidRadiator1 = new G4Box("solidRadiator1", xRadiator1, yRadiator1, zRadiator1); //setting the dimensions for the radiator

	G4LogicalVolume *logicRadiator1 = new G4LogicalVolume(solidRadiator1, radiatorMat1, "logicRadiator1"); //creating the aergoel radiator from dimensions

	G4VPhysicalVolume *physRadiator1 = new G4PVPlacement(0, G4ThreeVector(0., 0., zWorld-dRadiator1), logicRadiator1, "physRadiator1", logicWorld, false, 0, true); //placing radiator into world volume



	G4Box *solidRadiator2 = new G4Box("solidRadiator2", xRadiator2, yRadiator2, zRadiator2); //setting dimensions of glass radiator

	G4LogicalVolume *logicRadiator2 = new G4LogicalVolume(solidRadiator2, radiatorMat2, "logicRadiator2");

	G4VPhysicalVolume *physRadiator2 = new G4PVPlacement(0, G4ThreeVector(0., 0., zWorld-dRadiator2), logicRadiator2, "physRadiator2", logicWorld, false, 0, true);



	G4Box *solidDetector = new G4Box("solidDetector", xPixel, yPixel, zPixel);  //setting the dimensions for the detectors

	logicDetector = new G4LogicalVolume(solidDetector, worldMat, "logicDetector"); //creating the detectors, with same material as world


	for(G4int i = 0; i < nRows; i++)
	{

		for(G4int j = 0; j <nCols; j++)
		{
		    posX = -xDet+(i*2*xDet/nRows) + xDet/nRows;

		    posY = -yDet+(j*2*yDet/nCols) + yDet/nCols;

		    posZ = zWorld - zPixel;

			physDetector= new G4PVPlacement(0, G4ThreeVector(posX, posY, posZ), logicDetector, "physDetector", logicWorld, false, j+i*nCols, true); //placing detectors into the world

			G4cout << posX << posY << posZ << G4endl;

		}
	}



	return physWorld; //returning the world, including everything inside
}

void MyDetectorConstruction::ConstructSDandField()
{

    MySensitiveDetector *sensDet = new MySensitiveDetector("SensitiveDetector"); //creating a sensitive detector object

    if(logicDetector != NULL)
    {
       logicDetector->SetSensitiveDetector(sensDet); //assigning the detectors as senstive detectors (it generates a hit when a track traverses its volume)
    }

}


1 Like

Do you have a runManager->Initialize() embedded in your main()? If so, then the geometry is getting built before you change any of the parameters.

If you change the geometry parameters via macro, then you should also call runManager->GeometryHasBeenModified(), which will trigger the Run Manager to rebuild it (with your new values). I am not familiar with how to do this via G4GenericMessenger, but I would expect there to be examples that show it.

Hello thanks for getting back to me!

Yes I do have runManager->Initialize() in my main()

Main simulation file embedded below:

#include <iostream>

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

#include "construction.hh"
#include "physics.hh"
#include "action.hh"

int main(int argc, char** argv)
{


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

	runManager->SetUserInitialization(new MyDetectorConstruction());
	runManager->SetUserInitialization(new MyPhysicsList());
	runManager->SetUserInitialization(new MyActionInitialization());
	runManager->Initialize();


	G4UIExecutive  *ui = 0;

	if(argc == 1)
	{
		ui = new G4UIExecutive(argc, argv);
	}


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

	G4UImanager * UImanager = G4UImanager::GetUIpointer();

	if(ui)
	{
		UImanager->ApplyCommand("/control/execute vis.mac");
		ui->SessionStart();
	}
	else
	{
		G4String command = "/control/execute ";
		G4String fileName = argv[1];
		UImanager->ApplyCommand(command+fileName);
	}

	


    return 0;
}

Where do I run the runManager->GeometryHasBeenModified() command?

below is my macro file where i am changing my parameters via the generic messengers I have created in my construction.cc file (this macro file is executed from my vis.mac macro file):


/run/reinitializeGeometry

/gun/particle mu+
/gun/energy 4 GeV


/world/xWorld 0.06
/world/yWorld 0.06
/world/zWorld 0.06


/detector/xDet 0.012
/detector/yDet 0.012

/detector/nCols 10
/detector/nRows 10


/Radiator1/xRadiator1 0.02
/Radiator1/yRadiator1 0.2
/Radiator1/zRadiator1 0.005
/Radiator1/dRadiator1 0.04


/materials/mRadiator1 2

/materials/mWorld 3


/run/geometryModified
/run/initialize
/run/beamOn 1

Am I changing the parameters correctly via the macro file method??

Okay. So your geometry is getting built with all of the default settings, before your macro commands are ever even seen. If you don’t mind modifying your macro, I would recommend the following:

  1. Remove runManager->Initialize() from your main().
  2. Add /run/initialize to your macro file immediately before /run/beamOn. That will happen after all your macro commands setting up the geometry.

An alternative is to add the call to runManager->GeometryHasBeenModified() to each of your macro commands. I don’t know how to do that; you’ll have to read the documentation.

1 Like

I have adjusted my code so that now runManager->Initialize() has been removed from my main(), and inserted run/initialize before run/beamOn 1 in my macro file, after setting up all my parameters.
However, this didn’t work at first as then nothing was being built.
So I added run/initialize before setting up my parameters and after, and now it builds the new geometries, but with a few errors…

Firstly, the detectors are now not being built, and it says they are “overlapping with the mother volume” - I have checked the geometries and have no idea why this is happening.

Secondly, when I press the run beam, nothing is generated. I should see Cherenkov radiation through my 2 radiators but there is nothing.

Below is my updated macro file:

/run/initialize
/run/reinitializeGeometry

/gun/particle mu+
/gun/energy 4 GeV


/world/xWorld 0.05
/world/yWorld 0.05
/world/zWorld 0.05

/detector/xDetector 0.02
/detector/yDetector 0.02


/detector/Columns 10
/detector/Rows 10


/Radiator1/xRadiator1 0.02
/Radiator1/yRadiator1 0.04
/Radiator1/zRadiator1 0.005
/Radiator1/dRadiator1 0.03

/Radiator2/xRadiator2 0.02
/Radiator2/yRadiator2 0.02
/Radiator2/zRadiator2 0.005
/Radiator2/dRadiator2 0.007


/materials/mRadiator1 2

/materials/mWorld 3

/run/geometryModified
/run/initialize
/run/beamOn 1

Below is my updated main() file:\

#include <iostream>

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

#include "construction.hh"
#include "physics.hh"
#include "action.hh"

int main(int argc, char** argv)
{


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

	runManager->SetUserInitialization(new MyDetectorConstruction());
	runManager->SetUserInitialization(new MyPhysicsList());
	runManager->SetUserInitialization(new MyActionInitialization());
	//runManager->Initialize();


	G4UIExecutive  *ui = 0;

	if(argc == 1)
	{
		ui = new G4UIExecutive(argc, argv);
	}


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

	G4UImanager * UImanager = G4UImanager::GetUIpointer();

	if(ui)
	{
		UImanager->ApplyCommand("/control/execute vis.mac");
		ui->SessionStart();
	}
	else
	{
		G4String command = "/control/execute ";
		G4String fileName = argv[1];
		UImanager->ApplyCommand(command+fileName);
	}

	


    return 0;
}

Below is my construction.cc file - where my geometries are being created:

#include "construction.hh"


MyDetectorConstruction::MyDetectorConstruction()
{

    nCols = 10;
    nRows = 10;

    xWorld = 0.05*m;
    yWorld = 0.05*m;
    zWorld = 0.05*m;

    xRadiator1 = 0.02*m;
    yRadiator1 = 0.02*m;
    zRadiator1 = 0.005*m;
    dRadiator1 = 0.03*m;

    xRadiator2 = 0.02*m;
    yRadiator2 = 0.02*m;
    zRadiator2 = 0.005*m;
    dRadiator2 = 0.007*m;

    xDet = 0.02*m;
    yDet = 0.02*m;

    mRadiator1 = 2; // 1 = water, 2 = aerogel
    mRadiator2 = 3; // 3 = glass
    mWorld = 4; // 4 = air

    xPixel = xDet/nRows;
    yPixel = yDet/nCols;
    zPixel = 0.001*m;

    

    dMessenger = new G4GenericMessenger(this, "/detector/", "Detector Construction");
    wMessenger = new G4GenericMessenger(this, "/world/", "World Construction");
    r1Messenger = new G4GenericMessenger(this, "/Radiator1/", "Radiator1 Construction");
    r2Messenger = new G4GenericMessenger(this, "/Radiator2/", "Radiator2 Construction");
    mMessenger = new G4GenericMessenger(this, "/materials/", "Materials");

    dMessenger->DeclareProperty("Columns", nCols, "Number of columns");
    dMessenger->DeclareProperty("Rows", nRows, "Number of rows");
    dMessenger->DeclareProperty("xDetector", xDet, "X length of detector");
    dMessenger->DeclareProperty("yDetector", yDet, "Y length of detector");

    wMessenger->DeclareProperty("xWorld", xWorld, "X length of world");
    wMessenger->DeclareProperty("yWorld", yWorld, "Y length of world");
    wMessenger->DeclareProperty("zWorld", zWorld, "Z length of world");

    r1Messenger->DeclareProperty("xRadiator1", xRadiator1, "X length of Radiator1");
    r1Messenger->DeclareProperty("yRadiator1", yRadiator1, "Y length of Radiator1");
    r1Messenger->DeclareProperty("zRadiator1", zRadiator1, "Z length of Radiator1");
    r1Messenger->DeclareProperty("dRadiator1", dRadiator1, "Distance from Radiator1 to detectors");


    r2Messenger->DeclareProperty("xRadiator2", xRadiator2, "X length of Radiator2");
    r2Messenger->DeclareProperty("yRadiator2", yRadiator2, "Y length of Radiator2");
    r2Messenger->DeclareProperty("zRadiator2", zRadiator2, "Z length of Radiator2");
    r2Messenger->DeclareProperty("dRadiator2", dRadiator2, "Distance from Radiator2 to detectors");



    mMessenger->DeclareProperty("mRadiator1", mRadiator1, "Radiator 1 material");
    mMessenger->DeclareProperty("mRadiator2", mRadiator2, "Radiator 2 material");
    mMessenger->DeclareProperty("mWorld", mWorld, "World material");


    DefineMaterials();

}

MyDetectorConstruction::~MyDetectorConstruction()
{}

void MyDetectorConstruction::DefineMaterials()
{
    G4NistManager *nist = G4NistManager::Instance();  //the geant4 nist material database

	SiO2 = new G4Material("SiO2", 2.201*g/cm3, 2); //defining the silicone dioxide material object
	SiO2->AddElement(nist->FindOrBuildElement("Si"), 1);  //adding the silicone element to the object
	SiO2->AddElement(nist->FindOrBuildElement("O"), 2); //adding the oxygen element to the object

	H2O = new G4Material("H2O", 1.000*g/cm3, 2); //defining h20 material object
	H2O->AddElement(nist->FindOrBuildElement("H"), 2); //adding the hydrogen element to object
	H2O->AddElement(nist->FindOrBuildElement("O"), 1); //adding the oxygen element to object

	C = nist->FindOrBuildElement("C"); //creating the carbon material object

	B2O3 = new G4Material("B2O3", 2.46*g/cm3, 2);
	B2O3->AddElement(nist->FindOrBuildElement("B"), 2);
	B2O3->AddElement(nist->FindOrBuildElement("O"), 3);

	G4double energy[2] = {1.239841939*eV/0.9, 1.239841939*eV/0.2}; //momentum of photons usng conversion factor *eV / wavlength of red light and blue light

	G4double rindexAerogel[2] = {1.1, 1.1}; //refractive index of aerogel
	G4double rindexAir[2] = {1.0, 1.0}; //refractive index of the world volume (air)
	G4double rindexWater[2] = {1.333, 1.333}; //refractive index of the world volume (water)
	G4double rindexGlass[2] = {1.5, 1.5}; //refractive index of glass


    if(mRadiator1 == 1)
    {
        radiatorMat1 = nist->FindOrBuildMaterial("G4_WATER"); //createing the radiator material (water)
	    mptRadiator1 = new G4MaterialPropertiesTable(); //creating properites object for water
	    mptRadiator1->AddProperty("RINDEX", energy, rindexWater, 2); //adding property to object
	    radiatorMat1->SetMaterialPropertiesTable(mptRadiator1); //assigning properties object to radiator material object

    }
    if(mRadiator1 == 2)
    {

        radiatorMat1 = new G4Material("Aerogel", 0.200*g/cm3, 3); //creating the aerogel material object
	    radiatorMat1->AddMaterial(SiO2, 62.5*perCent);  //adding the silione dioxide material to aerogel object
	    radiatorMat1->AddMaterial(H2O, 37.4*perCent);  //adding the h20 material to aergoel object
	    radiatorMat1->AddElement(C, 0.1*perCent);  //adding the carbon material to aerogel object
	    mptRadiator1 = new G4MaterialPropertiesTable(); //creating aerogel material properties object
	    mptRadiator1->AddProperty("RINDEX", energy, rindexAerogel, 2); //adding property to this object
	    radiatorMat1->SetMaterialPropertiesTable(mptRadiator1); //assigning the Aergoel object the properties from the previous object created

    }
    if(mRadiator2 == 3)
    {

        radiatorMat2 = new G4Material("Glass", 2.23*g/cm3,2);//Creating glass
	    radiatorMat2->AddMaterial(SiO2, 70*perCent);
	    radiatorMat2->AddMaterial(B2O3, 30*perCent);
	    mptRadiator2 = new G4MaterialPropertiesTable(); //Creating glass material properties table
        mptRadiator2->AddProperty("RINDEX", energy, rindexGlass, 2); //adding property to this object

	    radiatorMat2->SetMaterialPropertiesTable(mptRadiator2); //setting material properties
    }


     if(mWorld == 4)
    {
        worldMat = nist->FindOrBuildMaterial("G4_AIR"); //createing the world material (air)
	    mptWorld = new G4MaterialPropertiesTable(); //creating properites object for air
	    mptWorld->AddProperty("RINDEX", energy, rindexAir, 2); //adding property to object
	    worldMat->SetMaterialPropertiesTable(mptWorld); //assigning properties object to world material object

    }



}

G4VPhysicalVolume *MyDetectorConstruction::Construct()
{

	G4Box *solidWorld = new G4Box("solidWorld", xWorld, yWorld, zWorld); //setting up world volume as a box

	G4LogicalVolume *logicWorld = new G4LogicalVolume(solidWorld, worldMat, "logicWorld"); //creating the world as dimensions from box and material

	G4VPhysicalVolume *physWorld = new G4PVPlacement(0, G4ThreeVector(0., 0., 0.), logicWorld, "physWorld", 0, false, 0, true); //placing the world into geant 4 sim



	G4Box *solidRadiator1 = new G4Box("solidRadiator1", xRadiator1, yRadiator1, zRadiator1); //setting the dimensions for the radiator

	G4LogicalVolume *logicRadiator1 = new G4LogicalVolume(solidRadiator1, radiatorMat1, "logicRadiator1"); //creating the aergoel radiator from dimensions

	G4VPhysicalVolume *physRadiator1 = new G4PVPlacement(0, G4ThreeVector(0., 0., zWorld-dRadiator1), logicRadiator1, "physRadiator1", logicWorld, false, 0, true); //placing radiator into world volume



	G4Box *solidRadiator2 = new G4Box("solidRadiator2", xRadiator2, yRadiator2, zRadiator2); //setting dimensions of glass radiator

	G4LogicalVolume *logicRadiator2 = new G4LogicalVolume(solidRadiator2, radiatorMat2, "logicRadiator2");

	G4VPhysicalVolume *physRadiator2 = new G4PVPlacement(0, G4ThreeVector(0., 0., zWorld-dRadiator2), logicRadiator2, "physRadiator2", logicWorld, false, 0, true);



	G4Box *solidDetector = new G4Box("solidDetector", xPixel, yPixel, zPixel);  //setting the dimensions for the detectors

	logicDetector = new G4LogicalVolume(solidDetector, worldMat, "logicDetector"); //creating the detectors, with same material as world


	for(G4int i = 0; i < nRows; i++)
	{

		for(G4int j = 0; j <nCols; j++)
		{
		    posX = -xDet+(i*2*xDet/nRows) + xDet/nRows;

		    posY = -yDet+(j*2*yDet/nCols) + yDet/nCols;

		    posZ = zWorld - zPixel;

			physDetector= new G4PVPlacement(0, G4ThreeVector(posX, posY, posZ), logicDetector, "physDetector", logicWorld, false, j+i*nCols, true); //placing detectors into the world

			G4cout << posX << posY << posZ << G4endl;

		}
	}



	return physWorld; //returning the world, including everything inside
}

void MyDetectorConstruction::ConstructSDandField()
{

    MySensitiveDetector *sensDet = new MySensitiveDetector("SensitiveDetector"); //creating a sensitive detector object

    if(logicDetector != NULL)
    {
       logicDetector->SetSensitiveDetector(sensDet); //assigning the detectors as senstive detectors (it generates a hit when a track traverses its volume)
    }

}


And not sure whether this will have any effect but, below is my vis.mac file, which sets all the visual properties of the simulation:

/vis/open OGL
/vis/viewer/set/viewpointVector 1 1 1
/vis/drawVolume
/vis/viewer/set/autoRefresh true
/vis/scene/add/trajectories smooth
/vis/scene/add/scale 10 cm
/vis/scene/add/axes
/vis/scene/add/eventID
/vis/scene/endOfEventAction accumulate
/control/execute set.mac

Any help would be appreciated!

Did you ever figure this out? I’m also having some issue with the geometry not updating after running ReinitializeGeometry() in the source file, or /run/reinitializeGeometry in a macro

Me too, Maybe this is a bug.

This is a snippet that works for me, maybe this helps?
The function is called via macro command in a messenger…

void DetectorConstruction::setRadius(G4double radius) {
    G4GeometryManager::GetInstance() -> OpenGeometry();

    //* example
    auto pipe = static_cast<G4Tubs*>(G4LogicalVolumeStore::GetInstance()->GetVolume("pipe")->GetSolid());
    pipe->SetOuterRadius(radius);
    //*

    G4RunManager::GetRunManager()->GeometryHasBeenModified();
    G4UImanager* UImanager = G4UImanager::GetUIpointer();
    if(UImanager->GetUIpointer()) {
        UImanager->ApplyCommand("/vis/viewer/rebuild");
    }
}
1 Like

I tried the two method, it did not work. Maybe this is reallly a bug.