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

CutPlugin class for cuts in straxen #274

Merged
merged 18 commits into from Jul 21, 2020

Conversation

JoranAngevaare
Copy link
Member

@JoranAngevaare JoranAngevaare commented Jun 23, 2020

The cuts currently in straxen (https://github.com/XENONnT/straxen/blob/master/straxen/plugins/x1t_cuts.py ) have a quite lot of overlap with one another. Most of the time a simple Boolean array is all that is returned. However, we each time have to add the time fields et cetera which may somewhat obscure the functionality.
To simplify the cuts somewhat I've written a simple Plugin Class. In straxen it could be used as for example:

class CutS1s(CutPlugin):
    depends_on = ('events', 'corrected_areas')
    provides = 'cs1_cut'
    cut_description = "Remove cS1 above 100 PE"
    cut_name ='cut_high_cs1'
    __version__ = '0.0.0'
    
    def cut_by(self, events):
        return events['cs1'] > 100
class CutS2s(CutPlugin):
    depends_on = ('events', 'corrected_areas')
    cut_description = "Remove cS2s below 100 PE"
    
    def cut_by(self, events):
        return events['cs2'] < 100
class CutRecord0(CutPlugin):
    depends_on = ('records',)
    provides = 'is_not_record0_cut'
    cut_description = "is record 0"
    cut_name ='is_not_record0_cut'
    __version__ = '0.0.0'
    
    def cut_by(self, records):
        return records['record_i'] != 0

The cuts currently in straxen (https://github.com/XENONnT/straxen/blob/master/straxen/plugins/x1t_cuts.py ) have a quite lot of overlap with one another. Most of the time a simple Boolean array is all that is returned. However, we each time have to add the time fields et cetera which may somewhat obscure the functionality.
To simplify the cuts somewhat I've written a simple Plugin Class. In straxen it could be used as for example:
```
class CutS1s(CutPlugin):
    depends_on = ('events', 'corrected_areas')
    provides = 'cs1_cut'
    cut_description = "Remove cS1 above 100 PE"
    cut_name ='cut_high_cs1'
    __version__ = '0.0.0'
    
    def cut_by(self, events):
        return events['cs1'] > 100
```
```
class CutS2s(CutPlugin):
    depends_on = ('events', 'corrected_areas')
    cut_description = "Remove cS2s below 100 PE"
    
    def cut_by(self, events):
        return events['cs2'] < 100
```
@WenzDaniel
Copy link
Collaborator

Hej Joran,

nice Idea. I have not checked your code yet, but one quick question. In your current version cuts would be the same data_kind as events would not they be? Maybe it is better to have a new "cut"-data_kind instead?

@JoranAngevaare
Copy link
Member Author

Hej Joran,

nice Idea. I have not checked your code yet, but one quick question. In your current version cuts would be the same data_kind as events would not they be? Maybe it is better to have a new "cut"-data_kind instead?

Hi Daniel,
Thanks for the suggestion! The datakind is derived from the dependency specified in the cut_by(self <datakind>), so in principle you could cut on peak level. I think it would make analysts lives harder if we create a new datatype that is not events as that is where most analysts will actually apply the cuts. That can get tricky if you want to load multiple datakinds as get_df (the function most analysts will use) will complain that this is not possible.

strax/plugin.py Outdated Show resolved Hide resolved
strax/plugin.py Outdated Show resolved Hide resolved
strax/plugin.py Outdated Show resolved Hide resolved
@JoranAngevaare
Copy link
Member Author

As @WenzDaniel just correctly pointed out the endtime needs to be computed when we are working with lower level plugins. Although it's not really the envisaged application it's easy enough to implement.

See now for example:

class CutRecord0(CutPlugin):
    depends_on = ('records',)
    provides = 'is_not_record0_cut'
    cut_description = "is record 0"
    cut_name ='is_not_record0_cut'
    __version__ = '0.0.0'
    
    def cut_by(self, records):
        return records['record_i'] != 0

@JoranAngevaare
Copy link
Member Author

JoranAngevaare commented Jul 7, 2020

In 752f521 I've added a test mainly since I think I should learn how how to write tests. Also it's completely fine to add more tests.

If someone foresees a good metric to add to this test, please let me know.

@JoranAngevaare JoranAngevaare changed the title Add CutPlugin class for cuts in straxen CutPlugin class for cuts in straxen Jul 7, 2020
strax/plugin.py Outdated Show resolved Hide resolved
@JoranAngevaare
Copy link
Member Author

@ ACs this is ready for merge

targets=strax.camel_to_snake(CutSomething.__name__))
correct_answer = np.sum(input_peaks[_dtype_name] > cut_threshold)
assert len(result) == len(input_peaks), "WTF??"
assert correct_answer == np.sum(result['cut_something']), "Cut plugin does not give boolean arrays correctly"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just add one additional test checking the endtime since we had these issues in peaks and you are computing some new endtimes here. Does not hurt much to have this little check. All the rest looks fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, this is done in 3673c28 !

@JoranAngevaare JoranAngevaare added documentation Something should be addressed in the docs enhancement New feature or request labels Jul 21, 2020
@WenzDaniel WenzDaniel merged commit b0d2428 into AxFoundation:master Jul 21, 2020
@JoranAngevaare JoranAngevaare deleted the patch-3 branch July 21, 2020 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Something should be addressed in the docs enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants