Skip to content
Snippets Groups Projects
Commit 9528db0a authored by Johannes Schumann's avatar Johannes Schumann
Browse files

Fixed rotation bug and make aanet output and upgrade it to uproot4

parent 1cd6cfb1
No related branches found
No related tags found
No related merge requests found
Pipeline #15772 passed
...@@ -160,7 +160,8 @@ class GiBUUOutput: ...@@ -160,7 +160,8 @@ class GiBUUOutput:
xsec = np.divide(total_flux_events * weights, deltaE * n_files) xsec = np.divide(total_flux_events * weights, deltaE * n_files)
return xsec return xsec
def _bjorken_x(self, roottuple_data): @staticmethod
def bjorken_x(roottuple_data):
d = roottuple_data d = roottuple_data
k_in = np.vstack([ k_in = np.vstack([
np.array(d.lepIn_E), np.array(d.lepIn_E),
...@@ -182,7 +183,8 @@ class GiBUUOutput: ...@@ -182,7 +183,8 @@ class GiBUUOutput:
x = np.divide(-q2, 2 * pq) x = np.divide(-q2, 2 * pq)
return np.array(x) return np.array(x)
def _bjorken_y(self, roottuple_data): @staticmethod
def bjorken_y(roottuple_data):
d = roottuple_data d = roottuple_data
y = 1 - np.divide(np.array(d.lepOut_E), np.array(d.lepIn_E)) y = 1 - np.divide(np.array(d.lepOut_E), np.array(d.lepIn_E))
return y return y
...@@ -195,6 +197,10 @@ class GiBUUOutput: ...@@ -195,6 +197,10 @@ class GiBUUOutput:
def Z(self): def Z(self):
return self.jobcard["target"]["target_z"] return self.jobcard["target"]["target_z"]
@property
def data_path(self):
return self._data_path
@property @property
def df(self): def df(self):
import pandas as pd import pandas as pd
...@@ -205,8 +211,8 @@ class GiBUUOutput: ...@@ -205,8 +211,8 @@ class GiBUUOutput:
tmp_df = awkward1.to_pandas(event_data) tmp_df = awkward1.to_pandas(event_data)
idx_mask = tmp_df.groupby(level=[0]).ngroup() idx_mask = tmp_df.groupby(level=[0]).ngroup()
tmp_df["xsec"] = self._event_xsec(event_data)[idx_mask] tmp_df["xsec"] = self._event_xsec(event_data)[idx_mask]
tmp_df["Bx"] = self._bjorken_x(event_data)[idx_mask] tmp_df["Bx"] = GiBUUOutput.bjorken_x(event_data)[idx_mask]
tmp_df["By"] = self._bjorken_y(event_data)[idx_mask] tmp_df["By"] = GiBUUOutput.bjorken_y(event_data)[idx_mask]
if df is None: if df is None:
df = tmp_df df = tmp_df
else: else:
...@@ -271,9 +277,12 @@ def write_detector_file(gibuu_output, ...@@ -271,9 +277,12 @@ def write_detector_file(gibuu_output,
sec_lep_type *= -1 sec_lep_type *= -1
for ifile in gibuu_output.root_pert_files: for ifile in gibuu_output.root_pert_files:
fobj = uproot.open(ifile) fobj = uproot4.open(join(gibuu_output.data_path, ifile))
event_data = fobj["RootTuple"] event_data = fobj["RootTuple"].arrays()
for event in event_data.lazyarrays(): bjorkenx = GiBUUOutput.bjorken_x(event_data)
bjorkeny = GiBUUOutput.bjorken_y(event_data)
from tqdm import tqdm
for i, event in tqdm(enumerate(event_data)):
aafile.evt.clear() aafile.evt.clear()
aafile.evt.id = mc_event_id aafile.evt.id = mc_event_id
aafile.evt.mc_run_id = mc_event_id aafile.evt.mc_run_id = mc_event_id
...@@ -295,9 +304,8 @@ def write_detector_file(gibuu_output, ...@@ -295,9 +304,8 @@ def write_detector_file(gibuu_output,
dir_z = cos_theta dir_z = cos_theta
direction = np.array([dir_x, dir_y, dir_z]) direction = np.array([dir_x, dir_y, dir_z])
rotation = np.array([dir_y, -dir_x, 0]) theta = np.arccos(cos_theta)
sin_rot = np.linalg.norm(rotation) R = Rotation.from_euler("yz", [theta, phi])
R = Rotation.from_rotvec(rotation * np.arcsin(sin_rot) / sin_rot)
timestamp = np.random.uniform(0, livetime) timestamp = np.random.uniform(0, livetime)
...@@ -321,9 +329,9 @@ def write_detector_file(gibuu_output, ...@@ -321,9 +329,9 @@ def write_detector_file(gibuu_output,
lep_out_trk.E = event.lepOut_E lep_out_trk.E = event.lepOut_E
lep_out_trk.t = timestamp lep_out_trk.t = timestamp
bjorken_y = 1.0 - float(event.lepOut_E / event.lepIn_E) # bjorken_y = 1.0 - float(event.lepOut_E / event.lepIn_E)
nu_in_trk.setusr('bx', -1) nu_in_trk.setusr('bx', bjorkenx[i])
nu_in_trk.setusr('by', bjorken_y) nu_in_trk.setusr('by', bjorkeny[i])
nu_in_trk.setusr('ichan', ichan) nu_in_trk.setusr('ichan', ichan)
nu_in_trk.setusr("cc", is_cc) nu_in_trk.setusr("cc", is_cc)
...@@ -343,7 +351,5 @@ def write_detector_file(gibuu_output, ...@@ -343,7 +351,5 @@ def write_detector_file(gibuu_output,
trk.t = timestamp trk.t = timestamp
aafile.evt.mc_trks.push_back(trk) aafile.evt.mc_trks.push_back(trk)
aafile.write() aafile.write()
# if mc_event_id > 100:
# break
del aafile del aafile
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment