Geant4  10.02.p01
G4ParticleHPElasticFS.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 // 25-08-06 New Final State type (refFlag==3 , Legendre (Low Energy) + Probability (High Energy) )
31 // is added by T. KOI
32 // 080904 Add Protection for negative energy results in very low energy ( 1E-6 eV ) scattering by T. Koi
33 //
34 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
35 //
36 #include "G4ParticleHPElasticFS.hh"
37 #include "G4ParticleHPManager.hh"
38 
39 #include "G4PhysicalConstants.hh"
40 #include "G4SystemOfUnits.hh"
41 #include "G4ReactionProduct.hh"
42 #include "G4Nucleus.hh"
43 #include "G4Proton.hh"
44 #include "G4Deuteron.hh"
45 #include "G4Triton.hh"
46 #include "G4Alpha.hh"
47 #include "G4ThreeVector.hh"
48 #include "G4LorentzVector.hh"
49 #include "G4IonTable.hh"
50 #include "G4ParticleHPDataUsed.hh"
51 #include "G4Pow.hh"
52 #include "zlib.h"
53 
55  {
56  G4String tString = "/FS";
57  G4bool dbool;
58  G4ParticleHPDataUsed aFile = theNames.GetName(static_cast<G4int>(A), static_cast<G4int>(Z), M, dirName, tString, dbool);
59  G4String filename = aFile.GetName();
60  SetAZMs( A, Z, M, aFile );
61  //theBaseA = aFile.GetA();
62  //theBaseZ = aFile.GetZ();
63  if(!dbool)
64  {
65  hasAnyData = false;
66  hasFSData = false;
67  hasXsec = false;
68  return;
69  }
70  //130205 For compressed data files
71  std::istringstream theData(std::ios::in);
73  //130205 END
74  theData >> repFlag >> targetMass >> frameFlag;
75  if(repFlag==1)
76  {
77  G4int nEnergy;
78  theData >> nEnergy;
81  G4double temp, energy;
82  G4int tempdep, nLegendre;
83  G4int i, ii;
84  for (i=0; i<nEnergy; i++)
85  {
86  theData >> temp >> energy >> tempdep >> nLegendre;
87  energy *=eV;
88  theCoefficients->Init(i, energy, nLegendre);
90  G4double coeff=0;
91  for(ii=0; ii<nLegendre; ii++)
92  {
93  // load legendre coefficients.
94  theData >> coeff;
95  theCoefficients->SetCoeff(i, ii+1, coeff); // @@@HPW@@@
96  }
97  }
98  }
99  else if (repFlag==2)
100  {
101  G4int nEnergy;
102  theData >> nEnergy;
103  theProbArray = new G4ParticleHPPartial(nEnergy, nEnergy);
105  G4double temp, energy;
106  G4int tempdep, nPoints;
107  for(G4int i=0; i<nEnergy; i++)
108  {
109  theData >> temp >> energy >> tempdep >> nPoints;
110  energy *= eV;
111  theProbArray->InitInterpolation(i, theData);
112  theProbArray->SetT(i, temp);
113  theProbArray->SetX(i, energy);
114  G4double prob, costh;
115  for(G4int ii=0; ii<nPoints; ii++)
116  {
117  // fill probability arrays.
118  theData >> costh >> prob;
119  theProbArray->SetX(i, ii, costh);
120  theProbArray->SetY(i, ii, prob);
121  }
122  theProbArray->DoneSetXY( i );
123  }
124  }
125  else if ( repFlag==3 )
126  {
127  G4int nEnergy_Legendre;
128  theData >> nEnergy_Legendre;
129  theCoefficients = new G4ParticleHPLegendreStore( nEnergy_Legendre );
131  G4double temp, energy;
132  G4int tempdep, nLegendre;
133  //G4int i, ii;
134  for ( G4int i = 0 ; i < nEnergy_Legendre ; i++ )
135  {
136  theData >> temp >> energy >> tempdep >> nLegendre;
137  energy *=eV;
138  theCoefficients->Init( i , energy , nLegendre );
139  theCoefficients->SetTemperature( i , temp );
140  G4double coeff = 0;
141  for (G4int ii = 0 ; ii < nLegendre ; ii++ )
142  {
143  // load legendre coefficients.
144  theData >> coeff;
145  theCoefficients->SetCoeff(i, ii+1, coeff); // @@@HPW@@@
146  }
147  }
148 
150 
151  G4int nEnergy_Prob;
152  theData >> nEnergy_Prob;
153  theProbArray = new G4ParticleHPPartial( nEnergy_Prob , nEnergy_Prob );
154  theProbArray->InitInterpolation( theData );
155  G4int nPoints;
156  for ( G4int i=0 ; i < nEnergy_Prob ; i++ )
157  {
158  theData >> temp >> energy >> tempdep >> nPoints;
159 
160  energy *= eV;
161 
162 // consistency check
163  if ( i == 0 )
164  //if ( energy != tE_of_repFlag3 ) //110620TK This is too tight for 32bit machines
165  if ( std::abs( energy - tE_of_repFlag3 ) / tE_of_repFlag3 > 1.0e-15 )
166  G4cout << "Warning Transition Energy of repFlag3 is not consistent." << G4endl;
167 
168  theProbArray->InitInterpolation( i , theData );
169  theProbArray->SetT( i , temp );
170  theProbArray->SetX( i , energy );
171  G4double prob, costh;
172  for( G4int ii = 0 ; ii < nPoints ; ii++ )
173  {
174  // fill probability arrays.
175  theData >> costh >> prob;
176  theProbArray->SetX( i , ii , costh );
177  theProbArray->SetY( i , ii , prob );
178  }
179  theProbArray->DoneSetXY( i );
180  }
181  }
182  else if (repFlag==0)
183  {
184  theData >> frameFlag;
185  }
186  else
187  {
188  G4cout << "unusable number for repFlag: repFlag="<<repFlag<<G4endl;
189  throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPElasticFS::Init -- unusable number for repFlag");
190  }
191  //130205 For compressed data files(theData changed from ifstream to istringstream)
192  //theData.close();
193  }
195  {
196 // G4cout << "G4ParticleHPElasticFS::ApplyYourself+"<<G4endl;
197  if ( theResult.Get() == NULL ) theResult.Put( new G4HadFinalState );
198  theResult.Get()->Clear();
199  G4double eKinetic = theTrack.GetKineticEnergy();
200  const G4HadProjectile *incidentParticle = &theTrack;
201  G4ReactionProduct theNeutron( const_cast<G4ParticleDefinition *>(incidentParticle->GetDefinition() ));
202  theNeutron.SetMomentum( incidentParticle->Get4Momentum().vect() );
203  theNeutron.SetKineticEnergy( eKinetic );
204 // G4cout << "G4ParticleHPElasticFS::ApplyYourself++"<<eKinetic<<" "<<G4endl;
205 // G4cout << "CMSVALUES 0 "<<theNeutron.GetTotalMomentum()<<G4endl;
206 
208  G4Nucleus aNucleus;
209  G4ThreeVector neuVelo = (1./incidentParticle->GetDefinition()->GetPDGMass())*theNeutron.GetMomentum();
210  theTarget = aNucleus.GetBiasedThermalNucleus( targetMass, neuVelo, theTrack.GetMaterial()->GetTemperature());
211  //t theTarget.SetDefinition( G4IonTable::GetIonTable()->GetIon( G4int(theBaseZ), G4int(theBaseA) , 0.0 ) ); //TESTPHP
212 // G4cout << "Nucleus-test"<<" "<<targetMass<<" ";
213 // G4cout << theTarget.GetMomentum().x()<<" ";
214 // G4cout << theTarget.GetMomentum().y()<<" ";
215 // G4cout << theTarget.GetMomentum().z()<<G4endl;
216 
217  // neutron and target defined as reaction products.
218 
219 // prepare lorentz-transformation to Lab.
220 
221  G4ThreeVector the3Neutron = theNeutron.GetMomentum();
222  G4double nEnergy = theNeutron.GetTotalEnergy();
223  G4ThreeVector the3Target = theTarget.GetMomentum();
224 // cout << "@@@" << the3Target<<G4endl;
225  G4double tEnergy = theTarget.GetTotalEnergy();
226  G4ReactionProduct theCMS;
227  G4double totE = nEnergy+tEnergy;
228  G4ThreeVector the3CMS = the3Target+the3Neutron;
229  theCMS.SetMomentum(the3CMS);
230  G4double cmsMom = std::sqrt(the3CMS*the3CMS);
231  G4double sqrts = std::sqrt((totE-cmsMom)*(totE+cmsMom));
232  theCMS.SetMass(sqrts);
233  theCMS.SetTotalEnergy(totE);
234 
235  // data come as fcn of n-energy in nuclear rest frame
236  G4ReactionProduct boosted;
237  boosted.Lorentz(theNeutron, theTarget);
238  eKinetic = boosted.GetKineticEnergy(); // get kinetic energy for scattering
239  G4double cosTh = -2;
240  if(repFlag == 1)
241  {
242  cosTh = theCoefficients->SampleElastic(eKinetic);
243  }
244 
245  else if (repFlag==2)
246  {
247  cosTh = theProbArray->Sample(eKinetic);
248  }
249  else if (repFlag==3)
250  {
251  if ( eKinetic <= tE_of_repFlag3 )
252  {
253  cosTh = theCoefficients->SampleElastic(eKinetic);
254  }
255  else
256  {
257  cosTh = theProbArray->Sample(eKinetic);
258  }
259  }
260  else if (repFlag==0)
261  {
262  cosTh = 2.*G4UniformRand()-1.;
263  }
264  else
265  {
266  G4cout << "unusable number for repFlag: repFlag="<<repFlag<<G4endl;
267  throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPElasticFS::Init -- unusable number for repFlag");
268  }
269  if(cosTh<-1.1) { return 0; }
270  G4double phi = twopi*G4UniformRand();
271  G4double theta = std::acos(cosTh);
272  G4double sinth = std::sin(theta);
273  if (frameFlag == 1) // final state data given in target rest frame.
274  {
275  // we have the scattering angle, now we need the energy, then do the
276  // boosting.
277  // relativistic elastic scattering energy angular correlation:
278  theNeutron.Lorentz(theNeutron, theTarget);
279  G4double e0 = theNeutron.GetTotalEnergy();
280  G4double p0 = theNeutron.GetTotalMomentum();
281  G4double mN = theNeutron.GetMass();
282  G4double mT = theTarget.GetMass();
283  G4double eE = e0+mT;
284  G4double ap = (mT+eE)*(mT-eE) + (p0+mN)*(p0-mN);
285  G4double a = 4*(eE+p0*cosTh)*(eE-p0*cosTh);
286  G4double b = 4*ap*p0*cosTh;
287  G4double c = (2.*eE*mN-ap)*(2.*eE*mN+ap);
288  G4double en = (-b+std::sqrt(b*b - 4*a*c) )/(2*a);
289  G4ThreeVector tempVector(en*sinth*std::cos(phi), en*sinth*std::sin(phi), en*std::cos(theta) );
290  theNeutron.SetMomentum(tempVector);
291  theNeutron.SetTotalEnergy(std::sqrt(en*en+theNeutron.GetMass()*theNeutron.GetMass()));
292  // first to lab
293  theNeutron.Lorentz(theNeutron, -1.*theTarget);
294  // now to CMS
295  theNeutron.Lorentz(theNeutron, theCMS);
296  theTarget.SetMomentum(-theNeutron.GetMomentum());
297  theTarget.SetTotalEnergy(theNeutron.GetTotalEnergy());
298  // and back to lab
299  theNeutron.Lorentz(theNeutron, -1.*theCMS);
300  theTarget.Lorentz(theTarget, -1.*theCMS);
301 //111005 Protection for not producing 0 kinetic energy target
302  if ( theNeutron.GetKineticEnergy() <= 0 ) theNeutron.SetTotalEnergy ( theNeutron.GetMass() * ( 1 + G4Pow::GetInstance()->powA( 10 , -15.65 ) ) );
303  if ( theTarget.GetKineticEnergy() <= 0 ) theTarget.SetTotalEnergy ( theTarget.GetMass() * ( 1 + G4Pow::GetInstance()->powA( 10 , -15.65 ) ) );
304  }
305  else if (frameFlag == 2) // CMS
306  {
307  theNeutron.Lorentz(theNeutron, theCMS);
308  theTarget.Lorentz(theTarget, theCMS);
309  G4double en = theNeutron.GetTotalMomentum(); // already in CMS.
310  G4ThreeVector cmsMom_tmp=theNeutron.GetMomentum(); // for neutron direction in CMS
311  G4double cms_theta=cmsMom_tmp.theta();
312  G4double cms_phi=cmsMom_tmp.phi();
313  G4ThreeVector tempVector;
314  tempVector.setX(std::cos(theta)*std::sin(cms_theta)*std::cos(cms_phi)
315  +std::sin(theta)*std::cos(phi)*std::cos(cms_theta)*std::cos(cms_phi)
316  -std::sin(theta)*std::sin(phi)*std::sin(cms_phi) );
317  tempVector.setY(std::cos(theta)*std::sin(cms_theta)*std::sin(cms_phi)
318  +std::sin(theta)*std::cos(phi)*std::cos(cms_theta)*std::sin(cms_phi)
319  +std::sin(theta)*std::sin(phi)*std::cos(cms_phi) );
320  tempVector.setZ(std::cos(theta)*std::cos(cms_theta)
321  -std::sin(theta)*std::cos(phi)*std::sin(cms_theta) );
322  tempVector *= en;
323  theNeutron.SetMomentum(tempVector);
324  theTarget.SetMomentum(-tempVector);
325  G4double tP = theTarget.GetTotalMomentum();
326  G4double tM = theTarget.GetMass();
327  theTarget.SetTotalEnergy(std::sqrt((tP+tM)*(tP+tM)-2.*tP*tM));
328 
329 /*
330 For debug purpose.
331 Same transformation G4ReactionProduct.Lorentz() by 4vectors
332 {
333 G4LorentzVector n4p = G4LorentzVector ( theNeutron.GetMomentum() , theNeutron.GetKineticEnergy() + theNeutron.GetMass() );
334 G4cout << "before " << ( n4p.e() - n4p.m() ) / eV<< G4endl;
335 G4LorentzVector cm4p = G4LorentzVector ( theCMS.GetMomentum() , theCMS.GetKineticEnergy() + theCMS.GetMass() );
336 n4p.boost( cm4p.boostVector() );
337 G4cout << cm4p/eV << G4endl;
338 G4cout << "after " << ( n4p.e() - n4p.m() ) / eV<< G4endl;
339 }
340 */
341 
342  theNeutron.Lorentz(theNeutron, -1.*theCMS);
343 //080904 Add Protection for very low energy (1e-6eV) scattering
344  if ( theNeutron.GetKineticEnergy() <= 0 )
345  {
346  //theNeutron.SetMomentum( G4ThreeVector(0) );
347  //theNeutron.SetTotalEnergy ( theNeutron.GetMass() );
348 //110822 Protection for not producing 0 kinetic energy neutron
349  theNeutron.SetTotalEnergy ( theNeutron.GetMass() * ( 1 + G4Pow::GetInstance()->powA( 10 , -15.65 ) ) );
350  }
351 
352  theTarget.Lorentz(theTarget, -1.*theCMS);
353 //080904 Add Protection for very low energy (1e-6eV) scattering
354  if ( theTarget.GetKineticEnergy() < 0 )
355  {
356  //theTarget.SetMomentum( G4ThreeVector(0) );
357  //theTarget.SetTotalEnergy ( theTarget.GetMass() );
358 //110822 Protection for not producing 0 kinetic energy target
359  theTarget.SetTotalEnergy ( theTarget.GetMass() * ( 1 + G4Pow::GetInstance()->powA( 10 , -15.65 ) ) );
360  }
361  }
362  else
363  {
364  G4cout <<"Value of frameFlag (1=LAB, 2=CMS): "<<frameFlag;
365  throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPElasticFS::ApplyYourSelf frameflag incorrect");
366  }
367  // now all in Lab
368 // nun den recoil generieren...und energy change, momentum change angeben.
370  theResult.Get()->SetMomentumChange(theNeutron.GetMomentum().unit());
371  G4DynamicParticle* theRecoil = new G4DynamicParticle;
372  theRecoil->SetDefinition( G4IonTable::GetIonTable()->GetIon(static_cast<G4int>(theBaseZ), static_cast<G4int>(theBaseA), 0 ) );
373  theRecoil->SetMomentum(theTarget.GetMomentum());
374  theResult.Get()->AddSecondary(theRecoil);
375 // G4cout << "G4ParticleHPElasticFS::ApplyYourself 10+"<<G4endl;
376  // postpone the tracking of the primary neutron
378  return theResult.Get();
379  }
static G4ParticleHPManager * GetInstance()
static G4Pow * GetInstance()
Definition: G4Pow.cc:55
G4double powA(G4double A, G4double y) const
Definition: G4Pow.hh:259
G4ParticleHPPartial * theProbArray
void Init(G4int i, G4double e, G4int n)
G4Cache< G4HadFinalState * > theResult
void SetMomentum(const G4ThreeVector &momentum)
G4double GetTotalMomentum() const
void Lorentz(const G4ReactionProduct &p1, const G4ReactionProduct &p2)
CLHEP::Hep3Vector G4ThreeVector
void InitInterpolation(G4int i, std::istream &aDataFile)
void SetKineticEnergy(const G4double en)
void SetMomentum(const G4double x, const G4double y, const G4double z)
value_type & Get() const
Definition: G4Cache.hh:282
void SetY(G4int i, G4int j, G4double y)
void SetAZMs(G4double anA, G4double aZ, G4int aM, G4ParticleHPDataUsed used)
void GetDataStream(G4String, std::istringstream &iss)
G4double a
Definition: TRTMaterials.hh:39
int G4int
Definition: G4Types.hh:78
void InitInterpolation(std::istream &aDataFile)
void SetStatusChange(G4HadFinalStateStatus aS)
void Init(G4double A, G4double Z, G4int M, G4String &dirName, G4String &aFSType, G4ParticleDefinition *)
G4ReactionProduct GetBiasedThermalNucleus(G4double aMass, G4ThreeVector aVelocity, G4double temp=-1) const
Definition: G4Nucleus.cc:113
void SetMass(const G4double mas)
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
double A(double temperature)
const G4ParticleDefinition * GetDefinition() const
G4double Sample(G4double x)
bool G4bool
Definition: G4Types.hh:79
G4double GetKineticEnergy() const
void SetTotalEnergy(const G4double en)
static const double twopi
Definition: G4SIunits.hh:75
G4HadFinalState * ApplyYourself(const G4HadProjectile &theTrack)
G4ErrorTarget * theTarget
Definition: errprop.cc:59
const G4LorentzVector & Get4Momentum() const
G4ParticleHPLegendreStore * theCoefficients
static G4IonTable * GetIonTable()
Definition: G4IonTable.hh:78
G4double GetKineticEnergy() const
void SetTemperature(G4int i, G4double temp)
void SetX(G4int i, G4double x)
static const double eV
Definition: G4SIunits.hh:212
void SetEnergyChange(G4double anEnergy)
G4double SampleElastic(G4double anEnergy)
G4double GetTotalEnergy() const
G4double GetPDGMass() const
G4double energy(const ThreeVector &p, const G4double m)
void SetCoeff(G4int i, G4int l, G4double coeff)
G4ThreeVector GetMomentum() const
G4double GetTemperature() const
Definition: G4Material.hh:182
#define G4endl
Definition: G4ios.hh:61
G4ParticleHPDataUsed GetName(G4int A, G4int Z, G4String base, G4String rest, G4bool &active)
void SetT(G4int i, G4double x)
const G4Material * GetMaterial() const
void AddSecondary(G4DynamicParticle *aP, G4int mod=-1)
double G4double
Definition: G4Types.hh:76
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
void Put(const value_type &val) const
Definition: G4Cache.hh:286
void SetMomentumChange(const G4ThreeVector &aV)
G4double GetMass() const