From f6f622625ac1334e11070cdda14b53e4e98d5d7a Mon Sep 17 00:00:00 2001 From: rpozzi <ruben.pozzi@cern.ch> Date: Tue, 16 May 2023 22:10:57 +0200 Subject: [PATCH 1/5] Fixed error with madgraph qmt test of empty option text --- .../tests/qmtest/gauss.qms/gauss-gen-42912009-madgraph.qmt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sim/Gauss/tests/qmtest/gauss.qms/gauss-gen-42912009-madgraph.qmt b/Sim/Gauss/tests/qmtest/gauss.qms/gauss-gen-42912009-madgraph.qmt index d16879e17..3caf076d7 100644 --- a/Sim/Gauss/tests/qmtest/gauss.qms/gauss-gen-42912009-madgraph.qmt +++ b/Sim/Gauss/tests/qmtest/gauss.qms/gauss-gen-42912009-madgraph.qmt @@ -34,7 +34,7 @@ <argument name="unsupported_platforms"><set/></argument> <argument name="workdir"><text/></argument> <argument name="stderr"><text/></argument> -<argument name="options"><text></text></argument> +<!-- <argument name="options"><text></text></argument> --> <argument name="validator"><text> expected_string = "Application Manager Terminated successfully" expected_string2 = "5 events processed" -- GitLab From b87c5c361869742c65fedec43683910f76fce058 Mon Sep 17 00:00:00 2001 From: rpozzi <ruben.pozzi@cern.ch> Date: Tue, 16 May 2023 22:45:26 +0200 Subject: [PATCH 2/5] Removed .h file for MadgraphProduction and added it to source file --- .../src/component/MadgraphProduction.cpp | 119 +++++++++++++- .../src/component/MadgraphProduction.h | 150 ------------------ 2 files changed, 118 insertions(+), 151 deletions(-) delete mode 100644 Gen/LbMadgraph/src/component/MadgraphProduction.h diff --git a/Gen/LbMadgraph/src/component/MadgraphProduction.cpp b/Gen/LbMadgraph/src/component/MadgraphProduction.cpp index b59464fde..411e8ce0d 100644 --- a/Gen/LbMadgraph/src/component/MadgraphProduction.cpp +++ b/Gen/LbMadgraph/src/component/MadgraphProduction.cpp @@ -8,18 +8,135 @@ * granted to it by virtue of its status as an Intergovernmental Organization * * or submit itself to any jurisdiction. * \*****************************************************************************/ + +// Beginning of header + // Gaudi. #include "GaudiKernel/SystemOfUnits.h" #include "Kernel/ParticleProperty.h" +#include "GaudiKernel/IRndmEngine.h" +#include "GaudiKernel/IRndmGenSvc.h" + // Generators. #include "Generators/IBeamTool.h" +// LbHard +#include "LbHard/HardProduction.h" + // LbMadgraph. -#include "MadgraphProduction.h" +#include "LHAMadgraph.h" #include <filesystem> +/** + * Production tool to generate events with Madgraph. This class + * utilizes the LHAupMadgraph class from Pythia 8. + * + * This class automatically generates hard processes with MadGraph 5 + * and aMC@NLO, reads in the LHEF file output, and performs + * matching. For tree-level generation MLM matching is performed while + * FxFx is used for aMC@NLO generation. + * + * The user can send commands to MadGraph via the "Commands" + * configurable. Any string begining with "configure " is used for the + * initial MadGraph configuration with "configure " stripped from the + * begining. In general, only the process needs to be provided. Run + * settings must begin with " set" (note the leading space). The + * output and launch commands, random seed, and shower choice are + * automatically handled. For example, the following will produce + * di-muon events from 13 TeV proton proton collisions at NLO in QCD: + * + * readString("generate p p > mu+ mu- [QCD]") + * + * The number of events generated per MadGraph run is controlled by + * the "Events" configurable. In general the default should be + * sufficient, but for highly inefficient selections, increasing this + * number is recommended. The maximum number of jets produced by + * MadGraph (needed for matching) is automatically determined but can + * be manually specified with "Jets" configurable. In general these + * configurables should not need to be touched. + * + * Events are generated with MadGraph utilizing the "gridpack" method + * for MadGraph 5: + * + * https://cp3.irmp.ucl.ac.be/projects/madgraph/wiki/GridDevelopment + * + * and an eqivalent method for aMC@NLO: + * + * https://answers.launchpad.net/mg5amcnlo/+question/243268 + * + * The run directory is set as + * + * <event number>_<beam 1 energy in GeV>_<beam 2 energy in GeV> + * + * and does not need to be deleted between independent runs with the + * same configuration (excluding random seeds). Indeed, keeping the + * directory significantly speeds the generation process, particularly + * for NLO generation with aMC@NLO as the grid initialization can be + * skipped after the initial run. + * + * Gridpacks can be generated with the "doc/gridpack.sh" script using + * the command: + * + * ./gridpack.sh <beam configuration> <decay file> + * + * This will generate a zipped tarball of the gridpack which can then + * be stored in "Gen/MadgraphData/gridpacks". + * + * git clone ssh://git@gitlab.cern.ch:7999/lhcb-datapkg/Gen/MadgraphData.git + * cp <gridpack>.tgz MadgraphData/gridpacks/ + * git -am "Added gridpack for <gridpack>." + * git push + * + * Note that a gridpack is only valid for a given beam energy + * configuration and event type. Note that a gridpack is not necessary + * for this tool to run, but it is highly recommended. + * + * @class MadgraphProduction + * @author Philip Ilten + * @date 2018-08-01 + */ + +class MadgraphProduction : public HardProduction { +public: + + /// Default constructor. + MadgraphProduction(const std::string &type, const std::string &name, + const IInterface *parent); + + /// Default destructor. + ~MadgraphProduction(); + + /** + * Initialize the hard process tool. + * + * This is called by HardProduction::initialize prior to + * initialization of the shower. Here, the Pythia 8 LHAup pointer is + * created, and the Madgraph initialization is performed. + */ + StatusCode hardInitialize() override; + + /// Generate an event. + StatusCode generateEvent(HepMC::GenEvent *theEvent, + LHCb::GenCollision *theCollision) override; + + /// Finalize. + StatusCode finalize() override; + +private: + + // Members. + IRndmGenSvc *m_randSvc; ///< Random number service. + Pythia8::LHAupMadgraph *m_madgraph; ///< The Madgraph LHAup object. + int m_seed; ///< Current random seed. + int m_events; ///< Number of events per Madgraph run. + int m_jets; ///< Number of fixed order jets. + std::vector<std::string> m_pdf; ///< Default PDF commands. + int m_eventType; ///< Event type. + bool m_genGridpack; ///< Gridpack generation flag +}; + //----------------------------------------------------------------------------- // Implementation file for class: MadgraphProduction // diff --git a/Gen/LbMadgraph/src/component/MadgraphProduction.h b/Gen/LbMadgraph/src/component/MadgraphProduction.h deleted file mode 100644 index 47d0ff2b7..000000000 --- a/Gen/LbMadgraph/src/component/MadgraphProduction.h +++ /dev/null @@ -1,150 +0,0 @@ -/*****************************************************************************\ -* (c) Copyright 2020 CERN for the benefit of the LHCb Collaboration * -* * -* This software is distributed under the terms of the GNU General Public * -* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * -* * -* In applying this licence, CERN does not waive the privileges and immunities * -* granted to it by virtue of its status as an Intergovernmental Organization * -* or submit itself to any jurisdiction. * -\*****************************************************************************/ -#ifndef LBMADGRAPH_MADGRAPHPRODUCTION_H -#define LBMADGRAPH_MADGRAPHPRODUCTION_H 1 - -// Gaudi. -#include "GaudiKernel/IRndmEngine.h" -#include "GaudiKernel/IRndmGenSvc.h" - -// LbHard. -#include "LbHard/HardProduction.h" - -// LbMadgraph. -#include "LHAMadgraph.h" - -#include "Event/GenHeader.h" - - - - -/** - * Production tool to generate events with Madgraph. This class - * utilizes the LHAupMadgraph class from Pythia 8. - * - * This class automatically generates hard processes with MadGraph 5 - * and aMC@NLO, reads in the LHEF file output, and performs - * matching. For tree-level generation MLM matching is performed while - * FxFx is used for aMC@NLO generation. - * - * The user can send commands to MadGraph via the "Commands" - * configurable. Any string begining with "configure " is used for the - * initial MadGraph configuration with "configure " stripped from the - * begining. In general, only the process needs to be provided. Run - * settings must begin with " set" (note the leading space). The - * output and launch commands, random seed, and shower choice are - * automatically handled. For example, the following will produce - * di-muon events from 13 TeV proton proton collisions at NLO in QCD: - * - * readString("generate p p > mu+ mu- [QCD]") - * - * The number of events generated per MadGraph run is controlled by - * the "Events" configurable. In general the default should be - * sufficient, but for highly inefficient selections, increasing this - * number is recommended. The maximum number of jets produced by - * MadGraph (needed for matching) is automatically determined but can - * be manually specified with "Jets" configurable. In general these - * configurables should not need to be touched. - * - * Events are generated with MadGraph utilizing the "gridpack" method - * for MadGraph 5: - * - * https://cp3.irmp.ucl.ac.be/projects/madgraph/wiki/GridDevelopment - * - * and an eqivalent method for aMC@NLO: - * - * https://answers.launchpad.net/mg5amcnlo/+question/243268 - * - * The run directory is set as - * - * <event number>_<beam 1 energy in GeV>_<beam 2 energy in GeV> - * - * and does not need to be deleted between independent runs with the - * same configuration (excluding random seeds). Indeed, keeping the - * directory significantly speeds the generation process, particularly - * for NLO generation with aMC@NLO as the grid initialization can be - * skipped after the initial run. - * - * Gridpacks can be generated with the "doc/gridpack.sh" script using - * the command: - * - * ./gridpack.sh <beam configuration> <decay file> - * - * This will generate a zipped tarball of the gridpack which can then - * be stored in "Gen/MadgraphData/gridpacks". - * - * git clone ssh://git@gitlab.cern.ch:7999/lhcb-datapkg/Gen/MadgraphData.git - * cp <gridpack>.tgz MadgraphData/gridpacks/ - * git -am "Added gridpack for <gridpack>." - * git push - * - * Note that a gridpack is only valid for a given beam energy - * configuration and event type. Note that a gridpack is not necessary - * for this tool to run, but it is highly recommended. - * - * @class MadgraphProduction - * @file MadgraphProduction.h - * @author Philip Ilten - * @date 2018-08-01 - */ -class MadgraphProduction : public HardProduction { -public: - - /// Default constructor. - MadgraphProduction(const std::string &type, const std::string &name, - const IInterface *parent); - - /// Default destructor. - ~MadgraphProduction(); - - /** - * Initialize the hard process tool. - * - * This is called by HardProduction::initialize prior to - * initialization of the shower. Here, the Pythia 8 LHAup pointer is - * created, and the Madgraph initialization is performed. - */ - StatusCode hardInitialize() override; - - /// Generate an event. - StatusCode generateEvent(HepMC::GenEvent *theEvent, - LHCb::GenCollision *theCollision) override; - - /// Finalize. - StatusCode finalize() override; - -private: - /// Location where to store the Header of the events (set by options) - Gaudi::Property<std::string> m_genHeaderLocation - { - this,"GenHeaderLocation", - LHCb::GenHeaderLocation::Default,"GenHeaderLocation" - } - ; - - - - - - - - // Members. - IRndmGenSvc *m_randSvc; ///< Random number service. - Pythia8::LHAupMadgraph *m_madgraph; ///< The Madgraph LHAup object. - int m_seed; ///< Current random seed. - int m_events; ///< Number of events per Madgraph run. - int m_jets; ///< Number of fixed order jets. - std::vector<std::string> m_pdf; ///< Default PDF commands. - int m_eventType; ///< Event type. - bool m_genGridpack; ///< Gridpack generation flag -}; - -#endif // LBMADGRAPH_MADGRAPHPRODUCTION_H -- GitLab From 8ac80a7b2d25d47af2e477f8d81a4c7ab527c07b Mon Sep 17 00:00:00 2001 From: rpozzi <ruben.pozzi@cern.ch> Date: Wed, 17 May 2023 13:49:44 +0200 Subject: [PATCH 3/5] Rewrote qmt test --- .../src/component/MadgraphProduction.cpp | 2 ++ .../gauss.qms/gauss-gen-42912009-madgraph.qmt | 26 +++++++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Gen/LbMadgraph/src/component/MadgraphProduction.cpp b/Gen/LbMadgraph/src/component/MadgraphProduction.cpp index 411e8ce0d..359fc4679 100644 --- a/Gen/LbMadgraph/src/component/MadgraphProduction.cpp +++ b/Gen/LbMadgraph/src/component/MadgraphProduction.cpp @@ -137,6 +137,8 @@ private: bool m_genGridpack; ///< Gridpack generation flag }; +// End of header + //----------------------------------------------------------------------------- // Implementation file for class: MadgraphProduction // diff --git a/Sim/Gauss/tests/qmtest/gauss.qms/gauss-gen-42912009-madgraph.qmt b/Sim/Gauss/tests/qmtest/gauss.qms/gauss-gen-42912009-madgraph.qmt index 3caf076d7..e8b4d9855 100644 --- a/Sim/Gauss/tests/qmtest/gauss.qms/gauss-gen-42912009-madgraph.qmt +++ b/Sim/Gauss/tests/qmtest/gauss.qms/gauss-gen-42912009-madgraph.qmt @@ -36,22 +36,16 @@ <argument name="stderr"><text/></argument> <!-- <argument name="options"><text></text></argument> --> <argument name="validator"><text> -expected_string = "Application Manager Terminated successfully" -expected_string2 = "5 events processed" -expected_string3 = "Requested to generate EventType 42912009" -expected_string4 = "Using as production engine MadgraphProduction" -if stdout.find(expected_string) == -1: - causes.append('missing string 1') - result['GaudiTest.expected_string'] = result.Quote(expected_string) -if stdout.find(expected_string2) == -1: - causes.append('missing string 2') - result['GaudiTest.expected_string2'] = result.Quote(expected_string2) -if stdout.find(expected_string3) == -1: - causes.append('missing string 3') - result['GaudiTest.expected_string3'] = result.Quote(expected_string3) -if stdout.find(expected_string4) == -1: - causes.append('missing string 4') - result['GaudiTest.expected_string4'] = result.Quote(expected_string4) +expected_strings = [ + "Application Manager Terminated successfully", + "5 events processed", + "Requested to generate EventType 42912009", + "Using as production engine MadgraphProduction" + ] +for exp_string in expected_strings: + if exp_string not in stdout: + causes.append('missing string') + result['GaudiTest.exp_string'] = result.Quote(exp_string) </text></argument> <argument name="resources"><set/></argument> <argument name="stdin"><text/></argument> -- GitLab From d0afbc06817f8faeca2df2b5c3a7de6c00d97914 Mon Sep 17 00:00:00 2001 From: rpozzi <ruben.pozzi@cern.ch> Date: Mon, 22 May 2023 12:01:10 +0200 Subject: [PATCH 4/5] Getting rid of declareProperties --- .../src/component/MadgraphProduction.cpp | 100 +++++++----------- 1 file changed, 38 insertions(+), 62 deletions(-) diff --git a/Gen/LbMadgraph/src/component/MadgraphProduction.cpp b/Gen/LbMadgraph/src/component/MadgraphProduction.cpp index 359fc4679..07e58bef5 100644 --- a/Gen/LbMadgraph/src/component/MadgraphProduction.cpp +++ b/Gen/LbMadgraph/src/component/MadgraphProduction.cpp @@ -27,6 +27,9 @@ // LbMadgraph. #include "LHAMadgraph.h" +#include "Event/GenHeader.h" + + #include <filesystem> /** @@ -99,42 +102,47 @@ */ class MadgraphProduction : public HardProduction { -public: + public: - /// Default constructor. - MadgraphProduction(const std::string &type, const std::string &name, - const IInterface *parent); + /// Default constructor. + using HardProduction::HardProduction; - /// Default destructor. - ~MadgraphProduction(); - - /** - * Initialize the hard process tool. - * - * This is called by HardProduction::initialize prior to - * initialization of the shower. Here, the Pythia 8 LHAup pointer is - * created, and the Madgraph initialization is performed. - */ - StatusCode hardInitialize() override; + /** + * Initialize the hard process tool. + * + * This is called by HardProduction::initialize prior to + * initialization of the shower. Here, the Pythia 8 LHAup pointer is + * created, and the Madgraph initialization is performed. + */ + StatusCode hardInitialize() override; - /// Generate an event. - StatusCode generateEvent(HepMC::GenEvent *theEvent, - LHCb::GenCollision *theCollision) override; + /// Generate an event. + StatusCode generateEvent(HepMC::GenEvent *theEvent, + LHCb::GenCollision *theCollision) override; - /// Finalize. - StatusCode finalize() override; + /// Finalize. + StatusCode finalize() override; + + private: -private: + // Members. + IRndmGenSvc *m_randSvc{nullptr}; ///< Random number service. + Pythia8::LHAupMadgraph *m_madgraph{nullptr}; ///< The Madgraph LHAup object. + Pythia8::UserHooks *m_hooks{nullptr}; ///< User hooks to veto events. + int m_seed{0}; ///< Current random seed. + Gaudi::Property<int> m_events {this, "Events",10000, + "Number of events to produce per Madgraph run."}; ///< Number of events per Madgraph run. + Gaudi::Property<int> m_jets{this, "Jets", -1, + "Number of jets produced at the highest fixed order." "If -1, then try to determine the number of jets."}; ///< Number of fixed order jets. + Gaudi::Property<std::vector<std::string>> m_pdf {this, "PdfCommands", {" set pdlabel lhapdf", " set lhaid 10770"}, + "Default PDF commands when no user PDF commands specified."}; ///< Default PDF commands. + Gaudi::Property<int> m_eventType {this, "EventType", 0, + "Event type, needed when searching for a gridpack."}; ///< Event type. + Gaudi::Property<bool> m_genGridpack{this, "GenGridpack", false, + "Flag for gridpack generation (only to be used by experts)" "If == true, no gridpack search is performed." }; ///< Gridpack generation flag + /// Location where to store the Header of the events (set by options) + Gaudi::Property<std::string> m_genHeaderLocation{this, "GenHeaderLocation", LHCb::GenHeaderLocation::Default,"GenHeaderLocation"}; - // Members. - IRndmGenSvc *m_randSvc; ///< Random number service. - Pythia8::LHAupMadgraph *m_madgraph; ///< The Madgraph LHAup object. - int m_seed; ///< Current random seed. - int m_events; ///< Number of events per Madgraph run. - int m_jets; ///< Number of fixed order jets. - std::vector<std::string> m_pdf; ///< Default PDF commands. - int m_eventType; ///< Event type. - bool m_genGridpack; ///< Gridpack generation flag }; // End of header @@ -148,38 +156,6 @@ private: // Declaration of the tool factory. DECLARE_COMPONENT( MadgraphProduction ) -//============================================================================= -// Default constructor. -//============================================================================= -MadgraphProduction::MadgraphProduction(const std::string &type, - const std::string &name, - const IInterface *parent) -: HardProduction (type, name, parent), m_randSvc(0), m_madgraph(0), m_seed(0){ - - // Declare the tool properties. - declareInterface<IProductionTool>(this); - declareProperty("Events", m_events = 10000, - "Number of events to produce per Madgraph run."); - declareProperty("Jets", m_jets = -1, - "Number of jets produced at the highest fixed order. " - "If -1, then try to determine the number of jets."); - declareProperty("PdfCommands", - m_pdf = {" set pdlabel lhapdf", " set lhaid 10770"}, - "Default PDF commands when no user PDF commands specified."); - declareProperty("EventType", m_eventType = 0, - "Event type, needed when searching for a gridpack."); - declareProperty("GenGridpack", m_genGridpack = false, - "Flag for gridpack generation (only to be used by experts)" - "If == true, no gridpack search is performed."); -} - -//============================================================================= -// Default destructor. -//============================================================================= -MadgraphProduction::~MadgraphProduction() { - // No deletion of m_madgraph is required, as this is called by - // Pythia8Production::finalize(). -} //============================================================================= // Initialize the hard process tool. -- GitLab From adf6fae9cf43550f61a65d6dc987e8c175b36f68 Mon Sep 17 00:00:00 2001 From: rpozzi <ruben.pozzi@cern.ch> Date: Tue, 8 Aug 2023 10:56:59 +0200 Subject: [PATCH 5/5] Removing redundant GenHeaderLocation --- Gen/LbHard/include/LbHard/HardProduction.h | 15 +++++++++------ .../src/component/MadgraphProduction.cpp | 3 --- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Gen/LbHard/include/LbHard/HardProduction.h b/Gen/LbHard/include/LbHard/HardProduction.h index 4b93539da..a8f92a943 100644 --- a/Gen/LbHard/include/LbHard/HardProduction.h +++ b/Gen/LbHard/include/LbHard/HardProduction.h @@ -131,12 +131,15 @@ protected: int hashSeed(); // Properties. - Gaudi::Property<CommandVector> m_userSettings{this,"Commands",{},"The commands to pass to the hard process generator."}; ///< The user settings vector. - Gaudi::Property<std::string> m_beamToolName{this,"BeamToolName","CollidingBeams","The beam tool to use."}; ///< The beam tool name. - Gaudi::Property<std::string> m_showerToolName{this,"ShowerToolName","PythiaProduction", - "The shower tool to use: PythiaProduction, Pythia8Production," - " or HerwigppProduction."}; ///< The shower generator name. - Gaudi::Property<std::string> m_genHeaderLocation{this,"GenHeaderLocation",LHCb::GenHeaderLocation::Default,"GenHeaderLocation"}; + Gaudi::Property<CommandVector> m_userSettings{this, "Commands" , {}, + "The commands to pass to the hard process generator."}; ///< The user settings vector. + Gaudi::Property<std::string> m_beamToolName{this, "BeamToolName", "CollidingBeams", + "The beam tool to use."}; ///< The beam tool name. + Gaudi::Property<std::string> m_showerToolName{this, "ShowerToolName", "PythiaProduction", + "The shower tool to use: PythiaProduction, Pythia8Production or HerwigppProduction."}; ///< The shower generator name. + Gaudi::Property<std::string> m_genHeaderLocation{this, "GenHeaderLocation", LHCb::GenHeaderLocation::Default, + "GenHeaderLocation"}; ///< Location where to store the Header of the events (set by options) + diff --git a/Gen/LbMadgraph/src/component/MadgraphProduction.cpp b/Gen/LbMadgraph/src/component/MadgraphProduction.cpp index 07e58bef5..f8061fcd2 100644 --- a/Gen/LbMadgraph/src/component/MadgraphProduction.cpp +++ b/Gen/LbMadgraph/src/component/MadgraphProduction.cpp @@ -140,9 +140,6 @@ class MadgraphProduction : public HardProduction { "Event type, needed when searching for a gridpack."}; ///< Event type. Gaudi::Property<bool> m_genGridpack{this, "GenGridpack", false, "Flag for gridpack generation (only to be used by experts)" "If == true, no gridpack search is performed." }; ///< Gridpack generation flag - /// Location where to store the Header of the events (set by options) - Gaudi::Property<std::string> m_genHeaderLocation{this, "GenHeaderLocation", LHCb::GenHeaderLocation::Default,"GenHeaderLocation"}; - }; // End of header -- GitLab