ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper Class Reference
Inheritance diagram for LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper:
Collaboration diagram for LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper:

Public Member Functions

def __init__ (self, flags, algClassOrObj=None, name=None, *args, **kwargs)
 
def defineDQAlgorithm (self, name, hanConfig, thresholdConfig=None)
 
def defineHistogram (self, *args, fillGroup=None, hanConfig={}, paths=[], **kwargs)
 
def defineTree (self, *args, fillGroup=None, **kwargs)
 
def result (self)
 

Static Public Member Functions

def printHanConfig (filename="collisions_run.config")
 

Public Attributes

 helper
 
 alg
 
 fillGroups
 
 dqEnv
 

Static Public Attributes

 hanConfigs
 
 hanAlgConfigs
 
 hanThresholdConfigs
 
 SIGNATURES
 
 HELPURL
 

Detailed Description

This class is designed to handle registering all of L1Calo's monitoring histograms and trees in a
coherent way. It will also generate the han config file for all the histograms.

Definition at line 5 of file LVL1CaloMonitoringConfig.py.

Constructor & Destructor Documentation

◆ __init__()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.__init__ (   self,
  flags,
  algClassOrObj = None,
  name = None,
args,
**  kwargs 
)
Create the configuration helper.

Arguments:
flags -- the configuration flag object
algClassOrObj -- the name you want to assign the family of algorithms

Definition at line 103 of file LVL1CaloMonitoringConfig.py.

103  def __init__(self, flags, algClassOrObj = None, name = None, *args, **kwargs):
104  '''
105  Create the configuration helper.
106 
107  Arguments:
108  flags -- the configuration flag object
109  algClassOrObj -- the name you want to assign the family of algorithms
110  '''
111  from AthenaMonitoring import AthMonitorCfgHelper
112  self.helper = AthMonitorCfgHelper(flags,name)
113  self.alg = self.helper.addAlgorithm(algClassOrObj,name,*args, **kwargs) if algClassOrObj is not None else None
114  self.fillGroups = {}
115  self.dqEnv = flags.DQ.Environment # used to decide if should defineTree or not ...
116 

Member Function Documentation

◆ defineDQAlgorithm()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.defineDQAlgorithm (   self,
  name,
  hanConfig,
  thresholdConfig = None 
)
:param name: name of algorithm
:param hanConfig: dict of algo properties
:param thresholdConfig: dict of thresholds, keys in form of ParName.level
:return:

Definition at line 117 of file LVL1CaloMonitoringConfig.py.

117  def defineDQAlgorithm(self,name,hanConfig,thresholdConfig=None):
118 
119  """
120 
121  :param name: name of algorithm
122  :param hanConfig: dict of algo properties
123  :param thresholdConfig: dict of thresholds, keys in form of ParName.level
124  :return:
125  """
126 
127  # note: this method will replace any existing alg definition
128 
129  thresNum = len(self.hanThresholdConfigs)
130  if thresholdConfig is not None:
131  hanConfig["thresholds"] = f"L1CaloThreshold{thresNum}"
132  threshDict = {}
133  for parName,limVals in thresholdConfig.items():
134  if len(limVals) != 2:
135  raise Exception("must specify two limits: warning and error")
136  if parName not in threshDict: threshDict[parName] = {}
137  threshDict[parName]["warning"] = limVals[0]
138  threshDict[parName]["error"] = limVals[1]
139  # see if any existing thresholds are identical, if so we can reuse
140  for threshName,thresh in self.hanThresholdConfigs.items():
141  if str(thresh)==str(threshDict):
142  threshDict = None
143  hanConfig["thresholds"] = threshName
144  break
145  if threshDict is not None: self.hanThresholdConfigs[hanConfig["thresholds"]] = threshDict
146  self.hanAlgConfigs[name] = hanConfig
147 
148  return
149 
150 

◆ defineHistogram()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.defineHistogram (   self,
args,
  fillGroup = None,
  hanConfig = {},
  paths = [],
**  kwargs 
)
:param path:
:param fillGroup:
:param args:
:param kwargs:
:return:

Definition at line 151 of file LVL1CaloMonitoringConfig.py.

