34 #define INCLXX_IN_GEANT4_MODE 1
67 particle1(p1), particle2(NULL),
70 violationEFunctor(NULL)
77 particle1(p1), particle2(p2),
78 isPiN((p1->isPion() && p2->isNucleon()) || (p2->isPion() && p1->isNucleon())),
80 violationEFunctor(NULL)
97 (*backupParticle1) = (*particle1);
103 (*backupParticle2) = (*particle2);
146 const short maxIterations=50;
148 if(pos2 < r*r)
return true;
150 while( pos2 >= r*r && iterations<maxIterations )
152 pos *= std::sqrt(r*r*0.9801/pos2);
156 if( iterations < maxIterations)
167 INCL_DEBUG(
"postInteraction: final state: " <<
'\n' << fs->
print() <<
'\n');
186 (*i)->makeParticipant();
187 (*i)->setOutOfWell();
189 INCL_DEBUG(
"Pion was created outside its potential well." <<
'\n'
197 INCL_DEBUG(
"Enforcing energy conservation: failed!" <<
'\n');
212 INCL_DEBUG(
"Enforcing energy conservation: success!" <<
'\n');
214 INCL_DEBUG(
"postInteraction after energy conservation: final state: " <<
'\n' << fs->
print() <<
'\n');
217 for(
ParticleIter i=modified.begin(),
e=modified.end(); i!=
e; ++i )
218 if((*i)->isDelta() &&
220 INCL_DEBUG(
"Mass of the produced delta below decay threshold; forbidding collision. deltaMass=" <<
221 (*i)->getMass() <<
'\n');
284 if((*i)->isOutOfWell())
continue;
287 if( !successBringParticlesInside ) {
288 INCL_ERROR(
"Failed to bring particle inside the nucleus!" <<
'\n');
294 std::vector<G4int> newBiasCollisionVector;
296 if(std::fabs(
weight-1.) > 1
E-6){
302 (*i)->setBiasCollisionVector(newBiasCollisionVector);
303 if(!(*i)->isOutOfWell()) {
306 G4bool goesBackToSpectator =
false;
308 G4double threshold = (*i)->getPotentialEnergy();
309 if((*i)->getType()==
Proton)
311 if((*i)->getKineticEnergy() < threshold)
312 goesBackToSpectator =
true;
315 (*i)->thawPropagation();
318 if(goesBackToSpectator) {
319 INCL_DEBUG(
"The following particle goes back to spectator:" <<
'\n'
320 << (*i)->print() <<
'\n');
321 if(!(*i)->isTargetSpectator()) {
324 (*i)->makeTargetSpectator();
326 if((*i)->isTargetSpectator()) {
329 (*i)->makeParticipant();
334 for(
ParticleIter i=destroyed.begin(),
e=destroyed.end(); i!=
e; ++i )
335 if(!(*i)->isTargetSpectator())
341 (*particle1) = (*backupParticle1);
343 (*particle2) = (*backupParticle2);
363 if(manyBodyFinalState)
377 (*violationEFunctor)(theSolution.
x);
379 INCL_DEBUG(
"Couldn't enforce energy conservation after an interaction, root-finding algorithm failed." <<
'\n');
393 finalParticles(modAndCre),
394 initialEnergy(totalEnergyBeforeInteraction),
397 shouldUseLocalEnergy(localE)
408 particleMomenta.clear();
412 scaleParticleMomenta(alpha);
415 for(
ParticleIter i=finalParticles.begin(),
e=finalParticles.end(); i!=
e; ++i)
416 deltaE += (*i)->getEnergy() - (*i)->getPotentialEnergy();
417 deltaE -= initialEnergy;
423 std::vector<ThreeVector>::const_iterator iP = particleMomenta.begin();
424 for(
ParticleIter i=finalParticles.begin(),
e=finalParticles.end(); i!=
e; ++i, ++iP) {
425 (*i)->setMomentum((*iP)*alpha);
426 (*i)->adjustEnergyFromMomentum();
432 (*i)->setPotentialEnergy(0.);
436 !(*i)->isKaon() && !(*i)->isAntiKaon() &&!(*i)->isLambda() && !(*i)->isSigma()) {
442 for(
G4int iterLocE=0;
446 (*i)->setEnergy(energy + locE);
447 (*i)->adjustMomentumFromEnergy();
450 deltaLocE = std::abs(locE-locEOld);
458 scaleParticleMomenta(1.);
467 initialEnergy(totalEnergyBeforeInteraction),
469 theParticle(aParticle),
470 theEnergy(theParticle->getEnergy()),
471 theMomentum(theParticle->getMomentum()),
479 setParticleEnergy(alpha);
480 return theParticle->getEnergy() - theParticle->getPotentialEnergy() - initialEnergy;
493 for(
G4int iterLocE=0;
497 G4double particleEnergy = energyThreshold + locE + alpha*(theEnergy-energyThreshold);
498 const G4double theMass2 = std::pow(particleEnergy,2.)-theMomentum.mag2();
501 theMass = std::sqrt(theMass2);
504 particleEnergy = energyThreshold;
506 theParticle->setMass(theMass);
507 theParticle->setEnergy(particleEnergy);
516 deltaLocE = std::abs(locE-locEOld);
523 setParticleEnergy(1.);
static const G4int maxIterLocE
Max number of iterations for the determination of the local-energy Q-value.
ParticleList::const_iterator ParticleIter
G4double total(Particle const *const p1, Particle const *const p2)
ThreeVector const & boostVector
Pointer to the boost vector.
const G4INCL::ThreeVector & getPosition() const
Static root-finder algorithm.
static const G4double pos
G4double getEnergy() const
void preInteractionLocalEnergy(Particle *const p)
Apply local-energy transformation, if appropriate.
static G4ThreadLocal Particle * backupParticle1
G4bool enforceEnergyConservation(FinalState *const fs)
Enforce energy conservation.
static void FillINCLBiasVector(G4double newBias)
G4bool bringParticleInside(Particle *const p)
const G4INCL::ThreeVector & getMomentum() const
LocalEnergyType getLocalEnergyBBType() const
Get the type of local energy for N-N avatars.
void addOutgoingParticle(Particle *p)
G4double getSurfaceRadius(Particle const *const particle) const
Get the maximum allowed radius for a given particle.
void incrementEnergyViolationInteraction()
static void deleteBackupParticles()
Release the memory allocated for the backup particles.
G4double getLocalEnergy(Nucleus const *const n, Particle *const p)
G4bool shouldUseLocalEnergy() const
true if the given avatar should use local energy
G4bool getBackToSpectator() const
Get back-to-spectator.
G4double getMass() const
Get the cached particle mass.
InteractionAvatar(G4double, G4INCL::Nucleus *, G4INCL::Particle *)
void updatePotentialEnergy(Particle *p) const
Update the particle potential energy.
G4bool isCDPPBlocked(ParticleList const &p, Nucleus const *const n)
Check CDPP blocking.
G4double operator()(const G4double x) const
Compute the energy-conservation violation.
void boost(const ThreeVector &b) const
std::string print() const
AvatarType getType() const
RootFunctor-derived object for enforcing energy conservation in delta production. ...
Solution solve(RootFunctor const *const f, const G4double x0)
Numerically solve a one-dimensional equation.
ParticleList finalParticles
List of final-state particles.
ViolationEEnergyFunctor(Nucleus *const nucleus, Particle *const aParticle, const G4double totalEnergyBeforeInteraction, const G4bool localE)
Prepare for calling the () operator and setParticleEnergy.
G4double getPotentialEnergy() const
Get the particle potential energy.
virtual void setPosition(const G4INCL::ThreeVector &position)
void setParticleEnergy(const G4double energy) const
Set the energy of the particle.
void makeNoEnergyConservation()
void preInteractionBlocking()
Store the state of the particles before the interaction.
void setTotalEnergyBeforeInteraction(G4double E)
static const G4double alpha
ThreeVector makeBoostVector(Particle const *const p1, Particle const *const p2)
void transformToLocalEnergyFrame(Nucleus const *const n, Particle *const p)
ParticleList const & getModifiedParticles() const
RootFunctor * violationEFunctor
LocalEnergyType getLocalEnergyPiType() const
Get the type of local energy for pi-N and decay avatars.
void incrementCascading()
virtual ~ViolationEMomentumFunctor()
void rpCorrelate()
Make the particle follow a strict r-p correlation.
void cleanUp(const G4bool success) const
Clean up after root finding.
virtual ~InteractionAvatar()
ParticleList const & getDestroyedParticles() const
ViolationEMomentumFunctor(Nucleus *const nucleus, ParticleList const &modAndCre, const G4double totalEnergyBeforeInteraction, ThreeVector const &boost, const G4bool localE)
Prepare for calling the () operator and scaleParticleMomenta.
G4double getTotalEnergyBeforeInteraction() const
void postInteraction(FinalState *)
G4int getAcceptedCollisions() const
G4double operator()(const G4double x) const
Compute the energy-conservation violation.
Config const * getConfig()
G4bool isMeson() const
Is this a Meson?
std::vector< ThreeVector > particleMomenta
CM particle momenta, as determined by the channel.
void scaleParticleMomenta(const G4double alpha) const
Scale the momenta of the modified and created particles.
void boost(const ThreeVector &aBoostVector)
static const G4double locEAccuracy
Target accuracy in the determination of the local-energy Q-value.
void decrementCascading()
void cleanUp(const G4bool success) const
Clean up after root finding.
G4ThreadLocal G4double minDeltaMass2
static G4ThreadLocal G4int nextBiasedCollisionID
G4double getTransmissionBarrier(Particle const *const p)
Get the transmission barrier.
ParticleList modifiedAndCreated
static G4ThreadLocal Particle * backupParticle2
RootFunctor-derived object for enforcing energy conservation in N-N.
void restoreParticles() const
Restore the state of both particles.
ParticleList const & getCreatedParticles() const
G4bool isBlocked(ParticleList const &p, Nucleus const *const n)
Check Pauli blocking.
ParticleList ModifiedAndDestroyed
std::vector< G4int > getParticleListBiasVector() const
G4ThreadLocal G4double minDeltaMass