Project
Loading...
Searching...
No Matches
G4FastSimulation.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15#include "SimConfig/G4Params.h"
16
17#include <fairlogger/Logger.h>
18
19#include <sstream>
20
21namespace o2::fastsim
22{
23
24namespace
25{
26std::vector<std::string> split(const std::string& value, char sep)
27{
28 std::vector<std::string> out;
29 std::stringstream stream(value);
30 std::string token;
31 while (std::getline(stream, token, sep)) {
32 if (!token.empty()) {
33 out.push_back(token);
34 }
35 }
36 return out;
37}
38} // namespace
39
40//_____________________________________________________________________________
41G4FastSimulation::G4FastSimulation(std::vector<std::string> models,
42 const std::string& envelope, double minEnergyGeV)
43 : TG4VUserFastSimulation(), mModels(std::move(models)), mEnvelope(envelope), mMinEnergy(minEnergyGeV)
44{
45 // Only the model itself can be declared here: this constructor runs before the
46 // geometry exists, so the regions cannot be derived yet. They are set later by
47 // FastSimRegionConstruction, in the window between geometry construction and
48 // region creation.
49 for (const auto& model : mModels) {
50 SetModel(model);
51 SetModelParticles(model, "all");
52 }
53}
54
55//_____________________________________________________________________________
57{
58 for (const auto& model : mModels) {
59 if (model == "toyAbsorber") {
60 LOG(info) << "fast simulation: registering model " << model << " on envelope '" << mEnvelope
61 << "' above " << mMinEnergy << " GeV";
62 Register(new ToyAbsorberFastSim(model, mEnvelope, mMinEnergy));
63 } else {
64 LOG(error) << "fast simulation: unknown model " << model << "; ignored";
65 }
66 }
67}
68
69//_____________________________________________________________________________
71{
73 auto models = split(params.fastSimModels, ',');
74 if (models.empty()) {
75 return nullptr; // the default: no fast simulation, unchanged behaviour
76 }
77 LOG(info) << "fast simulation is ENABLED on envelope '" << params.fastSimEnvelope << "'";
78 return new G4FastSimulation(std::move(models), params.fastSimEnvelope, params.fastSimMinEnergy);
79}
80
81//_____________________________________________________________________________
83{
85 auto models = split(params.fastSimModels, ',');
86 if (models.empty()) {
87 return TG4RunConfiguration::CreateUserPostDetConstruction();
88 }
89 std::vector<FastSimRegionConstruction::ModelRegions> wanted;
90 wanted.reserve(models.size());
91 for (auto& model : models) {
92 wanted.push_back({model, params.fastSimEnvelope, params.fastSimRegions});
93 }
94 return new FastSimRegionConstruction(std::move(wanted));
95}
96
97} // namespace o2::fastsim
Creates and registers the models named in G4.fastSimModels.
G4FastSimulation(std::vector< std::string > models, const std::string &envelope, double minEnergyGeV)
TG4VUserFastSimulation * CreateUserFastSimulation() override
TG4VUserPostDetConstruction * CreateUserPostDetConstruction() override
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLenum const GLfloat * params
Definition glcorearb.h:272
GLuint GLuint stream
Definition glcorearb.h:1806
std::vector< std::string > split(const std::string &str, char delimiter=',')
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"