Dear all,
In my code I’m trying to record any e- or e+ and respective energies that enter a CCD volume in my geometry. My simulation makes usage of GPS, and I shoot omnidirectional monoenergetic electrons, getting the record of secondaries that reach my volume. For that I use G4SteppingManager, and try to record everything in a ROOT file via g4tools.
In my RunAction.cc file I set the following to create ntuples:
// Create analysis manager
auto analysisManager = G4AnalysisManager::Instance();
G4cout << "Using " << analysisManager->GetType() << G4endl;
analysisManager->SetVerboseLevel(1);
#ifdef G4MULTITHREADED
analysisManager->SetNtupleMerging(true);
#endif
// Create Ntuples - ROOT
// Electron ntuple (id = 0)
analysisManager->CreateNtuple("e-", "e- quantities");
analysisManager->CreateNtupleIColumn("count"); // column id = 0
analysisManager->CreateNtupleDColumn("eKin"); // column id = 1
analysisManager->CreateNtupleDColumn("eTot"); // column id = 2
analysisManager->FinishNtuple();
// Positron ntuple (id = 1)
analysisManager->CreateNtuple("e+", "e+ quantities");
analysisManager->CreateNtupleIColumn("count"); // column id = 0
analysisManager->CreateNtupleDColumn("eKin"); // column id = 1
analysisManager->CreateNtupleDColumn("eTot"); // column id = 2
analysisManager->FinishNtuple();
And in my SteppingManager.cc I add the following to record e-/e+ with respective energies:
auto analysisManager = G4AnalysisManager::Instance();
auto volPreStep = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume();
auto volPostStep = step->GetPostStepPoint()->GetTouchableHandle()->GetVolume();
if(volPreStep != fGeometry->GetCCD() && volPostStep == fGeometry->GetCCD()){
if(step->GetTrack()->GetDefinition()->GetParticleName() == "e-"){
analysisManager->FillNtupleIColumn(0, 0, 1);
analysisManager->FillNtupleDColumn(0, 1, step->GetTrack()->GetKineticEnergy());
analysisManager->FillNtupleDColumn(0, 2, step->GetTrack()->GetTotalEnergy());
analysisManager->AddNtupleRow(0);
}
else if(step->GetTrack()->GetDefinition()->GetParticleName() == "e+"){
analysisManager->FillNtupleIColumn(1, 0, 1);
analysisManager->FillNtupleDColumn(1, 1, step->GetTrack()->GetKineticEnergy());
analysisManager->FillNtupleDColumn(1, 2, step->GetTrack()->GetTotalEnergy());
analysisManager->AddNtupleRow(1);
}
}
The simulation runs with no problem, but my ntuples are completely empty afterwards. I of course add the Write() and CloseFile() methods in EndOfRunAction of my RunAction.cc.
I tried adding the AddNtupleRow methods outside the if statements like below, but then the ntuples are filled at every step (with zeros when my if statements are not fulfilled), and my ROOT file becomes obscenely huge.
if(volPreStep != fGeometry->GetCCD() && volPostStep == fGeometry->GetCCD()){
if(step->GetTrack()->GetDefinition()->GetParticleName() == "e-"){
analysisManager->FillNtupleIColumn(0, 0, 1);
analysisManager->FillNtupleDColumn(0, 1, step->GetTrack()->GetKineticEnergy());
analysisManager->FillNtupleDColumn(0, 2, step->GetTrack()->GetTotalEnergy());
}
else if(step->GetTrack()->GetDefinition()->GetParticleName() == "e+"){
analysisManager->FillNtupleIColumn(1, 0, 1);
analysisManager->FillNtupleDColumn(1, 1, step->GetTrack()->GetKineticEnergy());
analysisManager->FillNtupleDColumn(1, 2, step->GetTrack()->GetTotalEnergy());
}
}
analysisManager->AddNtupleRow(0);
analysisManager->AddNtupleRow(1);
Any help on how to fill my ntuples inside the if statements only would be more than appreciated.
Thanks in advance.
_Geant4 Version:_10.7.3
_Operating System:_GNU/Linux Slackware 15 (conda environment)
_Compiler/Version:_GCC 10.4
_CMake Version:_3.21.4