source: trunk/source/particles/management/src/G4DecayProducts.cc@ 1344

Last change on this file since 1344 was 1340, checked in by garnier, 15 years ago

update ti head

File size: 11.1 KB
Line 
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//
27// $Id: G4DecayProducts.cc,v 1.19 2010/10/30 07:55:00 kurasige Exp $
28// GEANT4 tag $Name: particles-V09-03-15 $
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// ------------------------------------------------------------
39
40#include "G4ios.hh"
41#include "globals.hh"
42#include "G4DecayProducts.hh"
43
44#include "G4LorentzVector.hh"
45#include "G4LorentzRotation.hh"
46
47G4Allocator<G4DecayProducts> aDecayProductsAllocator;
48
49
50G4DecayProducts::G4DecayProducts()
51 :numberOfProducts(0),theParentParticle(0)
52{
53 //clear theProductVector
54 for (size_t i=0;i<MaxNumberOfProducts; i+=1){
55 theProductVector[i]=0;
56 }
57}
58
59G4DecayProducts::G4DecayProducts(const G4DynamicParticle &aParticle)
60 :numberOfProducts(0),theParentParticle(0)
61{
62 theParentParticle = new G4DynamicParticle(aParticle);
63 //clear theProductVector
64 for (size_t i=0;i<MaxNumberOfProducts; i+=1){
65 theProductVector[i]=0;
66 }
67}
68
69G4DecayProducts::G4DecayProducts(const G4DecayProducts &right)
70 :numberOfProducts(0)
71{
72 //clear theProductVector
73 for (size_t i=0;i<MaxNumberOfProducts; i+=1){
74 theProductVector[i]=0;
75 }
76
77 // copy parent (Deep Copy)
78 theParentParticle = new G4DynamicParticle(*right.theParentParticle);
79
80 //copy daughters (Deep Copy)
81 for (G4int index=0; index < right.numberOfProducts; index++)
82 {
83 G4DynamicParticle* daughter = right.theProductVector[index];
84 const G4DecayProducts* pPreAssigned = daughter->GetPreAssignedDecayProducts();
85 G4double properTime = daughter->GetPreAssignedDecayProperTime();
86 G4DynamicParticle* pDaughter = new G4DynamicParticle(*daughter);
87
88 if (pPreAssigned) {
89 G4DecayProducts* pPA = new G4DecayProducts(*pPreAssigned);
90 pDaughter->SetPreAssignedDecayProducts(pPA);
91 if(properTime>0.0)
92 { pDaughter->SetPreAssignedDecayProperTime(properTime); }
93 }
94
95 PushProducts( pDaughter );
96 }
97}
98
99G4DecayProducts & G4DecayProducts::operator=(const G4DecayProducts &right)
100{
101 G4int index;
102
103 if (this != &right)
104 {
105 // recreate parent
106 if (theParentParticle != 0) delete theParentParticle;
107 theParentParticle = new G4DynamicParticle(*right.theParentParticle);
108
109 // delete G4DynamicParticle objects
110 for (index=0; index < numberOfProducts; index++)
111 {
112 delete theProductVector[index];
113 }
114
115 //copy daughters (Deep Copy)
116 for (index=0; index < right.numberOfProducts; index++) {
117 PushProducts( new G4DynamicParticle(*right.theProductVector[index]) );
118 }
119 numberOfProducts = right.numberOfProducts;
120
121 }
122 return *this;
123}
124
125G4DecayProducts::~G4DecayProducts()
126{
127 //delete parent
128 if (theParentParticle != 0) delete theParentParticle;
129
130 // delete G4DynamicParticle object
131 for (G4int index=0; index < numberOfProducts; index++)
132 {
133 delete theProductVector[index];
134 }
135 numberOfProducts = 0;
136}
137
138G4DynamicParticle* G4DecayProducts::PopProducts()
139{
140 if ( numberOfProducts >0 ) {
141 numberOfProducts -= 1;
142 return theProductVector[numberOfProducts];
143 } else {
144 return 0;
145 }
146}
147
148G4int G4DecayProducts::PushProducts(G4DynamicParticle *aParticle)
149{
150 if ( numberOfProducts < MaxNumberOfProducts) {
151 theProductVector[numberOfProducts]= aParticle;
152 numberOfProducts += 1;
153 } else {
154#ifdef G4VERBOSE
155 G4cerr << "G4DecayProducts::PushProducts "
156 << " exceeds MaxNumberOfProducts(="
157 << G4int(MaxNumberOfProducts) << ")"
158 << G4endl;
159#endif
160 }
161 return numberOfProducts;
162}
163
164G4DynamicParticle* G4DecayProducts::operator[](G4int anIndex) const
165{
166 if ((numberOfProducts > anIndex) && (anIndex >=0) ) {
167 return theProductVector[anIndex];
168 } else {
169 return 0;
170 }
171}
172
173void G4DecayProducts::SetParentParticle(const G4DynamicParticle &aParticle)
174{
175 if (theParentParticle != 0) delete theParentParticle;
176 theParentParticle = new G4DynamicParticle(aParticle);
177}
178
179
180void G4DecayProducts::Boost(G4double totalEnergy, const G4ThreeVector &momentumDirection)
181{
182 // calcurate new beta
183 G4double mass = theParentParticle->GetMass();
184 G4double totalMomentum(0);
185 if (totalEnergy > mass ) totalMomentum = std::sqrt( (totalEnergy - mass)*(totalEnergy + mass) );
186 G4double betax = momentumDirection.x()*totalMomentum/totalEnergy;
187 G4double betay = momentumDirection.y()*totalMomentum/totalEnergy;
188 G4double betaz = momentumDirection.z()*totalMomentum/totalEnergy;
189 this->Boost(betax, betay, betaz);
190}
191
192void G4DecayProducts::Boost(G4double newbetax, G4double newbetay, G4double newbetaz)
193{
194 G4double mass = theParentParticle->GetMass();
195 G4double energy = theParentParticle->GetTotalEnergy();
196 G4double momentum = 0.0;
197
198 G4ThreeVector direction(0.0,0.0,1.0);
199 G4LorentzVector p4;
200
201 if (energy - mass > DBL_MIN) {
202 // calcurate beta of initial state
203 momentum = theParentParticle->GetTotalMomentum();
204 direction = theParentParticle->GetMomentumDirection();
205 G4double betax = -1.0*direction.x()*momentum/energy;
206 G4double betay = -1.0*direction.y()*momentum/energy;
207 G4double betaz = -1.0*direction.z()*momentum/energy;
208
209 for (G4int index=0; index < numberOfProducts; index++) {
210 // make G4LorentzVector for secondaries
211 p4 = theProductVector[index]->Get4Momentum();
212
213 // boost secondaries to theParentParticle's rest frame
214 p4.boost(betax, betay, betaz);
215
216 // boost secondaries to new frame
217 p4.boost(newbetax, newbetay, newbetaz);
218
219 // change energy/momentum
220 theProductVector[index]->Set4Momentum(p4);
221 }
222 } else {
223 for (G4int index=0; index < numberOfProducts; index++) {
224 // make G4LorentzVector for secondaries
225 p4 = theProductVector[index]->Get4Momentum();
226
227 // boost secondaries to new frame
228 p4.boost(newbetax, newbetay, newbetaz);
229
230 // change energy/momentum
231 theProductVector[index]->Set4Momentum(p4);
232 }
233 }
234 // make G4LorentzVector for parent in its rest frame
235 mass = theParentParticle->GetMass();
236 G4LorentzVector parent4( 0.0, 0.0, 0.0, mass);
237
238 // boost parent to new frame
239 parent4.boost(newbetax, newbetay, newbetaz);
240
241 // change energy/momentum
242 theParentParticle->Set4Momentum(parent4);
243}
244
245G4bool G4DecayProducts::IsChecked() const
246{
247 G4bool returnValue = true;
248 // check parent
249 // energy/momentum
250 G4double parent_energy = theParentParticle->GetTotalEnergy();
251 G4ThreeVector direction = theParentParticle->GetMomentumDirection();
252 G4ThreeVector parent_momentum = direction*(theParentParticle->GetTotalMomentum());
253 // check momentum dirction is a unit vector
254 if ( (parent_momentum.mag() >0.0) && (std::fabs(direction.mag()-1.0) >1.0e-6 ) ) {
255#ifdef G4VERBOSE
256 G4cerr << "G4DecayProducts::IsChecked():: "
257 << " Momentum Direction Vector of Parent is not normalized "
258 << " (=" << direction.mag() << ")" << G4endl;
259#endif
260 returnValue = false;
261 parent_momentum = parent_momentum * (1./direction.mag());
262 }
263
264 //daughters
265 G4double mass, energy;
266 G4ThreeVector momentum;
267 G4double total_energy = parent_energy;
268 G4ThreeVector total_momentum = parent_momentum;
269 for (G4int index=0; index < numberOfProducts; index++)
270 {
271 mass = theProductVector[index]->GetMass();
272 energy = theProductVector[index]->GetTotalEnergy();
273 direction = theProductVector[index]->GetMomentumDirection();
274 momentum = direction*(theProductVector[index]->GetTotalMomentum());
275 // check momentum dirction is a unit vector
276 if ( (momentum.mag()>0.0) && (std::fabs(direction.mag()-1.0) > 1.0e-6)) {
277#ifdef G4VERBOSE
278 G4cerr << "G4DecayProducts::IsChecked():: "
279 << " Momentum Direction Vector of Daughter [" << index
280 << "] is not normalized (=" << direction.mag() << ")" << G4endl;
281#endif
282 returnValue = false;
283 momentum = momentum * (1./direction.mag());
284 }
285 // whether daughter stops or not
286 if (energy - mass < DBL_MIN ) {
287#ifdef G4VERBOSE
288 G4cerr << "G4DecayProducts::IsChecked():: "
289 << " Daughter [" << index << "] has no kinetic energy "<< G4endl;
290#endif
291 returnValue = false;
292 }
293 total_energy -= energy;
294 total_momentum -= momentum;
295 }
296 // check energy/momentum conservation
297 if ( (std::fabs(total_energy) >1.0e-9*MeV) || (total_momentum.mag() >1.0e-9*MeV ) ){
298#ifdef G4VERBOSE
299 G4cerr << "G4DecayProducts::IsChecked():: "
300 << " Energy/Momentum is not conserved "<< G4endl;
301 G4cerr << " difference between parent energy and sum of dughters' energy : "
302 << total_energy /MeV << "[MeV] " << G4endl;
303 G4cerr << " difference between parent momentum and sum of dughters' momentum : "
304 << " x:" << total_momentum.getX()/MeV
305 << " y:" << total_momentum.getY()/MeV
306 << " z:" << total_momentum.getZ()/MeV
307 << G4endl;
308#endif
309 returnValue = false;
310 }
311 return returnValue;
312}
313
314void G4DecayProducts::DumpInfo() const
315{
316 G4cout << " ----- List of DecayProducts -----" << G4endl;
317 G4cout << " ------ Parent Particle ----------" << G4endl;
318 if (theParentParticle != 0) theParentParticle->DumpInfo();
319 G4cout << " ------ Daughter Particles ------" << G4endl;
320 for (G4int index=0; index < numberOfProducts; index++)
321 {
322 G4cout << " ----------" << index+1 << " -------------" << G4endl;
323 theProductVector[index]-> DumpInfo();
324 }
325 G4cout << " ----- End List of DecayProducts -----" << G4endl;
326 G4cout << G4endl;
327}
Note: See TracBrowser for help on using the repository browser.