Changing Detector Dimensions In Exended Example->Electromagnetic->TestEm1

I am running Extended Example->Electromagnetic->TestEm1. I want to change the detector material dimensions from a cubical box to a thin strip. In the src file DetectorConstruction.cc, I changed the following lines from:

‘’’
if(fPBox) { return fPBox; }
fBox = new G4Box(“Container”, //its name
fBoxSize/2,fBoxSize/2,fBoxSize/2); //its dimensions,
‘’’
to
‘’’
if(fPBox) { return fPBox; }
fBox = new G4Box(“Container”, //its name
fBoxSize/100,fBoxSize/2,fBoxSize/2); //its dimensions,
‘’’
and
‘’’
if(fBox) {
fBox->SetXHalfLength(fBoxSize/2);
fBox->SetYHalfLength(fBoxSize/2);
fBox->SetZHalfLength(fBoxSize/2);
}
‘’’
to
‘’’
if(fBox) {
fBox->SetXHalfLength(fBoxSize/100);
fBox->SetYHalfLength(fBoxSize/2);
fBox->SetZHalfLength(fBoxSize/2);
}
‘’’
.
The shape outline in the OpenGL visualizer changed as expected. However, after running 100 gamma rays of 2 MeV each in interactive mode, using Lead as the detector material, the visualizer behaved as though the detector dimensions had not changed from their original cubical shape. Is there anything I missed here, and anything else I need to do to change the shape of this detector material block?

In DetectorConstruction.hh, ~line 63 :
inline G4double GetSize() const {return fBoxSize/50;};

1 Like

michel,

It seems to work. Thank you.

I do have a question about this. In DetectorConstruction.cc, fBoxSize appears to dictate all three dimensions of the box. Does this change in DetectorConstruction.hh change all three dimensions?

In that particular example, the assumption is that you’re building a cube with just one dimension. So yeah, any code that calls GetBoxSize() will get the smaller value, and won’t realize that it only applies to one of the three dimensions.

Your modification suggests that a more general version of DetectorConstruction, written for your own job, would have three separate dimensions (call them “fBoxX”, “fBoxY”, and “fBoxZ” if you like). You’d then probably write three different Get functions, and whatever other code is using the Get function would need to be modified to ask for the appropriate dimension. This is part of the process of moving from a fixed simple example to a more complex real application.

Thanks mkelsey. The command that michel gave above seemed to work. Did that just make the box much smaller?

Yup. If you want to keep the thin slab, you’ll need to modify the code to treat it properly as a rectangle, not as a cube.

1 Like

Thanks mkelsey. I will look into it.