| Geant4 User's Guide For Application Developers Visualization

8.8 Filtering

#### 8.8.1 Trajectory Filtering

Trajectory filtering allows you to visualise a subset of available trajectories. This can be useful if you only want to view interesting trajectories and discard uninteresting ones. Trajectory filtering can be run in two modes:

- Soft filtering: In this mode, uninteresting trajectories are marked invisible. Hence, they are still written, but (depending on the driver) will not be displayed. Some drivers, for example the HepRepFile driver, will allow you to selectively view these soft filtered trajectories
- Hard filtering: In this mode, uninteresting trajectories are not drawn at all. This mode is especially useful if the job produces huge graphics files, dominated by data from uninteresting trajectories.

Trajectory filter models are used to apply filtering according to specific criteria. The following models are currently supplied with the Geant4 distribution:

- G4TrajectoryChargeFilter (chargeFilter)
- G4TrajectoryParticleFilter (particleFilter)
- G4TrajectoryOriginVolumeFilter (originVolumeFilter)
- G4TrajectoryAttributeFilter (attributeFilter)

Multiple filters are automatically chained together, and can configured either interactively or in commands or in compiled code. The filters can be inverted, set to be inactive or set in a verbose mode. The above models are described briefly below, followed by some example configuration commands.

#### G4TrajectoryChargeFilter

This model filters trajectories according to charge. In standard running mode, only trajectories with charges matching those registered with the model will pass the filter.

#### G4TrajectoryParticleFilter

This model filters trajectories according to particle type. In standard running mode, only trajectories with particle types matching those registered with the model will pass the filter.

#### G4TrajectoryOriginVolumeFilter

This model filters trajectories according to originating volume name. In standard running mode, only trajectories with originating volumes matching those registered with the model will pass the filter.

#### G4TrajectoryAttributeFilter

This model filters trajectories based on the HepRep style attributes associated with trajectories. Each attribute drawer can be configured with interval and/or single value data. Single value data should override the interval data. Units should be specified on the command line if the attribute unit is specified either as a G4BestUnit or if the unit is part of the value string.

#### 8.8.1.1 Controlling from Commands

Multiple trajectory filter models can be created and configured using commands in the "`/vis/filtering/trajectories/`" directory. All generated filter models are chained together automatically.

Model configuration commands are generated dynamically when a filter model is instantiated. These commands apply directly to that instance.
See the interactive help for more information on the available commands.

#### 8.8.1.2 Example commands

#Create a particle filter. Configure to pass only gammas. Then
#invert to pass anything other than gammas. Set verbose printout,
#and then deactivate filter
`/vis/filtering/trajectories/create/particleFilter`
`/vis/filtering/trajectories/particleFilter-0/add gamma`
`/vis/filtering/trajectories/particleFilter-0/invert true`
`/vis/filtering/trajectories/particleFilter-0/verbose true`
`/vis/filtering/trajectories/particleFilter-0/active false`
#Create a charge filter. Configure to pass only neutral trajectories.
#Set verbose printout. Reset filter and reconfigure to pass only
#negativly charged trajectories.
`/vis/filtering/trajectories/create/chargeFilter`
`/vis/filtering/trajectories/chargeFilter-0/add 0`
`/vis/filtering/trajectories/chargeFilter-0/verbose true`
`/vis/filtering/trajectories/chargeFilter-0/reset true`
`/vis/filtering/trajectories/chargeFilter-0/add -1`
#Create an attribute filter named attributeFilter-0
`/vis/filtering/trajectories/create/attributeFilter`
#Select attribute "IMag"
`/vis/filtering/trajectories/attributeFilter-0/setAttribute IMag`
#Select trajectories with 2.5 MeV <= IMag< 1000 MeV
`/vis/filtering/trajectories/attributeFilter-0/addInterval 2.5 MeV 1000 MeV`
#List filters
`/vis/filtering/trajectories/list`
#Note that although particleFilter-0 and chargeFilter-0 are automatically
#chained, particleFilter-0 will not have any effect since
#it is has been deactivated.

#### 8.8.2 Hit Filtering

The attribute based filtering can be used on hits as well as trajectories. To active the interactive attribute based hit filtering, a filter call should be added to the "Draw" method of the hit class:

       void MyHit::Draw()
       {
          ...
          if (! pVVisManager->FilterHit(*this)) return;
          ...
       }

Interactive filtering can then be done through the commands in /vis/filtering/hits.

Next section
Back to contents