1 | |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | // %%%%%%%%%% |
---|
32 | // G4 headers |
---|
33 | // %%%%%%%%%% |
---|
34 | #include "G4RunManager.hh" |
---|
35 | #include "G4UImanager.hh" |
---|
36 | #include "G4UIterminal.hh" |
---|
37 | #include "G4VisExecutive.hh" |
---|
38 | |
---|
39 | #include<LHEP.hh> |
---|
40 | #include<LHEP_BERT.hh> |
---|
41 | #include<LHEP_BERT_HP.hh> |
---|
42 | #include<QGSP.hh> |
---|
43 | #include<QGSP_BIC.hh> |
---|
44 | #include<QGSP_BIC_HP.hh> |
---|
45 | #include<QGSP_BERT.hh> |
---|
46 | #include<QGSP_BERT_HP.hh> |
---|
47 | |
---|
48 | #include "G4UIQt.hh" |
---|
49 | #include "G4Qt.hh" |
---|
50 | |
---|
51 | // %%%%%%%%%% |
---|
52 | // Qt headers |
---|
53 | // %%%%%%%%%% |
---|
54 | //#include "arthurwidgets.h" |
---|
55 | #include <QApplication> |
---|
56 | #include <QSplashScreen> |
---|
57 | |
---|
58 | // %%%%%%%%%%%%% |
---|
59 | // gemc headers |
---|
60 | // %%%%%%%%%%%%% |
---|
61 | |
---|
62 | #include "Clas12_HitProcess_MapRegister.h" |
---|
63 | #include "detector.h" |
---|
64 | #include "gemc_MainGui.h" |
---|
65 | #include "icons.h" |
---|
66 | #include "MagneticField.h" |
---|
67 | #include "MBankdefs.h" |
---|
68 | #include "MDetectorConstruction.h" |
---|
69 | #include "MEventAction.h" |
---|
70 | #include "MOutputBaseClass.h" |
---|
71 | //#include "MPHBaseClass.h" |
---|
72 | #include "MPhysicsList.h" |
---|
73 | #include "MPrimaryGeneratorAction.h" |
---|
74 | //#include "MSteppingAction.h" |
---|
75 | //#include "Output_Register.h" |
---|
76 | #include "usage.h" |
---|
77 | #include "run_conditions.h" |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | int main( int argc, char **argv ) |
---|
82 | { |
---|
83 | gemc_opts gemcOpt; |
---|
84 | gemcOpt.Set(argc, argv); |
---|
85 | string hd_msg = gemcOpt.args["LOG_MSG"].args + " Init: >> " ; |
---|
86 | |
---|
87 | cout << endl << hd_msg << " Geant4 MonteCarlo" << endl; |
---|
88 | double use_qt = gemcOpt.args["USE_QT"].arg; |
---|
89 | |
---|
90 | QApplication gemc_gui( argc, argv, (bool) use_qt ); |
---|
91 | QPixmap *splash_i; |
---|
92 | QSplashScreen *splash; |
---|
93 | |
---|
94 | |
---|
95 | if(use_qt) |
---|
96 | { |
---|
97 | splash_i = new QPixmap(CLAS12_cad); |
---|
98 | splash = new QSplashScreen(*splash_i); |
---|
99 | splash->show(); |
---|
100 | gemc_gui.processEvents(); |
---|
101 | } |
---|
102 | |
---|
103 | string msg; |
---|
104 | |
---|
105 | msg = " Setting CLHEP Random Engine..."; |
---|
106 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
107 | CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); |
---|
108 | string RAND = gemcOpt.args["RANDOM"].args; |
---|
109 | G4int seed; |
---|
110 | if(RAND=="TIME") |
---|
111 | { |
---|
112 | msg = " Initializing CLHEP Random Engine from time and clock..."; |
---|
113 | seed = time(NULL)-clock(); |
---|
114 | } |
---|
115 | else |
---|
116 | { |
---|
117 | seed = atoi(RAND.c_str()); |
---|
118 | msg = " Initializing CLHEP Random Engine from user seed..."; |
---|
119 | } |
---|
120 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
121 | CLHEP::HepRandom::setTheSeed(seed); |
---|
122 | char seeds[100]; |
---|
123 | sprintf(seeds, "%d", seed); |
---|
124 | msg = " Random Seed Initialised to: " ; |
---|
125 | msg.append(seeds); |
---|
126 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
127 | |
---|
128 | if(gemcOpt.args["gcard"].args != "no") |
---|
129 | { |
---|
130 | msg = " Opening GCARD file " + gemcOpt.args["gcard"].args + "..."; |
---|
131 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
132 | } |
---|
133 | run_conditions RunConditions(gemcOpt); |
---|
134 | |
---|
135 | msg = " Instantiating Run Manager..."; |
---|
136 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
137 | G4RunManager *runManager = new G4RunManager; |
---|
138 | |
---|
139 | |
---|
140 | msg = " Retrieving gemc Detector Map..."; |
---|
141 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
142 | map<string, detector> Hall_Map = read_detector(gemcOpt, RunConditions); |
---|
143 | |
---|
144 | msg = " Building gemc Process Hit Factory..."; |
---|
145 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
146 | map<string, MPHB_Factory> MProcessHit_Map = Clas12_HitProcess_Map(); |
---|
147 | |
---|
148 | msg = " Retrieving gemc Banks Map..."; |
---|
149 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
150 | map<string, MBank> MBank_Map = read_banks(gemcOpt, MProcessHit_Map); |
---|
151 | |
---|
152 | msg = " Retrieving gemc Materials Map..."; |
---|
153 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
154 | map<string, G4Material*> MMats = DefineMaterials(); |
---|
155 | |
---|
156 | msg = " Retrieving gemc Magnetic Fields Map..."; |
---|
157 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
158 | map<string, MagneticField> FieldMap = get_magnetic_Fields(gemcOpt); |
---|
159 | |
---|
160 | |
---|
161 | MDetectorConstruction* ExpHall = new MDetectorConstruction(gemcOpt); |
---|
162 | ExpHall->Hall_Map = &Hall_Map; |
---|
163 | ExpHall->MMats = &MMats; |
---|
164 | ExpHall->FieldMap = &FieldMap; |
---|
165 | runManager->SetUserInitialization(ExpHall); |
---|
166 | |
---|
167 | string phys_list = gemcOpt.args["USE_PHYSICSL"].args ; |
---|
168 | msg = " Initializing Physics List " + phys_list + "..."; |
---|
169 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
170 | G4VUserPhysicsList* physics; |
---|
171 | |
---|
172 | if(phys_list == "gemc") physics = new MPhysicsList(gemcOpt); |
---|
173 | if(phys_list == "LHEP") physics = new LHEP(1); |
---|
174 | if(phys_list == "LHEP_BERT") physics = new LHEP_BERT(1); |
---|
175 | if(phys_list == "LHEP_BERT_HP") physics = new LHEP_BERT_HP(1); |
---|
176 | if(phys_list == "QGSP") physics = new QGSP(1); |
---|
177 | if(phys_list == "QGSP_BIC") physics = new QGSP_BIC(1); |
---|
178 | if(phys_list == "QGSP_BIC_HP") physics = new QGSP_BIC_HP(1); |
---|
179 | if(phys_list == "QGSP_BERT") physics = new QGSP_BERT(1); |
---|
180 | if(phys_list == "QGSP_BERT_HP") physics = new QGSP_BERT_HP(1); |
---|
181 | // physics->SetDefaultCutValue(1*cm); |
---|
182 | runManager->SetUserInitialization(physics); |
---|
183 | // Setting Max step for all the simulation. |
---|
184 | G4TransportationManager::GetTransportationManager()->GetPropagatorInField()->SetLargestAcceptableStep(5*mm); |
---|
185 | |
---|
186 | |
---|
187 | msg = " Initializing Primary Generator Action..."; |
---|
188 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
189 | G4VUserPrimaryGeneratorAction* gen_action = new MPrimaryGeneratorAction(gemcOpt); |
---|
190 | runManager->SetUserAction(gen_action); |
---|
191 | |
---|
192 | msg = " Initializing Event Action..."; |
---|
193 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
194 | MEventAction* event_action = new MEventAction(gemcOpt); |
---|
195 | event_action->SetEvtNumber((int) gemcOpt.args["EVN"].arg); |
---|
196 | runManager->SetUserAction(event_action); |
---|
197 | |
---|
198 | |
---|
199 | msg = " Initializing Stepping Action..."; |
---|
200 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
201 | // MSteppingAction* SteppingAction = new MSteppingAction(gemcOpt); |
---|
202 | // runManager->SetUserAction(SteppingAction); |
---|
203 | |
---|
204 | G4UIsession * session = NULL; |
---|
205 | msg = " Initializing User Interface..."; |
---|
206 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
207 | if(use_qt == 1) |
---|
208 | { |
---|
209 | session = new G4UIQt(argc,argv); |
---|
210 | } |
---|
211 | else |
---|
212 | session = new G4UIterminal(); |
---|
213 | |
---|
214 | G4UImanager* UImanager = G4UImanager::GetUIpointer(); |
---|
215 | |
---|
216 | G4VisManager* visManager; |
---|
217 | if(use_qt) |
---|
218 | { |
---|
219 | visManager = new G4VisExecutive; |
---|
220 | visManager->Initialize(); |
---|
221 | } |
---|
222 | |
---|
223 | msg = " Initializing Run Manager...\n"; |
---|
224 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
225 | runManager->Initialize(); |
---|
226 | |
---|
227 | msg = " Initializing Output Action..."; |
---|
228 | MOutputs MOutput(gemcOpt); |
---|
229 | |
---|
230 | // map<string, MOutput_Factory> MProcessOutput_Map = Output_Map(); |
---|
231 | |
---|
232 | event_action->MOut = &MOutput; |
---|
233 | // event_action->Out = &MProcessOutput_Map; |
---|
234 | event_action->MProcessHit_Map = &MProcessHit_Map; |
---|
235 | event_action->SeDe_Map = ExpHall->SeDe_Map; |
---|
236 | event_action->MBank_Map = &MBank_Map; |
---|
237 | |
---|
238 | |
---|
239 | map<string, MSensitiveDetector*>::iterator it; |
---|
240 | for(it = ExpHall->SeDe_Map.begin(); it != ExpHall->SeDe_Map.end(); it++) |
---|
241 | it->second->MProcessHit_Map = &MProcessHit_Map; |
---|
242 | |
---|
243 | |
---|
244 | msg = " Executing initial directives...\n"; |
---|
245 | if(use_qt) splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
246 | vector<string> init_commands = init_dmesg(gemcOpt); |
---|
247 | for(int i=0; i<init_commands.size(); i++) |
---|
248 | UImanager->ApplyCommand(init_commands[i].c_str()); |
---|
249 | |
---|
250 | string exec_macro = "/control/execute " + gemcOpt.args["EXEC_MACRO"].args; |
---|
251 | |
---|
252 | if(use_qt) |
---|
253 | { |
---|
254 | msg = " Executing initial visual directives...\n"; |
---|
255 | splash->showMessage(msg.c_str()); gemc_gui.processEvents(); cout << hd_msg << msg << endl; |
---|
256 | vector<string> init_vcommands = init_dvmesg(gemcOpt); |
---|
257 | for(int i=0; i<init_vcommands.size(); i++) |
---|
258 | UImanager->ApplyCommand(init_vcommands[i].c_str()); |
---|
259 | |
---|
260 | if(use_qt == 1) session->SessionStart(); |
---|
261 | |
---|
262 | splash->showMessage("Starting GUI..."); |
---|
263 | gemc_gui.processEvents(); |
---|
264 | |
---|
265 | gemcMainWidget gemcW(runManager, visManager, UImanager); |
---|
266 | gemcW.Hall_Map = &Hall_Map; |
---|
267 | gemcW.MMats = &MMats; |
---|
268 | gemcW.gemcOpt = gemcOpt; |
---|
269 | |
---|
270 | gemcW.setWindowTitle( " gemc: Geant4 Simulation of the CLAS 12 Detector " ); |
---|
271 | |
---|
272 | gemcW.show(); |
---|
273 | splash->finish(&gemcW); |
---|
274 | |
---|
275 | if(exec_macro != "/control/execute no") UImanager->ApplyCommand(exec_macro.c_str()); |
---|
276 | if(gemcOpt.args["N"].arg>0) |
---|
277 | { |
---|
278 | char command[100]; |
---|
279 | sprintf(command, "/run/beamOn %d", (int) gemcOpt.args["N"].arg); |
---|
280 | UImanager->ApplyCommand(command); |
---|
281 | } |
---|
282 | |
---|
283 | // QStyle *arthurStyle = new ArthurStyle(); |
---|
284 | QList<QWidget *> widgets = qFindChildren<QWidget *>(&gemcW); |
---|
285 | // foreach (QWidget *w, widgets) |
---|
286 | // w->setStyle(arthurStyle); |
---|
287 | |
---|
288 | return gemc_gui.exec(); |
---|
289 | } |
---|
290 | else |
---|
291 | { |
---|
292 | if(gemcOpt.args["N"].arg>0) |
---|
293 | { |
---|
294 | char command[100]; |
---|
295 | sprintf(command, "/run/beamOn %d", (int) gemcOpt.args["N"].arg); |
---|
296 | UImanager->ApplyCommand(command); |
---|
297 | } |
---|
298 | if(exec_macro != "/control/execute no") UImanager->ApplyCommand(exec_macro.c_str()); |
---|
299 | } |
---|
300 | delete runManager; |
---|
301 | delete session; |
---|
302 | |
---|
303 | return 1; |
---|
304 | } |
---|
305 | |
---|
306 | |
---|
307 | |
---|
308 | |
---|
309 | |
---|
310 | |
---|
311 | |
---|
312 | |
---|