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