ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GDecay3.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4GDecay3.cc
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 // File: G4GDecay3.cc
28 // Author: Dennis Wright (SLAC)
29 // Date: 19 April 2013
30 //
31 // Description: three-body phase space momentum generator based on
32 // GDECA3 of Geant3
33 //
34 // 20130620 Address Coverity #51433, initializing all data members
35 // 20141201 Fix error message text to show correct class name
36 // 20150608 M. Kelsey -- Label all while loops as terminating.
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), mDaughter0(dMass0), mDaughter1(dMass1),
45  mDaughter2(dMass2), pDaughter0(0.), pDaughter1(0.), pDaughter2(0.)
46 {
48 }
49 
51 {
52  G4double rndm;
53  G4double rndm1;
54  G4double rndm2;
55 
56  G4double momentummax;
57  G4double momentumsum;
59 
61  do { /* Loop checking 08.06.2015 MHK */
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  } while (momentummax > momentumsum - momentummax);
91 
92  return true;
93 }
94 
95 
96 std::vector<G4ThreeVector> G4GDecay3::GetThreeBodyMomenta()
97 {
98 
99  std::vector<G4ThreeVector> pVect;
100 
102 
103  // Calculate directions
104  G4double costheta = 2.*G4UniformRand()-1.;
105  G4double sintheta = std::sqrt((1.0-costheta)*(1.0+costheta));
107  G4double sinphi = std::sin(phi);
108  G4double cosphi = std::cos(phi);
109  G4ThreeVector direction0(sintheta*cosphi, sintheta*sinphi, costheta);
110 
113  G4double sinthetan = std::sqrt((1.0-costhetan)*(1.0+costhetan));
114  G4double phin = twopi*G4UniformRand();
115  G4double sinphin = std::sin(phin);
116  G4double cosphin = std::cos(phin);
117  G4ThreeVector direction2;
118  direction2.setX(sinthetan*cosphin*costheta*cosphi -
119  sinthetan*sinphin*sinphi + costhetan*sintheta*cosphi);
120  direction2.setY(sinthetan*cosphin*costheta*sinphi +
121  sinthetan*sinphin*cosphi + costhetan*sintheta*sinphi);
122  direction2.setZ(-sinthetan*cosphin*sintheta + costhetan*costheta);
123 
124  // Return momentum vectors
125  pVect.push_back(pDaughter0*direction0);
126  pVect.push_back(-direction0*pDaughter0 - direction2*pDaughter2);
127  pVect.push_back(pDaughter2*direction2);
128 
129  } else {
130  G4cerr << "G4GDecay3::GetThreeBodyMomenta: " << loopMax
131  << " or more loops in momentum magnitude calculation " << G4endl;
132  }
133 
134  return pVect;
135 }
136