Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 08:31:16

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) : G4UImessenger(), fDetector(Det)
0045 {
0046   fDetDir.reset(new G4UIdirectory("/det/"));
0047   fDetDir->SetGuidance("detector construction commands");
0048 
0049   fSizeYZCmd.reset(new G4UIcmdWithADoubleAndUnit("/det/setSizeYZ", this));
0050   fSizeYZCmd->SetGuidance("Set tranverse size of the calorimeter");
0051   fSizeYZCmd->SetParameterName("Size", false);
0052   fSizeYZCmd->SetRange("Size>0.");
0053   fSizeYZCmd->SetUnitCategory("Length");
0054   fSizeYZCmd->AvailableForStates(G4State_PreInit);
0055   fSizeYZCmd->SetToBeBroadcasted(false);
0056 
0057   fNbLayersCmd.reset(new G4UIcmdWithAnInteger("/det/setNbOfLayers", this));
0058   fNbLayersCmd->SetGuidance("Set number of layers.");
0059   fNbLayersCmd->SetParameterName("NbLayers", false);
0060   fNbLayersCmd->SetRange("NbLayers>0");
0061   fNbLayersCmd->AvailableForStates(G4State_PreInit);
0062   fNbLayersCmd->SetToBeBroadcasted(false);
0063 
0064   fNbAbsorCmd.reset(new G4UIcmdWithAnInteger("/det/setNbOfAbsor", this));
0065   fNbAbsorCmd->SetGuidance("Set number of Absorbers.");
0066   fNbAbsorCmd->SetParameterName("NbAbsor", false);
0067   fNbAbsorCmd->SetRange("NbAbsor>0");
0068   fNbAbsorCmd->AvailableForStates(G4State_PreInit);
0069   fNbAbsorCmd->SetToBeBroadcasted(false);
0070 
0071   fAbsorCmd.reset(new G4UIcommand("/det/setAbsor", this));
0072   fAbsorCmd->SetGuidance("Set the absor nb, the material, the thickness.");
0073   fAbsorCmd->SetGuidance("  absor number : from 1 to NbOfAbsor");
0074   fAbsorCmd->SetGuidance("  material name");
0075   fAbsorCmd->SetGuidance("  thickness (with unit) : t>0.");
0076   //
0077   G4UIparameter* AbsNbPrm = new G4UIparameter("AbsorNb", 'i', false);
0078   AbsNbPrm->SetGuidance("absor number : from 1 to NbOfAbsor");
0079   AbsNbPrm->SetParameterRange("AbsorNb>0");
0080   fAbsorCmd->SetParameter(AbsNbPrm);
0081   //
0082   G4UIparameter* MatPrm = new G4UIparameter("material", 's', false);
0083   MatPrm->SetGuidance("material name");
0084   fAbsorCmd->SetParameter(MatPrm);
0085   //
0086   G4UIparameter* ThickPrm = new G4UIparameter("thickness", 'd', false);
0087   ThickPrm->SetGuidance("thickness of absorber");
0088   ThickPrm->SetParameterRange("thickness>0.");
0089   fAbsorCmd->SetParameter(ThickPrm);
0090   //
0091   G4UIparameter* unitPrm = new G4UIparameter("unit", 's', false);
0092   unitPrm->SetGuidance("unit of thickness");
0093   G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("mm"));
0094   unitPrm->SetParameterCandidates(unitList);
0095   fAbsorCmd->SetParameter(unitPrm);
0096   //
0097   fAbsorCmd->AvailableForStates(G4State_PreInit);
0098   fAbsorCmd->SetToBeBroadcasted(false);
0099 }
0100 
0101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0102 
0103 DetectorMessenger::~DetectorMessenger() = default;
0104 
0105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0106 
0107 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0108 {
0109   if (command == fSizeYZCmd.get()) {
0110     fDetector->SetCalorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));
0111   }
0112   else if (command == fNbLayersCmd.get()) {
0113     fDetector->SetNbOfLayers(fNbLayersCmd->GetNewIntValue(newValue));
0114   }
0115   else if (command == fNbAbsorCmd.get()) {
0116     fDetector->SetNbOfAbsor(fNbAbsorCmd->GetNewIntValue(newValue));
0117   }
0118   else if (command == fAbsorCmd.get()) {
0119     G4int num;
0120     G4double tick;
0121     G4String unt, mat;
0122     std::istringstream is(newValue);
0123     is >> num >> mat >> tick >> unt;
0124     G4String material = mat;
0125     tick *= G4UIcommand::ValueOf(unt);
0126     fDetector->SetAbsorMaterial(num, material);
0127     fDetector->SetAbsorThickness(num, tick);
0128   }
0129 }
0130 
0131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......