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 datatypes for storing generator (meta)data in a structured and defined way #310

Merged
merged 36 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a2a9bda
add GeneratorInformation definition
hegner May 22, 2024
cfcfbdd
remove typo
hegner May 22, 2024
3b7ae97
add better member documentation
hegner May 22, 2024
4338c77
cut of GeneratorPDFInfo
hegner May 22, 2024
9dd2355
add more explicit docs; fix types
hegner May 22, 2024
4d896d8
fix URL
hegner May 22, 2024
47e08e9
add new types to documentation and tests
hegner May 23, 2024
dd08dfb
add new generator data and metadata to the write example
hegner May 23, 2024
32c31ae
Update edm4hep.yaml
hegner May 23, 2024
bf612a5
include clang-format suggestions
hegner May 24, 2024
b4e56bf
Update include/edm4hep/GenToolInfo.h
hegner May 27, 2024
b44db85
Update include/edm4hep/GenToolInfo.h
hegner May 27, 2024
f992f4c
Update edm4hep.yaml
hegner May 27, 2024
c4fe0c8
Update include/edm4hep/GenToolInfo.h
hegner May 27, 2024
1f7ae9b
Update include/edm4hep/GenToolInfo.h
hegner May 27, 2024
4873b6f
include PR comments; improve test coverage
hegner May 28, 2024
34f1ddf
fix renamed class in readme file
hegner May 28, 2024
3067af3
move signalVertex member to generatorEventParameters
hegner Jun 4, 2024
be27423
add doc for generator information
hegner Jun 4, 2024
e329148
Merge branch 'main' into geninfo
hegner Jun 4, 2024
0e823ea
rename generator related members to fit naming conventions
hegner Jun 4, 2024
763bcd8
fix line numbers in README
hegner Jun 4, 2024
8823133
fix issues of pre-commit
hegner Jun 4, 2024
3ddd0c3
Update include/edm4hep/Constants.h
hegner Jun 11, 2024
0364ea6
Update include/edm4hep/GenToolInfo.h
hegner Jun 11, 2024
e9154e4
address PR comments about util namespaces and string naming convention
hegner Jun 11, 2024
a4bd341
parameters are now optional
hegner Jun 11, 2024
cc21262
Update test/read_events.h
hegner Jun 12, 2024
c7d5662
Update include/edm4hep/Constants.h
hegner Jun 12, 2024
1bd26b3
Merge branch 'main' into geninfo
tmadlener Jun 17, 2024
36726ec
Update all label spellings to compile again
tmadlener Jun 17, 2024
6985838
Rename GeneratorToolInfo for more consistency
tmadlener Jun 17, 2024
3aa87f3
Add documentation to generator tool info handling utilities
tmadlener Jun 17, 2024
921c5bd
Rename header for consistency and fix occurences
tmadlener Jun 17, 2024
8d33ff2
Pluralize labels
tmadlener Jun 17, 2024
4a9d409
Pluralize all usages
tmadlener Jun 17, 2024
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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ A generic event data model for future HEP collider experiments.
| [MCRecoTrackerHitPlaneAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L641) | [MCRecoCaloParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L650) | [MCRecoClusterParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L659) |
| [MCRecoTrackParticleAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L668) | [RecoParticleVertexAssociation](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L677) | |

**Generator related (meta-)data**

| | | |
|-|-|-|
| [GeneratorParameters](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L787) | | |
| [GeneratorPdfInfo](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L801) | | |

**Interfaces**

| | | |
|-|-|-|
| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L784) | | |
| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L813) | | |


The tests and examples in the `tests` directory show how to read, write, and use these types in your code.
Expand Down
30 changes: 30 additions & 0 deletions edm4hep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,36 @@ datatypes:
OneToOneRelations:
- edm4hep::Track track // the corresponding track


#===== Generator related data =====

