Error in G4UserRunAction (Root Problem)

Hello good day Forum, i experience this problem while trying to execute the command and run my Root.

/home/bashir/Bash/exercise/action.cc:16:28: error: ‘G4UserRunAction’ is an inaccessible base of ‘MyRunAction’
   16 |     SetUserAction(runAction);
      |                            ^
make[2]: *** [CMakeFiles/rano.dir/build.make:89: CMakeFiles/rano.dir/action.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:104: CMakeFiles/rano.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

these are some of my codes.
run.hh

#ifndef RUN_HH
#define RUN_HH

#include "G4UserRunAction.hh"

#include "G4AnalysisManager.hh"

class MyRunAction : public G4UserRunAction
{
public:
	MyRunAction();
	~MyRunAction();
	
	virtual void BeginOfRunAction(const G4Run*);
	virtual void EndOfRunAction(const G4Run*);
};	

#endif

run.cc
‘’’
#include “run.hh”

MyRunAction::MyRunAction()
{}

MyRunAction::~MyRunAction()
{}

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

man->OpenFile("output.root");

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

}

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

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

}

action.hh

#ifndef ACTION_HH
#define ACTION_HH

#include “G4VUserActionInitialization.hh”

#include “generator.hh”
#include “run.hh”

class MyActionInitialization : public G4VUserActionInitialization
{
public:
MyActionInitialization();
~MyActionInitialization();

virtual void Build() const;

};

#endif

action.cc

#include “action.hh”
#include “run.hh”

MyActionInitialization::MyActionInitialization()
{}

MyActionInitialization::~MyActionInitialization()
{}

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

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

}

main.cc/rano,cc

#include

#include “G4RunManager.hh”
#include “G4UImanager.hh”
#include “G4VisManager.hh”
#include “G4VisExecutive.hh”
#include “G4UIExecutive.hh”

#include “construction.hh”
#include “physics.hh”
#include “action.hh”

int main(int argc, char** argv)
{
G4RunManager *runManager = new G4RunManager();

runManager->SetUserInitialization(new MyDetectorConstruction());
runManager->SetUserInitialization(new MyPhysicsList());
runManager->SetUserInitialization(new MyActionInitialization());

runManager->Initialize();

G4UIExecutive *ui = new G4UIExecutive(argc, argv);

G4VisManager *visManager = new G4VisExecutive();
visManager->Initialize();

G4UImanager *UImanager = G4UImanager::GetUIpointer();

UImanager->ApplyCommand("/vis/open OGL");
UImanager->ApplyCommand("/vis/viewer/set/viewpointVector 1 1 1");
UImanager->ApplyCommand("/vis/drawVolume");
UImanager->ApplyCommand("/vis/viewer/set/autoRefresh true");
UImanager->ApplyCommand("/vis/scene/add/trajectories smooth");

ui->SessionStart();

return 0;

}

please help me out i spent so much time trying thank you

Hi Bashir,

Looking at your code there is nothing that appears obviously wrong. I have a few further questions which might help us determine what is going on though.

1.) I noticed that your header guards are manually entered, i.e. you use

#ifndef RUN_HH
#define RUN_HH

#endif

Instead of “#ifndef RUN_HH” you can use “#pragma once” so that you don’t have to change the name of the header guard in each file. Is it possible that you have another header file with the “ifndef RUN_HH” header guard that is obscuring your “run.hh” file?

2.) Could you share your CMakeLists file? I am wondering if it is possible your build environment is configured incorrectly.

3.) Lastly, what version of g++ are you using to compile the code? You can determine this by calling “g++ --version” from the terminal.

Joseph

Cmake

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

project(Myfirstproject)

find_package(Geant4 REQUIRED ui_all vis_all)

include(${Geant4_USE_FILE})

file(GLOB sources ${PROJECT_SOURCE_DIR}/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/*.hh)

add_executable(rano rano.cc ${sources} ${headers})
target_link_libraries(rano ${Geant4_LIBRARIES})

add_custom_target(Myfirstproject DEPENDS rano)

g++ version

g++ --version
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@JDecunha, any progress yet?

Hey Bashir,

Could you upload your full application on github or somewhere similar? This way, those interested can take a closer look and maybe help out.

Just a thought!

ok i will upload it here

i solved that problem, but my problem is that when i used the class named “g4root.hh” is not working. but when is replace it with “G4AnalysisManager.hh” it worked. but i cannot see the root file.

CMakeCache.txt  CMakeFiles  cmake_install.cmake  Makefile  rano

@JDecunha thank you all

@BashirAminu , please have a look at this discussion:

ok thank you i will look at it.

@dkonst Iam yet to solve these problems someone should kindly help.