| 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 | // 080808 Bug fix in serching mu bin and index for theBuff2b by T. Koi
|
|---|
| 31 | //
|
|---|
| 32 | #include "G4NeutronHPLabAngularEnergy.hh"
|
|---|
| 33 | #include "G4Gamma.hh"
|
|---|
| 34 | #include "G4Electron.hh"
|
|---|
| 35 | #include "G4Positron.hh"
|
|---|
| 36 | #include "G4Neutron.hh"
|
|---|
| 37 | #include "G4Proton.hh"
|
|---|
| 38 | #include "G4Deuteron.hh"
|
|---|
| 39 | #include "G4Triton.hh"
|
|---|
| 40 | #include "G4He3.hh"
|
|---|
| 41 | #include "G4Alpha.hh"
|
|---|
| 42 | #include "Randomize.hh"
|
|---|
| 43 |
|
|---|
| 44 | void G4NeutronHPLabAngularEnergy::Init(std::ifstream & aDataFile)
|
|---|
| 45 | {
|
|---|
| 46 | aDataFile >> nEnergies;
|
|---|
| 47 | theManager.Init(aDataFile);
|
|---|
| 48 | theEnergies = new G4double[nEnergies];
|
|---|
| 49 | nCosTh = new G4int[nEnergies];
|
|---|
| 50 | theData = new G4NeutronHPVector * [nEnergies];
|
|---|
| 51 | theSecondManager = new G4InterpolationManager [nEnergies];
|
|---|
| 52 | for(G4int i=0; i<nEnergies; i++)
|
|---|
| 53 | {
|
|---|
| 54 | aDataFile >> theEnergies[i];
|
|---|
| 55 | theEnergies[i]*=eV;
|
|---|
| 56 | aDataFile >> nCosTh[i];
|
|---|
| 57 | theSecondManager[i].Init(aDataFile);
|
|---|
| 58 | theData[i] = new G4NeutronHPVector[nCosTh[i]];
|
|---|
| 59 | G4double label;
|
|---|
| 60 | for(G4int ii=0; ii<nCosTh[i]; ii++)
|
|---|
| 61 | {
|
|---|
| 62 | aDataFile >> label;
|
|---|
| 63 | theData[i][ii].SetLabel(label);
|
|---|
| 64 | theData[i][ii].Init(aDataFile, eV);
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | G4ReactionProduct * G4NeutronHPLabAngularEnergy::Sample(G4double anEnergy, G4double massCode, G4double )
|
|---|
| 70 | {
|
|---|
| 71 | G4ReactionProduct * result = new G4ReactionProduct;
|
|---|
| 72 | G4int Z = static_cast<G4int>(massCode/1000);
|
|---|
| 73 | G4int A = static_cast<G4int>(massCode-1000*Z);
|
|---|
| 74 |
|
|---|
| 75 | if(massCode==0)
|
|---|
| 76 | {
|
|---|
| 77 | result->SetDefinition(G4Gamma::Gamma());
|
|---|
| 78 | }
|
|---|
| 79 | else if(A==0)
|
|---|
| 80 | {
|
|---|
| 81 | result->SetDefinition(G4Electron::Electron());
|
|---|
| 82 | if(Z==1) result->SetDefinition(G4Positron::Positron());
|
|---|
| 83 | }
|
|---|
| 84 | else if(A==1)
|
|---|
| 85 | {
|
|---|
| 86 | result->SetDefinition(G4Neutron::Neutron());
|
|---|
| 87 | if(Z==1) result->SetDefinition(G4Proton::Proton());
|
|---|
| 88 | }
|
|---|
| 89 | else if(A==2)
|
|---|
| 90 | {
|
|---|
| 91 | result->SetDefinition(G4Deuteron::Deuteron());
|
|---|
| 92 | }
|
|---|
| 93 | else if(A==3)
|
|---|
| 94 | {
|
|---|
| 95 | result->SetDefinition(G4Triton::Triton());
|
|---|
| 96 | if(Z==2) result->SetDefinition(G4He3::He3());
|
|---|
| 97 | }
|
|---|
| 98 | else if(A==4)
|
|---|
| 99 | {
|
|---|
| 100 | result->SetDefinition(G4Alpha::Alpha());
|
|---|
| 101 | if(Z!=2) throw G4HadronicException(__FILE__, __LINE__, "Unknown ion case 1");
|
|---|
| 102 | }
|
|---|
| 103 | else
|
|---|
| 104 | {
|
|---|
| 105 | throw G4HadronicException(__FILE__, __LINE__, "G4NeutronHPLabAngularEnergy: Unknown ion case 2");
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | // get theta, E
|
|---|
| 109 | G4double cosTh, secEnergy;
|
|---|
| 110 | G4int i, it(0);
|
|---|
| 111 | // find the energy bin
|
|---|
| 112 | for(i=0; i<nEnergies; i++)
|
|---|
| 113 | {
|
|---|
| 114 | it = i;
|
|---|
| 115 | if ( anEnergy < theEnergies[i] ) break;
|
|---|
| 116 | }
|
|---|
| 117 | //080808
|
|---|
| 118 | //if ( it == 0 || it == nEnergies-1 ) // it marks the energy bin
|
|---|
| 119 | if ( it == 0 ) // it marks the energy bin
|
|---|
| 120 | {
|
|---|
| 121 | if(it==0) G4cout << "080808 Something unexpected is happen in G4NeutronHPLabAngularEnergy " << G4endl;
|
|---|
| 122 | // integrate the prob for each costh, and select theta.
|
|---|
| 123 | G4double * running = new G4double [nCosTh[it]];
|
|---|
| 124 | running[0]=0;
|
|---|
| 125 | for(i=0;i<nCosTh[it]; i++)
|
|---|
| 126 | {
|
|---|
| 127 | if(i!=0) running[i] = running[i-1];
|
|---|
| 128 | running[i]+=theData[it][i].GetIntegral(); // Does interpolated integral.
|
|---|
| 129 | }
|
|---|
| 130 | G4double random = running[nCosTh[it]-1]*G4UniformRand();
|
|---|
| 131 | G4int ith(0);
|
|---|
| 132 | for(i=0;i<nCosTh[it]; i++)
|
|---|
| 133 | {
|
|---|
| 134 | ith = i;
|
|---|
| 135 | if(random<running[i]) break;
|
|---|
| 136 | }
|
|---|
| 137 | //080807
|
|---|
| 138 | //if ( ith == 0 || ith == nCosTh[it]-1 ) //ith marks the angluar bin
|
|---|
| 139 | if ( ith == 0 ) //ith marks the angluar bin
|
|---|
| 140 | {
|
|---|
| 141 | cosTh = theData[it][ith].GetLabel();
|
|---|
| 142 | secEnergy = theData[it][ith].Sample();
|
|---|
| 143 | currentMeanEnergy = theData[it][ith].GetMeanX();
|
|---|
| 144 | }
|
|---|
| 145 | else
|
|---|
| 146 | {
|
|---|
| 147 | //080808
|
|---|
| 148 | //G4double x1 = theData[it][ith-1].GetIntegral();
|
|---|
| 149 | //G4double x2 = theData[it][ith].GetIntegral();
|
|---|
| 150 | G4double x1 = running [ ith-1 ];
|
|---|
| 151 | G4double x2 = running [ ith ];
|
|---|
| 152 | G4double x = random;
|
|---|
| 153 | G4double y1 = theData[it][ith-1].GetLabel();
|
|---|
| 154 | G4double y2 = theData[it][ith].GetLabel();
|
|---|
| 155 | cosTh = theInt.Interpolate(theSecondManager[it].GetInverseScheme(ith),
|
|---|
| 156 | x, x1, x2, y1, y2);
|
|---|
| 157 | G4NeutronHPVector theBuff1;
|
|---|
| 158 | theBuff1.SetInterpolationManager(theData[it][ith-1].GetInterpolationManager());
|
|---|
| 159 | G4NeutronHPVector theBuff2;
|
|---|
| 160 | theBuff2.SetInterpolationManager(theData[it][ith].GetInterpolationManager());
|
|---|
| 161 | x1=y1;
|
|---|
| 162 | x2=y2;
|
|---|
| 163 | G4double y, mu;
|
|---|
| 164 | for(i=0;i<theData[it][ith-1].GetVectorLength(); i++)
|
|---|
| 165 | {
|
|---|
| 166 | mu = theData[it][ith-1].GetX(i);
|
|---|
| 167 | y1 = theData[it][ith-1].GetY(i);
|
|---|
| 168 | y2 = theData[it][ith].GetY(mu);
|
|---|
| 169 |
|
|---|
| 170 | y = theInt.Interpolate(theSecondManager[it].GetScheme(ith),
|
|---|
| 171 | cosTh, x1,x2,y1,y2);
|
|---|
| 172 | theBuff1.SetData(i, mu, y);
|
|---|
| 173 | }
|
|---|
| 174 | for(i=0;i<theData[it][ith].GetVectorLength(); i++)
|
|---|
| 175 | {
|
|---|
| 176 | mu = theData[it][ith].GetX(i);
|
|---|
| 177 | y1 = theData[it][ith-1].GetY(mu);
|
|---|
| 178 | y2 = theData[it][ith].GetY(i);
|
|---|
| 179 | y = theInt.Interpolate(theSecondManager[it].GetScheme(ith),
|
|---|
| 180 | cosTh, x1,x2,y1,y2);
|
|---|
| 181 | theBuff2.SetData(i, mu, y);
|
|---|
| 182 | }
|
|---|
| 183 | G4NeutronHPVector theStore;
|
|---|
| 184 | theStore.Merge(&theBuff1, &theBuff2);
|
|---|
| 185 | secEnergy = theStore.Sample();
|
|---|
| 186 | currentMeanEnergy = theStore.GetMeanX();
|
|---|
| 187 | }
|
|---|
| 188 | delete [] running;
|
|---|
| 189 | }
|
|---|
| 190 | else // this is the small big else.
|
|---|
| 191 | {
|
|---|
| 192 | G4double x, x1, x2, y1, y2, y, tmp, E;
|
|---|
| 193 | // integrate the prob for each costh, and select theta.
|
|---|
| 194 | G4NeutronHPVector run1;
|
|---|
| 195 | run1.SetY(0, 0.);
|
|---|
| 196 | for(i=0;i<nCosTh[it-1]; i++)
|
|---|
| 197 | {
|
|---|
| 198 | if(i!=0) run1.SetY(i, run1.GetY(i-1));
|
|---|
| 199 | run1.SetX(i, theData[it-1][i].GetLabel());
|
|---|
| 200 | run1.SetY(i, run1.GetY(i)+theData[it-1][i].GetIntegral());
|
|---|
| 201 | }
|
|---|
| 202 | G4NeutronHPVector run2;
|
|---|
| 203 | run2.SetY(0, 0.);
|
|---|
| 204 | for(i=0;i<nCosTh[it]; i++)
|
|---|
| 205 | {
|
|---|
| 206 | if(i!=0) run2.SetY(i, run2.GetY(i-1));
|
|---|
| 207 | run2.SetX(i, theData[it][i].GetLabel());
|
|---|
| 208 | run2.SetY(i, run2.GetY(i)+theData[it][i].GetIntegral());
|
|---|
| 209 | }
|
|---|
| 210 | // get the distributions for the correct neutron energy
|
|---|
| 211 | x = anEnergy;
|
|---|
| 212 | x1 = theEnergies[it-1];
|
|---|
| 213 | x2 = theEnergies[it];
|
|---|
| 214 | G4NeutronHPVector thBuff1; // to be interpolated as run1.
|
|---|
| 215 | thBuff1.SetInterpolationManager(theSecondManager[it-1]);
|
|---|
| 216 | for(i=0; i<run1.GetVectorLength(); i++)
|
|---|
| 217 | {
|
|---|
| 218 | tmp = run1.GetX(i); //theta
|
|---|
| 219 | y1 = run1.GetY(i); // integral
|
|---|
| 220 | y2 = run2.GetY(tmp);
|
|---|
| 221 | y = theInt.Interpolate(theManager.GetScheme(it), x, x1,x2,y1,y2);
|
|---|
| 222 | thBuff1.SetData(i, tmp, y);
|
|---|
| 223 | }
|
|---|
| 224 | G4NeutronHPVector thBuff2;
|
|---|
| 225 | thBuff2.SetInterpolationManager(theSecondManager[it]);
|
|---|
| 226 | for(i=0; i<run2.GetVectorLength(); i++)
|
|---|
| 227 | {
|
|---|
| 228 | tmp = run2.GetX(i); //theta
|
|---|
| 229 | y1 = run1.GetY(tmp); // integral
|
|---|
| 230 | y2 = run2.GetY(i);
|
|---|
| 231 | y = theInt.Lin(x, x1,x2,y1,y2);
|
|---|
| 232 | thBuff2.SetData(i, tmp, y);
|
|---|
| 233 | }
|
|---|
| 234 | G4NeutronHPVector theThVec;
|
|---|
| 235 | theThVec.Merge(&thBuff1 ,&thBuff2); // takes care of interpolation
|
|---|
| 236 | G4double random = (theThVec.GetY(theThVec.GetVectorLength()-1)
|
|---|
| 237 | -theThVec.GetY(0)) *G4UniformRand();
|
|---|
| 238 | G4int ith(0);
|
|---|
| 239 | for(i=1;i<theThVec.GetVectorLength(); i++)
|
|---|
| 240 | {
|
|---|
| 241 | ith = i;
|
|---|
| 242 | if(random<theThVec.GetY(i)-theThVec.GetY(0)) break;
|
|---|
| 243 | }
|
|---|
| 244 | {
|
|---|
| 245 | // calculate theta
|
|---|
| 246 | G4double x, x1, x2, y1, y2;
|
|---|
| 247 | x = random;
|
|---|
| 248 | x1 = theThVec.GetY(ith-1)-theThVec.GetY(0); // integrals
|
|---|
| 249 | x2 = theThVec.GetY(ith)-theThVec.GetY(0);
|
|---|
| 250 | y1 = theThVec.GetX(ith-1); // std::cos(theta)
|
|---|
| 251 | y2 = theThVec.GetX(ith);
|
|---|
| 252 | cosTh = theInt.Interpolate(theSecondManager[it].GetScheme(ith),
|
|---|
| 253 | x, x1,x2,y1,y2);
|
|---|
| 254 | }
|
|---|
| 255 | G4int i1(0), i2(0);
|
|---|
| 256 | // get the indixes of the vectors close to theta for low energy
|
|---|
| 257 | // first it-1 !!!! i.e. low in energy
|
|---|
| 258 | for(i=0; i<nCosTh[it-1]; i++)
|
|---|
| 259 | {
|
|---|
| 260 | i1 = i;
|
|---|
| 261 | if(cosTh<theData[it-1][i].GetLabel()) break;
|
|---|
| 262 | }
|
|---|
| 263 | // now get the prob at this energy for the right theta value
|
|---|
| 264 | x = cosTh;
|
|---|
| 265 | x1 = theData[it-1][i1-1].GetLabel();
|
|---|
| 266 | x2 = theData[it-1][i1].GetLabel();
|
|---|
| 267 | G4NeutronHPVector theBuff1a;
|
|---|
| 268 | theBuff1a.SetInterpolationManager(theData[it-1][i1-1].GetInterpolationManager());
|
|---|
| 269 | for(i=0;i<theData[it-1][i1-1].GetVectorLength(); i++)
|
|---|
| 270 | {
|
|---|
| 271 | E = theData[it-1][i1-1].GetX(i);
|
|---|
| 272 | y1 = theData[it-1][i1-1].GetY(i);
|
|---|
| 273 | y2 = theData[it-1][i1].GetY(E);
|
|---|
| 274 | y = theInt.Lin(x, x1,x2,y1,y2);
|
|---|
| 275 | theBuff1a.SetData(i, E, y); // wrong E, right theta.
|
|---|
| 276 | }
|
|---|
| 277 | G4NeutronHPVector theBuff2a;
|
|---|
| 278 | theBuff2a.SetInterpolationManager(theData[it-1][i1].GetInterpolationManager());
|
|---|
| 279 | for(i=0;i<theData[it-1][i1].GetVectorLength(); i++)
|
|---|
| 280 | {
|
|---|
| 281 | E = theData[it-1][i1].GetX(i);
|
|---|
| 282 | y1 = theData[it-1][i1-1].GetY(E);
|
|---|
| 283 | y2 = theData[it-1][i1].GetY(i);
|
|---|
| 284 | y = theInt.Lin(x, x1,x2,y1,y2);
|
|---|
| 285 | theBuff2a.SetData(i, E, y); // wrong E, right theta.
|
|---|
| 286 | }
|
|---|
| 287 | G4NeutronHPVector theStore1;
|
|---|
| 288 | theStore1.Merge(&theBuff1a, &theBuff2a); // wrong E, right theta, complete binning
|
|---|
| 289 |
|
|---|
| 290 | // get the indixes of the vectors close to theta for high energy
|
|---|
| 291 | // then it !!!! i.e. high in energy
|
|---|
| 292 | for(i=0; i<nCosTh[it]; i++)
|
|---|
| 293 | {
|
|---|
| 294 | i2 = i;
|
|---|
| 295 | if(cosTh<theData[it][i2].GetLabel()) break;
|
|---|
| 296 | } // sonderfaelle mit i1 oder i2 head on fehlen. @@@@@
|
|---|
| 297 | x1 = theData[it][i2-1].GetLabel();
|
|---|
| 298 | x2 = theData[it][i2].GetLabel();
|
|---|
| 299 | G4NeutronHPVector theBuff1b;
|
|---|
| 300 | theBuff1b.SetInterpolationManager(theData[it][i2-1].GetInterpolationManager());
|
|---|
| 301 | for(i=0;i<theData[it][i2-1].GetVectorLength(); i++)
|
|---|
| 302 | {
|
|---|
| 303 | E = theData[it][i2-1].GetX(i);
|
|---|
| 304 | y1 = theData[it][i2-1].GetY(i);
|
|---|
| 305 | y2 = theData[it][i2].GetY(E);
|
|---|
| 306 | y = theInt.Lin(x, x1,x2,y1,y2);
|
|---|
| 307 | theBuff1b.SetData(i, E, y); // wrong E, right theta.
|
|---|
| 308 | }
|
|---|
| 309 | G4NeutronHPVector theBuff2b;
|
|---|
| 310 | theBuff2b.SetInterpolationManager(theData[it][i2].GetInterpolationManager());
|
|---|
| 311 | //080808 i1 -> i2
|
|---|
| 312 | //for(i=0;i<theData[it][i1].GetVectorLength(); i++)
|
|---|
| 313 | for(i=0;i<theData[it][i2].GetVectorLength(); i++)
|
|---|
| 314 | {
|
|---|
| 315 | //E = theData[it][i1].GetX(i);
|
|---|
| 316 | //y1 = theData[it][i1-1].GetY(E);
|
|---|
| 317 | //y2 = theData[it][i1].GetY(i);
|
|---|
| 318 | E = theData[it][i2].GetX(i);
|
|---|
| 319 | y1 = theData[it][i2-1].GetY(E);
|
|---|
| 320 | y2 = theData[it][i2].GetY(i);
|
|---|
| 321 | y = theInt.Lin(x, x1,x2,y1,y2);
|
|---|
| 322 | theBuff2b.SetData(i, E, y); // wrong E, right theta.
|
|---|
| 323 | }
|
|---|
| 324 | G4NeutronHPVector theStore2;
|
|---|
| 325 | theStore2.Merge(&theBuff1b, &theBuff2b); // wrong E, right theta, complete binning
|
|---|
| 326 | // now get to the right energy.
|
|---|
| 327 |
|
|---|
| 328 | x = anEnergy;
|
|---|
| 329 | x1 = theEnergies[it-1];
|
|---|
| 330 | x2 = theEnergies[it];
|
|---|
| 331 | G4NeutronHPVector theOne1;
|
|---|
| 332 | theOne1.SetInterpolationManager(theStore1.GetInterpolationManager());
|
|---|
| 333 | for(i=0; i<theStore1.GetVectorLength(); i++)
|
|---|
| 334 | {
|
|---|
| 335 | E = theStore1.GetX(i);
|
|---|
| 336 | y1 = theStore1.GetY(i);
|
|---|
| 337 | y2 = theStore2.GetY(E);
|
|---|
| 338 | y = theInt.Interpolate(theManager.GetScheme(it), x, x1,x2,y1,y2);
|
|---|
| 339 | theOne1.SetData(i, E, y); // both correct
|
|---|
| 340 | }
|
|---|
| 341 | G4NeutronHPVector theOne2;
|
|---|
| 342 | theOne2.SetInterpolationManager(theStore2.GetInterpolationManager());
|
|---|
| 343 | for(i=0; i<theStore2.GetVectorLength(); i++)
|
|---|
| 344 | {
|
|---|
| 345 | E = theStore2.GetX(i);
|
|---|
| 346 | y1 = theStore1.GetY(E);
|
|---|
| 347 | y2 = theStore2.GetY(i);
|
|---|
| 348 | y = theInt.Interpolate(theManager.GetScheme(it), x, x1,x2,y1,y2);
|
|---|
| 349 | theOne2.SetData(i, E, y); // both correct
|
|---|
| 350 | }
|
|---|
| 351 | G4NeutronHPVector theOne;
|
|---|
| 352 | theOne.Merge(&theOne1, &theOne2); // both correct, complete binning
|
|---|
| 353 |
|
|---|
| 354 | secEnergy = theOne.Sample();
|
|---|
| 355 | currentMeanEnergy = theOne.GetMeanX();
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | // now do random direction in phi, and fill the result.
|
|---|
| 359 |
|
|---|
| 360 | result->SetKineticEnergy(secEnergy);
|
|---|
| 361 |
|
|---|
| 362 | G4double phi = twopi*G4UniformRand();
|
|---|
| 363 | G4double theta = std::acos(cosTh);
|
|---|
| 364 | G4double sinth = std::sin(theta);
|
|---|
| 365 | G4double mtot = result->GetTotalMomentum();
|
|---|
| 366 | G4ThreeVector tempVector(mtot*sinth*std::cos(phi), mtot*sinth*std::sin(phi), mtot*std::cos(theta) );
|
|---|
| 367 | result->SetMomentum(tempVector);
|
|---|
| 368 |
|
|---|
| 369 | return result;
|
|---|
| 370 | }
|
|---|