icecube / pisa

Monte Carlo-based data analysis
http://icecube.github.io/pisa/
Apache License 2.0
19 stars 47 forks source link

Technical question #720

Closed rruizdeaustri closed 1 year ago

rruizdeaustri commented 1 year ago

Hi,

I'm trying to understand the code with some detail but I can't figure out how the

container['nu_flux']

which has dimensions (40000, 2) for all container as defined in barr_simple.py is then converted to a different dimensions which match with the MC data in "apply_function" of prob3.py ?

Maybe it just takes the true_energy and true_cz for each MC event and interpolates in the 200 x 200 grid containing the nominal values from stage flux barr_simple ?

Where the 200 x 200 is defined ?

Thanks a lot !!

Roberto

atrettin commented 1 year ago

A PISA container can show data in different representations. If you set container.representation = "events", then the dimension of container['nu_flux'] should be (number of events, 2). If the representation is set to a binning, then it shows the values for all bins in an "unrolled" array. Hence why the dimension is (40000, 2): There are 200 x 200 = 40000 bins, and two values in each bin. The binning is passed in the apply_mode argument. If a calculation happens in a binned representation, and you then request the "events" representation, the container will do an automatic translation where it looks up into which bin each MC event belongs, and assigns that event the value oft that bin.

rruizdeaustri commented 1 year ago

Ok, thanks !

Could you pls tell me what function does the translation ?

Rbt

atrettin commented 1 year ago

The translation is run in this function: https://github.com/icecube/pisa/blob/339b882d25b94e472d23c6d07317ced43470021f/pisa/core/container.py#L504

Note that this is an internal mechanism that is automatically called when data is accessed. For instance, if you set representation = 'events', nothing happens initially. Only when you actually retrieve the data for a variable, it will call __get_data, then auto_translate and then translate.

rruizdeaustri commented 1 year ago

Ok thanks.