-
Notifications
You must be signed in to change notification settings - Fork 46
Description
This is a discussion topic to figure out what we want to do in this area, and eventually also how we would go about that.
Introduction
In LCIO there is the CellIDDecoder utility that allows to easily retrieve the encoded values from the cellID. This utility handles
- Retrieving the cell id encoding string from the collection (stored via parameters)
- parsing the string and splitting it into the different bits
- retrieving the specific value for one of the encoded cells, e.g.
const auto& fields = decoder(hit);
const auto layer = fields["layer"];Very similar functionality is available from DD4hep, with the BitFieldCoder.
Current status in EDM4hep
The LCIO CellIDDecoder is very much geared towards LCIO, as it relies on the fact that collection parameters are direcly attached to the collection. The DD4hep BitFieldCoder instead can be constructed from the encoding string.
The following is currently possible (using python here, but c++ works very much the same)
from podio.reading import get_reader
from dd4hep.core.DDSegmentation import BitFieldCoder
reader = get_reader("<input-file>")
metadata = reader.get("metadata")
metadata = metadata[0] # Working around https://github.com/AIDASoft/podio/issues/642
cell_id_encoding = metadata.get_parameter(f"{collection_name}__CellIDEncoding")
decoder = BitFieldCoder(cell_id_encoding)
events = reader.get("events")
event = events[0]
hits = event.get("hits")
layer = decoder.get(hits[0].getCellID(), "layer")
# or slightly more performant in tight loops
layer_index = decoder.index("layer")
layer = decoder.get(hits[0].getCellID(), layer_index)Things that should / could be improved
The following is a preliminarly list of things that could or maybe should be improved. IMO, some of them should definitely happen, others are much more open for discussion.
- String concatenation to get to the correct parameter name should be done via some helper function, e.g. https://github.com/AIDASoft/podio/blob/ec612dee213f0e0ef3584dcd6028f8a2427577a1/include/podio/FrameCategories.h#L21-L23
- We should also use the
edm4hep::labels::CellIDEncodingconstant for that instead of relying on hardcoding the string again
- We should also use the
- Should we have a utility function that returns the cell id encoding string directly from a reader and a given collection name?
- Should EDM4hep have a (re-)implementation of such a tool to not depend on external functionality (e.g. DD4hep)?
Finally, one thing that is not yet clear to me: How should all of this work inside the framework?