Signal overlay in data/MC plots #425
-
Hello, I would like to plot pre-fit distribution with signal overlaid on the background events, as well as scaling of signal events. I am implementing plotting part as cabinetry.visualize.data_mc(prediction_prefit,
data,
config=config,
figure_folder=figurespath,
log_scale=True,
close_figure=True)
cabinetry.visualize.data_mc(prediction_prefit,
data,
config=config,
figure_folder=figurespath,
log_scale=False,
close_figure=True) Best Regards, |
Beta Was this translation helpful? Give feedback.
Replies: 14 comments 8 replies
-
Hi @Tomoya-Iizawa, you can scale signal events pre-fit by changing the nominal value of the normalization factor you attach to the signal. In the example config, this corresponds to the following: https://github.com/scikit-hep/cabinetry/blob/master/config_example.yml#L57. When you talk about overlay, I assume you mean something like the red W' contribution in this example https://atlas.web.cern.ch/Atlas/GROUPS/PHYSICS/CONFNOTES/ATLAS-CONF-2021-043/fig_05a.png? There are two ways to draw this that I am aware of, normalized to total background or normalized to some reference cross-section. At the moment there is no built-in option to do this. It is conceptually not a difficult addition, but there are a few interface aspects that would be needed:
The easiest way right now to overlay a signal would be to just add the overlaid contribution manually via It would be interesting to get some feedback for how well this works if doing it manually and externally for this example, as I am generally curious to learn more about which kind of things would best be done outside of |
Beta Was this translation helpful? Give feedback.
-
Hi @alexander-held, Thank you for your quick answer. Best Regards, |
Beta Was this translation helpful? Give feedback.
-
The stack order follows the sample order defined by For changing the legend: what shows up in the legend is the name of the sample you put in your The notebook did not include an overlay example, it was just an example for how to generally edit existing figures. It now does include an example of that though: https://gist.github.com/alexander-held/2ca63e4c4c3de2114bf8d903bf28bb4a. In addition, it shows how to re-do the legend, which you can also use to edit the text of the legend to anything you want. |
Beta Was this translation helpful? Give feedback.
-
Hi @alexander-held, Thank you for including the example! Traceback (most recent call last): Do you have some idea to fix this? And I have another question that where the overlaid signal is added to plot? Best Regards, |
Beta Was this translation helpful? Give feedback.
-
You need a more recent version of I am not understanding the other question: |
Beta Was this translation helpful? Give feedback.
-
OK, I will check matplotlib version and try update. |
Beta Was this translation helpful? Give feedback.
-
Are you running the notebook as-is? It works fine for me and I do not know what could be causing problems on your end. Try with updated |
Beta Was this translation helpful? Give feedback.
-
Hi, I tried to change matplotlib version from 3.7.1 to 3.7.2, and modify bin_edges, it works. Best Regards, |
Beta Was this translation helpful? Give feedback.
-
Glad to hear it's working! I am closing this as I think this is best done externally like in the example here. If this request comes up again we can consider how we can make this more convenient to users. |
Beta Was this translation helpful? Give feedback.
-
Hi, this is just a question, is there any way not to draw signal events in histogram? Best, |
Beta Was this translation helpful? Give feedback.
-
No, there's no built-in option for that. You can do it in the following way:
Here is another gist showing you how to build custom model predictions: https://gist.github.com/alexander-held/9eb02d00986ebfbc908a887d8df64ef9. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your adivce. Traceback (most recent call last): The difference w.r.t. the example is Do you have any idea to resolve this? |
Beta Was this translation helpful? Give feedback.
-
I think the best place is probably the Q&A section in the discussions: https://github.com/scikit-hep/cabinetry/discussions. I'll convert this over from an issue to a discussion. With regards to the question: no, I don't have a good idea what could cause this. You can inspect the contents of the model prediction object, it sounds like the lengths of the yield prediction and uncertainties do not match. I do not know how this could happen. There might be a bug in my gist implementation, or a bug inside |
Beta Was this translation helpful? Give feedback.
-
Hi, As far as my current understanding, this error seems to happen when I include multiple regions in the fit. If I run for a single region, this works without error. I will keep investigation, but if you have any good idea to make this work for multiple regions, please let me know! Best, |
Beta Was this translation helpful? Give feedback.
The stack order follows the sample order defined by
pyhf
, which is alphabetical. There is currently no way to change that.For changing the legend: what shows up in the legend is the name of the sample you put in your
cabinetry
config (if you build your workspace withcabinetry
) or the workspace itself otherwise. This means that you can rename your signal to "signal x 100" and it will show up like that in the plot. You can accordingly scale the signal by 100 (e.g. by applying a weight of 100 in the config).The notebook did not include an overlay example, it was just an example for how to generally edit existing figures. It now does include an example of that though: https://gist.github.c…