Geant4  10.02
G4ParticleHPPhotonDist.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 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
45 //
46 #include <numeric>
47 
49 #include "G4PhysicalConstants.hh"
50 #include "G4SystemOfUnits.hh"
52 #include "G4Electron.hh"
53 #include "G4Poisson.hh"
54 
55 G4bool G4ParticleHPPhotonDist::InitMean(std::istream & aDataFile)
56 {
57 
58  G4bool result = true;
59  if(aDataFile >> repFlag)
60  {
61 
62  aDataFile >> targetMass;
63  if(repFlag==1)
64  {
65  // multiplicities
66  aDataFile >> nDiscrete;
67  disType = new G4int[nDiscrete];
68  energy = new G4double[nDiscrete];
69  //actualMult = new G4int[nDiscrete];
71  for (G4int i=0; i<nDiscrete; i++)
72  {
73  aDataFile >> disType[i]>>energy[i];
74  energy[i]*=eV;
75  theYield[i].Init(aDataFile, eV);
76  }
77  }
78  else if(repFlag == 2)
79  {
80  aDataFile >> theInternalConversionFlag;
81  aDataFile >> theBaseEnergy;
82  theBaseEnergy*=eV;
83  aDataFile >> theInternalConversionFlag;
84  // theInternalConversionFlag == 1 No IC, theInternalConversionFlag == 2 with IC
85  aDataFile >> nGammaEnergies;
88  if(theInternalConversionFlag == 2) thePhotonTransitionFraction = new G4double[nGammaEnergies];
89  for(G4int ii=0; ii<nGammaEnergies; ii++)
90  {
91  if(theInternalConversionFlag == 1)
92  {
93  aDataFile >> theLevelEnergies[ii] >> theTransitionProbabilities[ii];
94  theLevelEnergies[ii]*=eV;
95  }
96  else if(theInternalConversionFlag == 2)
97  {
99  theLevelEnergies[ii]*=eV;
100  }
101  else
102  {
103  throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPPhotonDist: Unknown conversion flag");
104  }
105  }
106  // Note, that this is equivalent to using the 'Gamma' classes.
107  // throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPPhotonDist: Transition probability array not sampled for the moment.");
108  }
109  else
110  {
111  G4cout << "Data representation in G4ParticleHPPhotonDist: "<<repFlag<<G4endl;
112  throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPPhotonDist: This data representation is not implemented.");
113  }
114  }
115  else
116  {
117  result = false;
118  }
119  return result;
120 }
121 
122 void G4ParticleHPPhotonDist::InitAngular(std::istream & aDataFile)
123 {
124 
125  G4int i, ii;
126  //angular distributions
127  aDataFile >> isoFlag;
128  if (isoFlag != 1)
129  {
130 if ( repFlag == 2 ) G4cout << "G4ParticleHPPhotonDist: repFlag == 2 && isoFlag != 1 is unexpected! If you use G4ND3.x, then please report to Geant4 Hyper News. Thanks." << G4endl;
131  aDataFile >> tabulationType >> nDiscrete2 >> nIso;
132 //080731
133  if ( theGammas != NULL && nDiscrete2 != nDiscrete ) G4cout << "080731c G4ParticleHPPhotonDist 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;
134 
135  // The order of cross section (InitPartials) and distribution (InitAngular here) data are different, we have to re-coordinate consistent data order.
136  std::vector < G4double > vct_gammas_par;
137  std::vector < G4double > vct_shells_par;
138  std::vector < G4int > vct_primary_par;
139  std::vector < G4int > vct_distype_par;
140  std::vector < G4ParticleHPVector* > vct_pXS_par;
141  if ( theGammas != NULL )
142  {
143  //copy the cross section data
144  for ( i = 0 ; i < nDiscrete ; i++ )
145  {
146  vct_gammas_par.push_back( theGammas[ i ] );
147  vct_shells_par.push_back( theShells[ i ] );
148  vct_primary_par.push_back( isPrimary[ i ] );
149  vct_distype_par.push_back( disType[ i ] );
151  *hpv = thePartialXsec[ i ];
152  vct_pXS_par.push_back( hpv );
153  }
154  }
155  if ( theGammas == NULL ) theGammas = new G4double[nDiscrete2];
156  if ( theShells == NULL ) theShells = new G4double[nDiscrete2];
157 //080731
158 
159  for (i=0; i< nIso; i++) // isotropic photons
160  {
161  aDataFile >> theGammas[i] >> theShells[i];
162  theGammas[i]*=eV;
163  theShells[i]*=eV;
164  }
165  nNeu = new G4int [nDiscrete2-nIso];
168  for(i=nIso; i< nDiscrete2; i++)
169  {
170  if(tabulationType==1)
171  {
172  aDataFile >> theGammas[i] >> theShells[i] >> nNeu[i-nIso];
173  theGammas[i]*=eV;
174  theShells[i]*=eV;
176  theLegendreManager.Init(aDataFile);
177  for (ii=0; ii<nNeu[i-nIso]; ii++)
178  {
179  theLegendre[i-nIso][ii].Init(aDataFile);
180  }
181  }
182  else if(tabulationType==2)
183  {
184  aDataFile >> theGammas[i] >> theShells[i] >> nNeu[i-nIso];
185  theGammas[i]*=eV;
186  theShells[i]*=eV;
187  theAngular[i-nIso]=new G4ParticleHPAngularP[nNeu[i-nIso]];
188  for (ii=0; ii<nNeu[i-nIso]; ii++)
189  {
190  theAngular[i-nIso][ii].Init(aDataFile);
191  }
192  }
193  else
194  {
195  G4cout << "tabulation type: tabulationType"<<G4endl;
196  throw G4HadronicException(__FILE__, __LINE__, "cannot deal with this tabulation type for angular distributions.");
197  }
198  }
199 //080731
200  if ( vct_gammas_par.size() > 0 )
201  {
202  //Reordering cross section data to corrsponding distribution data
203  for ( i = 0 ; i < nDiscrete ; i++ )
204  {
205  for ( G4int j = 0 ; j < nDiscrete ; j++ )
206  {
207  // Checking gamma and shell to identification
208  if ( theGammas[ i ] == vct_gammas_par [ j ] && theShells [ i ] == vct_shells_par[ j ] )
209  {
210  isPrimary [ i ] = vct_primary_par [ j ];
211  disType [ i ] = vct_distype_par [ j ];
212  thePartialXsec[ i ] = ( *( vct_pXS_par[ j ] ) );
213  }
214  }
215  }
216  //Garbage collection
217  for ( std::vector < G4ParticleHPVector* >::iterator
218  it = vct_pXS_par.begin() ; it != vct_pXS_par.end() ; it++ )
219  {
220  delete *it;
221  }
222  }
223 //080731
224  }
225 }
226 
227 
228 void G4ParticleHPPhotonDist::InitEnergies(std::istream & aDataFile)
229 {
230  G4int i, energyDistributionsNeeded = 0;
231  for (i=0; i<nDiscrete; i++)
232  {
233  if( disType[i]==1) energyDistributionsNeeded =1;
234  }
235  if(!energyDistributionsNeeded) return;
236  aDataFile >> nPartials;
240  G4int nen;
241  G4int dummy;
242  for (i=0; i<nPartials; i++)
243  {
244  aDataFile >> dummy;
245  probs[i].Init(aDataFile, eV);
246  aDataFile >> nen;
247  partials[i] = new G4ParticleHPPartial(nen);
248  partials[i]->InitInterpolation(aDataFile);
249  partials[i]->Init(aDataFile);
250  }
251 }
252 
253 void G4ParticleHPPhotonDist::InitPartials(std::istream & aDataFile)
254 {
255 
256  //G4cout << "G4ParticleHPPhotonDist::InitPartials " << G4endl;
257  aDataFile >> nDiscrete >> targetMass;
258  if(nDiscrete != 1)
259  {
260  theTotalXsec.Init(aDataFile, eV);
261  }
262  G4int i;
265  isPrimary = new G4int[nDiscrete];
266  disType = new G4int[nDiscrete];
268  for(i=0; i<nDiscrete; i++)
269  {
270  aDataFile>>theGammas[i]>>theShells[i]>>isPrimary[i]>>disType[i];
271  theGammas[i]*=eV;
272  theShells[i]*=eV;
273  thePartialXsec[i].Init(aDataFile, eV);
274  }
275 
276  //G4cout << "G4ParticleHPPhotonDist::InitPartials Test " << G4endl;
277  //G4cout << "G4ParticleHPPhotonDist::InitPartials nDiscrete " << nDiscrete << G4endl;
278  //G4ParticleHPVector* aHP = new G4ParticleHPVector;
279  //aHP->Check(1);
280 }
281 
283 {
284 
285  //G4cout << "G4ParticleHPPhotonDist::GetPhotons repFlag " << repFlag << G4endl;
286  // the partial cross-section case is not in this yet. @@@@ << 070601 TK add partial
287  if ( actualMult.Get() == NULL ) {
288  actualMult.Get() = new std::vector<G4int>( nDiscrete );
289  }
290  G4int i, ii, iii;
291  G4int nSecondaries = 0;
293  if(repFlag==1)
294  {
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  G4ParticleHPVector * 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  G4ParticleHPVector * 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__, "G4ParticleHPPhotonDist::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  G4ParticleHPVector * 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__, "G4ParticleHPPhotonDist::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  //
491  //Fix Bugzilla report #1745
492  //G4double theta = pi*G4UniformRand();
493  G4double costheta = 2.*G4UniformRand()-1;
494  G4double theta = std::acos(costheta);
495  G4double phi = twopi*G4UniformRand();
496  G4double sinth = std::sin(theta);
497  G4double en = thePhotons->operator[](i)->GetTotalEnergy();
498  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
499  thePhotons->operator[](i)->SetMomentum( tempVector ) ;
500  }
501  else if(tabulationType==1)
502  {
503  // legendre polynomials
504  G4int it(0);
505  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
506  {
507  it = iii;
508  if(theLegendre[ii-nIso][iii].GetEnergy()>anEnergy)
509  break;
510  }
511  G4ParticleHPLegendreStore aStore(2);
512  aStore.SetCoeff(1, &(theLegendre[ii-nIso][it]));
513  //aStore.SetCoeff(0, &(theLegendre[ii-nIso][it-1]));
514  //TKDB 110512
515  if ( it > 0 )
516  {
517  aStore.SetCoeff(0, &(theLegendre[ii-nIso][it-1]));
518  }
519  else
520  {
521  aStore.SetCoeff(0, &(theLegendre[ii-nIso][it]));
522  }
523  G4double cosTh = aStore.SampleMax(anEnergy);
524  G4double theta = std::acos(cosTh);
525  G4double phi = twopi*G4UniformRand();
526  G4double sinth = std::sin(theta);
527  G4double en = thePhotons->operator[](i)->GetTotalEnergy();
528  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
529  thePhotons->operator[](i)->SetMomentum( tempVector ) ;
530  }
531  else
532  {
533  // tabulation of probabilities.
534  G4int it(0);
535  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
536  {
537  it = iii;
538  if(theAngular[ii-nIso][iii].GetEnergy()>anEnergy)
539  break;
540  }
541  G4double costh = theAngular[ii-nIso][it].GetCosTh(); // no interpolation yet @@
542  G4double theta = std::acos(costh);
543  G4double phi = twopi*G4UniformRand();
544  G4double sinth = std::sin(theta);
545  G4double en = thePhotons->operator[](i)->GetTotalEnergy();
546  G4ThreeVector tmpVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*costh );
547  thePhotons->operator[](i)->SetMomentum( tmpVector ) ;
548  }
549  }
550  }
551  }
552  else if(repFlag == 2)
553  {
554  G4double * running = new G4double[nGammaEnergies];
555  running[0]=theTransitionProbabilities[0];
556  //G4int i; //declaration at 284th
557  for(i=1; i<nGammaEnergies; i++)
558  {
559  running[i]=running[i-1]+theTransitionProbabilities[i];
560  }
561  G4double random = G4UniformRand();
562  G4int it=0;
563  for(i=0; i<nGammaEnergies; i++)
564  {
565  it = i;
566  if(random < running[i]/running[nGammaEnergies-1]) break;
567  }
568  delete [] running;
569  G4double totalEnergy = theBaseEnergy - theLevelEnergies[it];
570  G4ReactionProduct * theOne = new G4ReactionProduct;
571  theOne->SetDefinition(G4Gamma::Gamma());
572  random = G4UniformRand();
574  {
576  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
577  //But never enter at least with G4NDL3.13
578  totalEnergy += G4Electron::Electron()->GetPDGMass(); //proposed correction: add this line for electron
579  }
580  theOne->SetTotalEnergy(totalEnergy);
581  if( isoFlag == 1 )
582  {
583  G4double costheta = 2.*G4UniformRand()-1;
584  G4double theta = std::acos(costheta);
585  G4double phi = twopi*G4UniformRand();
586  G4double sinth = std::sin(theta);
587  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
588  //G4double en = theOne->GetTotalEnergy();
589  G4double en = theOne->GetTotalMomentum();
590  //But never cause real effect at least with G4NDL3.13 TK
591  G4ThreeVector temp(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
592  theOne->SetMomentum( temp ) ;
593  }
594  else
595  {
596  G4double currentEnergy = theOne->GetTotalEnergy();
597  for(ii=0; ii<nDiscrete2; ii++)
598  {
599  if (std::abs(currentEnergy-theGammas[ii])<0.1*keV) break;
600  }
601  if(ii==nDiscrete2) ii--; // fix for what seems an (file12 vs file 14) inconsistancy found in the ENDF 7N14 data. @@
602  if(ii<nIso)
603  {
604  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
605  // isotropic distribution
606  //G4double theta = pi*G4UniformRand();
607  G4double theta = std::acos(2.*G4UniformRand()-1.);
608  //But this is alos never cause real effect at least with G4NDL3.13 TK not repFlag == 2 AND isoFlag != 1
609  G4double phi = twopi*G4UniformRand();
610  G4double sinth = std::sin(theta);
611  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
612  //G4double en = theOne->GetTotalEnergy();
613  G4double en = theOne->GetTotalMomentum();
614  //But never cause real effect at least with G4NDL3.13 TK
615  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
616  theOne->SetMomentum( tempVector ) ;
617  }
618  else if(tabulationType==1)
619  {
620  // legendre polynomials
621  G4int itt(0);
622  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
623  {
624  itt = iii;
625  if(theLegendre[ii-nIso][iii].GetEnergy()>anEnergy)
626  break;
627  }
628  G4ParticleHPLegendreStore aStore(2);
629  aStore.SetCoeff(1, &(theLegendre[ii-nIso][itt]));
630  //aStore.SetCoeff(0, &(theLegendre[ii-nIso][it-1]));
631  //TKDB 110512
632  if ( itt > 0 )
633  {
634  aStore.SetCoeff(0, &(theLegendre[ii-nIso][itt-1]));
635  }
636  else
637  {
638  aStore.SetCoeff(0, &(theLegendre[ii-nIso][itt]));
639  }
640  G4double cosTh = aStore.SampleMax(anEnergy);
641  G4double theta = std::acos(cosTh);
642  G4double phi = twopi*G4UniformRand();
643  G4double sinth = std::sin(theta);
644  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
645  //G4double en = theOne->GetTotalEnergy();
646  G4double en = theOne->GetTotalMomentum();
647  //But never cause real effect at least with G4NDL3.13 TK
648  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
649  theOne->SetMomentum( tempVector ) ;
650  }
651  else
652  {
653  // tabulation of probabilities.
654  G4int itt(0);
655  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
656  {
657  itt = iii;
658  if(theAngular[ii-nIso][iii].GetEnergy()>anEnergy)
659  break;
660  }
661  G4double costh = theAngular[ii-nIso][itt].GetCosTh(); // no interpolation yet @@
662  G4double theta = std::acos(costh);
663  G4double phi = twopi*G4UniformRand();
664  G4double sinth = std::sin(theta);
665  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
666  //G4double en = theOne->GetTotalEnergy();
667  G4double en = theOne->GetTotalMomentum();
668  //But never cause real effect at least with G4NDL3.13 TK
669  G4ThreeVector tmpVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*costh );
670  theOne->SetMomentum( tmpVector ) ;
671  }
672  }
673  thePhotons->push_back(theOne);
674  }
675  else if( repFlag==0 )
676  {
677 
678 // TK add
679  if ( thePartialXsec == 0 )
680  {
681  //G4cout << "repFlag is 0, but no PartialXsec data" << G4endl;
682  //G4cout << "This is not support yet." << G4endl;
683  return thePhotons;
684  }
685 
686 // Partial Case
687 
688  G4ReactionProduct * theOne = new G4ReactionProduct;
689  theOne->SetDefinition( G4Gamma::Gamma() );
690  thePhotons->push_back( theOne );
691 
692 // Energy
693 
694  //G4cout << "Partial Case nDiscrete " << nDiscrete << G4endl;
695  G4double sum = 0.0;
696  std::vector < G4double > dif( nDiscrete , 0.0 );
697  for ( G4int j = 0 ; j < nDiscrete ; j++ )
698  {
699  G4double x = thePartialXsec[ j ].GetXsec( anEnergy ); // x in barn
700  if ( x > 0 )
701  {
702  sum += x;
703  }
704  dif [ j ] = sum;
705  //G4cout << "j " << j << ", x " << x << ", dif " << dif [ j ] << G4endl;
706  }
707 
708  G4double rand = G4UniformRand();
709 
710  G4int iphoton = 0;
711  for ( G4int j = 0 ; j < nDiscrete ; j++ )
712  {
713  G4double y = rand*sum;
714  if ( dif [ j ] > y )
715  {
716  iphoton = j;
717  break;
718  }
719  }
720  //G4cout << "iphoton " << iphoton << G4endl;
721  //G4cout << "photon energy " << theGammas[ iphoton ] /eV << G4endl;
722 
723 // Angle
724  G4double cosTheta = 0.0; // mu
725 
726  if ( isoFlag == 1 )
727  {
728 
729 // Isotropic Case
730 
731  cosTheta = 2.*G4UniformRand()-1;
732 
733  }
734  else
735  {
736 
737  if ( iphoton < nIso )
738  {
739 
740 // still Isotropic
741 
742  cosTheta = 2.*G4UniformRand()-1;
743 
744  }
745  else
746  {
747 
748  //G4cout << "Not Isotropic and isoFlag " << isoFlag << G4endl;
749  //G4cout << "tabulationType " << tabulationType << G4endl;
750  //G4cout << "nDiscrete2 " << nDiscrete2 << G4endl;
751  //G4cout << "nIso " << nIso << G4endl;
752  //G4cout << "size of nNeu " << nDiscrete2-nIso << G4endl;
753  //G4cout << "nNeu[iphoton-nIso] " << nNeu[iphoton-nIso] << G4endl;
754 
755  if ( tabulationType == 1 )
756  {
757 // legendre polynomials
758 
759  G4int iangle = 0;
760  for ( G4int j = 0 ; j < nNeu [ iphoton - nIso ] ; j++ )
761  {
762  iangle = j;
763  if ( theLegendre[ iphoton - nIso ][ j ].GetEnergy() > anEnergy ) break;
764  }
765 
766  G4ParticleHPLegendreStore aStore( 2 );
767  aStore.SetCoeff( 1 , &( theLegendre[ iphoton - nIso ][ iangle ] ) );
768  aStore.SetCoeff( 0 , &( theLegendre[ iphoton - nIso ][ iangle - 1 ] ) );
769 
770  cosTheta = aStore.SampleMax( anEnergy );
771 
772  }
773  else if ( tabulationType == 2 )
774  {
775 
776 // tabulation of probabilities.
777 
778  G4int iangle = 0;
779  for ( G4int j = 0 ; j < nNeu [ iphoton - nIso ] ; j++ )
780  {
781  iangle = j;
782  if ( theAngular[ iphoton - nIso ][ j ].GetEnergy() > anEnergy ) break;
783  }
784 
785  cosTheta = theAngular[iphoton-nIso][ iangle ].GetCosTh(); // no interpolation yet @@
786 
787  }
788  }
789  }
790 
791 // Set
792  G4double phi = twopi*G4UniformRand();
793  G4double theta = std::acos( cosTheta );
794  G4double sinTheta = std::sin( theta );
795 
796  G4double photonE = theGammas[ iphoton ];
797  G4ThreeVector direction ( sinTheta*std::cos( phi ) , sinTheta * std::sin( phi ) , cosTheta );
798  G4ThreeVector photonP = photonE * direction;
799  thePhotons->operator[]( 0 )->SetMomentum( photonP ) ;
800 
801  }
802  else
803  {
804  delete thePhotons;
805  thePhotons = 0; // no gamma data available; some work needed @@@@@@@
806  }
807  return thePhotons;
808 }
809 
G4long G4Poisson(G4double mean)
Definition: G4Poisson.hh:51
G4int GetVectorLength() const
G4double GetTotalMomentum() const
CLHEP::Hep3Vector G4ThreeVector
G4ParticleHPLegendreTable ** theLegendre
void Init(std::istream &aDataFile)
void InitInterpolation(G4int i, std::istream &aDataFile)
void Init(G4int aScheme, G4int aRange)
G4ParticleHPPartial ** partials
void SetMomentum(const G4double x, const G4double y, const G4double z)
G4double SampleMax(G4double energy)
value_type & Get() const
Definition: G4Cache.hh:282
G4InterpolationManager theLegendreManager
void Init(std::istream &aDataFile)
G4ParticleHPAngularP ** theAngular
G4ParticleHPVector * thePartialXsec
G4double GetCosTh(G4int l)
G4Cache< std::vector< G4int > * > actualMult
int G4int
Definition: G4Types.hh:78
G4double GetXsec(G4int i)
void InitPartials(std::istream &aDataFile)
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
std::vector< G4ReactionProduct * > G4ReactionProductVector
void Init(std::istream &aDataFile, G4int total, G4double ux=1., G4double uy=1.)
G4ParticleHPVector * theYield
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
G4bool InitMean(std::istream &aDataFile)
bool G4bool
Definition: G4Types.hh:79
void SetTotalEnergy(const G4double en)
static const double twopi
Definition: G4SIunits.hh:75
G4double GetX(G4int i) const
G4double GetY(G4double x)
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
static const double eV
Definition: G4SIunits.hh:212
G4double GetTotalEnergy() const
G4double GetPDGMass() const
void SetCoeff(G4int i, G4int l, G4double coeff)
const G4double x[NPOINTSGL]
G4ReactionProductVector * GetPhotons(G4double anEnergy)
static G4Electron * Electron()
Definition: G4Electron.cc:94
#define G4endl
Definition: G4ios.hh:61
static const double keV
Definition: G4SIunits.hh:213
void InitEnergies(std::istream &aDataFile)
double G4double
Definition: G4Types.hh:76
void Init(std::istream &aDataFile)
void InitAngular(std::istream &aDataFile)
#define DBL_MAX
Definition: templates.hh:83
G4double GetY(G4int i, G4int j)