Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 08:27:41

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("UI commands specific to this example");
0048 
0049   fDetDir = new G4UIdirectory("/testem/det/");
0050   fDetDir->SetGuidance("detector construction commands");
0051 
0052   fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testem/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("/testem/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("/testem/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("/testem/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 
0104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0105 
0106 DetectorMessenger::~DetectorMessenger()
0107 {
0108   delete fSizeYZCmd;
0109   delete fNbLayersCmd;
0110   delete fNbAbsorCmd;
0111   delete fAbsorCmd;
0112   delete fDetDir;
0113   delete fTestemDir;
0114 }
0115 
0116 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0117 
0118 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0119 {
0120   if (command == fSizeYZCmd) {
0121     fDetector->SetCalorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));
0122   }
0123 
0124   if (command == fNbLayersCmd) {
0125     fDetector->SetNbOfLayers(fNbLayersCmd->GetNewIntValue(newValue));
0126   }
0127 
0128   if (command == fNbAbsorCmd) {
0129     fDetector->SetNbOfAbsor(fNbAbsorCmd->GetNewIntValue(newValue));
0130   }
0131 
0132   if (command == fAbsorCmd) {
0133     G4int num;
0134     G4double tick;
0135     G4String unt, mat;
0136     std::istringstream is(newValue);
0137     is >> num >> mat >> tick >> unt;
0138     G4String material = mat;
0139     tick *= G4UIcommand::ValueOf(unt);
0140     fDetector->SetAbsorMaterial(num, material);
0141     fDetector->SetAbsorThickness(num, tick);
0142   }
0143 }
0144 
0145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......