Record Species in different Volume & copynum

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

Geant4 Version: 11.2.beta
_Operating System:_Windows
_Compiler/Version:_MSVC_2019
CMake Version:

Hello, everyone
Recently, I am working to record different species in the multiple cells, I have added ScoreSpecies into MutiFunctionalDetector as SensitiveDetector in multiple mode. In the RunAction, I find that I can’t distinguish the molecular from different cells.I have add some output in TimeStepAction, but it’s not what I need. Now I want to add some functions in G4MoleculeCounter as following, but I can’t find the program’s interface.

void TimeStepAction::UserReactionAction(const G4Track& a, const G4Track& b,
                                        const std::vector<G4Track*>* products)
{
    G4double time = a.GetGlobalTime();
    auto LogicalVolume = a.GetLogicalVolumeAtVertex();
    G4String Name = LogicalVolume->GetName();
    G4int copynum = a.GetTouchable()->GetCopyNumber();
    G4cout << "current_time :  " << time << " current Volume name : " << Name 
        << " The copynum : "<< copynum <<G4endl;}

I appreciate any help you can provide. :smile:


Dear experts,
I find the program’s interface in the G4Molecule.cc, Function G4Track* G4Molecule::BuildTrack

G4Track* G4Molecule::BuildTrack(G4double globalTime,
                                 const G4ThreeVector& position)
{
    if (fpTrack != nullptr)
    {
        G4Exception("G4Molecule::BuildTrack", "Molecule001", FatalErrorInArgument,
                    "A track was already assigned to this molecule");
    }

    // Kinetic Values
    // Set a random direction to the molecule
    G4double costheta = (2 * G4UniformRand() - 1);
    G4double theta = acos(costheta);
    G4double phi = 2 * pi * G4UniformRand();

    G4double xMomentum = cos(phi) * sin(theta);
    G4double yMomentum = sin(theta) * sin(phi);
    G4double zMomentum = costheta;

    G4ThreeVector MomentumDirection(xMomentum, yMomentum, zMomentum);
    G4double KineticEnergy = GetKineticEnergy();

    G4DynamicParticle* dynamicParticle = new G4DynamicParticle(
        fpMolecularConfiguration->GetDefinition(), MomentumDirection,
        KineticEnergy);

    G4cout << "Here is BuildTrack() " ;

    //Set the Track
    fpTrack = new G4Track(dynamicParticle, globalTime, position);
    fpTrack->SetUserInformation(this);


    //GetVolumeName
    /*
    G4String Volume_name = fpTrack->GetLogicalVolumeAtVertex()->GetName();
    G4String Copynum = std::to_string(fpTrack->GetTouchable()->GetCopyNumber());
    G4String AreaName = Volume_name + Copynum;
    */
    if (G4VMoleculeCounter::Instance()->InUse())
    {
        G4VMoleculeCounter::Instance()->
            AddAMoleculeAtTime(fpMolecularConfiguration,
                globalTime,
                &(fpTrack->GetPosition())
                //AreaName
            );
    }
    /*
    G4cout << " AreaName is : "<< AreaName << G4endl;
    */
    return fpTrack;
}

It can be compiled successfully, but there is always an error when running the corresponding process.dll. I want to know if there is a way to return the Volume where the particle is located to the MoleculeCounter at the beginning of particle creation?