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 // J.L. Chuma, TRIUMF, 31-Oct-1996 26 // J.L. Chuma, TRIUMF, 31-Oct-1996 27 // last modified: 19-Dec-1996 27 // last modified: 19-Dec-1996 28 // Modified by J.L.Chuma, 05-May-97 28 // Modified by J.L.Chuma, 05-May-97 29 // M. Kelsey 29-Aug-2011 -- Use G4Allocator fo 29 // M. Kelsey 29-Aug-2011 -- Use G4Allocator for better memory management 30 30 31 #include "G4ReactionProduct.hh" 31 #include "G4ReactionProduct.hh" 32 32 33 G4Allocator<G4ReactionProduct>*& aRPAllocator( << 33 G4ThreadLocal G4Allocator<G4ReactionProduct> *aRPAllocator = 0; 34 { << 34 35 G4ThreadLocalStatic G4Allocator<G4Reaction << 36 return _instance; << 37 } << 38 35 39 G4ReactionProduct::G4ReactionProduct() : 36 G4ReactionProduct::G4ReactionProduct() : 40 theParticleDefinition(NULL), 37 theParticleDefinition(NULL), 41 formationTime(0.0), 38 formationTime(0.0), 42 hasInitialStateParton(false), 39 hasInitialStateParton(false), 43 mass(0.0), 40 mass(0.0), 44 totalEnergy(0.0), 41 totalEnergy(0.0), 45 kineticEnergy(0.0), 42 kineticEnergy(0.0), 46 timeOfFlight(0.0), 43 timeOfFlight(0.0), 47 side(0), 44 side(0), 48 theCreatorModel(-1), << 49 theParentResonanceDef(nullptr), << 50 theParentResonanceID(0), << 51 NewlyAdded(false), 45 NewlyAdded(false), 52 MayBeKilled(true) 46 MayBeKilled(true) 53 { 47 { 54 SetMomentum( 0.0, 0.0, 0.0 ); 48 SetMomentum( 0.0, 0.0, 0.0 ); 55 SetPositionInNucleus( 0.0, 0.0, 0.0 ); 49 SetPositionInNucleus( 0.0, 0.0, 0.0 ); 56 } 50 } 57 51 58 G4ReactionProduct::G4ReactionProduct( 52 G4ReactionProduct::G4ReactionProduct( 59 const G4ParticleDefinition *aParticleDefinit << 53 G4ParticleDefinition *aParticleDefinition ) 60 { 54 { 61 SetMomentum( 0.0, 0.0, 0.0 ); 55 SetMomentum( 0.0, 0.0, 0.0 ); 62 SetPositionInNucleus( 0.0, 0.0, 0.0 ); 56 SetPositionInNucleus( 0.0, 0.0, 0.0 ); 63 formationTime = 0.0; 57 formationTime = 0.0; 64 hasInitialStateParton = false; 58 hasInitialStateParton = false; 65 theParticleDefinition = aParticleDefinitio 59 theParticleDefinition = aParticleDefinition; 66 mass = aParticleDefinition->GetPDGMass(); 60 mass = aParticleDefinition->GetPDGMass(); 67 totalEnergy = mass; 61 totalEnergy = mass; 68 kineticEnergy = 0.0; 62 kineticEnergy = 0.0; 69 (aParticleDefinition->GetPDGEncoding()<0) 63 (aParticleDefinition->GetPDGEncoding()<0) ? timeOfFlight=-1.0 : timeOfFlight=1.0; 70 side = 0; 64 side = 0; 71 theCreatorModel = -1; << 72 theParentResonanceDef = nullptr; << 73 theParentResonanceID = 0; << 74 NewlyAdded = false; 65 NewlyAdded = false; 75 MayBeKilled = true; 66 MayBeKilled = true; 76 } 67 } 77 68 78 G4ReactionProduct::G4ReactionProduct( 69 G4ReactionProduct::G4ReactionProduct( 79 const G4ReactionProduct &right ) 70 const G4ReactionProduct &right ) 80 { 71 { 81 theParticleDefinition = right.theParticleD 72 theParticleDefinition = right.theParticleDefinition; 82 positionInNucleus = right.positionInNucleu 73 positionInNucleus = right.positionInNucleus; 83 formationTime = right.formationTime; 74 formationTime = right.formationTime; 84 hasInitialStateParton = right.hasInitialSt 75 hasInitialStateParton = right.hasInitialStateParton; 85 momentum = right.momentum; 76 momentum = right.momentum; 86 mass = right.mass; 77 mass = right.mass; 87 totalEnergy = right.totalEnergy; 78 totalEnergy = right.totalEnergy; 88 kineticEnergy = right.kineticEnergy; 79 kineticEnergy = right.kineticEnergy; 89 timeOfFlight = right.timeOfFlight; 80 timeOfFlight = right.timeOfFlight; 90 side = right.side; 81 side = right.side; 91 theCreatorModel = right.theCreatorModel; << 92 theParentResonanceDef = right.theParentRes << 93 theParentResonanceID = right.theParentReso << 94 NewlyAdded = right.NewlyAdded; 82 NewlyAdded = right.NewlyAdded; 95 MayBeKilled = right.MayBeKilled; 83 MayBeKilled = right.MayBeKilled; 96 } 84 } 97 85 98 G4ReactionProduct &G4ReactionProduct::operato 86 G4ReactionProduct &G4ReactionProduct::operator=( 99 const G4ReactionProduct &right ) 87 const G4ReactionProduct &right ) 100 { 88 { 101 if( this != &right ) { 89 if( this != &right ) { 102 theParticleDefinition = right.theParticl 90 theParticleDefinition = right.theParticleDefinition; 103 positionInNucleus = right.positionInNucl 91 positionInNucleus = right.positionInNucleus; 104 formationTime = right.formationTime; 92 formationTime = right.formationTime; 105 hasInitialStateParton = right.hasInitial 93 hasInitialStateParton = right.hasInitialStateParton; 106 momentum = right.momentum; 94 momentum = right.momentum; 107 mass = right.mass; 95 mass = right.mass; 108 totalEnergy = right.totalEnergy; 96 totalEnergy = right.totalEnergy; 109 kineticEnergy = right.kineticEnergy; 97 kineticEnergy = right.kineticEnergy; 110 timeOfFlight = right.timeOfFlight; 98 timeOfFlight = right.timeOfFlight; 111 side = right.side; 99 side = right.side; 112 theCreatorModel = right.theCreatorModel; << 113 theParentResonanceDef = right.theParentR << 114 theParentResonanceID = right.theParentRe << 115 NewlyAdded = right.NewlyAdded; 100 NewlyAdded = right.NewlyAdded; 116 MayBeKilled = right.MayBeKilled; 101 MayBeKilled = right.MayBeKilled; 117 } 102 } 118 return *this; 103 return *this; 119 } 104 } 120 105 121 G4ReactionProduct &G4ReactionProduct::operato 106 G4ReactionProduct &G4ReactionProduct::operator=( 122 const G4DynamicParticle &right ) 107 const G4DynamicParticle &right ) 123 { 108 { 124 theParticleDefinition = right.GetDefinitio 109 theParticleDefinition = right.GetDefinition(); 125 SetPositionInNucleus( 0.0, 0.0, 0.0 ); 110 SetPositionInNucleus( 0.0, 0.0, 0.0 ); 126 formationTime = 0.0; 111 formationTime = 0.0; 127 hasInitialStateParton = false; 112 hasInitialStateParton = false; 128 momentum = right.GetMomentum(); 113 momentum = right.GetMomentum(); 129 mass = right.GetDefinition()->GetPDGMass() 114 mass = right.GetDefinition()->GetPDGMass(); 130 totalEnergy = right.GetTotalEnergy(); 115 totalEnergy = right.GetTotalEnergy(); 131 kineticEnergy = right.GetKineticEnergy(); 116 kineticEnergy = right.GetKineticEnergy(); 132 (right.GetDefinition()->GetPDGEncoding()<0 117 (right.GetDefinition()->GetPDGEncoding()<0) ? timeOfFlight=-1.0 : timeOfFlight=1.0; 133 side = 0; 118 side = 0; 134 theCreatorModel = -1; << 135 theParentResonanceDef = nullptr; << 136 theParentResonanceID = 0; << 137 NewlyAdded = false; 119 NewlyAdded = false; 138 MayBeKilled = true; 120 MayBeKilled = true; 139 return *this; 121 return *this; 140 } 122 } 141 123 142 G4ReactionProduct &G4ReactionProduct::operato 124 G4ReactionProduct &G4ReactionProduct::operator=( 143 const G4HadProjectile &right ) 125 const G4HadProjectile &right ) 144 { 126 { 145 theParticleDefinition = right.GetDefinitio << 127 theParticleDefinition = const_cast<G4ParticleDefinition *>(right.GetDefinition()); 146 SetPositionInNucleus( 0.0, 0.0, 0.0 ); 128 SetPositionInNucleus( 0.0, 0.0, 0.0 ); 147 formationTime = 0.0; 129 formationTime = 0.0; 148 hasInitialStateParton = false; 130 hasInitialStateParton = false; 149 momentum = right.Get4Momentum().vect(); 131 momentum = right.Get4Momentum().vect(); 150 mass = right.GetDefinition()->GetPDGMass() 132 mass = right.GetDefinition()->GetPDGMass(); 151 totalEnergy = right.Get4Momentum().e(); 133 totalEnergy = right.Get4Momentum().e(); 152 kineticEnergy = right.GetKineticEnergy(); 134 kineticEnergy = right.GetKineticEnergy(); 153 (right.GetDefinition()->GetPDGEncoding()<0 135 (right.GetDefinition()->GetPDGEncoding()<0) ? timeOfFlight=-1.0 : timeOfFlight=1.0; 154 side = 0; 136 side = 0; 155 theCreatorModel = -1; << 156 theParentResonanceDef = nullptr; << 157 theParentResonanceID = 0; << 158 NewlyAdded = false; 137 NewlyAdded = false; 159 MayBeKilled = true; 138 MayBeKilled = true; 160 return *this; 139 return *this; 161 } 140 } 162 141 163 void G4ReactionProduct::SetDefinitionAndUpdat 142 void G4ReactionProduct::SetDefinitionAndUpdateE( 164 const G4ParticleDefinition *aParticleDefinit << 143 G4ParticleDefinition *aParticleDefinition ) 165 { G4double aKineticEnergy = GetKineticEne 144 { G4double aKineticEnergy = GetKineticEnergy(); 166 G4double pp = GetMomentum().mag(); 145 G4double pp = GetMomentum().mag(); 167 G4ThreeVector aMomentum = GetMomentum(); 146 G4ThreeVector aMomentum = GetMomentum(); 168 SetDefinition( aParticleDefinition ); 147 SetDefinition( aParticleDefinition ); 169 SetKineticEnergy( aKineticEnergy ); 148 SetKineticEnergy( aKineticEnergy ); 170 if( pp > DBL_MIN ) 149 if( pp > DBL_MIN ) 171 SetMomentum( aMomentum * (std::sqrt(aKin 150 SetMomentum( aMomentum * (std::sqrt(aKineticEnergy*aKineticEnergy + 172 2*aKinetic 151 2*aKineticEnergy*GetMass())/pp) ); 173 } 152 } 174 153 175 void G4ReactionProduct::SetDefinition( 154 void G4ReactionProduct::SetDefinition( 176 const G4ParticleDefinition *aParticleDefinit << 155 G4ParticleDefinition *aParticleDefinition ) 177 { 156 { 178 theParticleDefinition = aParticleDefinitio 157 theParticleDefinition = aParticleDefinition; 179 mass = aParticleDefinition->GetPDGMass(); 158 mass = aParticleDefinition->GetPDGMass(); 180 totalEnergy = mass; 159 totalEnergy = mass; 181 kineticEnergy = 0.0; 160 kineticEnergy = 0.0; 182 (aParticleDefinition->GetPDGEncoding()<0) 161 (aParticleDefinition->GetPDGEncoding()<0) ? 183 timeOfFlight=-1.0 : timeOfFlight=1.0; 162 timeOfFlight=-1.0 : timeOfFlight=1.0; 184 } 163 } 185 164 186 void G4ReactionProduct::SetMomentum( 165 void G4ReactionProduct::SetMomentum( 187 const G4double x, const G4double y, const G4 166 const G4double x, const G4double y, const G4double z ) 188 { 167 { 189 momentum.setX( x ); 168 momentum.setX( x ); 190 momentum.setY( y ); 169 momentum.setY( y ); 191 momentum.setZ( z ); 170 momentum.setZ( z ); 192 } 171 } 193 172 194 void G4ReactionProduct::SetMomentum( 173 void G4ReactionProduct::SetMomentum( 195 const G4double x, const G4double y ) 174 const G4double x, const G4double y ) 196 { 175 { 197 momentum.setX( x ); 176 momentum.setX( x ); 198 momentum.setY( y ); 177 momentum.setY( y ); 199 } 178 } 200 179 201 void G4ReactionProduct::SetMomentum( const G4 180 void G4ReactionProduct::SetMomentum( const G4double z ) 202 { 181 { 203 momentum.setZ( z ); 182 momentum.setZ( z ); 204 } 183 } 205 184 206 void G4ReactionProduct::SetZero() 185 void G4ReactionProduct::SetZero() 207 { 186 { 208 SetMomentum( 0.0, 0.0, 0.0 ); 187 SetMomentum( 0.0, 0.0, 0.0 ); 209 totalEnergy = 0.0; 188 totalEnergy = 0.0; 210 kineticEnergy = 0.0; 189 kineticEnergy = 0.0; 211 mass = 0.0; 190 mass = 0.0; 212 timeOfFlight = 0.0; 191 timeOfFlight = 0.0; 213 side = 0; 192 side = 0; 214 theCreatorModel = -1; << 215 theParentResonanceDef = nullptr; << 216 theParentResonanceID = 0; << 217 NewlyAdded = false; 193 NewlyAdded = false; 218 SetPositionInNucleus( 0.0, 0.0, 0.0 ); 194 SetPositionInNucleus( 0.0, 0.0, 0.0 ); 219 formationTime = 0.0; 195 formationTime = 0.0; 220 hasInitialStateParton = false; 196 hasInitialStateParton = false; 221 } 197 } 222 198 223 void G4ReactionProduct::Lorentz( 199 void G4ReactionProduct::Lorentz( 224 const G4ReactionProduct &p1, const G4Reacti 200 const G4ReactionProduct &p1, const G4ReactionProduct &p2 ) 225 { 201 { 226 G4ThreeVector p1M = p1.momentum; 202 G4ThreeVector p1M = p1.momentum; 227 G4ThreeVector p2M = p2.momentum; 203 G4ThreeVector p2M = p2.momentum; 228 G4double p1x = p1M.x(); G4double p1y = p1M 204 G4double p1x = p1M.x(); G4double p1y = p1M.y(); G4double p1z = p1M.z(); 229 G4double p2x = p2M.x(); G4double p2y = p2M 205 G4double p2x = p2M.x(); G4double p2y = p2M.y(); G4double p2z = p2M.z(); 230 G4double a = ( (p1x*p2x+p1y*p2y+p1z*p2z)/( 206 G4double a = ( (p1x*p2x+p1y*p2y+p1z*p2z)/(p2.totalEnergy+p2.mass) - 231 p1.totalEnergy ) / p2.mass; 207 p1.totalEnergy ) / p2.mass; 232 G4double x = p1x+a*p2x; 208 G4double x = p1x+a*p2x; 233 G4double y = p1y+a*p2y; 209 G4double y = p1y+a*p2y; 234 G4double z = p1z+a*p2z; 210 G4double z = p1z+a*p2z; 235 G4double p = std::sqrt(x*x+y*y+z*z); 211 G4double p = std::sqrt(x*x+y*y+z*z); 236 SetMass( p1.mass ); 212 SetMass( p1.mass ); 237 SetTotalEnergy( std::sqrt( (p1.mass+p)*(p1 213 SetTotalEnergy( std::sqrt( (p1.mass+p)*(p1.mass+p) - 2.*p1.mass*p ) ); 238 //SetTotalEnergy( std::sqrt( p1.mass*p1.ma 214 //SetTotalEnergy( std::sqrt( p1.mass*p1.mass + x*x + y*y + z*z ) ); 239 SetMomentum( x, y, z ); 215 SetMomentum( x, y, z ); 240 } 216 } 241 217 242 G4double G4ReactionProduct::Angle( 218 G4double G4ReactionProduct::Angle( 243 const G4ReactionProduct& p ) const 219 const G4ReactionProduct& p ) const 244 { 220 { 245 G4ThreeVector tM = momentum; 221 G4ThreeVector tM = momentum; 246 G4ThreeVector pM = p.momentum; 222 G4ThreeVector pM = p.momentum; 247 G4double tx = tM.x(); G4double ty = tM.y() 223 G4double tx = tM.x(); G4double ty = tM.y(); G4double tz = tM.z(); 248 G4double px = pM.x(); G4double py = pM.y() 224 G4double px = pM.x(); G4double py = pM.y(); G4double pz = pM.z(); 249 G4double a = std::sqrt( ( px*px + py*py + 225 G4double a = std::sqrt( ( px*px + py*py + pz*pz ) * ( tx*tx + ty*ty + tz*tz ) ); 250 if( a == 0.0 ) { 226 if( a == 0.0 ) { 251 return 0.0; 227 return 0.0; 252 } else { 228 } else { 253 a = ( tx*px + ty*py + tz*pz ) / a; 229 a = ( tx*px + ty*py + tz*pz ) / a; 254 if( std::abs(a) > 1.0 ) { a<0.0 ? a=-1.0 << 230 if( std::fabs(a) > 1.0 ) { a<0.0 ? a=-1.0 : a=1.0; } 255 return std::acos( a ); 231 return std::acos( a ); 256 } 232 } 257 } 233 } 258 234 259 G4ReactionProduct operator+( 235 G4ReactionProduct operator+( 260 const G4ReactionProduct& p1, const G4Reactio 236 const G4ReactionProduct& p1, const G4ReactionProduct& p2 ) 261 { 237 { 262 G4double totEnergy = p1.totalEnergy + p2.t 238 G4double totEnergy = p1.totalEnergy + p2.totalEnergy; 263 G4double x = p1.momentum.x() + p2.momentum 239 G4double x = p1.momentum.x() + p2.momentum.x(); 264 G4double y = p1.momentum.y() + p2.momentum 240 G4double y = p1.momentum.y() + p2.momentum.y(); 265 G4double z = p1.momentum.z() + p2.momentum 241 G4double z = p1.momentum.z() + p2.momentum.z(); 266 G4double newMass = totEnergy*totEnergy - ( 242 G4double newMass = totEnergy*totEnergy - ( x*x + y*y + z*z ); 267 if( newMass < 0.0 ) 243 if( newMass < 0.0 ) 268 newMass = -1. * std::sqrt( -newMass ); 244 newMass = -1. * std::sqrt( -newMass ); 269 else 245 else 270 newMass = std::sqrt( newMass ); 246 newMass = std::sqrt( newMass ); 271 G4ReactionProduct result; 247 G4ReactionProduct result; 272 result.SetMass( newMass ); 248 result.SetMass( newMass ); 273 result.SetMomentum( x, y, z ); 249 result.SetMomentum( x, y, z ); 274 result.SetTotalEnergy( totEnergy ); 250 result.SetTotalEnergy( totEnergy ); 275 result.SetPositionInNucleus( 0.0, 0.0, 0.0 251 result.SetPositionInNucleus( 0.0, 0.0, 0.0 ); 276 result.SetFormationTime(0.0); 252 result.SetFormationTime(0.0); 277 result.HasInitialStateParton(false); 253 result.HasInitialStateParton(false); 278 return result; 254 return result; 279 } 255 } 280 256 281 G4ReactionProduct operator-( 257 G4ReactionProduct operator-( 282 const G4ReactionProduct& p1, const G4Reactio 258 const G4ReactionProduct& p1, const G4ReactionProduct& p2 ) 283 { 259 { 284 G4double totEnergy = p1.totalEnergy - p2.t 260 G4double totEnergy = p1.totalEnergy - p2.totalEnergy; 285 G4double x = p1.momentum.x() - p2.momentum 261 G4double x = p1.momentum.x() - p2.momentum.x(); 286 G4double y = p1.momentum.y() - p2.momentum 262 G4double y = p1.momentum.y() - p2.momentum.y(); 287 G4double z = p1.momentum.z() - p2.momentum 263 G4double z = p1.momentum.z() - p2.momentum.z(); 288 G4double newMass = totEnergy*totEnergy - ( 264 G4double newMass = totEnergy*totEnergy - ( x*x + y*y + z*z ); 289 if( newMass < 0.0 ) 265 if( newMass < 0.0 ) 290 newMass = -1. * std::sqrt( -newMass ); 266 newMass = -1. * std::sqrt( -newMass ); 291 else 267 else 292 newMass = std::sqrt( newMass ); 268 newMass = std::sqrt( newMass ); 293 G4ReactionProduct result; 269 G4ReactionProduct result; 294 result.SetMass( newMass ); 270 result.SetMass( newMass ); 295 result.SetMomentum( x, y, z ); 271 result.SetMomentum( x, y, z ); 296 result.SetTotalEnergy( totEnergy ); 272 result.SetTotalEnergy( totEnergy ); 297 result.SetPositionInNucleus( 0.0, 0.0, 0.0 273 result.SetPositionInNucleus( 0.0, 0.0, 0.0 ); 298 result.SetFormationTime(0.0); 274 result.SetFormationTime(0.0); 299 result.HasInitialStateParton(false); 275 result.HasInitialStateParton(false); 300 return result; 276 return result; 301 } 277 } 302 /* end of code */ 278 /* end of code */ 303 279 304 280