Problem 1183

Summary: AddDaughter and FieldManager propagation when placing a logical volume
Product: Geant4 Reporter: Evaristo Cisbani <evaristo.cisbani>
Component: geometry/managementAssignee: Gabriele Cosmo <Gabriele.Cosmo>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: P5    
Version: 9.4   
Hardware: All   
OS: All   

Description Evaristo Cisbani 2011-03-30 19:59:05 CEST
The AddDaugher method of G4LogicalVolume propagates (and forces) the field manager to all children if the daughter has no field manager independently of the fact that the field manager is defined or not.

This may results in weird (or unwanted) behavior:

G4LogicalVolume *A = new G4LogicalVolume(...);
G4LogicalVolume *B = new G4LogicalVolume(...);
G4LogicalVolume *C = new G4LogicalVolume(...);

A->SetFieldManager(f, true);  // B and C does not have associated field manager

G4PVPlacement(..., A, "volA", B, ...);

G4PVPlacement(..., B, "volB", C, ...); // CHANGE the field manager of A!

or in other words:

assume the field manager of the volume A is set before its placement inside volume B which has no associated field; the field manager of A changes when volume B is placed into volume C. Same when volume C is placed in volume D ... and so on.

I suggest to modify the propagation of the field manager in AddDaughter changing the "forceToAllDaughters" flag to false, that is:

 if( pDaughterFieldManager == 0 )
  {
    pDaughterLogical->SetFieldManager(fFieldManager, false); // instead of "true" 
  }

Thanks
Comment 1 Gabriele Cosmo 2011-03-31 11:22:53 CEST
Thanks for reporting the problem and the clear use case.
Your proposed correction makes sense as applicable to the case when of pre-assignment of the field is made, as you correctly described.
The fix now under testing will be available in a next patch release.