Hello,
I have a doubt about the following questions. I’m saving some information in a Ntuple and in a TH1F object (SteppingAction.cc):
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();
analysisManager->FillH1(0, n_bounce);
}
}
If I check the #Entries in Ntuple with #Entries in TH1F, I obtain the same value. Now I want to save the #Entries of TH1F in a txt file (RunAction.cc):
void RunAction::EndOfRunAction(const G4Run* run)
{
auto analysisManager = G4AnalysisManager::Instance();
// save histograms & ntuple
//G4cout<<"entries = " << analysisManager->GetH1(0)->entries() <<G4endl;
std::ofstream file("test.txt", std::ofstream::app);
/*
auto runManager = G4RunManager::GetRunManager();
auto myPrimaryGenerator = runManager->GetUserPrimaryGeneratorAction();
auto energyy = myPrimaryGenerator->GetParticleGun()->GetEnergy();
*/
n_bounce = analysisManager->GetH1(0)->entries();
if(IsMaster())
file << std::fixed << std::setprecision(2) << 3.98+run->GetRunID()*0.02 << "\t" << n_bounce <<G4endl;
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, and n_bounce " << n_bounce << "."
<< G4endl
<< "------------------------------------------------------------\t"
<< G4endl;
}
else
{
G4cout
<< G4endl
<< "-----------------End of Local Run Thread--------------------"
<< G4endl
<< " The run was " << nofEvents << " events, and n_bounce " << n_bounce << "."
<< G4endl
<< "------------------------------------------------------------\t"
<< G4endl;
}
}
If I check the number of #Entries in the .txt file (that are taken from the command: n_bounce = analysisManager->GetH1(0)->entries();
of previus code) with the #Entries taken in TH1F and NTuple, I obtain different value.
Why this happen if i get the information directly from TH1F with the command n_bounce = analysisManager->GetH1(0)->entries();
? There is some problem with the Multithread? I don’t understand why I obtain that difference of values for every run.
PS: I create a TH1F because there is not any GetEntries() method for the NTuple…