From 80d9cc40c9ba0bd0925022ceda22654b3e866ee7 Mon Sep 17 00:00:00 2001 From: Victor Schwan Date: Thu, 26 Sep 2024 10:55:08 +0900 Subject: [PATCH] outsource creation of 2D hists to function --- utils/material_plots_2D.py | 51 ++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/utils/material_plots_2D.py b/utils/material_plots_2D.py index d7dbe5183..a93b61906 100644 --- a/utils/material_plots_2D.py +++ b/utils/material_plots_2D.py @@ -19,6 +19,24 @@ from plotstyle import FCCStyle +def create_histogram( + name_and_title: str, argument_name_space: argparse.Namespace +) -> ROOT.TH2F: + return ROOT.TH2F( + name_and_title, + name_and_title, + int( + (argument_name_space.angleMax - argument_name_space.angleMin) + / argument_name_space.angleBinning + ), + argument_name_space.angleMin, + argument_name_space.angleMax, + argument_name_space.nPhiBins, + -math.pi, + math.pi, + ) + + def main(): parser = argparse.ArgumentParser(description="Material Plotter") parser.add_argument( @@ -87,36 +105,9 @@ def main(): ROOT.gROOT.SetBatch(1) - h_x0 = ROOT.TH2F( - "h_x0", - "h_x0", - int((args.angleMax - args.angleMin) / args.angleBinning), - args.angleMin, - args.angleMax, - args.nPhiBins, - -math.pi, - math.pi, - ) - h_lambda = ROOT.TH2F( - "h_lambda", - "h_lambda", - int((args.angleMax - args.angleMin) / args.angleBinning), - args.angleMin, - args.angleMax, - args.nPhiBins, - -math.pi, - math.pi, - ) - h_depth = ROOT.TH2F( - "h_depth", - "h_depth", - int((args.angleMax - args.angleMin) / args.angleBinning), - args.angleMin, - args.angleMax, - args.nPhiBins, - -math.pi, - math.pi, - ) + h_x0 = create_histogram("h_x0", args) + h_lambda = create_histogram("h_lambda", args) + h_depth = create_histogram("h_depth", args) for angleBinning, entry in enumerate(tree): nMat = entry.nMaterials