Esempio di come plottare in python istogrammi che michela ha fatto con paw. Si trovano in genere in analysis_flight/histo/runXXXXXX_histo.hbook, e li ho convertiti in root con h2root

In [ ]:
import numpy as np
from matplotlib import pyplot as plt
from scipy.optimize import curve_fit
import sys, os, re, glob

import uproot
In [ ]:
fileToOpen = "run580083_histo.root" 
with uproot.open(fileToOpen) as f:
    for k in f:
        print(k)
        try:
            for kk in f[k]:
                print(kk)
        except:
            pass
        
    #print(f.describe())
h100;1
h1000;1
h1001;1
h1002;1
h1003;1
h1010;1
h201;1
h1201;1
h1101;1
h3401;1
h3001;1
h3501;1
h3601;1
h3301;1
h1701;1
h17001;1
h2701;1
h1731;1
h1761;1
h1301;1
h2301;1
h3101;1
h9701;1
h9711;1
h1401;1
h2401;1
h1501;1
h2501;1
h1601;1
h16001;1
h2601;1
h3201;1
h1801;1
h1811;1
h8801;1
h1901;1
h1951;1
h2001;1
h10001;1
h4001;1
h202;1
h1202;1
h1102;1
h3402;1
h3002;1
h3502;1
h3602;1
h3302;1
h1702;1
h17002;1
h2702;1
h1732;1
h1762;1
h1302;1
h2302;1
h3102;1
h9702;1
h9712;1
h1402;1
h2402;1
h1502;1
h2502;1
h1602;1
h16002;1
h2602;1
h3202;1
h1802;1
h1812;1
h8802;1
h1902;1
h1952;1
h2002;1
h10002;1
h4002;1
h203;1
h1203;1
h1103;1
h3403;1
h3003;1
h3503;1
h3603;1
h3303;1
h1703;1
h17003;1
h2703;1
h1733;1
h1763;1
h1303;1
h2303;1
h3103;1
h9703;1
h9713;1
h1403;1
h2403;1
h1503;1
h2503;1
h1603;1
h16003;1
h2603;1
h3203;1
h1803;1
h1813;1
h8803;1
h1903;1
h1953;1
h2003;1
h10003;1
h4003;1
h204;1
h1204;1
h1104;1
h3404;1
h3004;1
h3504;1
h3604;1
h3304;1
h1704;1
h17004;1
h2704;1
h1734;1
h1764;1
h1304;1
h2304;1
h3104;1
h9704;1
h9714;1
h1404;1
h2404;1
h1504;1
h2504;1
h1604;1
h16004;1
h2604;1
h3204;1
h1804;1
h1814;1
h8804;1
h1904;1
h1954;1
h2004;1
h10004;1
h4004;1
h205;1
h1205;1
h1105;1
h3405;1
h3005;1
h3505;1
h3605;1
h3305;1
h1705;1
h17005;1
h2705;1
h1735;1
h1765;1
h1305;1
h2305;1
h3105;1
h9705;1
h9715;1
h1405;1
h2405;1
h1505;1
h2505;1
h1605;1
h16005;1
h2605;1
h3205;1
h1805;1
h1815;1
h8805;1
h1905;1
h1955;1
h2005;1
h10005;1
h4005;1
h206;1
h1206;1
h1106;1
h3406;1
h3006;1
h3506;1
h3606;1
h3306;1
h1706;1
h17006;1
h2706;1
h1736;1
h1766;1
h1306;1
h2306;1
h3106;1
h9706;1
h9716;1
h1406;1
h2406;1
h1506;1
h2506;1
h1606;1
h16006;1
h2606;1
h3206;1
h1806;1
h1816;1
h8806;1
h1906;1
h1956;1
h2006;1
h10006;1
h4006;1
h9000;1
h9001;1
h9010;1
h9011;1
h9200;1
h9600;1
h9100;1
h9101;1
h9102;1
h94101;1
h94102;1
h94103;1
h94104;1
h6001;1
h6101;1
h6201;1
h6002;1
h6102;1
h6202;1
h6003;1
h6103;1
h6203;1
h6004;1
h6104;1
h6204;1
h6005;1
h6105;1
h6205;1
h6006;1
h6106;1
h6206;1
h6007;1
h6107;1
h6207;1
h6008;1
h6108;1
h6208;1
h6009;1
h6109;1
h6209;1
h6010;1
h6110;1
h6210;1
h6011;1
h6111;1
h6211;1
h6012;1
h6112;1
h6212;1
h6013;1
h6113;1
h6213;1
h6014;1
h6114;1
h6214;1
h6015;1
h6115;1
h6215;1
h6016;1
h6116;1
h6216;1
h6017;1
h6117;1
h6217;1
h6018;1
h6118;1
h6218;1
h6019;1
h6119;1
h6219;1
h6020;1
h6120;1
h6220;1
h6021;1
h6121;1
h6221;1
h6022;1
h6122;1
h6222;1
h6023;1
h6123;1
h6223;1
h6024;1
h6124;1
h6224;1
h67890;1
h7000;1
h7001;1
h90000;1
h90001;1
h91000;1
h91001;1
h91002;1
h6300;1
h6301;1
h6302;1
h6303;1
h6304;1
h6305;1
h6306;1
h6307;1
h6308;1
h7101;1
h7102;1
h7103;1
h7104;1

