Trouble with changing color of secondaries tracks

  • Geant4 Version:_V11.3.1
  • Operating System:_Ubuntu
  • Compiler/Version:_
  • CMake Version:_

Hi everyone,

I’m currently working on visualizing trajectories of particles in Geant4 and trying to use the “/vis/modeling/trajectories/…” commands in my “vis.mac” to change the color of trajectories of only secondary photons (i.e. Characteristic X-rays). Any idea how to do it? Thank you.

Best regards,
A.H.

Hi Adam

Interesting. I assume you have studied the documentation on the /vis/modeling/trajectories/ commands - Enhanced Trajectory Drawing — Book For Application Developers 11.3 documentation and Trajectory Filtering — Book For Application Developers 11.3 documentation. Are you saying you cannot see a way to do what you want?

Mmm. “secondary photons (i.e. Characteristic X-rays)”. You mean from atomic de-ecitation? What would characterise them in Geant4? Creator process, perhaps? You could dump an event with /tracking/verbose 2, for example, and see if this informs you.

To model or filter on creator process (if that does it for you), you would have to ask for rich trajectories (/vis/scene/add/trajectories rich), and use /vis/modeling/trajectories/create/drawByAttribute or /vis/filtering/trajectories/create/attributeFilter.

Does this help?

If all else fails, you can write your own DrawTrajectory - but that’s a considerable job, so come back if you think that would worth a way to go.

John

Hi John,

thank you for the information. Yes, I can not find a way using /vis/modeling/tajectories/… to change the color of the tracks of characteristic X-rays. The Creator process is “phot”.

Best regards,
A.H.

OK…

So could you create an attributeFilter that selects phot as the creator process.

Assuming /vis/scene/add/trajectories rich. Then consult the consequent output for information at startup about available attributes.

So, something like:

/vis/filtering/trajectories/create/attributeFilter
/vis/filtering/trajectories/attributeFilter-0/setAttribute CPN
/vis/filtering/trajectories/attributeFilter-0/addValue phot

Does something for me - see image. Is it what you want?

John

Hi John,

I followed your suggestion to filter the trajectories, and I see all tracks displayed in green. After consulting the manual, I applied the following commands:

/vis/modeling/trajectories/create/drawByAttribute
/vis/modeling/trajectories/drawByAttribute-0/setAttribute CPN
/vis/modeling/trajectories/drawByAttribute-0/addValue phot_key phot
/vis/modeling/trajectories/drawByAttribute-0/phot_key/setLineColour blue

This setup works partially: primary tracks appear in grey, and all other tracks are shown in blue. However, I intended for only secondary photons generated by the “phot” creator process to be displayed in blue—not all photons.

Thanks a lot for your support. I truly appreciate it.

Best regards,
A.H.

Hi Adam

Grey: yes, the default for tracks not otherwise specified.

Blue: all tracks with CPN==“phot”. Maybe all photons (except primaries) in your application are created by photon de-excitation. That might be just how it is. Mmmm. It may not be possible to differentiate the tracks you want. Can you think of some other additional criteria? I’m afraid I’m out of ideas.

John

Hi John,

thank you, Does CPN work only for “phot”? I have set up the following:

/vis/modeling/trajectories/create/drawByAttribute
/vis/modeling/trajectories/drawByAttribute-0/setAttribute CPN

Primary (empty string)

/vis/modeling/trajectories/drawByAttribute-0/addValue primary_key “”
/vis/modeling/trajectories/drawByAttribute-0/primary_key/setLineColour green

phot

/vis/modeling/trajectories/drawByAttribute-0/addValue phot_key phot
/vis/modeling/trajectories/drawByAttribute-0/phot_key/setLineColour blue

comp

/vis/modeling/trajectories/drawByAttribute-0/addValue compt_key compt
/vis/modeling/trajectories/drawByAttribute-0/compt_key/setLineColour red

Rayl

/vis/modeling/trajectories/drawByAttribute-0/addValue rayl_key Rayl
/vis/modeling/trajectories/drawByAttribute-0/rayl_key/setLineColour orange

However, I can only see tracks with CPN=“phot” in blue, even hough others (e.g. comp) sould also be present. Any idea why the others aren’t showing up?

Best regrads,
A.H.

Hi Adam

You are rapidly becoming the world expert on Geant4 trajectory modeling and filtering! :slight_smile:

Primary (empty string): does that actually work? Do you see green tracks?

comp and Rayl: These are rare processes. Depends on the energy (what are your energies?). You might see some if you make the rest invisible.

Note all such commands have a default option, E.g:

/vis/modeling/trajectories/drawByAttribute-0/default/

That can be a source of other options:

John

Hi John,

Using an empty string for the primary attribute does not work! However, I found that using CPN works—but only when CPN=phot.

When setting CPN=compt, the color applies to Compton electrons, not to Compton-scattered photons.

Setting CPN=Rayl doesn’t work at all, even though Rayleigh-scattered photons are there.

I think CPN is not a reliable way to distinguish between all these photon types. Therefore, I will implement the desired behavior in TrackingAction.cc.

Thanks a lot for your help—I really appreciate it!

Cheers,
A. H.

That makes sense: in Compton scattering, the outgoing photon is the same track as the incoming photon, just a lower energy. If you want to see photons which Compton-scattered, you’d have to filter on the G4Step::GetProcessDefinedStep(). Since the visualization works with the whole trajectory, I don’t believe that’s possible.

Ah. You’re right, Mike.

So, how to implement what you want, Adam? Would you be trying to issue Draw in TrackingAction? Be aware you can only Draw in Sequential/Serial mode (think of the mess that would happen in multithreading mode!):

  auto runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Serial);

(see exampleB1.cc).

I think that’s a good place to start. Ultimately, as I think I mentioned above, you could define your own trajectory and implement DrawTrajectory. But that’s a hike in effort; come back to us if you think it’s worth this.

Dear all,

thank you for your help.

Cheers,
A. H.