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?
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
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 */