app/geant-exporter/geant-exporter.cc
void store_particles(TFile* root_file, G4ParticleTable* particle_table)
{
    REQUIRE(root_file);
    REQUIRE(particle_table);

    cout << "Exporting particles..." << endl;
    TTree tree_particles("particles", "particles");

    // Create temporary particle
    ImportParticle particle;
    tree_particles.Branch("ImportParticle", &particle);

    G4ParticleTable::G4PTblDicIterator& particle_iterator
        = *(G4ParticleTable::GetParticleTable()->GetIterator());
    particle_iterator.reset();

    while (particle_iterator())
    {
        G4ParticleDefinition* g4_particle_def = particle_iterator.value();

        // Skip "dummy" particles: generic ion and geantino
        if (g4_particle_def->GetPDGEncoding() == 0)
            continue;

        particle.name      = g4_particle_def->GetParticleName();
        particle.pdg       = g4_particle_def->GetPDGEncoding();
        particle.mass      = g4_particle_def->GetPDGMass();
        particle.charge    = g4_particle_def->GetPDGCharge();
        particle.spin      = g4_particle_def->GetPDGSpin();
        particle.lifetime  = g4_particle_def->GetPDGLifeTime();
        particle.is_stable = g4_particle_def->GetPDGStable();

        if (!particle.is_stable)
        {
            // Convert lifetime of unstable particles to seconds
            particle.lifetime /= s;
        }

        tree_particles.Fill();

        cout << "  Added " << g4_particle_def->GetParticleName() << endl;
    }
    cout << endl;

    root_file->Write();
}
//---------------------------------------------------------------------------//
/*!
 * Write particle table data to ROOT.
 *
 * The ROOT file must be open before this call.
 */
Write particle table data to ROOT.
The ROOT file must be open before this call.
Write particle table data to ROOT . The ROOT file must be open before this call .
void store_particles(TFile* root_file, G4ParticleTable* particle_table)
{
    REQUIRE(root_file);
    REQUIRE(particle_table);
    cout << "Exporting particles..." << endl;
    TTree tree_particles("particles", "particles");
    ImportParticle particle;
    tree_particles.Branch("ImportParticle", &particle);
    G4ParticleTable::G4PTblDicIterator& particle_iterator
        = *(G4ParticleTable::GetParticleTable()->GetIterator());
    particle_iterator.reset();
    while (particle_iterator())
    {
        G4ParticleDefinition* g4_particle_def = particle_iterator.value();
        if (g4_particle_def->GetPDGEncoding() == 0)
            continue;
        particle.name      = g4_particle_def->GetParticleName();
        particle.pdg       = g4_particle_def->GetPDGEncoding();
        particle.mass      = g4_particle_def->GetPDGMass();
        particle.charge    = g4_particle_def->GetPDGCharge();
        particle.spin      = g4_particle_def->GetPDGSpin();
        particle.lifetime  = g4_particle_def->GetPDGLifeTime();
        particle.is_stable = g4_particle_def->GetPDGStable();
        if (!particle.is_stable)
        {
            particle.lifetime /= s;
        }
        tree_particles.Fill();
        cout << "  Added " << g4_particle_def->GetParticleName() << endl;
    }
    cout << endl;
    root_file->Write();
}
void store_particles ( TFile * root_file , G4ParticleTable * particle_table ) { REQUIRE ( root_file ) ; REQUIRE ( particle_table ) ; cout << " " << endl ; TTree tree_particles ( " " , " " ) ; ImportParticle particle ; tree_particles . Branch ( " " , & particle ) ; G4ParticleTable :: G4PTblDicIterator & particle_iterator = * ( G4ParticleTable :: GetParticleTable ( ) -> GetIterator ( ) ) ; particle_iterator . reset ( ) ; while ( particle_iterator ( ) ) { G4ParticleDefinition * g4_particle_def = particle_iterator . value ( ) ; if ( g4_particle_def -> GetPDGEncoding ( ) == 0 ) continue ; particle . name = g4_particle_def -> GetParticleName ( ) ; particle . pdg = g4_particle_def -> GetPDGEncoding ( ) ; particle . mass = g4_particle_def -> GetPDGMass ( ) ; particle . charge = g4_particle_def -> GetPDGCharge ( ) ; particle . spin = g4_particle_def -> GetPDGSpin ( ) ; particle . lifetime = g4_particle_def -> GetPDGLifeTime ( ) ; particle . is_stable = g4_particle_def -> GetPDGStable ( ) ; if ( ! particle . is_stable ) { particle . lifetime /= s ; } tree_particles . Fill ( ) ; cout << " " << g4_particle_def -> GetParticleName ( ) << endl ; } cout << endl ; root_file -> Write ( ) ; }
Write particle table data to ROOT.
Write particle table data to ROOT .
// Create temporary particle // Skip "dummy" particles: generic ion and geantino // Convert lifetime of unstable particles to seconds