Changeset 85 for snovis


Ignore:
Timestamp:
Feb 9, 2007, 10:21:33 AM (15 years ago)
Author:
barrand
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • snovis/head/applications/snovis_session.cc

    r6 r85  
    33 */
    44
    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
     5#include <snova/snova_mgr.hh>
    156
    16 #include <G4RunManager.hh>  // Program manager
    17 #include <G4UImanager.hh>   // User Interface manager
     7#include <SNvertex/base_VG_factory.h>
     8#include <SNvertex/CALO_basic_VG.h>
     9#include <SNvertex/source_simple_VG.h>
    1810
    19 #include <bhep/bhep_svc.h>
    20 #include <bhep/sreader.h>
     11#include <G4Runmanager.hh>
     12#include <G4UImanager.hh>
    2113
    2214// G4Lab :
     
    2517
    2618using namespace snova;
     19
     20namespace snovis {
     21  class mgr : public snova::snova_mgr {
     22  public:
     23    mgr(){}
     24    virtual ~mgr(){}
     25  public:
     26    void run_sim(int argc , char** argv) {
     27      G4UImanager* UI = G4UImanager::GetUIpointer(); 
     28
     29      UI->ApplyCommand("/control/shell cp currentEvent.rndm currentRun.rndm");
     30      UI->ApplyCommand("/random/setSavingFlag true");
     31      UI->ApplyCommand("/random/resetEngineFrom currentRun.rndm");
     32      UI->ApplyCommand("/tracking/storeTrajectory 1");
     33      UI->ApplyCommand("/tracking/verbose 1");
     34 
     35      //G4RunManager* runManager = __runManager;
     36      G4RunManager* runManager = G4RunManager::GetRunManager();
     37
     38      std::string gui = "$SNOVISROOT/scripts/OnX/snovis_session.onx"; //UIOnX
     39      G4UIsession* session =
     40        new G4Lab::UIOnX(*runManager,gui,argc,argv); //UIOnX
     41      session->SessionStart();
     42      delete session;
     43    }
     44  };
     45}
    2746
    2847int main( int argc , char** argv )
     
    3958    return 1;
    4059  }
    41   std::string params_filename = SNOVISROOT+"/scripts/snova.par";
    42   G4String geom_filename = SNOVISROOT+"/scripts/snemo.geom";
    4360
    44   // create a generic store:
    45   bhep::gstore store;
    46   G4cout << G4endl << "***** Reading parameters from '"
    47          << params_filename << "' file ..."
    48          << G4endl << G4endl;
     61  int error_code=EXIT_SUCCESS;
     62  try {
    4963
    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();
     64    std::cout << "Hello, this is a sample program for class 'snova_mgr'!" << std::endl;
     65 
     66    bool        debug           = false;
     67    //std::string params_filename = snova::constants::DEF_PARAMS_FILENAME;
     68    std::string params_filename = SNOVISROOT+"/scripts/snova.par";
     69    //G4String geom_filename = SNOVISROOT+"/scripts/snemo.geom";
     70    std::string G4_macro        = "";
     71    bool        visual_mode     = false;
     72   
     73    // A snova manager:
     74    snovis::mgr my_snova_mgr;
    5675
    57   G4String sim_verbosity = store.fetch_sstore("simulation_verbosity");
    58   G4cout << "***** Simulation verbosity set to: " << sim_verbosity << G4endl;
     76    // Configure some properties of the snova manager:
     77    my_snova_mgr.set_debug(debug);                     // debug verbosity
     78    my_snova_mgr.set_params_filename(params_filename); // the main simulation configuration file
     79    my_snova_mgr.set_visual_mode(visual_mode);         // use X11 display
     80    my_snova_mgr.set_G4_macro(G4_macro);               // run G4 macro
    5981
    60   G4String G4Tracking_verbosity = store.fetch_sstore("G4Tracking_verbosity");
    61   G4cout << "***** G4 Tracking verbosity set to: " << G4Tracking_verbosity << G4endl;
     82    // Use a dedicated vertex generator factory:
     83    snemo::base_VG_factory my_VG_factory;
     84    my_VG_factory.add("CALO_basic",    snemo::CALO_basic_VG::new_CALO_basic_VG );
     85    my_VG_factory.add("source_simple", snemo::source_simple_VG::new_source_simple_VG );
     86    // <here you may add more functors in the factory internal map... >
     87    //my_VG_factory.add("TC_nblocks", snemo::TC_nblocks_VG::new_TC_nblocks_VG ); // NOT AVAILABLE YET!
    6288
    63   G4String dst_fname = store.fetch_sstore("dst_fname");
    64   G4cout << "***** DST output file name:" << dst_fname << G4endl;
     89    my_VG_factory.init();
     90    if( debug ) my_VG_factory.dump(std::cerr);
     91    my_snova_mgr.set_VG_factory(my_VG_factory);
    6592
    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");
     93    // Build the guts of the simulation process within the snova manager:
     94    std::cerr << "prog_snova2: debug: "
     95              << "Build the guts" << std::endl;
     96    my_snova_mgr.init(); // from this point 'set_XXXX' methods failed (manager is locked!)
    7197
    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;
     98    // Run the simulation:
     99    std::cerr << "prog_snova2: debug: "
     100              << "Run the simulation" << std::endl;
     101    my_snova_mgr.run_sim(argc,argv);
     102
     103    // Clean the snova manager
     104    std::cerr << "prog_snova2: debug: "
     105              << "Clean the snova manager" << std::endl;
     106    my_snova_mgr.reset(); // not mandatory for we do it in the d-tor.
     107
     108    std::cerr << "prog_snova2: debug: "
     109              << "Done" << std::endl;
    79110  }
    80   else {
    81     G4cout << "***** Generator data source read from:" << gen_source << G4endl;
    82     G4cout << "***** Initial events: " << num_events << " pairs of " << part_name << G4endl;
     111  catch(std::exception & x){
     112    std::cerr << "prog_snova2: error: " << x.what() << std::endl;
     113    error_code=EXIT_FAILURE;
    83114  }
    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;
     115  catch(...){
     116    std::cerr << "prog_snova2: error: " << "unexpected error!" << std::endl;
     117    error_code=EXIT_FAILURE;
     118  }
     119  return error_code;
    184120}
    185 
    186 // end of prog_snova.cc
Note: See TracChangeset for help on using the changeset viewer.