import numpy,math #1 ########################################################################################################################### class histo: ######################################### #1 ########################################################################################################################### #2 #################################################################################### def __init__(self): """ initialisation of variable """ self.nb_point=0 self.value={} self.bin=[] self.len=0 #2 #################################################################################### def init_dict(self,data): """ define 0 entry for each bin """ for bin,value in data.items(): self.bin.append('%f' % float(bin)) self.value['%f' % float(bin)]=0 self.len=len(data) #2 #################################################################################### def add(self,value): if self.nb_point==0: self.init_dict(value) self.nb_point+=1 for bin in self.bin: self.value[bin]+=float(value[bin]) #2 #################################################################################### def write(self,filename): ff=open(filename,'w') for i in range(0,self.len): ff.writelines(str(i)+'\t'+str(self.value[i])+'\n') #2 #################################################################################### def out(self): return self.value #2 #################################################################################### def charge_file(self,name,auto=1): """ read file and return a dict of type {bin:value} """ out={} for line in file(name): data=line.split() out['%f' % float(data[0])] = float(data[1]) if auto==1: self.add(out) return out #1 ########################################################################################################################### class Error_in_histo(histo): ######################################### #1 ########################################################################################################################### #2 #################################################################################### def __init__(self): """ initialisation of variable """ self.nb_point=0 self.sum={} self.sum_square={} self.quad_term={} #2 #################################################################################### def init_dict(self,data): """ define 0 entry for each bin """ if isinstance(data,dict): data=data.keys() for bin in data: self.sum['%f' % float(bin)]=0 self.sum_square['%f' % float(bin)]=0 self.quad_term['%f' % float(bin)]={} list_bin2=[ bin2 for bin2 in data if float(bin2) nb_event_by_dir: break hist=histo() for k in range(cur_event, cur_event+step): hist.charge_file(init_pos+'/0%d_card_1event_%s.txt' % (cur_var, k)) stat_tool.update_value(hist.out()) cur_event += step stat_tool.compute_result() stat_tool.write_result('%s/mean_var_%s' % (output_dir, cur_var),'%s/error_var_%s' % (output_dir, cur_var),'%s/correlation_var_%s' % (output_dir, cur_var)) #1 ########################################################################################################################### class MW_chi_square: ######################################### #1 ########################################################################################################################### def __init__(self,total_event=380000): self.read_event=0 self.total_event=total_event def next_sample(self,N): step=numpy.random.poisson(N) if not self.read_event+step