source: trunk/source/event/src/G4SmartTrackStack.cc@ 1224

Last change on this file since 1224 was 1197, checked in by garnier, 16 years ago

nvx fichiers dans CVS

File size: 4.6 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4SmartTrackStack.cc,v 1.3 2009/09/16 23:10:46 asaim Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30
31#include "G4SmartTrackStack.hh"
32#include "G4VTrajectory.hh"
33
34G4SmartTrackStack::G4SmartTrackStack()
35:fTurn(0),nTurn(5)
36{
37 for(int i=0;i<nTurn;i++)
38 { stacks[i] = new G4TrackStack(); }
39 // If entry of one sub-stack exceeds safetyValve1, we will stick
40 // to that sub-stack until entry of that sub-stack goes down
41 // to safetyValve2.
42 nStick = 100;
43 safetyValve1 = 3000;
44 safetyValve2 = safetyValve1 - nStick;
45 maxNTracks = 0;
46}
47
48G4SmartTrackStack::~G4SmartTrackStack()
49{
50 for(int i=0;i<nTurn;i++)
51 { delete stacks[i]; }
52}
53
54const G4SmartTrackStack & G4SmartTrackStack::operator=(const G4SmartTrackStack &)
55{ return *this; }
56int G4SmartTrackStack::operator==(const G4SmartTrackStack &right) const
57{ return (this==&right); }
58int G4SmartTrackStack::operator!=(const G4SmartTrackStack &right) const
59{ return (this!=&right); }
60
61void G4SmartTrackStack::TransferTo(G4TrackStack * aStack)
62{
63 for(int i=0;i<nTurn;i++)
64 { stacks[i]->TransferTo(aStack); }
65}
66
67G4StackedTrack * G4SmartTrackStack::PopFromStack()
68{
69 if( n_stackedTrack() == 0 ) return 0;
70 G4StackedTrack * aStackedTrack = 0;
71 while(!aStackedTrack)
72 {
73 if(stacks[fTurn]->GetNTrack()==0)
74 {
75 fTurn = (++fTurn)%nTurn;
76 //G4cout<<"++++++++ Shift to Stack ["<<fTurn<<"] with "<<stacks[fTurn]->GetNTrack()<<" stacked tracks."<<G4endl;
77 }
78 else
79 { aStackedTrack = stacks[fTurn]->PopFromStack(); }
80 }
81 return aStackedTrack;
82}
83
84#include "G4Neutron.hh"
85#include "G4Gamma.hh"
86#include "G4Electron.hh"
87#include "G4Positron.hh"
88
89void G4SmartTrackStack::PushToStack( G4StackedTrack * aStackedTrack )
90{
91 static G4ParticleDefinition* neutDef = G4Neutron::Definition();
92 static G4ParticleDefinition* elecDef = G4Electron::Definition();
93 static G4ParticleDefinition* gammDef = G4Gamma::Definition();
94 static G4ParticleDefinition* posiDef = G4Positron::Definition();
95
96 G4int iDest = 0;
97 if( aStackedTrack->GetTrack()->GetParentID() == 0 )
98 {
99 // We have a primary track, which should go first.
100 fTurn = 0; // reseting the turn
101 }
102 else
103 {
104 G4ParticleDefinition* partDef = aStackedTrack->GetTrack()->GetDefinition();
105 if(partDef==neutDef)
106 { iDest = 1; }
107 else if(partDef==elecDef)
108 { iDest = 2; }
109 else if(partDef==gammDef)
110 { iDest = 3; }
111 else if(partDef==posiDef)
112 { iDest = 4; }
113 }
114
115 stacks[iDest]->PushToStack(aStackedTrack);
116 if(stacks[iDest]->GetNTrack()>safetyValve1)
117 {
118 // Too many tracks in the stack. Process tracks in this stack first
119 // unless the current stack also have too many tracks.
120 if(stacks[fTurn]->GetNTrack()<safetyValve2)
121 {
122 fTurn = iDest;
123 safetyValve2 = stacks[iDest]->GetNTrack() - nStick;
124 //G4cout<<"++++++++ Shift to Stack ["<<fTurn<<"] with "<<stacks[fTurn]->GetNTrack()<<" stacked tracks."<<G4endl;
125 }
126 }
127
128 if(n_stackedTrack()>maxNTracks) maxNTracks = n_stackedTrack();
129}
130
131void G4SmartTrackStack::clear()
132{
133 for(int i=0;i<nTurn;i++)
134 { stacks[i]->clear(); }
135}
136
137
Note: See TracBrowser for help on using the repository browser.