Skip to content

Add a StereoDispCombiner #2731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft

Add a StereoDispCombiner #2731

wants to merge 21 commits into from

Conversation

Hckjs
Copy link
Contributor

@Hckjs Hckjs commented Apr 2, 2025

This is basically the StereoCombiner already implemented here
in magic-cta-pipe.

It combines the mono DISP reconstruction by

  1. calculating combinations of 2 telescopes for every array event
  2. calculating the minimum distance for the 4 possible SIGN pairs for each combination
  3. calculating the weighted average for the minimum distance SIGN pair (fov lon/lat) per combination
  4. calculating the weighted average of all combinations for an array event with the summed weights from 3).

@Hckjs Hckjs requested review from maxnoe, kosack and LukasBeiske April 2, 2025 16:50
@Hckjs Hckjs changed the title Adding a StereoDispCombiner Add a StereoDispCombiner Apr 2, 2025
@@ -405,3 +415,251 @@ def predict_table(self, mono_predictions: Table) -> Table:
stereo_table[f"{self.prefix}_telescopes"] = tel_ids
add_defaults_and_meta(stereo_table, _containers[self.property], self.prefix)
return stereo_table


class StereoDispCombiner(StereoCombiner):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this algorithm differ from the implementation in EventDisplay by @GernotMaier ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also maybe a good citation: https://ui.adsabs.harvard.edu/abs/1999APh....12..135H/abstract, as this is essentially an implementation of "algorithm 3" of that paper.

if self.weights == "intensity":
return data.hillas.intensity

if self.weights == "konrad":
Copy link
Member

@kosack kosack Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've made this comment before: can we pick a better name here, since calling it "konrad" is not very helpful? This weighting is intensity x aspect-ratio, so we could call it "intensity-aspect-ratio" or "aspect-weighted-intensity" or "shape-intensity" or similar? maybe there is a shorter word... I think I prefer "aspect-weighted-intensity" , even though it's long, it is easy to understand.

@Hckjs Hckjs force-pushed the stereo_combiner branch from 8ecf073 to e998c78 Compare May 1, 2025 18:28
@LukasBeiske LukasBeiske force-pushed the stereo_combiner branch 2 times, most recently from 5f2dd49 to 47d2798 Compare May 15, 2025 11:39
Copy link
Member

@kosack kosack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a predicted disp.sign_score that is not used in this method, which seems odd. Is that the reason why the pair-wise average including both disps is made rather than a simple weighted average over predictions? Is there citation for the MARS method, by the way? i'd be interested to see if simpler methods were tested.

for tel_id, dl2 in event.dl2.tel.items():
if dl2.geometry[self.prefix].is_valid:
dl1 = event.dl1.tel[tel_id].parameters
hillas_fov_lon = dl1.hillas.fov_lon.to_value(u.deg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't actually have to convert or strip the units here, as astropy Quantities work automatically for numpy functions

>>> np.sin(90*u.deg) == np.sin(np.pi/2.0*u.rad)
True

>> np.sin(90*u.m)
UnitTypeError: Can only apply 'sin' function to quantities with angle units

That means you can avoid manually adding back the units later as well.

@LukasBeiske
Copy link
Contributor

LukasBeiske commented May 15, 2025

We have a predicted disp.sign_score that is not used in this method, which seems odd. Is that the reason why the pair-wise average including both disps is made rather than a simple weighted average over predictions? Is there citation for the MARS method, by the way? i'd be interested to see if simpler methods were tested.

This sign_score is mostly meant for performance plots (sign_score = np.abs(2 * sign_proba - 1.0) where sign_proba is the output of the sign classifier).
The weighted average over telescope-wise (alt, az) predictions is what the StereoMeanCombiner does for the disp reconstruction, but this method here seemed to perform better in a master thesis in Dortmund some years ago. We can add some performance plots here once the remaining issues are figured out.

@maxnoe
Copy link
Member

maxnoe commented May 15, 2025

The weighted average over telescope-wise (alt, az) predictions is what the StereoMeanCombiner does for the disp reconstruction, but this method was proven to perform better in a master thesis in Dortmund some years ago.

It's also easy to argue why: especially at low energies, disp sign is not really reconstructible (random guess, sign_score ~ 0.5). But with multiple telescopes, it's quite easy to see which option is actually correct and make the weighted average over the correct locations.

There are still a couple of different options for stereo disp, but most of them do not actually use the sign prediction, that is only used for mono as far as I know.

The MAGIC MARS method is explained in a short paragraph here:

Foreach of them, the disp identifies two possible reconstructed
source positions (head-tail ambiguity). At this stage for
each stereoscopic event, melibea evaluates all four possible
combinations of position pairs, and chooses the closest pair,
but only if its distance is smaller than a certain value. If none
of the pairs satisfies this condition, the event is rejected. The
stereo-reconstructed position is determined as the weighted
average of the chosen pair of positions.

https://cbpf.br/icrc2013/papers/icrc2013-0773.pdf

@LukasBeiske LukasBeiske mentioned this pull request Jun 12, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants