Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 07:50:10

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 "G4UIcmdWithAnInteger.hh"
0035 #include "G4UIcmdWithoutParameter.hh"
0036 #include "G4UIcommand.hh"
0037 #include "G4UIdirectory.hh"
0038 #include "G4UIparameter.hh"
0039 
0040 #include <sstream>
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 DetectorMessenger::DetectorMessenger(DetectorConstruction* Det) : fDetector(Det)
0045 {
0046   fTestemDir = new G4UIdirectory("/testhadr/");
0047   fTestemDir->SetGuidance("UI commands specific to this example");
0048 
0049   fDetDir = new G4UIdirectory("/testhadr/det/");
0050   fDetDir->SetGuidance("detector construction commands");
0051 
0052   fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setSizeYZ", this);
0053   fSizeYZCmd->SetGuidance("Set tranverse size of the calorimeter");
0054   fSizeYZCmd->SetParameterName("Size", false);
0055   fSizeYZCmd->SetRange("Size>0.");
0056   fSizeYZCmd->SetUnitCategory("Length");
0057   fSizeYZCmd->AvailableForStates(G4State_PreInit);
0058   fSizeYZCmd->SetToBeBroadcasted(false);
0059 
0060   fNbLayersCmd = new G4UIcmdWithAnInteger("/testhadr/det/setNbOfLayers", this);
0061   fNbLayersCmd->SetGuidance("Set number of layers.");
0062   fNbLayersCmd->SetParameterName("NbLayers", false);
0063   fNbLayersCmd->SetRange("NbLayers>0");
0064   fNbLayersCmd->AvailableForStates(G4State_PreInit);
0065   fNbLayersCmd->SetToBeBroadcasted(false);
0066 
0067   fNbAbsorCmd = new G4UIcmdWithAnInteger("/testhadr/det/setNbOfAbsor", this);
0068   fNbAbsorCmd->SetGuidance("Set number of Absorbers.");
0069   fNbAbsorCmd->SetParameterName("NbAbsor", false);
0070   fNbAbsorCmd->SetRange("NbAbsor>0");
0071   fNbAbsorCmd->AvailableForStates(G4State_PreInit);
0072   fNbAbsorCmd->SetToBeBroadcasted(false);
0073 
0074   fAbsorCmd = new G4UIcommand("/testhadr/det/setAbsor", this);
0075   fAbsorCmd->SetGuidance("Set the absor nb, the material, the thickness.");
0076   fAbsorCmd->SetGuidance("  absor number : from 1 to NbOfAbsor");
0077   fAbsorCmd->SetGuidance("  material name");
0078   fAbsorCmd->SetGuidance("  thickness (with unit) : t>0.");
0079   //
0080   G4UIparameter* AbsNbPrm = new G4UIparameter("AbsorNb", 'i', false);
0081   AbsNbPrm->SetGuidance("absor number : from 1 to NbOfAbsor");
0082   AbsNbPrm->SetParameterRange("AbsorNb>0");
0083   fAbsorCmd->SetParameter(AbsNbPrm);
0084   //
0085   G4UIparameter* MatPrm = new G4UIparameter("material", 's', false);
0086   MatPrm->SetGuidance("material name");
0087   fAbsorCmd->SetParameter(MatPrm);
0088   //
0089   G4UIparameter* ThickPrm = new G4UIparameter("thickness", 'd', false);
0090   ThickPrm->SetGuidance("thickness of absorber");
0091   ThickPrm->SetParameterRange("thickness>0.");
0092   fAbsorCmd->SetParameter(ThickPrm);
0093   //
0094   G4UIparameter* unitPrm = new G4UIparameter("unit", 's', false);
0095   unitPrm->SetGuidance("unit of thickness");
0096   G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("mm"));
0097   unitPrm->SetParameterCandidates(unitList);
0098   fAbsorCmd->SetParameter(unitPrm);
0099   //
0100   fAbsorCmd->AvailableForStates(G4State_PreInit);
0101   fAbsorCmd->SetToBeBroadcasted(false);
0102 
0103   fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat", this);
0104   fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
0105   fIsotopeCmd->SetGuidance("  symbol of isotope, Z, A, density of material");
0106   //
0107   G4UIparameter* symbPrm = new G4UIparameter("isotope", 's', false);
0108   symbPrm->SetGuidance("isotope symbol");
0109   fIsotopeCmd->SetParameter(symbPrm);
0110   //
0111   G4UIparameter* ZPrm = new G4UIparameter("Z", 'i', false);
0112   ZPrm->SetGuidance("Z");
0113   ZPrm->SetParameterRange("Z>0");
0114   fIsotopeCmd->SetParameter(ZPrm);
0115   //
0116   G4UIparameter* APrm = new G4UIparameter("A", 'i', false);
0117   APrm->SetGuidance("A");
0118   APrm->SetParameterRange("A>0");
0119   fIsotopeCmd->SetParameter(APrm);
0120   //
0121   G4UIparameter* densityPrm = new G4UIparameter("density", 'd', false);
0122   densityPrm->SetGuidance("density of material");
0123   densityPrm->SetParameterRange("density>0.");
0124   fIsotopeCmd->SetParameter(densityPrm);
0125   //
0126   G4UIparameter* unitPrm1 = new G4UIparameter("unit", 's', false);
0127   unitPrm1->SetGuidance("unit of density");
0128   G4String unitList1 = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("g/cm3"));
0129   unitPrm1->SetParameterCandidates(unitList1);
0130   fIsotopeCmd->SetParameter(unitPrm1);
0131   //
0132   fIsotopeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0133 }
0134 
0135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0136 
0137 DetectorMessenger::~DetectorMessenger()
0138 {
0139   delete fSizeYZCmd;
0140   delete fNbLayersCmd;
0141   delete fNbAbsorCmd;
0142   delete fAbsorCmd;
0143   delete fIsotopeCmd;
0144   delete fDetDir;
0145   delete fTestemDir;
0146 }
0147 
0148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0149 
0150 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0151 {
0152   if (command == fSizeYZCmd) {
0153     fDetector->SetCalorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));
0154   }
0155 
0156   if (command == fNbLayersCmd) {
0157     fDetector->SetNbOfLayers(fNbLayersCmd->GetNewIntValue(newValue));
0158   }
0159 
0160   if (command == fNbAbsorCmd) {
0161     fDetector->SetNbOfAbsor(fNbAbsorCmd->GetNewIntValue(newValue));
0162   }
0163 
0164   if (command == fAbsorCmd) {
0165     G4int num;
0166     G4double tick;
0167     G4String unt, mat;
0168     std::istringstream is(newValue);
0169     is >> num >> mat >> tick >> unt;
0170     G4String material = mat;
0171     tick *= G4UIcommand::ValueOf(unt);
0172     fDetector->SetAbsorMaterial(num, material);
0173     fDetector->SetAbsorThickness(num, tick);
0174   }
0175 
0176   if (command == fIsotopeCmd) {
0177     G4int Z;
0178     G4int A;
0179     G4double dens;
0180     G4String name, unt;
0181     std::istringstream is(newValue);
0182     is >> name >> Z >> A >> dens >> unt;
0183     dens *= G4UIcommand::ValueOf(unt);
0184     fDetector->MaterialWithSingleIsotope(name, name, dens, Z, A);
0185   }
0186 }
0187 
0188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......