Skip to content

Commit

Permalink
Adapt esmeralda and isaura to new track computation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
ausonandres committed Jul 20, 2021
1 parent f456dab commit 3e8742e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 44 deletions.
31 changes: 23 additions & 8 deletions invisible_cities/cities/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
from .. io .rwf_io import buffer_writer
from .. io .mcinfo_io import load_mchits_df
from .. io .dst_io import df_writer
from .. io .hits_io import hits_writer
from .. types .ic_types import xy
from .. types .ic_types import NN
from .. types .ic_types import NNN
Expand Down Expand Up @@ -1248,7 +1247,19 @@ def create_extract_track_blob_info(hitc):
return create_extract_track_blob_info


def compute_and_write_tracks_info(paolina_params, h5out):
def compute_and_write_tracks_info(paolina_params, h5out,
hit_type, filter_hits_table_name='hits_select',
write_paolina_hits=None):

filter_events_nohits = fl.map(lambda x : len(x.hits) > 0,
args = 'hits',
out = 'hits_passed')
hits_passed = fl.count_filter(bool, args="hits_passed")


copy_Efield = fl.map(Efield_copier(hit_type),
args = 'hits',
out = 'Ep_hits')

# Create tracks and compute topology-related information
create_extract_track_blob_info = fl.map(track_blob_info_creator_extractor(**paolina_params),
Expand All @@ -1271,18 +1282,22 @@ def compute_and_write_tracks_info(paolina_params, h5out):
write_tracks = fl.sink( track_writer (h5out=h5out) , args="topology_info" )
write_summary = fl.sink( summary_writer (h5out=h5out) , args="event_info" )
write_topology_filter = fl.sink( event_filter_writer(h5out, "topology_select"), args=("event_number", "topology_passed" ))
write_hits_paolina = fl.sink( hits_writer (h5out, group_name="CHITS", table_name="highTh")
, args="paolina_hits" )

write_no_hits_filter = fl.sink( event_filter_writer(h5out, filter_hits_table_name), args=("event_number", "hits_passed"))


fn_list = (create_extract_track_blob_info ,
fn_list = (filter_events_nohits ,
fl.branch(write_no_hits_filter) ,
hits_passed. filter ,
copy_Efield ,
create_extract_track_blob_info ,
filter_events_topology ,
fl.branch(make_final_summary, write_summary),
fl.branch(write_topology_filter) ,
fl.branch(write_hits_paolina) ,
write_paolina_hits ,
events_passed_topology. filter ,
fl.branch(write_tracks) ,)
fl.branch(write_tracks) )

compute_tracks = pipe(*fn_list)
compute_tracks = pipe(*filter(None, fn_list))

return compute_tracks
26 changes: 8 additions & 18 deletions invisible_cities/cities/esmeralda.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from . components import collect
from . components import copy_mc_info
from . components import hits_and_kdst_from_files
from . components import Efield_copier
from . components import compute_and_write_tracks_info

from .. types. ic_types import xy
Expand Down Expand Up @@ -190,23 +189,13 @@ def esmeralda(files_in, file_out, compression, event_range, print_mod,
out = 'cor_low_th_hits')

threshold_and_correct_hits_high = fl.map(hits_threshold_and_corrector(threshold_charge=cor_hits_params['threshold_charge_high'], **cor_hits_params_),
args = 'hits',
out = 'cor_high_th_hits')
item = 'hits')

filter_events_low_th = fl.map(lambda x : len(x.hits) > 0,
args = 'cor_low_th_hits',
out = 'low_th_hits_passed')

filter_events_high_th = fl.map(lambda x : len(x.hits) > 0,
args = 'cor_high_th_hits',
out = 'high_th_hits_passed')

hits_passed_low_th = fl.count_filter(bool, args="low_th_hits_passed")
hits_passed_high_th = fl.count_filter(bool, args="high_th_hits_passed")

copy_Efield = fl.map(Efield_copier(evm.HitEnergy.Ec),
args = 'cor_high_th_hits',
out = 'Ep_hits')

event_count_in = fl.spy_count()
event_count_out = fl.count()
Expand All @@ -218,13 +207,18 @@ def esmeralda(files_in, file_out, compression, event_range, print_mod,

write_hits_low_th = fl.sink( hits_writer (h5out, group_name='CHITS', table_name='lowTh'),
args="cor_low_th_hits")
write_hits_paolina = fl.sink( hits_writer (h5out, group_name="CHITS", table_name="highTh" ),
args="paolina_hits" )
write_hits_paolina_ = fl.branch(write_hits_paolina)

write_high_th_filter = fl.sink( event_filter_writer(h5out, "high_th_select" ) , args=("event_number", "high_th_hits_passed"))
write_low_th_filter = fl.sink( event_filter_writer(h5out, "low_th_select" ) , args=("event_number", "low_th_hits_passed" ))
write_kdst_table = fl.sink( kdst_from_df_writer(h5out) , args="kdst" )


compute_tracks = compute_and_write_tracks_info(paolina_params, h5out)
compute_tracks = compute_and_write_tracks_info(paolina_params, h5out,
hit_type = evm.HitEnergy.Ec,
filter_hits_table_name = "high_th_select",
write_paolina_hits = write_hits_paolina_)

evtnum_collect = collect()

Expand All @@ -241,10 +235,6 @@ def esmeralda(files_in, file_out, compression, event_range, print_mod,
hits_passed_low_th.filter ,
write_hits_low_th ),
threshold_and_correct_hits_high ,
filter_events_high_th ,
fl.branch(write_high_th_filter) ,
hits_passed_high_th .filter ,
copy_Efield ,
compute_tracks ,
"event_number" ,
event_count_out .sink ),
Expand Down
19 changes: 1 addition & 18 deletions invisible_cities/cities/isaura.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
from . components import copy_mc_info
from . components import dhits_from_files
from . components import compute_and_write_tracks_info
from . components import Efield_copier

from .. evm.event_model import HitEnergy

from .. io.run_and_event_io import run_and_event_writer
from .. io.event_filter_io import event_filter_writer



Expand Down Expand Up @@ -88,31 +86,16 @@ def isaura(files_in, file_out, compression, event_range, print_mod,
with tb.open_file(file_out, "w", filters=tbl.filters(compression)) as h5out:

write_event_info = fl.sink(run_and_event_writer(h5out), args=("run_number", "event_number", "timestamp"))
write_no_hits_filter = fl.sink( event_filter_writer(h5out, "hits_select" ) , args=("event_number", "hits_passed"))

evtnum_collect = collect()

filter_events_nohits = fl.map(lambda x : len(x.hits) > 0,
args = 'hits',
out = 'hits_passed')
hits_passed = fl.count_filter(bool, args="hits_passed")


copy_Efield = fl.map(Efield_copier(HitEnergy.E),
args = 'hits',
out = 'Ep_hits')

compute_tracks = compute_and_write_tracks_info(paolina_params, h5out)
compute_tracks = compute_and_write_tracks_info(paolina_params, h5out, hit_type=HitEnergy.E)

result = push(source = dhits_from_files(files_in),
pipe = pipe(fl.slice(*event_range, close_all=True) ,
print_every(print_mod) ,
event_count_in .spy ,
fl.branch("event_number", evtnum_collect.sink),
filter_events_nohits ,
fl.branch(write_no_hits_filter) ,
hits_passed. filter ,
copy_Efield ,
compute_tracks ,
event_count_out .spy ,
write_event_info ),
Expand Down

0 comments on commit 3e8742e

Please sign in to comment.