Show process progress during the run

Hello, I’m trying to write a function tu show the percent of the running progress

  1. In the B1EventAction.cc I wrote:
    a.

       B1EventAction::B1EventAction(B1RunAction* runAction)
             : G4UserEventAction(),
               fRunAction(runAction),
               fEdep(0.)
               fPrintModulo(10000)
             {} 
    

b.
fPrintModulo= 10000;
c.

evtNb = evt->GetEventID();
    	NevTot=G4RunManager::GetRunManager()->GetCurrentRun()->GetNumberOfEventToBeProcessed();
    	if ((100/fPrintModulo*evtNb)%NevTot==0) G4cout <<"\n---> Begin of Event:"<<evtNb<<" of "<<NevTot<<" Progress % is "<<(100*evtNb)/NevTot<<G4endl;
  1. In the B1Eventaction.hh I wrote
    virtual void BeginOfEventAction(const G4Event* evt);
    G4int fPrintModulo;

but I get error

Notice that I assigned to fPrintModulo the number of events that I want to simulate

Hello,
I’m not sure I completely understand the Italian error message, but from what I get it might be as simple as putting a comma between fEdep(0.) and fPrintModulo(10000).

That being said, to print the progress I would usually just write something like

if( evt->GetEventID()%10000==0 ) G4cout << evt->GetEventID() << G4endl;

in the EventAction.cc.

Thank you @swagner

Yes, that was the bug!

Thank you! it is easier!

Hey. I am trying to make a progress bar for rdecay02. Has anyone here already done it? It is a little bit similar to B1.

/run/printProgress <modulus>

Thanks. Do I put this into the BeginOfEventAction function of EventAction?

It’s a macro command. Put it in your macro file, on the line before /run/beamOn.

Hey. I am getting this error when I put this command in my batch macro file.

Replace the placeholder string with a numerical modulus.

Thank you for your help, but it is still no working. However I found another method that is working fine now. My next step is trying to print it on the same place instead of having it span in bunch of lines like this. I have tried to use “\r”, but it is not working.

Hey. I was able to write a code that print out the percentage of my progress at the command line. However, my code has some limitation. It only works if you are running number with only zeros such like “1000”. Otherwise, the calculation is messed up. Does anyone have an advice for me?

you could simply write

/run/printProgress 100000

(or whatever number giving you suitable steps for the number of events you want to run), and it will work without limitations :wink:

I f[quote=“weller, post:12, topic:3070, full:true”]
you could simply write

/run/printProgress 100000

(or whatever number giving you suitable steps for the number of events you want to run), and it will work without limitations :wink:
[/quote]

I tried this command, but I don’t see the progress…

Did you put that macro command before or after your /run/beamOn command? Obviously, if you put it afterward, it won’t apply during the run.

Hello @mkelsey I found the mistake…I wrote the same number of /run/beamOn…

Hi all,
sorry for the intrusion but I’m trying to understand somethinh basic of geant4, for example the difference bettween fPrintModulo and EventID. Could anyone tell me this difference?
Is EventID a characteristic of a primary particle? I mean, could I distinguish different primary particles exploiting the EventID value?

It could be a nonsense question, but geant4 is really difficult for me to understand. Sorry in advance.

Thank you

Claretta

An “event” in Geant4 starts with one or more primary particles. These are tracked through your geometry, interacting and maybe making secondaries. If you want to get high statistics to compare with reality, you will generate many, many events in your simulation.

Within an event, you distinguish the different tracks using the track ID, not the event ID.