Geant4  10.00.p03
G4GDecay3.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 // $Id$
27 //
28 // File: G4GDecay3.cc
29 // Author: Dennis Wright (SLAC)
30 // Date: 19 April 2013
31 //
32 // Description: three-body phase space momentum generator based on
33 // GDECA3 of Geant3
34 //
35 // 20130620 Address Coverity #51433, initializing all data members
36 
37 #include "G4GDecay3.hh"
38 #include "G4PhysicalConstants.hh"
39 #include "Randomize.hh"
40 
41 G4GDecay3::G4GDecay3(const G4double& pMass, const G4double& dMass0,
42  const G4double& dMass1, const G4double& dMass2)
43  : loopMax(100), parentMass(pMass), mDaughter0(dMass0), mDaughter1(dMass1),
44  mDaughter2(dMass2), pDaughter0(0.), pDaughter1(0.), pDaughter2(0.) {;}
45 
46 
48 {
49  G4int looper = 0;
50  G4bool status;
51 
52  G4double rndm;
53  G4double rndm1;
54  G4double rndm2;
55 
56  G4double momentummax;
57  G4double momentumsum;
59 
61  do {
62  rndm1 = G4UniformRand();
63  rndm2 = G4UniformRand();
64  if (rndm2 > rndm1) {
65  // keep randoms in descending order
66  rndm = rndm1;
67  rndm1 = rndm2;
68  rndm2 = rndm;
69  }
70  momentummax = 0.0;
71  momentumsum = 0.0;
72 
73  // daughter 0
74  energy = rndm2*availableE;
75  pDaughter0 = std::sqrt(energy*energy + 2.0*energy*mDaughter0);
76  if (pDaughter0 > momentummax) momentummax = pDaughter0;
77  momentumsum += pDaughter0;
78 
79  // daughter 1
80  energy = (1.-rndm1)*availableE;
81  pDaughter1 = std::sqrt(energy*energy + 2.0*energy*mDaughter1);
82  if (pDaughter1 > momentummax) momentummax = pDaughter1;
83  momentumsum += pDaughter1;
84 
85  // daughter 2
86  energy = (rndm1-rndm2)*availableE;
87  pDaughter2 = std::sqrt(energy*energy + 2.0*energy*mDaughter2);
88  if (pDaughter2 > momentummax) momentummax = pDaughter2;
89  momentumsum += pDaughter2;
90  looper++;
91  status = looper < loopMax;
92  } while ((momentummax > momentumsum - momentummax) && status);
93 
94  return status;
95 }
96 
97 
98 std::vector<G4ThreeVector> G4GDecay3::GetThreeBodyMomenta()
99 {
100 
101  std::vector<G4ThreeVector> pVect;
102 
104 
105  // Calculate directions
106  G4double costheta = 2.*G4UniformRand()-1.;
107  G4double sintheta = std::sqrt((1.0-costheta)*(1.0+costheta));
108  G4double phi = twopi*G4UniformRand();
109  G4double sinphi = std::sin(phi);
110  G4double cosphi = std::cos(phi);
111  G4ThreeVector direction0(sintheta*cosphi, sintheta*sinphi, costheta);
112 
115  G4double sinthetan = std::sqrt((1.0-costhetan)*(1.0+costhetan));
116  G4double phin = twopi*G4UniformRand();
117  G4double sinphin = std::sin(phin);
118  G4double cosphin = std::cos(phin);
119  G4ThreeVector direction2;
120  direction2.setX(sinthetan*cosphin*costheta*cosphi -
121  sinthetan*sinphin*sinphi + costhetan*sintheta*cosphi);
122  direction2.setY(sinthetan*cosphin*costheta*sinphi +
123  sinthetan*sinphin*cosphi + costhetan*sintheta*sinphi);
124  direction2.setZ(-sinthetan*cosphin*sintheta + costhetan*costheta);
125 
126  // Return momentum vectors
127  pVect.push_back(pDaughter0*direction0);
128  pVect.push_back(-direction0*pDaughter0 - direction2*pDaughter2);
129  pVect.push_back(pDaughter2*direction2);
130 
131  } else {
132  G4cerr << "G4GDecay::GetThreeBodyMomenta: " << loopMax
133  << " or more loops in momentum magnitude calculation " << G4endl;
134  }
135 
136  return pVect;
137 }
138 
G4double mDaughter0
Definition: G4GDecay3.hh:59
std::vector< G4ThreeVector > GetThreeBodyMomenta()
Definition: G4GDecay3.cc:98
CLHEP::Hep3Vector G4ThreeVector
int G4int
Definition: G4Types.hh:78
G4double pDaughter2
Definition: G4GDecay3.hh:65
G4double mDaughter1
Definition: G4GDecay3.hh:60
G4bool CalculateMomentumMagnitudes()
Definition: G4GDecay3.cc:47
G4double parentMass
Definition: G4GDecay3.hh:58
#define G4UniformRand()
Definition: Randomize.hh:87
bool G4bool
Definition: G4Types.hh:79
G4double energy(const ThreeVector &p, const G4double m)
G4double pDaughter0
Definition: G4GDecay3.hh:63
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4int loopMax
Definition: G4GDecay3.hh:56
G4double mDaughter2
Definition: G4GDecay3.hh:61
G4GLOB_DLL std::ostream G4cerr
G4double pDaughter1
Definition: G4GDecay3.hh:64