Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/particles/management/src/G4PhaseSpaceDecayChannel.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /particles/management/src/G4PhaseSpaceDecayChannel.cc (Version 11.3.0) and /particles/management/src/G4PhaseSpaceDecayChannel.cc (Version 10.1.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4PhaseSpaceDecayChannel class implementati << 
 27 //                                                 26 //
 28 // Author: H.Kurashige, 27 July 1996           <<  27 // $Id: G4PhaseSpaceDecayChannel.cc 95335 2016-02-05 07:47:45Z gcosmo $
 29 // ------------------------------------------- <<  28 //
 30                                                <<  29 // 
 31 #include "G4PhaseSpaceDecayChannel.hh"         <<  30 // ------------------------------------------------------------
                                                   >>  31 //      GEANT 4 class header file
                                                   >>  32 //
                                                   >>  33 //      History: first implementation, based on object model of
                                                   >>  34 //      27 July 1996 H.Kurashige
                                                   >>  35 //      20 Oct 1996 H.Kurashige
                                                   >>  36 //      30 May 1997 H.Kurashige
                                                   >>  37 // ------------------------------------------------------------
 32                                                    38 
 33 #include "G4DecayProducts.hh"                  << 
 34 #include "G4LorentzRotation.hh"                << 
 35 #include "G4LorentzVector.hh"                  << 
 36 #include "G4ParticleDefinition.hh"                 39 #include "G4ParticleDefinition.hh"
 37 #include "G4PhysicalConstants.hh"                  40 #include "G4PhysicalConstants.hh"
 38 #include "G4SystemOfUnits.hh"                      41 #include "G4SystemOfUnits.hh"
                                                   >>  42 #include "G4DecayProducts.hh"
 39 #include "G4VDecayChannel.hh"                      43 #include "G4VDecayChannel.hh"
                                                   >>  44 #include "G4PhaseSpaceDecayChannel.hh"
 40 #include "Randomize.hh"                            45 #include "Randomize.hh"
                                                   >>  46 #include "G4LorentzVector.hh"
                                                   >>  47 #include "G4LorentzRotation.hh"
                                                   >>  48 
                                                   >>  49 G4ThreadLocal G4double G4PhaseSpaceDecayChannel::current_parent_mass = 0.0;
 41                                                    50 
 42 G4PhaseSpaceDecayChannel::G4PhaseSpaceDecayCha     51 G4PhaseSpaceDecayChannel::G4PhaseSpaceDecayChannel(G4int Verbose)
 43   : G4VDecayChannel("Phase Space", Verbose)    <<  52  :G4VDecayChannel("Phase Space", Verbose)
 44 {}                                             <<  53 {
 45                                                    54 
 46 G4PhaseSpaceDecayChannel::G4PhaseSpaceDecayCha <<  55 }
 47                                                << 
 48                                                << 
 49                                                << 
 50                                                << 
 51                                                << 
 52                                                << 
 53   : G4VDecayChannel("Phase Space", theParentNa << 
 54                     theDaughterName2, theDaugh << 
 55 {}                                             << 
 56                                                    56 
 57 G4DecayProducts* G4PhaseSpaceDecayChannel::Dec <<  57 G4PhaseSpaceDecayChannel::G4PhaseSpaceDecayChannel(
                                                   >>  58              const G4String& theParentName,
                                                   >>  59              G4double        theBR,
                                                   >>  60              G4int           theNumberOfDaughters,
                                                   >>  61              const G4String& theDaughterName1,
                                                   >>  62              const G4String& theDaughterName2,
                                                   >>  63              const G4String& theDaughterName3,
                                                   >>  64              const G4String& theDaughterName4    )
                                                   >>  65                          :G4VDecayChannel("Phase Space",
                                                   >>  66             theParentName,theBR,
                                                   >>  67             theNumberOfDaughters,
                                                   >>  68             theDaughterName1,
                                                   >>  69             theDaughterName2,
                                                   >>  70             theDaughterName3,
                                                   >>  71             theDaughterName4)
 58 {                                                  72 {
 59 #ifdef G4VERBOSE                               << 
 60   if (GetVerboseLevel() > 1) G4cout << "G4Phas << 
 61 #endif                                         << 
 62                                                    73 
 63   G4DecayProducts* products = nullptr;         <<  74 }
 64                                                << 
 65   CheckAndFillParent();                        << 
 66   CheckAndFillDaughters();                     << 
 67                                                    75 
 68   if (parentMass > 0.0)                        <<  76 G4PhaseSpaceDecayChannel::~G4PhaseSpaceDecayChannel()
 69     current_parent_mass.Put(parentMass);       <<  77 {
 70   else                                         <<  78 }
 71     current_parent_mass.Put(G4MT_parent_mass); << 
 72                                                    79 
 73   switch (numberOfDaughters) {                 <<  80 G4DecayProducts *G4PhaseSpaceDecayChannel::DecayIt(G4double parentMass)
 74     case 0:                                    <<  81 {
 75 #ifdef G4VERBOSE                                   82 #ifdef G4VERBOSE
 76       if (GetVerboseLevel() > 0) {             <<  83   if (GetVerboseLevel()>1) G4cout << "G4PhaseSpaceDecayChannel::DecayIt ";
 77         G4cout << "G4PhaseSpaceDecayChannel::D << 
 78         G4cout << " daughters not defined " << << 
 79       }                                        << 
 80 #endif                                             84 #endif
 81       break;                                   <<  85   
 82     case 1:                                    <<  86   G4DecayProducts * products = 0;
 83       products = OneBodyDecayIt();             <<  87  
 84       break;                                   <<  88   if (G4MT_parent == 0) FillParent();  
 85     case 2:                                    <<  89   if (G4MT_daughters == 0) FillDaughters();
 86       products = TwoBodyDecayIt();             <<  90 
 87       break;                                   <<  91   if (parentMass >0.0) current_parent_mass = parentMass;
 88     case 3:                                    <<  92   else                 current_parent_mass = G4MT_parent_mass;
 89       products = ThreeBodyDecayIt();           <<  93 
 90       break;                                   <<  94   switch (numberOfDaughters){
 91     default:                                   <<  95   case 0:
 92       products = ManyBodyDecayIt();            <<  96 #ifdef G4VERBOSE
 93       break;                                   <<  97     if (GetVerboseLevel()>0) {
 94   }                                            <<  98       G4cout << "G4PhaseSpaceDecayChannel::DecayIt ";
 95 #ifdef G4VERBOSE                               <<  99       G4cout << " daughters not defined " <<G4endl;
 96   if ((products == nullptr) && (GetVerboseLeve << 100     }
 97     G4cout << "G4PhaseSpaceDecayChannel::Decay << 101 #endif
 98     G4cout << *parent_name << " cannot decay " << 102     break;
                                                   >> 103   case 1:
                                                   >> 104     products =  OneBodyDecayIt();
                                                   >> 105     break;
                                                   >> 106   case 2:
                                                   >> 107     products =  TwoBodyDecayIt();
                                                   >> 108     break;
                                                   >> 109   case 3:
                                                   >> 110     products =  ThreeBodyDecayIt();
                                                   >> 111     break;
                                                   >> 112   default:
                                                   >> 113     products =  ManyBodyDecayIt();
                                                   >> 114     break;
                                                   >> 115   }
                                                   >> 116 #ifdef G4VERBOSE
                                                   >> 117   if ((products == 0) && (GetVerboseLevel()>0)) {
                                                   >> 118     G4cout << "G4PhaseSpaceDecayChannel::DecayIt ";
                                                   >> 119     G4cout << *parent_name << " can not decay " << G4endl;
 99     DumpInfo();                                   120     DumpInfo();
100   }                                               121   }
101 #endif                                            122 #endif
102   return products;                                123   return products;
103 }                                                 124 }
104                                                   125 
105 G4DecayProducts* G4PhaseSpaceDecayChannel::One << 126 G4DecayProducts *G4PhaseSpaceDecayChannel::OneBodyDecayIt()
106 {                                                 127 {
107 #ifdef G4VERBOSE                                  128 #ifdef G4VERBOSE
108   if (GetVerboseLevel() > 1) G4cout << "G4Phas << 129   if (GetVerboseLevel()>1) G4cout << "G4PhaseSpaceDecayChannel::OneBodyDecayIt()"<<G4endl;
109 #endif                                            130 #endif
110   // parent mass                               << 
111   G4double parentmass = current_parent_mass.Ge << 
112                                                   131 
113   // create parent G4DynamicParticle at rest   << 132   //create parent G4DynamicParticle at rest
114   G4ThreeVector dummy;                            133   G4ThreeVector dummy;
115   auto parentparticle = new G4DynamicParticle( << 134   G4DynamicParticle * parentparticle = new G4DynamicParticle( G4MT_parent, dummy, 0.0);
116   // create G4Decayproducts                    << 135   //create G4Decayproducts
117   auto products = new G4DecayProducts(*parentp << 136   G4DecayProducts *products = new G4DecayProducts(*parentparticle);
118   delete parentparticle;                          137   delete parentparticle;
119                                                   138 
120   // create daughter G4DynamicParticle at rest << 139   //create daughter G4DynamicParticle at rest
121   auto daughterparticle = new G4DynamicParticl << 140   G4DynamicParticle * daughterparticle = new G4DynamicParticle( G4MT_daughters[0], dummy, 0.0);
122   if (useGivenDaughterMass) daughterparticle-> << 
123   products->PushProducts(daughterparticle);       141   products->PushProducts(daughterparticle);
124                                                   142 
125 #ifdef G4VERBOSE                                  143 #ifdef G4VERBOSE
126   if (GetVerboseLevel() > 1) {                 << 144   if (GetVerboseLevel()>1) {
127     G4cout << "G4PhaseSpaceDecayChannel::OneBo << 145      G4cout << "G4PhaseSpaceDecayChannel::OneBodyDecayIt ";
128     G4cout << " create decay products in rest  << 146      G4cout << "  create decay products in rest frame " <<G4endl;
129     products->DumpInfo();                      << 147      products->DumpInfo();
130   }                                               148   }
131 #endif                                            149 #endif
132   return products;                                150   return products;
133 }                                                 151 }
134                                                   152 
135 G4DecayProducts* G4PhaseSpaceDecayChannel::Two << 153 G4DecayProducts *G4PhaseSpaceDecayChannel::TwoBodyDecayIt()
136 {                                                 154 {
137 #ifdef G4VERBOSE                                  155 #ifdef G4VERBOSE
138   if (GetVerboseLevel() > 1) G4cout << "G4Phas << 156   if (GetVerboseLevel()>1) G4cout << "G4PhaseSpaceDecayChannel::TwoBodyDecayIt()"<<G4endl;
139 #endif                                            157 #endif
140   // parent mass                                  158   // parent mass
141   G4double parentmass = current_parent_mass.Ge << 159   G4double parentmass = current_parent_mass;
142                                                << 160   
143   // daughters'mass, width                     << 161   //daughters'mass, width
144   G4double daughtermass[2], daughterwidth[2];  << 162   G4double daughtermass[2], daughterwidth[2]; 
                                                   >> 163   G4double daughtermomentum;
145   daughtermass[0] = G4MT_daughters_mass[0];       164   daughtermass[0] = G4MT_daughters_mass[0];
146   daughtermass[1] = G4MT_daughters_mass[1];       165   daughtermass[1] = G4MT_daughters_mass[1];
147   daughterwidth[0] = G4MT_daughters_width[0];     166   daughterwidth[0] = G4MT_daughters_width[0];
148   daughterwidth[1] = G4MT_daughters_width[1];     167   daughterwidth[1] = G4MT_daughters_width[1];
149                                                   168 
150   // create parent G4DynamicParticle at rest   << 169   //create parent G4DynamicParticle at rest
151   G4ThreeVector dummy;                            170   G4ThreeVector dummy;
152   auto parentparticle = new G4DynamicParticle( << 171   G4DynamicParticle * parentparticle = new G4DynamicParticle( G4MT_parent, dummy, 0.0, parentmass);
153   // create G4Decayproducts                    << 172   //create G4Decayproducts
154   auto products = new G4DecayProducts(*parentp << 173   G4DecayProducts *products = new G4DecayProducts(*parentparticle);
155   delete parentparticle;                          174   delete parentparticle;
156                                                   175 
157   if (!useGivenDaughterMass) {                 << 176   G4bool withWidth = (daughterwidth[0]>1.0e-3*daughtermass[0]) || (daughterwidth[1]>1.0e-3*daughtermass[1]);
158     G4bool withWidth = (daughterwidth[0] > 1.0 << 177   if (withWidth) {
159                        || (daughterwidth[1] >  << 178     G4double sumofdaughterwidthsq = daughterwidth[0]*daughterwidth[0]+daughterwidth[1]*daughterwidth[1];
160     if (withWidth) {                           << 179     // check parent mass and daughter mass
161       G4double sumofdaughterwidthsq =          << 180     G4double maxDev = (parentmass - daughtermass[0] - daughtermass[1] )/std::sqrt(sumofdaughterwidthsq);
162         daughterwidth[0] * daughterwidth[0] +  << 181     if (maxDev < -0.9*rangeMass ){
163       // check parent mass and daughter mass   << 182 #ifdef G4VERBOSE
164       G4double maxDev =                        << 183       if (GetVerboseLevel()>0) {
165         (parentmass - daughtermass[0] - daught << 184   G4cout << "G4PhaseSpaceDecayChannel::TwoBodyDecayIt " 
166       if (maxDev <= -1.0 * rangeMass) {        << 185          << "sum of daughter mass is larger than parent mass" << G4endl;
167 #ifdef G4VERBOSE                               << 186   G4cout << "parent :" << G4MT_parent->GetParticleName() << "  " << current_parent_mass/GeV << G4endl;
168         if (GetVerboseLevel() > 0) {           << 187   G4cout << "daughter 1 :" << G4MT_daughters[0]->GetParticleName() << "  " << daughtermass[0]/GeV << G4endl;
169           G4cout << "G4PhaseSpaceDecayChannel: << 188   G4cout << "daughter 2:" << G4MT_daughters[1]->GetParticleName() << "  " << daughtermass[1]/GeV << G4endl;
170                  << "Sum of daughter mass is l << 189       }
171           G4cout << "Parent :" << G4MT_parent- << 190 #endif
172                  << current_parent_mass.Get()  << 191       G4Exception("G4PhaseSpaceDecayChannel::TwoBodyDecayIt",
173           G4cout << "Daughter 1 :" << G4MT_dau << 192       "PART112", JustWarning,
174                  << daughtermass[0] / GeV << G << 193                 "Can not create decay products: sum of daughter mass is larger than parent mass");
175           G4cout << "Daughter 2:" << G4MT_daug << 194       return products;
176                  << daughtermass[1] / GeV << G << 195     }
177         }                                      << 196     G4double dm1= DynamicalMass(daughtermass[0],daughterwidth[0], maxDev);
178 #endif                                         << 197     G4double dm2= DynamicalMass(daughtermass[1],daughterwidth[1], maxDev);
179         G4Exception("G4PhaseSpaceDecayChannel: << 198     while (dm1+dm2>parentmass){
180                     "Cannot create decay produ << 199       dm1= DynamicalMass(daughtermass[0],daughterwidth[0], maxDev);
181                      larger than parent mass!" << 200       dm2= DynamicalMass(daughtermass[1],daughterwidth[1], maxDev);
182         return products;                       << 201     }
183       }                                        << 202     daughtermass[0] = dm1;
184       G4double dm1 = daughtermass[0];          << 203     daughtermass[1] = dm2;
185       if (daughterwidth[0] > 0.) dm1 = Dynamic << 204   } else {
186       G4double dm2 = daughtermass[1];          << 205     if (parentmass < daughtermass[0] + daughtermass[1] ){
187       if (daughterwidth[1] > 0.) dm2 = Dynamic << 206 #ifdef G4VERBOSE
188       while (dm1 + dm2 > parentmass)  // Loop  << 207       if (GetVerboseLevel()>0) {
189       {                                        << 208   G4cout << "G4PhaseSpaceDecayChannel::TwoBodyDecayIt " 
190         dm1 = DynamicalMass(daughtermass[0], d << 209          << "sum of daughter mass is larger than parent mass" << G4endl;
191         dm2 = DynamicalMass(daughtermass[1], d << 210   G4cout << "parent :" << G4MT_parent->GetParticleName() << "  " << current_parent_mass/GeV << G4endl;
192       }                                        << 211   G4cout << "daughter 1 :" << G4MT_daughters[0]->GetParticleName() << "  " << daughtermass[0]/GeV << G4endl;
193       daughtermass[0] = dm1;                   << 212   G4cout << "daughter 2:" << G4MT_daughters[1]->GetParticleName() << "  " << daughtermass[1]/GeV << G4endl;
194       daughtermass[1] = dm2;                   << 213       }
195     }                                          << 214 #endif
196   }                                            << 215       G4Exception("G4PhaseSpaceDecayChannel::TwoBodyDecayIt",
197   else {                                       << 216       "PART112", JustWarning,
198     // use given daughter mass;                << 217       "Can not create decay products: sum of daughter mass is larger than parent mass");
199     daughtermass[0] = givenDaughterMasses[0];  << 218       return products;
200     daughtermass[1] = givenDaughterMasses[1];  << 219     }  
201   }                                            << 220   }
202   if (parentmass < daughtermass[0] + daughterm << 221 
203 #ifdef G4VERBOSE                               << 222   //calculate daughter momentum
204     if (GetVerboseLevel() > 0) {               << 223   daughtermomentum = Pmx(parentmass,daughtermass[0],daughtermass[1]);
205       G4cout << "G4PhaseSpaceDecayChannel::Two << 224 
206              << "Sum of daughter mass is large << 225   G4double costheta = 2.*G4UniformRand()-1.0;
207       G4cout << "Parent :" << G4MT_parent->Get << 226   G4double sintheta = std::sqrt((1.0 - costheta)*(1.0 + costheta));
208              << current_parent_mass.Get() / Ge << 227   G4double phi  = twopi*G4UniformRand()*rad;
209       G4cout << "Daughter 1 :" << G4MT_daughte << 228   G4ThreeVector direction(sintheta*std::cos(phi),sintheta*std::sin(phi),costheta);
210              << daughtermass[0] / GeV << G4end << 229 
211       G4cout << "Daughter 2:" << G4MT_daughter << 230   //create daughter G4DynamicParticle 
212              << daughtermass[1] / GeV << G4end << 231   G4double Ekin = std::sqrt(daughtermomentum*daughtermomentum + daughtermass[0]*daughtermass[0]) - daughtermass[0];
213       if (useGivenDaughterMass) {              << 232   G4DynamicParticle * daughterparticle = new G4DynamicParticle( G4MT_daughters[0], direction, Ekin, daughtermass[0]);
214         G4cout << "Daughter Mass is given." << << 
215       }                                        << 
216     }                                          << 
217 #endif                                         << 
218     G4Exception("G4PhaseSpaceDecayChannel::Two << 
219                 "Cannot create decay products: << 
220                  larger than parent mass!");   << 
221     return products;                           << 
222   }                                            << 
223                                                << 
224   // calculate daughter momentum               << 
225   G4double daughtermomentum = Pmx(parentmass,  << 
226                                                << 
227   G4double costheta = 2. * G4UniformRand() - 1 << 
228   G4double sintheta = std::sqrt((1.0 - costhet << 
229   G4double phi = twopi * G4UniformRand() * rad << 
230   G4ThreeVector direction(sintheta * std::cos( << 
231                                                << 
232   // create daughter G4DynamicParticle         << 
233   G4double Ekin = std::sqrt(daughtermomentum * << 
234                   - daughtermass[0];           << 
235   auto daughterparticle =                      << 
236     new G4DynamicParticle(G4MT_daughters[0], d << 
237   products->PushProducts(daughterparticle);       233   products->PushProducts(daughterparticle);
238   Ekin = std::sqrt(daughtermomentum * daughter << 234   Ekin = std::sqrt(daughtermomentum*daughtermomentum + daughtermass[1]*daughtermass[1]) - daughtermass[1];
239          - daughtermass[1];                    << 235   daughterparticle = new G4DynamicParticle( G4MT_daughters[1], -1.0*direction, Ekin, daughtermass[1]);
240   daughterparticle =                           << 
241     new G4DynamicParticle(G4MT_daughters[1], - << 
242   products->PushProducts(daughterparticle);       236   products->PushProducts(daughterparticle);
243                                                   237 
244 #ifdef G4VERBOSE                                  238 #ifdef G4VERBOSE
245   if (GetVerboseLevel() > 1) {                 << 239   if (GetVerboseLevel()>1) {
246     G4cout << "G4PhaseSpaceDecayChannel::TwoBo << 240      G4cout << "G4PhaseSpaceDecayChannel::TwoBodyDecayIt ";
247     G4cout << " Create decay products in rest  << 241      G4cout << "  create decay products in rest frame " <<G4endl;
248     products->DumpInfo();                      << 242      products->DumpInfo();
249   }                                               243   }
250 #endif                                            244 #endif
251   return products;                                245   return products;
252 }                                                 246 }
253                                                   247 
254 G4DecayProducts* G4PhaseSpaceDecayChannel::Thr << 248 G4DecayProducts *G4PhaseSpaceDecayChannel::ThreeBodyDecayIt()
                                                   >> 249 // algorism of this code is originally written in GDECA3 of GEANT3
255 {                                                 250 {
256   // Algorithm of this code originally written << 
257                                                << 
258 #ifdef G4VERBOSE                                  251 #ifdef G4VERBOSE
259   if (GetVerboseLevel() > 1) G4cout << "G4Phas << 252   if (GetVerboseLevel()>1) G4cout << "G4PhaseSpaceDecayChannel::ThreeBodyDecayIt()"<<G4endl;
260 #endif                                            253 #endif
261   // parent mass                                  254   // parent mass
262   G4double parentmass = current_parent_mass.Ge << 255   G4double parentmass = current_parent_mass;
263   // daughters'mass                            << 256   //daughters'mass
264   G4double daughtermass[3], daughterwidth[3];  << 257   G4double daughtermass[3], daughterwidth[3]; 
265   G4double sumofdaughtermass = 0.0;               258   G4double sumofdaughtermass = 0.0;
266   G4double sumofdaughterwidthsq = 0.0;            259   G4double sumofdaughterwidthsq = 0.0;
267   G4bool withWidth = false;                    << 260   G4bool withWidth = false; 
268   for (G4int index = 0; index < 3; ++index) {  << 261   for (G4int index=0; index<3; index++){
269     daughtermass[index] = G4MT_daughters_mass[    262     daughtermass[index] = G4MT_daughters_mass[index];
270     sumofdaughtermass += daughtermass[index];     263     sumofdaughtermass += daughtermass[index];
271     daughterwidth[index] = G4MT_daughters_widt    264     daughterwidth[index] = G4MT_daughters_width[index];
272     sumofdaughterwidthsq += daughterwidth[inde << 265     sumofdaughterwidthsq += daughterwidth[index]*daughterwidth[index];
273     withWidth = withWidth || (daughterwidth[in << 266     withWidth = withWidth ||(daughterwidth[index]>1.0e-3*daughtermass[index]);
274   }                                               267   }
275                                                << 268   
276   // create parent G4DynamicParticle at rest   << 269    //create parent G4DynamicParticle at rest
277   G4ThreeVector dummy;                            270   G4ThreeVector dummy;
278   auto parentparticle = new G4DynamicParticle( << 271   G4DynamicParticle * parentparticle = new G4DynamicParticle( G4MT_parent, dummy, 0.0, parentmass);
279                                                   272 
280   // create G4Decayproducts                    << 273 
281   auto products = new G4DecayProducts(*parentp << 274   //create G4Decayproducts
                                                   >> 275   G4DecayProducts *products = new G4DecayProducts(*parentparticle);
282   delete parentparticle;                          276   delete parentparticle;
283                                                   277 
284   if (!useGivenDaughterMass) {                 << 278   if (withWidth){
285     if (withWidth) {                           << 279     G4double maxDev = (parentmass - sumofdaughtermass )/std::sqrt(sumofdaughterwidthsq) ;
286       G4double maxDev = (parentmass - sumofdau << 280     if (maxDev < -0.9*rangeMass ){
287       if (maxDev <= -1.0 * rangeMass) {        << 281 #ifdef G4VERBOSE
288 #ifdef G4VERBOSE                               << 282       if (GetVerboseLevel()>0) {
289         if (GetVerboseLevel() > 0) {           << 283   G4cout << "G4PhaseSpaceDecayChannel::ThreeBodyDecayIt " 
290           G4cout << "G4PhaseSpaceDecayChannel: << 284          << "sum of daughter mass is larger than parent mass" << G4endl;
291                  << "Sum of daughter mass is l << 285   G4cout << "parent :" << G4MT_parent->GetParticleName() << "  " << current_parent_mass/GeV << G4endl;
292           G4cout << "Parent :" << G4MT_parent- << 286   G4cout << "daughter 1 :" << G4MT_daughters[0]->GetParticleName() << "  " << daughtermass[0]/GeV << G4endl;
293                  << current_parent_mass.Get()  << 287   G4cout << "daughter 2:" << G4MT_daughters[1]->GetParticleName() << "  " << daughtermass[1]/GeV << G4endl;
294           G4cout << "Daughter 1 :" << G4MT_dau << 288   G4cout << "daughter 3:" << G4MT_daughters[2]->GetParticleName() << "  " << daughtermass[2]/GeV << G4endl;
295                  << daughtermass[0] / GeV << G << 289       }
296           G4cout << "Daughter 2:" << G4MT_daug << 290 #endif
297                  << daughtermass[1] / GeV << G << 291       G4Exception("G4PhaseSpaceDecayChannel::ThreeBodyDecayIt",
298           G4cout << "Daughter 3:" << G4MT_daug << 292       "PART112", JustWarning,
299                  << daughtermass[2] / GeV << G << 293       "Can not create decay products: sum of daughter mass is larger than parent mass");
300         }                                      << 294       return products;
301 #endif                                         << 295     }
302         G4Exception("G4PhaseSpaceDecayChannel: << 296     G4double dm1= DynamicalMass(daughtermass[0],daughterwidth[0], maxDev);
303                     "Cannot create decay produ << 297     G4double dm2= DynamicalMass(daughtermass[1],daughterwidth[1], maxDev);
304                      is larger than parent mas << 298     G4double dm3= DynamicalMass(daughtermass[2],daughterwidth[2], maxDev);
305         return products;                       << 299     while (dm1+dm2+dm3>parentmass){
306       }                                        << 300       dm1= DynamicalMass(daughtermass[0],daughterwidth[0], maxDev);
307       G4double dm1 = daughtermass[0];          << 301       dm2= DynamicalMass(daughtermass[1],daughterwidth[1], maxDev);
308       if (daughterwidth[0] > 0.) dm1 = Dynamic << 302       dm3= DynamicalMass(daughtermass[2],daughterwidth[2], maxDev);
309       G4double dm2 = daughtermass[1];          << 303     }
310       if (daughterwidth[1] > 0.) dm2 = Dynamic << 304     daughtermass[0] = dm1;
311       G4double dm3 = daughtermass[2];          << 305     daughtermass[1] = dm2;
312       if (daughterwidth[2] > 0.) dm3 = Dynamic << 306     daughtermass[2] = dm3;
313       while (dm1 + dm2 + dm3 > parentmass)  // << 307 
314       {                                        << 308   } else {
315         dm1 = DynamicalMass(daughtermass[0], d << 309     if (sumofdaughtermass >parentmass) {
316         dm2 = DynamicalMass(daughtermass[1], d << 310 #ifdef G4VERBOSE
317         dm3 = DynamicalMass(daughtermass[2], d << 311       if (GetVerboseLevel()>0) {
318       }                                        << 312   G4cout << "G4PhaseSpaceDecayChannel::ThreeBodyDecayIt " 
319       daughtermass[0] = dm1;                   << 313          << "sum of daughter mass is larger than parent mass" << G4endl;
320       daughtermass[1] = dm2;                   << 314   G4cout << "parent :" << G4MT_parent->GetParticleName() << "  " << current_parent_mass/GeV << G4endl;
321       daughtermass[2] = dm3;                   << 315   G4cout << "daughter 1 :" << G4MT_daughters[0]->GetParticleName() << "  " << daughtermass[0]/GeV << G4endl;
322       sumofdaughtermass = dm1 + dm2 + dm3;     << 316   G4cout << "daughter 2:" << G4MT_daughters[1]->GetParticleName() << "  " << daughtermass[1]/GeV << G4endl;
323     }                                          << 317   G4cout << "daughter 3:" << G4MT_daughters[2]->GetParticleName() << "  " << daughtermass[2]/GeV << G4endl;
324   }                                            << 318   }
325   else {                                       << 319 #endif
326     // use given daughter mass;                << 320       G4Exception("G4PhaseSpaceDecayChannel::ThreeBodyDecayIt",
327     daughtermass[0] = givenDaughterMasses[0];  << 321       "PART112", JustWarning,
328     daughtermass[1] = givenDaughterMasses[1];  << 322       "Can not create decay products: sum of daughter mass is larger than parent mass");
329     daughtermass[2] = givenDaughterMasses[2];  << 323       return products;
330     sumofdaughtermass = daughtermass[0] + daug << 324     }
331   }                                            << 
332                                                << 
333   if (sumofdaughtermass > parentmass) {        << 
334 #ifdef G4VERBOSE                               << 
335     if (GetVerboseLevel() > 0) {               << 
336       G4cout << "G4PhaseSpaceDecayChannel::Thr << 
337              << "Sum of daughter mass is large << 
338       G4cout << "Parent :" << G4MT_parent->Get << 
339              << current_parent_mass.Get() / Ge << 
340       G4cout << "Daughter 1 :" << G4MT_daughte << 
341              << daughtermass[0] / GeV << G4end << 
342       G4cout << "Daughter 2:" << G4MT_daughter << 
343              << daughtermass[1] / GeV << G4end << 
344       G4cout << "Daughter 3:" << G4MT_daughter << 
345              << daughtermass[2] / GeV << G4end << 
346     }                                          << 
347     if (useGivenDaughterMass) {                << 
348       G4cout << "Daughter Mass is given." << G << 
349     }                                          << 
350 #endif                                         << 
351     G4Exception("G4PhaseSpaceDecayChannel::Thr << 
352                 "Can not create decay products << 
353                  is larger than parent mass!") << 
354     return products;                           << 
355   }                                               325   }
356                                                   326 
357   // calculate daughter momentum               << 327 
358   // Generate two                              << 328 
                                                   >> 329   //calculate daughter momentum
                                                   >> 330   //  Generate two 
359   G4double rd1, rd2, rd;                          331   G4double rd1, rd2, rd;
360   G4double daughtermomentum[3];                   332   G4double daughtermomentum[3];
361   G4double momentummax = 0.0, momentumsum = 0. << 333   G4double momentummax=0.0, momentumsum = 0.0;
362   G4double energy;                                334   G4double energy;
363   const std::size_t MAX_LOOP = 10000;          << 
364                                                   335 
365   for (std::size_t loop_counter = 0; loop_coun << 336   do {
366     rd1 = G4UniformRand();                        337     rd1 = G4UniformRand();
367     rd2 = G4UniformRand();                        338     rd2 = G4UniformRand();
368     if (rd2 > rd1) {                              339     if (rd2 > rd1) {
369       rd = rd1;                                << 340       rd  = rd1;
370       rd1 = rd2;                                  341       rd1 = rd2;
371       rd2 = rd;                                   342       rd2 = rd;
372     }                                          << 343     } 
373     momentummax = 0.0;                            344     momentummax = 0.0;
374     momentumsum = 0.0;                            345     momentumsum = 0.0;
375     // daughter 0                                 346     // daughter 0
376     energy = rd2 * (parentmass - sumofdaughter << 347     energy = rd2*(parentmass - sumofdaughtermass);
377     daughtermomentum[0] = std::sqrt(energy * e << 348     daughtermomentum[0] = std::sqrt(energy*energy + 2.0*energy* daughtermass[0]);
378     if (daughtermomentum[0] > momentummax) mom << 349     if ( daughtermomentum[0] >momentummax )momentummax =  daughtermomentum[0];
379     momentumsum += daughtermomentum[0];        << 350     momentumsum  +=  daughtermomentum[0];
380     // daughter 1                                 351     // daughter 1
381     energy = (1. - rd1) * (parentmass - sumofd << 352     energy = (1.-rd1)*(parentmass - sumofdaughtermass);
382     daughtermomentum[1] = std::sqrt(energy * e << 353     daughtermomentum[1] = std::sqrt(energy*energy + 2.0*energy* daughtermass[1]);
383     if (daughtermomentum[1] > momentummax) mom << 354     if ( daughtermomentum[1] >momentummax )momentummax =  daughtermomentum[1];
384     momentumsum += daughtermomentum[1];        << 355     momentumsum  +=  daughtermomentum[1];
385     // daughter 2                                 356     // daughter 2
386     energy = (rd1 - rd2) * (parentmass - sumof << 357     energy = (rd1-rd2)*(parentmass - sumofdaughtermass);
387     daughtermomentum[2] = std::sqrt(energy * e << 358     daughtermomentum[2] = std::sqrt(energy*energy + 2.0*energy* daughtermass[2]);
388     if (daughtermomentum[2] > momentummax) mom << 359     if ( daughtermomentum[2] >momentummax )momentummax =  daughtermomentum[2];
389     momentumsum += daughtermomentum[2];        << 360     momentumsum  +=  daughtermomentum[2];
390     if (momentummax <= momentumsum - momentumm << 361   } while (momentummax >  momentumsum - momentummax );
391   }                                            << 
392                                                << 
393   // output message                               362   // output message
394 #ifdef G4VERBOSE                                  363 #ifdef G4VERBOSE
395   if (GetVerboseLevel() > 1) {                 << 364   if (GetVerboseLevel()>1) {
396     G4cout << "     daughter 0:" << daughtermo << 365     G4cout << "     daughter 0:" << daughtermomentum[0]/GeV << "[GeV/c]" <<G4endl;
397     G4cout << "     daughter 1:" << daughtermo << 366     G4cout << "     daughter 1:" << daughtermomentum[1]/GeV << "[GeV/c]" <<G4endl;
398     G4cout << "     daughter 2:" << daughtermo << 367     G4cout << "     daughter 2:" << daughtermomentum[2]/GeV << "[GeV/c]" <<G4endl;
399     G4cout << "   momentum sum:" << momentumsu << 368     G4cout << "   momentum sum:" << momentumsum/GeV << "[GeV/c]" <<G4endl;
400   }                                               369   }
401 #endif                                            370 #endif
402                                                   371 
403   // create daughter G4DynamicParticle         << 372   //create daughter G4DynamicParticle 
404   G4double costheta, sintheta, phi, sinphi, co << 373   G4double costheta, sintheta, phi, sinphi, cosphi; 
405   G4double costhetan, sinthetan, phin, sinphin << 374   G4double costhetan, sinthetan, phin, sinphin, cosphin; 
406   costheta = 2. * G4UniformRand() - 1.0;       << 375   costheta = 2.*G4UniformRand()-1.0;
407   sintheta = std::sqrt((1.0 - costheta) * (1.0 << 376   sintheta = std::sqrt((1.0-costheta)*(1.0+costheta));
408   phi = twopi * G4UniformRand() * rad;         << 377   phi  = twopi*G4UniformRand()*rad;
409   sinphi = std::sin(phi);                         378   sinphi = std::sin(phi);
410   cosphi = std::cos(phi);                         379   cosphi = std::cos(phi);
411                                                   380 
412   G4ThreeVector direction0(sintheta * cosphi,  << 381   G4ThreeVector direction0(sintheta*cosphi,sintheta*sinphi,costheta);
413   G4double Ekin =                              << 382   G4double Ekin = std::sqrt(daughtermomentum[0]*daughtermomentum[0] + daughtermass[0]*daughtermass[0]) - daughtermass[0];
414     std::sqrt(daughtermomentum[0] * daughtermo << 383   G4DynamicParticle * daughterparticle = new G4DynamicParticle( G4MT_daughters[0], 
415     - daughtermass[0];                         << 384                 direction0, 
416   auto daughterparticle =                      << 385                 Ekin, daughtermass[0]);
417     new G4DynamicParticle(G4MT_daughters[0], d << 
418   products->PushProducts(daughterparticle);       386   products->PushProducts(daughterparticle);
419                                                   387 
420   costhetan = (daughtermomentum[1] * daughterm << 388   costhetan = (daughtermomentum[1]*daughtermomentum[1]-daughtermomentum[2]*daughtermomentum[2]-daughtermomentum[0]*daughtermomentum[0])/(2.0*daughtermomentum[2]*daughtermomentum[0]);
421                - daughtermomentum[0] * daughte << 389   sinthetan = std::sqrt((1.0-costhetan)*(1.0+costhetan));
422               / (2.0 * daughtermomentum[2] * d << 390   phin  = twopi*G4UniformRand()*rad;
423   sinthetan = std::sqrt((1.0 - costhetan) * (1 << 
424   phin = twopi * G4UniformRand() * rad;        << 
425   sinphin = std::sin(phin);                       391   sinphin = std::sin(phin);
426   cosphin = std::cos(phin);                       392   cosphin = std::cos(phin);
427   G4ThreeVector direction2;                       393   G4ThreeVector direction2;
428   direction2.setX(sinthetan * cosphin * costhe << 394   direction2.setX( sinthetan*cosphin*costheta*cosphi - sinthetan*sinphin*sinphi + costhetan*sintheta*cosphi); 
429                   + costhetan * sintheta * cos << 395   direction2.setY( sinthetan*cosphin*costheta*sinphi + sinthetan*sinphin*cosphi + costhetan*sintheta*sinphi); 
430   direction2.setY(sinthetan * cosphin * costhe << 396   direction2.setZ( -sinthetan*cosphin*sintheta + costhetan*costheta);
431                   + costhetan * sintheta * sin << 397   G4ThreeVector pmom = daughtermomentum[2]*direction2/direction2.mag();
432   direction2.setZ(-sinthetan * cosphin * sinth << 398   Ekin = std::sqrt(pmom.mag2() + daughtermass[2]*daughtermass[2]) - daughtermass[2];
433   G4ThreeVector pmom = daughtermomentum[2] * d << 399   daughterparticle = new G4DynamicParticle( G4MT_daughters[2], 
434   Ekin = std::sqrt(pmom.mag2() + daughtermass[ << 400               pmom/pmom.mag(),
435   daughterparticle =                           << 401               Ekin, daughtermass[2]);
436     new G4DynamicParticle(G4MT_daughters[2], p << 
437   products->PushProducts(daughterparticle);       402   products->PushProducts(daughterparticle);
438                                                   403 
439   pmom = (direction0 * daughtermomentum[0] + d << 404   pmom = (direction0*daughtermomentum[0] + direction2*(daughtermomentum[2]/direction2.mag()))*(-1.0);
440          * (-1.0);                             << 405   Ekin = std::sqrt(pmom.mag2() + daughtermass[1]*daughtermass[1]) - daughtermass[1];
441   Ekin = std::sqrt(pmom.mag2() + daughtermass[ << 406   daughterparticle = new G4DynamicParticle( 
442   daughterparticle =                           << 407              G4MT_daughters[1],
443     new G4DynamicParticle(G4MT_daughters[1], p << 408              pmom/pmom.mag(),
                                                   >> 409              Ekin, daughtermass[1]);
444   products->PushProducts(daughterparticle);       410   products->PushProducts(daughterparticle);
445                                                << 411   
446 #ifdef G4VERBOSE                                  412 #ifdef G4VERBOSE
447   if (GetVerboseLevel() > 1) {                 << 413   if (GetVerboseLevel()>1) {
448     G4cout << "G4PhaseSpaceDecayChannel::Three << 414      G4cout << "G4PhaseSpaceDecayChannel::ThreeBodyDecayIt ";
449     G4cout << " create decay products in rest  << 415      G4cout << "  create decay products in rest frame " <<G4endl;
450     products->DumpInfo();                      << 416      products->DumpInfo();
451   }                                               417   }
452 #endif                                            418 #endif
453   return products;                                419   return products;
454 }                                                 420 }
455                                                   421 
456 G4DecayProducts* G4PhaseSpaceDecayChannel::Man << 422 G4DecayProducts *G4PhaseSpaceDecayChannel::ManyBodyDecayIt()
                                                   >> 423 // algorithm of this code is originally written in FORTRAN by M.Asai
                                                   >> 424 //******************************************************************
                                                   >> 425 //  NBODY
                                                   >> 426 //   N-body phase space Monte-Carlo generator
                                                   >> 427 //  Makoto Asai 
                                                   >> 428 //   Hiroshima Institute of Technology
                                                   >> 429 //    (asai@kekvax.kek.jp)
                                                   >> 430 //  Revised release : 19/Apr/1995
                                                   >> 431 //
457 {                                                 432 {
458   // Algorithm of this code originally written << 
459   // ***************************************** << 
460   // NBODY - N-body phase space Monte-Carlo ge << 
461   // Makoto Asai - Hiroshima Institute of Tech << 
462   // Revised release : 19/Apr/1995             << 
463                                                << 
464   G4int index, index2;                            433   G4int index, index2;
465                                                   434 
                                                   >> 435   //return value
                                                   >> 436   G4DecayProducts *products;
                                                   >> 437 
466 #ifdef G4VERBOSE                                  438 #ifdef G4VERBOSE
467   if (GetVerboseLevel() > 1) G4cout << "G4Phas << 439   if (GetVerboseLevel()>1) G4cout << "G4PhaseSpaceDecayChannel::ManyBodyDecayIt()"<<G4endl;
468 #endif                                            440 #endif
469                                                << 
470   // parent mass                                  441   // parent mass
471   G4double parentmass = current_parent_mass.Ge << 442   G4double parentmass = current_parent_mass;
472                                                << 443   //daughters'mass
473   // parent particle                           << 444   G4double *daughtermass = new G4double[numberOfDaughters]; 
474   G4ThreeVector dummy;                         << 
475   auto parentparticle = new G4DynamicParticle( << 
476                                                << 
477   // create G4Decayproducts                    << 
478   auto products = new G4DecayProducts(*parentp << 
479   delete parentparticle;                       << 
480                                                << 
481   // daughters'mass                            << 
482   auto daughtermass = new G4double[numberOfDau << 
483                                                << 
484   G4double sumofdaughtermass = 0.0;               445   G4double sumofdaughtermass = 0.0;
485   for (index = 0; index < numberOfDaughters; + << 446   for (index=0; index<numberOfDaughters; index++){
486     if (!useGivenDaughterMass) {               << 447     daughtermass[index] = G4MT_daughters_mass[index];
487       daughtermass[index] = G4MT_daughters_mas << 
488     }                                          << 
489     else {                                     << 
490       daughtermass[index] = givenDaughterMasse << 
491     }                                          << 
492     sumofdaughtermass += daughtermass[index];     448     sumofdaughtermass += daughtermass[index];
493   }                                               449   }
494   if (sumofdaughtermass > parentmass) {        << 450   
495 #ifdef G4VERBOSE                               << 451   //Calculate daughter momentum
496     if (GetVerboseLevel() > 0) {               << 452   G4double *daughtermomentum = new G4double[numberOfDaughters];
497       G4cout << "G4PhaseSpaceDecayChannel::Man << 453   G4ThreeVector direction;  
498              << "Sum of daughter mass is large << 454   G4DynamicParticle **daughterparticle;
499       G4cout << "Parent :" << G4MT_parent->Get << 455   G4double *sm = new G4double[numberOfDaughters];
500              << current_parent_mass.Get() / Ge << 
501       G4cout << "Daughter 1 :" << G4MT_daughte << 
502              << daughtermass[0] / GeV << G4end << 
503       G4cout << "Daughter 2:" << G4MT_daughter << 
504              << daughtermass[1] / GeV << G4end << 
505       G4cout << "Daughter 3:" << G4MT_daughter << 
506              << daughtermass[2] / GeV << G4end << 
507       G4cout << "Daughter 4:" << G4MT_daughter << 
508              << daughtermass[3] / GeV << G4end << 
509       G4cout << "Daughter 5:" << G4MT_daughter << 
510              << daughtermass[4] / GeV << G4end << 
511     }                                          << 
512 #endif                                         << 
513     G4Exception("G4PhaseSpaceDecayChannel::Man << 
514                 "Can not create decay products << 
515                  is larger than parent mass!") << 
516     delete[] daughtermass;                     << 
517     return products;                           << 
518   }                                            << 
519                                                << 
520   // Calculate daughter momentum               << 
521   auto daughtermomentum = new G4double[numberO << 
522   G4ThreeVector direction;                     << 
523   G4DynamicParticle** daughterparticle;        << 
524   auto sm = new G4double[numberOfDaughters];   << 
525   G4double tmas;                                  456   G4double tmas;
526   G4double weight = 1.0;                          457   G4double weight = 1.0;
527   G4int numberOfTry = 0;                       << 458   G4int    numberOfTry = 0;
528   const std::size_t MAX_LOOP = 10000;          << 459  
529                                                << 460   do {
530   for (std::size_t loop_counter = 0; loop_coun << 461     //Generate rundom number in descending order 
531     // Generate rundom number in descending or << 
532     G4double temp;                                462     G4double temp;
533     auto rd = new G4double[numberOfDaughters]; << 463     G4double *rd = new G4double[numberOfDaughters];
534     rd[0] = 1.0;                                  464     rd[0] = 1.0;
535     for (index = 1; index < numberOfDaughters  << 465     for(index =1; index < numberOfDaughters -1; index++) rd[index] = G4UniformRand(); 
536       rd[index] = G4UniformRand();             << 466     rd[ numberOfDaughters -1] = 0.0;
537     }                                          << 467     for(index =1; index < numberOfDaughters -1; index++) {
538     rd[numberOfDaughters - 1] = 0.0;           << 468       for(index2 = index+1; index2 < numberOfDaughters; index2++) {
539     for (index = 1; index < numberOfDaughters  << 469         if (rd[index] < rd[index2]){
540       for (index2 = index + 1; index2 < number << 470           temp        = rd[index];
541         if (rd[index] < rd[index2]) {          << 471           rd[index]  = rd[index2];
542           temp = rd[index];                    << 
543           rd[index] = rd[index2];              << 
544           rd[index2] = temp;                      472           rd[index2] = temp;
545         }                                         473         }
546       }                                           474       }
547     }                                             475     }
548                                                << 476     
549     // calculate virtual mass                  << 477     //calcurate virtual mass 
550     tmas = parentmass - sumofdaughtermass;     << 478     tmas = parentmass -  sumofdaughtermass;
551     temp = sumofdaughtermass;                  << 479     temp =  sumofdaughtermass; 
552     for (index = 0; index < numberOfDaughters; << 480     for(index =0; index < numberOfDaughters; index++) {
553       sm[index] = rd[index] * tmas + temp;     << 481       sm[index] = rd[index]*tmas + temp;
554       temp -= daughtermass[index];                482       temp -= daughtermass[index];
555       if (GetVerboseLevel() > 1) {             << 483       if (GetVerboseLevel()>1) {
556         G4cout << index << "  rundom number:"  << 484         G4cout << index << "  rundom number:" << rd[index]; 
557         G4cout << "   virtual mass:" << sm[ind << 485         G4cout << "   virtual mass:" << sm[index]/GeV << "[GeV/c/c]" <<G4endl; 
558       }                                           486       }
559     }                                             487     }
560     delete[] rd;                               << 488     delete [] rd;
561                                                   489 
562     // Calculate daughter momentum             << 490     //Calculate daughter momentum
563     weight = 1.0;                                 491     weight = 1.0;
564     G4bool smOK = true;                        << 492     index =numberOfDaughters-1;
565     for (index = 0; index < numberOfDaughters  << 493     daughtermomentum[index]= Pmx( sm[index-1],daughtermass[index-1], sm[index]);
566       smOK = (sm[index] - daughtermass[index]  << 
567     }                                          << 
568     if (!smOK) continue;                       << 
569                                                << 
570     index = numberOfDaughters - 1;             << 
571     daughtermomentum[index] = Pmx(sm[index - 1 << 
572 #ifdef G4VERBOSE                                  494 #ifdef G4VERBOSE
573     if (GetVerboseLevel() > 1) {               << 495     if (GetVerboseLevel()>1) {
574       G4cout << "     daughter " << index << "    496       G4cout << "     daughter " << index << ":" << *daughters_name[index];
575       G4cout << " momentum:" << daughtermoment << 497       G4cout << " momentum:" << daughtermomentum[index]/GeV << "[GeV/c]" <<G4endl;
576     }                                             498     }
577 #endif                                            499 #endif
578     for (index = numberOfDaughters - 2; index  << 500     for(index =numberOfDaughters-2; index>=0; index--) {
579       // calculate                             << 501       // calculate 
580       daughtermomentum[index] = Pmx(sm[index], << 502       daughtermomentum[index]= Pmx( sm[index],daughtermass[index], sm[index +1]);
581       if (daughtermomentum[index] < 0.0) {     << 503       if(daughtermomentum[index] < 0.0) {
582         // !!! illegal momentum !!!               504         // !!! illegal momentum !!!
583 #ifdef G4VERBOSE                                  505 #ifdef G4VERBOSE
584         if (GetVerboseLevel() > 0) {           << 506         if (GetVerboseLevel()>0) {
585           G4cout << "G4PhaseSpaceDecayChannel: << 507           G4cout << "G4PhaseSpaceDecayChannel::ManyBodyDecayIt ";
586           G4cout << "     Cannot calculate dau << 508           G4cout << "     can not calculate daughter momentum " <<G4endl;
587           G4cout << "     parent:" << *parent_    509           G4cout << "     parent:" << *parent_name;
588           G4cout << " mass:" << parentmass / G << 510           G4cout << " mass:" << parentmass/GeV << "[GeV/c/c]" <<G4endl;
589           G4cout << "     daughter " << index     511           G4cout << "     daughter " << index << ":" << *daughters_name[index];
590           G4cout << " mass:" << daughtermass[i << 512           G4cout << " mass:" << daughtermass[index]/GeV << "[GeV/c/c]" ;
591           G4cout << " mass:" << daughtermoment << 513           G4cout << " mass:" << daughtermomentum[index]/GeV << "[GeV/c]" <<G4endl;
592           if (useGivenDaughterMass) {          << 
593             G4cout << "Daughter Mass is given. << 
594           }                                    << 
595         }                                         514         }
596 #endif                                            515 #endif
597         delete[] sm;                           << 516   delete [] sm;
598         delete[] daughtermass;                 << 517   delete [] daughtermass;
599         delete[] daughtermomentum;             << 518   delete [] daughtermomentum;
600         delete products;                       << 
601         G4Exception("G4PhaseSpaceDecayChannel: << 
602                     "Can not create decay prod << 
603                      is larger than parent mas << 
604         return nullptr;  // Error detection    << 
605       }                                        << 
606                                                   519 
607       // calculate weight of this events       << 520   G4Exception("G4PhaseSpaceDecayChannel::ManyBodyDecayIt",
608       weight *= daughtermomentum[index] / sm[i << 521                 "PART112", JustWarning,
                                                   >> 522                 "Can not create decay products: sum of daughter mass is larger than parent mass");
                                                   >> 523 
                                                   >> 524   return 0;   // Error detection
                                                   >> 525 
                                                   >> 526       } else {
                                                   >> 527   // calculate weight of this events
                                                   >> 528         weight *=  daughtermomentum[index]/sm[index];
609 #ifdef G4VERBOSE                                  529 #ifdef G4VERBOSE
610       if (GetVerboseLevel() > 1) {             << 530         if (GetVerboseLevel()>1) {
611         G4cout << "     daughter " << index << << 531           G4cout << "     daughter " << index << ":" << *daughters_name[index];
612         G4cout << " momentum:" << daughtermome << 532           G4cout << " momentum:" << daughtermomentum[index]/GeV << "[GeV/c]" <<G4endl;
613       }                                        << 533         }
614 #endif                                            534 #endif
                                                   >> 535       }
615     }                                             536     }
616                                                   537 
617 #ifdef G4VERBOSE                                  538 #ifdef G4VERBOSE
618     if (GetVerboseLevel() > 1) {               << 539     if (GetVerboseLevel()>1) {
619       G4cout << "    weight: " << weight << G4 << 540       G4cout << "    weight: " << weight <<G4endl;
620     }                                             541     }
621 #endif                                            542 #endif
622                                                << 543     
623     // exit if number of Try exceeds 100          544     // exit if number of Try exceeds 100
624     if (++numberOfTry > 100) {                 << 545     if (numberOfTry++ >100) {
625 #ifdef G4VERBOSE                                  546 #ifdef G4VERBOSE
626       if (GetVerboseLevel() > 0) {             << 547       if (GetVerboseLevel()>0) {
627         G4cout << "G4PhaseSpaceDecayChannel::M << 548         G4cout << "G4PhaseSpaceDecayChannel::ManyBodyDecayIt: ";
628         G4cout << "Cannot determine Decay Kine << 549   G4cout << " can not determine Decay Kinematics " << G4endl;
629         G4cout << "parent : " << *parent_name  << 550   G4cout << "parent : " << *parent_name << G4endl;
630         G4cout << "daughters : ";              << 551   G4cout << "daughters : "; 
631         for (index = 0; index < numberOfDaught << 552   for(index=0; index<numberOfDaughters; index++) {
632           G4cout << *daughters_name[index] <<  << 553     G4cout <<  *daughters_name[index] << " , ";
633         }                                      << 554   }
634         G4cout << G4endl;                      << 555   G4cout << G4endl;
635       }                                        << 556       }
636 #endif                                         << 557 #endif
637       G4Exception("G4PhaseSpaceDecayChannel::M << 558       G4Exception("G4PhaseSpaceDecayChannel::ManyBodyDecayIt: ",
638                   "Cannot decay: Decay Kinemat << 559                   "PART113", JustWarning,
639                                                << 560       " Cannot decay :  Decay Kinematics cannot be calculated ");
640       delete[] sm;                             << 561       
641       delete[] daughtermass;                   << 562       delete [] sm;
642       delete[] daughtermomentum;               << 563       delete [] daughtermass;
643       delete products;                         << 564       delete [] daughtermomentum;
644       return nullptr;  // Error detection      << 565       return 0;  // Error detection
645     }                                             566     }
646     if (weight < G4UniformRand()) break;       << 567   } while ( weight > G4UniformRand());
647   }                                            << 
648                                                   568 
649 #ifdef G4VERBOSE                                  569 #ifdef G4VERBOSE
650   if (GetVerboseLevel() > 1) {                 << 570   if (GetVerboseLevel()>1) {
651     G4cout << "Start calculation of daughters  << 571       G4cout << "Start calulation of daughters momentum vector "<<G4endl;
652   }                                               572   }
653 #endif                                         << 573 #endif 
654                                                << 574  
655   G4double costheta, sintheta, phi;               575   G4double costheta, sintheta, phi;
656   G4double beta;                                  576   G4double beta;
657   daughterparticle = new G4DynamicParticle*[nu    577   daughterparticle = new G4DynamicParticle*[numberOfDaughters];
658                                                   578 
659   index = numberOfDaughters - 2;               << 579   index = numberOfDaughters -2;
660   costheta = 2. * G4UniformRand() - 1.0;       << 580   costheta = 2.*G4UniformRand()-1.0;
661   sintheta = std::sqrt((1.0 - costheta) * (1.0 << 581   sintheta = std::sqrt((1.0-costheta)*(1.0+costheta));
662   phi = twopi * G4UniformRand() * rad;         << 582   phi  = twopi*G4UniformRand()*rad;
663   direction.setZ(costheta);                       583   direction.setZ(costheta);
664   direction.setY(sintheta * std::sin(phi));    << 584   direction.setY(sintheta*std::sin(phi));
665   direction.setX(sintheta * std::cos(phi));    << 585   direction.setX(sintheta*std::cos(phi));
666   daughterparticle[index] =                    << 586   daughterparticle[index] = new G4DynamicParticle( G4MT_daughters[index], direction*daughtermomentum[index] );
667     new G4DynamicParticle(G4MT_daughters[index << 587   daughterparticle[index+1] = new G4DynamicParticle( G4MT_daughters[index+1], direction*(-1.0*daughtermomentum[index]) );
668   daughterparticle[index + 1] =                << 588 
669     new G4DynamicParticle(G4MT_daughters[index << 589   for (index = numberOfDaughters -3;  index >= 0; index--) {
670                                                << 590     //calculate momentum direction
671   for (index = numberOfDaughters - 3; index >= << 591     costheta = 2.*G4UniformRand()-1.0;
672     // calculate momentum direction            << 592     sintheta = std::sqrt((1.0-costheta)*(1.0+costheta));
673     costheta = 2. * G4UniformRand() - 1.0;     << 593     phi  = twopi*G4UniformRand()*rad;
674     sintheta = std::sqrt((1.0 - costheta) * (1 << 
675     phi = twopi * G4UniformRand() * rad;       << 
676     direction.setZ(costheta);                     594     direction.setZ(costheta);
677     direction.setY(sintheta * std::sin(phi));  << 595     direction.setY(sintheta*std::sin(phi));
678     direction.setX(sintheta * std::cos(phi));  << 596     direction.setX(sintheta*std::cos(phi));
679                                                   597 
680     // boost already created particles         << 598     // boost already created particles 
681     beta = daughtermomentum[index];               599     beta = daughtermomentum[index];
682     beta /=                                    << 600     beta /= std::sqrt( daughtermomentum[index]*daughtermomentum[index] + sm[index+1]*sm[index+1] );
683       std::sqrt(daughtermomentum[index] * daug << 601     for (index2 = index+1; index2<numberOfDaughters; index2++) {
684     for (index2 = index + 1; index2 < numberOf << 
685       G4LorentzVector p4;                         602       G4LorentzVector p4;
686       // make G4LorentzVector for secondaries     603       // make G4LorentzVector for secondaries
687       p4 = daughterparticle[index2]->Get4Momen    604       p4 = daughterparticle[index2]->Get4Momentum();
688                                                   605 
689       // boost secondaries to  new frame       << 606       // boost secondaries to  new frame 
690       p4.boost(direction.x() * beta, direction << 607       p4.boost( direction.x()*beta, direction.y()*beta, direction.z()*beta);
691                                                   608 
692       // change energy/momentum                   609       // change energy/momentum
693       daughterparticle[index2]->Set4Momentum(p    610       daughterparticle[index2]->Set4Momentum(p4);
694     }                                             611     }
695     // create daughter G4DynamicParticle       << 612     //create daughter G4DynamicParticle 
696     daughterparticle[index] =                  << 613     daughterparticle[index]= new G4DynamicParticle( G4MT_daughters[index], direction*(-1.0*daughtermomentum[index]));
697       new G4DynamicParticle(G4MT_daughters[ind << 
698   }                                               614   }
699                                                   615 
700   // add daughters to G4Decayproducts          << 616   //create G4Decayproducts
701   for (index = 0; index < numberOfDaughters; + << 617   G4DynamicParticle *parentparticle; 
                                                   >> 618   direction.setX(1.0);  direction.setY(0.0); direction.setZ(0.0);
                                                   >> 619   parentparticle = new G4DynamicParticle( G4MT_parent, direction, 0.0, parentmass);
                                                   >> 620   products = new G4DecayProducts(*parentparticle);
                                                   >> 621   delete parentparticle;
                                                   >> 622   for (index = 0; index<numberOfDaughters; index++) {
702     products->PushProducts(daughterparticle[in    623     products->PushProducts(daughterparticle[index]);
703   }                                               624   }
704                                                   625 
705 #ifdef G4VERBOSE                                  626 #ifdef G4VERBOSE
706   if (GetVerboseLevel() > 1) {                 << 627   if (GetVerboseLevel()>1) { 
707     G4cout << "G4PhaseSpaceDecayChannel::ManyB << 628     G4cout << "G4PhaseSpaceDecayChannel::ManyBodyDecayIt ";
708     G4cout << " create decay products in rest  << 629     G4cout << "  create decay products in rest frame " << G4endl;
709     products->DumpInfo();                         630     products->DumpInfo();
710   }                                               631   }
711 #endif                                            632 #endif
712                                                   633 
713   delete[] daughterparticle;                   << 634   delete [] daughterparticle;
714   delete[] daughtermomentum;                   << 635   delete [] daughtermomentum;
715   delete[] daughtermass;                       << 636   delete [] daughtermass;
716   delete[] sm;                                 << 637   delete [] sm;
717                                                << 638   
718   return products;                                639   return products;
719 }                                                 640 }
720                                                   641 
721 G4bool G4PhaseSpaceDecayChannel::SetDaughterMa << 
722 {                                              << 
723   for (G4int idx = 0; idx < numberOfDaughters; << 
724     givenDaughterMasses[idx] = masses[idx];    << 
725   }                                            << 
726   useGivenDaughterMass = true;                 << 
727   return useGivenDaughterMass;                 << 
728 }                                              << 
729                                                   642 
730 G4bool G4PhaseSpaceDecayChannel::SampleDaughte << 643 G4double G4PhaseSpaceDecayChannel::Pmx(G4double e, G4double p1, G4double p2)
731 {                                                 644 {
732   useGivenDaughterMass = false;                << 645    // calcurate momentum of daughter particles in two-body decay
733   return useGivenDaughterMass;                 << 646    G4double ppp = (e+p1+p2)*(e+p1-p2)*(e-p1+p2)*(e-p1-p2)/(4.0*e*e);
                                                   >> 647    if (ppp>0) return std::sqrt(ppp);
                                                   >> 648    else       return -1.;
734 }                                                 649 }
735                                                   650 
736 G4bool G4PhaseSpaceDecayChannel::IsOKWithParen << 
737 {                                              << 
738   if (!useGivenDaughterMass) return G4VDecayCh << 
739                                                << 
740   CheckAndFillParent();                        << 
741   CheckAndFillDaughters();                     << 
742                                                   651 
743   G4double sumOfDaughterMassMin = 0.0;         << 
744   for (G4int index = 0; index < numberOfDaught << 
745     sumOfDaughterMassMin += givenDaughterMasse << 
746   }                                            << 
747   return (parentMass >= sumOfDaughterMassMin); << 
748 }                                              << 
749                                                   652 
750 G4double G4PhaseSpaceDecayChannel::Pmx(G4doubl << 
751 {                                              << 
752   // calcurate momentum of daughter particles  << 
753   G4double ppp = (e + p1 + p2) * (e + p1 - p2) << 
754   if (ppp > 0) return std::sqrt(ppp);          << 
755   return -1.;                                  << 
756 }                                              << 
757                                                   653