81const G4Fragment G4CollisionOutput::emptyFragment;
85 : verboseLevel(0), eex_rest(0), on_shell(false) {
87 G4cout <<
" >>> G4CollisionOutput::G4CollisionOutput" <<
G4endl;
94 verboseLevel = right.verboseLevel;
95 outgoingParticles = right.outgoingParticles;
96 outgoingNuclei = right.outgoingNuclei;
97 recoilFragments = right.recoilFragments;
98 eex_rest = right.eex_rest;
99 on_shell = right.on_shell;
105 outgoingNuclei.clear();
106 outgoingParticles.clear();
107 recoilFragments.clear();
117 ? recoilFragments[index] : emptyFragment);
126 recoilFragments = right.recoilFragments;
135 outgoingParticles.insert(outgoingParticles.end(),
136 particles.begin(), particles.end());
140 outgoingNuclei.insert(outgoingNuclei.end(), nuclea.begin(), nuclea.end());
150 for (
unsigned i=0; i<cparticles.size(); i++)
157 if (!rproducts)
return;
160 G4cout <<
" >>> G4CollisionOutput::addOutgoingParticles(G4RPVector)"
164 G4ReactionProductVector::const_iterator j;
165 for (j=rproducts->begin(); j!=rproducts->end(); ++j) {
175 <<
"), momentum " << mom <<
" GeV" <<
G4endl;
183 if (verboseLevel>1)
G4cout << outgoingParticles.back() <<
G4endl;
189 if (verboseLevel>1)
G4cout << outgoingNuclei.back() <<
G4endl;
199 outgoingParticles.erase(outgoingParticles.begin()+(
size_t)index);
204 outgoingNuclei.erase(outgoingNuclei.begin()+(
size_t)index);
211 std::find(outgoingParticles.begin(), outgoingParticles.end(), particle);
212 if (pos != outgoingParticles.end()) outgoingParticles.erase(pos);
217 std::find(outgoingNuclei.begin(), outgoingNuclei.end(), nuclei);
218 if (pos != outgoingNuclei.end()) outgoingNuclei.erase(pos);
224 if (index < 0) recoilFragments.clear();
226 recoilFragments.erase(recoilFragments.begin()+(
size_t)index);
233 if (verboseLevel > 1)
234 G4cout <<
" >>> G4CollisionOutput::getTotalOutputMomentum" <<
G4endl;
239 tot_mom += outgoingParticles[i].getMomentum();
242 tot_mom += outgoingNuclei[i].getMomentum();
245 tot_mom += recoilFragments[i].GetMomentum()/GeV;
252 if (verboseLevel > 1)
253 G4cout <<
" >>> G4CollisionOutput::getTotalCharge" <<
G4endl;
259 charge +=
G4int(outgoingParticles[i].getCharge());
262 charge +=
G4int(outgoingNuclei[i].getCharge());
265 charge += recoilFragments[i].GetZ_asInt();
272 if (verboseLevel > 1)
273 G4cout <<
" >>> G4CollisionOutput::getTotalBaryonNumber" <<
G4endl;
278 baryon += outgoingParticles[i].baryon();
281 baryon +=
G4int(outgoingNuclei[i].getA());
284 baryon += recoilFragments[i].GetA_asInt();
291 if (verboseLevel > 1)
292 G4cout <<
" >>> G4CollisionOutput::getTotalStrangeness" <<
G4endl;
297 strange += outgoingParticles[i].getStrangeness();
305 os <<
" Output: " <<
G4endl
310 os << outgoingParticles[i] <<
G4endl;
314 os << outgoingNuclei[i] <<
G4endl;
316 os << recoilFragments[i] <<
G4endl;
323 if (verboseLevel > 1)
324 G4cout <<
" >>> G4CollisionOutput::boostToLabFrame" <<
G4endl;
327 for(; ipart != outgoingParticles.end(); ipart++) {
331 std::sort(outgoingParticles.begin(), outgoingParticles.end(),
335 for (; inuc != outgoingNuclei.end(); inuc++) {
342 for (; ifrag != recoilFragments.end(); ifrag++) {
343 fmom = ifrag->GetMomentum() / GeV;
353 mom = convertor.
rotate(mom);
362 if (verboseLevel > 1)
363 G4cout <<
" >>> G4CollisionOutput::rotateEvent" <<
G4endl;
366 for(; ipart != outgoingParticles.end(); ipart++)
367 ipart->setMomentum(ipart->getMomentum()*=rotate);
370 for (; inuc != outgoingNuclei.end(); inuc++)
371 inuc->setMomentum(inuc->getMomentum()*=rotate);
374 for (; ifrag != recoilFragments.end(); ifrag++) {
376 ifrag->SetMomentum(mom*=rotate);
383 if (verboseLevel > 1)
384 G4cout <<
" >>> G4CollisionOutput::trivialize" <<
G4endl;
389 outgoingNuclei.push_back(*nuclei_target);
393 outgoingParticles.push_back(*particle);
397 outgoingNuclei.push_back(*nuclei_bullet);
401 outgoingParticles.push_back(*particle);
408 if (verboseLevel > 1)
409 G4cout <<
" >>> G4CollisionOutput::setOnShell" <<
G4endl;
418 if(verboseLevel > 2){
419 G4cout <<
" bullet momentum = " << ini_mom.
e() <<
", "<< ini_mom.
x() <<
", "<< ini_mom.
y()<<
", "<< ini_mom.
z()<<
G4endl;
420 G4cout <<
" target momentum = " << momt.
e()<<
", "<< momt.
x()<<
", "<< momt.
y()<<
", "<< momt.
z()<<
G4endl;
421 G4cout <<
" Fstate momentum = " << out_mom.
e()<<
", "<< out_mom.
x()<<
", "<< out_mom.
y()<<
", "<< out_mom.
z()<<
G4endl;
432 mom_non_cons = ini_mom - out_mom;
438 if(verboseLevel > 2) {
441 <<
" e " << enc <<
" p " << pnc <<
G4endl
442 <<
" remaining exitation " << eex_rest <<
G4endl;
445 if (std::fabs(enc) <= accuracy && pnc <= accuracy) {
453 if (verboseLevel > 2)
G4cout <<
" re-balancing four-momenta" <<
G4endl;
462 for (
G4int ip=npart-1; ip>=0; ip--) {
463 if (outgoingParticles[ip].getKineticEnergy()+enc > 0.) {
464 last_mom = outgoingParticles[ip].getMomentum();
465 last_mom += mom_non_cons;
466 outgoingParticles[ip].setMomentum(last_mom);
470 }
else if (nnuc > 0) {
471 for (
G4int in=nnuc-1; in>=0; in--) {
472 if (outgoingNuclei[in].getKineticEnergy()+enc > 0.) {
473 last_mom = outgoingNuclei[in].getMomentum();
474 last_mom += mom_non_cons;
475 outgoingNuclei[in].setMomentum(last_mom);
479 }
else if (nfrag > 0) {
480 for (
G4int ifr=nfrag-1; ifr>=0; ifr--) {
482 last_mom = recoilFragments[ifr].GetMomentum()/GeV;
483 if ((last_mom.
e()-last_mom.
m())+enc > 0.) {
484 last_mom += mom_non_cons;
485 recoilFragments[ifr].SetMomentum(last_mom*GeV);
493 mom_non_cons = ini_mom - out_mom;
494 pnc = mom_non_cons.
rho();
495 enc = mom_non_cons.
e();
497 if(verboseLevel > 2){
499 G4cout <<
" momentum non conservation after (1): " <<
G4endl
500 <<
" e " << enc <<
" p " << pnc <<
G4endl;
504 G4bool need_hard_tuning =
true;
506 G4double encMeV = mom_non_cons.
e() / GeV;
508 for (
G4int i=0; i < nfrag; i++) {
509 G4double eex = recoilFragments[0].GetExcitationEnergy();
510 if (eex > 0.0 && eex + encMeV >= 0.0) {
517 need_hard_tuning =
false;
521 }
else if (nnuc > 0) {
522 for (
G4int i=0; i < nnuc; i++) {
523 G4double eex = outgoingNuclei[i].getExitationEnergy();
524 if (eex > 0.0 && eex + encMeV >= 0.0) {
525 outgoingNuclei[i].setExitationEnergy(eex+encMeV);
526 need_hard_tuning =
false;
530 if (need_hard_tuning && encMeV > 0.) {
531 outgoingNuclei[0].setExitationEnergy(encMeV);
532 need_hard_tuning =
false;
536 if (!need_hard_tuning) {
542 if (verboseLevel > 2) {
543 G4cout <<
" trying hard (particle-pair) tuning" <<
G4endl;
573 std::pair<std::pair<G4int, G4int>,
G4int> tune_par = selectPairToTune(enc);
574 std::pair<G4int, G4int> tune_particles = tune_par.first;
575 G4int mom_ind = tune_par.second;
578 (tune_particles.first >= 0 && tune_particles.second >= 0 &&
581 if (!tuning_possible) {
582 if (verboseLevel > 2)
G4cout <<
" tuning impossible " <<
G4endl;
586 if(verboseLevel > 2) {
587 G4cout <<
" p1 " << tune_particles.first <<
" p2 " << tune_particles.second
588 <<
" ind " << mom_ind <<
G4endl;
591 G4LorentzVector mom1 = outgoingParticles[tune_particles.first].getMomentum();
592 G4LorentzVector mom2 = outgoingParticles[tune_particles.second].getMomentum();
594 if (tuneSelectedPair(mom1, mom2, mom_ind)) {
595 outgoingParticles[tune_particles.first ].setMomentum(mom1);
596 outgoingParticles[tune_particles.second].setMomentum(mom2);
603 mom_non_cons = ini_mom - out_mom;
604 pnc = mom_non_cons.
rho();
605 enc = mom_non_cons.
e();
607 on_shell = (std::fabs(enc) < accuracy || pnc < accuracy);
609 if(verboseLevel > 2) {
610 G4cout <<
" momentum non conservation tuning: " <<
G4endl
611 <<
" e " << enc <<
" p " << pnc
612 << (on_shell?
" success":
" FAILURE") <<
G4endl;
623 eex_rest += outgoingNuclei[i].getExitationEnergyInGeV();
625 eex_rest += recoilFragments[i].GetExcitationEnergy() / GeV;
629std::pair<std::pair<G4int, G4int>,
G4int>
630G4CollisionOutput::selectPairToTune(
G4double de)
const {
631 if (verboseLevel > 2)
632 G4cout <<
" >>> G4CollisionOutput::selectPairToTune" <<
G4endl;
634 std::pair<G4int, G4int> tup(-1, -1);
636 std::pair<std::pair<G4int, G4int>,
G4int> tuner(tup, i3);
638 if (outgoingParticles.size() < 2)
return tuner;
643 G4double pcut = 0.3 * std::sqrt(1.88 * std::fabs(de));
646 for (
G4int i = 0; i <
G4int(outgoingParticles.size())-1; i++) {
649 for (
G4int j = i+1; j <
G4int(outgoingParticles.size()); j++) {
653 if (mom1[l]*mom2[l]<0.0) {
654 if (std::fabs(mom1[l])>pcut && std::fabs(mom2[l])>pcut) {
655 G4double psum = std::fabs(mom1[l]) + std::fabs(mom2[l]);
670 if (i3 < 0)
return tuner;
676 tuner.first.first = (p1>0.) ? ibest1 : ibest2;
677 tuner.first.second = (p1>0.) ? ibest2 : ibest1;
679 tuner.first.first = (p1<0.) ? ibest2 : ibest1;
680 tuner.first.second = (p1<0.) ? ibest1 : ibest2;
689 G4int mom_ind)
const {
690 if (verboseLevel > 2)
691 G4cout <<
" >>> G4CollisionOutput::tuneSelectedPair" <<
G4endl;
693 G4double newE12 = mom1.
e() + mom2.
e() + mom_non_cons.
e();
694 G4double R = 0.5 * (newE12*newE12 + mom2.
e()*mom2.
e() - mom1.
e()*mom1.
e()) / newE12;
695 G4double Q = -(mom1[mom_ind] + mom2[mom_ind]) / newE12;
697 G4double W = (R * Q + mom2[mom_ind]) * UDQ;
702 if (verboseLevel > 2)
G4cout <<
" DET < 0 : tuning failed" <<
G4endl;
714 if (mom_non_cons.
e() > 0.0) {
716 if (R + Q * x1 >= 0.0) {
721 if (!xset && x2 > 0.0) {
722 if (R + Q * x2 >= 0.0) {
729 if (R + Q * x1 >= 0.) {
734 if (!xset && x2 < 0.0) {
735 if (R + Q * x2 >= 0.0) {
743 if (verboseLevel > 2)
G4cout <<
" no appropriate solution found" <<
G4endl;
std::vector< G4InuclElementaryParticle >::iterator particleIterator
std::vector< G4InuclNuclei >::const_iterator nucleiIterator
std::vector< G4InuclNuclei >::iterator nucleiIterator
std::vector< G4Fragment >::iterator fragmentIterator
std::vector< G4InuclElementaryParticle >::iterator particleIterator
std::vector< G4ReactionProduct * > G4ReactionProductVector
G4GLOB_DLL std::ostream G4cout
void setVectM(const Hep3Vector &spatial, double mass)
const G4InuclElementaryParticle & getParticle() const
G4int numberOfOutgoingParticles() const
G4int getTotalStrangeness() const
void setRemainingExitationEnergy()
G4LorentzVector getTotalOutputMomentum() const
G4CollisionOutput & operator=(const G4CollisionOutput &right)
G4int getTotalBaryonNumber() const
void removeRecoilFragment(G4int index=-1)
void boostToLabFrame(const G4LorentzConvertor &convertor)
void rotateEvent(const G4LorentzRotation &rotate)
void removeOutgoingNucleus(G4int index)
void printCollisionOutput(std::ostream &os=G4cout) const
void addOutgoingParticle(const G4InuclElementaryParticle &particle)
G4int getTotalCharge() const
const G4Fragment & getRecoilFragment(G4int index=0) const
void setOnShell(G4InuclParticle *bullet, G4InuclParticle *target)
G4int numberOfOutgoingNuclei() const
void add(const G4CollisionOutput &right)
void trivialise(G4InuclParticle *bullet, G4InuclParticle *target)
void addOutgoingNuclei(const std::vector< G4InuclNuclei > &nuclea)
G4int numberOfFragments() const
void removeOutgoingParticle(G4int index)
void addOutgoingParticles(const std::vector< G4InuclElementaryParticle > &particles)
static G4Electron * Electron()
G4LorentzVector getMomentum() const
G4bool reflectionNeeded() const
G4LorentzVector backToTheLab(const G4LorentzVector &mom) const
G4LorentzVector rotate(const G4LorentzVector &mom) const
G4int GetAtomicNumber() const
G4int GetAtomicMass() const
const G4String & GetParticleName() const