I have a python list which I use for storeing histograms. Each histogram is itself a list with n entries corresponding to the bins of the histogram. Each bin itself is again a list of three numbers and two list:
histograms = [ h1, h2 , h3, ... ],
h1 = [ "name", [ bin_0, bin_1, ..., bin_n ]],
bin_i = [ num_1, num_2, num_2, [ likelihood_sig ], [ likelihood_bkg ] ],
likelihood_x = [ bin_x_0 , ... , bin_x_10 ],
where bin_i/x
and num_i
are floats. In my code I scan over a data file and fill the histograms. Finding the right bins and filling the num_i
's works. However, filling the bin_x
's doesn't. Whatever I write into likelihood_sig
is automatically (feels like magic to me :P) written into likelihood_bkg
, too and vice versa.
Here is the part of the code where I fill the data into the list-structure (there are a lot of print statements as I tried to figure out whats going wrong...):
# 1d histograms
for histogram in self._histograms_1d:
# definition is a string with the name of the histogram
definition = histogram[0].strip().split()
# particles is a list of a list with four floats
# particles = [ p1, p2, ... ] , p1 = [ x0, x1, x2, x3 ]
actual_bin = self.which_bin_1d(particles,definition)
# add the data (dsig_s,dsig_b) to the correct bin (works)
histogram[1][actual_bin][1] = histogram[1][actual_bin][1] + dsig_s
histogram[1][actual_bin][2] = histogram[1][actual_bin][2] + dsig_b
# dq_bin = int ( log ( 1 + dsig_s/dsig_b) // binning_size (=0.5) ) ... works
# add data to likelihood (doesn't work ... )
my_debug_temp2 = histogram[1][actual_bin][4][dq_bin]
my_debug_temp1 = histogram[1][actual_bin][3][dq_bin] + dsig_s
histogram[1][actual_bin][3][dq_bin] = my_debug_temp1
histogram[1][actual_bin][4][dq_bin] = my_debug_temp2
my_debug_temp1 = histogram[1][actual_bin][3][dq_bin]
my_debug_temp2 = histogram[1][actual_bin][4][dq_bin] + dsig_b
histogram[1][actual_bin][4][dq_bin] = my_debug_temp2
histogram[1][actual_bin][3][dq_bin] = my_debug_temp1
# in the following print statement I find histogram[1][actual_bin][4][dq_bin] = histogram[1][actual_bin][4][dq_bin] (??? independent of my_debug_temp2 and my_debug_temp1 !!)
print histogram[1][actual_bin][3]
print histogram[1][actual_bin][4]
Would be nice if somebody knows how to handle this or tell me if I mis-use some Python statements.
edit: cut down on print's
edit: init phase of the histograms
This is the part of the code where I define the histogram structure. Then in the above part the are filled. They are not used anywhere else.
#================================================================
# load cuts from cut file
def load_1d(self):
for line in open(self._histogram_1d_file):
if line.strip()[:1]!='#' and len(line.strip())>0:
#print line.strip()
words = line.strip().split()
nbins = int(words[1])
histogram = []
dq_vec = []
for i in range(0,self._num_dq_bins):
dq_vec.append(0.0)
for i in range(0,nbins):
bin_i=[0,0,0,dq_vec,dq_vec]
histogram.append(bin_i)
self._histograms_1d.append([line.strip(),histogram])
return True
#================================================================