151  def defineHistogram(self,*args,fillGroup=None,hanConfig={},paths=[],**kwargs):
152  '''
153 
154  :param path:
155  :param fillGroup:
156  :param args:
157  :param kwargs:
158  :return:
159  '''
160 
161  if paths != []:
162  for path in paths:
163  # create a copy of the histogram in each of the extra locations
164  self.defineHistogram(*args,fillGroup=fillGroup,hanConfig=hanConfig,paths=[],path=path,**kwargs)
165  return None
166 
167  argsCopy = list(args) # need to convert tuple to list to convert it
168  if ";" not in args[0]:
169  argsCopy[0] += ";h_" + argsCopy[0].replace(":","_")
170 
171  if kwargs.get("path",None) is None:
172  # put in the Developer path, under the name of the algorithm
173  kwargs["path"] = "Developer/" + self.alg.name
174  elif kwargs["path"][-1] == '/':
175  kwargs["path"] = kwargs["path"][:-1] # strip trailing slash
176  # verify path obeys convention
177  splitPath = kwargs["path"].split("/")
178  if splitPath[0] not in ["Shifter","Expert","Developer"]:
179  raise Exception("Path of histogram invalid, does not start with one of the allowed audiences (Shifter,Expert,Developer)")
180 
181  # require a hanConfig not in Developer or a detail dir
182  if splitPath[0] != "Developer" and splitPath[-1] != "detail" and ("algorithm" not in hanConfig):
183  # will default to using GatherData as long as there is a description
184  if "description" not in hanConfig:
185  raise Exception("Must specify a hanConfig for a Shifter or Expert (non-detail) histogram")
186  else:
187  hanConfig["algorithm"] = "GatherData" # must have an algo, otherwise wont be valid han config
188 
189 
190  if fillGroup is None: fillGroup = self.alg.name + "_fillGroup"
191  if fillGroup not in self.fillGroups:
192  self.fillGroups[fillGroup] = self.helper.addGroup(self.alg,fillGroup,topPath="L1Calo")
193 
194  if "merge" not in kwargs and kwargs.get("type","") !="TEfficiency":
195  kwargs["merge"] = "merge" # ensures we don't get a warning about not specifying merge method
196  out = self.fillGroups[fillGroup].defineHistogram(*argsCopy,**kwargs)
197  histName = argsCopy[0].split(";")[-1]
198 
199  # add help link for all expert plots
200  if splitPath[0] == "Expert":
201  linkUrl = self.HELPURL + "#" + "".join(splitPath[1:]+[histName])
202  linkUrl = f"<a href=\"{linkUrl}\">Help</a>"
203  if "description" not in hanConfig: hanConfig["description"] = linkUrl
204  else: hanConfig["description"] += " - " + linkUrl
205 
206  splitPathWithHist = splitPath + [histName]
207  x = L1CaloMonitorCfgHelper.hanConfigs
208  for i,p in enumerate(splitPathWithHist):
209  key = ("dir " if i!=len(splitPathWithHist)-1 else "hist ") + p
210  if key not in x:
211  x[key] = {}
212  x = x[key]
213  hanConfig["output"] = "/".join(["L1Calo"]+splitPath)
214  x.update(hanConfig)
215 
216  return out
217 

◆ defineTree()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.defineTree (   self,
args,
  fillGroup = None,
**  kwargs 
)

Definition at line 218 of file LVL1CaloMonitoringConfig.py.

218  def defineTree(self,*args,fillGroup=None,**kwargs):
219 
220  if ";" not in args[0]:
221  raise Exception("Must specify a tree name using ';name' suffix")
222  treeName = args[0].split(";")[-1]
223 
224  if "," in args[1]: # catch a subtle typo that can screw up monitoring
225  raise Exception("Should not have comma in list of branch names and types")
226 
227  if kwargs.get("path",None) is None:
228  # put in the Developer path, under the name of the algorithm
229  kwargs["path"] = "Developer/" + self.alg.name
230 
231  # verify path obeys convention
232  splitPath = kwargs["path"].split("/")
233  if splitPath[0] not in ["Developer"]:
234  raise Exception("Path of tree invalid, must be in the audience=Developer directory")
235 
236 
237  if fillGroup is None: fillGroup = self.alg.name + "_fillGroup"
238  if fillGroup not in self.fillGroups:
239  self.fillGroups[fillGroup] = self.helper.addGroup(self.alg,fillGroup,topPath="L1Calo")
240 
241  # always define a histogram to go with the tree, which will indicate how many entries there are
242  # this also ensures we satisfy the requirement that every fillGroup has an object defined
243  # (in the cases of running online/tier0 the defineTrees are blocked, but we still need a hist then)
244  histName = "h_" + treeName + "_entries"
245  argsCopy = list(args)
246  argsCopy[0] = argsCopy[0].replace(";"+treeName,";"+histName)
247  kwargsCopy = dict(kwargs)
248  kwargsCopy["title"] = f"Number of Entries in {treeName} TTree" + ";" + ";".join(kwargsCopy.get("title","").split(";")[1:])
249  kwargsCopy["opt"] = ['kCanRebin']
250  kwargsCopy["merge"] = "merge"
251  is2d = (kwargsCopy["title"].count(";")>1)
252  self.defineHistogram(argsCopy[0],type="TH2I" if is2d else "TH1I",xbins=1,xmin=0,xmax=1,ybins=1 if is2d else None,ymin=0,ymax=1,fillGroup=fillGroup,**kwargsCopy)
253  if not any([x in self.dqEnv for x in ['tier0','online']]):
254  out = self.fillGroups[fillGroup].defineTree(*args,**kwargs)
255  else:
256  out = None
257  return out
258 

◆ printHanConfig()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.printHanConfig (   filename = "collisions_run.config")
static

Definition at line 23 of file LVL1CaloMonitoringConfig.py.

