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

Add LCIO to EDM4hep conversion functionality #11

Merged
merged 87 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
07ab63c
Add LCIO to EDM4hep conversion functionality
FinnJohannsen Feb 22, 2023
5a9d333
Minor cleanups
tmadlener Feb 22, 2023
402a92b
Add new header to PUBLIC_HEADER of target
tmadlener Feb 22, 2023
00f78f9
Make object mapping names easier to read
tmadlener Feb 23, 2023
3a1b768
Remove unnecessary temp variables
tmadlener Feb 23, 2023
589c047
Remove unnecessary nullptr check
tmadlener Feb 23, 2023
cad698e
Add particleID relation resolution for RecoParticles
tmadlener Feb 23, 2023
defd6cf
Comment unnecessary loop until underlying issue is resolved
tmadlener Feb 23, 2023
4e42c41
Convert ParticleIDs as part of the ReconstructedParticles
tmadlener Feb 23, 2023
d4c0e65
Format commented code block
tmadlener Feb 23, 2023
75bed64
Add include guards
tmadlener Feb 23, 2023
76e1296
Add library for basic comparisons of LCIO and EDM4hep
tmadlener Feb 23, 2023
4523cb2
Cleanup and clarification of simulator status
tmadlener Feb 23, 2023
87155c9
Fix typo in function name
tmadlener Feb 23, 2023
232325b
Add a standalone executable for converting LCIO to EDM4hep
FinnJohannsen Feb 23, 2023
1763077
Move comparison library to subfolder
tmadlener Feb 23, 2023
5813008
Add executable for comparing lcio and edm4hep file contents
FinnJohannsen Feb 23, 2023
77f7346
Add nullptr check
tmadlener Feb 23, 2023
b5aacff
Change TPCHit -> RawTimeSeries
jmcarcell Mar 6, 2023
aa29c4c
Adding ParticleID to Collections
FinnJohannsen Feb 27, 2023
8b4bc01
Added a Nullptr check before every map lookup to make what we are loo…
FinnJohannsen Mar 1, 2023
4606481
[clang-format] Format fixes
tmadlener Mar 7, 2023
01ec81b
made a seperate function to create simCaloHitContributionCollections
FinnJohannsen Mar 13, 2023
d529718
changed the name of the createCaloHitContributions to be in line with…
FinnJohannsen Mar 13, 2023
ec4b331
[clang-format] Fix formatting
tmadlener Mar 13, 2023
991cd4e
some small adjustments to names and docstrings
FinnJohannsen Mar 15, 2023
4ffaf81
restoring file
FinnJohannsen Mar 15, 2023
1351d58
some small changes to names and error messages
FinnJohannsen Mar 15, 2023
8ca79c4
Fixing a typo making the Associations not work
FinnJohannsen Mar 15, 2023
76f0d57
slight change to the interface of convertSimCalorimeterHit to make it…
FinnJohannsen Mar 20, 2023
987af8a
Only add MCParticle if there is one to add
tmadlener Mar 20, 2023
bc369f0
Rename output collection
tmadlener Mar 20, 2023
a058fa2
Add .vscode folder to .gitignore
FinnJohannsen Mar 22, 2023
9cb6427
Change to the tests to handle LCrelations without from type.
FinnJohannsen Mar 22, 2023
379afee
Chnage in compare for Vectors to make it nan safe.
FinnJohannsen Mar 22, 2023
76216a9
ome debug messages
FinnJohannsen Apr 3, 2023
24c2df8
removing some debug prints
FinnJohannsen Apr 3, 2023
f2079ba
adding a conversion of the EventHeader and its data
FinnJohannsen Apr 3, 2023
a9c125f
changed the tests to also check for same EventHeader information.
FinnJohannsen Apr 5, 2023
6132b05
[clang-format] Fix style
tmadlener Apr 12, 2023
ea8f727
change to the reading of patch Files to ignore spaces infront of type…
FinnJohannsen Apr 17, 2023
09b8a7c
removal of some debug output
FinnJohannsen Apr 17, 2023
98c1a54
removing alternative reading function
FinnJohannsen Apr 17, 2023
ef708df
Avoid unnecessary string copies
tmadlener Apr 17, 2023
3e46e9b
Remove debug try-catch block
tmadlener Apr 17, 2023
b704658
[clang-format] Fix formatting
tmadlener Apr 17, 2023
b7b81ef
Add a warning for missing From/ToType when converting relations
tmadlener Apr 17, 2023
1b08060
change to the reading of patch Files to ignore spaces infront of type…
FinnJohannsen Apr 17, 2023
1a1a669
removal of some debug output
FinnJohannsen Apr 17, 2023
97a9456
removing alternative reading function
FinnJohannsen Apr 17, 2023
8a7bd10
Avoid unnecessary string copies
tmadlener Apr 17, 2023
d30b363
Remove debug try-catch block
tmadlener Apr 17, 2023
ab8a3d3
[clang-format] Fix formatting
tmadlener Apr 17, 2023
da2d34a
Add a warning for missing From/ToType when converting relations
tmadlener Apr 17, 2023
8643c12
Create README.md
FinnJohannsen Apr 24, 2023
fa31c89
Avoid unnecessary string copies
tmadlener Apr 17, 2023
49be81c
[clang-format] Fix formatting
tmadlener Apr 17, 2023
e45bf00
fixing of some typos
FinnJohannsen Apr 26, 2023
e1f5394
fixing an error in the reading of files that had trailing whitespaces…
FinnJohannsen May 3, 2023
915199e
Merge branch 'add-lcioconv' into read-fix
tmadlener May 3, 2023
3a177dd
updating the README
FinnJohannsen May 3, 2023
3a68e67
[clang-format] Fix formatting
tmadlener May 3, 2023
daf488f
Update documentation
tmadlener May 3, 2023
61fe9dd
Add documentation and fix LCRelation conversions
tmadlener May 3, 2023
96ff112
Merge branch 'master' into add-lcioconv
tmadlener May 3, 2023
0c69f86
more documentation
FinnJohannsen May 15, 2023
6fba945
added an example to the doc and merged two documentations.
FinnJohannsen May 15, 2023
65affeb
fixing some typos and changing SubSet into Subset for consistency.
FinnJohannsen May 15, 2023
f2c03f7
changing SubSet to Subset for consistency
FinnJohannsen May 15, 2023
614f15f
adjustments to the documentation file
FinnJohannsen May 17, 2023
7cf119d
first attempt of converting LCIntVec collection, compiles and runs af…
FinnJohannsen May 17, 2023
d14632c
Added a conversion for LCFloatVec and LCIntVec Collections.
FinnJohannsen May 22, 2023
ed6bf4e
conversion of the event parameters
FinnJohannsen May 22, 2023
e377bdc
changed the conversion of LCVec's to a template
FinnJohannsen May 24, 2023
4c28fe0
change of convertEventParameters function to be more generall
FinnJohannsen May 24, 2023
0e04d40
Update k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepCo…
tmadlener May 24, 2023
0443519
Update doc/LCIO2EDM4hep.md
tmadlener May 24, 2023
19348fb
[format] Format cleanup, small re-org and README clarifications
tmadlener May 24, 2023
f1bfca3
Minor overhaul of documentation
tmadlener May 24, 2023
6ae5623
[format] Whitespace cleanup
tmadlener May 24, 2023
a6ce31e
Rename conversion functions for less ambiguity
tmadlener May 26, 2023
bb79f53
Add conversion of MCRecoCaloParticleAssociations
tmadlener Jun 2, 2023
366411d
Conversion of information in LCRunHeader
FinnJohannsen May 24, 2023
44e8ae0
Conversion of ParticleIDs of the Cluster Collection
FinnJohannsen May 31, 2023
326be85
Merge branch 'master' into add-lcioconv
tmadlener Jun 7, 2023
189cddb
Fix capitalization of subdetectorHitNumbers
tmadlener Jun 7, 2023
93012b4
Adapt to podio change to string_views
tmadlener Jun 13, 2023
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ install*
*.app

