Get the number of "/run/beamOn" in source code

We can set #of events we want to generate with /run/beamOn.
Is it possible to get this number in source code of ActionInitialization, RunAction or EventAction etc…??

for instance
int events = xxxx - > GetNumberOfEventsToBeProcessed()
int events = xxx - > GetNumberOfEventsToBeStored()
something like above.

Yes, you can call the following at the BeginOfRunAction to get the total number of events to be run.

void RunAction::BeginOfRunAction(const G4Run* aRun) { 
G4int eventsInRun = aRun->GetNumberOfEventToBeProcessed();

Hope that helps

I tested it, It works !
Thanks !

Is it possible to update this number in RunAction?

below does not work…

void RunAction::BeginOfRunAction(const G4Run* aRun) 
  // originally, it's 10, for instance.
  G4int eventsInRun = aRun->GetNumberOfEventToBeProcessed(); 
  // update it to 20
  G4RunManager::GetRunManager() ->SetNumberOfEventsToBeProcessed( 20 )
  // this can not update #of events to be processed. its still 10 in the follwowing.
  G4cout << "update #of Evts : " << aRun->GetNumberOfEventToBeProcessed() << G4endl; 

If I use G4RunManager::GetRunManager()-> Initialize()
it seems everything is initialized?

In fact, any place is ok. In other words, is it possible to give #of simulation events in source code without using /run/beamOn ?

Always we have to decide #of events in .mac using “/run/beamOn” ??
or, is it possible to decide it in “void main()” ??

As per line 170 in G4RunManager.hh /run/beamOn is analysed before the event loop. The BeginOfRunAction method is executed at the start of the event loop I believe, therefore, this is the reason why you cannot change the value here.

Yes, you can set the beam on and the number of events in the main program. An easy way is to call the beamOn method from the run manager. This can be done using the following:

RunManager* runMan= new RunManager();

Alternatively you can run UI commands in the main using:

G4UImanager *uiMan = G4UImanager::GetUIpointer();
uiMan ->ApplyCommand("/run/beamOn 20");

Yes, I put a few code in the upper main() to decide how many events to be generate.

Then, I’m using beamOn function to tell the number of times to be generated

Thanks !