Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-26 07:40:49

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file DetectorMessenger.cc
0027 /// \brief Implementation of the DetectorMessenger class
0028 
0029 #include "DetectorMessenger.hh"
0030 
0031 #include "DetectorConstruction.hh"
0032 
0033 #include "G4UIcmdWithABool.hh"
0034 #include "G4UIcmdWithADouble.hh"
0035 #include "G4UIcmdWithADoubleAndUnit.hh"
0036 #include "G4UIcmdWithAString.hh"
0037 #include "G4UIcmdWithAnInteger.hh"
0038 #include "G4UIcmdWithoutParameter.hh"
0039 #include "G4UIdirectory.hh"
0040 #include "globals.hh"
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 DetectorMessenger::DetectorMessenger(DetectorConstruction* myDet) : fDetector(myDet)
0045 {
0046   fDetectorDir = new G4UIdirectory("/mydet/");
0047   fDetectorDir->SetGuidance("Detector control.");
0048 
0049   fFieldCommand = new G4UIcmdWithADoubleAndUnit("/mydet/setField", this);
0050   fFieldCommand->SetGuidance("Define uniform magnetic field along Y.");
0051   fFieldCommand->SetGuidance(" -> in unit of  [Tesla]");
0052   fFieldCommand->SetParameterName("By", false);
0053   fFieldCommand->SetDefaultValue(0.0);
0054   fFieldCommand->SetUnitCategory("Magnetic flux density");
0055   fFieldCommand->AvailableForStates(G4State_PreInit, G4State_Idle);
0056 
0057   fAbsorberMaterial = new G4UIcmdWithAString("/mydet/absorberMaterial", this);
0058   fAbsorberMaterial->SetGuidance("Choice of the absorber material:");
0059   fAbsorberMaterial->SetGuidance("   iron / copper / tungsten / lead / PbWO4 / uranium ");
0060   fAbsorberMaterial->SetParameterName("choiceAbsorberMaterial", true);
0061   fAbsorberMaterial->SetDefaultValue("iron");
0062   fAbsorberMaterial->AvailableForStates(G4State_PreInit, G4State_Idle);
0063 
0064   fActiveMaterial = new G4UIcmdWithAString("/mydet/activeMaterial", this);
0065   fActiveMaterial->SetGuidance("Choice of the active material:");
0066   fActiveMaterial->SetGuidance("   scintillator / liquidArgon / PbWO4 / silicon / quartz ");
0067   fActiveMaterial->SetParameterName("choiceActiveMaterial", true);
0068   fActiveMaterial->SetDefaultValue("scintillator");
0069   fActiveMaterial->AvailableForStates(G4State_PreInit, G4State_Idle);
0070 
0071   fIsCalHomogeneous = new G4UIcmdWithABool("/mydet/isCalHomogeneous", this);
0072   fIsCalHomogeneous->SetParameterName("choiceIsCalHomogeneous", true);
0073   fIsCalHomogeneous->SetGuidance("Is the calorimeter homogeneous?");
0074   fIsCalHomogeneous->SetGuidance(" -> yes|y|true|t|1 : Homogeneous calorimeter");
0075   fIsCalHomogeneous->SetGuidance(" -> no|n|false|f|0 : Sampling calorimeter");
0076   fIsCalHomogeneous->SetDefaultValue(false);  // default: sampling calorimeter
0077   fIsCalHomogeneous->AvailableForStates(G4State_PreInit, G4State_Idle);
0078 
0079   fIsUnitInLambda = new G4UIcmdWithABool("/mydet/isUnitInLambda", this);
0080   fIsUnitInLambda->SetParameterName("choiceIsUnitInLambda", true);
0081   fIsUnitInLambda->SetGuidance("Is unit for absorber length in lambda?");
0082   fIsUnitInLambda->SetGuidance(" -> yes|y|true|t|1 : unit in lambda");
0083   fIsUnitInLambda->SetGuidance(" -> no|n|false|f|0 : unit in [mm]");
0084   fIsUnitInLambda->SetDefaultValue(false);  // default: unit in [mm].
0085   fIsUnitInLambda->AvailableForStates(G4State_PreInit, G4State_Idle);
0086 
0087   fAbsorberTotalLength = new G4UIcmdWithADouble("/mydet/absorberTotalLength", this);
0088   fAbsorberTotalLength->SetParameterName("choiceAbsorberTotalLength", true);
0089   fAbsorberTotalLength->SetGuidance("Absorber total length");
0090   fAbsorberTotalLength->SetGuidance(" -> in unit of lambda or [mm]");
0091   fAbsorberTotalLength->SetGuidance(" -> depending on value of choiceIsUnitInLambda");
0092   fAbsorberTotalLength->SetDefaultValue(2000.0);  // default: 2 meters.
0093   fAbsorberTotalLength->AvailableForStates(G4State_PreInit, G4State_Idle);
0094 
0095   fCalorimeterRadius = new G4UIcmdWithADouble("/mydet/calorimeterRadius", this);
0096   fCalorimeterRadius->SetParameterName("choiceCalorimeterRadius", true);
0097   fCalorimeterRadius->SetGuidance("Calorimeter Radius");
0098   fCalorimeterRadius->SetGuidance(" -> in unit of lambda or [mm]");
0099   fCalorimeterRadius->SetGuidance(" -> depending on value of choiceIsUnitInLambda");
0100   fCalorimeterRadius->SetDefaultValue(1000.0);  // default: 1 meter.
0101   fCalorimeterRadius->AvailableForStates(G4State_PreInit, G4State_Idle);
0102 
0103   fActiveLayerNumber = new G4UIcmdWithAnInteger("/mydet/activeLayerNumber", this);
0104   fActiveLayerNumber->SetParameterName("choiceActiveLayerNumber", true);
0105   fActiveLayerNumber->SetGuidance("Number of active layers");
0106   fActiveLayerNumber->SetDefaultValue(50);
0107   fActiveLayerNumber->AvailableForStates(G4State_PreInit, G4State_Idle);
0108 
0109   fActiveLayerSize = new G4UIcmdWithADouble("/mydet/activeLayerSize", this);
0110   fActiveLayerSize->SetParameterName("choiceActiveLayerSize", true);
0111   fActiveLayerSize->SetGuidance("Size (thickness) of the active layer, in [mm]");
0112   fActiveLayerSize->SetDefaultValue(4.0);  // default: 4 millimeters.
0113   fActiveLayerSize->AvailableForStates(G4State_PreInit, G4State_Idle);
0114 
0115   fIsRadiusUnitInLambda = new G4UIcmdWithABool("/mydet/isRadiusUnitInLambda", this);
0116   fIsRadiusUnitInLambda->SetParameterName("choiceIsRadiusUnitInLambda", true);
0117   fIsRadiusUnitInLambda->SetGuidance("Is unit of radius in lambda?");
0118   fIsRadiusUnitInLambda->SetGuidance(" -> yes|y|true|t|1 : unit in lambda");
0119   fIsRadiusUnitInLambda->SetGuidance(" -> no|n|false|f|0 : unit in [mm]");
0120   fIsRadiusUnitInLambda->SetDefaultValue(false);  // default: unit in [mm].
0121   fIsRadiusUnitInLambda->AvailableForStates(G4State_PreInit, G4State_Idle);
0122 
0123   fUpdateCommand = new G4UIcmdWithoutParameter("/mydet/update", this);
0124   fUpdateCommand->SetGuidance("Update calorimeter geometry.");
0125   fUpdateCommand->SetGuidance("This command MUST be applied before \"beamOn\" ");
0126   fUpdateCommand->SetGuidance("if you changed geometrical value(s).");
0127   fUpdateCommand->AvailableForStates(G4State_Idle);
0128 }
0129 
0130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0131 
0132 DetectorMessenger::~DetectorMessenger()
0133 {
0134   delete fFieldCommand;
0135   delete fDetectorDir;
0136   delete fAbsorberMaterial;
0137   delete fActiveMaterial;
0138   delete fIsCalHomogeneous;
0139   delete fIsUnitInLambda;
0140   delete fAbsorberTotalLength;
0141   delete fCalorimeterRadius;
0142   delete fActiveLayerNumber;
0143   delete fActiveLayerSize;
0144   delete fIsRadiusUnitInLambda;
0145   delete fUpdateCommand;
0146 }
0147 
0148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0149 
0150 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0151 {
0152   if (command == fFieldCommand) {
0153     fDetector->SetMagField(fFieldCommand->GetNewDoubleValue(newValue));
0154   }
0155   if (command == fAbsorberMaterial) {
0156     fDetector->SetAbsorberMaterial(newValue);
0157   }
0158   if (command == fActiveMaterial) {
0159     fDetector->SetActiveMaterial(newValue);
0160   }
0161   if (command == fIsCalHomogeneous) {
0162     fDetector->SetIsCalHomogeneous(fIsCalHomogeneous->GetNewBoolValue(newValue));
0163   }
0164   if (command == fIsUnitInLambda) {
0165     fDetector->SetIsUnitInLambda(fIsUnitInLambda->GetNewBoolValue(newValue));
0166   }
0167   if (command == fAbsorberTotalLength) {
0168     fDetector->SetAbsorberTotalLength(fAbsorberTotalLength->GetNewDoubleValue(newValue));
0169   }
0170   if (command == fCalorimeterRadius) {
0171     fDetector->SetCalorimeterRadius(fCalorimeterRadius->GetNewDoubleValue(newValue));
0172   }
0173   if (command == fActiveLayerNumber) {
0174     fDetector->SetActiveLayerNumber(fActiveLayerNumber->GetNewIntValue(newValue));
0175   }
0176   if (command == fActiveLayerSize) {
0177     fDetector->SetActiveLayerSize(fActiveLayerSize->GetNewDoubleValue(newValue));
0178   }
0179   if (command == fIsRadiusUnitInLambda) {
0180     fDetector->SetIsRadiusUnitInLambda(fIsRadiusUnitInLambda->GetNewBoolValue(newValue));
0181   }
0182   if (command == fUpdateCommand) {
0183     fDetector->UpdateGeometry();
0184   }
0185 }
0186 
0187 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......