Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 08:28:52

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("/testem/");
0047   fTestemDir->SetGuidance(" detector control.");
0048 
0049   fDetDir = new G4UIdirectory("/testem/det/");
0050   fDetDir->SetGuidance("detector construction commands");
0051 
0052   fNbAbsorCmd = new G4UIcmdWithAnInteger("/testem/det/setNbOfAbsor", this);
0053   fNbAbsorCmd->SetGuidance("Set number of Absorbers.");
0054   fNbAbsorCmd->SetParameterName("NbAbsor", false);
0055   fNbAbsorCmd->SetRange("NbAbsor>0");
0056   fNbAbsorCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0057   fNbAbsorCmd->SetToBeBroadcasted(false);
0058 
0059   fAbsorCmd = new G4UIcommand("/testem/det/setAbsor", this);
0060   fAbsorCmd->SetGuidance("Set the absor nb, the material, the thickness.");
0061   fAbsorCmd->SetGuidance("  absor number : from 1 to NbOfAbsor");
0062   fAbsorCmd->SetGuidance("  material name");
0063   fAbsorCmd->SetGuidance("  thickness (with unit) : t>0.");
0064   //
0065   G4UIparameter* AbsNbPrm = new G4UIparameter("AbsorNb", 'i', false);
0066   AbsNbPrm->SetGuidance("absor number : from 1 to NbOfAbsor");
0067   AbsNbPrm->SetParameterRange("AbsorNb>0");
0068   fAbsorCmd->SetParameter(AbsNbPrm);
0069   //
0070   G4UIparameter* MatPrm = new G4UIparameter("material", 's', false);
0071   MatPrm->SetGuidance("material name");
0072   fAbsorCmd->SetParameter(MatPrm);
0073   //
0074   G4UIparameter* ThickPrm = new G4UIparameter("thickness", 'd', false);
0075   ThickPrm->SetGuidance("thickness of absorber");
0076   ThickPrm->SetParameterRange("thickness>0.");
0077   fAbsorCmd->SetParameter(ThickPrm);
0078   //
0079   G4UIparameter* unitPrm = new G4UIparameter("unit", 's', false);
0080   unitPrm->SetGuidance("unit of thickness");
0081   G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("mm"));
0082   unitPrm->SetParameterCandidates(unitList);
0083   fAbsorCmd->SetParameter(unitPrm);
0084   //
0085   fAbsorCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0086   fAbsorCmd->SetToBeBroadcasted(false);
0087 
0088   fNdivCmd = new G4UIcommand("/testem/det/nDivAbsor", this);
0089   fNdivCmd->SetGuidance("Divide the absor nb : number of divisions");
0090   fNdivCmd->SetGuidance("  absor number : from 1 to NbOfAbsor");
0091   fNdivCmd->SetGuidance("  number of divisions >= 0");
0092   //
0093   G4UIparameter* AbsNbPar = new G4UIparameter("AbsorNb", 'i', false);
0094   AbsNbPar->SetGuidance("absor number : from 1 to NbOfAbsor");
0095   AbsNbPar->SetParameterRange("AbsorNb>0");
0096   fNdivCmd->SetParameter(AbsNbPar);
0097   //
0098   G4UIparameter* NdivPrm = new G4UIparameter("NdivNb", 'i', false);
0099   NdivPrm->SetGuidance("nb of divisions > 0");
0100   NdivPrm->SetParameterRange("NdivNb>0");
0101   fNdivCmd->SetParameter(NdivPrm);
0102   //
0103   fNdivCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0104   fNdivCmd->SetToBeBroadcasted(false);
0105 
0106   fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeYZ", this);
0107   fSizeYZCmd->SetGuidance("Set sizeYZ of the absorber");
0108   fSizeYZCmd->SetParameterName("SizeYZ", false);
0109   fSizeYZCmd->SetRange("SizeYZ>0.");
0110   fSizeYZCmd->SetUnitCategory("Length");
0111   fSizeYZCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0112   fSizeYZCmd->SetToBeBroadcasted(false);
0113 }
0114 
0115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0116 
0117 DetectorMessenger::~DetectorMessenger()
0118 {
0119   delete fNbAbsorCmd;
0120   delete fAbsorCmd;
0121   delete fNdivCmd;
0122   delete fSizeYZCmd;
0123   delete fDetDir;
0124   delete fTestemDir;
0125 }
0126 
0127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0128 
0129 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0130 {
0131   if (command == fNbAbsorCmd) {
0132     fDetector->SetNbOfAbsor(fNbAbsorCmd->GetNewIntValue(newValue));
0133   }
0134 
0135   if (command == fAbsorCmd) {
0136     G4int num;
0137     G4double tick;
0138     G4String unt, mat;
0139     std::istringstream is(newValue);
0140     is >> num >> mat >> tick >> unt;
0141     G4String material = mat;
0142     tick *= G4UIcommand::ValueOf(unt);
0143     fDetector->SetAbsorMaterial(num, material);
0144     fDetector->SetAbsorThickness(num, tick);
0145   }
0146 
0147   if (command == fNdivCmd) {
0148     G4int num, ndiv;
0149     std::istringstream is(newValue);
0150     is >> num >> ndiv;
0151     fDetector->SetNbOfDivisions(num, ndiv);
0152   }
0153 
0154   if (command == fSizeYZCmd) {
0155     fDetector->SetAbsorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));
0156   }
0157 }
0158 
0159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......