Hi all,
I’m using pyroot to dynamically draw many histograms like this
self.partition = ('LBA', 'LBC', 'EBA', 'EBC')
self.gain = ('LGLG', 'LGHG', 'HGLG', 'HGHG')
self.sample = ('A', 'BC', 'D', 'E')
self.labels = ('RMS', 'pileup', 'sigma1', 'sigma2', 'R',
'RMS_difference', 'Sigma1_difference')
....
for part in self.partition:
for gain in self.gain:
for samp in self.sample:
for run in self.runs:
for label in self.labels:
if (label == 'RMS'):
name = "h_%s_Zero_RMS_NoiseIn_%s_%s_%s" % (part, gain, samp, run)
title = "Zero RMS Noise Cells In %s %s cell in %s" % (part, samp, gain)
key = "%s_%s_%s_%s_%s" % (part, samp, gain, run, label)
if (label == 'pileup'):
name = "h_%s_Zero_Pileup_NoiseIn_%s_%s_%s" % (part, gain, samp, run)
title = "Zero Pileup Noise Cells In %s %s cell in %s" % (part, samp, gain)
key = "%s_%s_%s_%s_%s" % (part, samp, gain, run, label)
....
self.histo_names.append(name)
self.histo_titles.append(title)
self.histo_keys.append(key)
# Initialize the histograms.
for i in range(len(self.histo_names)):
self.histo_names[i] = ROOT.TH2D(self.histo_names[i],
self.histo_titles[i], 64, .5, 64.5, 48, -.5, 47.5)
# Generate a dictionary for the histograms with the key
# generated above.
self.histograms = dict((x, y) for x, y in
zip(self.histo_keys, self.histo_names))
I then fill them like this
[code] def fill_histo(histo_id, data):
self.histograms[histo_id].SetBinContent(int(module), int(channel_1) + 1, data)
if (len(region.GetChannels(true)) == 2):
self.histograms[histo_id].SetBinContent(int(module), int(channel_2) + 1, data)
[/code]
and write them as
[code] # Write the histograms.
for i in range(len(self.histo_names)):
self.histo_names[i].GetXaxis().SetTitle('Module Number')
self.histo_names[i].GetYaxis().SetTitle('Channel Number')
if not (self.histo_names[i].GetEntries() == 0):
self.histo_names[i].Write()
[/code]
I attach the whole file, I’m particularly interested in the Sigma1_difference histos, all the others are fine but for these two I get the potential memory leak, because I try to set the bin content of the same histogram many times during a loop.