matRad_writeMCsquareinputAllFiles

Purpose ^

generate input files for MCsquare dose calcualtion from matRad

Synopsis ^

function matRad_writeMCsquareinputAllFiles(filename,MCsquareConfig,stf)

Description ^

 generate input files for MCsquare dose calcualtion from matRad
 
 call
   matRad_writeMCsquareinputAllFiles(filename,MCsquareConfig,stf)

 input
   filename:       filename
   MCsquareConfig: matRad MCsquare configuration
   stf:            matRad steering information struct

 output
   -

 References
   [1] https://openreggui.org/git/open/REGGUI/blob/master/functions/io/convert_Plan_PBS.m

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 Copyright 2019 the matRad development team. 
 
 This file is part of the matRad project. It is subject to the license 
 terms in the LICENSE file found in the top-level directory of this 
 distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part 
 of the matRad project, including this file, may be copied, modified, 
 propagated, or distributed except according to the terms contained in the 
 LICENSE file.

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Cross-reference information ^

This function calls: This function is called by:

Subfunctions ^

Source code ^

0001 function matRad_writeMCsquareinputAllFiles(filename,MCsquareConfig,stf)
0002 % generate input files for MCsquare dose calcualtion from matRad
0003 %
0004 % call
0005 %   matRad_writeMCsquareinputAllFiles(filename,MCsquareConfig,stf)
0006 %
0007 % input
0008 %   filename:       filename
0009 %   MCsquareConfig: matRad MCsquare configuration
0010 %   stf:            matRad steering information struct
0011 %
0012 % output
0013 %   -
0014 %
0015 % References
0016 %   [1] https://openreggui.org/git/open/REGGUI/blob/master/functions/io/convert_Plan_PBS.m
0017 %
0018 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0019 %
0020 % Copyright 2019 the matRad development team.
0021 %
0022 % This file is part of the matRad project. It is subject to the license
0023 % terms in the LICENSE file found in the top-level directory of this
0024 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0025 % of the matRad project, including this file, may be copied, modified,
0026 % propagated, or distributed except according to the terms contained in the
0027 % LICENSE file.
0028 %
0029 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0030 
0031 
0032 %% write overall configuration file
0033 fileHandle = fopen(filename,'w');
0034 MCsquareConfig.write(fileHandle);
0035 fclose(fileHandle);
0036 
0037 %% prepare steering file writing
0038 numOfFields = length(stf);
0039 if MCsquareConfig.Beamlet_Mode
0040     totalMetersetWeightOfAllFields = 1;
0041 else
0042      totalMetersetWeightOfFields = NaN*ones(numOfFields,1);
0043      for i = 1:numOfFields
0044         totalMetersetWeightOfFields(i) = sum([stf(i).energyLayer.numOfPrimaries]);
0045     end
0046     totalMetersetWeightOfAllFields = sum(totalMetersetWeightOfFields);
0047 end
0048 
0049 %% write steering file
0050 
0051 fileHandle = fopen(MCsquareConfig.BDL_Plan_File,'w');
0052 
0053 fprintf(fileHandle,'#TREATMENT-PLAN-DESCRIPTION\n');
0054 fprintf(fileHandle,'#PlanName\n');
0055 fprintf(fileHandle,'matRad_bixel\n');
0056 fprintf(fileHandle,'#NumberOfFractions\n');
0057 fprintf(fileHandle,'1\n');
0058 fprintf(fileHandle,'##FractionID\n');
0059 fprintf(fileHandle,'1\n');
0060 fprintf(fileHandle,'##NumberOfFields\n');
0061 fprintf(fileHandle,[num2str(numOfFields) '\n']);
0062 for i = 1:numOfFields
0063     fprintf(fileHandle,'###FieldsID\n');
0064     fprintf(fileHandle,[num2str(i) '\n']);
0065 end
0066 fprintf(fileHandle,'\n#TotalMetersetWeightOfAllFields\n');
0067 fprintf(fileHandle,[num2str(totalMetersetWeightOfAllFields) '\n']);
0068     
0069 for i = 1:numOfFields
0070     fprintf(fileHandle,'\n#FIELD-DESCRIPTION\n');
0071     fprintf(fileHandle,'###FieldID\n');
0072     fprintf(fileHandle,[num2str(i) '\n']);
0073     fprintf(fileHandle,'###FinalCumulativeMeterSetWeight\n');
0074     if MCsquareConfig.Beamlet_Mode
0075         finalCumulativeMeterSetWeight = 1/numOfFields;
0076     else
0077         finalCumulativeMeterSetWeight = totalMetersetWeightOfFields(i);
0078     end
0079     fprintf(fileHandle,[num2str(finalCumulativeMeterSetWeight) '\n']);
0080     fprintf(fileHandle,'###GantryAngle\n');
0081     fprintf(fileHandle,[num2str(stf(i).gantryAngle) '\n']);
0082     fprintf(fileHandle,'###PatientSupportAngle\n');
0083     fprintf(fileHandle,[num2str(stf(i).couchAngle) '\n']);
0084     fprintf(fileHandle,'###IsocenterPosition\n');
0085     fprintf(fileHandle,[num2str(stf(i).isoCenter) '\n']);
0086     fprintf(fileHandle,'###NumberOfControlPoints\n');
0087     numOfEnergies = numel(stf(i).energies);
0088     fprintf(fileHandle,[num2str(numOfEnergies) '\n']);
0089 
0090     metersetOffset = 0;
0091     fprintf(fileHandle,'\n#SPOTS-DESCRIPTION\n');
0092     for j = 1:numOfEnergies
0093         fprintf(fileHandle,'####ControlPointIndex\n');
0094         fprintf(fileHandle,[num2str(j) '\n']);
0095         fprintf(fileHandle,'####SpotTunnedID\n');
0096         fprintf(fileHandle,['1\n']);
0097         fprintf(fileHandle,'####CumulativeMetersetWeight\n');
0098         if MCsquareConfig.Beamlet_Mode
0099             cumulativeMetersetWeight = j/numOfEnergies * 1/numOfFields;
0100         else 
0101             cumulativeMetersetWeight = metersetOffset + sum([stf(i).energyLayer(j).numOfPrimaries]);
0102             metersetOffset = cumulativeMetersetWeight;
0103         end
0104         fprintf(fileHandle,[num2str(cumulativeMetersetWeight) '\n']);
0105         fprintf(fileHandle,'####Energy (MeV)\n');
0106         fprintf(fileHandle,[num2str(stf(i).energies(j)) '\n']);
0107         fprintf(fileHandle,'####NbOfScannedSpots\n');
0108         numOfSpots = size(stf(i).energyLayer(j).targetPoints,1);
0109         fprintf(fileHandle,[num2str(numOfSpots) '\n']);
0110         fprintf(fileHandle,'####X Y Weight\n');
0111         for k = 1:numOfSpots
0112             if MCsquareConfig.Beamlet_Mode
0113                 n = stf(i).energyLayer(j).numOfPrimaries(k);
0114             else
0115                 n = stf(i).energyLayer(j).numOfPrimaries(k) / mcSquare_magicFudge(stf(i).energies(j));
0116             end
0117             fprintf(fileHandle,[num2str(stf(i).energyLayer(j).targetPoints(k,:)) ' ' num2str(n) '\n']);
0118         end
0119     end        
0120 end
0121 
0122 fclose(fileHandle);
0123 
0124 end
0125 
0126 function gain = mcSquare_magicFudge(energy)
0127 % mcSquare will scale the spot intensities in
0128 % https://gitlab.com/openmcsquare/MCsquare/blob/master/src/data_beam_model.c#L906
0129 % by this factor so we need to divide up front to make things work. The
0130 % original code can be found at https://gitlab.com/openmcsquare/MCsquare/blob/master/src/compute_beam_model.c#L16
0131 
0132 K = 35.87; % in eV (other value 34.23 ?)
0133 
0134 % // Air stopping power (fit ICRU) multiplied by air density
0135 SP = (9.6139e-9*energy^4 - 7.0508e-6*energy^3 + 2.0028e-3*energy^2 - 2.7615e-1*energy + 2.0082e1) * 1.20479E-3 * 1E6; % // in eV / cm
0136 
0137 % // Temp & Pressure correction
0138 PTP = 1.0; 
0139 
0140 % // MU calibration (1 MU = 3 nC/cm)
0141 % // 1cm de gap effectif
0142 C = 3.0E-9; % // in C / cm
0143 
0144 % // Gain: 1eV = 1.602176E-19 J
0145 gain = (C*K) / (SP*PTP*1.602176E-19);
0146 
0147 % divide by 1e7 to not get tiny numbers...
0148 gain = gain/1e7;
0149 
0150 end

| Generated by m2html © 2005