Skip to content

Commit

Permalink
Introduce FairExampleRunSim
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianTackeGSI committed Sep 23, 2023
1 parent e41888e commit 9f17cf7
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 28 deletions.
17 changes: 14 additions & 3 deletions examples/MQ/pixelDetector/macros/run_sim.C
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
/********************************************************************************
* Copyright (C) 2014-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2014-2023 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 <TFile.h>
#include <TH1F.h>
#include <TStopwatch.h>
Expand Down Expand Up @@ -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<FairRunSim>();
run->SetName(mcEngine); // Transport engine
auto run = std::make_unique<FairExampleRunSim>(mcEngine.Data());
run->SetIsMT(isMT); // Multi-threading mode (Geant4 only)
run->SetSink(std::make_unique<FairRootFileSink>(outFile));
FairRuntimeDb* rtdb = run->GetRuntimeDb();
Expand Down
4 changes: 2 additions & 2 deletions examples/MQ/pixelDetector/src/devices/FairMQSimDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "FairMQSimDevice.h"

#include "FairExampleRunSim.h"
#include "FairModule.h"
#include "FairParSet.h"
#include "FairPrimaryGenerator.h"
Expand Down Expand Up @@ -44,7 +45,7 @@ FairMQSimDevice::FairMQSimDevice()

void FairMQSimDevice::InitTask()
{
fRunSim = std::make_unique<FairRunSim>();
fRunSim = std::make_unique<FairExampleRunSim>(fTransportName.c_str());

SetupRunSink(*fRunSim);

Expand All @@ -56,7 +57,6 @@ void FairMQSimDevice::InitTask()
rtdb->setSecondInput(fSecondParameter);
}

fRunSim->SetName(fTransportName.c_str());
// fRunSim->SetSimulationConfig(new FairVMCConfig());
fRunSim->SetIsMT(kFALSE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "FairMQTransportDevice.h"

#include "FairExampleRunSim.h"
#include "FairGenericStack.h"
#include "FairMCApplication.h"
#include "FairMCSplitEventHeader.h"
Expand Down Expand Up @@ -65,7 +66,7 @@ void FairMQTransportDevice::Init()

void FairMQTransportDevice::InitTask()
{
fRunSim = std::make_unique<FairRunSim>();
fRunSim = std::make_unique<FairExampleRunSim>(fTransportName.c_str());

fMCSplitEventHeader = new FairMCSplitEventHeader(fRunId, 0, 0, 0);
fRunSim->SetMCEventHeader(fMCSplitEventHeader);
Expand All @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions examples/advanced/Tutorial3/macro/run_sim.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* copied verbatim in the file "LICENSE" *
********************************************************************************/

#include "FairExampleRunSim.h"

#if !defined(__CLING__) || defined(__ROOTCLING__)
#include "FairBoxGenerator.h"
#include "FairCave.h"
Expand All @@ -14,7 +16,6 @@
#include "FairParRootFileIo.h"
#include "FairPrimaryGenerator.h"
#include "FairRootFileSink.h"
#include "FairRunSim.h"
#include "FairSystemInfo.h"
#include "FairTestDetector.h"
#endif
Expand Down Expand Up @@ -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";
Expand Down
26 changes: 20 additions & 6 deletions examples/advanced/Tutorial3/macro/run_sim_sep.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,29 @@
* 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 <TRandom.h>
#include <TStopwatch.h>
#include <TString.h>
#include <TSystem.h>
#include <iostream>

using std::cout;
using std::endl;

void run_sim_sep(Int_t fileId, Int_t nEvents = 1000, TString mcEngine = "TGeant3")
{
Expand All @@ -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);
Expand Down
21 changes: 19 additions & 2 deletions examples/advanced/propagator/macros/runMC.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,30 @@
* 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 <TRandom.h>
#include <TStopwatch.h>
#include <TString.h>
#include <TSystem.h>
#include <iostream>
#include <memory>

using std::cout;
using std::endl;

int runMC(Int_t nEvents = 1000, TString mcEngine = "TGeant4", Bool_t isMT = false)
{
UInt_t randomSeed = 123456;
Expand Down Expand Up @@ -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<FairRootFileSink>(outFile));
Expand Down
20 changes: 18 additions & 2 deletions examples/advanced/propagator/macros/runMM.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,27 @@
* 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 <TRandom.h>
#include <TStopwatch.h>
#include <TString.h>
#include <TSystem.h>
#include <iostream>

using std::cout;
using std::endl;

int runMM(Int_t nEvents = 1000, TString mcEngine = "TGeant4", Bool_t isMT = false)
{
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/common/mcstack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
set(target ExMCStack)

set(sources
FairExampleRunSim.cxx
FairMCTrack.cxx
FairStack.cxx
)
Expand Down
15 changes: 15 additions & 0 deletions examples/common/mcstack/FairExampleRunSim.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/********************************************************************************
* Copyright (C) 2023 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);
}
32 changes: 32 additions & 0 deletions examples/common/mcstack/FairExampleRunSim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/********************************************************************************
* Copyright (C) 2023 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
8 changes: 4 additions & 4 deletions examples/common/mcstack/LinkDef.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2014-2023 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
Expand All @@ -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

0 comments on commit 9f17cf7

Please sign in to comment.