Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:03

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