r/esapi • • Sep 02 '26

Creating Verification Plan with FFF

Hey everyone, having issues strictly when source plans are using FFF beams. I keep getting an exception.

Documented mapping: energy 'EX', fluence 'FFF', MLC 'C419'. Error: Unable to cast object of type "VMS.TP5. Common.Model.AddOn' to type "VMS.TPS.Common.Model.PrimaryFluenceMode'.

Legacy mapping: energy '6X-FFF', fluence empty, MLC 'C419. Error: External beam configuration not found

Commissioned add-on mapping: energy '6X, fluence empty, MLC 'C419'. Error: Unable to cast object of type 'VMS.TPS. Common.Model.AddOn' to type "VMS.TPS.Common.Model.PrimaryFluenceMode'.

Has anyone dealt with this before? I'm on Eclipse 15.6 but we are upgrading to 18.1 in the next month or so

Thanks!

1 Upvotes

7 comments sorted by

3

u/dicomdom Sep 02 '26

This sounds more like a RT Admin configuration issue than ESAPI. Have you tried running the same process manually in the GUI to see if you get a more descriptive error?

1

u/branstarkkk Sep 02 '26

When trying to create verification plans manually, i don't seem to have an issue. It's just when the script runs.

2

u/dicomdom Sep 02 '26

Are the plans the FFF energy or are you trying to change it via ESAPI? Also can you post the code snippet

1

u/branstarkkk Sep 02 '26

The source plan already has 6X-FFF beams, here is the code snippet:

// ESAPI 15.6
 
IList<ControlPoint> controlPoints =
    sourceBeam.ControlPoints.ToList();
 
ControlPoint first = controlPoints.First();
ControlPoint last = controlPoints.Last();
 
IEnumerable<double> metersetWeights =
    controlPoints.Select(cp => cp.MetersetWeight).ToList();
 
// Suspected trigger:
ExternalPlanSetup qaPlan =
    qaCourse.AddExternalPlanSetupAsVerificationPlan(
        qaStructureSet,
        sourcePlan);
 
// Convert "6X-FFF" into energy="6X", fluence="FFF".
string displayName = sourceBeam.EnergyModeDisplayName.Trim();
int separator = displayName.IndexOf('-');
 
string energyModeId = separator > 0
    ? displayName.Substring(0, separator)
    : displayName;
 
string fluenceModeId = separator > 0
    ? displayName.Substring(separator + 1)
    : string.Empty;
 
// For our source beam this contains:
// machine = REDTB
// energy = 6X
// dose rate = 1400
// technique = ARC
// fluence mode = FFF
ExternalBeamMachineParameters machineParameters =
    new ExternalBeamMachineParameters(
        sourceBeam.TreatmentUnit.Id,
        energyModeId,
        sourceBeam.DoseRate,
        sourceBeam.Technique.Id,
        fluenceModeId);
 
Beam copiedBeam = qaPlan.AddVMATBeam(
    machineParameters,
    metersetWeights,
    first.CollimatorAngle,
    first.GantryAngle,
    last.GantryAngle,
    sourceBeam.GantryDirection,
    0.0,                       // QA couch angle
    qaIsocenter);
 
string sourceMlc = sourceBeam.MLC == null
    ? "<none>"
    : sourceBeam.MLC.Id;
 
string copiedMlc = copiedBeam.MLC == null
    ? "<none>"
    : copiedBeam.MLC.Id;
 
MessageBox.Show(string.Format(
    "Requested:\n" +
    "Machine={0}, Energy={1}, DoseRate={2}, Technique={3}, MLC={4}\n\n" +
    "Created:\n" +
    "Machine={5}, Energy={6}, DoseRate={7}, Technique={8}, MLC={9}",
    sourceBeam.TreatmentUnit.Id,
    sourceBeam.EnergyModeDisplayName,
    sourceBeam.DoseRate,
    sourceBeam.Technique.Id,
    sourceMlc,
    copiedBeam.TreatmentUnit.Id,
    copiedBeam.EnergyModeDisplayName,
    copiedBeam.DoseRate,
    copiedBeam.Technique.Id,
    copiedMlc));

