Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/hadronic/models/binary_cascade/src/G4BinaryCascade.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/hadronic/models/binary_cascade/src/G4BinaryCascade.cc (Version 11.3.0) and /processes/hadronic/models/binary_cascade/src/G4BinaryCascade.cc (Version 8.1.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26                                                    26 
 27 #include "globals.hh"                              27 #include "globals.hh"
 28 #include "G4PhysicalConstants.hh"              << 
 29 #include "G4SystemOfUnits.hh"                  << 
 30 #include "G4Proton.hh"                             28 #include "G4Proton.hh"
 31 #include "G4Neutron.hh"                            29 #include "G4Neutron.hh"
 32 #include "G4LorentzRotation.hh"                    30 #include "G4LorentzRotation.hh"
 33 #include "G4BinaryCascade.hh"                      31 #include "G4BinaryCascade.hh"
 34 #include "G4KineticTrackVector.hh"                 32 #include "G4KineticTrackVector.hh"
 35 #include "G4DecayKineticTracks.hh"             << 
 36 #include "G4ReactionProductVector.hh"              33 #include "G4ReactionProductVector.hh"
 37 #include "G4Track.hh"                              34 #include "G4Track.hh"
 38 #include "G4V3DNucleus.hh"                         35 #include "G4V3DNucleus.hh"
 39 #include "G4Fancy3DNucleus.hh"                     36 #include "G4Fancy3DNucleus.hh"
 40 #include "G4Scatterer.hh"                          37 #include "G4Scatterer.hh"
 41 #include "G4MesonAbsorption.hh"                    38 #include "G4MesonAbsorption.hh"
 42 #include "G4ping.hh"                               39 #include "G4ping.hh"
 43 #include "G4Delete.hh"                             40 #include "G4Delete.hh"
 44                                                    41 
 45 #include "G4CollisionManager.hh"                   42 #include "G4CollisionManager.hh"
 46 #include "G4Absorber.hh"                           43 #include "G4Absorber.hh"
 47                                                    44 
 48 #include "G4CollisionInitialState.hh"              45 #include "G4CollisionInitialState.hh"
 49 #include "G4ListOfCollisions.hh"                   46 #include "G4ListOfCollisions.hh"
 50 #include "G4Fragment.hh"                           47 #include "G4Fragment.hh"
 51 #include "G4RKPropagation.hh"                      48 #include "G4RKPropagation.hh"
 52                                                    49 
 53 #include "G4NuclearShellModelDensity.hh"       <<  50 #include "G4NuclearShellModelDensity.hh" 
 54 #include "G4NuclearFermiDensity.hh"                51 #include "G4NuclearFermiDensity.hh"
 55 #include "G4FermiMomentum.hh"                      52 #include "G4FermiMomentum.hh"
 56                                                    53 
 57 #include "G4PreCompoundModel.hh"                   54 #include "G4PreCompoundModel.hh"
 58 #include "G4ExcitationHandler.hh"                  55 #include "G4ExcitationHandler.hh"
 59 #include "G4HadronicInteractionRegistry.hh"    << 
 60                                                    56 
 61 #include "G4FermiPhaseSpaceDecay.hh"               57 #include "G4FermiPhaseSpaceDecay.hh"
 62                                                    58 
 63 #include "G4PreCompoundModel.hh"               << 
 64 #include "G4HadronicParameters.hh"             << 
 65                                                << 
 66 #include <algorithm>                               59 #include <algorithm>
 67 #include "G4ShortLivedConstructor.hh"              60 #include "G4ShortLivedConstructor.hh"
 68 #include <typeinfo>                                61 #include <typeinfo>
 69                                                    62 
 70 #include "G4PhysicsModelCatalog.hh"            << 
 71                                                << 
 72 //   turn on general debugging info, and consi     63 //   turn on general debugging info, and consistency checks
 73                                                << 
 74 //#define debug_G4BinaryCascade 1                  64 //#define debug_G4BinaryCascade 1
 75                                                    65 
 76 //  more detailed debugging -- deprecated      <<  66 //  more detailed debugging -- deprecated  
 77 //#define debug_H1_BinaryCascade 1             <<  67 //#define debug_1_BinaryCascade 1
 78                                                    68 
 79 //  specific debugging info per method or func <<  69 //  specific debuuging info per method or functionality
 80 //#define debug_BIC_ApplyCollision 1               70 //#define debug_BIC_ApplyCollision 1
 81 //#define debug_BIC_CheckPauli 1                   71 //#define debug_BIC_CheckPauli 1
 82 //#define debug_BIC_CorrectFinalPandE 1            72 //#define debug_BIC_CorrectFinalPandE 1
 83 //#define debug_BIC_Propagate 1                    73 //#define debug_BIC_Propagate 1
 84 //#define debug_BIC_Propagate_Excitation 1         74 //#define debug_BIC_Propagate_Excitation 1
 85 //#define debug_BIC_Propagate_Collisions 1     << 
 86 //#define debug_BIC_Propagate_finals 1             75 //#define debug_BIC_Propagate_finals 1
 87 //#define debug_BIC_DoTimeStep 1                   76 //#define debug_BIC_DoTimeStep 1
 88 //#define debug_BIC_CorrectBarionsOnBoundary 1     77 //#define debug_BIC_CorrectBarionsOnBoundary 1
 89 //#define debug_BIC_GetExcitationEnergy 1          78 //#define debug_BIC_GetExcitationEnergy 1
 90 //#define debug_BIC_DeexcitationProducts 1     << 
 91 //#define debug_BIC_FinalNucleusMomentum 1         79 //#define debug_BIC_FinalNucleusMomentum 1
 92 //#define debug_BIC_Final4Momentum 1           << 
 93 //#define debug_BIC_FillVoidnucleus 1          << 
 94 //#define debug_BIC_FindFragments 1                80 //#define debug_BIC_FindFragments 1
 95 //#define debug_BIC_BuildTargetList 1          << 
 96 //#define debug_BIC_FindCollision 1            << 
 97 //#define debug_BIC_return 1                   << 
 98                                                << 
 99 //-------                                      << 
100 //#if defined(debug_G4BinaryCascade)           << 
101 #if 0                                          << 
102   #define _CheckChargeAndBaryonNumber_(val) Ch << 
103   //#define debugCheckChargeAndBaryonNumberver << 
104 #else                                          << 
105   #define _CheckChargeAndBaryonNumber_(val)    << 
106 #endif                                         << 
107 //#if defined(debug_G4BinaryCascade)           << 
108 #if 0                                          << 
109   #define _DebugEpConservation(val)  DebugEpCo << 
110   //#define debugCheckChargeAndBaryonNumberver << 
111 #else                                          << 
112   #define _DebugEpConservation(val)            << 
113 #endif                                         << 
114                                                    81 
115 G4int G4BinaryCascade::theBIC_ID = -1;         << 
116                                                    82 
117 //                                             <<  83 
118 //  C O N S T R U C T O R S   A N D   D E S T      84 //  C O N S T R U C T O R S   A N D   D E S T R U C T O R S
119 //                                                 85 //
120 G4BinaryCascade::G4BinaryCascade(G4VPreCompoun <<  86 
121 G4VIntraNuclearTransportModel("Binary Cascade" <<  87 G4BinaryCascade::G4BinaryCascade() : G4VIntraNuclearTransportModel()
122 {                                                  88 {
123     // initialise the resonance sector         <<  89   // initialise the resonance sector
124     G4ShortLivedConstructor ShortLived;        <<  90   G4ShortLivedConstructor ShortLived;
125     ShortLived.ConstructParticle();            <<  91   ShortLived.ConstructParticle();
126                                                <<  92 
127     theCollisionMgr = new G4CollisionManager;  <<  93   theCollisionMgr = new G4CollisionManager;
128     theDecay=new G4BCDecay;                    <<  94   theDecay=new G4BCDecay;
129     theImR.push_back(theDecay);                <<  95   theImR.push_back(theDecay);
130     theLateParticle= new G4BCLateParticle;     <<  96   theImR.push_back(new G4Scatterer);
131     G4MesonAbsorption * aAb=new G4MesonAbsorpt <<  97   theImR.push_back(new G4MesonAbsorption);
132     theImR.push_back(aAb);                     <<  98   thePropagator = new G4RKPropagation;
133     G4Scatterer * aSc=new G4Scatterer;         <<  99   theCurrentTime = 0.;
134     theH1Scatterer = new G4Scatterer;          << 100   theCutOnP = 90*MeV; 
135     theImR.push_back(aSc);                     << 101   theCutOnPAbsorb= 0*MeV;
136                                                << 102 //  G4ExcitationHandler *
137     thePropagator = new G4RKPropagation;       << 103   theExcitationHandler = new G4ExcitationHandler;
138     theCurrentTime = 0.;                       << 104   SetDeExcitation(new G4PreCompoundModel(theExcitationHandler));
139     theBCminP = 45*MeV;                        << 105   SetMinEnergy(0.0*GeV);
140     theCutOnP = 90*MeV;                        << 106   SetMaxEnergy(10.1*GeV);
141     theCutOnPAbsorb= 0*MeV;   // No Absorption << 107   PrintWelcomeMessage();
142                                                << 108   thePrimaryEscape = true;
143     // reuse existing pre-compound model       << 109   thePrimaryType = 0;
144     if(!ptr) {                                 << 
145       G4HadronicInteraction* p =               << 
146   G4HadronicInteractionRegistry::Instance()->F << 
147       G4VPreCompoundModel* pre = static_cast<G << 
148       if(!pre) { pre = new G4PreCompoundModel( << 
149       SetDeExcitation(pre);                    << 
150     }                                          << 
151     theExcitationHandler = GetDeExcitation()-> << 
152     SetMinEnergy(0.0*GeV);                     << 
153     SetMaxEnergy(10.1*GeV);                    << 
154     //PrintWelcomeMessage();                   << 
155     thePrimaryEscape = true;                   << 
156     thePrimaryType = 0;                        << 
157                                                << 
158     SetEnergyMomentumCheckLevels(1.0*perCent,  << 
159                                                << 
160     // init data members                       << 
161     currentA=currentZ=0;                       << 
162     lateA=lateZ=0;                             << 
163     initialA=initialZ=0;                       << 
164     projectileA=projectileZ=0;                 << 
165     currentInitialEnergy=initial_nuclear_mass= << 
166     massInNucleus=0.;                          << 
167     theOuterRadius=0.;                         << 
168     theBIC_ID = G4PhysicsModelCatalog::GetMode << 
169     fBCDEBUG = G4HadronicParameters::Instance( << 
170 }                                                 110 }
171                                                   111 
                                                   >> 112 
                                                   >> 113 G4BinaryCascade::G4BinaryCascade(const G4BinaryCascade& )
                                                   >> 114 : G4VIntraNuclearTransportModel()
                                                   >> 115 {
                                                   >> 116 }
                                                   >> 117 
                                                   >> 118 
172 G4BinaryCascade::~G4BinaryCascade()               119 G4BinaryCascade::~G4BinaryCascade()
173 {                                                 120 {
174     ClearAndDestroy(&theTargetList);           << 121   ClearAndDestroy(&theTargetList);
175     ClearAndDestroy(&theSecondaryList);        << 122   ClearAndDestroy(&theSecondaryList);
176     ClearAndDestroy(&theCapturedList);         << 123   ClearAndDestroy(&theCapturedList);
177     delete thePropagator;                      << 124   ClearAndDestroy(&theProjectileList);
178     delete theCollisionMgr;                    << 125   delete thePropagator;
179     for(auto & ptr : theImR) { delete ptr; }   << 126   delete theCollisionMgr;
180     theImR.clear();                            << 127   std::for_each(theImR.begin(), theImR.end(), Delete<G4BCAction>());
181     delete theLateParticle;                    << 128   delete theExcitationHandler;
182     delete theH1Scatterer;                     << 
183 }                                              << 
184                                                << 
185 void G4BinaryCascade::ModelDescription(std::os << 
186 {                                              << 
187     outFile << "G4BinaryCascade is an intra-nu << 
188             << "an incident hadron collides wi << 
189             << "final-state particles, one or  << 
190             << "The resonances then decay hadr << 
191             << "are then propagated through th << 
192             << "trajectories until they re-int << 
193             << "This model is valid for incide << 
194             << "nucleons up to 10 GeV.\n"      << 
195             << "The remaining excited nucleus  << 
196             if (theDeExcitation)               << 
197             {                                  << 
198               outFile << theDeExcitation->GetM << 
199               theDeExcitation->DeExciteModelDe << 
200             }                                  << 
201             else if (theExcitationHandler)     << 
202             {                                  << 
203                outFile << "G4ExcitationHandler << 
204                theExcitationHandler->ModelDesc << 
205             }                                  << 
206             else                               << 
207             {                                  << 
208                outFile << "void.\n";           << 
209             }                                  << 
210     outFile<< " \n";                           << 
211 }                                              << 
212 void G4BinaryCascade::PropagateModelDescriptio << 
213 {                                              << 
214     outFile << "G4BinaryCascade propagtes seco << 
215             << "energy model through the wound << 
216             << "Secondaries are followed after << 
217             << "within the nucleus are propaga << 
218             << "potential along curved traject << 
219             << "with a nucleon, decay, or leav << 
220             << "An interaction of a secondary  << 
221             << "final-state particles, one or  << 
222             << "Resonances decay hadronically  << 
223             << "are in turn propagated through << 
224             << "trajectories until they re-int << 
225             << "This model is valid for pions  << 
226             << "nucleons up to about 3.5 GeV.\ << 
227             << "The remaining excited nucleus  << 
228     if (theDeExcitation)                // pre << 
229     {                                          << 
230       outFile << theDeExcitation->GetModelName << 
231       theDeExcitation->DeExciteModelDescriptio << 
232     }                                          << 
233     else if (theExcitationHandler)    // de-ex << 
234     {                                          << 
235        outFile << "G4ExcitationHandler";    // << 
236        theExcitationHandler->ModelDescription( << 
237     }                                          << 
238     else                                       << 
239     {                                          << 
240        outFile << "void.\n";                   << 
241     }                                          << 
242 outFile<< " \n";                               << 
243 }                                                 129 }
244                                                   130 
245 //--------------------------------------------    131 //----------------------------------------------------------------------------
246                                                   132 
247 //                                                133 //
248 //      I M P L E M E N T A T I O N               134 //      I M P L E M E N T A T I O N
249 //                                                135 //
250                                                   136 
251                                                   137 
252 //--------------------------------------------    138 //----------------------------------------------------------------------------
253 G4HadFinalState * G4BinaryCascade::ApplyYourse    139 G4HadFinalState * G4BinaryCascade::ApplyYourself(const G4HadProjectile & aTrack,
254         G4Nucleus & aNucleus)                  << 
255 //--------------------------------------------    140 //----------------------------------------------------------------------------
                                                   >> 141               G4Nucleus & aNucleus)
256 {                                                 142 {
257     if(fBCDEBUG) G4cerr << " ######### Binary  << 143   static G4int eventcounter=0;
258                                                << 144   //if(eventcounter == 100*(eventcounter/100) )
259     G4LorentzVector initial4Momentum = aTrack. << 145   eventcounter++;
260     const G4ParticleDefinition * definition =  << 146   if(getenv("BCDEBUG") ) G4cerr << " ######### Binary Cascade Reaction number starts ######### "<<eventcounter<<G4endl;
261                                                << 147   G4LorentzVector initial4Momentum = aTrack.Get4Momentum();
262     if(initial4Momentum.e()-initial4Momentum.m << 148   if(initial4Momentum.e()-initial4Momentum.m()<theCutOnP/2.)
263             ( definition==G4Neutron::NeutronDe << 149   {
264     {                                          << 150     return theDeExcitation->ApplyYourself(aTrack, aNucleus);
265         return theDeExcitation->ApplyYourself( << 151   }
266     }                                          << 152 
267                                                << 153   theParticleChange.Clear();
268     theParticleChange.Clear();                 << 154 // initialize the G4V3DNucleus from G4Nucleus
269     // initialize the G4V3DNucleus from G4Nucl << 155   the3DNucleus = new G4Fancy3DNucleus;
270     the3DNucleus = new G4Fancy3DNucleus;       << 156   the3DNucleus->Init(aNucleus.GetN(), aNucleus.GetZ());
271                                                << 157 
272     // Build a KineticTrackVector with the G4T << 158   thePropagator->Init(the3DNucleus);
273     G4KineticTrackVector * secondaries;// = ne << 159 
274     G4ThreeVector initialPosition(0., 0., 0.); << 160 // Build a KineticTrackVector with the G4Track
275                                                << 161   G4KineticTrackVector * secondaries = new G4KineticTrackVector;
276     if(!fBCDEBUG)                              << 162   G4ParticleDefinition * definition = const_cast<G4ParticleDefinition *>(aTrack.GetDefinition());
277     {                                          << 163   G4ThreeVector initialPosition(0., 0., 0.); // will be set later
278         if(definition!=G4Neutron::NeutronDefin << 164 
279                 definition!=G4Proton::ProtonDe << 165   if(!getenv("I_Am_G4BinaryCascade_Developer") )
280                 definition!=G4PionPlus::PionPl << 166   {
281                 definition!=G4PionMinus::PionM << 167     if(definition!=G4Neutron::NeutronDefinition() &&
282         {                                      << 168       definition!=G4Proton::ProtonDefinition() &&
283             G4cerr << "You are trying to use G << 169       definition!=G4PionPlus::PionPlusDefinition() &&
284             G4cerr << "G4BinaryCascade should  << 170       definition!=G4PionMinus::PionMinusDefinition() )
285             G4cerr << "If you want to continue << 171     {
286             G4cerr << "setenv I_Am_G4BinaryCas << 172       G4cerr << "You are using G4BinaryCascade for projectiles other than nucleons or pions."<<G4endl;
287             throw G4HadronicException(__FILE__ << 173       G4cerr << "If you want to continue, please switch on the developer environment: "<<G4endl;
288         }                                      << 174       G4cerr << "setenv I_Am_G4BinaryCascade_Developer 1 "<<G4endl<<G4endl;
289     }                                          << 175       throw G4HadronicException(__FILE__, __LINE__, "G4BinaryCascade - used for unvalid particle type - Fatal");
290                                                << 176     }
291     // keep primary                            << 177   }
292     thePrimaryType = definition;               << 178 
293     thePrimaryEscape = false;                  << 179 // keep primary
294                                                << 180   thePrimaryType = definition;
295     G4double timePrimary=aTrack.GetGlobalTime( << 181   thePrimaryEscape = false;
296                                                << 182 
297     // try until an interaction will happen    << 183 // try untill an interaction will happen
298     G4ReactionProductVector * products = nullp << 184   G4ReactionProductVector * products = 0;
299     G4int interactionCounter = 0,collisionLoop << 185   G4double radius = the3DNucleus->GetOuterRadius()+3*fermi;
300     do                                         << 186   G4int interactionCounter = 0;
301     {                                          << 187   do
302         // reset status that could be changed  << 188   {
303         theCollisionMgr->ClearAndDestroy();    << 189 // reset status that could be changed in previous loop event
304                                                << 190     theCollisionMgr->ClearAndDestroy();
305         if(products != nullptr)                << 191     ClearAndDestroy(&theTargetList);  // clear and rebuild theTargetList
306         {  // free memory from previous loop e << 192     the3DNucleus->Init(aNucleus.GetN(), aNucleus.GetZ());
307             ClearAndDestroy(products);         << 193     BuildTargetList();
308             delete products;                   << 194     G4KineticTrack * kt = new G4KineticTrack(definition, 0., initialPosition,
309         }                                      << 195                initial4Momentum);
310                                                << 196 // Note: secondaries has been cleared by Propagate() in the previous loop event
311         G4int massNumber=aNucleus.GetA_asInt() << 197     secondaries->push_back(kt);
312         the3DNucleus->Init(massNumber, aNucleu << 198 
313         thePropagator->Init(the3DNucleus);     << 199     while(theCollisionMgr->Entries() == 0)  // until we FIND a collision...
314         G4KineticTrack * kt;                   << 200     {
315       collisionLoopMaxCount = 200;             << 201       theCurrentTime=0;
316         do                  // sample impact p << 202       initialPosition=GetSpherePoint(1.1*radius, initial4Momentum);  // get random position
317         {                                      << 203       kt->SetPosition(initialPosition);         // kt is in secondaries!!
318             theCurrentTime=0;                  << 204       kt->SetState(G4KineticTrack::outside);
319             G4double radius = the3DNucleus->Ge << 205       FindCollisions(secondaries);
320             initialPosition=GetSpherePoint(1.1 << 206     }
321             kt = new G4KineticTrack(definition << 207     if(products != NULL)
322             kt->SetState(G4KineticTrack::outsi << 208     {  // free memory from previous loop event
323             // secondaries has been cleared by << 209       ClearAndDestroy(products);
324             secondaries= new G4KineticTrackVec << 210       delete products;
325             secondaries->push_back(kt);        << 211     }
326             if(massNumber > 1) // 1H1 is speci << 212     products = Propagate(secondaries, the3DNucleus);
327             {                                  << 213 
328                 products = Propagate(secondari << 214 // --------- debug
329             } else {                           << 215 // untill Propagate will be able to return some product...
330                 products = Propagate1H1(second << 216 //  if(1)
331             }                                  << 217 //    return &theParticleChange;
332             // until we FIND a collision ... o << 218 //  --------- end debug
333         } while(! products && --collisionLoopM << 219     if(++interactionCounter>99) break;
334                                                << 220   } while(products->size() == 0);  // ...untill we find an ALLOWED collision
335         if(++interactionCounter>99) break;     << 221 
336         // ...until we find an ALLOWED collisi << 222   if(products->size()==0)
337     } while(products && products->size() == 0) << 223   {
338                                                << 224     theParticleChange.SetStatusChange(isAlive);
339     if(products && products->size()>0)         << 225     theParticleChange.SetEnergyChange(aTrack.GetKineticEnergy());
340     {                                          << 226     theParticleChange.SetMomentumChange(aTrack.Get4Momentum().vect().unit());
341         //  G4cout << "BIC Applyyourself: numb << 227     return &theParticleChange;
342                                                << 228   }
343         // Fill the G4ParticleChange * with pr << 229 //  G4cout << "HKM Applyyourself: number of products " << products->size() << G4endl;
344         theParticleChange.SetStatusChange(stop << 
345         G4ReactionProductVector::iterator iter << 
346                                                << 
347         for(iter = products->begin(); iter !=  << 
348         {                                      << 
349           G4DynamicParticle * aNewDP =         << 
350                     new G4DynamicParticle((*it << 
351                             (*iter)->GetTotalE << 
352                             (*iter)->GetMoment << 
353           G4HadSecondary aNew = G4HadSecondary << 
354             G4double time=(*iter)->GetFormatio << 
355             if(time < 0.0) { time = 0.0; }     << 
356             aNew.SetTime(timePrimary + time);  << 
357             aNew.SetCreatorModelID((*iter)->Ge << 
358             aNew.SetParentResonanceDef((*iter) << 
359             aNew.SetParentResonanceID((*iter)- << 
360             theParticleChange.AddSecondary(aNe << 
361         }                                      << 
362                                                << 
363          //DebugFinalEpConservation(aTrack, pr << 
364                                                << 
365                                                << 
366     } else {  // no interaction, return primar << 
367         if(fBCDEBUG) G4cerr << " ######### Bin << 
368         theParticleChange.SetStatusChange(isAl << 
369         theParticleChange.SetEnergyChange(aTra << 
370         theParticleChange.SetMomentumChange(aT << 
371     }                                          << 
372                                                << 
373     if ( products )                            << 
374    {                                           << 
375       ClearAndDestroy(products);               << 
376        delete products;                        << 
377     }                                          << 
378                                                << 
379     delete the3DNucleus;                       << 
380     the3DNucleus = nullptr;                    << 
381                                                   230 
382     if(fBCDEBUG) G4cerr << " ######### Binary  << 231 // Fill the G4ParticleChange * with products
                                                   >> 232   theParticleChange.SetStatusChange(stopAndKill);
                                                   >> 233   G4ReactionProductVector::iterator iter;
                                                   >> 234   G4double Efinal=0;
                                                   >> 235     if (std::abs(theParticleChange.GetWeightChange() -1 ) > 1e-5 )
                                                   >> 236   {
                                                   >> 237      G4cout <<" BIC-weight change " << theParticleChange.GetWeightChange()<< G4endl;
                                                   >> 238   }
383                                                   239 
384     return &theParticleChange;                 << 240   for(iter = products->begin(); iter != products->end(); ++iter)
                                                   >> 241   {
                                                   >> 242     G4DynamicParticle * aNew =
                                                   >> 243       new G4DynamicParticle((*iter)->GetDefinition(),
                                                   >> 244           (*iter)->GetTotalEnergy(),
                                                   >> 245           (*iter)->GetMomentum());
                                                   >> 246     if(getenv("BCDEBUG") )
                                                   >> 247     {
                                                   >> 248       if(std::abs(aNew->GetDefinition()->GetPDGEncoding()) >100
                                                   >> 249          && std::abs(aNew->GetDefinition()->GetPDGEncoding()) < 300) G4cout << "Pion info "<<aNew->GetDefinition()->GetPDGEncoding() <<" "<<aNew->GetKineticEnergy()<<G4endl;
                                                   >> 250     }
                                                   >> 251     // FixMe: should I use "position" or "time" specifyed AddSecondary() methods?
                                                   >> 252     theParticleChange.AddSecondary(aNew);
                                                   >> 253 
                                                   >> 254 //   G4cout << " Secondary E - Ekin / p " <<
                                                   >> 255 //      (*iter)->GetDefinition()->GetParticleName() << " " <<
                                                   >> 256 //      (*iter)->GetTotalEnergy() << " - " <<
                                                   >> 257 //      (*iter)->GetKineticEnergy()<< " / " <<
                                                   >> 258 //      (*iter)->GetMomentum().x() << " " <<
                                                   >> 259 //      (*iter)->GetMomentum().y() << " " <<
                                                   >> 260 //      (*iter)->GetMomentum().z() << G4endl;
                                                   >> 261       Efinal += (*iter)->GetTotalEnergy();
                                                   >> 262   }
                                                   >> 263 
                                                   >> 264 //  G4cout << "e outgoing/ total : " << Efinal << " " << Efinal+GetFinal4Momentum().e()<< G4endl;
                                                   >> 265 
                                                   >> 266   ClearAndDestroy(products);
                                                   >> 267   delete products;
                                                   >> 268   delete secondaries;
                                                   >> 269 
                                                   >> 270   delete the3DNucleus;
                                                   >> 271   the3DNucleus = NULL;  // protect from wrong usage...
                                                   >> 272 
                                                   >> 273   if(getenv("BCDEBUG") ) G4cerr << " ######### Binary Cascade Reaction number ends ######### "<<eventcounter<<G4endl;
                                                   >> 274     if (std::abs(theParticleChange.GetWeightChange() -1 ) > 1e-5 )
                                                   >> 275   {
                                                   >> 276      G4cout <<" BIC-fin-weight change " << theParticleChange.GetWeightChange()<< G4endl;
                                                   >> 277   }
                                                   >> 278   return &theParticleChange;
385 }                                                 279 }
                                                   >> 280 
386 //--------------------------------------------    281 //----------------------------------------------------------------------------
387 G4ReactionProductVector * G4BinaryCascade::Pro    282 G4ReactionProductVector * G4BinaryCascade::Propagate(
388         G4KineticTrackVector * secondaries, G4 << 
389 //--------------------------------------------    283 //----------------------------------------------------------------------------
                                                   >> 284     G4KineticTrackVector * secondaries, G4V3DNucleus * nucleus)
390 {                                                 285 {
391     G4ping debug("debug_G4BinaryCascade");     << 286   G4ping debug("debug_G4BinaryCascade");
                                                   >> 287   debug.push_back("trial");
                                                   >> 288   debug.dump();
392 #ifdef debug_BIC_Propagate                        289 #ifdef debug_BIC_Propagate
393     G4cout << "G4BinaryCascade Propagate start << 290    G4cout << "G4BinaryCascade Propagate starting -------------------------------------------------------" <<G4endl;
394 #endif                                            291 #endif
395                                                << 292   G4ReactionProductVector * products = new G4ReactionProductVector;
396     the3DNucleus=aNucleus;                     << 293   the3DNucleus = nucleus;
397     G4ReactionProductVector * products = new G << 294   theOuterRadius = the3DNucleus->GetOuterRadius();
398     theOuterRadius = the3DNucleus->GetOuterRad << 295   theCurrentTime=0;
399     theCurrentTime=0;                          << 296 // build theSecondaryList, theProjectileList and theCapturedList
400     theProjectile4Momentum=G4LorentzVector(0,0 << 297   ClearAndDestroy(&theCapturedList);
401     theMomentumTransfer=G4ThreeVector(0,0,0);  << 298   ClearAndDestroy(&theSecondaryList);
402     // build theSecondaryList, theProjectileLi << 299   ClearAndDestroy(&theProjectileList);
403     ClearAndDestroy(&theCapturedList);         << 300   ClearAndDestroy(&theFinalState);
404     ClearAndDestroy(&theSecondaryList);        << 301   std::vector<G4KineticTrack *>::iterator iter;
405     theSecondaryList.clear();                  << 302   if(nucleus->GetMassNumber() == 1) // 1H1 is special case
406     ClearAndDestroy(&theFinalState);           << 303   {
407     std::vector<G4KineticTrack *>::iterator it << 304      return Propagate1H1(secondaries,nucleus);
408     theCollisionMgr->ClearAndDestroy();        << 305   }
409                                                << 306 
410     theCutOnP=90*MeV;                          << 307   for(iter = secondaries->begin(); iter != secondaries->end(); ++iter)
411     if(the3DNucleus->GetMass()>30) theCutOnP = << 308   {
412     if(the3DNucleus->GetMass()>60) theCutOnP = << 309     theSecondaryList.push_back(*iter);
413     if(the3DNucleus->GetMass()>120) theCutOnP  << 310     theProjectileList.push_back(new G4KineticTrack(*(*iter)));
414                                                << 311   }
415                                                << 312   secondaries->clear(); // Don't leave "G4KineticTrack *"s in two vectors
                                                   >> 313 
                                                   >> 314   thePropagator->Init(the3DNucleus);
                                                   >> 315 
                                                   >> 316 // if called stand alone, build theTargetList and find first collisions
                                                   >> 317 
                                                   >> 318   if(nucleus->GetMass()>30) theCutOnP = 70*MeV;
                                                   >> 319   if(nucleus->GetMass()>60) theCutOnP = 50*MeV;
                                                   >> 320   if(nucleus->GetMass()>120) theCutOnP = 45*MeV;
                                                   >> 321   if(theCollisionMgr->Entries() == 0)
                                                   >> 322   {
                                                   >> 323     the3DNucleus = nucleus;
                                                   >> 324     ClearAndDestroy(&theTargetList);
416     BuildTargetList();                            325     BuildTargetList();
                                                   >> 326     FindCollisions(&theSecondaryList);
                                                   >> 327   }
417                                                   328 
418 #ifdef debug_BIC_GetExcitationEnergy           << 329 //  thePropagator->Init(the3DNucleus);
419     G4cout << "ExcitationEnergy0 " << GetExcit << 
420 #endif                                         << 
421                                                << 
422     thePropagator->Init(the3DNucleus);         << 
423                                                   330 
424     G4bool success = BuildLateParticleCollisio << 331 // end of initialization: do the job now
425     if (! success )   // fails if no excitatio << 332 // loop untill there are collisions
426     {                                          << 
427        products=HighEnergyModelFSProducts(prod << 
428        ClearAndDestroy(secondaries);           << 
429        delete secondaries;                     << 
430                                                   333 
431 #ifdef debug_G4BinaryCascade                   << 
432        G4cout << "G4BinaryCascade::Propagate:  << 
433 #endif                                         << 
434                                                   334 
435        return products;                        << 335   G4bool haveProducts = false;
                                                   >> 336   G4int collisionCount=0;
                                                   >> 337   theMomentumTransfer=0;
                                                   >> 338   while(theCollisionMgr->Entries() > 0)
                                                   >> 339   {
                                                   >> 340     // G4cout << "Propagate Captured size: " << theCapturedList.size() << G4endl;
                                                   >> 341     // FixMe: at the moment I absorb pi with mom < theCutOnp, and I capture
                                                   >> 342     //        p and n with mom < theCutOnP. What about antip, k and sigmas
                                                   >> 343     //        with mom < theCutOnP?
                                                   >> 344     if(Absorb()) {  // absorb secondaries
                                                   >> 345       haveProducts = true;
                                                   >> 346       //G4cout << "Absorb sucess " << G4endl;
436     }                                             347     }
437     // check baryon and charge ...             << 
438                                                   348 
439     _CheckChargeAndBaryonNumber_("lateparticle << 349     if(Capture()) { // capture secondaries (nucleons)
440     _DebugEpConservation(" be4 findcollisions" << 350       haveProducts = true;
441                                                << 351       //G4cout << "Capture sucess " << G4endl;
442     // if called stand alone find first collis << 
443     FindCollisions(&theSecondaryList);         << 
444                                                << 
445                                                << 
446     if(theCollisionMgr->Entries() == 0 )       << 
447     {                                          << 
448         //G4cout << " no collsions -> return 0 << 
449         delete products;                       << 
450 #ifdef debug_BIC_return                        << 
451         G4cout << "return @ begin2,  no collis << 
452 #endif                                         << 
453         return nullptr;                        << 
454     }                                             352     }
455                                                   353 
456     // end of initialization: do the job now   << 354 // propagate to the next collision if any (collisions could have been deleted
457     // loop until there are no more collisions << 355 // by previous absorption or capture)
                                                   >> 356     if(theCollisionMgr->Entries() > 0)
                                                   >> 357     {
                                                   >> 358        G4CollisionInitialState *
                                                   >> 359   nextCollision = theCollisionMgr->GetNextCollision();
458                                                   360 
                                                   >> 361        debug.push_back("======>    test 1"); debug.dump();
                                                   >> 362        if (!DoTimeStep(nextCollision->GetCollisionTime()-theCurrentTime) )
                                                   >> 363        {
                                                   >> 364      // Check if nextCollision is still valid, ie. partcile did not leave nucleus
                                                   >> 365      if (theCollisionMgr->GetNextCollision() != nextCollision )
                                                   >> 366      {
                                                   >> 367          nextCollision = 0;
                                                   >> 368      }
                                                   >> 369   }
                                                   >> 370        debug.push_back("======>    test 2"); debug.dump();
                                                   >> 371 //       G4cerr <<"post- DoTimeStep 1"<<G4endl;
459                                                   372 
460     G4bool haveProducts = false;               << 373   if( nextCollision )
461 #ifdef debug_BIC_Propagate_Collisions          << 374   {
462     G4int collisionCount=0;                    << 375 // GF for testing only, must be removed otherwise!
463 #endif                                         << 376 //        theCollisionMgr->RemoveCollision(nextCollision);
464     G4int collisionLoopMaxCount=1000000;       << 377            debug.push_back("======>    test 3"); debug.dump();
465     while(theCollisionMgr->Entries() > 0 && cu << 378      if (ApplyCollision(nextCollision))
466     {                                          << 379 // testing          if ( true ) 
467       if(Absorb()) {  // absorb secondaries, p << 380      {
468             haveProducts = true;               << 381 // apply the collision
469       }                                        << 382               //G4cerr << "ApplyCollision sucess " << G4endl;
470       if(Capture()) { // capture secondaries,  << 383         haveProducts = true;
471             haveProducts = true;               << 384         collisionCount++;
472         }                                      << 385               debug.push_back("======>    test 4.1"); debug.dump();
473                                                << 386            } else {
474         // propagate to the next collision if  << 387               //G4cerr << "ApplyCollision failure " << G4endl;
475         // by previous absorption or capture)  << 388         theCollisionMgr->RemoveCollision(nextCollision);
476         if(theCollisionMgr->Entries() > 0)     << 389               debug.push_back("======>    test 4.2"); debug.dump();
477         {                                      << 390            }
478             G4CollisionInitialState *          << 391   }
479             nextCollision = theCollisionMgr->G << 392         debug.push_back("======>    test 5"); debug.dump();
480 #ifdef debug_BIC_Propagate_Collisions          << 393 //       G4cerr <<"post-post- DoTimeStep 1"<<G4endl;
481             G4cout << " NextCollision  * , Tim << 
482                     <<nextCollision->GetCollis << 
483                     theCurrentTime<< G4endl;   << 
484 #endif                                         << 
485             if (!DoTimeStep(nextCollision->Get << 
486             {                                  << 
487                 // Check if nextCollision is s << 
488                 if (theCollisionMgr->GetNextCo << 
489                 {                              << 
490                     nextCollision = nullptr;   << 
491                 }                              << 
492             }                                  << 
493            //_DebugEpConservation("Stepped");  << 
494                                                << 
495             if( nextCollision )                << 
496             {                                  << 
497                 if (ApplyCollision(nextCollisi << 
498                 {                              << 
499                     //G4cerr << "ApplyCollisio << 
500                     haveProducts = true;       << 
501 #ifdef debug_BIC_Propagate_Collisions          << 
502                     collisionCount++;          << 
503 #endif                                         << 
504                                                << 
505                 } else {                       << 
506                     //G4cerr << "ApplyCollisio << 
507                     theCollisionMgr->RemoveCol << 
508                 }                              << 
509             }                                  << 
510         }                                      << 
511     }                                          << 
512                                                << 
513     //--------- end of on Collisions           << 
514     //G4cout << "currentZ @ end loop " << curr << 
515     G4int nProtons(0);                         << 
516     for(iter = theTargetList.begin(); iter !=  << 
517     {                                          << 
518       if ( (*iter)->GetDefinition() == G4Proto << 
519     }                                          << 
520     if ( ! theTargetList.size() || ! nProtons  << 
521         // nucleus completely destroyed, fill  << 
522        products = FillVoidNucleusProducts(prod << 
523 #ifdef debug_BIC_return                        << 
524         G4cout << "return @ Z=0 after collisio << 
525         PrintKTVector(&theSecondaryList,std::s << 
526         G4cout << "theTargetList size: " << th << 
527         PrintKTVector(&theTargetList,std::stri << 
528         PrintKTVector(&theCapturedList,std::st << 
529                                                << 
530         G4cout << " ExcitE be4 Correct : " <<G << 
531         G4cout << " Mom Transfered to nucleus  << 
532         PrintKTVector(&theFinalState,std::stri << 
533         G4cout << "returned products: " << pro << 
534         _CheckChargeAndBaryonNumber_("destroye << 
535         _DebugEpConservation("destroyed Nucleu << 
536 #endif                                         << 
537                                                << 
538         return products;                       << 
539     }                                          << 
540                                                << 
541     // No more collisions: absorb, capture and << 
542     if(Absorb()) {                             << 
543         haveProducts = true;                   << 
544         // G4cout << "Absorb sucess " << G4end << 
545     }                                          << 
546                                                << 
547     if(Capture()) {                            << 
548         haveProducts = true;                   << 
549         // G4cout << "Capture sucess " << G4en << 
550     }                                             394     }
                                                   >> 395   }
551                                                   396 
552     if(!haveProducts)  // no collisions happen << 397    debug.push_back("======>    #### through the first loop"); debug.dump();
553     {                                          << 398 // No more collisions: absorb, capture and propagate the secondaries out of the nucleus
554 #ifdef debug_BIC_return                        << 399   if(Absorb()) {
555         G4cout << "return 3, no products "<< G << 400     haveProducts = true;
556 #endif                                         << 401    // G4cout << "Absorb sucess " << G4endl;
557         return products;                       << 402   }
558     }                                          << 403 
                                                   >> 404   if(Capture()) {
                                                   >> 405     haveProducts = true;
                                                   >> 406    // G4cout << "Capture sucess " << G4endl;
                                                   >> 407   }
                                                   >> 408 
                                                   >> 409   if(!haveProducts)  // no collisions happened. Return an empty vector.
                                                   >> 410   {
                                                   >> 411     return products;
                                                   >> 412   }
559                                                   413 
560                                                   414 
561 #ifdef debug_BIC_Propagate                        415 #ifdef debug_BIC_Propagate
562     G4cout << " Momentum transfer to Nucleus " << 416    G4cout << " Momentum transfer to Nucleus " << theMomentumTransfer << " " << theMomentumTransfer.mag() << G4endl;
563     G4cout << "  Stepping particles out......  << 417    G4cout << "  Stepping particles out...... " << G4endl;
564 #endif                                            418 #endif
565                                                   419 
566     StepParticlesOut();                        << 420   StepParticlesOut();
567     _DebugEpConservation("stepped out");       << 421   
568                                                << 422   
569                                                << 423   if ( theSecondaryList.size() > 0 )
570     if ( theSecondaryList.size() > 0 )         << 424   {
571     {                                          << 
572 #ifdef debug_G4BinaryCascade                      425 #ifdef debug_G4BinaryCascade
573         G4cerr << "G4BinaryCascade: Warning, h << 426       G4cerr << "G4BinaryCascade: Warning, have active particles at end" << G4endl;
574         PrintKTVector(&theSecondaryList, "acti << 
575 #endif                                            427 #endif
576         //  add left secondaries to FinalSate  << 428 //  add left secondaries to FinalSate
577         for ( iter =theSecondaryList.begin();  << 429        std::vector<G4KineticTrack *>::iterator iter;
578         {                                      << 430        for ( iter =theSecondaryList.begin(); iter != theSecondaryList.end(); ++iter)
579             theFinalState.push_back(*iter);    << 431        {
580         }                                      << 432      theFinalState.push_back(*iter);
581         theSecondaryList.clear();              << 433        }
                                                   >> 434        theSecondaryList.clear();
582                                                   435 
583     }                                          << 436   }
584     while ( theCollisionMgr->Entries() > 0 )   << 437   while ( theCollisionMgr->Entries() > 0 )
585     {                                          << 438   {
586 #ifdef debug_G4BinaryCascade                      439 #ifdef debug_G4BinaryCascade
587         G4cerr << " Warning: remove left over  << 440      G4cerr << " Warning: remove left over collision " << G4endl;
588 #endif                                            441 #endif
589         theCollisionMgr->RemoveCollision(theCo << 442       theCollisionMgr->RemoveCollision(theCollisionMgr->GetNextCollision());
590     }                                          << 443   }
591                                                   444 
592 #ifdef debug_BIC_Propagate_Excitation             445 #ifdef debug_BIC_Propagate_Excitation
593                                                   446 
594     PrintKTVector(&theSecondaryList,std::strin << 447   PrintKTVector(&theProjectileList,std::string(" theProjectileList"));
595     G4cout << "theTargetList size: " << theTar << 448   PrintKTVector(&theSecondaryList,std::string(" theSecondaryList"));
596     //  PrintKTVector(&theTargetList,std::stri << 449   G4cout << "theTargetList size: " << theTargetList.size() << G4endl;
597     PrintKTVector(&theCapturedList,std::string << 450 //  PrintKTVector(&theTargetList,std::string(" theTargetList"));
598                                                << 451   PrintKTVector(&theCapturedList,std::string(" theCapturedList"));
599     G4cout << " ExcitE be4 Correct : " <<GetEx << 452 
600     G4cout << " Mom Transfered to nucleus : "  << 453   G4cout << " ExcitE be4 Correct : " <<GetExcitationEnergy() << G4endl;
601     PrintKTVector(&theFinalState,std::string(" << 454   G4cout << " Mom Transfered to nucleus : " << theMomentumTransfer << " " << theMomentumTransfer.mag() << G4endl;
                                                   >> 455   PrintKTVector(&theFinalState,std::string(" FinalState uncorrected"));
602 #endif                                            456 #endif
603                                                   457 
604     //                                         << 458 //
605                                                   459 
606                                                   460 
607     G4double ExcitationEnergy=GetExcitationEne << 461   G4double ExcitationEnergy=GetExcitationEnergy();
608                                                   462 
609 #ifdef debug_BIC_Propagate_finals                 463 #ifdef debug_BIC_Propagate_finals
610     PrintKTVector(&theFinalState,std::string(" << 464   PrintKTVector(&theFinalState,std::string(" FinalState be4 corr"));
611     G4cout << " Excitation Energy prefinal,  # << 465   G4cout << " Excitation Energy prefinal,  #collisions:, out, captured  "
612             << ExcitationEnergy << " "         << 466   << ExcitationEnergy << " "
613             << collisionCount << " "           << 467   << collisionCount << " "
614             << theFinalState.size() << " "     << 468   << theFinalState.size() << " "
615             << theCapturedList.size()<<G4endl; << 469   << theCapturedList.size()<<G4endl;
616 #endif                                         << 470 #endif
617                                                << 471 
618     if (ExcitationEnergy < 0 )                 << 472   if (ExcitationEnergy < 0 ) 
619     {                                          << 473   { 
620         G4int maxtry=5, ntry=0;                << 474      G4int maxtry=5, ntry=0;
621         do {                                   << 475      do {
622             CorrectFinalPandE();               << 476        CorrectFinalPandE();
623             ExcitationEnergy=GetExcitationEner << 477        ExcitationEnergy=GetExcitationEnergy();
624         } while ( ++ntry < maxtry && Excitatio << 478      } while ( ++ntry < maxtry && ExcitationEnergy < 0 );
625     }                                          << 479   }
626     _DebugEpConservation("corrected");         << 
627                                                   480 
628 #ifdef debug_BIC_Propagate_finals                 481 #ifdef debug_BIC_Propagate_finals
629     PrintKTVector(&theFinalState,std::string(" << 482   PrintKTVector(&theFinalState,std::string(" FinalState corrected"));
630     G4cout << " Excitation Energy final,  #col << 483   G4cout << " Excitation Energy final,  #collisions:, out, captured  "
631             << ExcitationEnergy << " "         << 484   << ExcitationEnergy << " "
632             << collisionCount << " "           << 485   << collisionCount << " "
633             << theFinalState.size() << " "     << 486   << theFinalState.size() << " "
634             << theCapturedList.size()<<G4endl; << 487   << theCapturedList.size()<<G4endl;
635 #endif                                            488 #endif
636                                                   489 
637                                                   490 
638     if ( ExcitationEnergy < 0. )               << 491   if ( ExcitationEnergy < 0. )
639     {                                          << 492   {
640             #ifdef debug_G4BinaryCascade       << 493 //  if ( ExcitationEnergy < 0. )
641                   G4cerr << "G4BinaryCascade-W << 494   {
642                   G4cerr <<ExcitationEnergy<<G << 495 //#ifdef debug_G4BinaryCascade
643                  PrintKTVector(&theFinalState, << 496 //      G4cerr << "G4BinaryCascade-Warning: negative excitation energy ";
644                  PrintKTVector(&theCapturedLis << 497 //      G4cerr <<ExcitationEnergy<<G4endl;
645                 G4cout << "negative ExE:Final  << 498 //     PrintKTVector(&theFinalState,std::string("FinalState"));
646                         << " "<< GetFinal4Mome << 499 //    PrintKTVector(&theCapturedList,std::string("captured"));
647                         << "negative ExE:Final << 500 //    G4cout << "negative ExE:Final 4Momentum .mag: " << GetFinal4Momentum()
648                   << " "<< GetFinalNucleusMome << 501 //            << " "<< GetFinal4Momentum().mag()<< G4endl
649             #endif                             << 502 //            << "negative ExE:FinalNucleusMom  .mag: " << GetFinalNucleusMomentum()
650             #ifdef debug_BIC_return            << 503 //      << " "<< GetFinalNucleusMomentum().mag()<< G4endl;
651                     G4cout << "  negative Exci << 504 //#endif
652                     G4cout << "return 4, excit << 505   }
653             #endif                             << 506   ClearAndDestroy(products);
654                                                << 507   return products;   // return empty products
655         ClearAndDestroy(products);             << 508   }
656         return products;   // return empty pro << 
657     }                                          << 
658                                                << 
659     G4ReactionProductVector * precompoundProdu << 
660                                                   509 
661                                                   510 
662     G4DecayKineticTracks decay(&theFinalState) << 511 // find a fragment and call the precompound model.
663     _DebugEpConservation("decayed");           << 512   G4Fragment * fragment = 0;
                                                   >> 513   G4ReactionProductVector * precompoundProducts = 0;
                                                   >> 514  
                                                   >> 515    if ( ExcitationEnergy >= 0 ) 
                                                   >> 516    {
                                                   >> 517        fragment = FindFragments();
664                                                   518 
665     products= ProductsAddFinalState(products,  << 519     //  theDeExcitation =0;
                                                   >> 520        if(fragment && fragment->GetA() >1.5) // hpw @@@@ still to add the nucleon, if one exists.
                                                   >> 521        {
                                                   >> 522    if (theDeExcitation)
                                                   >> 523    {
                                                   >> 524              precompoundProducts= theDeExcitation->DeExcite(*fragment);
                                                   >> 525              delete fragment;
                                                   >> 526              fragment=0;
                                                   >> 527    } else if (theExcitationHandler)
                                                   >> 528    {
                                                   >> 529        precompoundProducts=theExcitationHandler->BreakItUp(*fragment);
                                                   >> 530              delete fragment;
                                                   >> 531              fragment=0;
                                                   >> 532    }
                                                   >> 533        } else {
                                                   >> 534          if ( theTargetList.size() == 1 )
                                                   >> 535    {
                                                   >> 536        precompoundProducts = new G4ReactionProductVector();
                                                   >> 537        std::vector<G4KineticTrack *>::iterator i=theTargetList.begin();
                                                   >> 538        G4ReactionProduct * aNew = new G4ReactionProduct((*i)->GetDefinition());
                                                   >> 539        aNew->SetTotalEnergy((*i)->GetDefinition()->GetPDGMass());       
                                                   >> 540        aNew->SetMomentum(G4ThreeVector(0));   // see boost fro preCompoundProducts below..
                                                   >> 541        precompoundProducts->push_back(aNew);
                                                   >> 542     } else if ( theTargetList.size() > 1)
                                                   >> 543     {
                                                   >> 544        precompoundProducts = new G4ReactionProductVector();
                                                   >> 545        std::vector<G4KineticTrack *>::iterator aNuc;
                                                   >> 546        G4LorentzVector aVec;
                                                   >> 547        std::vector<G4double> masses;
                                                   >> 548        G4double sumMass(0);
                                                   >> 549        for ( aNuc=theTargetList.begin(); aNuc != theTargetList.end(); aNuc++)
                                                   >> 550        {
                                                   >> 551           G4double mass=(*aNuc)->GetDefinition()->GetPDGMass();
                                                   >> 552     masses.push_back(mass);
                                                   >> 553     sumMass += mass;
                                                   >> 554        }
                                                   >> 555        G4LorentzVector finalP=GetFinal4Momentum();
                                                   >> 556        G4FermiPhaseSpaceDecay decay;
                                                   >> 557 //       G4cout << " some neutrons? " << masses.size() <<" " << theTargetList.size()<<" "<<finalP <<" " << finalP.mag()<<G4endl;
                                                   >> 558              G4double eCMS=finalP.mag();
                                                   >> 559        if ( eCMS < sumMass )                    // @@GF --- Cheat!!
                                                   >> 560        {
                                                   >> 561           eCMS=sumMass + (2*MeV*masses.size());     
                                                   >> 562     finalP.setE(std::sqrt(finalP.vect().mag2() + sqr(eCMS)));
                                                   >> 563        }
                                                   >> 564        precompoundLorentzboost.set(finalP.boostVector());
                                                   >> 565        std::vector<G4LorentzVector*> * momenta=decay.Decay(eCMS,masses);
                                                   >> 566        std::vector<G4LorentzVector*>::iterator aMom=momenta->begin();
                                                   >> 567        for ( aNuc=theTargetList.begin(); 
                                                   >> 568             (aNuc != theTargetList.end()) && (aMom!=momenta->end()); 
                                                   >> 569       aNuc++, aMom++ )
                                                   >> 570        {
                                                   >> 571           G4ReactionProduct * aNew = new G4ReactionProduct((*aNuc)->GetDefinition());
                                                   >> 572     aNew->SetTotalEnergy((*aMom)->e());
                                                   >> 573     aNew->SetMomentum((*aMom)->vect());
                                                   >> 574     precompoundProducts->push_back(aNew);
                                                   >> 575 //    G4cout << " only neutrons? " <<  (*aNuc)->GetDefinition()->GetParticleName() << G4endl;
                                                   >> 576                 delete *aMom;
                                                   >> 577        }
                                                   >> 578        delete momenta;
                                                   >> 579     }
                                                   >> 580        }
666                                                   581 
667     products= ProductsAddPrecompound(products, << 582    } 
668                                                   583 
669 //    products=ProductsAddFakeGamma(products); << 584   {
                                                   >> 585 // fill in products the outgoing particles
                                                   >> 586      G4double Ekinout=0;
                                                   >> 587      size_t i(0);
                                                   >> 588      for(i = 0; i< theFinalState.size(); i++)
                                                   >> 589      {
                                                   >> 590        G4KineticTrack * kt = theFinalState[i];
                                                   >> 591        if(kt->GetDefinition()->IsShortLived())
                                                   >> 592        {
                                                   >> 593          G4KineticTrackVector * dec = kt->Decay();
                                                   >> 594    G4KineticTrackVector::const_iterator jter;
                                                   >> 595    for(jter=dec->begin(); jter != dec->end(); jter++)
                                                   >> 596    {
                                                   >> 597      theFinalState.push_back(*jter);
                                                   >> 598    }
                                                   >> 599    delete dec;
                                                   >> 600        }
                                                   >> 601        else
                                                   >> 602        {
                                                   >> 603    G4ReactionProduct * aNew = new G4ReactionProduct(kt->GetDefinition());
                                                   >> 604    aNew->SetMomentum(kt->Get4Momentum().vect());
                                                   >> 605    aNew->SetTotalEnergy(kt->Get4Momentum().e());
                                                   >> 606    Ekinout += aNew->GetKineticEnergy();
                                                   >> 607    if(kt->IsParticipant()) 
                                                   >> 608    {
                                                   >> 609      aNew->SetNewlyAdded(true);
                                                   >> 610    }
                                                   >> 611    else
                                                   >> 612    {
                                                   >> 613      aNew->SetNewlyAdded(false);
                                                   >> 614    }
                                                   >> 615    //G4cout << " Particle Ekin " << aNew->GetKineticEnergy() << G4endl;
                                                   >> 616    products->push_back(aNew);
670                                                   617 
                                                   >> 618    #ifdef debug_BIC_Propagate_finals
                                                   >> 619    if (! kt->GetDefinition()->GetPDGStable() )
                                                   >> 620    {
                                                   >> 621              if (kt->GetDefinition()->IsShortLived())
                                                   >> 622        {
                                                   >> 623     G4cout << "final shortlived : ";
                                                   >> 624        } else
                                                   >> 625        {
                                                   >> 626     G4cout << "final un stable : ";
                                                   >> 627        }
                                                   >> 628        G4cout <<kt->GetDefinition()->GetParticleName()<< G4endl;
                                                   >> 629    }
                                                   >> 630    #endif
                                                   >> 631        }
671                                                   632 
672     thePrimaryEscape = true;                   << 633      }
                                                   >> 634      //G4cout << " Total Ekin " << Ekinout << G4endl;
                                                   >> 635   }
                                                   >> 636 // add precompound products to products
                                                   >> 637   if ( precompoundProducts )
                                                   >> 638   {
                                                   >> 639        std::vector<G4ReactionProduct *>::iterator j;
                                                   >> 640        for(j = precompoundProducts->begin(); j != precompoundProducts->end(); ++j)
                                                   >> 641        {
                                                   >> 642 // boost back to system of moving nucleus
                                                   >> 643          G4LorentzVector pProduct((*j)->GetMomentum(),(*j)->GetTotalEnergy());
                                                   >> 644 #ifdef debug_BIC_Propagate_finals
                                                   >> 645    G4cout << " pProduct be4 boost " <<pProduct << G4endl;
                                                   >> 646 #endif
                                                   >> 647    pProduct *= precompoundLorentzboost;
                                                   >> 648 #ifdef debug_BIC_Propagate_finals
                                                   >> 649    G4cout << " pProduct aft boost " <<pProduct << G4endl;
                                                   >> 650 #endif
                                                   >> 651          (*j)->SetTotalEnergy(pProduct.e());
                                                   >> 652          (*j)->SetMomentum(pProduct.vect());
                                                   >> 653    (*j)->SetNewlyAdded(true);
                                                   >> 654    products->push_back(*j);
                                                   >> 655        }
673                                                   656 
674     #ifdef debug_BIC_return                    << 657        precompoundProducts->clear();
675     G4cout << "BIC: return @end, all ok "<< G4 << 658        delete precompoundProducts;
676     //G4cout << "  return products " << produc << 659   }
677     #endif                                     << 660   else
                                                   >> 661   {
                                                   >> 662    G4ReactionProduct * aNew=0;
                                                   >> 663 // return nucleus e and p
                                                   >> 664    if  (fragment != 0 ) {
                                                   >> 665        aNew = new G4ReactionProduct(G4Gamma::GammaDefinition());   // we only want to pass e/p
                                                   >> 666        aNew->SetMomentum(fragment->GetMomentum().vect());
                                                   >> 667        aNew->SetTotalEnergy(fragment->GetMomentum().e());
                                                   >> 668        delete fragment;
                                                   >> 669        fragment=0;
                                                   >> 670    } else if (products->size() == 0) {
                                                   >> 671    // FixMe GF: for testing without precompound, return 1 gamma of 0.01 MeV in +x
                                                   >> 672 #include "G4Gamma.hh"
                                                   >> 673        aNew = new G4ReactionProduct(G4Gamma::GammaDefinition());
                                                   >> 674        aNew->SetMomentum(G4ThreeVector(0.01*MeV,0,0));
                                                   >> 675        aNew->SetTotalEnergy(0.01*MeV);
                                                   >> 676    }
                                                   >> 677    if ( aNew != 0 ) products->push_back(aNew);
                                                   >> 678   }
678                                                   679 
679     return products;                           << 680 //  G4cerr <<"mon - end of event       "<<G4endl;
                                                   >> 681   thePrimaryEscape = true;
                                                   >> 682   return products;
680 }                                                 683 }
681                                                   684 
                                                   >> 685 
682 //--------------------------------------------    686 //----------------------------------------------------------------------------
683 G4double G4BinaryCascade::GetExcitationEnergy(    687 G4double G4BinaryCascade::GetExcitationEnergy()
684 //--------------------------------------------    688 //----------------------------------------------------------------------------
685 {                                                 689 {
686                                                   690 
687     // get A and Z for the residual nucleus    << 691   G4ping debug("debug_ExcitationEnergy");
688 #if defined(debug_G4BinaryCascade) || defined( << 692 // get A and Z for the residual nucleus
689     G4int finalA = theTargetList.size()+theCap << 693   #ifdef debug_G4BinaryCascade
690     G4int finalZ = GetTotalCharge(theTargetLis << 694   G4int finalA = theTargetList.size()+theCapturedList.size();
691     if ( (currentA - finalA) != 0 || (currentZ << 695   G4int finalZ = GetTotalCharge(theTargetList)+GetTotalCharge(theCapturedList);
692     {                                          << 696   if ( (currentA - finalA) != 0 || (currentZ - finalZ) != 0 )
693         G4cerr << "G4BIC:GetExcitationEnergy() << 697   {
694                 << "("<< currentA << "," << fi << 698      G4cerr << "G4BIC:GetExcitationEnergy(): Nucleon counting error current/final{A,Z} " 
695     }                                          << 699             << currentA << " " << finalA << " "<< currentZ << " " << finalZ << G4endl;
                                                   >> 700   }
                                                   >> 701   
                                                   >> 702   #endif
                                                   >> 703 
                                                   >> 704   G4double excitationE(0);
                                                   >> 705   G4double nucleusMass(0);
                                                   >> 706   if(currentZ>.5)
                                                   >> 707   {
                                                   >> 708      nucleusMass = G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(currentZ,currentA);
                                                   >> 709   } 
                                                   >> 710   else if (currentZ==0 && currentA==1 )
                                                   >> 711   {
                                                   >> 712      nucleusMass = G4Neutron::Neutron()->GetPDGMass();
                                                   >> 713   } 
                                                   >> 714   else
                                                   >> 715   {
                                                   >> 716      #ifdef debug_BinaryCascade
                                                   >> 717      G4cout << "G4BinaryCascade::GetExcitationEnergy(): Warning - invalid nucleus (A,Z)=("
                                                   >> 718       << currentA << "," << currentZ << ")" << G4endl;
                                                   >> 719      #endif
                                                   >> 720      return 0;
                                                   >> 721   }
696                                                   722 
697 #endif                                         << 723   #ifdef debug_BIC_GetExcitationEnergy
                                                   >> 724   debug.push_back("====> current A, Z");
                                                   >> 725   debug.push_back(currentZ);
                                                   >> 726   debug.push_back(currentA);
                                                   >> 727   debug.push_back(finalZ);
                                                   >> 728   debug.push_back(finalA);
                                                   >> 729   debug.push_back(nucleusMass);
                                                   >> 730   debug.push_back(GetFinalNucleusMomentum().mag());
                                                   >> 731   debug.dump();
                                                   >> 732 //  PrintKTVector(&theTargetList, std::string(" current target list info"));
                                                   >> 733   PrintKTVector(&theCapturedList, std::string(" current captured list info"));
                                                   >> 734   #endif
698                                                   735 
699     G4double excitationE(0);                   << 736   excitationE = GetFinalNucleusMomentum().mag() - nucleusMass;
700     G4double nucleusMass(0);                   << 
701     if(currentZ>.5)                            << 
702     {                                          << 
703         nucleusMass = GetIonMass(currentZ,curr << 
704     }                                          << 
705     else if (currentZ==0 )                     << 
706     {                                          << 
707         if(currentA == 1) {nucleusMass = G4Neu << 
708         else              {nucleusMass = GetFi << 
709     }                                          << 
710     else                                       << 
711     {                                          << 
712 #ifdef debug_G4BinaryCascade                   << 
713         G4cout << "G4BinaryCascade::GetExcitat << 
714                 << currentA << "," << currentZ << 
715 #endif                                         << 
716         return 0;                              << 
717     }                                          << 
718                                                   737 
719 #ifdef debug_BIC_GetExcitationEnergy              738 #ifdef debug_BIC_GetExcitationEnergy
720     G4ping debug("debug_ExcitationEnergy");    << 739 // ------ debug
721     debug.push_back("====> current A, Z");     << 740   if ( excitationE < 0 )
722     debug.push_back(currentZ);                 << 741   {
723     debug.push_back(currentA);                 << 742      G4cout << "negative ExE final Ion mass" <<nucleusMass<< G4endl;
724     debug.push_back("====> final A, Z");       << 743      G4LorentzVector Nucl_mom=GetFinalNucleusMomentum();
725     debug.push_back(finalZ);                   << 744     if(finalZ>.5) G4cout << " Final nuclmom/mass " << Nucl_mom << " " << Nucl_mom.mag()  
726     debug.push_back(finalA);                   << 745            << " (A,Z)=("<< finalA <<","<<finalZ <<")"
727     debug.push_back(nucleusMass);              << 746            << " mass " << nucleusMass << " " 
728     debug.push_back(GetFinalNucleusMomentum(). << 747                  << " excitE " << excitationE << G4endl;
729     debug.dump();                              << 
730     //  PrintKTVector(&theTargetList, std::str << 
731     //PrintKTVector(&theCapturedList, std::str << 
732 #endif                                         << 
733                                                << 
734     excitationE = GetFinalNucleusMomentum().ma << 
735                                                << 
736     //G4double exE2 = GetFinal4Momentum().mag( << 
737                                                   748 
738     //G4cout << "old/new excitE " << excitatio << 
739                                                   749 
740 #ifdef debug_BIC_GetExcitationEnergy           << 750     G4int A = the3DNucleus->GetMassNumber();
741     // ------ debug                            << 751     G4int Z = the3DNucleus->GetCharge();
742     if ( excitationE < 0 )                     << 752     G4double initialExc(0);
                                                   >> 753     if(Z>.5)
743     {                                             754     {
744         G4cout << "negative ExE final Ion mass << 755       initialExc = theInitial4Mom.mag()-
745         G4LorentzVector Nucl_mom=GetFinalNucle << 756            G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(Z, A);
746         if(finalZ>.5) G4cout << " Final nuclmo << 757      G4cout << " Initial nucleus A Z" << A << " " << Z << initialExc << G4endl; 
747                        << " (A,Z)=("<< finalA  << 
748                        << " mass " << nucleusM << 
749                        << " excitE " << excita << 
750                                                << 
751                                                << 
752         G4int A = the3DNucleus->GetMassNumber( << 
753         G4int Z = the3DNucleus->GetCharge();   << 
754         G4double initialExc(0);                << 
755         if(Z>.5)                               << 
756         {                                      << 
757             initialExc = theInitial4Mom.mag()- << 
758             G4cout << "GetExcitationEnergy: In << 
759         }                                      << 
760     }                                             758     }
                                                   >> 759   }
761                                                   760 
762 #endif                                            761 #endif
763                                                   762 
764     return excitationE;                        << 763   return excitationE;
765 }                                                 764 }
766                                                   765 
767                                                   766 
768 //--------------------------------------------    767 //----------------------------------------------------------------------------
769 //                                                768 //
770 //       P R I V A T E   M E M B E R   F U N C    769 //       P R I V A T E   M E M B E R   F U N C T I O N S
771 //                                                770 //
772 //--------------------------------------------    771 //----------------------------------------------------------------------------
773                                                   772 
774 //--------------------------------------------    773 //----------------------------------------------------------------------------
775 void G4BinaryCascade::BuildTargetList()           774 void G4BinaryCascade::BuildTargetList()
776 //--------------------------------------------    775 //----------------------------------------------------------------------------
777 {                                                 776 {
778                                                   777 
779     if(!the3DNucleus->StartLoop())             << 778   if(!the3DNucleus->StartLoop())
780     {                                          << 779   {
781         //    G4cerr << "G4BinaryCascade::Buil << 780 //    G4cerr << "G4BinaryCascade::BuildTargetList(): StartLoop() error!"
782         //     << G4endl;                      << 781 //     << G4endl;
783         return;                                << 782     return;
784     }                                          << 783   }
785                                                << 784 
786     ClearAndDestroy(&theTargetList);  // clear << 785   G4Nucleon * nucleon;
787                                                << 786   G4ParticleDefinition * definition;
788     G4Nucleon * nucleon;                       << 787   G4ThreeVector pos;
789     const G4ParticleDefinition * definition;   << 788   G4LorentzVector mom;
790     G4ThreeVector pos;                         << 789 // if there are nucleon hit by higher energy models, then SUM(momenta) != 0
791     G4LorentzVector mom;                       << 790   theInitial4Mom = G4LorentzVector(0,0,0,0);
792     // if there are nucleon hit by higher ener << 791   currentA=0;
793     initialZ=the3DNucleus->GetCharge();        << 792   currentZ=0;
794     initialA=the3DNucleus->GetMassNumber();    << 793 //  G4RKPropagation * RKprop=(G4RKPropagation *)thePropagator;
795     initial_nuclear_mass=GetIonMass(initialZ,i << 794   while((nucleon = the3DNucleus->GetNextNucleon()) != NULL)
796     theInitial4Mom = G4LorentzVector(0,0,0,ini << 795   {
797     currentA=0;                                << 796 // check if nucleon is hit by higher energy model.
798     currentZ=0;                                << 797      if ( ! nucleon->AreYouHit() )
799     while((nucleon = the3DNucleus->GetNextNucl << 798      {
800     {                                          << 799   definition = nucleon->GetDefinition();
801         // check if nucleon is hit by higher e << 800   pos = nucleon->GetPosition();
802         if ( ! nucleon->AreYouHit() )          << 801   mom = nucleon->GetMomentum();
803         {                                      << 802  //    G4cout << "Nucleus " << pos.mag()/fermi << " " << mom.e() << G4endl;
804             definition = nucleon->GetDefinitio << 803   theInitial4Mom += mom;
805             pos = nucleon->GetPosition();      << 804 //   In the kinetic Model, the potential inside the nucleus is taken into account, and nucleons
806             mom = nucleon->GetMomentum();      << 805 //    are on mass shell.
807             //    G4cout << "Nucleus " << pos. << 806   mom.setE( std::sqrt( mom.vect().mag2() + sqr(definition->GetPDGMass()) ) );
808             //theInitial4Mom += mom;           << 807   G4KineticTrack * kt = new G4KineticTrack(definition, 0., pos, mom);
809             //        the potential inside the << 808   kt->SetState(G4KineticTrack::inside);
810             mom.setE( std::sqrt( mom.vect().ma << 809   kt->SetNucleon(nucleon);
811             G4KineticTrack * kt = new G4Kineti << 810   theTargetList.push_back(kt);
812             kt->SetState(G4KineticTrack::insid << 811   ++currentA;
813             kt->SetNucleon(nucleon);           << 812   if (definition->GetPDGCharge() > .5 ) ++currentZ;
814             theTargetList.push_back(kt);       << 813      }
815             ++currentA;                        << 814   }
816             if (definition->GetPDGCharge() > . << 815   massInNucleus = 0;
817         }                                      << 816   if(currentZ>.5)
818                                                << 817   {
819 #ifdef debug_BIC_BuildTargetList               << 818      massInNucleus = G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(currentZ,currentA);
820         else { G4cout << "nucleon is hit" << n << 819   } else if (currentZ==0 && currentA>=1 )
821 #endif                                         << 820   {
822     }                                          << 821      massInNucleus = currentA * G4Neutron::Neutron()->GetPDGMass();
823     massInNucleus = 0;                         << 822   } else
824     if(currentZ>.5)                            << 823   {
825     {                                          << 824      //G4cout << "G4BinaryCascade::BuildTargetList(): Warning - invalid nucleus (A,Z)=("
826         massInNucleus = GetIonMass(currentZ,cu << 825   //  << currentA << "," << currentZ << ")" << G4endl;
827     } else if (currentZ==0 && currentA>=1 )    << 826   }
828     {                                          << 827      //G4cout << "G4BinaryCascade::BuildTargetList():  nucleus (A,Z)=("
829         massInNucleus = currentA * G4Neutron:: << 828   //  << currentA << "," << currentZ << ") mass: " << massInNucleus <<
830     } else                                     << 829   //  ", theInitial4Mom " << theInitial4Mom << G4endl;
831     {                                          << 830     
832         G4cerr << "G4BinaryCascade::BuildTarge << 831   currentInitialEnergy= theInitial4Mom.e();
833                 << currentA << "," << currentZ << 832   G4KineticTrackVector::iterator i;
834         throw G4HadronicException(__FILE__, __ << 833   for(i = theProjectileList.begin() ; i != theProjectileList.end(); ++i)
835     }                                          << 834   {
836     currentInitialEnergy= theInitial4Mom.e() + << 835     currentInitialEnergy+= (*i)->GetTrackingMomentum().e();
837                                                << 836   }
838 #ifdef debug_BIC_BuildTargetList               << 837   
839     G4cout << "G4BinaryCascade::BuildTargetLis << 
840             << currentA << "," << currentZ <<  << 
841             ", theInitial4Mom " << theInitial4 << 
842             ", currentInitialEnergy " << curre << 
843 #endif                                         << 
844                                                << 
845 }                                              << 
846                                                << 
847 //-------------------------------------------- << 
848 G4bool  G4BinaryCascade::BuildLateParticleColl << 
849 //-------------------------------------------- << 
850 {                                              << 
851    G4bool success(false);                      << 
852    std::vector<G4KineticTrack *>::iterator ite << 
853                                                << 
854    lateA=lateZ=0;                              << 
855    projectileA=projectileZ=0;                  << 
856                                                << 
857    G4double StartingTime=DBL_MAX;        // Se << 
858    for(iter = secondaries->begin(); iter != se << 
859    {                                           << 
860       if((*iter)->GetFormationTime() < Startin << 
861          StartingTime = (*iter)->GetFormationT << 
862    }                                           << 
863                                                << 
864    //PrintKTVector(secondaries, "initial late  << 
865    G4LorentzVector lateParticles4Momentum(0,0, << 
866    for(iter = secondaries->begin(); iter != se << 
867    {                                           << 
868       //  G4cout << " Formation time : " << (* << 
869       //   << (*iter)->GetFormationTime() << G << 
870       G4double FormTime = (*iter)->GetFormatio << 
871       (*iter)->SetFormationTime(FormTime);     << 
872       if( (*iter)->GetState() == G4KineticTrac << 
873       {                                        << 
874          FindLateParticleCollision(*iter);     << 
875          lateParticles4Momentum += (*iter)->Ge << 
876          lateA += (*iter)->GetDefinition()->Ge << 
877          lateZ += G4lrint((*iter)->GetDefiniti << 
878          //PrintKTVector(*iter, "late particle << 
879       } else                                   << 
880       {                                        << 
881          theSecondaryList.push_back(*iter);    << 
882          //PrintKTVector(*iter, "incoming part << 
883          theProjectile4Momentum += (*iter)->Ge << 
884          projectileA += (*iter)->GetDefinition << 
885          projectileZ += G4lrint((*iter)->GetDe << 
886 #ifdef debug_BIC_Propagate                     << 
887          G4cout << " Adding initial secondary  << 
888                << " time" << (*iter)->GetForma << 
889                << ", state " << (*iter)->GetSt << 
890 #endif                                         << 
891       }                                        << 
892    }                                           << 
893    //theCollisionMgr->Print();                 << 
894    const G4HadProjectile * primary = GetPrimar << 
895                                                << 
896    if (primary){                               << 
897       G4LorentzVector mom=primary->Get4Momentu << 
898       theProjectile4Momentum += mom;           << 
899       projectileA = primary->GetDefinition()-> << 
900       projectileZ = G4lrint(primary->GetDefini << 
901       // now check if "excitation" energy left << 
902       G4double excitation= theProjectile4Momen << 
903 #ifdef debug_BIC_GetExcitationEnergy           << 
904       G4cout << "BIC: Proj.e, nucl initial, nu << 
905             << theProjectile4Momentum << ",  " << 
906             << initial_nuclear_mass<< ",  " << << 
907             << lateParticles4Momentum << G4end << 
908       G4cout << "BIC: Proj.e / initial excitat << 
909 #endif                                         << 
910       success = excitation > 0;                << 
911 #ifdef debug_G4BinaryCascade                   << 
912       if ( ! success ) {                       << 
913          G4cout << "G4BinaryCascade::BuildLate << 
914          //PrintKTVector(secondaries);         << 
915       }                                        << 
916 #endif                                         << 
917    } else {                                    << 
918       // no primary from HE model -> cascade   << 
919       success=true;                            << 
920    }                                           << 
921                                                << 
922    if (success) {                              << 
923       secondaries->clear(); // Don't leave "G4 << 
924       delete secondaries;                      << 
925    }                                           << 
926    return success;                             << 
927 }                                              << 
928                                                << 
929 //-------------------------------------------- << 
930 G4ReactionProductVector *  G4BinaryCascade::De << 
931 //-------------------------------------------- << 
932 {                                              << 
933    // find a fragment and call the precompound << 
934    G4Fragment * fragment = nullptr;            << 
935    G4ReactionProductVector * precompoundProduc << 
936                                                << 
937    G4LorentzVector pFragment(0);               << 
938    // G4cout << " final4mon " << GetFinal4Mome << 
939                                                << 
940    fragment = FindFragments();                 << 
941                                                << 
942    if(fragment)                                << 
943    {                                           << 
944       if(fragment->GetA_asInt() >1)            << 
945       {                                        << 
946          pFragment=fragment->GetMomentum();    << 
947          // G4cout << " going to preco with fr << 
948          if (theDeExcitation)                / << 
949          {                                     << 
950             precompoundProducts= theDeExcitati << 
951          }                                     << 
952          else if (theExcitationHandler)    //  << 
953          {                                     << 
954             precompoundProducts=theExcitationH << 
955          }                                     << 
956                                                << 
957       } else                                   << 
958       {                                   // f << 
959          if (theTargetList.size() + theCapture << 
960             throw G4HadronicException(__FILE__ << 
961          }                                     << 
962                                                << 
963          std::vector<G4KineticTrack *>::iterat << 
964          if ( theTargetList.size() == 1 )  {i= << 
965          if ( theCapturedList.size() == 1 ) {i << 
966          G4ReactionProduct * aNew = new G4Reac << 
967          aNew->SetTotalEnergy((*i)->GetDefinit << 
968          aNew->SetCreatorModelID(theBIC_ID);   << 
969    aNew->SetParentResonanceDef((*i)->GetParent << 
970    aNew->SetParentResonanceID((*i)->GetParentR << 
971          aNew->SetMomentum(G4ThreeVector(0));/ << 
972          precompoundProducts = new G4ReactionP << 
973          precompoundProducts->push_back(aNew); << 
974       }                            // End of f << 
975       delete fragment;                         << 
976       fragment=nullptr;                        << 
977                                                << 
978    } else                            // End of << 
979    {                                 // No fra << 
980                                                   838 
981       precompoundProducts = DecayVoidNucleus() << 
982    }                                           << 
983    #ifdef debug_BIC_DeexcitationProducts       << 
984                                                << 
985        G4LorentzVector fragment_momentum=GetFi << 
986        G4LorentzVector Preco_momentum;         << 
987        if ( precompoundProducts )              << 
988        {                                       << 
989           std::vector<G4ReactionProduct *>::it << 
990           for(j = precompoundProducts->begin() << 
991           {                                    << 
992              G4LorentzVector pProduct((*j)->Ge << 
993              Preco_momentum += pProduct;       << 
994            }                                   << 
995        }                                       << 
996        G4cout << "finalNuclMom / sum preco pro << 
997            << " delta E "<< fragment_momentum. << 
998                                                << 
999    #endif                                      << 
1000                                               << 
1001    return precompoundProducts;                << 
1002 }                                                839 }
1003                                                  840 
1004 //------------------------------------------- << 
1005 G4ReactionProductVector *  G4BinaryCascade::D << 
1006 //------------------------------------------- << 
1007 {                                             << 
1008    G4ReactionProductVector * result = nullptr << 
1009    if ( (theTargetList.size()+theCapturedList << 
1010    {                                          << 
1011       result = new G4ReactionProductVector;   << 
1012       std::vector<G4KineticTrack *>::iterator << 
1013       G4LorentzVector aVec;                   << 
1014       std::vector<G4double> masses;           << 
1015       G4double sumMass(0);                    << 
1016                                               << 
1017       if ( theTargetList.size() != 0)         << 
1018       {                                       << 
1019          for ( aNuc=theTargetList.begin(); aN << 
1020          {                                    << 
1021             G4double mass=(*aNuc)->GetDefinit << 
1022             masses.push_back(mass);           << 
1023             sumMass += mass;                  << 
1024          }                                    << 
1025       }                                       << 
1026                                               << 
1027       if ( theCapturedList.size() != 0)       << 
1028       {                                       << 
1029          for(aNuc = theCapturedList.begin();  << 
1030          {                                    << 
1031             G4double mass=(*aNuc)->GetDefinit << 
1032             masses.push_back(mass);           << 
1033             sumMass += mass;                  << 
1034          }                                    << 
1035       }                                       << 
1036                                               << 
1037       G4LorentzVector finalP=GetFinal4Momentu << 
1038       G4FermiPhaseSpaceDecay decay;           << 
1039       // G4cout << " some neutrons? " << mass << 
1040       // G4cout<< theTargetList.size()<<" "<< << 
1041                                               << 
1042       G4double eCMS=finalP.mag();             << 
1043       if ( eCMS < sumMass )                   << 
1044       {                                       << 
1045          eCMS=sumMass + 2*MeV*masses.size();  << 
1046          finalP.setE(std::sqrt(finalP.vect(). << 
1047       }                                       << 
1048                                               << 
1049       precompoundLorentzboost.set(finalP.boos << 
1050       std::vector<G4LorentzVector*> * momenta << 
1051       std::vector<G4LorentzVector*>::iterator << 
1052                                               << 
1053                                               << 
1054       if ( theTargetList.size() != 0)         << 
1055       {                                       << 
1056          for ( aNuc=theTargetList.begin();    << 
1057                (aNuc != theTargetList.end())  << 
1058                aNuc++, aMom++ )               << 
1059          {                                    << 
1060             G4ReactionProduct * aNew = new G4 << 
1061             aNew->SetTotalEnergy((*aMom)->e() << 
1062             aNew->SetMomentum((*aMom)->vect() << 
1063             aNew->SetCreatorModelID(theBIC_ID << 
1064       aNew->SetParentResonanceDef((*aNuc)->Ge << 
1065       aNew->SetParentResonanceID((*aNuc)->Get << 
1066             result->push_back(aNew);          << 
1067             delete *aMom;                     << 
1068          }                                    << 
1069       }                                       << 
1070                                               << 
1071       if ( theCapturedList.size() != 0)       << 
1072       {                                       << 
1073          for ( aNuc=theCapturedList.begin();  << 
1074                (aNuc != theCapturedList.end() << 
1075                aNuc++, aMom++ )               << 
1076          {                                    << 
1077             G4ReactionProduct * aNew = new G4 << 
1078             aNew->SetTotalEnergy((*aMom)->e() << 
1079             aNew->SetMomentum((*aMom)->vect() << 
1080             aNew->SetCreatorModelID(theBIC_ID << 
1081             aNew->SetParentResonanceDef((*aNu << 
1082             aNew->SetParentResonanceID((*aNuc << 
1083             result->push_back(aNew);          << 
1084             delete *aMom;                     << 
1085          }                                    << 
1086       }                                       << 
1087                                               << 
1088       delete momenta;                         << 
1089    }                                          << 
1090    return result;                             << 
1091 }                   // End if(!fragment)      << 
1092                                               << 
1093 //------------------------------------------- << 
1094 G4ReactionProductVector * G4BinaryCascade::Pr << 
1095 //------------------------------------------- << 
1096 {                                             << 
1097 // fill in products the outgoing particles    << 
1098     std::size_t i(0);                         << 
1099 #ifdef debug_BIC_Propagate_finals             << 
1100     G4LorentzVector mom_fs;                   << 
1101 #endif                                        << 
1102     for(i = 0; i< fs.size(); i++)             << 
1103     {                                         << 
1104         G4KineticTrack * kt = fs[i];          << 
1105         G4ReactionProduct * aNew = new G4Reac << 
1106         aNew->SetMomentum(kt->Get4Momentum(). << 
1107         aNew->SetTotalEnergy(kt->Get4Momentum << 
1108         aNew->SetNewlyAdded(kt->IsParticipant << 
1109         aNew->SetCreatorModelID(theBIC_ID);   << 
1110         aNew->SetParentResonanceDef(kt->GetPa << 
1111         aNew->SetParentResonanceID(kt->GetPar << 
1112         products->push_back(aNew);            << 
1113                                               << 
1114 #ifdef debug_BIC_Propagate_finals             << 
1115         mom_fs += kt->Get4Momentum();         << 
1116         G4cout <<kt->GetDefinition()->GetPart << 
1117         G4cout << " Particle Ekin " << aNew-> << 
1118         G4cout << ", is " << (kt->GetDefiniti << 
1119                 (kt->GetDefinition()->IsShort << 
1120         G4cout << G4endl;                     << 
1121 #endif                                        << 
1122                                               << 
1123     }                                         << 
1124 #ifdef debug_BIC_Propagate_finals             << 
1125     G4cout << " Final state momentum " << mom << 
1126 #endif                                        << 
1127                                                  841 
1128     return products;                          << 
1129 }                                             << 
1130 //-------------------------------------------    842 //----------------------------------------------------------------------------
1131 G4ReactionProductVector * G4BinaryCascade::Pr << 843 void  G4BinaryCascade::FindCollisions(G4KineticTrackVector * secondaries)
1132 //-------------------------------------------    844 //----------------------------------------------------------------------------
1133 {                                                845 {
1134    G4LorentzVector pSumPreco(0), pPreco(0);   << 846   for(std::vector<G4KineticTrack *>::iterator i = secondaries->begin();
1135                                               << 847      i != secondaries->end(); ++i)
1136    if ( precompoundProducts )                 << 848   {
1137    {                                          << 849     if ( (*i)->GetTrackingMomentum().mag2() < -1.*eV )
1138       for(auto j = precompoundProducts->cbegi << 850     {
                                                   >> 851       G4cout << "G4BinaryCascade::FindCollisions(): negative m2:" << (*i)->GetTrackingMomentum().mag2() << G4endl;
                                                   >> 852     } 
                                                   >> 853 for(std::vector<G4BCAction *>::iterator j = theImR.begin();
                                                   >> 854         j!=theImR.end(); j++)
                                                   >> 855     {
                                                   >> 856       const std::vector<G4CollisionInitialState *> & aCandList
                                                   >> 857           = (*j)->GetCollisions(*i, theTargetList, theCurrentTime);
                                                   >> 858       for(size_t count=0; count<aCandList.size(); count++)
1139       {                                          859       {
1140          // boost back to system of moving nu << 860         theCollisionMgr->AddCollision(aCandList[count]);
1141          G4LorentzVector pProduct((*j)->GetMo << 
1142          pPreco+= pProduct;                   << 
1143 #ifdef debug_BIC_Propagate_finals             << 
1144          G4cout << "BIC: pProduct be4 boost " << 
1145 #endif                                        << 
1146          pProduct *= precompoundLorentzboost; << 
1147 #ifdef debug_BIC_Propagate_finals             << 
1148          G4cout << "BIC: pProduct aft boost " << 
1149 #endif                                        << 
1150          pSumPreco += pProduct;               << 
1151          (*j)->SetTotalEnergy(pProduct.e());  << 
1152          (*j)->SetMomentum(pProduct.vect());  << 
1153          (*j)->SetNewlyAdded(true);           << 
1154          products->push_back(*j);             << 
1155       }                                          861       }
1156       // G4cout << " unboosted preco result m << 
1157       // G4cout << " preco result mom " << pS << 
1158       precompoundProducts->clear();           << 
1159       delete precompoundProducts;             << 
1160    }                                          << 
1161    return products;                           << 
1162 }                                             << 
1163 //------------------------------------------- << 
1164 void  G4BinaryCascade::FindCollisions(G4Kinet << 
1165 //------------------------------------------- << 
1166 {                                             << 
1167     for(auto i=secondaries->cbegin(); i!=seco << 
1168     {                                         << 
1169         for(auto j=theImR.cbegin(); j!=theImR << 
1170         {                                     << 
1171             //      G4cout << "G4BinaryCascad << 
1172             const std::vector<G4CollisionInit << 
1173             = (*j)->GetCollisions(*i, theTarg << 
1174             for(std::size_t count=0; count<aC << 
1175             {                                 << 
1176                 theCollisionMgr->AddCollision << 
1177                 //4cout << "================= << 
1178                 //theCollisionMgr->Print();   << 
1179             }                                 << 
1180         }                                     << 
1181     }                                            862     }
                                                   >> 863   }
1182 }                                                864 }
1183                                                  865 
1184                                               << 
1185 //-------------------------------------------    866 //----------------------------------------------------------------------------
1186 void  G4BinaryCascade::FindDecayCollision(G4K    867 void  G4BinaryCascade::FindDecayCollision(G4KineticTrack * secondary)
1187 //-------------------------------------------    868 //----------------------------------------------------------------------------
1188 {                                                869 {
1189     const auto& aCandList = theDecay->GetColl << 870     if ( secondary->GetTrackingMomentum().mag2() < -1.*eV )
1190     for(std::size_t count=0; count<aCandList. << 
1191     {                                         << 
1192         theCollisionMgr->AddCollision(aCandLi << 
1193     }                                         << 
1194 }                                             << 
1195                                               << 
1196 //------------------------------------------- << 
1197 void  G4BinaryCascade::FindLateParticleCollis << 
1198 //------------------------------------------- << 
1199 {                                             << 
1200                                               << 
1201     G4double tin=0., tout=0.;                 << 
1202     if (((G4RKPropagation*)thePropagator)->Ge << 
1203     {                                            871     {
1204         if ( tin > 0 )                        << 872       G4cout << "G4BinaryCascade::FindDecayCollision(): negative m2:" << secondary->GetTrackingMomentum().mag2() << G4endl;
1205         {                                     << 873     } 
1206             secondary->SetState(G4KineticTrac << 874     const std::vector<G4CollisionInitialState *> & aCandList
1207         } else if ( tout > 0 )                << 875         = theDecay->GetCollisions(secondary, theTargetList, theCurrentTime);
1208         {                                     << 876     for(size_t count=0; count<aCandList.size(); count++)
1209             secondary->SetState(G4KineticTrac << 
1210         } else {                              << 
1211             //G4cout << "G4BC set miss , tin, << 
1212             secondary->SetState(G4KineticTrac << 
1213         }                                     << 
1214     } else {                                  << 
1215         secondary->SetState(G4KineticTrack::m << 
1216         //G4cout << "G4BC set miss ,no inters << 
1217     }                                         << 
1218                                               << 
1219                                               << 
1220 #ifdef debug_BIC_FindCollision                << 
1221     G4cout << "FindLateP Particle, 4-mom, tim << 
1222             << secondary->GetDefinition()->Ge << 
1223             << secondary->Get4Momentum()      << 
1224             << " times " <<  tin << " " << to << 
1225             << secondary->GetState() << G4end << 
1226 #endif                                        << 
1227                                               << 
1228     const auto& aCandList = theLateParticle-> << 
1229     for(std::size_t count=0; count<aCandList. << 
1230     {                                            877     {
1231 #ifdef debug_BIC_FindCollision                << 878       theCollisionMgr->AddCollision(aCandList[count]);
1232         G4cout << " Adding a late Col : " <<  << 
1233 #endif                                        << 
1234         theCollisionMgr->AddCollision(aCandLi << 
1235     }                                            879     }
1236 }                                                880 }
1237                                                  881 
1238                                                  882 
1239 //-------------------------------------------    883 //----------------------------------------------------------------------------
1240 G4bool G4BinaryCascade::ApplyCollision(G4Coll    884 G4bool G4BinaryCascade::ApplyCollision(G4CollisionInitialState * collision)
1241 //-------------------------------------------    885 //----------------------------------------------------------------------------
1242 {                                                886 {
1243     G4KineticTrack * primary = collision->Get << 887   G4ping debug("debug_ApplyCollision");
1244                                               << 888   //G4cerr << "G4BinaryCascade::ApplyCollision start"<<G4endl;
1245 #ifdef debug_BIC_ApplyCollision               << 889   G4KineticTrack * primary = collision->GetPrimary();
1246     G4cerr << "G4BinaryCascade::ApplyCollisio << 890   if(primary->GetState() != G4KineticTrack::inside)
1247     theCollisionMgr->Print();                 << 891   {
1248     G4cout << "ApplyCollisions : projte 4mom  << 892 #ifdef debug_BinaryCascade
1249 #endif                                        << 893      G4cout << "G4BinaryCasacde::ApplyCollision(): StateError (ignored)" << primary << G4endl;
1250                                               << 894      G4KineticTrackVector debug;
1251     G4KineticTrackVector target_collection=co << 895      debug.push_back(primary);
1252     G4bool haveTarget=target_collection.size( << 896      PrintKTVector(&debug,std::string("primay- target"));
1253     if( haveTarget && (primary->GetState() != << 897      throw G4HadronicException(__FILE__, __LINE__, "G4BinaryCasacde::ApplyCollision()");
1254     {                                         << 898 #else
1255 #ifdef debug_G4BinaryCascade                  << 899      return false;
1256         G4cout << "G4BinaryCasacde::ApplyColl << 
1257         PrintKTVector(primary,std::string("pr << 
1258         PrintKTVector(&target_collection,std: << 
1259         collision->Print();                   << 
1260         G4cout << G4endl;                     << 
1261         theCollisionMgr->Print();             << 
1262         //*GF*     throw G4HadronicException( << 
1263 #endif                                           900 #endif
1264         return false;                         << 901   }
1265 //    } else {                                << 
1266 //       G4cout << "G4BinaryCasacde::ApplyCol << 
1267 //       PrintKTVector(primary,std::string("p << 
1268 //       G4double tin=0., tout=0.;            << 
1269 //       if (((G4RKPropagation*)thePropagator << 
1270 //       {                                    << 
1271 //           G4cout << "tin tout: " << tin << << 
1272 //       }                                    << 
1273                                               << 
1274     }                                         << 
1275                                               << 
1276     G4LorentzVector mom4Primary=primary->Get4 << 
1277                                               << 
1278     G4int initialBaryon(0);                   << 
1279     G4int initialCharge(0);                   << 
1280     if (primary->GetState() == G4KineticTrack << 
1281     {                                         << 
1282         initialBaryon = primary->GetDefinitio << 
1283         initialCharge = G4lrint(primary->GetD << 
1284     }                                         << 
1285                                               << 
1286     // for primary resonances, subtract neutr << 
1287     G4double initial_Efermi=CorrectShortlived << 
1288     //*************************************** << 
1289                                               << 
1290                                               << 
1291     G4KineticTrackVector * products = collisi << 
1292                                                  902 
                                                   >> 903   G4RKPropagation * RKprop=(G4RKPropagation *)thePropagator;
                                                   >> 904  
1293 #ifdef debug_BIC_ApplyCollision                  905 #ifdef debug_BIC_ApplyCollision
1294     DebugApplyCollisionFail(collision, produc << 906 //      G4cout << "ApplyCollisions : projte 4mom " << primary->GetTrackingMomentum()<< G4endl;
1295 #endif                                        << 
1296                                               << 
1297     // reset primary to initial state, in cas << 
1298     primary->Set4Momentum(mom4Primary);       << 
1299                                               << 
1300     G4bool lateParticleCollision= (!haveTarge << 
1301     G4bool decayCollision= (!haveTarget) && p << 
1302     G4bool Success(true);                     << 
1303                                               << 
1304                                               << 
1305 #ifdef debug_G4BinaryCascade                  << 
1306     G4int lateBaryon(0), lateCharge(0);       << 
1307 #endif                                        << 
1308                                               << 
1309     if ( lateParticleCollision )              << 
1310     {  // for late particles, reset charges   << 
1311         //G4cout << "lateP, initial B C state << 
1312         //        << initialCharge<< " " << p << 
1313 #ifdef debug_G4BinaryCascade                  << 
1314         lateBaryon = initialBaryon;           << 
1315         lateCharge = initialCharge;           << 
1316 #endif                                           907 #endif
1317         initialBaryon=initialCharge=0;        << 
1318         lateA -= primary->GetDefinition()->Ge << 
1319         lateZ -= G4lrint(primary->GetDefiniti << 
1320     }                                         << 
1321                                                  908 
1322     initialBaryon += collision->GetTargetBary << 909   G4int initialBaryon = primary->GetDefinition()->GetBaryonNumber();
1323     initialCharge += G4lrint(collision->GetTa << 910   G4int initialCharge(0);
1324     if (!lateParticleCollision)               << 911   initialCharge+=G4lrint(primary->GetDefinition()->GetPDGCharge());
1325     {                                         << 912 
1326        if( !products || products->size()==0 | << 913 // for primary resonances, subtract neutron ( = proton) field ( ie. add std::abs(field))
1327        {                                      << 914   G4int PDGcode=std::abs(primary->GetDefinition()->GetPDGEncoding());
1328 #ifdef debug_BIC_ApplyCollision               << 915   G4LorentzVector mom4Primary=primary->Get4Momentum();
1329           if (products) G4cout << " ======Fai << 916   G4double initial_Efermi=RKprop->GetField(primary->GetDefinition()->GetPDGEncoding(),primary->GetPosition());
1330           G4cerr << "G4BinaryCascade::ApplyCo << 917   if ( PDGcode > 1000 && PDGcode != 2112 && PDGcode != 2212 )
1331 #endif                                        << 918   {
1332           Success=false;                      << 919      initial_Efermi = RKprop->GetField(G4Neutron::Neutron()->GetPDGEncoding(),primary->GetPosition());
                                                   >> 920      primary->Update4Momentum(mom4Primary.e() - initial_Efermi);
                                                   >> 921   }
                                                   >> 922   G4KineticTrackVector target_collection=collision->GetTargetCollection();
                                                   >> 923   std::vector<G4KineticTrack *>::iterator titer;
                                                   >> 924   for ( titer=target_collection.begin() ; titer!=target_collection.end(); ++titer)
                                                   >> 925   {
                                                   >> 926      initial_Efermi+= RKprop->GetField((*titer)->GetDefinition()->GetPDGEncoding(),(*titer)->GetPosition());
                                                   >> 927   }
                                                   >> 928 
                                                   >> 929   G4KineticTrackVector * products=0;
                                                   >> 930   products = collision->GetFinalState();
                                                   >> 931   
                                                   >> 932   // reset primary to initial state
                                                   >> 933   primary->Set4Momentum(mom4Primary);
                                                   >> 934 
                                                   >> 935   initialBaryon += collision->GetTargetBaryonNumber();
                                                   >> 936   initialCharge+=G4lrint(collision->GetTargetCharge()); 
                                                   >> 937   
                                                   >> 938   if(!products || products->size()==0 || !CheckPauliPrinciple(products))
                                                   >> 939   {
                                                   >> 940    #ifdef debug_BIC_ApplyCollision
                                                   >> 941      if (products) G4cout << " ======Failed Pauli =====" << G4endl;
                                                   >> 942      G4cerr << "G4BinaryCascade::ApplyCollision blocked"<<G4endl;
                                                   >> 943    #endif
                                                   >> 944      if (products) ClearAndDestroy(products);
                                                   >> 945      if (target_collection.size() == 0 ) FindDecayCollision(primary);  // for decay, sample new decay
                                                   >> 946      delete products;
                                                   >> 947      return false;
                                                   >> 948   }
                                                   >> 949 
                                                   >> 950    G4double final_Efermi(0);
                                                   >> 951    G4KineticTrackVector resonances;
                                                   >> 952    for ( std::vector<G4KineticTrack *>::iterator i =products->begin(); i != products->end(); i++)
                                                   >> 953    {
                                                   >> 954        G4int PDGcode=std::abs((*i)->GetDefinition()->GetPDGEncoding());
                                                   >> 955        final_Efermi+=RKprop->GetField(PDGcode,(*i)->GetPosition());
                                                   >> 956        if ( PDGcode > 1000 && PDGcode != 2112 && PDGcode != 2212 )
                                                   >> 957        {  
                                                   >> 958     resonances.push_back(*i);
1333        }                                         959        }
                                                   >> 960    }  
                                                   >> 961    if ( resonances.size() > 0 ) 
                                                   >> 962    {  
                                                   >> 963       G4double delta_Fermi= (initial_Efermi-final_Efermi)/resonances.size();
                                                   >> 964       for (std::vector<G4KineticTrack *>::iterator res=resonances.begin(); res != resonances.end(); res++)
                                                   >> 965       {
                                                   >> 966     G4LorentzVector mom=(*res)->Get4Momentum();
                                                   >> 967     G4double mass2=mom.mag2();
                                                   >> 968     G4double newEnergy=mom.e() + delta_Fermi;
                                                   >> 969     G4double newEnergy2= newEnergy*newEnergy;
                                                   >> 970     if ( newEnergy2 < mass2 )
                                                   >> 971     {
                                                   >> 972        delete products;
                                                   >> 973        return false;
                                                   >> 974     }
                                                   >> 975 //    G4cout << " correct resonance from /to " << mom.e() << " / " << newEnergy<< G4endl;
                                                   >> 976     G4ThreeVector mom3=std::sqrt(newEnergy2 - mass2) * mom.vect().unit();
                                                   >> 977     (*res)->Set4Momentum(G4LorentzVector(mom3,newEnergy));
                                                   >> 978       }
                                                   >> 979    }
1334                                                  980 
                                                   >> 981       
1335                                                  982 
1336                                                  983 
1337        if (Success && primary->GetState() ==  << 
1338           if (! CorrectShortlivedFinalsForFer << 
1339              Success=false;                   << 
1340           }                                   << 
1341        }                                      << 
1342     }                                         << 
1343                                                  984 
                                                   >> 985 // debug block
1344 #ifdef debug_BIC_ApplyCollision                  986 #ifdef debug_BIC_ApplyCollision
1345     DebugApplyCollision(collision, products); << 987   G4KineticTrackVector debug1;
1346 #endif                                        << 988   debug1.push_back(collision->GetPrimary());
1347                                               << 989   PrintKTVector(&debug1,std::string(" Primary particle"));
1348     if ( ! Success ){                         << 990   PrintKTVector(&collision->GetTargetCollection(),std::string(" Target particles"));
1349         if (products) ClearAndDestroy(product << 991   PrintKTVector(products,std::string(" Scatterer products"));
1350         if ( decayCollision ) FindDecayCollis << 992   
1351         delete products;                      << 993   G4double thisExcitation(0);
1352         products=nullptr;                     << 994 //  excitation energy from this collision
1353         return false;                         << 995 //  initial state:
1354     }                                         << 996   G4double initial(0);
1355                                               << 997   G4KineticTrack * kt=collision->GetPrimary();
1356     G4int finalBaryon(0);                     << 998   initial +=  kt->Get4Momentum().e();
1357     G4int finalCharge(0);                     << 999   
1358     G4KineticTrackVector toFinalState;        << 1000   initial +=  RKprop->GetField(kt->GetDefinition()->GetPDGEncoding(),kt->GetPosition());
1359     for(auto i=products->cbegin(); i!=product << 1001   initial -=  RKprop->GetBarrier(kt->GetDefinition()->GetPDGEncoding());
1360     {                                         << 1002   G4cout << "prim. E/field/Barr/Sum " << kt->Get4Momentum().e()
1361         if ( ! lateParticleCollision )        << 1003           << " " << RKprop->GetField(kt->GetDefinition()->GetPDGEncoding(),kt->GetPosition())
1362         {                                     << 1004           << " " << RKprop->GetBarrier(kt->GetDefinition()->GetPDGEncoding()) 
1363             (*i)->SetState(primary->GetState( << 1005     << " " << initial << G4endl;;
1364             if ( (*i)->GetState() == G4Kineti << 1006   
1365                 finalBaryon+=(*i)->GetDefinit << 1007   G4KineticTrackVector ktv=collision->GetTargetCollection();
1366                 finalCharge+=G4lrint((*i)->Ge << 1008   for ( unsigned int it=0; it < ktv.size(); it++)
1367             } else {                          << 1009   {
1368                G4double tin=0., tout=0.;      << 1010      kt=ktv[it];
1369                if (((G4RKPropagation*)theProp << 1011      initial +=  kt->Get4Momentum().e();
1370                      tin < 0 && tout > 0 )    << 1012      thisExcitation += kt->GetDefinition()->GetPDGMass() 
1371                {                              << 1013              - kt->Get4Momentum().e() 
1372                   PrintKTVector((*i),"particl << 1014          - RKprop->GetField(kt->GetDefinition()->GetPDGEncoding(),kt->GetPosition());
1373                    G4cout << "tin tout: " <<  << 1015 //     initial +=  RKprop->GetField(kt->GetDefinition()->GetPDGEncoding(),kt->GetPosition());
1374                }                              << 1016 //     initial -=  RKprop->GetBarrier(kt->GetDefinition()->GetPDGEncoding());
1375             }                                 << 1017   G4cout << "Targ. def/E/field/Barr/Sum " <<  kt->GetDefinition()->GetPDGEncoding()
1376         } else {                              << 1018       << " " << kt->Get4Momentum().e()
1377             G4double tin=0., tout=0.;         << 1019           << " " << RKprop->GetField(kt->GetDefinition()->GetPDGEncoding(),kt->GetPosition())
1378             if (((G4RKPropagation*)thePropaga << 1020           << " " << RKprop->GetBarrier(kt->GetDefinition()->GetPDGEncoding()) 
1379             {                                 << 1021     << " " << initial <<" Excit " << thisExcitation << G4endl;;
1380                 //G4cout << "tin tout: " << t << 1022   }
1381                 if ( tin > 0 )                << 1023   
1382                 {                             << 1024   G4double final(0);
1383                     (*i)->SetState(G4KineticT << 1025   G4double mass_out(0);
1384                 }                             << 1026   G4int product_barions(0);
1385                 else if ( tout > 0 )          << 1027   for ( unsigned int it=0; it < products->size(); it++)
1386                 {                             << 1028   {
1387                     (*i)->SetState(G4KineticT << 1029      kt=(*products)[it];
1388                     finalBaryon+=(*i)->GetDef << 1030      final +=  kt->Get4Momentum().e();
1389                     finalCharge+=G4lrint((*i) << 1031      final +=  RKprop->GetField(kt->GetDefinition()->GetPDGEncoding(),kt->GetPosition());
1390                 }                             << 1032      final +=  RKprop->GetBarrier(kt->GetDefinition()->GetPDGEncoding());
1391                 else                          << 1033      if ( kt->GetDefinition()->GetBaryonNumber()==1 ) product_barions++;
1392                 {                             << 1034      mass_out += kt->GetDefinition()->GetPDGMass();
1393                     (*i)->SetState(G4KineticT << 1035   G4cout << "sec. def/E/field/Barr/Sum " << kt->GetDefinition()->GetPDGEncoding()
1394                     toFinalState.push_back((* << 1036       << " " << kt->Get4Momentum().e()
1395                 }                             << 1037           << " " << RKprop->GetField(kt->GetDefinition()->GetPDGEncoding(),kt->GetPosition())
1396             } else                            << 1038           << " " << RKprop->GetBarrier(kt->GetDefinition()->GetPDGEncoding()) 
1397             {                                 << 1039     << " " << final << G4endl;;
1398                 (*i)->SetState(G4KineticTrack << 1040   }
1399                 //G4cout << " G4BC - miss -la << 1041 
1400                 toFinalState.push_back((*i)); << 1042 
1401             }                                 << 1043   G4int finalA = currentA - product_barions;
1402                                               << 1044   G4int finalZ = currentZ - GetTotalCharge(*products);
1403         }                                     << 1045   G4double delta = G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(currentZ,currentA) 
1404     }                                         << 1046                    - (G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(finalZ,finalA) 
1405     if(!toFinalState.empty())                 << 1047            + mass_out); 
1406     {                                         << 1048   G4cout << " current/final a,z " << currentA << " " << currentZ << " "<< finalA<< " "<< finalZ 
1407         theFinalState.insert(theFinalState.ce << 1049         <<  " delta-mass " << delta<<G4endl;
1408                 toFinalState.cbegin(),toFinal << 1050   final+=delta;
1409         std::vector<G4KineticTrack *>::iterat << 1051     mass_out  = G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(finalZ,finalA);
1410         for(auto iter1=toFinalState.cbegin(); << 1052   G4cout << " initE/ E_out/ Mfinal/ Excit " << currentInitialEnergy
1411         {                                     << 1053          << " " <<   final << " "
1412             iter2 = std::find(products->begin << 1054    <<  mass_out<<" " 
1413             if ( iter2 != products->cend() )  << 1055    <<  currentInitialEnergy - final - mass_out
1414         }                                     << 1056    << G4endl;
1415         theCollisionMgr->RemoveTracksCollisio << 1057    currentInitialEnergy-=final;  
1416     }                                         << 1058 #endif
1417                                               << 1059 
1418     //G4cout << " currentA, Z be4: " << curre << 1060   G4int finalBaryon(0);
1419     currentA += finalBaryon-initialBaryon;    << 1061   G4int finalCharge(0);
1420     currentZ += finalCharge-initialCharge;    << 1062   for(size_t ig=0;ig<products->size();ig++)
1421     //G4cout << " ApplyCollision currentA, Z  << 1063   {
1422                                               << 1064     finalBaryon+=products->operator[](ig)->GetDefinition()->GetBaryonNumber();
1423     G4KineticTrackVector oldSecondaries;      << 1065     finalCharge+=G4lrint(products->operator[](ig)->GetDefinition()->GetPDGCharge());
1424     oldSecondaries.push_back(primary);        << 1066 // secondaries are created inside nucleus
1425     primary->Hit();                           << 1067     products->operator[](ig)->SetState(G4KineticTrack::inside);
1426                                               << 1068   }
                                                   >> 1069 
                                                   >> 1070   currentA += finalBaryon-initialBaryon;
                                                   >> 1071   currentZ += finalCharge-initialCharge;
                                                   >> 1072   
                                                   >> 1073   G4KineticTrackVector oldSecondaries;
                                                   >> 1074   oldSecondaries.push_back(primary);
1427 #ifdef debug_G4BinaryCascade                     1075 #ifdef debug_G4BinaryCascade
1428     if ( (finalBaryon-initialBaryon-lateBaryo << 1076   if ( (finalBaryon-initialBaryon) != 0 || (finalCharge-initialCharge) != 0 ) 
1429     {                                         << 1077      {
1430         G4cout << "G4BinaryCascade: Error in     1078         G4cout << "G4BinaryCascade: Error in Balancing: " << G4endl;
1431         G4cout << "initial/final baryon numbe    1079         G4cout << "initial/final baryon number, initial/final Charge "
1432                 << initialBaryon <<" "<< fina << 1080             << initialBaryon <<" "<< finalBaryon <<" "
1433                 << initialCharge <<" "<< fina << 1081       << initialCharge <<" "<< finalCharge <<" "
1434                 << " in Collision type: "<< t << 1082       << " in Collision type: "<< typeid(*collision->GetGenerator()).name()
1435                 << ", with number of products << 1083       << ", with number of products: "<< products->size() <<G4endl;
1436         G4cout << G4endl<<"Initial condition  << 1084        G4cout << G4endl<<"Initial condition are these:"<<G4endl;
1437         G4cout << "proj: "<<collision->GetPri << 1085        G4cout << "proj: "<<collision->GetPrimary()->GetDefinition()->GetParticleName()<<G4endl;
1438         for(std::size_t it=0; it<collision->G << 1086        for(size_t it=0; it<collision->GetTargetCollection().size(); it++)
1439         {                                     << 1087        {
1440             G4cout << "targ: "                << 1088          G4cout << "targ: "
1441                     <<collision->GetTargetCol << 1089         <<collision->GetTargetCollection()[it]->GetDefinition()->GetParticleName()<<G4endl;
1442         }                                     << 1090        }
1443         PrintKTVector(&collision->GetTargetCo << 1091        PrintKTVector(&collision->GetTargetCollection(),std::string(" Target particles"));
1444         G4cout << G4endl<<G4endl;             << 1092        G4cout << G4endl<<G4endl;
1445     }                                         << 1093      }
1446 #endif                                        << 1094 #endif
1447                                               << 1095 
1448     G4KineticTrackVector oldTarget = collisio << 1096   G4KineticTrackVector oldTarget = collision->GetTargetCollection();
1449     for(std::size_t ii=0; ii< oldTarget.size( << 1097   primary->Hit();
1450     {                                         << 1098   for(size_t ii=0; ii< oldTarget.size(); ii++)
1451         oldTarget[ii]->Hit();                 << 1099   {
1452     }                                         << 1100     oldTarget[ii]->Hit();
1453                                               << 1101   }
1454     UpdateTracksAndCollisions(&oldSecondaries << 1102 
1455     std::for_each(oldSecondaries.cbegin(), ol << 1103   debug.push_back("=======> we have hit nucleons <=======");
1456     std::for_each(oldTarget.cbegin(), oldTarg << 1104   
                                                   >> 1105   UpdateTracksAndCollisions(&oldSecondaries, &oldTarget, products);
                                                   >> 1106   std::for_each(oldSecondaries.begin(), oldSecondaries.end(), Delete<G4KineticTrack>()); 
                                                   >> 1107   std::for_each(oldTarget.begin(), oldTarget.end(), Delete<G4KineticTrack>()); 
1457                                                  1108 
1458     delete products;                          << 1109   delete products;
1459     return true;                              << 1110   return true;
1460 }                                                1111 }
1461                                                  1112 
1462                                                  1113 
1463 //-------------------------------------------    1114 //----------------------------------------------------------------------------
1464 G4bool G4BinaryCascade::Absorb()                 1115 G4bool G4BinaryCascade::Absorb()
1465 //-------------------------------------------    1116 //----------------------------------------------------------------------------
1466 {                                                1117 {
1467     // Do it in two step: cannot change theSe << 1118 // Do it in two step: cannot change theSecondaryList inside the first loop.
1468     G4Absorber absorber(theCutOnPAbsorb);     << 1119   G4Absorber absorber(theCutOnPAbsorb);
1469                                               << 
1470     // Build the vector of G4KineticTracks th << 
1471     G4KineticTrackVector absorbList;          << 
1472     std::vector<G4KineticTrack *>::const_iter << 
1473     //  PrintKTVector(&theSecondaryList, " te << 
1474     for(iter = theSecondaryList.cbegin();     << 
1475             iter != theSecondaryList.cend();  << 
1476     {                                         << 
1477         G4KineticTrack * kt = *iter;          << 
1478         if(kt->GetState() == G4KineticTrack:: << 
1479         {                                     << 
1480             if(absorber.WillBeAbsorbed(*kt))  << 
1481             {                                 << 
1482                 absorbList.push_back(kt);     << 
1483             }                                 << 
1484         }                                     << 
1485     }                                         << 
1486                                                  1120 
1487     if(absorbList.empty())                    << 1121 // Build the vector of G4KineticTracks that must be absorbed
1488         return false;                         << 1122   G4KineticTrackVector absorbList;
1489                                               << 1123   std::vector<G4KineticTrack *>::iterator iter;
1490     G4KineticTrackVector toDelete;            << 1124   for(iter = theSecondaryList.begin();
1491     for(iter = absorbList.cbegin(); iter != a << 1125       iter != theSecondaryList.end(); ++iter)
1492     {                                         << 1126   {
1493         G4KineticTrack * kt = *iter;          << 1127      G4KineticTrack * kt = *iter;
1494         if(!absorber.FindAbsorbers(*kt, theTa << 1128      if(kt->GetState() == G4KineticTrack::inside)// absorption happens only inside the nucleus
1495             throw G4HadronicException(__FILE_ << 1129      {
                                                   >> 1130   if(absorber.WillBeAbsorbed(*kt))
                                                   >> 1131   {
                                                   >> 1132      absorbList.push_back(kt);
                                                   >> 1133   }
                                                   >> 1134      }
                                                   >> 1135   }
1496                                                  1136 
1497         if(!absorber.FindProducts(*kt))       << 1137   if(absorbList.empty())
1498             throw G4HadronicException(__FILE_ << 1138     return false;
1499                                                  1139 
1500         G4KineticTrackVector * products = abs << 1140   G4KineticTrackVector toDelete;
1501         G4int maxLoopCount = 1000;            << 1141   for(iter = absorbList.begin(); iter != absorbList.end(); ++iter)
1502         while(!CheckPauliPrinciple(products)  << 1142   {
1503         {                                     << 1143     G4KineticTrack * kt = *iter;
1504             ClearAndDestroy(products);        << 1144     if(!absorber.FindAbsorbers(*kt, theTargetList))
1505             if(!absorber.FindProducts(*kt))   << 1145       throw G4HadronicException(__FILE__, __LINE__, "G4BinaryCascade::Absorb(): Cannot absorb a particle.");
1506                 throw G4HadronicException(__F << 1146 
1507                         "G4BinaryCascade::Abs << 1147     if(!absorber.FindProducts(*kt))
1508         }                                     << 1148       throw G4HadronicException(__FILE__, __LINE__, "G4BinaryCascade::Absorb(): Cannot absorb a particle.");
1509       if ( --maxLoopCount < 0 ) throw G4Hadro << 1149 
1510         // ------ debug                       << 1150     G4KineticTrackVector * products = absorber.GetProducts();
1511         //    G4cerr << "Absorb CheckPauliPri << 1151 // ------ debug
1512         // ------ end debug                   << 1152     G4int count = 0;
1513         G4KineticTrackVector toRemove;  // bu << 1153 // ------ end debug
1514         toRemove.push_back(kt);               << 1154     while(!CheckPauliPrinciple(products))
1515         toDelete.push_back(kt);  // delete th << 1155     {
1516         G4KineticTrackVector * absorbers = ab << 1156 // ------ debug
1517         UpdateTracksAndCollisions(&toRemove,  << 1157       count++;
1518         ClearAndDestroy(absorbers);           << 1158 // ------ end debug
1519     }                                         << 1159       ClearAndDestroy(products);
1520     ClearAndDestroy(&toDelete);               << 1160       if(!absorber.FindProducts(*kt))
1521     return true;                              << 1161   throw G4HadronicException(__FILE__, __LINE__, 
                                                   >> 1162     "G4BinaryCascade::Absorb(): Cannot absorb a particle.");
                                                   >> 1163     }
                                                   >> 1164 // ------ debug
                                                   >> 1165 //    G4cerr << "Absorb CheckPauliPrinciple count= " <<  count << G4endl;
                                                   >> 1166 // ------ end debug
                                                   >> 1167     G4KineticTrackVector toRemove;  // build a vector for UpdateTrack...
                                                   >> 1168     toRemove.push_back(kt);
                                                   >> 1169     toDelete.push_back(kt);  // delete the track later
                                                   >> 1170     G4KineticTrackVector * absorbers = absorber.GetAbsorbers();
                                                   >> 1171     UpdateTracksAndCollisions(&toRemove, absorbers, products);
                                                   >> 1172     ClearAndDestroy(absorbers);
                                                   >> 1173   }
                                                   >> 1174   ClearAndDestroy(&toDelete);
                                                   >> 1175   return true;
1522 }                                                1176 }
1523                                                  1177 
1524                                                  1178 
1525                                                  1179 
1526 // Capture all p and n with Energy < theCutOn    1180 // Capture all p and n with Energy < theCutOnP
1527 //-------------------------------------------    1181 //----------------------------------------------------------------------------
1528 G4bool G4BinaryCascade::Capture(G4bool verbos    1182 G4bool G4BinaryCascade::Capture(G4bool verbose)
1529 //-------------------------------------------    1183 //----------------------------------------------------------------------------
1530 {                                                1184 {
1531     G4KineticTrackVector captured;            << 1185   G4KineticTrackVector captured;
1532     G4bool capture = false;                   << 1186   G4bool capture = false;
1533     std::vector<G4KineticTrack *>::const_iter << 1187   std::vector<G4KineticTrack *>::iterator i;
1534                                               << 1188 
1535     G4RKPropagation * RKprop=(G4RKPropagation << 1189   G4RKPropagation * RKprop=(G4RKPropagation *)thePropagator;
1536                                               << 1190 
1537     G4double capturedEnergy = 0;              << 1191   G4double capturedEnergy = 0;
1538     G4int particlesAboveCut=0;                << 1192   G4int particlesAboveCut=0;
1539     G4int particlesBelowCut=0;                << 1193   G4int particlesBelowCut=0;
1540     if ( verbose ) G4cout << " Capture: secon << 1194   if ( verbose ) G4cout << " Capture: secondaries " << theSecondaryList.size() << G4endl;
1541     for(i = theSecondaryList.cbegin(); i != t << 1195   for(i = theSecondaryList.begin(); i != theSecondaryList.end(); ++i)
1542     {                                         << 1196   {
1543         G4KineticTrack * kt = *i;             << 1197     G4KineticTrack * kt = *i;
1544         if (verbose) G4cout << "Capture posit << 1198     if (verbose) G4cout << "Capture position, radius, state " <<kt->GetPosition().mag()<<" "<<theOuterRadius<<" "<<kt->GetState()<<G4endl;
1545         if(kt->GetState() == G4KineticTrack:: << 1199     if(kt->GetState() == G4KineticTrack::inside) // capture happens only inside the nucleus
1546         {                                     << 1200     {
1547             if((kt->GetDefinition() == G4Prot << 1201       if((kt->GetDefinition() == G4Proton::Proton()) ||
1548                     (kt->GetDefinition() == G << 1202    (kt->GetDefinition() == G4Neutron::Neutron()))
1549             {                                 << 1203       {
1550                 //GF cut on kinetic energy    << 1204       //GF cut on kinetic energy    if(kt->Get4Momentum().vect().mag() >= theCutOnP)
1551                 G4double field=RKprop->GetFie << 1205          G4double field=RKprop->GetField(kt->GetDefinition()->GetPDGEncoding(),kt->GetPosition())
1552                              -RKprop->GetBarr << 1206                  -RKprop->GetBarrier(kt->GetDefinition()->GetPDGEncoding());
1553                 G4double energy= kt->Get4Mome << 1207    G4double energy= kt->Get4Momentum().e() - kt->GetActualMass() + field;
1554                 if (verbose ) G4cout << "Capt << 1208          if (verbose ) G4cout << "Capture: .e(), mass, field, energy" << kt->Get4Momentum().e() <<" "<<kt->GetActualMass()<<" "<<field<<" "<<energy<< G4endl;
1555                 //   if( energy < theCutOnP ) << 1209 //   if( energy < theCutOnP )
1556                 //   {                        << 1210 //   {
1557                 capturedEnergy+=energy;       << 1211       capturedEnergy+=energy;
1558                 ++particlesBelowCut;          << 1212       ++particlesBelowCut;
1559                 //   } else                   << 1213 //   } else
1560                 //   {                        << 1214 //   {
1561                 //      ++particlesAboveCut;  << 1215 //      ++particlesAboveCut;
1562                 //   }                        << 1216 //   }
1563             }                                 << 1217      }
1564         }                                     << 1218     }
1565     }                                         << 1219   }
1566     if (verbose) G4cout << "Capture particles << 1220   if (verbose) G4cout << "Capture particlesAboveCut,particlesBelowCut, capturedEnergy,capturedEnergy/particlesBelowCut <? 0.2*theCutOnP "
1567             << particlesAboveCut << " " << pa << 1221        << particlesAboveCut << " " << particlesBelowCut << " " << capturedEnergy
1568             << " "  << G4endl;                << 1222        << " " << capturedEnergy/particlesBelowCut << " " << 0.2*theCutOnP << G4endl;
1569 //    << " " << (particlesBelowCut>0) ? (capt << 1223 //  if(particlesAboveCut==0 && particlesBelowCut>0 && capturedEnergy/particlesBelowCut<0.2*theCutOnP)
1570     //  if(particlesAboveCut==0 && particlesB << 1224   if(capturedEnergy/particlesBelowCut<0.2*theCutOnP)
1571     if(particlesBelowCut>0 && capturedEnergy/ << 1225   {
                                                   >> 1226     capture=true;
                                                   >> 1227     for(i = theSecondaryList.begin(); i != theSecondaryList.end(); ++i)
1572     {                                            1228     {
1573         capture=true;                         << 1229       G4KineticTrack * kt = *i;
1574         for(i = theSecondaryList.cbegin(); i  << 1230       if(kt->GetState() == G4KineticTrack::inside) // capture happens only inside the nucleus
                                                   >> 1231       {
                                                   >> 1232         if((kt->GetDefinition() == G4Proton::Proton()) ||
                                                   >> 1233      (kt->GetDefinition() == G4Neutron::Neutron()))
1575         {                                        1234         {
1576             G4KineticTrack * kt = *i;         << 1235     captured.push_back(kt);
1577             if(kt->GetState() == G4KineticTra << 1236     kt->Hit();        // 
1578             {                                 << 1237     theCapturedList.push_back(kt);
1579                 if((kt->GetDefinition() == G4 << 1238   }
1580                         (kt->GetDefinition()  << 1239       }
1581                 {                             << 
1582                     captured.push_back(kt);   << 
1583                     kt->Hit();        //      << 
1584                     theCapturedList.push_back << 
1585                 }                             << 
1586             }                                 << 
1587         }                                     << 
1588         UpdateTracksAndCollisions(&captured,  << 
1589     }                                            1240     }
                                                   >> 1241     UpdateTracksAndCollisions(&captured, NULL, NULL);
                                                   >> 1242   }
1590                                                  1243 
1591     return capture;                           << 1244   return capture;
1592 }                                                1245 }
1593                                                  1246 
1594                                                  1247 
1595 //-------------------------------------------    1248 //----------------------------------------------------------------------------
1596 G4bool G4BinaryCascade::CheckPauliPrinciple(G    1249 G4bool G4BinaryCascade::CheckPauliPrinciple(G4KineticTrackVector * products)
1597 //-------------------------------------------    1250 //----------------------------------------------------------------------------
1598 {                                                1251 {
1599     G4int A = the3DNucleus->GetMassNumber();  << 1252   G4int A = the3DNucleus->GetMassNumber();
1600     G4int Z = the3DNucleus->GetCharge();      << 1253   G4int Z = the3DNucleus->GetCharge();
1601                                               << 
1602     G4FermiMomentum fermiMom;                 << 
1603     fermiMom.Init(A, Z);                      << 
1604                                                  1254 
1605     const G4VNuclearDensity * density=the3DNu << 1255   G4FermiMomentum fermiMom;
                                                   >> 1256   fermiMom.Init(A, Z);
1606                                                  1257 
1607     G4KineticTrackVector::const_iterator i;   << 1258   const G4VNuclearDensity * density=the3DNucleus->GetNuclearDensity();
1608     const G4ParticleDefinition * definition;  << 
1609                                                  1259 
1610     // ------ debug                           << 1260   G4KineticTrackVector::iterator i;
1611     G4bool myflag = true;                     << 1261   G4ParticleDefinition * definition;
1612     // ------ end debug                       << 1262 
1613     //  G4ThreeVector xpos(0);                << 1263 // ------ debug
1614     for(i = products->cbegin(); i != products << 1264   G4bool myflag = true;
1615     {                                         << 1265 // ------ end debug
1616         definition = (*i)->GetDefinition();   << 1266 //  G4ThreeVector xpos(0);
1617         if((definition == G4Proton::Proton()) << 1267   for(i = products->begin(); i != products->end(); ++i)
1618                 (definition == G4Neutron::Neu << 1268   {
1619         {                                     << 1269     definition = (*i)->GetDefinition();
1620             G4ThreeVector pos = (*i)->GetPosi << 1270     if((definition == G4Proton::Proton()) ||
1621             G4double d = density->GetDensity( << 1271        (definition == G4Neutron::Neutron()))
1622             // energy correspondiing to fermi << 1272     {
1623             G4double eFermi = std::sqrt( sqr( << 1273        G4ThreeVector pos = (*i)->GetPosition();
1624             if( definition == G4Proton::Proto << 1274        G4double d = density->GetDensity(pos);
1625             {                                 << 1275   // energy correspondiing to fermi momentum
1626                 eFermi -= the3DNucleus->Coulo << 1276        G4double eFermi = std::sqrt( sqr(fermiMom.GetFermiMomentum(d)) + (*i)->Get4Momentum().mag2() );
1627             }                                 << 1277        if( definition == G4Proton::Proton() )
1628             G4LorentzVector mom = (*i)->Get4M << 1278        {
1629             // ------ debug                   << 1279          eFermi -= the3DNucleus->CoulombBarrier();
1630             /*                                << 1280        }
1631              *        G4cout << "p:[" << (1/M << 1281        G4LorentzVector mom = (*i)->Get4Momentum();
1632              *            << (1/MeV)*mom.z()  << 1282        // ------ debug
1633              *            << (1/MeV)*mom.vect << 1283 /*
1634              *            << (1/MeV)*mom.mag( << 1284  *        G4cout << "p:[" << (1/MeV)*mom.x() << " " << (1/MeV)*mom.y() << " "
1635              *            << (1/fermi)*pos.x( << 1285  *            << (1/MeV)*mom.z() << "] |p3|:"
1636              *            << (1/fermi)*pos.z( << 1286  *            << (1/MeV)*mom.vect().mag() << " E:" << (1/MeV)*mom.t() << " ] m: "
1637              *            << (1/fermi)*(pos-x << 1287  *            << (1/MeV)*mom.mag() << "  pos["
1638              *            << (1/MeV)*p << G4e << 1288  *            << (1/fermi)*pos.x() << " "<< (1/fermi)*pos.y() << " "
1639              *         xpos=pos;              << 1289  *            << (1/fermi)*pos.z() << "] |Dpos|: "
1640              */                               << 1290  *            << (1/fermi)*(pos-xpos).mag() << " Pfermi:"
1641             // ------ end debug               << 1291  *            << (1/MeV)*p << G4endl;
1642             if(mom.e() < eFermi )             << 1292  *         xpos=pos;
1643             {                                 << 1293  */
1644                 // ------ debug               << 1294        // ------ end debug
1645                 myflag = false;               << 1295        if(mom.e() < eFermi )
1646                 // ------ end debug           << 1296        {
1647                 //      return false;         << 1297    // ------ debug
1648             }                                 << 1298    myflag = false;
1649         }                                     << 1299    // ------ end debug
1650     }                                         << 1300    //      return false;
1651 #ifdef debug_BIC_CheckPauli                   << 1301        }
1652     if ( myflag  )                            << 1302      }
1653     {                                         << 1303   }
1654         for(i = products->cbegin(); i != prod << 1304   #ifdef debug_BIC_CheckPauli
1655         {                                     << 1305   if ( myflag  )
1656             definition = (*i)->GetDefinition( << 1306   {
1657             if((definition == G4Proton::Proto << 1307   for(i = products->begin(); i != products->end(); ++i)
1658                     (definition == G4Neutron: << 1308   {
1659             {                                 << 1309     definition = (*i)->GetDefinition();
1660                 G4ThreeVector pos = (*i)->Get << 1310     if((definition == G4Proton::Proton()) ||
1661                 G4double d = density->GetDens << 1311     (definition == G4Neutron::Neutron()))
1662                 G4double pFermi = fermiMom.Ge << 1312     {
1663                 G4LorentzVector mom = (*i)->G << 1313       G4ThreeVector pos = (*i)->GetPosition();
1664                 G4double field =((G4RKPropaga << 1314       G4double d = density->GetDensity(pos);
1665                 if ( mom.e()-mom.mag()+field  << 1315       G4double pFermi = fermiMom.GetFermiMomentum(d);
1666                 {                             << 1316       G4LorentzVector mom = (*i)->Get4Momentum();
1667                     G4cout << "momentum probl << 1317       G4double field =((G4RKPropagation*)thePropagator)->GetField(definition->GetPDGEncoding(),pos);
1668                             << " mom, mom.m " << 1318               if ( mom.e()-mom.mag()+field > 160*MeV ) 
1669                             << " field " << f << 1319       {
1670                 }                             << 1320           G4cout << "momentum problem pFermi=" <<  pFermi
1671             }                                 << 1321                << " mom, mom.m " << mom << " " << mom.mag()
1672         }                                     << 1322          << " field " << field << G4endl;
1673     }                                         << 1323       }
1674 #endif                                        << 1324     }
                                                   >> 1325   }
                                                   >> 1326   }
                                                   >> 1327   #endif
1675                                                  1328 
1676     return myflag;                            << 1329   return myflag;
1677 }                                                1330 }
1678                                                  1331 
1679 //-------------------------------------------    1332 //----------------------------------------------------------------------------
1680 void G4BinaryCascade::StepParticlesOut()         1333 void G4BinaryCascade::StepParticlesOut()
1681 //-------------------------------------------    1334 //----------------------------------------------------------------------------
1682 {                                                1335 {
1683     G4int counter=0;                          << 1336   G4int counter=0;
1684     G4int countreset=0;                       << 1337   G4int countreset=0;
1685     //G4cout << " nucl. Radius " << radius << << 1338   //G4cout << " nucl. Radius " << radius << G4endl;
1686     // G4cerr <<"pre-while- theSecondaryList  << 1339   // G4cerr <<"pre-while- theSecondaryList "<<G4endl;
1687     while( theSecondaryList.size() > 0 )      << 1340   while( theSecondaryList.size() > 0 )
1688                                               << 1341   {
1689     {                                         << 1342     G4int nsec=0;
1690         G4double minTimeStep = 1.e-12*ns;   / << 1343     G4double minTimeStep = 1.e-12*ns;   // about 30*fermi/(0.1*c_light);1.e-12*ns
1691                                             / << 1344                                         // i.e. a big step
1692         for(auto i = theSecondaryList.cbegin( << 1345     std::vector<G4KineticTrack *>::iterator i;
1693         {                                     << 1346     for(i = theSecondaryList.begin(); i != theSecondaryList.end(); ++i)
1694             G4KineticTrack * kt = *i;         << 1347     {
1695             if( kt->GetState() == G4KineticTr << 1348       G4KineticTrack * kt = *i;
1696             {                                 << 1349       if( kt->GetState() == G4KineticTrack::inside ) 
1697                 G4double tStep(0), tdummy(0); << 1350       {
1698                 G4bool intersect =            << 1351     nsec++;
1699                         ((G4RKPropagation*)th << 1352     G4double tStep(0), tdummy(0); 
                                                   >> 1353     ((G4RKPropagation*)thePropagator)->GetSphereIntersectionTimes(kt,tdummy,tStep);
1700 #ifdef debug_BIC_StepParticlesOut                1354 #ifdef debug_BIC_StepParticlesOut
1701                 G4cout << " minTimeStep, tSte << 1355     G4cout << " minTimeStep, tStep Particle " <<minTimeStep << " " <<tStep
1702                         << " " <<kt->GetDefin << 1356            << " " <<kt->GetDefinition()->GetParticleName() 
1703                         << " 4mom " << kt->Ge << 1357      << " 4mom " << kt->GetTrackingMomentum()<<G4endl;
1704                 if ( ! intersect );           << 1358 #endif
1705                 {                             << 1359     if(tStep<minTimeStep && tStep> 0 )
1706                     PrintKTVector(&theSeconda << 1360     {
1707                     throw G4HadronicException << 1361       minTimeStep = tStep;
1708                 }                             << 1362     }
1709 #endif                                        << 1363       } else if ( kt->GetState() != G4KineticTrack::outside ){
1710                 if(intersect && tStep<minTime << 1364           PrintKTVector(&theSecondaryList, std::string(" state ERROR....."));
1711                 {                             << 1365           throw G4HadronicException(__FILE__, __LINE__, "G4BinaryCascade::StepParticlesOut() particle not in nucleus");
1712                     minTimeStep = tStep;      << 1366       }
1713                 }                             << 1367     }
1714             } else if ( kt->GetState() != G4K << 1368     minTimeStep *= 1.2;
1715                 PrintKTVector(&theSecondaryLi << 1369 //    G4cerr << "CaptureCount = "<<counter<<" "<<nsec<<" "<<minTimeStep<<" "<<1*ns<<G4endl;
1716                 throw G4HadronicException(__F << 1370     G4double timeToCollision=DBL_MAX;
1717             }                                 << 1371     G4CollisionInitialState * nextCollision=0;
1718         }                                     << 1372     if(theCollisionMgr->Entries() > 0)
1719         minTimeStep *= 1.2;                   << 1373     {
1720         G4double timeToCollision=DBL_MAX;     << 1374        nextCollision = theCollisionMgr->GetNextCollision();
1721         G4CollisionInitialState * nextCollisi << 1375        timeToCollision = nextCollision->GetCollisionTime()-theCurrentTime;
1722         if(theCollisionMgr->Entries() > 0)    << 1376     }
1723         {                                     << 1377     if ( timeToCollision > minTimeStep )
1724             nextCollision = theCollisionMgr-> << 1378     {
1725             timeToCollision = nextCollision-> << 1379   DoTimeStep(minTimeStep);
1726             //  G4cout << " NextCollision  *  << 1380         ++counter;
1727         }                                     << 1381     } else
1728         if ( timeToCollision > minTimeStep )  << 1382     {
1729         {                                     << 1383         if (!DoTimeStep(timeToCollision) )
1730             DoTimeStep(minTimeStep);          << 1384   {
1731             ++counter;                        << 1385      // Check if nextCollision is still valid, ie. partcile did not leave nucleus
1732         } else                                << 1386      if (theCollisionMgr->GetNextCollision() != nextCollision )
1733         {                                     << 1387      {
1734             if (!DoTimeStep(timeToCollision)  << 1388          nextCollision = 0;
1735             {                                 << 1389      }
1736                 // Check if nextCollision is  << 1390   }
1737                 if (theCollisionMgr->GetNextC << 1391        // G4cerr <<"post- DoTimeStep 3"<<G4endl;
1738                 {                             << 
1739                     nextCollision = nullptr;  << 
1740                 }                             << 
1741             }                                 << 
1742             // G4cerr <<"post- DoTimeStep 3"< << 
1743                                               << 
1744             if(nextCollision)                 << 
1745             {                                 << 
1746                 if  ( ApplyCollision(nextColl << 
1747                 {                             << 
1748                     // G4cout << "ApplyCollis << 
1749                 } else                        << 
1750                 {                             << 
1751                     theCollisionMgr->RemoveCo << 
1752                 }                             << 
1753             }                                 << 
1754         }                                     << 
1755                                                  1392 
1756         if(countreset>100)                    << 1393   if(nextCollision)
1757         {                                     << 1394   {
                                                   >> 1395      if  ( ApplyCollision(nextCollision))
                                                   >> 1396      {
                                                   >> 1397          // G4cout << "ApplyCollision sucess " << G4endl;
                                                   >> 1398            } else
                                                   >> 1399            {
                                                   >> 1400          theCollisionMgr->RemoveCollision(nextCollision);
                                                   >> 1401            }
                                                   >> 1402   }
                                                   >> 1403     }
                                                   >> 1404 
                                                   >> 1405     if(countreset>100)
                                                   >> 1406     {
1758 #ifdef debug_G4BinaryCascade                     1407 #ifdef debug_G4BinaryCascade
1759             G4cerr << "G4BinaryCascade.cc: Wa << 1408        G4cerr << "G4BinaryCascade.cc: Warning - aborting looping particle(s)" << G4endl;
1760             PrintKTVector(&theSecondaryList," << 
1761 #endif                                           1409 #endif
1762                                                  1410 
1763             //  add left secondaries to Final << 1411 //  add left secondaries to FinalSate
1764             for (auto iter=theSecondaryList.c << 1412        std::vector<G4KineticTrack *>::iterator iter;
1765             {                                 << 1413        for ( iter =theSecondaryList.begin(); iter != theSecondaryList.end(); ++iter)
1766                 theFinalState.push_back(*iter << 1414        {
1767             }                                 << 1415      theFinalState.push_back(*iter);
1768             theSecondaryList.clear();         << 1416        }
1769                                               << 1417        theSecondaryList.clear();
1770             break;                            << 
1771         }                                     << 
1772                                               << 
1773         if(Absorb())                          << 
1774         {                                     << 
1775             //       haveProducts = true;     << 
1776             // G4cout << "Absorb sucess " <<  << 
1777         }                                     << 
1778                                               << 
1779         if(Capture(false))                    << 
1780         {                                     << 
1781             //       haveProducts = true;     << 
1782 #ifdef debug_BIC_StepParticlesOut             << 
1783             G4cout << "Capture sucess " << G4 << 
1784 #endif                                        << 
1785         }                                     << 
1786         if ( counter > 100 && theCollisionMgr << 
1787         {                                     << 
1788 #ifdef debug_BIC_StepParticlesOut             << 
1789             PrintKTVector(&theSecondaryList,s << 
1790 #endif                                        << 
1791             FindCollisions(&theSecondaryList) << 
1792             counter=0;                        << 
1793             ++countreset;                     << 
1794         }                                     << 
1795         //G4cout << "currentZ @ end loop " << << 
1796         if ( ! currentZ ){                    << 
1797             // nucleus completely destroyed,  << 
1798            // products = FillVoidNucleusProdu << 
1799     #ifdef debug_BIC_return                   << 
1800             G4cout << "return @ Z=0 after col << 
1801             PrintKTVector(&theSecondaryList,s << 
1802             G4cout << "theTargetList size: "  << 
1803             PrintKTVector(&theTargetList,std: << 
1804             PrintKTVector(&theCapturedList,st << 
1805                                               << 
1806             G4cout << " ExcitE be4 Correct :  << 
1807             G4cout << " Mom Transfered to nuc << 
1808             PrintKTVector(&theFinalState,std: << 
1809           //  G4cout << "returned products: " << 
1810     #endif                                    << 
1811         }                                     << 
1812                                                  1418 
                                                   >> 1419        break;
1813     }                                            1420     }
1814     //  G4cerr <<"Finished capture loop "<<G4 << 
1815                                               << 
1816     //G4cerr <<"pre- DoTimeStep 4"<<G4endl;   << 
1817     DoTimeStep(DBL_MAX);                      << 
1818     //G4cerr <<"post- DoTimeStep 4"<<G4endl;  << 
1819 }                                             << 
1820                                                  1421 
1821 //------------------------------------------- << 1422     if(Absorb())
1822 G4double G4BinaryCascade::CorrectShortlivedPr << 1423     {
1823         G4KineticTrack* primary,G4KineticTrac << 1424 //       haveProducts = true;
1824 //------------------------------------------- << 1425       // G4cout << "Absorb sucess " << G4endl;
1825 {                                             << 
1826     G4double Efermi(0);                       << 
1827     if (primary->GetState() == G4KineticTrack << 
1828         G4int PDGcode=primary->GetDefinition( << 
1829         Efermi=((G4RKPropagation *)thePropaga << 
1830                                               << 
1831         if ( std::abs(PDGcode) > 1000 && PDGc << 
1832         {                                     << 
1833             Efermi = ((G4RKPropagation *)theP << 
1834             G4LorentzVector mom4Primary=prima << 
1835             primary->Update4Momentum(mom4Prim << 
1836         }                                     << 
1837                                               << 
1838         for (auto titer=target_collection.cbe << 
1839         {                                     << 
1840             const G4ParticleDefinition * aDef << 
1841             G4int aCode=aDef->GetPDGEncoding( << 
1842             G4ThreeVector aPos=(*titer)->GetP << 
1843             Efermi+= ((G4RKPropagation *)theP << 
1844         }                                     << 
1845     }                                            1426     }
1846     return Efermi;                            << 
1847 }                                             << 
1848                                                  1427 
1849 //------------------------------------------- << 1428     if(Capture(false))
1850 G4bool G4BinaryCascade::CorrectShortlivedFina << 
1851         G4double initial_Efermi)              << 
1852 //------------------------------------------- << 
1853 {                                             << 
1854     G4double final_Efermi(0);                 << 
1855     G4KineticTrackVector resonances;          << 
1856     for (auto i =products->cbegin(); i != pro << 
1857     {                                            1429     {
1858         G4int PDGcode=(*i)->GetDefinition()-> << 1430 //       haveProducts = true;
1859         //       G4cout << " PDGcode, state " << 1431 #ifdef debug_BIC_StepParticlesOut
1860         final_Efermi+=((G4RKPropagation *)the << 1432        G4cout << "Capture sucess " << G4endl;
1861         if ( std::abs(PDGcode) > 1000 && PDGc << 1433 #endif
1862         {                                     << 
1863             resonances.push_back(*i);         << 
1864         }                                     << 
1865     }                                            1434     }
1866     if ( resonances.size() > 0 )              << 1435     if ( counter > 100 && theCollisionMgr->Entries() == 0)   // no collision, and stepping a while....
1867     {                                            1436     {
1868         G4double delta_Fermi= (initial_Efermi << 1437         #ifdef debug_1_BinaryCascade
1869         for (auto res=resonances.cbegin(); re << 1438         PrintKTVector(&theSecondaryList,std::string("stepping 100 steps"));
1870         {                                     << 1439   #endif
1871             G4LorentzVector mom=(*res)->Get4M << 1440   FindCollisions(&theSecondaryList);
1872             G4double mass2=mom.mag2();        << 1441   counter=0;
1873             G4double newEnergy=mom.e() + delt << 1442   ++countreset;
1874             G4double newEnergy2= newEnergy*ne << 
1875             //G4cout << "mom = " << mom <<" n << 
1876             if ( newEnergy2 < mass2 )         << 
1877             {                                 << 
1878                 return false;                 << 
1879             }                                 << 
1880             G4ThreeVector mom3=std::sqrt(newE << 
1881             (*res)->Set4Momentum(G4LorentzVec << 
1882                 //G4cout << " correct resonan << 
1883                 //        " 3mom from/to " << << 
1884         }                                     << 
1885     }                                            1443     }
1886     return true;                              << 1444   }
                                                   >> 1445 //  G4cerr <<"Finished capture loop "<<G4endl;
                                                   >> 1446 
                                                   >> 1447        //G4cerr <<"pre- DoTimeStep 4"<<G4endl;
                                                   >> 1448   DoTimeStep(DBL_MAX);
                                                   >> 1449        //G4cerr <<"post- DoTimeStep 4"<<G4endl;
                                                   >> 1450 
                                                   >> 1451 
1887 }                                                1452 }
1888                                                  1453 
1889 //-------------------------------------------    1454 //----------------------------------------------------------------------------
1890 void G4BinaryCascade::CorrectFinalPandE()        1455 void G4BinaryCascade::CorrectFinalPandE()
1891 //-------------------------------------------    1456 //----------------------------------------------------------------------------
1892 //                                               1457 //
1893 //  Modify momenta of outgoing particles.     << 1458 //  Modify momenta of outgoing particles. 
1894 //   Assume two body decay, nucleus(@nominal  << 1459 //   Assume two body decay, nucleus(@nominal mass) + sum of final state particles(SFSP). 
1895 //   momentum of SFSP shall be less than mome << 1460 //   momentum of SFSP shall be less than momentum for two body decay. 
1896 //                                               1461 //
1897 {                                                1462 {
1898 #ifdef debug_BIC_CorrectFinalPandE               1463 #ifdef debug_BIC_CorrectFinalPandE
1899     G4cerr << "BIC: -CorrectFinalPandE called << 1464   G4cerr << " -CorrectFinalPandE 1" << G4endl;
1900 #endif                                           1465 #endif
1901                                                  1466 
1902     if ( theFinalState.size() == 0 ) return;  << 1467  if ( theFinalState.size() == 0 ) return;
1903                                               << 
1904     G4KineticTrackVector::const_iterator i;   << 
1905     G4LorentzVector pNucleus=GetFinal4Momentu << 
1906     if ( pNucleus.e() == 0 ) return;    // ch << 
1907 #ifdef debug_BIC_CorrectFinalPandE            << 
1908     G4cerr << " -CorrectFinalPandE 3" << G4en << 
1909 #endif                                        << 
1910     G4LorentzVector pFinals(0);               << 
1911     for(i = theFinalState.cbegin(); i != theF << 
1912     {                                         << 
1913         pFinals += (*i)->Get4Momentum();      << 
1914 #ifdef debug_BIC_CorrectFinalPandE            << 
1915         G4cout <<"CorrectFinalPandE a final " << 
1916                        << " 4mom " << (*i)->G << 
1917 #endif                                        << 
1918     }                                         << 
1919 #ifdef debug_BIC_CorrectFinalPandE            << 
1920     G4cout << "CorrectFinalPandE pN pF: " <<p << 
1921 #endif                                        << 
1922     G4LorentzVector pCM=pNucleus + pFinals;   << 
1923                                                  1468 
1924     G4LorentzRotation toCMS(-pCM.boostVector( << 
1925     pFinals *=toCMS;                          << 
1926 #ifdef debug_BIC_CorrectFinalPandE               1469 #ifdef debug_BIC_CorrectFinalPandE
1927     G4cout << "CorrectFinalPandE pCM, CMS pCM << 1470   G4cerr << " -CorrectFinalPandE 2" << G4endl;
1928     G4cout << "CorrectFinal CMS pN pF " <<toC << 
1929             <<pFinals << G4endl               << 
1930             << " nucleus initial mass : " <<G << 
1931             <<" massInNucleus m(nucleus) m(fi << 
1932             << pFinals.mag() << " " << pCM.ma << 
1933 #endif                                           1471 #endif
1934                                                  1472 
1935     G4LorentzRotation toLab = toCMS.inverse() << 1473   G4KineticTrackVector::iterator i;
1936                                               << 1474   G4LorentzVector pNucleus=GetFinal4Momentum();
1937     G4double s0 = pCM.mag2();                 << 1475   if ( pNucleus.e() == 0 ) return;    // check against explicit 0 from GetNucleus4Momentum()
1938     G4double m10 = GetIonMass(currentZ,curren << 
1939     G4double m20 = pFinals.mag();             << 
1940     if( s0-(m10+m20)*(m10+m20) < 0 )          << 
1941     {                                         << 
1942 #ifdef debug_BIC_CorrectFinalPandE               1476 #ifdef debug_BIC_CorrectFinalPandE
1943         G4cout << "G4BinaryCascade::CorrectFi << 1477   G4cerr << " -CorrectFinalPandE 3" << G4endl;
1944                                               << 
1945         G4cout << "not enough mass to correct << 
1946                 << (s0-(m10+m20)*(m10+m20)) < << 
1947                 << currentA << " " << current << 
1948                 << m10 << " " << m20          << 
1949                 << G4endl;                    << 
1950         G4cerr << " -CorrectFinalPandE 4" <<  << 
1951                                               << 
1952         PrintKTVector(&theFinalState," mass p << 
1953 #endif                                           1478 #endif
1954         return;                               << 1479   G4LorentzVector pFinals(0);
1955     }                                         << 1480   G4int nFinals(0);
                                                   >> 1481   for(i = theFinalState.begin(); i != theFinalState.end(); ++i)
                                                   >> 1482   {
                                                   >> 1483     pFinals += (*i)->Get4Momentum();
                                                   >> 1484     ++nFinals;
                                                   >> 1485     #ifdef debug_BIC_CorrectFinalPandE
                                                   >> 1486       G4cout <<"CorrectFinalPandE a final " << (*i)->GetDefinition()->GetParticleName()
                                                   >> 1487            << " 4mom " << (*i)->Get4Momentum()<< G4endl;
                                                   >> 1488     #endif
                                                   >> 1489   }
                                                   >> 1490   #ifdef debug_BIC_CorrectFinalPandE
                                                   >> 1491     G4cout << "CorrectFinalPandE pN pF: " <<pNucleus << " " <<pFinals << G4endl;
                                                   >> 1492   #endif
                                                   >> 1493   G4LorentzVector pCM=pNucleus + pFinals;
1956                                                  1494 
1957     // Three momentum in cm system            << 1495   G4LorentzRotation toCMS(-pCM.boostVector());
1958     G4double pInCM = std::sqrt((s0-(m10+m20)* << 1496   pFinals *=toCMS;
1959 #ifdef debug_BIC_CorrectFinalPandE            << 
1960     G4cout <<" CorrectFinalPandE pInCM  new,  << 
1961             << " " << (pFinals).vect().mag()< << 
1962 #endif                                        << 
1963     if ( pFinals.vect().mag() > pInCM )       << 
1964     {                                         << 
1965         G4ThreeVector p3finals=pInCM*pFinals. << 
1966                                                  1497 
1967         G4double factor=std::max(0.98,pInCM/p << 
1968         G4LorentzVector qFinals(0);           << 
1969         for(i = theFinalState.cbegin(); i !=  << 
1970         {                                     << 
1971             //      G4ThreeVector p3((toCMS*( << 
1972             G4ThreeVector p3(factor*(toCMS*(* << 
1973             G4LorentzVector p(p3,std::sqrt((* << 
1974             qFinals += p;                     << 
1975             p *= toLab;                       << 
1976 #ifdef debug_BIC_CorrectFinalPandE               1498 #ifdef debug_BIC_CorrectFinalPandE
1977             G4cout << " final p corrected: "  << 1499   G4cout << "CorrectFinalPandE pCM, CMS pCM " << pCM << " " <<toCMS*pCM<< G4endl;
1978 #endif                                        << 1500   G4cout << "CorrectFinal CMS pN pF " <<toCMS*pNucleus << " "
1979             (*i)->Set4Momentum(p);            << 1501          <<pFinals << G4endl
1980         }                                     << 1502          << " nucleus initial mass : " <<GetFinal4Momentum().mag()
1981 #ifdef debug_BIC_CorrectFinalPandE            << 1503    <<" massInNucleus m(nucleus) m(finals) std::sqrt(s): " << massInNucleus << " " <<pNucleus.mag()<< " "
1982         G4cout << "CorrectFinalPandE nucleus  << 1504    << pFinals.mag() << " " << pCM.mag() << G4endl;
1983                 <<GetFinal4Momentum().mag() < << 1505 #endif
1984                 << " CMS pFinals , mag, 3.mag << 1506 
1985         G4cerr << " -CorrectFinalPandE 5 " << << 1507   G4LorentzRotation toLab = toCMS.inverse();
1986 #endif                                        << 1508 
                                                   >> 1509   G4double s = pCM.mag2();
                                                   >> 1510 //  G4double m10 = massInNucleus; //pNucleus.mag();
                                                   >> 1511   G4double m10 = GetIonMass(currentZ,currentA);
                                                   >> 1512   G4double m20 = pFinals.mag();
                                                   >> 1513   if( s-(m10+m20)*(m10+m20) < 0 )
                                                   >> 1514   {
                                                   >> 1515        #ifdef debug_BIC_CorrectFinalPandE
                                                   >> 1516   G4cout << "G4BinaryCascade::CorrectFinalPandE() : error! " << G4endl;
                                                   >> 1517 
                                                   >> 1518   G4cout << "not enough mass to correct: mass, A,Z, mass(nucl), mass(finals) " 
                                                   >> 1519               << std::sqrt(-s+(m10+m20)*(m10+m20)) << " " 
                                                   >> 1520         << currentA << " " << currentZ << " "
                                                   >> 1521         << m10 << " " << m20 
                                                   >> 1522         << G4endl;
                                                   >> 1523   G4cerr << " -CorrectFinalPandE 4" << G4endl;
                                                   >> 1524 
                                                   >> 1525   PrintKTVector(&theFinalState," mass problem");
                                                   >> 1526        #endif
                                                   >> 1527       return;
                                                   >> 1528   }
                                                   >> 1529 
                                                   >> 1530   // Three momentum in cm system
                                                   >> 1531   G4double pInCM = std::sqrt((s-(m10+m20)*(m10+m20))*(s-(m10-m20)*(m10-m20))/(4.*s));
                                                   >> 1532     #ifdef debug_BIC_CorrectFinalPandE
                                                   >> 1533     G4cout <<" CorrectFinalPandE pInCM  new, CURRENT, ratio : " << pInCM 
                                                   >> 1534        << " " << (pFinals).vect().mag()<< " " <<  pInCM/(pFinals).vect().mag() << G4endl;
                                                   >> 1535     #endif
                                                   >> 1536   if ( pFinals.vect().mag() > pInCM )
                                                   >> 1537   {
                                                   >> 1538     G4ThreeVector p3finals=pInCM*pFinals.vect().unit();
                                                   >> 1539 
                                                   >> 1540 //    G4ThreeVector deltap=(p3finals - pFinals.vect() ) / nFinals;
                                                   >> 1541    G4double factor=std::max(0.98,pInCM/pFinals.vect().mag());   // small correction
                                                   >> 1542     G4LorentzVector qFinals(0);
                                                   >> 1543     for(i = theFinalState.begin(); i != theFinalState.end(); ++i)
                                                   >> 1544     {
                                                   >> 1545 //      G4ThreeVector p3((toCMS*(*i)->Get4Momentum()).vect() + deltap);
                                                   >> 1546       G4ThreeVector p3(factor*(toCMS*(*i)->Get4Momentum()).vect());
                                                   >> 1547       G4LorentzVector p(p3,std::sqrt((*i)->Get4Momentum().mag2() + p3.mag2()));
                                                   >> 1548       qFinals += p;
                                                   >> 1549       p *= toLab;
                                                   >> 1550         #ifdef debug_BIC_CorrectFinalPandE
                                                   >> 1551         G4cout << " final p corrected: " << p << G4endl;
                                                   >> 1552         #endif
                                                   >> 1553       (*i)->Set4Momentum(p);
1987     }                                            1554     }
1988 #ifdef debug_BIC_CorrectFinalPandE            << 1555       #ifdef debug_BIC_CorrectFinalPandE
1989     else { G4cerr << " -CorrectFinalPandE 6 - << 1556        G4cout << "CorrectFinalPandE nucleus corrected mass : " << GetFinal4Momentum() << " "
1990 #endif                                        << 1557         <<GetFinal4Momentum().mag() << G4endl
1991                                               << 1558     << " CMS pFinals , mag, 3.mag : " << qFinals << " " << qFinals.mag() << " " << qFinals.vect().mag()<< G4endl;
                                                   >> 1559        G4cerr << " -CorrectFinalPandE 5 " << factor <<  G4endl;  
                                                   >> 1560       #endif
                                                   >> 1561   }
                                                   >> 1562   #ifdef debug_BIC_CorrectFinalPandE
                                                   >> 1563    else { G4cerr << " -CorrectFinalPandE 6 - no correction done" << G4endl; }
                                                   >> 1564   #endif
                                                   >> 1565  
1992 }                                                1566 }
1993                                                  1567 
1994 //-------------------------------------------    1568 //----------------------------------------------------------------------------
1995 void G4BinaryCascade::UpdateTracksAndCollisio    1569 void G4BinaryCascade::UpdateTracksAndCollisions(
1996         //----------------------------------- << 1570 //----------------------------------------------------------------------------
1997         G4KineticTrackVector * oldSecondaries << 1571       G4KineticTrackVector * oldSecondaries,
1998         G4KineticTrackVector * oldTarget,     << 1572       G4KineticTrackVector * oldTarget,
1999         G4KineticTrackVector * newSecondaries << 1573       G4KineticTrackVector * newSecondaries)
2000 {                                             << 1574 {
2001     std::vector<G4KineticTrack *>::const_iter << 1575   // G4cout << "Entering ... "<<oldTarget<<G4endl;
2002                                               << 1576   std::vector<G4KineticTrack *>::iterator iter1, iter2;
2003     // remove old secondaries from the second << 1577 
2004     if(oldSecondaries)                        << 1578 // remove old secondaries from the secondary list
                                                   >> 1579   if(oldSecondaries)
                                                   >> 1580   {
                                                   >> 1581     if(!oldSecondaries->empty())
2005     {                                            1582     {
2006         if(!oldSecondaries->empty())          << 1583       for(iter1 = oldSecondaries->begin(); iter1 != oldSecondaries->end();
2007         {                                     << 1584     ++iter1)
2008             for(auto iter1=oldSecondaries->cb << 1585       {
2009             {                                 << 1586   iter2 = std::find(theSecondaryList.begin(), theSecondaryList.end(),
2010                 iter2 = std::find(theSecondar << 1587           *iter1);
2011                 if ( iter2 != theSecondaryLis << 1588   theSecondaryList.erase(iter2);
2012             }                                 << 1589       }
2013             theCollisionMgr->RemoveTracksColl << 1590       theCollisionMgr->RemoveTracksCollisions(oldSecondaries);
2014         }                                     << 
2015     }                                            1591     }
                                                   >> 1592   }
2016                                                  1593 
2017     // remove old target from the target list << 1594 // remove old target from the target list
2018     if(oldTarget)                             << 1595   if(oldTarget)
                                                   >> 1596   {
                                                   >> 1597     // G4cout << "################## Debugging 0 "<<G4endl;
                                                   >> 1598     if(oldTarget->size()!=0)
2019     {                                            1599     {
2020         // G4cout << "################## Debu << 1600       // G4cout << "################## Debugging 1 "<<oldTarget->size()<<G4endl;
2021         if(oldTarget->size()!=0)              << 1601       for(iter1 = oldTarget->begin(); iter1 != oldTarget->end(); ++iter1)
2022         {                                     << 1602       {
2023                                               << 1603   iter2 = std::find(theTargetList.begin(), theTargetList.end(),
2024             // G4cout << "##################  << 1604           *iter1);
2025             for(auto iter1 = oldTarget->cbegi << 1605   theTargetList.erase(iter2);
2026             {                                 << 1606       }
2027                 iter2 = std::find(theTargetLi << 1607       theCollisionMgr->RemoveTracksCollisions(oldTarget);
2028                 theTargetList.erase(iter2);   << 
2029             }                                 << 
2030             theCollisionMgr->RemoveTracksColl << 
2031         }                                     << 
2032     }                                            1608     }
                                                   >> 1609   }
2033                                                  1610 
2034     if(newSecondaries)                        << 1611   if(newSecondaries)
                                                   >> 1612   {
                                                   >> 1613     if(!newSecondaries->empty())
2035     {                                            1614     {
2036         if(!newSecondaries->empty())          << 1615       // insert new secondaries in the secondary list
2037         {                                     << 1616       for(iter1 = newSecondaries->begin(); iter1 != newSecondaries->end();
2038             // insert new secondaries in the  << 1617     ++iter1)
2039             for(auto iter1 = newSecondaries-> << 1618       {
2040             {                                 << 1619   theSecondaryList.push_back(*iter1);
2041                 theSecondaryList.push_back(*i << 1620       }
2042                 if ((*iter1)->GetState() == G << 1621       // look for collisions of new secondaries
2043                 {                             << 1622       FindCollisions(newSecondaries);
2044                    PrintKTVector(*iter1, "und << 
2045                 }                             << 
2046                                               << 
2047                                               << 
2048             }                                 << 
2049             // look for collisions of new sec << 
2050             FindCollisions(newSecondaries);   << 
2051         }                                     << 
2052     }                                            1623     }
2053     // G4cout << "Exiting ... "<<oldTarget<<G << 1624   }
                                                   >> 1625   // G4cout << "Exiting ... "<<oldTarget<<G4endl;
2054 }                                                1626 }
2055                                                  1627 
2056                                                  1628 
2057 class SelectFromKTV                              1629 class SelectFromKTV
2058 {                                                1630 {
2059 private:                                      << 1631   private:
2060     G4KineticTrackVector * ktv;               << 1632   G4KineticTrackVector * ktv;
2061     G4KineticTrack::CascadeState wanted_state << 1633     G4KineticTrack::CascadeState wanted_state;
2062 public:                                       << 1634   public:
2063     SelectFromKTV(G4KineticTrackVector * out, << 1635     SelectFromKTV(G4KineticTrackVector * out, G4KineticTrack::CascadeState astate)
2064     :                                         << 1636   :
2065         ktv(out), wanted_state(astate)        << 1637     ktv(out), wanted_state(astate)
2066     {};                                       << 1638   {};
2067     void operator() (G4KineticTrack *& kt) co << 1639   void operator() (G4KineticTrack *& kt) const 
2068     {                                         << 1640   {
2069         if ( (kt)->GetState() == wanted_state << 1641      if ( (kt)->GetState() == wanted_state ) ktv->push_back(kt);
2070     };                                        << 1642   };
2071 };                                               1643 };
2072                                               << 1644   
2073                                                  1645 
2074                                                  1646 
2075 //-------------------------------------------    1647 //----------------------------------------------------------------------------
2076 G4bool G4BinaryCascade::DoTimeStep(G4double t    1648 G4bool G4BinaryCascade::DoTimeStep(G4double theTimeStep)
2077 //-------------------------------------------    1649 //----------------------------------------------------------------------------
2078 {                                                1650 {
2079                                                  1651 
2080 #ifdef debug_BIC_DoTimeStep                      1652 #ifdef debug_BIC_DoTimeStep
2081     G4ping debug("debug_G4BinaryCascade");    << 1653   G4ping debug("debug_G4BinaryCascade");
2082     debug.push_back("======> DoTimeStep 1");  << 1654   debug.push_back("======> DoTimeStep 1"); debug.dump();
2083     G4cerr <<"G4BinaryCascade::DoTimeStep: en << 1655   G4cerr <<"G4BinaryCascade::DoTimeStep: enter "<< theTimeStep << G4endl;
2084             << " , time="<<theCurrentTime <<  << 1656   PrintKTVector(&theSecondaryList, std::string("DoTimeStep - theSecondaryList"));
2085     PrintKTVector(&theSecondaryList, std::str << 1657 //   PrintKTVector(&theTargetList, std::string("DoTimeStep - theTargetList"));
2086     //PrintKTVector(&theTargetList, std::stri << 1658 #endif
2087 #endif                                        << 1659 
2088                                               << 1660   G4bool success=true;
2089     G4bool success=true;                      << 1661   std::vector<G4KineticTrack *>::iterator iter;
2090     std::vector<G4KineticTrack *>::const_iter << 1662 // Count particles in nucleus
2091                                               << 1663   #ifdef debug_BIC_DoTimeStep
2092     G4KineticTrackVector * kt_outside = new G << 1664   G4int secondaryBarions=0;
2093     std::for_each( theSecondaryList.begin(),t << 1665   G4int secondaryCharge=0;
2094             SelectFromKTV(kt_outside,G4Kineti << 1666   G4double secondaryMass=0;
2095     //PrintKTVector(kt_outside, std::string(" << 1667   #endif
2096                                               << 1668 
2097     G4KineticTrackVector * kt_inside = new G4 << 1669   G4KineticTrackVector * kt_outside = new G4KineticTrackVector;
2098     std::for_each( theSecondaryList.begin(),t << 1670   std::for_each( theSecondaryList.begin(),theSecondaryList.end(),
2099             SelectFromKTV(kt_inside, G4Kineti << 1671            SelectFromKTV(kt_outside,G4KineticTrack::outside));
2100     //  PrintKTVector(kt_inside, std::string( << 1672 //  PrintKTVector(kt_outside, std::string("DoTimeStep - found outside"));   
2101     //-----                                   << 1673 
                                                   >> 1674   G4KineticTrackVector * kt_inside = new G4KineticTrackVector;
                                                   >> 1675   std::for_each( theSecondaryList.begin(),theSecondaryList.end(),
                                                   >> 1676            SelectFromKTV(kt_inside, G4KineticTrack::inside));
                                                   >> 1677 //  PrintKTVector(kt_inside, std::string("DoTimeStep - found inside"));   
                                                   >> 1678 //-----
2102     G4KineticTrackVector dummy;   // needed f    1679     G4KineticTrackVector dummy;   // needed for re-usability
2103 #ifdef debug_BIC_DoTimeStep                   << 1680     #ifdef debug_BIC_DoTimeStep
2104     G4cout << "NOW WE ARE ENTERING THE TRANSP    1681     G4cout << "NOW WE ARE ENTERING THE TRANSPORT"<<G4endl;
2105 #endif                                        << 1682     #endif
2106                                               << 
2107     // =================== Here we move the p << 
2108                                               << 
2109     thePropagator->Transport(theSecondaryList << 
2110                                                  1683 
2111     // =================== Here we move the p << 1684 // =================== Here we move the particles  ===================  
2112                                                  1685 
2113     //------                                  << 1686      thePropagator->Transport(theSecondaryList, dummy, theTimeStep);
                                                   >> 1687      
                                                   >> 1688 // =================== Here we move the particles  ===================  
2114                                                  1689 
2115     theMomentumTransfer += thePropagator->Get << 1690 //------
2116 #ifdef debug_BIC_DoTimeStep                      1691 #ifdef debug_BIC_DoTimeStep
2117     G4cout << "DoTimeStep : theMomentumTransf << 1692   PrintKTVector(&theSecondaryList, std::string("DoTimeStep - secondaries"));
2118     PrintKTVector(&theSecondaryList, std::str << 1693     debug.push_back("======> DoTimeStep 1.1.1"); debug.dump();
2119 #endif                                           1694 #endif
2120                                                  1695 
2121     //_DebugEpConservation(" after stepping") << 1696      theMomentumTransfer += thePropagator->GetMomentumTransfer();
2122                                               << 
2123     // Partclies which went INTO nucleus      << 
2124                                               << 
2125     G4KineticTrackVector * kt_gone_in = new G << 
2126     std::for_each( kt_outside->begin(),kt_out << 
2127             SelectFromKTV(kt_gone_in,G4Kineti << 
2128     //  PrintKTVector(kt_gone_in, std::string << 
2129                                               << 
2130                                               << 
2131     // Partclies which  went OUT OF nucleus   << 
2132     G4KineticTrackVector * kt_gone_out = new  << 
2133     std::for_each( kt_inside->begin(),kt_insi << 
2134             SelectFromKTV(kt_gone_out, G4Kine << 
2135                                               << 
2136     //  PrintKTVector(kt_gone_out, std::strin << 
2137                                               << 
2138     G4KineticTrackVector *fail=CorrectBarions << 
2139                                               << 
2140     if ( fail )                               << 
2141     {                                         << 
2142         // some particle(s) supposed to enter << 
2143         kt_gone_in->clear();                  << 
2144         std::for_each( kt_outside->begin(),kt << 
2145                 SelectFromKTV(kt_gone_in,G4Ki << 
2146                                               << 
2147         kt_gone_out->clear();                 << 
2148         std::for_each( kt_inside->begin(),kt_ << 
2149                 SelectFromKTV(kt_gone_out, G4 << 
2150                                               << 
2151 #ifdef debug_BIC_DoTimeStep                   << 
2152         PrintKTVector(fail,std::string(" Fail << 
2153         PrintKTVector(kt_gone_in, std::string << 
2154         PrintKTVector(kt_gone_out, std::strin << 
2155 #endif                                        << 
2156         delete fail;                          << 
2157     }                                         << 
2158                                               << 
2159     // Add tracks missing nucleus and tracks  << 
2160     std::for_each( kt_outside->begin(),kt_out << 
2161             SelectFromKTV(kt_gone_out,G4Kinet << 
2162     //PrintKTVector(kt_gone_out, std::string( << 
2163     std::for_each( kt_outside->begin(),kt_out << 
2164             SelectFromKTV(kt_gone_out,G4Kinet << 
2165                                               << 
2166 #ifdef debug_BIC_DoTimeStep                      1697 #ifdef debug_BIC_DoTimeStep
2167     PrintKTVector(kt_gone_out, std::string("a << 1698     G4cout << "DoTimeStep : theMomentumTransfer = " << theMomentumTransfer << G4endl;
2168 #endif                                           1699 #endif
                                                   >> 1700      
                                                   >> 1701 // Partclies which went INTO nucleus
                                                   >> 1702 
                                                   >> 1703   G4KineticTrackVector * kt_gone_in = new G4KineticTrackVector;
                                                   >> 1704   std::for_each( kt_outside->begin(),kt_outside->end(),
                                                   >> 1705            SelectFromKTV(kt_gone_in,G4KineticTrack::inside));
                                                   >> 1706 //  PrintKTVector(kt_gone_in, std::string("DoTimeStep - gone in"));   
                                                   >> 1707 
                                                   >> 1708    //PrintKTVector(&theSecondaryList,std::string("aft trsprt....."));
                                                   >> 1709 
                                                   >> 1710 // Partclies which  went OUT OF nucleus
                                                   >> 1711   G4KineticTrackVector * kt_gone_out = new G4KineticTrackVector;
                                                   >> 1712   std::for_each( kt_inside->begin(),kt_inside->end(),
                                                   >> 1713            SelectFromKTV(kt_gone_out, G4KineticTrack::gone_out));
                                                   >> 1714 
                                                   >> 1715 //  PrintKTVector(kt_gone_out, std::string("DoTimeStep - gone out"));   
                                                   >> 1716   G4KineticTrackVector *fail=CorrectBarionsOnBoundary(kt_gone_in,kt_gone_out);
                                                   >> 1717   if ( fail )
                                                   >> 1718   {
                                                   >> 1719     // some particle(s) supposed to leave was captured by the correction
                                                   >> 1720 //     PrintKTVector(fail,std::string(" Failed to go out -> captured"));
                                                   >> 1721      delete fail;
                                                   >> 1722      kt_gone_out->clear();
                                                   >> 1723      std::for_each( kt_inside->begin(),kt_inside->end(),
                                                   >> 1724            SelectFromKTV(kt_gone_out, G4KineticTrack::gone_out));
                                                   >> 1725 //    PrintKTVector(kt_gone_out, std::string("recreated kt_gone_out"));
                                                   >> 1726      
                                                   >> 1727   } 
                                                   >> 1728 
                                                   >> 1729 // Add tracks missing nucleus and tracks going straight though  to addFinals
                                                   >> 1730   std::for_each( kt_outside->begin(),kt_outside->end(),
                                                   >> 1731            SelectFromKTV(kt_gone_out,G4KineticTrack::miss_nucleus));
                                                   >> 1732   std::for_each( kt_outside->begin(),kt_outside->end(),
                                                   >> 1733            SelectFromKTV(kt_gone_out,G4KineticTrack::gone_out));
                                                   >> 1734     
                                                   >> 1735     #ifdef debug_BIC_DoTimeStep
                                                   >> 1736     PrintKTVector(kt_gone_out, std::string("append to final state.."));
                                                   >> 1737     #endif
2169                                                  1738 
2170     theFinalState.insert(theFinalState.end(), << 1739   theFinalState.insert(theFinalState.end(),
2171             kt_gone_out->begin(),kt_gone_out- << 1740       kt_gone_out->begin(),kt_gone_out->end());
2172                                                  1741 
2173     // Partclies which could not leave nucleu << 1742 // Partclies which could not leave nucleus,  captured...
2174     G4KineticTrackVector * kt_captured = new  << 1743   G4KineticTrackVector * kt_captured = new G4KineticTrackVector;
2175     std::for_each( theSecondaryList.begin(),t    1744     std::for_each( theSecondaryList.begin(),theSecondaryList.end(),
2176             SelectFromKTV(kt_captured, G4Kine << 1745            SelectFromKTV(kt_captured, G4KineticTrack::captured));
2177                                                  1746 
2178     // Check no track is part in next collisi << 1747 // Check no track is part in next collision, ie.
2179     //  this step was to far, and collisions  << 1748 //  this step was to far, and collisions should not occur any more 
2180                                                  1749 
2181     if ( theCollisionMgr->Entries()> 0 )      << 1750   if ( theCollisionMgr->Entries()> 0 )
2182     {                                         << 1751   {
2183         if (kt_gone_out->size() )             << 1752      if (kt_gone_out->size() )
2184         {                                     << 1753      {
2185             G4KineticTrack * nextPrimary = th << 1754   G4KineticTrack * nextPrimary = theCollisionMgr->GetNextCollision()->GetPrimary();
2186             iter = std::find(kt_gone_out->beg << 1755   iter = std::find(kt_gone_out->begin(),kt_gone_out->end(),nextPrimary);
2187             if ( iter !=  kt_gone_out->cend() << 1756   if ( iter !=  kt_gone_out->end() )
2188             {                                 << 1757   {
2189                 success=false;                << 1758      success=false;
2190 #ifdef debug_BIC_DoTimeStep                      1759 #ifdef debug_BIC_DoTimeStep
2191                 G4cout << " DoTimeStep - WARN << 1760      G4cout << " DoTimeStep - WARNING: deleting current collision!" << G4endl;
2192 #endif                                           1761 #endif
2193             }                                 << 1762   }
2194         }                                     << 1763      }  
2195         if ( kt_captured->size() )            << 1764      if ( kt_captured->size() )
2196         {                                     << 1765      {
2197             G4KineticTrack * nextPrimary = th << 1766   G4KineticTrack * nextPrimary = theCollisionMgr->GetNextCollision()->GetPrimary();
2198             iter = std::find(kt_captured->beg << 1767   iter = std::find(kt_captured->begin(),kt_captured->end(),nextPrimary);
2199             if ( iter !=  kt_captured->cend() << 1768   if ( iter !=  kt_captured->end() )
2200             {                                 << 1769   {
2201                 success=false;                << 1770      success=false;
2202 #ifdef debug_BIC_DoTimeStep                      1771 #ifdef debug_BIC_DoTimeStep
2203                 G4cout << " DoTimeStep - WARN << 1772      G4cout << " DoTimeStep - WARNING: deleting current collision!" << G4endl;
2204 #endif                                           1773 #endif
2205             }                                 << 1774   }
2206         }                                     << 1775      }  
2207                                               << 
2208     }                                         << 
2209     // PrintKTVector(kt_gone_out," kt_gone_ou << 
2210     UpdateTracksAndCollisions(kt_gone_out,0 , << 
2211                                               << 
2212                                               << 
2213     if ( kt_captured->size() )                << 
2214     {                                         << 
2215         theCapturedList.insert(theCapturedLis << 
2216                 kt_captured->begin(),kt_captu << 
2217         //should be      std::for_each(kt_cap << 
2218         //              std::mem_fun(&G4Kinet << 
2219         // but VC 6 requires:                 << 
2220         for(auto i_captured=kt_captured->cbeg << 
2221         {                                     << 
2222             (*i_captured)->Hit();             << 
2223         }                                     << 
2224         //     PrintKTVector(kt_captured," kt << 
2225         UpdateTracksAndCollisions(kt_captured << 
2226     }                                         << 
2227                                                  1776 
                                                   >> 1777   }
                                                   >> 1778     //G4cout << "Here we are 4 "<<kt_gone_out->size()<<G4endl;
                                                   >> 1779 //     PrintKTVector(kt_gone_out," kt_gone_out be4 updatetrack...");
                                                   >> 1780   UpdateTracksAndCollisions(kt_gone_out,0 ,0);
                                                   >> 1781     //G4cout << "Here we are 5"<<G4endl;
                                                   >> 1782 
                                                   >> 1783 
                                                   >> 1784   if ( kt_captured->size() )
                                                   >> 1785   {
                                                   >> 1786      theCapturedList.insert(theCapturedList.end(),
                                                   >> 1787                             kt_captured->begin(),kt_captured->end());
                                                   >> 1788 //should be      std::for_each(kt_captured->begin(),kt_captured->end(),
                                                   >> 1789 //              std::mem_fun(&G4KineticTrack::Hit));
                                                   >> 1790 // but VC 6 requires:
                                                   >> 1791      std::vector<G4KineticTrack *>::iterator i_captured;
                                                   >> 1792      for(i_captured=kt_captured->begin();i_captured!=kt_captured->end();i_captured++)
                                                   >> 1793      {
                                                   >> 1794         (*i_captured)->Hit();
                                                   >> 1795      }
                                                   >> 1796 //     PrintKTVector(kt_captured," kt_catured be4 updatetrack...");
                                                   >> 1797      UpdateTracksAndCollisions(kt_captured, NULL, NULL);
                                                   >> 1798   }
                                                   >> 1799   
2228 #ifdef debug_G4BinaryCascade                     1800 #ifdef debug_G4BinaryCascade
2229     delete kt_inside;                         << 1801   delete kt_inside;
2230     kt_inside = new G4KineticTrackVector;     << 1802   kt_inside = new G4KineticTrackVector;
2231     std::for_each( theSecondaryList.begin(),t << 1803   std::for_each( theSecondaryList.begin(),theSecondaryList.end(),
2232             SelectFromKTV(kt_inside, G4Kineti << 1804            SelectFromKTV(kt_inside, G4KineticTrack::inside));
2233     if ( currentZ != (GetTotalCharge(theTarge << 1805    if ( currentZ != (GetTotalCharge(theTargetList) 
2234             + GetTotalCharge(theCapturedList) << 1806                     + GetTotalCharge(theCapturedList)
2235             + GetTotalCharge(*kt_inside)) )   << 1807         + GetTotalCharge(*kt_inside)) )
2236     {                                         << 1808    {
2237         G4cout << " error-DoTimeStep aft, A,  << 1809       G4cout << " error-DoTimeStep, aft, A, Z, sec-Z,... "
2238                 << " sum(tgt,capt,active) "   << 1810        << currentA << " "
2239                 << GetTotalCharge(theTargetLi << 1811        << currentZ << " "
2240                 << " targets: "  << GetTotalC << 1812        << GetTotalCharge(theTargetList)
2241                 << " captured: " << GetTotalC << 1813           + GetTotalCharge(theCapturedList)
2242                 << " active: "   << GetTotalC << 1814           + GetTotalCharge(*kt_inside) << " "
2243                 << G4endl;                    << 1815        << GetTotalCharge(theTargetList) << " " 
2244     }                                         << 1816        << GetTotalCharge(theCapturedList) << " "
2245 #endif                                        << 1817        << GetTotalCharge(*kt_inside) << " "
2246                                               << 1818        << G4endl;
2247     delete kt_inside;                         << 1819    }    
2248     delete kt_outside;                        << 1820 #endif
2249     delete kt_captured;                       << 1821 
2250     delete kt_gone_in;                        << 1822   delete kt_inside;
2251     delete kt_gone_out;                       << 1823   delete kt_outside;
                                                   >> 1824   delete kt_captured;
                                                   >> 1825   delete kt_gone_in;
                                                   >> 1826   delete kt_gone_out;
2252                                                  1827 
2253     //  G4cerr <<"G4BinaryCascade::DoTimeStep << 1828 //  G4cerr <<"G4BinaryCascade::DoTimeStep: exit "<<G4endl;
2254     theCurrentTime += theTimeStep;            << 1829   theCurrentTime += theTimeStep;
2255                                                  1830 
2256     //debug.push_back("======> DoTimeStep 2") << 1831   //debug.push_back("======> DoTimeStep 2"); debug.dump();
2257     return success;                           << 1832   return success;
2258                                                  1833 
2259 }                                                1834 }
2260                                                  1835 
2261 //-------------------------------------------    1836 //----------------------------------------------------------------------------
2262 G4KineticTrackVector* G4BinaryCascade::Correc    1837 G4KineticTrackVector* G4BinaryCascade::CorrectBarionsOnBoundary(
2263         G4KineticTrackVector *in,             << 1838                                  G4KineticTrackVector *in, 
2264         G4KineticTrackVector *out)            << 1839                                  G4KineticTrackVector *out)
2265 //-------------------------------------------    1840 //----------------------------------------------------------------------------
2266 {                                                1841 {
2267     G4KineticTrackVector * kt_fail(nullptr);  << 1842    G4KineticTrackVector * kt_fail(0);
2268     std::vector<G4KineticTrack *>::const_iter << 1843    std::vector<G4KineticTrack *>::iterator iter;
2269     //  G4cout << "CorrectBarionsOnBoundary,c << 1844 //  G4cout << "CorrectBarionsOnBoundary,currentZ,currentA," 
2270     //         << currentZ << " "<< currentA  << 1845 //         << currentZ << " "<< currentA << G4endl;
2271     if (in->size())                           << 1846   if (in->size())
2272     {                                         << 1847   {
2273         G4int secondaries_in(0);              << 1848      G4int secondaries_in(0);
2274         G4int secondaryBarions_in(0);         << 1849      G4int secondaryBarions_in(0);
2275         G4int secondaryCharge_in(0);          << 1850      G4int secondaryCharge_in(0);
2276         G4double secondaryMass_in(0);         << 1851      G4double secondaryMass_in(0);
2277                                               << 1852 
2278         for ( iter =in->cbegin(); iter != in- << 1853      for ( iter =in->begin(); iter != in->end(); ++iter)
2279         {                                     << 1854      {
2280             ++secondaries_in;                 << 1855    ++secondaries_in;
2281             secondaryCharge_in += G4lrint((*i << 1856    secondaryCharge_in += G4lrint((*iter)->GetDefinition()->GetPDGCharge());
2282             if ((*iter)->GetDefinition()->Get << 1857    if ((*iter)->GetDefinition()->GetBaryonNumber()==1 )
2283             {                                 << 1858    {
2284                 secondaryBarions_in += (*iter << 1859       ++secondaryBarions_in;
2285                 if((*iter)->GetDefinition() = << 1860       if((*iter)->GetDefinition() == G4Neutron::Neutron() ||
2286                         (*iter)->GetDefinitio << 1861          (*iter)->GetDefinition() == G4Proton::Proton()  )
2287                 {                             << 1862       {
2288                     secondaryMass_in += (*ite << 1863          secondaryMass_in += (*iter)->GetDefinition()->GetPDGMass();
2289                 } else    {                   << 1864       } else    {
2290                     secondaryMass_in += G4Pro << 1865         secondaryMass_in += G4Proton::Proton()->GetPDGMass();
2291                 }                             << 1866       }
2292             }                                 << 1867    }
2293         }                                     << 1868      }
2294         G4double mass_initial= GetIonMass(cur << 1869      G4double mass_initial= GetIonMass(currentZ,currentA);
2295                                               << 1870           
2296         currentZ += secondaryCharge_in;       << 1871      currentZ += secondaryCharge_in;
2297         currentA += secondaryBarions_in;      << 1872      currentA += secondaryBarions_in;
2298                                               << 1873      
2299         //  G4cout << "CorrectBarionsOnBounda << 1874 //  G4cout << "CorrectBarionsOnBoundary,secondaryCharge_in, secondaryBarions_in"
2300         //         <<    secondaryCharge_in < << 1875 //         <<    secondaryCharge_in << " "<<  secondaryBarions_in << G4endl;
2301                                               << 1876      
2302         G4double mass_final= GetIonMass(curre << 1877      G4double mass_final= GetIonMass(currentZ,currentA);
2303                                               << 1878      
2304         G4double correction= secondaryMass_in << 1879      G4double correction= secondaryMass_in + mass_initial - mass_final;
2305         if (secondaries_in>1)                 << 1880      if (secondaries_in>1) 
2306         {correction /= secondaries_in;}       << 1881        {correction /= secondaries_in;}
2307                                                  1882 
2308 #ifdef debug_BIC_CorrectBarionsOnBoundary        1883 #ifdef debug_BIC_CorrectBarionsOnBoundary
2309         G4cout << "CorrectBarionsOnBoundary,c << 1884        G4cout << "CorrectBarionsOnBoundary,currentZ,currentA,"
2310                 << "secondaryCharge_in,second << 1885              << "secondaryCharge_in,secondaryBarions_in," 
2311                 << "energy correction,m_secon << 1886              << "energy correction,m_secondry,m_nucl_init,m_nucl_final "
2312                 << currentZ << " "<< currentA << 1887    << currentZ << " "<< currentA <<" "
2313                 << secondaryCharge_in<<" "<<s << 1888    << secondaryCharge_in<<" "<<secondaryBarions_in<<" "
2314                 << correction << " "          << 1889    << correction << " "
2315                 << secondaryMass_in << " "    << 1890    << secondaryMass_in << " "
2316                 << mass_initial << " "        << 1891    << mass_initial << " "
2317                 << mass_final << " "          << 1892    << mass_final << " "
2318                 << G4endl;                    << 1893    << G4endl;
2319         PrintKTVector(in,std::string("in be4  << 1894      PrintKTVector(in,std::string("in be4 correction"));
2320 #endif                                        << 1895 #endif
2321         for ( iter = in->cbegin(); iter != in << 1896  
2322         {                                     << 1897      for ( iter = in->begin(); iter != in->end(); ++iter)
2323             if ((*iter)->GetTrackingMomentum( << 1898      {
2324             {                                 << 1899   (*iter)->UpdateTrackingMomentum((*iter)->GetTrackingMomentum().e() + correction);
2325                 (*iter)->UpdateTrackingMoment << 1900      }
2326             } else {                          << 
2327                 //particle cannot go in, put  << 
2328                 G4RKPropagation * RKprop=(G4R << 
2329                 (*iter)->SetState(G4KineticTr << 
2330                 // Undo correction for Colomb << 
2331                 G4double barrier=RKprop->GetB << 
2332                 (*iter)->UpdateTrackingMoment << 
2333                 if ( ! kt_fail ) kt_fail=new  << 
2334                 kt_fail->push_back(*iter);    << 
2335                 currentZ -= G4lrint((*iter)-> << 
2336                 currentA -= (*iter)->GetDefin << 
2337                                               << 
2338             }                                 << 
2339                                               << 
2340         }                                     << 
2341 #ifdef debug_BIC_CorrectBarionsOnBoundary        1901 #ifdef debug_BIC_CorrectBarionsOnBoundary
2342         G4cout << " CorrectBarionsOnBoundary, << 1902    G4cout << " CorrectBarionsOnBoundary, aft, A, Z, sec-Z,A,m,m_in_nucleus "
2343                 << currentZ << " " << current << 1903        << currentA << " " << currentZ << " "
2344                 << secondaryCharge_in << " "  << 1904        << secondaryCharge_in << " " << secondaryBarions_in << " "
2345                 << secondaryMass_in  << " "   << 1905        << secondaryMass_in  << " "
2346                 << G4endl;                    << 1906        << G4endl;
2347         PrintKTVector(in,std::string("in AFT  << 1907      PrintKTVector(in,std::string("in AFT correction"));
2348 #endif                                        << 1908 #endif
2349                                               << 1909     
2350     }                                         << 1910   }
2351     //--------------------------------------- << 1911 //----------------------------------------------
2352     if (out->size())                          << 1912   if (out->size())
2353     {                                         << 1913   {
2354         G4int secondaries_out(0);             << 1914      G4int secondaries_out(0);
2355         G4int secondaryBarions_out(0);        << 1915      G4int secondaryBarions_out(0);
2356         G4int secondaryCharge_out(0);         << 1916      G4int secondaryCharge_out(0);
2357         G4double secondaryMass_out(0);        << 1917      G4double secondaryMass_out(0);
2358                                               << 1918 
2359         for ( iter = out->cbegin(); iter != o << 1919      for ( iter =out->begin(); iter != out->end(); ++iter)
2360         {                                     << 1920      {
2361             ++secondaries_out;                << 1921    ++secondaries_out;
2362             secondaryCharge_out += G4lrint((* << 1922    secondaryCharge_out += G4lrint((*iter)->GetDefinition()->GetPDGCharge());
2363             if ((*iter)->GetDefinition()->Get << 1923    if ((*iter)->GetDefinition()->GetBaryonNumber()==1 )
2364             {                                 << 1924    {
2365                 secondaryBarions_out += (*ite << 1925       ++secondaryBarions_out;
2366                 if((*iter)->GetDefinition() = << 1926       if((*iter)->GetDefinition() == G4Neutron::Neutron() ||
2367                         (*iter)->GetDefinitio << 1927          (*iter)->GetDefinition() == G4Proton::Proton()  ) 
2368                 {                             << 1928       {
2369                     secondaryMass_out += (*it << 1929          secondaryMass_out += (*iter)->GetDefinition()->GetPDGMass();
2370                 } else {                      << 1930       } else {
2371                     secondaryMass_out += G4Ne << 1931          secondaryMass_out += G4Neutron::Neutron()->GetPDGMass();
2372                 }                             << 1932       }
2373             }                                 << 1933    }
2374         }                                     << 1934      }
2375                                               << 1935 
2376         G4double mass_initial=  GetIonMass(cu << 1936      G4double mass_initial=  GetIonMass(currentZ,currentA);
2377         currentA -=secondaryBarions_out;      << 1937      currentA -=secondaryBarions_out;
2378         currentZ -=secondaryCharge_out;       << 1938      currentZ -=secondaryCharge_out;
2379                                               << 1939 
2380         //  G4cout << "CorrectBarionsOnBounda << 1940 //  G4cout << "CorrectBarionsOnBoundary,secondaryCharge_out, secondaryBarions_out"
2381         //         <<    secondaryCharge_out  << 1941 //         <<    secondaryCharge_out << " "<<  secondaryBarions_out << G4endl;
2382                                               << 1942 
2383         //                        a delta min << 1943 //                        a delta minus will do currentZ < 0 in light nuclei
2384         //     if (currentA < 0 || currentZ < << 1944 //     if (currentA < 0 || currentZ < 0 ) 
2385         if (currentA < 0 )                    << 1945      if (currentA < 0 ) 
2386         {                                     << 1946      {   
2387             G4cerr << "G4BinaryCascade - seco << 1947     G4cerr << "G4BinaryCascade - secondaryBarions_out,secondaryCharge_out " <<
2388                     secondaryBarions_out << " << 1948            secondaryBarions_out << " " << secondaryCharge_out << G4endl;
2389             PrintKTVector(&theTargetList,"Cor << 1949   PrintKTVector(&theTargetList,"CorrectBarionsOnBoundary Target");
2390             PrintKTVector(&theCapturedList,"C << 1950   PrintKTVector(&theCapturedList,"CorrectBarionsOnBoundary Captured");
2391             PrintKTVector(&theSecondaryList," << 1951   PrintKTVector(&theSecondaryList,"CorrectBarionsOnBoundary Secondaries");
2392             G4cerr << "G4BinaryCascade - curr << 1952         G4cerr << "G4BinaryCascade - currentA, currentZ " << currentA << " " << currentZ << G4endl; 
2393             throw G4HadronicException(__FILE_ << 1953         throw G4HadronicException(__FILE__, __LINE__, "G4BinaryCascade::CorrectBarionsOnBoundary() - fatal error");
2394         }                                     << 1954      }
2395         G4double mass_final=GetIonMass(curren << 1955      G4double mass_final=GetIonMass(currentZ,currentA);
2396         G4double correction= mass_initial - m << 1956      G4double correction= mass_initial - mass_final - secondaryMass_out;
2397         // G4cout << "G4BinaryCascade::Correc << 
2398                                                  1957 
2399         if (secondaries_out>1) correction /=  << 1958      if (secondaries_out>1) correction /= secondaries_out;
2400 #ifdef debug_BIC_CorrectBarionsOnBoundary        1959 #ifdef debug_BIC_CorrectBarionsOnBoundary
2401         G4cout << "DoTimeStep,(current Z,A)," << 1960        G4cout << "DoTimeStep,currentZ,currentA,"
2402                 << "(secondaries out,Charge,B << 1961         << "secondaries_out,"
2403                 <<"* energy correction,(m_sec << 1962               <<"secondaryCharge_out,secondaryBarions_out,"
2404                 << "("<< currentZ << ","<< cu << 1963         <<"energy correction,m_secondry,m_nucl_init,m_nucl_final "
2405                 << secondaries_out << ","     << 1964    << " "<< currentZ << " "<< currentA <<" "
2406                 << secondaryCharge_out<<","<< << 1965    << secondaries_out << " " 
2407                 << correction << " ("         << 1966    << secondaryCharge_out<<" "<<secondaryBarions_out<<" "
2408                 << secondaryMass_out << ", "  << 1967    << correction << " "
2409                 << mass_initial << ", "       << 1968    << secondaryMass_out << " "
2410                 << mass_final << ")"          << 1969    << mass_initial << " "
2411                 << G4endl;                    << 1970    << mass_final << " "
2412         PrintKTVector(out,std::string("out be << 1971    << G4endl;
2413 #endif                                        << 1972      PrintKTVector(out,std::string("out be4 correction"));
2414                                               << 1973 #endif
2415         for ( iter = out->cbegin(); iter != o << 1974  
2416         {                                     << 1975      for ( iter = out->begin(); iter != out->end(); ++iter)
2417             if ((*iter)->GetTrackingMomentum( << 1976      {
2418             {                                 << 1977         if ((*iter)->GetTrackingMomentum().e()+correction > (*iter)->GetActualMass())
2419                 (*iter)->UpdateTrackingMoment << 1978   {
2420             } else                            << 1979      (*iter)->UpdateTrackingMomentum((*iter)->GetTrackingMomentum().e() + correction);
2421             {                                 << 1980   } else
2422                 // particle cannot go out due << 1981   {
2423                 //  capture protons and neutr << 1982      // particle cannot go out due to change of nuclear potential! 
2424                 if(((*iter)->GetDefinition()  << 1983      //  capture protons and neutrons; 
2425                         ((*iter)->GetDefiniti << 1984      if(((*iter)->GetDefinition() == G4Proton::Proton()) ||
2426                 {                             << 1985      ((*iter)->GetDefinition() == G4Neutron::Neutron()))
2427                     (*iter)->SetState(G4Kinet << 1986            {
2428                     // Undo correction for Co << 1987        G4RKPropagation * RKprop=(G4RKPropagation *)thePropagator;
2429                     G4double barrier=((G4RKPr << 1988        (*iter)->SetState(G4KineticTrack::captured);
2430                     (*iter)->UpdateTrackingMo << 1989        // Undo correction for Colomb Barrier
2431                     if ( kt_fail == 0 ) kt_fa << 1990        G4double barrier=RKprop->GetBarrier((*iter)->GetDefinition()->GetPDGEncoding());
2432                     kt_fail->push_back(*iter) << 1991        (*iter)->UpdateTrackingMomentum((*iter)->GetTrackingMomentum().e() - barrier); 
2433                     currentZ += G4lrint((*ite << 1992        if ( kt_fail == 0 ) kt_fail=new G4KineticTrackVector;
2434                     currentA += (*iter)->GetD << 1993        kt_fail->push_back(*iter);   
2435                 }                             << 1994        currentZ += G4lrint((*iter)->GetDefinition()->GetPDGCharge());
                                                   >> 1995        if ((*iter)->GetDefinition()->GetBaryonNumber()==1 ) ++currentA;
                                                   >> 1996      } 
2436 #ifdef debug_BIC_CorrectBarionsOnBoundary        1997 #ifdef debug_BIC_CorrectBarionsOnBoundary
2437                 else                          << 1998      else
2438                 {                             << 1999      {
2439                     G4cout << "Not correcting << 2000         G4cout << "Not correcting outgoing " << *iter << " " 
2440                             << (*iter)->GetDe << 2001                << (*iter)->GetDefinition()->GetPDGEncoding() << " " 
2441                             << (*iter)->GetDe << 2002          << (*iter)->GetDefinition()->GetParticleName() << G4endl;
2442                     PrintKTVector(out,std::st << 2003         PrintKTVector(out,std::string("outgoing, one not corrected"));
2443                 }                             << 2004      }          
2444 #endif                                           2005 #endif
2445             }                                 << 2006   }   
2446         }                                     << 2007      }
2447                                                  2008 
2448 #ifdef debug_BIC_CorrectBarionsOnBoundary        2009 #ifdef debug_BIC_CorrectBarionsOnBoundary
2449         PrintKTVector(out,std::string("out AF << 2010      PrintKTVector(out,std::string("out AFTER correction"));
2450         G4cout << " DoTimeStep, nucl-update,  << 2011       G4cout << " DoTimeStep, nucl-update, A, Z, sec-Z,A,m,m_in_nucleus, table-mass, delta "
2451                 << currentA << " "<< currentZ << 2012         << currentA << " "<< currentZ << " "
2452                 << secondaryCharge_out << " " << 2013   << secondaryCharge_out << " "<< secondaryBarions_out << " "<<
2453                 secondaryMass_out << " "      << 2014   secondaryMass_out << " "
2454                 << massInNucleus << " "       << 2015         << massInNucleus << " "
2455                 << GetIonMass(currentZ,curren << 2016         << G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(currentZ,currentA)
2456                 << " " << massInNucleus - Get << 2017         << " " << massInNucleus -G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(currentZ,currentA)
2457                 << G4endl;                    << 2018   << G4endl;
2458 #endif                                        << 2019 #endif
2459     }                                         << 2020   }
2460                                               << 2021   
2461     return kt_fail;                           << 2022   return kt_fail;
2462 }                                                2023 }
2463                                                  2024 
2464                                               << 2025              
2465 //-------------------------------------------    2026 //----------------------------------------------------------------------------
2466                                                  2027 
2467 G4Fragment * G4BinaryCascade::FindFragments()    2028 G4Fragment * G4BinaryCascade::FindFragments()
2468 //-------------------------------------------    2029 //----------------------------------------------------------------------------
2469 {                                                2030 {
2470                                                  2031 
                                                   >> 2032   G4int a = theTargetList.size()+theCapturedList.size();
2471 #ifdef debug_BIC_FindFragments                   2033 #ifdef debug_BIC_FindFragments
2472     G4cout << "target, captured, secondary: " << 2034   G4cout << "target, captured, secondary: "
2473             << theTargetList.size() << " "    << 2035          << theTargetList.size() << " " 
2474             << theCapturedList.size()<< " "   << 2036    << theCapturedList.size()<< " "
2475             << theSecondaryList.size()        << 2037    << theSecondaryList.size()
2476             << G4endl;                        << 2038    << G4endl;
2477 #endif                                        << 2039 #endif
2478                                               << 2040   G4int zTarget = 0;
2479     G4int a = G4int(theTargetList.size()+theC << 2041   G4KineticTrackVector::iterator i;
2480     G4int zTarget = 0;                        << 2042   for(i = theTargetList.begin(); i != theTargetList.end(); ++i)
2481     for(auto i = theTargetList.cbegin(); i != << 2043   {
2482     {                                         << 2044       if((*i)->GetDefinition()->GetPDGCharge() == eplus)
2483         if(G4lrint((*i)->GetDefinition()->Get << 2045       {
2484         {                                     << 2046          zTarget++;
2485             zTarget++;                        << 2047       }
2486         }                                     << 2048   }
2487     }                                         << 
2488                                                  2049 
2489     G4int zCaptured = 0;                      << 2050   G4int zCaptured = 0;
2490     G4LorentzVector CapturedMomentum(0.,0.,0. << 2051   G4LorentzVector CapturedMomentum=0;
2491     for(auto i = theCapturedList.cbegin(); i  << 2052   for(i = theCapturedList.begin(); i != theCapturedList.end(); ++i)
2492     {                                         << 2053   {
2493         CapturedMomentum += (*i)->Get4Momentu << 2054       CapturedMomentum += (*i)->Get4Momentum();
2494         if(G4lrint((*i)->GetDefinition()->Get << 2055       if((*i)->GetDefinition()->GetPDGCharge() == eplus)
2495         {                                     << 2056       {
2496             zCaptured++;                      << 2057    zCaptured++;
2497         }                                     << 2058       }
2498     }                                         << 2059   }
2499                                                  2060 
2500     G4int z = zTarget+zCaptured;              << 2061   G4int z = zTarget+zCaptured;
2501                                                  2062 
2502 #ifdef debug_G4BinaryCascade                     2063 #ifdef debug_G4BinaryCascade
2503     if ( z != (GetTotalCharge(theTargetList)  << 2064   if ( z != (GetTotalCharge(theTargetList) + GetTotalCharge(theCapturedList)) )
2504     {                                         << 2065   {
2505         G4cout << " FindFragment Counting err << 2066       G4cout << " FindFragment Counting error z a " << z << " " <<a << " "  
2506                 << GetTotalCharge(theTargetLi << 2067       << GetTotalCharge(theTargetList) << " " <<  GetTotalCharge(theCapturedList)<<
2507                 G4endl;                       << 2068       G4endl;
2508         PrintKTVector(&theTargetList, std::st << 2069       PrintKTVector(&theTargetList, std::string("theTargetList"));
2509         PrintKTVector(&theCapturedList, std:: << 2070       PrintKTVector(&theCapturedList, std::string("theCapturedList"));
2510     }                                         << 2071   }
2511 #endif                                        << 2072 #endif
2512     //debug                                   << 2073 //debug
2513     /*                                        << 2074 /*
2514      *   G4cout << " Fragment mass table / re << 2075  *   G4cout << " Fragment mass table / real "
2515      *          << GetIonMass(z, a)           << 2076  *          << G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(z, a)
2516      *   << " / " << GetFinal4Momentum().mag( << 2077  *   << " / " << GetFinal4Momentum().mag()
2517      *   << " difference "                    << 2078  *   << " difference "
2518      *   <<  GetFinal4Momentum().mag() - GetI << 2079  *   <<  GetFinal4Momentum().mag() - G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(z, a)
2519      *   << G4endl;                           << 2080  *   << G4endl;
2520      */                                       << 2081  */
2521     //                                        << 2082 //
2522     //  if(fBCDEBUG) G4cerr << "Fragment A, Z << 2083 //  if(getenv("BCDEBUG") ) G4cerr << "Fragment A, Z "<< a <<" "<< z<<G4endl;
2523     if ( z < 1 ) return 0;                    << 2084   if ( z < 1 ) return 0;
2524                                               << 2085   G4Fragment * fragment = new G4Fragment(a,z,GetFinalNucleusMomentum());
2525     G4int holes = G4int(the3DNucleus->GetMass << 2086 
2526     G4int excitons = (G4int)theCapturedList.s << 2087   G4int holes = the3DNucleus->GetMassNumber() - theTargetList.size();
                                                   >> 2088   fragment->SetNumberOfHoles(holes);
                                                   >> 2089 
                                                   >> 2090   G4int excitons = theCapturedList.size();
                                                   >> 2091 //GF  fragment->SetNumberOfParticles(excitons-holes);
                                                   >> 2092   fragment->SetNumberOfParticles(excitons);
                                                   >> 2093   fragment->SetNumberOfCharged(zCaptured);
                                                   >> 2094   G4ParticleDefinition * aIonDefinition =
                                                   >> 2095        G4ParticleTable::GetParticleTable()->FindIon(a,z,0,z);
                                                   >> 2096   fragment->SetParticleDefinition(aIonDefinition);
2527 #ifdef debug_BIC_FindFragments                   2097 #ifdef debug_BIC_FindFragments
2528     G4cout << "Fragment: a= " << a << " z= "  << 2098    G4cout << "Fragment: a= " << a
2529             << " Charged= " << zCaptured << " << 2099    << " z= " << z
2530             << " excitE= " <<GetExcitationEne << 2100    << " particles= " <<  excitons
2531             << " Final4Momentum= " << GetFina << 2101    << " Charged= " << zCaptured
2532             << G4endl;                        << 2102    << " holes= " << holes
2533 #endif                                        << 2103    << " excitE= " <<GetExcitationEnergy()
2534                                               << 2104    << " Final4Momentum= " << GetFinalNucleusMomentum()
2535     G4Fragment * fragment = new G4Fragment(a, << 2105    << " capturMomentum= " << CapturedMomentum
2536     fragment->SetNumberOfHoles(holes);        << 2106    << G4endl;
2537                                               << 2107 #endif
2538     //GF  fragment->SetNumberOfParticles(exci << 
2539     fragment->SetNumberOfParticles(excitons); << 
2540     fragment->SetNumberOfCharged(zCaptured);  << 
2541     fragment->SetCreatorModelID(theBIC_ID);   << 
2542                                                  2108 
2543     return fragment;                          << 2109   return fragment;
2544 }                                                2110 }
2545                                                  2111 
2546 //-------------------------------------------    2112 //----------------------------------------------------------------------------
2547                                                  2113 
2548 G4LorentzVector G4BinaryCascade::GetFinal4Mom    2114 G4LorentzVector G4BinaryCascade::GetFinal4Momentum()
2549 //-------------------------------------------    2115 //----------------------------------------------------------------------------
2550 // Return momentum of reminder nulceus;       << 
2551 //  ie. difference of (initial state(primarie << 
2552 {                                                2116 {
2553     G4LorentzVector final4Momentum = theIniti << 2117 // the initial 3-momentum will differ from 0, if nucleus created by string model.
2554     G4LorentzVector finals(0,0,0,0);          << 2118   G4LorentzVector final4Momentum = theInitial4Mom;
2555     for(auto i = theFinalState.cbegin(); i != << 2119   G4KineticTrackVector::iterator i;
2556     {                                         << 2120   for(i = theProjectileList.begin() ; i != theProjectileList.end(); ++i)
2557         final4Momentum -= (*i)->Get4Momentum( << 2121   {
2558         finals       += (*i)->Get4Momentum(); << 2122     final4Momentum += (*i)->GetTrackingMomentum();
2559     }                                         << 2123     //G4cout << "Initial state: "<<(*i)->Get4Momentum()<<G4endl;
2560                                               << 2124   }
2561     if(final4Momentum.e()> 0 && (final4Moment << 2125   for(i = theFinalState.begin(); i != theFinalState.end(); ++i)
2562     {                                         << 2126   {
2563 #ifdef debug_BIC_Final4Momentum               << 2127     final4Momentum -= (*i)->Get4Momentum();
2564         G4cerr << G4endl;                     << 2128   }
2565         G4cerr << "G4BinaryCascade::GetFinal4 << 2129 
2566         G4KineticTrackVector::iterator i;     << 2130   if((final4Momentum.vect()/final4Momentum.e()).mag()>1.0 && currentA > 0)
2567         G4cerr <<"Total initial 4-momentum "  << 2131   {
2568         G4cerr <<" GetFinal4Momentum: Initial << 2132 #  ifdef debug_BIC_Final4Momentum
2569         for(i = theFinalState.begin(); i != t << 2133      G4cerr << G4endl;
2570         {                                     << 2134      G4cerr << "G4BinaryCascade::GetFinal4Momentum - Fatal"<<G4endl;
2571             G4cerr <<" Final state: "<<(*i)-> << 2135      G4KineticTrackVector::iterator i;
2572         }                                     << 2136      G4cerr <<" Initial nucleus "<<theInitial4Mom<<G4endl;
2573         G4cerr << "Sum( 4-mom ) finals " << f << 2137      for(i = theProjectileList.begin() ; i != theProjectileList.end(); ++i)
2574         G4cerr<< " Final4Momentum = "<<final4 << 2138      {
2575         G4cerr <<" current A, Z = "<< current << 2139        G4cerr << " Initial state (get4M), (trackingM): "
2576         G4cerr << G4endl;                     << 2140             <<(*i)->Get4Momentum()<<", " << (*i)->GetTrackingMomentum() <<","
2577 #endif                                        << 2141       <<(*i)->GetDefinition()->GetParticleName()<<G4endl;
2578                                               << 2142      }
2579         final4Momentum=G4LorentzVector(0,0,0, << 2143      for(i = theFinalState.begin(); i != theFinalState.end(); ++i)
2580     }                                         << 2144      {
2581     return final4Momentum;                    << 2145        G4cerr <<" Final state: "<<(*i)->Get4Momentum()<<(*i)->GetDefinition()->GetParticleName()<<G4endl;
                                                   >> 2146      }
                                                   >> 2147      G4cerr<< " Final4Momentum = "<<final4Momentum <<" "<<final4Momentum.m()<<G4endl;
                                                   >> 2148      G4cerr <<" current A, Z = "<< currentA<<", "<<currentZ<<G4endl;
                                                   >> 2149      G4cerr << G4endl;
                                                   >> 2150 #  endif
                                                   >> 2151 
                                                   >> 2152      final4Momentum=G4LorentzVector(0);
                                                   >> 2153   }
                                                   >> 2154   return final4Momentum;
2582 }                                                2155 }
2583                                                  2156 
2584 //-------------------------------------------    2157 //----------------------------------------------------------------------------
2585 G4LorentzVector G4BinaryCascade::GetFinalNucl    2158 G4LorentzVector G4BinaryCascade::GetFinalNucleusMomentum()
2586 //-------------------------------------------    2159 //----------------------------------------------------------------------------
2587 {                                                2160 {
2588     // return momentum of nucleus for use wit << 2161 // return momentum of nucleus for use with precompound model; also keep transformation to
2589     //   apply to precompoud products.        << 2162 //   apply to precompoud products.
2590                                               << 
2591     G4LorentzVector CapturedMomentum(0,0,0,0) << 
2592     //  G4cout << "GetFinalNucleusMomentum Ca << 
2593     for(auto i = theCapturedList.cbegin(); i  << 
2594     {                                         << 
2595         CapturedMomentum += (*i)->Get4Momentu << 
2596     }                                         << 
2597     //G4cout << "GetFinalNucleusMomentum Capt << 
2598     //  G4cerr << "it 9"<<G4endl;             << 
2599                                                  2163 
2600     G4LorentzVector NucleusMomentum = GetFina << 2164   G4LorentzVector CapturedMomentum=0;
2601     if ( NucleusMomentum.e() > 0 )            << 2165   G4KineticTrackVector::iterator i;
2602     {                                         << 2166 //  G4cout << "GetFinalNucleusMomentum Captured size: " <<theCapturedList.size() << G4endl;
2603         // G4cout << "GetFinalNucleusMomentum << 2167   for(i = theCapturedList.begin(); i != theCapturedList.end(); ++i)
2604         // boost nucleus to a frame such that << 2168   {
2605         G4ThreeVector boost= (NucleusMomentum << 2169       CapturedMomentum += (*i)->Get4Momentum();
2606         if(boost.mag2()>1.0)                  << 2170   }
2607         {                                     << 2171 //G4cout << "GetFinalNucleusMomentum CapturedMomentum= " <<CapturedMomentum << G4endl;
                                                   >> 2172 //  G4cerr << "it 9"<<G4endl;
                                                   >> 2173 
                                                   >> 2174   G4LorentzVector NucleusMomentum = GetFinal4Momentum();
                                                   >> 2175   if ( NucleusMomentum.e() > 0 )
                                                   >> 2176   { 
                                                   >> 2177        // G4cout << "GetFinalNucleusMomentum GetFinal4Momentum= " <<NucleusMomentum <<" "<<NucleusMomentum.mag()<<G4endl;
                                                   >> 2178     // boost nucleus to a frame such that the momentum of nucleus == momentum of Captured
                                                   >> 2179       G4ThreeVector boost= (NucleusMomentum.vect() -CapturedMomentum.vect())/NucleusMomentum.e();
                                                   >> 2180       if(boost.mag2()>1.0)
                                                   >> 2181       {
2608 #     ifdef debug_BIC_FinalNucleusMomentum       2182 #     ifdef debug_BIC_FinalNucleusMomentum
2609             G4cerr << "G4BinaryCascade::GetFi << 2183   G4cerr << "G4BinaryCascade::GetFinalNucleusMomentum - Fatal"<<G4endl;
2610             G4cerr << "it 0"<<boost <<G4endl; << 2184   G4cerr << "it 0"<<boost <<G4endl;
2611             G4cerr << "it 01"<<NucleusMomentu << 2185   G4cerr << "it 01"<<NucleusMomentum<<" "<<CapturedMomentum<<" "<<G4endl;
2612             G4cout <<" testing boost "<<boost << 2186   G4cout <<" testing boost "<<boost<<" "<<boost.mag()<<G4endl;
2613 #      endif                                     2187 #      endif
2614             boost=G4ThreeVector(0,0,0);       << 2188   boost=G4ThreeVector(0);
2615             NucleusMomentum=G4LorentzVector(0 << 2189   NucleusMomentum=G4LorentzVector(0);
2616         }                                     << 2190       }
2617         G4LorentzRotation  nucleusBoost( -boo << 2191       G4LorentzRotation  nucleusBoost( -boost );
2618         precompoundLorentzboost.set( boost ); << 2192       precompoundLorentzboost.set( boost );
2619 #ifdef debug_debug_BIC_FinalNucleusMomentum   << 2193     #ifdef debug_debug_BIC_FinalNucleusMomentum
2620         G4cout << "GetFinalNucleusMomentum be << 2194       G4cout << "GetFinalNucleusMomentum be4 boostNucleusMomentum, CapturedMomentum"<<NucleusMomentum<<" "<<CapturedMomentum<<" "<<G4endl;
2621 #endif                                        << 2195      #endif
2622         NucleusMomentum *= nucleusBoost;      << 2196      NucleusMomentum *= nucleusBoost;
2623 #ifdef debug_BIC_FinalNucleusMomentum         << 2197     #ifdef debug_BIC_FinalNucleusMomentum
2624         G4cout << "GetFinalNucleusMomentum af << 2198       G4cout << "GetFinalNucleusMomentum aft boost GetFinal4Momentum= " <<NucleusMomentum <<G4endl;
2625 #endif                                        << 2199     #endif
2626     }                                         << 2200   }
2627     return NucleusMomentum;                   << 2201   return NucleusMomentum;
2628 }                                                2202 }
2629                                                  2203 
2630 //-------------------------------------------    2204 //----------------------------------------------------------------------------
2631 G4ReactionProductVector * G4BinaryCascade::Pr    2205 G4ReactionProductVector * G4BinaryCascade::Propagate1H1(
2632         //----------------------------------- << 2206 //----------------------------------------------------------------------------
2633         G4KineticTrackVector * secondaries, G << 2207     G4KineticTrackVector * secondaries, G4V3DNucleus * nucleus)
2634 {                                                2208 {
2635     G4ReactionProductVector * products = new     2209     G4ReactionProductVector * products = new G4ReactionProductVector;
2636     const G4ParticleDefinition * aHTarg = G4P << 2210     G4ParticleDefinition * aHTarg = G4Proton::ProtonDefinition();
2637     if (nucleus->GetCharge() == 0) aHTarg = G << 
2638     G4double mass = aHTarg->GetPDGMass();        2211     G4double mass = aHTarg->GetPDGMass();
2639     G4KineticTrackVector * secs = nullptr;    << 2212     if (nucleus->GetCharge() == 0) aHTarg = G4Neutron::NeutronDefinition();
                                                   >> 2213     mass = aHTarg->GetPDGMass();
                                                   >> 2214     G4KineticTrackVector * secs = 0;
2640     G4ThreeVector pos(0,0,0);                    2215     G4ThreeVector pos(0,0,0);
2641     G4LorentzVector mom(mass);                   2216     G4LorentzVector mom(mass);
2642     G4KineticTrack aTarget(aHTarg, 0., pos, m    2217     G4KineticTrack aTarget(aHTarg, 0., pos, mom);
2643     G4bool done(false);                          2218     G4bool done(false);
2644     // data member    static G4Scatterer theH << 2219     std::vector<G4KineticTrack *>::iterator iter, jter;
2645     //G4cout << " start 1H1 for " << (*second << 2220     static G4Scatterer theScatterer;
2646     //       << " on " << aHTarg->GetParticle << 2221 //G4cout << " start 1H1 for " << (*secondaries).front()->GetDefinition()->GetParticleName()
                                                   >> 2222 //       << " on " << aHTarg->GetParticleName() << G4endl;  
2647     G4int tryCount(0);                           2223     G4int tryCount(0);
2648     while(!done && tryCount++ <200)           << 2224     while(!done && tryCount++ <200)
2649     {                                            2225     {
2650         if(secs)                              << 2226       if(secs)
2651         {                                     << 2227       {
2652             std::for_each(secs->begin(), secs << 2228        std::for_each(secs->begin(), secs->end(), DeleteKineticTrack());
2653             delete secs;                      << 2229        delete secs;
2654         }                                     << 2230       }
2655         secs = theH1Scatterer->Scatter(*(*sec << 2231       secs = theScatterer.Scatter(*(*secondaries).front(), aTarget);
2656 #ifdef debug_H1_BinaryCascade                 << 2232       for(size_t ss=0; secs && ss<secs->size(); ss++)
2657         PrintKTVector(secs," From Scatter");  << 2233       {
2658 #endif                                        << 2234 //        G4cout << "1H1 " << (*secs)[ss]->GetDefinition()->GetParticleName()
2659         for(std::size_t ss=0; secs && ss<secs << 2235 //         << ", shortlived? "<< (*secs)[ss]->GetDefinition()->IsShortLived()<< G4endl;
2660         {                                     << 2236         if((*secs)[ss]->GetDefinition()->IsShortLived()) done = true;
2661             // must have one resonance in fin << 2237       }
2662             if((*secs)[ss]->GetDefinition()-> << 2238 //    G4cout << G4endl;
2663         }                                     << 
2664     }                                            2239     }
2665                                               << 2240     size_t current(0);
2666     ClearAndDestroy(&theFinalState);          << 2241     for(current=0; current<secs->size(); current++)
2667     ClearAndDestroy(secondaries);             << 
2668     delete secondaries;                       << 
2669                                               << 
2670     for(std::size_t current=0; secs && curren << 
2671     {                                            2242     {
2672         if((*secs)[current]->GetDefinition()- << 2243       if((*secs)[current]->GetDefinition()->IsShortLived())
2673         {                                     << 2244       {
2674             done = true;  // must have one re << 2245         G4KineticTrackVector * dec = (*secs)[current]->Decay();
2675             G4KineticTrackVector * dec = (*se << 2246   for(jter=dec->begin(); jter != dec->end(); jter++)
2676             for(auto jter=dec->cbegin(); jter << 2247   {
2677             {                                 << 2248     //G4cout << "Decay"<<G4endl;
2678                 //G4cout << "Decay"<<G4endl;  << 2249     secs->push_back(*jter);
2679                 secs->push_back(*jter);       << 2250     //G4cout << "decay "<<(*jter)->GetDefinition()->GetParticleName()<<G4endl;
2680                 //G4cout << "decay "<<(*jter) << 2251   }
2681             }                                 << 2252   delete (*secs)[current];
2682             delete (*secs)[current];          << 2253   delete dec;
2683             delete dec;                       << 2254       }
2684         }                                     << 2255       else
2685         else                                  << 2256       {
2686         {                                     << 2257   //G4cout << "FS "<<G4endl;
2687             //G4cout << "FS "<<G4endl;        << 2258   //G4cout << "FS "<<(*secs)[current]->GetDefinition()->GetParticleName()<<G4endl;
2688             //G4cout << "FS "<<(*secs)[curren << 2259         theFinalState.push_back((*secs)[current]);
2689             theFinalState.push_back((*secs)[c << 2260       }
2690         }                                     << 
2691     }                                            2261     }
2692                                               << 2262     //G4cout << "Through loop"<<G4endl;
2693     delete secs;                                 2263     delete secs;
2694 #ifdef debug_H1_BinaryCascade                 << 2264     for(iter = theFinalState.begin(); iter != theFinalState.end(); ++iter)
2695     PrintKTVector(&theFinalState," FinalState << 
2696 #endif                                        << 
2697     for(auto iter = theFinalState.cbegin(); i << 
2698     {                                            2265     {
2699         G4KineticTrack * kt = *iter;          << 2266       G4KineticTrack * kt = *iter;
2700         G4ReactionProduct * aNew = new G4Reac << 2267       G4ReactionProduct * aNew = new G4ReactionProduct(kt->GetDefinition());
2701         aNew->SetMomentum(kt->Get4Momentum(). << 2268       aNew->SetMomentum(kt->Get4Momentum().vect());
2702         aNew->SetTotalEnergy(kt->Get4Momentum << 2269       aNew->SetTotalEnergy(kt->Get4Momentum().e());
2703         aNew->SetCreatorModelID(theBIC_ID);   << 2270       products->push_back(aNew);
2704         aNew->SetParentResonanceDef(kt->GetPa << 2271       #ifdef debug_1_BinaryCascade
2705         aNew->SetParentResonanceID(kt->GetPar << 2272       if (! kt->GetDefinition()->GetPDGStable() )
2706         products->push_back(aNew);            << 2273       {
2707 #ifdef debug_H1_BinaryCascade                 << 2274           if (kt->GetDefinition()->IsShortLived())
2708         if (! kt->GetDefinition()->GetPDGStab << 2275     {
2709         {                                     << 2276        G4cout << "final shortlived : ";
2710             if (kt->GetDefinition()->IsShortL << 2277     } else
2711             {                                 << 2278     {
2712                 G4cout << "final shortlived : << 2279        G4cout << "final un stable : ";
2713             } else                            << 2280     }
2714             {                                 << 2281     G4cout <<kt->GetDefinition()->GetParticleName()<< G4endl;
2715                 G4cout << "final un stable :  << 2282       }
2716             }                                 << 2283       #endif
2717             G4cout <<kt->GetDefinition()->Get << 2284       delete kt;
2718         }                                     << 
2719 #endif                                        << 
2720         delete kt;                            << 
2721     }                                            2285     }
2722     theFinalState.clear();                       2286     theFinalState.clear();
2723     return products;                             2287     return products;
2724                                                  2288 
2725 }                                                2289 }
2726                                                  2290 
2727 //-------------------------------------------    2291 //----------------------------------------------------------------------------
2728 G4ThreeVector G4BinaryCascade::GetSpherePoint    2292 G4ThreeVector G4BinaryCascade::GetSpherePoint(
2729         G4double r, const G4LorentzVector & m << 2293           G4double r, const G4LorentzVector & mom4)
2730 //-------------------------------------------    2294 //----------------------------------------------------------------------------
2731 {                                                2295 {
2732     //  Get a point outside radius.           << 2296 //  Get a point outside radius.
2733     //     point is random in plane (circle o << 2297 //     point is random in plane (circle of radius r) orthogonal to mom,
2734     //      plus -1*r*mom->vect()->unit();    << 2298 //      plus -1*r*mom->vect()->unit();
2735     G4ThreeVector o1, o2;                        2299     G4ThreeVector o1, o2;
2736     G4ThreeVector mom = mom4.vect();             2300     G4ThreeVector mom = mom4.vect();
2737                                                  2301 
2738     o1= mom.orthogonal();  // we simply need     2302     o1= mom.orthogonal();  // we simply need any vector non parallel
2739     o2= mom.cross(o1);     //  o2 is now orth    2303     o2= mom.cross(o1);     //  o2 is now orthogonal to mom and o1, ie. o1 and o2  define plane.
2740                                                  2304 
2741     G4double x2, x1;                             2305     G4double x2, x1;
2742                                                  2306 
2743     do                                           2307     do
2744     {                                            2308     {
2745         x1=(G4UniformRand()-.5)*2;            << 2309       x1=(G4UniformRand()-.5)*2;
2746         x2=(G4UniformRand()-.5)*2;            << 2310       x2=(G4UniformRand()-.5)*2;
2747     } while (sqr(x1) +sqr(x2) > 1.);          << 2311     } while (sqr(x1) +sqr(x2) > 1.);
2748                                                  2312 
2749     return G4ThreeVector(r*(x1*o1.unit() + x2    2313     return G4ThreeVector(r*(x1*o1.unit() + x2*o2.unit() - 1.5* mom.unit()));
2750                                                  2314 
2751                                                  2315 
2752                                                  2316 
2753     /*                                        << 2317 /*
2754      * // Get a point uniformly distributed o << 2318  * // Get a point uniformly distributed on the surface of a sphere,
2755      * // with z < 0.                         << 2319  * // with z < 0.
2756      *   G4double b = r*G4UniformRand();  //  << 2320  *   G4double b = r*G4UniformRand();  // impact parameter
2757      *   G4double phi = G4UniformRand()*2*pi; << 2321  *   G4double phi = G4UniformRand()*2*pi;
2758      *   G4double x = b*std::cos(phi);        << 2322  *   G4double x = b*std::cos(phi);
2759      *   G4double y = b*std::sin(phi);        << 2323  *   G4double y = b*std::sin(phi);
2760      *   G4double z = -std::sqrt(r*r-b*b);    << 2324  *   G4double z = -std::sqrt(r*r-b*b);
2761      *   z *= 1.001; // Get position a little << 2325  *   z *= 1.001; // Get position a little bit out of the sphere...
2762      *   point.setX(x);                       << 2326  *   point.setX(x);
2763      *   point.setY(y);                       << 2327  *   point.setY(y);
2764      *   point.setZ(z);                       << 2328  *   point.setZ(z);
2765      */                                       << 2329  */
2766 }                                                2330 }
2767                                                  2331 
2768 //-------------------------------------------    2332 //----------------------------------------------------------------------------
2769                                                  2333 
2770 void G4BinaryCascade::ClearAndDestroy(G4Kinet    2334 void G4BinaryCascade::ClearAndDestroy(G4KineticTrackVector * ktv)
2771 //-------------------------------------------    2335 //----------------------------------------------------------------------------
2772 {                                                2336 {
2773     for(auto i = ktv->cbegin(); i != ktv->cen << 2337   std::vector<G4KineticTrack *>::iterator i;
2774         delete (*i);                          << 2338   for(i = ktv->begin(); i != ktv->end(); ++i)
2775     ktv->clear();                             << 2339     delete (*i);
                                                   >> 2340   ktv->clear();
2776 }                                                2341 }
2777                                                  2342 
2778 //-------------------------------------------    2343 //----------------------------------------------------------------------------
2779 void G4BinaryCascade::ClearAndDestroy(G4React    2344 void G4BinaryCascade::ClearAndDestroy(G4ReactionProductVector * rpv)
2780 //-------------------------------------------    2345 //----------------------------------------------------------------------------
2781 {                                                2346 {
2782     for(auto i = rpv->cbegin(); i != rpv->cen << 2347   std::vector<G4ReactionProduct *>::iterator i;
2783         delete (*i);                          << 2348   for(i = rpv->begin(); i != rpv->end(); ++i)
2784     rpv->clear();                             << 2349     delete (*i);
                                                   >> 2350   rpv->clear();
2785 }                                                2351 }
2786                                                  2352 
2787 //-------------------------------------------    2353 //----------------------------------------------------------------------------
2788 void G4BinaryCascade::PrintKTVector(G4Kinetic    2354 void G4BinaryCascade::PrintKTVector(G4KineticTrackVector * ktv, std::string comment)
2789 //-------------------------------------------    2355 //----------------------------------------------------------------------------
2790 {                                                2356 {
2791     if (comment.size() > 0 ) G4cout << "G4Bin << 2357   if (comment.size() > 0 ) G4cout << comment << G4endl;
2792     if (ktv) {                                << 2358   G4cout << "  vector: " << ktv << ", number of tracks: " << ktv->size()
2793         G4cout << "  vector: " << ktv << ", n << 2359    << G4endl;
2794                << G4endl;                     << 2360   std::vector<G4KineticTrack *>::iterator i;
2795         std::vector<G4KineticTrack *>::const_ << 2361   G4int count;
2796         G4int count;                          << 2362 
2797                                               << 2363   for(count = 0, i = ktv->begin(); i != ktv->end(); ++i, ++count)
2798         for(count = 0, i = ktv->cbegin(); i ! << 2364   {
2799         {                                     << 2365     G4KineticTrack * kt = *i;
2800             G4KineticTrack * kt = *i;         << 2366     G4cout << "  track n. " << count << ", id: " << kt << G4endl;
2801             G4cout << "  track n. " << count; << 2367     G4ThreeVector pos = kt->GetPosition();
2802             PrintKTVector(kt);                << 2368     G4LorentzVector mom = kt->Get4Momentum();
2803         }                                     << 2369     G4LorentzVector tmom = kt->GetTrackingMomentum();
2804     } else {                                  << 2370     G4ParticleDefinition * definition = kt->GetDefinition();
2805         G4cout << "G4BinaryCascade::PrintKTVe << 2371     G4cout << "    definition: " << definition->GetPDGEncoding() << " pos: "
2806     }                                         << 2372      << 1/fermi*pos << " R: " << 1/fermi*pos.mag() << " 4mom: "
2807 }                                             << 2373      << 1/MeV*mom <<"Tr_mom" <<  1/MeV*tmom << " P: " << 1/MeV*mom.vect().mag() 
2808 //------------------------------------------- << 2374      << " M: " << 1/MeV*mom.mag() << G4endl;
2809 void G4BinaryCascade::PrintKTVector(G4Kinetic << 2375     G4cout <<"    trackstatus: "<<kt->GetState()<<G4endl;
2810 //------------------------------------------- << 2376   }
2811 {                                             << 2377 }
2812     if (comment.size() > 0 ) G4cout << "G4Bin << 2378 
2813     if ( kt ){                                << 2379 //----------------------------------------------------------------------------
2814         G4cout << ", id: " << kt << G4endl;   << 2380 G4bool G4BinaryCascade::CheckDecay(G4KineticTrackVector * products)
2815         G4ThreeVector pos = kt->GetPosition() << 2381 //----------------------------------------------------------------------------
2816         G4LorentzVector mom = kt->Get4Momentu << 2382 {
2817         G4LorentzVector tmom = kt->GetTrackin << 2383   G4int A = the3DNucleus->GetMassNumber();
2818         const G4ParticleDefinition * definiti << 2384   G4int Z = the3DNucleus->GetCharge();
2819         G4cout << "    definition: " << defin << 2385 
2820                 << 1/fermi*pos << " R: " << 1 << 2386   G4FermiMomentum fermiMom;
2821                 << 1/MeV*mom <<"Tr_mom" <<  1 << 2387   fermiMom.Init(A, Z);
2822                 << " M: " << 1/MeV*mom.mag()  << 2388 
2823         G4cout <<"    trackstatus: "<<kt->Get << 2389   const G4VNuclearDensity * density=the3DNucleus->GetNuclearDensity();
2824     } else {                                  << 2390 
2825         G4cout << "G4BinaryCascade::PrintKTVe << 2391   G4KineticTrackVector::iterator i;
2826     }                                         << 2392   G4ParticleDefinition * definition;
                                                   >> 2393 
                                                   >> 2394 // ------ debug
                                                   >> 2395   G4bool myflag = true;
                                                   >> 2396 // ------ end debug
                                                   >> 2397   for(i = products->begin(); i != products->end(); ++i)
                                                   >> 2398   {
                                                   >> 2399     definition = (*i)->GetDefinition();
                                                   >> 2400     if((definition->GetParticleName() != "delta++" )&&
                                                   >> 2401        (definition->GetParticleName() != "delta+" )&&
                                                   >> 2402        (definition->GetParticleName() != "delta0" )&&
                                                   >> 2403        (definition->GetParticleName() != "delta-" ))
                                                   >> 2404        continue;
                                                   >> 2405        G4ThreeVector pos = (*i)->GetPosition();
                                                   >> 2406        G4double d = density->GetDensity(pos);
                                                   >> 2407        G4double pFermi= fermiMom.GetFermiMomentum(d);
                                                   >> 2408        G4LorentzVector mom = (*i)->Get4Momentum();
                                                   >> 2409        G4LorentzRotation boost(mom.boostVector()); 
                                                   >> 2410        G4ThreeVector pion3(227*MeV * mom.vect().unit()); // 227 is decay product in rest frame
                                                   >> 2411        G4LorentzVector pion(pion3, std::sqrt(sqr(140*MeV) +pion3.mag()));
                                                   >> 2412      // G4cout << "pi rest " << pion << G4endl;
                                                   >> 2413        pion = boost * pion;
                                                   >> 2414      // G4cout << "pi lab  " << pion << G4endl;
                                                   >> 2415 // ------ debug
                                                   >> 2416 //     G4cout << "p:[" << (1/MeV)*pion.x() << " " << (1/MeV)*pion.y() << " "
                                                   >> 2417 //     << (1/MeV)*pion.z() << "] |p3|:"
                                                   >> 2418 //     << (1/MeV)*pion.vect().mag() << " E:" << (1/MeV)*pion.t() << " ] m: "
                                                   >> 2419 //     << (1/MeV)*pion.mag() << "  pos[" 
                                                   >> 2420 //     << (1/fermi)*pos.x() << " "<< (1/fermi)*pos.y() << " "
                                                   >> 2421 //     << (1/fermi)*pos.z() << "] |Dpos|: "
                                                   >> 2422 //     <<  " Pfermi:"
                                                   >> 2423 //     << (1/MeV)*pFermi << G4endl;   
                                                   >> 2424 // ------ end debug
                                                   >> 2425        
                                                   >> 2426      if( pion.vect().mag() < pFermi )
                                                   >> 2427      {
                                                   >> 2428 // ------ debug
                                                   >> 2429        myflag = false;
                                                   >> 2430 // ------ end debug
                                                   >> 2431     }
                                                   >> 2432   }
                                                   >> 2433   return myflag;
                                                   >> 2434 //  return true;
2827 }                                                2435 }
2828                                                  2436 
2829                                               << 
2830 //-------------------------------------------    2437 //----------------------------------------------------------------------------
2831 G4double G4BinaryCascade::GetIonMass(G4int Z,    2438 G4double G4BinaryCascade::GetIonMass(G4int Z, G4int A)
2832 //-------------------------------------------    2439 //----------------------------------------------------------------------------
2833 {                                                2440 {
2834     G4double mass(0);                         << 2441    G4double mass(0);
2835     if ( Z > 0 && A >= Z )                    << 2442    if ( Z > 0 && A >= Z ) 
2836     {                                         << 
2837         mass = G4ParticleTable::GetParticleTa << 
2838                                               << 
2839     } else if ( A > 0 && Z>0 )                << 
2840     {                                         << 
2841         // charge Z > A; will happen for ligh << 
2842         mass = G4ParticleTable::GetParticleTa << 
2843                                               << 
2844     } else if ( A >= 0 && Z<=0 )              << 
2845     {                                         << 
2846         // all neutral, or empty nucleus      << 
2847         mass = A * G4Neutron::Neutron()->GetP << 
2848                                               << 
2849     } else if ( A == 0  )                     << 
2850     {                                         << 
2851         // empty nucleus, except maybe pions  << 
2852         mass = 0;                             << 
2853                                               << 
2854     } else                                    << 
2855     {                                         << 
2856         G4cerr << "G4BinaryCascade::GetIonMas << 
2857                 << A << "," << Z << ")" <<G4e << 
2858         throw G4HadronicException(__FILE__, _ << 
2859                                               << 
2860     }                                         << 
2861    //  G4cout << "G4BinaryCascade::GetIonMass << 
2862     return mass;                              << 
2863 }                                             << 
2864 G4ReactionProductVector * G4BinaryCascade::Fi << 
2865 {                                             << 
2866     // return product when nucleus is destroy << 
2867     G4double Esecondaries(0.);                << 
2868     G4LorentzVector psecondaries;             << 
2869     std::vector<G4KineticTrack *>::const_iter << 
2870     std::vector<G4ReactionProduct *>::const_i << 
2871     decayKTV.Decay(&theFinalState);           << 
2872                                               << 
2873     for(iter = theFinalState.cbegin(); iter ! << 
2874     {                                         << 
2875         G4ReactionProduct * aNew = new G4Reac << 
2876         aNew->SetMomentum((*iter)->Get4Moment << 
2877         aNew->SetTotalEnergy((*iter)->Get4Mom << 
2878         aNew->SetCreatorModelID(theBIC_ID);   << 
2879   aNew->SetParentResonanceDef((*iter)->GetPar << 
2880   aNew->SetParentResonanceID((*iter)->GetPare << 
2881         Esecondaries +=(*iter)->Get4Momentum( << 
2882         psecondaries +=(*iter)->Get4Momentum( << 
2883         aNew->SetNewlyAdded(true);            << 
2884         //G4cout << " Particle Ekin " << aNew << 
2885         products->push_back(aNew);            << 
2886     }                                         << 
2887                                               << 
2888     // pull out late particles from collision << 
2889     //theCollisionMgr->Print();               << 
2890     while(theCollisionMgr->Entries() > 0)     << 
2891     {                                         << 
2892         G4CollisionInitialState *             << 
2893         collision = theCollisionMgr->GetNextC << 
2894                                               << 
2895         if ( ! collision->GetTargetCollection << 
2896             G4KineticTrackVector * lates = co << 
2897             if ( lates->size() == 1 ) {       << 
2898                 G4KineticTrack * atrack=*(lat << 
2899                 //PrintKTVector(atrack, " lat << 
2900                                               << 
2901                 G4ReactionProduct * aNew = ne << 
2902                 aNew->SetMomentum(atrack->Get << 
2903                 aNew->SetTotalEnergy(atrack-> << 
2904                 aNew->SetCreatorModelID(atrac << 
2905     aNew->SetParentResonanceDef(atrack->GetPa << 
2906     aNew->SetParentResonanceID(atrack->GetPar << 
2907                 Esecondaries +=atrack->Get4Mo << 
2908                 psecondaries +=atrack->Get4Mo << 
2909                 aNew->SetNewlyAdded(true);    << 
2910                 products->push_back(aNew);    << 
2911                                               << 
2912             }                                 << 
2913         }                                     << 
2914         theCollisionMgr->RemoveCollision(coll << 
2915                                               << 
2916     }                                         << 
2917                                               << 
2918     // decay must be after loop on Collisions << 
2919     //   to by Collisions.                    << 
2920     decayKTV.Decay(&theSecondaryList);        << 
2921                                               << 
2922     // Correct for momentum transfered to Nuc << 
2923     G4ThreeVector transferCorrection(0);      << 
2924     if ( (theSecondaryList.size() + theCaptur << 
2925     {                                         << 
2926       transferCorrection= theMomentumTransfer << 
2927     }                                         << 
2928                                               << 
2929     for(iter = theSecondaryList.cbegin(); ite << 
2930     {                                         << 
2931         G4ReactionProduct * aNew = new G4Reac << 
2932         (*iter)->Update4Momentum((*iter)->Get << 
2933         aNew->SetMomentum((*iter)->Get4Moment << 
2934         aNew->SetTotalEnergy((*iter)->Get4Mom << 
2935         aNew->SetCreatorModelID(theBIC_ID);   << 
2936   aNew->SetParentResonanceDef((*iter)->GetPar << 
2937   aNew->SetParentResonanceID((*iter)->GetPare << 
2938         Esecondaries +=(*iter)->Get4Momentum( << 
2939         psecondaries +=(*iter)->Get4Momentum( << 
2940         if ( (*iter)->IsParticipant() ) aNew- << 
2941         products->push_back(aNew);            << 
2942     }                                         << 
2943                                               << 
2944     for(iter = theCapturedList.cbegin(); iter << 
2945     {                                         << 
2946         G4ReactionProduct * aNew = new G4Reac << 
2947         (*iter)->Update4Momentum((*iter)->Get << 
2948         aNew->SetMomentum((*iter)->Get4Moment << 
2949         aNew->SetTotalEnergy((*iter)->Get4Mom << 
2950         aNew->SetCreatorModelID(theBIC_ID);   << 
2951   aNew->SetParentResonanceDef((*iter)->GetPar << 
2952   aNew->SetParentResonanceID((*iter)->GetPare << 
2953         Esecondaries +=(*iter)->Get4Momentum( << 
2954         psecondaries +=(*iter)->Get4Momentum( << 
2955         aNew->SetNewlyAdded(true);            << 
2956         products->push_back(aNew);            << 
2957     }                                         << 
2958                                               << 
2959     G4double SumMassNucleons(0.);             << 
2960     G4LorentzVector pNucleons(0.);            << 
2961     for(iter = theTargetList.cbegin(); iter ! << 
2962     {                                         << 
2963         SumMassNucleons += (*iter)->GetDefini << 
2964         pNucleons += (*iter)->Get4Momentum(); << 
2965     }                                         << 
2966                                               << 
2967     G4double Ekinetic=theProjectile4Momentum. << 
2968      #ifdef debug_BIC_FillVoidnucleus         << 
2969         G4LorentzVector deltaP=theProjectile4 << 
2970                         psecondaries - pNucle << 
2971         //G4cout << "BIC::FillVoidNucleus() n << 
2972       //       ", deltaP " <<  deltaP << " de << 
2973      #endif                                   << 
2974     if (Ekinetic > 0. && theTargetList.size() << 
2975         Ekinetic /= theTargetList.size();     << 
2976     } else {                                  << 
2977         G4double Ekineticrdm(0);              << 
2978         if (theTargetList.size()) Ekineticrdm << 
2979         G4double TotalEkin(Ekineticrdm);      << 
2980         for (rpiter=products->cbegin(); rpite << 
2981           TotalEkin+=(*rpiter)->GetKineticEne << 
2982         }                                     << 
2983         G4double correction(1.);              << 
2984         if ( std::abs(Ekinetic) < 20*perCent  << 
2985           correction=1. + (Ekinetic-Ekineticr << 
2986         }                                     << 
2987         #ifdef debug_G4BinaryCascade          << 
2988       else {                                  << 
2989         G4cout << "BLIC::FillVoidNucleus() fa << 
2990       }                                       << 
2991         #endif                                << 
2992                                               << 
2993         for (rpiter=products->cbegin(); rpite << 
2994         (*rpiter)->SetKineticEnergy((*rpiter) << 
2995           (*rpiter)->SetMomentum((*rpiter)->G << 
2996                                               << 
2997         }                                     << 
2998                                               << 
2999         Ekinetic=Ekineticrdm*correction;      << 
3000         if (theTargetList.size())Ekinetic /=  << 
3001                                               << 
3002   }                                           << 
3003                                               << 
3004     for(iter = theTargetList.cbegin(); iter ! << 
3005       // set Nucleon it to be hit - as it is  << 
3006       (*iter)->Hit();                         << 
3007         G4ReactionProduct * aNew = new G4Reac << 
3008         aNew->SetKineticEnergy(Ekinetic);     << 
3009         aNew->SetMomentum(aNew->GetTotalMomen << 
3010         aNew->SetNewlyAdded(true);            << 
3011         aNew->SetCreatorModelID(theBIC_ID);   << 
3012   aNew->SetParentResonanceDef((*iter)->GetPar << 
3013   aNew->SetParentResonanceID((*iter)->GetPare << 
3014         products->push_back(aNew);            << 
3015         Esecondaries += aNew->GetTotalEnergy( << 
3016         psecondaries += G4LorentzVector(aNew- << 
3017     }                                         << 
3018     psecondaries=G4LorentzVector(0);          << 
3019     for (rpiter=products->cbegin(); rpiter!=p << 
3020       psecondaries += G4LorentzVector((*rpite << 
3021     }                                         << 
3022                                               << 
3023     G4LorentzVector initial4Mom=theProjectile << 
3024                                               << 
3025     //G4cout << "::FillVoidNucleus()final e/p << 
3026     //  << " final " << psecondaries << " del << 
3027                                               << 
3028     G4ThreeVector SumMom=psecondaries.vect(); << 
3029                                               << 
3030     SumMom=initial4Mom.vect()-SumMom;         << 
3031     G4int loopcount(0);                       << 
3032                                               << 
3033     // reverse_iterator reverse - start to co << 
3034     while ( SumMom.mag() > 0.1*MeV && loopcou << 
3035     {                                         << 
3036       G4int index=(G4int)products->size();    << 
3037       for (auto reverse=products->crbegin();  << 
3038         SumMom=initial4Mom.vect();            << 
3039         for (rpiter=products->cbegin(); rpite << 
3040           SumMom-=(*rpiter)->GetMomentum();   << 
3041         }                                     << 
3042         G4double p=((*reverse)->GetMomentum() << 
3043         (*reverse)->SetMomentum(  p*(((*rever << 
3044       }                                       << 
3045     }                                         << 
3046     return products;                          << 
3047 }                                             << 
3048                                               << 
3049 G4ReactionProductVector * G4BinaryCascade::Hi << 
3050         G4KineticTrackVector * secondaries)   << 
3051 {                                             << 
3052     for(auto iter = secondaries->cbegin(); it << 
3053     {                                         << 
3054         G4ReactionProduct * aNew = new G4Reac << 
3055         aNew->SetMomentum((*iter)->Get4Moment << 
3056         aNew->SetTotalEnergy((*iter)->Get4Mom << 
3057         aNew->SetNewlyAdded(true);            << 
3058         aNew->SetCreatorModelID((*iter)->GetC << 
3059         aNew->SetParentResonanceDef((*iter)-> << 
3060         aNew->SetParentResonanceID((*iter)->G << 
3061         //G4cout << " Particle Ekin " << aNew << 
3062         products->push_back(aNew);            << 
3063     }                                         << 
3064     const G4ParticleDefinition* fragment = 0; << 
3065     if (currentA == 1 && currentZ == 0) {     << 
3066         fragment = G4Neutron::NeutronDefiniti << 
3067     } else if (currentA == 1 && currentZ == 1 << 
3068         fragment = G4Proton::ProtonDefinition << 
3069     } else if (currentA == 2 && currentZ == 1 << 
3070         fragment = G4Deuteron::DeuteronDefini << 
3071     } else if (currentA == 3 && currentZ == 1 << 
3072         fragment = G4Triton::TritonDefinition << 
3073     } else if (currentA == 3 && currentZ == 2 << 
3074         fragment = G4He3::He3Definition();    << 
3075     } else if (currentA == 4 && currentZ == 2 << 
3076         fragment = G4Alpha::AlphaDefinition() << 
3077     } else {                                  << 
3078         fragment =                            << 
3079                 G4ParticleTable::GetParticleT << 
3080     }                                         << 
3081     if (fragment != 0) {                      << 
3082         G4ReactionProduct * theNew = new G4Re << 
3083         theNew->SetMomentum(G4ThreeVector(0,0 << 
3084         theNew->SetTotalEnergy(massInNucleus) << 
3085         theNew->SetCreatorModelID(theBIC_ID); << 
3086         //theNew->SetFormationTime(??0.??);   << 
3087         //G4cout << " Nucleus (" << currentZ  << 
3088         products->push_back(theNew);          << 
3089     }                                         << 
3090     return products;                          << 
3091 }                                             << 
3092                                               << 
3093 void G4BinaryCascade::PrintWelcomeMessage()   << 
3094 {                                             << 
3095     G4cout <<"Thank you for using G4BinaryCas << 
3096 }                                             << 
3097                                               << 
3098 //------------------------------------------- << 
3099 void G4BinaryCascade::DebugApplyCollisionFail << 
3100       G4KineticTrackVector * products)        << 
3101 {                                             << 
3102    G4bool havePion=false;                     << 
3103    if (products)                              << 
3104    {                                             2443    {
3105       for ( auto i =products->cbegin(); i !=  << 2444       mass = G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(Z,A);
3106       {                                       << 2445       
3107          G4int PDGcode=std::abs((*i)->GetDefi << 2446    } else if ( A > 0 && Z>0 )
3108          if (std::abs(PDGcode)==211 || PDGcod << 
3109       }                                       << 
3110    }                                          << 
3111    if ( !products  || havePion)               << 
3112    {                                             2447    {
3113       const G4BCAction &action= *collision->G << 2448       // charge Z > A; will happen for light nuclei with pions involved. 
3114       G4cout << " Collision " << collision << << 2449       mass = G4ParticleTable::GetParticleTable()->GetIonTable()->GetIonMass(A,A);
3115                                   << ", with  << 2450       
3116       G4cout << G4endl<<"Initial condition ar << 2451    } else if ( A >= 0 && Z<=0 )
3117       G4cout << "proj: "<<collision->GetPrima << 2452    {
3118       PrintKTVector(collision->GetPrimary()); << 2453       // all neutral, or empty nucleus 
3119       for(std::size_t it=0; it<collision->Get << 2454       mass = A * G4Neutron::Neutron()->GetPDGMass();
3120       {                                       << 2455       
3121          G4cout << "targ: "                   << 2456    } else if ( A == 0 && std::abs(Z)<2 )
3122                <<collision->GetTargetCollecti << 2457    {
3123       }                                       << 2458       // empty nucleus, except maybe pions
3124       PrintKTVector(&collision->GetTargetColl << 2459       mass = 0;
3125    }                                          << 2460       
3126    //  if ( lateParticleCollision ) G4cout << << 2461    } else
3127    //  if ( lateParticleCollision && products << 2462    {
3128 }                                             << 2463       G4cerr << "G4BinaryCascade::GetIonMass() - invalid (A,Z) = ("
3129                                               << 2464               << A << "," << Z << ")" <<G4endl;
3130 //------------------------------------------- << 2465       G4Exception("G4BinaryCascade::GetIonMass() - giving up");
3131                                               << 
3132 G4bool G4BinaryCascade::CheckChargeAndBaryonN << 
3133 {                                             << 
3134    static G4int lastdA(0), lastdZ(0);         << 
3135    G4int iStateA = the3DNucleus->GetMassNumbe << 
3136    G4int iStateZ = the3DNucleus->GetCharge()  << 
3137                                               << 
3138    G4int fStateA(0);                          << 
3139    G4int fStateZ(0);                          << 
3140                                               << 
3141    G4int CapturedA(0), CapturedZ(0);          << 
3142    G4int secsA(0), secsZ(0);                  << 
3143    for (auto i=theCapturedList.cbegin(); i!=t << 
3144       CapturedA += (*i)->GetDefinition()->Get << 
3145       CapturedZ += G4lrint((*i)->GetDefinitio << 
3146    }                                          << 
3147                                               << 
3148    for (auto i=theSecondaryList.cbegin(); i!= << 
3149       if ( (*i)->GetState() != G4KineticTrack << 
3150          secsA += (*i)->GetDefinition()->GetB << 
3151          secsZ += G4lrint((*i)->GetDefinition << 
3152       }                                       << 
3153    }                                          << 
3154                                               << 
3155    for (auto i=theFinalState.cbegin(); i!=the << 
3156       fStateA += (*i)->GetDefinition()->GetBa << 
3157       fStateZ += G4lrint((*i)->GetDefinition( << 
3158    }                                             2466    }
3159                                               << 2467    return mass;
3160    G4int deltaA= iStateA -  secsA - fStateA - << 
3161    G4int deltaZ= iStateZ -  secsZ - fStateZ - << 
3162                                               << 
3163 #ifdef debugCheckChargeAndBaryonNumberverbose << 
3164   G4cout << where <<" A: iState= "<< iStateA< << 
3165   G4cout << where <<" Z: iState= "<< iStateZ< << 
3166 #endif                                        << 
3167                                               << 
3168    if (deltaA != 0  || deltaZ!=0 ) {          << 
3169       if (deltaA != lastdA || deltaZ != lastd << 
3170          G4cout << "baryon/charge imbalance - << 
3171                << "deltaA " <<deltaA<<", iSta << 
3172                << ", fStateA "<<fStateA << ", << 
3173                << "deltaZ "<<deltaZ<<", iStat << 
3174                << ", fStateZ "<<fStateZ << ", << 
3175          lastdA=deltaA;                       << 
3176          lastdZ=deltaZ;                       << 
3177       }                                       << 
3178    } else { lastdA=lastdZ=0;}                 << 
3179                                               << 
3180    return true;                               << 
3181 }                                             << 
3182 //------------------------------------------- << 
3183 void G4BinaryCascade::DebugApplyCollision(G4C << 
3184         G4KineticTrackVector * products)      << 
3185 {                                             << 
3186                                               << 
3187     PrintKTVector(collision->GetPrimary(),std << 
3188     PrintKTVector(&collision->GetTargetCollec << 
3189     PrintKTVector(products,std::string(" Scat << 
3190                                               << 
3191 #ifdef dontUse                                << 
3192     G4double thisExcitation(0);               << 
3193     //  excitation energy from this collision << 
3194     //  initial state:                        << 
3195     G4double initial(0);                      << 
3196     G4KineticTrack * kt=collision->GetPrimary << 
3197     initial +=  kt->Get4Momentum().e();       << 
3198                                               << 
3199     G4RKPropagation * RKprop=(G4RKPropagation << 
3200                                               << 
3201     initial +=  RKprop->GetField(kt->GetDefin << 
3202     initial -=  RKprop->GetBarrier(kt->GetDef << 
3203     G4cout << "prim. E/field/Barr/Sum " << kt << 
3204                       << " " << RKprop->GetFi << 
3205                       << " " << RKprop->GetBa << 
3206                       << " " << initial << G4 << 
3207                                               << 
3208     G4KineticTrackVector ktv=collision->GetTa << 
3209     for ( unsigned int it=0; it < ktv.size(); << 
3210     {                                         << 
3211         kt=ktv[it];                           << 
3212         initial +=  kt->Get4Momentum().e();   << 
3213         thisExcitation += kt->GetDefinition() << 
3214                          - kt->Get4Momentum() << 
3215                          - RKprop->GetField(k << 
3216         //     initial +=  RKprop->GetField(k << 
3217         //     initial -=  RKprop->GetBarrier << 
3218         G4cout << "Targ. def/E/field/Barr/Sum << 
3219                   << " " << kt->Get4Momentum( << 
3220                   << " " << RKprop->GetField( << 
3221                   << " " << RKprop->GetBarrie << 
3222                   << " " << initial <<" Excit << 
3223     }                                         << 
3224                                               << 
3225     G4double fin(0);                          << 
3226     G4double mass_out(0);                     << 
3227     G4int product_barions(0);                 << 
3228     if ( products )                           << 
3229     {                                         << 
3230         for ( unsigned int it=0; it < product << 
3231         {                                     << 
3232             kt=(*products)[it];               << 
3233             fin +=  kt->Get4Momentum().e();   << 
3234             fin +=  RKprop->GetField(kt->GetD << 
3235             fin +=  RKprop->GetBarrier(kt->Ge << 
3236             if ( kt->GetDefinition()->GetBary << 
3237             mass_out += kt->GetDefinition()-> << 
3238             G4cout << "sec. def/E/field/Barr/ << 
3239                      << " " << kt->Get4Moment << 
3240                      << " " << RKprop->GetFie << 
3241                      << " " << RKprop->GetBar << 
3242                      << " " << fin << G4endl; << 
3243         }                                     << 
3244     }                                         << 
3245                                               << 
3246                                               << 
3247     G4int finalA = currentA;                  << 
3248     G4int finalZ = currentZ;                  << 
3249     if ( products )                           << 
3250     {                                         << 
3251         finalA -= product_barions;            << 
3252         finalZ -= GetTotalCharge(*products);  << 
3253     }                                         << 
3254     G4double delta = GetIonMass(currentZ,curr << 
3255     G4cout << " current/final a,z " << curren << 
3256             <<  " delta-mass " << delta<<G4en << 
3257     fin+=delta;                               << 
3258     mass_out  = GetIonMass(finalZ,finalA);    << 
3259     G4cout << " initE/ E_out/ Mfinal/ Excit " << 
3260             << " " <<   fin << " "            << 
3261             <<  mass_out<<" "                 << 
3262             <<  currentInitialEnergy - fin -  << 
3263             << G4endl;                        << 
3264     currentInitialEnergy-=fin;                << 
3265 #endif                                        << 
3266 }                                                2468 }
3267                                                  2469 
3268 //------------------------------------------- << 2470 void G4BinaryCascade::PrintWelcomeMessage()
3269 G4bool G4BinaryCascade::DebugFinalEpConservat << 
3270         G4ReactionProductVector* products)    << 
3271 //------------------------------------------- << 
3272 {                                                2471 {
3273     G4double Efinal(0);                       << 2472   G4cout <<"Thank you for using G4BinaryCascade. "<<G4endl;
3274     G4ThreeVector pFinal(0);                  << 
3275     if (std::abs(theParticleChange.GetWeightC << 
3276     {                                         << 
3277         G4cout <<" BIC-weight change " << the << 
3278     }                                         << 
3279                                               << 
3280     for(auto iter = products->cbegin(); iter  << 
3281     {                                         << 
3282                                               << 
3283         G4cout << " Secondary E - Ekin / p "  << 
3284               (*iter)->GetDefinition()->GetPa << 
3285               (*iter)->GetTotalEnergy() << "  << 
3286               (*iter)->GetKineticEnergy()<< " << 
3287               (*iter)->GetMomentum().x() << " << 
3288               (*iter)->GetMomentum().y() << " << 
3289               (*iter)->GetMomentum().z() << G << 
3290         Efinal += (*iter)->GetTotalEnergy();  << 
3291         pFinal += (*iter)->GetMomentum();     << 
3292     }                                         << 
3293                                               << 
3294       G4cout << "e outgoing/ total : " << Efi << 
3295       G4cout << "BIC E/p delta " <<           << 
3296             (aTrack.Get4Momentum().e()+theIni << 
3297             " MeV / mom " << (aTrack.Get4Mome << 
3298                                               << 
3299     return (aTrack.Get4Momentum().e() + theIn << 
3300                                               << 
3301 }                                                2473 }
3302 //------------------------------------------- << 
3303 G4bool G4BinaryCascade::DebugEpConservation(c << 
3304 //------------------------------------------- << 
3305 {                                             << 
3306     G4cout << where << G4endl;                << 
3307     G4LorentzVector psecs,    ptgts,    pcpts << 
3308     if (std::abs(theParticleChange.GetWeightC << 
3309     {                                         << 
3310         G4cout <<" BIC-weight change " << the << 
3311     }                                         << 
3312                                               << 
3313     std::vector<G4KineticTrack *>::const_iter << 
3314     for(ktiter = theSecondaryList.cbegin(); k << 
3315        {                                      << 
3316                                                  2474 
3317               G4cout << " Secondary E - Ekin  << 
3318                  (*ktiter)->GetDefinition()-> << 
3319                  (*ktiter)->Get4Momentum().e( << 
3320                  (*ktiter)->Get4Momentum().e( << 
3321                  (*ktiter)->Get4Momentum().ve << 
3322            psecs += (*ktiter)->Get4Momentum() << 
3323        }                                      << 
3324                                                  2475 
3325     for(ktiter = theTargetList.cbegin(); ktit << 
3326        {                                      << 
3327                                                  2476 
3328               G4cout << " Target E - Ekin / p << 
3329                  (*ktiter)->GetDefinition()-> << 
3330                  (*ktiter)->Get4Momentum().e( << 
3331                  (*ktiter)->Get4Momentum().e( << 
3332                  (*ktiter)->Get4Momentum().ve << 
3333            ptgts += (*ktiter)->Get4Momentum() << 
3334        }                                      << 
3335                                                  2477 
3336     for(ktiter = theCapturedList.cbegin(); kt << 
3337         {                                     << 
3338                                                  2478 
3339                G4cout << " Captured E - Ekin  << 
3340                   (*ktiter)->GetDefinition()- << 
3341                   (*ktiter)->Get4Momentum().e << 
3342                   (*ktiter)->Get4Momentum().e << 
3343                   (*ktiter)->Get4Momentum().v << 
3344             pcpts += (*ktiter)->Get4Momentum( << 
3345         }                                     << 
3346                                                  2479 
3347     for(ktiter = theFinalState.cbegin(); ktit << 
3348         {                                     << 
3349                                                  2480 
3350                G4cout << " Finals E - Ekin /  << 
3351                   (*ktiter)->GetDefinition()- << 
3352                   (*ktiter)->Get4Momentum().e << 
3353                   (*ktiter)->Get4Momentum().e << 
3354                   (*ktiter)->Get4Momentum().v << 
3355             pfins += (*ktiter)->Get4Momentum( << 
3356         }                                     << 
3357                                               << 
3358       G4cout << " Secondaries " << psecs << " << 
3359           <<" Captured    " << pcpts << ", Fi << 
3360           <<" Sum " << psecs + ptgts + pcpts  << 
3361           <<" Sum+PTransfer " << psecs + ptgt << 
3362           << G4endl<< G4endl;                 << 
3363                                               << 
3364                                               << 
3365     return true;                              << 
3366                                                  2481 
3367 }                                             << 
3368                                               << 
3369 //------------------------------------------- << 
3370 G4ReactionProductVector * G4BinaryCascade::Pr << 
3371 //------------------------------------------- << 
3372 {                                             << 
3373    //    else                                 << 
3374 //    {                                       << 
3375 //        G4ReactionProduct * aNew=0;         << 
3376 //        // return nucleus e and p           << 
3377 //        if  (fragment != 0 ) {              << 
3378 //            aNew = new G4ReactionProduct(G4 << 
3379 //            aNew->SetMomentum(fragment->Get << 
3380 //            aNew->SetTotalEnergy(fragment-> << 
3381 //            delete fragment;                << 
3382 //            fragment=0;                     << 
3383 //        } else if (products->size() == 0) { << 
3384 //            // FixMe GF: for testing withou << 
3385 //#include "G4Gamma.hh"                       << 
3386 //            aNew = new G4ReactionProduct(G4 << 
3387 //            aNew->SetMomentum(G4ThreeVector << 
3388 //            aNew->SetTotalEnergy(0.01*MeV); << 
3389 //        }                                   << 
3390 //        if ( aNew != 0 ) products->push_bac << 
3391 //    }                                       << 
3392    return products;                           << 
3393 }                                             << 
3394                                               << 
3395 //------------------------------------------- << 
3396                                                  2482