Geant4  10.02.p02
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 // 20141201 Fix error message text to show correct class name
37 // 20150608 M. Kelsey -- Label all while loops as terminating.
38 
39 #include "G4GDecay3.hh"
40 #include "G4PhysicalConstants.hh"
41 #include "Randomize.hh"
42 
43 G4GDecay3::G4GDecay3(const G4double& pMass, const G4double& dMass0,
44  const G4double& dMass1, const G4double& dMass2)
45  : loopMax(100), parentMass(pMass), mDaughter0(dMass0), mDaughter1(dMass1),
46  mDaughter2(dMass2), pDaughter0(0.), pDaughter1(0.), pDaughter2(0.) {;}
47 
48 
50 {
51  G4int looper = 0;
52  G4bool status;
53 
54  G4double rndm;
55  G4double rndm1;
56  G4double rndm2;
57 
58  G4double momentummax;
59  G4double momentumsum;
61 
63  do { /* Loop checking 08.06.2015 MHK */
64  rndm1 = G4UniformRand();
65  rndm2 = G4UniformRand();
66  if (rndm2 > rndm1) {
67  // keep randoms in descending order
68  rndm = rndm1;
69  rndm1 = rndm2;
70  rndm2 = rndm;
71  }
72  momentummax = 0.0;
73  momentumsum = 0.0;
74 
75  // daughter 0
76  energy = rndm2*availableE;
77  pDaughter0 = std::sqrt(energy*energy + 2.0*energy*mDaughter0);
78  if (pDaughter0 > momentummax) momentummax = pDaughter0;
79  momentumsum += pDaughter0;
80 
81  // daughter 1
82  energy = (1.-rndm1)*availableE;
83  pDaughter1 = std::sqrt(energy*energy + 2.0*energy*mDaughter1);
84  if (pDaughter1 > momentummax) momentummax = pDaughter1;
85  momentumsum += pDaughter1;
86 
87  // daughter 2
88  energy = (rndm1-rndm2)*availableE;
89  pDaughter2 = std::sqrt(energy*energy + 2.0*energy*mDaughter2);
90  if (pDaughter2 > momentummax) momentummax = pDaughter2;
91  momentumsum += pDaughter2;
92  looper++;
93  status = looper < loopMax;
94  } while ((momentummax > momentumsum - momentummax) && status);
95 
96  return status;
97 }
98 
99 
100 std::vector<G4ThreeVector> G4GDecay3::GetThreeBodyMomenta()
101 {
102 
103  std::vector<G4ThreeVector> pVect;
104 
106 
107  // Calculate directions
108  G4double costheta = 2.*G4UniformRand()-1.;
109  G4double sintheta = std::sqrt((1.0-costheta)*(1.0+costheta));
110  G4double phi = twopi*G4UniformRand();
111  G4double sinphi = std::sin(phi);
112  G4double cosphi = std::cos(phi);
113  G4ThreeVector direction0(sintheta*cosphi, sintheta*sinphi, costheta);
114 
117  G4double sinthetan = std::sqrt((1.0-costhetan)*(1.0+costhetan));
118  G4double phin = twopi*G4UniformRand();
119  G4double sinphin = std::sin(phin);
120  G4double cosphin = std::cos(phin);
121  G4ThreeVector direction2;
122  direction2.setX(sinthetan*cosphin*costheta*cosphi -
123  sinthetan*sinphin*sinphi + costhetan*sintheta*cosphi);
124  direction2.setY(sinthetan*cosphin*costheta*sinphi +
125  sinthetan*sinphin*cosphi + costhetan*sintheta*sinphi);
126  direction2.setZ(-sinthetan*cosphin*sintheta + costhetan*costheta);
127 
128  // Return momentum vectors
129  pVect.push_back(pDaughter0*direction0);
130  pVect.push_back(-direction0*pDaughter0 - direction2*pDaughter2);
131  pVect.push_back(pDaughter2*direction2);
132 
133  } else {
134  G4cerr << "G4GDecay3::GetThreeBodyMomenta: " << loopMax
135  << " or more loops in momentum magnitude calculation " << G4endl;
136  }
137 
138  return pVect;
139 }
140 
G4double mDaughter0
Definition: G4GDecay3.hh:59
std::vector< G4ThreeVector > GetThreeBodyMomenta()
Definition: G4GDecay3.cc:100
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:49
G4double parentMass
Definition: G4GDecay3.hh:58
#define G4UniformRand()
Definition: Randomize.hh:97
bool G4bool
Definition: G4Types.hh:79
static const double twopi
Definition: G4SIunits.hh:75
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