# CMake generated
Testing
Testing

# Tooling
.vscode
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ find_package(LCIO REQUIRED)
find_package(EDM4HEP REQUIRED)

add_subdirectory(k4EDM4hep2LcioConv)
add_subdirectory(standalone)

include(CTest)
if (BUILD_TESTING)
add_subdirectory(tests)
endif()

include(cmake/k4EDM4hep2LcioConvCreateConfig.cmake)
125 changes: 125 additions & 0 deletions doc/LCIO2EDM4hep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Standalone conversion from LCIO to EDM4hep
The `lcio2edm4hep` executable reads LCIO (`.slcio`) files and converts its
contents into EDM4hep. Each `LCEvent` of the input file will be put into a
`podio::Frame` in the output file (under the `events` category). The most basic
usage is simply

```bash
lcio2edm4hep <input.slcio> <output.edm4hep.root>
```

## Patching missing collections on the fly
A major difference between LCIO and EDM4hep is that in LCIO an `LCEvent` can
effectively have arbitrary contents, whereas in EDM4hep the assumption is that
each event consists of the same collections (even if some of them are empty).
Hence, it is necessary to either ensure that all events in the LCIO file have
the same contents or or to give `lcio2edm4hep` some additional information such
that it can patch in potentially missing collections on the fly. This additional
information comes in the form of a third argument to `lcio2edm4hep` and is
effectively a list of collection names and their types that comprise the
superset of all collectoins appearing in at least one event in the input LCIO
file. The format looks like this, where each collection is a single line
containing the name first and than its type, e.g.

```
SETSpacePoints TrackerHit
RecoMCTruthLink LCRelation[ReconstructedParticle,MCParticle]
```

The easiest way to obtain such a file is to use the `check_missing_cols`
executable that comes with LCIO using the `--minimal` flag. The output of this
can be directly consumed by `lcio2edm4hep`

