54 def write(self, tdirectory=None):
55 """Writes the figures of merit as a TNtuple.
59 tdirectory : ROOT.TDirectory, optional
60 The directory to which the TNtuple shall be written.
61 Defaults to the current directory.
65 if not self.figures_by_name:
66 get_logger().warning(f'Do not create Ntuple for empty ValidationFiguresOfMerit {name}')
69 title = self.title or name
70 contact = self.contact
72 description = self.description
75 figure_names = [root_save_name(key) for key in list(self.figures_by_name.keys())]
76 values = list(self.figures_by_name.values())
78 with root_cd(tdirectory) as tdirectory:
79 # Try to find the object first
80 tntuple = tdirectory.Get(name)
82 former_description = tntuple.GetAlias('Description')
83 former_check = tntuple.GetAlias('Check')
84 former_figure_names = []
87 for tleaf in tntuple.GetListOfLeaves():
88 former_figure_names.append(tleaf.GetName())
89 former_values.append(tleaf.GetValue())
91 # Append the description and check of this figure of merit to whatever is there
92 description = former_description + ' <br/>\n' + description
93 check = former_check + ' <br/>\n' + check
95 figure_names = former_figure_names + figure_names
96 values = former_values + values
98 # Need both delete and overwrite to get rid of the former object.
99 tdirectory.Delete(name)
100 write_option = ROOT.TObject.kOverwrite
105 leaf_specification = ':'.join(figure_names)
106 tntuple = ROOT.TNtuple(name, title, leaf_specification)
108 array_of_values = array.array('f', values)
109 tntuple.Fill(array_of_values)
111 tntuple.SetAlias('Description', description)
112 tntuple.SetAlias('Check', check)
113 tntuple.SetAlias('Contact', contact)
115 # Overwrite the former TNtuple if one was there
116 tntuple.Write("", write_option)