readout software for 2 channels [0 and 1] of the tdc-gpx2 board with raspberry pi 3B SPI readout. This code is a fork of the original design by marvin.peter@physik.uni-giessen.de https://github.com/marvin5300/tdc-gpx2_software
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

1 year ago
  1. import argparse
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. #parse the command line arguments
  5. parser = argparse.ArgumentParser(description="Plot a histogram")
  6. parser.add_argument("input_file",help="Path to the input data set with 7 columns")
  7. args = parser.parse_args()
  8. # Open the file and read in the data
  9. with open(args.input_file, 'r') as f:
  10. lines = f.readlines()
  11. # Extract the second column of data
  12. data = []
  13. for line in lines:
  14. values = line.strip().split()
  15. if len(values) >= 7 and float(values[5]) == 0:
  16. data.append(float(values[6]))
  17. #determine histrange from data
  18. hist_range = 10 * np.std(data)
  19. hist_mean = np.mean(data)
  20. hist_start = hist_mean - hist_range
  21. hist_end = hist_mean + hist_range
  22. # Create the histogram with range
  23. hist, bins, _ = plt.hist(data, bins=200, range=(hist_start,hist_end))
  24. # Calculate the mean and RMS
  25. bin_centers = 0.5 * (bins[:-1] + bins[1:])
  26. mean = np.average(bin_centers, weights=hist)
  27. rms = np.sqrt(np.average((bin_centers - mean)**2, weights=hist ))
  28. # Set the x-axis label and title
  29. plt.xlabel('time difference / seconds')
  30. plt.title(' - ')
  31. plt.annotate(f"Mean: {mean:.3g}\nRMS; {rms:.3g}",
  32. xy=(0.75, 0.85),
  33. xycoords='axes fraction',
  34. fontsize=12,
  35. bbox=dict(boxstyle="round,pad=0.3", edgecolor="gray", facecolor="lightgray"))
  36. # Show the plot
  37. plt.show()