Closed clelange closed 1 year ago
Hi @clelange, @anmalara,
This is my modified version of CMSStyle.py
with a solution for the dynamic placement and scaling of the usual CMS labels. I think you more or less need these for placing the CMS labels outside the frame:
H = pad.GetWh()*pad.GetHNDC()
W = pad.GetWw()*pad.GetWNDC()
l = pad.GetLeftMargin()
t = pad.GetTopMargin()
r = pad.GetRightMargin()
b = pad.GetBottomMargin()
e = 0.025
scale = float(H)/W if W>H else 1 # float(W)/H
[...]
if iPosX==0:
relPosX_ = relPosX_*(42*t*scale)*(cmsTextSize/0.84)
posX = l + relPosX_ #*(1-l-r)
posY = 1 - t + lumiTextOffset*t
Examples of output that shows the dynamic placement works: https://ineuteli.web.cern.ch/ineuteli/forCAT/CMSStyle/
It required some finetuning, and reverse engineering of ROOT's canvas coordinate system... You can test it yourself with these standalone scripts, which should reproduce the plots on my website above:
wget https://raw.githubusercontent.com/cms-tau-pog/TauFW/master/Plotter/python/plot/CMSStyle.py
wget https://raw.githubusercontent.com/cms-tau-pog/TauFW/master/Plotter/test/testCMSStyle.py
python3 testCMSStyle.py -v2
As mentioned in https://github.com/cms-cat/cms-root-style/issues/10, a possible alternative solution is getting the width of "CMS" with one of these methods: TLaTeX::GetBoundingBox
, TLaTeX::GetXsize
, but I never tried it...
Examples of output that shows the dynamic placement works: https://ineuteli.web.cern.ch/ineuteli/forCAT/CMSStyle/
I like these a lot. They already very closely match the style in mplhep
except having ticks on all sides https://cms-analysis.docs.cern.ch/guidelines/plotting/general/#cms-label-position
If we could sync on this, that would be great!
Yes, actually the ticks are missing on all sides are missing because of a bug that I fixed (pad.SetTicks(1,1)
). This was indeed default in the original TDR style. Lemme update the images.
As mentioned in #10, a possible alternative solution is getting the width of "CMS" with one of these methods:
TLaTeX::GetBoundingBox
,TLaTeX::GetXsize
, but I never tried it...
Btw, I could not get these methods to work... They all return 0 size... Not sure if I am missing something...
import ctypes
w, h = ctypes.c_uint(), ctypes.c_uint()
latex = TLatex()
...
latex.DrawLatex(...,"CMS")
latex.GetBoundingBox(w,h)
print(">>> latex.GetXsize()=%r, latex.GetBoundingBox()=%r"%(latex.GetXsize(),(w.value,h.value)))
Hi @clelange, @anmalara, This is my modified version of
CMSStyle.py
with a solution for the dynamic placement and scaling of the usual CMS labels. I think you more or less need these for placing the CMS labels outside the frame:H = pad.GetWh()*pad.GetHNDC() W = pad.GetWw()*pad.GetWNDC() l = pad.GetLeftMargin() t = pad.GetTopMargin() r = pad.GetRightMargin() b = pad.GetBottomMargin() e = 0.025 scale = float(H)/W if W>H else 1 # float(W)/H [...] if iPosX==0: relPosX_ = relPosX_*(42*t*scale)*(cmsTextSize/0.84) posX = l + relPosX_ #*(1-l-r) posY = 1 - t + lumiTextOffset*t
Examples of output that shows the dynamic placement works: https://ineuteli.web.cern.ch/ineuteli/forCAT/CMSStyle/
It required some finetuning, and reverse engineering of ROOT's canvas coordinate system... You can test it yourself with these standalone scripts, which should reproduce the plots on my website above:
wget https://raw.githubusercontent.com/cms-tau-pog/TauFW/master/Plotter/python/plot/CMSStyle.py wget https://raw.githubusercontent.com/cms-tau-pog/TauFW/master/Plotter/test/testCMSStyle.py python3 testCMSStyle.py -v2
@IzaakWN do you think you can create a Pull Request modifying the example/TDR script including your snippet?
Sorry @IzaakWN, any news on this?
Hi @ttedeschi, yes, I just discussed it with @anmalara, and he agreed to try it out.
Thanks, @IzaakWN for the tip. I've implemented it in https://github.com/cms-cat/cms-root-style/pull/15
@IzaakWN said he had a solution for this that would be great to try.