Problem recording data from detector - generating empty histograms and ntuples files

Dear users,
I am trying to export information about my detectors such as number of photons detected, their energy, etc. However it’s generating an empty output file. I’ve used the example B4a as a guide but I’m not sure if the problem is in my logic of recording data in SteppingAction, or filling the histograms and ntuples, or even in somewhere else.

I am creating the histograms and ntuples in RunAction as follows:

MyRunAction::MyRunAction()
{ }
MyRunAction::~MyRunAction()
{}
void MyRunAction::BeginOfRunAction(const G4Run* aRun)
{
G4cout << “### Run " << aRun->GetRunID() << " start.” << G4endl;
// Get analysis manager
auto analysisManager = G4AnalysisManager::Instance();
G4cout << “Using " << analysisManager->GetType() << " analisys manager.” << G4endl;
// Open an output file
G4String fileName = “OutPut”;
analysisManager->OpenFile(fileName);
analysisManager->SetVerboseLevel(1);
// set printing event number per each event
G4RunManager::GetRunManager()->SetPrintProgress(1);
// Indicates the ID of the first histogram created
analysisManager->SetFirstHistoId(1);
// Create directories
analysisManager->SetHistoDirectoryName(“histograms”);
analysisManager->SetNtupleDirectoryName(“ntuple”);
analysisManager->SetVerboseLevel(1);
analysisManager->SetNtupleMerging(true);
// Creating histograms
analysisManager->CreateH1(“h1”,“Energy deposited in SiPM1”, 100, 0., 5eV);
// Indicates the ID of the first ntuple created
analysisManager->SetFirstNtupleId(1);
// Creating ntuple
analysisManager->CreateNtuple(“T1”, “data”);
analysisManager->CreateNtupleDColumn(“Edep”);
analysisManager->CreateNtupleDColumn(“kineticEnergy”);
analysisManager->CreateNtupleDColumn(“Total Number of Photons”);
analysisManager->CreateNtupleDColumn(“axisX”);
analysisManager->CreateNtupleDColumn(“axisY”);
analysisManager->CreateNtupleDColumn(“axisZ”);
analysisManager->FinishNtuple();
}
void MyRunAction::EndOfRunAction(const G4Run
aRun)
{
G4cout << “End of run” << G4endl;
// save histograms & ntuple
auto analysisManager = G4AnalysisManager::Instance();
analysisManager->Write();
analysisManager->CloseFile();
delete G4AnalysisManager::Instance();
}

and my logic in steppingAction for recording information is as follows:

MySteppingAction::MySteppingAction(MyEventAction* eventAction): G4UserSteppingAction(),
fEventAction(eventAction)
{}
MySteppingAction::~MySteppingAction()
{}
void MySteppingAction::UserSteppingAction(const G4Step* aStep){
auto step_x = aStep->GetTrack()->GetPosition().x();
auto step_y = aStep->GetTrack()->GetPosition().y();
auto step_z = aStep->GetTrack()->GetPosition().z();
// get analysis manager
auto analysisManager = G4AnalysisManager::Instance();
// Step
auto track = aStep->GetTrack();
auto particle = track->GetDefinition()->GetParticleName();
auto material = track->GetMaterial()->GetName();
// Energy info about the track
auto kineticEnergy = track->GetKineticEnergy();
auto TotalEnergy = track->GetTotalEnergy();
// get volume of the current step
//preStep info
auto aPrePoint = aStep->GetPreStepPoint();
auto aPrePhysVol = aPrePoint->GetPhysicalVolume();
auto PreVolName = “”;
if (aPrePhysVol) PreVolName = aPrePhysVol->GetName();
//postStep info
auto aPostPoint = aStep->GetPostStepPoint();
auto aPostPhysVol = aPostPoint->GetPhysicalVolume();
auto PostVolName = “”;
if (aPostPhysVol) PostVolName = aPostPhysVol->GetName();
auto Edep = aStep->GetTotalEnergyDeposit();
auto trackID = aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
auto processName = aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
int countPhotons1 = 0;
if(particle == “opticalphoton”) {
// we’ll compare the pre and post volumes of each step to see if the particle passes through a SiPM
if(PreVolName == “DetectorVolume” && PostVolName ==“Sensor1” ){
countPhotons1++;
// fill histograms
analysisManager->FillH1(1, Edep);
// fill ntuple
analysisManager->FillNtupleDColumn(0, Edep);
analysisManager->FillNtupleDColumn(1,kineticEnergy);
analysisManager->FillNtupleDColumn(2,countPhotons1);
analysisManager->FillNtupleDColumn(3,step_x);
analysisManager->FillNtupleDColumn(4,step_y);
analysisManager->FillNtupleDColumn(5,step_z);
analysisManager->AddNtupleRow(1);
Edep = 0;
kineticEnergy = 0;
}

That’s the histogram I get:

image

I have a very simple geometry, a box with very reflective internal walls and a silicon detector at the center of each box face. All of the detectors volumes are made of silicon, and the properties attributed to the silicon in DetectorConstruction class are:

// Creating the SiPMs detectors
// adding length threshold for absorption/killing photons at the surface of the SiPM detector
auto siliconPropertiesTable = new G4MaterialPropertiesTable();
G4double abs_silicon[N_DATA] = {0.00001*nm};
siliconPropertiesTable->AddProperty(“ABSLENGTH”, photonEnergies, abs_sillicon, N_DATA);
silicon->SetMaterialPropertiesTable( silliconPropertiesTable );

Could anyone please try to help me with this?
Thanks in advance.
Best regards.

I believe you should be seeing in your simulation output of warnings like "ntupleId 1 does not exist. "

It looks to me like you create only one ntuple, with a default ID=0, so if you remove 1 you will be filling your ntuple:

analysisManager->AddNtupleRow();

Thanks for your answer, Anna!
Indeed, I’m getting that warning message. I tried your suggestion, but still get that message:
image
and get no TTree at all
image

I did not notice that before. Indeed what you did here before was correct:

But what you miss is ntuple ID in FillNtupleDColumn() (have a look in the user guide):

 analysisManager->FillNtupleDColumn(1, 0, Edep);

etc. with other columns.