Segmentation violation

Hello everyone. I have met another problem when I tried using ROOT to analyse data from Geant4
What I am doing is copying data from Geant4 to a ROOT tree, consisting of time, and position etc. I defined a TVector3 called fX and paste position data to it in each step. When I make the Geant file. it came out fine. However, when I run it, the following message iwas produced:

*** Break *** segmentation violation Generating stack trace... 0x00fba8c3 in PTrack::SetTime(float) at include/PTrack.h:12 from /home/klhui/tmp/Linux-g++/sure/libsure.so 0x00fba290 in MySteppingAction::UserSteppingAction(G4Step const*) at src/MySteppingAction.cc:29 from /home/klhui/tmp/Linux-g++/sure/libsure.so 0x0018818c in G4SteppingManager::Stepping() + 0x500 from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4tracking.so 0x0018eef8 in G4TrackingManager::ProcessOneTrack(G4Track*) + 0x16c from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4tracking.so 0x00b8cf82 in G4EventManager::DoProcessing(G4Event*) + 0x336 from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4event.so 0x00b8d4ee in G4EventManager::ProcessOneEvent(G4Event*) + 0x26 from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4event.so 0x00ebf397 in G4RunManager::DoEventLoop(int, char const*, int) + 0xe7 from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4run.so 0x00ebda30 in G4RunManager::BeamOn(int, char const*, int) + 0x44 from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4run.so 0x00ec269e in G4RunMessenger::SetNewValue(G4UIcommand*, G4String) + 0x2da from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4run.so 0x008309c2 in G4UIcommand::DoIt(G4String) + 0x40e from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4intercoms.so 0x0083e306 in G4UImanager::ApplyCommand(char const*) + 0x57e from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4intercoms.so 0x00822dfa in G4UIbatch::SessionStart() + 0x4de from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4intercoms.so 0x0083abea in G4UImanager::ExecuteMacroFile(char const*) + 0x3e from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4intercoms.so 0x00838b2e in G4UIcontrolMessenger::SetNewValue(G4UIcommand*, G4String) + 0xb6 from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4intercoms.so 0x008309c2 in G4UIcommand::DoIt(G4String) + 0x40e from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4intercoms.so 0x0083e306 in G4UImanager::ApplyCommand(char const*) + 0x57e from /usr/local/geant4.8.0p01/lib/Linux-g++/libG4intercoms.so 0x0804bc1b in main + 0x53d from /home/klhui/bin/Linux-g++/sure 0x02a5de23 in __libc_start_main + 0xd3 from /lib/tls/libc.so.6 0x0804afbd in __gxx_personality_v0 + 0x71 from /home/klhui/bin/Linux-g++/sure Abort
The code I put down in my Stepping action was

[code] PTrack* track;
G4Track* fTrack = aStep->GetTrack();
track->SetTime(fTrack->GetGlobalTime()/ns);
Double_t positionx = fTrack->GetPosition().x()/cm;
Double_t positiony = fTrack->GetPosition().y()/cm;
Double_t positionz = fTrack->GetPosition().z()/cm;
track->SetX(positionx,positiony,positionz);
track->SetEnergy(fTrack->GetKineticEnergy()/MeV);
track->SetdE(aStep->GetTotalEnergyDeposit()/MeV);
track->SetStepLength(aStep->GetStepLength()/cm);
track->SetTrackLength(fTrack->GetTrackLength()/cm);

out->AddTrack(track);[/code]
The problem was absent when I comment out the line of recording position.
Thank you very much for your help.

Hi,
at least in the code snippet you provided you never initialize the track pointer; it has a random value, pointing to a random position in memory. You probably meant

[code] PTrack track;
G4Track* fTrack = aStep->GetTrack();
track.SetTime(fTrack->GetGlobalTime()/ns);
Double_t positionx = fTrack->GetPosition().x()/cm;
Double_t positiony = fTrack->GetPosition().y()/cm;
Double_t positionz = fTrack->GetPosition().z()/cm;
track.SetX(positionx,positiony,positionz);
track.SetEnergy(fTrack->GetKineticEnergy()/MeV);
track.SetdE(aStep->GetTotalEnergyDeposit()/MeV);
track.SetStepLength(aStep->GetStepLength()/cm);
track.SetTrackLength(fTrack->GetTrackLength()/cm);

out->AddTrack(&track);[/code]
Axel.

Thanks alot!