Visualization with python bindings

Hi,
I am using the following commands to avoid drawing a lot of low energy tracks:

/vis/filtering/trajectories/create/attributeFilter
/vis/filtering/trajectories/attributeFilter-0/setAttribute IMag
/vis/filtering/trajectories/attributeFilter-0/addInterval 10 MeV 100 TeV

This works nicely in a standalone application. However when using Geant4 with python I get the error message

***** COMMAND NOT FOUND </vis/filtering/trajectories/create/attributeFilter> *****

The command is in a vis.mac macro that I execute with
g4.gApplyUICommand("/control/execute vis.mac")

All other vis commands in the macro work fine, also with python. Only when these are activated I get the error…
I also tried setting these through the UI manager in BeginOfRunAction but although there is no error issued nothing happens. (running without python also this approach works fine)

geant4-config --version ==> 10.7.2

Many thanks for any help !

That command is instantiated by the filter factory. At startup, or soon after, you should get something like the below. It seems you get this with your standalone application, but could you please check if you get it with the python interface? (I have never used the python interface myself, so this might be a question for the Python experts.)

John

Registering model factories...

You have successfully registered the following model factories.
Registered model factories:
  generic
  drawByAttribute
  drawByCharge
  drawByOriginVolume
  drawByParticleID
  drawByEncounteredVolume

Registered models:
  None

Registered filter factories:
  attributeFilter
  chargeFilter
  originVolumeFilter
  particleFilter
  encounteredVolumeFilter

Registered filters:
  None

Hi,
Indeed, I get those messages at startup if using the standalone application, but none appears with python interface (I used python interface just a few times, essentially adapting others code…) . I get at startup:


Geant4 version Name: geant4-10-07-patch-02 (11-June-2021)
Copyright : Geant4 Collaboration
References : NIM A 506 (2003), 250-303
: IEEE-TNS 53 (2006), 270-278
: NIM A 835 (2016), 186-225
WWW : http://geant4.org/


Visualization Manager instantiating with verbosity “warnings (3)”…
<<< Geant4 Physics List simulation engine: FTFP_BERT

etc… but none of the above mentioned …
Thanks !

Hi,

Given that there seems not to exist a Python dedicated channel, how could I contact with an expert on this regard ? Thanks

OK, thanks. Let me iterate…I think this is a problem for the Python experts.

This is strange, You get

Visualization Manager instantiating with verbosity “warnings (3)”…

but not the other stuff. I wonder if the Python wrapper is using an old version of the vis manager…

Ah! I think I have it. It seems the g4py vis manager does not instantiate filter factories - see below. Compare this with the latest version of RegisterModelFactories in G4VisExecutive - also see below.

This is definitely an issue for the Python experts. (Perhaps you yourself can see what needs to be done?)

John

geant4/environments/g4py/source/visualization/pyG4VisManager.cc:

class PyG4VisManager : public G4VisManager {
...
  virtual void RegisterModelFactories() {
    RegisterModelFactory(new G4TrajectoryDrawByChargeFactory());
    RegisterModelFactory(new G4TrajectoryDrawByParticleIDFactory());
  }
};
inline void
G4VisExecutive::RegisterModelFactories()
{
   // Trajectory draw models
   RegisterModelFactory(new G4TrajectoryGenericDrawerFactory());
   RegisterModelFactory(new G4TrajectoryDrawByAttributeFactory());
   RegisterModelFactory(new G4TrajectoryDrawByChargeFactory());
   RegisterModelFactory(new G4TrajectoryDrawByOriginVolumeFactory());
   RegisterModelFactory(new G4TrajectoryDrawByParticleIDFactory());
   RegisterModelFactory(new G4TrajectoryDrawByEncounteredVolumeFactory());

   // Trajectory filter models
   RegisterModelFactory(new G4TrajectoryAttributeFilterFactory());
   RegisterModelFactory(new G4TrajectoryChargeFilterFactory());
   RegisterModelFactory(new G4TrajectoryOriginVolumeFilterFactory());
   RegisterModelFactory(new G4TrajectoryParticleFilterFactory());
   RegisterModelFactory(new G4TrajectoryEncounteredVolumeFilterFactory());

   // Hit filter models
   RegisterModelFactory(new G4HitAttributeFilterFactory());

   // Digi filter models
   RegisterModelFactory(new G4DigiAttributeFilterFactory());
}

Hi Bernado
You’re right there’s no specific forum for this, so this forum is probably the best. I have just escalated it to our Python expert, so let’s see what happens. Meanwhile, if you have an expertise in this direction please have a go yourself.
John

Would it be too simple too suggest that PyG4VisManager simply inherit G4VisExecutive instead of G4VisManager? Try it.

Hi John,
Thanks for the suggestion. Sure I can give it a try. I’m a python absolute beginner, but I understand this should be changed in the Geant4 source code, and recompile it, right ?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.