FillNtupleTColumn - Error

Hello all,

I am having some issues with saving my data, which seems new as it used to work. I’ve included the error message below, but for context, the simulation still works it’s just not saving anything.

I’ll also include some snippets of my code.
I believe it may be an issue with my energy deposition variable, I want to print the value to the terminal unless it is 0. But it should be saving it all.

Error Message:

G4WT0 > 
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : Analysis_W001
      issued by : G4TNtupleManager<NT,FT>::FillNtupleTColumn
Ntuple 0 does not exist.
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

G4WT0 > Energy deposition: 7.72819
G4WT0 > 
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : Analysis_W001
      issued by : G4TNtupleManager<NT,FT>::FillNtupleTColumn
Ntuple 1 does not exist.
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

G4WT0 > 
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : Analysis_W001
      issued by : G4ToolsAnalysisManager::CloseFileImpl
Deleting empty files failed
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

Implementing tuples:

MyRunAction::MyRunAction()
{
	G4AnalysisManager *man = G4AnalysisManager::Instance();

	man->CreateNtuple("Photons", "Photons");
	man->CreateNtupleIColumn("fEvent");
	man->CreateNtupleDColumn("fX");
	man->CreateNtupleDColumn("fY");
	man->CreateNtupleDColumn("fZ");
	man->CreateNtupleDColumn("fmomX");
	man->CreateNtupleDColumn("fmomY");
	man->CreateNtupleDColumn("fmomZ");
	man->CreateNtupleDColumn("fwlen");
	man->CreateNtupleDColumn("fT");
	man->FinishNtuple(0);

	man->CreateNtuple("Scoring", "Scoring");
	man->CreateNtupleDColumn("fEdep");
	man->FinishNtuple(1);
}

Writing to tuples:

void MyEventAction::EndOfEventAction(const G4Event*)
{

    if(fEdep != 0.)
    {
        G4cout << "Energy deposition: " << fEdep << G4endl;
    }
    G4AnalysisManager *man = G4AnalysisManager::Instance();
    man->FillNtupleDColumn(1, 0, fEdep);
    man->AddNtupleRow(1);
 
}

and again…

G4AnalysisManager *man = G4AnalysisManager::Instance();

	man->FillNtupleIColumn(0, 0, evt);
	man->FillNtupleDColumn(0, 1, posPhoton[0]);
	man->FillNtupleDColumn(0, 2, posPhoton[1]);
	man->FillNtupleDColumn(0, 3, posPhoton[2]);
	man->FillNtupleDColumn(0, 4, momPhoton[0]);
	man->FillNtupleDColumn(0, 5, momPhoton[1]);
	man->FillNtupleDColumn(0, 6, momPhoton[2]);
	man->FillNtupleDColumn(0, 7, wlen);
	man->FillNtupleDColumn(0, 8, Ptime);
	man->AddNtupleRow(0);

Hello,

Do you have the code for file opening/closing in your RunAction as below ?

void RunAction::BeginOfRunAction(const G4Run* /*run*/)
{
  // Get analysis manager
  auto analysisManager = G4AnalysisManager::Instance();

  // Open an output file
  analysisManager->OpenFile("myFile.ext");
}

void RunAction::EndOfRunAction(const G4Run* /*run*/)
{
  auto analysisManager = G4AnalysisManager::Instance();
  analysisManager->Write();
  analysisManager->CloseFile();
}

Also, you RunAction should be created in ActionInitialization::Build(), and if you want to use ntuple merging (with ROOT output), then also in ActionInitialization::BuildForMaster().

Hello,

yes i have that code as shown below;

Below in my action.cc file


void MyActionInitialization::Build() const
{
	MyPrimaryGenerator *generator = new MyPrimaryGenerator();
	SetUserAction(generator);

	MyRunAction *runAction = new MyRunAction();
	SetUserAction(runAction);

    MyEventAction *eventAction = new MyEventAction(runAction);
    SetUserAction(eventAction);

    MySteppingAction *steppingAction = new MySteppingAction(eventAction);
    SetUserAction(steppingAction);

}

Below in my run.cc file


void MyRunAction::BeginOfRunAction(const G4Run* run)
{
	G4AnalysisManager *man = G4AnalysisManager::Instance();

	G4int runID = run->GetRunID();

	std::stringstream strRunID;
	strRunID << runID;

	man->OpenFile("data/output"+strRunID.str()+".csv");


}

void MyRunAction::EndOfRunAction(const G4Run*)
{
	G4AnalysisManager *man = G4AnalysisManager::Instance();

	man->Write();
	man->CloseFile();
}

Hello,

The problem is most probably in non-existing output directory data.

You should see a warning of this kind at the first place:

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : Analysis_W001
      issued by : G4CsvFileManager::CreateFileImpl
Cannot create file data/output0_nt_yz_t0.csv
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

The G4 analysis manager supports writing histograms and ntuples for the CSV output format in different directories; which can be defined with

SetHistoDirectoryName(const G4String&);
SetNtupleDirectoryName(const G4String&);

however the directories must be created by the user.
You can use this function in

MyRunAction::MyRunAction()
{
   G4AnalysisManager *man = G4AnalysisManager::Instance();
   man->SetNtupleDirectoryName("data");
   // ...
}

and then use just a file name in OpenFile() call:

  man->OpenFile("output"+strRunID.str()+".csv");

When setting the directory name explicitly, the saving ntuples should not fail when a directory data is missing, but the ntuples would be written in the current directory.

See more in the documentation: Analysis Manager Classes — Book For Application Developers 11.2 documentation.

Best regards,

Hello,

thank you for the response, The issue did in fact seem to lie with the incorrect directory for the data folder. This needed to be within my build folder, where as before it was located outside.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.