#---------- GeneratorParameters
edm4hep::GeneratorParameters:
Description: "Generator parameters"
Author: "EDM4hep authors"
Members:
- double event_scale // event scale
hegner marked this conversation as resolved.
Show resolved Hide resolved
- double alphaQED // alpha_QED
- double alphaQCD // alpha_QCD
- int signal_process_id // id of signal process
hegner marked this conversation as resolved.
Show resolved Hide resolved
- double sqrt_s [GeV] // sqrt(s)
hegner marked this conversation as resolved.
Show resolved Hide resolved
VectorMembers:
- double crossSections // list of cross sections in pb
- double crossSectionErrors // list of cross section errors
hegner marked this conversation as resolved.
Show resolved Hide resolved

#---------- GeneratorPdfInfo
edm4hep::GeneratorPdfInfo:
Description: "Generator pdf information"
Author: "EDM4hep authors"
Members:
- std::array<int, 2> parton_id // Parton PDG id
hegner marked this conversation as resolved.
Show resolved Hide resolved
- std::array<int, 2> id // LHAPDF PDF id (see https://lhapdf.hepforge.org/pdfsets.html)
hegner marked this conversation as resolved.
Show resolved Hide resolved
- std::array<double, 2> x // Parton momentum fraction
- std::array<double, 2> xf // PDF value
- double scale [GeV] // Factorisation scale
OneToManyRelations:
- edm4hep::MCParticle signal_vertex // pointing into MC Generators collection
hegner marked this conversation as resolved.
Show resolved Hide resolved

interfaces:
edm4hep::TrackerHit:
Description: "Tracker hit interface class"
Expand Down
47 changes: 47 additions & 0 deletions include/edm4hep/GenToolInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef EDM4HEP_GENTOOLINFO_H
hegner marked this conversation as resolved.
Show resolved Hide resolved
#define EDM4HEP_GENTOOLINFO_H

#include "podio/Frame.h"
#include "Constants.h"
hegner marked this conversation as resolved.
Show resolved Hide resolved
#include <string>
#include <vector>

namespace edm4hep {

struct GenToolInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

The classes we define in the yaml file are all prefixed Generator, but this one is Gen. For consistency reasons, I think they should both be the same. The choice is also related with how we want to name the constants.

std::string name;
std::string version;
std::string description;
};

tmadlener marked this conversation as resolved.
Show resolved Hide resolved
const std::vector<GenToolInfo> getGenToolInfos(podio::Frame& frame) {
auto toolInfos = std::vector<GenToolInfo>();
auto names = frame.getParameter<std::string>("name");
auto versions = frame.getParameter<std::string>("version");
auto descriptions = frame.getParameter<std::string>("description");
hegner marked this conversation as resolved.
Show resolved Hide resolved
for (unsigned int i = 0; i < names.size(); ++i) {
auto toolInfo = GenToolInfo();
toolInfo.name = names[i];
toolInfo.version = versions[i];
toolInfo.description = descriptions[i];
hegner marked this conversation as resolved.
Show resolved Hide resolved
}
return toolInfos;
};

void putGenToolInfos(podio::Frame& frame, std::vector<GenToolInfo>& toolInfos) {
auto names = std::vector<std::string>();
auto versions = std::vector<std::string>();
auto descriptions = std::vector<std::string>();
for (auto& toolInfo : toolInfos){
names.push_back(toolInfo.name);
versions.push_back(toolInfo.version);
descriptions.push_back(toolInfo.description);
}
frame.putParameter("name", names);
frame.putParameter("version", versions);
frame.putParameter("description", descriptions);
hegner marked this conversation as resolved.
Show resolved Hide resolved
};

hegner marked this conversation as resolved.
Show resolved Hide resolved
} // namespace edm4hep

#endif // EDM4HEP_GENTOOLINFO_H
40 changes: 40 additions & 0 deletions test/write_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#define EDM4HEP_TEST_WRITE_EVENTS_H

// Data model

