Skip to content

Commit b533648

Browse files
MoelfrafaeljacobsenRafael Antonio Jacobsen
authored
Add yield cutflow and refactor the insanity (#97)
* fix CutFlow duplications * add some tests Co-authored-by: Rafael Jacobsen <[email protected]> Co-authored-by: Rafael Antonio Jacobsen <[email protected]>
1 parent 30923ef commit b533648

6 files changed

+168
-172
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ julia> addprocs(HTCManager(10); extrajdl=["+queue=\"short\""], exeflags = `-e 'i
3131
Waiting for 10 workers: 1 2 3 4 5 6 7 8 9 10 .
3232

3333
julia> foreach(WVZAnalysis.ALL_TAGS) do tag
34-
WVZAnalysis.hist_root_pmap(tag; scouting=false, output_dir="/data/jiling/WVZ/v2.3_hists_uproot_nov14_andMET/");
34+
WVZAnalysis.hist_root(tag; scouting=false, output_dir="/data/jiling/WVZ/v2.3_hists_uproot_nov14_andMET/");
3535
end
3636
```

src/WWZ_ana.jl

-35
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,3 @@ function WWZ_chi2(Z_pair, W_pair, v_l_pid, v_l_tlv)
2424
end
2525
return chi2
2626
end
27-
28-
function WWZ_Cut(
29-
Z_pair, W_pair, v_l_pid, v_l_order, v_l_tlv, dict, cutflow_ptr, NN_hist
30-
)
31-
chi2 = WWZ_chi2(Z_pair, W_pair, v_l_pid, v_l_tlv)
32-
FAIL = (false, Inf, W_pair)
33-
@inbounds for i in eachindex(v_l_tlv)
34-
for j in (i + 1):length(v_l_tlv)
35-
v_l_pid[i] + v_l_pid[j] != 0 && continue
36-
WWZ_dilepton_mass = mass(v_l_tlv[i] + v_l_tlv[j])
37-
WWZ_dilepton_mass < 12 && return FAIL
38-
end
39-
end
40-
cutflow_ptr[] += 1
41-
if NN_hist push!(dict[:CutFlow], cutflow_ptr[]) end
42-
43-
@inbounds pt(v_l_tlv[v_l_order[1]]) < 30 && return FAIL
44-
@inbounds pt(v_l_tlv[v_l_order[2]]) < 15 && return FAIL
45-
@inbounds pt(v_l_tlv[v_l_order[3]]) < 8 && return FAIL
46-
@inbounds pt(v_l_tlv[v_l_order[4]]) < 6 && return FAIL
47-
cutflow_ptr[] += 1
48-
if NN_hist push!(dict[:CutFlow], cutflow_ptr[]) end
49-
50-
# selected lepton min dR
51-
@inbounds for i in 1:4
52-
for j in (i + 1):4
53-
dR = deltar(v_l_tlv[v_l_order[i]], v_l_tlv[v_l_order[j]])
54-
dR < 0.1 && return FAIL
55-
end
56-
end
57-
cutflow_ptr[] += 1
58-
if NN_hist push!(dict[:CutFlow], cutflow_ptr[]) end
59-
60-
return true, chi2, W_pair
61-
end

src/analysis_utils.jl

+18-51
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const MINITREE_DIR = Ref("/data/jiling/WVZ/v2.3")
66
const ANALYSIS_DIR = Ref("/data/jiling/WVZ/v2.3_hists")
77

88
const ONNX_MODEL_PATH = Ref("/data/grabanal/NN/NN_08_23.onnx")
9-
const BDT_MODEL_PATH = Ref("/home/rjacobse/BDT/kfolding/")
9+
const BDT_MODEL_PATH = Ref("/data/rjacobse/WVZ/kfolding/")
1010

1111
function init_ONNX()
1212
model=ONNX.load(ONNX_MODEL_PATH[], zeros(Float32, 30, 1))
@@ -326,54 +326,12 @@ end
326326

327327

328328
"""
329-
hist_root(tag; output_dir, kw...)
330-
331-
return a dictionary of all systematics histograms for a given tag, the `output_dir` is
332-
used to store Julia Serializatio files as a backup measure, and for later conversion to
333-
`.root` histograms via `PythonCall.jl` + `uproot`.
334-
"""
335-
function hist_root(tag; output_dir, kw...)
336-
p = output_dir
337-
if !isdir(p)
338-
mkdir(p)
339-
end
340-
@show Threads.nthreads()
341-
@info "-------------- $tag SF begin ------------ "
342-
sf_tasks = prep_tasks(tag)
343-
println("$(length(sf_tasks)) tasks in total")
344-
p1 = Progress(length(sf_tasks))
345-
sf_list = map(sf_tasks) do t
346-
x = main_looper(t)
347-
next!(p1)
348-
x
349-
end
350-
sf_hist = reduce(mergewith(+), sf_list)
351-
352-
@info "-------------- $tag shapes begin ------------ "
353-
shape_tasks = mapreduce(shape_variation -> prep_tasks(tag; shape_variation), vcat,
354-
SHAPE_TREE_NAMES)
355-
sort!(shape_tasks; by = x->x.path)
356-
println("$(length(shape_tasks)) tasks in total")
357-
p2 = Progress(length(shape_tasks))
358-
shape_list = map(shape_tasks) do t
359-
x = main_looper(t)
360-
next!(p2)
361-
x
362-
end
363-
shape_hist = reduce(mergewith(+), shape_list)
364-
365-
Hs = merge(sf_hist, shape_hist)
366-
serialize(joinpath(p, "$(tag).jlserialize"), Hs)
367-
Hs
368-
end
369-
370-
"""
371-
hist_root_pmap(tag; output_dir, kw...)
329+
hist_root(tag; mapper=pmap, no_shape=false, output_dir, kw...)
372330
373331
Similar to the one without `pmap`, except uses pmap for everything. Checkout `ClusterManager.jl`
374332
and be sure to have a handful of workers before running this.
375333
"""
376-
function hist_root_pmap(tag; output_dir, kw...)
334+
function hist_root(tag; mapper=pmap, no_shape = false, output_dir, kw...)
377335
p = output_dir
378336
if !isdir(p)
379337
mkdir(p)
@@ -382,16 +340,25 @@ function hist_root_pmap(tag; output_dir, kw...)
382340

383341
all_tasks = prep_tasks(tag; sfsys=true)
384342
if tag != "Data"
385-
@info "-------------- $tag SF + shapes ------------ "
386-
shape_tasks = mapreduce(shape_variation -> prep_tasks(tag; shape_variation, sfsys=false), vcat,
387-
SHAPE_TREE_NAMES)
388-
sort!(shape_tasks; by = x->x.path)
389-
append!(all_tasks, shape_tasks)
343+
if no_shape
344+
@info "-------------- $tag SF ------------ "
345+
else
346+
@info "-------------- $tag SF + shapes ------------ "
347+
shape_tasks = mapreduce(shape_variation -> prep_tasks(tag; shape_variation, sfsys=false), vcat,
348+
SHAPE_TREE_NAMES)
349+
sort!(shape_tasks; by = x->x.path)
350+
append!(all_tasks, shape_tasks)
351+
end
390352
else
391353
@info "-------------- !!! $tag !!! ------------ "
392354
end
393355
println("$(length(all_tasks)) tasks in total")
394-
all_list = @showprogress pmap(main_looper, all_tasks)
356+
prog = Progress(length(all_tasks))
357+
all_list = mapper(all_tasks) do task
358+
_m = main_looper(task)
359+
next!(prog)
360+
return _m
361+
end
395362
# TODO
396363
# process_theory_syst!.(all_list)
397364
Hs = reduce(mergewith(+), all_list)

src/hist_exfiltration.jl

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ function NN_hist_init(; sfsys, shape_variation)
2626
populate_hist!(_dict, shape_variation, (:SFinZ__Njet, :SFnoZ__Njet, :DF__Njet, :ZZCR__Njet, :ttZCR__Njet), bins, sfsys)
2727

2828
_dict[:CutFlow] = Hist1D(Int; bins=1:20)
29+
_dict[:CutFlowWgt] = Hist1D(Float64; bins=1:20)
30+
_dict[:SFinZCutFlow] = Hist1D(Int; bins=1:20)
31+
_dict[:SFinZCutFlowWgt] = Hist1D(Float64; bins=1:20)
32+
_dict[:SFnoZCutFlow] = Hist1D(Int; bins=1:20)
33+
_dict[:SFnoZCutFlowWgt] = Hist1D(Float64; bins=1:20)
34+
_dict[:DFCutFlow] = Hist1D(Int; bins=1:20)
35+
_dict[:DFCutFlowWgt] = Hist1D(Float64; bins=1:20)
2936

3037
return _dict
3138
end

0 commit comments

Comments
 (0)