Skip to content

Conversation

@andLaing
Copy link
Collaborator

Adds functions to generate unique event numbers for MC to allow for safe processing of split nexus events and simplify MC event mixing.

In need of more tests and a file number reader but ready for discussion.

Discussion continues from issue #715

@mmkekic
Copy link
Collaborator

mmkekic commented Oct 30, 2020

This seems closely related to the Issue #145 and corresponding PRs:
#168 where a solution was to introduce first_event parameter in the configuration file and leave it up to a user to make sure the parameter is sensible;
#245 (3185e07) where we used hash on the input filename and
#255 where we used pattern matching to extract file index from one full production

The definite solution was to fix the issue in the NEXUS itself making sure that one production has a unique event count, however since now (probably before too?) we need to be able to split a long NEXUS event into shorter buffer-size events we are back to the problem of having to re-index events after the NEXUS production and ensure their uniqueness. Maybe @jacg and @jmbenlloch that were dealing with this problem in the past can give us some guidance?

@mmkekic
Copy link
Collaborator

mmkekic commented Nov 2, 2020

Since this is somewhat urgent and we lack a very appealing option, I am inclined to go with the simplest one for now, ie add one parameter in config file (either start_event_id or file_id) that will be used in the #752 too. If we opt for file_id we have to think of a unique pattern for event_number. @andLaing suggested something like int(f'{file_id}0{nexus_event_number}'), thought we might need more 0s in between to be certain this is unique. Suggestions @paolafer , @jmalbos , @msorel , @jjgomezcadenas .. ?

@mmkekic mmkekic requested a review from jmalbos November 4, 2020 19:37
@andLaing andLaing force-pushed the unique-mc-evtnumber branch from c656983 to 6a2cb85 Compare November 5, 2020 15:38
@andLaing
Copy link
Collaborator Author

andLaing commented Nov 5, 2020

In the current version the event numbers generated become int(f'{nexus_seed_from_config}00{nexus_start_id}' + str(counter)). Still some tests missing, higher level checks to make sure this format is enough needed too.

return -1


def copy_nexus_eventmap(h5out : tb.file.File,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mabe add 'safe_copy ...` since in case the table is not present you don't copy and the name is a bit misleading

for fn in files_in:
evt_map = load_eventnumbermap(fn)
try:
evt_mask = evt_map.evt_number.isin(evt_arr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a bit hard to understand. Can you add a comment that evt_map is None if the table is not present, and you are also protected against table present but with wrong columns?

except AttributeError:
## No copy and return the parts of the
## original arrays found.
if check_mc_present(fn):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need this check? This function should work with MC files, so the table has to be present. The copy_mc_info should take care it raises appropriate error/warning in case the table is not present. In case there is no MC table you probably do not even want to do any event mapping

event_numbers: List[int] ,
db_file : str ,
run_number : int ,
copy_eventmap: bool = True) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add new parameter to docstrings

def test_copy_nexus_eventmap(config_tmpdir, ICDATADIR):
file_in = os.path.join(ICDATADIR ,
'nexus_new_kr83m_full.newformat.buffers.h5')
file_out = os.path.join(ICDATADIR, 'evtMapCopy.h5')
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a temporary path, not ICDATADIR

@andLaing andLaing force-pushed the unique-mc-evtnumber branch from dd45b71 to c7aa5b6 Compare December 14, 2020 22:09
To be used to test MC copy and eventMap copy
where there are split nexus events.
Copy link
Collaborator

@mmkekic mmkekic left a comment

Choose a reason for hiding this comment

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

This PR adds a event splitting functionality keeping unique nexus event numbers across files by assuming a constant maximum number of splits per event. A new table that maps IC event number to original MC event number is added to Run group ensuring the code is compatible with the old formats of MC production. The code is documented and tested, good job!

@carmenromo carmenromo merged commit e0bc6de into next-exp:master Dec 21, 2020
@andLaing andLaing deleted the unique-mc-evtnumber branch December 21, 2020 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants