[807] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // $Id: TiaraSim.cc,v 1.9 2006/06/29 15:45:31 gunter Exp $ |
---|
| 27 | // GEANT4 tag $Name: $ |
---|
| 28 | // |
---|
| 29 | |
---|
| 30 | #include "TiaraSim.hh" |
---|
| 31 | #include <iostream> |
---|
| 32 | |
---|
| 33 | #include "CLHEP/Random/Random.h" |
---|
| 34 | |
---|
| 35 | #include "G4RunManager.hh" |
---|
| 36 | |
---|
| 37 | #include "G4VPhysicalVolume.hh" |
---|
| 38 | #include "G4VUserPhysicsList.hh" |
---|
| 39 | |
---|
| 40 | #include "G4VUserDetectorConstruction.hh" |
---|
| 41 | |
---|
| 42 | #include "TiaraPrimaryGeneratorAction.hh" |
---|
| 43 | #include "G4VisExecutive.hh" |
---|
| 44 | #include "G4UItcsh.hh" |
---|
| 45 | #include "TiaraVisEventAction.hh" |
---|
| 46 | #include "TiaraVisRunAction.hh" |
---|
| 47 | #include "G4VUserPrimaryGeneratorAction.hh" |
---|
| 48 | #include "TiaraEnergyCutProcess.hh" |
---|
| 49 | #include "G4UserStackingAction.hh" |
---|
| 50 | #include "G4UserEventAction.hh" |
---|
| 51 | #include "TiaraStackingAction.hh" |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | TiaraSim *TiaraSim::fTiaraSim = 0; |
---|
| 55 | TiaraSim &TiaraSim::GetTiaraSim() { |
---|
| 56 | if (!fTiaraSim) { |
---|
| 57 | fTiaraSim = new TiaraSim; |
---|
| 58 | } |
---|
| 59 | return *fTiaraSim; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | TiaraSim::TiaraSim(): |
---|
| 63 | fVisManager(0), |
---|
| 64 | fSession(new G4UItcsh), |
---|
| 65 | fGeometry(0), |
---|
| 66 | fPrimary(0), |
---|
| 67 | fPhysics(0), |
---|
| 68 | fCutProcessVector(), |
---|
| 69 | fPlacers(), |
---|
| 70 | fStackingAction(0), |
---|
| 71 | fUserEventAction(0) |
---|
| 72 | { |
---|
| 73 | |
---|
| 74 | frunMgr = new G4RunManager; |
---|
| 75 | |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | void TiaraSim::SetGeometry(G4VUserDetectorConstruction *geo){ |
---|
| 79 | fGeometry = geo; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | void TiaraSim::AddTiaraEventAction(G4UserEventAction *eventAction) { |
---|
| 84 | fUserEventAction = eventAction; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void TiaraSim:: |
---|
| 88 | SetPhysicsList(G4VUserPhysicsList *physicsList) { |
---|
| 89 | fPhysics = physicsList; |
---|
| 90 | frunMgr->SetUserInitialization(fPhysics); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | void TiaraSim:: |
---|
| 94 | SetPrimaryGenerator(G4VUserPrimaryGeneratorAction *primGen){ |
---|
| 95 | fPrimary = primGen; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | void TiaraSim::AddParticleCut(const std::string &particle, |
---|
| 101 | G4double cut) { |
---|
| 102 | if (!fStackingAction) { |
---|
| 103 | fStackingAction = new TiaraStackingAction; |
---|
| 104 | frunMgr->SetUserAction(fStackingAction); |
---|
| 105 | } |
---|
| 106 | TiaraEnergyCutProcess *cutProcess = new TiaraEnergyCutProcess(cut); |
---|
| 107 | fCutProcessVector.push_back(cutProcess); |
---|
| 108 | fPlacers.push_back(G4ProcessPlacer(particle)); |
---|
| 109 | fPlacers[fPlacers.size() - 1]. |
---|
| 110 | AddProcessAsLastDoIt(cutProcess); |
---|
| 111 | fStackingAction->AddParticleCut(particle, cut); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | void TiaraSim::AddVisRunAction() { |
---|
| 115 | fVisManager = new G4VisExecutive; |
---|
| 116 | frunMgr->SetUserAction(new TiaraVisRunAction); |
---|
| 117 | } |
---|
| 118 | void TiaraSim::initializeVisManager() { |
---|
| 119 | if (fVisManager) { |
---|
| 120 | fVisManager->Initialize(); |
---|
| 121 | }else { |
---|
| 122 | G4cout << "TiaraSim::initializeVisManager(): no VisManager!" << G4endl; |
---|
| 123 | } |
---|
| 124 | }; |
---|
| 125 | void TiaraSim::initialize(){ |
---|
| 126 | G4bool ready(true); |
---|
| 127 | if (!fPrimary) { |
---|
| 128 | G4cout << "TiaraSim::initialize: no primary generator set" << G4endl; |
---|
| 129 | ready = false; |
---|
| 130 | } |
---|
| 131 | if (ready) { |
---|
| 132 | frunMgr->SetUserInitialization(fGeometry); |
---|
| 133 | frunMgr->SetUserAction(fPrimary); |
---|
| 134 | if (fUserEventAction) { |
---|
| 135 | frunMgr->SetUserAction(fUserEventAction); |
---|
| 136 | } |
---|
| 137 | if (fVisManager) { |
---|
| 138 | fVisManager->Initialize(); |
---|
| 139 | } |
---|
| 140 | frunMgr->Initialize(); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | void TiaraSim::startSession(){ |
---|
| 145 | fSession.SessionStart(); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | void TiaraSim::BeamOn(G4int nEvents){ |
---|
| 150 | frunMgr->BeamOn(nEvents); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | TiaraSim::~TiaraSim(){ |
---|
| 154 | for (size_t i = 0; i < fCutProcessVector.size(); i++) { |
---|
| 155 | fPlacers[i].RemoveProcess(fCutProcessVector[i]); |
---|
| 156 | delete fCutProcessVector[i]; |
---|
| 157 | } |
---|
| 158 | if (fStackingAction) { |
---|
| 159 | delete fStackingAction; |
---|
| 160 | } |
---|
| 161 | if (fVisManager) { |
---|
| 162 | delete fVisManager; |
---|
| 163 | } |
---|
| 164 | delete frunMgr; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | |
---|