In the case that particles are being passed back to Geant4 then we may have particles which have already interacted, so we should set the regeneration number accordingly.
780{
782
784 if (!truthBinding) {
786 description << G4String(
"getG4PrimaryParticle: ") +
"No ISF::TruthBinding associated with ISParticle (" << isp <<
")";
787 G4Exception(
"iGeant4::TransportTool",
"NoISFTruthBinding", FatalException,
description);
788 return nullptr;
789 }
792
794
795 if (particleDefinition==nullptr) {
796 ATH_MSG_ERROR(
"ISF_to_G4Event particle conversion failed. ISF_Particle PDG code = " << isp.
pdgCode() <<
797 "\n This usually indicates a problem with the evgen step.\n" <<
798 "Please report this to the Generators group, mentioning the release and generator used for evgen and the PDG code above." );
799 return nullptr;
800 }
801
802
803
807 if (useHepMC && currentGenPart) {
808 auto ¤tGenPartMomentum = currentGenPart->momentum();
809 px = currentGenPartMomentum.x();
810 py = currentGenPartMomentum.y();
811 pz = currentGenPartMomentum.z();
812 }
813 else {
815 px = ispMomentum.x();
816 py = ispMomentum.y();
817 pz = ispMomentum.z();
818 }
819
820 std::unique_ptr<G4PrimaryParticle> g4particle = std::make_unique<G4PrimaryParticle>(particleDefinition,px,py,pz);
821
822 std::unique_ptr<PrimaryParticleInformation> primaryPartInfo = std::make_unique<PrimaryParticleInformation>(primaryGenpart,&isp);
823
830 }
831 primaryPartInfo->SetRegenerationNr(regenerationNr);
832
833 if ( currentGenPart ) {
834 if (currentGenPart->end_vertex()) {
835
836
837 ATH_MSG_ERROR (
"getG4PrimaryParticle(): GenParticle has a valid end GenVertexPtr!" );
839 ATH_MSG_ERROR (
"getG4PrimaryParticle(): currentGenPart->end_vertex(): " << currentGenPart->end_vertex() <<
", barcode: " <<
HepMC::barcode(currentGenPart->end_vertex()) );
840 ATH_MSG_FATAL (
"getG4PrimaryParticle(): Passing GenParticles with a valid end GenVertexPtr as input is no longer supported." );
841 abort();
842 }
844 && !currentGenPart->end_vertex()) {
845
846
847 auto A_part = currentGenPart->attribute<HepMC::ShadowParticle>(HepMCStr::ShadowParticle);
849 if (!shadowPart) {
850 ATH_MSG_FATAL (
"Found a GenParticle with no matching GenParticle in the shadowGenEvent - something is wrong here!");
851 abort();
852 }
853 if (!shadowPart->end_vertex()) {
854 ATH_MSG_FATAL (
"Found status==2 shadow GenParticle with no end vertex - something is wrong here!");
855 abort();
856 }
858 }
859
861 const double pmass = g4particle->GetMass();
862 CLHEP::Hep3Vector gpv = g4particle->GetMomentum();
863 double g4px=g4particle->GetMomentum().x();
864 double g4py=g4particle->GetMomentum().y();
865 double g4pz=g4particle->GetMomentum().z();
866 if (useHepMC) {
867
871 } else {
872
873 px=currentGenPart->momentum().px();
874 py=currentGenPart->momentum().py();
875 pz=currentGenPart->momentum().pz();
876
877
878
879
880
881
882
883
884
885 if (std::abs(px-g4px)<CLHEP::keV && std::abs(py-g4py)<CLHEP::keV && std::abs(pz-g4pz)<CLHEP::keV) {
889 }
890 }
892 const double pe = std::sqrt(
mag2 + pmass*pmass);
893
894 double originalEnergy=currentGenPart->momentum().e();
895 if (originalEnergy>0.01) {
896 if ((originalEnergy-pe)/originalEnergy>0.01) {
897 double genpx=currentGenPart->momentum().px();
898 double genpy=currentGenPart->momentum().py();
899 double genpz=currentGenPart->momentum().pz();
900 double genp=sqrt(genpx*genpx + genpy*genpy + genpz*genpz);
901 ATH_MSG_WARNING(
"Truth change in energy for: " << currentGenPart<<
" Morg="<<currentGenPart->momentum().m()<<
" Mmod="<<pmass<<
" Eorg="<<originalEnergy<<
" Emod="<<pe<<
" porg="<<genp<<
" pmod="<<gpv.mag());
902 }
903 }
904
905 auto& currentGenPart_nc = currentGenPart;
907 }
908
910 ATH_MSG_VERBOSE(
" GetParticleUniqueID = " << primaryPartInfo->GetParticleUniqueID());
911 ATH_MSG_VERBOSE(
" GetRegenerationNr = " << primaryPartInfo->GetRegenerationNr());
912 ATH_MSG_VERBOSE(
" GetHepMCParticle = " << primaryPartInfo->GetHepMCParticle());
913 ATH_MSG_VERBOSE(
" GetISFParticle = " << primaryPartInfo->GetISFParticle());
914 g4particle->SetUserInformation(primaryPartInfo.release());
915
916 return g4particle.release();
917}
Scalar mag2() const
mag2 method - forward to squaredNorm()
const TruthBinding * getTruthBinding() const
pointer to the simulation truth - optional, can be 0
const Amg::Vector3D & momentum() const
The current momentum vector of the ISFParticle.
int pdgCode() const
PDG value.
HepMC::GenParticlePtr getCurrentGenParticle()
pointer to the particle in the simulation truth
std::string description
glabal timer - how long have I taken so far?
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation (only to be used in...
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation based on the status...
HepMC3::FourVector FourVector
HepMC3::GenParticlePtr GenParticlePtr
HepMC3::ConstGenParticlePtr ConstGenParticlePtr