No GetEntries() method for NTuple?

Hello,

I’m writing a simulation where in the main.cc file i start a multiple run (with different energy):

if ( ! ui ) {
    // batch mode
    UImanager->ApplyCommand("/control/execute init_vis.mac");
    //UImanager->ApplyCommand("/control/execute Run.mac"); 
    UImanager->ApplyCommand("/run/beamOn 1000000");
  }

where Run.mac is:

/gun/energy 3.98 eV
/run/beamOn 1000000
...
...
/gun/energy 4.96 eV
/run/beamOn 1000000

For every of 50 runs, I want to write in an external file the value all the value of energies and entries in two different columns.

In the SteppingActions.cc file i created the NTuple:

void SteppingAction::UserSteppingAction(const G4Step* step)
{

  auto volume_pre = step->GetPreStepPoint()->GetPhysicalVolume()->GetName();
  
  auto volume_post = step->GetPostStepPoint()->GetPhysicalVolume()->GetName();


  if ( step->GetTrack()->GetTrackID() == 1. &&  /*if particle is a optical photon... */ 

       step->GetTrack()->GetTrackStatus() == fStopAndKill && /*if particle dies...  */ 

       volume_post == "SiPMPhys" /*... in SiPM.  */) {


        n_bounce = step->GetTrack()->GetCurrentStepNumber()/2;
        stepTime = (step->GetTrack()->GetGlobalTime())*ns;
        total_track = (step->GetTrack()->GetTrackLength())*cm;
        
        auto analysisManager = G4AnalysisManager::Instance();
     
        analysisManager->FillNtupleIColumn(0, n_bounce);
        analysisManager->FillNtupleDColumn(1, stepTime);
        analysisManager->FillNtupleDColumn(2, total_track);
        analysisManager->AddNtupleRow();
        
  }

while in RunAction.cc file i create the root file for NTuple:

void RunAction::BeginOfRunAction(const G4Run* run)
{
  G4cout << "### Run " << run->GetRunID() << " start." << G4endl;

  //reset accumulables to their initial values
  G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
  accumulableManager->Reset();
  
  
  // Get analysis manager
  auto analysisManager = G4AnalysisManager::Instance();

  // Open an output file
  analysisManager->OpenFile("B3_result_histo.root");

}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void RunAction::EndOfRunAction(const G4Run* run)
{
  
  auto analysisManager = G4AnalysisManager::Instance();

  // save histograms & ntuple
  analysisManager->Write();
  analysisManager->CloseFile();
  
  
  
  G4int nofEvents = run->GetNumberOfEvent();
  if (nofEvents == 0) return;

  // Merge accumulables
  G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
  accumulableManager->Merge();

  //Print results
  if (IsMaster())
  {
    G4cout
     << G4endl
     << "--------------------End of Global Run-----------------------"
     << G4endl
     << "  The run was " << nofEvents << " events."
     << G4endl
     << "------------------------------------------------------------\t"
     << G4endl;
  }
  else
  {
    G4cout
     << G4endl
     << "-----------------End of Local Run Thread--------------------"
     << G4endl
     << "  The run was " << nofEvents << "  events."
     << G4endl
     << "------------------------------------------------------------\t"
     << G4endl;
     
  } 
 
}

Now, I suppose, that here i need to create an external txt file, and save information about energies and entries, but How?

  1. I dind’t found any GetEntries() method for get the entries of Ntuple named n_bounce. How can I save the info about Entries?;
  2. The txt file goes created on RunAction, right?
  3. How can i retrive the info about energy for each run and append the information?
1 Like