# Odd EnergyFilter behaviour

**URL:** <https://openmc.discourse.group/t/odd-energyfilter-behaviour/1266>\
**Category:** User Support\
**Created:** [June 23, 2021, 5:16pm UTC](https://openmc.discourse.group/t/odd-energyfilter-behaviour/1266 "2021-06-23T17:16:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sourena](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/sourena/32/1249_2.png) [@sourena](https://openmc.discourse.group/u/sourena)\
**Post date:** [June 23, 2021, 5:16pm UTC](https://openmc.discourse.group/t/odd-energyfilter-behaviour/1266/1 "2021-06-23T17:16:40Z")

</div>

I’ve noticed the following odd behaviour when plotting energy spectra using defined energy grids (or I am fundamentally misunderstanding this filter). I will demonstrate with the [pincell example](https://docs.openmc.org/en/stable/examples/pincell.html):

```auto
tallies = openmc.Tallies()

#create two sets of energy tallies: 
#one set with uniform log energy grids with np.logspace and 
#the second set with pre-defined grids

#evenly-spaced grids
num_groups = [75, 150, 300, 600, 1200]
for n in num_groups:
    groups = np.logspace(-5, log10(20e6), n)
    tally = openmc.Tally(name=str(n))
    tally.scores = ['flux']
    efil_in = openmc.EnergyFilter(groups)
    tally.filters = [efil_in]
    tallies.append(tally)

#pre-defined grids
scale_energy_grid = [1.000E-5, 1.000E-4, ... 1.733E+7, 2.000E+7] #shortened for easier viewing
grids = ['CASMO-70', 'XMAS-172', 'SCALE-238', 'SHEM-361', 'UKAEA-1102']

for grid in grids:
    if grid=='SCALE-238':
        groups = scale_energy_grid
    else:
        groups = openmc.mgxs.GROUP_STRUCTURES[grid]
    tally = openmc.Tally(name=grid)
    tally.scores = ['flux']
    efil_in = openmc.EnergyFilter(groups)
    tally.filters = [efil_in]
    tallies.append(tally)

tallies.export_to_xml()
openmc.run()

```

When plotting the results of all these EnergyFilter tallies we see fairly smooth results for the set of tallies using np.logspace, but wildly oscillating spectra from the set which used defined group structures:

 ![image](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/0/0ef42b5d3936177b3ded6f4a74e370a9f3010735.png)  
 ![image](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/6/68df9754712897da83ab8320cc5dac1893adb0ad.png)

Again I might be misunderstanding how the filter works, but some clarification would be much appreciated!

Thanks,

Sourena

---

<div class="post-metadata">

**Author:** ![Pranto](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/pranto/32/489_2.png) [@Pranto](https://openmc.discourse.group/u/Pranto)\
**Post date:** [June 23, 2021, 9:37pm UTC](https://openmc.discourse.group/t/odd-energyfilter-behaviour/1266/2 "2021-06-23T21:37:37Z")

</div>

@sourena Did you divide each flux value by its energy width?

```python
energies = openmc.mgxs.GROUP_STRUCTURES['XMAS-172']

ax.loglog(energies[:-1], mean_7/np.diff(energies), label='XMAS-172')

```

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [June 24, 2021, 8:07am UTC](https://openmc.discourse.group/t/odd-energyfilter-behaviour/1266/3 "2021-06-24T08:07:25Z")

</div>

@Pranto’s suggestion is right on. In fact, I recently put together a [Jupyter notebook showing how to tally and plot a flux spectrum](https://nbviewer.jupyter.org/github/openmc-dev/openmc-notebooks/blob/main/flux-spectrum.ipynb) and this is mentioned (the need to divide by energy bin width).

---

<div class="post-metadata">

**Author:** ![sourena](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/sourena/32/1249_2.png) [@sourena](https://openmc.discourse.group/u/sourena)\
**Post date:** [June 25, 2021, 6:54am UTC](https://openmc.discourse.group/t/odd-energyfilter-behaviour/1266/4 "2021-06-25T06:54:39Z")

</div>

Thank you both, you are absolutely correct. The plots shown above were a straight flux plot, and were from a simplified version of the model in which the odd spectra were originally encountered. I revisited the original model after seeing your notes and the energy width calculation was being performed incorrectly. Thank you again for your help.

---

<div class="post-metadata">

**Author:** ![rezack](https://avatars.discourse-cdn.com/v4/letter/r/2acd7d/32.png) [@rezack](https://openmc.discourse.group/u/rezack)\
**Post date:** [January 22, 2025, 7:22pm UTC](https://openmc.discourse.group/t/odd-energyfilter-behaviour/1266/5 "2025-01-22T19:22:30Z")

</div>

I am a new user of OpenMC. Very nice job, and thanks to all creators!

I did my first simulations. However, I have some misunderstandings with the interpretation of data. My question was: When using an Energy filter with non-equidistant bin size, what quantity do OpenMC scores, dN or dN/dE? Does the corresponding bin size divide data in each bin, i.e., the distribution is created? Or are data not divided by bin size, i.e., dN is scored?

However, after reading this thread and [Jupyter Notebook Viewer](https://nbviewer.org/github/openmc-dev/openmc-notebooks/blob/main/flux-spectrum.ipynb)  
I think that I know the answer - only dN is scored. Please, am I right?

---

<div class="post-metadata">

**Author:** ![Shimwell](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/shimwell/32/3876_2.png) [@Shimwell](https://openmc.discourse.group/u/Shimwell)\
**Post date:** [January 22, 2025, 7:26pm UTC](https://openmc.discourse.group/t/odd-energyfilter-behaviour/1266/6 "2025-01-22T19:26:02Z")

</div>

Yes number of scores in each bin dN

Not bin density dN/dE

Perhaps related, we do have some methods on the [EnergyFilter](https://docs.openmc.org/en/stable/pythonapi/generated/openmc.EnergyFilter.html) like `.lethargy_bin_width` if you want to do some lethargy plotting and need to divide by the bin width. Example [here](https://github.com/fusion-energy/neutronics-workshop/blob/main/tasks/task_07_CSG_cell_tally_spectra/3_example_neutron_spectra_on_surface.ipynb)

---

<div class="post-metadata">

**Author:** ![rezack](https://avatars.discourse-cdn.com/v4/letter/r/2acd7d/32.png) [@rezack](https://openmc.discourse.group/u/rezack)\
**Post date:** [January 22, 2025, 7:42pm UTC](https://openmc.discourse.group/t/odd-energyfilter-behaviour/1266/7 "2025-01-22T19:42:59Z")

</div>

Thank you so much for the answer!

My best regards,  
Karel
