Compare commits

...

2 commits

Author SHA1 Message Date
Ava
4f4e820102 ADD plot_dThist.py 2024-08-21 17:36:29 +02:00
Ava
828fe53e54 ADD timediffs to AHBGOx.py 2024-08-21 17:35:58 +02:00
2 changed files with 125 additions and 4 deletions

View file

@ -24,6 +24,8 @@ parser.add_argument("-export", type=str, nargs='+', help = "filpath to store out
parser.add_argument("-nameadd", type=str, nargs='+', help = "custom nameadd to add to filename")
parser.add_argument("-six", action='store_true', help = "use channels for 'AHBGOS'")
parser.add_argument("-ignoreT", action='store_true', help = "ignores temperature values")
parser.add_argument("-deltaT", action='store_true', help = "saves deltatimes between events")
parser.add_argument("-deltaTmuons", action='store_true', help = "saves deltatimes between muon events")
#parser.add_argument("-tdhist", action='store_true', help = "makes 2d histogramm of B1 against B2 if AHBGOC")
@ -60,6 +62,10 @@ elif 'AHBGOS' in file:
def main(x):
global thr
global ch
ch,name,thr,u = channels()
if args.Itime:
Itime = find_Itime()
fname = 'histograms/'+filename+ '.Itime'
@ -77,11 +83,37 @@ def main(x):
frame = pd.DataFrame({'time': time, 'T': temp})
frame.to_csv('histograms/'+filename+'.ntc', sep = ' ', index = False)
else:
global thr
global ch
ch,name,thr,u = channels()
elif args.deltaT:
dTh = np.zeros((1000000,2))
dTh[:, 0] = np.arange(1, 1000001)
with fileinput.input(files=(file), encoding="utf-8", errors='ignore') as f:
for line in f:
l = line.split()
if not 'EOF' in l and l[0] == 'EI':
dT = int(l[4].split(":")[0])
x = int(dT/3)
dTh[x, 1] += 1
frame = pd.DataFrame(dTh, columns = ["deltaT","count"])
frame.to_csv('histograms/'+filename+'.dThist', sep = ' ', index = False)
elif args.deltaTmuons:
dTh = np.zeros((10000000,2))
dTh[:, 0] = np.arange(1, 10000001)
with fileinput.input(files=(file), encoding="utf-8", errors='ignore') as f:
dT = 0
for line in f:
l = line.split()
if not 'EOF' in l and l[0] == 'EI':
dT += int(l[4].split(":")[0])
if isMuon(l):
x = int(dT/3)
dTh[x, 1] += 1
dT = 0
frame = pd.DataFrame(dTh, columns = ["deltaTmuons","count"])
frame.to_csv('histograms/'+filename+'_muons'+'.dThist', sep = ' ', index = False)
else:
if name[0] == None and verbosity>0:
print("no valid filename. Filename should contain 'AHBGOD' or 'AHBGOC'")
sys.exit()

89
plot_dThist.py Normal file
View file

@ -0,0 +1,89 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 21 13:33:03 2024
@author: ava
"""
import argparse
import sys
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import os.path
def main():
parser = argparse.ArgumentParser(description="This script plots histogramms of given data ending on '.hist'")
parser.add_argument("-v", "--verbose", choices = ['0','1','2'], help = "when zero only emit serious error messages; when one also emit warnings, when two emit informational messages")
parser.add_argument("filepath", type = str, help="path/file were data is stored in")
parser.add_argument("-t", "--title", type = str, help="title to use in plot; if not given a standard title will be chosen")
parser.add_argument("-e", "--export", type = str, nargs='+', help = "first: filepath were figure shall be exported to (if f, filepath of histdata will be chosen with filepath_plot) \n second:format (png,pdf,...)")
parser.add_argument("-l", "--limits", type=str, nargs='+',help = "limits of plot in order xmin,xmax, ymin,ymax,")
args = parser.parse_args()
if args.verbose == None:
verbosity = 1
else:
verbosity = args.verbose
if verbosity == 2:
sys.stderr.write("--verbostiy = '" + str(args.verbose)+"'\n")
sys.stderr.write("--filepath = '" + str(args.filepath)+"'\n")
sys.stderr.write("--title = '" + str(args.title)+"'\n")
sys.stderr.write("--export = '" + str(args.export) +"'\n")
sys.stderr.write("--limits = '" + str(args.limits) +"'\n")
sys.stderr.write("--dhist = '" + str(args.dhist) +"'\n")
file = args.filepath
if args.title == None:
tit = 'Histplot, '+"'"+file.split('/')[-1]+"' "
else:
tit = args.title
data = pd.read_csv(file, sep='\s+', skiprows=1, names = ["dTime","counts"])
plt.figure(figsize=(15,10))
plt.step(data["dTime"], data["counts"], label='deltatimes')
fs = 15
lim = [0, 90000, 0.9, 30000]
if not args.limits == None:
for i in range(0,4):
if not args.limits[i] == None:
lim[i] = float(args.limits[i])
xlab = 'deltatime in $\mu$s'
ylab = 'counts'
plt.legend(fontsize = fs, loc="upper right")
plt.xticks(fontsize=fs)
plt.yticks(fontsize=fs)
plt.title(tit, fontsize = fs+10, pad = 15)
plt.yscale('log')
plt.ylabel(ylab, fontsize = fs+5)
plt.xlabel(xlab, fontsize=fs+5)
plt.ylim(lim[2],lim[3])
plt.xlim(lim[0],lim[1])
if args.export == None:
plt.show()
else:
if args.export[0] == 'f':
name = 'plots/dThist_' + file.split('/')[-1].split('.')[0]
else:
name = args.export[0]
if len(args.export)>1:
end = '.' + args.export[1]
else:
end=''
plt.savefig(name+end)
main()