From a2a9bda79108389f790aa053efb1b42ce59b257b Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Wed, 22 May 2024 09:47:03 +0200 Subject: [PATCH 01/34] add GeneratorInformation definition --- edm4hep.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/edm4hep.yaml b/edm4hep.yaml index 0db016be4..b10ed44ce 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -780,6 +780,31 @@ datatypes: OneToOneRelations: - edm4hep::Track track // the corresponding track + + #===== Generator related data ===== + + #---------- + edm4hep::GeneratorParameters + Description: "Generator parameters" + Author: "EDM4hep authors" + Members: + - double event_scale // event scale + - double alphaQED // alpha_QED + - double alphaQCD // alpha_QCD + - int signal_process_id // id of signal process + - double PDF_scale // PDF scale + - double sqrt_s // sqrt(s) + VectorMembers: + - double crossSections + - double crossSectionErrors + - double PDF_parton_id // PDF parton id + - double PDX_x // PDF x + - double PDF_xf // PDF xf + - double PDF_id // PDF id + OneToOneRelations: + - MCParticle signal_vertex // pointing into MC Generators collection + + interfaces: edm4hep::TrackerHit: Description: "Tracker hit interface class" From cfcfbdd409263b9d268ef2d33d64521737153045 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Wed, 22 May 2024 10:25:32 +0200 Subject: [PATCH 02/34] remove typo --- edm4hep.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index b10ed44ce..c84c28ca8 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -784,7 +784,7 @@ datatypes: #===== Generator related data ===== #---------- - edm4hep::GeneratorParameters + edm4hep::GeneratorParameters: Description: "Generator parameters" Author: "EDM4hep authors" Members: From 3b7ae97789abf66af2a1be233f825253c3edc592 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Wed, 22 May 2024 10:54:54 +0200 Subject: [PATCH 03/34] add better member documentation --- edm4hep.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index c84c28ca8..6e1d9debf 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -795,8 +795,8 @@ datatypes: - double PDF_scale // PDF scale - double sqrt_s // sqrt(s) VectorMembers: - - double crossSections - - double crossSectionErrors + - double crossSections // list of cross sections + - double crossSectionErrors // list of cross section errors - double PDF_parton_id // PDF parton id - double PDX_x // PDF x - double PDF_xf // PDF xf From 4338c770f5386c367e44a429c6e0cb82b048be42 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Wed, 22 May 2024 11:04:47 +0200 Subject: [PATCH 04/34] cut of GeneratorPDFInfo --- edm4hep.yaml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index 6e1d9debf..a68935cf4 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -783,7 +783,7 @@ datatypes: #===== Generator related data ===== - #---------- + #---------- GeneratorParameters edm4hep::GeneratorParameters: Description: "Generator parameters" Author: "EDM4hep authors" @@ -792,18 +792,23 @@ datatypes: - double alphaQED // alpha_QED - double alphaQCD // alpha_QCD - int signal_process_id // id of signal process - - double PDF_scale // PDF scale - double sqrt_s // sqrt(s) VectorMembers: - double crossSections // list of cross sections - double crossSectionErrors // list of cross section errors - - double PDF_parton_id // PDF parton id - - double PDX_x // PDF x - - double PDF_xf // PDF xf - - double PDF_id // PDF id - OneToOneRelations: - - MCParticle signal_vertex // pointing into MC Generators collection + #---------- GeneratorPdfInfo + edm4hep::GeneratorPdfInfo: + Description: "Generator pdf information" + Author: "EDM4hep authors" + Members: + - std::array parton_id // PDF parton id + - std::array x // PDF x + - std::array xf // PDF xf + - std::array id // PDF id + - double scale // PDF scale + OneToManyRelations: + - MCParticle signal_vertex // pointing into MC Generators collection interfaces: edm4hep::TrackerHit: From 9dd23556ac91467237c1cbb1bf84ce8fe5cfab4c Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Wed, 22 May 2024 22:27:53 +0200 Subject: [PATCH 05/34] add more explicit docs; fix types --- edm4hep.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index a68935cf4..d38b63a23 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -794,7 +794,7 @@ datatypes: - int signal_process_id // id of signal process - double sqrt_s // sqrt(s) VectorMembers: - - double crossSections // list of cross sections + - double crossSections // list of cross sections in pb - double crossSectionErrors // list of cross section errors #---------- GeneratorPdfInfo @@ -802,11 +802,11 @@ datatypes: Description: "Generator pdf information" Author: "EDM4hep authors" Members: - - std::array parton_id // PDF parton id - - std::array x // PDF x - - std::array xf // PDF xf - - std::array id // PDF id - - double scale // PDF scale + - std::array parton_id // Parton PDG id + - std::array id // LHAPDF PDF id (see http:///projects.hepforge.org/lhapdf/PDFsets.index) + - std::array x // Parton momentum fraction + - std::array xf // PDF value + - double scale [GeV] // Factorisation scale OneToManyRelations: - MCParticle signal_vertex // pointing into MC Generators collection From 4d896d879c005302228eb5e76782f218bde829a2 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Wed, 22 May 2024 22:29:45 +0200 Subject: [PATCH 06/34] fix URL --- edm4hep.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index d38b63a23..8ae91e3c7 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -803,7 +803,7 @@ datatypes: Author: "EDM4hep authors" Members: - std::array parton_id // Parton PDG id - - std::array id // LHAPDF PDF id (see http:///projects.hepforge.org/lhapdf/PDFsets.index) + - std::array id // LHAPDF PDF id (see https://lhapdf.hepforge.org/pdfsets.html) - std::array x // Parton momentum fraction - std::array xf // PDF value - double scale [GeV] // Factorisation scale From 47e08e94446802eab990e3861765bc987ace8465 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Thu, 23 May 2024 18:31:53 +0200 Subject: [PATCH 07/34] add new types to documentation and tests --- README.md | 9 ++++++++- edm4hep.yaml | 12 ++++++------ tools/include/edm4hep2json.hxx | 8 ++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 98c90415e..fae8ddfbc 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/edm4hep.yaml b/edm4hep.yaml index 8ae91e3c7..57e5bcb85 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -802,13 +802,13 @@ datatypes: Description: "Generator pdf information" Author: "EDM4hep authors" Members: - - std::array parton_id // Parton PDG id - - std::array id // LHAPDF PDF id (see https://lhapdf.hepforge.org/pdfsets.html) - - std::array x // Parton momentum fraction - - std::array xf // PDF value - - double scale [GeV] // Factorisation scale + - std::array parton_id // Parton PDG id + - std::array id // LHAPDF PDF id (see https://lhapdf.hepforge.org/pdfsets.html) + - std::array x // Parton momentum fraction + - std::array xf // PDF value + - double scale [GeV] // Factorisation scale OneToManyRelations: - - MCParticle signal_vertex // pointing into MC Generators collection + - edm4hep::MCParticle signal_vertex // pointing into MC Generators collection interfaces: edm4hep::TrackerHit: diff --git a/tools/include/edm4hep2json.hxx b/tools/include/edm4hep2json.hxx index 0849453de..4e510ecd9 100644 --- a/tools/include/edm4hep2json.hxx +++ b/tools/include/edm4hep2json.hxx @@ -5,6 +5,8 @@ #include "edm4hep/CaloHitContributionCollection.h" #include "edm4hep/CalorimeterHitCollection.h" #include "edm4hep/ClusterCollection.h" +#include "edm4hep/GeneratorParametersCollection.h" +#include "edm4hep/GeneratorPdfInfoCollection.h" #include "edm4hep/EventHeaderCollection.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/ParticleIDCollection.h" @@ -154,6 +156,12 @@ nlohmann::json processEvent(const podio::Frame& frame, std::vector& insertIntoJson>(jsonDict, coll, collList[i]); } else if (coll->getTypeName() == "podio::UserDataCollection") { insertIntoJson>(jsonDict, coll, collList[i]); + } + // Generator (meta-)data + else if (coll->getTypeName() == "podio::GeneratorParametersCollection") { + insertIntoJson(jsonDict, coll, collList[i]); + } else if (coll->getTypeName() == "podio::GeneratorPdfInfoCollection") { + insertIntoJson(jsonDict, coll, collList[i]); } else { std::cout << "WARNING: Collection type not recognized!\n" << " " << coll->getTypeName() << "\n"; From dd08dfb5421f96951e5cdcecb6b85c7ff3a0d00a Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Thu, 23 May 2024 21:36:28 +0200 Subject: [PATCH 08/34] add new generator data and metadata to the write example --- include/edm4hep/GenToolInfo.h | 48 +++++++++++++++++++++++++++++++++++ test/write_events.h | 39 ++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 include/edm4hep/GenToolInfo.h diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h new file mode 100644 index 000000000..687d4a600 --- /dev/null +++ b/include/edm4hep/GenToolInfo.h @@ -0,0 +1,48 @@ +#ifndef EDM4HEP_GENTOOLINFO_H +#define EDM4HEP_GENTOOLINFO_H + +#include +#include +#include "podio/Frame.h" +#include "Constants.h" + + +namespace edm4hep { + +struct GenToolInfo { + std::string name; + std::string version; + std::string description; +}; + +const std::vector getGenToolInfos(podio::Frame& frame) { + auto toolInfos = std::vector(); + auto names = frame.getParameter("name"); + auto versions = frame.getParameter("version"); + auto descriptions = frame.getParameter("description"); + for (unsigned int i = 0; i < names.size(); ++i){ + auto toolInfo = GenToolInfo(); + toolInfo.name = names[i]; + toolInfo.version = versions[i]; + toolInfo.description = descriptions[i]; + } + return toolInfos; +}; + +void putGenToolInfos(podio::Frame& frame, std::vector& toolInfos) { + auto names = std::vector(); + auto versions = std::vector(); + auto descriptions = std::vector(); + 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); +}; + +} // namespace edm4hep + +#endif // EDM4HEP_GENTOOLINFO_H \ No newline at end of file diff --git a/test/write_events.h b/test/write_events.h index e80d5c6f2..fb451a8ac 100644 --- a/test/write_events.h +++ b/test/write_events.h @@ -2,6 +2,9 @@ #define EDM4HEP_TEST_WRITE_EVENTS_H // Data model +#include "edm4hep/GeneratorParametersCollection.h" +#include "edm4hep/GeneratorPdfInfoCollection.h" +#include "edm4hep/GenToolInfo.h" #include "edm4hep/CaloHitContributionCollection.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/RawTimeSeriesCollection.h" @@ -28,6 +31,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 // @@ -108,6 +112,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(); + 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 ? //------------------------------------------------------------- @@ -237,6 +275,7 @@ void write(std::string outfilename) { event.putParameter("EventType", "test"); writer.writeFrame(event, "events"); + writer.writeFrame(run, "runs"); } writer.finish(); From 32c31ae0e0b1f41cc0003f1041ffe00c1b727406 Mon Sep 17 00:00:00 2001 From: hegner Date: Thu, 23 May 2024 21:42:21 +0200 Subject: [PATCH 09/34] Update edm4hep.yaml Co-authored-by: Thomas Madlener --- edm4hep.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index 57e5bcb85..6a09eb9c6 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -792,7 +792,7 @@ datatypes: - double alphaQED // alpha_QED - double alphaQCD // alpha_QCD - int signal_process_id // id of signal process - - double sqrt_s // sqrt(s) + - double sqrt_s [GeV] // sqrt(s) VectorMembers: - double crossSections // list of cross sections in pb - double crossSectionErrors // list of cross section errors From bf612a51d4128213f4fa0dc9d962a4f6f6b6fa36 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Fri, 24 May 2024 09:18:05 +0200 Subject: [PATCH 10/34] include clang-format suggestions --- include/edm4hep/GenToolInfo.h | 7 +++---- test/write_events.h | 17 +++++++++-------- tools/include/edm4hep2json.hxx | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index 687d4a600..f5cb6d424 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -1,11 +1,10 @@ #ifndef EDM4HEP_GENTOOLINFO_H #define EDM4HEP_GENTOOLINFO_H -#include -#include #include "podio/Frame.h" #include "Constants.h" - +#include +#include namespace edm4hep { @@ -20,7 +19,7 @@ const std::vector getGenToolInfos(podio::Frame& frame) { auto names = frame.getParameter("name"); auto versions = frame.getParameter("version"); auto descriptions = frame.getParameter("description"); - for (unsigned int i = 0; i < names.size(); ++i){ + for (unsigned int i = 0; i < names.size(); ++i) { auto toolInfo = GenToolInfo(); toolInfo.name = names[i]; toolInfo.version = versions[i]; diff --git a/test/write_events.h b/test/write_events.h index fb451a8ac..54cbba471 100644 --- a/test/write_events.h +++ b/test/write_events.h @@ -2,10 +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/GenToolInfo.h" -#include "edm4hep/CaloHitContributionCollection.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/RawTimeSeriesCollection.h" #include "edm4hep/SimCalorimeterHitCollection.h" @@ -31,7 +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(); + auto run = podio::Frame(); // place the following generator event to the MCParticle collection // @@ -117,7 +118,7 @@ void write(std::string outfilename) { auto genParametersCollection = edm4hep::GeneratorParametersCollection(); auto genParam = genParametersCollection.create(); genParam.setEvent_scale(23); - genParam.setAlphaQED(1/127); + genParam.setAlphaQED(1 / 127); genParam.setAlphaQCD(0.1); genParam.setSignal_process_id(42); genParam.setSqrt_s(90); @@ -127,10 +128,10 @@ void write(std::string outfilename) { 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.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); diff --git a/tools/include/edm4hep2json.hxx b/tools/include/edm4hep2json.hxx index 4e510ecd9..53adfb5c4 100644 --- a/tools/include/edm4hep2json.hxx +++ b/tools/include/edm4hep2json.hxx @@ -5,9 +5,9 @@ #include "edm4hep/CaloHitContributionCollection.h" #include "edm4hep/CalorimeterHitCollection.h" #include "edm4hep/ClusterCollection.h" +#include "edm4hep/EventHeaderCollection.h" #include "edm4hep/GeneratorParametersCollection.h" #include "edm4hep/GeneratorPdfInfoCollection.h" -#include "edm4hep/EventHeaderCollection.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/ParticleIDCollection.h" #include "edm4hep/RawCalorimeterHitCollection.h" From b4e56bf52a1b678084cde99bbffb6e0d21f08b92 Mon Sep 17 00:00:00 2001 From: hegner Date: Mon, 27 May 2024 16:59:16 +0200 Subject: [PATCH 11/34] Update include/edm4hep/GenToolInfo.h Co-authored-by: Thomas Madlener --- include/edm4hep/GenToolInfo.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index f5cb6d424..7c554a085 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -37,9 +37,9 @@ void putGenToolInfos(podio::Frame& frame, std::vector& toolInfos) { versions.push_back(toolInfo.version); descriptions.push_back(toolInfo.description); } - frame.putParameter("name", names); - frame.putParameter("version", versions); - frame.putParameter("description", descriptions); + frame.putParameter("name", std::move(names)); + frame.putParameter("version", std::move(versions)); + frame.putParameter("description", std::move(descriptions)); }; } // namespace edm4hep From b44db85e9367b1e3015089803d66f8ffae3a93f3 Mon Sep 17 00:00:00 2001 From: hegner Date: Mon, 27 May 2024 16:59:26 +0200 Subject: [PATCH 12/34] Update include/edm4hep/GenToolInfo.h Co-authored-by: Thomas Madlener --- include/edm4hep/GenToolInfo.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index 7c554a085..21ed5a43e 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -20,10 +20,7 @@ const std::vector getGenToolInfos(podio::Frame& frame) { auto versions = frame.getParameter("version"); auto descriptions = frame.getParameter("description"); for (unsigned int i = 0; i < names.size(); ++i) { - auto toolInfo = GenToolInfo(); - toolInfo.name = names[i]; - toolInfo.version = versions[i]; - toolInfo.description = descriptions[i]; + toolInfo.emplace_back(names[i], versions[i], descriptions[i]); } return toolInfos; }; From f992f4c7f7475546e8d2376f07442cdb13ed691b Mon Sep 17 00:00:00 2001 From: hegner Date: Mon, 27 May 2024 18:41:45 +0200 Subject: [PATCH 13/34] Update edm4hep.yaml Co-authored-by: Andre Sailer --- edm4hep.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index 6a09eb9c6..35b5facf2 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -808,7 +808,7 @@ datatypes: - std::array xf // PDF value - double scale [GeV] // Factorisation scale OneToManyRelations: - - edm4hep::MCParticle signal_vertex // pointing into MC Generators collection + - edm4hep::MCParticle signal_vertex // pointing into MCParticle collection interfaces: edm4hep::TrackerHit: From c4fe0c88aaee68fbd41003b3c9e71582f22b54e2 Mon Sep 17 00:00:00 2001 From: hegner Date: Mon, 27 May 2024 18:42:10 +0200 Subject: [PATCH 14/34] Update include/edm4hep/GenToolInfo.h Co-authored-by: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> --- include/edm4hep/GenToolInfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index 21ed5a43e..25d83cc4b 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -20,7 +20,7 @@ const std::vector getGenToolInfos(podio::Frame& frame) { auto versions = frame.getParameter("version"); auto descriptions = frame.getParameter("description"); for (unsigned int i = 0; i < names.size(); ++i) { - toolInfo.emplace_back(names[i], versions[i], descriptions[i]); + toolInfos.emplace_back(names[i], versions[i], descriptions[i]); } return toolInfos; }; From 1f7ae9b47bdba722415540babab908130c15d2fa Mon Sep 17 00:00:00 2001 From: hegner Date: Mon, 27 May 2024 18:42:18 +0200 Subject: [PATCH 15/34] Update include/edm4hep/GenToolInfo.h Co-authored-by: Andre Sailer --- include/edm4hep/GenToolInfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index 25d83cc4b..ba493670d 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -2,7 +2,7 @@ #define EDM4HEP_GENTOOLINFO_H #include "podio/Frame.h" -#include "Constants.h" +#include "edm4hep/Constants.h" #include #include From 4873b6f675e94ab89505548aadb0784a76629a7a Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Tue, 28 May 2024 12:34:56 +0200 Subject: [PATCH 16/34] include PR comments; improve test coverage --- edm4hep.yaml | 8 +++---- include/edm4hep/Constants.h | 8 +++++++ include/edm4hep/GenToolInfo.h | 22 ++++++++++++-------- test/read_events.h | 38 ++++++++++++++++++++++++++++++++++ test/write_events.h | 15 ++++++++++---- tools/include/edm4hep2json.hxx | 4 ++-- 6 files changed, 76 insertions(+), 19 deletions(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index 35b5facf2..f3e4152f6 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -783,9 +783,9 @@ datatypes: #===== Generator related data ===== - #---------- GeneratorParameters - edm4hep::GeneratorParameters: - Description: "Generator parameters" + #---------- GeneratorEventParameters + edm4hep::GeneratorEventParameters: + Description: "Generator event parameters" Author: "EDM4hep authors" Members: - double event_scale // event scale @@ -794,7 +794,7 @@ datatypes: - int signal_process_id // id of signal process - double sqrt_s [GeV] // sqrt(s) VectorMembers: - - double crossSections // list of cross sections in pb + - double crossSections [pb] // list of cross sections - double crossSectionErrors // list of cross section errors #---------- GeneratorPdfInfo diff --git a/include/edm4hep/Constants.h b/include/edm4hep/Constants.h index d75959942..a7d08a655 100644 --- a/include/edm4hep/Constants.h +++ b/include/edm4hep/Constants.h @@ -50,6 +50,14 @@ static constexpr const char* pidParameterNames = "ParameterNames"; static constexpr const char* pidAlgoName = "AlgoName"; static constexpr const char* pidAlgoType = "AlgoType"; +// Parameter names for Generator level metadata +static constexpr const char* generatorToolVersionLabel = "generatorToolVersion"; +static constexpr const char* generatorToolNameLabel = "generatorToolName"; +static constexpr const char* generatorToolDescriptionLabel = "generatorToolDescription"; +static constexpr const char* generatorEventParametersLabel = "generatorEventParameters"; +static constexpr const char* generatorPdfInfoLabel = "generatorPdfInfo"; +static constexpr const char* generatorWeightNamesLabel = "generatorWeightNames"; + } // namespace edm4hep #endif // EDM4HEP_CONSTANTS_H diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index ba493670d..0953efa2c 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -1,8 +1,8 @@ #ifndef EDM4HEP_GENTOOLINFO_H #define EDM4HEP_GENTOOLINFO_H -#include "podio/Frame.h" #include "edm4hep/Constants.h" +#include "podio/Frame.h" #include #include @@ -12,13 +12,17 @@ struct GenToolInfo { std::string name; std::string version; std::string description; + + GenToolInfo(){}; + GenToolInfo(const std::string& name, const std::string& version, const std::string& description) : + name(name), version(version), description(description){}; }; -const std::vector getGenToolInfos(podio::Frame& frame) { +const std::vector getGenToolInfos(const podio::Frame& frame) { auto toolInfos = std::vector(); - auto names = frame.getParameter("name"); - auto versions = frame.getParameter("version"); - auto descriptions = frame.getParameter("description"); + const auto names = frame.getParameter>(generatorToolNameLabel); + const auto versions = frame.getParameter>(generatorToolVersionLabel); + const auto descriptions = frame.getParameter>(generatorToolDescriptionLabel); for (unsigned int i = 0; i < names.size(); ++i) { toolInfos.emplace_back(names[i], versions[i], descriptions[i]); } @@ -29,14 +33,14 @@ void putGenToolInfos(podio::Frame& frame, std::vector& toolInfos) { auto names = std::vector(); auto versions = std::vector(); auto descriptions = std::vector(); - for (auto& toolInfo : toolInfos){ + for (auto& toolInfo : toolInfos) { names.push_back(toolInfo.name); versions.push_back(toolInfo.version); descriptions.push_back(toolInfo.description); } - frame.putParameter("name", std::move(names)); - frame.putParameter("version", std::move(versions)); - frame.putParameter("description", std::move(descriptions)); + frame.putParameter(generatorToolNameLabel, std::move(names)); + frame.putParameter(generatorToolVersionLabel, std::move(versions)); + frame.putParameter(generatorToolDescriptionLabel, std::move(descriptions)); }; } // namespace edm4hep diff --git a/test/read_events.h b/test/read_events.h index d3a71d5ae..cb74a2ea8 100644 --- a/test/read_events.h +++ b/test/read_events.h @@ -3,6 +3,9 @@ // test data model #include "edm4hep/CaloHitContributionCollection.h" +#include "edm4hep/GenToolInfo.h" +#include "edm4hep/GeneratorEventParametersCollection.h" +#include "edm4hep/GeneratorPdfInfoCollection.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/RawTimeSeriesCollection.h" #include "edm4hep/SimCalorimeterHitCollection.h" @@ -16,6 +19,27 @@ // STL #include +void processRun(const podio::Frame& run) { + //=============================================================================== + // get generator tool info from the run + auto toolInfos = edm4hep::getGenToolInfos(run); + auto toolinfo = toolInfos[0]; + if (toolinfo.name != "something") + throw std::runtime_error("toolinfo.name != 'something'"); + if (toolinfo.version != "v1") + throw std::runtime_error("toolinfo.version != 'v1'"); + if (toolinfo.description != "some tool") + throw std::runtime_error("toolinfo.description != 'some tool'"); + + //=============================================================================== + // get generator weight names + auto weightNames = run.getParameter>(edm4hep::generatorWeightNamesLabel); + if (weightNames[0] != "oneWeight") + throw std::runtime_error("weightNames[0] != 'oneWeight'"); + if (weightNames[1] != "anotherWeight") + throw std::runtime_error("weightNames[1] != 'anotherWeight'"); +} + void processEvent(const podio::Frame& event) { auto& mcps = event.get("MCParticles"); auto& sths = event.get("SimTrackerHits"); @@ -232,6 +256,17 @@ void processEvent(const podio::Frame& event) { throw std::runtime_error("Collection 'TrackerHitPlanes' should be present"); } + //=============================================================================== + // check the generator meta data + auto& genParametersCollection = + event.get(edm4hep::generatorEventParametersLabel); + auto genParam = genParametersCollection[0]; + if (genParam.getEvent_scale() != 23) + throw std::runtime_error("Event_scale != 23"); + + auto& generatorPdfInfoCollection = event.get(edm4hep::generatorPdfInfoLabel); + auto genPdfInfo = generatorPdfInfoCollection[0]; + // //=============================================================================== // if( sccons.isValid() ){ // } else { @@ -251,6 +286,9 @@ void read_events(const std::string& filename) { ReaderT reader; reader.openFile(filename); + const auto run = podio::Frame(reader.readNextEntry("runs")); + processRun(run); + unsigned nEvents = reader.getEntries("events"); for (unsigned i = 0; i < nEvents; ++i) { std::cout << "reading event " << i << std::endl; diff --git a/test/write_events.h b/test/write_events.h index 54cbba471..a5a706e70 100644 --- a/test/write_events.h +++ b/test/write_events.h @@ -5,7 +5,7 @@ #include "edm4hep/CaloHitContributionCollection.h" #include "edm4hep/GenToolInfo.h" -#include "edm4hep/GeneratorParametersCollection.h" +#include "edm4hep/GeneratorEventParametersCollection.h" #include "edm4hep/GeneratorPdfInfoCollection.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/RawTimeSeriesCollection.h" @@ -115,7 +115,7 @@ void write(std::string outfilename) { //=============================================================================== // write some generator event data - auto genParametersCollection = edm4hep::GeneratorParametersCollection(); + auto genParametersCollection = edm4hep::GeneratorEventParametersCollection(); auto genParam = genParametersCollection.create(); genParam.setEvent_scale(23); genParam.setAlphaQED(1 / 127); @@ -124,7 +124,7 @@ void write(std::string outfilename) { genParam.setSqrt_s(90); genParam.addToCrossSections(10); genParam.addToCrossSectionErrors(3); - event.put(std::move(genParametersCollection), "GeneratorParameters"); + event.put(std::move(genParametersCollection), edm4hep::generatorEventParametersLabel); auto genPdfInfoCollection = edm4hep::GeneratorPdfInfoCollection(); auto genPdfInfo = genPdfInfoCollection.create(); @@ -135,7 +135,7 @@ void write(std::string outfilename) { genPdfInfo.setScale(23); genPdfInfo.addToSignal_vertex(mcp1); genPdfInfo.addToSignal_vertex(mcp2); - event.put(std::move(genPdfInfoCollection), "GeneratorPdfInfo"); + event.put(std::move(genPdfInfoCollection), edm4hep::generatorPdfInfoLabel); //=============================================================================== // write some generator tool info into the run @@ -147,6 +147,13 @@ void write(std::string outfilename) { toolInfos.emplace_back(std::move(toolInfo)); edm4hep::putGenToolInfos(run, toolInfos); + //=============================================================================== + // write some generator weightname info into the run + auto weightNames = std::vector(); + weightNames.emplace_back("oneWeight"); + weightNames.emplace_back("anotherWeight"); + run.putParameter(edm4hep::generatorWeightNamesLabel, std::move(weightNames)); + // fixme: should this become a utility function ? //------------------------------------------------------------- diff --git a/tools/include/edm4hep2json.hxx b/tools/include/edm4hep2json.hxx index 53adfb5c4..2ff0faba0 100644 --- a/tools/include/edm4hep2json.hxx +++ b/tools/include/edm4hep2json.hxx @@ -6,7 +6,7 @@ #include "edm4hep/CalorimeterHitCollection.h" #include "edm4hep/ClusterCollection.h" #include "edm4hep/EventHeaderCollection.h" -#include "edm4hep/GeneratorParametersCollection.h" +#include "edm4hep/GeneratorEventParametersCollection.h" #include "edm4hep/GeneratorPdfInfoCollection.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/ParticleIDCollection.h" @@ -159,7 +159,7 @@ nlohmann::json processEvent(const podio::Frame& frame, std::vector& } // Generator (meta-)data else if (coll->getTypeName() == "podio::GeneratorParametersCollection") { - insertIntoJson(jsonDict, coll, collList[i]); + insertIntoJson(jsonDict, coll, collList[i]); } else if (coll->getTypeName() == "podio::GeneratorPdfInfoCollection") { insertIntoJson(jsonDict, coll, collList[i]); } else { From 34f1ddf9061b85a19b2b98f3add93206a18a0569 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Tue, 28 May 2024 12:42:26 +0200 Subject: [PATCH 17/34] fix renamed class in readme file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fae8ddfbc..515ee033a 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ A generic event data model for future HEP collider experiments. | | | | |-|-|-| -| [GeneratorParameters](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L787) | | | +| [GeneratorEventParameters](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L787) | | | | [GeneratorPdfInfo](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L801) | | | **Interfaces** From 3067af31823524b26d0753c58e8caca9939a9010 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Tue, 4 Jun 2024 09:14:24 +0200 Subject: [PATCH 18/34] move signalVertex member to generatorEventParameters --- README.md | 2 +- edm4hep.yaml | 4 ++-- test/write_events.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 515ee033a..60e2a0f20 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ A generic event data model for future HEP collider experiments. | | | | |-|-|-| -| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L813) | | | +| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L814) | | | The tests and examples in the `tests` directory show how to read, write, and use these types in your code. diff --git a/edm4hep.yaml b/edm4hep.yaml index f3e4152f6..64e370786 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -796,6 +796,8 @@ datatypes: VectorMembers: - double crossSections [pb] // list of cross sections - double crossSectionErrors // list of cross section errors + OneToManyRelations: + - edm4hep::MCParticle signalVertex // pointing into MCParticle collection #---------- GeneratorPdfInfo edm4hep::GeneratorPdfInfo: @@ -807,8 +809,6 @@ datatypes: - std::array x // Parton momentum fraction - std::array xf // PDF value - double scale [GeV] // Factorisation scale - OneToManyRelations: - - edm4hep::MCParticle signal_vertex // pointing into MCParticle collection interfaces: edm4hep::TrackerHit: diff --git a/test/write_events.h b/test/write_events.h index a5a706e70..b6a4aef94 100644 --- a/test/write_events.h +++ b/test/write_events.h @@ -124,6 +124,8 @@ void write(std::string outfilename) { genParam.setSqrt_s(90); genParam.addToCrossSections(10); genParam.addToCrossSectionErrors(3); + genParam.addToSignalVertex(mcp1); + genParam.addToSignalVertex(mcp2); event.put(std::move(genParametersCollection), edm4hep::generatorEventParametersLabel); auto genPdfInfoCollection = edm4hep::GeneratorPdfInfoCollection(); @@ -133,8 +135,6 @@ void write(std::string outfilename) { 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), edm4hep::generatorPdfInfoLabel); //=============================================================================== From be27423af63fc7448bfb132912c6138312396722 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Tue, 4 Jun 2024 09:18:21 +0200 Subject: [PATCH 19/34] add doc for generator information --- doc/GeneratorInfo.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 doc/GeneratorInfo.md diff --git a/doc/GeneratorInfo.md b/doc/GeneratorInfo.md new file mode 100644 index 000000000..da3ed1acc --- /dev/null +++ b/doc/GeneratorInfo.md @@ -0,0 +1,35 @@ +# Dealing with Generator (meta-)data + +EDM4hep provides data types and helper functions to handle the storage of generator meta data, both at run and event level. + +## Storing and retrieving run level information +At run level, information about generator tools (name, version, description) are being stored. They can be written via + + +```cpp + #include "edm4hep/GenToolInfo.h" + ... + // write some generator tool info into the run + auto toolInfo = edm4hep::GenToolInfo(); + auto toolInfos = std::vector(); + toolInfo.name = "something"; + toolInfo.version = "v1"; + toolInfo.description = "some tool"; + toolInfos.emplace_back(std::move(toolInfo)); + + edm4hep::putGenToolInfos(run, toolInfos); +``` + +and read-back via: + +```cpp + #include "edm4hep/GenToolInfo.h" + ... + auto toolInfos = edm4hep::getGenToolInfos(run); + +``` + +### Storing and retrieving event specific generator parameters and PDF information + +For storing information about event level parameters of generators one can use the type `GeneratorEventParameters`. +For storing information about PDFs, one can use the type `GeneratorPdfInfo`. \ No newline at end of file From 0e823eadcfc1236a495320dbcd8b8f438fd6aa61 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Tue, 4 Jun 2024 11:21:05 +0200 Subject: [PATCH 20/34] rename generator related members to fit naming conventions --- edm4hep.yaml | 15 ++++++++------- test/read_events.h | 2 +- test/write_events.h | 10 +++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/edm4hep.yaml b/edm4hep.yaml index c22cdc106..b53aaacdf 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -791,24 +791,25 @@ datatypes: Description: "Generator event parameters" Author: "EDM4hep authors" Members: - - double event_scale // event scale + - double eventScale // event scale - double alphaQED // alpha_QED - double alphaQCD // alpha_QCD - - int signal_process_id // id of signal process - - double sqrt_s [GeV] // sqrt(s) + - int signalProcessId // id of signal process + - double sqrts [GeV] // sqrt(s) VectorMembers: - double crossSections [pb] // list of cross sections - - double crossSectionErrors // list of cross section errors + - double crossSectionErrors [pb] // list of cross section errors OneToManyRelations: - - edm4hep::MCParticle signalVertex // pointing into MCParticle collection + - edm4hep::MCParticle signalVertex // List of initial state MCParticle that are the source of the hard interaction + #---------- GeneratorPdfInfo edm4hep::GeneratorPdfInfo: Description: "Generator pdf information" Author: "EDM4hep authors" Members: - - std::array parton_id // Parton PDG id - - std::array id // LHAPDF PDF id (see https://lhapdf.hepforge.org/pdfsets.html) + - std::array partonId // Parton PDG id + - std::array lhapdfId // LHAPDF PDF id (see https://lhapdf.hepforge.org/pdfsets.html) - std::array x // Parton momentum fraction - std::array xf // PDF value - double scale [GeV] // Factorisation scale diff --git a/test/read_events.h b/test/read_events.h index cb74a2ea8..be174bd8f 100644 --- a/test/read_events.h +++ b/test/read_events.h @@ -261,7 +261,7 @@ void processEvent(const podio::Frame& event) { auto& genParametersCollection = event.get(edm4hep::generatorEventParametersLabel); auto genParam = genParametersCollection[0]; - if (genParam.getEvent_scale() != 23) + if (genParam.getEventScale() != 23) throw std::runtime_error("Event_scale != 23"); auto& generatorPdfInfoCollection = event.get(edm4hep::generatorPdfInfoLabel); diff --git a/test/write_events.h b/test/write_events.h index b6a4aef94..af14bb46c 100644 --- a/test/write_events.h +++ b/test/write_events.h @@ -117,11 +117,11 @@ void write(std::string outfilename) { // write some generator event data auto genParametersCollection = edm4hep::GeneratorEventParametersCollection(); auto genParam = genParametersCollection.create(); - genParam.setEvent_scale(23); + genParam.setEventScale(23); genParam.setAlphaQED(1 / 127); genParam.setAlphaQCD(0.1); - genParam.setSignal_process_id(42); - genParam.setSqrt_s(90); + genParam.setSignalProcessId(42); + genParam.setSqrts(90); genParam.addToCrossSections(10); genParam.addToCrossSectionErrors(3); genParam.addToSignalVertex(mcp1); @@ -130,8 +130,8 @@ void write(std::string outfilename) { auto genPdfInfoCollection = edm4hep::GeneratorPdfInfoCollection(); auto genPdfInfo = genPdfInfoCollection.create(); - genPdfInfo.setParton_id(1, 2); - genPdfInfo.setId({20, 20}); + genPdfInfo.setPartonId(1, 2); + genPdfInfo.setLhapdfId({20, 20}); genPdfInfo.setX({0.5, 0.5}); genPdfInfo.setXf({0.5, 0.5}); genPdfInfo.setScale(23); From 763bcd8d6a7d5034b29057765e3bfe3fa15bce2b Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Tue, 4 Jun 2024 12:25:50 +0200 Subject: [PATCH 21/34] fix line numbers in README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1a4ce95fb..b26e1e3a1 100644 --- a/README.md +++ b/README.md @@ -43,14 +43,14 @@ A generic event data model for future HEP collider experiments. | | | | |-|-|-| -| [GeneratorEventParameters](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L787) | | | -| [GeneratorPdfInfo](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L801) | | | +| [GeneratorEventParameters](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L790) | | | +| [GeneratorPdfInfo](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L806) | | | **Interfaces** | | | | |-|-|-| -| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L814) | | | +| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L817) | | | The tests and examples in the `tests` directory show how to read, write, and use these types in your code. From 8823133da03fcd0e8ff95bfed9508e865148a759 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Tue, 4 Jun 2024 12:55:41 +0200 Subject: [PATCH 22/34] fix issues of pre-commit --- README.md | 4 ++-- edm4hep.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b26e1e3a1..e5bf720c8 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,13 @@ A generic event data model for future HEP collider experiments. | | | | |-|-|-| | [GeneratorEventParameters](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L790) | | | -| [GeneratorPdfInfo](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L806) | | | +| [GeneratorPdfInfo](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L807) | | | **Interfaces** | | | | |-|-|-| -| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L817) | | | +| [TrackerHit](https://github.com/key4hep/EDM4hep/blob/main/edm4hep.yaml#L818) | | | The tests and examples in the `tests` directory show how to read, write, and use these types in your code. diff --git a/edm4hep.yaml b/edm4hep.yaml index b53aaacdf..eb823226c 100644 --- a/edm4hep.yaml +++ b/edm4hep.yaml @@ -801,7 +801,7 @@ datatypes: - double crossSectionErrors [pb] // list of cross section errors OneToManyRelations: - edm4hep::MCParticle signalVertex // List of initial state MCParticle that are the source of the hard interaction - + #---------- GeneratorPdfInfo edm4hep::GeneratorPdfInfo: From 3ddd0c303a887e2d364e772bfd25a4d025b01547 Mon Sep 17 00:00:00 2001 From: hegner Date: Tue, 11 Jun 2024 15:14:24 +0200 Subject: [PATCH 23/34] Update include/edm4hep/Constants.h Co-authored-by: Thomas Madlener --- include/edm4hep/Constants.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/edm4hep/Constants.h b/include/edm4hep/Constants.h index a7d08a655..bf6162558 100644 --- a/include/edm4hep/Constants.h +++ b/include/edm4hep/Constants.h @@ -51,12 +51,12 @@ static constexpr const char* pidAlgoName = "AlgoName"; static constexpr const char* pidAlgoType = "AlgoType"; // Parameter names for Generator level metadata -static constexpr const char* generatorToolVersionLabel = "generatorToolVersion"; -static constexpr const char* generatorToolNameLabel = "generatorToolName"; -static constexpr const char* generatorToolDescriptionLabel = "generatorToolDescription"; -static constexpr const char* generatorEventParametersLabel = "generatorEventParameters"; -static constexpr const char* generatorPdfInfoLabel = "generatorPdfInfo"; -static constexpr const char* generatorWeightNamesLabel = "generatorWeightNames"; +static constexpr const char* generatorToolVersion = "generatorToolVersion"; +static constexpr const char* generatorToolName = "generatorToolName"; +static constexpr const char* generatorToolDescription = "generatorToolDescription"; +static constexpr const char* generatorEventParameters = "generatorEventParameters"; +static constexpr const char* generatorPdfInfo = "generatorPdfInfo"; +static constexpr const char* generatorWeightNames = "generatorWeightNames"; } // namespace edm4hep From 0364ea668a9f1bf5d321a7721a3048875efa5332 Mon Sep 17 00:00:00 2001 From: hegner Date: Tue, 11 Jun 2024 15:14:34 +0200 Subject: [PATCH 24/34] Update include/edm4hep/GenToolInfo.h Co-authored-by: Thomas Madlener --- include/edm4hep/GenToolInfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index 0953efa2c..e2fff6e54 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -42,7 +42,7 @@ void putGenToolInfos(podio::Frame& frame, std::vector& toolInfos) { frame.putParameter(generatorToolVersionLabel, std::move(versions)); frame.putParameter(generatorToolDescriptionLabel, std::move(descriptions)); }; - +} // namespace utils } // namespace edm4hep #endif // EDM4HEP_GENTOOLINFO_H \ No newline at end of file From e9154e4acab19d1b15b95958dbe371c21eff3eed Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Tue, 11 Jun 2024 15:26:49 +0200 Subject: [PATCH 25/34] address PR comments about util namespaces and string naming convention --- doc/GeneratorInfo.md | 4 +-- include/edm4hep/GenToolInfo.h | 48 ++++++++++++++++++----------------- test/read_events.h | 8 +++--- test/write_events.h | 8 +++--- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/doc/GeneratorInfo.md b/doc/GeneratorInfo.md index da3ed1acc..299b7bcb3 100644 --- a/doc/GeneratorInfo.md +++ b/doc/GeneratorInfo.md @@ -17,7 +17,7 @@ At run level, information about generator tools (name, version, description) are toolInfo.description = "some tool"; toolInfos.emplace_back(std::move(toolInfo)); - edm4hep::putGenToolInfos(run, toolInfos); + edm4hep::utils::putGenToolInfos(run, toolInfos); ``` and read-back via: @@ -25,7 +25,7 @@ and read-back via: ```cpp #include "edm4hep/GenToolInfo.h" ... - auto toolInfos = edm4hep::getGenToolInfos(run); + auto toolInfos = edm4hep::utils::getGenToolInfos(run); ``` diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index e2fff6e54..d54c00681 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -18,30 +18,32 @@ struct GenToolInfo { name(name), version(version), description(description){}; }; -const std::vector getGenToolInfos(const podio::Frame& frame) { - auto toolInfos = std::vector(); - const auto names = frame.getParameter>(generatorToolNameLabel); - const auto versions = frame.getParameter>(generatorToolVersionLabel); - const auto descriptions = frame.getParameter>(generatorToolDescriptionLabel); - for (unsigned int i = 0; i < names.size(); ++i) { - toolInfos.emplace_back(names[i], versions[i], descriptions[i]); - } - return toolInfos; -}; +namespace utils { -void putGenToolInfos(podio::Frame& frame, std::vector& toolInfos) { - auto names = std::vector(); - auto versions = std::vector(); - auto descriptions = std::vector(); - for (auto& toolInfo : toolInfos) { - names.push_back(toolInfo.name); - versions.push_back(toolInfo.version); - descriptions.push_back(toolInfo.description); - } - frame.putParameter(generatorToolNameLabel, std::move(names)); - frame.putParameter(generatorToolVersionLabel, std::move(versions)); - frame.putParameter(generatorToolDescriptionLabel, std::move(descriptions)); -}; + const std::vector getGenToolInfos(const podio::Frame& frame) { + auto toolInfos = std::vector(); + const auto names = frame.getParameter>(generatorToolName); + const auto versions = frame.getParameter>(generatorToolVersion); + const auto descriptions = frame.getParameter>(generatorToolDescription); + for (unsigned int i = 0; i < names.size(); ++i) { + toolInfos.emplace_back(names[i], versions[i], descriptions[i]); + } + return toolInfos; + }; + + void putGenToolInfos(podio::Frame& frame, std::vector& toolInfos) { + auto names = std::vector(); + auto versions = std::vector(); + auto descriptions = std::vector(); + for (auto& toolInfo : toolInfos) { + names.push_back(toolInfo.name); + versions.push_back(toolInfo.version); + descriptions.push_back(toolInfo.description); + } + frame.putParameter(generatorToolName, std::move(names)); + frame.putParameter(generatorToolVersion, std::move(versions)); + frame.putParameter(generatorToolDescription, std::move(descriptions)); + }; } // namespace utils } // namespace edm4hep diff --git a/test/read_events.h b/test/read_events.h index be174bd8f..3984bd83f 100644 --- a/test/read_events.h +++ b/test/read_events.h @@ -22,7 +22,7 @@ void processRun(const podio::Frame& run) { //=============================================================================== // get generator tool info from the run - auto toolInfos = edm4hep::getGenToolInfos(run); + auto toolInfos = edm4hep::utils::getGenToolInfos(run); auto toolinfo = toolInfos[0]; if (toolinfo.name != "something") throw std::runtime_error("toolinfo.name != 'something'"); @@ -33,7 +33,7 @@ void processRun(const podio::Frame& run) { //=============================================================================== // get generator weight names - auto weightNames = run.getParameter>(edm4hep::generatorWeightNamesLabel); + auto weightNames = run.getParameter>(edm4hep::generatorWeightNames); if (weightNames[0] != "oneWeight") throw std::runtime_error("weightNames[0] != 'oneWeight'"); if (weightNames[1] != "anotherWeight") @@ -259,12 +259,12 @@ void processEvent(const podio::Frame& event) { //=============================================================================== // check the generator meta data auto& genParametersCollection = - event.get(edm4hep::generatorEventParametersLabel); + event.get(edm4hep::generatorEventParameters); auto genParam = genParametersCollection[0]; if (genParam.getEventScale() != 23) throw std::runtime_error("Event_scale != 23"); - auto& generatorPdfInfoCollection = event.get(edm4hep::generatorPdfInfoLabel); + auto& generatorPdfInfoCollection = event.get(edm4hep::generatorPdfInfo); auto genPdfInfo = generatorPdfInfoCollection[0]; // //=============================================================================== diff --git a/test/write_events.h b/test/write_events.h index af14bb46c..26520ccf8 100644 --- a/test/write_events.h +++ b/test/write_events.h @@ -126,7 +126,7 @@ void write(std::string outfilename) { genParam.addToCrossSectionErrors(3); genParam.addToSignalVertex(mcp1); genParam.addToSignalVertex(mcp2); - event.put(std::move(genParametersCollection), edm4hep::generatorEventParametersLabel); + event.put(std::move(genParametersCollection), edm4hep::generatorEventParameters); auto genPdfInfoCollection = edm4hep::GeneratorPdfInfoCollection(); auto genPdfInfo = genPdfInfoCollection.create(); @@ -135,7 +135,7 @@ void write(std::string outfilename) { genPdfInfo.setX({0.5, 0.5}); genPdfInfo.setXf({0.5, 0.5}); genPdfInfo.setScale(23); - event.put(std::move(genPdfInfoCollection), edm4hep::generatorPdfInfoLabel); + event.put(std::move(genPdfInfoCollection), edm4hep::generatorPdfInfo); //=============================================================================== // write some generator tool info into the run @@ -145,14 +145,14 @@ void write(std::string outfilename) { toolInfo.version = "v1"; toolInfo.description = "some tool"; toolInfos.emplace_back(std::move(toolInfo)); - edm4hep::putGenToolInfos(run, toolInfos); + edm4hep::utils::putGenToolInfos(run, toolInfos); //=============================================================================== // write some generator weightname info into the run auto weightNames = std::vector(); weightNames.emplace_back("oneWeight"); weightNames.emplace_back("anotherWeight"); - run.putParameter(edm4hep::generatorWeightNamesLabel, std::move(weightNames)); + run.putParameter(edm4hep::generatorWeightNames, std::move(weightNames)); // fixme: should this become a utility function ? //------------------------------------------------------------- From a4bd341e1dc8d149d87b7e3bd007102543189bbd Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Tue, 11 Jun 2024 15:32:54 +0200 Subject: [PATCH 26/34] parameters are now optional --- include/edm4hep/GenToolInfo.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index d54c00681..a45638c05 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -22,9 +22,9 @@ namespace utils { const std::vector getGenToolInfos(const podio::Frame& frame) { auto toolInfos = std::vector(); - const auto names = frame.getParameter>(generatorToolName); - const auto versions = frame.getParameter>(generatorToolVersion); - const auto descriptions = frame.getParameter>(generatorToolDescription); + const auto names = frame.getParameter>(generatorToolName).value(); + const auto versions = frame.getParameter>(generatorToolVersion).value(); + const auto descriptions = frame.getParameter>(generatorToolDescription).value(); for (unsigned int i = 0; i < names.size(); ++i) { toolInfos.emplace_back(names[i], versions[i], descriptions[i]); } From cc21262ab1641204e00ce053b1cbcb01bcd0225f Mon Sep 17 00:00:00 2001 From: hegner Date: Wed, 12 Jun 2024 12:45:44 +0200 Subject: [PATCH 27/34] Update test/read_events.h Co-authored-by: Thomas Madlener --- test/read_events.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/read_events.h b/test/read_events.h index 3984bd83f..17f2ed4fa 100644 --- a/test/read_events.h +++ b/test/read_events.h @@ -33,7 +33,7 @@ void processRun(const podio::Frame& run) { //=============================================================================== // get generator weight names - auto weightNames = run.getParameter>(edm4hep::generatorWeightNames); + auto weightNames = run.getParameter>(edm4hep::generatorWeightNames).value(); if (weightNames[0] != "oneWeight") throw std::runtime_error("weightNames[0] != 'oneWeight'"); if (weightNames[1] != "anotherWeight") From c7d56627e39b6f95c13da8bc354ee63ccb6356ea Mon Sep 17 00:00:00 2001 From: hegner Date: Wed, 12 Jun 2024 12:46:07 +0200 Subject: [PATCH 28/34] Update include/edm4hep/Constants.h Co-authored-by: Thomas Madlener --- include/edm4hep/Constants.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/edm4hep/Constants.h b/include/edm4hep/Constants.h index bf6162558..73d19a3e6 100644 --- a/include/edm4hep/Constants.h +++ b/include/edm4hep/Constants.h @@ -51,12 +51,12 @@ static constexpr const char* pidAlgoName = "AlgoName"; static constexpr const char* pidAlgoType = "AlgoType"; // Parameter names for Generator level metadata -static constexpr const char* generatorToolVersion = "generatorToolVersion"; -static constexpr const char* generatorToolName = "generatorToolName"; -static constexpr const char* generatorToolDescription = "generatorToolDescription"; -static constexpr const char* generatorEventParameters = "generatorEventParameters"; -static constexpr const char* generatorPdfInfo = "generatorPdfInfo"; -static constexpr const char* generatorWeightNames = "generatorWeightNames"; +static constexpr const char* GeneratorToolVersion = "GeneratorToolVersion"; +static constexpr const char* GeneratorToolName = "GeneratorToolName"; +static constexpr const char* GeneratorToolDescription = "GeneratorToolDescription"; +static constexpr const char* GeneratorEventParameters = "GeneratorEventParameters"; +static constexpr const char* GeneratorPdfInfo = "GeneratorPdfInfo"; +static constexpr const char* GeneratorWeightNames = "GeneratorWeightNames"; } // namespace edm4hep From 36726ecf9da18283a452a95a2bcf625955612fa1 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Mon, 17 Jun 2024 14:07:37 +0200 Subject: [PATCH 29/34] Update all label spellings to compile again --- include/edm4hep/Constants.h | 1 - include/edm4hep/GenToolInfo.h | 20 +++++++++++++------- test/read_events.h | 6 +++--- test/write_events.h | 6 +++--- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/include/edm4hep/Constants.h b/include/edm4hep/Constants.h index 34bf98d17..d49c3994b 100644 --- a/include/edm4hep/Constants.h +++ b/include/edm4hep/Constants.h @@ -45,7 +45,6 @@ namespace labels { static constexpr const char* GeneratorEventParameters = "GeneratorEventParameters"; static constexpr const char* GeneratorPdfInfo = "GeneratorPdfInfo"; static constexpr const char* GeneratorWeightNames = "GeneratorWeightNames"; - } // namespace labels DEPRECATED_LABEL(CellIDEncoding, CellIDEncoding); diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index a45638c05..14cfde968 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -21,10 +21,14 @@ struct GenToolInfo { namespace utils { const std::vector getGenToolInfos(const podio::Frame& frame) { + using namespace edm4hep::labels; auto toolInfos = std::vector(); - const auto names = frame.getParameter>(generatorToolName).value(); - const auto versions = frame.getParameter>(generatorToolVersion).value(); - const auto descriptions = frame.getParameter>(generatorToolDescription).value(); + const auto names = + frame.getParameter>(GeneratorToolName).value_or(std::vector{}); + const auto versions = + frame.getParameter>(GeneratorToolVersion).value_or(std::vector{}); + const auto descriptions = + frame.getParameter>(GeneratorToolDescription).value_or(std::vector{}); for (unsigned int i = 0; i < names.size(); ++i) { toolInfos.emplace_back(names[i], versions[i], descriptions[i]); } @@ -40,11 +44,13 @@ namespace utils { versions.push_back(toolInfo.version); descriptions.push_back(toolInfo.description); } - frame.putParameter(generatorToolName, std::move(names)); - frame.putParameter(generatorToolVersion, std::move(versions)); - frame.putParameter(generatorToolDescription, std::move(descriptions)); + + using namespace edm4hep::labels; + frame.putParameter(GeneratorToolName, std::move(names)); + frame.putParameter(GeneratorToolVersion, std::move(versions)); + frame.putParameter(GeneratorToolDescription, std::move(descriptions)); }; } // namespace utils } // namespace edm4hep -#endif // EDM4HEP_GENTOOLINFO_H \ No newline at end of file +#endif // EDM4HEP_GENTOOLINFO_H diff --git a/test/read_events.h b/test/read_events.h index 17f2ed4fa..2d54b7003 100644 --- a/test/read_events.h +++ b/test/read_events.h @@ -33,7 +33,7 @@ void processRun(const podio::Frame& run) { //=============================================================================== // get generator weight names - auto weightNames = run.getParameter>(edm4hep::generatorWeightNames).value(); + auto weightNames = run.getParameter>(edm4hep::labels::GeneratorWeightNames).value(); if (weightNames[0] != "oneWeight") throw std::runtime_error("weightNames[0] != 'oneWeight'"); if (weightNames[1] != "anotherWeight") @@ -259,12 +259,12 @@ void processEvent(const podio::Frame& event) { //=============================================================================== // check the generator meta data auto& genParametersCollection = - event.get(edm4hep::generatorEventParameters); + event.get(edm4hep::labels::GeneratorEventParameters); auto genParam = genParametersCollection[0]; if (genParam.getEventScale() != 23) throw std::runtime_error("Event_scale != 23"); - auto& generatorPdfInfoCollection = event.get(edm4hep::generatorPdfInfo); + auto& generatorPdfInfoCollection = event.get(edm4hep::labels::GeneratorPdfInfo); auto genPdfInfo = generatorPdfInfoCollection[0]; // //=============================================================================== diff --git a/test/write_events.h b/test/write_events.h index 26520ccf8..207480ca1 100644 --- a/test/write_events.h +++ b/test/write_events.h @@ -126,7 +126,7 @@ void write(std::string outfilename) { genParam.addToCrossSectionErrors(3); genParam.addToSignalVertex(mcp1); genParam.addToSignalVertex(mcp2); - event.put(std::move(genParametersCollection), edm4hep::generatorEventParameters); + event.put(std::move(genParametersCollection), edm4hep::labels::GeneratorEventParameters); auto genPdfInfoCollection = edm4hep::GeneratorPdfInfoCollection(); auto genPdfInfo = genPdfInfoCollection.create(); @@ -135,7 +135,7 @@ void write(std::string outfilename) { genPdfInfo.setX({0.5, 0.5}); genPdfInfo.setXf({0.5, 0.5}); genPdfInfo.setScale(23); - event.put(std::move(genPdfInfoCollection), edm4hep::generatorPdfInfo); + event.put(std::move(genPdfInfoCollection), edm4hep::labels::GeneratorPdfInfo); //=============================================================================== // write some generator tool info into the run @@ -152,7 +152,7 @@ void write(std::string outfilename) { auto weightNames = std::vector(); weightNames.emplace_back("oneWeight"); weightNames.emplace_back("anotherWeight"); - run.putParameter(edm4hep::generatorWeightNames, std::move(weightNames)); + run.putParameter(edm4hep::labels::GeneratorWeightNames, std::move(weightNames)); // fixme: should this become a utility function ? //------------------------------------------------------------- From 6985838cf07b741627d2a20bcae5b657a0bef3c1 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Mon, 17 Jun 2024 14:09:41 +0200 Subject: [PATCH 30/34] Rename GeneratorToolInfo for more consistency --- include/edm4hep/GenToolInfo.h | 12 ++++++------ test/write_events.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index 14cfde968..83ec0aeeb 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -8,21 +8,21 @@ namespace edm4hep { -struct GenToolInfo { +struct GeneratorToolInfo { std::string name; std::string version; std::string description; - GenToolInfo(){}; - GenToolInfo(const std::string& name, const std::string& version, const std::string& description) : + GeneratorToolInfo(){}; + GeneratorToolInfo(const std::string& name, const std::string& version, const std::string& description) : name(name), version(version), description(description){}; }; namespace utils { - const std::vector getGenToolInfos(const podio::Frame& frame) { + const inline std::vector getGenToolInfos(const podio::Frame& frame) { using namespace edm4hep::labels; - auto toolInfos = std::vector(); + auto toolInfos = std::vector(); const auto names = frame.getParameter>(GeneratorToolName).value_or(std::vector{}); const auto versions = @@ -35,7 +35,7 @@ namespace utils { return toolInfos; }; - void putGenToolInfos(podio::Frame& frame, std::vector& toolInfos) { + void inline putGenToolInfos(podio::Frame& frame, std::vector& toolInfos) { auto names = std::vector(); auto versions = std::vector(); auto descriptions = std::vector(); diff --git a/test/write_events.h b/test/write_events.h index 207480ca1..9e52c86bf 100644 --- a/test/write_events.h +++ b/test/write_events.h @@ -139,8 +139,8 @@ void write(std::string outfilename) { //=============================================================================== // write some generator tool info into the run - auto toolInfos = std::vector(); - auto toolInfo = edm4hep::GenToolInfo(); + auto toolInfos = std::vector(); + auto toolInfo = edm4hep::GeneratorToolInfo(); toolInfo.name = "something"; toolInfo.version = "v1"; toolInfo.description = "some tool"; From 3aa87f3e93307b2b28bda8cda9cc1e7199429fd4 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Mon, 17 Jun 2024 14:19:45 +0200 Subject: [PATCH 31/34] Add documentation to generator tool info handling utilities --- include/edm4hep/GenToolInfo.h | 39 ++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GenToolInfo.h index 83ec0aeeb..6399a5a0b 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GenToolInfo.h @@ -8,18 +8,40 @@ namespace edm4hep { +/// Meta information class to group information about the used generator (tools) +/// to create a file +/// +/// @note Since this is all rather loosely coupled and stored via podio Frame +/// parameters, use of the @ref getGenToolInfos and @ref putGenToolInfos utility +/// functions for retrieval, resp. storage of this information is crucial to +/// ensure consistent information. struct GeneratorToolInfo { - std::string name; - std::string version; - std::string description; + std::string name{}; ///< The name of the tool + std::string version{}; ///< The version of the tool + std::string description{}; ///< A brief description of the tool - GeneratorToolInfo(){}; + /// Construct a complete tool info object from all ingredients + /// + /// @param name The name of the tool + /// @param version The version of the tool + /// @param description The brief description of the tool GeneratorToolInfo(const std::string& name, const std::string& version, const std::string& description) : name(name), version(version), description(description){}; }; namespace utils { + /// Get all the generator tool infos that are available from the passed + /// (metadata) frame. + /// + /// Tries to retrieve all meta information that are available and that have + /// been stored via the @ref putGenToolInfos function. + /// + /// @param frame The (metadata) frame that should be queried for the + /// information + /// + /// @returns The GeneratorToolInfo that were found in the Frame. If none ar + /// found an empty vector will be returned. const inline std::vector getGenToolInfos(const podio::Frame& frame) { using namespace edm4hep::labels; auto toolInfos = std::vector(); @@ -35,7 +57,14 @@ namespace utils { return toolInfos; }; - void inline putGenToolInfos(podio::Frame& frame, std::vector& toolInfos) { + /// Put the generator tool meta information into a (metadata) frame + /// + /// In order to guarantee consistent storage and retrieval of these metadata + /// it is necessary to use this utility function. + /// + /// @param frame The (metadata) Frame into which the generator tool info should go + /// @param toolInfos The generator tool infos that should be stored + void inline putGenToolInfos(podio::Frame& frame, const std::vector& toolInfos) { auto names = std::vector(); auto versions = std::vector(); auto descriptions = std::vector(); From 921c5bdcf36780808a5faf0e65d8fdf4d3d33213 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Mon, 17 Jun 2024 14:23:49 +0200 Subject: [PATCH 32/34] Rename header for consistency and fix occurences --- doc/GeneratorInfo.md | 14 +++++++------- .../edm4hep/{GenToolInfo.h => GeneratorToolInfo.h} | 9 ++++++--- test/read_events.h | 2 +- test/write_events.h | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) rename include/edm4hep/{GenToolInfo.h => GeneratorToolInfo.h} (94%) diff --git a/doc/GeneratorInfo.md b/doc/GeneratorInfo.md index 299b7bcb3..02da37bb7 100644 --- a/doc/GeneratorInfo.md +++ b/doc/GeneratorInfo.md @@ -7,11 +7,11 @@ At run level, information about generator tools (name, version, description) are ```cpp - #include "edm4hep/GenToolInfo.h" - ... + #include "edm4hep/GeneratorToolInfo.h" + // ... // write some generator tool info into the run - auto toolInfo = edm4hep::GenToolInfo(); - auto toolInfos = std::vector(); + auto toolInfo = edm4hep::GeneratorToolInfo(); + auto toolInfos = std::vector(); toolInfo.name = "something"; toolInfo.version = "v1"; toolInfo.description = "some tool"; @@ -23,8 +23,8 @@ At run level, information about generator tools (name, version, description) are and read-back via: ```cpp - #include "edm4hep/GenToolInfo.h" - ... + #include "edm4hep/GeneratorToolInfo.h" + // ... auto toolInfos = edm4hep::utils::getGenToolInfos(run); ``` @@ -32,4 +32,4 @@ and read-back via: ### Storing and retrieving event specific generator parameters and PDF information For storing information about event level parameters of generators one can use the type `GeneratorEventParameters`. -For storing information about PDFs, one can use the type `GeneratorPdfInfo`. \ No newline at end of file +For storing information about PDFs, one can use the type `GeneratorPdfInfo`. diff --git a/include/edm4hep/GenToolInfo.h b/include/edm4hep/GeneratorToolInfo.h similarity index 94% rename from include/edm4hep/GenToolInfo.h rename to include/edm4hep/GeneratorToolInfo.h index 6399a5a0b..949120c19 100644 --- a/include/edm4hep/GenToolInfo.h +++ b/include/edm4hep/GeneratorToolInfo.h @@ -1,5 +1,5 @@ -#ifndef EDM4HEP_GENTOOLINFO_H -#define EDM4HEP_GENTOOLINFO_H +#ifndef EDM4HEP_GENERATORTOOLINFO_H +#define EDM4HEP_GENERATORTOOLINFO_H #include "edm4hep/Constants.h" #include "podio/Frame.h" @@ -20,6 +20,9 @@ struct GeneratorToolInfo { std::string version{}; ///< The version of the tool std::string description{}; ///< A brief description of the tool + /// Construct a generator tool info object with all empty fields + GeneratorToolInfo() = default; + /// Construct a complete tool info object from all ingredients /// /// @param name The name of the tool @@ -82,4 +85,4 @@ namespace utils { } // namespace utils } // namespace edm4hep -#endif // EDM4HEP_GENTOOLINFO_H +#endif // EDM4HEP_GENERATORTOOLINFO_H diff --git a/test/read_events.h b/test/read_events.h index 2d54b7003..ea805483c 100644 --- a/test/read_events.h +++ b/test/read_events.h @@ -3,9 +3,9 @@ // test data model #include "edm4hep/CaloHitContributionCollection.h" -#include "edm4hep/GenToolInfo.h" #include "edm4hep/GeneratorEventParametersCollection.h" #include "edm4hep/GeneratorPdfInfoCollection.h" +#include "edm4hep/GeneratorToolInfo.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/RawTimeSeriesCollection.h" #include "edm4hep/SimCalorimeterHitCollection.h" diff --git a/test/write_events.h b/test/write_events.h index 9e52c86bf..9eaa2ebe6 100644 --- a/test/write_events.h +++ b/test/write_events.h @@ -4,9 +4,9 @@ // Data model #include "edm4hep/CaloHitContributionCollection.h" -#include "edm4hep/GenToolInfo.h" #include "edm4hep/GeneratorEventParametersCollection.h" #include "edm4hep/GeneratorPdfInfoCollection.h" +#include "edm4hep/GeneratorToolInfo.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/RawTimeSeriesCollection.h" #include "edm4hep/SimCalorimeterHitCollection.h" From 8d33ff28fc2faa8a82dc837f90ec35a60571c0b8 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Mon, 17 Jun 2024 16:01:42 +0200 Subject: [PATCH 33/34] Pluralize labels --- include/edm4hep/Constants.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/edm4hep/Constants.h b/include/edm4hep/Constants.h index d49c3994b..ef769a004 100644 --- a/include/edm4hep/Constants.h +++ b/include/edm4hep/Constants.h @@ -39,9 +39,9 @@ namespace labels { static constexpr const char* PIDAlgoType = "AlgoType"; // Parameter names for Generator level metadata - static constexpr const char* GeneratorToolVersion = "GeneratorToolVersion"; - static constexpr const char* GeneratorToolName = "GeneratorToolName"; - static constexpr const char* GeneratorToolDescription = "GeneratorToolDescription"; + static constexpr const char* GeneratorToolVersions = "GeneratorToolVersions"; + static constexpr const char* GeneratorToolNames = "GeneratorToolNames"; + static constexpr const char* GeneratorToolDescriptions = "GeneratorToolDescriptions"; static constexpr const char* GeneratorEventParameters = "GeneratorEventParameters"; static constexpr const char* GeneratorPdfInfo = "GeneratorPdfInfo"; static constexpr const char* GeneratorWeightNames = "GeneratorWeightNames"; From 4a9d409fa8ea1331aaa3562b5f8eb8ef37ebeeb6 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Mon, 17 Jun 2024 18:15:48 +0200 Subject: [PATCH 34/34] Pluralize all usages --- include/edm4hep/GeneratorToolInfo.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/edm4hep/GeneratorToolInfo.h b/include/edm4hep/GeneratorToolInfo.h index 949120c19..71dc91124 100644 --- a/include/edm4hep/GeneratorToolInfo.h +++ b/include/edm4hep/GeneratorToolInfo.h @@ -49,11 +49,11 @@ namespace utils { using namespace edm4hep::labels; auto toolInfos = std::vector(); const auto names = - frame.getParameter>(GeneratorToolName).value_or(std::vector{}); + frame.getParameter>(GeneratorToolNames).value_or(std::vector{}); const auto versions = - frame.getParameter>(GeneratorToolVersion).value_or(std::vector{}); + frame.getParameter>(GeneratorToolVersions).value_or(std::vector{}); const auto descriptions = - frame.getParameter>(GeneratorToolDescription).value_or(std::vector{}); + frame.getParameter>(GeneratorToolDescriptions).value_or(std::vector{}); for (unsigned int i = 0; i < names.size(); ++i) { toolInfos.emplace_back(names[i], versions[i], descriptions[i]); } @@ -78,9 +78,9 @@ namespace utils { } using namespace edm4hep::labels; - frame.putParameter(GeneratorToolName, std::move(names)); - frame.putParameter(GeneratorToolVersion, std::move(versions)); - frame.putParameter(GeneratorToolDescription, std::move(descriptions)); + frame.putParameter(GeneratorToolNames, std::move(names)); + frame.putParameter(GeneratorToolVersions, std::move(versions)); + frame.putParameter(GeneratorToolDescriptions, std::move(descriptions)); }; } // namespace utils } // namespace edm4hep