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