ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4SmartTrackStack.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4SmartTrackStack.cc
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 // Author: S.Kamperis - 04/Oct/12
27 // --------------------------------------------------------------------
28 
29 #include "G4SmartTrackStack.hh"
30 #include "G4VTrajectory.hh"
31 #include "G4Track.hh"
32 
34 {
35  // Print to stderr so that we can split stats output from normal
36  // output of Geant4 which is typically being printed to stdout
37  for (G4int i=0; i<nTurn; ++i)
38  {
39  G4cerr << stacks[i]->GetNTrack() << " ";
40  G4cerr << stacks[i]->getTotalEnergy() << " ";
41  }
42  G4cerr << G4endl;
43 }
44 
46  : fTurn(0), nTurn(5), maxNTracks(0), nTracks(0)
47 {
48  for(G4int i=0; i<nTurn; ++i)
49  {
50  stacks[i] = new G4TrackStack(5000);
51  energies[i] = 0.;
52  }
53 }
54 
56 {
57  for (G4int i=0; i<nTurn; ++i)
58  {
59  delete stacks[i];
60  }
61 }
62 
64 {
65  for (G4int i=0; i<nTurn; ++i)
66  {
67  stacks[i]->TransferTo(aStack);
68  }
69  nTracks = 0;
70 }
71 
73 {
74  G4StackedTrack aStackedTrack;
75 
76  if (nTracks)
77  {
78  while (true)
79  {
80  if (stacks[fTurn]->GetNTrack())
81  {
82  aStackedTrack = stacks[fTurn]->PopFromStack();
83  energies[fTurn] -= aStackedTrack.GetTrack()->GetDynamicParticle()->GetTotalEnergy();
84  --nTracks;
85  break;
86  }
87  else
88  {
89  fTurn = (fTurn+1) % nTurn;
90  }
91  }
92  }
93 
94  return aStackedTrack;
95 }
96 
97 enum
98 {
99  electronCode = 11, positronCode = -11, gammaCode = 22, neutronCode = 2112
100 };
101 
102 void G4SmartTrackStack::PushToStack( const G4StackedTrack& aStackedTrack )
103 {
104 
105  G4int iDest = 0;
106  if (aStackedTrack.GetTrack()->GetParentID())
107  {
108  G4int code = aStackedTrack.GetTrack()->GetDynamicParticle()->GetPDGcode();
109  if (code == electronCode)
110  iDest = 2;
111  else if (code == gammaCode)
112  iDest = 3;
113  else if (code == positronCode)
114  iDest = 4;
115  else if (code == neutronCode)
116  iDest = 1;
117  }
118  else
119  {
120  // We have a primary track, which should go first.
121  fTurn = 0; // reseting the turn
122  }
123  stacks[iDest]->PushToStack(aStackedTrack);
124  energies[iDest] += aStackedTrack.GetTrack()->GetDynamicParticle()->GetTotalEnergy();
125  ++nTracks;
126 
127  G4int dy1 = stacks[iDest]->GetNTrack() - stacks[iDest]->GetSafetyValue1();
129 
130  if (dy1 > 0 || dy1 > dy2 ||
131  (iDest == 2 &&
132  stacks[iDest]->GetNTrack() < 50 && energies[iDest] < energies[fTurn]))
133  {
134  fTurn = iDest;
135  }
136 
138 }
139 
141 {
142  for (G4int i = 0; i < nTurn; ++i)
143  {
144  stacks[i]->clear();
145  energies[i] = 0.0;
146  fTurn = 0;
147  }
148  nTracks = 0;
149 }
150 
152 {
153  for (G4int i = 0; i < nTurn; ++i)
154  {
155  stacks[i]->clearAndDestroy();
156  energies[i] = 0.0;
157  fTurn = 0;
158  }
159  nTracks = 0;
160 }