Hi, I’ve got Cerenkov photons hit on the SD, but I want to know the position(x,y,z) where they were generated through Cerenkov effect in the radiator. I have tried setuserinformation() to set the position information into Cerenkov photon’s track, but when I get information of this track hit on the SD by getuserinformation(), any next operation to this track information won’t work, and my GUI crashes and closes unexpectedly, but there are no error messages in the terminal.
Would you please help me? Appreciate!
Can you share your user information class (and where you set it)? RE01 can be adapted almost 1-1 to most situations using custom user track information.
I set userinformation in my steppingAction file:
const std::vector<const G4Track*> *secondaries = step->GetSecondaryInCurrentStep();
const G4TrackVector *Secondary = step->GetSecondary();
for (auto sec : secondaries)
{
if(sec->GetDynamicParticle()->GetParticleDefinition() == opticalphoton)
{
G4String creator_process = sec->GetCreatorProcess()->GetProcessName();
if(creator_process == “Cerenkov”)
{
CerenkovPhotonNum++;
G4ThreeVector secMomtenum = sec->GetMomentum();
G4double wlen = (1.239841939eV/secMomtenum.mag())1E+03;
man->FillNtupleDColumn(1, 0, CerenkovPhotonID);
man->FillNtupleDColumn(1, 1, wlen);
man->AddNtupleRow(1);
G4ThreeVector sec_pos = sec->GetPosition();
G4String depth = std::to_string(sec_pos[2]);
G4VUserTrackInformation secInfo = new G4VUserTrackInformation(depth);
sec->SetUserInformation(secInfo);
// G4cout << ">>>>> “<< thisParticelStatus << " >>>>>>>>>>>>>>>>>>>>>>>>>> Wave Length: " << wlen << " nm <<<<<<<<<<<<<<<<<<<<<<<<” << G4endl;
}
}
}
and in my SD file, I define SD hits function:
G4bool SensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory ROhist)
{
G4Track track = aStep->GetTrack();
G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
G4StepPoint *postStepPoint = aStep->GetPostStepPoint();
// G4ThreeVector posPhoton = postStepPoint->GetPosition();
// auto typePhoton = preStepPoint->GetCharge();
auto trackInfo = track->GetUserInformation();
track->SetTrackStatus(fStopAndKill);
}
It would probably be easier to just attach the code instead of segments.
First, since it isn’t guaranteed that UserInformation might exist since it is only conditionally sent:
auto trackInfo = track->GetUserInformation();
should be
if (track->GetUserInformation()){
auto trackInfo = track->GetUserInformation();
}
More importantly though, what about your user information class. You have to define it by writing your own user information class. RE01 has an example of this here.
I think I roughly understand what you mean. I should define my own user information class. I will take another look at that RE01 example and then try again. Thank you!