Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4SmartTrackStack class implementation << 27 // 26 // 28 // Author: S.Kamperis - 4 October 2012 << 27 // $Id: G4SmartTrackStack.cc,v 1.5 2010-11-24 22:56:57 asaim Exp $ 29 // ------------------------------------------- << 28 // GEANT4 tag $Name: geant4-09-04-patch-01 $ >> 29 // 30 30 31 #include "G4SmartTrackStack.hh" 31 #include "G4SmartTrackStack.hh" 32 #include "G4VTrajectory.hh" 32 #include "G4VTrajectory.hh" 33 #include "G4Track.hh" << 34 << 35 void G4SmartTrackStack::dumpStatistics() << 36 { << 37 // Print to stderr so that we can split stat << 38 // output of Geant4 which is typically being << 39 for (G4int i=0; i<nTurn; ++i) << 40 { << 41 G4cerr << stacks[i]->GetNTrack() << " "; << 42 G4cerr << stacks[i]->getTotalEnergy() << " << 43 } << 44 G4cerr << G4endl; << 45 } << 46 33 47 G4SmartTrackStack::G4SmartTrackStack() << 34 G4SmartTrackStack::G4SmartTrackStack() >> 35 :fTurn(0),nTurn(5) 48 { 36 { 49 for(G4int i=0; i<nTurn; ++i) << 37 for(int i=0;i<nTurn;i++) 50 { << 38 { stacks[i] = new G4TrackStack(); } 51 stacks[i] = new G4TrackStack(5000); << 39 // If entry of one sub-stack exceeds safetyValve1, we will stick 52 energies[i] = 0.; << 40 // to that sub-stack until entry of that sub-stack goes down 53 } << 41 // to safetyValve2. >> 42 nStick = 100; >> 43 safetyValve1 = 3000; >> 44 safetyValve2 = safetyValve1 - nStick; >> 45 maxNTracks = 0; 54 } 46 } 55 47 56 G4SmartTrackStack::~G4SmartTrackStack() 48 G4SmartTrackStack::~G4SmartTrackStack() 57 { 49 { 58 for (auto* sp : stacks) << 50 for(int i=0;i<nTurn;i++) 59 { << 51 { delete stacks[i]; } 60 delete sp; << 61 } << 62 } 52 } 63 53 64 void G4SmartTrackStack::TransferTo(G4TrackStac << 54 const G4SmartTrackStack & G4SmartTrackStack::operator=(const G4SmartTrackStack &) >> 55 { return *this; } >> 56 int G4SmartTrackStack::operator==(const G4SmartTrackStack &right) const >> 57 { return (this==&right); } >> 58 int G4SmartTrackStack::operator!=(const G4SmartTrackStack &right) const >> 59 { return (this!=&right); } >> 60 >> 61 void G4SmartTrackStack::TransferTo(G4TrackStack * aStack) 65 { 62 { 66 for (auto* sp : stacks) << 63 for(int i=0;i<nTurn;i++) 67 { << 64 { stacks[i]->TransferTo(aStack); } 68 sp->TransferTo(aStack); << 69 } << 70 nTracks = 0; << 71 } 65 } 72 66 73 G4StackedTrack G4SmartTrackStack::PopFromStack << 67 G4StackedTrack * G4SmartTrackStack::PopFromStack() 74 { 68 { 75 G4StackedTrack aStackedTrack; << 69 if( n_stackedTrack() == 0 ) return 0; 76 << 70 G4StackedTrack * aStackedTrack = 0; 77 if (nTracks != 0) << 71 while(!aStackedTrack) 78 { 72 { 79 while (true) << 73 if(stacks[fTurn]->GetNTrack()==0) 80 { 74 { 81 if (stacks[fTurn]->GetNTrack() != 0u) << 75 fTurn = (fTurn+1)%nTurn; 82 { << 76 //G4cout<<"++++++++ Shift to Stack ["<<fTurn<<"] with "<<stacks[fTurn]->GetNTrack()<<" stacked tracks."<<G4endl; 83 aStackedTrack = stacks[fTurn]->PopFrom << 84 energies[fTurn] -= aStackedTrack.GetTr << 85 --nTracks; << 86 break; << 87 } << 88 << 89 fTurn = (fTurn+1) % nTurn; << 90 } 77 } >> 78 else >> 79 { aStackedTrack = stacks[fTurn]->PopFromStack(); } 91 } 80 } 92 << 93 return aStackedTrack; 81 return aStackedTrack; 94 } 82 } 95 83 96 enum << 84 #include "G4Neutron.hh" 97 { << 85 #include "G4Gamma.hh" 98 electronCode = 11, positronCode = -11, gamma << 86 #include "G4Electron.hh" 99 }; << 87 #include "G4Positron.hh" >> 88 >> 89 void 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(); 100 95 101 void G4SmartTrackStack::PushToStack( const G4S << 96 if(!aStackedTrack) return; 102 { << 103 97 104 G4int iDest = 0; 98 G4int iDest = 0; 105 if (aStackedTrack.GetTrack()->GetParentID() << 99 if( aStackedTrack->GetTrack()->GetParentID() == 0 ) 106 { 100 { 107 G4int code = aStackedTrack.GetTrack()->Get << 101 // We have a primary track, which should go first. 108 if (code == electronCode) << 102 fTurn = 0; // reseting the turn 109 iDest = 2; << 110 else if (code == gammaCode) << 111 iDest = 3; << 112 else if (code == positronCode) << 113 iDest = 4; << 114 else if (code == neutronCode) << 115 iDest = 1; << 116 } 103 } 117 else 104 else 118 { 105 { 119 // We have a primary track, which should g << 106 G4ParticleDefinition* partDef = aStackedTrack->GetTrack()->GetDefinition(); 120 fTurn = 0; // reseting the turn << 107 if(partDef==neutDef) >> 108 { iDest = 1; } >> 109 else if(partDef==elecDef) >> 110 { iDest = 2; } >> 111 else if(partDef==gammDef) >> 112 { iDest = 3; } >> 113 else if(partDef==posiDef) >> 114 { iDest = 4; } 121 } 115 } >> 116 122 stacks[iDest]->PushToStack(aStackedTrack); 117 stacks[iDest]->PushToStack(aStackedTrack); 123 energies[iDest] += aStackedTrack.GetTrack()- << 118 if(stacks[iDest]->GetNTrack()>safetyValve1) 124 ++nTracks; << 125 << 126 G4long dy1 = stacks[iDest]->GetNTrack() - st << 127 G4long dy2 = stacks[fTurn]->GetNTrack() - st << 128 << 129 if (dy1 > 0 || dy1 > dy2 || << 130 (iDest == 2 && << 131 stacks[iDest]->GetNTrack() < 50 && ener << 132 { 119 { 133 fTurn = iDest; << 120 // Too many tracks in the stack. Process tracks in this stack first >> 121 // unless the current stack also have too many tracks. >> 122 if(stacks[fTurn]->GetNTrack()<safetyValve2) >> 123 { >> 124 fTurn = iDest; >> 125 safetyValve2 = stacks[iDest]->GetNTrack() - nStick; >> 126 //G4cout<<"++++++++ Shift to Stack ["<<fTurn<<"] with "<<stacks[fTurn]->GetNTrack()<<" stacked tracks."<<G4endl; >> 127 } 134 } 128 } 135 << 129 136 if (nTracks > maxNTracks) maxNTracks = nTrac << 130 if(n_stackedTrack()>maxNTracks) maxNTracks = n_stackedTrack(); 137 } 131 } 138 132 139 void G4SmartTrackStack::clear() 133 void G4SmartTrackStack::clear() 140 { 134 { 141 for (G4int i = 0; i < nTurn; ++i) << 135 for(int i=0;i<nTurn;i++) 142 { << 136 { stacks[i]->clear(); } 143 stacks[i]->clear(); << 144 energies[i] = 0.0; << 145 fTurn = 0; << 146 } << 147 nTracks = 0; << 148 } 137 } 149 138 150 void G4SmartTrackStack::clearAndDestroy() << 139 151 { << 152 for (G4int i = 0; i < nTurn; ++i) << 153 { << 154 stacks[i]->clearAndDestroy(); << 155 energies[i] = 0.0; << 156 fTurn = 0; << 157 } << 158 nTracks = 0; << 159 } << 160 140