Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 08:28:59

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 "G4UIcmdWithADoubleAndUnit.hh"
0034 #include "G4UIcmdWithAString.hh"
0035 #include "G4UIcmdWithAnInteger.hh"
0036 #include "G4UIcmdWithoutParameter.hh"
0037 #include "G4UIcommand.hh"
0038 #include "G4UIdirectory.hh"
0039 #include "G4UIparameter.hh"
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 DetectorMessenger::DetectorMessenger(DetectorConstruction* Det)
0044   : G4UImessenger(),
0045     fDetector(Det),
0046     fTestemDir(nullptr),
0047     fDetDir(nullptr),
0048     fMaterCmd(nullptr),
0049     fWMaterCmd(nullptr),
0050     fSizeXCmd(nullptr),
0051     fSizeYZCmd(nullptr),
0052     fMagFieldCmd(nullptr),
0053     fTalNbCmd(nullptr),
0054     fTalDefCmd(nullptr),
0055     fTalPosiCmd(nullptr)
0056 {
0057   fTestemDir = new G4UIdirectory("/testem/");
0058   fTestemDir->SetGuidance(" detector control.");
0059 
0060   fDetDir = new G4UIdirectory("/testem/det/");
0061   fDetDir->SetGuidance("detector construction commands");
0062 
0063   fMaterCmd = new G4UIcmdWithAString("/testem/det/setMat", this);
0064   fMaterCmd->SetGuidance("Select material of the box.");
0065   fMaterCmd->SetParameterName("choice", false);
0066   fMaterCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0067 
0068   fWMaterCmd = new G4UIcmdWithAString("/testem/det/setWorldMat", this);
0069   fWMaterCmd->SetGuidance("Select material of the world.");
0070   fWMaterCmd->SetParameterName("choice", false);
0071   fWMaterCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0072 
0073   fSizeXCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeX", this);
0074   fSizeXCmd->SetGuidance("Set sizeX of the absorber");
0075   fSizeXCmd->SetParameterName("SizeX", false);
0076   fSizeXCmd->SetRange("SizeX>0.");
0077   fSizeXCmd->SetUnitCategory("Length");
0078   fSizeXCmd->AvailableForStates(G4State_PreInit);
0079 
0080   fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeYZ", this);
0081   fSizeYZCmd->SetGuidance("Set sizeYZ of the absorber");
0082   fSizeYZCmd->SetParameterName("SizeYZ", false);
0083   fSizeYZCmd->SetRange("SizeYZ>0.");
0084   fSizeYZCmd->SetUnitCategory("Length");
0085   fSizeYZCmd->AvailableForStates(G4State_PreInit);
0086 
0087   fMagFieldCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setField", this);
0088   fMagFieldCmd->SetGuidance("Define magnetic field.");
0089   fMagFieldCmd->SetGuidance("Magnetic field will be in Z direction.");
0090   fMagFieldCmd->SetParameterName("Bz", false);
0091   fMagFieldCmd->SetUnitCategory("Magnetic flux density");
0092   fMagFieldCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0093 
0094   fTalNbCmd = new G4UIcmdWithAnInteger("/testem/det/tallyNumber", this);
0095   fTalNbCmd->SetGuidance("Set number of fTallies.");
0096   fTalNbCmd->SetParameterName("tallyNb", false);
0097   fTalNbCmd->SetRange("tallyNb>=0");
0098   fTalNbCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0099 
0100   fTalDefCmd = new G4UIcommand("/testem/det/tallyDefinition", this);
0101   fTalDefCmd->SetGuidance("Set tally nb, box dimensions.");
0102   fTalDefCmd->SetGuidance("  tally number : from 0 to tallyNumber");
0103   fTalDefCmd->SetGuidance("  material name");
0104   fTalDefCmd->SetGuidance("  dimensions (3-vector with unit)");
0105   //
0106   G4UIparameter* fTalNbPrm = new G4UIparameter("tallyNb", 'i', false);
0107   fTalNbPrm->SetGuidance("tally number : from 0 to tallyNumber");
0108   fTalNbPrm->SetParameterRange("tallyNb>=0");
0109   fTalDefCmd->SetParameter(fTalNbPrm);
0110   //
0111   G4UIparameter* SizeXPrm = new G4UIparameter("sizeX", 'd', false);
0112   SizeXPrm->SetGuidance("sizeX");
0113   SizeXPrm->SetParameterRange("sizeX>0.");
0114   fTalDefCmd->SetParameter(SizeXPrm);
0115   //
0116   G4UIparameter* SizeYPrm = new G4UIparameter("sizeY", 'd', false);
0117   SizeYPrm->SetGuidance("sizeY");
0118   SizeYPrm->SetParameterRange("sizeY>0.");
0119   fTalDefCmd->SetParameter(SizeYPrm);
0120   //
0121   G4UIparameter* SizeZPrm = new G4UIparameter("sizeZ", 'd', false);
0122   SizeZPrm->SetGuidance("sizeZ");
0123   SizeZPrm->SetParameterRange("sizeZ>0.");
0124   fTalDefCmd->SetParameter(SizeZPrm);
0125   //
0126   G4UIparameter* unitPrm = new G4UIparameter("unit", 's', false);
0127   unitPrm->SetGuidance("unit of dimensions");
0128   G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("mm"));
0129   unitPrm->SetParameterCandidates(unitList);
0130   fTalDefCmd->SetParameter(unitPrm);
0131   //
0132   fTalDefCmd->AvailableForStates(G4State_PreInit);
0133 
0134   fTalPosiCmd = new G4UIcommand("/testem/det/tallyPosition", this);
0135   fTalPosiCmd->SetGuidance("Set tally nb, position");
0136   fTalPosiCmd->SetGuidance("  tally number : from 0 to tallyNumber");
0137   fTalPosiCmd->SetGuidance("  position (3-vector with unit)");
0138   //
0139   G4UIparameter* fTalNumPrm = new G4UIparameter("tallyNum", 'i', false);
0140   fTalNumPrm->SetGuidance("tally number : from 0 to tallyNumber");
0141   fTalNumPrm->SetParameterRange("tallyNum>=0");
0142   fTalPosiCmd->SetParameter(fTalNumPrm);
0143   //
0144   G4UIparameter* PosiXPrm = new G4UIparameter("posiX", 'd', false);
0145   PosiXPrm->SetGuidance("position X");
0146   fTalPosiCmd->SetParameter(PosiXPrm);
0147   //
0148   G4UIparameter* PosiYPrm = new G4UIparameter("posiY", 'd', false);
0149   PosiYPrm->SetGuidance("position Y");
0150   fTalPosiCmd->SetParameter(PosiYPrm);
0151   //
0152   G4UIparameter* PosiZPrm = new G4UIparameter("posiZ", 'd', false);
0153   PosiZPrm->SetGuidance("position Z");
0154   fTalPosiCmd->SetParameter(PosiZPrm);
0155   //
0156   G4UIparameter* unitPr = new G4UIparameter("unit", 's', false);
0157   unitPr->SetGuidance("unit of position");
0158   unitPr->SetParameterCandidates(unitList);
0159   fTalPosiCmd->SetParameter(unitPr);
0160   //
0161   fTalPosiCmd->AvailableForStates(G4State_PreInit);
0162 }
0163 
0164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0165 
0166 DetectorMessenger::~DetectorMessenger()
0167 {
0168   delete fMaterCmd;
0169   delete fWMaterCmd;
0170   delete fSizeXCmd;
0171   delete fSizeYZCmd;
0172   delete fMagFieldCmd;
0173   delete fTalNbCmd;
0174   delete fTalDefCmd;
0175   delete fTalPosiCmd;
0176   delete fDetDir;
0177   delete fTestemDir;
0178 }
0179 
0180 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0181 
0182 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0183 {
0184   if (command == fMaterCmd) {
0185     fDetector->SetMaterial(newValue);
0186   }
0187 
0188   if (command == fWMaterCmd) {
0189     fDetector->SetWorldMaterial(newValue);
0190   }
0191 
0192   if (command == fSizeXCmd) {
0193     fDetector->SetSizeX(fSizeXCmd->GetNewDoubleValue(newValue));
0194   }
0195 
0196   if (command == fSizeYZCmd) {
0197     fDetector->SetSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));
0198   }
0199 
0200   if (command == fMagFieldCmd) {
0201     fDetector->SetMagField(fMagFieldCmd->GetNewDoubleValue(newValue));
0202   }
0203 
0204   if (command == fTalNbCmd) {
0205     fDetector->SetTallyNumber(fTalNbCmd->GetNewIntValue(newValue));
0206   }
0207 
0208   if (command == fTalDefCmd) {
0209     G4int num;
0210     G4double v1, v2, v3;
0211     G4String unt;
0212     std::istringstream is(newValue);
0213     is >> num >> v1 >> v2 >> v3 >> unt;
0214     G4ThreeVector vec(v1, v2, v3);
0215     vec *= G4UIcommand::ValueOf(unt);
0216     fDetector->SetTallySize(num, vec);
0217   }
0218 
0219   if (command == fTalPosiCmd) {
0220     G4int num;
0221     G4double v1, v2, v3;
0222     G4String unt;
0223     std::istringstream is(newValue);
0224     is >> num >> v1 >> v2 >> v3 >> unt;
0225     G4ThreeVector vec(v1, v2, v3);
0226     vec *= G4UIcommand::ValueOf(unt);
0227     fDetector->SetTallyPosition(num, vec);
0228   }
0229 }
0230 
0231 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......