The degrees of freedom calculated to give chi2/dof is incorrect for chi2rz and chi2rphi, it should be nstub - 2 to match what is calculated in the track word.
The equation given by Chris is correct in the case of a 4-param KF fit. If a 5-param KF fit is being used, then the number of degrees of freedom for chi2rphi should be nstub-3.
The degrees of freedom calculated to give chi2/dof is incorrect for chi2rz and chi2rphi, it should be nstub - 2 to match what is calculated in the track word.
https://github.com/cms-L1TK/cmssw/blob/791c901f9706b28216598c23bff4370ecee020fc/L1Trigger/TrackFindingTracklet/test/L1TrackNtuplePlot.C#L1054