Esempio n. 1
0
def process(filenames):
    events = 0
    num = 0
    e_mu = LorentzVector(0.0, 0.0, BEAM_E, energy=BEAM_E)
    for f in filenames:
        reader = hipo_reader(f)
        while reader.next():
            events += 1

    print("Processing {} Events".format(events))
    W = np.ones(shape=(SECTORS, events * 2)) * np.nan
    Q2 = np.ones(shape=(SECTORS, events * 2)) * np.nan

    for f in filenames:
        reader = hipo_reader(f)
        pid = reader.getIntNode(u"REC::Particle", u"pid")
        px = reader.getFloatNode(u"REC::Particle", u"px")
        py = reader.getFloatNode(u"REC::Particle", u"py")
        pz = reader.getFloatNode(u"REC::Particle", u"pz")
        vx = reader.getFloatNode(u"REC::Particle", u"vx")
        vy = reader.getFloatNode(u"REC::Particle", u"vy")
        vz = reader.getFloatNode(u"REC::Particle", u"vz")
        charge = reader.getInt8Node(u"REC::Particle", u"charge")
        beta = reader.getFloatNode(u"REC::Particle", u"beta")

        track_pindex = reader.getInt16Node(u"REC::Track", u"pindex")
        track_sector = reader.getInt8Node(u"REC::Track", u"sector")

        cal_pindex = reader.getInt16Node(u"REC::Calorimeter", u"pindex")
        cal_sector = reader.getInt8Node(u"REC::Calorimeter", u"sector")

        while reader.next():
            if len(pid) == 0:
                continue
            num += 1
            sec = GetSector(track_pindex, track_sector)
            e_mu_prime = LorentzVector(px[0], py[0], pz[0], mass=MASS_ELEC)
            W[sec][num] = W_calc(e_mu, e_mu_prime)
            Q2[sec][num] = Q2_calc(e_mu, e_mu_prime)

    return events, W, Q2
Esempio n. 2
0
tree = uproot.open(sys.argv[1] + ".root")["clas12"]
pid, px, py, pz = tree.arrays([
    "REC_Particle_pid", "REC_Particle_px", "REC_Particle_py", "REC_Particle_pz"
],
                              outputtype=tuple)
momentum_root = []
for pid, pxi, pyi, pzi in zip(pid, px, py, pz):
    if (len(pid) > 0 and pid[0] == 11):
        for pxj, pyj, pzj in zip(pxi, pyi, pzi):
            momentum_root.append(math.sqrt(pxj**2 + pyj**2 + pzj**2))

plt.hist(momentum_root, bins=500, range=(0, 5))

file_name = sys.argv[1]
reader = hipo_reader(unicode(file_name, "utf-8"))
rec_part_px = reader.getFloatNode(u"REC::Particle", u"px")
rec_part_py = reader.getFloatNode(u"REC::Particle", u"py")
rec_part_pz = reader.getFloatNode(u"REC::Particle", u"pz")
rec_part_pid = reader.getIntNode(u"REC::Particle", u"pid")

momentum_hipo = []
while (reader.next()):
    if (rec_part_pid.getLength() > 0 and rec_part_pid[0] == 11):
        for i in range(0, rec_part_pid.getLength()):
            momentum_hipo.append(
                math.sqrt(rec_part_px[i]**2 + rec_part_py[i]**2 +
                          rec_part_pz[i]**2))

plt.hist(momentum_hipo, bins=500, range=(0, 5))
plt.show()
Esempio n. 3
0

def vertex_time(sc_time, sc_pathlength, relatavistic_beta):
    return sc_time - (sc_pathlength / (relatavistic_beta * c_special_units))


def deltat(momentum, sc_t, sc_r, vertex, mass):
    if momentum == 0:
        return np.nan
    mp = (mass / momentum)
    beta = 1.0 / np.sqrt(1.0 + (mp * mp))
    return vertex - vertex_time(sc_t, sc_r, beta)


file_name = sys.argv[1]
reader = hipo_reader(file_name)
data = Event(reader)

tot_events = 0

pvsb_pos = TH2F('momentum_vs_beta_pos', 'P vs #beta + Particles', 500, 0, 4, 500, 0, 1.2)
pvsb_neg = TH2F('momentum_vs_beta_neg', 'P vs #beta - Particles', 500, 0, 4, 500, 0, 1.2)
pvsb_neutral = TH2F('momentum_vs_beta_neutral', 'P vs #beta 0 Particles', 500, 0, 4, 500, 0, 1.2)
hfile = TFile('simple.root', 'RECREATE', 'Demo ROOT file with histograms')

start = time.time()
for event in data:
    tot_events += 1
    if len(event) == 0 or event.particle[0].pid != 11:
        continue
    for part in event.particle[1:]:
Esempio n. 4
0
from __future__ import print_function

import sys

import matplotlib.pyplot as plt
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC

from hipopy import LorentzVector, hipo_reader

px_py_pz_beta = []
true_pid = []
for f in sys.argv[1:]:
    print("Loading {}".format(f))
    reader = hipo_reader(f)
    pid = reader.getIntNode(u"REC::Particle", u"pid")
    px = reader.getFloatNode(u"REC::Particle", u"px")
    py = reader.getFloatNode(u"REC::Particle", u"py")
    pz = reader.getFloatNode(u"REC::Particle", u"pz")
    vx = reader.getFloatNode(u"REC::Particle", u"vx")
    vy = reader.getFloatNode(u"REC::Particle", u"vy")
    vz = reader.getFloatNode(u"REC::Particle", u"vz")
    charge = reader.getInt8Node(u"REC::Particle", u"charge")
    beta = reader.getFloatNode(u"REC::Particle", u"beta")

    mc_pid = reader.getIntNode(u"MC::Particle", u"pid")
    mc_px = reader.getFloatNode(u"MC::Particle", u"px")
    mc_py = reader.getFloatNode(u"MC::Particle", u"py")
    mc_pz = reader.getFloatNode(u"MC::Particle", u"pz")
    mc_vx = reader.getFloatNode(u"MC::Particle", u"vx")