//initialization of class in header of Steppingaction in geant4 class SecondariesClass {public: Double_t xPre_S, yPre_S, zPre_S, xPost_S, yPost_S, zPost_S, Ekin_Pre_S, Ekin_Post_S, Edep_S, Elost_S, ELaBr3_S, StepLength_S, xScatter_S, yScatter_S, zScatter_S , ColLength_S; Int_t GammaNum_S, particle_PDG_S, parent_ID_S, track_ID_S, stepNo_S, Scatter_S , user_PreVolumeIndex_S , user_PostVolumeIndex_S; }; class SteppingAction : public G4UserSteppingAction { public: SteppingAction(); virtual ~SteppingAction(); virtual void UserSteppingAction(const G4Step*); private: //Variables used in Steppingaction G4String PreProcessName, PostProcessName, PreVolumeName, PostVolumeName, ParticleName, PSMode, EdepMode, SecMode, CreatorProcess; Int_t TrackID, Z, A, StepNo, ParentID, Scatter, GammaNum, pdgID, PrevolumeIndex, PostvolumeIndex; G4double PreStepEkin, PostStepEkin, xPre, yPre, zPre, xPost, yPost, zPost, PostPx, PostPy, PostPz, GlobalTime, StepLength,xScatter, yScatter, zScatter; G4double xEdep, yEdep, zEdep, Edep, Etot, Elost, ELaBr3, ColLength; // ROOT files and trees TFile *rootfile; TTree *sec_Tree; //variable for root file name G4String filename; // data structures (classes here) corresponding to ROOT branches SecondariesClass Secondaries; G4int jobNum; }; //use of class in steppingaction //1.constructor SteppingAction::SteppingAction(){ filename = Output1_1.root; rootfile = new TFile(filename,"RECREATE"); // create new trees sec_Tree = new TTree("SecondariesTree", "Secondaries ROOT tree"); sec_Tree->Branch("SecondariesBranch",&Secondaries,"xPre_S/D:yPre_S/D:zPre_S/D:xPost_S/D:yPost_S/D:zPost_S/D:Ekin_Pre_S/D:Ekin_Post_S/D:Edep_S/D:Elost_S/D:ELaBr3_S/D:StepLength_S/D:xScatter_S/D:yScatter_S/D:zScatter_S/D:ColLength_S/D:GammaNum_S/I:particle_PDG_S/I:parent_ID_S/I:track_ID_S/I:stepNo_S/I:Scatter_S/I:user_PreVolumeIndex_S/I:user_PostVolumeIndex_S/I"); } //2.Destructor SteppingAction::~SteppingAction() { // flush all info into the root file rootfile->Write(); // delete pointers to the trees delete sec_Tree; // close root file and delete pointer rootfile->Close(); delete rootfile; } //3.Main void SteppingAction::UserSteppingAction(const G4Step * s){ //only the root related part: Secondaries.particle_PDG_S = pdgID; Secondaries.parent_ID_S = ParentID; Secondaries.track_ID_S = TrackID; Secondaries.stepNo_S = StepNo; Secondaries.xPre_S = xPre/cm; Secondaries.yPre_S = yPre/cm; Secondaries.zPre_S = zPre/cm; Secondaries.xPost_S = xPost/cm; Secondaries.yPost_S = yPost/cm; Secondaries.zPost_S = zPost/cm; Secondaries.Ekin_Pre_S = PreStepEkin/keV; Secondaries.Ekin_Post_S = PostStepEkin/keV; Secondaries.Edep_S = Edep/keV; Secondaries.Elost_S = Elost/keV; Secondaries.ELaBr3_S = ELaBr3/keV; Secondaries.Scatter_S = Scatter; Secondaries.user_PreVolumeIndex_S = PrevolumeIndex; Secondaries.user_PostVolumeIndex_S = PostvolumeIndex; Secondaries.StepLength_S = StepLength/cm; Secondaries.xScatter_S = xScatter; Secondaries.yScatter_S = yScatter; Secondaries.zScatter_S = zScatter; Secondaries.ColLength_S = ColLength; Secondaries.GammaNum_S = GammaNum; sec_Tree->Fill(); }