WC_Messenger.cc

Go to the documentation of this file.
00001 //! \file
00002 //!
00003 //! Source file for Wire_Chamber messenger class for the user interface.
00004 //!
00005 //! Defines the singleton messenger class and its member routines which
00006 //! control the parameters of Wire_Chamber detector within the OLYMPUS
00007 //! Monte Carlo.  This allow the user to control the parameters and/or
00008 //! running from command files or interactively.
00009 //!
00010 //! \author D.K. Hasell
00011 //! \version 1.0
00012 //! \date 2010-04-12
00013 //!
00014 //! \ingroup control
00015 
00016 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+****
00017 
00018 // Include user header files referenced in this file.
00019 
00020 #include "WC_Messenger.h"
00021 
00022 #include "WC_SD.h"
00023 
00024 // Include the GEANT4 header files referenced in this file.
00025 
00026 #include "G4UIdirectory.hh"
00027 
00028 // Initialise the static data pointer for the Messenger class.
00029 
00030 WC_Messenger * WC_Messenger::m_pInstance = 0;
00031 
00032 // Use the standard namespace.
00033 
00034 using namespace std;
00035 
00036 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+****
00037 
00038 // Define the routine to return pointer to the instance of WC_Messenger.
00039 
00040 WC_Messenger * WC_Messenger::Instance() {
00041    if( m_pInstance == 0 ) {
00042       m_pInstance = new WC_Messenger();
00043    }
00044    return m_pInstance;
00045 }
00046 
00047 // Constructor of WC_Messenger class.
00048 
00049 WC_Messenger::WC_Messenger() {
00050 
00051    WCdir = new G4UIdirectory( "/Olympus/WC/" );
00052    WCdir->SetGuidance( "OLYMPUS Wire Chamber user commands." );
00053 
00054 }
00055 
00056 // Routine to set a pointer to the WC_SD class and define the user
00057 // functions available.
00058 
00059 void WC_Messenger::setWC_SDptr( WC_SD * ptr ) {
00060 
00061    pWC_SD = ptr;
00062 
00063    WC_SDdir = new G4UIdirectory( "/Olympus/WC/SD/" );
00064    WC_SDdir->SetGuidance( "Wire Chamber Sensitive Detector commands." );
00065 
00066    // Threshold.
00067 
00068    WC_SDsetThreshold = new
00069       G4UIcmdWithADoubleAndUnit( "/Olympus/WC/SD/setThreshold", this );
00070    WC_SDsetThreshold->SetDefaultUnit( "eV" );
00071    WC_SDsetThreshold->SetGuidance( "Set hit threshold." );
00072    WC_SDsetThreshold->SetParameterName( "energy", false );
00073    WC_SDsetThreshold->SetRange( "energy >= 0.0" );
00074    WC_SDsetThreshold->AvailableForStates( G4State_Idle );
00075 
00076    WC_SDgetThreshold = new
00077       G4UIcmdWithoutParameter( "/Olympus/WC/SD/getThreshold", this );
00078    WC_SDgetThreshold->SetGuidance( "Get hit threshold." );
00079 
00080    // X resolution.
00081 
00082    WC_SDsetXresol = new
00083       G4UIcmdWithADoubleAndUnit( "/Olympus/WC/SD/setXresol", this );
00084    WC_SDsetXresol->SetDefaultUnit( "um" );
00085    WC_SDsetXresol->SetGuidance( "Set X resolution." );
00086    WC_SDsetXresol->SetParameterName( "x", false );
00087    WC_SDsetXresol->SetRange( "x >= 0.0" );
00088    WC_SDsetXresol->AvailableForStates( G4State_Idle );
00089 
00090    WC_SDgetXresol = new
00091       G4UIcmdWithoutParameter( "/Olympus/WC/SD/getXresol", this );
00092    WC_SDgetXresol->SetGuidance( "Get X resolution." );
00093 
00094    // Y resolution.
00095 
00096    WC_SDsetYresol = new
00097       G4UIcmdWithADoubleAndUnit( "/Olympus/WC/SD/setYresol", this );
00098    WC_SDsetYresol->SetDefaultUnit( "um" );
00099    WC_SDsetYresol->SetGuidance( "Set Y resolution." );
00100    WC_SDsetYresol->SetParameterName( "y", false );
00101    WC_SDsetYresol->SetRange( "y >= 0.0" );
00102    WC_SDsetYresol->AvailableForStates( G4State_Idle );
00103 
00104    WC_SDgetYresol = new
00105       G4UIcmdWithoutParameter( "/Olympus/WC/SD/getYresol", this );
00106    WC_SDgetYresol->SetGuidance( "Get Y resolution." );
00107 
00108 }
00109 
00110 // Routines to set new values and get current values.
00111 
00112 void WC_Messenger::SetNewValue( G4UIcommand * command, G4String newValue ) {
00113 
00114    // WC_SD Threshold.
00115 
00116    if( command == WC_SDsetThreshold ) {
00117       pWC_SD->setThreshold( WC_SDsetThreshold->GetNewDoubleValue( newValue ) );
00118       G4cout << "WC_SD threshold = " << newValue << G4endl;
00119    }
00120    else if( command == WC_SDgetThreshold ) {
00121       G4cout << "WC_SD threshold = " << pWC_SD->getThreshold() / eV 
00122              << " [eV]" << G4endl;
00123    }
00124 
00125   // WC_SD X resolution.
00126 
00127    else if( command == WC_SDsetXresol ) {
00128       pWC_SD->setXresol( WC_SDsetXresol->GetNewDoubleValue( newValue ) );
00129       G4cout << "WC_SD X resolution = " << newValue << G4endl;
00130    }
00131    else if( command == WC_SDgetXresol ) {
00132       G4cout << "WC_SD X resolution = " << pWC_SD->getXresol() / um 
00133              << " [um]" << G4endl;
00134    }
00135 
00136   // WC_SD Y resolution.
00137 
00138    else if( command == WC_SDsetYresol ) {
00139       pWC_SD->setYresol( WC_SDsetYresol->GetNewDoubleValue( newValue ) );
00140       G4cout << "WC_SD Y resolution = " << newValue << G4endl;
00141    }
00142    else if( command == WC_SDgetYresol ) {
00143       G4cout << "WC_SD Y resolution = " << pWC_SD->getYresol() / um 
00144              << " [um]" << G4endl;
00145    }
00146 
00147 }
00148 
00149 // Routine to get current value (not used).
00150 
00151 G4String WC_Messenger::GetCurrentValue( G4UIcommand * command ) {
00152    G4String cv;
00153    return cv;
00154 }