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 // G4DecayProducts class implementation << 27 // 26 // 28 // Author: H.Kurashige, 12 July 1996 << 27 // $Id: G4DecayProducts.cc,v 1.19 2010-10-30 07:55:00 kurasige Exp $ >> 28 // GEANT4 tag $Name: not supported by cvs2svn $ >> 29 // >> 30 // >> 31 // ------------------------------------------------------------ >> 32 // GEANT 4 class implementation file >> 33 // >> 34 // History: first implementation, based on object model of >> 35 // 10 July 1996 H.Kurashige >> 36 // 21 Oct 1996 H.Kurashige >> 37 // 12 Dec 1997 H.Kurashige >> 38 // 4 Apr. 2012 H.Kurashige use std::vector 29 // ------------------------------------------- 39 // ------------------------------------------------------------ 30 40 >> 41 #include "G4ios.hh" >> 42 #include "globals.hh" 31 #include "G4DecayProducts.hh" 43 #include "G4DecayProducts.hh" 32 44 33 #include "G4LorentzRotation.hh" << 34 #include "G4LorentzVector.hh" 45 #include "G4LorentzVector.hh" 35 #include "G4PhysicalConstants.hh" << 46 #include "G4LorentzRotation.hh" 36 #include "G4SystemOfUnits.hh" << 47 37 #include "G4ios.hh" << 38 #include "globals.hh" << 39 48 40 G4DecayProducts::G4DecayProducts() 49 G4DecayProducts::G4DecayProducts() 41 { << 50 :numberOfProducts(0),theParentParticle(0) 42 theProductVector = new G4DecayProductVector( << 51 { >> 52 theProductVector = new G4DecayProductVector(); 43 } 53 } 44 54 45 G4DecayProducts::G4DecayProducts(const G4Dynam << 55 G4DecayProducts::G4DecayProducts(const G4DynamicParticle &aParticle) >> 56 :numberOfProducts(0),theParentParticle(0) 46 { 57 { 47 theParentParticle = new G4DynamicParticle(aP 58 theParentParticle = new G4DynamicParticle(aParticle); 48 theProductVector = new G4DecayProductVector( 59 theProductVector = new G4DecayProductVector(); 49 } 60 } 50 61 51 G4DecayProducts::G4DecayProducts(const G4Decay << 62 G4DecayProducts::G4DecayProducts(const G4DecayProducts &right) >> 63 :numberOfProducts(0) 52 { 64 { 53 theProductVector = new G4DecayProductVector( 65 theProductVector = new G4DecayProductVector(); 54 66 55 // copy parent (Deep Copy) 67 // copy parent (Deep Copy) 56 theParentParticle = new G4DynamicParticle(*r 68 theParentParticle = new G4DynamicParticle(*right.theParentParticle); 57 69 58 // copy daughters (Deep Copy) << 70 //copy daughters (Deep Copy) 59 for (G4int index = 0; index < right.numberOf << 71 for (G4int index=0; index < right.numberOfProducts; index++) { 60 G4DynamicParticle* daughter = right.thePro 72 G4DynamicParticle* daughter = right.theProductVector->at(index); 61 auto pDaughter = new G4DynamicParticle(*da << 73 const G4DecayProducts* pPreAssigned = daughter->GetPreAssignedDecayProducts(); 62 << 63 G4double properTime = daughter->GetPreAssi 74 G4double properTime = daughter->GetPreAssignedDecayProperTime(); 64 if (properTime > 0.0) pDaughter->SetPreAss << 75 G4DynamicParticle* pDaughter = new G4DynamicParticle(*daughter); 65 76 66 const G4DecayProducts* pPreAssigned = daug << 77 if (pPreAssigned) { 67 if (pPreAssigned != nullptr) { << 78 G4DecayProducts* pPA = new G4DecayProducts(*pPreAssigned); 68 auto pPA = new G4DecayProducts(*pPreAssi << 69 pDaughter->SetPreAssignedDecayProducts(p 79 pDaughter->SetPreAssignedDecayProducts(pPA); >> 80 if(properTime>0.0) >> 81 { pDaughter->SetPreAssignedDecayProperTime(properTime); } 70 } 82 } 71 theProductVector->push_back(pDaughter); << 83 >> 84 theProductVector->push_back( pDaughter ); 72 } 85 } 73 numberOfProducts = right.numberOfProducts; 86 numberOfProducts = right.numberOfProducts; 74 } 87 } 75 88 76 G4DecayProducts& G4DecayProducts::operator=(co << 89 G4DecayProducts & G4DecayProducts::operator=(const G4DecayProducts &right) 77 { 90 { 78 G4int index; 91 G4int index; 79 92 80 if (this != &right) { << 93 if (this != &right) >> 94 { 81 // recreate parent 95 // recreate parent 82 delete theParentParticle; << 96 if (theParentParticle != 0) delete theParentParticle; 83 theParentParticle = new G4DynamicParticle( 97 theParentParticle = new G4DynamicParticle(*right.theParentParticle); 84 98 85 // delete G4DynamicParticle objects 99 // delete G4DynamicParticle objects 86 for (index = 0; index < numberOfProducts; << 100 for (index=0; index < numberOfProducts; index++) { 87 delete theProductVector->at(index); 101 delete theProductVector->at(index); 88 } 102 } 89 theProductVector->clear(); 103 theProductVector->clear(); 90 104 91 // copy daughters (Deep Copy) << 105 //copy daughters (Deep Copy) 92 for (index = 0; index < right.numberOfProd << 106 for (index=0; index < right.numberOfProducts; index++) { 93 G4DynamicParticle* daughter = right.theP << 107 theProductVector->push_back( new G4DynamicParticle( *(right.theProductVector->at(index)) ) ); 94 auto pDaughter = new G4DynamicParticle(* << 108 } 95 << 96 G4double properTime = daughter->GetPreAs << 97 if (properTime > 0.0) pDaughter->SetPreA << 98 << 99 const G4DecayProducts* pPreAssigned = da << 100 if (pPreAssigned != nullptr) { << 101 auto pPA = new G4DecayProducts(*pPreAs << 102 pDaughter->SetPreAssignedDecayProducts << 103 } << 104 theProductVector->push_back(pDaughter); << 105 } << 106 numberOfProducts = right.numberOfProducts; 109 numberOfProducts = right.numberOfProducts; >> 110 107 } 111 } 108 return *this; 112 return *this; 109 } 113 } 110 114 111 G4DecayProducts::~G4DecayProducts() 115 G4DecayProducts::~G4DecayProducts() 112 { 116 { 113 // delete parent << 117 //delete parent 114 delete theParentParticle; << 118 if (theParentParticle != 0) delete theParentParticle; 115 theParentParticle = nullptr; << 119 116 << 117 // delete G4DynamicParticle object 120 // delete G4DynamicParticle object 118 for (G4int index = 0; index < numberOfProduc << 121 for (G4int index=0; index < numberOfProducts; index++) { 119 delete theProductVector->at(index); << 122 delete theProductVector->at(index); 120 } 123 } 121 theProductVector->clear(); 124 theProductVector->clear(); 122 numberOfProducts = 0; << 125 numberOfProducts = 0; 123 delete theProductVector; 126 delete theProductVector; 124 theProductVector = nullptr; << 125 } 127 } 126 128 127 G4DynamicParticle* G4DecayProducts::PopProduct 129 G4DynamicParticle* G4DecayProducts::PopProducts() 128 { 130 { 129 if (numberOfProducts > 0) { << 131 if ( numberOfProducts >0 ) { 130 numberOfProducts -= 1; << 132 numberOfProducts -= 1; 131 G4DynamicParticle* part = theProductVector << 133 G4DynamicParticle* part = theProductVector->back(); 132 theProductVector->pop_back(); << 134 theProductVector->pop_back(); 133 return part; << 135 return part; 134 } << 136 } else { 135 << 137 return 0; 136 return nullptr; << 138 } 137 } 139 } 138 140 139 G4int G4DecayProducts::PushProducts(G4DynamicP << 141 G4int G4DecayProducts::PushProducts(G4DynamicParticle *aParticle) 140 { 142 { 141 theProductVector->push_back(aParticle); 143 theProductVector->push_back(aParticle); 142 numberOfProducts += 1; << 144 numberOfProducts += 1; 143 return numberOfProducts; 145 return numberOfProducts; 144 } 146 } 145 147 146 G4DynamicParticle* G4DecayProducts::operator[] 148 G4DynamicParticle* G4DecayProducts::operator[](G4int anIndex) const 147 { 149 { 148 if ((numberOfProducts > anIndex) && (anIndex << 150 if ((numberOfProducts > anIndex) && (anIndex >=0) ) { 149 return theProductVector->at(anIndex); << 151 return theProductVector->at(anIndex); 150 } << 152 } else { 151 << 153 return 0; 152 return nullptr; << 154 } 153 } 155 } 154 156 155 void G4DecayProducts::SetParentParticle(const << 157 void G4DecayProducts::SetParentParticle(const G4DynamicParticle &aParticle) 156 { 158 { 157 delete theParentParticle; << 159 if (theParentParticle != 0) delete theParentParticle; 158 theParentParticle = new G4DynamicParticle(aP 160 theParentParticle = new G4DynamicParticle(aParticle); 159 } 161 } 160 162 161 void G4DecayProducts::Boost(G4double totalEner << 163 >> 164 void G4DecayProducts::Boost(G4double totalEnergy, const G4ThreeVector &momentumDirection) 162 { 165 { 163 // calculate new beta << 166 // calcurate new beta 164 G4double mass = theParentParticle->GetMass() << 167 G4double mass = theParentParticle->GetMass(); 165 G4double totalMomentum(0); << 168 G4double totalMomentum(0); 166 if (totalEnergy > mass) { << 169 if (totalEnergy > mass ) totalMomentum = std::sqrt( (totalEnergy - mass)*(totalEnergy + mass) ); 167 totalMomentum = std::sqrt((totalEnergy - m << 170 G4double betax = momentumDirection.x()*totalMomentum/totalEnergy; 168 } << 171 G4double betay = momentumDirection.y()*totalMomentum/totalEnergy; 169 G4double betax = momentumDirection.x() * tot << 172 G4double betaz = momentumDirection.z()*totalMomentum/totalEnergy; 170 G4double betay = momentumDirection.y() * tot << 173 this->Boost(betax, betay, betaz); 171 G4double betaz = momentumDirection.z() * tot << 172 Boost(betax, betay, betaz); << 173 } 174 } 174 175 175 void G4DecayProducts::Boost(G4double newbetax, 176 void G4DecayProducts::Boost(G4double newbetax, G4double newbetay, G4double newbetaz) 176 { << 177 { 177 G4double mass = theParentParticle->GetMass() << 178 G4double mass = theParentParticle->GetMass(); 178 G4double energy = theParentParticle->GetTota << 179 G4double energy = theParentParticle->GetTotalEnergy(); 179 G4double momentum = 0.0; << 180 G4double momentum = 0.0; 180 181 181 G4ThreeVector direction(0.0, 0.0, 1.0); << 182 G4ThreeVector direction(0.0,0.0,1.0); 182 G4LorentzVector p4; 183 G4LorentzVector p4; 183 184 184 if (energy - mass > DBL_MIN) { 185 if (energy - mass > DBL_MIN) { 185 // calcurate beta of initial state 186 // calcurate beta of initial state 186 momentum = theParentParticle->GetTotalMome << 187 momentum = theParentParticle->GetTotalMomentum(); 187 direction = theParentParticle->GetMomentum 188 direction = theParentParticle->GetMomentumDirection(); 188 G4double betax = -1.0 * direction.x() * mo << 189 G4double betax = -1.0*direction.x()*momentum/energy; 189 G4double betay = -1.0 * direction.y() * mo << 190 G4double betay = -1.0*direction.y()*momentum/energy; 190 G4double betaz = -1.0 * direction.z() * mo << 191 G4double betaz = -1.0*direction.z()*momentum/energy; 191 << 192 192 for (G4int index = 0; index < numberOfProd << 193 for (G4int index=0; index < numberOfProducts; index++) { 193 // make G4LorentzVector for secondaries << 194 // make G4LorentzVector for secondaries 194 p4 = (theProductVector->at(index))->Get4 << 195 p4 = (theProductVector->at(index))->Get4Momentum(); 195 << 196 196 // boost secondaries to theParentParticl << 197 // boost secondaries to theParentParticle's rest frame 197 p4.boost(betax, betay, betaz); << 198 p4.boost(betax, betay, betaz); 198 << 199 199 // boost secondaries to new frame << 200 // boost secondaries to new frame 200 p4.boost(newbetax, newbetay, newbetaz); << 201 p4.boost(newbetax, newbetay, newbetaz); 201 << 202 202 // change energy/momentum << 203 // change energy/momentum 203 (theProductVector->at(index))->Set4Momen << 204 (theProductVector->at(index))->Set4Momentum(p4); 204 } << 205 } 205 } << 206 } else { 206 else { << 207 for (G4int index=0; index < numberOfProducts; index++) { 207 for (G4int index = 0; index < numberOfProd << 208 // make G4LorentzVector for secondaries 208 // make G4LorentzVector for secondaries << 209 p4 = (theProductVector->at(index))->Get4Momentum(); 209 p4 = (theProductVector->at(index))->Get4 << 210 210 211 // boost secondaries to new frame << 211 // boost secondaries to new frame 212 p4.boost(newbetax, newbetay, newbetaz); << 212 p4.boost(newbetax, newbetay, newbetaz); 213 213 214 // change energy/momentum << 214 // change energy/momentum 215 (theProductVector->at(index))->Set4Momen << 215 (theProductVector->at(index))->Set4Momentum(p4); 216 } << 216 } 217 } << 217 } 218 << 218 // make G4LorentzVector for parent in its rest frame 219 // make G4LorentzVector for parent in its re << 219 mass = theParentParticle->GetMass(); 220 mass = theParentParticle->GetMass(); << 220 G4LorentzVector parent4( 0.0, 0.0, 0.0, mass); 221 G4LorentzVector parent4(0.0, 0.0, 0.0, mass) << 222 221 223 // boost parent to new frame << 222 // boost parent to new frame 224 parent4.boost(newbetax, newbetay, newbetaz); << 223 parent4.boost(newbetax, newbetay, newbetaz); 225 224 226 // change energy/momentum << 225 // change energy/momentum 227 theParentParticle->Set4Momentum(parent4); << 226 theParentParticle->Set4Momentum(parent4); 228 } 227 } 229 228 230 G4bool G4DecayProducts::IsChecked() const 229 G4bool G4DecayProducts::IsChecked() const 231 { 230 { 232 G4bool returnValue = true; 231 G4bool returnValue = true; 233 << 232 // check parent 234 // check parent << 233 // energy/momentum 235 // energy/momentum << 234 G4double parent_energy = theParentParticle->GetTotalEnergy(); 236 G4double parent_energy = theParentParticle-> << 237 G4ThreeVector direction = theParentParticle- 235 G4ThreeVector direction = theParentParticle->GetMomentumDirection(); 238 G4ThreeVector parent_momentum = direction * << 236 G4ThreeVector parent_momentum = direction*(theParentParticle->GetTotalMomentum()); 239 << 237 // check momentum dirction is a unit vector 240 // check momentum direction is a unit vector << 238 if ( (parent_momentum.mag() >0.0) && (std::fabs(direction.mag()-1.0) >1.0e-6 ) ) { 241 if ((parent_momentum.mag() > 0.0) && (std::f << 242 #ifdef G4VERBOSE 239 #ifdef G4VERBOSE 243 G4cout << "G4DecayProducts::IsChecked():: << 240 G4cerr << "G4DecayProducts::IsChecked():: " 244 << " Momentum Direction Vector of P 241 << " Momentum Direction Vector of Parent is not normalized " 245 << " (=" << direction.mag() << ")" 242 << " (=" << direction.mag() << ")" << G4endl; 246 #endif 243 #endif 247 returnValue = false; 244 returnValue = false; 248 parent_momentum = parent_momentum * (1. / << 245 parent_momentum = parent_momentum * (1./direction.mag()); 249 } 246 } 250 247 251 // daughters << 248 //daughters 252 G4double mass, energy; << 249 G4double mass, energy; 253 G4ThreeVector momentum; 250 G4ThreeVector momentum; 254 G4double total_energy = parent_energy; << 251 G4double total_energy = parent_energy; 255 G4ThreeVector total_momentum = parent_moment << 252 G4ThreeVector total_momentum = parent_momentum; 256 << 253 for (G4int index=0; index < numberOfProducts; index++) 257 for (G4int index = 0; index < numberOfProduc << 254 { 258 G4DynamicParticle* part = theProductVector 255 G4DynamicParticle* part = theProductVector->at(index); 259 mass = part->GetMass(); 256 mass = part->GetMass(); 260 energy = part->GetTotalEnergy(); << 257 energy = part->GetTotalEnergy(); 261 direction = part->GetMomentumDirection(); 258 direction = part->GetMomentumDirection(); 262 momentum = direction * (part->GetTotalMome << 259 momentum = direction*(part->GetTotalMomentum()); 263 << 260 // check momentum dirction is a unit vector 264 // check momentum direction is a unit vect << 261 if ( (momentum.mag()>0.0) && (std::fabs(direction.mag()-1.0) > 1.0e-6)) { 265 if ((momentum.mag() > 0.0) && (std::fabs(d << 266 #ifdef G4VERBOSE 262 #ifdef G4VERBOSE 267 G4cout << "G4DecayProducts::IsChecked(): << 263 G4cerr << "G4DecayProducts::IsChecked():: " 268 << " Momentum Direction Vector of 264 << " Momentum Direction Vector of Daughter [" << index 269 << "] is not normalized (=" << d 265 << "] is not normalized (=" << direction.mag() << ")" << G4endl; 270 #endif 266 #endif 271 returnValue = false; 267 returnValue = false; 272 momentum = momentum * (1. / direction.ma << 268 momentum = momentum * (1./direction.mag()); 273 } 269 } 274 // whether daughter stops or not 270 // whether daughter stops or not 275 if (energy - mass < DBL_MIN) { << 271 if (energy - mass < DBL_MIN ) { 276 #ifdef G4VERBOSE 272 #ifdef G4VERBOSE 277 G4cout << "G4DecayProducts::IsChecked(): << 273 G4cerr << "G4DecayProducts::IsChecked():: " 278 << " Daughter [" << index << "] << 274 << " Daughter [" << index << "] has no kinetic energy "<< G4endl; 279 #endif 275 #endif 280 returnValue = false; 276 returnValue = false; 281 } 277 } 282 total_energy -= energy; << 278 total_energy -= energy; 283 total_momentum -= momentum; 279 total_momentum -= momentum; 284 } 280 } 285 // check energy/momentum conservation 281 // check energy/momentum conservation 286 if ((std::fabs(total_energy) > 1.0e-9 * MeV) << 282 if ( (std::fabs(total_energy) >1.0e-9*MeV) || (total_momentum.mag() >1.0e-9*MeV ) ){ 287 #ifdef G4VERBOSE 283 #ifdef G4VERBOSE 288 G4cout << "G4DecayProducts::IsChecked():: << 284 G4cerr << "G4DecayProducts::IsChecked():: " 289 << " Energy/Momentum is not conserv << 285 << " Energy/Momentum is not conserved "<< G4endl; 290 G4cout << " difference between parent ener << 286 G4cerr << " difference between parent energy and sum of dughters' energy : " 291 << "[MeV] " << G4endl; << 287 << total_energy /MeV << "[MeV] " << G4endl; 292 G4cout << " difference between parent mome << 288 G4cerr << " difference between parent momentum and sum of dughters' momentum : " 293 << " x:" << total_momentum.getX() / << 289 << " x:" << total_momentum.getX()/MeV 294 << " z:" << total_momentum.getZ() / << 290 << " y:" << total_momentum.getY()/MeV >> 291 << " z:" << total_momentum.getZ()/MeV >> 292 << G4endl; 295 #endif 293 #endif 296 returnValue = false; 294 returnValue = false; 297 } 295 } 298 return returnValue; 296 return returnValue; 299 } 297 } 300 298 301 void G4DecayProducts::DumpInfo() const 299 void G4DecayProducts::DumpInfo() const 302 { 300 { 303 G4cout << " ----- List of DecayProducts --- << 301 G4cout << " ----- List of DecayProducts -----" << G4endl; 304 G4cout << " ------ Parent Particle --------- << 302 G4cout << " ------ Parent Particle ----------" << G4endl; 305 if (theParentParticle != nullptr) theParentP << 303 if (theParentParticle != 0) theParentParticle->DumpInfo(); 306 G4cout << " ------ Daughter Particles ----- << 304 G4cout << " ------ Daughter Particles ------" << G4endl; 307 for (G4int index = 0; index < numberOfProduc << 305 for (G4int index=0; index < numberOfProducts; index++) 308 G4cout << " ----------" << index + 1 << " << 306 { 309 (theProductVector->at(index))->DumpInfo(); << 307 G4cout << " ----------" << index+1 << " -------------" << G4endl; 310 } << 308 (theProductVector->at(index))-> DumpInfo(); 311 G4cout << " ----- End List of DecayProducts << 309 } 312 G4cout << G4endl; << 310 G4cout << " ----- End List of DecayProducts -----" << G4endl; 313 } << 311 G4cout << G4endl; >> 312 } 314 313