diff --git a/DDG4/src/Geant4InputHandling.cpp b/DDG4/src/Geant4InputHandling.cpp index e753b6eab36a639763422e70626a64f9d6e1171c..48e9ceaa0ebb0846e6ea54cabcb126bced5f187a 100644 --- a/DDG4/src/Geant4InputHandling.cpp +++ b/DDG4/src/Geant4InputHandling.cpp @@ -344,7 +344,8 @@ int dd4hep::sim::smearInteraction(const Geant4Action* caller, static G4PrimaryParticle* createG4Primary(const Geant4ParticleHandle p) { G4PrimaryParticle* g4 = 0; if ( 0 != p->pdgID ) { - const int pdgID = p->pdgID < 1000000000 ? p->pdgID : (p->pdgID / 10) * 10; + // For ions we use the pdgID of the definition, in case we had to zero the excitation level, see Geant4Particle.cpp + const int pdgID = p->pdgID < 1000000000 ? p->pdgID : p.definition()->GetPDGEncoding(); g4 = new G4PrimaryParticle(pdgID, p->psx, p->psy, p->psz, p.energy()); } else { diff --git a/DDG4/src/Geant4Particle.cpp b/DDG4/src/Geant4Particle.cpp index 2b2c007163992dffb2afecc6541dc81e064c7fbb..a238109370f185e1fb58e38f8a8d5a8d3e414e92 100644 --- a/DDG4/src/Geant4Particle.cpp +++ b/DDG4/src/Geant4Particle.cpp @@ -118,13 +118,31 @@ const G4ParticleDefinition* Geant4ParticleHandle::definition() const { G4ParticleTable* tab = G4ParticleTable::GetParticleTable(); G4ParticleDefinition* def = tab->FindParticle(particle->pdgID); if( 1000000000 < particle->pdgID) { - if(particle->pdgID % 10) { - // this is an excited ion, not sure how to handle this - std::cout << "We are ignoring excited state!!!!" << std::endl; + // creating ions here + // ion encoding is 10 L ZZZ AAA I + int id = particle->pdgID - 1000000000; // leading 10 is just identifier + const int L = id / 10000000; id %= 10000000; // strange-quark content + const int Z = id / 10000; id %= 10000; + const int A = id / 10; id %= 10; + const int lvl = id; + G4IonTable* tab_ion = G4IonTable::GetIonTable(); + // Have to look for existing Ions, excited or not + G4ParticleDefinition* def_ion = tab_ion->FindIon(Z, A, L, lvl); + if(def_ion) { + //We found an existing Ion, we are good to go + printout(VERBOSE,"Geant4Particle","+++ Returning ion with PDG %10d", def_ion->GetPDGEncoding()); + return def_ion; + } else if(lvl == 0) { + // GetIon creates the Ion if it does not exist, if this does not work something is seriously wrong + printout(VERBOSE,"Geant4Particle","+++ Creating ion with PDG %10d", particle->pdgID); + return tab_ion->GetIon(Z, A, L, 0.0); } - // last digit is the excitation level, we just set this to zero - return G4IonTable::GetIonTable()->GetIon((particle->pdgID / 10) * 10); - } + //Cannot use GetIon with lvl > 0, must give energy, but we don't know where to get energy from + printout(WARNING,"Geant4Particle","+++ Cannot find excited ion with PDG %10d, setting excitation level to zero", + particle->pdgID); + return tab_ion->GetIon(Z, A, L, /* E= */ 0.0); + } // finished with ions + if ( 0 == def && 0 == particle->pdgID ) { if ( 0 == particle->charge ) return G4Geantino::Definition();