Geant4  10.01.p03
G4ParticleHPChannelList.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // neutron_hp -- source file
27 // J.P. Wellisch, Nov-1996
28 // A prototype of the low energy neutron transport model.
29 //
30 // 070523 bug fix for G4FPE_DEBUG on by A. Howard ( and T. Koi)
31 //
32 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
33 //
35 #include "G4Element.hh"
36 #include "G4HadFinalState.hh"
37 #include "G4HadProjectile.hh"
39 
41 
43  :theProjectile(projectile)
44  {
45  nChannels = n;
47  allChannelsCreated = false;
48  theInitCount = 0;
49  }
50 
52  {
53  nChannels = 0;
54  theChannels = 0;
55  allChannelsCreated = false;
56  theInitCount = 0;
57  }
58 
60  {
61  if(theChannels!=0)
62  {
63  for(G4int i=0;i<nChannels; i++)
64  {
65  delete theChannels[i];
66  }
67  delete [] theChannels;
68  }
69  }
70 
72  #include "G4ParticleHPManager.hh"
74  {
75  G4ParticleHPThermalBoost aThermalE;
76  G4int i, ii;
77  // decide on the isotope
78  G4int numberOfIsos(0);
79  for(ii=0; ii<nChannels; ii++)
80  {
81  numberOfIsos = theChannels[ii]->GetNiso();
82  if(numberOfIsos!=0) break;
83  }
84  G4double * running= new G4double [numberOfIsos];
85  running[0] = 0;
86  for(i=0;i<numberOfIsos; i++)
87  {
88  if(i!=0) running[i] = running[i-1];
89  for(ii=0; ii<nChannels; ii++)
90  {
91  if(theChannels[ii]->HasAnyData(i))
92  {
93  running[i] +=theChannels[ii]->GetWeightedXsec(aThermalE.GetThermalEnergy(aTrack,
94  theChannels[ii]->GetN(i),
95  theChannels[ii]->GetZ(i),
96  aTrack.GetMaterial()->GetTemperature()),
97  i);
98  }
99  }
100  }
101  G4int isotope=nChannels-1;
102  G4double random=G4UniformRand();
103  for(i=0;i<numberOfIsos; i++)
104  {
105  isotope = i;
106  //if(random<running[i]/running[numberOfIsos-1]) break;
107  if(running[numberOfIsos-1] != 0) if(random<running[i]/running[numberOfIsos-1]) break;
108  }
109  delete [] running;
110 
111  // decide on the channel
112  running = new G4double[nChannels];
113  running[0]=0;
114  G4int targA=-1; // For production of unChanged
115  G4int targZ=-1;
116  for(i=0; i<nChannels; i++)
117  {
118  if(i!=0) running[i] = running[i-1];
119  if(theChannels[i]->HasAnyData(isotope))
120  {
121  targA=(G4int)theChannels[i]->GetN(isotope); //Will be simply used the last valid value
122  targZ=(G4int)theChannels[i]->GetZ(isotope);
123  running[i] += theChannels[i]->GetFSCrossSection(aThermalE.GetThermalEnergy(aTrack,
124  targA,
125  targZ,
126  aTrack.GetMaterial()->GetTemperature()),
127  isotope);
128  targA=(G4int)theChannels[i]->GetN(isotope); //Will be simply used the last valid value
129  targZ=(G4int)theChannels[i]->GetZ(isotope);
130  // G4cout << " G4ParticleHPChannelList " << i << " targA " << targA << " targZ " << targZ << " running " << running[i] << G4endl;
131  }
132  }
133 
134  //TK120607
135  if ( running[nChannels-1] == 0 )
136  {
137  //This happened usually by the miss match between the cross section data and model
138  if ( targA == -1 && targZ == -1 ) {
139  throw G4HadronicException(__FILE__, __LINE__, "ParticleHP model encounter lethal discrepancy with cross section data");
140  }
141 
142  //TK121106
143  G4cout << "Warning from NeutronHP: could not find proper reaction channel. This may cause by inconsistency between cross section and model. Unchanged final states are returned." << G4endl;
144  unChanged.Clear();
145 
146  //For Ep Check create unchanged final state including rest target
147  G4ParticleDefinition* targ_pd = G4IonTable::GetIonTable()->GetIon ( targZ , targA , 0.0 );
148  G4DynamicParticle* targ_dp = new G4DynamicParticle( targ_pd , G4ThreeVector(1,0,0), 0.0 );
150  unChanged.SetMomentumChange(aTrack.Get4Momentum().vect() );
151  unChanged.AddSecondary(targ_dp);
152  //TK121106
155  return &unChanged;
156  }
157  //TK120607
158 
159 
160  G4int lChan=0;
161  random=G4UniformRand();
162  for(i=0; i<nChannels; i++)
163  {
164  lChan = i;
165  if(running[nChannels-1] != 0) if(random<running[i]/running[nChannels-1]) break;
166  }
167  delete [] running;
168 #ifdef G4PHPDEBUG
169  if( getenv("G4ParticleHPDebug") ) G4cout << " G4ParticleHPChannelList SELECTED ISOTOPE " << isotope << " SELECTED CHANNEL " << lChan << G4endl;
170 #endif
171  return theChannels[lChan]->ApplyYourself(aTrack, isotope);
172  }
173 
174 void G4ParticleHPChannelList::Init(G4Element * anElement, const G4String & dirName, G4ParticleDefinition* projectile )
175  {
176  theDir = dirName;
177 // G4cout << theDir << G4endl;
178  theElement = anElement;
179 // G4cout << theElement << G4endl;
180  theProjectile = projectile;
181  }
182 
184  const G4String & aName )
185  {
186  if(!allChannelsCreated)
187  {
188  if(nChannels!=0)
189  {
190  G4ParticleHPChannel ** theBuffer = new G4ParticleHPChannel * [nChannels+1];
191  G4int i;
192  for(i=0; i<nChannels; i++)
193  {
194  theBuffer[i] = theChannels[i];
195  }
196  delete [] theChannels;
197  theChannels = theBuffer;
198  }
199  else
200  {
202  }
203  G4String name;
204  name = aName+"/";
207  // theChannels[nChannels]->SetProjectile( theProjectile );
208  nChannels++;
209  }
210 
211  //110527TKDB Unnessary codes, Detected by gcc4.6 compiler
212  //G4bool result;
213  //result = theChannels[theInitCount]->Register(theFS);
215  theInitCount++;
216  }
217 
219 
220  G4cout<<"================================================================"<<G4endl;
221  G4cout<<" Element: "<<theElement->GetName()<<G4endl;
222  G4cout<<" Number of channels: "<<nChannels<<G4endl;
223  G4cout<<" Projectile: "<<theProjectile->GetParticleName()<<G4endl;
224  G4cout<<" Directory name: "<<theDir<<G4endl;
225  for(int i=0;i<nChannels;i++){
227  G4cout<<"----------------------------------------------------------------"<<G4endl;
228  theChannels[i]->DumpInfo();
229  G4cout<<"----------------------------------------------------------------"<<G4endl;
230  }
231  }
232  G4cout<<"================================================================"<<G4endl;
233 
234 }
static G4ParticleHPManager * GetInstance()
CLHEP::Hep3Vector G4ThreeVector
G4String name
Definition: TRTMaterials.hh:40
G4ParticleDefinition * GetIon(G4int Z, G4int A, G4int lvl=0)
Definition: G4IonTable.cc:463
static G4ThreadLocal G4int trycounter
G4double GetN(G4int i)
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
G4bool Register(G4ParticleHPFinalState *theFS)
#define G4UniformRand()
Definition: Randomize.hh:93
G4GLOB_DLL std::ostream G4cout
G4double GetKineticEnergy() const
G4double GetZ(G4int i)
void Register(G4ParticleHPFinalState *theFS, const G4String &aName)
void Init(G4Element *theElement, const G4String dirName)
const G4int n
const G4LorentzVector & Get4Momentum() const
static G4IonTable * GetIonTable()
Definition: G4IonTable.hh:78
G4double GetThermalEnergy(const G4HadProjectile &aP, const G4Element *anE, G4double aT)
void SetEnergyChange(G4double anEnergy)
G4double GetFSCrossSection(G4double energy, G4int isoNumber)
G4double GetWeightedXsec(G4double energy, G4int isoNumber)
G4double GetTemperature() const
Definition: G4Material.hh:182
#define G4endl
Definition: G4ios.hh:61
const G4Material * GetMaterial() const
void AddSecondary(G4DynamicParticle *aP, G4int mod=-1)
G4HadFinalState * ApplyYourself(const G4Element *theElement, const G4HadProjectile &aTrack)
double G4double
Definition: G4Types.hh:76
const G4String & GetName() const
Definition: G4Element.hh:127
G4ParticleHPReactionWhiteBoard * GetReactionWhiteBoard()
G4ParticleHPChannel ** theChannels
void SetMomentumChange(const G4ThreeVector &aV)
G4HadFinalState * ApplyYourself(const G4HadProjectile &theTrack, G4int isoNumber=-1)
G4ParticleDefinition * theProjectile