Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ venv/
ENV/
env.bak/
venv.bak/
# For IntelliJIDEA folder that is made once you open the directory in that editory
.idea/


# Prerequisites
*.d
Expand Down
9 changes: 5 additions & 4 deletions python/do_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

import ROOT # type: ignore

from utils import random_string
from utils import random_string, boolean_of


ROOT.gROOT.SetBatch(True)
ROOT.gStyle.SetOptStat(0)
Expand Down Expand Up @@ -526,9 +527,9 @@ def runPlotsHistmaker(config: dict[str, Any],
xmax = hist_cfg['xmax'] if 'xmax' in hist_cfg else -1
ymin = hist_cfg['ymin'] if 'ymin' in hist_cfg else -1
ymax = hist_cfg['ymax'] if 'ymax' in hist_cfg else -1
stack = hist_cfg['stack'] if 'stack' in hist_cfg else False
logx = hist_cfg['logx'] if 'logx' in hist_cfg else False
logy = hist_cfg['logy'] if 'logy' in hist_cfg else False
stack = boolean_of(hist_cfg['stack'],"histogram stack") if 'stack' in hist_cfg else False
logx = boolean_of(hist_cfg['logx'], hist_cfg['xtitle']) if 'logx' in hist_cfg else False
logy = boolean_of(hist_cfg['logy'], hist_cfg['ytitle']) if 'logy' in hist_cfg else False
extralab = hist_cfg['extralab'] if 'extralab' in hist_cfg else ""

intLumi = f'L = {param.intLumi / 1e+06:.0f} ab^{{-1}}'
Expand Down
25 changes: 25 additions & 0 deletions python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,28 @@ def random_string(length: int = 8):
'''
return ''.join(random.choices(string.ascii_letters + string.digits,
k=length))

def boolean_of(inputStatement, context: str) -> bool | None:
"""
given an string checks in true and false statements dictionary
to see if the user wants True or False.

raises error if the string input cannot be considered a boolean!

@param input: the input of the user
@param context: the context of the boolean (used for giving better errors to the user for debugging.

@return boolean
"""
booleanDictionary = {
"falseStatements" : ["false", "f", "0", "no", "n"],
"trueStatements" : ["true", "t", "1","yes","y"]
}
statement = str(inputStatement)
if statement.lower() in booleanDictionary["falseStatements"]:
return False
elif statement.lower() in booleanDictionary["trueStatements"]:
return True
else:
LOGGER.warning(f"In {context} you provided {inputStatement} which cannot be considered a boolean in our source-code please use: False : {booleanDictionary['falseStatements']} and True: {booleanDictionary['trueStatements']}.")
return None
1 change: 1 addition & 0 deletions python/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ import logging
LOGGER: logging.Logger

def generate_graph(dframe, args, suffix: str | None = None) -> None: ...
def boolean_of(): ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types do no match