Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DecayProducts.cc
Go to the documentation of this file.
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// G4DecayProducts class implementation
27//
28// Author: H.Kurashige, 12 July 1996
29// ------------------------------------------------------------
30
31#include "G4ios.hh"
32#include "globals.hh"
34#include "G4SystemOfUnits.hh"
35#include "G4DecayProducts.hh"
36
37#include "G4LorentzVector.hh"
38#include "G4LorentzRotation.hh"
39
41{
42 theProductVector = new G4DecayProductVector();
43}
44
46{
47 theParentParticle = new G4DynamicParticle(aParticle);
48 theProductVector = new G4DecayProductVector();
49}
50
52{
53 theProductVector = new G4DecayProductVector();
54
55 // copy parent (Deep Copy)
56 theParentParticle = new G4DynamicParticle(*right.theParentParticle);
57
58 //copy daughters (Deep Copy)
59 for (G4int index=0; index<right.numberOfProducts; ++index)
60 {
61 G4DynamicParticle* daughter = right.theProductVector->at(index);
62 G4DynamicParticle* pDaughter = new G4DynamicParticle(*daughter);
63
64 G4double properTime = daughter->GetPreAssignedDecayProperTime();
65 if(properTime>0.0) pDaughter->SetPreAssignedDecayProperTime(properTime);
66
67 const G4DecayProducts* pPreAssigned
68 = daughter->GetPreAssignedDecayProducts();
69 if (pPreAssigned != nullptr)
70 {
71 G4DecayProducts* pPA = new G4DecayProducts(*pPreAssigned);
72 pDaughter->SetPreAssignedDecayProducts(pPA);
73 }
74 theProductVector->push_back( pDaughter );
75 }
76 numberOfProducts = right.numberOfProducts;
77}
78
80{
81 G4int index;
82
83 if (this != &right)
84 {
85 // recreate parent
86 if (theParentParticle != nullptr) delete theParentParticle;
87 theParentParticle = new G4DynamicParticle(*right.theParentParticle);
88
89 // delete G4DynamicParticle objects
90 for (index=0; index<numberOfProducts; ++index)
91 {
92 delete theProductVector->at(index);
93 }
94 theProductVector->clear();
95
96 //copy daughters (Deep Copy)
97 for (index=0; index<right.numberOfProducts; ++index)
98 {
99 G4DynamicParticle* daughter = right.theProductVector->at(index);
100 G4DynamicParticle* pDaughter = new G4DynamicParticle(*daughter);
101
102 G4double properTime = daughter->GetPreAssignedDecayProperTime();
103 if(properTime>0.0) pDaughter->SetPreAssignedDecayProperTime(properTime);
104
105 const G4DecayProducts* pPreAssigned
106 = daughter->GetPreAssignedDecayProducts();
107 if (pPreAssigned != nullptr)
108 {
109 G4DecayProducts* pPA = new G4DecayProducts(*pPreAssigned);
110 pDaughter->SetPreAssignedDecayProducts(pPA);
111 }
112 theProductVector->push_back( pDaughter );
113 }
114 numberOfProducts = right.numberOfProducts;
115 }
116 return *this;
117}
118
120{
121 //delete parent
122 if (theParentParticle != nullptr) delete theParentParticle;
123 theParentParticle = nullptr;
124
125 // delete G4DynamicParticle object
126 for (G4int index=0; index<numberOfProducts; ++index)
127 {
128 delete theProductVector->at(index);
129 }
130 theProductVector->clear();
131 numberOfProducts = 0;
132 delete theProductVector;
133 theProductVector = nullptr;
134}
135
137{
138 if ( numberOfProducts >0 )
139 {
140 numberOfProducts -= 1;
141 G4DynamicParticle* part = theProductVector->back();
142 theProductVector->pop_back();
143 return part;
144 }
145 else
146 {
147 return nullptr;
148 }
149}
150
152{
153 theProductVector->push_back(aParticle);
154 numberOfProducts += 1;
155 return numberOfProducts;
156}
157
159{
160 if ((numberOfProducts > anIndex) && (anIndex >=0) )
161 {
162 return theProductVector->at(anIndex);
163 }
164 else
165 {
166 return nullptr;
167 }
168}
169
171{
172 if (theParentParticle != nullptr) delete theParentParticle;
173 theParentParticle = new G4DynamicParticle(aParticle);
174}
175
176
178 const G4ThreeVector& momentumDirection)
179{
180 // calculate new beta
181 G4double mass = theParentParticle->GetMass();
182 G4double totalMomentum(0);
183 if ( totalEnergy > mass )
184 {
185 totalMomentum = std::sqrt( (totalEnergy - mass)*(totalEnergy + mass) );
186 }
187 G4double betax = momentumDirection.x()*totalMomentum/totalEnergy;
188 G4double betay = momentumDirection.y()*totalMomentum/totalEnergy;
189 G4double betaz = momentumDirection.z()*totalMomentum/totalEnergy;
190 Boost(betax, betay, betaz);
191}
192
194 G4double newbetay,
195 G4double newbetaz)
196{
197 G4double mass = theParentParticle->GetMass();
198 G4double energy = theParentParticle->GetTotalEnergy();
199 G4double momentum = 0.0;
200
201 G4ThreeVector direction(0.0,0.0,1.0);
203
204 if (energy - mass > DBL_MIN)
205 {
206 // calcurate beta of initial state
207 momentum = theParentParticle->GetTotalMomentum();
208 direction = theParentParticle->GetMomentumDirection();
209 G4double betax = -1.0*direction.x()*momentum/energy;
210 G4double betay = -1.0*direction.y()*momentum/energy;
211 G4double betaz = -1.0*direction.z()*momentum/energy;
212
213 for (G4int index=0; index<numberOfProducts; ++index)
214 {
215 // make G4LorentzVector for secondaries
216 p4 = (theProductVector->at(index))->Get4Momentum();
217
218 // boost secondaries to theParentParticle's rest frame
219 p4.boost(betax, betay, betaz);
220
221 // boost secondaries to new frame
222 p4.boost(newbetax, newbetay, newbetaz);
223
224 // change energy/momentum
225 (theProductVector->at(index))->Set4Momentum(p4);
226 }
227 }
228 else
229 {
230 for (G4int index=0; index<numberOfProducts; ++index)
231 {
232 // make G4LorentzVector for secondaries
233 p4 = (theProductVector->at(index))->Get4Momentum();
234
235 // boost secondaries to new frame
236 p4.boost(newbetax, newbetay, newbetaz);
237
238 // change energy/momentum
239 (theProductVector->at(index))->Set4Momentum(p4);
240 }
241 }
242
243 // make G4LorentzVector for parent in its rest frame
244 mass = theParentParticle->GetMass();
245 G4LorentzVector parent4( 0.0, 0.0, 0.0, mass);
246
247 // boost parent to new frame
248 parent4.boost(newbetax, newbetay, newbetaz);
249
250 // change energy/momentum
251 theParentParticle->Set4Momentum(parent4);
252}
253
255{
256 G4bool returnValue = true;
257
258 // check parent
259 // energy/momentum
260 G4double parent_energy = theParentParticle->GetTotalEnergy();
261 G4ThreeVector direction = theParentParticle->GetMomentumDirection();
262 G4ThreeVector parent_momentum
263 = direction*(theParentParticle->GetTotalMomentum());
264
265 // check momentum direction is a unit vector
266 if ((parent_momentum.mag() >0.0) && (std::fabs(direction.mag()-1.0) >1.0e-6))
267 {
268#ifdef G4VERBOSE
269 G4cout << "G4DecayProducts::IsChecked():: "
270 << " Momentum Direction Vector of Parent is not normalized "
271 << " (=" << direction.mag() << ")" << G4endl;
272#endif
273 returnValue = false;
274 parent_momentum = parent_momentum * (1./direction.mag());
275 }
276
277 // daughters
278 G4double mass, energy;
279 G4ThreeVector momentum;
280 G4double total_energy = parent_energy;
281 G4ThreeVector total_momentum = parent_momentum;
282
283 for (G4int index=0; index < numberOfProducts; ++index)
284 {
285 G4DynamicParticle* part = theProductVector->at(index);
286 mass = part->GetMass();
287 energy = part->GetTotalEnergy();
288 direction = part->GetMomentumDirection();
289 momentum = direction*(part->GetTotalMomentum());
290
291 // check momentum direction is a unit vector
292 if ( (momentum.mag()>0.0) && (std::fabs(direction.mag()-1.0) > 1.0e-6))
293 {
294#ifdef G4VERBOSE
295 G4cout << "G4DecayProducts::IsChecked():: "
296 << " Momentum Direction Vector of Daughter [" << index
297 << "] is not normalized (=" << direction.mag() << ")" << G4endl;
298#endif
299 returnValue = false;
300 momentum = momentum * (1./direction.mag());
301 }
302 // whether daughter stops or not
303 if (energy - mass < DBL_MIN )
304 {
305#ifdef G4VERBOSE
306 G4cout << "G4DecayProducts::IsChecked():: "
307 << " Daughter [" << index << "] has no kinetic energy "<< G4endl;
308#endif
309 returnValue = false;
310 }
311 total_energy -= energy;
312 total_momentum -= momentum;
313 }
314 // check energy/momentum conservation
315 if ( (std::fabs(total_energy) >1.0e-9*MeV)
316 || (total_momentum.mag() >1.0e-9*MeV ) )
317 {
318#ifdef G4VERBOSE
319 G4cout << "G4DecayProducts::IsChecked():: "
320 << " Energy/Momentum is not conserved "<< G4endl;
321 G4cout << " difference between parent energy & sum of daughters energy: "
322 << total_energy /MeV << "[MeV] " << G4endl;
323 G4cout << " difference between parent momentum & sum of daughters momentum: "
324 << " x:" << total_momentum.getX()/MeV
325 << " y:" << total_momentum.getY()/MeV
326 << " z:" << total_momentum.getZ()/MeV
327 << G4endl;
328#endif
329 returnValue = false;
330 }
331 return returnValue;
332}
333
335{
336 G4cout << " ----- List of DecayProducts -----" << G4endl;
337 G4cout << " ------ Parent Particle ----------" << G4endl;
338 if (theParentParticle != 0) theParentParticle->DumpInfo();
339 G4cout << " ------ Daughter Particles ------" << G4endl;
340 for (G4int index=0; index<numberOfProducts; ++index)
341 {
342 G4cout << " ----------" << index+1 << " -------------" << G4endl;
343 (theProductVector->at(index))-> DumpInfo();
344 }
345 G4cout << " ----- End List of DecayProducts -----" << G4endl;
346 G4cout << G4endl;
347}
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
double z() const
double getZ() const
double x() const
double y() const
double mag() const
double getX() const
double getY() const
HepLorentzVector & boost(double, double, double)
void DumpInfo() const
std::vector< G4DynamicParticle * > G4DecayProductVector
G4DynamicParticle * PopProducts()
G4int PushProducts(G4DynamicParticle *aParticle)
G4DecayProducts & operator=(const G4DecayProducts &right)
G4DynamicParticle * operator[](G4int anIndex) const
void SetParentParticle(const G4DynamicParticle &aParticle)
G4bool IsChecked() const
void Boost(G4double totalEnergy, const G4ThreeVector &momentumDirection)
G4double GetMass() const
void SetPreAssignedDecayProducts(G4DecayProducts *aDecayProducts)
void DumpInfo(G4int mode=0) const
const G4ThreeVector & GetMomentumDirection() const
const G4DecayProducts * GetPreAssignedDecayProducts() const
G4double GetTotalEnergy() const
void Set4Momentum(const G4LorentzVector &momentum)
void SetPreAssignedDecayProperTime(G4double)
G4double GetPreAssignedDecayProperTime() const
G4double GetTotalMomentum() const
#define DBL_MIN
Definition: templates.hh:54