How construct and apply user-defined Filter in UI-command base scoring

Dear G4 experts:
I am simulating 150MeV proton inject water phantom and scoring the dose distribution. I do the scoring with UI-command scoring with code:
G4ScoringManager::GetScoringManager();
I use
# define scorer
/score/quantity/energyDeposit EdepScorer MeV
to define the Edep scorer, but the default filter can not separate Edep from primary protons and secondary protons. How can I construct a primary filter and how to make the filter available in UI-command? Are there any examples to show how to construct it?

Thanks in Advance.

Hello everyone, I now construct a Messenger to show my filter cmd in the UI-command. And also I implement the filter class with self-defined Accept(). But seems the
mesh->SetFilter();
did not work correctly. Anyone who knows how to apply the self-defined Filter to a scorer?
Thanks in advance.

Hi everyone:

the code
G4VScoringMesh* mesh = fScoringManager->GetCurrentMesh();
seems not work correctly in Multi-thread mode. When I compile my code with single-thread, then everything works as expected.

Anyone who knows how to set this sentence correctly? Thanks in advance.