1 | |
---|
2 | // Geant4: |
---|
3 | #include <G4ios.hh> |
---|
4 | #include <G4RunManager.hh> |
---|
5 | #include <G4UImanager.hh> |
---|
6 | #include <G4SDManager.hh> |
---|
7 | |
---|
8 | //AIDA : |
---|
9 | #include <AIDA/IAnalysisFactory.h> |
---|
10 | |
---|
11 | // std:: |
---|
12 | #include <iostream> |
---|
13 | |
---|
14 | // Slash : |
---|
15 | #include <Slash/Core/IManager.h> |
---|
16 | #include <Slash/Core/ISession.h> |
---|
17 | #include <Slash/Data/IProcessor.h> |
---|
18 | |
---|
19 | // Lib : |
---|
20 | #include <Lib/Manager.h> |
---|
21 | #include <Lib/System.h> |
---|
22 | #include <Lib/Out.h> |
---|
23 | #include <Lib/Cast.h> |
---|
24 | |
---|
25 | // G4Lab : |
---|
26 | #include <G4Lab/UIOnX.h> |
---|
27 | #include <G4Lab/TrackingAction.h> |
---|
28 | #include <G4Lab/Interfaces/IGeant4Manager.h> |
---|
29 | //#include <G4Lab/DigitsCollectionAccessor.h> |
---|
30 | |
---|
31 | //ELYSE: |
---|
32 | #include "ELYSE/Analysis.hh" |
---|
33 | #include "ELYSE/SteppingVerbose.hh" |
---|
34 | #include "ELYSE/DetectorConstruction.hh" |
---|
35 | #include "ELYSE/PhysicsList.hh" |
---|
36 | #include "ELYSE/PrimaryGeneratorAction.hh" |
---|
37 | #include "ELYSE/EventAction.hh" |
---|
38 | #include "ELYSE/RunAction.hh" |
---|
39 | #include "ELYSE/StackingAction.hh" |
---|
40 | #include "ELYSE/TrackingAction.hh" |
---|
41 | #include "ELYSE/SteppingAction.hh" |
---|
42 | #include <ELYSE/HitsCollectionAccessor.h> |
---|
43 | |
---|
44 | // Create a manager to access the ELYSEAnalysis from the callbacks : |
---|
45 | |
---|
46 | //JEC 10/1/06 introduce ELYSE namespace |
---|
47 | namespace ELYSE { |
---|
48 | |
---|
49 | class AppManager |
---|
50 | :public virtual Slash::Core::IManager |
---|
51 | ,public Analysis { |
---|
52 | public: //Slash::Core::IManager |
---|
53 | virtual std::string name() const { return fName;} |
---|
54 | virtual void* cast(const std::string& aClass) const { |
---|
55 | if_Lib_SCast(ELYSE::AppManager) |
---|
56 | else if_Lib_SCast(ELYSE::IAppManager) |
---|
57 | else if_Lib_SCast(ELYSE::Analysis) |
---|
58 | else if_Lib_SCast(Slash::Core::IManager) |
---|
59 | else return 0; |
---|
60 | } |
---|
61 | public://IAppManager |
---|
62 | virtual bool initialize() { |
---|
63 | //GB : |
---|
64 | // Used in the ELYSE_Initialize callback. |
---|
65 | // Do all the below here because of platforms having |
---|
66 | // not Geant4 shared libs. |
---|
67 | IGeant4Manager* g4Manager = |
---|
68 | Lib_findManager(fSession,"Geant4Manager",IGeant4Manager); |
---|
69 | if(!g4Manager) { |
---|
70 | Lib::Out out(fSession.printer()); |
---|
71 | out << "ELYSE_Initialize :" |
---|
72 | << " Geant4Manager not found." |
---|
73 | << Lib::endl; |
---|
74 | return false; |
---|
75 | } |
---|
76 | |
---|
77 | // To initialize G4Lab Types (PV, Trajectory, HitsCollection, etc.. types). |
---|
78 | // To initialize G4Lab SoNodes. |
---|
79 | g4Manager->initialize(); |
---|
80 | |
---|
81 | // Overload the HitsCollectionAccessor of G4Lab : |
---|
82 | Slash::Data::IProcessor* accessorManager = |
---|
83 | Lib_findManager(fSession,"AccessorManager",Slash::Data::IProcessor); |
---|
84 | if(accessorManager) { |
---|
85 | G4SDManager* sdManager = g4Manager->sdManager(); |
---|
86 | if(sdManager) { |
---|
87 | G4HCtable* hcTable = sdManager->GetHCtable(); |
---|
88 | if(hcTable) { |
---|
89 | int number = hcTable->entries(); |
---|
90 | for(int index=0;index<number;index++) { |
---|
91 | G4String hcName = hcTable->GetHCname(index); |
---|
92 | accessorManager->removeAccessor(hcName); |
---|
93 | accessorManager->addAccessor |
---|
94 | (new ELYSE::HitsCollectionAccessor(fSession,hcName)); |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|
99 | return true; |
---|
100 | } |
---|
101 | public: |
---|
102 | AppManager(Slash::Core::ISession& aSession,AIDA::IAnalysisFactory* aAIDA,bool aBatch) |
---|
103 | :Analysis(aAIDA,"",aBatch) |
---|
104 | ,fSession(aSession) |
---|
105 | ,fName("ELYSE::AppManager") {} |
---|
106 | virtual ~AppManager(){} |
---|
107 | private: |
---|
108 | Slash::Core::ISession& fSession; |
---|
109 | std::string fName; |
---|
110 | }; |
---|
111 | } |
---|
112 | |
---|
113 | ////////////////////////////////////////////////////////////////////////////// |
---|
114 | int main( |
---|
115 | int aArgc |
---|
116 | ,char** aArgv |
---|
117 | ) |
---|
118 | ////////////////////////////////////////////////////////////////////////////// |
---|
119 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
120 | { |
---|
121 | //Lib::Debug::checkByClass(true); |
---|
122 | |
---|
123 | |
---|
124 | // User Verbose output class |
---|
125 | // |
---|
126 | G4VSteppingVerbose* verbosity = new ELYSE::SteppingVerbose; |
---|
127 | G4VSteppingVerbose::SetInstance(verbosity); |
---|
128 | |
---|
129 | |
---|
130 | G4RunManager* runManager = new G4RunManager; |
---|
131 | |
---|
132 | // Need to pass the G4RunManager at UIOnX creation |
---|
133 | std::string gui = "$ELYSEROOT/scripts/OnX/ELYSE_session.onx"; |
---|
134 | G4Lab::UIOnX* session = new G4Lab::UIOnX(*runManager,gui,aArgc,aArgv); |
---|
135 | if(!session->isValid()) { |
---|
136 | std::cout << "ELYSE_session : problem starting OnX." << std::endl; |
---|
137 | return EXIT_FAILURE; |
---|
138 | } |
---|
139 | |
---|
140 | ELYSE::AppManager* appManager = 0; |
---|
141 | |
---|
142 | AIDA::IAnalysisFactory* aida = session->findAIDA(); |
---|
143 | if(!aida) { |
---|
144 | std::cout << "ELYSE_session : AIDA not found." << std::endl; |
---|
145 | } |
---|
146 | |
---|
147 | appManager = new ELYSE::AppManager(*session->session(),aida,false); |
---|
148 | session->addManager(appManager); |
---|
149 | |
---|
150 | ELYSE::DetectorConstruction* ELYSEdetector = new ELYSE::DetectorConstruction(); |
---|
151 | |
---|
152 | runManager->SetUserInitialization(ELYSEdetector); |
---|
153 | |
---|
154 | runManager->SetUserInitialization(new ELYSE::PhysicsList); |
---|
155 | |
---|
156 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
157 | if (UI) { |
---|
158 | std::string file = |
---|
159 | Lib::System::getenv("ELYSEROOT")+"/scripts/Geant4/jobOptions.mac"; |
---|
160 | UI->ApplyCommand("/control/execute "+file); |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | // Set user action classes |
---|
165 | ELYSE::PrimaryGeneratorAction* myGeneratorAction = new ELYSE::PrimaryGeneratorAction(); |
---|
166 | runManager->SetUserAction(myGeneratorAction); |
---|
167 | |
---|
168 | ELYSE::RunAction* myRunAction = new ELYSE::RunAction(); |
---|
169 | |
---|
170 | runManager->SetUserAction(myRunAction); |
---|
171 | |
---|
172 | |
---|
173 | runManager->SetUserAction(new ELYSE::EventAction(*appManager, |
---|
174 | myRunAction, |
---|
175 | ELYSEdetector, |
---|
176 | myGeneratorAction)); |
---|
177 | runManager->SetUserAction(new ELYSE::TrackingAction); |
---|
178 | |
---|
179 | runManager->SetUserAction(new ELYSE::StackingAction); |
---|
180 | |
---|
181 | runManager->SetUserAction(new ELYSE::SteppingAction); |
---|
182 | |
---|
183 | // Initialize G4 kernel |
---|
184 | runManager->Initialize(); |
---|
185 | |
---|
186 | if (UI) { |
---|
187 | std::string file = |
---|
188 | Lib::System::getenv("ELYSEROOT")+"/scripts/Geant4/init.g4m"; |
---|
189 | UI->ApplyCommand("/control/execute "+file); |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | // Main UI loop : |
---|
194 | // GUI is really constructed here. |
---|
195 | // Create callbacks are executed here too. |
---|
196 | session->SessionStart(); |
---|
197 | |
---|
198 | delete session; //It will delete the appManager. |
---|
199 | |
---|
200 | delete runManager; |
---|
201 | |
---|
202 | return EXIT_SUCCESS; |
---|
203 | } |
---|
204 | |
---|