Geant4  10.01.p01
G4ParticleHPChannel.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 // 071031 bug fix T. Koi on behalf of A. Howard
32 // 081203 bug fix in Register method by T. Koi
33 //
34 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
35 //
36 #include <stdlib.h>
37 
38 #include "G4ParticleHPChannel.hh"
39 #include "globals.hh"
40 #include "G4SystemOfUnits.hh"
42 #include "G4HadTmpUtil.hh"
43 
44 #include "G4ParticleHPManager.hh"
46 
48  {
49  return std::max(0., theChannelData->GetXsec(energy));
50  }
51 
53  {
54  return theIsotopeWiseData[isoNumber].GetXsec(energy);
55  }
56 
58  {
59  return theFinalStates[isoNumber]->GetXsec(energy);
60  }
61 
63  Init(G4Element * anElement, const G4String dirName, const G4String aFSType)
64  {
65  theFSType = aFSType;
66  Init(anElement, dirName);
67  }
68 
69  void G4ParticleHPChannel::Init(G4Element * anElement, const G4String dirName)
70  {
71  theDir = dirName;
72  theElement = anElement;
73  }
74 
76  {
77  registerCount++;
78  G4int Z = G4lrint(theElement->GetZ());
79 
80  Z = Z-registerCount;
81  if ( registerCount > 5 ) throw G4HadronicException(__FILE__, __LINE__, "Channel: Do not know what to do with this material"); // for Elastic, Capture, Fission case
82  if ( Z < 1 ) return false;
83 /*
84  if(registerCount<5)
85  {
86  Z = Z-registerCount;
87  }
88 */
89  //if(Z=theElement->GetZ()-5) throw G4HadronicException(__FILE__, __LINE__, "Channel: Do not know what to do with this material");
90  // Bug fix by TK on behalf of AH
91  if ( Z <=theElement->GetZ()-5 ) throw G4HadronicException(__FILE__, __LINE__, "Channel: Do not know what to do with this material");
92  G4int count = 0;
93  if(registerCount==0) count = theElement->GetNumberOfIsotopes();
94  if(count == 0||registerCount!=0) count +=
96  niso = count;
97  delete [] theIsotopeWiseData;
99  delete [] active;
100  active = new G4bool[niso];
101 
102  delete [] theFinalStates;
104  delete theChannelData;
106  for(G4int i=0; i<niso; i++)
107  {
108  theFinalStates[i] = theFS->New();
110  }
111  count = 0;
112  G4int nIsos = niso;
113  if(theElement->GetNumberOfIsotopes()!=0&&registerCount==0)
114  {
115  for (G4int i1=0; i1<nIsos; i1++)
116  {
117  // G4cout <<" Init: normal case"<<G4endl;
118  G4int A = theElement->GetIsotope(i1)->GetN();
119  G4int M = theElement->GetIsotope(i1)->Getm();
121  //theFinalStates[i1]->SetA_Z(A, Z);
122  //UpdateData(A, Z, count++, frac);
123  theFinalStates[i1]->SetA_Z(A, Z, M);
124  UpdateData(A, Z, M, count++, frac, theProjectile);
125  }
126  } else {
127  //G4cout <<" Init: mean case: "
128  // <<theStableOnes.GetNumberOfIsotopes(Z)<<" "
129  // <<Z<<" "<<theElement
130  // << G4endl;
132  for(G4int i1=0;
134  i1++)
135  {
137  G4double frac = theStableOnes.GetAbundance(first+i1);
138  theFinalStates[i1]->SetA_Z(A, Z);
139  UpdateData(A, Z, count++, frac, theProjectile);
140  }
141  }
142  G4bool result = HasDataInAnyFinalState();
143  return result;
144  }
145 
146  //void G4ParticleHPChannel::UpdateData(G4int A, G4int Z, G4int index, G4double abundance)
148  {
149  // Initialze the G4FissionFragment generator for this isomer if needed
151  {
153  }
154 
155  theFinalStates[index]->Init(A, Z, M, theDir, theFSType, projectile);
156  if(!theFinalStates[index]->HasAnyData()) return; // nothing there for exactly this isotope.
157 
158  // the above has put the X-sec into the FS
159  theBuffer = 0;
160  if(theFinalStates[index]->HasXsec())
161  {
162  theBuffer = theFinalStates[index]->GetXsec();
163  theBuffer->Times(abundance/100.);
165  }
166  else // get data from CrossSection directory
167  {
168  G4String tString = "/CrossSection";
169  //active[index] = theIsotopeWiseData[index].Init(A, Z, abundance, theDir, tString);
170  active[index] = theIsotopeWiseData[index].Init(A, Z, M, abundance, theDir, tString);
171  if(active[index]) theBuffer = theIsotopeWiseData[index].MakeChannelData();
172  }
174  }
175 
177  {
178  G4int s_tmp = 0, n=0, m_tmp=0;
179  G4ParticleHPVector * theMerge = new G4ParticleHPVector;
180  G4ParticleHPVector * anActive = theStore;
181  G4ParticleHPVector * aPassive = theNew;
182  G4ParticleHPVector * tmp;
183  G4int a = s_tmp, p = n, t;
184  while (a<anActive->GetVectorLength()&&p<aPassive->GetVectorLength())
185  {
186  if(anActive->GetEnergy(a) <= aPassive->GetEnergy(p))
187  {
188  G4double xa = anActive->GetEnergy(a);
189  theMerge->SetData(m_tmp, xa, anActive->GetXsec(a)+std::max(0., aPassive->GetXsec(xa)) );
190  m_tmp++;
191  a++;
192  G4double xp = aPassive->GetEnergy(p);
193  if( std::abs(std::abs(xp-xa)/xa)<0.001 )
194  {
195  p++;
196  }
197  } else {
198  tmp = anActive; t=a;
199  anActive = aPassive; a=p;
200  aPassive = tmp; p=t;
201  }
202  }
203  while (a!=anActive->GetVectorLength())
204  {
205  theMerge->SetData(m_tmp++, anActive->GetEnergy(a), anActive->GetXsec(a));
206  a++;
207  }
208  while (p!=aPassive->GetVectorLength())
209  {
210  if(std::abs(theMerge->GetEnergy(std::max(0,m_tmp-1))-aPassive->GetEnergy(p))/aPassive->GetEnergy(p)>0.001)
211  theMerge->SetData(m_tmp++, aPassive->GetEnergy(p), aPassive->GetXsec(p));
212  p++;
213  }
214  delete theStore;
215  theStore = theMerge;
216  }
217 
219 
221  ApplyYourself(const G4HadProjectile & theTrack, G4int anIsotope)
222  {
223 // G4cout << "G4ParticleHPChannel::ApplyYourself+"<<niso<<G4endl;
224  if ( anIsotope != -1 && anIsotope != -2 )
225  {
226  //Inelastic Case
227  //G4cout << "G4ParticleHPChannel Inelastic Case"
228  //<< " Z= " << this->GetZ(it) << " A = " << this->GetN(it) << G4endl;
231  return theFinalStates[anIsotope]->ApplyYourself(theTrack);
232  }
233  G4double sum=0;
234  G4int it=0;
235  G4double * xsec = new G4double[niso];
236  G4ParticleHPThermalBoost aThermalE;
237  for (G4int i=0; i<niso; i++)
238  {
239  if(theFinalStates[i]->HasAnyData())
240  {
241  xsec[i] = theIsotopeWiseData[i].GetXsec(aThermalE.GetThermalEnergy(theTrack,
242  theFinalStates[i]->GetN(),
243  theFinalStates[i]->GetZ(),
244  theTrack.GetMaterial()->GetTemperature()));
245  sum += xsec[i];
246  }
247  else
248  {
249  xsec[i]=0;
250  }
251  }
252  if(sum == 0)
253  {
254 // G4cout << "G4ParticleHPChannel::ApplyYourself theFinalState->Initialize+"<<G4endl;
255 // G4cout << "G4ParticleHPChannel::ApplyYourself theFinalState->Initialize-"<<G4endl;
256  it = static_cast<G4int>(niso*G4UniformRand());
257  }
258  else
259  {
260 // G4cout << "Are we still here? "<<sum<<G4endl;
261 // G4cout << "TESTHP 23 NISO="<<niso<<G4endl;
262  G4double random = G4UniformRand();
263  G4double running=0;
264 // G4cout << "G4ParticleHPChannel::ApplyYourself Done the sum"<<niso<<G4endl;
265 // G4cout << "TESTHP 24 NISO="<<niso<<G4endl;
266  for (G4int ix=0; ix<niso; ix++)
267  {
268  running += xsec[ix];
269  //if(random<=running/sum)
270  if( sum == 0 || random <= running/sum )
271  {
272  it = ix;
273  break;
274  }
275  }
276  if(it==niso) it--;
277  }
278  delete [] xsec;
279  G4HadFinalState * theFinalState=0;
280  const G4int A = (G4int)this->GetN(it);
281  const G4int Z = (G4int)this->GetZ(it);
282  const G4int M = (G4int)this->GetM(it);
283 
284  //-2:Marker for Fission
285  if(wendtFissionGenerator&&anIsotope==-2)
286  {
287  theFinalState = wendtFissionGenerator->ApplyYourself(theTrack, Z, A);
288  }
289 
290  // Use the standard procedure if the G4FissionFragmentGenerator model fails
291  if (!theFinalState)
292  {
293  while(theFinalState==0)
294  {
295 // G4cout << "TESTHP 24 it="<<it<<G4endl;
296  theFinalState = theFinalStates[it]->ApplyYourself(theTrack);
297  }
298  }
299 
300  //G4cout <<"THE IMPORTANT RETURN"<<G4endl;
301  //G4cout << "TK G4ParticleHPChannel Elastic, Capture and Fission Cases "
302  //<< " Z= " << this->GetZ(it) << " A = " << this->GetN(it) << G4endl;
306 
307  return theFinalState;
308  }
309 
310 
312 
313  G4cout<<" Element: "<<theElement->GetName()<<G4endl;
314  G4cout<<" Directory name: "<<theDir<<G4endl;
315  G4cout<<" FS name: "<<theFSType<<G4endl;
316  G4cout<<" Number of Isotopes: "<<niso<<G4endl;
317  G4cout<<" Have cross sections: "<<G4endl;
318  for(int i=0;i<niso;i++){
319  G4cout<<theFinalStates[i]->HasXsec()<<" ";
320  }
321  G4cout<<G4endl;
322  if(theChannelData){
323  G4cout<<" Cross Section (total for this channel):"<<G4endl;
325  G4cout<<np<<G4endl;
326  for(int i=0;i<np;i++){
328  }
329  }
330 
331 }
332 
333 
334 
static G4ParticleHPManager * GetInstance()
size_t GetNumberOfIsotopes() const
Definition: G4Element.hh:158
G4double GetEnergy(G4int i) const
G4HadFinalState * ApplyYourself(const G4HadProjectile &projectile, G4int Z, G4int A)
virtual G4HadFinalState * ApplyYourself(const G4HadProjectile &)
G4int GetVectorLength() const
void Init(G4double A, G4double Z, G4String &dirName, G4String &aFSType, G4ParticleDefinition *projectile)
void UpdateData(G4int A, G4int Z, G4int index, G4double abundance, G4ParticleDefinition *projectile)
G4int GetFirstIsotope(G4int Z)
G4double GetM(G4int i)
void SetData(G4int i, G4double x, G4double y)
G4ParticleHPFinalState ** theFinalStates
G4double GetZ() const
Definition: G4Element.hh:131
G4double GetXsec(G4double energy)
G4double GetN(G4int i)
G4double a
Definition: TRTMaterials.hh:39
virtual G4ParticleHPFinalState * New()=0
int G4int
Definition: G4Types.hh:78
G4double GetXsec(G4int i)
G4bool Register(G4ParticleHPFinalState *theFS)
G4ParticleHPIsoData * theIsotopeWiseData
void Harmonise(G4ParticleHPVector *&theStore, G4ParticleHPVector *theNew)
void InitializeANucleus(const G4int A, const G4int Z, const G4int M, const G4String &dataDirectory)
G4int GetN() const
Definition: G4Isotope.hh:94
#define G4UniformRand()
Definition: Randomize.hh:95
G4GLOB_DLL std::ostream G4cout
G4int Getm() const
Definition: G4Isotope.hh:100
bool G4bool
Definition: G4Types.hh:79
G4double GetZ(G4int i)
void Times(G4double factor)
G4double * GetRelativeAbundanceVector() const
Definition: G4Element.hh:166
G4ParticleHPVector * MakeChannelData()
static const double perCent
Definition: G4SIunits.hh:296
void Init(G4Element *theElement, const G4String dirName)
G4StableIsotopes theStableOnes
const G4int n
static const G4double A[nN]
void SetProjectile(G4ParticleDefinition *projectile)
G4int GetNumberOfIsotopes(G4int Z)
G4double GetThermalEnergy(const G4HadProjectile &aP, const G4Element *anE, G4double aT)
G4ParticleDefinition * theProjectile
static const double eV
Definition: G4SIunits.hh:194
G4bool HasAnyData(G4int isoNumber)
G4ParticleHPVector * theChannelData
G4int GetIsotopeNucleonCount(G4int number)
int G4lrint(double ad)
Definition: templates.hh:163
G4double GetFSCrossSection(G4double energy, G4int isoNumber)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4double energy(const ThreeVector &p, const G4double m)
G4ParticleHPVector * theBuffer
virtual G4double GetXsec(G4double)
const G4Isotope * GetIsotope(G4int iso) const
Definition: G4Element.hh:169
G4double GetWeightedXsec(G4double energy, G4int isoNumber)
G4double GetTemperature() const
Definition: G4Material.hh:182
#define G4endl
Definition: G4ios.hh:61
const G4Material * GetMaterial() const
void SetA_Z(G4double anA, G4double aZ, G4int aM=0)
G4bool Init(G4int A, G4int Z, G4double abun, G4String dirName, G4String aFSType)
G4double GetAbundance(G4int number)
void FillChannelData(G4ParticleHPVector *aBuffer)
double G4double
Definition: G4Types.hh:76
const G4String & GetName() const
Definition: G4Element.hh:127
G4WendtFissionFragmentGenerator *const wendtFissionGenerator
G4ParticleHPReactionWhiteBoard * GetReactionWhiteBoard()
G4double GetXsec(G4double energy)
G4HadFinalState * ApplyYourself(const G4HadProjectile &theTrack, G4int isoNumber=-1)