lcdd/include
diff -N SensitiveDetectorMessenger.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SensitiveDetectorMessenger.hh 18 Dec 2006 21:20:08 -0000 1.1
@@ -0,0 +1,54 @@
+#ifndef LCDD_SENSITIVEDETECTORMESSENGER_HH
+#define LCDD_SENSITIVEDETECTORMESSENGER_HH 1
+
+// geant4
+#include "G4UImessenger.hh"
+
+// lcdd
+#include "G4SensitiveDetector.hh"
+
+class G4UIcommand;
+class G4UIcmdWithABool;
+class G4UIcmdWithAnInteger;
+class G4UIdirectory;
+class G4UIcmdWithADoubleAndUnit;
+
+/**
+ * SensitiveDetectorMessenger is a G4UImessenger subclass
+ * that provides a macro command interface for each
+ * G4VSensitiveDetector registered by LCDD.
+ */
+class SensitiveDetectorMessenger : public G4UImessenger
+{
+public:
+ SensitiveDetectorMessenger(G4SensitiveDetector* detector);
+
+ virtual ~SensitiveDetectorMessenger();
+
+public:
+
+ virtual void SetNewValue(G4UIcommand* cmd, G4String newVals);
+
+ static void makeDetectorsDir();
+
+ void defineCommands(G4VSensitiveDetector* sd);
+
+private:
+
+ static G4UIdirectory* m_detectorsDir;
+
+ G4SensitiveDetector* m_detector;
+
+ G4UIdirectory* m_detectorDir;
+
+ G4UIcommand* m_printInfoCmd;
+ G4UIcommand* m_printHitsCmd;
+ G4UIcommand* m_printVolumesCmd;
+ G4UIcommand* m_printTotalEdepCmd;
+ G4UIcommand* m_printNHitsCmd;
+ G4UIcmdWithAnInteger* m_verboseCmd;
+ G4UIcmdWithABool* m_activateCmd;
+ G4UIcmdWithADoubleAndUnit* m_ecutCmd;
+};
+
+#endif
lcdd/src
diff -N SensitiveDetectorMessenger.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SensitiveDetectorMessenger.cc 18 Dec 2006 21:20:08 -0000 1.1
@@ -0,0 +1,114 @@
+// $Id: SensitiveDetectorMessenger.cc,v 1.1 2006/12/18 21:20:08 jeremy Exp $
+#include "SensitiveDetectorMessenger.hh"
+
+// geant4
+#include "G4UIcommand.hh"
+#include "G4UIcmdWithAnInteger.hh"
+#include "G4UIcmdWithABool.hh"
+#include "G4UIcmdWithADoubleAndUnit.hh"
+#include "G4UIdirectory.hh"
+#include "G4VSensitiveDetector.hh"
+
+G4UIdirectory* SensitiveDetectorMessenger::m_detectorsDir = 0;
+
+SensitiveDetectorMessenger::SensitiveDetectorMessenger(G4SensitiveDetector* detector)
+ : m_detector(detector)
+{
+ if ( m_detectorsDir == 0 ) {
+ makeDetectorsDir();
+ }
+
+ defineCommands(m_detector);
+}
+
+SensitiveDetectorMessenger::~SensitiveDetectorMessenger()
+{
+ // TODO: put command deletes here
+}
+
+void SensitiveDetectorMessenger::SetNewValue(G4UIcommand* cmd, G4String newVals)
+{
+ if ( cmd == m_printInfoCmd ) {
+ m_detector->printBasicInfo( std::cout );
+ }
+ else if ( cmd == m_printNHitsCmd ) {
+ m_detector->printNumberOfHits( std::cout );
+ }
+ else if ( cmd == m_printTotalEdepCmd ) {
+ m_detector->printEdep( std::cout );
+ }
+ else if ( cmd == m_printVolumesCmd ) {
+ m_detector->printVolumes( std::cout );
+ }
+ else if ( cmd == m_printHitsCmd ) {
+ m_detector->printHits( std::cout );
+ }
+ else if ( cmd == m_verboseCmd ) {
+ m_detector->setVerbose( G4UIcmdWithAnInteger::GetNewIntValue( newVals ) );
+ }
+ else if ( cmd == m_activateCmd ) {
+ m_detector->Activate( G4UIcmdWithABool::GetNewBoolValue( newVals ) );
+ }
+ else if ( cmd == m_ecutCmd ) {
+ m_detector->setEcut( G4UIcmdWithADoubleAndUnit::GetNewDoubleValue( newVals ) );
+ }
+
+}
+
+void SensitiveDetectorMessenger::makeDetectorsDir()
+{
+ m_detectorsDir = new G4UIdirectory( "/detectors/" );
+ m_detectorsDir->SetGuidance("Commands for sensitive detectors. [LCDD]");
+}
+
+void SensitiveDetectorMessenger::defineCommands(G4VSensitiveDetector* sd)
+{
+ // Name of the sensitive detector.
+ const G4String& name = sd->GetName();
+
+ // Name of the sensitive detector's command directory.
+ const G4String& dirName = G4String("/detectors/" + name + "/");
+
+ // Create the sensitive detector's Geant4 macro command directory.
+ m_detectorDir = new G4UIdirectory( dirName.c_str() );
+ m_detectorDir->SetGuidance( G4String( "Commands for the sensitive detector " + name ).c_str() );
+
+ // Print command.
+ m_printInfoCmd = new G4UIcommand( G4String( dirName + "print" ).c_str(), this );
+ m_printInfoCmd->SetGuidance( G4String( "Print basic information about the sensitive detector " + name ).c_str() );
+
+ // Print number of hits command.
+ m_printNHitsCmd = new G4UIcommand( G4String( dirName + "printNumberOfHits" ).c_str(), this );
+ m_printInfoCmd->SetGuidance( G4String( "Print the number of hits from the detector " + name ).c_str() );
+
+ // Print energy deposition.
+ m_printTotalEdepCmd = new G4UIcommand( G4String( dirName + "printEdep" ).c_str(), this );
+ m_printTotalEdepCmd->SetGuidance( G4String( "Print the total energy deposition from the detector " + name ).c_str() );
+
+ // Print energy deposition.
+ m_printVolumesCmd = new G4UIcommand( G4String( dirName + "printVolumes" ).c_str(), this );
+ m_printVolumesCmd->SetGuidance( G4String( "Print a list of logical volume names associated with the detector " + name ).c_str() );
+
+ // Print energy deposition.
+ m_printHitsCmd = new G4UIcommand( G4String( dirName + "printHits" ).c_str(), this );
+ m_printHitsCmd->SetGuidance( G4String( "Print a list of hits from the detector " + name ).c_str() );
+
+ // Set the verbosity.
+ m_verboseCmd = new G4UIcmdWithAnInteger( G4String( dirName + "setVerbose" ).c_str(), this );
+ m_verboseCmd->SetGuidance( G4String( "Set the verbosity of the detector " + name ).c_str() );
+ m_verboseCmd->SetDefaultValue( 2 );
+ m_verboseCmd->SetParameterName( "verbose", true, true );
+
+ // Activate or deactive this detector.
+ m_activateCmd = new G4UIcmdWithABool( G4String( dirName + "setActive" ).c_str(), this );
+ m_activateCmd->SetGuidance( G4String( "Set whether the detector " + name + " is active.").c_str() );
+ m_activateCmd->SetDefaultValue( true );
+ m_activateCmd->SetParameterName( "active", true, true );
+
+ // Set the ecut with unit.
+ m_ecutCmd = new G4UIcmdWithADoubleAndUnit( G4String( dirName + "setHitEnergyCut").c_str(), this);
+ m_ecutCmd->SetGuidance( G4String( "Set the single hit energy cut for detector " + name).c_str() );
+ m_ecutCmd->SetDefaultValue( 0.0 );
+ m_ecutCmd->SetDefaultUnit ( "GeV" );
+ m_ecutCmd->SetParameterName( "cut", true, true );
+}