Skip to content
Snippets Groups Projects
CherProto.cc 3.13 KiB
Newer Older
  • Learn to ignore specific revisions
  • Chao Peng's avatar
    Chao Peng committed
    
    /// \file CherProto/CherProto.cc
    /// \brief Main program of the CherProto
    //
    // Description: Process of G4Cerenkov for JLab Cherekov Phototype
    //              -- Generation Cerenkov Photons --
    // Version:     1.0
    // Created:     1996-04-30
    // Author:
    // mail:
    //
    
    
    Chao Peng's avatar
    Chao Peng committed
    #include "PhysicsList.hh"
    #include "DetectorConstruction.hh"
    #include "ActionInitialization.hh"
    
    Chao Peng's avatar
    Chao Peng committed
    
    
    #include "G4RunManager.hh"
    #include "G4UImanager.hh"
    
    Chao Peng's avatar
    Chao Peng committed
    #include "G4VisExecutive.hh"
    #include "G4UIExecutive.hh"
    
    #include "TFile.h"
    #include <random>
    
    Chao Peng's avatar
    Chao Peng committed
    
    
    namespace {
    
        void PrintUsage() {
            G4cerr << " Usage: " << G4endl;
            G4cerr << " CherProto [-m macro ] [-u UIsession] [-r seed] [-c config] "
                   << G4endl;
        }
    
    Chao Peng's avatar
    Chao Peng committed
    }
    
    
    int main(int argc,char** argv)
    {
    
        // Evaluate arguments
        //
        if ( argc > 9 ) {
            PrintUsage();
            return 1;
    
    Chao Peng's avatar
    Chao Peng committed
        }
    
    
        G4String macro, session, config = "cher_proto_det.mac";
        G4int myseed = -1;
    
        for ( G4int i = 1; i < argc; i = i+2 ) {
            if      ( G4String(argv[i]) == "-m" ) macro   = argv[i+1];
            else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
            else if ( G4String(argv[i]) == "-r" ) myseed  = atoi(argv[i+1]);
            else if ( G4String(argv[i]) == "-c" ) config  = argv[i+1];
            else {
                PrintUsage();
                return 1;
            }
    
    Chao Peng's avatar
    Chao Peng committed
        }
    
    
        // Choose the Random engine
        G4Random::setTheEngine(new CLHEP::RanecuEngine);
    
        // Construct the default run manager
        G4RunManager * runManager = new G4RunManager;
    
        // Seed the random number generator manually
        std::random_device rd;
        G4Random::setTheSeed((myseed < 0) ? rd() : myseed);
    
        // Get the pointer to the User Interface manager
        G4UImanager* UImanager = G4UImanager::GetUIpointer();
    
        // Set mandatory initialization classes
        // Detector construction
        runManager->SetUserInitialization(new DetectorConstruction());
    
        // Physics list
        runManager->SetUserInitialization(new PhysicsList());
    
        // User action initialization
        runManager->SetUserInitialization(new ActionInitialization());
    
        G4String command = "/control/execute ";
        UImanager->ApplyCommand(command + config);
    
        // Initialize G4 kernel
        runManager->Initialize();
    
        // Initialize visualization
        G4VisManager* visManager = new G4VisExecutive;
        // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
        // G4VisManager* visManager = new G4VisExecutive("Quiet");
        visManager->Initialize();
    
        if ( macro.size() ) {
            // Batch mode
            UImanager->ApplyCommand(command+macro);
            // Define UI session for interactive mode
        } else {
            G4UIExecutive * ui = new G4UIExecutive(argc,argv,session);
            UImanager->ApplyCommand("/control/execute vis.mac");
            if (ui->IsGUI()) { UImanager->ApplyCommand("/control/execute gui.mac"); }
            ui->SessionStart();
            delete ui;
        }
    
    Chao Peng's avatar
    Chao Peng committed
    
    
        // Job termination
        // Free the store: user actions, physics_list and detector_description are
        //                 owned and deleted by the run manager, so they should not
        //                 be deleted in the main() program !
    
    Chao Peng's avatar
    Chao Peng committed
    
    
        delete visManager;
        delete runManager;
    
    Chao Peng's avatar
    Chao Peng committed
    
    
    Chao Peng's avatar
    Chao Peng committed
    }