Not getting the output.root file

run.cc
#include “run.hh”

MyRunAction::MyRunAction()
{}

MyRunAction::~MyRunAction()
{}

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

//TFile* file = new TFile("output.root", "RECREATE");
man->OpenFile("Output.root");

man->CreateNtuple("Hits" ,"Hits");
man->CreateNtupleIColumn("fEvent");
man->CreateNtupleDColumn("fX");
man->CreateNtupleDColumn("fY");
man->CreateNtupleDColumn("fZ");
man->FinishNtuple(0);

}

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

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

}
detector.cc
#include “detector.hh”

MySensitiveDetector::MySensitiveDetector(G4String name) : G4VSensitiveDetector(name)
{}

MySensitiveDetector::~MySensitiveDetector()
{}

G4bool MySensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
{
G4Track *track =aStep->GetTrack();

track->SetTrackStatus(fStopAndKill);

G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
G4StepPoint *postStepPoint = aStep->GetPostStepPoint();

G4ThreeVector posPhoton =preStepPoint->GetPosition();

//G4cout << "Photon position: " << posPhoton << G4endl;

const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();

G4int copyNo = touchable->GetCopyNumber();

//G4cout << "Copy number: " << copyNo << G4endl;

G4VPhysicalVolume *physVol = touchable->GetVolume();
G4ThreeVector posDetector = physVol->GetTranslation();

G4cout << "Detector Position: " << posDetector << G4endl;

G4int evt = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();

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


**man->FillNtupleIColumn(0, evt);**

** man->FillNtupleDColumn(1, posDetector[0]);**
** man->FillNtupleDColumn(2, posDetector[1]);**
** man->FillNtupleDColumn(3, posDetector[2]);**
** man->AddNtupleRow(0);**

return true;

}
without the above ** commands, I am getting the output. But as I input all the commands (highlights **) getting the message “code dumped”. I am also not getting any output.root file.
please suggest me how to solve the above issues.
_Geant4 Version:_11.2.2
_Operating System:_ubuntu 20.04
_Compiler/Version:_C++14
_CMake Version:_3.16.3


Hello @TanmayeeSamal

Maybe you try by replacing
posDetector[0] with posDetector.getX() -->for X position
and do same for Y and Z.

VRS

No result…
I always get this message as I click the "/run/beamOn 1 ".
“Detector Position: (-115,25,490)
Segmentation fault (core dumped)”

Try in ActionInitialisation class add override BuildForMaster() and add there SetUserAction(new YourRunActionClass)

@TanmayeeSamal

Please try it with gdb. Maybe your code is encountering a return null pointer.

example can be gdb ./yourApplication
and then follow gdb steps to troubleshoot the problem.

Further Reads or Ref → Problem with visualizing the detector or running the simulation - #4 by allison

VRS

I have tried the command “gdb ./hpge” and got the bellow information, then what ?

GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.2) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type “show copying” and “show warranty” for details.
This GDB was configured as “x86_64-linux-gnu”.
Type “show configuration” for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.

For help, type “help”.
Type “apropos word” to search for commands related to “word”…
./hpge: No such file or directory.
(gdb) where
No stack.
(gdb)

@TanmayeeSamal

please rebuild your application using
cmake -DCMAKE_BUILD_TYPE=Debug
and then use gdb ./hpge

VRS

santosh@santosh-desktop:~/software/geant4/geant4-v11.2.2/build$ cmake -DCMAKE_BUILD_TYPE=Debug
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.

CMake Error: The source directory “/home/santosh/software/geant4/geant4-v11.2.2/build” does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
santosh@santosh-desktop:~/software/geant4/geant4-v11.2.2/build$ gdb ./hpge
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.2) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type “show copying” and “show warranty” for details.
This GDB was configured as “x86_64-linux-gnu”.
Type “show configuration” for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.

For help, type “help”.
Type “apropos word” to search for commands related to “word”…
./hpge: No such file or directory.
(gdb) run
Starting program:
No executable file specified.
Use the “file” or “exec-file” command.
(gdb)

i got this output

@TanmayeeSamah

Did you directed cmake to CMakeLists.txt at the end of cmake call ?

VRS