source: trunk/source/processes/hadronic/models/incl/src/G4Incl.cc @ 962

Last change on this file since 962 was 962, checked in by garnier, 15 years ago

update processes

File size: 228.6 KB
Line 
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// $Id: G4Incl.cc,v 1.20 2008/11/06 10:11:27 kaitanie Exp $
27// Translation of INCL4.2/ABLA V3
28// Pekka Kaitaniemi, HIP (translation)
29// Christelle Schmidt, IPNL (fission code)
30// Alain Boudard, CEA (contact person INCL/ABLA)
31// Aatos Heikkinen, HIP (project coordination)
32
33#include "G4Incl.hh"
34#include <iostream>
35#include "Randomize.hh"
36#include "G4InclRandomNumbers.hh"
37#include "G4Ranecu.hh"
38
39G4Incl::G4Incl()
40{
41  verboseLevel = 0;
42
43  // Set functions to be used for integration routine. 
44  wsaxFunction = 0;
45  derivWsaxFunction = 1;
46  dmhoFunction = 2;
47  derivMhoFunction = 3;
48  derivGausFunction = 4;
49  densFunction = 5;
50
51  //  randomGenerator = new G4InclGeant4Random();
52  randomGenerator = new G4Ranecu();
53}
54
55G4Incl::G4Incl(G4Hazard *aHazard, G4Dton *aDton, G4Saxw *aSaxw, G4Ws *aWs)
56{
57  verboseLevel = 0;
58
59  // Set functions to be used for integration routine. 
60  wsaxFunction = 0;
61  derivWsaxFunction = 1;
62  dmhoFunction = 2;
63  derivMhoFunction = 3;
64  derivGausFunction = 4;
65  densFunction = 5;
66
67  // Set input data for testing.
68  hazard = aHazard;
69  dton = aDton;
70  saxw = aSaxw;
71  ws = aWs;
72
73  //randomGenerator = new G4Ranecu();
74  randomGenerator = new G4InclGeant4Random();
75}
76
77G4Incl::G4Incl(G4Hazard *aHazard, G4Calincl *aCalincl, G4Ws *aWs, G4Mat *aMat, G4VarNtp *aVarntp)
78{
79  verboseLevel = 0;
80
81  // Set functions to be used for integration routine.   
82  wsaxFunction = 0;
83  derivWsaxFunction = 1;
84  dmhoFunction = 2;
85  derivMhoFunction = 3;
86  derivGausFunction = 4;
87  densFunction = 5;
88
89  // Set input data for INCL run. 
90  hazard = aHazard;
91  calincl = aCalincl;
92  ws = aWs;
93  mat = aMat;
94  varntp = aVarntp;
95
96  //  randomGenerator = new G4InclGeant4Random();
97  randomGenerator = new G4Ranecu();
98  light_gaus_nuc = new G4LightGausNuc();
99  light_nuc = new G4LightNuc();
100  spl2 = new G4Spl2();
101  saxw = new G4Saxw();
102  dton = new G4Dton();
103  bl1 = new G4Bl1();
104  bl2 = new G4Bl2();
105  bl3 = new G4Bl3();
106  bl4 = new G4Bl4();
107  bl5 = new G4Bl5();
108  bl6 = new G4Bl6();
109  bl8 = new G4Bl8();
110  bl9 = new G4Bl9();
111  bl10 = new G4Bl10();
112  kindstruct = new G4Kind();
113  paul = new G4Paul();
114  varavat = new G4VarAvat();
115  varavat->kveux = 0;
116
117  volant = new G4Volant();
118  volant->iv = 0;
119  evaporationResult = new G4VarNtp();
120  evaporationResult->ntrack = -1;
121
122  // Initialize evaporation.
123  abla = new G4Abla(hazard, volant, evaporationResult);
124  abla->initEvapora();
125}
126
127G4Incl::~G4Incl()
128{
129  delete randomGenerator;
130  delete light_gaus_nuc;
131  delete light_nuc;
132  delete spl2;
133  delete saxw;
134  delete dton;
135  delete bl1;
136  delete bl2;
137  delete bl3;
138  delete bl4;
139  delete bl5;
140  delete bl6;
141  delete bl8;
142  delete bl9;
143  delete bl10;
144  delete kindstruct;
145  delete paul;
146  delete varavat;
147
148  delete abla;
149  delete evaporationResult;
150  delete volant;
151}
152
153/**
154 *Methods for debugging.
155 */
156G4double G4Incl::energyTest(G4int i)
157{
158  return am(bl1->p1[i]+bl1->p1[i],bl1->p2[i]+bl1->p2[i],bl1->p3[i]+bl1->p3[i],bl1->eps[i]+bl1->eps[i]);
159}
160
161void G4Incl::dumpBl5(std::ofstream& dumpOut)
162{
163  dumpOut <<"Dumping G4Bl5:" << G4endl;
164  for(G4int i = 0; i < 300; i++) {
165    dumpOut <<"i = " << i << " nesc[i] = " << bl5->nesc[i] << G4endl;
166  }
167}
168
169void G4Incl::dumpSaxw(std::ofstream& dumpOut)
170{
171  dumpOut << "Dumping G4Saxw" << G4endl;
172  dumpOut << "saxw->k    = " << saxw->k    << G4endl;
173  dumpOut << "saxw->n    = " << saxw->n    << G4endl;
174  dumpOut << "saxw->imat = " << saxw->imat << G4endl;
175  for(G4int i = 0; i < 30; i++) {
176    dumpOut <<"i = " << i << " x = " << saxw->x[i][0] << " y = " << saxw->y[i][0] << " s = " << saxw->s[i][0] << G4endl; 
177  }
178}
179
180void G4Incl::dumpBl1(std::ofstream& dumpOut)
181{
182  dumpOut <<"Dumping Bl1: " << G4endl;
183  dumpOut <<"bl1->ta = " << bl1->ta << G4endl;
184  for(G4int i = 0; i <= bl2->k; i++) {
185    dumpOut <<"i = " << i;
186    dumpOut <<" bl1->p1 = "   << bl1->p1[i]    << " bl1->p2 = "  << bl1->p2[i] <<" bl1->p3 = " << bl1->p3[i];
187    dumpOut <<" bl1->eps = "  << bl1->eps[i];
188    dumpOut <<" bl1->ind1 = " << bl1->ind1[i]  <<" bl1->ind2 = " << bl1->ind2[i] << G4endl;
189  }
190  dumpOut <<"End of Bl1 dump." << G4endl << G4endl;
191}
192
193void G4Incl::dumpBl2(std::ofstream& dumpOut)
194{
195  dumpOut <<"Dumping Bl2: bl2->k = " << bl2->k << G4endl;
196  for(G4int i = 0; i <= bl2->k; i++) {
197    dumpOut <<"i = " << i;
198    dumpOut <<" bl2->ind " << bl2->ind[i] << " bl2->jnd = " << bl2->jnd[i] <<" bl2->crois = " << bl2->crois[i] << G4endl;
199  }
200  dumpOut <<"End of Bl2 dump." << G4endl << G4endl;}
201
202
203void G4Incl::dumpBl3(std::ofstream& dumpOut)
204{
205  dumpOut <<"Dumping Bl3:" << G4endl;
206  dumpOut <<"r1   = " << bl3->r1   << " r2 = "  << bl3->r2  << G4endl;
207  dumpOut <<"ia1  = " << bl3->ia1  << " ia2 = " << bl3->ia2 << G4endl;
208  dumpOut <<"rab2 = " << bl3->rab2                          << G4endl;
209
210  for(G4int i = 0; i <= bl2->k; i++) {
211    dumpOut <<"i = "        << i;
212    dumpOut <<" bl3->x1 = " << bl3->x1[i] << " bl3->x2 = " << bl3->x2[i] <<" bl3->x3 = " << bl3->x3[i] << G4endl;
213  }
214  dumpOut <<"End of Bl2 dump." << G4endl << G4endl;
215}
216
217// End debug functions
218
219void G4Incl::setVerboseLevel(G4int level)
220{
221  verboseLevel = level;
222}
223
224G4int G4Incl::getVerboseLevel()
225{
226  return verboseLevel;
227}
228
229void G4Incl::setDtonData(G4Dton *newDton)
230{
231  dton = newDton;
232}
233
234void G4Incl::setWsData(G4Ws *newWs)
235{
236  ws = newWs;
237}
238
239void G4Incl::setHazardData(G4Hazard *newHazard)
240{
241  hazard = newHazard;
242}
243
244void G4Incl::setSaxwData(G4Saxw *newSaxw)
245{
246  saxw = newSaxw;
247}
248
249void G4Incl::setSpl2Data(G4Spl2 *newSpl2)
250{
251  spl2 = newSpl2;
252}
253
254void G4Incl::setCalinclData(G4Calincl *newCalincl)
255{
256  calincl = newCalincl;
257}
258
259void G4Incl::setMatData(G4Mat *newMat)
260{
261  mat = newMat;
262}
263
264void G4Incl::setLightNucData(G4LightNuc *newLightNuc)
265{
266  light_nuc = newLightNuc;
267}
268
269void G4Incl::setLightGausNucData(G4LightGausNuc *newLightGausNuc)
270{
271  light_gaus_nuc = newLightGausNuc;
272}
273
274void G4Incl::setBl1Data(G4Bl1 *newBl1)
275{
276  bl1 = newBl1;
277}
278
279void G4Incl::setBl2Data(G4Bl2 *newBl2)
280{
281  bl2 = newBl2;
282}
283
284void G4Incl::setBl3Data(G4Bl3 *newBl3)
285{
286  bl3 = newBl3;
287}
288
289void G4Incl::setBl4Data(G4Bl4 *newBl4)
290{
291  bl4 = newBl4;
292}
293
294void G4Incl::setBl5Data(G4Bl5 *newBl5)
295{
296  bl5 = newBl5;
297}
298
299void G4Incl::setBl6Data(G4Bl6 *newBl6)
300{
301  bl6 = newBl6;
302}
303
304void G4Incl::setBl8Data(G4Bl8 *newBl8)
305{
306  bl8 = newBl8;
307}
308
309void G4Incl::setBl9Data(G4Bl9 *newBl9)
310{
311  bl9 = newBl9;
312}
313
314void G4Incl::setBl10Data(G4Bl10 *newBl10)
315{
316  bl10 = newBl10;
317}
318
319void G4Incl::setKindData(G4Kind *newKind)
320{
321  kindstruct = newKind;
322}
323
324/**
325 * INCL main routines for event processing.
326 */
327
328void G4Incl::processEventIncl()
329{
330  const G4double uma = 931.4942;
331  const G4double melec = 0.511;
332
333  G4double   pcorem = 0.0;
334  G4double   pxrem = 0.0;
335  G4double   pyrem = 0.0;
336  G4double   pzrem = 0.0;
337
338  G4double ap = 0.0, zp = 0.0, mprojo = 0.0, pbeam = 0.0;
339
340  varntp->clear();
341  if(calincl->f[6] == 3.0) { // pi+
342    mprojo = 139.56995;
343    ap = 0.0;
344    zp = 1.0;
345  }
346
347  if(calincl->f[6] == 4.0) { // pi0
348    mprojo = 134.9764;
349    ap = 0.0;
350    zp = 0.0;
351  }
352
353  if(calincl->f[6] == 5.0) { // pi-
354    mprojo = 139.56995;
355    ap = 0.0;
356    zp = -1.0;
357  }
358
359  // Coulomb en entree seulement pour les particules ci-dessous.
360  if(calincl->f[6] == 1.0) { // proton
361    mprojo = 938.27231;
362    ap = 1.0;
363    zp = 1.0;
364  }
365 
366  if(calincl->f[6] == 2.0) { // neutron 
367    mprojo = 939.56563;
368    ap = 1.0;
369    zp = 0.0;
370  }
371 
372  if(calincl->f[6] == 6.0) { // deuteron
373    mprojo = 1875.61276;
374    ap = 2.0;
375    zp = 1.0;
376  }
377 
378  if(calincl->f[6] == 7.0) { // triton
379    mprojo = 2808.95;
380    ap = 3.0;
381    zp = 1.0;
382  }
383 
384  if(calincl->f[6] == 8.0) { // He3
385    mprojo = 2808.42;
386    ap = 3.0;
387    zp = 2.0;
388  }
389
390  if(calincl->f[6] == 9.0) { // Alpha
391    mprojo = 3727.42;
392    ap = 4.0;
393    zp = 2.0;
394  }
395
396  pbeam = std::sqrt(calincl->f[2]*(calincl->f[2] + 2.0*mprojo));         
397
398  G4double at = calincl->f[0];
399       
400  calincl->f[3] = 0.0;    // seuil sortie proton
401  calincl->f[7] = 0.0;    // seuil sortie neutron
402
403  G4int ibert = 1;
404
405  G4int nopart = 0;
406  G4int izrem = 0;
407  G4int iarem = 0;
408  G4double esrem = 0.0;
409  G4double erecrem = 0.0;
410  G4double berem = 0.0;
411  G4double garem = 0.0;
412  G4double bimpac = 0.0;
413  G4int jrem = 0;
414  G4double alrem = 0.0;
415
416  /**
417   * Coulomb barrier treatment.
418   */
419  G4double probaTrans = 0.0;
420  G4double rndm = 0.0;
421  if((calincl->f[6] == 1.0) || (calincl->f[6] >= 6.0)) {
422    probaTrans = coulombTransm(calincl->f[2],ap,zp,calincl->f[0],calincl->f[1]);
423    standardRandom(&rndm, &(hazard->ial));
424    if(rndm <= (1.0 - probaTrans)) {
425      varntp->ntrack = -1;
426      return;
427    }
428  }
429
430  /**
431   * Call the actual INCL routine.
432   */
433  pnu(&ibert, &nopart,&izrem,&iarem,&esrem,&erecrem,&alrem,&berem,&garem,&bimpac,&jrem);
434  forceAbsor(&nopart, &iarem, &izrem, &esrem, &erecrem, &alrem, &berem, &garem, &jrem);
435  G4double aprf = double(iarem); // mass number of the prefragment
436  G4double jprf = 0.0;           // angular momentum of the prefragment
437
438  // Mean angular momentum of prefragment.                                 
439  jprf = 0.165 * std::pow(at,(2.0/3.0)) * aprf * (at - aprf) / (at - 1.0);                               
440  if (jprf < 0) {
441    jprf = 0.0;
442  }
443
444  // Reference M. de Jong, Ignatyuk, Schmidt Nuc. Phys A 613, p442, 7th line
445  jprf = std::sqrt(2*jprf);
446  jprf = jrem;
447  varntp->jremn = jrem; // Copy jrem to output tuple.
448
449  G4double numpi = 0;  // Number  of pions.
450  G4double multn = 0;  // Number (multiplicity) of neutrons.
451  G4double multp = 0;  // Number (multiplicity) of protons.
452
453  // Ecriture dans le ntuple des particules de cascade (sauf remnant).     
454  varntp->ntrack = nopart; // Nombre de particules pour ce tir.
455  varntp->massini = iarem;
456  varntp->mzini = izrem;
457  varntp->exini = esrem;
458  varntp->bimpact = bimpac;
459 
460  /**
461   * Three ways to compute the mass of the remnant:
462   * -from the output of the cascade and the canonic mass
463   * -from energy balance (input - all emitted energies)
464   * -following the approximations of the cugnon code (esrem...)
465   */
466  G4double f0 = calincl->f[0];
467  G4double f1 = calincl->f[1];
468  G4double f2 = calincl->f[2];
469  G4double mcorem = mprojo + f2 + abla->pace2(f0, f1) + f0 * uma - f1 * melec;
470
471  G4double pxbil = 0.0;
472  G4double pybil = 0.0;
473  G4double pzbil = 0.0;         
474
475  if(nopart > -1) {
476    for(G4int j = 0; j < nopart; j++) {
477      varntp->itypcasc[j] = 1;
478      // kind(): 1=proton, 2=neutron, 3=pi+, 4=pi0, 5=pi -     
479      if(kind[j] == 1) { 
480        varntp->avv[j] = 1;
481        varntp->zvv[j] = 1;
482        varntp->plab[j] = std::sqrt(ep[j] * (ep[j] + 1876.5592)); // cugnon
483        multp = multp + 1;
484        mcorem = mcorem - ep[j] - 938.27231;
485        if(verboseLevel > 3) {
486          G4cout <<"G4Incl: Proton produced! " << G4endl;
487          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
488        }
489      }
490
491      if(kind[j] == 2) { 
492        varntp->avv[j] = 1;
493        varntp->zvv[j] = 0;
494        varntp->plab[j] = std::sqrt(ep[j]*(ep[j]+1876.5592)); // cugnon
495        //varntp->plab[j] = std::sqrt(ep[j] * (ep[j] + 1879.13126)); // PK mass check
496        multn = multn + 1;
497        mcorem = mcorem - ep[j] - 939.56563;
498        if(verboseLevel > 3) {
499          G4cout <<"G4Incl: Neutron produced! " << G4endl;
500          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
501        }
502      }
503
504      if(kind[j] == 3) { 
505        varntp->avv[j] = -1;
506        varntp->zvv[j] = 1;
507        varntp->plab[j] = std::sqrt(ep[j]*(ep[j]+276.0)); // cugnon
508        numpi = numpi + 1;
509        mcorem = mcorem - ep[j] - 139.56995;
510        if(verboseLevel > 3) {
511          G4cout <<"G4Incl: Pi+ produced! " << G4endl;
512          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
513        }
514      }
515
516      if(kind[j] == 4) { 
517        varntp->avv[j] = -1;
518        varntp->zvv[j] = 0;
519        varntp->plab[j] = std::sqrt(ep[j]*(ep[j]+276.0)); // cugnon
520        numpi = numpi + 1;
521        mcorem = mcorem - ep[j] - 134.9764;
522        if(verboseLevel > 3) {
523          G4cout <<"G4Incl: Pi0 produced! " << G4endl;
524          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
525        }
526      }
527
528      if(kind[j] == 5) { 
529        varntp->avv[j] = -1;
530        varntp->zvv[j] = -1;
531        varntp->plab[j] = std::sqrt(ep[j]*(ep[j]+276.0)); // cugnon
532        numpi = numpi + 1;
533        mcorem = mcorem - ep[j] - 139.56995;
534        if(verboseLevel > 3) {
535          G4cout <<"G4Incl: Pi+ produced! " << G4endl;
536          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
537        }
538      }
539
540      if(kind[j] == 6) { 
541        varntp->avv[j] = 2;
542        varntp->zvv[j] = 1;
543        varntp->plab[j] = std::sqrt(ep[j]*(ep[j] + 2.0*1874.34)); // cugnon
544        numpi = numpi + 1;
545        mcorem = mcorem - ep[j] - 2806.359;
546        if(verboseLevel > 3) {
547          G4cout <<"G4Incl: Deuteron produced! " << G4endl;
548          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
549        }
550      }
551
552      if(kind[j] == 7) { 
553        varntp->avv[j] = 3;
554        varntp->zvv[j] = 1;
555        varntp->plab[j] = std::sqrt(ep[j]*(ep[j] + 2.0*2806.359)); // cugnon
556        numpi = numpi + 1;
557        mcorem = mcorem - ep[j] - 2806.359;
558        if(verboseLevel > 3) {
559          G4cout <<"G4Incl: Triton produced! " << G4endl;
560          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
561        }
562      }
563
564      if(kind[j] == 8) { 
565        varntp->avv[j] = 3;
566        varntp->zvv[j] = 2;
567        varntp->plab[j] = std::sqrt(ep[j]*(ep[j] + 2.0*2807.119)); // cugnon
568        numpi = numpi + 1;
569        mcorem = mcorem - ep[j] - 2807.119;
570        if(verboseLevel > 3) {
571          G4cout <<"G4Incl: He3 produced! " << G4endl;
572          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
573        }
574      }
575
576      if(kind[j] == 9) { 
577        varntp->avv[j] = 4;
578        varntp->zvv[j] = 2;
579        varntp->plab[j] = std::sqrt(ep[j]*(ep[j] + 2.0*3724.818)); // cugnon
580        numpi = numpi + 1;
581        mcorem = mcorem - ep[j] - 3724.818;
582        if(verboseLevel > 3) {
583          G4cout <<"G4Incl: He4 produced! " << G4endl;
584          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
585        }
586      }
587
588      varntp->enerj[j] = ep[j];
589      varntp->tetlab[j] = 180.0*std::acos(gam[j])/3.141592654;
590      varntp->philab[j] = 180.0*std::atan2(beta[j],alpha[j])/3.141592654;
591      pxbil = pxbil + varntp->plab[j]*alpha[j];
592      pybil = pybil + varntp->plab[j]*beta[j];
593      pzbil = pzbil + varntp->plab[j]*gam[j];
594
595      if(verboseLevel > 3) {
596        G4cout <<"Momentum: " << varntp->plab[j] << G4endl;
597        G4cout <<"Theta: " << varntp->tetlab[j] << G4endl;
598        G4cout <<"Phi: " << varntp->philab[j] << G4endl;
599      }
600    }
601
602    // calcul de la masse (impulsion) du remnant coherente avec la conservation d'energie:
603    pcorem=std::sqrt(erecrem*(erecrem +2.*938.2796*iarem));   // cugnon
604    mcorem = 938.2796*iarem;                               // cugnon
605               
606    // Note: Il faut negliger l'energie d'excitation (ESREM) pour que le bilan
607    // d'impulsion soit correct a la sortie de la cascade.....et prendre la
608    // masse MCOREM comme ci-dessus (fausse de ~1GeV par rapport aux tables...)       
609    pxrem=pcorem*alrem;
610    pyrem=pcorem*berem;
611    pzrem=pcorem*garem;
612       
613    pxbil=pxbil+pxrem;
614    pybil=pybil+pyrem;
615    pzbil=pzbil+pzrem;
616
617    if((std::fabs(pzbil-pbeam) > 5.0) || (std::sqrt(std::pow(pxbil,2)+std::pow(pybil,2)) >= 3.0)) {
618      if(verboseLevel > 3) {
619        G4cout <<"bad momentum conservation after incl:" << G4endl;
620      }
621    }
622       
623    volant->iv = 0;   // init du compteur des part evaporees
624    varntp->kfis = 0;  //drapeau de fission copie dans le ntuple
625    varntp->estfis = 0.0;
626    varntp->izfis = 0;
627    varntp->iafis = 0;
628
629    //  varntp->ntrack = varntp->ntrack + 1;  // on recopie le remnant dans le ntuple
630    varntp->massini = iarem;
631    varntp->mzini = izrem;
632    varntp->exini = esrem;
633    varntp->itypcasc[varntp->ntrack] = 1;
634    varntp->avv[varntp->ntrack] = iarem;
635    varntp->zvv[varntp->ntrack]= izrem;
636    varntp->plab[varntp->ntrack] = pcorem;
637    varntp->enerj[varntp->ntrack] = std::sqrt(std::pow(pcorem,2) + std::pow(mcorem,2)) - mcorem;
638    varntp->tetlab[varntp->ntrack] = 180.0*std::acos(garem)/3.141592654;
639    varntp->philab[varntp->ntrack] = 180.0*std::atan2(berem,alrem)/3.141592654;
640    varntp->ntrack++;
641    varntp->mulncasc = varntp->ntrack;
642    varntp->mulnevap = 0;
643    varntp->mulntot = varntp->mulncasc + varntp->mulnevap;
644    if(verboseLevel > 3) {
645      G4cout <<"G4Incl: Returning nucleus fragment. " << G4endl;
646      G4cout <<"G4Incl: Fragment A = " << varntp->avv[varntp->ntrack] << " Z = " << varntp->zvv[varntp->ntrack] << G4endl;
647      G4cout <<"Energy: " << varntp->enerj[varntp->ntrack] << G4endl;
648      G4cout <<"Momentum: " << varntp->plab[varntp->ntrack] << G4endl;
649      G4cout <<"Theta: " << varntp->tetlab[varntp->ntrack] << G4endl;
650      G4cout <<"Phi: " << varntp->philab[varntp->ntrack] << G4endl;
651    }
652  }
653  else {
654    if(nopart == -2) {
655      varntp->ntrack = -2; //FIX: Error flag to remove events containing unphysical events (Ekin > Ebullet).
656    }
657    else {
658      varntp->ntrack = -1;
659    }
660  }
661}
662
663
664void G4Incl::processEventInclAbla(G4int eventnumber)
665{
666  const G4double uma = 931.4942;
667  const G4double melec = 0.511;
668
669  G4double pcorem = 0.0;
670  G4double pxrem = 0.0;
671  G4double pyrem = 0.0;
672  G4double pzrem = 0.0;
673
674  G4double ap = 0.0, zp = 0.0, mprojo = 0.0, pbeam = 0.0;
675
676  varntp->clear();
677
678  // pi+
679  if(calincl->f[6] == 3.0) { 
680    mprojo = 139.56995;
681    ap = 0.0;
682    zp = 1.0;
683  }
684
685  // pi0
686  if(calincl->f[6] == 4.0) {
687    mprojo = 134.9764;
688    ap = 0.0;
689    zp = 0.0;
690  }
691
692  // pi-
693  if(calincl->f[6] == 5.0) {
694    mprojo = 139.56995;
695    ap = 0.0;
696    zp = -1.0;
697  }
698
699  // coulomb en entree seulement pour les particules ci-dessous
700
701  // proton
702  if(calincl->f[6] == 1.0) {
703    mprojo = 938.27231;
704    ap = 1.0;
705    zp = 1.0;
706  }
707
708  // neutron 
709  if(calincl->f[6] == 2.0) {
710    mprojo = 939.56563;
711    ap = 1.0;
712    zp = 0.0;
713  }
714
715  // deuteron
716  if(calincl->f[6] == 6.0) {
717    mprojo = 1875.61276;
718    ap = 2.0;
719    zp = 1.0;
720  }
721
722  // triton
723  if(calincl->f[6] == 7.0) {
724    mprojo = 2808.95;
725    ap = 3.0;
726    zp = 1.0;
727  }
728
729  // He3
730  if(calincl->f[6] == 8.0) {
731    mprojo = 2808.42;
732    ap = 3.0;
733    zp = 2.0;
734  }
735
736  // Alpha
737  if(calincl->f[6] == 9.0) {
738    mprojo = 3727.42;
739    ap = 4.0;
740    zp = 2.0;
741  }
742
743  pbeam = std::sqrt(calincl->f[2]*(calincl->f[2] + 2.0*mprojo));         
744
745  G4double at = calincl->f[0];
746       
747  calincl->f[3] = 0.0;    //     !seuil sortie proton
748  calincl->f[7] = 0.0;  //       !seuil sortie neutron
749
750  G4int ibert = 1;
751
752  G4int nopart = 0;
753  G4int izrem = 0;
754  G4int iarem = 0;
755  G4double esrem = 0.0;
756  G4double erecrem = 0.0;
757  G4double berem = 0.0;
758  G4double garem = 0.0;
759  G4double bimpac = 0.0;
760  G4int jrem = 0;
761  G4double alrem = 0.0;
762
763  // Coulomb barrier
764 
765  G4double probaTrans = 0.0;
766  G4double rndm = 0.0;
767
768  if((calincl->f[6] == 1.0) || (calincl->f[6] >= 6.0)) {
769    //    probaTrans = coulombTransm(calincl->f[2],apro,zpro,calincl->f[0],calincl->f[1]);
770    probaTrans = coulombTransm(calincl->f[2],ap,zp,calincl->f[0],calincl->f[1]);
771    standardRandom(&rndm, &(hazard->ial));
772    if(rndm <= (1.0 - probaTrans)) {
773      varntp->ntrack = -1;
774      return;
775    }
776  }
777
778  // Call the actual INCL routine:
779  pnu(&ibert, &nopart,&izrem,&iarem,&esrem,&erecrem,&alrem,&berem,&garem,&bimpac,&jrem);
780//   nopart=1;
781//   kind[0]=1;
782//   ep[0]=799.835;
783//   alpha[0]=0.08716;
784//   beta[0]=0.;
785//   gam[0]=0.99619;
786//   izrem=82;
787//   iarem=208;
788//   esrem=200.;
789//   erecrem=0.18870;
790//   alrem=-0.47101;
791//   berem=0.;
792//   garem=0.88213;
793//   bimpac=2.;
794  forceAbsor(&nopart, &iarem, &izrem, &esrem, &erecrem, &alrem, &berem, &garem, &jrem);
795  G4double aprf = double(iarem);    // mass number of the prefragment
796  G4double jprf = 0.0;                // angular momentum of the prefragment
797
798  // Mean angular momentum of prefragment                                 
799  jprf = 0.165 * std::pow(at,(2.0/3.0)) * aprf*(at - aprf)/(at - 1.0);                               
800  if (jprf < 0) {
801    jprf = 0.0;
802  }
803
804  // check m.de jong, ignatyuk, schmidt nuc.phys a 613, pg442, 7th line
805  jprf = std::sqrt(2*jprf);
806
807  jprf = jrem;
808  varntp->jremn = jrem;      // jrem copie dans le ntuple
809
810  G4double numpi = 0;  // compteurs de pions, neutrons protons
811  G4double multn = 0; 
812  G4double multp = 0;
813
814  // ecriture dans le ntuple des particules de cascade (sauf remnant)     
815  varntp->ntrack = nopart;          // nombre de particules pour ce tir
816  if(varntp->ntrack >= VARNTPSIZE) {
817    if(verboseLevel > 2) {
818      G4cout <<"G4Incl error: Output data structure not big enough." << G4endl;
819    }
820  }
821  varntp->massini = iarem;
822  varntp->mzini = izrem;
823  varntp->exini = esrem;
824  varntp->bimpact = bimpac;
825 
826  //  three ways to compute the mass of the remnant:
827  //                -from the output of the cascade and the canonic mass
828  //                -from energy balance (input - all emitted energies)
829  //                -following the approximations of the cugnon code (esrem...)
830  G4double mcorem = mprojo + calincl->f[2] + abla->pace2(double(calincl->f[0]),double(calincl->f[1]))
831    + calincl->f[0]*uma - calincl->f[1]*melec;
832
833  G4double pxbil = 0.0;
834  G4double pybil = 0.0;
835  G4double pzbil = 0.0;         
836
837  if(nopart > -1) {
838    for(G4int j = 0; j < nopart; j++) {
839      varntp->itypcasc[j] = 1;
840      // kind(): 1=proton, 2=neutron, 3=pi+, 4=pi0, 5=pi -     
841      if(kind[j] == 1) { 
842        varntp->avv[j] = 1;
843        varntp->zvv[j] = 1;
844        varntp->plab[j] = std::sqrt(ep[j]*(ep[j]+1876.5592)); // cugnon
845        multp = multp + 1;
846        mcorem = mcorem - ep[j] - 938.27231;
847        if(verboseLevel > 3) {
848          G4cout <<"G4Incl: Proton produced! " << G4endl;
849          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
850        }
851      }
852
853      if(kind[j] == 2) { 
854        varntp->avv[j] = 1;
855        varntp->zvv[j] = 0;
856        varntp->plab[j] = std::sqrt(ep[j]*(ep[j]+1876.5592)); // cugnon
857        multn = multn + 1;
858        mcorem = mcorem - ep[j] - 939.56563;
859        if(verboseLevel > 3) {
860          G4cout <<"G4Incl: Neutron produced! " << G4endl;
861          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
862        }
863      }
864     
865      if(kind[j] == 3) { 
866        varntp->avv[j] = -1;
867        varntp->zvv[j] = 1;
868        varntp->plab[j] = std::sqrt(ep[j]*(ep[j]+276.0)); // cugnon
869        numpi = numpi + 1;
870        mcorem = mcorem - ep[j] - 139.56995;
871        if(verboseLevel > 3) {
872          G4cout <<"G4Incl: Pi+ produced! " << G4endl;
873          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
874        }
875      }
876
877      if(kind[j] == 4) { 
878        varntp->avv[j] = -1;
879        varntp->zvv[j] = 0;
880        varntp->plab[j] = std::sqrt(ep[j]*(ep[j]+276.0)); // cugnon
881        numpi = numpi + 1;
882        mcorem = mcorem - ep[j] - 134.9764;
883        if(verboseLevel > 3) {
884          G4cout <<"G4Incl: Pi0 produced! " << G4endl;
885          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
886        }
887      }
888
889      if(kind[j] == 5) { 
890        varntp->avv[j] = -1;
891        varntp->zvv[j] = -1;
892        varntp->plab[j] = std::sqrt(ep[j]*(ep[j]+276.0)); // cugnon
893        numpi = numpi + 1;
894        mcorem = mcorem - ep[j] - 139.56995;
895        if(verboseLevel > 3) {
896          G4cout <<"G4Incl: Pi+ produced! " << G4endl;
897          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
898        }
899      }
900
901      if(kind[j] == 6) { 
902        varntp->avv[j] = 2;
903        varntp->zvv[j] = 1;
904        varntp->plab[j] = std::sqrt(ep[j]*(ep[j] + 2.0*1874.34)); // cugnon
905        numpi = numpi + 1;
906        mcorem = mcorem - ep[j] - 2806.359;
907        if(verboseLevel > 3) {
908          G4cout <<"G4Incl: Deuteron produced! " << G4endl;
909          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
910        }
911      }
912
913      if(kind[j] == 7) { 
914        varntp->avv[j] = 3;
915        varntp->zvv[j] = 1;
916        varntp->plab[j] = std::sqrt(ep[j]*(ep[j] + 2.0*2806.359)); // cugnon
917        numpi = numpi + 1;
918        mcorem = mcorem - ep[j] - 2806.359;
919        if(verboseLevel > 3) {
920          G4cout <<"G4Incl: Triton produced! " << G4endl;
921          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
922        }
923      }
924
925      if(kind[j] == 8) { 
926        varntp->avv[j] = 3;
927        varntp->zvv[j] = 2;
928        varntp->plab[j] = std::sqrt(ep[j]*(ep[j] + 2.0*2807.119)); // cugnon
929        numpi = numpi + 1;
930        mcorem = mcorem - ep[j] - 2807.119;
931        if(verboseLevel > 3) {
932          G4cout <<"G4Incl: He3 produced! " << G4endl;
933          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
934        }
935      }
936
937      if(kind[j] == 9) { 
938        varntp->avv[j] = 4;
939        varntp->zvv[j] = 2;
940        varntp->plab[j] = std::sqrt(ep[j]*(ep[j] + 2.0*3724.818)); // cugnon
941        numpi = numpi + 1;
942        mcorem = mcorem - ep[j] - 3724.818;
943        if(verboseLevel > 3) {
944          G4cout <<"G4Incl: He3 produced! " << G4endl;
945          G4cout <<"G4Incl: Momentum: "<< varntp->plab[j] << G4endl;
946        }
947      }
948
949      varntp->enerj[j] = ep[j];
950      varntp->tetlab[j] = 180.0*std::acos(gam[j])/3.141592654;
951      varntp->philab[j] = 180.0*std::atan2(beta[j],alpha[j])/3.141592654;
952      pxbil = pxbil + varntp->plab[j]*alpha[j];
953      pybil = pybil + varntp->plab[j]*beta[j];
954      pzbil = pzbil + varntp->plab[j]*gam[j];
955
956      if(verboseLevel > 3) {
957        G4cout <<"Momentum: " << varntp->plab[j]   << G4endl;
958        G4cout <<"Theta: "    << varntp->tetlab[j] << G4endl;
959        G4cout <<"Phi: "      << varntp->philab[j] << G4endl;
960      }
961    }
962
963    // calcul de la masse (impulsion) du remnant coherente avec la conservation d'energie:
964    pcorem = std::sqrt(erecrem*(erecrem + 2.0 * 938.2796 * iarem));   // cugnon
965    mcorem = 938.2796 * iarem;                               // cugnon
966    varntp->pcorem = pcorem;
967    varntp->mcorem = mcorem;
968    // Note: Il faut negliger l'energie d'excitation (ESREM) pour que le bilan
969    // d'impulsion soit correct a la sortie de la cascade.....et prendre la
970    // masse MCOREM comme ci-dessus (fausse de ~1GeV par rapport aux tables...)       
971    pxrem = pcorem * alrem;
972    pyrem = pcorem * berem;
973    pzrem = pcorem * garem;
974    varntp->pxrem = pxrem;
975    varntp->pyrem = pyrem;
976    varntp->pzrem = pzrem;
977    pxbil = pxbil + pxrem;
978    pybil = pybil + pyrem;
979    pzbil = pzbil + pzrem;
980
981    if((std::fabs(pzbil - pbeam) > 5.0) || (std::sqrt(std::pow(pxbil,2) + std::pow(pybil,2)) >= 3.0)) {
982      if(verboseLevel > 3) {
983        G4cout <<"bad momentum conservation after incl:" << G4endl;
984      }
985    }
986       
987    volant->iv = 0;   // init du compteur des part evaporees
988    varntp->kfis = 0;  //drapeau de fission copie dans le ntuple
989    varntp->estfis = 0.0;
990    varntp->izfis = 0;
991    varntp->iafis = 0;
992
993    // on recopie le remnant dans le ntuple
994    // varntp->ntrack = varntp->ntrack + 1;
995    varntp->massini = iarem;
996    varntp->mzini = izrem;
997    varntp->exini = esrem;
998
999    if(verboseLevel > 2) {
1000      G4cout << __FILE__ << ":" << __LINE__ << "Dump varntp after cascade: " << G4endl;
1001      varntp->dump();
1002    }
1003    // Evaporation/fission:
1004    evaporationResult->ntrack = 0;
1005    abla->breakItUp(varntp->massini, varntp->mzini, mcorem, varntp->exini, varntp->jremn,
1006                    erecrem, pxrem, pyrem, pzrem, eventnumber);
1007
1008    if(verboseLevel > 2) {
1009      G4cout << __FILE__ << ":" << __LINE__ << "Dump evaporationResult after evaporation: " << G4endl;
1010      evaporationResult->dump();
1011    }
1012    for(G4int evaporatedParticle = 0; evaporatedParticle < evaporationResult->ntrack; evaporatedParticle++) {
1013      if(evaporationResult->avv[evaporatedParticle] == 0 && evaporationResult->zvv[evaporatedParticle] == 0) { //Fix: Skip "empty" particles with A = 0 and Z = 0
1014        // continue;
1015      }
1016      varntp->kfis = evaporationResult->kfis;
1017      varntp->itypcasc[varntp->ntrack] = evaporationResult->itypcasc[evaporatedParticle];
1018      varntp->avv[varntp->ntrack] = evaporationResult->avv[evaporatedParticle];
1019      varntp->zvv[varntp->ntrack]= evaporationResult->zvv[evaporatedParticle];
1020      varntp->plab[varntp->ntrack] = evaporationResult->plab[evaporatedParticle];
1021      varntp->enerj[varntp->ntrack] = evaporationResult->enerj[evaporatedParticle];
1022      varntp->tetlab[varntp->ntrack] = evaporationResult->tetlab[evaporatedParticle];
1023      varntp->philab[varntp->ntrack] = evaporationResult->philab[evaporatedParticle];
1024      varntp->ntrack++;
1025      if(verboseLevel > 3) {
1026        G4cout <<"G4Incl: Returning evaporation result"           << G4endl;
1027        G4cout <<"G4Incl: A = " << varntp->avv[varntp->ntrack]    << " Z = " << varntp->zvv[varntp->ntrack] << G4endl;
1028        G4cout <<"Energy: "     << varntp->enerj[varntp->ntrack]  << G4endl;
1029        G4cout <<"Momentum: "   << varntp->plab[varntp->ntrack]   << G4endl;
1030        G4cout <<"Theta: "      << varntp->tetlab[varntp->ntrack] << G4endl;
1031        G4cout <<"Phi: "        << varntp->philab[varntp->ntrack] << G4endl;
1032      }
1033    }
1034    if(verboseLevel > 2) {
1035      G4cout <<"G4Incl: ntrack = "          << varntp->ntrack << G4endl;
1036      G4cout <<"G4Incl: Done extracting..." << G4endl;
1037    }
1038  }
1039  if(nopart == -2) {
1040    varntp->ntrack = -2; //FIX: Error flag to remove events containing unphysical events (Ekin > Ebullet).
1041    evaporationResult->ntrack = -2; //FIX: Error flag to remove events containing unphysical events (Ekin > Ebullet).
1042  }
1043  else if(nopart == -1) {
1044    varntp->ntrack = -1;
1045    evaporationResult->ntrack = -1;
1046  }
1047  if(verboseLevel > 2) {
1048    G4cout << __FILE__ << ":" << __LINE__ << "Dump varntp after combining: " << G4endl;
1049    varntp->dump();
1050  }
1051}
1052
1053// Initialization routines
1054void G4Incl::initIncl(G4bool initRandomSeed)
1055{
1056  // Subroutine for initialisation of intranuclear cascade incl
1057  //
1058  // this will  read some specific parameters for incl,
1059  // prepare the saxon-wood density for each nucleus
1060  // compute the deuteron momentum space density from paris pot.
1061  // print some global informations
1062  //
1063  // input: should contain z and a for nbmat nucleus considered in this problem
1064  //
1065  // input: should contain a seed (ial, odd and of 5 digits) to start the work.     
1066
1067  G4double xrand = 0.0;
1068  G4double ialdep = 0.0;
1069  G4int imat = 0;
1070  G4int iamat = 0, izmat = 0;
1071
1072  // for the 19 secondary seeds of hazard:
1073  G4int nbtirhaz[IGRAINESIZE] = {38,82,76,18,39,31,41,59,26,54,
1074                                 14,84,13,15,91,89,10,6,52};
1075
1076  // specific parameters for incl:       
1077  // espace de phases test (r et p) pour pauli:
1078  // valeur recommandee par j.c. v-test=0.592 h**3:
1079  G4double rbl = 2.;
1080
1081  // valeur pour avoir v-test=2 h**3 (avec pbl=200)
1082  rbl = 3.1848;
1083
1084  // preparation of 19 other seeds (can also be initialized from outside):
1085  if(initRandomSeed) {
1086    ialdep=hazard->ial;
1087    for(G4int i = 0; i < IGRAINESIZE; i++) {
1088      for(G4int j = 0; j < nbtirhaz[i]; j++) {
1089        standardRandom(&xrand,&(hazard->ial));
1090      }
1091
1092      // Zero is not accepted as random seed!
1093      do {
1094        standardRandom(&xrand,&(hazard->ial));
1095      } while(xrand == 0);
1096
1097      xrand = xrand * 100000;
1098
1099      while(xrand < 10000) {
1100        xrand = xrand * 10;
1101      }
1102      hazard->igraine[i] = (int) xrand;
1103      if(hazard->igraine[i] == ((hazard->igraine[i] / 2) * 2)) {
1104        hazard->igraine[i] = hazard->igraine[i] + 1;
1105      }
1106    }
1107
1108    hazard->ial = int(ialdep);
1109  }
1110
1111  // calculation with realistic nuclear density (saxon-wood)
1112  if (ws->nosurf <= 0) {
1113    // prepare nucleus density for nbmat nucleus defined in struct mat
1114    if(mat->nbmat >= 500) {
1115      if(verboseLevel > 2) {
1116        G4cout <<"You need " << mat->nbmat << " nuclei in your problem. The maximum number of nuclei is 500 " << G4endl;
1117      }
1118      return;
1119    }
1120
1121    for(G4int i = 0; i < mat->nbmat; i++) {
1122      imat = i;
1123      izmat = int(mat->zmat[i]);
1124      iamat = int(mat->amat[i]);
1125
1126      initMaterial(izmat, iamat, imat);
1127    }
1128  }
1129
1130  // deuteron density in momentum space:
1131  densDeut();
1132}
1133
1134
1135void G4Incl::initMaterial(G4int izmat, G4int iamat, G4int imat)
1136{
1137  G4double res_dws = 0.0;
1138  G4double fnor = 0.0;
1139
1140  G4double rcour = 0.0, geom = 0.0;
1141  G4int nbr = 0;
1142
1143  G4double step = 0.0, f_r = 0.0;
1144
1145  // rms espace r, espace p, fermi momentum and energy for light gauss nuc.     
1146  const G4double datarms1t[LGNSIZE] = {0.0, 0.0, 0.0, 0.0, 0.0, 2.10, 1.80, 1.80, 1.63};
1147  const G4double datapf1t[LGNSIZE] = {0.0, 0.0, 0.0, 0.0, 0.0, 77.0, 110.0, 110.0, 153.0};
1148
1149  for(G4int i = 0; i < LGNSIZE; i++) {
1150    light_gaus_nuc->rms1t[i] = datarms1t[i];
1151    light_gaus_nuc->pf1t[i] = datapf1t[i];
1152  }
1153
1154  // fermi 2 param from a=19 to 28, modified harm oscil a=6 to 18
1155  // (h. de vries et al. at. data and nuc. data tab. 36 (1987) 495)
1156  const G4double datarln[LNSIZE] = {0.0,0.0,0.0,0.0,0.0,0.334,0.327,0.479,0.631,0.838,
1157                                    0.811,1.07,1.403,1.335,1.25,1.544,1.498,1.513,
1158                                    2.58,2.77, 2.775,2.78,2.88,2.98,3.22,3.03,2.84,
1159                                    3.14,0.0,0.0};
1160
1161  const G4double dataaln[LNSIZE] = {0.0,0.0,0.0,0.0,0.0,1.78,1.77,1.77,1.77,1.71,
1162                                    1.69,1.69,1.635,1.730,1.81,1.833,1.798,
1163                                    1.841,0.567,0.571, 0.560,0.549,0.550,0.551,
1164                                    0.580,0.575,0.569,0.537,0.0,0.0};
1165
1166  for(G4int i = 0; i < LNSIZE; i++) {
1167    light_nuc->r[i] = datarln[i];
1168    light_nuc->a[i] = dataaln[i];
1169  }
1170
1171  if(verboseLevel > 3) {
1172    G4cout <<"Nuclear density for nucleus (z, a): " << izmat << " " << iamat << " " << imat << G4endl;
1173  }
1174 
1175  const G4double fmp = 938.2796; // From INCL data
1176
1177  // parametres moyens de densite de la cible (fermi 2 parametres)
1178  if (iamat >= 28) {
1179    ws->r0 = (2.745e-4*iamat+1.063)*std::pow(G4double(iamat), 0.33333333);
1180    ws->adif = 1.63e-4*iamat+0.510;
1181    ws->rmaxws = ws->r0 + (ws->xfoisa)*(ws->adif);
1182  }
1183  else if(iamat >= 19) {
1184    ws->r0 = light_nuc->r[iamat-1];
1185    ws->adif = light_nuc->a[iamat-1];
1186    ws->rmaxws = ws->r0 + (ws->xfoisa)*(ws->adif);
1187  }
1188  else if(iamat >= 6) {
1189    ws->r0 = light_nuc->r[iamat-1];
1190    ws->adif = light_nuc->a[iamat-1];
1191    ws->rmaxws = 5.5 + 0.3*(double(iamat)-6.)/12.;
1192  }
1193  else if(iamat >= 2) {
1194    if(iamat == 2) {
1195      ws->r0=light_gaus_nuc->rms1t[5]; // Orig: rms1t(6)
1196      light_gaus_nuc->pfln[5] = light_gaus_nuc->pf1t[5]*1.291;  // Orig [6], std::sqrt(5/3)=1.291
1197      light_gaus_nuc->tfln[5] = std::sqrt(std::pow(light_gaus_nuc->pfln[5],2) + fmp*fmp) - fmp;
1198      light_gaus_nuc->vnuc[5] = light_gaus_nuc->tfln[5] + 2.22;
1199      if(verboseLevel > 2) {
1200        G4cout <<"Nuclear potential: " << light_gaus_nuc->vnuc[5] << "MeV, Fermi momentum and energy: " << light_gaus_nuc->pfln[5] << " " << light_gaus_nuc->tfln[5] << G4endl;
1201      }
1202    }
1203    if(iamat == 3 && izmat == 1) {
1204      ws->r0=light_gaus_nuc->rms1t[6]; // Orig: rms1t(7)
1205      light_gaus_nuc->pfln[6] = light_gaus_nuc->pf1t[6]*1.291;  // Orig [7], std::sqrt(5/3)=1.291
1206      light_gaus_nuc->tfln[6] = std::sqrt(std::pow(light_gaus_nuc->pfln[6],2) + fmp*fmp) - fmp;
1207      light_gaus_nuc->vnuc[6] = light_gaus_nuc->tfln[6] + 4.24;
1208      if(verboseLevel > 2) {
1209        G4cout <<"Nuclear potential: " << light_gaus_nuc->vnuc[6] << "MeV, Fermi momentum and energy: " << light_gaus_nuc->pfln[6] << " " << light_gaus_nuc->tfln[6] << G4endl;
1210      }
1211    }
1212    if(iamat == 3 && izmat == 2) {
1213      ws->r0 = light_gaus_nuc->rms1t[7]; // Orig: rms1t(8)
1214      light_gaus_nuc->pfln[7] = light_gaus_nuc->pf1t[7]*1.291;   //!std::sqrt(5/3)=1.291
1215      light_gaus_nuc->tfln[7] = std::sqrt(std::pow(light_gaus_nuc->pfln[7],2) + fmp*fmp) - fmp;
1216      light_gaus_nuc->vnuc[7] = light_gaus_nuc->tfln[7] + 3.86;
1217      if(verboseLevel > 2) {
1218        G4cout <<"Nuclear potential: " << light_gaus_nuc->vnuc[7] << "MeV, Fermi momentum and energy: " << light_gaus_nuc->pfln[7] << " " << light_gaus_nuc->tfln[7] << G4endl;
1219      }
1220    }
1221    if(iamat == 4) {
1222      ws->r0 = light_gaus_nuc->rms1t[8]; // Orig: rms1t(9)
1223      light_gaus_nuc->pfln[8] = light_gaus_nuc->pf1t[8]*1.291;   // !std::sqrt(5/3)=1.291
1224      light_gaus_nuc->tfln[8] = std::sqrt(std::pow(light_gaus_nuc->pfln[8],2) + fmp*fmp) - fmp;
1225      light_gaus_nuc->vnuc[8] = light_gaus_nuc->tfln[8] + 9.43;
1226      if(verboseLevel > 2) {
1227        G4cout <<"Nuclear potential: " << light_gaus_nuc->vnuc[8] << "MeV, Fermi momentum and energy: " << light_gaus_nuc->pfln[8] << " " << light_gaus_nuc->tfln[8] << G4endl;
1228      }
1229    }
1230    ws->adif = 0.57735*ws->r0;
1231    ws->rmaxws = ws->r0 + 2.5;
1232  }
1233  ws->drws = (ws->rmaxws)/29.0;
1234
1235  // bmax for sigma geom and various projectiles (p,n,pion/d/t/he3/he4/)
1236  G4int j = 0;
1237  for(G4int i = 0; i < MATGEOSIZE; i++) { // Orig: do i=1,6
1238    j = i;
1239    if(i >= 2) {
1240      j = i + 3;
1241    }
1242    mat->bmax_geo[i][imat] = (ws->rmaxws) + (light_gaus_nuc->rms1t[j]);
1243  }
1244
1245  // preparation de la distribution w.s.:
1246  if (iamat >= 19) {
1247    G4double step = 0.2;
1248    res_dws = integrate(0.0, 13.5, step, derivWsaxFunction);
1249  }
1250  else { 
1251    // preparation de la distribution m.h.o.:
1252    if(iamat >= 6) {
1253      step=0.1;
1254      res_dws = integrate(0.0, 10.0, step, derivMhoFunction);
1255    }
1256    else {
1257      // preparation de la distribution gaussienne:
1258      //         G4double cte = std::pow(ws->adif,3)*std::sqrt(2.*3.141592654);       
1259      res_dws = 3.0*(std::pow(ws->adif, 3)*std::sqrt(2.0*3.141592654))/2.0;
1260    }
1261  }
1262  fnor = res_dws;
1263
1264  // calcul de q/pf=f(r)     
1265  nbr = int(std::floor((ws->rmaxws)/(ws->drws) + 1.5));
1266  rcour = -1*(ws->drws);
1267
1268  j = 0;
1269  for(G4int i = 0; i < nbr; i++) { // do i=1,nbr
1270    rcour = rcour + (ws->drws);
1271    if(i == 0) { // 1->0
1272      f_r = 0.0;
1273      saxw->x[j][imat] = f_r;
1274      saxw->y[j][imat] = 0.0;           //!on impose x(1)=0., y(1)=0.
1275      res_dws = 0.0;
1276    }
1277    else {
1278      step = rcour/20.;
1279      if(step >= 0.05) {
1280        step = 0.05;
1281      }
1282      if (iamat >= 19) {
1283        //integ(ws, dton, 0.,rcour,step,&derivwsax,&res_dws);
1284        res_dws = integrate(0.0, rcour, step, derivWsaxFunction);
1285        f_r = res_dws/fnor;
1286      }
1287      else { 
1288        if(iamat >= 6) {
1289          //integ(ws, dton, 0.,rcour,step,&derivmho,&res_dws);
1290          res_dws = integrate(0.0, rcour, step, derivMhoFunction);
1291          f_r = res_dws/fnor;
1292        }
1293        else { 
1294          //integ(ws, dton, 0.,rcour,step,&derivgaus,&res_dws);
1295          res_dws = integrate(0.0, rcour, step, derivGausFunction);
1296          f_r = res_dws/fnor;
1297        }
1298      }
1299      // modif le 20/10/2003; éviter les valeurs négatives avant **1/3 !
1300      //       }
1301      if(f_r >= 0.0)  {
1302        f_r = std::pow(f_r,(1./3.));
1303        saxw->x[j][imat] = f_r;
1304        saxw->y[j][imat] = rcour;
1305      }
1306    }
1307    j = j + 1;
1308  }
1309  saxw->n = j;
1310  saxw->x[j-1][imat] = 1.; // !on impose saxw->x[nbpinter-1]=1. (y=rmax)
1311
1312  // interpolation de f_inv(r) (fonction inverse de f(r))       
1313  // flin2(imat, saxw, ws);
1314  firstDerivative(imat);
1315
1316  if(verboseLevel > 3) {
1317    if(iamat >= 19) {
1318      G4cout <<"Wood-Saxon density, r0 = " << ws->r0 << " a = " << ws->adif << G4endl;
1319    }
1320    if(iamat >= 6 && iamat <= 19) {
1321      G4cout <<"Modif. harm. oscil. density, alpha = " << ws->r0 << " a = " << ws->adif << G4endl;
1322    }
1323    if(iamat >= 2 && iamat <= 6) {
1324      G4cout <<"Gaussian density, r.m.s = " << ws->r0 << " sigma = " << ws->adif << G4endl;
1325    }
1326  }
1327 
1328  geom = 31.41592653*std::pow(ws->rmaxws,2);
1329
1330  if(verboseLevel > 3) {
1331    G4cout <<"For incident nucleons or pions rmax = " << ws->rmaxws << " and geometrical (pi*rmaxws*rmaxws) reaction cross section (mb) is " << geom << G4endl;
1332    for(G4int k = 2; k < MATGEOSIZE; k++) {
1333      G4cout << "Rmaxws for d/t/3he/4he = " << mat->bmax_geo[k][imat] << G4endl;
1334    }
1335
1336    G4cout <<"Exact calculation of the r(q) function for the target nucleus density q/pf  r(q/pf)" << G4endl;
1337  }
1338}
1339
1340G4double G4Incl::deutv(G4int l, G4double q)
1341{
1342  G4double res = 0.0;
1343
1344  if (l == 0) {
1345    for(G4int i = 0; i < DTONSIZE; i++) {
1346      res = res + dton->c[i]/(std::pow(q,2) + fm2(i+1));
1347    }
1348  }
1349  if(l != 0) {
1350    for(G4int i = 0; i < DTONSIZE; i++) { 
1351      res = res + dton->d[i]/(std::pow(q,2) + fm2(i+1));
1352    }
1353  }
1354
1355  return res*std::sqrt(2./CLHEP::pi)*dton->fn; // See G4InclDataDefs.hh
1356}
1357
1358G4double G4Incl::fm2(G4int j)
1359{
1360  /**
1361   * In implementation Returns the values of the function:
1362   * \f[
1363   * (0.23162461 + (j - 1))^2
1364   * \f]
1365   * @param j an integer parameter
1366   * @return a double value
1367   */
1368 
1369  return std::pow((0.23162461 + (j - 1)),2);
1370}
1371
1372G4double G4Incl::interpolateFunction(G4double xv)
1373{
1374  // fonction d'interpolation au point xv ( meme hors bornes )             
1375  // de la fn x->y dont les derivees premieres (s) ont ete                 
1376  // evaluees par l'appel prealable de flin2                             
1377  // les indices vont de 1 a n
1378
1379  saxw->k = saxw->imat;
1380  G4double tz = xv - saxw->x[0][saxw->imat];
1381  G4int j = 0;
1382   
1383  if(tz < 0) {
1384    return (saxw->y[0][saxw->imat] + saxw->s[0][saxw->imat]*tz);
1385  }
1386  else if(tz == 0) {
1387    return (saxw->y[0][saxw->imat]);
1388  }
1389  else {
1390    for(G4int i = 1; i < saxw->n; i++) {
1391      j = i - 1;
1392      tz = xv - saxw->x[j][saxw->imat];
1393      if(tz < 0) {
1394        break;
1395      }
1396      else if(tz == 0) {
1397        return saxw->y[j][saxw->imat];
1398      }
1399    }
1400  }
1401
1402  G4double dgx = xv - saxw->x[j][saxw->imat];
1403  return(saxw->y[j][saxw->imat] + saxw->s[j][saxw->imat]*dgx);
1404}
1405
1406void G4Incl::firstDerivative(G4int k)
1407{
1408  for(G4int i=0; i < saxw->n-1; i++) {
1409    saxw->s[i][k] = (saxw->y[i+1][k] - saxw->y[i][k]) / (saxw->x[i+1][k] - saxw->x[i][k]);
1410  }
1411  saxw->s[saxw->n-1][k] = saxw->s[saxw->n-2][k];
1412}
1413
1414G4double G4Incl::wsax(G4double r) {
1415  return std::pow(r,2) / (1.0+std::exp(r-(ws->r0)/(ws->adif)));
1416}
1417
1418G4double G4Incl::derivWsax(G4double r)
1419{
1420  G4double derivwsax = std::pow(r,3)*std::exp((r-(ws->r0))/(ws->adif))/std::pow((1.0+std::exp((r-(ws->r0))/(ws->adif))),2);
1421  return derivwsax/(ws->adif);
1422}
1423
1424G4double G4Incl::dmho(G4double r)
1425{
1426  G4double arg=std::pow((r/(ws->adif)),2);
1427  return r*r*(1.+(ws->r0)*arg)*std::exp(-arg);
1428}
1429
1430G4double G4Incl::derivMho(G4double r)
1431{
1432  G4double arg=std::pow((r/(ws->adif)),2);
1433  return -2.*r*r*arg*((ws->r0) -1.-(ws->r0)*arg)*std::exp(-arg);
1434}
1435
1436G4double G4Incl::derivGaus(G4double r)
1437{
1438  G4double arg=std::pow((r/(ws->adif)),2);
1439  return r*r*arg*std::exp(-arg/2.);     
1440}
1441
1442void G4Incl::densDeut()
1443{
1444  // ce subroutine appele sur le premier tir va calculer la densite du deuton
1445  // dans l'espace des impulsions et preparer l'interpolation permettant ensuite
1446  // le tir au hasard d'un module de l'impulsion (q).
1447  // ce subroutine remplit le common /spl2/:
1448  // xsp(0:1), ysp integrale normalisee de la densite de 0 a q.
1449  // a(),b(),c() coefs des nsp points pour une interpolation du second degre.
1450  // q est en fm-1.
1451
1452  //    495           dimension q(100),f(100)
1453  //    496           common/spl2/ xsp(100),ysp(100),a(100),b(100),cc(100),nbp
1454  G4double cData[DTONSIZE] = {0.88688076e+00,-0.34717093e+00,-.30502380e+01,
1455                              .56207766e+02,-.74957334e+03,.53365279e+04,-.22706863e+05,
1456                              .60434469e+05,-.10292058e+06,.11223357e+06,-.75925226e+05,
1457                              .29059715e+05,-.48157368e+04};
1458
1459  G4double dData[DTONSIZE] = {.23135193e-01,-.85604572e+00,.56068193e+01,
1460                              -.69462922e+02,.41631118e+03,-.12546621e+04,.12387830e+04,
1461                              .33739172e+04,-.13041151e+05,.19512524e+05,-.15634324e+05,
1462                              .66231089e+04,-.11698185e+04};
1463
1464  G4double fnData = 0.28212e+00;
1465
1466  for(G4int i = 0; i < DTONSIZE; i++) {
1467    dton->c[i] = cData[i];
1468    dton->d[i] = dData[i];
1469  }
1470  dton->fn = fnData;
1471
1472  //    509     c avec fn=.28212 les fo radiales suivantes sont normalisees a:          deu00470
1473  //    510     c somme(0,infini)(deut0(q)**2 + deut2(q)**2))*q*q*dq = 1./4*pi          deu00480
1474  //    511     c et ceci dans l'espace r et dans l'espace q. pd=5.74%                  deu00490
1475  //    512     cjcd
1476  //    513           common /inout/ in, io, itty, iscrt                               
1477  //    514     cjcd
1478
1479  const G4int qsize = 100;
1480  G4double q[qsize];
1481  G4double f[qsize];
1482  for(G4int init_i = 0; init_i < qsize; init_i++) {
1483    q[init_i] = 0.0;
1484    f[init_i] = 0.0;
1485  }
1486
1487  G4double dq=0.01;
1488  q[0]=0.0;
1489  for(G4int i = 1; i < 50; i++) {
1490    q[i] = q[i-1] + dq;
1491    f[i] = 0.0;
1492  }
1493
1494  spl2->n = 77; // nombre de points de calcul
1495
1496  dq=0.1;
1497  for(G4int i = 50; i < spl2->n; i++) {
1498    q[i] = q[i-1] + dq;
1499  }
1500
1501  f[0]=0.0;
1502
1503  G4double sumint=0.0;
1504
1505  // the id if the function we wish to integrate (in this case: G4Incl::dens
1506  for(G4int i = 1; i < spl2->n; i++) {
1507    dq = (q[i]-q[i-1])/10.0;
1508    sumint = sumint + integrate(q[i-1], q[i], dq, densFunction);
1509    f[i] = sumint;
1510  }
1511
1512  for(G4int i = 0; i < spl2->n; i++) {
1513    spl2->x[i] = f[i]/f[spl2->n-1];
1514    spl2->y[i] = q[i];
1515  }
1516
1517  spl2ab();
1518
1519  if(verboseLevel > 3) {
1520    G4cout << "deuteron density in q space from Paris potential: " << spl2->n << " Exact values from 0 to " 
1521              << q[spl2->n-1] << " fm-1 " << G4endl;
1522  }
1523}
1524
1525G4double G4Incl::integrate(G4double ami, G4double ama, G4double step, G4int functionChoice)
1526{
1527  G4double res = 0.0;
1528  G4double x1[5];
1529  for(G4int init_i = 0; init_i < 5; init_i++) {
1530    x1[init_i] = 0.0;
1531  }
1532  G4double ri = ami;
1533  G4double ra = ama;
1534  G4int nb = 0;
1535  G4double acont = 1.0;
1536  G4double dr = step;
1537
1538  if(ama <= ami) {
1539    acont = -1.0;
1540    ri = ama;
1541    ra = ami;
1542  }
1543 
1544  x1[0] = 95.0/288.0;
1545  x1[1] = 317.0/240.0;
1546  x1[2] = 23.0/30.0;
1547  x1[3] = 793.0/720.0;
1548  x1[4] = 157.0/160.0;
1549  nb = int(std::floor(((ra - ri)/step + 1.0000000001))); // 1.0000000001 -> 0.0
1550  dr = (ra - ri)/(double(nb - 1)); 
1551  res = 0.0;
1552
1553  if(nb < 10) {
1554    if(verboseLevel > 2) {
1555      G4cout <<"pas assez de points d'integration" << G4endl;
1556    }
1557    return 0.0;
1558  }
1559 
1560  for(G4int i = 0; i < 5; i++) {
1561    res = res + (callFunction(functionChoice, ri) + callFunction(functionChoice, ra))*x1[i];
1562    ri = ri + dr;
1563    ra = ra - dr;
1564  }
1565
1566  nb = nb - 10;
1567
1568  if(nb == 0) {
1569    return (res*dr*acont);
1570  }
1571
1572  for(G4int i = 0; i < nb; i++) {
1573    res = res + callFunction(functionChoice, ri);
1574    ri = ri + dr;
1575  }
1576
1577  return(res*dr*acont);
1578}
1579
1580
1581G4double G4Incl::dens(G4double q)
1582{
1583  return q*q*(std::pow(deutv(0,q),2)+std::pow(deutv(2,q),2));
1584}
1585
1586void G4Incl::spl2ab() 
1587{
1588  G4int i = 0, j = 0, k = 0;
1589
1590  for(i=0; i <= spl2->n-3; i++) {
1591    j = i + 1;
1592    k = i + 2;
1593
1594    spl2->c[i] = ((spl2->y[k]-spl2->y[i])*(spl2->x[j]-spl2->x[i])-(spl2->x[k]-spl2->x[i])*(spl2->y[j]-spl2->y[i]))
1595      /((spl2->x[j]-spl2->x[i])*(spl2->x[k]-spl2->x[i])*(spl2->x[k]-spl2->x[j]));
1596
1597    spl2->b[i] = (spl2->y[j]-spl2->y[i])/(spl2->x[j]-spl2->x[i]);
1598
1599    spl2->a[i] = spl2->y[i];
1600  }
1601
1602  for(i = spl2->n-2; i < spl2->n; i++) {
1603    spl2->c[i] = spl2->c[spl2->n-3];
1604    spl2->b[i] = spl2->b[spl2->n-3];
1605    spl2->a[i] = spl2->a[spl2->n-3]; 
1606  }
1607}
1608
1609G4double G4Incl::splineab(G4double xv)
1610{
1611  G4double tz = xv-spl2->x[0];
1612  G4int j;
1613
1614  if(tz < 0) {
1615    return spl2->a[0] + spl2->b[0] * tz + spl2->c[0] * tz * (xv - spl2->x[1]);
1616  }
1617  if(tz == 0) {
1618    return spl2->y[0];                                                       
1619  }
1620  if(tz > 0) {
1621    for(G4int i = 1; i <= spl2->n-1; i++) {
1622      j = i;
1623      tz = xv - spl2->x[i];                                 
1624
1625      if(tz < 0) { 
1626        j = j - 1;
1627        tz = xv - spl2->x[j];
1628        return spl2->a[j] + spl2->b[j] * tz + spl2->c[j] * tz * (xv - spl2->x[j+1]);
1629      }
1630      if(tz == 0) {
1631        return spl2->y[j];                                                   
1632      }
1633    }
1634  }
1635
1636  // Returns 0.0 if the point xv is outside the defined region (xv > spl2->x[spl2->n-1])
1637  if(verboseLevel > 2) {
1638    G4cout <<"G4Incl::splineab : requested point outside defined region! Returning 0.0." << G4endl;
1639  }
1640  return 0.0; 
1641}
1642
1643// Actual calculation
1644
1645void G4Incl::pnu(G4int *ibert_p, G4int *nopart_p, G4int *izrem_p, G4int *iarem_p, G4double *esrem_p,
1646                 G4double *erecrem_p, G4double *alrem_p, G4double *berem_p, G4double *garem_p,
1647                 G4double *bimpact_p, G4int *l_p)
1648{
1649  G4int ibert = (*ibert_p);
1650  //  float f[15]; // = (*f_p);
1651  G4int nopart = (*nopart_p);
1652//   G4int kind[300]; //= (*kind_p);
1653//   G4double ep[300]; // = (*ep_p);
1654//   G4double alpha[300]; // = (*alpha_p);
1655//   G4double beta[300]; // = (*beta_p);
1656//   G4double gam[300]; // = (*gam_p);
1657  G4int izrem = (*izrem_p);
1658  G4int iarem = (*iarem_p);
1659  G4double esrem = (*esrem_p); 
1660  G4double erecrem = (*erecrem_p);
1661  G4double alrem = (*alrem_p);
1662  G4double berem = (*berem_p);
1663  G4double garem = (*garem_p);
1664  G4double bimpact = (*bimpact_p);
1665  G4int l = (*l_p);
1666
1667  G4double minus_b1 = 0.0, minus_b2 = 0.0, minus_b3 = 0.0;
1668  G4double aml1 = 0.0;
1669  G4double aml2 = 0.0;
1670  G4double amlnew = 0.0;
1671  G4double arg = 0.0;
1672  G4double b1 = 0.0;
1673  G4double b2 = 0.0;
1674  G4double b3 = 0.0;
1675  G4double bb2 = 0.0;
1676  G4double be = 0.0;
1677  G4double bmass[2000]; 
1678  for(G4int init_i = 0; init_i < 2000; init_i++) {
1679    bmass[init_i] = 0.0;
1680  }
1681  G4double bmax2 = 0.0;
1682  G4double c1 = 0.0;
1683  G4double c2 = 0.0;
1684  G4double cb0 = 0.0;
1685  G4double cchi = 0.0;
1686  G4double ccr = 0.0;
1687  G4double cg = 0.0;
1688  G4double cif = 0.0;
1689  G4double cmultn = 0.0;
1690  G4double cobe = 0.0;
1691  G4double coeffb0 = 0.0;
1692  G4double comom = 0.0;
1693  G4double cstet = 0.0;
1694  G4double dis1 = 0.0;
1695  G4double dis2 = 0.0;
1696  G4double dis3 = 0.0;
1697  G4double dist = 0.0;
1698  G4double eb0 = 0.0;
1699  G4double ecoreh5 = 0.0;
1700  G4double efer = 0.0;
1701  G4double egs = 0.0;
1702  G4double eh5 = 0.0;
1703  G4double eh6 = 0.0;
1704  G4double eij = 0.0;
1705  G4double ekout = 0.0;
1706  G4double elead = 0.0;
1707  G4double energie_in = 0.0;
1708  G4double ener_max = 0.0;
1709  G4double eout = 0.0;
1710  G4double eps_c[BL1SIZE]; 
1711  for(G4int init_i = 0; init_i < BL1SIZE; init_i++) {
1712    eps_c[init_i] = 0.0;
1713  }
1714  G4double epsv = 0.0;
1715  G4double erecg = 0.0;
1716  G4double erem = 0.0;
1717  G4double exi = 0.0;
1718  G4double expob0 = 0.0;
1719  G4double factemp = 0.0;
1720  G4double fffc = 0.0;
1721  G4double fm = 0.0;
1722  G4double g1 = 0.0;
1723  G4double g2 = 0.0;
1724  G4double ge = 0.0;
1725  G4double geff = 0.0;
1726  G4double gg = 0.0;
1727  G4double gl1 = 0.0;
1728  G4double gl2 = 0.0;
1729  G4double gpsg = 0.0;
1730  G4int i1 = 0;
1731  G4int i20 = 0;
1732  G4int ic33 = 0;
1733  G4int ich1 = 0;
1734  G4int ich2 = 0;
1735  G4int ich3 = 0;
1736  G4int ich4 = 0;
1737  G4int ichd = 0;
1738  G4int ichpion = 0;
1739  G4int idecf = 0;
1740  G4int idep = 0;
1741  G4int iej = 0;
1742  G4int iejn = 0;
1743  G4int iejp = 0;
1744  G4int i_emax = 0;
1745  G4int iflag = 0;
1746  G4int iflag20 = 0; 
1747  G4int iflag40 = 0; 
1748  G4int iflag60 = 0; 
1749  G4int ilm = 0; 
1750  G4int imin = 0;
1751  G4int indic[3000]; 
1752  for(G4int init_i = 0; init_i < 3000; init_i++) {
1753    indic[init_i] = 0;
1754  }
1755  G4int inrem = 0;
1756  G4int ip = 0;
1757  G4int ipi[2000]; 
1758  for(G4int init_i = 0; init_i < 2000; init_i++) {
1759    ipi[init_i] = 0;
1760  }
1761  G4int iqe = 0;
1762  G4int irem = 0;
1763  G4int irst_avatar = 0;
1764  G4int isos = 0; 
1765  G4int itch = 0;
1766  G4int iteste = 0;
1767  G4int itt = 0;
1768  G4int ixr1 = 0;
1769  G4int ixr2 = 0;
1770  G4int ixr3 = 0;
1771  //  G4int k;
1772  G4int kcol = 0;
1773  G4int kd = 0;
1774  //  G4int klm = 0;
1775//   G4int l1;
1776//   G4int l2;
1777  G4int ldel = 0;
1778  G4int lead = 0;
1779  G4int led = 0;
1780  G4int lnew = 0;
1781  G4int lp = 0; 
1782  G4int lp1 = 0;
1783  G4double mcdd = 0.0;
1784  //G4double mg;
1785  G4int mg = 0;
1786  G4double mpaul1 = 0.0;
1787  G4double mpaul2 = 0.0;
1788  G4double mrdd = 0.0;
1789  G4double mrdn = 0.0;
1790  G4double mrdp = 0.0;
1791  G4double mrnd = 0.0;
1792  G4double mrnn = 0.0;
1793  G4double mrpd = 0.0;
1794  G4int n20 = 0;
1795  G4int nbalttf = 0;
1796  G4int nbquit = 0;
1797  G4int nbtest = 0;
1798  G4int nc[300];
1799  G4int npproj[300];
1800  for(G4int init_i = 0; init_i < 300; init_i++) {
1801    nc[init_i] = 0;
1802    npproj[init_i] = 0;
1803  }
1804  G4int ncol = 0;
1805  G4int ncol_2c = 0;
1806  G4int next = 0;
1807  G4int nmiss = 0;
1808  G4int np = 0;
1809  G4int npidir = 0;
1810  G4int npion = 0;
1811  G4int npx = 0;
1812  G4int nsum_col = 0;
1813  G4double p1v = 0.0;
1814  G4double p2v = 0.0;
1815  G4double p3v = 0.0;
1816  G4double pfrem1 = 0.0;
1817  G4double pfrem2 = 0.0;
1818  G4double pfrem3 = 0.0;
1819  G4double pfreml = 0.0;
1820  G4double pfreml2 = 0.0;
1821  G4double phi = 0.0;
1822  G4double p_mod = 0.0;
1823  G4double pot = 0.0;
1824  G4double pout1 = 0.0;
1825  G4double pout2 = 0.0;
1826  G4double pout3 = 0.0;
1827  G4double pppp = 0.0;
1828  G4double prem1 = 0.0;
1829  G4double prem2 = 0.0;
1830  G4double prem3 = 0.0;
1831  G4double psf = 0.0;
1832  G4double pspr = 0.0;
1833  G4double ptotl = 0.0;
1834  G4double qdeut = 0.0;
1835  G4double qqq = 0.0;
1836  G4double r22 = 0.0;
1837  G4double rcm1 = 0.0;
1838  G4double rcm2 = 0.0;
1839  G4double rcm3 = 0.0;
1840  G4double rcorr = 0.0;
1841  G4double rhopi = 0.0;
1842  G4double rndm = 0.0;
1843  G4double rr = 0.0;
1844  G4double rrrr = 0.0;
1845  G4double s = 0.0;
1846  G4double s1t1 = 0.0;
1847  G4double s2t1 = 0.0;
1848  G4double s3t1 = 0.0;
1849  G4double schi = 0.0;
1850  G4double sepa = 0.0;
1851  G4double sif = 0.0;
1852  G4double sitet = 0.0;
1853  G4double sp1t1 = 0.0;
1854  G4double sp2t1 = 0.0;
1855  G4double sp3t1 = 0.0;
1856  G4double sq = 0.0;
1857  G4double sueps = 0.0;
1858  G4double t[50];
1859  for(G4int init_i = 0; init_i < 50; init_i++) {
1860    t[init_i] = 0.0;
1861  }
1862  G4double t0 = 0.0;
1863  G4double t1 = 0.0;
1864  G4double t2 = 0.0;
1865  G4double t3 = 0.0;
1866  G4double t33 = 0.0;
1867  G4double t4 = 0.0;
1868  G4double t5 = 0.0;
1869  G4double t6 = 0.0;
1870  G4double t7 = 0.0;
1871  G4double t8 = 0.0;
1872  G4double tau = 0.0;
1873  G4double tbid = 0.0;
1874  G4double tdel = 0.0;
1875  G4double temfin = 0.0;
1876  G4double tim = 0.0;
1877  G4double timi = 0.0;
1878  G4double tlabu = 0.0;
1879  G4double tp = 0.0;
1880  G4double tref = 0.0;
1881  G4double tri = 0.0;
1882  G4double tt31 = 0.0;
1883  G4double tt32 = 0.0;
1884  G4double tt33 = 0.0;
1885  G4double tt34 = 0.0;
1886  G4double tt35 = 0.0;
1887  G4double tt36 = 0.0;
1888  G4double tte = 0.0;
1889  G4double u = 0.0;
1890  G4double v = 0.0;
1891  G4double var_ab = 0.0;
1892  G4double x = 0.0;
1893  G4double x1l1 = 0.0;
1894  G4double x1l2 = 0.0;
1895  G4double x1_target = 0.0; 
1896  G4double x2_target = 0.0; 
1897  G4double x3_target = 0.0; 
1898  G4double x2cour = 0.0;
1899  G4double x2l1 = 0.0;
1900  G4double x2l2 = 0.0;
1901  G4double x3l1 = 0.0;
1902  G4double x3l2 = 0.0;
1903  G4double xapres = 0.0;
1904  G4double xavant = 0.0;
1905  G4double xbl1 = 0.0;
1906  G4double xbl2 = 0.0;
1907  G4double xc = 0.0;
1908  G4double xe = 0.0;
1909  G4double xga = 0.0;
1910  G4double xl1 = 0.0;
1911  G4double xl2 = 0.0;
1912  G4double xl3 = 0.0;
1913  G4double xlab = 0.0;
1914  G4double xleng = 0.0;
1915  G4double xlengm = 0.0;
1916  G4double xmodp = 0.0;
1917  G4double xpb = 0.0;
1918  G4double xq = 0.0;
1919  G4double xr1 = 0.0;
1920  G4double xr2 = 0.0;
1921  G4double xr3 = 0.0;
1922  G4double xr4 = 0.0;
1923  G4double xr5 = 0.0;
1924  G4double xr6 = 0.0;
1925  G4double xr7 = 0.0;
1926  G4double xr8 = 0.0;
1927  G4double xv = 0.0;
1928  G4double xxx = 0.0;
1929  G4double xy1 = 0.0;
1930  G4double xy2 = 0.0;
1931  G4double xy3 = 0.0;
1932  G4double xye = 0.0;
1933  G4double y = 0.0;
1934  G4double p3_c[BL1SIZE];
1935  G4double q1[BL1SIZE];
1936  G4double q2[BL1SIZE];
1937  G4double q3[BL1SIZE];
1938  G4double q4[BL1SIZE];
1939  G4double ym[BL1SIZE];
1940  for(G4int init_i = 0; init_i < BL1SIZE; init_i++) {
1941    q1[init_i] = 0.0;
1942    q2[init_i] = 0.0;
1943    q3[init_i] = 0.0;
1944    q4[init_i] = 0.0;
1945    ym[init_i] = 0.0;
1946  }
1947  G4double y1[BL3SIZE];
1948  G4double y2[BL3SIZE];
1949  G4double y3[BL3SIZE];
1950  for(G4int init_i = 0; init_i < BL1SIZE; init_i++) {
1951    y1[init_i] = 0.0;
1952    y2[init_i] = 0.0;
1953    y3[init_i] = 0.0;
1954  }
1955  G4double z = 0.0;
1956  G4double za_i = 0.0;
1957  G4double zai2 = 0.0;
1958  G4double zshif = 0.0;
1959  G4double ztouch = 0.0; 
1960  G4double ztu = 0.0;
1961
1962  // LIEGE INC-model as a subroutine
1963
1964  // The Liege INC model has been applied to several systems and in
1965  // several conditions. Refinements are still in progress.
1966
1967  // PLEASE refer to this version as INCL4.1 in order to avoid
1968  // confusion when comparing to the results of your colleagues.
1969
1970  // DIFFERENT from INCL2.0 in the sense that the cascade is stopped
1971  // when the excitation energy vanishes if this occurs before the
1972  // predetermined stopping time (herein denoted as temfin) Special
1973  // are taken to avoid emission of slow particles due to the
1974  // imperfect Pauli blocking
1975
1976  // PLEASE notice: There are basically only two parameters in the
1977  // model: the average potential depth, denoted as V0, and the time
1978  // at which the cascade is stopped denoted as temfin. In this
1979  // program, the "standard" values (those G4introduced in the ref
1980  // NPA620(1997)475) are V0=40MeV and temfin=1.25*some function of
1981  // incident energy and impact parameter. You may, of course, change
1982  // these parameters V0 and the numerical coefficient in temfin,
1983  // within reasonable limits (i.e. V0 cannot be lower than 38MeV;
1984  // V0=45MeV is recommended for heavy nuclei). If you do, PLEASE
1985  // indicate your choice, once again, for the same reason as above.
1986
1987  // The description of the cascade model(incl2.0) can be found in:
1988  // J.C., C.VOLANT & S.VUILLIER, NPA620(1997)475 It is basically the
1989  // same model as described in J.C. NPA462(1987)751 (version 7 (in
1990  // our jargon), sketched below) + a refinement of the
1991  // parametrization of the cross-sections, based on J.C., D. L'HOTE,
1992  // J.VANDERMEULEN, NIM B111(1996)215 and J.C., S.LERAY, E.MARTINEZ,
1993  // Y.PATIN & S.VUILLIER PRC56(1998)2431
1994
1995  // technical notes:
1996  // 1.for the parametrizations of cross  sections, see
1997  //   notes of 4/10/96, 9/10/96, 31/12/97 and 13/10/98
1998  // 2.temfin=1.25*... 18/6/98
1999  // 3.sepa in concordance with v0-tf 2/7/98
2000  // 4.special care for stopping the cascade before t=temfin 27/04/99
2001
2002  //     84     c+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2003  //     85     C                                                                       P-N00030
2004  //     86     C     VERSION 7:  2/2/93                                                P-N00040
2005  //     87     C
2006  //     88     C++++++++++++ DESCRIPTION OF INPUT AND OUTPUT+++++++++++++++++++++++++++++
2007  //     89     C
2008  //     90     C **INPUT DATA**
2009  //     91     C
2010  //     92     C  IBERT=O IN THE FIRST CALL
2011  //     93     C        1 IN THE SUBSEQUENT CALLS
2012  //     94     C
2013  //     95     C  F= (REAL) ARRAY OF DIMENSION 8
2014  //     96     C
2015  //     97     C    F(1)= A (TARGET)
2016  //     98     C    F(2)= Z (TARGET)
2017  //     99     C    F(3)= KINETIC ENERGY (IN MEV) OF THE INCIDENT PARTICLE
2018  //    100     C    F(4)= SUPPOSED TO BE THE MINIMUM  PROTON ENERGY REQUIRED TO LEAVE
2019  //    101     C          THE TARGET. IN THIS CASCADE MODEL, IT IS ZERO
2020  //    102     C    F(5)= Nuclear potential V0 (standard value=45 MeV for heavy nuclei)
2021  //    103     C    F(6)= Rescale the cascade duration (the standard value t0 is MULTIPLIED
2022  //    104     c          by this value. F(6)=1. is the standard)
2023  //    105     C    F(7)= TYPE OF INCIDENT PARTICLE
2024  //    106     C           1.00 FOR PROTON
2025  //    107     C           2.00 FOR NEUTRON
2026  //    108     C           3.00 FOR PI+
2027  //    109     C           4.00 FOR PI0
2028  //    110     C           5.00 FOR PI-
2029  //    111     C           6.00 FOR DEUTERON
2030  //    112     C           7.00 FOR TRITON
2031  //    113     C           8.00 FOR HE3
2032  //    114     C           9.00 FOR HE4
2033  //    115     C    F(8)= SUPPOSED TO BE THE MINIMUM NEUTRON ENERGY REQUIRED TO LEAVE
2034  //    116     C          THE TARGET. IN THIS CASCADE MODEL, IT IS ZERO
2035  //    117     C
2036  //    118     C                                 NOSURF=1 Sharp density (hard sphere),
2037  //    119     C                                 NOSURF=0 Wood-Saxon density, stopping time "70"
2038  //    120     C                                                without B (impact) dependence.
2039  //    121     C                                 NOSURF=-1 Wood-Saxon density, stopping time "70"
2040  //    122     C                                                with B (impact) dependence
2041  //    123     C                                 (on peut toujours nenormaliser ces fonctions
2042  //    124     C                                  de temps avec le facteur F(6): t=t0*F(6) )
2043  //    125     C                                XFOISA      Rmaxws = R0 + XFOISA*A
2044  //    126     C                                            Bmax = Rmaxws for pions and nucleons
2045  //    127     C                                            Bmax = Rmaxws + rms1t (data) for composits
2046  //    128     C         Pauli strict (1) or statistic (0) or without pauli (2):     NPAULSTR
2047  //    129     C
2048  //    130     C    F(9)= imat, target material identifier for the right choose of Sax.-Wood density
2049  //    131     c
2050  //    132     c common/hazard/ial,IY1,IY2,IY3,IY4,IY5,IY6,IY7,IY8,IY9,IY10,
2051  //    133     c     s               IY11,IY12,IY13,IY14,IY15,IY16,IY17,IY18,IY19
2052  //    134     c ......20 numbers in the main routine to initialize the random numbers
2053  //    135     c
2054  //    136     C **OUTPUT DATA**
2055  //    137     C
2056  //    138     C  NOPART=-1 PSEUDO REACTION (VOID EVENT)
2057  //    139     C          0 ABSORPTION
2058  //    140     C         >0 TRUE EVENT, = NUMBER OF PARTICLES EMITTED (EXCLUDING THE REMNANT)
2059  //    141     C
2060  //    142     C  FOR N=1,NOPART:
2061  //    143     C  KIND(N)= TYPE OF PARTICLES (SAME CONVENTION AS FOR F(7), BUT IN G4INTEGERS)
2062  //    144     C
2063  //    145     C  EP(N)=  KINETIC ENERGY
2064  //    146     C
2065  //    147     C  ALPHA(N),BETA(N),GAM(N)= DIRECTION COSINES
2066  //    148     C
2067  //    149     C  IZREM= Z (REMNANT)
2068  //    150     C
2069  //    151     C  IAREM= A (REMNANT)
2070  //    152     C
2071  //    153     C  ESREM= EXCITATION ENERGY OF THE REMNANT
2072  //    154     C
2073  //    155     C  ERECREM= RECOIL ENERGY OF THE REMNANT
2074  //    156     C
2075  //    157     C  ALREM,BEREM,GAREM=DIRECTION COSINES OF THE REMNANT
2076  //    158     C
2077  //    159     C  BIMPACT impact parameter
2078  //    160     C
2079  //    161     C  L G4intrinsic momentum of the remnant in units of h/2pi=hbar=197.328
2080  //    162     C+++++++++ DESCRIPTION OF THE INC MODEL ++++++++++++++++++++++++++++++++++++
2081  //    163     C
2082  //    164     C     MODEL DESCRIBED IN J.CUGNON (NP A462(1987)751)                    P-N00050
2083  //    165     C     =MODEL (DR) OF J.CUGNON,D.KINET,J.VANDERMEULEN(NP A379(1982)567)  P-N00060
2084  //    166     C                                                                       P-N00110
2085  //    167     C        +REFLECTION OR TRANSMISSION ON THE POTENTIAL WALL              P-N00120
2086  //    168     C              (THE POTENTIAL DEPTH IS THE SAME FOR NUCLEONS & DELTA'S) P-N00130
2087  //    169     C              (CONTAINS A COULOMB BARRIER)                             P-N00140
2088  //    170     C                                                                       P-N00150
2089  //    171     C        +ABSORPTION OF THE PION ABOVE THE (3,3) RESONANCE (NOT IN      P-N00160
2090  //    172     C                VERSION 2)                                             P-N00170
2091  //    173     C                                                                       P-N00180
2092  //    174     C        +POSSIBLE PAULI BLOCKING OF TWO BODY COLLISIONS                P-N00190
2093  //    175     C        +POSSIBLE PAULI BLOCKING OF DELTA DECAY                        P-N00200
2094  //    176     C                 THE PAULI BLOCKING IS APPLIED TO THE NUCLEONS         P-N00210
2095  //    177     C                 ONLY.THE PAULI BLOCKING FACTORS ARE EVALUATED         P-N00220
2096  //    178     C                 BY COUNTING THE NUCLEONS INSIDE A VOLUME IN           P-N00230
2097  //    179     C                 PHASE SPACE.THE EXTENSION OF THIS VOLUME IS           P-N00240
2098  //    180     C                 OF THE ORDER OF H**3                                  P-N00250
2099  //    181     C                                                                       P-N00260
2100  //    182     C    ADDITIONAL FEATURES:                                               P-N00270
2101  //    183     C                                                                       P-N00280
2102  //    184     C        +ISOSPIN (WITH NEW PN BACKWARD-FORWARD ASYMMETRY)              P-N00290
2103  //    185     C                                                                       P-N00300
2104  //    186     C        +"LONGITUDINAL GROWTH" OF THE BARYONS (NOT ACTIVATED HERE)
2105  //    187     C
2106  //    188     C        + PARTICLE #1 IS ALWAYS THE FASTEST PARTICLE IN THE Z-DIRECTIONP-N00100
2107  //    189     C                                 (NOT ACTIVATED HERE)
2108  //    190     C        +SIMPLIFIED NEUTRON EVAPORATION AT THE END OF THE CASCADE      P-N00310
2109  //    191     C                                 (NOT PRESENT HERE)
2110  //    192     C                 
2111  //    193     C        +POSSIBLE CONSERVATION OF ANGULAR MOMENTUM (NOT ACTIVATED
2112  //    194     C                    HERE, COPIED FROM P_NUCJ)
2113  //    195     C        P-NU7=SAME AS P-NU6 + EVAPORATION                              P-N00330
2114  //    196     C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++P-N00340
2115  //    197     
2116  //    198           DIMENSION f(15),kind(300),ep(300),alpha(300),beta(300),gam(300)
2117  //    199           DIMENSION bmass(300)
2118  //    200           COMMON/hazard/ial,IY1,IY2,IY3,IY4,IY5,IY6,IY7,IY8,IY9,IY10,
2119  //    201          s               IY11,IY12,IY13,IY14,IY15,IY16,IY17,IY18,IY19
2120  //    202           COMMON/kind/kindf7
2121  //    203           DIMENSION IND(20000),JND(20000)                                   P-N00350
2122  //    204           DIMENSION INDIC(3000)                                             P-N00360
2123  //    205           DIMENSION NPAR(625,15),NIMP(600,15),NNCO(15),NIMPP(600)           P-N00370
2124  //    206           DIMENSION NENTR(10,8,20,10),NOUT1(15),NOUT2(15)                   P-N00380
2125  //    207     
2126  //    208     c     DIMENSION TEM(15),NSR(40),NSP(40),NSR1(40),NSP1(40)               P-N00400
2127  //    209           DIMENSION TEM(15),NSR1(40),NSP1(40)                               P-N00400
2128  //    210           DIMENSION T(200),LINE(132),Q1(200),Q2(200),Q3(200),Q4(200),NC(300)P-N00410
2129  //    211           DIMENSION Y1(200),Y2(200),Y3(200),YM(200),IPI(200)                P-N00420
2130  //    212           DIMENSION NRNN(15),NRND(15),NRDD(15),NRDN(15),NRDP(15),NRPD(15),NCP-N00430
2131  //    213          -DD(15),NPAUL1(15),NPAUL2(15)                                      P-N00440
2132  //    214           DIMENSION NPDIR(600)                                              P-N00450
2133  //    215           DIMENSION NEJ(6,15),NRES(6,15),NPIA(6,15),NCHPRO(15),NDEL(15)     P-N00460
2134  //    216           DIMENSION EDEP1(15),EDEP2(15),EDEP3(15),EDEP4(15),NG4INT(15)        P-N00470
2135  //    217          -,EPAR1(15),EPAR2(15),EPAR3(15),EPAR4(15),ENPI(15),E1(15),EZ3(15)  P-N00480
2136  //    218           DIMENSION IHF1(50),IHF2(50),IHF3(50),IHF4(50),IHP(2,100),IHC(50), P-N00490
2137  //    219          -IHE(2,100),IHF5(100),IHREM(100,100)
2138  //    220         
2139  //    221           DIMENSION JPARTICIP(300),eps_c(4),p3_c(4)
2140  //    222         
2141  //    223     C Dialogue with INCL: function R(q/pf) for each nucleus
2142  //    224           COMMON/SAXW/ XX(30,500),YY(30,500),SS(30,500),NBPG4INTER,IMAT
2143  //    225           COMMON/WS/R0,ADIF,RMAXWS,DRWS,NOSURF,XFOISA,NPAULSTR,BMAX     
2144  //    226     
2145  //    227     C RMS espace R, espace P, Fermi momentum and energy for light gauss nuc.     
2146  //    228           COMMON/light_gaus_nuc/rms1t(9),pf1t(9),pfln(9),tfln(9),vnuc(9)
2147  //    229           
2148  //    230     C Fermi 2 param from A=19 to 28, modified harm oscil A=6 to 18
2149  //    231     C (H. De Vries et al. At. Data and Nuc. Data Tab. 36 (1987) 495)
2150  //    232           COMMON/light_nuc/R_light_nuc(30),a_light_nuc(30)     
2151  //    233     
2152  //    234     c common for study of avatars through an ntuple optionally produced
2153  //    235           real*4 bavat,timeavat,energyavat
2154  //    236           G4integer bloc_paul,bloc_cdpp,go_out,avm,del1avat,del2avat
2155  //    237           parameter (avm=1000)
2156  //    238           common/var_avat/kveux,bavat,nopartavat,ncolavat,
2157  //    239          s r1_in(3),r1_first_avat(3),
2158  //    240          s epsd(250),eps2(250),eps4(250),eps6(250),epsf(250),
2159  //    241          s nb_avat,
2160  //    242          s timeavat(avm),l1avat(avm),l2avat(avm),jpartl1(avm),jpartl2(avm),
2161  //    243          s del1avat(avm),del2avat(avm),energyavat(avm),
2162  //    244          s bloc_paul(avm),bloc_cdpp(avm),go_out(avm)
2163  //    245     
2164  //    246           dimension npproj(300)
2165  //    247           common/spl2/ xsp(100),ysp(100),ad(100),bd(100),cd(100),ndeut
2166  //    248     c deutons     
2167  //    249     c     dimension ltt(15)                                                 p-n00520
2168  //    250           common/bl1/p1(300),p2(300),p3(300),eps(300),ind1(300),ind2(300),tap-n00530
2169  //    251           common/bl2/crois(19900),k,ind,jnd                                 p-n00540
2170  //    252           common/bl3/r1,r2,x1(300),x2(300),x3(300),ia1,ia2,rab2             p-n00550
2171  //    253           common/bl4/tmax5                                                  p-n00560
2172  //    254           common/bl5/tlg(300),nesc(300)                                     p-n00570
2173  //    255           common/bl6/xx10,isa                                               p-n00580
2174  //    256           common/bl8/rathr,ramass
2175  //    257           common/bl9/hel(300),l1,l2
2176  //    258           common/bl10/ri4,rs4,r2i,r2s,pf
2177  //    259           common/paul/ct0,ct1,ct2,ct3,ct4,ct5,ct6,pr,pr2,xrr,xrr2,
2178  //    260          s            cp0,cp1,cp2,cp3,cp4,cp5,cp6
2179  //    261         
2180  //    262           dimension ia1t(9),iz1t(9),fmpinct(9)     
2181  //    264           data line/132*1h*/,hc,fmp,fmd,fmpi/197.328,938.2796,1232.,138.00/ p-n00590
2182  G4double hc = 197.328;
2183  G4double fmp = 938.2796;
2184  G4double fmpi = 138.00;
2185  //    265           data /ia1t,iz1t,fmpinct/1,1,0,0,0,2,3,3,4,1,0,1,0,-1,1,1,2,2,
2186  //    266          -938.2796,938.2796,138.0,138.0,138.0,1874.35,2806.8,2806.8,3727.
2187  G4int ia1t[9] = {1,1,0,0,0,2,3,3,4};
2188  G4int iz1t[9] = {1,0,1,0,-1,1,1,2,2};
2189  G4double fmpinct[9] = {938.2796,938.2796,138.0,138.0,138.0,1874.35,2806.8,2806.8,3727.};
2190
2191  // Initialize array:
2192   for(G4int i = 0; i < 300; i++) {
2193     npproj[i] = 0;
2194     nc[i] = 0;
2195   }
2196
2197  //    266         
2198  //    267     c      data rms1t,pf1t/0.,0.,0.,0.,0.,2.10,1.80,1.80,1.63,
2199  //    268     c     -0.,0.,0.,0.,0.,77.,110.,110.,153./
2200  //    269     
2201  //    270     
2202  //    271     c deutons
2203  //    272           data nentr/16000*0/                                               p-n00620
2204  //    389     c                                                                       p-n01700
2205  //    390     ccc   reading of the data                                               p-n01710
2206  //    391     c                                                                       p-n01720
2207  //    392     c-------explanation of some physical quantities------------------------ p-n01730
2208  //    393     c           (basically input data, when run as a program)
2209  //    394     c                                                                       p-n01740
2210  //    395     c     ia1=mass number of the incident ion                               p-n01750
2211  //    396     c                                                                       p-n01760
2212  //    397     c     ia2=mass number of the target                                     p-n01770
2213  //    398     c     iz1=atomic number of the projectile                               p-n01780
2214  //    399     c                                                                       p-n01790
2215  //    400     c     iz2=atomic number of the target                                   p-n01800
2216  //    401     c     r01=radius parameter of the projectile                            p-n01810
2217  //    402     c           r01 should be put to 1.000                                  p-n01820
2218  //    403     c     r02=radius parameter of the target                                p-n01830
2219  //    404     c     adif1=diffuseness of the projectile                               p-n01840
2220  //    405     c           adif1 should be put to 1.0000                               p-n01850
2221  //    406     c     adif2=diffuseness of the target                                   p-n01860
2222  //    407     c                                                                       p-n01870
2223  //    408     c     tlab = incident energy  (in mev)                                  p-n01880
2224  //    409     c                                                                       p-n01890
2225  //    410     c     k1=1 reference frame=c.m. of the covering matter                  p-n01900
2226  //    411     c     k1=2 reference frame=c.m. frame of the incident ion and its       p-n01910
2227  //    412     c          G4intercept                                                    p-n01920
2228  //    413     c     k1=3 reference frame=c.m. frame of a n-n system with the same     p-n01930
2229  //    414     c          kinematics as the two ions                                   p-n01940
2230  //    415     c     k1=4 reference frame=c.m. frame for the total  system             p-n01950
2231  //    416     c     k1=5 reference frame=lab system                                   p-n01960
2232  //    417     c              k1 should be put to 5 in this version                    p-n01970
2233  //    418     c     k2=0 relativistic kinematics                                      p-n01980
2234  //    419     c     k2=1 non-relativistic kinematics(abandonned in this version)      p-n01990
2235  //    420     c     k3=0  deltas are produced                                         p-n02000
2236  //    421     c     k3=1  no delta production                                         p-n02010
2237  //    422     c     k4=0 the delta is given a vanishing lifetime                      p-n02020
2238  //    423     c     k4=1 the delta has a very large lifetime                          p-n02030
2239  //    424     c     k4=2 the delta has a exponentially random lifetime                p-n02040
2240  //    425     c     k5=0 no delta-nucleon,delta-delta G4interactions                    p-n02050
2241  //    426     c     k5=1 delta-nucleon=delta-delta=nucleon-nucleon elastic x-section  p-n02060
2242  //    427     c     k6=0 no angular momentum conservation                             p-n02070
2243  //    428     c     k6=1 angular momentum conservation                                p-n02080
2244  //    429     c                                                                       p-n02090
2245  //    430     c     b=impact parameter                                                p-n02100
2246  //    431     c                                                                       p-n02110
2247  //    432     c     rbl(pbl) is the radius in real(momentum) space of the volume      p-n02120
2248  //    433     c         on which the nucleons are counted to evaluate the pauli       p-n02130
2249  //    434     c         blocking factors                                              p-n02140
2250  //    435     c     recommended values are 2 fm and 200 mev/c respectively            p-n02150
2251  //    436     c                                                                       p-n02160
2252  //    437     c     nrun= number of  runs (irrelevant here)                           p-n02170
2253  //    438     c                                                                       p-n02180
2254  //    439     c     ntm=number of G4intermediate times at which the spatial and momentump-n02190
2255  //    440     c         distributions are stored (not relevant here)                  p-n02200
2256  //    441     c                                                                       p-n02210
2257  //    442     c     tem(it)=values of the G4intermediate times                          p-n02220
2258  //    443     c                                                                       p-n02230
2259  //    444     c     v0=depth of the nucleon potential                                 p-n02240
2260  //    445     c     v1=depth of the delta potential                                   p-n02250
2261  //    446     c         in this version v1 should be equal to v0                      p-n02260
2262  //    447     c         (attention! a  v0 > 0 corresponds to an attractive potential) p-n02270
2263  //    448     c                                                                       p-n02280
2264  //    449     c     ncase=number of cells necessary to depict the spatial distributionp-n02290
2265  //    450     c         in the x and z directions                                     p-n02300
2266  //    451     c                                                                       p-n02310
2267  //    452     c     xp,xg,zp,zg=limits of the box in the x and z directions           p-n02320
2268  //    453     c     in order to have the same scale in the two directions ,put xg-xp= p-n02330
2269  //    454     c         0.9*(zg-zp)                                                   p-n02340
2270  //    455     c     dy=dimension of the box in the y direction                        p-n02350
2271  //    456     c                                                                       p-n02360
2272  //    457     c     rap1,rap2,pp1,pp2=limits of the box in the rapidity-p(perpendicu- p-n02370
2273  //    458     c          -lar) space                                                  p-n02380
2274  //    459     c     the box is divided G4into 15 cells along p(perp) and 40 cells along p-n02390
2275  //    460     c         the rapidity                                                  p-n02400
2276  //    461     c                                                                       p-n02410
2277  //    462     c     en,sn=average energy carried away by a nucleon,separation energy  p-n02420
2278  //    463     c                                                                       p-n02430
2279  //    464     c       (ntm,ncase,xp,...,sn are not used here)
2280  //    465     c-----------------------------------------------------------------------p-n02440
2281
2282  // for logging
2283  //  std::ofstream dumpOut("inclDump.txt");
2284  // end for logging
2285
2286  G4int jparticip[BL1SIZE];
2287  for(G4int i = 0; i < BL1SIZE; i++) {
2288    jparticip[i] = 0;
2289  }
2290
2291  G4double beproj = 0.;
2292  bl3->ia2 = G4int(std::floor(calincl->f[0] + 0.1)); // f(1)->f[0] and so on..., calincl added
2293  G4int iz2 = G4int(std::floor(calincl->f[1] + 0.1));
2294  G4double r02 = 1.12;
2295  kindstruct->kindf7 = int(std::floor(calincl->f[6] + 0.1));
2296
2297  bl3->ia1 = ia1t[G4int(kindstruct->kindf7)-1];
2298  G4int iz1 = iz1t[G4int(kindstruct->kindf7)-1];
2299  G4double fmpinc = fmpinct[G4int(kindstruct->kindf7)-1];
2300  G4double rms1 = light_gaus_nuc->rms1t[G4int(kindstruct->kindf7)-1];
2301  G4double pf1 = light_gaus_nuc->pf1t[G4int(kindstruct->kindf7)-1];
2302  G4double tlab = calincl->f[2];
2303
2304  G4int k2 = 0;
2305  G4int k3 = 0;
2306  //  G4int k3 = 1; // No deltas!
2307  G4int k4 = 2;
2308  G4int k5 = 1;
2309  G4int k6 = 0;
2310
2311  // material number:     
2312  saxw->imat = G4int(std::floor(calincl->f[8] + 0.5)); // f(9) -> f[8]
2313  // espace de phases test (r et p) pour pauli:
2314  // valeur recommandee par j.c. v-test=0.589 h**3:
2315  G4double rbl = 2.0;
2316  G4double pbl=200.0;
2317
2318  paul->xrr = rbl;
2319  paul->xrr2 = (paul->xrr) * (paul->xrr);
2320  paul->pr=pbl;
2321  paul->pr2 = paul->pr*(paul->pr);
2322
2323  G4double tem[10];
2324  tem[0] = 100000.0;  // tem(1) -> tem[0]
2325  // temfin (time at which the inc is stopped), tmax5 defined after chosing b
2326
2327  G4double v0 = calincl->f[4]; // f(5)->f[4]
2328  G4double v1 = v0;
2329  bl8->rathr = 0.;
2330  bl8->ramass = 0.;
2331
2332  // constants and derived data
2333  bl10->pf = 1.37*hc;
2334  G4double tf = std::sqrt(bl10->pf*(bl10->pf)+fmp*fmp)-fmp;
2335  G4double g0 = 115.0;
2336  G4double th = 0.;
2337  G4double pm2 = fmp*fmp;
2338  G4int ia = bl3->ia1 + bl3->ia2;
2339  G4int a2 = bl3->ia2;
2340  bl3->r2 = r02*std::pow(G4double(a2),0.33333333);
2341
2342  // parametres moyens de densite de la cible (fermi 2 parametres)
2343  if (bl3->ia2 >= 28) { //then
2344    ws->r0 = (2.745e-4*bl3->ia2+1.063)*std::pow(G4double(bl3->ia2),0.33333333);
2345    ws->adif = 1.63e-4*bl3->ia2 + 0.510;
2346    ws->rmaxws = ws->r0 + ws->xfoisa*(ws->adif);
2347  }
2348  else if(bl3->ia2 >= 19) { //then
2349    ws->r0 = light_nuc->r[bl3->ia2-1];
2350    ws->adif = light_nuc->a[bl3->ia2-1];
2351    ws->rmaxws = ws->r0 + ws->xfoisa*(ws->adif);
2352  }
2353  else if(bl3->ia2>=6) { //then
2354    ws->r0 = 1.581*(light_nuc->a[bl3->ia2-1]) * (2.0 + 5.0 * (light_nuc->r[bl3->ia2-1]))/(2.0 + 3.0*(light_nuc->r[bl3->ia2-1]));
2355    ws->adif = light_nuc->a[bl3->ia2-1];
2356    ws->rmaxws = 5.5 + 0.3*(double(bl3->ia2) - 6.0)/12.0;
2357  }
2358  else if(bl3->ia2 >= 2) { // then
2359    if(bl3->ia2 == 2) { //then
2360      ws->r0 = light_gaus_nuc->rms1t[5]; // rms1t(6) -> rms1t[5]
2361      bl10->pf = light_gaus_nuc->pfln[5]; //pfln(6)->pfln[5]
2362      tf = light_gaus_nuc->tfln[5]; // tfln(6) -> tfln[5]
2363      v0 = light_gaus_nuc->vnuc[5]; // vnuc(6) -> vnuc(5)
2364    } //endif
2365    if(bl3->ia2 == 3 && iz2 == 1) { //then
2366      ws->r0 = light_gaus_nuc->rms1t[6]; //rms1t(7)->rms1t[6] and so on...
2367      bl10->pf = light_gaus_nuc->pfln[6];
2368      tf = light_gaus_nuc->tfln[6];
2369      v0 = light_gaus_nuc->vnuc[6];
2370    } //endif
2371    if(bl3->ia2 == 3 && iz2 == 2) { //then
2372      ws->r0 = light_gaus_nuc->rms1t[7]; //rms1t(8)->rms1t[7] and so on...
2373      bl10->pf = light_gaus_nuc->pf1t[7];
2374      tf = light_gaus_nuc->tfln[7];
2375      v0 = light_gaus_nuc->vnuc[7];
2376    } //endif
2377    if(bl3->ia2 == 4) { //then
2378      ws->r0 = light_gaus_nuc->rms1t[8]; // rms1t(9) -> rms1t[8] and so on...
2379      bl10->pf = light_gaus_nuc->pf1t[8];
2380      tf = light_gaus_nuc->tfln[8];
2381      v0 = light_gaus_nuc->vnuc[8];
2382    } //endif
2383    v1 = v0;
2384    ws->adif = 0.57735*(ws->r0);
2385    ws->rmaxws = ws->r0+2.5;
2386  } // end if
2387  if(ws->nosurf > 0) { //then
2388    ws->adif=0.0;
2389    ws->rmaxws=ws->r0;
2390  } //end if
2391  ws->drws = ws->rmaxws/29.0;
2392
2393  // on impose le rayon du noyau:
2394  // ....voir coherence function wsax(r) et derivwsax(r)
2395  bl3->r2 = ws->r0;
2396  if(verboseLevel > 3) {
2397    G4cout <<"Radius bl3->r2 = " << bl3->r2 << G4endl;
2398  }
2399 
2400  G4double tnr = tlab;
2401  G4double binc = std::sqrt(tnr*tnr + 2.0*tlab*fmpinc)/(tnr+fmpinc);
2402  G4double ginc=1.0/std::sqrt(1.0 - binc*binc);
2403  G4double pinc = fmpinc*binc*ginc;
2404
2405  for(G4int bli = 0; bli < BL1SIZE; bli++) {
2406    bl1->eps[bli] = 0.0;
2407    bl1->p1[bli] = 0.0;
2408    bl1->p2[bli] = 0.0;
2409    bl1->p3[bli] = 0.0;
2410    q1[bli] = 0.0;
2411    q2[bli] = 0.0;
2412    q3[bli] = 0.0;
2413    q4[bli] = 0.0;
2414  }
2415
2416  // skip initialisations
2417  G4double efrun = 0.0;
2418  G4int iavat = 0;
2419
2420  // generation of the initial distribution in the rest frame of the iop-n03870
2421  // surface
2422  //    700     c      bmax=r2+2.2*adif
2423  //    701     c      r2i=(r2-2.2*adif)
2424  //    702     c      r2s=(r2+2.2*adif)
2425  //    703     c **********
2426  //    704           
2427
2428  ws->bmax = ws->rmaxws;                // maximum extension of the nucleus ( w.s.)
2429
2430  //  fin surface (que faire aux pions ?)
2431  //    709     c      if (kindf7.gt.2) bmax=r2+2.2
2432  //    710     c      if (kindf7.gt.2) bmax=bmax       ! a.b. (avec w.s., idem les nucleons)
2433  // deutons cv 22/01/2001
2434  if (kindstruct->kindf7 <= 2)  { //then
2435    ws->bmax = ws->bmax;     // comme alain
2436  }
2437  else {
2438    if (kindstruct->kindf7 < 6) { // then   
2439      ws->bmax = ws->bmax;   // comme alain
2440    }
2441    else {
2442      beproj = fmpinc - bl3->ia1*fmp;
2443      ws->bmax = ws->rmaxws + rms1;     // maximum extension of the nucleus ( w.s.)
2444    }
2445  }
2446
2447  // deutons     
2448  G4double al;
2449  standardRandom(&al, &(hazard->ial));
2450  G4double b = std::sqrt(al)*(ws->bmax);
2451  G4double bred = b/bl3->r2;
2452  //G4double bimpact=b;
2453  bimpact = b;
2454  G4double tnor;
2455
2456  if(ws->nosurf != -2) { // la suite, c'est la version temps avant 2001
2457    if(ws->nosurf <= 0) {
2458      tnor = 70.0/30.6349;         
2459    }
2460    // PK endif removed
2461    else {
2462      tnor=1.;
2463    } //endif               
2464    if(ws->nosurf == 0) {
2465      bred = 0.;
2466    }
2467    if (kindstruct->kindf7 <= 2) {
2468      if (tlab < 400.0) {
2469        cb0 = 6.86 - 0.0035 * tlab;
2470        eb0 = 0.32 - 0.00005 * tlab;
2471      }
2472      else {
2473        if (tlab < 1000.0) { //then
2474          cb0 = 5.23 + 0.000575 * tlab;
2475          eb0 = 0.32 - 0.00005 * tlab;
2476        }
2477        else {
2478          cb0 = 5.73 + 0.00007 * tlab;
2479          eb0 = 0.283 - 0.000013 * tlab;
2480        }
2481      }
2482      temfin = 1.25*cb0/amax1(1.0,0.854 + 0.438*bred)*std::pow(G4double(bl3->ia2),(eb0/amax1(1.0,0.941+0.177*bred)));
2483      temfin = temfin*tnor;
2484    }
2485    else {
2486      if (kindstruct->kindf7 < 6) {
2487        // here for pions:
2488        temfin = 30.0*std::pow((float(bl3->ia2)/208.0),0.25)*(1.0 - 0.2*bred)*(1.0 - tlab/1250.0);
2489        // correction for pions in the case nosurf=0 or -1 (a.b., c.v. 2/2002)
2490        temfin = temfin*tnor;
2491      }
2492      else {
2493        // deutons
2494        tlabu = tlab/double(bl3->ia1);
2495        if (tlabu <= 400) {
2496          coeffb0 = -0.0035*tlabu + 6.86;
2497          expob0 = -0.00005*tlabu + 0.32;
2498        }
2499        else {
2500          if (tlabu <= 1000) { //then   
2501            coeffb0 = 0.000575*tlabu + 5.23;
2502            expob0 = -0.00005*tlabu + 0.32;
2503          }
2504          else {
2505            coeffb0 = 0.00007*tlabu + 5.73;
2506            expob0 = -0.000013*tlabu + 0.283;
2507          }
2508        }
2509        if (bred <= 0.33333) {
2510          xc = 1.0;
2511          xe = 1.0;
2512        }
2513        else {
2514          xc = 0.438*bred + 0.854;
2515          xe = 0.177*bred + 0.941;
2516        }
2517        temfin = 1.25*(coeffb0/xc)*std::pow(G4double(bl3->ia2),(expob0/xe));
2518        // same renormalisation of time for p,n and composit particles.
2519        temfin = temfin*tnor;
2520      }
2521    }
2522  }
2523  else { //ici,nosurf=-2 c'est la fonction temps 2001 (avec surface).
2524    if(kindstruct->kindf7 >= 3 && kindstruct->kindf7 <= 5) {
2525      // here for pions (arbitrary multiplied by 2 for surface) (a.b., c.v.) 2/2002:
2526      // temfin=60.*(float(ia2)/208.)**0.25*(1.-0.2*bred)*(1.-tlab/1250.)
2527      // modified in april 2003 (more reasonable but not yet checked!)
2528      temfin = 25.5*std::pow(G4double(bl3->ia2),0.16);  // pb208->60fm/c
2529    }
2530    else {
2531      // here for other hadrons
2532      temfin = 29.8*std::pow(G4double(bl3->ia2),0.16);  // pb208->70fm/c
2533    }
2534  }
2535
2536  // deutons
2537  // a way to change stopping time f[5] not used here
2538  factemp = calincl->f[5]; // f(6)->f[5]
2539  // attention !!! 30/04/2001 scaling time is now a multiplication factor
2540  temfin = temfin*factemp;
2541
2542  exi = 0.0;
2543  nbquit = 0;
2544  iqe = 0;
2545  idecf = 0;
2546  bl4->tmax5 = temfin+0.1;
2547  npion = 0;
2548  efer = 0.0;
2549
2550  // deutons
2551  if (bl3->ia1 > 1) {
2552    goto pnu7;
2553  }
2554
2555  // deutons
2556  if (bl3->ia1 == 1) { //then
2557    //    bl5->nesc[0] = 0; // nesc(1)->nesc[0] and so on...
2558    bl5->nesc[1] = 0;
2559    //    bl1->ind2[0] = 2*iz1 - 1;
2560    bl1->ind2[1] = 2*iz1 - 1;
2561    bl1->ind1[1] = 0;
2562    bl3->x1[1] = 0.0;
2563    bl3->x2[1] = 0.0;
2564    bl3->x3[1] = 0.0;
2565    bl1->p1[1] = 0.0;
2566    bl1->p2[1] = 0.0;
2567    bl1->p3[1] = 0.0;
2568    bl9->hel[0] = 0.0;
2569    bl9->hel[1] = 0.0;
2570    jparticip[0] = 0;
2571    jparticip[1] = 1;
2572  }
2573  else {
2574    npion = 1;
2575    ipi[1] = 8 - 2*(kindstruct->kindf7);
2576    y1[1] = 0.0;
2577    y2[1] = 0.0;
2578    y3[1] = 0.0;
2579    q1[1] = 0.0;
2580    q2[1] = 0.0;
2581    q3[1] = 0.0;
2582    q4[1] = fmpi;
2583  }
2584
2585  // deutons
2586  goto pnu9;
2587  //    850     
2588 pnu7: 
2589  s1t1 = 0.0;
2590  s2t1 = 0.0;
2591  s3t1 = 0.0;
2592  sp1t1 = 0.0;
2593  sp2t1 = 0.0;
2594  sp3t1 = 0.0;
2595  for(G4int i = 1; i <= bl3->ia1; i++) {
2596  //for(G4int i = 1; i <= (bl3->ia1-1); i++) {
2597  //  for(G4int i = 1; i < (bl3->ia1-1); i++) {
2598    bl9->hel[i] = 0;
2599    bl5->nesc[i] = 0;
2600    bl1->ind2[i] = 1;
2601    if (i > iz1) {
2602      bl1->ind2[i] = -1;
2603    }
2604    bl1->ind1[i] = 0;
2605    // deutons
2606    jparticip[i] = 1;
2607
2608    // deutons
2609    gaussianRandom(&xga);
2610    bl3->x1[i] = xga*rms1*0.57735;
2611    s1t1 = s1t1 + bl3->x1[i];
2612    gaussianRandom(&xga);
2613    bl3->x2[i] = xga*rms1*0.57735;
2614    s2t1 = s2t1 + bl3->x2[i];
2615    gaussianRandom(&xga);
2616    bl3->x3[i] = xga*rms1*0.57735; 
2617    s3t1 = s3t1 + bl3->x3[i];
2618
2619    if(kindstruct->kindf7 == 6) { //then
2620      // deuteron density from paris potential in q space:     
2621      standardRandom(&xq, &(hazard->igraine[9]));
2622      qdeut = splineab(xq) * 197.3289;
2623      standardRandom(&u, &(hazard->igraine[10]));
2624      cstet = u*2 - 1;
2625      sitet = std::sqrt(1.0 - std::pow(cstet,2));
2626      standardRandom(&v, &(hazard->igraine[11]));
2627      phi = 2.0*3.141592654*v;
2628
2629      bl1->p1[i] = qdeut*sitet*std::cos(phi);
2630      bl1->p2[i] = qdeut*sitet*std::sin(phi);
2631      bl1->p3[i] = qdeut*cstet;
2632    }
2633    else {
2634      // density of composite as a gaussien in q space:
2635      gaussianRandom(&xga);
2636      bl1->p1[i] = xga*pf1*0.57735;
2637      gaussianRandom(&xga);
2638      bl1->p2[i] = xga*pf1*0.57735;
2639      gaussianRandom(&xga);
2640      bl1->p3[i] = xga*pf1*0.57735;
2641    }
2642
2643    bl1->eps[i] = w(bl1->p1[i],bl1->p2[i],bl1->p3[i],fmp);
2644
2645    sp1t1 = sp1t1 + bl1->p1[i];
2646    sp2t1 = sp2t1 + bl1->p2[i];
2647    sp3t1 = sp3t1 + bl1->p3[i];
2648  }
2649
2650  bl9->hel[bl3->ia1] = 0;
2651  bl5->nesc[bl3->ia1] = 0;
2652  bl1->ind2[bl3->ia1] = -1;
2653  bl1->ind1[bl3->ia1] = 0;
2654  bl3->x1[bl3->ia1] = -s1t1;
2655  bl3->x2[bl3->ia1] = -s2t1;
2656  bl3->x3[bl3->ia1] = -s3t1;
2657  bl1->p1[bl3->ia1] = -sp1t1;
2658  bl1->p2[bl3->ia1] = -sp2t1;
2659  bl1->p3[bl3->ia1] = -sp3t1;
2660  bl1->eps[bl3->ia1] = w(bl1->p1[bl3->ia1],bl1->p2[bl3->ia1],bl1->p3[bl3->ia1],fmp);
2661 
2662  // deutons
2663  jparticip[bl3->ia1] = 1;
2664  if(verboseLevel > 3) {
2665    G4cout <<"Particle " << bl3->ia1-1 << " is now participant." << G4endl;
2666  }
2667 pnu9: // continue
2668  // deutons
2669  // target preparation for 1 < a < 5 (with sum of momentum =0)
2670  if(bl3->ia2 >= 2 && bl3->ia2 <= 4) {
2671  pnu1633: 
2672    s1t1 = 0.0;
2673    s2t1 = 0.0;
2674    s3t1 = 0.0;
2675    sp1t1 = 0.0;
2676    sp2t1 = 0.0;
2677    sp3t1 = 0.0;
2678    efer = 0.0;
2679    for(G4int i = bl3->ia1+1; i <= ia; i++) {
2680    //    for(G4int i = bl3->ia1; i < ia-1; i++) {
2681    //    for(G4int i = bl3->ia1; i < ia; i++) {
2682      bl1->ind2[i] = 1;
2683      bl5->nesc[i] = 0;
2684      if (i > (iz2+bl3->ia1)) {
2685        bl1->ind2[i] = -1;
2686      }
2687      for(G4int j = 0; j < 7; j++) {
2688        standardRandom(&t[j], &(hazard->ial));
2689      }
2690
2691      t[1] = -1.0 + 2.0*t[1];      // t(2)->t[1]                                       
2692      t[2] = 6.283185*t[2];   // t(3)->t[2]                                     
2693      t[4] = -1.0 + 2.0*t[4];     // t(5)->t[4]                                 
2694      t[5] = 6.283185*t[5];   // t(6) -> t[5]                                     
2695      t1 = t[1];              // t(2)->t[1]                                           
2696      t2 = std::sqrt(1.0 - t1*t1);                                       
2697      t3 = std::cos(t[2]);  //t(3)->t[2]                                           
2698      t4 = std::sin(t[2]);   //t(3)->t[2]                                                                                     
2699      t5 = t[4];       // t(5)->t[4]                                                 
2700      t6 = std::sqrt(1.0 - t5*t5);                                         
2701      t7 = std::cos(t[5]);   //t(6) -> t[5]                                             
2702      t8 = std::sin(t[5]);   // t(6)->t[5]                                         
2703      if (ws->nosurf == 1) {
2704        x = bl3->r2*std::pow(t[0],0.33333333); // t(1)->t[0]                                     
2705        y = (bl10->pf)*std::pow(t[3],0.33333333); // t(4)->t[3] 
2706      }
2707      else {
2708        // surface..w.s.: impulsion (sphere dure), puis r(q)
2709        t33 = std::pow(t[6],0.33333333); // t(7)->t[6]
2710        y = (bl10->pf)*t33;
2711
2712        rr = interpolateFunction(t33);
2713        x = rr*std::pow(t[3],0.33333333); // t(4)->t[3]
2714        // fin surface on a redefini x et y
2715      }
2716      bl3->x1[i] = x*t2*t3;                                               
2717      bl3->x2[i] = x*t2*t4; 
2718      bl3->x3[i] = x*t1;                                                   
2719      s1t1 = s1t1 + bl3->x1[i];
2720      s2t1 = s2t1 + bl3->x2[i];
2721      s3t1 = s3t1+bl3->x3[i];
2722      bl1->p1[i] = y*t6*t7; 
2723      bl1->p2[i] = y*t6*t8;                                                 
2724      bl1->p3[i] = y*t5;                                                   
2725      sp1t1 = sp1t1+bl1->p1[i];
2726      sp2t1 = sp2t1+bl1->p2[i];
2727      sp3t1 = sp3t1+bl1->p3[i];
2728      bl1->ind1[i] = 0;                                                     
2729      bl1->eps[i] = w(bl1->p1[i],bl1->p2[i],bl1->p3[i],fmp);                           
2730      bl9->hel[i] = 0.0;
2731      efer = efer + bl1->eps[i] - fmp;                                       
2732    }
2733
2734    bl9->hel[ia] = 0; 
2735    bl5->nesc[ia] = 0;
2736    bl1->ind2[ia] = -1;
2737    bl1->ind1[ia] = 0;
2738    bl3->x1[ia] = -s1t1;
2739    bl3->x2[ia] = -s2t1;
2740    bl3->x3[ia] = -s3t1;
2741    bl1->p1[ia] = -sp1t1;
2742    bl1->p2[ia] = -sp2t1;
2743    bl1->p3[ia] = -sp3t1;
2744
2745    p_mod = std::sqrt(std::pow(bl1->p1[ia],2) + std::pow(bl1->p2[ia],2) + std::pow(bl1->p3[ia],2));
2746    if(p_mod > ((bl10->pf)+0.05)) {
2747      goto pnu1633;
2748    }
2749
2750    bl1->eps[ia] = w(bl1->p1[ia],bl1->p2[ia],bl1->p3[ia],fmp);
2751   
2752    efer = efer + bl1->eps[ia]-fmp;                                       
2753
2754  } //end if       !(bl3->ia2 >= 2 && bl3->ia2 <= 4)
2755
2756  // target preparation for a > 4
2757  if(bl3->ia2 > 4) {
2758    x1_target = 0.0;
2759    x2_target = 0.0;
2760    x3_target = 0.0;
2761    for(G4int i = bl3->ia1+1; i <= ia; i++) { //do 1 i=bl3->ia1+1,ia
2762      bl5->nesc[i] = 0;
2763      bl1->ind2[i] = 1;
2764      if (i > (iz2+bl3->ia1)) {
2765        bl1->ind2[i] = -1;
2766      }
2767      // surface ajout de t(7) surface.f avait do 6 j=2,7 ici 1,6 ?
2768      for(G4int j = 0; j < 7; j++) {
2769        standardRandom(&t[j], &(hazard->ial));
2770      }
2771
2772      //    pnu6: // continue
2773      t[1] = -1.0 + 2.0*t[1]; //t(2)->t[1]
2774      t[2] = 6.283185*t[2];
2775      t[4] = -1.0 + 2.0*t[4]; // t(5)->t[4]
2776      t[5] = 6.283185*t[5]; //t(6)->t[5]
2777      t1 = t[1]; // t(2)->t[1]
2778      t2 = std::sqrt(1.0 - t1*t1);
2779      t3 = std::cos(t[2]);  //t(3)->t[2]
2780      t4 = std::sin(t[2]); //t(3)->t[2]
2781      t5 = t[4]; //t(5)->t[4]
2782      t6 = std::sqrt(1.0 - t5*t5);
2783      t7 = std::cos(t[5]);  //t(6)->t[5]
2784      t8 = std::sin(t[5]);   // t(6)->t[5]
2785
2786      if (ws->nosurf == 1) {
2787        x = bl3->r2*std::pow(t[0],0.33333333); // t(1)->t[0]
2788        y = bl10->pf*std::pow(t[3],0.33333333); // t(4)->t3
2789      }
2790      else {
2791        // surface..w.s.: impulsion (sphere dure), puis r(q)
2792        t33 = std::pow(t[6],0.33333333); // t(7)->t[6]
2793        y=bl10->pf*t33;
2794        rr=interpolateFunction(t33);
2795        x=rr*std::pow(t[3],0.33333333); // t(4)->t[3]       
2796        // fin surface on a redefini x et y
2797      }
2798      bl3->x1[i] = x*t2*t3;
2799      bl3->x2[i] = x*t2*t4;
2800      bl3->x3[i] = x*t1;
2801      bl1->p1[i] = y*t6*t7;
2802      bl1->p2[i] = y*t6*t8;
2803      bl1->p3[i] = y*t5;
2804      x1_target = x1_target + bl3->x1[i];
2805      x2_target = x2_target + bl3->x2[i];
2806      x3_target = x3_target + bl3->x3[i];
2807      bl1->ind1[i] = 0;
2808      bl1->eps[i] = w(bl1->p1[i],bl1->p2[i],bl1->p3[i],fmp);
2809
2810      bl9->hel[i] = 0.0;
2811      efer = efer + bl1->eps[i] - fmp;
2812    }
2813    x1_target = x1_target/double(bl3->ia2);
2814    x2_target = x2_target/double(bl3->ia2);
2815    x3_target = x3_target/double(bl3->ia2);
2816  }
2817
2818  efrun = efrun + efer;
2819
2820  // location of incident particle at point (b,z)
2821  r22 = bl3->r2*(bl3->r2);
2822  z = ws->bmax * (ws->bmax) - b*b;       // for the wood-saxon density...
2823
2824  if (z < 0.0) {
2825    z=0.0;
2826  }
2827
2828  z = std::sqrt(z);
2829  // random azimuthal direction of the impact parameter (sept 99)
2830
2831  if (kindstruct->kindf7 <= 2) {
2832    G4long testseed = hazard->igraine[13];
2833    //    standardRandom(&tbid, &(hazard->igraine[13]));
2834    standardRandom(&tbid, &testseed);
2835    hazard->igraine[13] = testseed;
2836    tbid = tbid*6.283185;
2837    bl3->x1[1] = bl3->x1[1] + b*std::cos(tbid);  //x1(1)->x1[1]                                       
2838    bl3->x2[1] = bl3->x2[1] + b*std::sin(tbid); //x2(1)->x2[1]
2839    bl3->x3[1] = bl3->x3[1] - z;
2840    // pour le ntuple des avatars:
2841    if(varavat->kveux == 1) {
2842      varavat->r1_in[0] = bl3->x1[1]; //r1_in(1)->r1_in[0] and x1(1)->x1[0]
2843      varavat->r1_in[1] = bl3->x2[1]; //r1_in(2)->r1_in[1] and x1(2)->x1[1]
2844      varavat->r1_in[2] = bl3->x3[1]; //r1_in(3)->r1_in[2] and x1(3)->x1[2]
2845    } //endif
2846  }
2847  else {
2848    if (kindstruct->kindf7 < 6) { //then ! pour les pions on laisse
2849      //call standardRandom(tbid,iy14)
2850      standardRandom(&tbid, &(hazard->igraine[13]));
2851      tbid = tbid*6.283185;
2852      y1[1] = y1[1] + b*std::cos(tbid); //y1(1)->y1[0]
2853      y2[1] = y2[1] + b*std::sin(tbid); //y2(1)->y2[0]
2854      y3[1] = y3[1] - z;
2855    }
2856    else {
2857      // deutons
2858      //nmiss=0.;
2859      nmiss = 0;
2860      xlengm=1000.0;
2861     
2862      for(G4int i = 1; i <= bl3->ia1; i++) {
2863      //      for(G4int i = 1; i < bl3->ia1; i++) {
2864        bl3->x3[i] = bl3->x3[i]/ginc;
2865        zai2 = ws->rmaxws*(ws->rmaxws) - std::pow((b+bl3->x1[i]),2) - std::pow(bl3->x2[i],2);
2866        if (zai2 < 0.0) {
2867          goto pnu22;
2868        }
2869        ztu = -std::sqrt(zai2);
2870        // r22 remplace par rmaxws*rmaxws et r2 par rmaxws cv correct ?
2871        za_i = 2.0*(ws->rmaxws) + ztu;
2872        xleng = za_i - bl3->x3[i];
2873        if (xleng > xlengm) {
2874          //  goto pnu21;
2875          continue;
2876        }
2877        ilm = i;
2878        xlengm = xleng;
2879        ztouch = ztu;
2880        //      goto pnu21;
2881        continue;
2882      pnu22:
2883        nmiss = nmiss + 1; 
2884      }
2885      //    pnu21:
2886      if (nmiss == bl3->ia1) { //then
2887        nopart = -1;
2888        //      return;
2889        if(verboseLevel > 3) {
2890          G4cout <<"nmiss == bl3->ia1" << G4endl;
2891          G4cout <<"End of algorithm after pnu21." << G4endl;
2892        }
2893        goto pnureturn;
2894      }
2895      else {
2896        zshif = bl3->x3[ilm] - ztouch;
2897        standardRandom(&tbid, &(hazard->igraine[13]));
2898        tbid = tbid*6.283185;
2899        for(G4int i = 1; i <= bl3->ia1; i++) {
2900          xxx = bl3->x1[i] + b;
2901          bl3->x1[i] = xxx*std::cos(tbid) - bl3->x2[i]*std::sin(tbid);
2902          bl3->x2[i] = xxx*std::sin(tbid) + bl3->x2[i]*std::cos(tbid);
2903          bl3->x3[i] = bl3->x3[i] - zshif;
2904        }
2905        if (std::fabs(std::pow(bl3->x1[ilm],2)+std::pow(bl3->x2[ilm],2)+std::pow(bl3->x3[ilm],2)-ws->rmaxws*(ws->rmaxws)) > 0.01) {
2906          if(verboseLevel > 2) {
2907            G4cout <<"wrong position" << G4endl;
2908          }
2909        }
2910      }
2911    }
2912  }
2913
2914  // initial momentum for all type of incident particles:
2915  xl1 = b*pinc*std::sin(tbid);                                 
2916  xl2 = -b*pinc*std::cos(tbid);                                         
2917  xl3 = 0.0;                                           
2918
2919  // transcription in the general frame of reference
2920  // (here,=lab frame)
2921
2922  be = 0.0;
2923  ge = 1.0;
2924  b1 = (binc - be)/(1.0 - be*binc);
2925  b2 = -be;
2926  g1 = 1.0/std::sqrt(1.0 - b1*b1);
2927  g2 = 1.0;
2928  // deutons
2929  // here for nucleons
2930  if (kindstruct->kindf7 <= 2) {
2931    bl1->eps[1] = g1*fmp + v0;
2932    bl1->p3[1] = std::sqrt(std::pow(bl1->eps[1],2) - std::pow(fmp,2));
2933  }
2934  else {
2935    // here for pions
2936    if (kindstruct->kindf7 < 6) { //then
2937      q4[1] = g1*fmpi; // q4(1)->q4[0]
2938      q3[1] = b1*q4[1];
2939    }
2940    else {
2941      // here for composite projectiles:
2942      // the kinetic energy is below the threshold. put all
2943      // fermi momentum to 0... projectile nucleons not on shell!
2944      energie_in = tlab + fmpinc;
2945      if((energie_in) <= (bl3->ia1*fmp)) {
2946        for(G4int i = 1; i <= bl3->ia1; i++) {
2947          bl1->eps[i] = energie_in/double(bl3->ia1);
2948          bl1->p1[i] = 0.0;
2949          bl1->p2[i] = 0.0;
2950          bl1->p3[i] = pinc/double(bl3->ia1);
2951        }
2952        goto pnu1871;
2953      }
2954      // here the composit is above threshold
2955      for(G4int i = 1; i <= bl3->ia1; i++) { //do i=1,bl3->ia1  !save e,p in the composit rest frame
2956        eps_c[i] = bl1->eps[i];
2957        p3_c[i] = bl1->p3[i];
2958      } //enddo
2959
2960      nbtest = bl3->ia1 - 1;
2961      if(kindstruct->kindf7 == 6) {
2962        nbtest = 2;
2963      }
2964      iflag = 0;
2965    pnu1870:
2966      sueps = 0.0;
2967
2968      iflag = iflag + 1;
2969
2970      for(G4int i = 1; i <= bl3->ia1; i++) { //do i=1,bl3->ia1
2971        tte = eps_c[i];
2972        bl1->eps[i] = g1*(eps_c[i] + b1*p3_c[i]);
2973        bl1->p3[i] = g1*(b1*tte + p3_c[i]);
2974        sueps = sueps + bl1->eps[i];
2975      } //enddo
2976
2977      cobe = (tlab + fmpinc)/sueps;
2978
2979      // off shell problem for incident clusters (a.b. 2/2002)
2980
2981      if(iflag == nbtest) { // too much..all momentum to 0
2982        for(G4int klm = 1; klm <= bl3->ia1; klm++) { //do klm=1,bl3->ia1
2983          eps_c[klm] = fmp;
2984          bl1->p1[klm] = 0.0;
2985          bl1->p2[klm] = 0.0;
2986          p3_c[klm] = 0;
2987        }
2988        goto pnu1870;
2989      }
2990      for(G4int i = 1; i <= bl3->ia1; i++) { //do i=1,bl3->ia1
2991        arg = std::pow((cobe*(bl1->eps[i])),2)-pm2;
2992        if (arg <= 0.) { //then ! put maximum momentum to 0.
2993          i_emax = 1; //        !find maximum
2994          ener_max = bl1->eps[1];
2995          for(G4int klm = 2; klm <= bl3->ia1; klm++) { //do klm=2,bl3->ia1     
2996            if(bl1->eps[klm] > ener_max) {
2997              ener_max = bl1->eps[klm];
2998              i_emax = klm;
2999            }
3000          }
3001          eps_c[i_emax] = fmp;
3002          bl1->p1[i_emax] = 0.0;
3003          bl1->p2[i_emax] = 0.0;
3004          p3_c[i_emax] = 0.0;
3005
3006          if(i_emax == bl3->ia1) { //    circular permut if the last one
3007            epsv = eps_c[bl3->ia1]; //   permutation circulaire
3008            p1v = bl1->p1[bl3->ia1];
3009            p2v = bl1->p2[bl3->ia1];
3010            p3v = p3_c[bl3->ia1];
3011            for(bl2->k = bl3->ia1-1; bl2->k >= 1; bl2->k = bl2->k - 1) { //do k=bl3->ia1-1,1,-1
3012              eps_c[bl2->k+1] = eps_c[bl2->k];
3013              bl1->p1[bl2->k+1] = bl1->p1[bl2->k];
3014              bl1->p2[bl2->k+1] = bl1->p2[bl2->k];
3015              p3_c[bl2->k+1] = p3_c[bl2->k];
3016            }
3017            eps_c[1] = epsv;
3018            bl1->p1[1] = p1v;
3019            bl1->p2[1] = p2v;
3020            p3_c[1] = p3v;      // fin permut.
3021          }
3022          sp1t1 = 0.0;   // re-compute the last one
3023          sp2t1 = 0.0;
3024          sp3t1 = 0.0;
3025          for(G4int j = 1; j <= bl3->ia1-1; j++) { //do j=1,bl3->ia1-1
3026            sp1t1 = sp1t1 + bl1->p1[j];
3027            sp2t1 = sp2t1 + bl1->p2[j];
3028            sp3t1 = sp3t1 + p3_c[j];
3029          }
3030          bl1->p1[bl3->ia1] = -sp1t1;
3031          bl1->p2[bl3->ia1] = -sp2t1;
3032          p3_c[bl3->ia1] = -sp3t1;
3033          eps_c[bl3->ia1] = w(bl1->p1[bl3->ia1],bl1->p2[bl3->ia1],p3_c[bl3->ia1],fmp); 
3034
3035          goto pnu1870;  // ..and boost all of them.
3036        }
3037      }
3038
3039      for(G4int i = 1; i <= bl3->ia1; i++) { //do i=1,bl3->ia1
3040      //      for(G4int i = 1; i < bl3->ia1; i++) { //do i=1,bl3->ia1
3041        arg = std::pow((cobe*(bl1->eps[i])),2) - pm2;
3042        comom = std::sqrt(arg/(std::pow(bl1->eps[i],2) - pm2));
3043        bl1->p1[i] = comom*(bl1->p1[i]);
3044        bl1->p2[i] = comom*(bl1->p2[i]);
3045        bl1->p3[i] = comom*(bl1->p3[i]);
3046        bl1->eps[i] = bl1->eps[i]*cobe;
3047        if (std::fabs(am(bl1->p1[i],bl1->p2[i],bl1->p3[i],bl1->eps[i])-fmp) > 0.01) {
3048          if(verboseLevel > 2) {
3049            G4cout <<"wrong correction " << i << G4endl;                 
3050          }
3051        }
3052      }
3053      bl1->eps[ilm] = bl1->eps[ilm] + v0; 
3054    }
3055  }
3056
3057 pnu1871:
3058  // evaluation of the times t(a,b)
3059  bl2->k = 0;
3060  kcol = 0;
3061  if (kindstruct->kindf7 <= 2) {
3062    // modif s.vuillier tient compte propagation projectile,1e collision
3063    // imposee pour lui (c'est une maniere de faire!!)
3064    G4int ioldk = 0;
3065    for(G4int i = 1; i <= ia; i++) { //do 40 i=1,ia
3066      ioldk = bl2->k;
3067      //   bl2->k = bl2->k + 1;
3068      //                tref=ref(x1(i),x2(i),x3(i),p1(i),p2(i),p3(i),eps(i),r22)          p-n04740
3069      tref = ref(bl3->x1[i], bl3->x2[i], bl3->x3[i], bl1->p1[i], bl1->p2[i], bl1->p3[i], bl1->eps[i], r22); 
3070      if (tref > bl4->tmax5) {
3071        goto pnu45;
3072      }
3073
3074      bl2->k = bl2->k + 1;
3075      bl2->crois[bl2->k]=tref;
3076      bl2->ind[bl2->k]=i;
3077      bl2->jnd[bl2->k]=-1;
3078    pnu45:
3079      i1=i-1;
3080      if (i == 1) {
3081        //goto pnu40;
3082        continue;
3083      }
3084      //   1326 c ici on ne calcule que les G4interactions nn impliquant le projectile !!! (2/02)
3085      if (i1 > bl3->ia1) {
3086        i1=bl3->ia1;
3087      }
3088      for(G4int j = 1; j <= i1; j++) { //do 41 j=1,i1
3089        // no collisions before the first collision of the incident particle
3090        time (i, j);
3091        if (bl1->ta < 0.0) {
3092          continue;
3093        }
3094        if(bl1->ta > bl4->tmax5) {
3095          continue;
3096        }
3097        eij=am(bl1->p1[i]+bl1->p1[j],bl1->p2[i]+bl1->p2[j],bl1->p3[i]+bl1->p3[j],bl1->eps[i]+bl1->eps[j]);
3098        if (eij < 1925.0) {
3099          continue;
3100        }
3101        isos=bl1->ind2[i]+bl1->ind2[j];
3102
3103        if (31.0*(bl3->rab2) > totalCrossSection(eij,0,isos)) {
3104          continue;
3105        }
3106
3107        bl2->k = bl2->k + 1;
3108        if (j == 1) {
3109          kcol = kcol + 1;
3110        }
3111        bl2->crois[bl2->k]=bl1->ta;
3112        bl2->ind[bl2->k]=i;
3113        bl2->jnd[bl2->k]=j;
3114      }
3115      if(verboseLevel > 3) {
3116        if(bl2->k == (ioldk + 2)) {
3117          if(verboseLevel > 2) {
3118            G4cout <<"bl2->k incremented twice!" << G4endl;
3119          }
3120        }
3121      }
3122    }
3123  }
3124  else {
3125    // deutons
3126    if (kindstruct->kindf7 < 6) { //then
3127      // here for incoming pions:
3128      for(G4int i = bl3->ia1+1; i <= ia; i++) { //do i=ia1+1,ia
3129        tref = ref(bl3->x1[i], bl3->x2[i], bl3->x3[i], bl1->p1[i], bl1->p2[i], bl1->p3[i], bl1->eps[i], r22); 
3130        if (tref < bl4->tmax5) {
3131          bl2->k = bl2->k + 1;
3132          bl2->crois[bl2->k] = tref;
3133          bl2->ind[bl2->k] = i;
3134          bl2->jnd[bl2->k] = -1;
3135        }
3136      }
3137      new2(y1[1], y2[1], y3[1], q1[1], q2[1], q3[1], q4[1], 1, 0);
3138
3139      //   modif a.b. 21/06/2002: should check at least one valid collision
3140      //   1361 c    with incoming pion.
3141      //   1362 c      kcol=1
3142      if(bl2->k != 0) {
3143        kcol = 1;
3144      }
3145    }
3146    else {
3147      for(G4int i = 1; i <= bl3->ia1; i++) { //do 38 i=1,ia1
3148        bl5->nesc[i] = 1;
3149        if (i != ilm) { 
3150          goto pnu36;
3151        }
3152        tref = ref(bl3->x1[i], bl3->x2[i], bl3->x3[i], bl1->p1[i], bl1->p2[i], bl1->p3[i], bl1->eps[i], r22);
3153        if(verboseLevel > 3) {
3154          if(tref < 0.0) {
3155            if(verboseLevel > 2) {
3156              G4cout <<"G4Incl: Reflection time < 0! (line 2579)" << G4endl;
3157            }
3158          }
3159        }
3160        bl5->nesc[i] = 0;
3161        npproj[i] = 0;
3162        goto pnu37;
3163      pnu36:
3164        t1 = bl3->x1[i]*(bl1->p1[i])+bl3->x2[i]*(bl1->p2[i])+bl3->x3[i]*(bl1->p3[i]);                     
3165        t2 = bl1->p1[i]*(bl1->p1[i])+bl1->p2[i]*(bl1->p2[i])+bl1->p3[i]*(bl1->p3[i]);               
3166        t3 = t1/t2;
3167        t4 = bl3->x1[i]*(bl3->x1[i])+bl3->x2[i]*(bl3->x2[i])+bl3->x3[i]*(bl3->x3[i]); 
3168        //   1379       c incoming nucleons enter potential at maximum radius (modif. 13/06/01)
3169        t5 = t3*t3 + ((ws->rmaxws)*(ws->rmaxws) - t4)/t2;
3170        if(verboseLevel > 3) {
3171          G4cout <<"x1 = " << bl3->x1[i] <<" x2 = " << bl3->x2[i] <<" x3 = " << bl3->x3[i] << G4endl; 
3172          G4cout <<"t1 = " << t1 << G4endl;
3173          G4cout <<"t2 = " << t2 << G4endl;
3174          G4cout <<"t3 = " << t3 << G4endl;
3175          G4cout <<"t4 = " << t4 << G4endl;
3176          G4cout <<"rmaxws = " << ws->rmaxws << G4endl;
3177          G4cout <<"t5 = " << t5 << G4endl;
3178        }
3179        if (t5 < 0.) {
3180          continue;
3181        }
3182        tref = (-1.0*t3 - std::sqrt(t5))*(bl1->eps[i]); 
3183        if (tref > bl4->tmax5) {
3184          continue;
3185        }
3186        npproj[i] = 1;
3187      pnu37:
3188        bl2->k = bl2->k + 1; 
3189        bl2->crois[bl2->k] = tref; 
3190        bl2->ind[bl2->k] = i; 
3191        bl2->jnd[bl2->k] = -1;
3192      }
3193      kcol = 1;
3194     
3195      //      for(G4int i = bl3->ia1+1; i < ia; i++) { //do  39 i=ia1+1,ia
3196      for(G4int i = bl3->ia1+1; i <= ia; i++) { //do  39 i=ia1+1,ia
3197        npproj[i] = 0;
3198        tref = ref(bl3->x1[i], bl3->x2[i], bl3->x3[i], bl1->p1[i], bl1->p2[i], bl1->p3[i], bl1->eps[i], r22); // line 2609
3199        if(verboseLevel > 3) {
3200          if(tref < 0.0) {
3201            G4cout <<"G4Incl: Reflection time < 0! (line 2609)" << G4endl;
3202          }
3203        }
3204
3205        if (tref < bl4->tmax5) { //then
3206          bl2->k = bl2->k + 1;
3207          bl2->crois[bl2->k]=tref;
3208          bl2->ind[bl2->k]=i;
3209          bl2->jnd[bl2->k]=-1;
3210        } //endif
3211
3212        time (i, ilm);
3213        if (bl1->ta < 0.) {
3214          continue;
3215        }
3216        if (bl1->ta > bl4->tmax5) {
3217          continue;
3218        }
3219        eij=am(bl1->p1[i]+bl1->p1[ilm],bl1->p2[i]+bl1->p2[ilm],bl1->p3[i]+bl1->p3[ilm],bl1->eps[i]+bl1->eps[ilm]);
3220        if (eij < 1925.0) {
3221          continue;
3222        }
3223        isos=bl1->ind2[i]+bl1->ind2[ilm];                                             
3224        if (31.*(bl3->rab2) > totalCrossSection(eij,0,isos)) {
3225          continue;
3226        }                                                               
3227        bl2->k = bl2->k + 1;                                                             
3228        kcol=kcol+1; 
3229        bl2->crois[bl2->k]=bl1->ta;                                                     
3230        bl2->ind[bl2->k]=i; 
3231        bl2->jnd[bl2->k]=ilm;
3232      }
3233    }
3234  }
3235
3236  //  dumpBl3(dumpOut);
3237
3238  if(verboseLevel > 3) {
3239    G4cout <<"Variables after time evaluation:" << G4endl;
3240
3241    G4cout <<"bl3->ia1 + bl3->ia2 = ia " << G4endl;
3242    G4cout << bl3->ia1 << "         " << bl3->ia2 << "          " << ia << G4endl; 
3243    G4cout <<"B11" << G4endl;
3244
3245    for(G4int idebugtest = 0; idebugtest <= bl2->k; idebugtest++) {
3246      G4cout <<"index = " << idebugtest << " ind1 = " << bl1->ind1[idebugtest] << " ind2 = " << bl1->ind2[idebugtest] << " p1 = " << bl1->p1[idebugtest] << " p2 = " << bl1->p2[idebugtest] << " p3 = " << bl1->p3[idebugtest] << " bl1->eps = " << bl1->eps[idebugtest] << G4endl;
3247    }
3248   
3249    G4cout <<"Bl2" << G4endl;
3250    for(G4int idebugtest = 0; idebugtest <= bl2->k; idebugtest++) {
3251      G4cout <<"index = " << idebugtest << " ind = " << bl2->ind[idebugtest] << " jnd = " << bl2->jnd[idebugtest] << " crois = " << bl2->crois[idebugtest] << G4endl;
3252    }
3253
3254    G4cout <<"jparticip[i]" << G4endl;
3255    for(G4int idebugtest = 0; idebugtest < 300; idebugtest++) {
3256      G4cout <<" " << jparticip[idebugtest];
3257    }
3258    G4cout << G4endl;
3259  }
3260 
3261
3262  // deutons
3263  if (kcol != 0) {
3264    if(verboseLevel > 3) {
3265      G4cout <<"After time evaluation: kcol != 0!" << G4endl;
3266    }
3267    goto pnu48;
3268  }
3269  nopart = -1;
3270  // Pour eviter renvoi des resultats du run precedent cv 7/7/98
3271  iarem = bl3->ia2;
3272  izrem = iz2;
3273  esrem = 0.0;
3274  erecrem = 0.0;
3275
3276  if(verboseLevel > 3) {
3277    G4cout <<"kcol == 0. No collisions..." << G4endl;
3278    G4cout <<"End of algorithm because kcol == 0." << G4endl;
3279    G4cout <<"kcol = " << kcol << G4endl;
3280    G4cout <<"Return after pnu39." << G4endl;
3281  }
3282  // fin ajout cv
3283  goto pnureturn;
3284
3285  // Initialization  at the beginning of the run
3286 pnu48:
3287  if(verboseLevel > 3) {
3288    G4cout <<"Beginning a run..." << G4endl;
3289  }
3290  timi = 0.0;
3291  tim = 0.0;
3292  ncol = 0;
3293
3294  // compteur des collisions a deux corps (call collis acceptes par pauli)
3295  ncol_2c = 0;
3296
3297  //C  npion=0;
3298  mrnn = 0;
3299  mrnd = 0;
3300  mrdd = 0;
3301  mrdn = 0;
3302  mrdp = 0;
3303  mrpd = 0;
3304  mcdd = 0;
3305  mpaul2 = 0;
3306  mpaul1 = 0;
3307
3308  // approx. (not considering escaping protons of incident clusters) 11/03 a.b.
3309  itch = iz1 + iz2 - 1;
3310  for(G4int i = 1; i <= ia; i++)  { //do 47 i=1,ia
3311    bl5->tlg[i] = 0.0;
3312    nc[i] = 0;
3313  }
3314  itt = 1;
3315
3316  // tableau des energies a l'initialisation
3317  if(varavat->kveux == 1) {
3318    for(G4int i = bl3->ia1+1; i <= ia; i++) {
3319      varavat->epsd[i] = bl1->eps[i];
3320    }
3321    iflag20 = 0;
3322    iflag40 = 0;
3323    iflag60 = 0;
3324  }
3325
3326  // search for the smallest positive t(a,b)
3327  // pour tests, =0 G4interdit les  reflexions avant un avatar du projectile,
3328  //             =1 comme avant (reflexions autorisees). (a.b. 3/2002)
3329  irst_avatar = 1;
3330
3331  if(verboseLevel > 3) {
3332    G4cout <<"Now arriving to label pnu449." << G4endl;
3333  }
3334 pnu449:
3335  if(verboseLevel > 3) {
3336    G4cout <<"Now at 449" << G4endl;
3337    G4cout <<"G4Incl: Now at label pnu449." << G4endl;
3338  }
3339  next = 1;
3340  indic[next] = 1;
3341
3342 pnu44:
3343  if(verboseLevel > 3) {
3344    G4cout <<"Now at 44" << G4endl;
3345    G4cout <<"Starting a new loop at pnu44..." << G4endl;
3346  }
3347  if(next == 0) {
3348    if(verboseLevel > 3) {
3349      G4cout <<"next == 0. Returning to label pnu449." << G4endl;
3350      G4cout <<"next == 0" << G4endl;
3351    }
3352    goto pnu449;
3353  }
3354 
3355  idep = indic[next] + 1;
3356  tau = bl2->crois[idep-1];
3357
3358  if(idep > bl2->k) {
3359    if(verboseLevel > 3) {
3360      G4cout <<"G4Incl: idep > bl2->k. Going to pnu448." << G4endl;
3361    }
3362    goto pnu448;
3363  }
3364  for(G4int i = idep; i <= bl2->k; i++) { //do 42 i=idep,k
3365    if (bl2->crois[i] > tau) {
3366      continue;
3367    }
3368    tau = bl2->crois[i]; 
3369    next = next + 1;
3370    indic[next] = i;
3371  }
3372
3373  if(verboseLevel > 3) {
3374    G4cout <<"next = " << next << G4endl;
3375  }
3376 pnu448:
3377  imin = indic[next];
3378  bl9->l1 = bl2->ind[imin]; //NOTE: l1 changed to bl9->l1.
3379  bl9->l2 = bl2->jnd[imin]; //NOTE: l2 changed to bl9->l2.
3380
3381  // test le 20/3/2003: tue sinon le dernier avatar?
3382  if (bl2->k == 0) {
3383    if(verboseLevel > 2) {
3384      G4cout <<"k == 0. Going to the end of the avatar." << G4endl;
3385    }
3386    goto pnu230;
3387  }
3388  bl2->k = bl2->k - 1; // bugfix k belongs to struct bl2!
3389  next = next - 1;
3390
3391  // correction s.vuillier 25/1/96 decalage temps correct
3392  if (imin > bl2->k) {
3393    goto pnu46;
3394  }
3395
3396  for(G4int i = imin; i <= bl2->k; i++) { //do 43 i=imin,k
3397    bl2->crois[i] = bl2->crois[i+1];
3398    bl2->ind[i] = bl2->ind[i+1];
3399    bl2->jnd[i] = bl2->jnd[i+1];
3400  }
3401 pnu46:
3402  if(verboseLevel > 3) {
3403    G4cout <<"G4Incl: Now at pnu46." << G4endl;
3404  }
3405  tim = timi + tau;
3406
3407  // tableau des energies a t=20,40,60 fm/c
3408  if(varavat->kveux == 1) {
3409    if(iflag20 == 0 && tim >= 20.0) {
3410      iflag20 = 1;
3411      for(G4int i = 1; i <= ia; i++) {
3412        if(bl5->nesc[i] == 0) {
3413          if(jparticip[i] == 1) {
3414            varavat->eps2[i] = bl1->eps[i];
3415          }
3416          else {
3417            varavat->eps2[i] = 0.0;
3418          }
3419        }
3420        else {
3421          varavat->eps2[i] = 0.;
3422        }
3423      }
3424    }
3425   
3426    if(iflag40 == 0 && tim >= 40.0) {
3427      iflag40 = 1;
3428      for(G4int i = 1; i <= ia; i++) {
3429        if(bl5->nesc[i] == 0) {
3430          if(jparticip[i] == 1) {
3431            varavat->eps4[i] = bl1->eps[i];
3432          }
3433          else {
3434            varavat->eps4[i] = 0.0;
3435          }
3436        }
3437        else {
3438          varavat->eps4[i] = 0.0;
3439        }
3440      }
3441    }
3442   
3443    if(iflag60 == 0 && tim >= 60.) {
3444      iflag60=1;
3445      for(G4int i = 1; i <= ia; i++) {
3446        if(bl5->nesc[i] == 0) {
3447          if(jparticip[i] == 1) {
3448            varavat->eps6[i] = bl1->eps[i];
3449          }
3450          else {
3451            varavat->eps6[i] = 0.0;
3452          }
3453        }
3454        else {
3455          varavat->eps6[i] = 0.0;
3456        }
3457      }
3458    }
3459  }
3460
3461  // modif: pas de reflexions avant au moins un avatar du (des) nucleon incident
3462  // celui-ci ne peut etre qu'une collision nn (ou pin)
3463
3464  if((irst_avatar == 0) && (bl9->l2 == -1)) {
3465    if(verboseLevel > 3) {
3466      G4cout <<"Interaction type: reflection (l2 = " << bl9->l2 << "). No first interaction with a participant yet." << G4endl;
3467    }
3468    goto pnu44;
3469  }
3470
3471  irst_avatar = irst_avatar+1;
3472
3473  if (tim < temfin) {
3474    if(verboseLevel > 3) {
3475      G4cout <<"G4Incl: tim < temfin. Going to pnu49 (line 2886)" << G4endl;
3476    }
3477    goto pnu49; // line 2886
3478  }
3479
3480  goto pnu255;
3481 pnu49:
3482  if(verboseLevel > 3) {
3483    G4cout <<"G4Incl: Now at pnu49. " << G4endl;
3484  }
3485 
3486  if (bl2->k == 0) {
3487    if(verboseLevel > 3) {
3488      G4cout <<"G4Incl: bl2->k == 0. Going to pnu255." << G4endl;
3489    }
3490    goto pnu255;
3491  }
3492  // l1 va a la surface du noyau:
3493  if (bl9->l2 == -1) {
3494    if(verboseLevel > 3) {
3495      G4cout <<"G4Incl: l2 == -1. Going to pnu220." << G4endl;
3496    }
3497    goto pnu220;
3498  }
3499
3500  if((k4-1) <= 0) {
3501    if(verboseLevel > 3) {
3502      G4cout <<"G4Incl: (k4 - 1) <= 0. Going to pnu803." << G4endl;
3503    }
3504    goto pnu803;
3505  }
3506  if((k4-1) > 0) {
3507    if(verboseLevel > 3) {
3508      G4cout <<"G4Incl: (k4 - 1) > 0. Going to pnu830." << G4endl;
3509    }
3510    goto pnu830;
3511  }
3512
3513  // l1 est un delta:
3514 pnu830:
3515  if(verboseLevel > 3) {
3516    G4cout <<"G4Incl: Now at pnu830." << G4endl;
3517  }
3518 
3519  if(bl9->l2 == 0) {
3520    goto pnu220;
3521  }
3522  // interaction pi(l1-ia)-nucleon(l2)
3523  if(bl9->l1 > ia) { // line 2916
3524    if(verboseLevel > 3) {
3525      G4cout <<"G4Incl: l1 > ia (line 2916)" << G4endl;
3526    }
3527    goto pnu801;
3528  }
3529 pnu803:
3530  // pas de collision entre 2 non participants:
3531  if(jparticip[bl9->l1] == 0 && jparticip[bl9->l2] == 0) {
3532    if(verboseLevel > 3) {
3533      G4cout <<"G4Incl: both particles are spectators. No collision. " << G4endl;
3534    }
3535    goto pnu44;
3536  }
3537
3538  // parameters for the next colliding pair
3539  t[9] = bl1->eps[bl9->l1] + bl1->eps[bl9->l2]; //t(10)->t[9]
3540  t0 = 1.0/t[9]; // t(10)->t[9]
3541  b1 = (bl1->p1[bl9->l1] + bl1->p1[bl9->l2])*t0;
3542  b2 = (bl1->p2[bl9->l1] + bl1->p2[bl9->l2])*t0;
3543  b3 = (bl1->p3[bl9->l1] + bl1->p3[bl9->l2])*t0;
3544  s = (1.0 - b1*b1 - b2*b2 - b3*b3)*t[9]*t[9]; //t(10)->t[9]
3545  sq = std::sqrt(s);
3546
3547  if(sq < 1925.5) {
3548    if(verboseLevel > 3) {
3549      G4cout <<"sq < 1925.5" << G4endl;
3550      G4cout <<"Particles: l1 = " << bl9->l1 << " l2 = " << bl9->l2 << G4endl;
3551      G4cout <<"eps[bl9->l1] = " << bl1->eps[bl9->l1] << " eps[bl9->l2] = " << bl1->eps[bl9->l2] << G4endl;
3552      G4cout <<"p1[bl9->l1] = " << bl1->p1[bl9->l1] << " p1[bl9->l2] = " << bl1->p1[bl9->l2] << G4endl;
3553      G4cout <<"p2[bl9->l1] = " << bl1->p2[bl9->l1] << " p2[bl9->l2] = " << bl1->p2[bl9->l2] << G4endl;
3554      G4cout <<"p3[bl9->l1] = " << bl1->p3[bl9->l1] << " p3[bl9->l2] = " << bl1->p3[bl9->l2] << G4endl;
3555      G4cout <<"sq = " << sq << G4endl;
3556    }
3557    goto pnu44;
3558  }
3559
3560  bl1->ta = tau/bl1->eps[bl9->l1];
3561  x1l1 = bl3->x1[bl9->l1] + bl1->p1[bl9->l1]*(bl1->ta);
3562  x2l1 = bl3->x2[bl9->l1] + bl1->p2[bl9->l1]*(bl1->ta);
3563  x3l1 = bl3->x3[bl9->l1] + bl1->p3[bl9->l1]*(bl1->ta);
3564
3565  bl1->ta = tau/bl1->eps[bl9->l2];
3566  x1l2 = bl3->x1[bl9->l2] + bl1->p1[bl9->l2]*(bl1->ta);
3567  x2l2 = bl3->x2[bl9->l2] + bl1->p2[bl9->l2]*(bl1->ta);
3568  x3l2 = bl3->x3[bl9->l2] + bl1->p3[bl9->l2]*(bl1->ta);
3569
3570  // test on the minimum distance of approach
3571  t[10] = x1l1 - x1l2; //t(11)->t[10]
3572  t[11] = x2l1 - x2l2; //t(12)->t[11]
3573  t[12] = x3l1 - x3l2; //t(13)->t[12]
3574  t[13] = t[10]*t[10] + t[11]*t[11] + t[12]*t[12]; //t(N)->t[N-1]
3575  t[14] = b1*t[10] + b2*t[11] + b3*t[12]; //t(N)->t[N-1]
3576  t[15] = b1*b1 + b2*b2 + b3*b3; //t(16)->t[15]
3577  bb2 = t[13] + t[14]*t[14]/(1.0 - t[15]); //t(N)->t[N-1]
3578
3579  if(verboseLevel > 3) {
3580    G4cout <<"Minimum dist. of approach tested..." << G4endl;
3581  }
3582 
3583  // Replaced goto structure:
3584  // if (k3 == 1) go to 260
3585  // if (k4 == 0) go to 260
3586  if(k3 != 1 && k4 != 0) {
3587    mg=bl1->ind1[bl9->l1]+bl1->ind1[bl9->l2];
3588    isos=bl1->ind2[bl9->l1]+bl1->ind2[bl9->l2];
3589  }
3590  if((k3 != 1) && (k4 != 0) && (mg == 1)) {
3591    // if (mg != 1) go to 260
3592    ldel = bl9->l2;
3593    if(mg-bl1->ind1[bl9->l1] == 0) {
3594      ldel = bl9->l1;
3595    }
3596    bl6->xx10 = std::sqrt(std::pow(bl1->eps[ldel],2) - std::pow(bl1->p1[ldel],2) - std::pow(bl1->p2[ldel],2) - std::pow(bl1->p3[ldel],2));
3597    bl6->isa = bl1->ind2[ldel];
3598    bmax2 = totalCrossSection(sq,mg,isos)/31.415926;
3599    if (k5 == 0 && mg != 0) {
3600      bmax2 = bmax2 - lowEnergy(sq,mg,isos)/31.415926;
3601    }
3602    // go to 261
3603  }
3604  else {
3605    bmax2 = totalCrossSection(sq,mg,isos)/31.41592;
3606  }
3607
3608  if (bb2 < bmax2) {
3609    goto pnu220;
3610  }
3611  if (bl2->k == 0) {
3612    goto pnu230;
3613  }
3614
3615  if(verboseLevel > 3) {
3616    G4cout <<"bb2 >= bmax2 or bl2->k == 0" << G4endl;
3617  }
3618  goto pnu44;
3619  // loop while((bb2 >= bmax2) && (k != 0)) (PK)
3620  // evaluation of the positions at time = tim
3621 pnu220:
3622  timi = tim;
3623   if(verboseLevel > 3) {
3624     G4cout <<"Evaluating positions at time = tim" << G4endl;
3625     G4cout <<"tim = " << tim << G4endl;
3626   }
3627
3628//   dumpSaxw(dumpOut);
3629//   dumpBl1(dumpOut);
3630//   dumpBl2(dumpOut);
3631//   dumpBl3(dumpOut);
3632
3633  if(varavat->kveux == 1) { //then
3634    iavat = iavat + 1;
3635    varavat->timeavat[iavat] = tim;
3636    varavat->l1avat[iavat] = bl9->l1;
3637    varavat->l2avat[iavat] = bl9->l2;
3638    varavat->energyavat[iavat] = sq;
3639
3640    if(bl9->l1 <= ia) {
3641      varavat->jpartl1[iavat] = jparticip[bl9->l1];
3642    }
3643    else {
3644      varavat->jpartl1[iavat] = 0;
3645    }
3646
3647    if(bl9->l2 > 0) {
3648      varavat->jpartl2[iavat] = jparticip[bl9->l2];
3649    }
3650    else {
3651      varavat->jpartl2[iavat] = 0;
3652    }
3653  }
3654
3655  // gel des nucleons non participants sur le premier avatar (nn)=(l1,1)     
3656  if (irst_avatar == 1) {
3657    for(G4int i = 1; i <= bl9->l1; i = i + bl9->l1 - 1) { // bugfix!
3658      bl1->ta = tau/bl1->eps[i];                                               
3659      bl3->x1[i] = bl3->x1[i] + bl1->p1[i]*(bl1->ta);                                     
3660      bl3->x2[i] = bl3->x2[i] + bl1->p2[i]*(bl1->ta);                                   
3661      bl3->x3[i] = bl3->x3[i] + bl1->p3[i]*(bl1->ta);
3662      if(verboseLevel > 3) {
3663        G4cout <<"G4Incl: i = " << G4endl;
3664      }
3665    }
3666    for(G4int i = 1; i <= bl2->k; i++) {
3667      bl2->crois[i] = bl2->crois[i] + tau;
3668    }
3669  }
3670  else {
3671    for(G4int i = 1; i <= ia; i++) {
3672      bl1->ta = tau/bl1->eps[i];
3673      bl3->x1[i] = bl3->x1[i] + bl1->p1[i]*(bl1->ta);
3674      bl3->x2[i] = bl3->x2[i] + bl1->p2[i]*(bl1->ta);
3675      bl3->x3[i] = bl3->x3[i] + bl1->p3[i]*(bl1->ta);
3676    }
3677  }
3678
3679  //  if(npion != 0) {
3680  if(npion > 0) {
3681    for(G4int i = 1; i <= npion; i++) {
3682      bl1->ta = tau/q4[i];
3683      y1[i] = y1[i] + q1[i]*(bl1->ta);
3684      y2[i] = y2[i] + q2[i]*(bl1->ta);
3685      y3[i] = y3[i] + q3[i]*(bl1->ta);
3686    }
3687  }
3688
3689  if(bl9->l2 == 0) {
3690    if(verboseLevel > 3) {
3691      G4cout <<"G4Incl: l2 == 0. Going to pnu805." << G4endl;
3692    }
3693    goto pnu805;
3694  }
3695  // Candidate: if(l2!=0)...
3696
3697  // reflexions sur le potentiel, sortie eventuelle de la particule:
3698  if (bl9->l2 == -1) {
3699    if(verboseLevel > 3) {
3700      G4cout <<"G4Incl: l2 == -1. Going to pnu600." << G4endl;
3701    }
3702    goto pnu600;
3703  }
3704
3705  if(bl9->l1 > ia) {
3706    if(verboseLevel > 3) {
3707      G4cout <<"G4Incl: l1 > ia. Going to pnu831." << G4endl;
3708    }
3709    goto pnu831;
3710  }
3711
3712  // collision of particles l1 and l2
3713  if(verboseLevel > 3) {
3714    G4cout <<"Particles l1 and l2 collide!" << G4endl;
3715  }
3716 
3717  ich1 = bl1->ind1[bl9->l1];
3718  ich2 = bl1->ind1[bl9->l2];
3719  ich3 = bl1->ind2[bl9->l1];
3720  ich4 = bl1->ind2[bl9->l2];
3721  aml1 = std::sqrt(std::pow(bl1->eps[bl9->l1],2) - std::pow(bl1->p1[bl9->l1],2) - std::pow(bl1->p2[bl9->l1],2) - std::pow(bl1->p3[bl9->l1],2));
3722  aml2 = std::sqrt(std::pow(bl1->eps[bl9->l2],2) - std::pow(bl1->p1[bl9->l2],2) - std::pow(bl1->p2[bl9->l2],2) - std::pow(bl1->p3[bl9->l2],2));
3723  gl1 = bl1->eps[bl9->l1]/aml1;
3724  gl2 = bl1->eps[bl9->l2]/aml2;
3725  // l-conservation
3726  if (k6 == 1) {
3727    t[30] = (aml1*(bl3->x1[bl9->l1]) + aml2*(bl3->x1[bl9->l2]))/(aml1 + aml2); //t(31)->t[30]
3728    t[31] = (aml1*(bl3->x2[bl9->l1]) + aml2*(bl3->x2[bl9->l2]))/(aml1 + aml2); //t(32)->t[31]
3729    t[32] = (aml1*(bl3->x3[bl9->l1]) + aml2*(bl3->x3[bl9->l2]))/(aml1 + aml2); //t(33)->t[32]
3730    tt31 = bl3->x1[bl9->l1] - bl3->x1[bl9->l2];
3731    tt32 = bl3->x2[bl9->l1] - bl3->x2[bl9->l2];
3732    tt33 = bl3->x3[bl9->l1] - bl3->x3[bl9->l2];
3733    t[33] = (aml2*(bl1->p1[bl9->l1]) - aml1*(bl1->p1[bl9->l2]))/(aml1 + aml2); //t(34)->t[33]
3734    t[34] = (aml2*(bl1->p2[bl9->l1]) - aml1*(bl1->p2[bl9->l2]))/(aml1 + aml2); //t(35)->t[34]
3735    t[35] = (aml2*(bl1->p3[bl9->l1]) - aml1*(bl1->p3[bl9->l2]))/(aml1 + aml2); //t(36)->t[35]
3736    tt34 = bl1->p1[bl9->l1] + bl1->p1[bl9->l2];
3737    tt35 = bl1->p2[bl9->l1] + bl1->p2[bl9->l2];
3738    tt36 = bl1->p3[bl9->l1] + bl1->p3[bl9->l2];
3739  }
3740
3741  // l-conservation
3742  t[20] = bl1->p1[bl9->l1]; //t(21)->t[20]
3743  t[21] = bl1->p2[bl9->l1]; //t(22)->t[21]
3744  t[22] = bl1->p3[bl9->l1]; //t(23)->t[22]
3745  t[23] = bl1->eps[bl9->l1]; //t(24)->t[23]
3746  t[24] = bl1->p1[bl9->l2]; //t(25)->t[24]
3747  t[25] = bl1->p2[bl9->l2]; //t(26)->t[25]
3748  t[26] = bl1->p3[bl9->l2]; //t(27)->t[26]
3749  t[27] = bl1->eps[bl9->l2]; //t(28)->t[27]
3750
3751  // info delta ou nucleon:
3752  if(varavat->kveux == 1) {
3753    varavat->del1avat[iavat] = bl1->ind1[bl9->l1];
3754    varavat->del2avat[iavat] = bl1->ind1[bl9->l2];                                               
3755  }
3756
3757  minus_b1 = -1.0*b1;
3758  minus_b2 = -1.0*b2;
3759  minus_b3 = -1.0*b3;
3760  loren(&(bl1->p1[bl9->l1]), &(bl1->p2[bl9->l1]), &(bl1->p3[bl9->l1]), &minus_b1, &minus_b2, &minus_b3, &(bl1->eps[bl9->l1]));
3761  loren(&(bl1->p1[bl9->l2]), &(bl1->p2[bl9->l2]), &(bl1->p3[bl9->l2]), &minus_b1, &minus_b2, &minus_b3, &(bl1->eps[bl9->l2]));
3762
3763  if(verboseLevel > 3) {
3764    G4cout <<"Calling collis..." << G4endl;
3765    G4cout <<"Energy eps[bl9->l1] = " << bl1->eps[bl9->l1] << G4endl;
3766    G4cout <<"Momentum: p1 = " << bl1->p1[bl9->l1] << " p2 = " << bl1->p2[bl9->l1] << " p3 = " << bl1->p3[bl9->l1] << G4endl;
3767    G4cout <<"Energy eps[bl9->l2] = " << bl1->eps[bl9->l2] << G4endl;
3768    G4cout <<"Momentum: p1 = " << bl1->p1[bl9->l2] << " p2 = " << bl1->p2[bl9->l2] << " p3 = " << bl1->p3[bl9->l2] << G4endl;
3769  }
3770//   bl9->l1 = l1;
3771//   bl9->l2 = l2;
3772  collis(&(bl1->p1[bl9->l1]), &(bl1->p2[bl9->l1]), &(bl1->p3[bl9->l1]),
3773         &(bl1->eps[bl9->l1]), &(bl1->p1[bl9->l2]), &(bl1->p2[bl9->l2]), &(bl1->p3[bl9->l2]), &(bl1->eps[bl9->l2]),
3774         &(t[11]), &(t[12]), &(t[13]), &(t[14]), &np, &ip, &k2, &k3, &k4, &k5,
3775         &(bl1->ind1[bl9->l1]), &(bl1->ind1[bl9->l2]), &(bl1->ind2[bl9->l1]), &(bl1->ind2[bl9->l2]));
3776//   l1 = bl9->l1;
3777//   l2 = bl9->l2;
3778  if(verboseLevel > 3) {
3779    G4cout <<"End of collis call" << G4endl;
3780    G4cout <<"Energy eps[bl9->l1] = " << bl1->eps[bl9->l1] << G4endl;
3781    G4cout <<"Energy eps[bl9->l2] = " << bl1->eps[bl9->l2] << G4endl;
3782  }
3783 
3784  if(verboseLevel > 3) {
3785    G4cout <<"Variables after collis call: "<< G4endl;
3786    G4cout <<"bl1->p1[" << bl9->l1 <<"] = " << bl1->p1[bl9->l1] <<" bl1->p2[" << bl9->l1 <<"] = " << bl1->p2[bl9->l1] <<" bl1->p3[" << bl9->l1 <<"] = " << bl1->p3[bl9->l1] <<" bl1->eps[" << bl9->l1 <<"] = " << bl1->eps[bl9->l1] << G4endl;
3787    G4cout <<"bl1->p1[" << bl9->l2 <<"] = " << bl1->p1[bl9->l2] <<" bl2->p2[" << bl9->l2 <<"] = " << bl1->p2[bl9->l2] <<" bl2->p3[" << bl9->l2 <<"] = " << bl1->p3[bl9->l2] <<" bl1->eps[" << bl9->l2 <<"] = " << bl1->eps[bl9->l2] << G4endl;
3788  }
3789 
3790  loren(&(bl1->p1[bl9->l1]), &(bl1->p2[bl9->l1]), &(bl1->p3[bl9->l1]), &b1, &b2, &b3, &(bl1->eps[bl9->l1]));
3791  loren(&(bl1->p1[bl9->l2]), &(bl1->p2[bl9->l2]), &(bl1->p3[bl9->l2]), &b1, &b2, &b3, &(bl1->eps[bl9->l2]));
3792
3793  if (bl1->ind1[bl9->l1] == 1) { // bugfix 1 -> 0
3794    goto pnu243;
3795  }
3796  xbl1 = pauliBlocking(bl9->l1, rbl, pbl);
3797  standardRandom(&rndm,&(hazard->igraine[10])); 
3798  if (rndm > (1.0 - xbl1)) {
3799    goto pnu248;
3800  }
3801 pnu243:
3802  if (bl1->ind1[bl9->l2] == 1) { // bugfix 1 -> 0
3803    goto pnu241;
3804  }
3805  xbl2 = pauliBlocking(bl9->l2, rbl, pbl);
3806  standardRandom(&rndm,&(hazard->igraine[10]));
3807  if (rndm > (1.0 - xbl2)) {
3808    goto pnu248;
3809  }
3810  goto pnu241;
3811 pnu248:
3812  if(verboseLevel > 3) {
3813    G4cout <<"Pauli blocked transition!" << G4endl;
3814  }
3815 
3816  mpaul1 = mpaul1 + 1;
3817  if(varavat->kveux == 1) {
3818    varavat->bloc_paul[iavat] = 1;
3819  }
3820  // restitution de l1 et l2 si rejet de la col. par pauli:
3821  bl1->p1[bl9->l1] = t[20]; //t(21)->t[20]
3822  bl1->p2[bl9->l1] = t[21]; //t(22)->t[21]
3823  bl1->p3[bl9->l1] = t[22]; //t(23)->t[22]
3824  bl1->eps[bl9->l1] = t[23]; //t(24)->t[23]
3825  bl1->p1[bl9->l2] = t[24]; //t(25)->t[24]
3826  bl1->p2[bl9->l2] = t[25]; //t(26)->t[25]
3827  bl1->p3[bl9->l2] = t[26]; //t(27)->t[26]
3828  bl1->eps[bl9->l2] = t[27]; //t(28)->t[27]
3829  bl1->ind1[bl9->l1] = ich1;
3830  bl1->ind1[bl9->l2] = ich2;
3831  bl1->ind2[bl9->l1] = ich3;
3832  bl1->ind2[bl9->l2] = ich4;
3833
3834  if (bl2->k == 0) {
3835    goto pnu230;
3836  }
3837  for(G4int i = 1; i <= bl2->k; i++) {
3838    bl2->crois[i] = bl2->crois[i] - tau;
3839  }
3840
3841  // pour le temps de calcul (a.b. 02/2002)
3842  if(verboseLevel > 3) {
3843    G4cout <<"G4Incl: bl2->k != 0" << G4endl;
3844  }
3845  goto pnu44;
3846
3847 pnu241:
3848
3849  // la premiere collision a deux corps ne peut pas baisser l'energie
3850  // du nucleon de recul (bloque par pauli dans un noyau cible froid).
3851  // (ici, toujours l2 < l1)
3852  ncol_2c = ncol_2c + 1;
3853  if(ncol_2c == 1) {
3854    for (G4int icomp = 1; icomp <= bl3->ia1; icomp++) {
3855      // test on the first collision modified 4/07/2001 for direct and exchange.
3856      if(icomp == bl9->l1 || icomp == bl9->l2) {
3857        xavant = min(t[23],t[27]); //t(24)->t[23], t(28)->t[27]
3858        xapres = min(bl1->eps[bl9->l1],bl1->eps[bl9->l2]);
3859        if(xapres <= xavant) {
3860          if(varavat->kveux == 1) {
3861            varavat->bloc_cdpp[iavat] = 1;
3862          }
3863          goto pnu248;
3864        }
3865      }
3866    }
3867
3868    // pour le ntuple des avatars:
3869    if(varavat->kveux == 1) { //then
3870      varavat->r1_first_avat[0] = bl3->x1[1]; //(N)->[N-1]
3871      varavat->r1_first_avat[1] = bl3->x2[1]; //(N)->[N-1]
3872      varavat->r1_first_avat[2] = bl3->x3[1]; //(N)->[N-1]
3873    } //endif
3874  }
3875  else {
3876    // les collisions suivantes ne penvent conduire a un noyau de a nucleons
3877    // sous l'energie de fermi et dans une config. d'energie inferieure a
3878    // efer-(ia2-nbalttf)*tf).
3879    egs = 0.0;
3880    nbalttf = 0;
3881    //    for(G4int i = 1; i <= ia-1; i++) {
3882    for(G4int i = 1; i <= ia; i++) {
3883      if(bl5->nesc[i] == 0) {
3884        if(std::sqrt(std::pow(bl1->p1[i],2)+std::pow(bl1->p2[i],2)+std::pow(bl1->p3[i],2)) < bl10->pf) {
3885          nbalttf = nbalttf + 1;
3886          egs = egs + bl1->eps[i] - fmp;
3887        }
3888      }
3889    }
3890
3891    if(egs < (efer- double(bl3->ia2-nbalttf)*tf)) {
3892      if(varavat->kveux == 1) {
3893        varavat->bloc_cdpp[iavat] = 1;
3894      }
3895      goto pnu248;
3896    }
3897  }
3898
3899  if(varavat->kveux == 1) {
3900    varavat->bloc_cdpp[iavat] = 0;
3901    varavat->bloc_paul[iavat] = 0;
3902  }
3903
3904  jparticip[bl9->l1] = 1;
3905  jparticip[bl9->l2] = 1;
3906  if(verboseLevel > 3) {
3907    G4cout <<"Particle " << bl9->l1 << " is now participant." << G4endl;
3908    G4cout <<"Particle " << bl9->l2 << " is now participant." << G4endl;
3909  }
3910 
3911  if (ws->nosurf <= 0) {
3912    // surface
3913    pppp = std::sqrt(std::pow(bl1->p1[bl9->l1],2) + std::pow(bl1->p2[bl9->l1],2) + std::pow(bl1->p3[bl9->l1],2));
3914    rrrr = std::sqrt(std::pow(bl3->x1[bl9->l1],2) + std::pow(bl3->x2[bl9->l1],2) + std::pow(bl3->x3[bl9->l1],2));
3915    if (pppp <= bl10->pf) {
3916      xv = pppp/bl10->pf;
3917      rcorr = interpolateFunction(xv);
3918      if (rrrr > rcorr) {
3919        bl3->x1[bl9->l1] = bl3->x1[bl9->l1]*rcorr/rrrr;
3920        bl3->x2[bl9->l1] = bl3->x2[bl9->l1]*rcorr/rrrr;
3921        bl3->x3[bl9->l1] = bl3->x3[bl9->l1]*rcorr/rrrr;
3922      }
3923    }
3924    pppp = std::sqrt(std::pow(bl1->p1[bl9->l2],2) + std::pow(bl1->p2[bl9->l2],2) + std::pow(bl1->p3[bl9->l2],2));
3925    rrrr = std::sqrt(std::pow(bl3->x1[bl9->l2],2) + std::pow(bl3->x2[bl9->l2],2) + std::pow(bl3->x3[bl9->l2],2));
3926    if (pppp <= bl10->pf) {
3927      xv = pppp/bl10->pf;
3928      rcorr = interpolateFunction(xv);
3929      if (rrrr > rcorr) {
3930        bl3->x1[bl9->l2] = bl3->x1[bl9->l2]*rcorr/rrrr;
3931        bl3->x2[bl9->l2] = bl3->x2[bl9->l2]*rcorr/rrrr;
3932        bl3->x3[bl9->l2] = bl3->x3[bl9->l2]*rcorr/rrrr;
3933      }
3934    }
3935  }
3936 
3937  if (np == 0) {
3938    goto pnu240;
3939  }
3940
3941  npion = npion + 1;
3942  loren(&(t[11]), &(t[12]), &(t[13]), &b1, &b2, &b3, &(t[14])); //t(N)->t[N-1]
3943  q1[npion] = t[11]; //t(12)->t[11]
3944  q2[npion] = t[12]; //t(13)->t[12]
3945  q3[npion] = t[13]; //t(14)->t[13]
3946  q4[npion] = t[14]; //t(15)->t[14]
3947 pnu240:
3948  ncol = ncol + 1;
3949  if (bl9->l2 != 1) {
3950    goto pnu870;
3951  }
3952
3953  // critere pour la leading particle: avant impulsion longitudinale max l=1
3954  // change en fevrier 2002: leading part. = energie totale max (l=1)
3955  if (bl1->p3[bl9->l2] > bl1->p3[bl9->l1]) { 
3956    goto pnu870;
3957  }
3958
3959  // attention, il faut mieux faire et selectionner la plus grande energie
3960  // des particules participantes (jparticip()=1) et dans le noyau (nesc()=0)!
3961
3962  xr1 = bl1->p1[bl9->l1];
3963  xr2 = bl1->p2[bl9->l1];
3964  xr3 = bl1->p3[bl9->l1];
3965  xr4 = bl1->eps[bl9->l1];
3966  xr5 = bl3->x1[bl9->l1];
3967  xr6 = bl3->x2[bl9->l1];
3968  xr7 = bl3->x3[bl9->l1];
3969  xr8 = gl1;
3970  ixr1 = bl1->ind1[bl9->l1];
3971  ixr2 = bl1->ind2[bl9->l1];
3972  ixr3 = ich1;
3973  bl1->p1[bl9->l1] = bl1->p1[bl9->l2];
3974  bl1->p2[bl9->l1] = bl1->p2[bl9->l2];
3975  bl1->p3[bl9->l1] = bl1->p3[bl9->l2];
3976  bl1->eps[bl9->l1] = bl1->eps[bl9->l2];
3977
3978  bl3->x1[bl9->l1] = bl3->x1[bl9->l2];
3979  bl3->x2[bl9->l1] = bl3->x2[bl9->l2];
3980  bl3->x3[bl9->l1] = bl3->x3[bl9->l2];
3981  gl1 = gl2;
3982  bl1->ind1[bl9->l1] = bl1->ind1[bl9->l2];
3983  bl1->ind2[bl9->l1] = bl1->ind2[bl9->l2];
3984  ich1 = ich2;
3985  bl1->p1[bl9->l2] = xr1;
3986  bl1->p2[bl9->l2] = xr2;
3987  bl1->p3[bl9->l2] = xr3;
3988  bl1->eps[bl9->l2] = xr4;
3989 
3990  bl3->x1[bl9->l2] = xr5;
3991  bl3->x2[bl9->l2] = xr6;
3992  bl3->x3[bl9->l2] = xr7;
3993  gl2 = xr8;
3994  bl1->ind1[bl9->l2] = ixr1;
3995  bl1->ind2[bl9->l2] = ixr2;
3996  ich2 = ixr3;
3997
3998  if(ich1 + ich2 - bl1->ind1[bl9->l1] - bl1->ind1[bl9->l2] != 0 || (ich1 + ich2) != 1) {
3999    goto pnu870;
4000  }
4001  if (bl2->k == 0) {
4002    goto pnu870;
4003  }
4004
4005  for(G4int i = 1; i <= bl2->k; i++) {
4006    if((bl2->ind[i] != 1) || (bl2->jnd[i] != 0)) {
4007      if((bl2->ind[i] != bl9->l1) || (bl2->jnd[i] != 0)) {
4008        continue;
4009      }
4010      bl2->ind[i] = 1;
4011      break;
4012    }
4013
4014    bl2->ind[i] = bl9->l1;
4015    break;
4016  }
4017
4018  pnu870:
4019  bl5->tlg[bl9->l1] = th*(bl1->eps[bl9->l1])/std::sqrt(std::pow(bl1->eps[bl9->l1],2)-std::pow(bl1->p1[bl9->l1],2)-std::pow(bl1->p2[bl9->l1],2)-std::pow(bl1->p3[bl9->l1],2));
4020  bl5->tlg[bl9->l2] = th*(bl1->eps[bl9->l2])/std::sqrt(std::pow(bl1->eps[bl9->l2],2)-std::pow(bl1->p1[bl9->l2],2)-std::pow(bl1->p2[bl9->l2],2)-std::pow(bl1->p3[bl9->l2],2));
4021  nc[bl9->l1] = nc[bl9->l1] + 1;
4022  nc[bl9->l2] = nc[bl9->l2] + 1;
4023  led = 0;
4024
4025  if((ich1+ich2-bl1->ind1[bl9->l1]-bl1->ind1[bl9->l2]) < 0) {
4026    mrnd = mrnd + 1;
4027  }
4028  if((ich1+ich2-bl1->ind1[bl9->l1]-bl1->ind1[bl9->l2]) == 0) {
4029    if((ich1+ich2-1) < 0) {
4030      mrnn = mrnn + 1;
4031    }
4032    if((ich1+ich2-1) == 0) {
4033      mrdd = mrdd + 1;
4034      led = 1;
4035    }
4036    if((ich1+ich2-1) > 0) {
4037      mcdd = mcdd + 1;
4038      led = 1;
4039    }
4040  }
4041  if((ich1+ich2-bl1->ind1[bl9->l1]-bl1->ind1[bl9->l2]) > 0) {
4042    mrdn = mrdn + 1;
4043  }
4044
4045
4046  // reevaluation of the times t(a,b) for (a or b)=(l1 or l2)
4047
4048  // l-conservation
4049  if (k6 == 1) {
4050    aml1 = am(bl1->p1[bl9->l1],bl1->p2[bl9->l1],bl1->p3[bl9->l1],bl1->eps[bl9->l1]);
4051    aml2 = am(bl1->p1[bl9->l2],bl1->p2[bl9->l2],bl1->p3[bl9->l2],bl1->eps[bl9->l2]);
4052   
4053    t[36] = (aml2*(bl1->p1[bl9->l1]) - aml1*(bl1->p1[bl9->l2]))/(aml1+aml2); //t(37)->t[36]
4054    t[37] = (aml2*(bl1->p2[bl9->l1]) - aml1*(bl1->p2[bl9->l2]))/(aml1+aml2); //t(38)->t[37]
4055    t[38] = (aml2*(bl1->p3[bl9->l1]) - aml1*(bl1->p3[bl9->l2]))/(aml1+aml2); //t(39)->t[38]
4056    t[39] = std::sqrt(t[33]*t[33] + t[34]*t[34] + t[35]*t[35]); //t(N)->t[N-1]
4057    t[40] = std::sqrt(t[36]*t[36] + t[37]*t[37] + t[38]*t[38]); //t(N)->t[N-1]
4058    rhopi = tt31*t[33] + tt32*t[34] + tt33*t[35]; //t(N)->t[N-1]
4059    t[42] = tt31 - rhopi*t[33]/std::pow(t[39],2); //t(N)->t[N-1]
4060    t[43] = tt32 - rhopi*t[34]/std::pow(t[39],2); //t(N)->t[N-1]
4061    t[44] = tt33 - rhopi*t[35]/std::pow(t[39],2); //t(N)->t[N-1]
4062    t[45] = std::sqrt(t[42]*t[42] + t[43]*t[43] + t[44]*t[44]); //t(N)->t[N-1]
4063    t[42] = t[42]/t[45]; //t(N)->t[N-1]
4064    t[43] = t[43]/t[45]; //t(N)->t[N-1]
4065    t[44] = t[44]/t[45];
4066    cif = (t[33]*t[36] + t[34]*t[37] + t[35]*t[38])/t[39]/t[40]; //t(N)->t[N-1]
4067   
4068    // trouble with forward scattering 22/3/95
4069    if(std::fabs(cif) > 1.) {
4070      cif = sign(1.0,cif);
4071    }
4072    sif = std::sqrt(1.0 - cif*cif);
4073    t[36] = (t[33]*cif/t[39] + t[42]*sif)*t[40]; //t(N)->t[N-1]
4074    t[37] = (t[34]*cif/t[39] + t[43]*sif)*t[40]; //t(N)->t[N-1]
4075    t[38] = (t[35]*cif/t[39] + t[44]*sif)*t[40]; //t(N)->t[N-1]
4076    tri = std::sqrt(tt31*tt31 + tt32*tt32 + tt33*tt33);
4077    cchi = rhopi/tri/t[39]; //t(40)->t[39]
4078    schi = std::sqrt(1.0 - cchi*cchi);
4079    c1 = cif*cchi - sif*schi;
4080    c2 = sif*cchi + cif*schi;
4081    tt31 = (c1*t[33]/t[39] + c2*t[42])*tri*t[39]/t[40]; //t(N)->t[N-1]
4082    tt32 = (c1*t[34]/t[39] + c2*t[43])*tri*t[39]/t[40]; //t(N)->t[N-1]
4083    tt33 = (c1*t[35]/t[39] + c2*t[44])*tri*t[39]/t[40]; //t(N)->t[N-1]
4084    bl3->x1[bl9->l1] = t[30] + aml2*tt31/(aml1 + aml2); //t(31)->t[30]
4085    bl3->x2[bl9->l1] = t[31] + aml2*tt32/(aml1 + aml2); //t(32)->t[30]
4086    bl3->x3[bl9->l1] = t[32] + aml2*tt33/(aml1 + aml2); //t(33)->t[32]
4087    bl3->x1[bl9->l2] = t[30] - aml1*tt31/(aml1 + aml2); //t(31)->t[30]
4088    bl3->x2[bl9->l2] = t[31] - aml1*tt32/(aml1 + aml2); //t(32)->t[31]
4089    bl3->x3[bl9->l2] = t[32] - aml1*tt33/(aml1 + aml2); //t(33)->t[32]
4090    bl1->p1[bl9->l1] = aml1*tt34/(aml1 + aml2) + t[36]; //t(37)->t[36]
4091    bl1->p2[bl9->l1] = aml1*tt35/(aml1 + aml2) + t[37]; //t(38)->t[37]
4092    bl1->p3[bl9->l1] = aml1*tt36/(aml1 + aml2) + t[38]; //t(39)->t[38]
4093    bl1->eps[bl9->l1] = w(bl1->p1[bl9->l1],bl1->p2[bl9->l1],bl1->p3[bl9->l1],aml1);
4094    bl1->p1[bl9->l2] = aml2*tt34/(aml1 + aml2) - t[36]; //t(37)->t[36]
4095    bl1->p2[bl9->l2] = aml2*tt35/(aml1 + aml2) - t[37]; //t(38)->t[37]
4096    bl1->p3[bl9->l2] = aml2*tt36/(aml1 + aml2) - t[38]; //t(39)->t[38]
4097    bl1->eps[bl9->l2] = w(bl1->p1[bl9->l2],bl1->p2[bl9->l2],bl1->p3[bl9->l2],aml2);
4098  }
4099  // l-conservation
4100
4101  if(bl2->k != 0) {
4102    kd = 0;
4103    ccr = tau;
4104//     for(G4int i = 1; i <= bl2->k; i++) {
4105//       i20 = i - kd;
4106//       if (k4 != 2 || led != 1) {
4107//      if((bl2->ind[i] == l1) || (bl2->ind[i] == l2) || (bl2->jnd[i] == l1) || (bl2->jnd[i] == l2)) {
4108//        kd = kd + 1;
4109//        continue;
4110//      }
4111//       }
4112//       else {
4113//      if(bl2->jnd[i] == 0) {
4114//        if (bl2->ind[i] == l1 && bl1->ind1[l1] == 1) {
4115//          bl2->crois[i]=(bl2->crois[i]-ccr)*(bl1->eps[l1])/std::sqrt(std::pow(bl1->eps[l1],2)-std::pow(bl1->p1[l1],2)-std::pow(bl1->p2[l1],2)-std::pow(bl1->p3[l1],2))/gl1+ccr;
4116//        }
4117//        if (bl2->ind[i] == l2 && bl1->ind1[l2] == 1) {
4118//          bl2->crois[i]=(bl2->crois[i]-ccr)*(bl1->eps[l2])/std::sqrt(std::pow(bl1->eps[l2],2)-std::pow(bl1->p1[l2],2)-std::pow(bl1->p2[l2],2)-std::pow(bl1->p3[l2],2))/gl2+ccr;
4119//        }
4120//      }
4121//       }
4122   
4123//       bl2->crois[i20]=bl2->crois[i]-ccr;
4124//       bl2->ind[i20]=bl2->ind[i];
4125//       bl2->jnd[i20]=bl2->jnd[i];
4126//     }
4127
4128    for(G4int i = 1; i <= bl2->k; i++) { //do 50 i=1,k                                                       p-n09070
4129      i20 = i - kd;
4130      if(k4 != 2 || led != 1) { //if (k4.ne.2.or.led.ne.1) go to 512                                p-n09090
4131        goto pnu512;
4132      }
4133      if(bl2->jnd[i] == 0) {//if (jnd(i).eq.0) go to 511                                        p-n09100
4134        goto pnu511;
4135      }
4136    pnu512:
4137      if(bl2->ind[i] == bl9->l1) {//if (ind(i).eq.l1) go to 52                                        p-n09120
4138        goto pnu52; 
4139
4140      }
4141      if(bl2->ind[i] == bl9->l2) {//if (ind(i).eq.l2) go to 52                                        p-n09130
4142        goto pnu52;
4143        }
4144      if(bl2->jnd[i] == bl9->l2) {//if (jnd(i).eq.l2) go to 52                                        p-n09140
4145        goto pnu52;
4146      }
4147      if(bl2->jnd[i] == bl9->l1) {//if (jnd(i).eq.l1) go to 52                                        p-n09150
4148        goto pnu52;
4149      }
4150      goto pnu513;
4151    pnu511:
4152      //if (ind(i).eq.l1.and.ind1(l1).eq.1) crois(i)=(crois(i)-ccr)*eps(l1p-n09170
4153      //-)/std::sqrt(eps(l1)**2-p1(l1)**2-p2(l1)**2-p3(l1)**2)/gl1+ccr          p-n09180
4154      if(bl2->ind[i] == bl9->l1 && bl1->ind1[bl9->l1] == 1) {
4155        bl2->crois[i]=(bl2->crois[i]-ccr)*bl1->eps[bl9->l1]/std::sqrt(std::pow(bl1->eps[bl9->l1],2)-std::pow(bl1->p1[bl9->l1],2)-std::pow(bl1->p2[bl9->l1],2)-std::pow(bl1->p3[bl9->l1],2))/gl1+ccr;
4156      }
4157      //if (ind(i).eq.l2.and.ind1(l2).eq.1) crois(i)=(crois(i)-ccr)*eps(l2p-n09190
4158      //-)/std::sqrt(eps(l2)**2-p1(l2)**2-p2(l2)**2-p3(l2)**2)/gl2+ccr          p-n09200
4159      if(bl2->ind[i] == bl9->l2 && bl1->ind1[bl9->l2] == 1) {
4160        bl2->crois[i]=(bl2->crois[i]-ccr)*bl1->eps[bl9->l2]/std::sqrt(std::pow(bl1->eps[bl9->l2],2)-std::pow(bl1->p1[bl9->l2],2)-std::pow(bl1->p2[bl9->l2],2)-std::pow(bl1->p3[bl9->l2],2))/gl1+ccr;
4161      }
4162 pnu513:
4163      bl2->crois[i20]=bl2->crois[i]-ccr;
4164      bl2->ind[i20]=bl2->ind[i];
4165      bl2->jnd[i20]=bl2->jnd[i];
4166      continue; // goto pnu50
4167    pnu52:
4168      kd=kd+1;
4169    }
4170 
4171    bl2->k = bl2->k - kd;
4172  }
4173
4174  newt(bl9->l1,bl9->l2);
4175
4176  tref=ref(bl3->x1[bl9->l1], bl3->x2[bl9->l1], bl3->x3[bl9->l1], bl1->p1[bl9->l1], bl1->p2[bl9->l1], bl1->p3[bl9->l1], bl1->eps[bl9->l1],r22); // line 3502
4177 
4178  if(verboseLevel > 3) {
4179    if(tref < 0.0) {
4180      G4cout <<"G4Incl: Reflection time < 0! (line 3502)" << G4endl;
4181    }
4182  }
4183
4184  if(tref <= bl4->tmax5) {
4185    bl2->k = bl2->k + 1;
4186    bl2->crois[bl2->k] = tref;
4187    bl2->ind[bl2->k] = bl9->l1;
4188    bl2->jnd[bl2->k] = -1;
4189  }
4190
4191  tref=ref(bl3->x1[bl9->l2], bl3->x2[bl9->l2], bl3->x3[bl9->l2], bl1->p1[bl9->l2], bl1->p2[bl9->l2], bl1->p3[bl9->l2], bl1->eps[bl9->l2],r22); // line 3516
4192 
4193  if(verboseLevel > 3) {
4194    if(tref < 0.0) {
4195      G4cout <<"G4Incl: Reflection time < 0! (line 3516)" << G4endl;
4196    }
4197  }
4198
4199  if(tref <= bl4->tmax5) {
4200    bl2->k = bl2->k + 1;
4201    bl2->crois[bl2->k] = tref;
4202    bl2->ind[bl2->k] = bl9->l2;
4203    bl2->jnd[bl2->k] = -1;
4204  }
4205
4206  if (k4 == 2) {
4207    goto pnu848;
4208  }
4209
4210  if(bl2->k < 0) {
4211    goto pnu230;
4212  }
4213  if(bl2->k == 0) {
4214    goto pnu230;
4215  }
4216  if(bl2->k > 0) {
4217    if(verboseLevel > 3) {
4218      G4cout <<"G4Incl: bl2->k > 0 at line 3488. Going back to label pnu449." << G4endl;
4219    }
4220    goto pnu449;
4221  }
4222
4223 pnu848:
4224  if (npion == 0) {
4225    goto pnu844;
4226  }
4227  if (bl1->ind1[bl9->l1] == 1) {
4228    goto pnu843;
4229  }
4230  for(G4int k20 = 1; k20 <= npion; k20++) {
4231    if(verboseLevel > 3) {
4232      G4cout <<"G4Incl: calling G4Incl::new3" << G4endl;
4233    }
4234    new3((y1[k20]), (y2[k20]), (y3[k20]), (q1[k20]), (q2[k20]), (q3[k20]), (q4[k20]), k20, bl9->l1);
4235    if(verboseLevel > 3) {
4236      G4cout <<"G4Incl: After new3:" << G4endl;
4237      G4cout <<"y1[" << k20 << "] = " << y1[k20] <<" y2[" << k20 << "] = " << y2[k20] <<" y3[" << k20 << "] = " << y3[k20] << G4endl;
4238      G4cout <<"q1[" << k20 << "] = " << q1[k20] <<" q2[" << k20 << "] = " << q2[k20] <<" q3[" << k20 << "] = " << q3[k20] << G4endl;
4239    }
4240  }
4241
4242 pnu843:
4243  if(bl1->ind1[bl9->l2] != 1) {
4244    for(G4int k20 = 1; k20 <= npion; k20++) {
4245      //new3(y1[k20], y2[k20], y3[k20], q1[k20], q2[k20], q3[k20], q4[k20], -k20, l2);
4246      new3(y1[k20], y2[k20], y3[k20], q1[k20], q2[k20], q3[k20], q4[k20], k20, bl9->l2);
4247    }
4248  }
4249 pnu844:
4250
4251  if(bl1->ind1[bl9->l1]+bl1->ind1[bl9->l2] <= ich1+ich2) {
4252    goto pnu849;
4253  }
4254  if(bl1->ind1[bl9->l1]-ich1 != 1) {
4255    goto pnu820;
4256  }
4257  lnew = bl9->l1;
4258  goto pnu821;
4259 pnu820:
4260  if(bl1->ind1[bl9->l2]-ich2 != 1) {
4261    goto pnu849;
4262  }
4263  lnew = bl9->l2;
4264
4265 pnu821:
4266  standardRandom(&rndm,&(hazard->igraine[16]));
4267  // largeur variable du delta (phase space factor G4introduced 4/2001)
4268  amlnew = std::sqrt(std::pow(bl1->eps[lnew],2)-std::pow(bl1->p1[lnew],2)-std::pow(bl1->p2[lnew],2)-std::pow(bl1->p3[lnew],2)); 
4269 
4270  geff = bl1->eps[lnew]/amlnew;
4271  qqq = std::sqrt((std::pow(amlnew,2) - std::pow((fmp+fmpi),2))*(std::pow(amlnew,2) - std::pow((fmp-fmpi),2)))/(2.0*amlnew);
4272 
4273  psf = std::pow(qqq,3)/(std::pow(qqq,3) + 5832000.0);
4274  tdel = -hc/(g0*psf)*std::log(rndm)*geff;                                 
4275 
4276  if(tdel <= bl4->tmax5) {
4277    bl2->k = bl2->k + 1;
4278    bl2->crois[bl2->k] = tdel;
4279    bl2->ind[bl2->k] = lnew;
4280    bl2->jnd[bl2->k] = 0;
4281  }
4282
4283 pnu849:
4284  if (bl2->k == 0) { 
4285    goto pnu230;
4286  }
4287  if(verboseLevel > 3) {
4288    G4cout <<"G4Incl: bl2->k != 0. Going back to label pnu449." << G4endl;
4289  }
4290  goto pnu449;
4291
4292  // decay of the delta particle                                       p-n09780
4293 pnu805:
4294  npion = npion + 1;
4295  ichd = bl1->ind2[bl9->l1];
4296  t[30] = bl1->p1[bl9->l1];   //t(31)->t[30]
4297  t[31] = bl1->p2[bl9->l1]; //t(32)->t[31]
4298  t[32] = bl1->p3[bl9->l1]; //t(33)->t[32]
4299  t[33] = bl1->eps[bl9->l1]; //t(34)->t[33]
4300  var_ab = std::pow(bl1->eps[bl9->l1],2) - std::pow(bl1->p1[bl9->l1],2) - std::pow(bl1->p2[bl9->l1],2) - std::pow(bl1->p3[bl9->l1],2);
4301  ym[npion] = 0.0;
4302
4303  if(var_ab > 0.0) {
4304    ym[npion] = std::sqrt(var_ab);
4305  }
4306
4307  //PK: This workaround avoids a NaN problem encountered with
4308  //geant4. The problem does not seem to exist if we run in standalone
4309  //mode.
4310  //  if(((std::pow(ym[npion],2)-std::pow(fmp+fmpi,2))*(std::pow(ym[npion],2)-std::pow(fmp-fmpi,2))) < 0) {
4311  //    ym[npion] = ym[npion]+fmpi+100.0;
4312  //  }
4313  // PK
4314  if(varavat->kveux == 1) {
4315    varavat->del1avat[iavat] = bl1->ind1[bl9->l1];
4316    varavat->energyavat[iavat] = ym[npion];
4317  }
4318
4319  if(verboseLevel > 3) {
4320    G4cout <<"Calling decay2 from pnu" << G4endl;
4321    G4cout <<"npion = " << npion << G4endl;
4322    G4cout <<"q1 = " << q1[npion] << " q2 = " << q2[npion] << " q3 = " << q3[npion] << " q4 = " << q4[npion] << G4endl;
4323  }
4324  decay2(&(bl1->p1[bl9->l1]), &(bl1->p2[bl9->l1]), &(bl1->p3[bl9->l1]), &(bl1->eps[bl9->l1]), &(q1[npion]), &(q2[npion]), &(q3[npion]),
4325         &(q4[npion]), &(ym[npion]), &fmp, &fmpi, &(bl9->hel[bl9->l1]));
4326
4327  if(verboseLevel > 3) {
4328    G4cout <<"Quantities after decay2: " << G4endl;
4329    G4cout <<"l1 = " << bl9->l1 << " bl1->p1[l1] = " << bl1->p1[bl9->l1] << " bl1->p2[l1] = " << bl1->p2[bl9->l1] << " bl1->p3[l1] = " << bl1->p3[bl9->l1] << " bl1->eps[l1] = " << bl1->eps[bl9->l1] << G4endl;
4330  }
4331 
4332  // decay
4333  if (bl1->ind2[bl9->l1]*(bl1->ind2[bl9->l1]) == 9) {
4334    goto pnu806;
4335  }
4336 
4337  standardRandom(&rndm, &(hazard->ial));
4338  if (rndm < 0.333333333) {
4339    goto pnu837;
4340  }
4341 
4342  ipi[npion]=0;
4343  goto pnu809;
4344
4345 pnu837:
4346  ipi[npion]=bl1->ind2[bl9->l1]*2;
4347  bl1->ind2[bl9->l1]=-1*(bl1->ind2[bl9->l1]);
4348  goto pnu809;
4349 pnu806:
4350  bl1->ind2[bl9->l1]=bl1->ind2[bl9->l1]/3;
4351  ipi[npion]=2*(bl1->ind2[bl9->l1]);
4352 pnu809: // continue
4353  bl1->ind1[bl9->l1]=0;
4354  bl5->tlg[bl9->l1]=0.;
4355
4356  // escape ?
4357  if (bl5->nesc[bl9->l1] > 0) {
4358    goto pnu850;
4359  }
4360
4361  iteste = 0;
4362  xpb = pauliBlocking(bl9->l1, rbl, pbl);
4363  standardRandom(&rndm,&(hazard->igraine[10])); 
4364
4365  // pauli blocking?
4366  if (rndm <= xpb) {
4367    goto pnu1848;
4368  }
4369  // le decay ne peut conduire a un noyau de a nucleons
4370  // sous l'energie de fermi et dans une config. d'energie inferieure a
4371  // c  efer-(ia2-nbalttf)*tf).
4372  egs = 0.0;
4373  nbalttf = 0;
4374  iteste = 1;
4375  for(G4int i = 1; i <= ia; i++) {
4376    if(bl5->nesc[i] == 0) {
4377      if(std::sqrt(std::pow(bl1->p1[i],2)+std::pow(bl1->p2[i],2)+std::pow(bl1->p3[i],2)) < bl10->pf) {
4378        nbalttf = nbalttf + 1;
4379        egs = egs + bl1->eps[i] - fmp;
4380      }
4381    }
4382  }
4383  if(egs >= (efer - double(bl3->ia2-nbalttf)*tf)) {
4384    goto pnu850;
4385  }
4386
4387  // attention, logique negative!!! liberer le goto si on veut supprimer la
4388  // sequence precedente (cdpp sur delta-> pi n)
4389
4390  if(varavat->kveux == 1) {
4391    varavat->bloc_cdpp[iavat] = 1;
4392  }
4393
4394  // it is blocked!     
4395 pnu1848:
4396  mpaul2 = mpaul2 + 1;
4397  if(varavat->kveux == 1) {
4398    varavat->bloc_paul[iavat] = 1;
4399  }
4400
4401  // largeur variable du delta (phase space factor G4introduced 4/2001)
4402  // (180.**3 = 5832000.)
4403  qqq = std::sqrt((std::pow(ym[npion],2) - std::pow((fmp+fmpi),2))*(std::pow(ym[npion],2) - std::pow((fmp-fmpi),2)))/(2.*ym[npion]);
4404  psf = std::pow(qqq,3)/(std::pow(qqq,3)+5832000.0);
4405  tdel = hc*t[33]/(g0*psf*ym[npion]); //t(34)->t[33]                                 
4406
4407  if (iteste == 0) {
4408    tdel = tdel*xpb/(1.000001-xpb);
4409  }
4410
4411  if(tdel <= bl4->tmax5) {
4412    bl2->k = bl2->k + 1;
4413    bl2->crois[bl2->k] = tdel;
4414    bl2->ind[bl2->k] = bl9->l1;
4415    bl2->jnd[bl2->k] = 0;
4416  }
4417
4418  bl1->p1[bl9->l1] = t[30]; //t(31)->t[30]
4419  bl1->p2[bl9->l1] = t[31]; //t(32)->t[31]
4420  bl1->p3[bl9->l1] = t[32]; //t(33)->t[32]
4421  bl1->eps[bl9->l1] = t[33]; //t(34)->t[33]
4422  bl1->ind1[bl9->l1] = 1;
4423  bl1->ind2[bl9->l1] = ichd;
4424  npion = npion - 1;
4425
4426  if (bl2->k == 0) {
4427    goto pnu230;
4428  }
4429
4430  for(G4int i = 1; i <= bl2->k; i++) {
4431    bl2->crois[i] = bl2->crois[i] - tau;
4432  }
4433
4434  if(verboseLevel > 3) {
4435    G4cout <<"G4Incl: Going back to label pnu449 after a loop from 1 to bl2->k" << G4endl;
4436  }
4437  goto pnu449;
4438
4439  // valid decay of the delta
4440 pnu850:
4441  if(varavat->kveux == 1) {
4442    varavat->bloc_paul[iavat] = 0;
4443    varavat->bloc_cdpp[iavat] = 0;
4444  }
4445
4446  if (ws->nosurf <= 0) {
4447    // surface
4448    pppp = std::sqrt(std::pow(bl1->p1[bl9->l1],2) + std::pow(bl1->p2[bl9->l1],2) + std::pow(bl1->p3[bl9->l1],2));
4449    rrrr = std::sqrt(std::pow(bl3->x1[bl9->l1],2) + std::pow(bl3->x2[bl9->l1],2) + std::pow(bl3->x3[bl9->l1],2));
4450    if (pppp <= bl10->pf) {
4451      xv = pppp/bl10->pf;
4452      rcorr = interpolateFunction(xv);
4453      if (rrrr > rcorr) {
4454        bl3->x1[bl9->l1] = bl3->x1[bl9->l1]*rcorr/rrrr;
4455        bl3->x2[bl9->l1] = bl3->x2[bl9->l1]*rcorr/rrrr;
4456        bl3->x3[bl9->l1] = bl3->x3[bl9->l1]*rcorr/rrrr;
4457      }
4458    }
4459  }
4460
4461  ncol = ncol + 1;
4462  mrdp = mrdp + 1;
4463  y1[npion] = bl3->x1[bl9->l1];
4464  y2[npion] = bl3->x2[bl9->l1];
4465  y3[npion] = bl3->x3[bl9->l1];
4466
4467  if (bl2->k == 0) {
4468    goto pnu4047;
4469  }
4470 
4471  kd = 0;
4472  ccr = tau;
4473  for(G4int i = 1; i <= bl2->k; i++) {
4474    i20 = i - kd;
4475
4476    if((bl2->ind[i] == bl9->l1) || (bl2->jnd[i] == bl9->l1)) {
4477      kd = kd + 1;
4478    }
4479    else {
4480      bl2->crois[i20] = bl2->crois[i] - ccr;
4481      bl2->ind[i20] = bl2->ind[i];
4482      bl2->jnd[i20] = bl2->jnd[i];
4483    }
4484  }
4485  bl2->k = bl2->k - kd;
4486 
4487 pnu4047:
4488  if (bl5->nesc[bl9->l1] != 0) {
4489    goto pnu845;
4490  }
4491
4492  new1(bl9->l1);
4493  bl2->k = bl2->k + 1;
4494  bl2->crois[bl2->k] = ref(bl3->x1[bl9->l1], bl3->x2[bl9->l1], bl3->x3[bl9->l1], bl1->p1[bl9->l1], bl1->p2[bl9->l1], bl1->p3[bl9->l1], bl1->eps[bl9->l1],r22);
4495  bl2->ind[bl2->k] = bl9->l1;
4496  bl2->jnd[bl2->k] = -1;
4497  if(verboseLevel > 3) {
4498    if(bl2->crois[bl2->k] < 0.0) {
4499      G4cout <<"G4Incl: Reflection time < 0! (line 3797)" << G4endl;
4500    }
4501  }
4502
4503
4504  if(npion > 1) {
4505    n20 = npion - 1;
4506    for(G4int k20 = 1; k20 <= n20; k20++) {
4507      new3(y1[k20], y2[k20], y3[k20], q1[k20], q2[k20], q3[k20], q4[k20], k20, bl9->l1);
4508    }
4509  }
4510
4511 pnu845: 
4512  new2(y1[npion], y2[npion], y3[npion], q1[npion], q2[npion], q3[npion], q4[npion], npion, bl9->l1);
4513  if(bl2->k == 0) {
4514    goto pnu230;
4515  }
4516
4517  if(verboseLevel > 3) {
4518    G4cout <<"G4Incl: bl2->k == 0 after a call to new2. Going back to label pnu449." << G4endl;
4519  }
4520  goto pnu449;
4521
4522  // pion-nucleon collision
4523 pnu801:
4524  if(verboseLevel > 3) {
4525    G4cout <<"Pion-nucleon collision!" << G4endl;
4526  }
4527  lp = bl9->l1 - ia;
4528  dis1 = bl3->x1[bl9->l2]-y1[lp] + (bl1->p1[bl9->l2]/bl1->eps[bl9->l2] - q1[lp]/q4[lp])*tau;
4529  dis2 = bl3->x2[bl9->l2]-y2[lp] + (bl1->p2[bl9->l2]/bl1->eps[bl9->l2] - q2[lp]/q4[lp])*tau;
4530  dis3 = bl3->x3[bl9->l2]-y3[lp] + (bl1->p3[bl9->l2]/bl1->eps[bl9->l2] - q3[lp]/q4[lp])*tau;
4531  dist = dis1*dis1 + dis2*dis2 + dis3*dis3;
4532  t[9] = bl1->eps[bl9->l2] + q4[lp]; //t(10)->t[9]
4533  t0 = 1.0/t[9]; //t(10)->t[9]
4534  b1 = (bl1->p1[bl9->l2] + q1[lp])*t0;
4535  b2 = (bl1->p2[bl9->l2] + q2[lp])*t0;
4536  b3 = (bl1->p3[bl9->l2] + q3[lp])*t0;
4537  s = (1.0 - b1*b1 - b2*b2 - b3*b3)*t[9]*t[9]; //t(10)->t[9]
4538  sq = std::sqrt(s);
4539  cg = 4+bl1->ind2[bl9->l2]*ipi[lp];
4540
4541  if(verboseLevel > 3) {
4542    G4cout <<"Pion-Nucleon collision done! " << G4endl;
4543  }
4544 
4545  if(sq > 3000.0) {
4546    if(verboseLevel > 3) {
4547      G4cout <<"sq = " << sq << G4endl;
4548    }
4549    goto pnu832;
4550  }
4551  if(31.41592*dist > pionNucleonCrossSection(sq)*cg/6.0) {
4552    goto pnu832;
4553  }
4554
4555  if(verboseLevel > 3) {
4556    G4cout <<"Going to pnu220!" << G4endl;
4557  }
4558 
4559  goto pnu220;
4560
4561 pnu832:
4562  if (bl2->k == 0) {
4563    goto pnu230;
4564  }
4565
4566  if(verboseLevel > 3) {
4567    G4cout <<"G4Incl: bl2->k != 0. Going back to pnu44." << G4endl;
4568  }
4569  goto pnu44;
4570 pnu831:
4571  standardRandom(&rndm, &(hazard->igraine[18]));
4572  geff = t[9]/sq; //t(10)->t[9]
4573  gg = g0;
4574  if (sq > 1500.0) {
4575    gg=200.0;
4576  }
4577
4578  // largeur variable du delta (phase space factor G4introduced 4/2001)
4579  // (180.**3 = 5832000.)
4580  qqq = std::sqrt((std::pow(sq,2) - std::pow((fmp+fmpi),2))*(std::pow(sq,2) - std::pow((fmp-fmpi),2)))/(2.0*sq);
4581  psf = std::pow(qqq,3)/(std::pow(qqq,3)+5832000.);
4582  tdel = -hc/(gg*psf)*std::log(rndm)*geff;         
4583
4584  bl1->ind1[bl9->l2] = 1;
4585  bl1->ind2[bl9->l2] = bl1->ind2[bl9->l2] + ipi[lp];
4586  nc[bl9->l2] = nc[bl9->l2] + 1;
4587  bl1->eps[bl9->l2] = t[9]; //t(10)->t[9]
4588  bl1->p1[bl9->l2] = bl1->p1[bl9->l2] + q1[lp];
4589  bl1->p2[bl9->l2] = bl1->p2[bl9->l2] + q2[lp];
4590  bl1->p3[bl9->l2] = bl1->p3[bl9->l2] + q3[lp]; 
4591
4592  // ce nucleon (ici delta) devient un participant:
4593  jparticip[bl9->l2] = 1;
4594  if(verboseLevel > 3) {
4595    G4cout <<"Particle " << bl9->l2 << " is now participant." << G4endl;
4596  }
4597 
4598  if (ws->nosurf <= 0) {
4599    // surface
4600    pppp = std::sqrt(std::pow(bl1->p1[bl9->l2],2) + std::pow(bl1->p2[bl9->l2],2) + std::pow(bl1->p3[bl9->l2],2));
4601    rrrr = std::sqrt(std::pow(bl3->x1[bl9->l2],2) + std::pow(bl3->x2[bl9->l2],2) + std::pow(bl3->x3[bl9->l2],2));
4602    if (pppp <= bl10->pf) {
4603      xv = pppp/bl10->pf;
4604      rcorr = interpolateFunction(xv);
4605      if (rrrr > rcorr) {
4606        bl3->x1[bl9->l2] = bl3->x1[bl9->l2]*rcorr/rrrr;
4607        bl3->x2[bl9->l2] = bl3->x2[bl9->l2]*rcorr/rrrr;
4608        bl3->x3[bl9->l2] = bl3->x3[bl9->l2]*rcorr/rrrr;
4609      }
4610    }
4611    // fin surface
4612  }
4613
4614  // difference with standard cascade :
4615  // the delta is located at the nucleon site to avoid problems
4616  // with the reflexion on the wall
4617  if(lp != npion) {
4618    lp1 = lp + 1;
4619    //    for(G4int i10 = lp1; i10 <= npion; lp1++) {
4620    for(G4int i10 = lp1; i10 <= npion; i10++) {
4621      ipi[i10-1] = ipi[i10];
4622      ym[i10-1] = ym[i10];
4623      q1[i10-1] = q1[i10];
4624      q2[i10-1] = q2[i10];
4625      q3[i10-1] = q3[i10];
4626      q4[i10-1] = q4[i10];
4627      y1[i10-1] = y1[i10];
4628      y2[i10-1] = y2[i10];
4629      y3[i10-1] = y3[i10];
4630    }
4631  }
4632  npion = npion-1;
4633  ncol = ncol+1;
4634  mrpd = mrpd+1;
4635
4636  if(bl2->k != 0) {
4637    kd = 0;
4638    ccr = tau;
4639    for(G4int i = 1; i <= bl2->k; i++) {
4640      i20 = i - kd;
4641      if((bl2->ind[i] == bl9->l1) || (bl2->ind[i] == bl9->l2) || (bl2->jnd[i] == bl9->l1) || (bl2->jnd[i] == bl9->l2)) {
4642        kd = kd + 1;
4643      }
4644      else {
4645        bl2->crois[i20] = bl2->crois[i] - ccr;
4646        bl2->ind[i20] = bl2->ind[i];
4647        bl2->jnd[i20] = bl2->jnd[i];
4648      }
4649    }
4650
4651    bl2->k = bl2->k - kd;
4652    for(G4int i10 = 1; i10 <= bl2->k; i10++) {
4653      if(bl2->ind[i10] <= bl9->l1) {
4654        continue;
4655      }
4656      else {
4657        bl2->ind[i10] = bl2->ind[i10] - 1;
4658      }
4659    }
4660  }
4661
4662  new1(bl9->l2);
4663
4664  if(tdel <= bl4->tmax5) {
4665    bl2->k = bl2->k + 1;
4666    bl2->crois[bl2->k] = tdel;
4667    bl2->ind[bl2->k] = bl9->l2;
4668    bl2->jnd[bl2->k] = 0;
4669  }
4670
4671  bl2->k = bl2->k + 1;
4672  bl2->crois[bl2->k] = ref(bl3->x1[bl9->l2], bl3->x2[bl9->l2], bl3->x3[bl9->l2], bl1->p1[bl9->l2], bl1->p2[bl9->l2], bl1->p3[bl9->l2], bl1->eps[bl9->l2],r22);
4673  if(verboseLevel > 3) {
4674    if(bl2->crois[bl2->k] < 0.0) {
4675      G4cout <<"G4Incl: Reflection time < 0! (line 3955)" << G4endl;
4676    }
4677  }
4678  bl2->ind[bl2->k] = bl9->l2;
4679  bl2->jnd[bl2->k] = -1;
4680
4681  if(verboseLevel > 3) {
4682    G4cout <<"G4Incl: Going back to pnu449 at line 3917." << G4endl;
4683  }
4684  goto pnu449; // Line 3917
4685
4686  // reflection on or transmission through the potential wall
4687 pnu600:
4688  // deutons pas bien compris ici cv ?
4689  if (npproj[bl9->l1] == 0) {
4690    if(verboseLevel > 3) {
4691      G4cout <<"G4Incl: npproj[l1] == 0. Going to pnu608." << G4endl;
4692    }
4693    goto pnu608;
4694  }
4695 
4696  if (bl1->ind1[bl9->l1] != 0) {
4697    if(verboseLevel > 3) {
4698      G4cout <<"wrong reentering particle (ind1[l1] != 0)" << G4endl;
4699      G4cout <<"ind1[" << bl9->l1 << "] = " << bl1->ind1[bl9->l1] << G4endl;
4700    }
4701  }
4702 
4703  if (bl3->x1[bl9->l1]*(bl1->p1[bl9->l1])+bl3->x2[bl9->l1]*(bl1->p2[bl9->l1])+bl3->x3[bl9->l1]*(bl1->p3[bl9->l1]) > 0.0) {
4704    if(verboseLevel > 3) {
4705      G4cout <<"wrong reentering particle" << G4endl;
4706      G4cout <<"particle: l1 = " << bl9->l1 << G4endl;
4707    }
4708  }
4709 
4710  var_ab = std::pow(bl1->p1[bl9->l1],2) + std::pow(bl1->p2[bl9->l1],2) + std::pow(bl1->p3[bl9->l1],2);
4711  gpsg = 0.0;
4712  if (var_ab > 0.0) {
4713    gpsg = std::sqrt((std::pow(bl1->eps[bl9->l1]+v0,2)-pm2)/var_ab); 
4714  }
4715 
4716  bl1->p1[bl9->l1] = gpsg*(bl1->p1[bl9->l1]);                                               
4717  bl1->p2[bl9->l1] = gpsg*(bl1->p2[bl9->l1]);                                               
4718  bl1->p3[bl9->l1] = gpsg*(bl1->p3[bl9->l1]);                                               
4719  bl1->eps[bl9->l1] = bl1->eps[bl9->l1] + v0;
4720  npproj[bl9->l1] = 0;
4721  bl5->nesc[bl9->l1] = 0;
4722
4723  // reevaluation of the times tab after entrance of 2nd,..nucleon
4724  // of the projectile (goto 602 instead of 607 modif. 13/06/01)
4725  goto pnu602;
4726
4727  // deutons
4728  // pour un non participant la transmission est impossible:
4729 pnu608:
4730  if(varavat->kveux == 1) {
4731    varavat->del1avat[iavat] = bl1->ind1[bl9->l1];
4732    varavat->energyavat[iavat] = bl1->eps[bl9->l1] - fmp;
4733  }
4734  if(jparticip[bl9->l1] == 0) {
4735    if(verboseLevel > 3) {
4736      G4cout <<"G4Incl: jparticip[l1] == 0. Going to pnu601." << G4endl;
4737    }
4738    goto pnu601;
4739  }
4740  if(varavat->kveux == 1) {
4741    varavat->go_out[iavat]=1;
4742  }
4743  if (bl1->ind1[bl9->l1] == 0) {
4744    goto pnu605;
4745  }
4746  fm = am(bl1->p1[bl9->l1],bl1->p2[bl9->l1],bl1->p3[bl9->l1],bl1->eps[bl9->l1]);
4747  pot = v1;
4748  goto pnu606;
4749
4750 pnu605:
4751  fm = fmp;
4752  pot = v0;
4753
4754 pnu606:
4755  if(verboseLevel > 3) {
4756    G4cout <<"G4Incl: Now at pnu606. Calculating transmission probability." << G4endl;
4757  }
4758  tp = transmissionProb(bl1->eps[bl9->l1]-fm,bl1->ind2[bl9->l1],itch,bl3->r2,v0);
4759  if(varavat->kveux == 1) {
4760    varavat->energyavat[iavat] = bl1->eps[bl9->l1] - fm;
4761  }
4762  standardRandom(&rndm,&(hazard->igraine[10]));
4763
4764  if (rndm > tp) {
4765    if(verboseLevel > 3) {
4766      G4cout <<"G4Incl:" << G4endl;
4767    }
4768    goto pnu601;
4769  }
4770
4771  // ici la particule l1 s'échappe du noyau:
4772  bl5->nesc[bl9->l1] = 1;
4773  nbquit = nbquit + 1;
4774  itch = itch - (1 + bl1->ind2[bl9->l1])/2;
4775  var_ab = std::pow(bl1->p1[bl9->l1],2) + std::pow(bl1->p2[bl9->l1],2) + std::pow(bl1->p3[bl9->l1],2);
4776  gpsg = 0.0;
4777  if(var_ab > 0.0) {
4778    gpsg = std::sqrt((std::pow(bl1->eps[bl9->l1]-pot,2) - fm*fm)/(var_ab));
4779  }
4780  bl1->p1[bl9->l1] = gpsg*(bl1->p1[bl9->l1]);
4781  bl1->p2[bl9->l1] = gpsg*(bl1->p2[bl9->l1]);
4782  bl1->p3[bl9->l1] = gpsg*(bl1->p3[bl9->l1]);
4783  bl1->eps[bl9->l1] = bl1->eps[bl9->l1] - pot;
4784
4785  // comptage des particules hors du noyau (7/6/2002):
4786  // (remnant minimum=1 nucleon)
4787  if(nbquit >= (ia-1)) {
4788    if(verboseLevel > 3) {
4789      G4cout <<"G4Incl: nbquit >= (ia - 1). Going to pnu255." << G4endl;
4790    }
4791    goto pnu255;
4792  }
4793
4794  if(verboseLevel > 3) {
4795    G4cout <<"G4Incl: Going to pnu 602." << G4endl;
4796  }
4797  goto pnu602;
4798
4799  // here no transmission possible
4800 pnu601:
4801  pspr=bl3->x1[bl9->l1]*(bl1->p1[bl9->l1])+bl3->x2[bl9->l1]*(bl1->p2[bl9->l1])+bl3->x3[bl9->l1]*(bl1->p3[bl9->l1]);
4802  if(varavat->kveux == 1) {
4803    varavat->go_out[iavat]=0;
4804  }
4805
4806  // surface: modif a.b. pour tenir compte du rayon variable du noyau.
4807  // (x2cour remplace r22 le rayon**2 fixe du noyau)
4808  x2cour = std::pow(bl3->x1[bl9->l1],2) + std::pow(bl3->x2[bl9->l1],2) + std::pow(bl3->x3[bl9->l1],2);
4809  bl1->p1[bl9->l1] = bl1->p1[bl9->l1] - 2.0*(bl3->x1[bl9->l1])*pspr/x2cour;
4810  bl1->p2[bl9->l1] = bl1->p2[bl9->l1] - 2.0*(bl3->x2[bl9->l1])*pspr/x2cour;
4811  bl1->p3[bl9->l1] = bl1->p3[bl9->l1] - 2.0*(bl3->x3[bl9->l1])*pspr/x2cour;
4812  // fin modif surface a.b.             
4813
4814 pnu602:
4815  if(verboseLevel > 3) {
4816    G4cout <<"G4Incl: Now at pnu602." << G4endl;
4817  }
4818 
4819  if(bl2->k != 0) {
4820    kd = 0;
4821    ccr = tau;
4822    for(G4int i = 1; i <= bl2->k; i++) {
4823      i20 = i - kd;
4824
4825      if((bl2->jnd[i] == bl9->l1) || ((bl2->ind[i] == bl9->l1) && (bl2->jnd[i] != 0))) {
4826        kd = kd + 1;
4827        continue;
4828      }
4829     
4830      bl2->crois[i20] = bl2->crois[i] - ccr;
4831      bl2->ind[i20] = bl2->ind[i];
4832      bl2->jnd[i20] = bl2->jnd[i];
4833    }
4834    bl2->k = bl2->k - kd;
4835
4836    if (bl5->nesc[bl9->l1] == 1) {
4837      goto pnu613;
4838    }
4839  }
4840
4841  if(verboseLevel > 3) {
4842    G4cout <<"G4Incl: Now calling new1(l1) (new1(" << bl9->l1 << "))" << G4endl;
4843  }
4844  new1(bl9->l1);
4845
4846  if(verboseLevel > 3) {
4847    G4cout <<"G4Incl: Now calling ref." << G4endl;
4848    G4cout <<"x1 = " << bl3->x1[bl9->l1] <<" x2 = " << bl3->x2[bl9->l1] <<" x3 = " << bl3->x3[bl9->l1] << G4endl;
4849    G4cout <<"p1 = " << bl1->p1[bl9->l1] <<" p2 = " << bl1->p2[bl9->l1] <<" p3 = " << bl1->p3[bl9->l1] <<" eps = " << bl1->eps[bl9->l1] << G4endl;
4850  }
4851  tref = ref(bl3->x1[bl9->l1],bl3->x2[bl9->l1],bl3->x3[bl9->l1],bl1->p1[bl9->l1],bl1->p2[bl9->l1],bl1->p3[bl9->l1],bl1->eps[bl9->l1],r22); // line 4101
4852  if(verboseLevel > 3) {
4853    G4cout <<"Returned from function ref. tref = " << tref << G4endl;
4854  }
4855 
4856  if(verboseLevel > 3) {
4857    if(tref < 0.0) {
4858      G4cout <<"G4Incl: Reflection time < 0 (line 4101)!" << G4endl;
4859      G4cout <<"G4Incl: bl1->eps[" << bl9->l1 << "] = " << bl1->eps[bl9->l1] << G4endl;
4860    }
4861  }
4862 
4863  if (tref > bl4->tmax5) {
4864    goto pnu615;
4865  }
4866  bl2->k = bl2->k + 1;
4867  bl2->crois[bl2->k] = tref;
4868  bl2->ind[bl2->k] = bl9->l1;
4869  bl2->jnd[bl2->k] = -1;
4870
4871 pnu615:
4872  if(verboseLevel > 3) {
4873    G4cout <<"G4Incl: Now at pnu615." << G4endl;
4874  }
4875 
4876  if (npion == 0) {
4877    goto pnu613;
4878  }
4879  if (bl1->ind1[bl9->l1] == 1) {
4880    goto pnu613;
4881  }
4882  for(G4int k20 = 1; k20 <= npion; k20++) { //do 614 k20=1,npion
4883    new3(y1[k20], y2[k20], y3[k20], q1[k20], q2[k20], q3[k20], q4[k20], k20, bl9->l1);
4884  }
4885 pnu613:
4886  if(verboseLevel > 3) {
4887    G4cout <<"G4Incl: Now at pnu613." << G4endl;
4888  }
4889
4890  if (bl2->k == 0) {
4891    goto pnu230;
4892  }
4893
4894  if(verboseLevel > 3) {
4895    G4cout <<"G4Incl. bl2->k != 0. Going back to pnu449 from line 4077." << G4endl;
4896    G4cout <<"G4Incl: bl2->k = " << bl2->k << G4endl;
4897    for(G4int myindex = 0; myindex <= bl2->k; myindex++) {
4898      G4cout <<"index = " << myindex << " ind = " << bl2->ind[myindex] << " jnd = " << bl2->jnd[myindex] << " crois = " << bl2->crois[myindex] << G4endl;
4899      if(bl2->crois[myindex] < 0.0) {
4900        G4cout <<"Negative time!!! Dumping information on collision: " << G4endl;
4901        G4int part1 = bl2->ind[myindex];
4902        G4int part2 = bl2->jnd[myindex];
4903        G4cout <<"particle 1 index = " << bl2->ind[myindex] << " \t particle 2 index = " << bl2->jnd[myindex] << G4endl;
4904        if(part1 >= 0) {
4905          G4cout <<"Particle 1: " << G4endl;
4906          G4cout <<"p1 = " << bl1->p1[part1] <<"p2 = " << bl1->p2[part1] <<"p3 = " << bl1->p3[part1] <<" eps = " << bl1->eps[part1] << G4endl;
4907          G4cout <<"x1 = " << bl3->x1[part1] <<"x2 = " << bl3->x2[part1] <<"x3 = " << bl3->x3[part1] << G4endl;
4908        }
4909        if(part2 >= 0) {
4910          G4cout <<"Particle 2: " << G4endl;
4911          G4cout <<"p1 = " << bl1->p1[part2] <<"p2 = " << bl1->p2[part2] <<"p3 = " << bl1->p3[part2] <<" eps = " << bl1->eps[part2] << G4endl;
4912          G4cout <<"x1 = " << bl3->x1[part2] <<"x2 = " << bl3->x2[part2] <<"x3 = " << bl3->x3[part2] << G4endl;
4913        }
4914      }
4915    }
4916  }
4917
4918  goto pnu449; // Line 4077
4919
4920  // decay of the surviving deltas
4921 pnu230:
4922  if(verboseLevel > 3) {
4923    G4cout <<"G4Incl: Now at pnu230." << G4endl;
4924  }
4925  // decay of the surviving deltas
4926pnu255:
4927  if(verboseLevel > 3) {
4928    G4cout <<"G4Incl: Now at pnu6255." << G4endl;
4929  }
4930
4931  if (k3 == 1) {
4932    goto pnu256;
4933  }
4934  if (k4 == 0) {
4935    goto pnu256;
4936  }
4937
4938  npidir = npion;
4939  for(G4int i = 1; i <= ia; i++) {
4940    if (bl1->ind1[i] == 0) {
4941      continue;
4942    }
4943    npion = npion + 1;
4944    var_ab = std::pow(bl1->eps[i],2) - std::pow(bl1->p1[i],2) - std::pow(bl1->p2[i],2) - std::pow(bl1->p3[i],2);
4945    ym[npion] = 0.0;
4946
4947    if(var_ab > 0.0) {
4948      ym[npion] = std::sqrt(var_ab);
4949    }
4950    xy1 = bl1->p1[i];
4951    xy2 = bl1->p2[i];
4952    xy3 = bl1->p3[i];
4953    xye = bl1->eps[i];
4954    if(varavat->kveux == 1) {
4955      iavat = iavat + 1;
4956      varavat->timeavat[iavat] = tim;
4957      varavat->l1avat[iavat] = i;
4958      varavat->l2avat[iavat] = -2;
4959      varavat->energyavat[iavat] = ym[npion];
4960      varavat->bloc_paul[iavat] = 0;
4961      varavat->bloc_cdpp[iavat] = 0;
4962      varavat->del1avat[iavat] = bl1->ind1[bl9->l1];
4963      varavat->jpartl1[iavat] = 1;
4964      varavat->jpartl2[iavat] = 0;
4965    }
4966
4967    decay2(&(bl1->p1[i]), &(bl1->p2[i]), &(bl1->p3[i]), &(bl1->eps[i]), &(q1[npion]), &(q2[npion]), &(q3[npion]),
4968           &(q4[npion]), &(ym[npion]), &fmp, &fmpi, &(bl9->hel[i]));
4969
4970    if(verboseLevel > 3) {
4971      G4cout <<"Quantities after decay2: " << G4endl;
4972      G4cout <<"i = " << i << " bl1->p1[i] = " << bl1->p1[i] << " bl1->p2[i] = " << bl1->p2[i] << " bl1->p3[i] = " << bl1->p3[i] << " bl1->eps[i] = " << bl1->eps[i] << G4endl;
4973    }
4974   
4975    if(bl5->nesc[i] == 0) {
4976      idecf = 1;
4977    }
4978
4979    if (ws->nosurf <= 0) {
4980      // surface
4981      if (bl5->nesc[i] == 0.0) {
4982        pppp = std::sqrt(std::pow(bl1->p1[i],2) + std::pow(bl1->p2[i],2) + std::pow(bl1->p3[i],2));
4983        rrrr = std::sqrt(std::pow(bl3->x1[i],2) + std::pow(bl3->x2[i],2) + std::pow(bl3->x3[i],2));
4984        if (pppp <= bl10->pf) {
4985          xv = pppp/bl10->pf;
4986          rcorr = interpolateFunction(xv);
4987          if (rrrr > rcorr) { //then
4988            bl3->x1[i] = bl3->x1[i]*rcorr/rrrr;
4989            bl3->x2[i] = bl3->x2[i]*rcorr/rrrr;
4990            bl3->x3[i] = bl3->x3[i]*rcorr/rrrr;
4991          }
4992        }
4993      }
4994      // fin surface
4995    }
4996
4997    if (bl1->ind2[i]*(bl1->ind2[i]) == 9) {
4998      goto pnu280;
4999    }
5000
5001    standardRandom(&rndm, &(hazard->ial));
5002
5003    if (rndm*3. < 1.0) {
5004      goto pnu283;
5005    }
5006    ipi[npion] = 0;
5007    goto pnu285;
5008
5009  pnu283:
5010    if(verboseLevel > 3) {
5011      G4cout <<"G4Incl: Now at pnu283." << G4endl;
5012    }
5013
5014    ipi[npion] = bl1->ind2[i]*2;
5015    bl1->ind2[i] = -1*(bl1->ind2[i]);
5016    goto pnu285;
5017
5018  pnu280:
5019    if(verboseLevel > 3) {
5020      G4cout <<"G4Incl: Now at pnu280." << G4endl;
5021    }
5022
5023    bl1->ind2[i] = bl1->ind2[i]/3;
5024    ipi[npion] = 2*(bl1->ind2[i]);
5025
5026  pnu285:
5027    if(verboseLevel > 3) {
5028      G4cout <<"G4Incl: Now at pnu285." << G4endl;
5029    }
5030
5031    y1[npion] = bl3->x1[i];
5032    y2[npion] = bl3->x2[i];
5033    y3[npion] = bl3->x3[i];
5034  }
5035
5036  if(verboseLevel > 3) {
5037    G4cout <<"out of the loop..." << G4endl;
5038  }
5039 
5040  if(varavat->kveux == 1) {
5041    varavat->bavat = b;
5042    varavat->nopartavat = nopart;
5043    varavat->ncolavat = ncol;
5044    varavat->nb_avat = iavat;
5045  }
5046
5047  // final properties of the incoming nucleon and of the remnant
5048  // before evaporation
5049
5050  // tableau des energies a la fin (avatar.hbk)
5051  if(varavat->kveux == 1) {
5052    for(G4int i = 1; i <= ia; i++) {
5053      if(bl5->nesc[i] == 0) {
5054        if(jparticip[i] == 1) {
5055          varavat->epsf[i] = bl1->eps[i];
5056        }
5057        else {
5058          varavat->epsf[i] = 0.0;
5059        }
5060      }
5061      else {
5062        varavat->epsf[i] = 0.0;
5063      }
5064    }
5065  }
5066
5067 pnu256:
5068  if(verboseLevel > 3) {
5069    G4cout <<"G4Incl: Now at pnu256." << G4endl;
5070  }
5071
5072  elead = 0.0;
5073  lead = 0;
5074  npx = 0;
5075  erem = 0.;
5076  izrem = 0;
5077  inrem = 0;
5078  iarem = 0;
5079  rcm1 = 0.0;
5080  rcm2 = 0.0;
5081  rcm3 = 0.0;
5082  prem1 = 0.0;
5083  prem2 = 0.0;
5084  prem3 = 0.0;
5085  pout1 = 0.0;
5086  pout2 = 0.0;
5087  pout3 = 0.0;
5088  eout = 0.0;
5089  cmultn = 0.0;
5090
5091  if (kindstruct->kindf7 <= 2) {
5092    if (ncol == 0 || nc[1] == 0) { // then nc(1)->nc[0]
5093      if(verboseLevel > 3) {
5094        G4cout <<"no collisioms" << G4endl;
5095      }
5096      goto pnu9100;
5097    }
5098  }
5099  else {
5100    if (kindstruct->kindf7 <= 5) {
5101      if (ncol == 0) {
5102        if(verboseLevel > 3) {
5103          G4cout <<"no collisioms" << G4endl;
5104        }
5105        goto pnu9100;
5106      }
5107    }
5108    else {
5109      // ici faisceau composite: modif a.b. 2/2002 pour tous les composites:
5110      nsum_col = 0;
5111      for(G4int i = 1; i <= bl3->ia1; i++) {
5112        nsum_col = nsum_col + nc[i];
5113      }
5114      if (ncol == 0 || nsum_col == 0) { //then
5115        goto pnu9100;
5116      }
5117    }
5118  }
5119
5120  goto pnu9101;
5121  // pour eviter renvoi des resultats du run precedent cv 20/11/98
5122 pnu9100:
5123  iarem = bl3->ia2;
5124  izrem = iz2;
5125  esrem = 0.0;
5126  erecrem = 0.0;
5127  nopart = -1;
5128  // fin ajout cv
5129  if(verboseLevel > 3) {
5130    G4cout <<"End of algorithm after pnu9100." << G4endl;
5131  }
5132  goto pnureturn;
5133
5134 pnu9101:
5135  if(verboseLevel > 3) {
5136    G4cout <<"G4Incl: Now at pnu9101." << G4endl;
5137  }
5138
5139  nopart = 0;
5140  ekout = 0.0;
5141
5142  for(G4int i = 1; i <= ia; i++) {
5143    if(bl5->nesc[i] != 0) {
5144      xl1 = xl1-bl3->x2[i]*(bl1->p3[i]) + (bl3->x3[i])*(bl1->p2[i]);
5145      xl2 = xl2-bl3->x3[i]*(bl1->p1[i]) + bl3->x1[i]*(bl1->p3[i]);
5146      xl3 = xl3-bl3->x1[i]*(bl1->p2[i]) + bl3->x2[i]*(bl1->p1[i]);
5147
5148      // ici ajout de pout cv le 5/7/95
5149      pout1 = pout1 + bl1->p1[i];
5150      pout2 = pout2 + bl1->p2[i];
5151      pout3 = pout3 + bl1->p3[i];
5152      eout = eout+bl1->eps[i] - fmp;
5153      //      ic33 = int((std::floor(double(bl1->ind2[i]+3))/double(2)));
5154      ic33 = (bl1->ind2[i]+3)/2;
5155      //nopart = nopart + 1;
5156      kind[nopart] = 3 - ic33;
5157      if(verboseLevel > 3) {
5158        G4cout <<"kind[" << nopart << "] = " << kind[nopart] << G4endl;
5159      }
5160      ep[nopart] = bl1->eps[i] - fmp;
5161      if(verboseLevel > 2) {
5162        if(ep[nopart] > calincl->f[2]) {
5163          G4cout <<"ep[" << nopart << "] = " << ep[nopart] << " > " << calincl->f[2] << G4endl;
5164          G4cout <<"E = " << bl1->eps[nopart] << G4endl;
5165          G4cout <<"px = " << bl1->p1[nopart] << " py = " << bl1->p2[nopart] << " pz = " << bl1->p3[nopart] << G4endl;
5166          G4cout <<"Particle mass = " << fmp << G4endl;
5167        }
5168      }
5169      bmass[nopart] = fmp;
5170      ekout = ekout + ep[nopart];
5171      ptotl = std::sqrt(std::pow(bl1->p1[i],2) + std::pow(bl1->p2[i],2) + std::pow(bl1->p3[i],2));
5172      alpha[nopart] = bl1->p1[i]/ptotl;
5173      beta[nopart] = bl1->p2[i]/ptotl;
5174      gam[nopart] = bl1->p3[i]/ptotl;
5175      nopart = nopart + 1;
5176      continue;
5177    }
5178   
5179    t[3] = bl3->x1[i]*(bl3->x1[i]) + bl3->x2[i]*(bl3->x2[i]) + bl3->x3[i]*(bl3->x3[i]); //t(4)->t[3]
5180    erem = erem + bl1->eps[i] - fmp;
5181    rcm1 = rcm1 + bl3->x1[i];
5182    rcm2 = rcm2 + bl3->x2[i];
5183    rcm3 = rcm3 + bl3->x3[i];
5184    prem1 = prem1 + bl1->p1[i];
5185    prem2 = prem2 + bl1->p2[i];
5186    prem3 = prem3 + bl1->p3[i];
5187    izrem = izrem + (1 + bl1->ind2[i])/2;
5188    iarem = iarem + 1;
5189  }
5190
5191  //  correction pions 21/3/95 jc
5192  ichpion = 0;
5193  if(npion != 0) {
5194    for(G4int ipion = 1; ipion <= npion; ipion++) {
5195      pout1 = pout1 + q1[ipion];
5196      pout2 = pout2 + q2[ipion];
5197      pout3 = pout3 + q3[ipion];
5198      eout = eout + q4[ipion];
5199      xl1 = xl1 - y2[ipion]*q3[ipion] + y3[ipion]*q2[ipion];
5200      xl2 = xl2 - y3[ipion]*q1[ipion] + y1[ipion]*q3[ipion];
5201      xl3 = xl3 - y1[ipion]*q2[ipion] + y2[ipion]*q1[ipion];
5202      ichpion = ichpion + ipi[ipion]/2;
5203      //      nopart = nopart + 1;
5204      kind[nopart] = 4 - ipi[ipion]/2;
5205      ptotl = std::sqrt(std::pow(q1[ipion],2) + std::pow(q2[ipion],2) + std::pow(q3[ipion],2));
5206      ep[nopart] = q4[ipion] - fmpi;
5207      bmass[nopart] = fmpi;
5208      ekout = ekout + ep[nopart];
5209      alpha[nopart] = q1[ipion]/ptotl;
5210      beta[nopart] = q2[ipion]/ptotl;
5211      gam[nopart] = q3[ipion]/ptotl;
5212      nopart++;
5213    }
5214  }
5215 
5216  // fin correction pions sur impulsion et moment angulaire et charge
5217  // ici ajout de pfrem cv le 5/7/95
5218  pfrem1 = -pout1;
5219  pfrem2 = -pout2;
5220  pfrem3 = pinc - pout3;
5221
5222  inrem = iarem - izrem;
5223  iejp = iz2 - izrem;
5224  iejn = bl3->ia2 - inrem - iz2;
5225  irem = inrem + izrem;
5226
5227  // intrinsic momentum of the remnant (a.b. 05/2001):
5228  // momentum of projectile minus momentum of all outgoing particles
5229  // minus angular momentum of the remnant computed
5230  // from the sum of all inside nucleons.
5231  //   2675     c      xl1=xl1-rcm2/irem*prem3+rcm3/irem*prem2
5232  //   2676     c      xl2=xl2-rcm3/irem*prem1+rcm1/irem*prem3
5233  //   2677     c      xl3=xl3-rcm1/irem*prem2+rcm2/irem*prem1
5234  //   2678     c                           here the remnant momentum is pin - sig(pout),
5235  //   2679     c   and the distance with respect to the barycenter of the actual target
5236  xl1 = xl1 - (rcm2/irem - x2_target)*pfrem3+(rcm3/irem - x3_target)*pfrem2;
5237  xl2 = xl2 - (rcm3/irem - x3_target)*pfrem1+(rcm1/irem - x1_target)*pfrem3;
5238  xl3 = xl3 - (rcm1/irem - x1_target)*pfrem2+(rcm2/irem - x2_target)*pfrem1;
5239  l = int(std::sqrt(xl1*xl1 + xl2*xl2 + xl3*xl3)/hc + 0.5);
5240
5241  iej = bl3->ia2 - irem;
5242
5243  eh5 = erem - std::pow(double(irem)/double(a2),1.666667)*efer;
5244  if(verboseLevel > 3) {
5245    G4cout <<"erem used for excitation energy calculation = " << erem << G4endl;
5246    G4cout <<"irem used for excitation energy calculation = " << irem << G4endl;
5247    G4cout <<"a2 used for excitation energy calculation = " << a2 << G4endl;
5248    G4cout <<"eh5 used for excitation energy calculation = " << eh5 << G4endl;
5249  }
5250  sepa = (bl3->ia2 - irem)*(v0 - tf);
5251  eh6 = eh5;
5252
5253  // deutons ajout beproj ?????? on retire beproj (18/06/2002 ab cv)
5254  // eh5=erem-efer-beproj+(ia2-irem)*tf
5255  eh5 = erem - efer + (bl3->ia2 - irem)*tf;
5256  if (eh5 < 0.0) {
5257    eh5 = 0.00000001;
5258  }
5259
5260  xlab = tlab - eout - eh5 - sepa;
5261  ecoreh5 = 0.0;
5262
5263  if (iqe == 1) {
5264    eh5=0.00000001;
5265  }
5266  else {
5267    if (eh5 < 0.0) {
5268      if (npion == 0) {
5269        nopart = -1;
5270        if(verboseLevel > 3) {
5271          G4cout <<"npion == 0" << G4endl;
5272          G4cout <<"End of algorithm because npion == 0" << G4endl;
5273        }
5274        goto pnureturn;
5275      }
5276      else {
5277        ecoreh5 = -eh5;
5278        eh5 = 0.000000001;
5279      }
5280    }
5281  }
5282  if (idecf != 0 && eh5 < 0.0) {
5283    ecoreh5 = -eh5;
5284    eh5 = 0.000001;
5285  }
5286
5287  iarem = irem;
5288  pfreml2 = std::pow(pfrem1,2) + std::pow(pfrem2,2) + std::pow(pfrem3,2);
5289  if (pfreml2 > 1.0e-12) {
5290    pfreml = std::sqrt(pfreml2);
5291    alrem = pfrem1/pfreml;
5292    berem = pfrem2/pfreml;
5293    garem = pfrem3/pfreml;
5294  }
5295  else {
5296    alrem = 0.0;
5297    berem = 0.0;
5298    garem = 1.0;
5299  }
5300
5301  erecrem = pfreml2/(std::sqrt(pfreml2 + std::pow((fmp*iarem),2)) + fmp*iarem);
5302
5303  if(iarem == 1) {
5304    erecrem = erecrem + eh5;
5305  }
5306
5307  // correction recul
5308  erecg = erecrem + ecoreh5;
5309  // correction energie d'excitation pour une absorption (a.b., c.v. 2/2002)
5310  esrem = eh5;
5311
5312  if (ekout < 0.001) {
5313    if(verboseLevel > 3) {
5314      G4cout <<"ekout < 0.001" << G4endl;
5315      G4cout <<"End of algorithm because kout < 0.001" << G4endl;
5316    }
5317    goto pnureturn;
5318  }
5319 
5320  // on ote l'instruction precedente car esrem toujours nulle 14/9/99
5321
5322  if (erecg > 0.25) {
5323    fffc = (ekout - erecg)/ekout;
5324    if (fffc < 0.0) {
5325      fffc = 0.0;
5326    }
5327
5328    for(G4int ipart = 0; ipart < nopart; ipart++) {
5329      ep[ipart] = ep[ipart]*fffc;
5330    }
5331  }
5332
5333  // modif boudard juillet 99 (il faut tenir compte de la renormalisation
5334  // des energies pour les impulsions.)
5335  pfrem1 = 0.0;
5336  pfrem2 = 0.0;
5337  pfrem3 = pinc;
5338  for(G4int ipart = 0; ipart < nopart; ipart++) {
5339    xmodp = std::sqrt(ep[ipart]*(2.0*bmass[ipart] + ep[ipart]));
5340    pfrem1 = pfrem1 - alpha[ipart]*xmodp;
5341    pfrem2 = pfrem2 - beta[ipart]*xmodp;
5342    pfrem3 = pfrem3 - gam[ipart]*xmodp;
5343  }
5344  // fin modif a.b.
5345
5346  pfreml2 = std::pow(pfrem1,2) + std::pow(pfrem2,2) + std::pow(pfrem3,2);
5347  erecrem = pfreml2/(std::sqrt(pfreml2 + std::pow((fmp*iarem),2)) + fmp*iarem);
5348
5349  if (pfreml2 > 1.0e-12) {
5350    pfreml = std::sqrt(pfreml2);
5351    alrem = pfrem1/pfreml;
5352    berem = pfrem2/pfreml;
5353    garem = pfrem3/pfreml;
5354  }
5355  else {
5356    alrem = 0.0;
5357    berem = 0.0;
5358    garem = 1.0;
5359  }
5360  // fin  modif a.b. pour incl3
5361
5362  esrem = eh5;
5363
5364  // if the remnant is a nucleon, no excitation energy
5365  if(iarem == 1) {
5366    esrem = 0.0;
5367  }
5368
5369  if(verboseLevel > 3) {
5370    G4cout <<"Reached end of routine..." << G4endl;
5371  }
5372  goto pnureturn;
5373
5374  if(verboseLevel > 3) {
5375    G4cout <<"ia1 > 1 ! " << G4endl;
5376  }
5377 pnureturn:
5378  (*ibert_p) = ibert;
5379  (*nopart_p) = nopart;
5380  (*izrem_p) = izrem;
5381  (*iarem_p) = iarem;
5382  (*esrem_p) = esrem; 
5383  (*erecrem_p) = erecrem;
5384  (*alrem_p) = alrem;
5385  (*berem_p) = berem;
5386  (*garem_p) = garem;
5387  (*bimpact_p) = bimpact;
5388  (*l_p) = l;
5389}
5390
5391
5392void G4Incl::collis(G4double *p1_p, G4double *p2_p, G4double *p3_p, G4double *e1_p, G4double *pout11_p, G4double *pout12_p, 
5393                    G4double *pout13_p, G4double *eout1_p, G4double *q1_p, G4double *q2_p, G4double *q3_p,
5394                    G4double *q4_p, G4int *np_p, G4int *ip_p, G4int *k2_p, G4int *k3_p, G4int *k4_p, 
5395                    G4int *k5_p, G4int *m1_p, G4int *m2_p, G4int *is1_p, G4int *is2_p)
5396{
5397  G4double p1 = (*p1_p);
5398  G4double p2 = (*p2_p);
5399  G4double p3 = (*p3_p);
5400
5401  G4double e1 = (*e1_p);
5402
5403  G4double debugOutput = 0.0;
5404  debugOutput = am(p1,p2,p3,e1);
5405
5406  G4double pout11 = (*pout11_p);
5407  G4double pout12 = (*pout12_p);
5408  G4double pout13 = (*pout13_p);
5409  G4double eout1 = (*eout1_p);
5410
5411  G4double q1 = (*q1_p);
5412  G4double q2 = (*q2_p);
5413  G4double q3 = (*q3_p);
5414  //  G4double q4 = -1*(*q4_p);
5415  G4double q4 = (*q4_p);
5416
5417  G4int np = (*np_p);
5418  G4int ip = (*ip_p);
5419
5420  G4int k2 = (*k2_p);
5421  G4int k3 = (*k3_p);
5422  G4int k4 = (*k4_p);
5423  G4int k5 = (*k5_p);
5424
5425  G4int m1 = (*m1_p);
5426  G4int m2 = (*m2_p);
5427
5428  G4int is1 = (*is1_p);
5429  G4int is2 = (*is2_p);
5430
5431  // Variables:
5432  G4double a = 0.0;
5433  G4double aaa = 0.0;
5434  G4double aac = 0.0;
5435  //  G4double alog;
5436  G4double alphac = 0.0;
5437  //  G4double amax1;
5438  G4double apt = 0.0;
5439  G4double argu = 0.0;
5440  G4double b = 0.0;
5441  G4double btmax = 0.0;
5442  G4double cfi = 0.0;
5443  G4double cpt = 0.0;
5444  G4double ctet = 0.0;
5445  G4double e3 = 0.0;
5446  G4double ecm = 0.0;
5447  G4double ex[3];
5448  G4double ey[3];
5449  G4double ez[3];
5450  G4double qq[3];
5451  for(G4int init_i = 0; init_i < 3; init_i++) {
5452    ex[init_i] = 0.0;
5453    ey[init_i] = 0.0;
5454    ez[init_i] = 0.0;
5455    qq[init_i] = 0.0;
5456  }
5457  G4double f3 = 0.0;
5458  G4double f3max = 0.0;
5459  G4double fi = 0.0;
5460  G4double fracpn = 0.0;
5461  G4double heli = 0.0;
5462  G4int iexpi = 0;
5463  G4int ii = 0;
5464  G4int index = 0;
5465  G4int index2 = 0;
5466  G4int isi = 0;
5467  G4double pin = 0.0;
5468  G4double pl = 0.0;
5469  G4double pnorm = 0.0;
5470  //  G4double pq = 0.0;
5471  G4double psq = 0.0;
5472  G4double qq4 = 0.0;
5473  G4double ranres = 0.0;
5474  G4double rndm = 0.0;
5475  G4double s = 0.0;
5476  G4double s1 = 0.0;
5477  //  G4double sel;
5478  G4double sfi = 0.0;
5479  G4double stet = 0.0;
5480  G4double t = 0.0;
5481  G4double x = 0.0;
5482  G4double xkh = 0.0;
5483  G4double xp1 = 0.0;
5484  G4double xp2 = 0.0;
5485  G4double xp3 = 0.0;
5486  G4double xx = 0.0;
5487  G4double y = 0.0;
5488  G4double yn = 0.0;
5489  G4double z = 0.0;
5490  G4double zn = 0.0;
5491  G4double zz = 0.0;
5492
5493  // !!!  q4 = -1*q4;
5494  //   2837     c
5495  //   2838     c collis                                                                p-n17770
5496  //   2839           subroutine collis(p1,p2,p3,e1,pout11,pout12,pout13,eout1,q1,q2,q3,p-n17780
5497  //   2840          -q4,np,ip,k2,k3,k4,k5,m1,m2,is1,is2)                               p-n17790
5498
5499  //   2841           common/bl6/xx10,isa                                               p-n17800
5500  //   2842           common/bl8/rathr,ramass                                           p-n17810
5501  //   2843           common/hazard/ial,iy1,iy2,iy3,iy4,iy5,iy6,iy7,iy8,iy9,iy10,
5502  //   2844          s               iy11,iy12,iy13,iy14,iy15,iy16,iy17,iy18,iy19
5503  //   2845           common/bl9/hel(300),l1,l2
5504  //  2846            dimension ex(3),ey(3),ez(3),qq(3)                                 p-n17820
5505  //  2847            data xm,xm2,xmdel,ezero,xpi/938.2796,8.8037e5,1232.,1876.6,138./  p-n17830
5506  G4double xm = 938.2796;
5507  G4double xm2 = 8.8037e5;
5508  G4double xmdel = 1232.0;
5509  G4double xpi = 138.0;
5510
5511  //   2848     c      data iy1,iy2,iy3,iy4,iy5,iy6,iy7,iy8,iy10,iy11,iy12,iy13/         p-n17840
5512  //   2849     c     1 12345,22345,32345,42345,52345,62345,72345,82345,34567,47059,21033p-n17850
5513  //   2850     c     1 12345,22345,32345,42345,52345,62345,72345,82341,34567,47059,21033p-n17850
5514  //   2851     c     2,32835/                                                           p-n17860
5515  //   2852     c      data iy9/15637/
5516  //  2853            pcm(e,a,c)=0.5*std::sqrt((e**2-(a+c)**2)*(e**2-(a-c)**2))/e            p-n17870
5517  G4int iso = is1 + is2;
5518  np = 0;
5519  psq = p1*p1 + p2*p2 + p3*p3;
5520  pnorm = std::sqrt(psq);
5521  ecm = e1 + eout1;
5522 
5523  if(ecm < 1925.0) {
5524    goto collis160;
5525  }
5526
5527  if (k3 == 1) {
5528    goto collis17;
5529  }
5530
5531  if(ecm < (2065.0 + bl8->rathr)) {
5532    goto collis17;
5533  }
5534
5535  if((k4-1) < 0) {
5536    goto collis18;
5537  }
5538  if((k4-1) == 0) {
5539    goto collis10;
5540  }
5541  if((k4-1) > 0) {
5542    goto collis20;
5543  }
5544
5545 collis10:
5546  if((m1+m2-1) < 0) {
5547    goto collis19;
5548  }
5549  if((m1+m2-1) == 0) {
5550    goto collis14;
5551  }
5552  if((m1+m2-1) > 0) {
5553    goto collis13;
5554  }
5555
5556 collis19:
5557  if((ecm-2170.4-bl8->ramass) <= 0) {
5558    goto collis17;
5559  }
5560  if((ecm-2170.4-bl8->ramass) > 0) {
5561    goto collis18;
5562  }
5563
5564 collis20:
5565  if((m1+m2-1) < 0) {
5566    goto collis18;
5567  }
5568  if((m1+m2-1) == 0) {
5569    goto collis14;
5570  }
5571  if((m1+m2-1) > 0) {
5572    goto collis13;
5573  }
5574
5575  // test on the recombination possibility for the n-delta system
5576 collis14:
5577  if (k5 == 0) {
5578    goto collis170;
5579  }
5580
5581  standardRandom(&rndm, &(hazard->igraine[10]));
5582
5583  s1 = lowEnergy(ecm, 1, iso);
5584 
5585  if(m1 != 0) {
5586    bl6->xx10=std::sqrt(e1*e1-psq);
5587    bl6->isa=is1;
5588  }
5589  else {
5590    bl6->xx10 = std::sqrt(std::pow(eout1,2)-psq);
5591    bl6->isa = is2;
5592  }
5593
5594  s = s1 + srec(ecm,bl6->xx10, iso,int(bl6->isa));
5595  a = (s - s1)/s;
5596 
5597  if((rndm-a) <= 0) {
5598    goto collis170;
5599  }
5600  if((rndm-a) > 0) {
5601    goto collis17;
5602  }
5603
5604  // test for the behaviour of the delta-delta system
5605 collis13:
5606  if (k5 == 0) {
5607    goto collis160;
5608  }
5609  goto collis17;
5610
5611  // test on the inelasticity
5612 collis18:
5613  standardRandom(&rndm, &(hazard->igraine[0]));
5614  s = lowEnergy(ecm,0,iso);
5615  a = deltaProductionCrossSection(ecm,iso);
5616  a = s/(s+a);
5617  if(rndm > a) {
5618    goto collis100;
5619  }
5620
5621  // elastic scattering
5622  // fit of the b parameter in the differential x-section:
5623  // taken from :j.c.,d.l'hote, j.vandermeulen,nimb111(1996)215
5624  // for pn :improvement of the backward scattering according
5625  // j.c et al, prc56(1997)2431
5626 collis17:
5627  pl = 0.5*ecm*std::sqrt(std::pow(ecm,2) - 4.0*xm2)/xm;
5628  x = 0.001*pl;
5629 
5630  if (iso == 0) {
5631    goto collis80;
5632  }
5633  if (pl > 2000.0) {
5634    goto collis81;
5635  }
5636  x = x*x;
5637  x = std::pow(x,4);
5638  b = 5.5e-6*x/(7.7+x);
5639  goto collis82;
5640
5641 collis81:
5642  b = (5.34 + 0.67*(x-2.0))*1.e-6;
5643  goto collis82;
5644
5645 collis80: 
5646  if (pl < 800.) {
5647    b = (7.16 - 1.63*x)*1.e-6;
5648    b = b/(1.0 + std::exp(-(x - 0.45)/0.05));
5649  }
5650  else {
5651    if (pl < 1100.) {
5652      b = (9.87 - 4.88*x)*1.e-6;
5653    }
5654    else {
5655      b = (3.68 + 0.76*x)*1.e-6;
5656    }
5657  }
5658
5659 collis82:
5660  debugOutput = am(p1,p2,p3,e1);
5661 
5662  btmax = 4.0*psq*b;
5663  z = std::exp(-btmax);
5664  standardRandom(&rndm, &(hazard->igraine[1]));
5665  ranres = rndm; 
5666  y = 1.0 - rndm*(1.0 - z);
5667  t = std::log(y)/b;
5668  iexpi = 0;
5669
5670  if (((m1+m2) == 0) && (iso == 0)) {
5671    apt = 1.0;                                                       
5672    if (pl > 800.) {
5673      apt = std::pow((800.0/pl),2);                                         
5674      cpt = amax1(6.23*std::exp(-1.79*x),0.3);
5675      alphac = 100.0*1.e-6;
5676      aaa = (1 + apt)*(1 - std::exp(-btmax))/b;
5677      argu = psq*alphac;
5678
5679      if (argu >= 8) {
5680        argu = 0.0;
5681      }
5682      else {
5683        argu = std::exp(-4.0*argu);
5684      }
5685
5686      aac = cpt*(1.0 - argu)/alphac;
5687      fracpn = aaa/(aac + aaa);
5688      standardRandom(&rndm, &(hazard->igraine[7]));
5689      if (rndm > fracpn) {
5690        z = std::exp(-4.0*psq*alphac);
5691        iexpi = 1;
5692        //      y = 1.0 - ranres*(10.0 - z);
5693        y = 1.0 - ranres*(1.0 - z);
5694        t = std::log(y)/alphac;
5695      }
5696    }
5697  }
5698
5699  ctet = 1.0 + 0.5*t/psq;
5700  if(std::fabs(ctet) > 1.0) {
5701    ctet = sign(1.0,ctet);
5702  }     
5703
5704  stet = std::sqrt(1.0 - std::pow(ctet,2));
5705  standardRandom(&rndm, &(hazard->igraine[2]));
5706  fi = 6.2832*rndm;
5707  cfi = std::cos(fi);
5708  sfi = std::sin(fi);
5709  xx = p1*p1 + p2*p2;
5710  zz = p3*p3;   
5711
5712  debugOutput = am(p1,p2,p3,e1);
5713
5714  if(xx >= (zz*1.0e-8)) {
5715    yn=std::sqrt(xx);
5716    zn=yn*pnorm;
5717    ez[0] = p1/pnorm; // ez(1) -> ez[0] and so on...
5718    ez[1] = p2/pnorm;
5719    ez[2] = p3/pnorm;
5720    ex[0] = p2/yn;
5721    ex[1] = -p1/yn;
5722    ex[2] = 0.0;     
5723    ey[0] = p1*p3/zn;
5724    ey[1] = p2*p3/zn;
5725    ey[2] = -xx/zn;
5726    p1 = (ex[0]*cfi*stet + ey[0]*sfi*stet + ez[0]*ctet)*pnorm;
5727    p2 = (ex[1]*cfi*stet + ey[1]*sfi*stet + ez[1]*ctet)*pnorm;
5728    p3 = (ex[2]*cfi*stet + ey[2]*sfi*stet + ez[2]*ctet)*pnorm;
5729  }
5730  else {
5731    p1 = p3*cfi*stet;
5732    p2 = p3*sfi*stet;
5733    p3 = p3*ctet;
5734  }
5735  pout11 = -p1;
5736  pout12 = -p2;
5737  pout13 = -p3;
5738  debugOutput = am(p1,p2,p3,e1);
5739
5740  // backward scattering according the parametrization of ref
5741  // prc56(1997)1
5742
5743  if(((m1+m2) != 1) || (iso == 0)) {
5744    standardRandom(&rndm, &(hazard->igraine[7]));
5745    apt = 1.0;
5746    if (pl > 800.0) {
5747      apt = std::pow((800.0/pl),2);
5748    }
5749    if ((iexpi == 1) || (rndm > (1./(1.+apt)))) {
5750      ii = is1;
5751      is1 = is2;
5752      is2 = ii;
5753    }
5754  }
5755
5756  debugOutput = am(p1,p2,p3,e1);
5757  goto exitRoutine;
5758
5759  // delta production
5760  // the production is not isotropic in this version
5761  // it has the same std::exp(b*t) structure as the nn elastic scatteringp-n19170
5762  // (formula 2.3 of j.cugnon et al, nucl phys a352(1981)505)
5763  // parametrization of b taken from ref. prc56(1997)2431
5764 collis100:
5765  if (k4 != 1) {
5766    goto collis101;
5767  }
5768  xmdel = 1232.0 + bl8->ramass;
5769  goto collis103;
5770 collis101: 
5771  //call ribm(rndm,iy10)
5772  standardRandom(&rndm, &(hazard->igraine[9]));
5773
5774  y = std::tan(3.1415926*(rndm - 0.5));
5775  x = 1232.0 + 0.5*130.0*y + bl8->ramass;
5776  if (x < (xm+xpi+2.0)) {
5777    goto collis101;
5778  }
5779  if (ecm < (x+xm+1.)) {
5780    goto collis101;
5781  }
5782
5783  // generation of the delta mass with the penetration factor
5784  // (see prc56(1997)2431)
5785  y = std::pow(ecm,2);
5786  q2 = (y - std::pow(1076.0,2))*(y - std::pow(800.0,2))/y/4.0;                                 
5787  q3 = std::pow((std::sqrt(q2)),3);                                                 
5788  f3max = q3/(q3 + std::pow(180.0,3));                                     
5789  y = std::pow(x,2);
5790  q2 = (y - std::pow(1076.0,2))*(y - std::pow(800.0,2))/y/4.0;                                 
5791  q3 = std::pow((std::sqrt(q2)),3);                                                 
5792  f3 = q3/(q3 + std::pow(180.0,3));
5793
5794  standardRandom(&rndm, &(hazard->igraine[10]));
5795  if (rndm > (f3/f3max)) {
5796    goto collis101;
5797  }                         
5798  xmdel = x;
5799
5800 collis103:
5801  pin = pnorm;
5802  pnorm = pcm(ecm,xm,xmdel);
5803  if (pnorm <= 0) {
5804    pnorm = 0.000001;
5805  }
5806  index = 0;
5807  index2 = 0;
5808
5809  standardRandom(&rndm, &(hazard->igraine[3]));
5810  if (rndm < 0.5) {
5811    index = 1;
5812  }
5813 
5814  if (iso == 0) {
5815    standardRandom(&rndm, &(hazard->igraine[4]));
5816    if (rndm < 0.5) {
5817      index2 = 1;
5818    } 
5819  }
5820
5821  standardRandom(&rndm, &(hazard->igraine[5]));
5822  x = 0.001*0.5*ecm*std::sqrt(std::pow(ecm,2) - 4.0*xm2)/xm;
5823  if(x < 1.4) {
5824    b = (5.287/(1.0 + std::exp((1.3 - x)/0.05)))*1.e-6;
5825  }
5826  else {
5827    b = (4.65 + 0.706*(x - 1.4))*1.e-6;
5828  }
5829
5830  xkh = 2.0*b*pin*pnorm;
5831  ctet=1.0 + std::log(1.0 - rndm*(1.0 - std::exp(-2.0*xkh)))/xkh;
5832  if(std::fabs(ctet) > 1.0) {
5833    ctet = sign(1.0,ctet);
5834  }
5835 
5836  stet = std::sqrt(1.0 - std::pow(ctet,2));
5837  standardRandom(&rndm, &(hazard->igraine[6]));
5838  fi = 6.2832*rndm;
5839  cfi = std::cos(fi);
5840  sfi = std::sin(fi);
5841
5842  // delta production: correction of the angular distribution 02/09/02
5843  xx = p1*p1 + p2*p2;
5844  zz = p3*p3;
5845  if(xx >= (zz*1.0e-8)) {
5846    yn = std::sqrt(xx);
5847    zn = yn*pin;
5848    ez[0] = p1/pin; // ez(1) -> ez[0] and so on...
5849    ez[1] = p2/pin;
5850    ez[2] = p3/pin;
5851    ex[0] = p2/yn;
5852    ex[1] = -p1/yn;
5853    ex[2] = 0.0;
5854    ey[0] = p1*p3/zn;
5855    ey[1] = p2*p3/zn;
5856    ey[2] = -xx/zn;
5857    xp1 = (ex[0]*cfi*stet + ey[0]*sfi*stet + ez[0]*ctet)*pnorm;
5858    xp2 = (ex[1]*cfi*stet + ey[1]*sfi*stet + ez[1]*ctet)*pnorm;
5859    xp3 = (ex[2]*cfi*stet + ey[2]*sfi*stet + ez[2]*ctet)*pnorm;
5860  }
5861  else {
5862    xp1 = pnorm*stet*cfi;
5863    xp2 = pnorm*stet*sfi;
5864    xp3 = pnorm*ctet;
5865  }
5866  // end of correction angular distribution of delta production
5867
5868  e3 = std::sqrt(xp1*xp1 + xp2*xp2 + xp3*xp3 + xm*xm);
5869  if(k4 != 0) {
5870    goto collis161;
5871  }
5872 
5873  // decay of the delta particle (k4=0)
5874  np = 1;
5875  ip = 0;
5876  qq[0] = xp1; //qq(1) -> qq[0]
5877  qq[1] = xp2;
5878  qq[2] = xp3;
5879  qq4 = std::sqrt(xp1*xp1 + xp2*xp2 + xp3*xp3 + xmdel*xmdel);
5880  heli = std::pow(ctet,2);
5881
5882  if(verboseLevel > 3) {
5883    G4cout <<"Caling decay2 from collis" << G4endl;
5884  }
5885  decay2(&qq[0],&qq[1],&qq[2],&qq4,&q1,&q2,&q3,&q4,&xmdel,&xm,&xpi,&heli);
5886
5887  if(index != 0) {
5888    p1 = qq[0]; //qq(1) -> qq[0] and so on...
5889    p2 = qq[1];
5890    p3 = qq[2];
5891    pout11 = -xp1;
5892    pout12 = -xp2;
5893    pout13 = -xp3;
5894    eout1 = e3;
5895  }
5896  else {
5897    pout11 = qq[0]; //qq(1) -> qq[0] and so on...
5898    pout12 = qq[1];
5899    pout13 = qq[2];
5900    eout1 = e1;
5901    p1 = -xp1;
5902    p2 = -xp2;
5903    p3 = -xp3;
5904    e1 = e3;
5905  }
5906  debugOutput = am(p1,p2,p3,e1);
5907
5908  if (iso == 0) {
5909    goto collis150;
5910  }
5911  if (rndm > 0.333333) {
5912    debugOutput = am(p1,p2,p3,e1);
5913    goto exitRoutine;
5914  }
5915
5916  is1 = -is1;
5917  ip = -2*is1;
5918
5919 collis150:
5920  if (index == 1) {
5921    debugOutput = am(p1,p2,p3,e1);
5922    goto exitRoutine;
5923  }
5924  if (rndm < 0.5) {
5925    goto collis152;
5926  }
5927  is1 = 1;
5928  is2 = 1;
5929  ip = -2;
5930  debugOutput = am(p1,p2,p3,e1);
5931  goto exitRoutine;
5932
5933 collis152: 
5934  is1 = -1;
5935  is2 = -1;
5936  ip = 2;
5937  debugOutput = am(p1,p2,p3,e1);
5938  goto exitRoutine;
5939
5940 collis160:
5941  pout11 = -p1;
5942  pout12 = -p2;
5943  pout13 = -p3;
5944  debugOutput = am(p1,p2,p3,e1);
5945  goto exitRoutine;
5946
5947  // long-lived delta
5948 collis161:
5949  if(index != 1) {
5950    p1=xp1;
5951    p2=xp2;
5952    p3=xp3;
5953    eout1=e3;
5954    e1=ecm-eout1;
5955    m1=1;
5956  }
5957  else {
5958    p1=-xp1;
5959    p2=-xp2;
5960    p3=-xp3;
5961    eout1=e3;
5962    e1=ecm-eout1;
5963    m1=1;
5964  }
5965  debugOutput = am(p1,p2,p3,e1);
5966
5967  // symmetrization of charges in pn -> n delta
5968  // the test on "index" above symetrizes the excitation of one
5969  // of the nucleons with respect to the delta excitation
5970  // (see note 16/10/97)
5971  if (iso == 0) {
5972   if (index2 == 1) {
5973     isi = is1;
5974     is1 = is2;
5975     is2 = isi;
5976   }
5977   goto collis160;
5978  }
5979
5980  bl9->hel[bl9->l1] = std::pow(ctet,2);
5981  standardRandom(&rndm, &(hazard->igraine[7]));
5982  if (rndm < 0.25) {
5983    goto collis160;
5984  }
5985
5986  is1=3*is1*m1-(1-m1)*is1;
5987  is2=3*is2*m2-(1-m2)*is2;
5988  goto collis160;
5989
5990  // recombination process
5991 collis170: 
5992  pnorm = pcm(ecm,xm,xm);
5993  standardRandom(&rndm, &(hazard->igraine[11]));
5994  ctet = -1.0 + 2.0*rndm;
5995  if(std::fabs(ctet) > 1.0) {
5996    ctet = sign(1.0,ctet);
5997  }
5998  stet = std::sqrt(1.0 - ctet*ctet);
5999  standardRandom(&rndm, &(hazard->igraine[12]));
6000  fi = 6.2832*rndm;
6001  cfi = std::cos(fi);
6002  sfi = std::sin(fi);
6003  p1 = pnorm*stet*cfi;
6004  p2 = pnorm*stet*sfi;
6005  p3 = pnorm*ctet;
6006  m1 = 0;
6007  m2 = 0;
6008  e1 = std::sqrt(p1*p1 + p2*p2 + p3*p3 + xm*xm);
6009  eout1 = ecm - e1;
6010  debugOutput = am(p1,p2,p3,e1);
6011
6012  if (iso == 0) {
6013    goto collis160;
6014  }
6015  is1=iso/2;
6016  is2=iso/2;
6017  goto collis160;
6018 
6019 exitRoutine:
6020  debugOutput = am(p1,p2,p3,e1);
6021  (*p1_p) = p1;// Was pq
6022  (*p2_p) = p2;
6023  (*p3_p) = p3;
6024
6025  (*e1_p) = e1;
6026
6027  debugOutput = am(pout11,pout12,pout13,eout1);
6028  (*pout11_p) = pout11;
6029  (*pout12_p) = pout12;
6030  (*pout13_p) = pout13;
6031  (*eout1_p) = eout1;
6032
6033  (*q1_p) = q1;
6034  (*q2_p) = q2;
6035  (*q3_p) = q3;
6036  (*q4_p) = q4;
6037
6038  (*np_p) = np;
6039  (*ip_p) = np;
6040
6041  (*k2_p) = k2;
6042  (*k3_p) = k2;
6043  (*k4_p) = k4;
6044  (*k5_p) = k5;
6045
6046  (*m1_p) = m1;
6047  (*m2_p) = m2;
6048
6049  (*is1_p) = is1;
6050  (*is2_p) = is2;
6051}
6052
6053void G4Incl::decay2(G4double *p1_p, G4double *p2_p, G4double *p3_p, G4double *wp_p, G4double *q1_p, 
6054                    G4double *q2_p, G4double *q3_p, G4double *wq_p, G4double *xi_p, G4double *x1_p, G4double *x2_p, 
6055                    G4double *hel_p)
6056{           
6057  // This routine describes the anisotropic decay of a particle of mass
6058  // xi into 2 particles of masses x1,x2                             
6059  // the anisotropy is supposed to follow a 1+3*hel*(std::cos(theta))**2
6060  // law with respect to the direction of the incoming particle
6061  // in the input, p1,p2,p3 is the momentum of particle xi
6062  // in the output, p1,p2,p3 is the momentum of particle x1 , while
6063  // q1,q2,q3 is the momentum of particle x2
6064
6065  // Temporary variables for input/output data:
6066
6067  G4double p1 = (*p1_p);
6068  G4double p2 = (*p2_p);
6069  G4double p3 = (*p3_p);
6070
6071  G4double q1 = (*q1_p);
6072  G4double q2 = (*q2_p);
6073  G4double q3 = (*q3_p);
6074
6075  G4double wp = (*wp_p);
6076  G4double wq = (*wq_p);
6077
6078  G4double xi = (*xi_p);
6079  G4double x1 = (*x1_p);
6080  G4double x2 = (*x2_p);
6081  G4double hel = (*hel_p);
6082
6083  G4double rndm = 0.0;
6084
6085  G4double xe = wp;
6086  G4double b1 = p1/xe;
6087  G4double b2 = p2/xe;
6088  G4double b3 = p3/xe;                                                         
6089  // PK: NaN workaround
6090  // if(((std::pow(xi,2)-std::pow(x1+x2,2))*(std::pow(xi,2)-std::pow(x1-x2,2))) < 0) {
6091  //   xi = xi+x2+100.0;
6092  // }
6093  // PK
6094  G4double xq = pcm(xi,x1,x2);                                                 
6095  G4double ctet = 0.0, stet = 0.0;
6096
6097  G4double fi = 0.0, cfi = 0.0, sfi = 0.0;
6098  G4double sal = 0.0, cal = 0.0;
6099  G4double t1 = 0.0, t2 = 0.0;
6100  G4double w1 = 0.0;
6101  G4double beta = 0.0;
6102
6103  if(verboseLevel > 3) {
6104    G4cout <<"Delta decay in progress: " << G4endl;
6105    G4cout <<"Starting values: " << G4endl;
6106    G4cout <<"p1 = " << p1 << " p2 = " << p2 << " p3 = " << p3 << " wp = " << wp << G4endl;
6107    G4cout <<"q1 = " << q1 << " q2 = " << q2 << " q3 = " << q3 << " wq = " << wq << G4endl;
6108  }
6109
6110  do {
6111    standardRandom(&rndm, &(hazard->igraine[7]));
6112    ctet = -1.0 + 2.0*rndm;
6113    if(std::fabs(ctet) > 1.0) {
6114      ctet = sign(1.0,ctet);
6115    }
6116    stet = std::sqrt(1.0 - std::pow(ctet,2));
6117    standardRandom(&rndm, &(hazard->igraine[9]));
6118  } while(rndm > ((1.0 + 3.0*hel*std::pow(ctet,2))/(1.0 + 3.0*hel)));
6119 
6120  standardRandom(&rndm, &(hazard->igraine[8]));
6121  fi = 6.2832*rndm;
6122  cfi = std::cos(fi);
6123  sfi = std::sin(fi);
6124  beta = std::sqrt(b1*b1+b2*b2+b3*b3);
6125
6126  sal = std::sqrt(std::pow(b1,2) + std::pow(b2,2))/beta;
6127  cal = b3/beta;
6128
6129  if((beta >= 1.0e-10) || (sal >= 1.0e-6)) {
6130    t1 = ctet + cal*stet*sfi/sal;
6131    t2 = stet/sal;                                                       
6132    q1 = xq*(b1*t1 + b2*t2*cfi)/beta;
6133    q2 = xq*(b2*t1 - b1*t2*cfi)/beta;
6134    q3 = xq*(b3*t1/beta - t2*sfi);
6135  }
6136  else {
6137    q1 = xq*stet*cfi;                                                   
6138    q2 = xq*stet*sfi;                                                   
6139    q3 = xq*ctet;
6140  }
6141 
6142  hel = 0.0;                                                       
6143  w1 = q1*q1 + q2*q2 + q3*q3;
6144  wq = std::sqrt(w1 + x2*x2);
6145  p1 = -q1;
6146  p2 = -q2;
6147  p3 = -q3;
6148  wp = std::sqrt(w1+x1*x1);
6149  loren(&q1, &q2, &q3, &b1, &b2, &b3, &wq);
6150  loren(&p1, &p2, &p3, &b1, &b2, &b3, &wp);
6151
6152  // Return calculated values:
6153  (*p1_p) = p1;
6154  (*p2_p) = p2;
6155  (*p3_p) = p3;
6156
6157  (*q1_p) = q1;
6158  (*q2_p) = q2;
6159  (*q3_p) = q3;
6160
6161  (*wp_p) = wp;
6162  (*wq_p) = wq;
6163
6164  (*xi_p) = xi;
6165  (*x1_p) = x1;
6166  (*x2_p) = x2;
6167  (*hel_p) = hel;
6168}
6169
6170void G4Incl::time(G4int i, G4int j)
6171{
6172  // time
6173  G4double t[10] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
6174
6175  t[0] = bl1->p1[i]/bl1->eps[i] - bl1->p1[j]/bl1->eps[j]; // t(1)->t[0]
6176  t[1] = bl1->p2[i]/bl1->eps[i] - bl1->p2[j]/bl1->eps[j]; // t(2)->t[1] and so on ...
6177  t[2] = bl1->p3[i]/bl1->eps[i] - bl1->p3[j]/bl1->eps[j]; 
6178  t[3] = bl3->x1[i] - bl3->x1[j];
6179  t[4] = bl3->x2[i] - bl3->x2[j];
6180  t[5] = bl3->x3[i] - bl3->x3[j];
6181
6182  t[6] = t[0]*t[3] + t[1]*t[4] + t[2]*t[5];
6183  t[9] = t[0]*t[0] + t[1]*t[1] + t[2]*t[2];
6184
6185  if(t[9] <= 1.0e-10) {
6186    bl1->ta = 100000;
6187  }
6188  else {       
6189    bl1->ta = -1.0*t[6]/t[9];
6190  }
6191
6192  bl3->rab2 = t[3]*t[3] + t[4]*t[4] + t[5]*t[5] + bl1->ta*t[6];
6193}
6194
6195void G4Incl::newt(G4int l1, G4int l2)
6196{
6197  G4int ig = 0, id = 0, kg = 0, kd = 0;
6198  G4int iy = 0, ix = 0;
6199  G4double E = 0.0;
6200
6201  G4int ia = bl3->ia1 + bl3->ia2;
6202  for(G4int i = 1; i <= ia; i++) { // do 52 i=1,ia
6203    if (bl5->nesc[i] != 0) {
6204      continue;
6205    }
6206    //    if (i-l2) 53,52,54
6207    if((i-l2) < 0) {
6208      goto newt53;
6209    }
6210    if((i-l2) == 0) {
6211      continue;
6212    }
6213    if((i-l2) > 0) {
6214      goto newt54;
6215    }
6216  newt53: 
6217    ig=l2;
6218    id=i;
6219    kg=l1;
6220    kd=i;
6221    goto newt55;
6222  newt54:
6223    //      if (i-l1) 56,52,57
6224    if((i-l1) == 0) {
6225      continue;
6226    }
6227    if((i-l1) < 0) {
6228      goto newt56;
6229    }
6230    if((i-l1) > 0) {
6231      goto newt57;
6232    }
6233  newt56:
6234    kg=l1;
6235    kd=i; 
6236    goto newt58;
6237  newt57:
6238    kg=i;
6239    kd=l1;
6240  newt58:
6241    ig=i;
6242    id=l2;
6243  newt55:
6244    //  call time(ig,id)
6245    time(ig, id);
6246    if (bl1->ta < 0.0) {
6247      goto newt50;
6248    }
6249    if(bl1->ta > bl4->tmax5) {
6250      goto newt50;
6251    }
6252    if (bl1->ta < bl5->tlg[l1]) { // tlg(12)->tlg[11]
6253      goto newt50;
6254    }
6255    if ((bl1->ind1[ig]+bl1->ind1[id]) > 0) {
6256      goto newt60;
6257    }
6258
6259    E=am(bl1->p1[ig]+bl1->p1[id],bl1->p2[ig]+bl1->p2[id],bl1->p3[ig]+bl1->p3[id],bl1->eps[ig]+bl1->eps[id]);
6260    if (E < 1925.0) {
6261      goto newt50;
6262    }
6263    iy=bl1->ind1[ig]+bl1->ind1[id];
6264    if (iy != 1) {
6265      goto newt61;
6266    }
6267    ix=ig*(bl1->ind1[ig])+id*(bl1->ind1[id]);
6268    bl6->xx10=am(bl1->p1[ix],bl1->p2[ix],bl1->p3[ix],bl1->eps[ix]);
6269    bl6->isa=bl1->ind2[ix];
6270  newt61:
6271    if ((31.*(bl3->rab2)) > totalCrossSection(E,iy,bl1->ind2[ig]+bl1->ind2[id])) {
6272      goto newt50;
6273    }
6274  newt60: // continue
6275    bl2->k=bl2->k+1;
6276    bl2->crois[bl2->k]=bl1->ta;
6277    bl2->ind[bl2->k]=ig;
6278    bl2->jnd[bl2->k]=id;
6279  newt50:
6280    time(kg,kd);
6281    if (bl1->ta < 0.) {
6282      continue;
6283    }
6284    if(bl1->ta > bl4->tmax5) {
6285      continue;
6286    }
6287    if (bl1->ta < bl5->tlg[10]) { //tlg(11)->tlg[10]
6288      continue;
6289    }
6290    if ((bl1->ind1[kg]+bl1->ind1[kd]) > 0) {
6291      goto newt62;
6292    }
6293    E=am(bl1->p1[kg]+bl1->p1[kd],bl1->p2[kg]+bl1->p2[kd],bl1->p3[kg]+bl1->p3[kd],bl1->eps[kg]+bl1->eps[kd]);
6294    if (E < 1925.) {
6295      continue;
6296    }
6297    iy=bl1->ind1[kg]+bl1->ind1[kd];
6298    if (iy != 1) {
6299      goto newt63;
6300    }
6301    ix=kg*(bl1->ind1[kg])+kd*(bl1->ind1[kd]);
6302    bl6->xx10=am(bl1->p1[ix],bl1->p2[ix],bl1->p3[ix],bl1->eps[ix]);
6303    bl6->isa=bl1->ind2[ix];
6304  newt63: 
6305    if ((31.*(bl3->rab2)) > totalCrossSection(E,iy,bl1->ind2[kg]+bl1->ind2[kd])) {
6306      continue;
6307    }
6308  newt62:
6309    bl2->k=bl2->k+1;
6310    bl2->crois[bl2->k]=bl1->ta;
6311    bl2->ind[bl2->k]=kg;
6312    bl2->jnd[bl2->k]=kd;
6313  }
6314}
6315
6316void G4Incl::new1(G4int l1)
6317{
6318  G4int ia = 0, iy = 0, ix = 0;
6319  G4double E = 0.0;
6320
6321  ia=bl3->ia1+bl3->ia2;
6322  for(G4int i = 1; i <= ia; i++) {
6323    if (bl5->nesc[i] != 0) {
6324      continue;
6325    }
6326    //if(i-l1) 53,52,54
6327    if((i-l1) < 0) {
6328      goto new153;
6329    }
6330    if((i-l1) == 0) {
6331      continue;
6332    }
6333    if((i-l1) > 0) {
6334      goto new154;
6335    }
6336  new153: 
6337    time(i, l1);
6338    if(bl1->ta < 0.0) {
6339      continue;
6340    }
6341    if(bl1->ta > bl4->tmax5) {
6342      continue;
6343    }
6344    if (bl1->ind1[i]+bl1->ind1[l1] > 0) {
6345      goto new160;
6346    }
6347    E=am(bl1->p1[i]+bl1->p1[l1],bl1->p2[i]+bl1->p2[l1],bl1->p3[i]+bl1->p3[l1],bl1->eps[i]+bl1->eps[l1]);
6348    if (E < 1925.0) {
6349      continue;
6350    }
6351    iy=bl1->ind1[i]+bl1->ind1[l1];
6352    if (iy != 1) {
6353      goto new161;
6354    }
6355    ix=i*(bl1->ind1[i])+l1*(bl1->ind1[l1]);
6356    bl6->xx10=am(bl1->p1[ix],bl1->p2[ix],bl1->p3[ix],bl1->eps[ix]);
6357    bl6->isa=bl1->ind2[ix];
6358  new161: 
6359    if ((31.*(bl3->rab2)) > totalCrossSection(E ,iy,bl1->ind2[i]+bl1->ind2[l1])) {
6360      continue;
6361    }
6362  new160: //continue
6363    bl2->k=bl2->k+1;
6364    bl2->crois[bl2->k]=bl1->ta;
6365    bl2->ind[bl2->k]=l1;
6366    bl2->jnd[bl2->k]=i;
6367    continue;
6368  new154:
6369    time(i, l1);
6370    if(bl1->ta < 0.) {
6371      continue;
6372    }
6373    if(bl1->ta > bl4->tmax5) {
6374      continue;
6375    }
6376    if ((bl1->ind1[i]+bl1->ind1[l1]) > 0) {
6377      goto new170;
6378    }
6379    E=am(bl1->p1[i]+bl1->p1[l1],bl1->p2[i]+bl1->p2[l1],bl1->p3[i]+bl1->p3[l1],bl1->eps[i]+bl1->eps[l1]);
6380    if (E < 1925.0) {
6381      continue;
6382    }
6383    iy=bl1->ind1[i]+bl1->ind1[l1];
6384    if (iy != 1) {
6385      goto new171;
6386    }
6387    ix=i*(bl1->ind1[i])+l1*(bl1->ind1[l1]);
6388    bl6->xx10=am(bl1->p1[ix],bl1->p2[ix],bl1->p3[ix],bl1->eps[ix]);
6389    bl6->isa=bl1->ind2[ix];
6390  new171: 
6391    if ((31.0*(bl3->rab2)) > totalCrossSection(E,iy,bl1->ind2[i]+bl1->ind2[l1])) {
6392      continue;
6393    }
6394  new170: 
6395    bl2->k=bl2->k+1;
6396    bl2->crois[bl2->k]=bl1->ta;
6397    bl2->ind[bl2->k]=i;
6398    bl2->jnd[bl2->k]=l1;
6399  }
6400  //  std::ofstream newout("new1Dump.out");
6401  //  dumpBl2(newout);
6402  //  dumpBl5(newout);
6403  //  newout.close();
6404  //  exit(0);
6405}
6406
6407void G4Incl::new2(G4double y1, G4double y2, G4double y3, G4double q1, G4double q2, G4double q3, 
6408                  G4double q4, G4int npion, G4int l1)
6409{
6410  G4double t[10] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
6411
6412  G4int ia = bl3->ia1 + bl3->ia2;
6413  for(G4int i = 1; i <= ia; i++) {
6414    if (bl5->nesc[i] != 0) {
6415      continue;
6416    }
6417    if(i == l1) {
6418      continue;
6419    }
6420    if(bl1->ind1[i] == 1) {
6421      continue;
6422    }
6423
6424    t[0] = bl1->p1[i]/bl1->eps[i] - q1/q4;
6425    t[1] = bl1->p2[i]/bl1->eps[i] - q2/q4;
6426    t[2] = bl1->p3[i]/bl1->eps[i] - q3/q4;
6427    t[3] = bl3->x1[i] - y1;
6428    t[4] = bl3->x2[i] - y2;
6429    t[5] = bl3->x3[i] - y3;
6430    t[6] = t[0]*t[3] + t[1]*t[4] + t[2]*t[5];
6431
6432    if(t[6] > 0.0) {
6433      continue;
6434    }
6435
6436    t[9] = t[0]*t[0] + t[1]*t[1] + t[2]*t[2];
6437    bl1->ta = -1 * t[6]/t[9];
6438    if(bl1->ta > bl4->tmax5) {
6439      continue;
6440    }
6441    G4double xx2 = t[3]*t[3] + t[4]*t[4] + t[5]*t[5] + (bl1->ta)*t[6];
6442    G4double E = std::sqrt(std::pow((bl1->eps[i]+q4),2) - std::pow((bl1->p1[i]+q1),2) - std::pow((bl1->p2[i]+q2),2) - std::pow((bl1->p3[i]+q3),2));
6443    if ((31.0*xx2) > pionNucleonCrossSection(E)) {
6444      continue;
6445    }
6446    bl2->k=bl2->k+1;
6447    bl2->crois[bl2->k]=bl1->ta;
6448    bl2->ind[bl2->k]=ia+npion;
6449    bl2->jnd[bl2->k]=i;
6450  }
6451}
6452
6453void G4Incl::new3(G4double y1, G4double y2, G4double y3, G4double q1, G4double q2, G4double q3, 
6454                  G4double q4, G4int npion, G4int l1)
6455{
6456  G4double t[10] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
6457  G4double E = 0.0, xx2 = 0.0;
6458  G4int ia = 0;
6459
6460  if(bl5->nesc[l1] > 0) {
6461    return;
6462  }
6463
6464  t[0] = bl1->p1[l1]/bl1->eps[l1] - q1/q4;
6465  t[1] = bl1->p2[l1]/bl1->eps[l1] - q2/q4;
6466  t[2] = bl1->p3[l1]/bl1->eps[l1] - q3/q4;
6467  t[3] = bl3->x1[l1] - y1;
6468  t[4] = bl3->x2[l1] - y2;
6469  t[5] = bl3->x3[l1] - y3;
6470  t[6] = t[0]*t[3] + t[1]*t[4] + t[2]*t[5];
6471
6472  if(t[6] > 0.0) {
6473    return;
6474  }
6475
6476  t[9] = t[0]*t[0] + t[1]*t[1] + t[2]*t[2];
6477  bl1->ta = -1 * t[6]/t[9];
6478  if(bl1->ta > bl4->tmax5) {
6479    return;
6480  }
6481  if (bl1->ta < bl5->tlg[l1]) {
6482    return;
6483  }
6484  xx2 = t[3]*t[3] + t[4]*t[4] + t[5]*t[5] + (bl1->ta)*t[6];
6485  E = std::sqrt(std::pow((bl1->eps[l1]+q4),2) - std::pow((bl1->p1[l1]+q1),2) - std::pow((bl1->p2[l1]+q2),2) - std::pow((bl1->p3[l1]+q3),2));
6486  if ((31.0*xx2) > pionNucleonCrossSection(E)) {
6487    return;
6488  }
6489 
6490  bl2->k = bl2->k + 1;
6491  bl2->crois[bl2->k] = bl1->ta;
6492  ia = bl3->ia1+bl3->ia2;
6493  bl2->ind[bl2->k] = ia + npion;
6494  bl2->jnd[bl2->k] = l1;
6495}
6496
6497void G4Incl::loren(G4double *q1, G4double *q2, G4double *q3, G4double *b1, G4double *b2, G4double *b3, G4double *E)
6498{
6499  // Transforms momentum q and energy E from a frame moving with
6500  // velocity beta
6501
6502  G4double bb2 = (*b1) * (*b1) + (*b2) * (*b2) + (*b3) * (*b3);
6503  G4double bq = (*b1) * (*q1) + (*b2) * (*q2) + (*b3) * (*q3);
6504  G4double gam2 = 1.0/(1.0 - bb2);
6505  G4double gam = std::sqrt(gam2);
6506  G4double c = gam2/(gam + 1.0);
6507  G4double g = c * bq + gam*(*E);
6508  (*E) = gam * ((*E) + bq);
6509  (*q1) = (*q1) + (*b1) * g;
6510  (*q2) = (*q2) + (*b2) * g; 
6511  (*q3) = (*q3) + (*b3) * g;
6512}
6513
6514G4double G4Incl::pauliBlocking(G4int l, G4double xr, G4double pr)
6515{
6516  //   G4int l = (*l_p);
6517  //   G4double xr = (*xr_p);
6518  //   G4double pr = (*pr_p);
6519  //   G4double f = (*f_p);
6520
6521  // This subroutine calculates the occupation in phase space around
6522  // nucleon l , by counting the particles in a volume around l the
6523  // volume is the product of a sphere of radius xr in r-space by a
6524  // sphere of radius pr in momentum space average is taken on the spin
6525  // only
6526
6527  //   3756           common/bl1/p1(300),p2(300),p3(300),eps(300),ind1(300),ind2(300),tap-n24950
6528  //   3757           common/bl3/r1,r2,x1(300),x2(300),x3(300),ia1,ia2,rab2             p-n24960
6529  //   3758           common/bl5/tlg(300),nesc(300)                                     p-n24970
6530  //   3759           common/saxw/ xx(30,500),yy(30,500),ss(30,500),nbpG4inter,imat
6531  //   3760           common/ws/r0,adif,rmaxws,drws,nosurf,xfoisa,npaulstr,bmax
6532
6533  G4double pmod = 0.0, pr2 = 0.0;
6534  G4double xr2 = 0.0, rdeq = 0.0, dx2 = 0.0, dp2 = 0.0;
6535  G4double rs = 0.0, vol = 0.0;
6536  G4int nl = 0;
6537  G4int ia = 0;
6538
6539  if (ws->npaulstr == 2) {
6540    return 0.0;
6541  }
6542
6543  if (ws->npaulstr == 1) {
6544    // pauli strict
6545    pmod = std::sqrt(std::pow(bl1->p1[l],2) + std::pow(bl1->p2[l],2) + std::pow(bl1->p3[l],2));
6546    if (pmod < 270.0) {
6547      return 1.0;
6548    } else {
6549      return 0.0;
6550    }
6551  } else {
6552    // Statistic Pauli blocking
6553    xr2 = xr*xr;
6554    pr2 = pr*pr;
6555    vol = std::pow((40.0*3.1415926/3.0),2) * (std::pow((xr*pr)/(2.0*3.1415926*197.13),3));
6556    rs = std::sqrt(bl3->x1[l]*bl3->x1[l] + bl3->x2[l]*bl3->x2[l] + bl3->x3[l]*bl3->x3[l]);
6557    if (ws->nosurf <= 0) {
6558      // modifs a.b.: r2 -> rmaxws pour la densite en w.s.
6559      rdeq = ws->rmaxws;
6560    } else {
6561      rdeq = ws->r0;
6562    }
6563
6564    if ((rs - xr) <= rdeq) {
6565      if ((rs + xr) > rdeq) {
6566        vol = vol*0.5*(rdeq-rs+xr)/xr;
6567      }
6568
6569      ia = bl3->ia1 + bl3->ia2;
6570      nl = 0;
6571
6572      for(G4int i = 1; i <= ia; i++) {
6573        dx2 = std::pow((bl3->x1[l]-bl3->x1[i]),2) + std::pow((bl3->x2[l]-bl3->x2[i]),2) + std::pow((bl3->x3[l]-bl3->x3[i]),2);
6574        dp2 = std::pow((bl1->p1[l]-bl1->p1[i]),2) + std::pow((bl1->p2[l]-bl1->p2[i]),2) + std::pow((bl1->p3[l]-bl1->p3[i]),2);
6575     
6576        if((bl5->nesc[i] > 0) || (bl1->ind1[i] > 0) || (bl1->ind2[i] != bl1->ind2[l]) || (dx2 > xr2) || (dp2 > pr2)) {
6577          if(((nl - 1)/vol/2.0) > 1.0) {
6578            return 1.0;
6579          } else {
6580            return ((nl - 1)/vol/2.0);
6581          }
6582        }
6583        nl = nl + 1;
6584      }
6585    } else {
6586      return 0.0;
6587    }
6588  }
6589
6590  return 0.0; // The algorithm is not supposed to reach this point.
6591}
6592
6593G4double G4Incl::lowEnergy(G4double E, G4double m, G4double i)
6594{
6595  // fit by j.vandermeulen
6596  // low enrgy fit of j.c., d. l'hote, j. vdm, nim b111(1996)215
6597  // i = 2,0,-2  for pp,pn,nn
6598  // m = 0,1,2 for nucleon-nucleon,nucleon-delta,delta,delta
6599
6600  G4double scale = 1.0;
6601  G4double plab = E*std::sqrt(E*E-3.52e6)/1876.6;
6602  G4double p1 = 0.001*plab;
6603  G4double alp = 0.0;
6604
6605  if(plab > 2000.0) {
6606    // goto sel13;
6607    // sel13:
6608    return ((77.0/(p1 + 1.5))*scale);
6609  }
6610
6611  if((m-1) < 0) {
6612    if (i == 0) {
6613      if (plab < 800.0) {
6614        if (plab < 450.0) {
6615          alp = std::log(p1);
6616          return(6.3555*std::exp(-3.2481*alp - 0.377*alp*alp));
6617        }
6618        else {
6619          return((33.0 + 196.0*std::sqrt(std::fabs(std::pow((p1 - 0.95),5))))*scale);
6620        }
6621      }
6622      else {
6623        return(31.0/std::sqrt(p1)*scale);
6624      }
6625    }
6626  }
6627
6628  if (plab < 800.0) {
6629    if (plab < 440.0) {
6630      return(34.0*std::pow((p1/0.4),(-2.104)));
6631    }
6632    else {
6633      return((23.5 + 1000.*std::pow((p1 - 0.7),4))*scale);
6634    }
6635  }
6636  else if(plab > 2000.0) {
6637    return ((77.0/(p1 + 1.5))*scale);
6638  }
6639  else {
6640    return((1250.0/(50.0 + p1) - 4.0*std::pow((p1 - 1.3),2))*scale);
6641  }
6642}
6643
6644G4double G4Incl::totalCrossSection(G4double E, G4int m, G4int i)
6645{
6646  // total cross-sections
6647  // i=2,0,-2  for pp,pn,nn
6648  // m=0,1,2 for nucleon-nucleon,nucleon-delta,delta,delta
6649
6650  G4double stotResult = 0.0;
6651  G4double sine = 0.0;
6652
6653  if((m-1) < 0) {
6654    sine = deltaProductionCrossSection(E,int(i));
6655  }
6656
6657  if((m-1) == 0) {
6658    sine = srec(E,(bl6->xx10),i,int(bl6->isa));
6659  }
6660
6661  if((m-1) > 0) {
6662    sine = 0.0;
6663  }
6664
6665  stotResult = sine + lowEnergy(E,m,i);
6666  return stotResult;
6667}
6668
6669G4double G4Incl::srec(G4double Ein, G4double d, G4int i, G4int isa)
6670{
6671  G4double E = Ein;
6672  G4double s = 0.0;
6673  G4double x = 0.0, y = 0.0;
6674  G4double srecResult = 0.0;
6675
6676  if (i*i == 16) {
6677    return 0.0;
6678  }
6679
6680  if(E <= (938.3 + d)) {
6681    return 0.0;
6682  } else {
6683    if(E < (938.3 + d + 2.0)) {
6684      E = 938.3 + d + 2.0;
6685    }
6686    s = E*E;
6687    x = (s - 3.523e6)/(s - std::pow((938.3 + d),2));
6688    y = s/(s - std::pow((d - 938.3),2));
6689    srecResult = 0.5*x*y*deltaProductionCrossSection(E, i);
6690    srecResult = srecResult*(32.0 + i*i*(isa*isa - 5))/64.0;
6691    srecResult = srecResult/(1.0 + 0.25*i*i);
6692    srecResult = 3.0*srecResult;  //pi absorption increased also for internal pions (7/3/01)
6693
6694    return srecResult;
6695  }
6696}
6697
6698G4double G4Incl::deltaProductionCrossSection(G4double E, G4int i)
6699{
6700  // delta production cross-sections
6701  // fit by j.vandermeulen
6702  // i = 2,0,-2  for pp,pn,nn
6703
6704//   G4double scali = 1.0;
6705//   G4double plab;
6706//   G4double p1;
6707//   G4double sproResult;
6708
6709//   G4double EE = E - bl8->rathr;
6710
6711//   if(EE*EE-3.53e6 < 0) {
6712//     return 0.0;
6713//   }
6714//   else {
6715//     plab = EE*std::sqrt(EE*EE-3.52e6)/1876.6;
6716//     p1 = 0.001*plab;
6717//     if (plab > 800.0) {
6718//       //goto spro1;
6719//       //  spro1:
6720//       if (i*i == 4) {
6721//      //      goto spro10;
6722//      //spro10:
6723//      if (plab < 2000.0) {
6724//        //    goto spro11;
6725//        //  spro11:
6726//        if (plab < 1500.0) {
6727//          //      goto spro12;
6728//          // spro12:
6729//          sproResult = 23.5 + 24.6/(1.0 + std::exp(-10.0*p1 + 12.0)) - 1250.0/(p1+50.0)+4.0*std::pow((p1-1.3),2);
6730//          return (sproResult*scali);
6731//        }
6732//        else {
6733//          sproResult = 41.0 + 60.0*(p1 - 0.9)*std::exp(-1.2*p1) - 1250.0/(p1+50.0) + 4.*std::pow((p1 - 1.3),2);
6734//          return (sproResult*scali);
6735//        }
6736//      }
6737//      else {
6738//        return ((41.0 + (60.0*p1 - 54.0)*std::exp(-1.2*p1) - 77.0/(p1 + 1.5))*scali);
6739//      }
6740//       }
6741//       else {
6742//      if (plab < 2000.0) {
6743//        //goto spro2;
6744//        //  spro2:
6745//        if (plab < 1000.0) {
6746//          //goto spro3;
6747//          //  spro3:
6748//          return ((33.0 + 196.0*std::sqrt(std::pow(std::fabs(p1 - 0.95),5)) - 31.1/std::sqrt(p1))*scali);
6749//        }
6750//        else {
6751//          return ((24.2 + 8.9*p1 - 31.1/std::sqrt(p1))*scali);
6752//        }
6753//      }
6754//      else {
6755//        return ((42.-77./(p1+1.5))*scali);
6756//      }
6757//       }
6758//     }
6759//     // plab <= 800.0
6760//     else {
6761//       return 0.0;
6762//     }
6763//   }
6764  double scali=1.0;
6765  double plab = 0.0;
6766  double p1 = 0.0;
6767  double sproResult = 0.0;
6768
6769  double EE = E -(bl8->rathr);
6770
6771  if(EE*EE-3.53e6 < 0) {
6772    goto spro22;
6773  }
6774  plab = EE * std::sqrt(EE*EE - 3.52e6)/1876.6;
6775  p1 = 0.001*plab;
6776  if (plab > 800.) {
6777    goto spro1;
6778  }
6779  spro22:
6780  sproResult = 0.0;
6781  return sproResult;
6782
6783  spro1:
6784  if (i*i == 4) {
6785    goto spro10;
6786  }
6787  if (plab < 2000.) {
6788    goto spro2;
6789  }
6790  sproResult=(42.-77./(p1+1.5))*scali;
6791  return sproResult;
6792  spro2: if (plab < 1000.) {
6793    goto spro3;
6794  }
6795  sproResult=(24.2+8.9*p1-31.1/std::sqrt(p1))*scali;
6796  return sproResult;
6797  spro3: sproResult = (33.0 + 196.0*std::sqrt(std::pow(std::fabs(p1 - 0.95),5)) - 31.1/std::sqrt(p1))*scali;
6798  return sproResult;
6799  spro10: if (plab < 2000.) {
6800    goto spro11;
6801  }
6802  sproResult = (41.0 + (60.0*p1 - 54.0)*std::exp(-1.2*p1) - 77.0/(p1 + 1.5))*scali;
6803  return sproResult;
6804  spro11: if (plab < 1500.) {
6805    goto spro12;
6806  }
6807  sproResult = 41.0 + 60.0*(p1 - 0.9)*std::exp(-1.2*p1) - 1250.0/(p1 + 50.0)+4.0*std::pow((p1-1.3),2);
6808  sproResult = sproResult*scali;
6809  return sproResult;
6810 spro12: sproResult=23.5 + 24.6/(1.0 + std::exp(-10.0*p1 + 12.0)) - 1250.0/(p1 + 50.0) + 4.0*std::pow((p1 - 1.3),2);
6811  sproResult=sproResult*scali;
6812  return sproResult;
6813}
6814
6815G4double G4Incl::pionNucleonCrossSection(G4double x)
6816{
6817  //   sigma(pi+ + p) in the (3,3) region
6818  //   new fit by j.vandermeulen + constant value above the (3,3)
6819  //   resonance
6820
6821  G4double y = x*x;
6822  G4double q2 = (y-std::pow(1076.0,2))*(y-std::pow(800.0,2))/y/4.0;
6823  G4double q3 = 0.0, f3 = 0.0;
6824  G4double spn = 0.0;
6825
6826  if(q2 <= 0) {
6827    return 0.0;
6828  } else {
6829    q3 = std::pow((std::sqrt(q2)),3);
6830    f3 = q3/(q3+std::pow(180.0,3));
6831    spn = 326.5/(std::pow(((x - 1215.0 - bl8->ramass)*2.0/110.0),2)+1.0);
6832    spn = spn*(1.0 - 5.0 * (bl8->ramass/1215.0));
6833    return (spn*f3);
6834  }
6835}
6836
6837G4double G4Incl::transmissionProb(G4double E, G4double iz, G4double izn, G4double r, G4double v0)
6838{
6839  // transmission probability for a nucleon of kinetic energy
6840  // E on the edge of the well of depth v0 (nr approximation)
6841  // iz is the isospin of the nucleon,izn the instanteneous charge
6842  // of the nucleus and r is the target radius
6843
6844  G4double x = 0.0;
6845  G4double barr = 0.0;
6846
6847  // We need enough energy to escape from the potential well.
6848  if (E > v0) {
6849    x = std::sqrt(E*(E - v0));
6850    barr = 4.0*x/(E + E - v0 + x + x);
6851    if (iz > 0) {
6852      G4double b = izn*1.44/r;
6853      G4double px = std::sqrt((E - v0)/b);
6854     
6855      if (px < 1.0) {
6856        G4double g = izn/137.03*std::sqrt(2.0*938.3/(E - v0))*(std::acos(px) - px*std::sqrt(1.0 - px*px));
6857        if (g > 35.){
6858          barr=0.0;
6859        } else {
6860          barr = barr*std::exp(-2.0*g);
6861        }
6862        return barr;
6863      } else {
6864        return barr;
6865      }
6866    } else {
6867      return barr;
6868    }
6869  } else {
6870    return barr;
6871  }
6872}
6873
6874G4double G4Incl::ref(G4double x1, G4double x2, G4double x3, G4double p1, G4double p2, G4double p3, G4double E, G4double r2)
6875{
6876  const G4double  pf = 270.339 , pf2 = 73083.4;
6877
6878  G4double ref = 0.0;
6879  G4double t1 = 0.0, t3 = 0.0, t4 = 0.0, t5 = 0.0;
6880 
6881  G4double t2 = p1*p1 + p2*p2 + p3*p3;
6882  G4double p = std::sqrt(t2);
6883  G4double r = r2;
6884  G4double xv = 0.0;
6885  G4double s = 0.0;
6886 
6887  if (ws->nosurf <= 0) {
6888    xv = p/pf;
6889    r = interpolateFunction(xv);
6890    r = r*r;
6891    if (t2 > pf2) {
6892      r = std::pow(ws->rmaxws,2);
6893    }
6894  }
6895
6896  t4 = x1*x1 + x2*x2 + x3*x3;
6897  while(t4 > r) {
6898    s = std::sqrt(r*0.99/t4);
6899    x1 = x1*s;
6900    x2 = x2*s;
6901    x3 = x3*s;
6902    t4 = x1*x1 + x2*x2 + x3*x3;
6903  }
6904 
6905  t1 = x1*p1 + x2*p2 + x3*p3;
6906  t3 = t1/t2;
6907
6908  t5 = t3*t3 + (r - t4)/t2;   
6909  if (t5 > 0) {
6910    ref = (-t3 + std::sqrt(t5))*E;
6911    return ref;
6912  }
6913  else {
6914    ref = 10000.0;
6915    return ref;
6916  }
6917}
6918
6919// void G4Incl::forceAbsor(G4int nopart, G4double iarem, G4double izrem, G4double esrem, G4double erecrem,
6920//                      G4double alrem, G4double berem, G4double garem, G4double jrem)
6921void G4Incl::forceAbsor(G4int *nopart, G4int *iarem, G4int *izrem, G4double *esrem, G4double *erecrem,
6922                        G4double *alrem, G4double *berem, G4double *garem, G4int *jrem)
6923{ 
6924  //  4341        C------------------------------------------------------------------------------
6925  //   4342             SUBROUTINE FORCE_ABSOR(nopart,F,IAREM,IZREM,ESREM,ERECREM,
6926  //   4343            s  ALREM,BEREM,GAREM,JREM)
6927
6928  //   4346             DIMENSION F(15)
6929  //   4347             REAL*4 ia1,iz1
6930  //   4348             
6931  //   4349             COMMON/hazard/ial,IY(19)
6932  //   4350       C Dialogue with INCL for nucleus density and parameters.
6933  //   4351             COMMON/WS/R0,ADIF,RMAXWS,DRWS,NOSURF,XFOISA,NPAULSTR,BMAX
6934  //   4352       C RMS espace R, espace P, Fermi momentum and energy for light gauss nuc.     
6935  //   4353             COMMON/light_gaus_nuc/rms1t(9),pf1t(9),pfln(9),tfln(9),vnuc(9)
6936
6937  G4int itg = 0;
6938  G4double sep = 0.0;
6939  G4double iz1 = 0.0;
6940  G4double del = 0.0;
6941  G4double bmaxt = 0.0;
6942  G4double proba, proba_trans;
6943  G4double alea;
6944
6945  if((*nopart) != -1) {
6946    return;
6947  }
6948
6949  bl3->ia2 = int(std::floor(calincl->f[0] + 0.1)); // f(1) -> f[0]
6950  sep = 6.8309;
6951
6952  if(bl3->ia2 <= 4) {
6953    if(bl3->ia2 == 2) {
6954      itg = 6 - 1;
6955    }
6956    if(bl3->ia2 == 3 && calincl->f[1] == 1) {
6957      itg = 7 - 1;
6958    }
6959    if(bl3->ia2 == 3 && calincl->f[1] == 2) {
6960      itg = 8 - 1;
6961    }
6962    if(bl3->ia2 == 4) {
6963      itg = 9 - 1;
6964    }
6965    sep = light_gaus_nuc->vnuc[itg] - light_gaus_nuc->tfln[itg]; // :::BUG::: Off-by-one!!!
6966  }
6967
6968  if((calincl->f[2] >= 10.0) && (calincl->f[2] <= 100.0)) {
6969    if(calincl->f[6] == 1.0) {
6970      bl3->ia1 = int(1.0);
6971      iz1 = 1.0;
6972      G4double fmpinc = 938.2796;
6973      G4double pbeam2 = calincl->f[2]*(calincl->f[2] + 2.0*fmpinc);
6974      bmaxt = ws->bmax;
6975      proba_trans = coulombTransm(calincl->f[2],bl3->ia1,iz1,calincl->f[0],calincl->f[1]);
6976      proba = forceAbs(1,calincl->f[0],calincl->f[1],calincl->f[2],bmaxt,proba_trans);
6977     
6978      standardRandom(&alea,&(hazard->igraine[4]));
6979      if(alea > proba) {
6980        return;
6981      }
6982
6983      (*iarem) = int(calincl->f[0]) + bl3->ia1;
6984      (*izrem) = int(calincl->f[1]) + int(iz1);
6985     
6986      del = std::sqrt(std::pow(((calincl->f[0] + 1.0)*fmpinc + calincl->f[2]),2) - pbeam2);
6987     
6988      (*erecrem) = pbeam2/((calincl->f[0] + 1.0)*fmpinc+calincl->f[2] + del);
6989
6990      (*esrem) = calincl->f[2] + sep - (*erecrem);
6991
6992      (*alrem) = 0.00001;
6993      (*berem) = 0.0;
6994      (*garem) = 0.99999;
6995      (*jrem) = 0;
6996      (*nopart) = 0;
6997      return;
6998    }
6999    else if((calincl->f[6] == 2) && (calincl->f[2] >= 20.0)) {
7000      bl3->ia1 = int(1.0);
7001      iz1 = 0.0;
7002      G4double fmpinc = 938.2796;
7003      G4double pbeam2 = calincl->f[2]*(calincl->f[2] + 2.0*fmpinc);
7004      bmaxt = ws->bmax;
7005      proba_trans = coulombTransm(calincl->f[2],bl3->ia1,iz1,calincl->f[0],calincl->f[1]);
7006      proba = forceAbs(1,calincl->f[0],calincl->f[1],calincl->f[2],bmaxt,proba_trans);
7007     
7008      standardRandom(&alea,&(hazard->igraine[4]));
7009      if(alea > proba) {
7010        return;
7011      }
7012
7013      (*iarem) = int(calincl->f[0]) + bl3->ia1;
7014      (*izrem) = int(calincl->f[1]) + int(iz1);
7015     
7016      del = std::sqrt(std::pow(((calincl->f[0]+1.)*fmpinc+calincl->f[2]),2)-pbeam2);
7017     
7018      (*erecrem) = pbeam2/((calincl->f[0] + 1.0)*fmpinc + calincl->f[2] + del);
7019
7020      (*esrem) = calincl->f[2] + sep - (*erecrem);
7021
7022      (*alrem) = 0.00001;
7023      (*berem) = 0.0;
7024      (*garem) = 0.99999;
7025      (*jrem) = 0;
7026      (*nopart) = 0;
7027      return;
7028    }
7029  } //      end if
7030}
7031
7032G4double G4Incl::forceAbs(G4double iprojo, G4double at, G4double zt, G4double ep, G4double bmax, G4double pt)
7033{
7034  // Results of xabs2 and sig_reac
7035  G4double sig_exp, sig_incl;
7036  G4double proba;
7037 
7038  G4double ap,zp,A,Z,E; 
7039  A=at;
7040  Z=zt;
7041  E=ep;
7042  double sig_g = 31.41592654*bmax*bmax;
7043  if(iprojo == 1) {
7044    ap = 1.0;
7045    zp = 1.0;
7046  }
7047  else {
7048    ap=1.0;
7049    zp=0.0;
7050  }
7051
7052  sig_exp = xabs2(zp, ap, zt, at, ep);
7053  sig_incl = crossSection(int(iprojo), ep, at);
7054 
7055  proba = (sig_exp-pt*sig_incl)/(pt*(sig_g - sig_incl));
7056  if(proba <= 0.0) {
7057    proba = 0.0;
7058  }
7059  if(proba > 1.0) {
7060    proba = 1.0;
7061  }
7062
7063  return proba;
7064}
7065
7066G4double G4Incl::xabs2(G4double zp, G4double ap, G4double zt, G4double at, G4double ep)
7067{                                         
7068  G4double sig = 0.0;
7069 
7070  G4double Const, xzt, xat, Const1 = 0.0, t1, gcm, bcm, plab, ecmp, ecmt, rela, ecm, rm, bigr, bigb;
7071  G4double xm, x1, sl, phst, ce, term1, delta, beta, twxsec;
7072  G4double xsec;
7073
7074  const G4double dp0 = 0.e0, dp1 = 1.e0, dp2 = 2.e0, dp3 = 3.e0, dph = 0.5e0;
7075  const G4double dp10 = 1.e1, dpth = dp1/dp3, dppi = 3.1415926535898;
7076
7077  // absoprption xsec revised version rkt-97/5 neutron data from
7078  // barashenkov this gives absorption xsec for given zp,ap,zt,at,e
7079  // (mev/nucleon) arguement changed to mev; then e=ep/ap mev/nucleon
7080  // can be used for neutrons also.  this has coulomb as ours
7081
7082  G4double E = ep/ap;
7083
7084  //   nucleon-nucleon inelastc xsec not included here                       
7085  if ((nint(ap*at) == 1) || (nint(zp+zt) == 1)) {                   
7086    return dp0;
7087  }
7088  G4double rp = radius(ap);                                                     
7089  G4double rt = radius(at);                                                     
7090  G4double vp = (dp1 + dpth)*dppi*std::pow(rp,3);                                         
7091  G4double vt = (dp1 + dpth)*dppi*std::pow(rt,3);                                         
7092  G4double density = dph*((ap/vp) + (at/vt));                                     
7093  Const=1.75e0*density/8.824728e-02;                                 
7094
7095  if ((zt < zp) || ((zt == zp) && (at < ap))) {
7096    xzt = zp;                                                         
7097    xat = ap;                                                         
7098    zp = zt;                                                           
7099    ap = at;                                                           
7100    zt = xzt;                                                         
7101    at = xat;                                                         
7102  }
7103
7104  if (nint(ap) == 1) {
7105    Const=2.05;
7106  }                                   
7107  if ((nint(zp) == 2) && (nint(ap) == 4)) {
7108    Const1 = 2.77 - at*8.0e-03 + (at*at)*1.8e-05;                         
7109  }
7110  if (nint(zp) == 3) {
7111    Const=Const/3.0;
7112  }                                 
7113  t1=40.0;                                                         
7114  if (nint(zp) == 0) {
7115    if ((nint(at) >= 11) && (nint(at) < 40)) {
7116      t1=30.0;                 
7117    }
7118    if (nint(zt) == 14) {
7119      t1=35.0;
7120    }                                     
7121    if (nint(zt) == 26) {
7122      t1=30.0;
7123    }                                     
7124  }
7125
7126  gcm = (ap*(dp1 + E/938.0) + at)/(std::pow((std::pow(ap,2) + std::pow(at,2) + dp2*ap*(E + 938.0)*at/938.e0),dph));
7127  bcm = std::sqrt(dp1-dp1/(std::pow(gcm,2)));
7128 
7129  plab = ap*std::sqrt(dp2*938.0*E + E*E);                                   
7130  ecmp = gcm*(E+938.0)*ap - bcm*gcm*plab - ap*938.0;                     
7131  ecmt = gcm*938.0*at - at*938.0;
7132  rela = ecmp + ecmt;                                                   
7133  ecm = rela;                                                         
7134  if (ecm < (0.1*rela)) {
7135    ecm = 0.1*rela;
7136  }                             
7137  rm = (197.32/137.01)*zp*zt/ecm;                                     
7138  bigr = rp + rt + 1.2*(std::pow(ap,dpth) + std::pow(at,dpth))/(std::pow(ecm,dpth));                   
7139
7140  bigb = 1.44*zp*zt/bigr;                                             
7141 
7142  if ((nint(zp) == 1) && (nint(at) > 56)) {
7143    bigb = 0.90*bigb;
7144  }             
7145  if ((nint(ap) > 56) && (nint(zt) == 1)) {
7146    bigb = 0.90*bigb;
7147  }             
7148  if ((nint(ap) == 1) && (nint(at) == 12)) {
7149    bigb = 3.5*bigb;
7150  }               
7151  if (nint(ap) == 1) {
7152    if ((nint(at) <= 16) && (nint(at) >= 13)) {
7153      bigb = (at/7.)*bigb;                                             
7154    }
7155    if (nint(zt) == 12) {
7156      bigb = 1.8*bigb;
7157    }                               
7158    if (nint(zt) == 14) {
7159      bigb = 1.4*bigb;
7160    }                               
7161    if (nint(zt) == 20) {
7162      bigb = 1.3*bigb;
7163    }                               
7164  }
7165  if ((nint(ap) == 1) && (nint(at) < 4)) {
7166    bigb = 21.0*bigb;
7167  }               
7168  if ((nint(ap) < 4) && (nint(at) == 1)) {
7169    bigb = 21.0*bigb;
7170  }               
7171  if ((nint(ap) == 1) && (nint(at) == 4)) {
7172    bigb = 27.0*bigb;
7173  }               
7174  if ((nint(ap) == 4) && (nint(at) == 1)) {
7175    bigb = 27.0*bigb;
7176  }               
7177  if ((nint(zp) == 0) || (nint(zt) == 0)) {
7178    bigb = dp0;
7179  }                         
7180  xsec = dp10*dppi*bigr*bigr*(dp1-bigb/ecm);                                           
7181  xm=1.0;                                                             
7182  if (nint(zp) == 0) {
7183    if (nint(at) < 200) {
7184      x1 = 2.83 - 3.1e-02*at + 1.7e-04*at*at;                             
7185      if (x1 <= 1) {
7186        x1=1.0;
7187      }                                           
7188      sl=dp1;                                                       
7189      if (nint(at) == 12) {
7190        sl=1.6;
7191      }                                   
7192      if (nint(at) < 12) {
7193        sl=0.6;
7194      }                                   
7195      xm = (1 - x1*std::exp(-E/(sl*x1)));                                     
7196      if (E < 20) {
7197        //      cout <<"e,xm= " << e << " " << xm << endl;
7198      }
7199    }                           
7200    else {                                                           
7201      xm = (1-0.3*std::exp(-(E-1)/15))*(1 - std::exp(-(E-0.9)));
7202    }
7203  }
7204  if ((nint(zp) == 2) && (nint(ap) == 4)) {
7205    Const = Const1 - 0.8/(1 + std::exp((250.0-E)/75.0));                     
7206  }
7207  if ((nint(zp) == 1) && (nint(ap) == 1)) {
7208    if (nint(at) > 45) {
7209      t1 = 40.0 + at/dp3;                                               
7210    }
7211    if (nint(at) < 4) {
7212      t1 = 55;                                                         
7213    }
7214    Const = 2.05 - 0.05/(1 + std::exp((250.0-E)/75.0));                     
7215    if (nint(at) < 4) {
7216      Const = 1.7;
7217    }                                   
7218    if (nint(zt) == 12) {
7219      t1=40.0;                                                     
7220      Const=2.05 - dp3/(1.0 + safeExp((E - 20.0)/dp10));                   
7221    }
7222    if (nint(zt) == 14) {
7223      t1 = 40.0;                                                     
7224      Const = 2.05 - 1.75/(1.0 + safeExp((E - 20.0)/dp10));                 
7225    }                                   
7226    if (nint(zt) == 18) {
7227      t1 = 40.0;                                                     
7228      Const = 2.05 - dp2/(1.0 + safeExp((E - 20.0)/dp10));                   
7229    }                 
7230    if (nint(zt) == 20) {
7231      t1 = 40.0;                                                     
7232      Const = 2.05 - dp1/(1.0 + safeExp((E - 40.0)/dp10));                   
7233      Const = Const - 0.25/(1 + std::exp((250.0 - E)/75.0));                 
7234    }
7235    if (nint(zt) >= 35) {
7236      phst = (nint(zt)-35.e0)/260.e0;                                   
7237      Const = Const - phst/(1 + std::exp((250.0 - E)/75.0));                   
7238    }
7239  }
7240
7241  if ((nint(zp) == 0) && (nint(ap) == 1)) {
7242    Const = 2*(0.134457/density);                                     
7243    if ((nint(at) > 140) && (nint(at) <200)) {
7244      Const = Const - 1.5*(at - dp2*zt)/at;                                                       
7245    }
7246    if (nint(at) < 60) {
7247      Const = Const - 1.5*(at - dp2*zt)/at;
7248    }           
7249    if (nint(at) <= 40) {
7250      Const = Const + 0.25/(dp1 + safeExp(-(170.0 - E)/100.0));                                                         
7251    }
7252    if (nint(zt) > 82) {
7253      Const = Const - zt/(at - zt);                     
7254    }
7255    if (nint(zt) >= 82) {
7256      Const = Const - dp2/(1.0 + safeExp((E - 20.0)/20.0));
7257    } 
7258    if ((nint(zt) <= 20) && (nint(zt) >= 10)) {
7259      Const = Const - dp1/(dp1 + safeExp((E - 20.0)/dp10));
7260    }                                               
7261  }
7262 
7263  ce = Const * (1.0 - std::exp(-E/t1)) - 0.292*std::exp(-E / 792) * std::cos(0.229*std::pow(E,0.453));   
7264  term1 = std::pow((at*ap),dpth)/(std::pow(at,dpth) + std::pow(ap,dpth));                           
7265  delta = 1.615*term1 - 0.873*ce;                                     
7266  delta = delta + 0.140*term1/(std::pow(ecm,dpth));                                 
7267  delta = delta + 0.794*(at - dp2*zt)*zp/(at*ap);                       
7268  delta = -delta;                   
7269  beta = 1.0;                                                           
7270  twxsec = dp10*dppi*1.26e0*1.26e0*beta*std::pow((0.873e0*std::pow(ap,dpth) + 0.873e0*std::pow(at,dpth)-delta),2);   
7271  sig = twxsec*(dp1-bigb/ecm)*xm;
7272  if (sig < dp0) {
7273    sig = dp0;
7274  }
7275
7276  return sig;
7277}
7278
7279void G4Incl::standardRandom(G4double *rndm, G4long *seed)
7280{
7281  (*seed) = (*seed); // Avoid warning during compilation.
7282  // Use Geant4 G4UniformRand
7283  //  (*rndm) = G4UniformRand();
7284  (*rndm) = randomGenerator->getRandom();
7285}
7286
7287void G4Incl::gaussianRandom(G4double *rndm)
7288{
7289  // Gaussian random number generator
7290 
7291  G4double tempRandom = 0.0, random = 0.0, randomShuffle = 0.0;
7292 
7293  do {
7294    random = 0.0;
7295   
7296    for(G4int i = 0; i < 12; i++) {
7297      standardRandom(&tempRandom, &(hazard->ial));
7298      random = random + tempRandom;
7299    }
7300
7301    random = random - 6.0;
7302  } while(random*random > 9);
7303
7304  // Shuffle the random seeds
7305  standardRandom(&randomShuffle, &(hazard->igraine[10]));
7306
7307  if(randomShuffle > 0.5) {
7308    standardRandom(&tempRandom, &(hazard->ial));
7309  }
7310
7311  (*rndm) = random;
7312}
7313
7314G4double G4Incl::safeExp(G4double x)
7315{                                               
7316  if (x < -80.0) {
7317    x = -80.0;                                         
7318  }
7319  if (x > 80.0) {
7320    x = 80.0;
7321  }                                           
7322
7323  return std::exp(x);
7324}
7325
7326G4double G4Incl::radius(G4double A)
7327{                                               
7328  const G4double dp1 = 1.0, dp3 = 3.0; 
7329  const G4double dp5 = 5.0, dpth = dp1/dp3;
7330  const G4int naSize = 23;
7331  const G4int rmsSize = naSize;
7332
7333  const G4int na[naSize] = {1,2,3,4,6,7,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26};
7334 
7335  const G4double rms[rmsSize] = {0.85,2.095,1.976,1.671,2.57,2.41,2.519,2.45,
7336                                 2.42,2.471,2.440,2.58,2.611,2.730,2.662,2.727,
7337                                 2.900,3.040,2.969,2.94,3.075,3.11,3.06};
7338             
7339  G4double fact = std::sqrt(dp5/dp3);                                               
7340  G4int ia = int(std::floor(A+0.4));                                                       
7341  G4double result = fact * (0.84 * std::pow(A,dpth) + 0.55);                               
7342  for(G4int i = 0; i < naSize; i++) {
7343    if (ia == na[i]) {
7344      result = fact*rms[i];
7345    }
7346  }
7347 
7348  return result;                                                           
7349}
7350
7351G4double G4Incl::crossSection(G4int projectile, G4double E, G4double A) 
7352{
7353  const G4double coefp[4][3] = {{ -5.9260e-9, 6.89450e-6, -6.0980e-6},
7354                                {  2.1544e-6,-1.84800e-3, -5.9820e-4},
7355                                { -2.5900e-4, 0.17595e+0,  1.1741e+0},
7356                                {  1.1504e-3, 2.82810e+0,-28.7300e+0}};
7357 
7358  const G4double coefn[4][3] = {{1.6105e-9,3.3985e-7,1.4678e-5},
7359                                {-5.35e-7,-3.465e-4,-0.01633e+0},
7360                                {-4.755e-6,0.07608e+0,2.8135e+0},
7361                                {-3.622e-3,3.5924e+0,-38.294e+0}};
7362 
7363  const G4double coef2p[5][3] = {{6.8108e-9,-2.163e-7,2.1898e-6},
7364                                 {-2.187e-6,7.8331e-5,-7.164e-4},
7365                                 {2.3651e-4,-9.690e-3,0.076424e+0},
7366                                 {-9.195e-3,0.5030e+0,-2.4979e+0},
7367                                 {-0.01087e+0,2.6494e+0,-2.5173e+0}}; 
7368
7369  G4double apow[3] = {0.0, 0.0, 0.0}, epow[5] = {0.0, 0.0, 0.0};
7370  G4int ii = 0, jj = 0;
7371
7372  if(A >= 27.0) {
7373    ii = 3;       
7374    jj = 4;
7375  } else {
7376    ii = 3;
7377    jj = 5;
7378  }
7379
7380  for(int i = 1; i <= ii; i++) {
7381    apow[i-1] = std::pow(A,(ii-i));
7382  }
7383
7384  for(int j = 1; j <= jj; j++) {
7385    epow[j-1] = std::pow(E,(jj-j));
7386  }
7387
7388  double result = 0.0;
7389
7390  if(A >= 27.0) { 
7391    if(projectile == 1) {
7392      for(G4int i = 0; i < ii; i++) {
7393        for(G4int j = 0; j < jj; j++) {
7394          result = result + coefp[j][i]*apow[i]*epow[j];
7395        }
7396      }
7397    } else {
7398      for(G4int i = 0; i < ii; i++ ) {
7399        for(G4int j = 0; j < jj; j++) {
7400          result = result + coefn[j][i]*apow[i]*epow[j];
7401        }
7402      }
7403    }
7404  } else {
7405    for(G4int i = 0; i < ii; i++) {
7406      for(G4int j = 0; j < jj; j++) {
7407        result = result + coef2p[j][i]*apow[i]*epow[j];
7408      }
7409    }
7410  }
7411
7412  return result;
7413}
7414
7415G4double G4Incl::coulombTransm(G4double E, G4double fm1, G4double z1, G4double fm2, G4double z2)
7416{
7417  G4double eta = 0.0, rho = 0.0;
7418  const G4double c2 = 0.00516;
7419  const G4double c3 = 0.007165;
7420  const G4double uma = 938.0;
7421  G4double ml = 0.0;
7422 
7423  G4double ecm = E*fm2/(fm1+fm2);
7424  G4double fm = fm1*fm2*uma/(fm1+fm2);
7425  G4double r1 = 0.0;
7426  G4double r2 = 0.0;
7427  if(fm1 >= 2.0) {
7428    r1 = 1.2*std::pow(fm1,0.33333333);
7429  }
7430  r2 = 1.2*std::pow(fm2,0.33333333);
7431  eta = c2*z1*z2*std::sqrt(fm/ecm);
7432  rho = c3*(r1+r2)*std::sqrt(fm*ecm);
7433
7434  return clmb1(rho,eta,&ml);
7435}
7436
7437G4double G4Incl::clmb1(G4double rho, G4double eta, G4double *ml) 
7438{                                       
7439  const G4double dp1 = 1.0, dp2 = 2.e0, dp4 = 4.e0, dph = 0.5, dp5 = 5.0; 
7440
7441  const G4double prm1 = 69.06;                                         
7442  const G4int ln0 = 81, lt0 = 21;                                       
7443  const G4int ln1 = 61, lt1 = 61;                                       
7444  static G4double psi0[ln0], trans0[lt0][ln0], x0[lt0], f0[ln0], psi1[ln1];
7445  static G4double trans1[lt1][ln1], x1[lt1], f1[ln1];                               
7446
7447  const G4double pi = 3.14159;                                               
7448  const G4double c0 = 0.11225, c1 = dph, gamma = 0.5772157e0, s3 = 0.2020569;
7449  const G4double s4 = 0.08232323;
7450  static G4double y = dp2*eta;                                                         
7451  static G4double psi = rho*y;                                                         
7452
7453  static G4int i0 = 0, j0 = 0;
7454 
7455  static G4double prob = 0.0;
7456  static G4double dumm = 0.0, x = 0.0, cx = 0.0;
7457  static G4double t = 0.0, t1 = 0.0, t2 = 0.0, t3 = 0.0;
7458  static G4double f = 0.0, g = 0.0;
7459  static G4double temp = 0.0, temp1 = 0.0, temp2 = 0.0;
7460  static G4double xk = 0.0, delp0 = 0.0, delp1 = 0.0, delx0 = 0.0, delx1 = 0.0;
7461
7462  if (rho > y) {                                                 
7463    if (psi > dp4 && psi < 50.0) {                           
7464      prob = clmb2(rho,eta,&dumm);                                       
7465    } else {
7466      x = std::exp(std::log(eta)/6.0);
7467      prob = std::sqrt(dp1 - y*x/(c0 + c1 * std::pow(x,3) + rho * x));
7468    } 
7469    (*ml) = 0;
7470  } else {
7471    x = rho/y;                                                         
7472    if (psi <= psi0[0]) {
7473      t = min(pi*y,prm1);                                             
7474      cx = t/(std::exp(t) - dp1);                                             
7475      t1 = std::cos(rho) * (dp1-0.75*std::pow(psi,2) + dp5 * x * std::pow(psi,2)) - dph * psi * rho * std::sin(rho);
7476      t2 = dp1 + dph * psi * (dp1 - x/6.0);                                   
7477      if (eta > dp1) {                                         
7478        t3 = std::log(psi)+dp2*gamma - dp1 + dp1/(12.e0*std::pow(eta,2))+dp1/(12.e1*std::pow(eta,4));
7479      } else {                                                         
7480        t3 = std::log(dp2*rho) + gamma - dp1/(dp1 + std::pow(eta,2)) + s3*std::pow(eta,2) + s4*std::pow(eta,4);   
7481      }
7482      g = t1 + psi*t2*t3;                                               
7483      f = cx*rho*t2;                                                   
7484      prob = cx/(std::pow(g,2)+std::pow(f,2));                                           
7485      (*ml) = 3;
7486    } else if (psi <= psi0[ln0-1]) {
7487      if (x <= x0[0]) {
7488        temp = std::log(psi/psi0[0]);
7489        j0 = 1 + int(temp/delp0);                                       
7490        j0 = min(max(j0,1),(ln0-1));                                     
7491        temp = temp - (j0-1)*delp0;                                     
7492        t = f0[j0] + (f0[j0+1] - f0[j0])*temp/delp0;                       
7493        xk = x*std::sqrt(psi);                                             
7494        prob = (dp1+3.33e-1*x+3.e-1*xk+1.e-1*std::pow(xk,2))*std::exp(t);           
7495        t = min(pi*y,prm1);                                           
7496        cx = t/(std::exp(t)-dp1);                                           
7497        prob = cx/std::pow(prob,2);                                             
7498        (*ml) = 1;
7499      } else {                                                         
7500        temp1 = std::log(x/x0[0]);
7501        i0 = min(max(1 + int(temp1/delx0),1),lt0-1);                                     
7502        temp1 = temp1 - (i0 - 1)*delx0;                                   
7503        temp2 = std::log(psi/psi0[0]);
7504        j0 = min(max(1+int(temp2/delp0),1),ln0-1);                                     
7505        temp2 = temp2-(j0-1)*delp0;                                   
7506        t1 = trans0[i0][j0] + (trans0[i0+1][j0] - trans0[i0][j0]) * temp1/delx0;
7507        t2 = trans0[i0][j0+1] + (trans0[i0+1][j0+1] - trans0[i0][j0+1]) * temp1/delx0;
7508        prob = std::exp(t1 + (t2 - t1)*temp2/delp0);                                   
7509        (*ml)=2;                                                       
7510      }
7511    } else if (psi <= psi1[ln1-1]) {
7512      if (x <= x1[0]) {
7513        temp = std::log(psi/psi1[0]);
7514        j0 = min(max(1+int(temp/delp1), 1), ln1-1);
7515        t = f1[j0]+(f1[j0+1]-f1[j0])*(temp - (j0 - 1)*delp1)/delp1;                       
7516        xk = x*std::sqrt(psi);                                             
7517        prob = (dp1+3.33e-1*x+3.0e-1*xk+1.e-1*std::pow(xk,2))*std::exp(t);           
7518        t = min(pi*y,prm1);                                           
7519        cx = t/(std::exp(t)-dp1);                                           
7520        prob = cx/std::pow(prob,2);                                             
7521        (*ml) = 1;
7522      } else {                                                         
7523        temp1 = std::log(x/x1[0]);
7524        i0 = min(max(1+int(temp1/delx1),1),lt1-1);                                   
7525        temp1 = temp1-(i0-1)*delx1;                                   
7526        temp2 = std::log(psi/psi1[0]);
7527        j0 = min(max(1+int(temp2/delp1),1),ln1-1);                                     
7528        temp2 = temp2 - (j0-1)*delp1;                                   
7529        t1 = trans1[i0][j0] + (trans1[i0+1][j0] - trans1[i0][j0])*temp1/delx1;
7530        t2 = trans1[i0][j0+1] + (trans1[i0+1][j0+1] - trans1[i0][j0+1])*temp1/delx1;                                                     
7531        prob = std::exp(t1 + (t2-t1)*temp2/delp1);                                   
7532        (*ml)=2;                                                       
7533      }
7534    } else {
7535      prob = clmb2(rho,eta,&dumm);                                       
7536      (*ml) = 4;                                             
7537    }
7538  }
7539
7540  return prob;
7541}
7542
7543G4double G4Incl::clmb2(G4double rho, G4double eta, G4double *t1)
7544{
7545  const G4double dp0 = 0.0, dp1 = 1.0, dp2 = 2.0, dp3 = 3.0;
7546  const G4double dph = 0.5, dpth = dp1/dp3;                                                   
7547  const G4int ln = 102;
7548
7549  const G4double t0[ln] = {0.0, dp0,.1083,.1369,.1572,.1736,.1876,.2,.2113,
7550                           0.2216,.2312,.2403,.2489,.2571,.265,.2725,.2798,
7551                           .2869,.2938,.3006,.3071,.3136,.3199,.3261,.3322,
7552                           .3382,.3442,.3499,.3557,.3615,.3672,.3729,.3785,
7553                           .3841,.3897,.3952,.4008,.4063,.4118,.4173,.4228,
7554                           .4283,.4338,.4393,.4448,.4504,.4559,.4615,.4671,
7555                           .4728,.4784,.4841,.4899,.4957,.5015,.5074,.5133,
7556                           .5193,.5253,.5315,.5376,.5439,.5503,.5567,.5632,
7557                           .5698,.5765,.5833,.5903,.5973,.6045,.6118,.6193,
7558                           .6269,.6346,.6426,.6507,.659,.6675,.6763,.6853,
7559                           .6945,.704,.7139,.724,.7345,.7453,.7566,.7683,
7560                           .7805,.7932,.8065,.8205,.8352,.8508,.8673,.8849,
7561                           .9038,.9243,.9467,.9715,dp1};                                           
7562  const G4double x1 = 0.01;
7563  const G4double xi = 100;                                       
7564  static G4double x = 0.0, temp = 0.0, prob = 0.0;
7565  static G4int i = 0;
7566
7567  x = dp1/(dp1 + std::sqrt(dph*rho*eta));                                     
7568  if (x < x1) {                                                 
7569    temp = t0[2] * std::pow((x/x1),dpth);
7570  } else {
7571    i = int(std::floor(xi*x));                                                         
7572    i = i + 1;
7573    if(i == 101) {
7574      i = 100;
7575    }
7576    i = max(min(i,ln-1),2); // 2->1
7577    temp = t0[i] + (t0[i+1] - t0[i]) * (x - i * x1)/x1;                         
7578  }
7579  (*t1) = dp1 - temp;                                                       
7580  prob = dp1 - dp2 * (*t1) * eta/rho;                                           
7581
7582  return (max(prob,dp0));
7583}
7584
7585// Utilities
7586
7587G4double G4Incl::min(G4double a, G4double b)
7588{
7589  if(a < b) {
7590    return a;
7591  } else {
7592    return b;
7593  }
7594}
7595
7596G4int G4Incl::min(G4int a, G4int b)
7597{
7598  if(a < b) {
7599    return a;
7600  } else {
7601    return b;
7602  }
7603}
7604
7605G4double G4Incl::max(G4double a, G4double b)
7606{
7607  if(a > b) {
7608    return a;
7609  } else {
7610    return b;
7611  }
7612}
7613
7614G4int G4Incl::max(G4int a, G4int b)
7615{
7616  if(a > b) {
7617    return a;
7618  } else {
7619    return b;
7620  }
7621}
7622
7623G4int G4Incl::nint(G4double number)
7624{
7625  G4double intpart;
7626  G4double fractpart;
7627  fractpart = std::modf(number, &intpart);
7628  if(number == 0) {
7629    return 0;
7630  }
7631  if(number > 0) {
7632    if(fractpart < 0.5) {
7633      return int(std::floor(number));
7634    } else {
7635      return int(std::ceil(number));
7636    }
7637  }
7638  if(number < 0) {
7639    if(fractpart < -0.5) {
7640      return int(std::floor(number));
7641    } else {
7642      return int(std::ceil(number));
7643    }
7644  }
7645 
7646  return 0;
7647}
7648
7649G4double G4Incl::callFunction(G4int functionChoice, G4double r)
7650{
7651  if(functionChoice == wsaxFunction) {
7652    return wsax(r);
7653  }
7654  else if(functionChoice == derivWsaxFunction) {
7655    return derivWsax(r);
7656  }
7657  else if(functionChoice == dmhoFunction) {
7658    return dmho(r);
7659  }
7660  else if(functionChoice == derivMhoFunction) {
7661    return derivMho(r);
7662  }
7663  else if(functionChoice  == derivGausFunction) {
7664    return derivGaus(r);
7665  }
7666  else if(functionChoice == densFunction) {
7667    return dens(r);
7668  }
7669
7670  return 0.0;
7671}
7672
7673G4double G4Incl::am(G4double a, G4double b, G4double c, G4double d) 
7674{
7675  return std::sqrt(d*d-a*a-b*b-c*c);
7676}
7677
7678G4double G4Incl::pcm(G4double E, G4double A, G4double C)
7679{
7680  return (0.5*std::sqrt((std::pow(E,2)-std::pow((A+C),2))*(std::pow(E,2)-std::pow((A-C),2)))/E);
7681}
7682
7683G4double G4Incl::sign(G4double a, G4double b)
7684{
7685  if(b >= 0) {
7686    return utilabs(a);
7687  }
7688  if(b < 0) {
7689    return (-1.0*utilabs(a));
7690  }
7691
7692  if(verboseLevel > 2) {
7693    G4cout <<"Error: sign function failed. " << G4endl;
7694  }
7695  return a; // The algorithm is never supposed to reach this point.
7696}
7697
7698G4double G4Incl::utilabs(G4double a)
7699{
7700  if(a > 0) {
7701    return a;
7702  }
7703  if(a < 0) {
7704    return (-1.0*a);
7705  }
7706  if(a == 0) {
7707    return a;
7708  }
7709
7710  if(verboseLevel > 2) {
7711    G4cout <<"Error: utilabs function failed. " << G4endl;
7712  }
7713  return a;
7714}
7715
7716G4double G4Incl::amax1(G4double a, G4double b)
7717{
7718  if(a > b) {
7719    return a;
7720  }
7721  else if(b > a) {
7722    return b;
7723  }
7724  else if(a == b) {
7725    return a;
7726  }
7727
7728  return a; // The algorithm is never supposed to reach this point.
7729}
7730
7731G4double G4Incl::w(G4double a, G4double b, G4double c, G4double d)
7732{
7733  return (std::sqrt(a*a+b*b+c*c+d*d));
7734}
7735
7736G4int G4Incl::idnint(G4double a)
7737{
7738  G4int value = 0;
7739
7740  G4int valueCeil = int(std::ceil(a));
7741  G4int valueFloor = int(std::floor(a));
7742
7743  if(std::abs(value - valueCeil) < std::abs(value - valueFloor)) {
7744    return valueCeil;
7745  }
7746  else {
7747    return valueFloor;
7748  }
7749}
Note: See TracBrowser for help on using the repository browser.