78 const G4Fragment G4CollisionOutput::emptyFragment;
82 : verboseLevel(0), eex_rest(0), on_shell(false) {
84 G4cout <<
" >>> G4CollisionOutput::G4CollisionOutput" <<
G4endl;
91 verboseLevel = right.verboseLevel;
92 outgoingParticles = right.outgoingParticles;
93 outgoingNuclei = right.outgoingNuclei;
94 recoilFragments = right.recoilFragments;
95 eex_rest = right.eex_rest;
96 on_shell = right.on_shell;
102 outgoingNuclei.clear();
103 outgoingParticles.clear();
104 recoilFragments.clear();
114 ? recoilFragments[index] : emptyFragment);
123 recoilFragments = right.recoilFragments;
132 outgoingParticles.insert(outgoingParticles.end(),
133 particles.begin(), particles.end());
137 outgoingNuclei.insert(outgoingNuclei.end(), nuclea.begin(), nuclea.end());
147 for (
unsigned i=0; i<cparticles.size(); i++)
154 if (!rproducts)
return;
157 G4cout <<
" >>> G4CollisionOutput::addOutgoingParticles(G4RPVector)"
161 G4ReactionProductVector::const_iterator j;
162 for (j=rproducts->begin(); j!=rproducts->end(); ++j) {
172 <<
"), momentum " << mom <<
" GeV" <<
G4endl;
180 if (verboseLevel>1)
G4cout << outgoingParticles.back() <<
G4endl;
186 if (verboseLevel>1)
G4cout << outgoingNuclei.back() <<
G4endl;
196 outgoingParticles.erase(outgoingParticles.begin()+(size_t)index);
201 outgoingNuclei.erase(outgoingNuclei.begin()+(size_t)index);
208 std::find(outgoingParticles.begin(), outgoingParticles.end(), particle);
209 if (pos != outgoingParticles.end()) outgoingParticles.erase(pos);
214 std::find(outgoingNuclei.begin(), outgoingNuclei.end(),
nuclei);
215 if (pos != outgoingNuclei.end()) outgoingNuclei.erase(pos);
221 if (index < 0) recoilFragments.clear();
223 recoilFragments.erase(recoilFragments.begin()+(size_t)index);
230 if (verboseLevel > 1)
231 G4cout <<
" >>> G4CollisionOutput::getTotalOutputMomentum" <<
G4endl;
236 tot_mom += outgoingParticles[i].getMomentum();
239 tot_mom += outgoingNuclei[i].getMomentum();
242 tot_mom += recoilFragments[i].GetMomentum()/
GeV;
249 if (verboseLevel > 1)
250 G4cout <<
" >>> G4CollisionOutput::getTotalCharge" <<
G4endl;
255 charge +=
G4int(outgoingParticles[i].getCharge());
258 charge +=
G4int(outgoingNuclei[i].getCharge());
261 charge += recoilFragments[i].GetZ_asInt();
268 if (verboseLevel > 1)
269 G4cout <<
" >>> G4CollisionOutput::getTotalBaryonNumber" <<
G4endl;
274 baryon += outgoingParticles[i].baryon();
277 baryon +=
G4int(outgoingNuclei[i].getA());
280 baryon += recoilFragments[i].GetA_asInt();
287 if (verboseLevel > 1)
288 G4cout <<
" >>> G4CollisionOutput::getTotalStrangeness" <<
G4endl;
293 strange += outgoingParticles[i].getStrangeness();
301 os <<
" Output: " <<
G4endl
306 os << outgoingParticles[i] << G4endl;
310 os << outgoingNuclei[i] << G4endl;
312 os << recoilFragments[i] << G4endl;
319 if (verboseLevel > 1)
320 G4cout <<
" >>> G4CollisionOutput::boostToLabFrame" <<
G4endl;
323 for(; ipart != outgoingParticles.end(); ipart++) {
327 std::sort(outgoingParticles.begin(), outgoingParticles.end(),
331 for (; inuc != outgoingNuclei.end(); inuc++) {
338 for (; ifrag != recoilFragments.end(); ifrag++) {
339 fmom = ifrag->GetMomentum() /
GeV;
349 mom = convertor.
rotate(mom);
358 if (verboseLevel > 1)
359 G4cout <<
" >>> G4CollisionOutput::rotateEvent" <<
G4endl;
362 for(; ipart != outgoingParticles.end(); ipart++)
363 ipart->setMomentum(ipart->getMomentum()*=
rotate);
366 for (; inuc != outgoingNuclei.end(); inuc++)
367 inuc->setMomentum(inuc->getMomentum()*=
rotate);
370 for (; ifrag != recoilFragments.end(); ifrag++) {
372 ifrag->SetMomentum(mom*=rotate);
379 if (verboseLevel > 1)
380 G4cout <<
" >>> G4CollisionOutput::trivialize" <<
G4endl;
384 if (
G4InuclNuclei* nuclei_target = dynamic_cast<G4InuclNuclei*>(target)) {
385 outgoingNuclei.push_back(*nuclei_target);
389 outgoingParticles.push_back(*particle);
392 if (
G4InuclNuclei* nuclei_bullet = dynamic_cast<G4InuclNuclei*>(bullet)) {
393 outgoingNuclei.push_back(*nuclei_bullet);
397 outgoingParticles.push_back(*particle);
404 if (verboseLevel > 1)
405 G4cout <<
" >>> G4CollisionOutput::setOnShell" <<
G4endl;
414 if(verboseLevel > 2){
415 G4cout <<
" bullet momentum = " << ini_mom.
e() <<
", "<< ini_mom.
x() <<
", "<< ini_mom.
y()<<
", "<< ini_mom.
z()<<
G4endl;
416 G4cout <<
" target momentum = " << momt.
e()<<
", "<< momt.
x()<<
", "<< momt.
y()<<
", "<< momt.
z()<<
G4endl;
417 G4cout <<
" Fstate momentum = " << out_mom.
e()<<
", "<< out_mom.
x()<<
", "<< out_mom.
y()<<
", "<< out_mom.
z()<<
G4endl;
428 if(verboseLevel > 2) {
430 G4cout <<
" momentum non conservation: " << G4endl
431 <<
" e " << enc <<
" p " << pnc << G4endl
432 <<
" remaining exitation " << eex_rest <<
G4endl;
435 if (std::fabs(enc) <= accuracy && pnc <= accuracy) {
443 if (verboseLevel > 2)
G4cout <<
" re-balancing four-momenta" <<
G4endl;
452 for (
G4int ip=npart-1; ip>=0; ip--) {
453 if (outgoingParticles[ip].getKineticEnergy()+enc > 0.) {
454 last_mom = outgoingParticles[ip].getMomentum();
455 last_mom += mom_non_cons;
456 outgoingParticles[ip].setMomentum(last_mom);
460 }
else if (nnuc > 0) {
462 if (outgoingNuclei[
in].getKineticEnergy()+enc > 0.) {
463 last_mom = outgoingNuclei[
in].getMomentum();
464 last_mom += mom_non_cons;
465 outgoingNuclei[
in].setMomentum(last_mom);
469 }
else if (nfrag > 0) {
470 for (
G4int ifr=nfrag-1; ifr>=0; ifr--) {
472 last_mom = recoilFragments[ifr].GetMomentum()/
GeV;
473 if ((last_mom.
e()-last_mom.
m())+enc > 0.) {
474 last_mom += mom_non_cons;
475 recoilFragments[ifr].SetMomentum(last_mom*
GeV);
483 mom_non_cons = ini_mom - out_mom;
484 pnc = mom_non_cons.
rho();
485 enc = mom_non_cons.
e();
487 if(verboseLevel > 2){
489 G4cout <<
" momentum non conservation after (1): " << G4endl
490 <<
" e " << enc <<
" p " << pnc <<
G4endl;
494 G4bool need_hard_tuning =
true;
498 for (
G4int i=0; i < nfrag; i++) {
499 G4double eex = recoilFragments[0].GetExcitationEnergy();
500 if (eex > 0.0 && eex + encMeV >= 0.0) {
507 need_hard_tuning =
false;
511 }
else if (nnuc > 0) {
512 for (
G4int i=0; i < nnuc; i++) {
513 G4double eex = outgoingNuclei[i].getExitationEnergy();
514 if (eex > 0.0 && eex + encMeV >= 0.0) {
515 outgoingNuclei[i].setExitationEnergy(eex+encMeV);
516 need_hard_tuning =
false;
520 if (need_hard_tuning && encMeV > 0.) {
521 outgoingNuclei[0].setExitationEnergy(encMeV);
522 need_hard_tuning =
false;
526 if (!need_hard_tuning) {
532 if (verboseLevel > 2)
533 G4cout <<
" trying hard (particle-pair) tuning" <<
G4endl;
535 std::pair<std::pair<G4int, G4int>,
G4int> tune_par = selectPairToTune(mom_non_cons.
e());
536 std::pair<G4int, G4int> tune_particles = tune_par.first;
537 G4int mom_ind = tune_par.second;
539 if(verboseLevel > 2) {
540 G4cout <<
" p1 " << tune_particles.first <<
" p2 " << tune_particles.second
541 <<
" ind " << mom_ind <<
G4endl;
545 (tune_particles.first >= 0 && tune_particles.second >= 0 &&
548 if (!tuning_possible) {
549 if (verboseLevel > 2)
G4cout <<
" tuning impossible " <<
G4endl;
553 G4LorentzVector mom1 = outgoingParticles[tune_particles.first].getMomentum();
554 G4LorentzVector mom2 = outgoingParticles[tune_particles.second].getMomentum();
555 G4double newE12 = mom1.
e() + mom2.
e() + mom_non_cons.
e();
556 G4double R = 0.5 * (newE12 * newE12 + mom2.
e() * mom2.
e() - mom1.
e() * mom1.
e()) / newE12;
557 G4double Q = -(mom1[mom_ind] + mom2[mom_ind]) / newE12;
559 G4double W = (R * Q + mom2[mom_ind]) * UDQ;
560 G4double V = (mom2.
e() * mom2.
e() - R * R) * UDQ;
576 if(mom_non_cons.
e() > 0.0) {
578 if(R + Q * x1 >= 0.0) {
583 if(!xset && x2 > 0.0) {
584 if(R + Q * x2 >= 0.0) {
591 if(R + Q * x1 >= 0.) {
596 if(!xset && x2 < 0.0) {
597 if(R + Q * x2 >= 0.0) {
613 outgoingParticles[tune_particles.first ].setMomentum(mom1);
614 outgoingParticles[tune_particles.second].setMomentum(mom2);
617 mom_non_cons = ini_mom - out_mom;
618 pnc = mom_non_cons.
rho();
619 enc = mom_non_cons.e();
621 on_shell = (std::fabs(enc) < accuracy || pnc < accuracy);
623 if(verboseLevel > 2) {
624 G4cout <<
" momentum non conservation tuning: " << G4endl
625 <<
" e " << enc <<
" p " << pnc
626 << (on_shell?
" success":
" FAILURE") << G4endl;
637 eex_rest += outgoingNuclei[i].getExitationEnergyInGeV();
639 eex_rest += recoilFragments[i].GetExcitationEnergy() /
GeV;
643 std::pair<std::pair<G4int, G4int>,
G4int>
644 G4CollisionOutput::selectPairToTune(
G4double de)
const {
645 if (verboseLevel > 2)
646 G4cout <<
" >>> G4CollisionOutput::selectPairToTune" <<
G4endl;
648 std::pair<G4int, G4int> tup(-1, -1);
650 std::pair<std::pair<G4int, G4int>,
G4int> tuner(tup, i3);
652 if (outgoingParticles.size() < 2)
return tuner;
657 G4double pcut = 0.3 * std::sqrt(1.88 * std::fabs(de));
660 for (
G4int i = 0; i <
G4int(outgoingParticles.size())-1; i++) {
663 for (
G4int j = i+1; j <
G4int(outgoingParticles.size()); j++) {
667 if (mom1[l]*mom2[l]<0.0) {
668 if (std::fabs(mom1[l])>pcut && std::fabs(mom2[l])>pcut) {
669 G4double psum = std::fabs(mom1[l]) + std::fabs(mom2[l]);
684 if (i3 < 0)
return tuner;
690 tuner.first.first = (p1>0.) ? ibest1 : ibest2;
691 tuner.first.second = (p1>0.) ? ibest2 : ibest1;
693 tuner.first.first = (p1<0.) ? ibest2 : ibest1;
694 tuner.first.second = (p1<0.) ? ibest1 : ibest2;
void trivialise(G4InuclParticle *bullet, G4InuclParticle *target)
G4CollisionOutput & operator=(const G4CollisionOutput &right)
void addOutgoingNuclei(const std::vector< G4InuclNuclei > &nuclea)
G4LorentzVector getMomentum() const
void removeRecoilFragment(G4int index=-1)
void printCollisionOutput(std::ostream &os=G4cout) const
void addOutgoingParticle(const G4InuclElementaryParticle &particle)
G4LorentzVector rotate(const G4LorentzVector &mom) const
G4LorentzVector backToTheLab(const G4LorentzVector &mom) const
G4LorentzVector getTotalOutputMomentum() const
const G4InuclElementaryParticle & getParticle() const
const G4String & GetParticleName() const
G4int GetAtomicNumber() const
std::vector< G4ReactionProduct * > G4ReactionProductVector
void setVectM(const Hep3Vector &spatial, double mass)
void add(const G4CollisionOutput &right)
G4GLOB_DLL std::ostream G4cout
G4int getTotalStrangeness() const
G4int numberOfOutgoingParticles() const
void boostToLabFrame(const G4LorentzConvertor &convertor)
void removeOutgoingParticle(G4int index)
void rotateEvent(const G4LorentzRotation &rotate)
G4int GetAtomicMass() const
G4int numberOfOutgoingNuclei() const
G4bool reflectionNeeded() const
void addOutgoingParticles(const std::vector< G4InuclElementaryParticle > &particles)
G4int getTotalBaryonNumber() const
std::vector< G4InuclNuclei >::const_iterator nucleiIterator
G4int getTotalCharge() const
std::vector< G4InuclElementaryParticle >::iterator particleIterator
void setRemainingExitationEnergy()
std::vector< G4Fragment >::iterator fragmentIterator
G4int numberOfFragments() const
void removeOutgoingNucleus(G4int index)
const G4Fragment & getRecoilFragment(G4int index=0) const
void setOnShell(G4InuclParticle *bullet, G4InuclParticle *target)