Getting user-defined geometry attribute in my RunAction

Hi all,

I am using a user-defined detector construction. I want to allow my program to run with two different geometry configurations, so I introduced a macro command through a boolean messenger in my detector construction class. I need to retrieve the value of this boolean afterwards in my RunAction class, but I have not figured out the way of doing it.
I thought of adding an attribute to my user-defined detector construction that I could get in the RunAction class, but I did not find a way of accessing the detector construction object from the RunAction. Is there a way of doing so?

Any other alternative is welcome.

Thanks in advance.

I know that from stepping action you can get your runaction class from G4RunManager::GetRunManager()->GetNonConstcurrentRun();

You should be able to do this from your detectorconstructor (but I could be wrong). If so, just have a detectorconstructor method that sets a boolean in your runAction

I have looked up the documentation and I’ve seen that GetNonConstCurrentRun() returns a G4Run * object, which is not an RunAction object, right?

Please correct me if I am mistaken.

Thanks for your answer.

Since you put the parameter into your detector construction class, you may provide a public accessor (G4bool GetMySpecialValue() const { return mySpecialValue; }) in your detector construction class.

In your RunAction, you can fetch the pointer to the detector construction that you registered into G4RunManager:

  G4RunManager* rm = G4RunManager::GetRunManager();
  const G4VUserDetectorConstruction* baseDetCons = rm->GetUserDetectorConstruction();
  // *** I think the casting below works, but you may need to modify it
  const MyOwnDetectorConstruction* detCons = dynamic_cast<const MyOwnDetectorConstruction*>(baseDetCons);
  if (!detCons) {
    G4cerr << "ERROR!!!  THIS IS NOT MY OWN DETECTOR CONSTRUCTION!" << G4endl;
    return;
  }

  G4bool myFlag = detCons->GetMySpecialValue();
  /* Now do something with your special flag */

See example extended/electromagnetic/TestEm1 :

  • DetectorConstruction is created in TestEm1.cc
  • a pointer on it (det) is passed to ActionInitialization
  • then, it is passed from ActionInitialization::Build() to RunAction
1 Like

Indeed that worked! Thanks!

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