Hi There,
I am trying to count the number of steps taken inside a volume and I have come across a very strange error where after a certain number of steps taken for a given track, the step number suddenly goes to 1 and begins to count up again.
The conditions I have set in my SteppingAction are as follows:
//check if particle is entering the cavity
if (namePreStepPoint=="cavity" && aStep->IsFirstStepInVolume()){
firstStepNumber = aStep->GetTrack()->GetCurrentStepNumber();
G4cout << "Enters Cavity with initial step number = " << firstStepNumber << G4endl;
//Set in cavity condition to true
InCavity = true;
//Get Track IDs
trackID += 1;
}
//If the particle is in the cavity
if (InCavity){
//Check current step number and only enter if the current step is greater than or equal to the first step
currentStep = aStep->GetTrack()->GetCurrentStepNumber();
G4cout << "For TrackID = " << trackID << ", the current step number in the Cavity = " << currentStep << G4endl;
// Check if the step number is less than the first one
// The code is picking this up sometimes and sometimes it is not because the initial step number is 1 so the step can never be less than one.
if (currentStep < firstStepNumber){
G4cout << "The current step = " << currentStep << ", but the first step in the volume was = " << firstStepNumber << G4endl;
G4cout << "This step number is lower than the first!!" << G4endl;
}
}
//If the step is last in volume, return InCavity parameter to false
if (InCavity && aStep->IsLastStepInVolume()){
G4cout << "Passed Into Exit Condition with step number = " << currentStep << G4endl;
//Set InCavity Condition to false and also reset trackLengthInCavity and StepNumber to zero for next track
InCavity = false;
}
The output for this seems normal for a few tracks and then becomes:
Enters Cavity with initial step number = 26
G4WT0 > For TrackID = 7, the current step number in the Cavity = 26
G4WT0 > For TrackID = 7, the current step number in the Cavity = 27
G4WT0 > For TrackID = 7, the current step number in the Cavity = 28
G4WT0 > For TrackID = 7, the current step number in the Cavity = 29
G4WT0 > For TrackID = 7, the current step number in the Cavity = 30
G4WT0 > For TrackID = 7, the current step number in the Cavity = 31
G4WT0 > For TrackID = 7, the current step number in the Cavity = 32
G4WT0 > For TrackID = 7, the current step number in the Cavity = 33
G4WT0 > For TrackID = 7, the current step number in the Cavity = 34
G4WT0 > For TrackID = 7, the current step number in the Cavity = 35
G4WT0 > For TrackID = 7, the current step number in the Cavity = 36
G4WT0 > For TrackID = 7, the current step number in the Cavity = 37
G4WT0 > For TrackID = 7, the current step number in the Cavity = 38
G4WT0 > For TrackID = 7, the current step number in the Cavity = 39
G4WT0 > For TrackID = 7, the current step number in the Cavity = 40
G4WT0 > For TrackID = 7, the current step number in the Cavity = 41
G4WT0 > For TrackID = 7, the current step number in the Cavity = 42
G4WT0 > For TrackID = 7, the current step number in the Cavity = 43
G4WT0 > For TrackID = 7, the current step number in the Cavity = 44
G4WT0 > For TrackID = 7, the current step number in the Cavity = 45
G4WT0 > For TrackID = 7, the current step number in the Cavity = 46
G4WT0 > For TrackID = 7, the current step number in the Cavity = 47
G4WT0 > For TrackID = 7, the current step number in the Cavity = 48
G4WT0 > For TrackID = 7, the current step number in the Cavity = 49
G4WT0 > For TrackID = 7, the current step number in the Cavity = 50
G4WT0 > For TrackID = 7, the current step number in the Cavity = 51
G4WT0 > For TrackID = 7, the current step number in the Cavity = 52
G4WT0 > For TrackID = 7, the current step number in the Cavity = 53
G4WT0 > For TrackID = 7, the current step number in the Cavity = 54
G4WT0 > For TrackID = 7, the current step number in the Cavity = 55
G4WT0 > For TrackID = 7, the current step number in the Cavity = 56
G4WT0 > For TrackID = 7, the current step number in the Cavity = 57
G4WT0 > For TrackID = 7, the current step number in the Cavity = 58
G4WT0 > For TrackID = 7, the current step number in the Cavity = 59
G4WT0 > For TrackID = 7, the current step number in the Cavity = 60
G4WT0 > For TrackID = 7, the current step number in the Cavity = 61
G4WT0 > For TrackID = 7, the current step number in the Cavity = 62
G4WT0 > For TrackID = 7, the current step number in the Cavity = 63
G4WT0 > For TrackID = 7, the current step number in the Cavity = 64
G4WT0 > For TrackID = 7, the current step number in the Cavity = 65
G4WT0 > For TrackID = 7, the current step number in the Cavity = 66
G4WT0 > For TrackID = 7, the current step number in the Cavity = 67
G4WT0 > For TrackID = 7, the current step number in the Cavity = 68
G4WT0 > For TrackID = 7, the current step number in the Cavity = 69
G4WT0 > For TrackID = 7, the current step number in the Cavity = 70
G4WT0 > For TrackID = 7, the current step number in the Cavity = 71
G4WT0 > For TrackID = 7, the current step number in the Cavity = 1
G4WT0 > The current step = 1, but the first step in the volume was = 26
G4WT0 > This step number is lower than the first!!
G4WT0 > For TrackID = 7, the current step number in the Cavity = 2
G4WT0 > The current step = 2, but the first step in the volume was = 26
G4WT0 > This step number is lower than the first!!
G4WT0 > For TrackID = 7, the current step number in the Cavity = 3
G4WT0 > The current step = 3, but the first step in the volume was = 26
G4WT0 > This step number is lower than the first!!
G4WT0 > For TrackID = 7, the current step number in the Cavity = 4
G4WT0 > The current step = 4, but the first step in the volume was = 26
G4WT0 > This step number is lower than the first!!
G4WT0 > For TrackID = 7, the current step number in the Cavity = 5
G4WT0 > The current step = 5, but the first step in the volume was = 26
G4WT0 > This step number is lower than the first!!
G4WT0 > For TrackID = 7, the current step number in the Cavity = 6
G4WT0 > The current step = 6, but the first step in the volume was = 26
G4WT0 > This step number is lower than the first!!
G4WT0 > For TrackID = 7, the current step number in the Cavity = 7
G4WT0 > The current step = 7, but the first step in the volume was = 26
G4WT0 > This step number is lower than the first!!
G4WT0 > For TrackID = 7, the current step number in the Cavity = 8
G4WT0 > The current step = 8, but the first step in the volume was = 26
G4WT0 > This step number is lower than the first!!
OR even stranger is the following:
G4WT0 > Enters Cavity with initial step number = 1
G4WT0 > For TrackID = 14, the current step number in the Cavity = 1
G4WT0 > For TrackID = 14, the current step number in the Cavity = 2
G4WT0 > For TrackID = 14, the current step number in the Cavity = 1
G4WT0 > For TrackID = 14, the current step number in the Cavity = 2
G4WT0 > For TrackID = 14, the current step number in the Cavity = 3
G4WT0 > For TrackID = 14, the current step number in the Cavity = 4
G4WT0 > For TrackID = 14, the current step number in the Cavity = 5
G4WT0 > For TrackID = 14, the current step number in the Cavity = 6
G4WT0 > For TrackID = 14, the current step number in the Cavity = 7
G4WT0 > For TrackID = 14, the current step number in the Cavity = 8
G4WT0 > For TrackID = 14, the current step number in the Cavity = 1
G4WT0 > For TrackID = 14, the current step number in the Cavity = 2
G4WT0 > For TrackID = 14, the current step number in the Cavity = 3
G4WT0 > For TrackID = 14, the current step number in the Cavity = 4
G4WT0 > For TrackID = 14, the current step number in the Cavity = 5
G4WT0 > For TrackID = 14, the current step number in the Cavity = 6
G4WT0 > For TrackID = 14, the current step number in the Cavity = 7
G4WT0 > For TrackID = 14, the current step number in the Cavity = 8
G4WT0 > For TrackID = 14, the current step number in the Cavity = 1
G4WT0 > For TrackID = 14, the current step number in the Cavity = 2
G4WT0 > For TrackID = 14, the current step number in the Cavity = 3
G4WT0 > For TrackID = 14, the current step number in the Cavity = 4
G4WT0 > For TrackID = 14, the current step number in the Cavity = 5
G4WT0 > For TrackID = 14, the current step number in the Cavity = 6
G4WT0 > For TrackID = 14, the current step number in the Cavity = 7
G4WT0 > For TrackID = 14, the current step number in the Cavity = 1
Where it just loops over the same few steps.
I am not an expert in C++ and I was wondering if anyone can see anything wrong with the code I have used and I am missing something simple. I am not running the simulation in MT mode so I shouldn’t have a problem with the code counting incrementally through the steps.
Thanks in advance,
Michael