GeantTips

From Mu2eWiki
Jump to navigation Jump to search

Introduction

Duplicate volume names

In G4 it is legal to create multiple logical volumes with the same name. For many purposes this is just fine; in particular G4 itself will work just fine. However if you do this there is one feature of G4 you must never use or it will silently produce incorrect results and without warning.

The class G4LogicalVolumeStore provides a member function:

G4LogicalVolume* G4LogicalVolumeStore::GetVolume( G4String const& );

This function returns a pointer to the *first* G4LogicalVolume whose name matches the G4String argument. Here "first" means the first volume encountered by looping over the store. If there are multiple volumes with the same name you can never access the second or subsequent volumes this way.

If you need to do something to all of the volumes with the same name, you need to loop over the volume store and find each match yourself.