19#include "Ex03PrimaryGenerator.h"
22#include <TMCRootManager.h>
24#include <TMCManager.h>
27#include <TGeoManager.h>
28#include <TGeoUniformMagField.h>
29#include <TInterpreter.h>
36#include <TVirtualGeoTrack.h>
37#include <TVirtualMC.h>
39#include <TLorentzVector.h>
49 const
char* name, const
char* title, Bool_t isMulti, Bool_t splitSimulation)
64 fSplitSimulation(splitSimulation),
73 if (splitSimulation && !isMulti) {
74 Fatal(
"Ex03cMCApplication",
75 "Cannot split simulation between engines without \"isMulti\" being "
79 cout <<
"--------------------------------------------------------------"
81 cout <<
" VMC Example E03c: new version with multiple engines" << endl;
82 cout <<
"--------------------------------------------------------------"
98 fMagField =
new TGeoUniformMagField();
102 fMCManager->SetUserStack(fStack);
110 fPrintModulo(origin.fPrintModulo),
112 fVerbose(origin.fVerbose),
114 fDetConstruction(origin.fDetConstruction),
116 fPrimaryGenerator(0),
118 fOldGeometry(origin.fOldGeometry),
119 fIsControls(origin.fIsControls),
121 fIsMultiRun(origin.fIsMultiRun),
122 fSplitSimulation(origin.fSplitSimulation),
125 fDebug(origin.fDebug)
155 fPrimaryGenerator(0),
157 fOldGeometry(kFALSE),
161 fSplitSimulation(kFALSE),
218 if (TString(setup) !=
"") {
219 gROOT->LoadMacro(setup);
220 gInterpreter->ProcessLine(
"Config()");
223 "InitMC",
"Processing Config() has failed. (No MC is instantiated.)");
228#if ROOT_VERSION_CODE >= 336402
231 fRootManager =
new TMCRootManager(GetName(), TMCRootManager::kWrite);
236 fRootManager =
new TMCRootManager(GetName(), TMCRootManager::kWrite);
241 fMC->SetRootGeometry();
249 Info(
"InitMC",
"Single run initialised");
264 "Initialisation of multiple engines not supported in single run");
267 if (setupMacros.size() > 0) {
268 for (
const char* setup : setupMacros) {
269 gROOT->LoadMacro(setup);
270 gInterpreter->ProcessLine(
"Config()");
273 "InitMC",
"Processing Config() has failed. (No MC is instantiated.)");
276 gInterpreter->UnloadFile(setup);
292 "Initialisation of multiple engines not supported in single run");
296#if ROOT_VERSION_CODE >= 336402
299 fRootManager =
new TMCRootManager(GetName(), TMCRootManager::kWrite);
304 fRootManager =
new TMCRootManager(GetName(), TMCRootManager::kWrite);
308 fMCManager->Init([
this](TVirtualMC* mc) {
309 mc->SetRootGeometry();
316 fG3Id = fMCManager->GetEngineId(
"TGeant3TGeo");
317 fG4Id = fMCManager->GetEngineId(
"TGeant4");
319 Info(
"InitMC",
"Multi run initialised");
320 std::cout <<
"Engine IDs\n"
321 <<
"TGeant3TGeo: " <<
fG3Id <<
"\n"
322 <<
"TGeant4: " <<
fG4Id << std::endl;
339 Info(
"RunMC",
"Start single run");
340 std::cout <<
"Simulation entirely done with engine " << fMC->GetName()
344 fMC->ProcessRun(nofEvents);
348 Info(
"RunMC",
"Start multi run");
350 std::cout <<
"GAPX simulated with engine "
351 << fMCManager->GetEngine(0)->GetName() <<
"\n"
352 <<
"ABSO simulated with engine "
353 << fMCManager->GetEngine(1)->GetName() << std::endl;
356 std::cout <<
"Simulation entirely done with engine "
357 << fMCManager->GetCurrentEngine()->GetName() << std::endl;
361 fMCManager->Run(nofEvents);
365 Info(
"RunMC",
"Transport finished.");
396 fRootManager =
new TMCRootManager(GetName(), TMCRootManager::kWrite);
437 Fatal(
"ConstructGeometry",
"Cannot run with old geomtry");
470 for (Int_t kz = 0; kz < 6; kz++) {
477 mode[0][0] = kNeutron;
478 mode[0][1] = 1000020040;
489 for (Int_t kz = 0; kz < 6; kz++) {
500 fMC->DefineParticle(1000020050,
"He5", kPTHadron, 5.03427, 2.0, 0.002,
"Ion",
501 0.0, 0, 1, 0, 0, 0, 0, 0, 5, kFALSE);
502 fMC->SetDecayMode(1000020050, bratio, mode);
503 fMC->SetDecayMode(kK0Short, bratio2, mode2);
512 fMC->DefineIon(
"MyIon", 34, 70, 12, 0.);
536 if (!
fIsMultiRun && TString(fMC->GetName()) ==
"TGeant3TGeo" &&
537 gGeoManager->GetListOfTracks() && gGeoManager->GetTrack(0) &&
538 ((TVirtualGeoTrack*)gGeoManager->GetTrack(0))->HasPoints()) {
540 gGeoManager->ClearTracks();
546 cout <<
"\n---> Begin of event: " <<
fEventNo << endl;
587 <<
" is a decay product of Parent ID = "
605 fMC->TrackPosition(pos);
606 fMC->TrackMomentum(mom);
609 std::cout <<
"Current engine " << fMC->GetName() <<
"\n"
612 <<
"E=" << mom.T() <<
", Px=" << mom.X() <<
", Py=" << mom.Y()
613 <<
", Pz=" << mom.Z() << std::endl;
619 if (fMC->GetId() == 0 && strcmp(fMC->CurrentVolName(),
"ABSO") == 0) {
622 else if (fMC->GetId() == 1 && strcmp(fMC->CurrentVolName(),
"GAPX") == 0) {
627 Info(
"Stepping",
"Transfer track");
629 fMCManager->TransferTrack(targetId);
662 if (!
fIsMultiRun && TString(fMC->GetName()) ==
"TGeant3TGeo") {
665 gGeoManager->SetVisOption(0);
666 gGeoManager->SetTopVisible();
667 gGeoManager->GetTopVolume()->Draw();
672 if (gGeoManager->GetListOfTracks() && gGeoManager->GetTrack(0) &&
673 ((TVirtualGeoTrack*)gGeoManager->GetTrack(0))->HasPoints()) {
675 gGeoManager->DrawTracks(
"/*");
Definition of the Ex03cMCApplication class.
Definition of the Ex03cMCStack class.
virtual void GeneratePrimaries(const TVector3 &worldSize)
Bool_t GetUserDecay() const
Return true if particle with user decay is activated.
The calorimeter sensitive detector.
The detector construction (via TGeo )
Double_t GetCalorSizeYZ() const
Double_t GetWorldSizeX() const
void ConstructMaterials()
Implementation of the TVirtualMCApplication.
TGeoUniformMagField * fMagField
Magnetic field.
TMCRootManager * fRootManager
Root manager.
virtual void BeginPrimary()
Ex03PrimaryGenerator * fPrimaryGenerator
Primary generator.
virtual void InitOnWorker()
Ex03cDetectorConstruction * fDetConstruction
Dector construction.
virtual void BeginEvent()
Int_t fG3Id
engine ID of Geant3
TMCVerbose fVerbose
VMC verbose helper.
Ex03cCalorimeterSD * fCalorimeterSD
Calorimeter SD.
virtual void GeneratePrimaries()
virtual void AddParticles()
void RegisterStack() const
void RunMC(Int_t nofEvents)
Bool_t fOldGeometry
Option for geometry definition.
Bool_t fIsControls
Option to activate special controls.
Int_t fPrintModulo
The event modulus number to be printed.
virtual ~Ex03cMCApplication()
Bool_t fIsMultiRun
Flag if having multiple engines.
virtual TVirtualMCApplication * CloneForWorker() const
Bool_t fIsMaster
If is on master thread.
Bool_t fSplitSimulation
Split geometry given user criteria.
Ex03cMCStack * fStack
VMC stack.
Int_t fEventNo
Event counter.
virtual void ConstructGeometry()
virtual void FinishRunOnWorker()
virtual void FinishEvent()
Int_t fG4Id
engine ID of Geant4
virtual void FinishPrimary()
virtual void InitGeometry()
Int_t fDebug
debug option for multiple run
Implementation of the TVirtualMCStack interface.
virtual TParticle * GetCurrentTrack() const
virtual Int_t GetCurrentParentTrackNumber() const
virtual Int_t GetCurrentTrackNumber() const
TParticle * GetParticle(Int_t id) const