C++ written module for dose distribution (DD) optimization based on data exchange with Theraplan Plus (TPP) is presented.An CT based radiotherapy treatment plan is prepared using the TPP system. Patient data (contours, densities) and beams geometry are exported to the TPP Export File. The compensators for each beam are designed using TPP Export File. The dose D n at n–th point is given by total primary dose: D n =∑ J W j •I jn •isq jn • exp(-μ(d r,jn -d r,max )), where J is the total number of beams, W j is the weight of the j-th beam, I jn is the relative energy fluence (REF) of jn-th pencil beam, isq is the inverse square factor, d r,jn , d r,max are radiological depths of n-th point and max dose respectively. The Probability of Uncomplicated Control (Pun) function is used as an objective function: Pun=TCP•II L (1v I •NCTP I ) where L is the number of critical organs in question, V I is the relative gravity of the injury. In the course of iteration the changes of REF values are performed sequentially for all beams. For one beam the value of Pun function for each ray is calculated separately and compared to the previous one. The new REF gives the max value of Pun. After the calculations for one beam are completed, the dose distribution for this beam is calculated with the new values of REF and process is continued for next beam until the objective function reaches its minimum.The program was tested for a number of real H&N cases with a U-shaped target, the spinal cord being the critical organ. It has been assumed that for an ideal DD the Pun values is 0.5. After optimization, the Pun values was never less than 0.46. Obtaining the optimal DD required usually 15 to 30 iterations and took about 5 minutes.Theraplan Plus is an ideal tool for the user who wishes to designe his own algorithms of the DD optimization. A rapid raytracing approach developed and implemented by the authors allows for an effective optimization of the DD.