CbmRoot
Loading...
Searching...
No Matches
CbmGeant4Settings.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer] */
4
5#include "CbmGeant4Settings.h"
6
7#include <FairRunSim.h>
8#include <Logger.h>
9
10#include <TGeant4.h>
11#include <TPythia6Decayer.h>
12#include <TVirtualMC.h>
13
14#include <G4NuclearLevelData.hh>
15
16void CbmGeant4Settings::Init(TVirtualMC* vmc)
17{
18
20
21 TGeant4* vmcg4 = dynamic_cast<TGeant4*>(vmc);
22
23 assert(vmcg4);
24
25 // TODO: These settings were taken over from g4Config.C. To be documented.
26
27 // --- Set external decayer (Pythia) if required
28 if (FairRunSim::Instance()->IsExtDecayer()) {
29 TVirtualMCDecayer* decayer = TPythia6Decayer::Instance();
30 vmcg4->SetExternalDecayer(decayer);
31 LOG(info) << ": Using Phythia6 decayer";
32 }
33
34 // --- Random seed and maximum number of steps
35 size_t buf_size = 100;
36 Text_t buffer[buf_size];
37 // Get the infomation about the seed value defined by SetSeed from the base class.
38 // Since ROOT 6.24 the derrived classes return a differnt value.
39 fRandomSeed = gRandom->TRandom::GetSeed();
40 LOG(info) << "Set Geant4 random seed to " << fRandomSeed;
41 int result_length = snprintf(buffer, buf_size - 1, "/random/setSeeds %i %i ", fRandomSeed, fRandomSeed);
42 if (!(result_length > 0 && result_length < static_cast<int>(buf_size))) {
43 LOG(fatal) << "Buffer overrun. Random seed for Geant4 would be improper.";
44 }
45 vmcg4->ProcessGeantCommand(buffer);
46
47 vmcg4->SetMaxNStep(fMaxNumSteps);
48
49 for (std::string command : fG4Commands) {
50 LOG(info) << "Passing the following command to Geant4: " << command;
51 vmcg4->ProcessGeantCommand(command.c_str());
52 }
53
54 LOG(warning) << "Fix for Geant4 bug applied (see "
55 "https://bugzilla-geant4.kek.jp/show_bug.cgi?id=2226)";
56 G4NuclearLevelData::GetInstance()->GetParameters()->SetMaxLifeTime(1 * CLHEP::microsecond);
57}
58
ClassImp(CbmGeant4Settings)
User interface class to define the Geant4 simulation settings.
void Init(TVirtualMC *)
Set all parameters defined in this class.
std::vector< std::string > fG4Commands
void Init(TVirtualMC *)
Set all parameters defined in this class.