Skip to content
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

NSB tunning : pre-generated NSB only waveforms and a new class #1274

Merged
merged 6 commits into from
Jul 30, 2024

Conversation

gabemery
Copy link
Collaborator

@gabemery gabemery commented Jul 9, 2024

In order to implement the possibility to pre-generate nsb waveforms to add nsb to events instead of generating new nsb waveforms on the fly, a new class was added.

The class WaveformNsbTunner take a new config file entry pre_computed_multiplicity which can be set to 0 to generate nsb on the fly. Or to any int to pre-generate pre_computed_multiplicity X number of pixels X number of gains waveforms.

Closes #1273

To do before removing draft :

  • Add docstrings to function and class
  • Pass CI
  • Quick result consistency check

Some processing duration to illustrate the gain on a single (proton) MC file :
+50% NSB, no pre-generation : 1min 39s
+50% NSB, 10X pre-generation : 1min 28s
+1000% NSB, no pre-generation : 3min 18s
+1000% NSB, 10X pre-generation : 1min 31s

Results of the tuning are compatible between using pre-generated waveforms or on the fly generation. Results are also the same as the previous implementation. See the signal less pixel charges for a data runs vs MC without and with tuning.
image

Unrelated to this PR , but the injection of 55% nominal NSB here is a bit higher than automatically extracted using calculate_required_additional_nsb (~40%). This will need to be investigated independently.

…possibility to pre-generate NSB only waveforms to randomly apply to events.
@gabemery gabemery requested a review from moralejo July 9, 2024 15:05
@vuillaut
Copy link
Member

vuillaut commented Jul 9, 2024

Hi Grabiel, all,

Won't this negatively affect image-based methods that do not use cleaning?

@gabemery
Copy link
Collaborator Author

Hi @vuillaut. You mean that using correlated nsb injection could lead to issues? Or are you speaking of something else?

@vuillaut
Copy link
Member

Hi @vuillaut. You mean that using correlated nsb injection could lead to issues? Or are you speaking of something else?

Hi.
Yes exactly. I understand that after cleaning, most of the injected nsb will anyway be removed so re-using nsb waveforms should not be a problem but I am afraid it won't be the case for methods using uncleaned images.

@gabemery
Copy link
Collaborator Author

It also concerned me, but with the current implementation I think it should not be a massive issue because:

  • Assuming 10X pre-generation, I have 18550 simulated waveform of which I use 1855 selected in a random order. So each full injection will be likely unique in terms of 1855 selected waveforms.
  • Injection is done on already existing r1, so the resulting waveform is the sum of the cleanly simulated simtel waveform and my injection. So they all are unique. Of course if the injected NSB is significantly higher than the original, the resulting injection will be dominated by the new waveforms.
  • All of this is done file-wise. So a new generation of nsb waveform is done every O(1000) events
  • This is adding stochastic noise on top of signal without changing the baseline, so there should be no specific pattern with useful information for machine learning algorithm?

Copy link

codecov bot commented Jul 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.44%. Comparing base (ef91c64) to head (15e9093).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1274      +/-   ##
==========================================
+ Coverage   73.35%   73.44%   +0.08%     
==========================================
  Files         134      134              
  Lines       14117    14161      +44     
==========================================
+ Hits        10356    10400      +44     
  Misses       3761     3761              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@morcuended morcuended left a comment

Choose a reason for hiding this comment

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

thanks @gabemery, I left some comments

@@ -130,6 +130,9 @@ def test_r0_to_dl1_lhfit_mc(tmp_path, mc_gamma_testfile):
config['lh_fit_config']["use_interleaved"] = True
config['waveform_nsb_tuning']['nsb_tuning'] = True
r0_to_dl1(mc_gamma_testfile, custom_config=config, output_filename=tmp_path / "tmp.h5")
os.remove(tmp_path / "tmp.h5")
config['waveform_nsb_tuning']['pre_computed_multiplicity'] = 0
Copy link
Member

Choose a reason for hiding this comment

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

wasn't it already 'pre_computed_multiplicity'=0 in the first place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It defaults to 10 from line 432 in r0_to_dl1.py (and in the class, but this is not used) and is not defined in the standard config file.
I should probably add it there too as being 10 for consistency. (Or make it None in the default config file and change the code to support it)
And in this test it may be clearer if I explicitly select its value as 10 to avoid confusion.


"""
log.info(f"Pre-generating nsb waveforms for nsb tuning and telescope id {tel_id}.")
n = 25
Copy link
Member

Choose a reason for hiding this comment

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

this n = 25 is defined several times, does it make sense to define it once at the beginning of the file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does, I will change it.

…efinition done twice in WaveformNsbTunner to init. Clarify parameter naming and add comment.
@gabemery gabemery marked this pull request as ready for review July 11, 2024 15:11
@gabemery gabemery requested a review from morcuended July 11, 2024 15:11
@moralejo moralejo merged commit a3da2c0 into main Jul 30, 2024
9 checks passed
@morcuended morcuended deleted the Implementing_precomputed_nsb_waveforms branch July 30, 2024 08:56
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.

Speeding-up the NSB addition at waveform level
4 participants