Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4NeutronHPChannelList.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 // neutron_hp -- source file
27 // J.P. Wellisch, Nov-1996
28 // A prototype of the low energy neutron transport model.
29 //
30 // 070523 bug fix for G4FPE_DEBUG on by A. Howard ( and T. Koi)
31 //
33 #include "G4Element.hh"
34 #include "G4HadFinalState.hh"
35 #include "G4HadProjectile.hh"
36 #include "G4NeutronHPFinalState.hh"
37 
38  G4int G4NeutronHPChannelList::trycounter = 0;
39 
41  {
42  nChannels = n;
43  theChannels = new G4NeutronHPChannel * [n];
44  allChannelsCreated = false;
45  theInitCount = 0;
46  }
47 
49  {
50  nChannels = 0;
51  theChannels = 0;
52  allChannelsCreated = false;
53  theInitCount = 0;
54  }
55 
57  {
58  if(theChannels!=0)
59  {
60  for(G4int i=0;i<nChannels; i++)
61  {
62  delete theChannels[i];
63  }
64  delete [] theChannels;
65  }
66  }
67 
69  #include "G4NeutronHPManager.hh"
71  {
72  G4NeutronHPThermalBoost aThermalE;
73  G4int i, ii;
74  // decide on the isotope
75  G4int numberOfIsos(0);
76  for(ii=0; ii<nChannels; ii++)
77  {
78  numberOfIsos = theChannels[ii]->GetNiso();
79  if(numberOfIsos!=0) break;
80  }
81  G4double * running= new G4double [numberOfIsos];
82  running[0] = 0;
83  for(i=0;i<numberOfIsos; i++)
84  {
85  if(i!=0) running[i] = running[i-1];
86  for(ii=0; ii<nChannels; ii++)
87  {
88  if(theChannels[ii]->HasAnyData(i))
89  {
90  running[i] +=theChannels[ii]->GetWeightedXsec(aThermalE.GetThermalEnergy(aTrack,
91  theChannels[ii]->GetN(i),
92  theChannels[ii]->GetZ(i),
93  aTrack.GetMaterial()->GetTemperature()),
94  i);
95  }
96  }
97  }
98  G4int isotope=nChannels-1;
99  G4double random=G4UniformRand();
100  for(i=0;i<numberOfIsos; i++)
101  {
102  isotope = i;
103  //if(random<running[i]/running[numberOfIsos-1]) break;
104  if(running[numberOfIsos-1] != 0) if(random<running[i]/running[numberOfIsos-1]) break;
105  }
106  delete [] running;
107 
108  // decide on the channel
109  running = new G4double[nChannels];
110  running[0]=0;
111  G4int targA=-1; // For production of unChanged
112  G4int targZ=-1;
113  for(i=0; i<nChannels; i++)
114  {
115  if(i!=0) running[i] = running[i-1];
116  if(theChannels[i]->HasAnyData(isotope))
117  {
118  running[i] += theChannels[i]->GetFSCrossSection(aThermalE.GetThermalEnergy(aTrack,
119  theChannels[i]->GetN(isotope),
120  theChannels[i]->GetZ(isotope),
121  aTrack.GetMaterial()->GetTemperature()),
122  isotope);
123  targA=(G4int)theChannels[i]->GetN(isotope); //Will be simply used the last valid value
124  targZ=(G4int)theChannels[i]->GetZ(isotope);
125  }
126  }
127 
128  //TK120607
129  if ( running[nChannels-1] == 0 )
130  {
131  //This happened usually by the miss match between the cross section data and model
132  if ( targA == -1 && targZ == -1 ) {
133  throw G4HadronicException(__FILE__, __LINE__, "NeutronHP model encounter lethal discrepancy with cross section data");
134  }
135 
136  //TK121106
137  G4cout << "Warning from NeutronHP: could not find proper reaction channel. This may cause by inconsistency between cross section and model. Unchanged final states are returned." << G4endl;
138  unChanged.Clear();
139 
140  //For Ep Check create unchanged final state including rest target
141  G4ParticleDefinition* targ_pd = G4ParticleTable::GetParticleTable()->GetIon ( targZ , targA , 0.0 );
142  G4DynamicParticle* targ_dp = new G4DynamicParticle( targ_pd , G4ThreeVector(1,0,0), 0.0 );
143  unChanged.SetEnergyChange(aTrack.GetKineticEnergy());
144  unChanged.SetMomentumChange(aTrack.Get4Momentum().vect() );
145  unChanged.AddSecondary(targ_dp);
146  //TK121106
149  return &unChanged;
150  }
151  //TK120607
152 
153 
154  G4int lChan=0;
155  random=G4UniformRand();
156  for(i=0; i<nChannels; i++)
157  {
158  lChan = i;
159  if(running[nChannels-1] != 0) if(random<running[i]/running[nChannels-1]) break;
160  }
161  delete [] running;
162  return theChannels[lChan]->ApplyYourself(aTrack, isotope);
163  }
164 
165  void G4NeutronHPChannelList::Init(G4Element * anElement, const G4String & dirName)
166  {
167  theDir = dirName;
168 // G4cout << theDir << G4endl;
169  theElement = anElement;
170 // G4cout << theElement << G4endl;
171  ;
172  }
173 
175  const G4String & aName)
176  {
177  if(!allChannelsCreated)
178  {
179  if(nChannels!=0)
180  {
181  G4NeutronHPChannel ** theBuffer = new G4NeutronHPChannel * [nChannels+1];
182  G4int i;
183  for(i=0; i<nChannels; i++)
184  {
185  theBuffer[i] = theChannels[i];
186  }
187  delete [] theChannels;
188  theChannels = theBuffer;
189  }
190  else
191  {
192  theChannels = new G4NeutronHPChannel * [nChannels+1];
193  }
194  G4String name;
195  name = aName+"/";
196  theChannels[nChannels] = new G4NeutronHPChannel;
197  theChannels[nChannels]->Init(theElement, theDir, name);
198  nChannels++;
199  }
200 
201  //110527TKDB Unnessary codes, Detected by gcc4.6 compiler
202  //G4bool result;
203  //result = theChannels[theInitCount]->Register(theFS);
204  theChannels[theInitCount]->Register(theFS);
205  theInitCount++;
206  }