How to change geometry of logicalVolume during runs

Hi I try to change the geometry of a logicalVolume through UI commands and loop over its size. My UI commands are

# in file run3.mac
/control/loop filtration.mac thickness 0.1 1.0 0.2 

and another file

# in file filtration.mac
/filtration/filtraAl true
/filtration/filtraFe true
/filtration/Fe_thickness {thickness} mm
/process/em/fluo true
/run/setCut  0.01 mm
/process/em/deexcitationIgnoreCut true
/run/reinitializeGeometry
/run/initialize
#
/control/verbose 2
/run/verbose 2
#/tracking/verbose 1
#define particle source
/gps/particle gamma
#/gps/ang/type iso
/gps/ang/mintheta  2.355 rad
/gps/ang/maxtheta 3.14 rad
/gps/ang/minphi 0. rad
/gps/ang/maxphi 6.28 rad
#user defined angle distribution(hist)
/gps/ang/type user
/gps/hist/type theta
/control/execute theta_command.mac
/gps/pos/type Plane
/gps/pos/centre 0. 0. 3. mm
/gps/pos/shape Square
/gps/pos/halfx 7. um
/gps/pos/halfy 7. um
/gps/pos/rot1 1 0 0
/gps/pos/rot2 0 0 1
#user defined energy histogram
/gps/ene/type User
/gps/hist/type energy
#use hist for energy spectrum
/control/execute energy_command.mac
#/run/printProgress 100000000 
/run/beamOn 100000000
#

But it meets errors with tips and only the first run works
May I ask how to fix this up?

It’s probably nothing to do with G4SDStructure::AddNewDetector(). Maybe my UI commands have problem.

Hi @repan !

Probably the answer lies in this post.

Ciao , VRS

Hi @drvijayraj ,
I read this post but still didn’t solve the problem. In my case, the first run can work while all other runs didn’t record any events. The other runs started while the detecor didn’t recond anything. Here the detector is not same as the sensitive detector, but another detector and it reconds information in steppingAction.cc.

### Run 4 starts.
 Run terminated.
Run Summary
  Number of events processed : 1000
  User=0.020000s Real=0.021409s Sys=0.000000s

--------------------End of Global Run-----------------------
 The run consists of 1000 gamma of 56.9305 keV
------------------------------------------------------------

After some investigation, I found the problem is in SteppingAction.cc . In an if statement it judge two Volume whethe same or not, this sentence doesn’t work. But if I judge whether the name of the two volumes, then the codes work. In other words,

G4LogicalVolume* volume
    = step->GetPreStepPoint()->GetTouchableHandle()
      ->GetVolume()->GetLogicalVolume();
  if (volume != fScoringVolume) 
      #even if two volume same  judged true and return
         return;

This part only works for first run while not for the rest runs. the following codes give different results.

G4LogicalVolume* volume
    = step->GetPreStepPoint()->GetTouchableHandle()
      ->GetVolume()->GetLogicalVolume();
  G4String volumeName=volume->GetName();
  G4String detectorName=fScoringVolume->GetName();
   // check if we are in Scoring volume
  if (volumeName != detectorName) 
      return;

I changed the code into these, then the rest runs also work. it’s weird! Now the codes works, but I don’t know why the first method can’t work.

Hi @repan

Thanks for updates. I usually define all logical volumes in deetctor.hh and call in stepping action with integer of my choice for easy analysis volume by volume.

I guess fScoringVolume or volume is already defined in detector.hh which you need to call under UserSteppinAction class as fScoringVolume = detectorConstruction->GetScoringVolume().

To get volume of the current step.

it is code hierarchy that you need to call your logical volumes if more than one by method GetName(); to pass fScoringVolumes.

Below code check if you are in scoring volume.

I am happy that you resolved the problem.
:slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.