1

u/dicomdom Sep 03 '26

Try this.

if (sourceBeam.MLCPlanType != MLCPlanType.VMAT) throw new InvalidOperationException("not a VMAT beam");
if (sourceBeam.GantryDirection == GantryDirection.None) throw new InvalidOperationException("no arc direction");

// Snapshot everything from the source before any write.
var srcCps  = sourceBeam.ControlPoints.ToList();
var weights = srcCps.Select(cp => cp.MetersetWeight).ToArray();
var leaves  = srcCps.Select(cp => cp.LeafPositions).ToArray();
var jaws    = srcCps.Select(cp => cp.JawPositions).ToArray();
var gantry  = srcCps.Select(cp => cp.GantryAngle).ToArray();

double collAngle   = srcCps.First().CollimatorAngle;
double gantryStart = srcCps.First().GantryAngle;
double gantryStop  = srcCps.Last().GantryAngle;
var    gantryDir   = sourceBeam.GantryDirection;

string machineId   = sourceBeam.TreatmentUnit.Id;
int    doseRate    = sourceBeam.DoseRate;
string techniqueId = sourceBeam.Technique.Id;

string display = sourceBeam.EnergyModeDisplayName.Trim();
int sep = display.IndexOf('-');
string energyModeId  = sep > 0 ? display.Substring(0, sep) : display;
string fluenceModeId = sep > 0 ? display.Substring(sep + 1) : string.Empty;   // empty string is valid

// AddVMATBeam requires [0, 360[
foreach (double a in gantry.Concat(new[] { collAngle }))
    if (a < 0.0 || a >= 360.0) throw new InvalidOperationException("angle outside [0,360[: " + a);

// ---- writes ----
ExternalPlanSetup qaPlan = qaCourse.AddExternalPlanSetupAsVerificationPlan(qaStructureSet, sourcePlan);

var mp = new ExternalBeamMachineParameters(machineId, energyModeId, doseRate, techniqueId, fluenceModeId);

Beam copiedBeam = qaPlan.AddVMATBeam(
    mp, weights, collAngle, gantryStart, gantryStop, gantryDir, 0.0, qaIsocenter);

// AddVMATBeam created control points but no aperture and no intermediate gantry angles.
BeamParameters bp = copiedBeam.GetEditableParameters();
var cps = bp.ControlPoints.ToArray();
if (cps.Length != srcCps.Count) throw new InvalidOperationException("control point count mismatch");

for (int i = 0; i < cps.Length; i++)
{
    cps[i].LeafPositions = leaves[i];
    cps[i].JawPositions  = jaws[i];
    cps[i].GantryAngle   = gantry[i];
}

copiedBeam.ApplyParameters(bp);   // throws ApplicationException on an invalid combination

For the diagnostic, drop the MLC ID comparison and check something that can actually fail — e.g. copiedBeam.ControlPoints.First().LeafPositions[0, 0] against the source, before and after ApplyParameters.

2

u/steller03 Sep 12 '26

We have this issue as well. I’ve spent plenty of time trying to solve it. As far as I can tell in v16, this is not solvable via ESAPI. Not sure about v18.

If it’s helpful, it seems like it’s a derivative problem from 6X and 6X-FFF being the same nominal energy in RT admin. 6X-FFF is just 6X in FFF fluence mode.

It seems like the energy definition is catching the first 6X beam definition, which is 6X. I’m curious if anyone has found a solution.

1

u/branstarkkk Sep 14 '26

i think it may still be an issue in 18.1, my thinking was it is a dose rate issue. where if there is two default dose rates 6X and 6X-FFF then it keeps the 6X default instead of the dose rate in the plan.