#include "edm4hep/CaloHitContributionCollection.h"
#include "edm4hep/GenToolInfo.h"
#include "edm4hep/GeneratorParametersCollection.h"
#include "edm4hep/GeneratorPdfInfoCollection.h"
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/RawTimeSeriesCollection.h"
#include "edm4hep/SimCalorimeterHitCollection.h"
Expand All @@ -28,6 +32,7 @@ void write(std::string outfilename) {
for (unsigned i = 0; i < nevents; ++i) {
std::cout << " --- processing event " << i << std::endl;
auto event = podio::Frame();
auto run = podio::Frame();

// place the following generator event to the MCParticle collection
//
Expand Down Expand Up @@ -108,6 +113,40 @@ void write(std::string outfilename) {
}
}

//===============================================================================
// write some generator event data
auto genParametersCollection = edm4hep::GeneratorParametersCollection();
auto genParam = genParametersCollection.create();
genParam.setEvent_scale(23);
genParam.setAlphaQED(1 / 127);
genParam.setAlphaQCD(0.1);
genParam.setSignal_process_id(42);
genParam.setSqrt_s(90);
genParam.addToCrossSections(10);
genParam.addToCrossSectionErrors(3);
event.put(std::move(genParametersCollection), "GeneratorParameters");

auto genPdfInfoCollection = edm4hep::GeneratorPdfInfoCollection();
auto genPdfInfo = genPdfInfoCollection.create();
genPdfInfo.setParton_id(1, 2);
genPdfInfo.setId({20, 20});
genPdfInfo.setX({0.5, 0.5});
genPdfInfo.setXf({0.5, 0.5});
genPdfInfo.setScale(23);
genPdfInfo.addToSignal_vertex(mcp1);
genPdfInfo.addToSignal_vertex(mcp2);
event.put(std::move(genPdfInfoCollection), "GeneratorPdfInfo");

//===============================================================================
// write some generator tool info into the run
auto toolInfos = std::vector<edm4hep::GenToolInfo>();
auto toolInfo = edm4hep::GenToolInfo();
toolInfo.name = "something";
toolInfo.version = "v1";
toolInfo.description = "some tool";
toolInfos.emplace_back(std::move(toolInfo));
edm4hep::putGenToolInfos(run, toolInfos);

// fixme: should this become a utility function ?
//-------------------------------------------------------------

Expand Down Expand Up @@ -237,6 +276,7 @@ void write(std::string outfilename) {
event.putParameter("EventType", "test");

writer.writeFrame(event, "events");
writer.writeFrame(run, "runs");
}

writer.finish();
Expand Down
8 changes: 8 additions & 0 deletions tools/include/edm4hep2json.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "edm4hep/CalorimeterHitCollection.h"
#include "edm4hep/ClusterCollection.h"
#include "edm4hep/EventHeaderCollection.h"
#include "edm4hep/GeneratorParametersCollection.h"
#include "edm4hep/GeneratorPdfInfoCollection.h"
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/ParticleIDCollection.h"
#include "edm4hep/RawCalorimeterHitCollection.h"
Expand Down Expand Up @@ -154,6 +156,12 @@ nlohmann::json processEvent(const podio::Frame& frame, std::vector<std::string>&
insertIntoJson<podio::UserDataCollection<uint32_t>>(jsonDict, coll, collList[i]);
} else if (coll->getTypeName() == "podio::UserDataCollection<uint64_t>") {
insertIntoJson<podio::UserDataCollection<uint64_t>>(jsonDict, coll, collList[i]);
}
// Generator (meta-)data
else if (coll->getTypeName() == "podio::GeneratorParametersCollection") {
insertIntoJson<edm4hep::GeneratorParametersCollection>(jsonDict, coll, collList[i]);
} else if (coll->getTypeName() == "podio::GeneratorPdfInfoCollection") {
insertIntoJson<edm4hep::GeneratorPdfInfoCollection>(jsonDict, coll, collList[i]);
} else {
std::cout << "WARNING: Collection type not recognized!\n"
<< " " << coll->getTypeName() << "\n";
Expand Down
Loading