#### Example:
1. Get the patch file
```bash
check_missing_cols --minimal \
/pnfs/desy.de/ilc/prod/ilc/mc-2020/ild/rec/250-SetA/higgs/ILD_l5_o2_v02/v02-02-01/00015671/000/rv02-02-01.sv02-02-01.mILD_l5_o2_v02.E250-SetA.I402005.Pe3e3h.eL.pR.n000_002.d_rec_00015671_493.slcio \
> patch.txt
```
2. Pass it to `lcio2edm4hep`
```bash
lcio2edm4hep \
/pnfs/desy.de/ilc/prod/ilc/mc-2020/ild/rec/250-SetA/higgs/ILD_l5_o2_v02/v02-02-01/00015671/000/rv02-02-01.sv02-02-01.mILD_l5_o2_v02.E250-SetA.I402005.Pe3e3h.eL.pR.n000_002.d_rec_00015671_493.slcio \
Output.root \
patch.txt
```

### Converting `LCRelation` collections
For collections of `LCRelation` type it is necessary to define the `FromType` and
`ToType` as well, as otherwise the converter will not be able to create the
correct edm4hep file. The `check_missing_cols` executable will try to determine
these types from the collection parameters and will warn if it cannot do it for
certain collections. In this case it is the **users responsibility to provide
the missing types** as otherwise the conversion will simply skip these
collections, or potentially even crash.


# Library usage of the conversion functions
The conversion functions are designed to also be usable as a library. The overall design is to make the conversion a two step process. Step one is converting the data and step two being the resolving of the relations and filling of subset collection.

## Converting collection (data)
The main entry point is `convertCollection` which will automatically dispatch to
the correct conversion function depending on the type information that is stored
in the input `LCCollection`. It is also possible to access the individual
conversion functions for each type. All of the conversion functions take a map
of LCIO to EDM4hep objects of their specific type that will be filled during the
conversion. for convenience all necessary maps are bundled in the
`LcioEdmTypeMapping` struct.

## Handling relations
**Once all necessary collections have been converted, it is necessary to resolve
the relations between the obects.** This is done using the `resolveRelations`
function. This will again dispatch to the correct relation resolving function
for the corresponding types, which can obviously also be invoked directly.

## Handling of subset collections
Subset collections are handled similar to relations using the function
`fillSubset`. Internally this simply forwards to `handleSubsetColl` which
handles all the type details and can obviously also be used directly.

## Handling of `LCRelation`s
`LCRelation` only exist in LCIO and their conversion is limited to what is
available in EDM4hep. They use the `"FromType"` and `"ToType"` collection
parameters to get the necessary type information.

The AssociationCollections in EDM4hep are then created using `createAssociations`.

## Converting entire events
Converting an entire event can be done calling the `convertEvent`. This can also
be used as an example to guide the implementation of custom conversions using
the available functionality.

## Converting Event parameters
This can be done by calling `convertObjectParameters` that will put all the event parameters into the passed `podio::Frame`.

## Subtle differences between LCIO and EDM4hep
There are a few small differences between LCIO and EDM4hep that shine through in the conversion, these are:

- `CaloHitContributions` are part of the SimCalorimeterHits in LCIO while being their own data type in EDM4hep. They are created by [`createCaloHitContributions`](../k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h).
- The event informaton like is part of the `LCEvent` in LCIO. In EDM4hep there is a separate EventHeader Collection. It can be created using [`EventHeaderCollection`](../k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h) which is stored under the name `"EventHeader"`.
- Particle IDs are converted during the conversion of the the reconstructed Particle collection.

## Example for a ReconstructedParticle Collection
```cpp
#include "k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h"

// the struct defined in the header file is used for the maps linking Lcio particles
// to their EDM counterparts.

auto typeMapping = LcioEdmTypeMapping{};

// We assume that this is a collection of ReconstructedParticles!
LCEVENT::LCCollection* lcCollection;

// Convert the data
auto edmCollections = convertReconstructedParticle("name",
lcCollection,
typeMapping.recoParticles,
typeMapping.particleIDs);

// Resolve relations (only converted objects will be available)
// This has to be called at the very end, after all collection data has been
// converted
resolveRelations(typeMapping);
```
7 changes: 5 additions & 2 deletions k4EDM4hep2LcioConv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
add_library(k4EDM4hep2LcioConv SHARED
src/k4EDM4hep2LcioConv.cpp)
src/k4EDM4hep2LcioConv.cpp
src/k4Lcio2EDM4hepConv.cpp
)

target_include_directories(k4EDM4hep2LcioConv PUBLIC
${LCIO_INCLUDE_DIRS}
Expand All @@ -12,7 +14,8 @@ target_link_libraries(k4EDM4hep2LcioConv PUBLIC

set_target_properties(${CMAKE_PROJECT_NAME}
PROPERTIES
PUBLIC_HEADER "include/${CMAKE_PROJECT_NAME}/k4EDM4hep2LcioConv.h")
PUBLIC_HEADER "include/${CMAKE_PROJECT_NAME}/k4EDM4hep2LcioConv.h;include/${CMAKE_PROJECT_NAME}/k4Lcio2EDM4hepConv.h"
)

install(TARGETS k4EDM4hep2LcioConv
EXPORT ${CMAKE_PROJECT_NAME}Targets
Expand Down
Loading