source: snovis/trunk/applications/snovis_session.cc @ 84

Last change on this file since 84 was 6, checked in by barrand, 16 years ago
File size: 6.0 KB
Line 
1/*
2 * Version of prog_snova.cc to handle a G4Lab::UIOnX session
3 */
4
5#include <snova/snova_const.hh>
6#include <snova/geometry2.hh>         // Geometry definition
7#include <snova/physics.hh>           // Physical proceses to consider
8#include <snova/generator.hh>         // Initial particles generator
9#include <snova/run.hh>               // User actions per run basis
10#include <snova/event.hh>             // User actions per event basis
11#include <snova/tracking.hh>          // User actions per track basis
12#include <snova/stacking.hh>          // User actions related with tracks stacking
13#include <snova/stepping.hh>          // User actions per step basis
14#include <snova/stepping_verbose.hh>  // Information dump per step basis
15
16#include <G4RunManager.hh>  // Program manager
17#include <G4UImanager.hh>   // User Interface manager
18
19#include <bhep/bhep_svc.h>
20#include <bhep/sreader.h>
21
22// G4Lab :
23#include <G4Lab/UIOnX.h> //UIOnX
24#include "Environment.h"
25
26using namespace snova;
27
28int main( int argc , char** argv ) 
29{
30  if(argc<=0) return 1;
31  if(!check_envs(argv[0])) return 1;
32
33  //std::string params_filename = snova::constants::DEF_PARAMS_FILENAME;
34  std::string SNOVISROOT;
35  if(!Lib::System::getenv("SNOVISROOT",SNOVISROOT)) {
36    G4cout << "snovis_session :"
37           << " Environment variable SNOVISROOT not defined."
38           << G4endl;
39    return 1;
40  }
41  std::string params_filename = SNOVISROOT+"/scripts/snova.par";
42  G4String geom_filename = SNOVISROOT+"/scripts/snemo.geom";
43
44  // create a generic store:
45  bhep::gstore store;
46  G4cout << G4endl << "***** Reading parameters from '" 
47         << params_filename << "' file ..." 
48         << G4endl << G4endl;
49
50  // and a reader:
51  bhep::sreader reader(store);
52  reader.file(params_filename);
53  reader.info_level(NORMAL);
54  reader.group("GLOBAL");
55  reader.read();
56
57  G4String sim_verbosity = store.fetch_sstore("simulation_verbosity");
58  G4cout << "***** Simulation verbosity set to: " << sim_verbosity << G4endl;
59
60  G4String G4Tracking_verbosity = store.fetch_sstore("G4Tracking_verbosity");
61  G4cout << "***** G4 Tracking verbosity set to: " << G4Tracking_verbosity << G4endl;
62
63  G4String dst_fname = store.fetch_sstore("dst_fname");
64  G4cout << "***** DST output file name:" << dst_fname << G4endl;
65
66  G4String gen_source = store.fetch_sstore("gen_source");
67  G4double gen_min_E  = store.fetch_dstore("gen_min_E");
68  G4double gen_max_E  = store.fetch_dstore("gen_max_E");
69  G4int    num_events = store.fetch_istore("num_events");
70  G4String part_name  = store.fetch_sstore("part_name");
71
72  if (gen_source == "random") {
73    G4cout << "***** Generator data will follow a flat random distribution in: " << G4endl;
74    G4cout << "*****           Ekin  (Mev): (" << gen_min_E << " , " 
75           << gen_max_E << ")" << G4endl;
76    G4cout << "*****           Theta (deg): (0 , 90)" <<  G4endl;
77    G4cout << "*****           Phi   (deg): (0 , 180)" <<  G4endl;
78    G4cout << "***** Initial events: " << num_events << " " << part_name << G4endl;
79  }
80  else {
81    G4cout << "***** Generator data source read from:" << gen_source << G4endl;
82    G4cout << "***** Initial events: " << num_events << " pairs of " << part_name << G4endl;
83  }
84
85  if(geom_filename=="") 
86    geom_filename = store.fetch_sstore("geom_file");
87
88  //G4String geom_filename = store.fetch_sstore("geom_file");
89  G4cout << "***** Reading geometry parameters from: '" 
90         << geom_filename << "'" << G4endl;
91  G4cout << "***** Reading physics parameters from:  '" 
92         << params_filename << "'" << G4endl;
93 
94  G4cout << "**********************************************************"
95         << G4endl << G4endl;
96 
97  // The ihep::event service is generated. This server must be instantiated
98  // wherever you want to access all the info.
99  bhep::bhep_svc bsvc; 
100
101  // my Verbose output class:
102  G4VSteppingVerbose* verbosity = new stepping_verbose;
103  G4VSteppingVerbose::SetInstance(verbosity);
104
105  // Run manager:
106  G4RunManager* runManager = new G4RunManager;
107
108  // UserInitialization classes (mandatory)
109
110  // geometry
111  geometry* geom = new geometry(geom_filename,params_filename);
112  geom->set_info_level(sim_verbosity);
113  runManager->SetUserInitialization(geom);
114
115  // physics
116  physics* phys = new physics(params_filename);
117  phys->set_info_level(sim_verbosity);
118  runManager->SetUserInitialization(phys);
119
120  // UserAction classes
121  // generator
122  generator* my_gen = new generator( part_name , 
123                                     gen_source , 
124                                     gen_min_E , 
125                                     gen_max_E , 
126                                     geom->get_geom_mgr() , 
127                                     params_filename );
128  my_gen->set_info_level(sim_verbosity);
129  runManager->SetUserAction(my_gen);
130
131  // run
132  run* my_run = new run(dst_fname);
133  runManager->SetUserAction(my_run); 
134
135  //event
136  snova::event* my_evt = new snova::event(part_name, dst_fname);
137  my_evt->set_info_level(sim_verbosity);
138  runManager->SetUserAction(my_evt);
139
140  // track
141  tracking* my_tracking = new tracking();
142  my_tracking->set_info_level(sim_verbosity);
143  runManager->SetUserAction(my_tracking);
144
145  // step
146  stepping* my_stepping = new stepping(part_name);
147  my_stepping->set_info_level(sim_verbosity);
148  runManager->SetUserAction(my_stepping);
149
150  // stack
151  stacking* my_stacking = new stacking(part_name);
152  my_stacking->set_info_level(sim_verbosity);
153  runManager->SetUserAction(my_stacking);
154
155
156  //Initialize G4 kernel
157  runManager->Initialize();
158
159    G4UImanager * UI = G4UImanager::GetUIpointer(); 
160
161    G4String command = "/control/shell cp currentEvent.rndm currentRun.rndm";
162    UI->ApplyCommand(command);
163    command = "/random/setSavingFlag true";
164    UI->ApplyCommand(command);
165    command = "/random/resetEngineFrom currentRun.rndm";
166    UI->ApplyCommand(command);
167
168    command = "/tracking/verbose ";
169    UI->ApplyCommand(command + G4Tracking_verbosity);
170 
171    command = "/tracking/storeTrajectory 1";
172    UI->ApplyCommand(command);
173 
174  std::string gui = "$SNOVISROOT/scripts/OnX/snovis_session.onx"; //UIOnX
175  G4UIsession* session = new G4Lab::UIOnX(*runManager,gui,argc,argv); //UIOnX
176
177  session->SessionStart();
178  delete session;
179 
180  delete runManager;
181  delete verbosity;
182 
183  return 0;
184}
185
186// end of prog_snova.cc
Note: See TracBrowser for help on using the repository browser.