From 0b59886a8aa93c3189604ae24dd83e987e913f25 Mon Sep 17 00:00:00 2001 From: "armin.ilg" Date: Wed, 25 Sep 2024 08:41:28 +0200 Subject: [PATCH] Improving material_plots(_2D).py scripts to take list ofmaterial strings as input to be ignored and list of substrings in materials to be removed --- utils/material_plots.py | 15 +++++++++------ utils/material_plots_2D.py | 6 ++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/utils/material_plots.py b/utils/material_plots.py index d51413584..580746d22 100644 --- a/utils/material_plots.py +++ b/utils/material_plots.py @@ -14,7 +14,9 @@ def main(): parser.add_argument('--angleMax', dest='angleMax', default=6, type=float, help="maximum eta/theta/cosTheta") parser.add_argument('--angleDef', dest='angleDef', default="eta", type=str, help="angle definition to use: eta, theta, cosTheta or thetaRad, default: eta") parser.add_argument('--angleBinning', "-b", dest='angleBinning', default=0.05, type=float, help="eta/theta/cosTheta/thetaRad bin width") - parser.add_argument('--x0max', "-x", dest='x0max', default=0.0, type=float, help="Max of x0") + parser.add_argument('--x0max', "-x", dest='x0max', default=0.0, type=float, help="Max of x0") + parser.add_argument('--removeMatsSubstrings', dest='removeMatsSubstrings', nargs='+', default=[], help="Substrings to be removed from materials strings (e.g. '66D' for reduced density materials)") + parser.add_argument('--ignoreMats', "-i", dest='ignoreMats', nargs='+', default=[], help="List of materials that should be ignored") args = parser.parse_args() f = ROOT.TFile.Open(args.fname, "read") @@ -30,13 +32,14 @@ def main(): for i in range(nMat): material = entry.material.at(i) - # If you need to replace some string in the material, add that here - material = material.replace("66D","") - material = material.replace("Vtx","") + # Removing substrings from materials + for substring in args.removeMatsSubstrings: + material = material.replace(substring,"") - # Ignore materials used in beam pipe as vertex material budget does not work without beam pipe. You can add more materials to ignore here - if material in ["Air","Tungsten","Copper","beam","LiquidNDecane", "AlBeMet162", "Gold"]: + # Ignore certain materials if specified + if material in args.ignoreMats: continue + if material not in histDict.keys(): histDict[material] = { "x0": ROOT.TH1F("", "", (int)((args.angleMax-args.angleMin) / args.angleBinning), args.angleMin, args.angleMax), diff --git a/utils/material_plots_2D.py b/utils/material_plots_2D.py index 186971937..d87e549f5 100644 --- a/utils/material_plots_2D.py +++ b/utils/material_plots_2D.py @@ -17,6 +17,7 @@ def main(): parser.add_argument('--angleBinning', "-b", dest='angleBinning', default=0.05, type=float, help="eta/theta/cosTheta bin width") parser.add_argument('--nPhiBins', dest='nPhiBins', default=100, type=int, help="number of bins in phi") parser.add_argument('--x0max', "-x", dest='x0max', default=0.0, type=float, help="Max of x0") + parser.add_argument('--ignoreMats', "-i", dest='ignoreMats', nargs='+', default=[], help="List of materials that should be ignored") args = parser.parse_args() ROOT.gStyle.SetNumberContours(100) @@ -36,9 +37,10 @@ def main(): entry_x0, entry_lambda, entry_depth = 0.0, 0.0, 0.0 for i in range(nMat): - # Ignore materials used in beam pipe as vertex material budget does not work without beam pipe. You can add more materials to ignore here - if entry.material.at(i) in ["Air","Tungsten","Copper","beam","LiquidNDecane", "AlBeMet162", "Gold"]: + # Ignore certain materials if specified + if entry.material.at(i) in args.ignoreMats: continue + entry_x0 += entry.nX0.at(i)*100.0 entry_lambda += entry.nLambda.at(i) entry_depth += entry.matDepth.at(i)