Nebula-simulator / Nebula

Nebula: Monte Carlo simulator of electron-matter interaction
BSD 3-Clause "New" or "Revised" License
19 stars 12 forks source link

cpu_edep #10

Open khalkhal91 opened 1 week ago

khalkhal91 commented 1 week ago

Can you please provide any scripts for reading deposit-filename calculated by nebula_cpu_edep?

lvkessel commented 1 day ago

Yes! Please note that this code isn't always practical. If an electron loses energy, that energy loss is recorded. However, if a secondary electron is created, the energy that the SE gets is not subtracted from this. So if you sum up all of the "deposited energy", the result will in general be much bigger than the total amount of energy you put into the simulation.

That said, it's a chunk of binary data, just like the "regular" output, but now each entry represents an event where an electron lost energy (instead of each entry representing an electron being detected). It has the following format:

  1. (x, y, z) position, in nm, as 32-bit floats
  2. Energy the electron had before the scattering event, as 32-bit float
  3. Energy the electron lost in the event (before minus after), as 32-bit float
  4. The primary electron pixel tags, two 32-bit integers.

If you read the data with python, you can use the following:

import numpy as np

dtype = np.dtype([
    ('x',  '=f'), ('y',  '=f'), ('z',  '=f'),
    ('E',  '=f'), ('dE',  '=f'),
    ('px', '=i'), ('py', '=i')])

data = np.fromfile(filename, dtype=dtype)

Then data will be an array with length equal to the number of scattering events that took place in the simulation. If you want to make a picture of the interaction volume, you can make a histogram of all the x, y, and z coordinates.

khalkhal91 commented 21 hours ago

Thanks a lot! Am I right that if SE is created, it is also added to the output after the primary one (with energy not equal to the loss of primary's) and so on?