Outputs after generating a plan

Hello, after generating a plan, there’s a PlanPencil.txt file in the \openTPS_workspace\Simulations\MCsquare_simulation path. What exactly is that file?
I need to get the dose deposition matrix after generating a plan, but I can’t find it in the Outputs folder as it should be. Where can I get it?

Hi Nicolas,

The PlanPencil.txt file contains all the computed beamlets, along with their indices and coordinates.

Regarding the dose deposition matrix, you can directly save it in your Python script using the saveBeamlets function after the MCsquare computation. You can also find it directly in the openTPS_workspace/Simulations/MCsquare_simulation/Outputs/ folder, where the files Dose.mhd and Dose.raw are located. However, please note that these files need to be scaled with the proton charge, number of protons, and MUs.

I hope this clarifies things for you!

Best regards,
Eliot

Here are my files after generating a plan and performing dose computation. I don’t know what they are, and I can’t open the .bin file. Could you please explain it to me? I’d really appreciate it :slight_smile:

Here I have some code which uses the saveBeamlets function and generates a .blm file

# --- INICIO DEL CÓDIGO AÑADIDO ---
try:
    from opentps.core.io.serializedObjectIO import saveBeamlets

    ruta_de_guardado = 'C:/Users/chico/openTPS_workspace/Simulations/ddm_exportada_auto.blm'

    saveBeamlets(beamletDose, ruta_de_guardado)

    logger.info(f"DDM guardada automáticamente en: {ruta_de_guardado}")
except Exception as e:
    logger.error(f"Error al intentar guardar la DDM: {e}")
# --- FIN DEL CÓDIGO AÑADIDO ---

return beamletDose

And then I get the beamlets loaded into the array. I need to know if I’m on the right track to finding the DDM, and if so, how do I get it by ROI? For example, I need a DDM of the pelvis, a DDM of the tumor, etc.

If you can help me, I would really appreciate it!

Hello,

The Sparse_Dose.bin file is an output of MCsquare. If you are computing the beamlets, this is the binary file containing the beamlet matrix. However, please note that this file is overwritten each time you launch an MCsquare computation.

As for your beamlets, you saved them correctly!

What you are seeing is the sparse beamlet matrix (in CSC format). Since there are many zeros in the matrix, only the indices of the non-zero entries are stored. The beamlet matrix is also flattened, meaning the first dimension corresponds to 512 x 512 x 91 = 23,855,104 voxels, and the second dimension corresponds to 4,604 beamlets.

To extract the beamlet matrix for a specific ROI, you need a flattened ROI mask. Then, you can simply do:

DDM_ROI = BeamletMatrix[ROIMaskFlattened, :]

This will give you a matrix of dimensions (Nr x 4604), where Nr is the number of voxels in your ROI.

If you have any more questions, don’t hesitate to ask!

Best regards,
Eliot

Hi Eliot, thank you so much for replying. How can I use that piece of code you provided?

It mainly depends on what you aim to do with the DDM matrix, but since you’re already using the scripting window, you just need to import the ROI structure, flatten it using NumPy, and then apply the line above.
You can also save your DDM_ROI matrix in any format you prefer (you might consider using sparse matrices, depending on the dose distribution in your ROI) for further analysis or plotting.

I hope this makes more sense now.