Logical Volume Redefinitions using Generic Messenger and Macro Looping

I have defined a generic messenger to change the thickness of my x-ray target in my simulation. In a macro, I have defined it to loop over a certain range. However, upon each run after the first, I get the below error:

*** G4Exception : GeomMgt1001
      issued by : G4LogicalVolumeStore::GetVolume()
There exists more than ONE logical volume in store named: TargetLogic!
Returning the first found.
*** This is just a warning message. ***

I do have /run/reinitializeGeometry in the macro, but does something else have to happen when redefining the dimensions of a volume in this way? Thank you!

would you post the code (messenger and what is run by the messenger to change the thickness of the target)? otherwise I believe it would be just wild guessing what went wrong :wink:

1 Like

of course! Please find what I believe is the relevant code below, let me know if you need any other parts of it:

detectorConstruction::detectorConstruction() //constructor
    G4RunManager* runManager = G4RunManager::GetRunManager();
    Messenger = new G4GenericMessenger(this, "/detector/", "thickness");
    Messenger->DeclareProperty("thickness", Thickness, "Target thickness");


    Thickness = 0.5;


As you can see, the command to change the thickness is /detector/thickness X where X is the numeric value defined in the loop macro

as I understand, the messenger command alters the value that is stored in Thickness (which is overwritten in the following line with a default of 0.5 anyways, but that is probably not relevant at the moment). This should then influence the thickness within

G4VPhysicalVolume* detectorConstruction::Construct()


How/where do you call the reconstruction of the detector?

Probably the part of detectorconstruction where the Thickness is used in Construct() is also interesting…

1 Like

Thank you for your help. In the Construct() function, the thickness is simply called as below as I have it listed as a private variable in my header file:

 TargetSolid = new G4Box("TargetSolid", 0.5*m, 0.5*m, Thickness * um); 

and constructed as usual (i.e. with the logical/physical volume definitions).

I am unsure about what you’re referring to in terms of ‘reconstruction’ - after I change the thickness in the loop, I run the /run/reinitalizeGeometry macro command which I am under the impression does this reconstruction, but perhaps I am mistaken here?

Thank you for pointing out the Thickness overwrite - that’s an oversight that I’ll fix now!

That was what I meant. Looks fine to me, as it is exactly what is also done in

Not sure about this, but maybe defining the destructor (and deleting the world/experimental hall) could be the solution:

1 Like

Hmm I seem to be still getting the same error message even with the implementation of the destructor and deleting the world volume in it - not too sure what is going on!