ATLAS Offline Software
Loading...
Searching...
No Matches
makeDcubeConfig.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
4
7
8import argparse, os, sys
9import subprocess
10from AthenaCommon.Logging import logging
11log = logging.getLogger( "makeDcubeConfig.py" )
12
13# Parsing arguments
14parser = argparse.ArgumentParser( description = "makeDcubeConfig.py options:" )
15parser.add_argument( "-i", "--inputFile", help="IDPVM input file", required=True )
16parser.add_argument( "-c", "--configName", help="Name of the output dcube xml config file", default="dcube_config.xml" )
17parser.add_argument( "-d", "--debug", help='set debug level printout', action='store_true', default=False )
18MyArgs = parser.parse_args()
19if MyArgs.debug : log.setLevel( logging.DEBUG )
20
21
22dcubeExe = os.getenv( "ATLAS_LOCAL_ROOT" )+"/dcube/current/DCubeClient/python/dcube.py"
23log.debug( f"Setting Dcube executable to {dcubeExe}" )
24if not os.path.exists( dcubeExe ):
25 log.error( f"Dcube executable {dcubeExe} not found. Exiting." )
26 sys.exit(1)
27
28
29dcubeCmd = [ dcubeExe, '-g',
30 '-c', 'tmp_'+MyArgs.configName,
31 '-r', MyArgs.inputFile, MyArgs.inputFile ]
32log.debug( "Running: "+(' '.join( dcubeCmd )) )
33subprocess.run( dcubeCmd, check=True )
34if not os.path.exists( 'tmp_'+MyArgs.configName ):
35 log.error( f"Temporary dcube config tmp_{MyArgs.configName} not found. Exiting." )
36 sys.exit(1)
37
38
39import xml.etree.ElementTree as ET
40treeXML = ET.parse( 'tmp_'+MyArgs.configName )
41rootXML = treeXML.getroot()
42
43
45for tdir in rootXML.iter("TDirectory"):
46 histList = tdir.findall("hist1D")
47 histList += tdir.findall("hist2D")
48 histList += tdir.findall("graph")
49
50 for hist in histList:
51
52 if "TH1" in hist.get("type"):
53 hist.set("plotopts", "norm;ratio") # for 1D plots
54 if "TH2" in hist.get("type"):
55 hist.set("plotopts", "norm;box") # for 1D plots
56 if hist.get("type") == "TProfile" or hist.get("type") == "TEfficiency":
57 hist.set("plotopts", "ratio") # for 1D TProfiles and TEfficiencies
58 if ( "2D" in hist.get("type") or
59 ( "TEfficiency" in hist.get("type") and "2D" in hist.get("name") ) ):
60 hist.set("plotopts", "box") # for 2D TProfile2Ds and TEff2Ds
61
62 if tdir.get("name") == "Multiplicities":
63 if "summary" in hist.get("name"):
64 hist.set("plotopts", "logy")
65 if tdir.get("name") == "Resolutions":
66 if ( "resolution" in hist.get("name") or
67 "resmean" in hist.get("name") or
68 "pullwidth" in hist.get("name") or
69 "pullmean" in hist.get("name") ):
70 hist.set("plotopts", "ratio") # just ratio for resol, no need for norm
71 if "_vs_" in hist.get("name") and hist.get("name").endswith("pt"):
72 hist.set("plotopts", "logx;ratio") # also logx for e.g. resol vs pt plots
73log.info( "Done editing Dcube XML config" )
74
75
76treeXML.write( MyArgs.configName, xml_declaration=True )
77log.info( f"New Dcube XML config written {MyArgs.configName}" )
78os.remove( 'tmp_'+MyArgs.configName ) # remove tmp config