| 1 | // -*- mode: C++; -*-
|
|---|
| 2 | /* prog_snova.cc
|
|---|
| 3 | * SuperNEMO module G4 based simulation program
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | #include <string>
|
|---|
| 7 |
|
|---|
| 8 | #include <snova/snova_const.hh>
|
|---|
| 9 | #include <snova/geometry2.hh> // Geometry definition
|
|---|
| 10 | #include <snova/physics.hh> // Physical proceses to consider
|
|---|
| 11 | #include <snova/generator.hh> // Initial particles generator
|
|---|
| 12 | #include <snova/run.hh> // User actions per run basis
|
|---|
| 13 | #include <snova/event.hh> // User actions per event basis
|
|---|
| 14 | #include <snova/tracking.hh> // User actions per track basis
|
|---|
| 15 | #include <snova/stacking.hh> // User actions related with tracks stacking
|
|---|
| 16 | #include <snova/stepping.hh> // User actions per step basis
|
|---|
| 17 | #include <snova/stepping_verbose.hh> // Information dump per step basis
|
|---|
| 18 |
|
|---|
| 19 | #include "G4RunManager.hh" // Program manager
|
|---|
| 20 | #include "G4UImanager.hh" // User Interface manager
|
|---|
| 21 | #include "G4UIterminal.hh" // User Interface manager through the terminal
|
|---|
| 22 |
|
|---|
| 23 | #ifdef G4UI_USE_TCSH
|
|---|
| 24 | #include "G4UItcsh.hh" // For terminal tcsh use
|
|---|
| 25 | #endif
|
|---|
| 26 |
|
|---|
| 27 | #undef G4VIS_USE
|
|---|
| 28 |
|
|---|
| 29 | #ifdef G4VIS_USE
|
|---|
| 30 | #include "G4VisExecutive.hh"
|
|---|
| 31 | #endif
|
|---|
| 32 |
|
|---|
| 33 | #include <bhep/bhep_svc.h>
|
|---|
| 34 | #include <bhep/sreader.h>
|
|---|
| 35 |
|
|---|
| 36 | using namespace snova;
|
|---|
| 37 |
|
|---|
| 38 | int main( int argc_ , char** argv_ )
|
|---|
| 39 | {
|
|---|
| 40 | bool debug = false;
|
|---|
| 41 | std::string params_filename = snova::constants::DEF_PARAMS_FILENAME;
|
|---|
| 42 | bool automatic = true;
|
|---|
| 43 | bool visual_mode = false;
|
|---|
| 44 | std::string G4_macro = "";
|
|---|
| 45 |
|
|---|
| 46 | // parse switches:
|
|---|
| 47 | int iarg=1;
|
|---|
| 48 | while ( iarg < argc_ ) {
|
|---|
| 49 |
|
|---|
| 50 | std::string arg = argv_[iarg];
|
|---|
| 51 |
|
|---|
| 52 | if ( arg[0] == '-' ) {
|
|---|
| 53 |
|
|---|
| 54 | if ( arg == "-d" || arg == "--debug" ) debug=true;
|
|---|
| 55 |
|
|---|
| 56 | if ( arg == "-p" || arg == "--params" ) {
|
|---|
| 57 | iarg++;
|
|---|
| 58 | if (iarg==argc_) {
|
|---|
| 59 | throw std::runtime_error("Missing simulation parameters file!");
|
|---|
| 60 | }
|
|---|
| 61 | params_filename=argv_[iarg];
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | }
|
|---|
| 65 | else {
|
|---|
| 66 | G4cerr << "arg=" << arg << G4endl;
|
|---|
| 67 |
|
|---|
| 68 | if ( arg == "vis" || arg == "visual" ) {
|
|---|
| 69 | visual_mode = true;
|
|---|
| 70 | }
|
|---|
| 71 | else {
|
|---|
| 72 | G4_macro=arg;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | iarg++;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | if ( visual_mode || !G4_macro.empty() ) automatic=false;
|
|---|
| 81 |
|
|---|
| 82 | // create a generic store:
|
|---|
| 83 | bhep::gstore store;
|
|---|
| 84 | G4cout << G4endl << "***** Reading parameters from '"
|
|---|
| 85 | << params_filename << "' file ..."
|
|---|
| 86 | << G4endl << G4endl;
|
|---|
| 87 |
|
|---|
| 88 | // and a reader:
|
|---|
| 89 | bhep::sreader reader(store);
|
|---|
| 90 | reader.file(params_filename.c_str());
|
|---|
| 91 | reader.info_level(NORMAL);
|
|---|
| 92 | reader.group("GLOBAL");
|
|---|
| 93 | reader.read();
|
|---|
| 94 |
|
|---|
| 95 | G4String sim_verbosity = store.fetch_sstore("simulation_verbosity");
|
|---|
| 96 | G4cout << "***** Simulation verbosity set to: " << sim_verbosity << G4endl;
|
|---|
| 97 |
|
|---|
| 98 | G4String G4Tracking_verbosity = store.fetch_sstore("G4Tracking_verbosity");
|
|---|
| 99 | G4cout << "***** G4 Tracking verbosity set to: " << G4Tracking_verbosity << G4endl;
|
|---|
| 100 |
|
|---|
| 101 | G4String dst_fname = store.fetch_sstore("dst_fname");
|
|---|
| 102 | G4cout << "***** DST output file name:" << dst_fname << G4endl;
|
|---|
| 103 |
|
|---|
| 104 | G4String gen_source = store.fetch_sstore("gen_source");
|
|---|
| 105 | G4double gen_min_E = store.fetch_dstore("gen_min_E");
|
|---|
| 106 | G4double gen_max_E = store.fetch_dstore("gen_max_E");
|
|---|
| 107 | G4int num_events = store.fetch_istore("num_events");
|
|---|
| 108 | G4String part_name = store.fetch_sstore("part_name");
|
|---|
| 109 |
|
|---|
| 110 | if (gen_source == "random") {
|
|---|
| 111 | G4cout << "***** Generator data will follow a flat random distribution in: " << G4endl;
|
|---|
| 112 | G4cout << "***** Ekin (Mev): (" << gen_min_E << " , "
|
|---|
| 113 | << gen_max_E << ")" << G4endl;
|
|---|
| 114 | G4cout << "***** Theta (deg): (0 , 90)" << G4endl;
|
|---|
| 115 | G4cout << "***** Phi (deg): (0 , 180)" << G4endl;
|
|---|
| 116 | G4cout << "***** Initial events: " << num_events << " " << part_name << G4endl;
|
|---|
| 117 | }
|
|---|
| 118 | else {
|
|---|
| 119 | G4cout << "***** Generator data source read from:" << gen_source << G4endl;
|
|---|
| 120 | G4cout << "***** Initial events: " << num_events << " pairs of " << part_name << G4endl;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | G4String geom_filename = store.fetch_sstore("geom_file");
|
|---|
| 124 | G4cout << "***** Reading geometry parameters from: '"
|
|---|
| 125 | << geom_filename << "'" << G4endl;
|
|---|
| 126 | G4cout << "***** Reading physics parameters from: '"
|
|---|
| 127 | << params_filename << "'" << G4endl;
|
|---|
| 128 |
|
|---|
| 129 | G4cout << "**********************************************************"
|
|---|
| 130 | << G4endl << G4endl;
|
|---|
| 131 |
|
|---|
| 132 | // The ihep::event service is generated. This server must be instantiated
|
|---|
| 133 | // wherever you want to access all the info.
|
|---|
| 134 | bhep::bhep_svc bsvc;
|
|---|
| 135 |
|
|---|
| 136 | // my Verbose output class:
|
|---|
| 137 | G4VSteppingVerbose* verbosity = new stepping_verbose;
|
|---|
| 138 | G4VSteppingVerbose::SetInstance(verbosity);
|
|---|
| 139 |
|
|---|
| 140 | // Run manager:
|
|---|
| 141 | G4RunManager * runManager = new G4RunManager;
|
|---|
| 142 |
|
|---|
| 143 | // UserInitialization classes (mandatory)
|
|---|
| 144 |
|
|---|
| 145 | // geometry
|
|---|
| 146 | geometry* geom = new geometry(geom_filename,params_filename);
|
|---|
| 147 | geom->set_info_level(sim_verbosity);
|
|---|
| 148 | runManager->SetUserInitialization(geom);
|
|---|
| 149 |
|
|---|
| 150 | // physics
|
|---|
| 151 | physics* phys = new physics(params_filename);
|
|---|
| 152 | phys->set_info_level(sim_verbosity);
|
|---|
| 153 | runManager->SetUserInitialization(phys);
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 | #ifdef G4VIS_USE
|
|---|
| 157 | // Visualization, if you choose to have it!
|
|---|
| 158 | G4VisManager* visManager = new G4VisExecutive;
|
|---|
| 159 | visManager->Initialize();
|
|---|
| 160 | #endif
|
|---|
| 161 |
|
|---|
| 162 | // UserAction classes
|
|---|
| 163 | // generator
|
|---|
| 164 | generator* my_gen = new generator( part_name ,
|
|---|
| 165 | gen_source ,
|
|---|
| 166 | gen_min_E ,
|
|---|
| 167 | gen_max_E ,
|
|---|
| 168 | geom->get_geom_mgr() ,
|
|---|
| 169 | params_filename );
|
|---|
| 170 | my_gen->set_info_level(sim_verbosity);
|
|---|
| 171 | runManager->SetUserAction(my_gen);
|
|---|
| 172 |
|
|---|
| 173 | // run
|
|---|
| 174 | run* my_run = new run(dst_fname);
|
|---|
| 175 | runManager->SetUserAction(my_run);
|
|---|
| 176 |
|
|---|
| 177 | //event
|
|---|
| 178 | snova::event* my_evt = new snova::event(part_name, dst_fname);
|
|---|
| 179 | my_evt->set_info_level(sim_verbosity);
|
|---|
| 180 | runManager->SetUserAction(my_evt);
|
|---|
| 181 |
|
|---|
| 182 | // track
|
|---|
| 183 | tracking* my_tracking = new tracking();
|
|---|
| 184 | my_tracking->set_info_level(sim_verbosity);
|
|---|
| 185 | runManager->SetUserAction(my_tracking);
|
|---|
| 186 |
|
|---|
| 187 | // step
|
|---|
| 188 | stepping* my_stepping = new stepping(part_name);
|
|---|
| 189 | my_stepping->set_info_level(sim_verbosity);
|
|---|
| 190 | runManager->SetUserAction(my_stepping);
|
|---|
| 191 |
|
|---|
| 192 | // stack
|
|---|
| 193 | stacking* my_stacking = new stacking(part_name);
|
|---|
| 194 | my_stacking->set_info_level(sim_verbosity);
|
|---|
| 195 | runManager->SetUserAction(my_stacking);
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 | //Initialize G4 kernel
|
|---|
| 199 | runManager->Initialize();
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 | //////////////////////////////////////////////////////////////
|
|---|
| 203 | //////////////////////////////////////////////////////////////
|
|---|
| 204 | //get the pointer to the User Interface manager
|
|---|
| 205 | //in order for the user to issue commands to the program
|
|---|
| 206 | G4UImanager * UI = G4UImanager::GetUIpointer();
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 | //////////////////////////////////////////////////////////////
|
|---|
| 210 | // Automatic mode
|
|---|
| 211 | if( automatic ) {
|
|---|
| 212 |
|
|---|
| 213 | #ifdef G4VIS_USE
|
|---|
| 214 | visManager->SetVerboseLevel("quiet");
|
|---|
| 215 | #endif
|
|---|
| 216 |
|
|---|
| 217 | G4String command = "/control/shell cp currentEvent.rndm currentRun.rndm";
|
|---|
| 218 | UI->ApplyCommand(command);
|
|---|
| 219 | command = "/random/setSavingFlag true";
|
|---|
| 220 | UI->ApplyCommand(command);
|
|---|
| 221 | command = "/random/resetEngineFrom currentRun.rndm";
|
|---|
| 222 | UI->ApplyCommand(command);
|
|---|
| 223 |
|
|---|
| 224 | command = "/tracking/verbose ";
|
|---|
| 225 | UI->ApplyCommand(command + G4Tracking_verbosity);
|
|---|
| 226 |
|
|---|
| 227 | command = "/run/beamOn ";
|
|---|
| 228 | UI->ApplyCommand(command+to_string(num_events));
|
|---|
| 229 |
|
|---|
| 230 | }
|
|---|
| 231 | else {
|
|---|
| 232 | // Visual mode
|
|---|
| 233 | if ( visual_mode ) {
|
|---|
| 234 |
|
|---|
| 235 | // G4UIterminal is a (dumb) terminal.
|
|---|
| 236 | G4UIsession *session = 0;
|
|---|
| 237 |
|
|---|
| 238 | #ifdef G4UI_USE_TCSH
|
|---|
| 239 | session = new G4UIterminal(new G4UItcsh);
|
|---|
| 240 | #else
|
|---|
| 241 | session = new G4UIterminal();
|
|---|
| 242 | #endif
|
|---|
| 243 |
|
|---|
| 244 | UI->ApplyCommand("/control/execute snova_vis.mac");
|
|---|
| 245 | session->SessionStart();
|
|---|
| 246 | delete session;
|
|---|
| 247 | }
|
|---|
| 248 | // Batch mode
|
|---|
| 249 | else {
|
|---|
| 250 |
|
|---|
| 251 | #ifdef G4VIS_USE
|
|---|
| 252 | visManager->SetVerboseLevel("quiet");
|
|---|
| 253 | #endif
|
|---|
| 254 |
|
|---|
| 255 | G4String command = "/control/execute ";
|
|---|
| 256 | G4String fileName = G4_macro.c_str();
|
|---|
| 257 | UI->ApplyCommand(command + fileName);
|
|---|
| 258 |
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | #ifdef G4VIS_USE
|
|---|
| 264 | delete visManager;
|
|---|
| 265 | #endif
|
|---|
| 266 |
|
|---|
| 267 | delete runManager;
|
|---|
| 268 | delete verbosity;
|
|---|
| 269 |
|
|---|
| 270 | return 0;
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | // end of prog_snova.cc
|
|---|