PULL¶

In [ ]:
with uproot.open(fileToOpen)["h1702"] as f:
    a = f.all_members
        
    # Directly access the bins and height matrix
    b = f.to_numpy()
    

# Extract bins and height matrix
h_2 = b[0]
bins_2 = b[1]
binc_2 = bins_2[:-1] + (bins_2[1] - bins_2[0])/2


with uproot.open(fileToOpen)["h1703"] as f:
    a = f.all_members
        
    # Directly access the bins and height matrix
    b = f.to_numpy()
    

# Extract bins and height matrix
h_3 = b[0]
bins_3 = b[1]
binc_3 = bins_3[:-1] + (bins_3[1] - bins_3[0])/2


with uproot.open(fileToOpen)["h1705"] as f:
    a = f.all_members
        
    # Directly access the bins and height matrix
    b = f.to_numpy()
    

# Extract bins and height matrix
h_5 = b[0]
bins_5 = b[1]
binc_5 = bins_5[:-1] + (bins_5[1] - bins_5[0])/2
In [ ]:
fig, ax = plt.subplots(3, 1)
fig.set_size_inches(11, 6)
fig.subplots_adjust(hspace = .2)
ax = ax.flatten()

ax[0].set_title("Pull distribution", fontsize = 20)


ax[0].plot(binc_2[5:], h_2[5:], ds = "steps-mid", c = "darkgreen", lw = 2, label = "Pull - X1")
ax[0].fill_between(binc_2[5:], h_2[5:], step = "mid", color = "lime", alpha = 1)

ax[1].plot(binc_3[5:], h_3[5:], ds = "steps-mid", c = "darkgreen", lw = 2, label = "Pull - X2")
ax[1].fill_between(binc_3[5:], h_3[5:], step = "mid", color = "lime", alpha = 1)

ax[2].plot(binc_5[5:], h_5[5:], ds = "steps-mid", c = "darkgreen", lw = 2, label = "Pull - X3")
ax[2].fill_between(binc_5[5:], h_5[5:], step = "mid", color = "lime", alpha = 1)




# ax.set_title("", fontsize = 16)

for i, a in enumerate(ax):
    # a.set_xlabel("Energy [ADC]", fontsize = 14)
    a.set_ylabel("Entries", fontsize = 14)
    a.grid()
    a.legend(fontsize = 14)

fig.savefig("galore-pull.pdf", format = "pdf", bbox_inches="tight", pad_inches=0)
plt.show()

SNR¶

In [ ]:
with uproot.open(fileToOpen)["h1402"] as f:
    a = f.all_members
        
    # Directly access the bins and height matrix
    b = f.to_numpy()
    

# Extract bins and height matrix
h_2 = b[0]
bins_2 = b[1]
binc_2 = bins_2[:-1] + (bins_2[1] - bins_2[0])/2


with uproot.open(fileToOpen)["h1403"] as f:
    a = f.all_members
        
    # Directly access the bins and height matrix
    b = f.to_numpy()
    

# Extract bins and height matrix
h_3 = b[0]
bins_3 = b[1]
binc_3 = bins_3[:-1] + (bins_3[1] - bins_3[0])/2


