Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4HadPhaseSpaceKopylov.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 // Multibody "phase space" generator using Kopylov's algorithm
29 //
30 // Author: Michael Kelsey (SLAC) <kelsey@slac.stanford.edu>
31 
33 #include "G4LorentzVector.hh"
34 #include "G4Pow.hh"
35 #include "Randomize.hh"
36 #include <vector>
37 #include <algorithm>
38 #include <numeric>
39 #include <cmath>
40 
41 
42 // Generator
43 
46  const std::vector<G4double>& masses,
47  std::vector<G4LorentzVector>& finalState) {
48  if (GetVerboseLevel()) G4cout << GetName() << "::GenerateMultiBody" << G4endl;
49 
50  finalState.clear();
51 
52  size_t N = masses.size();
53  finalState.resize(N);
54 
55  G4double mtot = std::accumulate(masses.begin(), masses.end(), 0.0);
56  G4double mu = mtot;
57  G4double PFragMagCM = 0.0;
58  G4double Mass = initialMass;
59  G4double T = Mass-mtot;
60  G4LorentzVector PFragCM(0.0,0.0,0.0,0.0);
61  G4LorentzVector PRestCM(0.0,0.0,0.0,0.0);
62  G4LorentzVector PRestLab(0.0,0.0,0.0,Mass);
63 
64  for (size_t k=N-1; k>0; --k) {
65  mu -= masses[k];
66  T *= (k>1) ? BetaKopylov(k) : 0.;
67 
68  G4double RestMass = mu + T;
69 
70  PFragMagCM = TwoBodyMomentum(Mass,masses[k],RestMass);
71 
72  // Create a unit vector with a random direction isotropically distributed
73  G4ThreeVector RandVector = UniformVector(PFragMagCM);
74 
75  PFragCM.setVectM(RandVector,masses[k]);
76  PRestCM.setVectM(-RandVector,RestMass);
77 
78  G4ThreeVector BoostV = PRestLab.boostVector();
79 
80  PFragCM.boost(BoostV);
81  PRestCM.boost(BoostV);
82  PRestLab = PRestCM;
83  Mass = RestMass;
84  finalState[k] = PFragCM;
85  }
86 
87  finalState[0] = PRestLab;
88 }
89 
90 
91 // Generate scale factor for final state particle
92 
94  G4Pow* g4pow = G4Pow::GetInstance();
95 
96  G4int N = 3*K - 5;
97  G4double xN = G4double(N);
98  G4double Fmax = std::sqrt(g4pow->powN(xN/(xN+1.),N)/(xN+1.));
99 
100  G4double F, chi;
101  const G4int maxNumberOfLoops = 10000;
102  G4int loopCounter = 0;
103  do {
104  chi = G4UniformRand();
105  F = std::sqrt(g4pow->powN(chi,N)*(1.-chi));
106  } while ( ( Fmax*G4UniformRand() > F ) && ++loopCounter < maxNumberOfLoops ); /* Loop checking, 02.11.2015, A.Ribon */
107  if ( loopCounter >= maxNumberOfLoops ) {
109  ed << " Failed sampling after maxNumberOfLoops attempts : forced exit" << G4endl;
110  G4Exception( " G4HadPhaseSpaceKopylov::BetaKopylov ", "HAD_KOPYLOV_001", JustWarning, ed );
111  }
112 
113  return chi;
114 }
static G4Pow * GetInstance()
Definition: G4Pow.cc:55
Hep3Vector boostVector() const
G4double powN(G4double x, G4int n) const
Definition: G4Pow.cc:128
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
Definition: G4Pow.hh:56
G4int GetVerboseLevel() const
int G4int
Definition: G4Types.hh:78
void setVectM(const Hep3Vector &spatial, double mass)
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
virtual void GenerateMultiBody(G4double initialMass, const std::vector< G4double > &masses, std::vector< G4LorentzVector > &finalState)
HepLorentzVector & boost(double, double, double)
G4double BetaKopylov(G4int K) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const G4String & GetName() const
G4double TwoBodyMomentum(G4double M0, G4double M1, G4double M2) const
#define G4endl
Definition: G4ios.hh:61
**D E S C R I P T I O N
Definition: HEPEvtcom.cc:77
double G4double
Definition: G4Types.hh:76
G4ThreeVector UniformVector(G4double mag=1.) const