Message: Re: Resetting the Global Time Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Ok Re: Resetting the Global Time 

Forum: Event and Track Management
Re: Question Resetting the Global Time (Chelsea Bartram)
Date: 26 Sep, 2014
From: Chelsea Bartram <Chelsea Bartram>

This issue was resolved! For anyone looking to do this, here was the solution. Feel free to ask more questions if my response is confusing:

You have to create a G4UserStackingAction and write a remodeled ClassifyNewTrack() method of G4UserStackingAction. Your StackingAction needs a method called 'SetTrigger(G4double)'. You call it from SteppingAction with:

G4double trigger = aStep->GetTrack()->GetGlobalTime(); G4EventManager::GetEventManager()->GetUserStackingAction()->SetTrigger(trigger);

I also added a method called 'SetSameTime(G4double)' which I also call from the SteppingAction G4double reset = 142.0*ns; G4double sameTime = reset; G4EventManager::GetEventManager()->GetUserStackingAction()->SetSameTime(sameTime); That way if I changed 142 ns in the SteppingAction, it would automatically change in the StackingAction. This is useful if you want to select reset from some distribution, for example, and set it in the StackingAction each time.

If you want to do this for specific steps only, you should call both of these every time you check for a specific step.
For example, in my code, this ended up looking like this:
G4int subtype = PhysProcess->GetProcessSubType();
G4double reset = 142.0*ns;
  if(subtype==26){
     G4double trigger = aStep->GetTrack()->GetGlobalTime();
     G4EventManager::GetEventManager()->GetUserStackingAction()->SetTrigger(trigger);
     G4EventManager::GetEventManager()->GetStackManager()->ReClassify();
     G4EventManager::GetEventManager()->GetUserStackingAction()->SetSameTime(sameTime);
     aStep->GetTrack()->SetGlobalTime(trigger+reset);
}
e.g. you add a private member 'G4double trigger' to your G4UserSteppingAction and the corresponding SetTrigger method. You also have to set this private trigger back to zero in PrepareNewEvent().

The variable 'reset' was the time that I wanted to add to the global track at that given point, in my case, 142 ns.

ReClassify will now in turn call your ClassifyNewTracks method for each track on the stack. In your ClassifyNewTrack method you code: G4double time = sameTime; aTrack->SetGlobalTime(aTrack->GetGlobalTime() - trigger + time + aTrack->GetGlobalTime()); return fUrgent;

This won't work right away because:

ClassifyNewTrack(const G4Track* aTrack)

so you have to strip the constness off the aTrack first. To "strip the constness off the aTrack" you need to have this const_cast thing in front like so actually type this: (const_cast<G4Track *>(aTrack))->SetGlobalTime(aTrack->GetGlobalTime() - trigger + time + aTrack->GetGlobalTime());

In my case, I had a StackingAction class which inherited from the G4UserStackingAction, so I had to make sure everything I defined in the G4UserStackingAction was also defined in the StackingAction (might be obvious to some, but it threw me for a loop for a while).

In the end, I achieved the desired result: when a positron underwent a particular user defined process, I overtake the global time at that step and add 142 ns. The global time for all subsequent daughter tracks then have this 142 ns added to them. It's a very nice hack; a bit hard to implement in Geant4 but it worked. Thanks to Peter for all the help!

 Add Message Add Message
to: "Re: Resetting the Global Time"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]