A data export problem


I defined a water tank and then split this tank into 505050 small micro elements. I defined each micro-element as a SD used to capture the energy deposition of particles inside the tank. I also defined a table, and since the size of each micro-element that makes up the tank is small enough, I defined each micro-element as a data point so that I can extract only the energy deposition when I extract the data. Here is the procedure I used to create the coordinate points.

void EventAction::EndOfEventAction(const G4Event* event)
  if(fBoxHCID == -1){
    fBoxHCID = G4SDManager::GetSDMpointer()->GetCollectionID("boxHitsCollection");
  auto boxHC = GetHitsCollection(fBoxHCID,event);
  auto analysisManager = G4AnalysisManager::Instance();
  G4int count = 0;
  for(int z = -25;z<25;z++){
    for(int x = -25;x<25;x++){
      for(int y = -25;y<25;y++){
        auto boxHit = static_cast<CalorHit*>(boxHC->GetHit(count));

As I envisioned at the end of the experiment a table of 125,000 rows would be created. But when I run it, I have a problem, I run it in multi-threaded mode and when /run/beamOn 10 I see that the csv file output by each thread is indeed 125000 rows, but when /run/beamOn 100 or /run/beamOn 1000 I see that the csv file output by each thread is repeated after After 125000 lines the coordinate points are created repeatedly.

That means that if many particles are launched using /run/beamOn, then the csv file of each thread will have duplicate tables created.

I would like to ask you all what causes this. Thank you all for your replies.

EndOfEventAction is active at the end of each event. The output of 1 event (or N events on N threads) is 125000 rows in each file as per the loops with 50x50x50 . With /run/beamOn M for number of events M in the run larger than the number of workers/threads, there will be multiple sets of 125000 rows in the output file(s).

Thanks for your answer, I think this does work as you say. I ran the program a few times after this and each time the table created was an integer multiple of 125000.