23  def printHanConfig(filename="collisions_run.config"):
24  from contextlib import redirect_stdout
25  with open(filename,'w') as f:
26  with redirect_stdout(f):
27  # Note: common configs (see common dir in DataQualityConfiguration) provides following algorithms by default:
28  # algorithm All_Bins_Filled
29  # algorithm Histogram_Effective_Empty
30  # algorithm Histogram_Empty
31  # algorithm Histogram_Not_Empty
32  # algorithm No_OverFlows
33  # algorithm No_UnderFlows
34 
35  outputs = set()
36  def printConf(d,prefix=""):
37  for key,value in d.items():
38  if type(value)==dict:
39  print(prefix,key,"{")
40  if(key=="dir detail" or key=="dir Developer"):
41  print(prefix+" algorithm = GatherData") # define GatherData as default algo for all of these hists
42  printConf(value,prefix + " ")
43  print(prefix,"}")
44  else:
45  print(prefix,key,"=",value)
46  # save all output paths to add to output block
47  if key == "output": outputs.add(value)
48 
49  print("#inputs")
50  print("dir L1Calo {")
51  printConf(L1CaloMonitorCfgHelper.hanConfigs," ")
52  print("}")
53  print("#outputs")
54  print("output top_level {")
55  def printOutputs(d,prefix=""):
56  for key,value in d.items():
57  if(key.startswith("hist ")):
58  pass # do nothing
59  elif type(value)==dict:
60  print(prefix,key.replace("dir ","output "),"{")
61  printOutputs(value,prefix + " ")
62  print(prefix,"}")
63  print(" output L1Calo {")
64  printOutputs(L1CaloMonitorCfgHelper.hanConfigs," ")
65  print(" }")
66  print("}")
67  # include example of adding algorithms and thresholds
68  print("""
69 #algorithms
70 algorithm AnyNonZeroBinIsError {
71  # Use this algo if want error on any non-zero bin content
72  libname = libdqm_summaries.so
73  name = Bins_NotEqual_Threshold
74  BinThreshold = 0.
75  thresholds = th_AnyBinIsError
76 }
77 """)
78  for algName,algProps in L1CaloMonitorCfgHelper.hanAlgConfigs.items():
79  print(f"algorithm {algName} {{")
80  for propName,propVal in algProps.items():
81  print(f" {propName} = {propVal}")
82  print(" }")
83  print("""
84 #thresholds
85 thresholds th_AnyBinIsError {
86  limits NBins {
87  warning = 0
88  error = 1
89  }
90 }
91 """)
92  for threshName,threshProps in L1CaloMonitorCfgHelper.hanThresholdConfigs.items():
93  print(f"thresholds {threshName} {{")
94  for parName,parLims in threshProps.items():
95  print(f" limits {parName} {{")
96  for limName,limVal in parLims.items():
97  print(f" {limName} = {limVal}")
98  print(" }")
99  print("}")
100 
101 
102 

◆ result()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.result (   self)

Definition at line 259 of file LVL1CaloMonitoringConfig.py.

259  def result(self):
260  return self.helper.result()
261 
262 

Member Data Documentation

◆ alg

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.alg

Definition at line 113 of file LVL1CaloMonitoringConfig.py.

◆ dqEnv

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.dqEnv

Definition at line 115 of file LVL1CaloMonitoringConfig.py.

◆ fillGroups

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.fillGroups

Definition at line 114 of file LVL1CaloMonitoringConfig.py.

◆ hanAlgConfigs

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.hanAlgConfigs
static

Definition at line 16 of file LVL1CaloMonitoringConfig.py.

◆ hanConfigs

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.hanConfigs
static

Definition at line 15 of file LVL1CaloMonitoringConfig.py.

◆ hanThresholdConfigs

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.hanThresholdConfigs
static

Definition at line 17 of file LVL1CaloMonitoringConfig.py.

◆ helper

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.helper

Definition at line 112 of file LVL1CaloMonitoringConfig.py.

◆ HELPURL

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.HELPURL
static

Definition at line 20 of file LVL1CaloMonitoringConfig.py.

◆ SIGNATURES

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.SIGNATURES
static

Definition at line 19 of file LVL1CaloMonitoringConfig.py.


The documentation for this class was generated from the following file:
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
get_generator_info.result
result
Definition: get_generator_info.py:21
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:224
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
LVL1CaloMonitoringConfig.type
type
Definition: LVL1CaloMonitoringConfig.py:437
GenericMonitoringTool.defineTree
def defineTree(flags, varname, treedef, path=None, title=None, opt='', convention=None, cutmask=None)
Generate tree definition string for the GenericMonitoringTool.Histograms property.
Definition: GenericMonitoringTool.py:491
GenericMonitoringTool.defineHistogram
def defineHistogram(flags, varname, type='TH1F', path=None, title=None, weight=None, xbins=100, xmin=0, xmax=1, xlabels=None, ybins=None, ymin=None, ymax=None, ylabels=None, zmin=None, zmax=None, zlabels=None, opt=None, convention=None, cutmask=None, treedef=None, merge=None)
Generate histogram definition string for the GenericMonitoringTool.Histograms property.
Definition: GenericMonitoringTool.py:306
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569
str
Definition: BTagTrackIpAccessor.cxx:11
Trk::split
@ split
Definition: LayerMaterialProperties.h:38