Geant4  10.01.p01
G4NeutronHPPhotonDist.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 Try to limit sum of secondary photon energy while keeping distribution shape
31 // in the of nDiscrete = 1 an nPartial = 1. Most case are satisfied.
32 // T. Koi
33 // 070606 Add Partial case by T. Koi
34 // 070618 fix memory leaking by T. Koi
35 // 080801 fix memory leaking by T. Koi
36 // 080801 Correcting data disorder which happened when both InitPartial
37 // and InitAnglurar methods was called in a same instance by T. Koi
38 // 090514 Fix bug in IC electron emission case
39 // Contribution from Chao Zhang (Chao.Zhang@usd.edu) and Dongming Mei(Dongming.Mei@usd.edu)
40 // But it looks like never cause real effect in G4NDL3.13 (at least Natural elements) TK
41 // 101111 Change warning message for "repFlag == 2 && isoFlag != 1" case
42 //
43 // there is a lot of unused (and undebugged) code in this file. Kept for the moment just in case. @@
44 
45 #include <numeric>
46 
47 #include "G4NeutronHPPhotonDist.hh"
48 #include "G4PhysicalConstants.hh"
49 #include "G4SystemOfUnits.hh"
51 #include "G4Electron.hh"
52 #include "G4Poisson.hh"
53 
54 G4bool G4NeutronHPPhotonDist::InitMean(std::istream & aDataFile)
55 {
56 
57  G4bool result = true;
58  if(aDataFile >> repFlag)
59  {
60 
61  aDataFile >> targetMass;
62  if(repFlag==1)
63  {
64  // multiplicities
65  aDataFile >> nDiscrete;
66  disType = new G4int[nDiscrete];
67  energy = new G4double[nDiscrete];
68  //actualMult = new G4int[nDiscrete];
70  for (G4int i=0; i<nDiscrete; i++)
71  {
72  aDataFile >> disType[i]>>energy[i];
73  energy[i]*=eV;
74  theYield[i].Init(aDataFile, eV);
75  }
76  }
77  else if(repFlag == 2)
78  {
79  aDataFile >> theInternalConversionFlag;
80  aDataFile >> theBaseEnergy;
81  theBaseEnergy*=eV;
82  aDataFile >> theInternalConversionFlag;
83  // theInternalConversionFlag == 1 No IC, theInternalConversionFlag == 2 with IC
84  aDataFile >> nGammaEnergies;
87  if(theInternalConversionFlag == 2) thePhotonTransitionFraction = new G4double[nGammaEnergies];
88  for(G4int ii=0; ii<nGammaEnergies; ii++)
89  {
90  if(theInternalConversionFlag == 1)
91  {
92  aDataFile >> theLevelEnergies[ii] >> theTransitionProbabilities[ii];
93  theLevelEnergies[ii]*=eV;
94  }
95  else if(theInternalConversionFlag == 2)
96  {
98  theLevelEnergies[ii]*=eV;
99  }
100  else
101  {
102  throw G4HadronicException(__FILE__, __LINE__, "G4NeutronHPPhotonDist: Unknown conversion flag");
103  }
104  }
105  // Note, that this is equivalent to using the 'Gamma' classes.
106  // throw G4HadronicException(__FILE__, __LINE__, "G4NeutronHPPhotonDist: Transition probability array not sampled for the moment.");
107  }
108  else
109  {
110  G4cout << "Data representation in G4NeutronHPPhotonDist: "<<repFlag<<G4endl;
111  throw G4HadronicException(__FILE__, __LINE__, "G4NeutronHPPhotonDist: This data representation is not implemented.");
112  }
113  }
114  else
115  {
116  result = false;
117  }
118  return result;
119 }
120 
121 void G4NeutronHPPhotonDist::InitAngular(std::istream & aDataFile)
122 {
123 
124  G4int i, ii;
125  //angular distributions
126  aDataFile >> isoFlag;
127  if (isoFlag != 1)
128  {
129 if ( repFlag == 2 ) G4cout << "G4NeutronHPPhotonDist: repFlag == 2 && isoFlag != 1 is unexpected! If you use G4ND3.x, then please report to Geant4 Hyper News. Thanks." << G4endl;
130  aDataFile >> tabulationType >> nDiscrete2 >> nIso;
131 //080731
132  if ( theGammas != NULL && nDiscrete2 != nDiscrete ) G4cout << "080731c G4NeutronHPPhotonDist nDiscrete2 != nDiscrete, It looks like something wrong in your NDL files. Please update the latest. If you still have this messages after the update, then please report to Geant4 Hyper News." << G4endl;
133 
134  // The order of cross section (InitPartials) and distribution (InitAngular here) data are different, we have to re-coordinate consistent data order.
135  std::vector < G4double > vct_gammas_par;
136  std::vector < G4double > vct_shells_par;
137  std::vector < G4int > vct_primary_par;
138  std::vector < G4int > vct_distype_par;
139  std::vector < G4NeutronHPVector* > vct_pXS_par;
140  if ( theGammas != NULL )
141  {
142  //copy the cross section data
143  for ( i = 0 ; i < nDiscrete ; i++ )
144  {
145  vct_gammas_par.push_back( theGammas[ i ] );
146  vct_shells_par.push_back( theShells[ i ] );
147  vct_primary_par.push_back( isPrimary[ i ] );
148  vct_distype_par.push_back( disType[ i ] );
150  *hpv = thePartialXsec[ i ];
151  vct_pXS_par.push_back( hpv );
152  }
153  }
154  if ( theGammas == NULL ) theGammas = new G4double[nDiscrete2];
155  if ( theShells == NULL ) theShells = new G4double[nDiscrete2];
156 //080731
157 
158  for (i=0; i< nIso; i++) // isotropic photons
159  {
160  aDataFile >> theGammas[i] >> theShells[i];
161  theGammas[i]*=eV;
162  theShells[i]*=eV;
163  }
164  nNeu = new G4int [nDiscrete2-nIso];
167  for(i=nIso; i< nDiscrete2; i++)
168  {
169  if(tabulationType==1)
170  {
171  aDataFile >> theGammas[i] >> theShells[i] >> nNeu[i-nIso];
172  theGammas[i]*=eV;
173  theShells[i]*=eV;
175  theLegendreManager.Init(aDataFile);
176  for (ii=0; ii<nNeu[i-nIso]; ii++)
177  {
178  theLegendre[i-nIso][ii].Init(aDataFile);
179  }
180  }
181  else if(tabulationType==2)
182  {
183  aDataFile >> theGammas[i] >> theShells[i] >> nNeu[i-nIso];
184  theGammas[i]*=eV;
185  theShells[i]*=eV;
186  theAngular[i-nIso]=new G4NeutronHPAngularP[nNeu[i-nIso]];
187  for (ii=0; ii<nNeu[i-nIso]; ii++)
188  {
189  theAngular[i-nIso][ii].Init(aDataFile);
190  }
191  }
192  else
193  {
194  G4cout << "tabulation type: tabulationType"<<G4endl;
195  throw G4HadronicException(__FILE__, __LINE__, "cannot deal with this tabulation type for angular distributions.");
196  }
197  }
198 //080731
199  if ( vct_gammas_par.size() > 0 )
200  {
201  //Reordering cross section data to corrsponding distribution data
202  for ( i = 0 ; i < nDiscrete ; i++ )
203  {
204  for ( G4int j = 0 ; j < nDiscrete ; j++ )
205  {
206  // Checking gamma and shell to identification
207  if ( theGammas[ i ] == vct_gammas_par [ j ] && theShells [ i ] == vct_shells_par[ j ] )
208  {
209  isPrimary [ i ] = vct_primary_par [ j ];
210  disType [ i ] = vct_distype_par [ j ];
211  thePartialXsec[ i ] = ( *( vct_pXS_par[ j ] ) );
212  }
213  }
214  }
215  //Garbage collection
216  for ( std::vector < G4NeutronHPVector* >::iterator
217  it = vct_pXS_par.begin() ; it != vct_pXS_par.end() ; it++ )
218  {
219  delete *it;
220  }
221  }
222 //080731
223  }
224 }
225 
226 
227 void G4NeutronHPPhotonDist::InitEnergies(std::istream & aDataFile)
228 {
229  G4int i, energyDistributionsNeeded = 0;
230  for (i=0; i<nDiscrete; i++)
231  {
232  if( disType[i]==1) energyDistributionsNeeded =1;
233  }
234  if(!energyDistributionsNeeded) return;
235  aDataFile >> nPartials;
239  G4int nen;
240  G4int dummy;
241  for (i=0; i<nPartials; i++)
242  {
243  aDataFile >> dummy;
244  probs[i].Init(aDataFile, eV);
245  aDataFile >> nen;
246  partials[i] = new G4NeutronHPPartial(nen);
247  partials[i]->InitInterpolation(aDataFile);
248  partials[i]->Init(aDataFile);
249  }
250 }
251 
252 void G4NeutronHPPhotonDist::InitPartials(std::istream & aDataFile)
253 {
254 
255  //G4cout << "G4NeutronHPPhotonDist::InitPartials " << G4endl;
256  aDataFile >> nDiscrete >> targetMass;
257  if(nDiscrete != 1)
258  {
259  theTotalXsec.Init(aDataFile, eV);
260  }
261  G4int i;
264  isPrimary = new G4int[nDiscrete];
265  disType = new G4int[nDiscrete];
267  for(i=0; i<nDiscrete; i++)
268  {
269  aDataFile>>theGammas[i]>>theShells[i]>>isPrimary[i]>>disType[i];
270  theGammas[i]*=eV;
271  theShells[i]*=eV;
272  thePartialXsec[i].Init(aDataFile, eV);
273  }
274 
275  //G4cout << "G4NeutronHPPhotonDist::InitPartials Test " << G4endl;
276  //G4cout << "G4NeutronHPPhotonDist::InitPartials nDiscrete " << nDiscrete << G4endl;
277  //G4NeutronHPVector* aHP = new G4NeutronHPVector;
278  //aHP->Check(1);
279 }
280 
282 {
283 
284  //G4cout << "G4NeutronHPPhotonDist::GetPhotons repFlag " << repFlag << G4endl;
285  // the partial cross-section case is not in this yet. @@@@ << 070601 TK add partial
286  if ( actualMult.Get() == NULL ) {
287  actualMult.Get() = new std::vector<G4int>( nDiscrete );
288  }
289  G4int i, ii, iii;
290  G4int nSecondaries = 0;
292  if(repFlag==1)
293  {
294  //if ( (G4int) actualMult.Get()->size() != nDiscrete ) actualMult.Get().resize( nDiscrete );
295  G4double current=0;
296  for(i=0; i<nDiscrete; i++)
297  {
298  current = theYield[i].GetY(anEnergy);
299  actualMult.Get()->at(i) = G4Poisson(current); // max cut-off still missing @@@
300  if(nDiscrete==1&&current<1.0001)
301  {
302  actualMult.Get()->at(i) = static_cast<G4int>(current);
303  if(current<1)
304  {
305  actualMult.Get()->at(i) = 0;
306  if(G4UniformRand()<current) actualMult.Get()->at(i) = 1;
307  }
308  }
309  nSecondaries += actualMult.Get()->at(i);
310  }
311  //G4cout << "nSecondaries " << nSecondaries << " anEnergy " << anEnergy/eV << G4endl;
312  for(i=0;i<nSecondaries;i++)
313  {
314  G4ReactionProduct * theOne = new G4ReactionProduct;
315  theOne->SetDefinition(G4Gamma::Gamma());
316  thePhotons->push_back(theOne);
317  }
318  G4int count=0;
319 
320 /*
321 G4double totalCascadeEnergy = 0.;
322 G4double lastCascadeEnergy = 0.;
323 G4double eGamm = 0;
324 G4int maxEnergyIndex = 0;
325 */
326  //Gcout << "nDiscrete " << nDiscrete << " nPartials " << nPartials << G4endl;
327 //3456
328  if ( nDiscrete == 1 && nPartials == 1 )
329  {
330  if ( actualMult.Get()->at(0) > 0 )
331  {
332  if ( disType[0] == 1 ) // continuum
333  {
334 
335 /*
336  for(ii=0; ii< actualMult[0]; ii++)
337  {
338 
339  G4double sum=0, run=0;
340  for(iii=0; iii<nPartials; iii++) sum+=probs[iii].GetY(anEnergy);
341  G4double random = G4UniformRand();
342  G4int theP = 0;
343  for(iii=0; iii<nPartials; iii++)
344  {
345  run+=probs[iii].GetY(anEnergy);
346  theP = iii;
347  if(random<run/sum) break;
348  }
349  if(theP==nPartials) theP=nPartials-1; // das sortiert J aus.
350  sum=0;
351  G4NeutronHPVector * temp;
352  temp = partials[theP]->GetY(anEnergy); //@@@ look at, seems fishy
353  // Looking for TotalCascdeEnergy or LastMaxEnergy
354  if (ii == 0)
355  {
356  maxEnergyIndex = temp->GetVectorLength()-1;
357  totalCascadeEnergy = temp->GetX(maxEnergyIndex);
358  lastCascadeEnergy = totalCascadeEnergy;
359  }
360  lastCascadeEnergy -= eGamm;
361  if (ii != actualMult[i]-1) eGamm = temp->SampleWithMax(lastCascadeEnergy);
362  else eGamm = lastCascadeEnergy;
363  thePhotons->operator[](count)->SetKineticEnergy(eGamm);
364  delete temp;
365 
366  }
367 */
368  G4NeutronHPVector * temp;
369  temp = partials[ 0 ]->GetY(anEnergy); //@@@ look at, seems fishy
370  G4double maximumE = temp->GetX( temp->GetVectorLength()-1 ); // This is an assumption.
371 
372  //G4cout << "start " << actualMult[ 0 ] << " maximumE " << maximumE/eV << G4endl;
373 
374  std::vector< G4double > photons_e_best( actualMult.Get()->at(0) , 0.0 );
375  G4double best = DBL_MAX;
376  G4int maxTry = 1000;
377  for ( G4int j = 0 ; j < maxTry ; j++ )
378  {
379  std::vector< G4double > photons_e( actualMult.Get()->at(0) , 0.0 );
380  for ( std::vector< G4double >::iterator
381  it = photons_e.begin() ; it < photons_e.end() ; it++ )
382  {
383  *it = temp->Sample();
384  }
385  if ( std::accumulate( photons_e.begin() , photons_e.end() , 0.0 ) > maximumE )
386  {
387  if ( std::accumulate( photons_e.begin() , photons_e.end() , 0.0 ) < best )
388  photons_e_best = photons_e;
389  continue;
390  }
391  else
392  {
393  for ( std::vector< G4double >::iterator
394  it = photons_e.begin() ; it < photons_e.end() ; it++ )
395  {
396  thePhotons->operator[](count)->SetKineticEnergy( *it );
397  }
398  //G4cout << "OK " << actualMult[0] << " j " << j << " total photons E "
399  // << std::accumulate( photons_e.begin() , photons_e.end() , 0.0 )/eV << " ratio " << std::accumulate( photons_e.begin() , photons_e.end() , 0.0 ) / maximumE
400  // << G4endl;
401 
402  break;
403  }
404  G4cout << "NeutronHPPhotonDist could not find fitted energy set for multiplicity of " << actualMult.Get()->at(0) << "." << G4endl;
405  G4cout << "NeutronHPPhotonDist will use the best set." << G4endl;
406  for ( std::vector< G4double >::iterator
407  it = photons_e_best.begin() ; it < photons_e_best.end() ; it++ )
408  {
409  thePhotons->operator[](count)->SetKineticEnergy( *it );
410  }
411  //G4cout << "Not Good " << actualMult[0] << " j " << j << " total photons E "
412  // << best/eV << " ratio " << best / maximumE
413  // << G4endl;
414  }
415  // TKDB
416  delete temp;
417  }
418  else // discrete
419  {
420  thePhotons->operator[](count)->SetKineticEnergy(energy[i]);
421  }
422  count++;
423  if(count > nSecondaries) throw G4HadronicException(__FILE__, __LINE__, "G4NeutronHPPhotonDist::GetPhotons inconsistancy");
424  }
425 
426  }
427  else
428  {
429  for(i=0; i<nDiscrete; i++)
430  {
431  for(ii=0; ii< actualMult.Get()->at(i); ii++)
432  {
433  if(disType[i]==1) // continuum
434  {
435  G4double sum=0, run=0;
436  for(iii=0; iii<nPartials; iii++) sum+=probs[iii].GetY(anEnergy);
437  G4double random = G4UniformRand();
438  G4int theP = 0;
439  for(iii=0; iii<nPartials; iii++)
440  {
441  run+=probs[iii].GetY(anEnergy);
442  theP = iii;
443  if(random<run/sum) break;
444  }
445  if(theP==nPartials) theP=nPartials-1; // das sortiert J aus.
446  sum=0;
447  G4NeutronHPVector * temp;
448  temp = partials[theP]->GetY(anEnergy); //@@@ look at, seems fishy
449  G4double eGamm = temp->Sample();
450  thePhotons->operator[](count)->SetKineticEnergy(eGamm);
451  delete temp;
452  }
453  else // discrete
454  {
455  thePhotons->operator[](count)->SetKineticEnergy(energy[i]);
456  }
457  count++;
458  if(count > nSecondaries) throw G4HadronicException(__FILE__, __LINE__, "G4NeutronHPPhotonDist::GetPhotons inconsistancy");
459  }
460  }
461  }
462  // now do the angular distributions...
463  if( isoFlag == 1)
464  {
465  for (i=0; i< nSecondaries; i++)
466  {
467  G4double costheta = 2.*G4UniformRand()-1;
468  G4double theta = std::acos(costheta);
469  G4double phi = twopi*G4UniformRand();
470  G4double sinth = std::sin(theta);
471  G4double en = thePhotons->operator[](i)->GetTotalEnergy();
472  G4ThreeVector temp(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
473  thePhotons->operator[](i)->SetMomentum( temp ) ;
474  // G4cout << "Isotropic distribution in PhotonDist"<<temp<<G4endl;
475  }
476  }
477  else
478  {
479  for(i=0; i<nSecondaries; i++)
480  {
481  G4double currentEnergy = thePhotons->operator[](i)->GetTotalEnergy();
482  for(ii=0; ii<nDiscrete2; ii++)
483  {
484  if (std::abs(currentEnergy-theGammas[ii])<0.1*keV) break;
485  }
486  if(ii==nDiscrete2) ii--; // fix for what seems an (file12 vs file 14) inconsistancy found in the ENDF 7N14 data. @@
487  if(ii<nIso)
488  {
489  // isotropic distribution
490  G4double theta = pi*G4UniformRand();
491  G4double phi = twopi*G4UniformRand();
492  G4double sinth = std::sin(theta);
493  G4double en = thePhotons->operator[](i)->GetTotalEnergy();
494  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
495  thePhotons->operator[](i)->SetMomentum( tempVector ) ;
496  }
497  else if(tabulationType==1)
498  {
499  // legendre polynomials
500  G4int it(0);
501  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
502  {
503  it = iii;
504  if(theLegendre[ii-nIso][iii].GetEnergy()>anEnergy)
505  break;
506  }
507  G4NeutronHPLegendreStore aStore(2);
508  aStore.SetCoeff(1, &(theLegendre[ii-nIso][it]));
509  //aStore.SetCoeff(0, &(theLegendre[ii-nIso][it-1]));
510  //TKDB 110512
511  if ( it > 0 )
512  {
513  aStore.SetCoeff(0, &(theLegendre[ii-nIso][it-1]));
514  }
515  else
516  {
517  aStore.SetCoeff(0, &(theLegendre[ii-nIso][it]));
518  }
519  G4double cosTh = aStore.SampleMax(anEnergy);
520  G4double theta = std::acos(cosTh);
521  G4double phi = twopi*G4UniformRand();
522  G4double sinth = std::sin(theta);
523  G4double en = thePhotons->operator[](i)->GetTotalEnergy();
524  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
525  thePhotons->operator[](i)->SetMomentum( tempVector ) ;
526  }
527  else
528  {
529  // tabulation of probabilities.
530  G4int it(0);
531  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
532  {
533  it = iii;
534  if(theAngular[ii-nIso][iii].GetEnergy()>anEnergy)
535  break;
536  }
537  G4double costh = theAngular[ii-nIso][it].GetCosTh(); // no interpolation yet @@
538  G4double theta = std::acos(costh);
539  G4double phi = twopi*G4UniformRand();
540  G4double sinth = std::sin(theta);
541  G4double en = thePhotons->operator[](i)->GetTotalEnergy();
542  G4ThreeVector tmpVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*costh );
543  thePhotons->operator[](i)->SetMomentum( tmpVector ) ;
544  }
545  }
546  }
547  }
548  else if(repFlag == 2)
549  {
550  G4double * running = new G4double[nGammaEnergies];
551  running[0]=theTransitionProbabilities[0];
552  //G4int i; //declaration at 284th
553  for(i=1; i<nGammaEnergies; i++)
554  {
555  running[i]=running[i-1]+theTransitionProbabilities[i];
556  }
557  G4double random = G4UniformRand();
558  G4int it=0;
559  for(i=0; i<nGammaEnergies; i++)
560  {
561  it = i;
562  if(random < running[i]/running[nGammaEnergies-1]) break;
563  }
564  delete [] running;
565  G4double totalEnergy = theBaseEnergy - theLevelEnergies[it];
566  G4ReactionProduct * theOne = new G4ReactionProduct;
567  theOne->SetDefinition(G4Gamma::Gamma());
568  random = G4UniformRand();
570  {
572  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
573  //But never enter at least with G4NDL3.13
574  totalEnergy += G4Electron::Electron()->GetPDGMass(); //proposed correction: add this line for electron
575  }
576  theOne->SetTotalEnergy(totalEnergy);
577  if( isoFlag == 1 )
578  {
579  G4double costheta = 2.*G4UniformRand()-1;
580  G4double theta = std::acos(costheta);
581  G4double phi = twopi*G4UniformRand();
582  G4double sinth = std::sin(theta);
583  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
584  //G4double en = theOne->GetTotalEnergy();
585  G4double en = theOne->GetTotalMomentum();
586  //But never cause real effect at least with G4NDL3.13 TK
587  G4ThreeVector temp(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
588  theOne->SetMomentum( temp ) ;
589  }
590  else
591  {
592  G4double currentEnergy = theOne->GetTotalEnergy();
593  for(ii=0; ii<nDiscrete2; ii++)
594  {
595  if (std::abs(currentEnergy-theGammas[ii])<0.1*keV) break;
596  }
597  if(ii==nDiscrete2) ii--; // fix for what seems an (file12 vs file 14) inconsistancy found in the ENDF 7N14 data. @@
598  if(ii<nIso)
599  {
600  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
601  // isotropic distribution
602  //G4double theta = pi*G4UniformRand();
603  G4double theta = std::acos(2.*G4UniformRand()-1.);
604  //But this is alos never cause real effect at least with G4NDL3.13 TK not repFlag == 2 AND isoFlag != 1
605  G4double phi = twopi*G4UniformRand();
606  G4double sinth = std::sin(theta);
607  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
608  //G4double en = theOne->GetTotalEnergy();
609  G4double en = theOne->GetTotalMomentum();
610  //But never cause real effect at least with G4NDL3.13 TK
611  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
612  theOne->SetMomentum( tempVector ) ;
613  }
614  else if(tabulationType==1)
615  {
616  // legendre polynomials
617  G4int itt(0);
618  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
619  {
620  itt = iii;
621  if(theLegendre[ii-nIso][iii].GetEnergy()>anEnergy)
622  break;
623  }
624  G4NeutronHPLegendreStore aStore(2);
625  aStore.SetCoeff(1, &(theLegendre[ii-nIso][itt]));
626  //aStore.SetCoeff(0, &(theLegendre[ii-nIso][it-1]));
627  //TKDB 110512
628  if ( itt > 0 )
629  {
630  aStore.SetCoeff(0, &(theLegendre[ii-nIso][itt-1]));
631  }
632  else
633  {
634  aStore.SetCoeff(0, &(theLegendre[ii-nIso][itt]));
635  }
636  G4double cosTh = aStore.SampleMax(anEnergy);
637  G4double theta = std::acos(cosTh);
638  G4double phi = twopi*G4UniformRand();
639  G4double sinth = std::sin(theta);
640  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
641  //G4double en = theOne->GetTotalEnergy();
642  G4double en = theOne->GetTotalMomentum();
643  //But never cause real effect at least with G4NDL3.13 TK
644  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
645  theOne->SetMomentum( tempVector ) ;
646  }
647  else
648  {
649  // tabulation of probabilities.
650  G4int itt(0);
651  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
652  {
653  itt = iii;
654  if(theAngular[ii-nIso][iii].GetEnergy()>anEnergy)
655  break;
656  }
657  G4double costh = theAngular[ii-nIso][itt].GetCosTh(); // no interpolation yet @@
658  G4double theta = std::acos(costh);
659  G4double phi = twopi*G4UniformRand();
660  G4double sinth = std::sin(theta);
661  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
662  //G4double en = theOne->GetTotalEnergy();
663  G4double en = theOne->GetTotalMomentum();
664  //But never cause real effect at least with G4NDL3.13 TK
665  G4ThreeVector tmpVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*costh );
666  theOne->SetMomentum( tmpVector ) ;
667  }
668  }
669  thePhotons->push_back(theOne);
670  }
671  else if( repFlag==0 )
672  {
673 
674 // TK add
675  if ( thePartialXsec == 0 )
676  {
677  //G4cout << "repFlag is 0, but no PartialXsec data" << G4endl;
678  //G4cout << "This is not support yet." << G4endl;
679  return thePhotons;
680  }
681 
682 // Partial Case
683 
684  G4ReactionProduct * theOne = new G4ReactionProduct;
685  theOne->SetDefinition( G4Gamma::Gamma() );
686  thePhotons->push_back( theOne );
687 
688 // Energy
689 
690  //G4cout << "Partial Case nDiscrete " << nDiscrete << G4endl;
691  G4double sum = 0.0;
692  std::vector < G4double > dif( nDiscrete , 0.0 );
693  for ( G4int j = 0 ; j < nDiscrete ; j++ )
694  {
695  G4double x = thePartialXsec[ j ].GetXsec( anEnergy ); // x in barn
696  if ( x > 0 )
697  {
698  sum += x;
699  }
700  dif [ j ] = sum;
701  //G4cout << "j " << j << ", x " << x << ", dif " << dif [ j ] << G4endl;
702  }
703 
704  G4double rand = G4UniformRand();
705 
706  G4int iphoton = 0;
707  for ( G4int j = 0 ; j < nDiscrete ; j++ )
708  {
709  G4double y = rand*sum;
710  if ( dif [ j ] > y )
711  {
712  iphoton = j;
713  break;
714  }
715  }
716  //G4cout << "iphoton " << iphoton << G4endl;
717  //G4cout << "photon energy " << theGammas[ iphoton ] /eV << G4endl;
718 
719 // Angle
720  G4double cosTheta = 0.0; // mu
721 
722  if ( isoFlag == 1 )
723  {
724 
725 // Isotropic Case
726 
727  cosTheta = 2.*G4UniformRand()-1;
728 
729  }
730  else
731  {
732 
733  if ( iphoton < nIso )
734  {
735 
736 // still Isotropic
737 
738  cosTheta = 2.*G4UniformRand()-1;
739 
740  }
741  else
742  {
743 
744  //G4cout << "Not Isotropic and isoFlag " << isoFlag << G4endl;
745  //G4cout << "tabulationType " << tabulationType << G4endl;
746  //G4cout << "nDiscrete2 " << nDiscrete2 << G4endl;
747  //G4cout << "nIso " << nIso << G4endl;
748  //G4cout << "size of nNeu " << nDiscrete2-nIso << G4endl;
749  //G4cout << "nNeu[iphoton-nIso] " << nNeu[iphoton-nIso] << G4endl;
750 
751  if ( tabulationType == 1 )
752  {
753 // legendre polynomials
754 
755  G4int iangle = 0;
756  for ( G4int j = 0 ; j < nNeu [ iphoton - nIso ] ; j++ )
757  {
758  iangle = j;
759  if ( theLegendre[ iphoton - nIso ][ j ].GetEnergy() > anEnergy ) break;
760  }
761 
762  G4NeutronHPLegendreStore aStore( 2 );
763  aStore.SetCoeff( 1 , &( theLegendre[ iphoton - nIso ][ iangle ] ) );
764  aStore.SetCoeff( 0 , &( theLegendre[ iphoton - nIso ][ iangle - 1 ] ) );
765 
766  cosTheta = aStore.SampleMax( anEnergy );
767 
768  }
769  else if ( tabulationType == 2 )
770  {
771 
772 // tabulation of probabilities.
773 
774  G4int iangle = 0;
775  for ( G4int j = 0 ; j < nNeu [ iphoton - nIso ] ; j++ )
776  {
777  iangle = j;
778  if ( theAngular[ iphoton - nIso ][ j ].GetEnergy() > anEnergy ) break;
779  }
780 
781  cosTheta = theAngular[iphoton-nIso][ iangle ].GetCosTh(); // no interpolation yet @@
782 
783  }
784  }
785  }
786 
787 // Set
788  G4double phi = twopi*G4UniformRand();
789  G4double theta = std::acos( cosTheta );
790  G4double sinTheta = std::sin( theta );
791 
792  G4double photonE = theGammas[ iphoton ];
793  G4ThreeVector direction ( sinTheta*std::cos( phi ) , sinTheta * std::sin( phi ) , cosTheta );
794  G4ThreeVector photonP = photonE * direction;
795  thePhotons->operator[]( 0 )->SetMomentum( photonP ) ;
796 
797  }
798  else
799  {
800  delete thePhotons;
801  thePhotons = 0; // no gamma data available; some work needed @@@@@@@
802  }
803  return thePhotons;
804 }
805 
G4ReactionProductVector * GetPhotons(G4double anEnergy)
G4double GetY(G4double x)
G4int GetVectorLength() const
G4long G4Poisson(G4double mean)
Definition: G4Poisson.hh:51
G4double SampleMax(G4double energy)
G4double GetTotalMomentum() const
CLHEP::Hep3Vector G4ThreeVector
void Init(G4int aScheme, G4int aRange)
G4NeutronHPPartial ** partials
void SetMomentum(const G4double x, const G4double y, const G4double z)
const G4double pi
value_type & Get() const
Definition: G4Cache.hh:253
void Init(std::istream &aDataFile)
void SetCoeff(G4int i, G4int l, G4double coeff)
void Init(std::istream &aDataFile, G4int total, G4double ux=1., G4double uy=1.)
G4double GetX(G4int i) const
G4double GetCosTh(G4int l)
int G4int
Definition: G4Types.hh:78
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
G4NeutronHPAngularP ** theAngular
std::vector< G4ReactionProduct * > G4ReactionProductVector
void InitAngular(std::istream &aDataFile)
#define G4UniformRand()
Definition: Randomize.hh:95
G4GLOB_DLL std::ostream G4cout
void Init(std::istream &aDataFile)
bool G4bool
Definition: G4Types.hh:79
void SetTotalEnergy(const G4double en)
G4NeutronHPVector theTotalXsec
void InitEnergies(std::istream &aDataFile)
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
G4double GetY(G4int i, G4int j)
static const double eV
Definition: G4SIunits.hh:194
G4double GetTotalEnergy() const
G4bool InitMean(std::istream &aDataFile)
G4double GetPDGMass() const
G4double GetXsec(G4int i)
G4InterpolationManager theLegendreManager
G4NeutronHPLegendreTable ** theLegendre
static G4Electron * Electron()
Definition: G4Electron.cc:94
#define G4endl
Definition: G4ios.hh:61
G4Cache< std::vector< G4int > * > actualMult
void InitInterpolation(G4int i, std::istream &aDataFile)
static const double keV
Definition: G4SIunits.hh:195
G4NeutronHPVector * thePartialXsec
double G4double
Definition: G4Types.hh:76
void Init(std::istream &aDataFile)
G4NeutronHPVector * theYield
#define DBL_MAX
Definition: templates.hh:83
void InitPartials(std::istream &aDataFile)