Skip to content

Commit 85f2221

Browse files
committed
make error and warning message colored
1 parent c4c5686 commit 85f2221

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

PWGHF/D2H/Macros/compute_fraction_cutvar.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def main(config):
3838
hist_rawy_name = cfg["rawyields"]["histoname"]
3939
hist_rawy.append(infile_rawy.Get(hist_rawy_name))
4040
if not isinstance(hist_rawy[-1], ROOT.TH1):
41-
sys.exit(f"Fatal error: Histogram with raw yield \"{hist_rawy_name}\" is absent. Exit.")
41+
sys.exit(f"\33[31mFatal error: Histogram with raw yield \"{hist_rawy_name}\" is absent. Exit.\33[0m")
4242
hist_rawy[-1].SetDirectory(0)
4343
infile_rawy.Close()
4444

@@ -48,18 +48,18 @@ def main(config):
4848
hist_effp.append(infile_eff.Get(hist_effp_name))
4949
hist_effnp.append(infile_eff.Get(hist_effnp_name))
5050
if not isinstance(hist_effp[-1], ROOT.TH1):
51-
sys.exit(f"Fatal error: Histogram with efficiency for prompt \"{hist_effp_name}\" is absent. Exit.")
51+
sys.exit(f"\33[31mFatal error: Histogram with efficiency for prompt \"{hist_effp_name}\" is absent. Exit.\33[0m")
5252
if not isinstance(hist_effnp[-1], ROOT.TH1):
53-
sys.exit(f"Fatal error: Histogram with efficiency for nonprompt \"{hist_effnp}\" is absent. Exit.")
53+
sys.exit(f"\33[31mFatal error: Histogram with efficiency for nonprompt \"{hist_effnp}\" is absent. Exit.\33[0m")
5454
hist_effp[-1].SetDirectory(0)
5555
hist_effnp[-1].SetDirectory(0)
5656
infile_eff.Close()
5757

5858
pt_bin_to_process = cfg.get("pt_bin_to_process", -1)
5959
if not isinstance(pt_bin_to_process, int):
60-
sys.exit("Fatal error: pt_bin_to_process must be an integer value. Exit.")
60+
sys.exit("\33[31mFatal error: pt_bin_to_process must be an integer value. Exit.")
6161
if (pt_bin_to_process != -1 and pt_bin_to_process < 1) or pt_bin_to_process > hist_rawy[0].GetNbinsX():
62-
sys.exit("Fatal error: pt_bin_to_process must be a positive value up to number of bins in raw yield histogram. Exit.")
62+
sys.exit("\33[31mFatal error: pt_bin_to_process must be a positive value up to number of bins in raw yield histogram. Exit.")
6363

6464
is_draw_title_rawy = cfg.get("is_draw_title", {}).get("rawy", True)
6565
is_draw_title_eff = cfg.get("is_draw_title", {}).get("eff", False)
@@ -73,11 +73,11 @@ def main(config):
7373
hist_central_effp_name = cfg["central_efficiency"]["histonames"]["prompt"]
7474
hist_central_effp = infile_central_eff.Get(hist_central_effp_name)
7575
if not isinstance(hist_central_effp[-1], ROOT.TH1):
76-
sys.exit(f"Fatal error: Histogram with central efficiency for prompt \"{hist_central_effp_name}\" is absent. Exit.")
76+
sys.exit(f"\33[31mFatal error: Histogram with central efficiency for prompt \"{hist_central_effp_name}\" is absent. Exit.\33[0m")
7777
hist_central_effnp_name = cfg["central_efficiency"]["histonames"]["nonprompt"]
7878
hist_central_effnp = infile_central_eff.Get(hist_central_effnp_name)
7979
if not isinstance(hist_central_effnp[-1], ROOT.TH1):
80-
sys.exit(f"Fatal error: Histogram with central efficiency for nonprompt \"{hist_central_effnp_name}\" is absent. Exit.")
80+
sys.exit(f"\33[31mFatal error: Histogram with central efficiency for nonprompt \"{hist_central_effnp_name}\" is absent. Exit.\33[0m")
8181
hist_central_effp.SetDirectory(0)
8282
hist_central_effnp.SetDirectory(0)
8383
infile_central_eff.Close()
@@ -177,10 +177,10 @@ def main(config):
177177

178178
if cfg["minimisation"]["correlated"]:
179179
if not (np.all(rawy[1:] > rawy[:-1]) or np.all(rawy[1:] < rawy[:-1])):
180-
print("WARNING! main(): the raw yield vector is not monotonous. Check the input for stability.")
180+
print("\0\33[33mWARNING! main(): the raw yield vector is not monotonous. Check the input for stability.\0\33[0m")
181181
print(f"raw yield vector elements = {rawy}\n")
182182
if not (np.all(unc_rawy[1:] > unc_rawy[:-1]) or np.all(unc_rawy[1:] < unc_rawy[:-1])):
183-
print("WARNING! main(): the raw yield uncertainties vector is not monotonous. Check the input for stability.")
183+
print("\0\33[33mWARNING! main(): the raw yield uncertainties vector is not monotonous. Check the input for stability.\0\33[0m")
184184
print(f"raw yield uncertainties vector elements = {unc_rawy}\n")
185185

186186
minimiser = CutVarMinimiser(rawy, effp, effnp, unc_rawy, unc_effp, unc_effnp)

PWGHF/D2H/Macros/cut_variation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ def __check_input_consistency(self):
7979
"""
8080

8181
if len(self.eff_prompt) != self.n_sets or len(self.eff_nonprompt) != self.n_sets:
82-
print("ERROR: number of raw yields and efficiencies not consistent! Exit")
82+
print("33[31mERROR: number of raw yields and efficiencies not consistent! Exit\033[0m")
8383
sys.exit()
8484

8585
if len(self.unc_raw_yields) != self.n_sets:
86-
print("ERROR: number of raw yields and raw-yield uncertainties not consistent! Exit")
86+
print("33[31mERROR: number of raw yields and raw-yield uncertainties not consistent! Exit\033[0m")
8787
sys.exit()
8888

8989
if len(self.unc_eff_prompt) != self.n_sets or len(self.unc_eff_nonprompt) != self.n_sets:
90-
print("ERROR: number of raw yields and efficiency uncertainties not consistent! Exit")
90+
print("33[31mERROR: number of raw yields and efficiency uncertainties not consistent! Exit\033[0m")
9191
sys.exit()
9292

9393
def __initialise_objects(self):
@@ -199,7 +199,7 @@ def minimise_system(self, correlated=True, precision=1.0e-8, max_iterations=100)
199199
if correlated:
200200
m_cov_sets_diag = np.diag(self.m_cov_sets)
201201
if not (np.all(m_cov_sets_diag[1:] > m_cov_sets_diag[:-1]) or np.all(m_cov_sets_diag[1:] < m_cov_sets_diag[:-1])):
202-
print("WARNING! minimise_system(): the residual vector uncertainties elements are not monotonous. Check the input for stability.")
202+
print("\033[33mWARNING! minimise_system(): the residual vector uncertainties elements are not monotonous. Check the input for stability.\033[0m")
203203
print(f"residual vector uncertainties elements = {np.sqrt(m_cov_sets_diag)}\n")
204204

205205
# chi2

0 commit comments

Comments
 (0)