From ce472af238cd54bb7f81be0f094386e59d01efe7 Mon Sep 17 00:00:00 2001 From: Christian Tacke <58549698+ChristianTackeGSI@users.noreply.github.com> Date: Fri, 23 Feb 2024 16:11:31 +0100 Subject: [PATCH] Introduce FairExampleRunSim --- examples/MQ/pixelDetector/macros/run_sim.C | 17 ++++++++-- .../src/devices/FairMQSimDevice.cxx | 6 ++-- .../src/devices/FairMQTransportDevice.cxx | 5 ++- examples/advanced/Tutorial3/macro/run_sim.C | 11 +++---- .../advanced/Tutorial3/macro/run_sim_sep.C | 28 ++++++++++++---- examples/advanced/propagator/macros/runMC.C | 23 +++++++++++-- examples/advanced/propagator/macros/runMM.C | 22 +++++++++++-- examples/common/mcstack/CMakeLists.txt | 3 +- examples/common/mcstack/FairExampleRunSim.cxx | 15 +++++++++ examples/common/mcstack/FairExampleRunSim.h | 32 +++++++++++++++++++ examples/common/mcstack/LinkDef.h | 8 ++--- 11 files changed, 136 insertions(+), 34 deletions(-) create mode 100644 examples/common/mcstack/FairExampleRunSim.cxx create mode 100644 examples/common/mcstack/FairExampleRunSim.h diff --git a/examples/MQ/pixelDetector/macros/run_sim.C b/examples/MQ/pixelDetector/macros/run_sim.C index 64ae764724..624f2b44c3 100644 --- a/examples/MQ/pixelDetector/macros/run_sim.C +++ b/examples/MQ/pixelDetector/macros/run_sim.C @@ -1,11 +1,23 @@ /******************************************************************************** - * Copyright (C) 2014-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ +#include "FairExampleRunSim.h" + +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include "FairBoxGenerator.h" +#include "FairCave.h" +#include "FairParRootFileIo.h" +#include "FairPrimaryGenerator.h" +#include "FairRootFileSink.h" +#include "FairSystemInfo.h" +#include "Pixel.h" +#endif + #include #include #include @@ -59,8 +71,7 @@ void run_sim(Int_t nEvents = 10, TString mcEngine = "TGeant3", Int_t fileId = 0, // ------------------------------------------------------------------------ // ----- Create simulation run ---------------------------------------- - auto run = std::make_unique(); - run->SetName(mcEngine); // Transport engine + auto run = std::make_unique(mcEngine.Data()); run->SetIsMT(isMT); // Multi-threading mode (Geant4 only) run->SetSink(std::make_unique(outFile)); FairRuntimeDb* rtdb = run->GetRuntimeDb(); diff --git a/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.cxx b/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.cxx index 0d7a54ec09..3635fbe08b 100644 --- a/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.cxx +++ b/examples/MQ/pixelDetector/src/devices/FairMQSimDevice.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence version 3 (LGPL) version 3, * @@ -14,6 +14,7 @@ #include "FairMQSimDevice.h" +#include "FairExampleRunSim.h" #include "FairModule.h" #include "FairParSet.h" #include "FairPrimaryGenerator.h" @@ -44,7 +45,7 @@ FairMQSimDevice::FairMQSimDevice() void FairMQSimDevice::InitTask() { - fRunSim = std::make_unique(); + fRunSim = std::make_unique(fTransportName.c_str()); SetupRunSink(*fRunSim); @@ -56,7 +57,6 @@ void FairMQSimDevice::InitTask() rtdb->setSecondInput(fSecondParameter); } - fRunSim->SetName(fTransportName.c_str()); // fRunSim->SetSimulationConfig(new FairVMCConfig()); fRunSim->SetIsMT(kFALSE); diff --git a/examples/MQ/pixelSimSplit/src/devices/FairMQTransportDevice.cxx b/examples/MQ/pixelSimSplit/src/devices/FairMQTransportDevice.cxx index b129ba9f14..43e1a1d54a 100644 --- a/examples/MQ/pixelSimSplit/src/devices/FairMQTransportDevice.cxx +++ b/examples/MQ/pixelSimSplit/src/devices/FairMQTransportDevice.cxx @@ -14,6 +14,7 @@ #include "FairMQTransportDevice.h" +#include "FairExampleRunSim.h" #include "FairGenericStack.h" #include "FairMCApplication.h" #include "FairMCSplitEventHeader.h" @@ -65,7 +66,7 @@ void FairMQTransportDevice::Init() void FairMQTransportDevice::InitTask() { - fRunSim = std::make_unique(); + fRunSim = std::make_unique(fTransportName.c_str()); fMCSplitEventHeader = new FairMCSplitEventHeader(fRunId, 0, 0, 0); fRunSim->SetMCEventHeader(fMCSplitEventHeader); @@ -81,8 +82,6 @@ void FairMQTransportDevice::InitTask() rtdb->setSecondInput(fSecondParameter); } - fRunSim->SetName(fTransportName.c_str()); - if (fUserConfig.Length() > 0) fRunSim->SetUserConfig(fUserConfig); if (fUserCuts.Length() > 0) diff --git a/examples/advanced/Tutorial3/macro/run_sim.C b/examples/advanced/Tutorial3/macro/run_sim.C index 6a86e0717a..4bfbcdbe6d 100644 --- a/examples/advanced/Tutorial3/macro/run_sim.C +++ b/examples/advanced/Tutorial3/macro/run_sim.C @@ -1,11 +1,13 @@ /******************************************************************************** - * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ +#include "FairExampleRunSim.h" + #if !defined(__CLING__) || defined(__ROOTCLING__) #include "FairBoxGenerator.h" #include "FairCave.h" @@ -14,7 +16,6 @@ #include "FairParRootFileIo.h" #include "FairPrimaryGenerator.h" #include "FairRootFileSink.h" -#include "FairRunSim.h" #include "FairSystemInfo.h" #include "FairTestDetector.h" #endif @@ -45,13 +46,9 @@ void run_sim(Int_t nEvents = 100, TString mcEngine = "TGeant4") gSystem->Setenv("CONFIG_DIR", tut_configdir.Data()); // create Instance of Run Manager class - FairRunSim run{}; + FairExampleRunSim run{mcEngine.Data()}; run.SetUseFairLinks(kTRUE); // FairLinkManager::Instance()->AddIncludeType(0); - // set the MC version used - // ------------------------ - - run.SetName(mcEngine); TString outFile = "data/testrun_"; outFile = outFile + mcEngine + ".root"; diff --git a/examples/advanced/Tutorial3/macro/run_sim_sep.C b/examples/advanced/Tutorial3/macro/run_sim_sep.C index 518c4d1da6..f5c8c4c240 100644 --- a/examples/advanced/Tutorial3/macro/run_sim_sep.C +++ b/examples/advanced/Tutorial3/macro/run_sim_sep.C @@ -1,15 +1,34 @@ /******************************************************************************** - * Copyright (C) 2012-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2012-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ +#include "FairExampleRunSim.h" + +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include "FairBoxGenerator.h" +#include "FairCave.h" +#include "FairConstField.h" +#include "FairMagnet.h" +#include "FairParRootFileIo.h" +#include "FairPrimaryGenerator.h" +#include "FairRootFileSink.h" +#include "FairRuntimeDb.h" +#include "FairSystemInfo.h" +#include "FairTestDetector.h" +#endif + #include #include #include #include +#include + +using std::cout; +using std::endl; void run_sim_sep(Int_t fileId, Int_t nEvents = 1000, TString mcEngine = "TGeant3") { @@ -30,12 +49,7 @@ void run_sim_sep(Int_t fileId, Int_t nEvents = 1000, TString mcEngine = "TGeant3 gSystem->Setenv("CONFIG_DIR", tut_configdir.Data()); // create Instance of Run Manager class - FairRunSim run{}; - - // set the MC version used - // ------------------------ - - run.SetName(mcEngine); + FairExampleRunSim run{mcEngine}; TString outfile = Form("data/testrun_%s_f%d.root", mcEngine.Data(), fileId); TString outparam = Form("data/testpar_%s_f%d.root", mcEngine.Data(), fileId); diff --git a/examples/advanced/propagator/macros/runMC.C b/examples/advanced/propagator/macros/runMC.C index e4d258abb6..629fc86ef4 100644 --- a/examples/advanced/propagator/macros/runMC.C +++ b/examples/advanced/propagator/macros/runMC.C @@ -1,17 +1,35 @@ /******************************************************************************** - * Copyright (C) 2019-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2019-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ +#include "FairExampleRunSim.h" + +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include "FairBoxGenerator.h" +#include "FairCave.h" +#include "FairConstField.h" +#include "FairParRootFileIo.h" +#include "FairPrimaryGenerator.h" +#include "FairRootFileSink.h" +#include "FairSystemInfo.h" +#include "FairTrajFilter.h" +#include "FairTutPropDet.h" +#endif + #include #include #include #include +#include #include +using std::cout; +using std::endl; + int runMC(Int_t nEvents = 1000, TString mcEngine = "TGeant4", Bool_t isMT = false) { UInt_t randomSeed = 123456; @@ -55,8 +73,7 @@ int runMC(Int_t nEvents = 1000, TString mcEngine = "TGeant4", Bool_t isMT = fals // ------------------------------------------------------------------------ // ----- Create simulation run ---------------------------------------- - FairRunSim run{}; - run.SetName(mcEngine); // Transport engine + FairExampleRunSim run{mcEngine.Data()}; // run.SetSimulationConfig(new FairVMCConfig()); run.SetIsMT(isMT); // Multi-threading mode (Geant4 only) run.SetSink(std::make_unique(outFile)); diff --git a/examples/advanced/propagator/macros/runMM.C b/examples/advanced/propagator/macros/runMM.C index 652cff0369..6d61fd3547 100644 --- a/examples/advanced/propagator/macros/runMM.C +++ b/examples/advanced/propagator/macros/runMM.C @@ -1,15 +1,32 @@ /******************************************************************************** - * Copyright (C) 2019-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2019-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ +#include "FairExampleRunSim.h" + +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include "FairBoxGenerator.h" +#include "FairCave.h" +#include "FairConstField.h" +#include "FairParRootFileIo.h" +#include "FairPrimaryGenerator.h" +#include "FairRootFileSink.h" +#include "FairSystemInfo.h" +#include "FairTutPropDet.h" +#endif + #include #include #include #include +#include + +using std::cout; +using std::endl; int runMM(Int_t nEvents = 1000, TString mcEngine = "TGeant4", Bool_t isMT = false) { @@ -47,8 +64,7 @@ int runMM(Int_t nEvents = 1000, TString mcEngine = "TGeant4", Bool_t isMT = fals // ------------------------------------------------------------------------ // ----- Create simulation run ---------------------------------------- - FairRunSim run{}; - run.SetName(mcEngine); // Transport engine + FairExampleRunSim run{mcEngine}; // run.SetSimulationConfig(new FairVMCConfig()); run.SetIsMT(isMT); // Multi-threading mode (Geant4 only) run.SetSink(new FairRootFileSink(outFile)); // Output file diff --git a/examples/common/mcstack/CMakeLists.txt b/examples/common/mcstack/CMakeLists.txt index 9cebc30630..1f2aea2cb0 100644 --- a/examples/common/mcstack/CMakeLists.txt +++ b/examples/common/mcstack/CMakeLists.txt @@ -1,5 +1,5 @@ ################################################################################ -# Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # +# Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # # # # This software is distributed under the terms of the # # GNU Lesser General Public Licence (LGPL) version 3, # @@ -9,6 +9,7 @@ set(target ExMCStack) set(sources + FairExampleRunSim.cxx FairMCTrack.cxx FairStack.cxx ) diff --git a/examples/common/mcstack/FairExampleRunSim.cxx b/examples/common/mcstack/FairExampleRunSim.cxx new file mode 100644 index 0000000000..a863985415 --- /dev/null +++ b/examples/common/mcstack/FairExampleRunSim.cxx @@ -0,0 +1,15 @@ +/******************************************************************************** + * Copyright (C) 2023-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +#include "FairExampleRunSim.h" + +FairExampleRunSim::FairExampleRunSim(const char* mcEngine) + : FairRunSim() +{ + SetName(mcEngine); +} diff --git a/examples/common/mcstack/FairExampleRunSim.h b/examples/common/mcstack/FairExampleRunSim.h new file mode 100644 index 0000000000..958dfae465 --- /dev/null +++ b/examples/common/mcstack/FairExampleRunSim.h @@ -0,0 +1,32 @@ +/******************************************************************************** + * Copyright (C) 2023-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIREXAMPLERUNSIM_H +#define FAIREXAMPLERUNSIM_H + +#include "FairRunSim.h" + +/** + * \brief RunSim with specific behaviour for an experiment + * + * \note This is an advanced use case and is likely only + * interesting for bigger / more complex experiments + * that need this kind of refactoring. + * + * One can derive from the FairRun classes. + * But please only call public APIs from inside any member + * functions. + */ +class FairExampleRunSim : public FairRunSim +{ + public: + explicit FairExampleRunSim(const char* mcEngine); + ~FairExampleRunSim() override = default; + ClassDefOverride(FairExampleRunSim, 0); +}; + +#endif diff --git a/examples/common/mcstack/LinkDef.h b/examples/common/mcstack/LinkDef.h index bece7e043d..d0f9a7af04 100644 --- a/examples/common/mcstack/LinkDef.h +++ b/examples/common/mcstack/LinkDef.h @@ -1,8 +1,8 @@ /******************************************************************************** - * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * - * This software is distributed under the terms of the * - * GNU Lesser General Public Licence (LGPL) version 3, * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ // $Id: ZdcLinkDef.h,v 1.1.1.1 @@ -14,8 +14,8 @@ #pragma link off all classes; #pragma link off all functions; +#pragma link C++ class FairExampleRunSim+; #pragma link C++ class FairStack+; #pragma link C++ class FairMCTrack+; #endif -