Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the way the style is forced in the cmsStyle to allow changing parameters #49

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/cmsstyle/cmsstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def SetExtraText(text):

def SetCmsTextFont(font):
"""
Function that allows to edit th default font of the
Function that allows to edit the default font of the
"CMS" string

Args:
Expand Down Expand Up @@ -119,7 +119,7 @@ def AppendAdditionalInfo(text):

def SetCmsTextSize(size):
"""
Function that allows to edit th default fontsize of the
Function that allows to edit the default fontsize of the
"CMS" string

Args:
Expand Down Expand Up @@ -351,13 +351,13 @@ def UpdatePad(pad=None):
rt.gPad.Update()


def setCMSStyle():
def setCMSStyle(force=rt.kTRUE):
global cmsStyle
if cmsStyle != None:
del cmsStyle
cmsStyle = rt.TStyle("cmsStyle", "Style for P-CMS")
rt.gROOT.SetStyle(cmsStyle.GetName())
rt.gROOT.ForceStyle()
rt.gROOT.ForceStyle(force)
# for the canvas:
cmsStyle.SetCanvasBorderMode(0)
cmsStyle.SetCanvasColor(rt.kWhite)
Expand Down Expand Up @@ -629,7 +629,7 @@ def cmsCanvas(
"""

# Set CMS style
setCMSStyle()
if cmsStyle is None: setCMSStyle()

# Set canvas dimensions and margins
W_ref = 600 if square else 800
Expand Down Expand Up @@ -965,7 +965,7 @@ def is_valid_hex_color(hex_color):
bool: True if the string is a valid hexadecimal color code, False otherwise.
"""
hex_color_pattern = re.compile(r'^#(?:[0-9a-fA-F]{3}){1,2}$')

return bool(hex_color_pattern.match(hex_color))


Expand All @@ -991,7 +991,7 @@ def cmsDrawStack(stack, legend, MC, data = None, palette = None, invertLegendEnt
print("Length of provided palette is smaller than the number of histograms to be drawn, wrap around is enabled")
else:
print("Invalid palette elements provided, default palette will be used")

if palette == None or is_user_palette_valid == False:
if len(MC.keys()) < 7:
palette_ = petroff_6
Expand All @@ -1013,7 +1013,7 @@ def cmsDrawStack(stack, legend, MC, data = None, palette = None, invertLegendEnt
if not invertLegendEntries:
legend.AddEntry(item[1], item[0], "f")
stack.Draw("HIST SAME")

if data != None:
cmsDraw(data, "P", mcolor=rt.kBlack)
legend.AddEntry(data, "Data", "lp")
Expand Down