Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: None padding order, adding otherjets in Wc WF #60

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 25 additions & 29 deletions src/BTVNanoCommissioning/workflows/ctag_Wc_valid_sf.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def process_shift(self, events, shift_name):
# muon twiki: https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideMuonIdRun2
iso_muon = events.Muon[(events.Muon.pt > 30) & mu_idiso(events, self._campaign)]
req_muon = ak.count(iso_muon.pt, axis=1) == 1
jet_sel = jet_id(events, self._campaign) & (
ak.all(events.Jet.metric_table(iso_muon) > 0.5, axis=2)
)
Comment on lines +122 to +124
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the additional ak.fill_none for the selection to avoid None in the jet selection. (just to be sure None filtered out 😉 )

iso_muon = ak.pad_none(iso_muon, 1, axis=1)
iso_muon = iso_muon[:, 0]
iso_muindx = ak.mask(
Expand All @@ -129,9 +132,6 @@ def process_shift(self, events, shift_name):
iso_muindx = iso_muindx[:, 0]

## Jet cuts
jet_sel = jet_id(events, self._campaign) & (
ak.all(events.Jet.metric_table(iso_muon) > 0.5, axis=2, mask_identity=True)
)
if "DeepJet_nsv" in events.Jet.fields:
jet_sel = jet_sel & (events.Jet.DeepJet_nsv > 0)
event_jet = events.Jet[jet_sel]
Expand All @@ -140,30 +140,13 @@ def process_shift(self, events, shift_name):
## Soft Muon cuts
soft_muon = events.Muon[softmu_mask(events, self._campaign)]
req_softmu = ak.count(soft_muon.pt, axis=1) >= 1
soft_muon = ak.pad_none(soft_muon, 1, axis=1)

## Muon-jet cuts
mu_jet = event_jet[
(
ak.all(
event_jet.metric_table(soft_muon) <= 0.4, axis=2, mask_identity=True
)
)
mujetsel = (
(ak.all(event_jet.metric_table(soft_muon) <= 0.4, axis=2))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mask_identity=True should be there to avoid None events pass True criteria.
The ak.fill_none(mujetsel,False,axis=-1) then remove None, this cut can be proceed anywhere. (Then you don't need mujetsel2)

& ((event_jet.muonIdx1 != -1) | (event_jet.muonIdx2 != -1))
& ((event_jet.muEF + event_jet.neEmEF) < 0.7)
]
req_mujet = ak.num(mu_jet.pt, axis=1) >= 1
mu_jet = ak.pad_none(mu_jet, 1, axis=1)

## store jet index for PFCands, create mask on the jet index
jet_selpf = (
jet_id(events, self._campaign)
& (
ak.all(
events.Jet.metric_table(iso_muon) > 0.5, axis=2, mask_identity=True
)
)
& ((events.Jet.muEF + events.Jet.neEmEF) < 0.7)
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No mujetsel2 is needed once we ak.fill_none(mujetsel,False,axis=-1)

mujetsel2 = (
((events.Jet.muEF + events.Jet.neEmEF) < 0.7)
& (
ak.all(
events.Jet.metric_table(soft_muon) <= 0.4,
Expand All @@ -173,6 +156,16 @@ def process_shift(self, events, shift_name):
)
& ((events.Jet.muonIdx1 != -1) | (events.Jet.muonIdx2 != -1))
)
soft_muon = ak.pad_none(soft_muon, 1, axis=1)

## Muon-jet cuts
mu_jet = event_jet[mujetsel]
otherjets = event_jet[~mujetsel]
req_mujet = ak.num(mu_jet.pt, axis=1) >= 1
mu_jet = ak.pad_none(mu_jet, 1, axis=1)

## store jet index for PFCands, create mask on the jet index
jet_selpf = (jet_sel) & (mujetsel2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to mujetsel

if "DeepJet_nsv" in events.Jet.fields:
jet_selpf = jet_selpf & (events.Jet.DeepJet_nsv > 0)
jetindx = ak.mask(ak.local_index(events.Jet.pt), jet_selpf == True)
Expand Down Expand Up @@ -260,6 +253,7 @@ def process_shift(self, events, shift_name):
ssmu = soft_muon[event_level]
smet = MET[event_level]
smuon_jet = mu_jet[event_level]
sotherjets = otherjets[event_level]
nsoftmu = ak.count(ssmu.pt, axis=1)
nmujet = ak.count(smuon_jet.pt, axis=1)
smuon_jet = smuon_jet[:, 0]
Expand Down Expand Up @@ -489,10 +483,11 @@ def process_shift(self, events, shift_name):
if self.isArray:
# Keep the structure of events and pruned the object size
pruned_ev = events[event_level]
pruned_ev.Jet = sjets
pruned_ev.Muon = shmu
pruned_ev["Jet"] = sjets
pruned_ev["Muon"] = shmu
pruned_ev["MuonJet"] = smuon_jet
pruned_ev["SoftMuon"] = ssmu
pruned_ev["OtherJets"] = sotherjets
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still want to store the jet flag instead of collections on MuonJet & OtherJet? The mujetsel can still considered as a flag in the Jet variables

pruned_ev["osss"] = osss
if "PFCands" in events.fields:
pruned_ev.PFCands = spfcands
Expand All @@ -518,7 +513,7 @@ def process_shift(self, events, shift_name):
out_branch,
np.where(
(out_branch == "SoftMuon")
| (out_branch == "MuonJet")
# | (out_branch == "MuonJet")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I understand correctly you want to store PFcands in the MuonJet collection so you commented out?(also OtherJets also not included)

| (out_branch == "dilep")
),
)
Expand All @@ -528,7 +523,7 @@ def process_shift(self, events, shift_name):
"Muon",
"Jet",
"SoftMuon",
"MuonJet",
# "MuonJet",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kinematics variables will not save, is this done intentionally?

"dilep",
"charge",
"MET",
Expand All @@ -544,6 +539,7 @@ def process_shift(self, events, shift_name):
out_branch, ["Jet_btagDeep*", "Jet_DeepJet*", "PFCands_*", "SV_*"]
)
# write to root files
print("Branches to write:", out_branch)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the check you want to keep when running the code?
Indeed the out_branch also contains some regexp which not really returns full variable. Maybe would be interesting to check with fout["Events"].fields for check all the entries

with uproot.recreate(
f"tmp/{dataset}_{systematics[0]}_{int(events.metadata['entrystop']/self.chunksize)}.root"
) as fout:
Expand Down
54 changes: 23 additions & 31 deletions src/BTVNanoCommissioning/workflows/ctag_eWc_valid_sf.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def process_shift(self, events, shift_name):
(events.Electron.pt > 34) & ele_mvatightid(events, self._campaign)
]
req_ele = ak.count(iso_ele.pt, axis=1) == 1
jet_sel = jet_id(events, self._campaign) & (
ak.all(events.Jet.metric_table(iso_ele) > 0.5, axis=2)
)
Comment on lines +125 to +127
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the additional ak.fill_none for the selection to avoid None in the jet selection. (just to be sure None filtered out)

iso_ele = ak.pad_none(iso_ele, 1, axis=1)
iso_ele = iso_ele[:, 0]
iso_eindx = ak.mask(
Expand All @@ -132,9 +135,7 @@ def process_shift(self, events, shift_name):
iso_eindx = iso_eindx[:, 0]

## Jet cuts
jet_sel = jet_id(events, self._campaign) & (
ak.all(events.Jet.metric_table(iso_ele) > 0.5, axis=2, mask_identity=True)
)

if "DeepJet_nsv" in events.Jet.fields:
jet_sel = jet_sel & (events.Jet.DeepJet_nsv > 0)
event_jet = events.Jet[jet_sel]
Expand All @@ -143,37 +144,25 @@ def process_shift(self, events, shift_name):
## Soft Muon cuts
soft_muon = events.Muon[softmu_mask(events, self._campaign)]
req_softmu = ak.count(soft_muon.pt, axis=1) >= 1
mujetsel = (ak.all(event_jet.metric_table(soft_muon) <= 0.4, axis=2)) & (
(event_jet.muonIdx1 != -1) | (event_jet.muonIdx2 != -1)
)
mujetsel2 = (
ak.all(
events.Jet.metric_table(soft_muon) <= 0.4,
axis=2,
)
) & ((events.Jet.muonIdx1 != -1) | (events.Jet.muonIdx2 != -1))
Comment on lines +147 to +155
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mask_identity=True should be there to avoid None events pass True criteria.
The ak.fill_none(mujetsel,False,axis=-1) then remove None, this cut can be proceed anywhere. (Then you don't need mujetsel2)

soft_muon = ak.pad_none(soft_muon, 1, axis=1)

## Muon-jet cuts
mu_jet = event_jet[
(
ak.all(
event_jet.metric_table(soft_muon) <= 0.4, axis=2, mask_identity=True
)
)
& ((event_jet.muonIdx1 != -1) | (event_jet.muonIdx2 != -1))
]
mu_jet = event_jet[mujetsel]
otherjets = event_jet[~mujetsel]
req_mujet = ak.num(mu_jet.pt, axis=1) >= 1
mu_jet = ak.pad_none(mu_jet, 1, axis=1)

## store jet index for PFCands, create mask on the jet index
jet_selpf = (
jet_id(events, self._campaign)
& (
ak.all(
events.Jet.metric_table(iso_ele) > 0.5, axis=2, mask_identity=True
)
)
& (
ak.all(
events.Jet.metric_table(soft_muon) <= 0.4,
axis=2,
mask_identity=True,
)
)
& ((events.Jet.muonIdx1 != -1) | (events.Jet.muonIdx2 != -1))
)
jet_selpf = (jet_sel) & (mujetsel2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the mujetsel

if "DeepJet_nsv" in events.Jet.fields:
jet_selpf = jet_selpf & (events.Jet.DeepJet_nsv > 0)
jetindx = ak.mask(ak.local_index(events.Jet.pt), jet_selpf == True)
Expand Down Expand Up @@ -255,6 +244,7 @@ def process_shift(self, events, shift_name):
ssmu = soft_muon[event_level]
smet = MET[event_level]
smuon_jet = mu_jet[event_level]
sotherjets = otherjets[event_level]
nsoftmu = ak.count(ssmu.pt, axis=1)
nmujet = ak.count(smuon_jet.pt, axis=1)
smuon_jet = smuon_jet[:, 0]
Expand Down Expand Up @@ -484,9 +474,10 @@ def process_shift(self, events, shift_name):
if self.isArray:
# Keep the structure of events and pruned the object size
pruned_ev = events[event_level]
pruned_ev.Jet = sjets
pruned_ev.Muon = shmu
pruned_ev["Jet"] = sjets
pruned_ev["Muon"] = shmu
pruned_ev["MuonJet"] = smuon_jet
pruned_ev["OtherJets"] = sotherjets
Comment on lines +477 to +480
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still want to store the jet flag instead of collections on MuonJet & OtherJet? The mujetsel can still considered as a flag in the Jet variables

pruned_ev["SoftMuon"] = ssmu
pruned_ev["osss"] = osss
if "PFCands" in events.fields:
Expand All @@ -513,7 +504,7 @@ def process_shift(self, events, shift_name):
out_branch,
np.where(
(out_branch == "SoftMuon")
| (out_branch == "MuonJet")
# | (out_branch == "MuonJet")
Comment on lines -516 to +507
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I understand correctly you want to store PFcands in the MuonJet collection so you commented out?(also OtherJets also not included)

| (out_branch == "dilep")
),
)
Expand All @@ -523,7 +514,7 @@ def process_shift(self, events, shift_name):
"Muon",
"Jet",
"SoftMuon",
"MuonJet",
# "MuonJet",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kinematics variables will not save, is this done intentionally?

"dilep",
"charge",
"MET",
Expand All @@ -539,6 +530,7 @@ def process_shift(self, events, shift_name):
out_branch, ["Jet_btagDeep*", "Jet_DeepJet*", "PFCands_*", "SV_*"]
)
# write to root files
print("Branches to write:", out_branch)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the check you want to keep when running the code?
Indeed the out_branch also contains some regexp which not really returns full variable. Maybe would be interesting to check with fout["Events"].fields for check all the entries

with uproot.recreate(
f"tmp/{dataset}_{systematics[0]}_{int(events.metadata['entrystop']/self.chunksize)}.root"
) as fout:
Expand Down