Geant4  10.01.p01
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  G4int i, ii, iii;
288  G4int nSecondaries = 0;
290  if(repFlag==1)
291  {
292  G4double current=0;
293  for(i=0; i<nDiscrete; i++)
294  {
295  current = theYield[i].GetY(anEnergy);
296  actualMult[i] = G4Poisson(current); // max cut-off still missing @@@
297  if(nDiscrete==1&&current<1.0001)
298  {
299  actualMult[i] = static_cast<G4int>(current);
300  if(current<1)
301  {
302  actualMult[i] = 0;
303  if(G4UniformRand()<current) actualMult[i] = 1;
304  }
305  }
306  nSecondaries += actualMult[i];
307  }
308  //G4cout << "nSecondaries " << nSecondaries << " anEnergy " << anEnergy/eV << G4endl;
309  for(i=0;i<nSecondaries;i++)
310  {
311  G4ReactionProduct * theOne = new G4ReactionProduct;
312  theOne->SetDefinition(G4Gamma::Gamma());
313  thePhotons->push_back(theOne);
314  }
315  G4int count=0;
316 
317 /*
318 G4double totalCascadeEnergy = 0.;
319 G4double lastCascadeEnergy = 0.;
320 G4double eGamm = 0;
321 G4int maxEnergyIndex = 0;
322 */
323  //Gcout << "nDiscrete " << nDiscrete << " nPartials " << nPartials << G4endl;
324 //3456
325  if ( nDiscrete == 1 && nPartials == 1 )
326  {
327  if ( actualMult[ 0 ] > 0 )
328  {
329  if ( disType[0] == 1 ) // continuum
330  {
331 
332 /*
333  for(ii=0; ii< actualMult[0]; ii++)
334  {
335 
336  G4double sum=0, run=0;
337  for(iii=0; iii<nPartials; iii++) sum+=probs[iii].GetY(anEnergy);
338  G4double random = G4UniformRand();
339  G4int theP = 0;
340  for(iii=0; iii<nPartials; iii++)
341  {
342  run+=probs[iii].GetY(anEnergy);
343  theP = iii;
344  if(random<run/sum) break;
345  }
346  if(theP==nPartials) theP=nPartials-1; // das sortiert J aus.
347  sum=0;
348  G4ParticleHPVector * temp;
349  temp = partials[theP]->GetY(anEnergy); //@@@ look at, seems fishy
350  // Looking for TotalCascdeEnergy or LastMaxEnergy
351  if (ii == 0)
352  {
353  maxEnergyIndex = temp->GetVectorLength()-1;
354  totalCascadeEnergy = temp->GetX(maxEnergyIndex);
355  lastCascadeEnergy = totalCascadeEnergy;
356  }
357  lastCascadeEnergy -= eGamm;
358  if (ii != actualMult[i]-1) eGamm = temp->SampleWithMax(lastCascadeEnergy);
359  else eGamm = lastCascadeEnergy;
360  thePhotons->operator[](count)->SetKineticEnergy(eGamm);
361  delete temp;
362 
363  }
364 */
365  G4ParticleHPVector * temp;
366  temp = partials[ 0 ]->GetY(anEnergy); //@@@ look at, seems fishy
367  G4double maximumE = temp->GetX( temp->GetVectorLength()-1 ); // This is an assumption.
368 
369  //G4cout << "start " << actualMult[ 0 ] << " maximumE " << maximumE/eV << G4endl;
370 
371  std::vector< G4double > photons_e_best( actualMult[ 0 ] , 0.0 );
372  G4double best = DBL_MAX;
373  G4int maxTry = 1000;
374  for ( G4int j = 0 ; j < maxTry ; j++ )
375  {
376  std::vector< G4double > photons_e( actualMult[ 0 ] , 0.0 );
377  for ( std::vector< G4double >::iterator
378  it = photons_e.begin() ; it < photons_e.end() ; it++ )
379  {
380  *it = temp->Sample();
381  }
382  if ( std::accumulate( photons_e.begin() , photons_e.end() , 0.0 ) > maximumE )
383  {
384  if ( std::accumulate( photons_e.begin() , photons_e.end() , 0.0 ) < best )
385  photons_e_best = photons_e;
386  continue;
387  }
388  else
389  {
390  for ( std::vector< G4double >::iterator
391  it = photons_e.begin() ; it < photons_e.end() ; it++ )
392  {
393  thePhotons->operator[](count)->SetKineticEnergy( *it );
394  }
395  //G4cout << "OK " << actualMult[0] << " j " << j << " total photons E "
396  // << std::accumulate( photons_e.begin() , photons_e.end() , 0.0 )/eV << " ratio " << std::accumulate( photons_e.begin() , photons_e.end() , 0.0 ) / maximumE
397  // << G4endl;
398 
399  break;
400  }
401  G4cout << "NeutronHPPhotonDist could not find fitted energy set for multiplicity of " << actualMult[0] << "." << G4endl;
402  G4cout << "NeutronHPPhotonDist will use the best set." << G4endl;
403  for ( std::vector< G4double >::iterator
404  it = photons_e_best.begin() ; it < photons_e_best.end() ; it++ )
405  {
406  thePhotons->operator[](count)->SetKineticEnergy( *it );
407  }
408  //G4cout << "Not Good " << actualMult[0] << " j " << j << " total photons E "
409  // << best/eV << " ratio " << best / maximumE
410  // << G4endl;
411  }
412  // TKDB
413  delete temp;
414  }
415  else // discrete
416  {
417  thePhotons->operator[](count)->SetKineticEnergy(energy[i]);
418  }
419  count++;
420  if(count > nSecondaries) throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPPhotonDist::GetPhotons inconsistancy");
421  }
422 
423  }
424  else
425  {
426  for(i=0; i<nDiscrete; i++)
427  {
428  for(ii=0; ii< actualMult[i]; ii++)
429  {
430  if(disType[i]==1) // continuum
431  {
432  G4double sum=0, run=0;
433  for(iii=0; iii<nPartials; iii++) sum+=probs[iii].GetY(anEnergy);
434  G4double random = G4UniformRand();
435  G4int theP = 0;
436  for(iii=0; iii<nPartials; iii++)
437  {
438  run+=probs[iii].GetY(anEnergy);
439  theP = iii;
440  if(random<run/sum) break;
441  }
442  if(theP==nPartials) theP=nPartials-1; // das sortiert J aus.
443  sum=0;
444  G4ParticleHPVector * temp;
445  temp = partials[theP]->GetY(anEnergy); //@@@ look at, seems fishy
446  G4double eGamm = temp->Sample();
447  thePhotons->operator[](count)->SetKineticEnergy(eGamm);
448  delete temp;
449  }
450  else // discrete
451  {
452  thePhotons->operator[](count)->SetKineticEnergy(energy[i]);
453  }
454  count++;
455  if(count > nSecondaries) throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPPhotonDist::GetPhotons inconsistancy");
456  }
457  }
458  }
459  // now do the angular distributions...
460  if( isoFlag == 1)
461  {
462  for (i=0; i< nSecondaries; i++)
463  {
464  G4double costheta = 2.*G4UniformRand()-1;
465  G4double theta = std::acos(costheta);
466  G4double phi = twopi*G4UniformRand();
467  G4double sinth = std::sin(theta);
468  G4double en = thePhotons->operator[](i)->GetTotalEnergy();
469  G4ThreeVector temp(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
470  thePhotons->operator[](i)->SetMomentum( temp ) ;
471  // G4cout << "Isotropic distribution in PhotonDist"<<temp<<G4endl;
472  }
473  }
474  else
475  {
476  for(i=0; i<nSecondaries; i++)
477  {
478  G4double currentEnergy = thePhotons->operator[](i)->GetTotalEnergy();
479  for(ii=0; ii<nDiscrete2; ii++)
480  {
481  if (std::abs(currentEnergy-theGammas[ii])<0.1*keV) break;
482  }
483  if(ii==nDiscrete2) ii--; // fix for what seems an (file12 vs file 14) inconsistancy found in the ENDF 7N14 data. @@
484  if(ii<nIso)
485  {
486  // isotropic distribution
487  G4double theta = pi*G4UniformRand();
488  G4double phi = twopi*G4UniformRand();
489  G4double sinth = std::sin(theta);
490  G4double en = thePhotons->operator[](i)->GetTotalEnergy();
491  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
492  thePhotons->operator[](i)->SetMomentum( tempVector ) ;
493  }
494  else if(tabulationType==1)
495  {
496  // legendre polynomials
497  G4int it(0);
498  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
499  {
500  it = iii;
501  if(theLegendre[ii-nIso][iii].GetEnergy()>anEnergy)
502  break;
503  }
504  G4ParticleHPLegendreStore aStore(2);
505  aStore.SetCoeff(1, &(theLegendre[ii-nIso][it]));
506  //aStore.SetCoeff(0, &(theLegendre[ii-nIso][it-1]));
507  //TKDB 110512
508  if ( it > 0 )
509  {
510  aStore.SetCoeff(0, &(theLegendre[ii-nIso][it-1]));
511  }
512  else
513  {
514  aStore.SetCoeff(0, &(theLegendre[ii-nIso][it]));
515  }
516  G4double cosTh = aStore.SampleMax(anEnergy);
517  G4double theta = std::acos(cosTh);
518  G4double phi = twopi*G4UniformRand();
519  G4double sinth = std::sin(theta);
520  G4double en = thePhotons->operator[](i)->GetTotalEnergy();
521  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
522  thePhotons->operator[](i)->SetMomentum( tempVector ) ;
523  }
524  else
525  {
526  // tabulation of probabilities.
527  G4int it(0);
528  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
529  {
530  it = iii;
531  if(theAngular[ii-nIso][iii].GetEnergy()>anEnergy)
532  break;
533  }
534  G4double costh = theAngular[ii-nIso][it].GetCosTh(); // no interpolation yet @@
535  G4double theta = std::acos(costh);
536  G4double phi = twopi*G4UniformRand();
537  G4double sinth = std::sin(theta);
538  G4double en = thePhotons->operator[](i)->GetTotalEnergy();
539  G4ThreeVector tmpVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*costh );
540  thePhotons->operator[](i)->SetMomentum( tmpVector ) ;
541  }
542  }
543  }
544  }
545  else if(repFlag == 2)
546  {
547  G4double * running = new G4double[nGammaEnergies];
548  running[0]=theTransitionProbabilities[0];
549  //G4int i; //declaration at 284th
550  for(i=1; i<nGammaEnergies; i++)
551  {
552  running[i]=running[i-1]+theTransitionProbabilities[i];
553  }
554  G4double random = G4UniformRand();
555  G4int it=0;
556  for(i=0; i<nGammaEnergies; i++)
557  {
558  it = i;
559  if(random < running[i]/running[nGammaEnergies-1]) break;
560  }
561  delete [] running;
562  G4double totalEnergy = theBaseEnergy - theLevelEnergies[it];
563  G4ReactionProduct * theOne = new G4ReactionProduct;
564  theOne->SetDefinition(G4Gamma::Gamma());
565  random = G4UniformRand();
567  {
569  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
570  //But never enter at least with G4NDL3.13
571  totalEnergy += G4Electron::Electron()->GetPDGMass(); //proposed correction: add this line for electron
572  }
573  theOne->SetTotalEnergy(totalEnergy);
574  if( isoFlag == 1 )
575  {
576  G4double costheta = 2.*G4UniformRand()-1;
577  G4double theta = std::acos(costheta);
578  G4double phi = twopi*G4UniformRand();
579  G4double sinth = std::sin(theta);
580  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
581  //G4double en = theOne->GetTotalEnergy();
582  G4double en = theOne->GetTotalMomentum();
583  //But never cause real effect at least with G4NDL3.13 TK
584  G4ThreeVector temp(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
585  theOne->SetMomentum( temp ) ;
586  }
587  else
588  {
589  G4double currentEnergy = theOne->GetTotalEnergy();
590  for(ii=0; ii<nDiscrete2; ii++)
591  {
592  if (std::abs(currentEnergy-theGammas[ii])<0.1*keV) break;
593  }
594  if(ii==nDiscrete2) ii--; // fix for what seems an (file12 vs file 14) inconsistancy found in the ENDF 7N14 data. @@
595  if(ii<nIso)
596  {
597  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
598  // isotropic distribution
599  //G4double theta = pi*G4UniformRand();
600  G4double theta = std::acos(2.*G4UniformRand()-1.);
601  //But this is alos never cause real effect at least with G4NDL3.13 TK not repFlag == 2 AND isoFlag != 1
602  G4double phi = twopi*G4UniformRand();
603  G4double sinth = std::sin(theta);
604  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
605  //G4double en = theOne->GetTotalEnergy();
606  G4double en = theOne->GetTotalMomentum();
607  //But never cause real effect at least with G4NDL3.13 TK
608  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
609  theOne->SetMomentum( tempVector ) ;
610  }
611  else if(tabulationType==1)
612  {
613  // legendre polynomials
614  G4int itt(0);
615  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
616  {
617  itt = iii;
618  if(theLegendre[ii-nIso][iii].GetEnergy()>anEnergy)
619  break;
620  }
621  G4ParticleHPLegendreStore aStore(2);
622  aStore.SetCoeff(1, &(theLegendre[ii-nIso][itt]));
623  //aStore.SetCoeff(0, &(theLegendre[ii-nIso][it-1]));
624  //TKDB 110512
625  if ( itt > 0 )
626  {
627  aStore.SetCoeff(0, &(theLegendre[ii-nIso][itt-1]));
628  }
629  else
630  {
631  aStore.SetCoeff(0, &(theLegendre[ii-nIso][itt]));
632  }
633  G4double cosTh = aStore.SampleMax(anEnergy);
634  G4double theta = std::acos(cosTh);
635  G4double phi = twopi*G4UniformRand();
636  G4double sinth = std::sin(theta);
637  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
638  //G4double en = theOne->GetTotalEnergy();
639  G4double en = theOne->GetTotalMomentum();
640  //But never cause real effect at least with G4NDL3.13 TK
641  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
642  theOne->SetMomentum( tempVector ) ;
643  }
644  else
645  {
646  // tabulation of probabilities.
647  G4int itt(0);
648  for (iii=0; iii<nNeu[ii-nIso]; iii++) // find the neutron energy
649  {
650  itt = iii;
651  if(theAngular[ii-nIso][iii].GetEnergy()>anEnergy)
652  break;
653  }
654  G4double costh = theAngular[ii-nIso][itt].GetCosTh(); // no interpolation yet @@
655  G4double theta = std::acos(costh);
656  G4double phi = twopi*G4UniformRand();
657  G4double sinth = std::sin(theta);
658  //Bug reported Chao Zhang (Chao.Zhang@usd.edu), Dongming Mei(Dongming.Mei@usd.edu) Feb. 25, 2009
659  //G4double en = theOne->GetTotalEnergy();
660  G4double en = theOne->GetTotalMomentum();
661  //But never cause real effect at least with G4NDL3.13 TK
662  G4ThreeVector tmpVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*costh );
663  theOne->SetMomentum( tmpVector ) ;
664  }
665  }
666  thePhotons->push_back(theOne);
667  }
668  else if( repFlag==0 )
669  {
670 
671 // TK add
672  if ( thePartialXsec == 0 )
673  {
674  //G4cout << "repFlag is 0, but no PartialXsec data" << G4endl;
675  //G4cout << "This is not support yet." << G4endl;
676  return thePhotons;
677  }
678 
679 // Partial Case
680 
681  G4ReactionProduct * theOne = new G4ReactionProduct;
682  theOne->SetDefinition( G4Gamma::Gamma() );
683  thePhotons->push_back( theOne );
684 
685 // Energy
686 
687  //G4cout << "Partial Case nDiscrete " << nDiscrete << G4endl;
688  G4double sum = 0.0;
689  std::vector < G4double > dif( nDiscrete , 0.0 );
690  for ( G4int j = 0 ; j < nDiscrete ; j++ )
691  {
692  G4double x = thePartialXsec[ j ].GetXsec( anEnergy ); // x in barn
693  if ( x > 0 )
694  {
695  sum += x;
696  }
697  dif [ j ] = sum;
698  //G4cout << "j " << j << ", x " << x << ", dif " << dif [ j ] << G4endl;
699  }
700 
701  G4double rand = G4UniformRand();
702 
703  G4int iphoton = 0;
704  for ( G4int j = 0 ; j < nDiscrete ; j++ )
705  {
706  G4double y = rand*sum;
707  if ( dif [ j ] > y )
708  {
709  iphoton = j;
710  break;
711  }
712  }
713  //G4cout << "iphoton " << iphoton << G4endl;
714  //G4cout << "photon energy " << theGammas[ iphoton ] /eV << G4endl;
715 
716 // Angle
717  G4double cosTheta = 0.0; // mu
718 
719  if ( isoFlag == 1 )
720  {
721 
722 // Isotropic Case
723 
724  cosTheta = 2.*G4UniformRand()-1;
725 
726  }
727  else
728  {
729 
730  if ( iphoton < nIso )
731  {
732 
733 // still Isotropic
734 
735  cosTheta = 2.*G4UniformRand()-1;
736 
737  }
738  else
739  {
740 
741  //G4cout << "Not Isotropic and isoFlag " << isoFlag << G4endl;
742  //G4cout << "tabulationType " << tabulationType << G4endl;
743  //G4cout << "nDiscrete2 " << nDiscrete2 << G4endl;
744  //G4cout << "nIso " << nIso << G4endl;
745  //G4cout << "size of nNeu " << nDiscrete2-nIso << G4endl;
746  //G4cout << "nNeu[iphoton-nIso] " << nNeu[iphoton-nIso] << G4endl;
747 
748  if ( tabulationType == 1 )
749  {
750 // legendre polynomials
751 
752  G4int iangle = 0;
753  for ( G4int j = 0 ; j < nNeu [ iphoton - nIso ] ; j++ )
754  {
755  iangle = j;
756  if ( theLegendre[ iphoton - nIso ][ j ].GetEnergy() > anEnergy ) break;
757  }
758 
759  G4ParticleHPLegendreStore aStore( 2 );
760  aStore.SetCoeff( 1 , &( theLegendre[ iphoton - nIso ][ iangle ] ) );
761  aStore.SetCoeff( 0 , &( theLegendre[ iphoton - nIso ][ iangle - 1 ] ) );
762 
763  cosTheta = aStore.SampleMax( anEnergy );
764 
765  }
766  else if ( tabulationType == 2 )
767  {
768 
769 // tabulation of probabilities.
770 
771  G4int iangle = 0;
772  for ( G4int j = 0 ; j < nNeu [ iphoton - nIso ] ; j++ )
773  {
774  iangle = j;
775  if ( theAngular[ iphoton - nIso ][ j ].GetEnergy() > anEnergy ) break;
776  }
777 
778  cosTheta = theAngular[iphoton-nIso][ iangle ].GetCosTh(); // no interpolation yet @@
779 
780  }
781  }
782  }
783 
784 // Set
785  G4double phi = twopi*G4UniformRand();
786  G4double theta = std::acos( cosTheta );
787  G4double sinTheta = std::sin( theta );
788 
789  G4double photonE = theGammas[ iphoton ];
790  G4ThreeVector direction ( sinTheta*std::cos( phi ) , sinTheta * std::sin( phi ) , cosTheta );
791  G4ThreeVector photonP = photonE * direction;
792  thePhotons->operator[]( 0 )->SetMomentum( photonP ) ;
793 
794  }
795  else
796  {
797  delete thePhotons;
798  thePhotons = 0; // no gamma data available; some work needed @@@@@@@
799  }
800  return thePhotons;
801 }
802 
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)
const G4double pi
G4InterpolationManager theLegendreManager
void Init(std::istream &aDataFile)
G4ParticleHPAngularP ** theAngular
G4ParticleHPVector * thePartialXsec
G4double GetCosTh(G4int l)
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:95
G4GLOB_DLL std::ostream G4cout
G4bool InitMean(std::istream &aDataFile)
bool G4bool
Definition: G4Types.hh:79
void SetTotalEnergy(const G4double en)
G4double GetX(G4int i) const
G4double GetY(G4double x)
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
static const double eV
Definition: G4SIunits.hh:194
G4double GetTotalEnergy() const
G4double GetPDGMass() const
void SetCoeff(G4int i, G4int l, G4double coeff)
G4ReactionProductVector * GetPhotons(G4double anEnergy)
static G4Electron * Electron()
Definition: G4Electron.cc:94
#define G4endl
Definition: G4ios.hh:61
static const double keV
Definition: G4SIunits.hh:195
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)