I know there are different libraries such as Scofield or specialized softwares like CasaXPS, but I would like to know the step-by-step how these factors are calculated.
The link below will take you to C.D. Wagner's pioneering paper on "Sensitivity Factors for XPS Analysis of Surface Atoms". That should give you all the parameters needed to calculate sensitivity factors.
Relative sensitivity factors are sensitivity factors normalized against that of the carbon 1s orbital (e.g. C 1s is assigned a nominal RSF value of 1.000, and sensitivity factors for other orbitals expressed relative to that value).