MW_Messenger.cc

Go to the documentation of this file.
00001 //! \file
00002 //!
00003 //! Source file for MWPC messenger class for the user interface.
00004 //!
00005 //! Defines the singleton messenger class and its member routines which
00006 //! control the parameters of MWPC 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-10-17
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 "MW_Messenger.h"
00021 #include "MW_SD.h"
00022 
00023 // Include the GEANT4 header files referenced in this file.
00024 
00025 #include "G4UIdirectory.hh"
00026 
00027 // Initialise the static data pointer for the MW_Messenger class.
00028 
00029 MW_Messenger * MW_Messenger::m_pInstance = 0;
00030 
00031 // Use the standard namespace.
00032 
00033 using namespace std;
00034 
00035 // *+****1****+****2****+****3****+****4****+****5****+****6****+****7****+****
00036 
00037 // Define the routine to return pointer to the instance of MW_Messenger.
00038 
00039 MW_Messenger * MW_Messenger::Instance() {
00040    if( m_pInstance == 0 ) {
00041       m_pInstance = new MW_Messenger();
00042    }
00043    return m_pInstance;
00044 }
00045 
00046 // Constructor of MW_Messenger class.
00047 
00048 MW_Messenger::MW_Messenger() {
00049 
00050    MWdir = new G4UIdirectory( "/Olympus/MW/" );
00051    MWdir->SetGuidance( "OLYMPUS MWPC user commands." );
00052 
00053 }
00054 
00055 // Routine to set a pointer to the MW_SD class and define the user
00056 // functions available.
00057 
00058 void MW_Messenger::setMW_SDptr( MW_SD * ptr ) {
00059 
00060    pMW_SD = ptr;
00061 
00062    MW_SDdir = new G4UIdirectory( "/Olympus/MW/SD/" );
00063    MW_SDdir->SetGuidance( "MWPC Sensitive Detector commands." );
00064 
00065    // Threshold.
00066 
00067    MW_SDsetThreshold = new
00068       G4UIcmdWithADoubleAndUnit( "/Olympus/MW/SD/setThreshold", this );
00069    MW_SDsetThreshold->SetDefaultUnit( "eV" );
00070    MW_SDsetThreshold->SetGuidance( "Set hit threshold." );
00071    MW_SDsetThreshold->SetParameterName( "energy", false );
00072    MW_SDsetThreshold->SetRange( "energy >= 0.0" );
00073    MW_SDsetThreshold->AvailableForStates( G4State_Idle );
00074 
00075    MW_SDgetThreshold = new
00076       G4UIcmdWithoutParameter( "/Olympus/MW/SD/getThreshold", this );
00077    MW_SDgetThreshold->SetGuidance( "Get hit threshold." );
00078 
00079    // X resolution.
00080 
00081    MW_SDsetXresol = new
00082       G4UIcmdWithADoubleAndUnit( "/Olympus/MW/SD/setXresol", this );
00083    MW_SDsetXresol->SetDefaultUnit( "um" );
00084    MW_SDsetXresol->SetGuidance( "Set X resolution." );
00085    MW_SDsetXresol->SetParameterName( "x", false );
00086    MW_SDsetXresol->SetRange( "x >= 0.0" );
00087    MW_SDsetXresol->AvailableForStates( G4State_Idle );
00088 
00089    MW_SDgetXresol = new
00090       G4UIcmdWithoutParameter( "/Olympus/MW/SD/getXresol", this );
00091    MW_SDgetXresol->SetGuidance( "Get X resolution." );
00092 
00093    // Y resolution.
00094 
00095    MW_SDsetYresol = new
00096       G4UIcmdWithADoubleAndUnit( "/Olympus/MW/SD/setYresol", this );
00097    MW_SDsetYresol->SetDefaultUnit( "um" );
00098    MW_SDsetYresol->SetGuidance( "Set Y resolution." );
00099    MW_SDsetYresol->SetParameterName( "y", false );
00100    MW_SDsetYresol->SetRange( "y >= 0.0" );
00101    MW_SDsetYresol->AvailableForStates( G4State_Idle );
00102 
00103    MW_SDgetYresol = new
00104       G4UIcmdWithoutParameter( "/Olympus/MW/SD/getYresol", this );
00105    MW_SDgetYresol->SetGuidance( "Get Y resolution." );
00106 
00107 }
00108 
00109 // Routines to set new values and get current values.
00110 
00111 void MW_Messenger::SetNewValue( G4UIcommand * command, G4String newValue ) {
00112 
00113    // MW_SD Threshold.
00114 
00115    if( command == MW_SDsetThreshold ) {
00116       pMW_SD->setThreshold( MW_SDsetThreshold->GetNewDoubleValue( newValue ) );
00117       G4cout << "MW_SD threshold = " << newValue << G4endl;
00118    }
00119    else if( command == MW_SDgetThreshold ) {
00120       G4cout << "MW_SD threshold = " << pMW_SD->getThreshold() / eV 
00121              << " [eV]" << G4endl;
00122    }
00123 
00124   // MW_SD X resolution.
00125 
00126    else if( command == MW_SDsetXresol ) {
00127       pMW_SD->setXresol( MW_SDsetXresol->GetNewDoubleValue( newValue ) );
00128       G4cout << "MW_SD X resolution = " << newValue << G4endl;
00129    }
00130    else if( command == MW_SDgetXresol ) {
00131       G4cout << "MW_SD X resolution = " << pMW_SD->getXresol() / um 
00132              << " [um]" << G4endl;
00133    }
00134 
00135   // MW_SD Y resolution.
00136 
00137    else if( command == MW_SDsetYresol ) {
00138       pMW_SD->setYresol( MW_SDsetYresol->GetNewDoubleValue( newValue ) );
00139       G4cout << "MW_SD Y resolution = " << newValue << G4endl;
00140    }
00141    else if( command == MW_SDgetYresol ) {
00142       G4cout << "MW_SD Y resolution = " << pMW_SD->getYresol() / um 
00143              << " [um]" << G4endl;
00144    }
00145 
00146 }
00147 
00148 // Routine to get current value (not used).
00149 
00150 G4String MW_Messenger::GetCurrentValue( G4UIcommand * command ) {
00151    G4String cv;
00152    return cv;
00153 }