diff --git a/Analyse/ana.py b/Analyse/ana.py new file mode 100644 index 0000000..2615c75 --- /dev/null +++ b/Analyse/ana.py @@ -0,0 +1,175 @@ +import os +import csv +import math +from ROOT import TH1D, TH2D, TCanvas, TGraph, TLine +from array import array + + +def RMS(arr): + square = 0 + mean = 0.0 + root = 0.0 + n=len(arr) + #Calculate square + for i in range(0,n): + square += (arr[i]**2) + + #Calculate Mean + mean = (square / (float)(n)) + + #Calculate Root + root = math.sqrt(mean) + + return root + +def mean(arr): + return sum(arr)/float(len(arr)) + +def correct_mean(arr, mean): + n=len(arr) + for i in xrange(0,n): + arr[i]=arr[i]-mean + return arr + +def integral(T,V): + sum=0. + n=len(T) + for i in range(1,n): + sum+= (T[i]-T[i-1])*(V[i]+V[i-1])/2. + + return sum + +class Reader: + def __init__(self, data): + self.data=data + + + def read(self,scope, temperature, sig): + print 'Reading the data from Scope: ', scope, "temprature: ", temperature, "Signal/noise: ", sig + data_file="data/" + if(scope == "TL"): + data_file+="lecroy_unpacked/" + # now reading data + dir,chan=self.get_dir(scope,temperature, sig) + if(len(dir)>1): + print 'WARNING, We have 2 entries for Scope: ', scope, "temprature: ", temperature, "Signal/noise: ", sig + + data_file+=dir[0] + print data_file + print chan + + + if(scope == "RS"): + for filename in os.listdir(data_file): + time=[] + V=[] + V_trig=[] + print filename + if(filename=="INDEX.CSV"): + continue + + with open(data_file+"/"+filename, 'r') as file: + + data_csv=csv.reader(file, delimiter=',') + first=True + for row in data_csv: + + if(first): + first=False + continue + time.append(float(row[0])*1.e6) + #print chan[0] + #print row + V_tmp=[] + for c in xrange(1,5): + if(c != chan[0]): + V_tmp.append(float(row[c])) + print 'Appendet channel ', c + V.append(V_tmp) + V_trig.append(float(row[chan[0]])) + ana=Analysis(time,V,V_trig) + f_out=filename + f_out=f_out.replace("CSV", "pdf") + int1,int2,int3=ana.ana(f_out) + + def get_dir(self,scope,temperature, sig): + ret=[] + t_chan=[] + for i in self.data: + if( (i["scope"]==scope) and (i["temperature"]>temperature-0.1 and i["temperature"]