Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 15, 2023
1 parent 6a6fd3d commit 6716f33
Showing 1 changed file with 46 additions and 50 deletions.
96 changes: 46 additions & 50 deletions src/HHbbVV/processors/bbVVSkimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,48 +784,49 @@ def getVBFVars(
& (np.abs(jets.eta) > 1.5)
)
vbfJets = jets[vbfJets_mask]

vbfJets_sorted_pt = vbfJets[ak.argsort(vbfJets.pt,ascending = False)]
vbfJets_sorted_pt = ak.pad_none(vbfJets_sorted_pt, 2, clip=True) # this is the only which does not guarantee two guys. in the other sorts, the entries are specifically None.

vbfJets_sorted_pt = vbfJets[ak.argsort(vbfJets.pt, ascending=False)]
vbfJets_sorted_pt = ak.pad_none(
vbfJets_sorted_pt, 2, clip=True
) # this is the only which does not guarantee two guys. in the other sorts, the entries are specifically None.

# pt sorted eta and dijet mass mask
vbf1 = vector.array(
{
"pt": ak.flatten(pad_val(vbfJets_sorted_pt[:,0:1].pt, 1, axis=1)),
"phi": ak.flatten(pad_val(vbfJets_sorted_pt[:,0:1].phi, 1, axis=1)),
"eta": ak.flatten(pad_val(vbfJets_sorted_pt[:,0:1].eta, 1, axis=1)),
"M": ak.flatten(pad_val(vbfJets_sorted_pt[:,0:1].mass, 1, axis=1)),
}
)
{
"pt": ak.flatten(pad_val(vbfJets_sorted_pt[:, 0:1].pt, 1, axis=1)),
"phi": ak.flatten(pad_val(vbfJets_sorted_pt[:, 0:1].phi, 1, axis=1)),
"eta": ak.flatten(pad_val(vbfJets_sorted_pt[:, 0:1].eta, 1, axis=1)),
"M": ak.flatten(pad_val(vbfJets_sorted_pt[:, 0:1].mass, 1, axis=1)),
}
)

vbf2 = vector.array(
{
"pt": ak.flatten(pad_val(vbfJets_sorted_pt[:,1:2].pt, 1, axis=1)),
"phi": ak.flatten(pad_val(vbfJets_sorted_pt[:,1:2].phi, 1, axis=1)),
"eta":ak.flatten(pad_val( vbfJets_sorted_pt[:,1:2].eta, 1, axis=1)),
"M": ak.flatten(pad_val(vbfJets_sorted_pt[:,1:2].mass, 1, axis=1)),
}
)
{
"pt": ak.flatten(pad_val(vbfJets_sorted_pt[:, 1:2].pt, 1, axis=1)),
"phi": ak.flatten(pad_val(vbfJets_sorted_pt[:, 1:2].phi, 1, axis=1)),
"eta": ak.flatten(pad_val(vbfJets_sorted_pt[:, 1:2].eta, 1, axis=1)),
"M": ak.flatten(pad_val(vbfJets_sorted_pt[:, 1:2].mass, 1, axis=1)),
}
)

jj = vbf1 + vbf2

mass_jj_cut_sorted_pt = jj.mass > 500
eta_jj_cut_sorted_pt = np.abs(vbf1.eta - vbf2.eta) > 4.0

vbfJets_mask_sorted_pt = vbfJets_mask #* mass_jj_cut_sorted_pt * eta_jj_cut_sorted_pt # uncomment these last two to include dijet cuts
n_good_vbf_jets_sorted_pt = ak.fill_none(ak.sum(vbfJets_mask_sorted_pt, axis=1),0)



mass_jj_cut_sorted_pt = jj.mass > 500
eta_jj_cut_sorted_pt = np.abs(vbf1.eta - vbf2.eta) > 4.0

vbfJets_mask_sorted_pt = vbfJets_mask # * mass_jj_cut_sorted_pt * eta_jj_cut_sorted_pt # uncomment these last two to include dijet cuts
n_good_vbf_jets_sorted_pt = ak.fill_none(ak.sum(vbfJets_mask_sorted_pt, axis=1), 0)

# add vbf gen quark info
if isGen: # add | True when debugging with local files
if isGen: # add | True when debugging with local files
vbfGenJets = events.GenPart[events.GenPart.hasFlags(["isHardProcess"])][:, 4:6]

vbfVars[f"vbfptGen"] = pad_val(vbfGenJets.pt, 2, axis=1)
vbfVars[f"vbfetaGen"] = pad_val(vbfGenJets.eta, 2, axis=1)
vbfVars[f"vbfphiGen"] = pad_val(vbfGenJets.phi, 2, axis=1)
vbfVars[f"vbfMGen"] = pad_val(vbfGenJets.mass, 2, axis=1)
jet_pairs = ak.cartesian({"reco": vbfJets_sorted_pt[:,0:2], "gen": vbfGenJets[:,0:2]})

