1 | #include "OpticsFactory.hh" |
---|
2 | #include "Config.hh" |
---|
3 | |
---|
4 | #include "PhotonsOnPupil.hh" |
---|
5 | #include "Photon.hh" |
---|
6 | #include "EConst.hh" |
---|
7 | |
---|
8 | #include "EsafMsg.hh" |
---|
9 | #include "EsafMsgSource.hh" |
---|
10 | |
---|
11 | #include <G4RunManager.hh> |
---|
12 | #include <G4StateManager.hh> |
---|
13 | #include <G4TrackingManager.hh> |
---|
14 | #include <G4ApplicationState.hh> |
---|
15 | #include <G4UImanager.hh> |
---|
16 | #include <G4UIterminal.hh> |
---|
17 | #include <G4UItcsh.hh> |
---|
18 | #include <G4UIcommand.hh> |
---|
19 | #include <G4UIcmdWithAString.hh> |
---|
20 | #include <G4UImessenger.hh> |
---|
21 | #include <G4Track.hh> |
---|
22 | #ifdef G4VIS_USE |
---|
23 | #include <G4VisManager.hh> |
---|
24 | #include <G4VisExecutive.hh> |
---|
25 | #endif |
---|
26 | |
---|
27 | #include <utils.hh> |
---|
28 | #include <globals.hh> |
---|
29 | |
---|
30 | #include "G4TransportManager.hh" |
---|
31 | |
---|
32 | #include "DetectorFactory.hh" |
---|
33 | |
---|
34 | #include "OptPhysicsList.hh" |
---|
35 | #include "OptPrimaryGeneratorAction.hh" |
---|
36 | #include "OptRunAction.hh" |
---|
37 | #include "OptSteppingAction.hh" |
---|
38 | #include "OptUserStackingAction.hh" |
---|
39 | #include "IdealFocalSurface.hh" |
---|
40 | #include "OpticsFactory.hh" |
---|
41 | #include "FocalPlane.hh" |
---|
42 | |
---|
43 | #include "SimuApplication.hh" |
---|
44 | |
---|
45 | |
---|
46 | using namespace sou; |
---|
47 | //______________________________________________________________________________ |
---|
48 | G4TransportManager::G4TransportManager() |
---|
49 | { |
---|
50 | |
---|
51 | SetSender("G4TransportManager"); |
---|
52 | |
---|
53 | fOptics = OpticsFactory::Get()->MakeOpticalSystem(); |
---|
54 | fFocalPlane = OpticsFactory::Get()->MakeFocalPlane(); |
---|
55 | fIdealFocalSurface=OpticsFactory::Get()->MakeIdealFocalSurface(); |
---|
56 | fFocalPlane = OpticsFactory::Get()->MakeFocalPlane(); |
---|
57 | |
---|
58 | fEffectiveEfficiencyFactor = |
---|
59 | Config::Get()->GetCF("G4TransportManager","NOpticalSystem")->GetNum("NOpticalSystem.fEffectiveEfficiencyFactor"); |
---|
60 | // Run manager |
---|
61 | runManager = new G4RunManager(); |
---|
62 | |
---|
63 | // UserInitialization classes - mandatory |
---|
64 | G4VUserDetectorConstruction* detector = DetectorFactory::Instance()->GetDetector(); |
---|
65 | runManager->SetUserInitialization((G4VUserDetectorConstruction*)detector); |
---|
66 | |
---|
67 | G4VUserPhysicsList* physics = new OptPhysicsList; |
---|
68 | runManager-> SetUserInitialization(physics); |
---|
69 | |
---|
70 | G4UserRunAction* run_action = new OptRunAction; |
---|
71 | runManager->SetUserAction(run_action); |
---|
72 | |
---|
73 | bool active = (bool)Conf()->GetNum("G4TransportManager.ActivatePrimaryGenAction"); |
---|
74 | if(active)MsgForm(EsafMsg::Info,"Geant4 generator is available"); |
---|
75 | gen_action = new OptPrimaryGeneratorAction(active); |
---|
76 | runManager->SetUserAction((G4VUserPrimaryGeneratorAction*)gen_action); |
---|
77 | |
---|
78 | stack_action = new OptUserStackingAction(fIdealFocalSurface); |
---|
79 | runManager->SetUserAction((G4UserStackingAction*)stack_action); |
---|
80 | int nevents = (int)Conf()->GetNum("G4TransportManager.Nphotons"); |
---|
81 | if ( nevents ) stack_action->SetNmax(nevents); |
---|
82 | |
---|
83 | OptSteppingAction* stepping_action = new OptSteppingAction(stack_action); |
---|
84 | runManager->SetUserAction((G4UserSteppingAction*)stepping_action); |
---|
85 | stack_action->stepping=stepping_action; |
---|
86 | |
---|
87 | //G4UserTrackingAction* tracking_action = new OptTrackingAction; |
---|
88 | runManager->SetUserAction((G4UserTrackingAction*)stack_action); |
---|
89 | runManager->SetUserAction((G4UserEventAction*)stack_action); |
---|
90 | //stack_action->tracking=tracking_action; |
---|
91 | |
---|
92 | #ifdef G4VIS_USE |
---|
93 | // visualization manager |
---|
94 | printf("VisManager is created.\n"); |
---|
95 | visManager = new G4VisExecutive; |
---|
96 | visManager->Initialize(); |
---|
97 | #endif |
---|
98 | |
---|
99 | // Initialize G4 kernel |
---|
100 | runManager->Initialize(); |
---|
101 | |
---|
102 | |
---|
103 | if(nevents==-2){ |
---|
104 | fNTracked=0; |
---|
105 | bool state=G4RunManagerKernel::GetRunManagerKernel()->RunInitialization(); |
---|
106 | if (!state) { printf("Error\n"); exit(1); } |
---|
107 | trackManager = G4EventManager::GetEventManager()->GetTrackingManager(); |
---|
108 | G4StateManager* stateManager = G4StateManager::GetStateManager(); |
---|
109 | G4ApplicationState currentState = stateManager->GetCurrentState(); |
---|
110 | if(currentState!=G4State_GeomClosed) |
---|
111 | { |
---|
112 | G4Exception("G4EventManager::ProcessOneEvent", |
---|
113 | "IllegalApplicationState",JustWarning, |
---|
114 | "Geometry is not closed : cannot process an event."); |
---|
115 | return; |
---|
116 | } |
---|
117 | |
---|
118 | stateManager->SetNewState(G4State_EventProc); |
---|
119 | |
---|
120 | } |
---|
121 | MsgForm(EsafMsg::Info,"Creating Geant4 transport manager."); |
---|
122 | } |
---|
123 | |
---|
124 | G4TransportManager::~G4TransportManager() { |
---|
125 | |
---|
126 | //delete stack_action; |
---|
127 | G4EventManager::GetEventManager()->SetUserAction((G4UserTrackingAction*)0); |
---|
128 | G4EventManager::GetEventManager()->SetUserAction((G4UserEventAction*)0); |
---|
129 | delete runManager; |
---|
130 | #ifdef G4VIS_USE |
---|
131 | delete visManager; |
---|
132 | #endif |
---|
133 | } |
---|
134 | |
---|
135 | void G4TransportManager::UIterminal(){ |
---|
136 | int v = (int)Conf()->GetNum("G4TransportManager.Vis"); |
---|
137 | int t = (int)Conf()->GetNum("G4TransportManager.Terminal"); |
---|
138 | int nevents = (int)Conf()->GetNum("G4TransportManager.NumberOfEvents"); |
---|
139 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
140 | if(t==1) // Define (G)UI terminal for interactive mode |
---|
141 | { |
---|
142 | // G4UIterminal is a (dumb) terminal |
---|
143 | // |
---|
144 | G4UIsession * session = 0; |
---|
145 | #ifdef G4UI_USE_TCSH |
---|
146 | session = new G4UIterminal(new G4UItcsh); |
---|
147 | #else |
---|
148 | session = new G4UIterminal(); |
---|
149 | #endif |
---|
150 | |
---|
151 | if(v!=0) UI->ApplyCommand("/control/execute config/G4/vis.mac"); |
---|
152 | session->SessionStart(); |
---|
153 | delete session; |
---|
154 | } |
---|
155 | else // Batch mode |
---|
156 | { |
---|
157 | UI->ApplyCommand("/run/verbose 0"); |
---|
158 | UI->ApplyCommand("/event/verbose 0"); |
---|
159 | UI->ApplyCommand("/tracking/verbose 0"); |
---|
160 | UI->ApplyCommand("/process/verbose 0"); |
---|
161 | UI->ApplyCommand("/control/verbose 0"); |
---|
162 | UI->ApplyCommand("/process/eLoss/verbose 0"); |
---|
163 | if(v!=0) UI->ApplyCommand("/control/execute config/G4/vis.mac"); |
---|
164 | runManager->BeamOn(nevents); |
---|
165 | if(v!=0) UI->ApplyCommand("/control/execute config/G4/vis_post.mac"); |
---|
166 | } |
---|
167 | |
---|
168 | } |
---|
169 | //______________________________________________________________________________ |
---|
170 | void G4TransportManager::Go( PhotonsOnPupil* pupil ) { |
---|
171 | // |
---|
172 | // Get and trace all the photons in PhotonsOnPupil |
---|
173 | // |
---|
174 | if ( !pupil ) { |
---|
175 | MsgForm(EsafMsg::Warning,"PhotonsOnPupil is NULL. Photon tracing disabled."); |
---|
176 | return; |
---|
177 | } |
---|
178 | |
---|
179 | stack_action->SetPupil(pupil); |
---|
180 | UIterminal(); |
---|
181 | fTimeFirstPhoton=stack_action->GetTimeFirst(); |
---|
182 | fTimeLastPhoton=stack_action->GetTimeLast(); |
---|
183 | } |
---|
184 | |
---|
185 | //______________________________________________________________________________ |
---|
186 | Photon* G4TransportManager::Transport(Photon* p) const { |
---|
187 | |
---|
188 | |
---|
189 | if(EsafRandom::Get()->Rndm()>=fEffectiveEfficiencyFactor){ |
---|
190 | p->history=0; |
---|
191 | return 0; |
---|
192 | } |
---|
193 | stack_action->Reset(); |
---|
194 | G4Track* track = (G4Track*)stack_action->NewPhoton(p, 0, 0); |
---|
195 | G4TrackingManager* trackManager = G4EventManager::GetEventManager()->GetTrackingManager(); |
---|
196 | EVector& phpos=p->pos; |
---|
197 | G4ThreeVector pos(phpos[X],phpos[Y],phpos[Z]); |
---|
198 | G4Navigator* navigator = |
---|
199 | G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking(); |
---|
200 | navigator->LocateGlobalPointAndSetup(pos,0,false); |
---|
201 | trackManager->ProcessOneTrack (track); |
---|
202 | delete track; |
---|
203 | |
---|
204 | return 0; |
---|
205 | } |
---|
206 | |
---|
207 | //______________________________________________________________________________ |
---|
208 | void G4TransportManager::Reset() { |
---|
209 | |
---|
210 | } |
---|