Geant4-11
G4DecayTable.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// G4DecayTable class implementation
27//
28// Author: H.Kurashige, 7 July 1996
29// --------------------------------------------------------------------
30
31#include "globals.hh"
32#include "G4DecayTable.hh"
33#include "Randomize.hh"
34
36{
38}
39
41{
42 // remove and delete all contents
43 for (auto iCh = channels->cbegin(); iCh!= channels->cend(); ++iCh)
44 {
45 delete (*iCh);
46 }
47 channels->clear();
48 delete channels;
49 channels = nullptr;
50 parent = nullptr;
51}
52
54{
55 if (parent == nullptr)
56 {
57 parent = (G4ParticleDefinition*)(aChannel->GetParent());
58 }
59 if (parent != aChannel->GetParent())
60 {
61#ifdef G4VERBOSE
62 G4cout << " G4DecayTable::Insert :: bad G4VDecayChannel (mismatch parent) "
63 << " " << parent->GetParticleName()
64 << " input:" << aChannel->GetParent()->GetParticleName() << G4endl;
65#endif
66 }
67 else
68 {
69 G4double br = aChannel->GetBR();
70 for (auto iCh = channels->cbegin(); iCh!= channels->cend(); ++iCh)
71 {
72 if (br > (*iCh)->GetBR())
73 {
74 channels->insert(iCh,aChannel);
75 return;
76 }
77 }
78 channels->push_back(aChannel);
79 }
80}
81
83{
84 // check if contents exist
85 if (channels->size()<1) return nullptr;
86
87 if(parentMass < 0.) parentMass=parent->GetPDGMass();
88
89 G4double sumBR = 0.;
90 for (auto iCh = channels->cbegin(); iCh!= channels->cend(); ++iCh)
91 {
92 if ( !((*iCh)->IsOKWithParentMass(parentMass)) ) continue;
93 sumBR += (*iCh)->GetBR();
94 }
95 if (sumBR <= 0.0)
96 {
97#ifdef G4VERBOSE
98 G4cout << " G4DecayTable::SelectADecayChannel :: no possible DecayChannel"
99 << " " << parent->GetParticleName() << G4endl;
100#endif
101 return nullptr;
102 }
103
104 const std::size_t MAX_LOOP = 10000;
105 for (std::size_t loop_counter=0; loop_counter<MAX_LOOP; ++loop_counter)
106 {
107 G4double sum = 0.0;
108 G4double br= sumBR*G4UniformRand();
109 // select decay channel
110 for (auto iCh = channels->cbegin(); iCh!= channels->cend(); ++iCh)
111 {
112 sum += (*iCh)->GetBR();
113 if ( !((*iCh)->IsOKWithParentMass(parentMass)) ) continue;
114 if (br < sum) return (*iCh);
115 }
116 }
117 return nullptr;
118}
119
121{
122 G4cout << "G4DecayTable: " << parent->GetParticleName() << G4endl;
123 G4int index =0;
124 for (auto iCh = channels->cbegin(); iCh!= channels->cend(); ++iCh)
125 {
126 G4cout << index << ": ";
127 (*iCh)->DumpInfo();
128 index += 1;
129 }
130 G4cout << G4endl;
131}
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define G4UniformRand()
Definition: Randomize.hh:52
void Insert(G4VDecayChannel *aChannel)
Definition: G4DecayTable.cc:53
G4VDecayChannelVector * channels
Definition: G4DecayTable.hh:80
G4VDecayChannel * SelectADecayChannel(G4double parentMass=-1.)
Definition: G4DecayTable.cc:82
void DumpInfo() const
G4ParticleDefinition * parent
Definition: G4DecayTable.hh:79
std::vector< G4VDecayChannel * > G4VDecayChannelVector
Definition: G4DecayTable.hh:49
const G4String & GetParticleName() const
G4double GetBR() const
G4ParticleDefinition * GetParent()