jet_pairs = ak.cartesian({"reco": vbfJets_sorted_pt[:, 0:2], "gen": vbfGenJets[:, 0:2]})

# Calculate delta eta and delta phi for each pair
delta_eta = jet_pairs["reco"].eta - jet_pairs["gen"].eta
Expand All @@ -834,18 +835,17 @@ def getVBFVars(
# Calculate delta R for each pair
delta_R = np.sqrt(delta_eta**2 + delta_phi**2)

# Apply a mask for a low delta R value
# Apply a mask for a low delta R value
mask_low_delta_R = delta_R < 0.4
num_per_event= ak.sum(mask_low_delta_R, axis=-1) # miscounts 0's since some are empty


num_per_event = ak.sum(mask_low_delta_R, axis=-1) # miscounts 0's since some are empty

# Combine masks with logical 'and' operation
total_mask = n_good_vbf_jets_sorted_pt > 1

# set event that fail to have 0 for num of events.
num_per_event = ak.where(total_mask, num_per_event, 0)
vbfVars[f"vbfNumMatchedGen"] = num_per_event.to_numpy()

# adds data about R1 R2 selection efficiencies.
graphingR1R2 = False
if (
Expand Down Expand Up @@ -955,21 +955,17 @@ def compute_spatial_part(E, px, py, pz, boost_vector, boost_vector_dot_product):
)

return px_prime, py_prime, pz_prime








# seperation between both ak8 higgs jets
#print(f"\nTime taken defining: {time.time()-start_time:.6f} seconds")

vbfVars[f"vbf_dR_HH"] = VVJet.deltaR(bbJet) # may have to treat same as nGoodVBFJets. same holds for other 1d arrays
#print(f"\nTime after inserting one item: {time.time()-start_time:.6f} seconds")
# print(f"\nTime taken defining: {time.time()-start_time:.6f} seconds")

# ∆R distance between H-VV and the leading VBF-jet:
#vbfVars[f"vbf_dR_HVV"] = pad_val(VVJet.delta_r(vbfJets_sorted_pt), 2, axis=1)
vbfVars[f"vbf_dR_HH"] = VVJet.deltaR(
bbJet
) # may have to treat same as nGoodVBFJets. same holds for other 1d arrays
# print(f"\nTime after inserting one item: {time.time()-start_time:.6f} seconds")

# ∆R distance between H-VV and the leading VBF-jet:
# vbfVars[f"vbf_dR_HVV"] = pad_val(VVJet.delta_r(vbfJets_sorted_pt), 2, axis=1)

vbfVars[f"vbf_dR_j0_HVV"] = vbf1.deltaR(VVJet)
vbfVars[f"vbf_dR_j1_HVV"] = vbf2.deltaR(VVJet)
Expand All @@ -986,7 +982,7 @@ def compute_spatial_part(E, px, py, pz, boost_vector, boost_vector_dot_product):
# print(f"\nTime taken computing jj stuff: {time.time()-start_time:.6f} seconds")
jj = vbf1 + vbf2
vbfVars[f"vbf_Mass_jj"] = jj.M
print(jj.M[0:10] ,'testing masses to see if we implemented this correctly.')
print(jj.M[0:10], "testing masses to see if we implemented this correctly.")
vbfVars[f"vbf_dEta_jj"] = np.abs(vbf1.eta - vbf2.eta)

# print(f"\nTime taken inserting several: {time.time()-start_time:.6f} seconds")
Expand Down Expand Up @@ -1031,8 +1027,8 @@ def compute_spatial_part(E, px, py, pz, boost_vector, boost_vector_dot_product):

vbfVars[f"vbf_cos_j1"] = np.abs(costheta1) # may have to treat same as nGoodVBFJets
vbfVars[f"vbf_cos_j2"] = np.abs(costheta2)
#print(f"\nTime taken computing theta1 and 2: {time.time()-start_time:.6f} seconds")
# print(f"\nTime taken computing theta1 and 2: {time.time()-start_time:.6f} seconds")

# # https://github.com/scikit-hep/vector/blob/main/src/vector/_methods.py#L916
# system_4vec = vbf1 + vbf2 + VVJet + bbJet # this boost is not along beam line unfortunately possibly bc of missing energy or somth?
# print(f"\nTime taken defining system vector: {time.time()-start_time:.6f} seconds")
Expand Down

0 comments on commit 6716f33

Please sign in to comment.