with uproot.open(fileToOpen)["h1405"] as f:
    a = f.all_members
        
    # Directly access the bins and height matrix
    b = f.to_numpy()
    

# Extract bins and height matrix
h_5 = b[0]
bins_5 = b[1]
binc_5 = bins_5[:-1] + (bins_5[1] - bins_5[0])/2
In [ ]:
fig, ax = plt.subplots(3, 1)
fig.set_size_inches(11, 6)
fig.subplots_adjust(hspace = .2)
ax = ax.flatten()

ax[0].set_title("SNR distribution", fontsize = 20)


ax[0].plot(binc_2[5:], h_2[5:], ds = "steps-mid", c = "darkgreen", lw = 2, label = "SNR - X1")
ax[0].fill_between(binc_2[5:], h_2[5:], step = "mid", color = "lime", alpha = 1)

ax[1].plot(binc_3[5:], h_3[5:], ds = "steps-mid", c = "darkgreen", lw = 2, label = "SNR - X2")
ax[1].fill_between(binc_3[5:], h_3[5:], step = "mid", color = "lime", alpha = 1)

ax[2].plot(binc_5[5:], h_5[5:], ds = "steps-mid", c = "darkgreen", lw = 2, label = "SNR - X3")
ax[2].fill_between(binc_5[5:], h_5[5:], step = "mid", color = "lime", alpha = 1)




# ax.set_title("", fontsize = 16)

for i, a in enumerate(ax):
    # a.set_xlabel("Energy [ADC]", fontsize = 14)
    a.set_ylabel("Entries", fontsize = 14)
    a.grid()
    a.legend(fontsize = 14)

fig.savefig("galore-snr.pdf", format = "pdf", bbox_inches="tight", pad_inches=0)
plt.show()

ETA¶

In [ ]:
with uproot.open(fileToOpen)["h1952"] as f:
    a = f.all_members
        
    # Directly access the bins and height matrix
    b = f.to_numpy()
    

# Extract bins and height matrix
h_2 = b[0]
bins_2 = b[1]
binc_2 = bins_2[:-1] + (bins_2[1] - bins_2[0])/2


with uproot.open(fileToOpen)["h1953"] as f:
    a = f.all_members
        
    # Directly access the bins and height matrix
    b = f.to_numpy()
    

# Extract bins and height matrix
h_3 = b[0]
bins_3 = b[1]
binc_3 = bins_3[:-1] + (bins_3[1] - bins_3[0])/2


with uproot.open(fileToOpen)["h1955"] as f:
    a = f.all_members
        
    # Directly access the bins and height matrix
    b = f.to_numpy()
    

# Extract bins and height matrix
h_5 = b[0]
bins_5 = b[1]
binc_5 = bins_5[:-1] + (bins_5[1] - bins_5[0])/2
In [ ]:
fig, ax = plt.subplots(3, 1)
fig.set_size_inches(11, 6)
fig.subplots_adjust(hspace = .2)
ax = ax.flatten()

ax[0].set_title("Eta distribution", fontsize = 20)


ax[0].plot(binc_2[5:], h_2[5:], ds = "steps-mid", c = "darkgreen", lw = 2, label = "Eta - X1")
ax[0].fill_between(binc_2[5:], h_2[5:], step = "mid", color = "lime", alpha = 1)

ax[1].plot(binc_3[5:], h_3[5:], ds = "steps-mid", c = "darkgreen", lw = 2, label = "Eta - X2")
ax[1].fill_between(binc_3[5:], h_3[5:], step = "mid", color = "lime", alpha = 1)

ax[2].plot(binc_5[5:], h_5[5:], ds = "steps-mid", c = "darkgreen", lw = 2, label = "Eta - X3")
ax[2].fill_between(binc_5[5:], h_5[5:], step = "mid", color = "lime", alpha = 1)




# ax.set_title("", fontsize = 16)

for i, a in enumerate(ax):
    # a.set_xlabel("Energy [ADC]", fontsize = 14)
    a.set_ylabel("Entries", fontsize = 14)
    a.grid()
    a.legend(fontsize = 14)

fig.savefig("galore-eta.pdf", format = "pdf", bbox_inches="tight", pad_inches=0)
plt.show()