Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-31 07:50:43

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 "G4OpticalSurface.hh"
0034 #include "G4UIcmdWithADouble.hh"
0035 #include "G4UIcmdWithADoubleAndUnit.hh"
0036 #include "G4UIcmdWithAString.hh"
0037 #include "G4UIcmdWithAnInteger.hh"
0038 #include "G4UIcmdWithoutParameter.hh"
0039 #include "G4UIcommand.hh"
0040 #include "G4UIdirectory.hh"
0041 #include "G4UIparameter.hh"
0042 
0043 #include <iostream>
0044 #include <sstream>
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 DetectorMessenger::DetectorMessenger(DetectorConstruction* Det) : G4UImessenger(), fDetector(Det)
0049 {
0050   fOpticalDir = new G4UIdirectory("/opnovice2/");
0051   fOpticalDir->SetGuidance("Parameters for optical simulation.");
0052 
0053   fSurfaceTypeCmd = new G4UIcmdWithAString("/opnovice2/surfaceType", this);
0054   fSurfaceTypeCmd->SetGuidance("Surface type.");
0055   fSurfaceTypeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0056   fSurfaceTypeCmd->SetToBeBroadcasted(false);
0057 
0058   fSurfaceFinishCmd = new G4UIcmdWithAString("/opnovice2/surfaceFinish", this);
0059   fSurfaceFinishCmd->SetGuidance("Surface finish.");
0060   fSurfaceFinishCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0061   fSurfaceFinishCmd->SetToBeBroadcasted(false);
0062 
0063   fSurfaceModelCmd = new G4UIcmdWithAString("/opnovice2/surfaceModel", this);
0064   fSurfaceModelCmd->SetGuidance("surface model.");
0065   fSurfaceModelCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0066   fSurfaceModelCmd->SetToBeBroadcasted(false);
0067 
0068   fSurfaceSigmaAlphaCmd = new G4UIcmdWithADouble("/opnovice2/surfaceSigmaAlpha", this);
0069   fSurfaceSigmaAlphaCmd->SetGuidance("surface sigma alpha");
0070   fSurfaceSigmaAlphaCmd->SetGuidance(" parameter.");
0071   fSurfaceSigmaAlphaCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0072   fSurfaceSigmaAlphaCmd->SetToBeBroadcasted(false);
0073 
0074   fSurfacePolishCmd = new G4UIcmdWithADouble("/opnovice2/surfacePolish", this);
0075   fSurfacePolishCmd->SetGuidance("surface polish");
0076   fSurfacePolishCmd->SetGuidance(" parameter (for Glisur model).");
0077   fSurfacePolishCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0078   fSurfacePolishCmd->SetToBeBroadcasted(false);
0079 
0080   fSurfaceMatPropVectorCmd = new G4UIcmdWithAString("/opnovice2/surfaceProperty", this);
0081   fSurfaceMatPropVectorCmd->SetGuidance("Set material property vector");
0082   fSurfaceMatPropVectorCmd->SetGuidance(" for the surface.");
0083   fSurfaceMatPropVectorCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0084   fSurfaceMatPropVectorCmd->SetToBeBroadcasted(false);
0085 
0086   fSurfaceMatPropConstCmd = new G4UIcmdWithAString("/opnovice2/surfaceConstProperty", this);
0087   fSurfaceMatPropConstCmd->SetGuidance("Set material constant property");
0088   fSurfaceMatPropConstCmd->SetGuidance(" for the surface.");
0089   fSurfaceMatPropConstCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0090   fSurfaceMatPropConstCmd->SetToBeBroadcasted(false);
0091 
0092   fTankMatPropVectorCmd = new G4UIcmdWithAString("/opnovice2/boxProperty", this);
0093   fTankMatPropVectorCmd->SetGuidance("Set material property vector for ");
0094   fTankMatPropVectorCmd->SetGuidance("the box.");
0095   fTankMatPropVectorCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0096   fTankMatPropVectorCmd->SetToBeBroadcasted(false);
0097 
0098   fTankMatPropConstCmd = new G4UIcmdWithAString("/opnovice2/boxConstProperty", this);
0099   fTankMatPropConstCmd->SetGuidance("Set material constant property ");
0100   fTankMatPropConstCmd->SetGuidance("for the box.");
0101   fTankMatPropConstCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0102   fTankMatPropConstCmd->SetToBeBroadcasted(false);
0103 
0104   fTankMaterialCmd = new G4UIcmdWithAString("/opnovice2/boxMaterial", this);
0105   fTankMaterialCmd->SetGuidance("Set material of box.");
0106   fTankMaterialCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0107   fTankMaterialCmd->SetToBeBroadcasted(false);
0108 
0109   fWorldMatPropVectorCmd = new G4UIcmdWithAString("/opnovice2/worldProperty", this);
0110   fWorldMatPropVectorCmd->SetGuidance("Set material property vector ");
0111   fWorldMatPropVectorCmd->SetGuidance("for the world.");
0112   fWorldMatPropVectorCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0113   fWorldMatPropVectorCmd->SetToBeBroadcasted(false);
0114 
0115   fWorldMatPropConstCmd = new G4UIcmdWithAString("/opnovice2/worldConstProperty", this);
0116   fWorldMatPropConstCmd->SetGuidance("Set material constant property");
0117   fWorldMatPropConstCmd->SetGuidance(" for the world.");
0118   fWorldMatPropConstCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0119   fWorldMatPropConstCmd->SetToBeBroadcasted(false);
0120 
0121   fWorldMaterialCmd = new G4UIcmdWithAString("/opnovice2/worldMaterial", this);
0122   fWorldMaterialCmd->SetGuidance("Set material of world.");
0123   fWorldMaterialCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0124   fWorldMaterialCmd->SetToBeBroadcasted(false);
0125 }
0126 
0127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0128 
0129 DetectorMessenger::~DetectorMessenger()
0130 {
0131   delete fOpticalDir;
0132   delete fSurfaceFinishCmd;
0133   delete fSurfaceTypeCmd;
0134   delete fSurfaceModelCmd;
0135   delete fSurfaceSigmaAlphaCmd;
0136   delete fSurfacePolishCmd;
0137   delete fSurfaceMatPropVectorCmd;
0138   delete fSurfaceMatPropConstCmd;
0139   delete fTankMatPropVectorCmd;
0140   delete fTankMatPropConstCmd;
0141   delete fTankMaterialCmd;
0142   delete fWorldMatPropVectorCmd;
0143   delete fWorldMatPropConstCmd;
0144   delete fWorldMaterialCmd;
0145 }
0146 
0147 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0148 
0149 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0150 {
0151   //    FINISH
0152   if (command == fSurfaceFinishCmd) {
0153     if (newValue == "polished") {
0154       fDetector->SetSurfaceFinish(polished);
0155     }
0156     else if (newValue == "polishedfrontpainted") {
0157       fDetector->SetSurfaceFinish(polishedfrontpainted);
0158     }
0159     else if (newValue == "polishedbackpainted") {
0160       fDetector->SetSurfaceFinish(polishedbackpainted);
0161     }
0162     else if (newValue == "ground") {
0163       fDetector->SetSurfaceFinish(ground);
0164     }
0165     else if (newValue == "groundfrontpainted") {
0166       fDetector->SetSurfaceFinish(groundfrontpainted);
0167     }
0168     else if (newValue == "groundbackpainted") {
0169       fDetector->SetSurfaceFinish(groundbackpainted);
0170     }
0171     else if (newValue == "polishedlumirrorair") {
0172       fDetector->SetSurfaceFinish(polishedlumirrorair);
0173     }
0174     else if (newValue == "polishedlumirrorglue") {
0175       fDetector->SetSurfaceFinish(polishedlumirrorglue);
0176     }
0177     else if (newValue == "polishedair") {
0178       fDetector->SetSurfaceFinish(polishedair);
0179     }
0180     else if (newValue == "polishedteflonair") {
0181       fDetector->SetSurfaceFinish(polishedteflonair);
0182     }
0183     else if (newValue == "polishedtioair") {
0184       fDetector->SetSurfaceFinish(polishedtioair);
0185     }
0186     else if (newValue == "polishedtyvekair") {
0187       fDetector->SetSurfaceFinish(polishedtyvekair);
0188     }
0189     else if (newValue == "polishedvm2000air") {
0190       fDetector->SetSurfaceFinish(polishedvm2000air);
0191     }
0192     else if (newValue == "polishedvm2000glue") {
0193       fDetector->SetSurfaceFinish(polishedvm2000glue);
0194     }
0195     else if (newValue == "etchedlumirrorair") {
0196       fDetector->SetSurfaceFinish(etchedlumirrorair);
0197     }
0198     else if (newValue == "etchedlumirrorglue") {
0199       fDetector->SetSurfaceFinish(etchedlumirrorglue);
0200     }
0201     else if (newValue == "etchedair") {
0202       fDetector->SetSurfaceFinish(etchedair);
0203     }
0204     else if (newValue == "etchedteflonair") {
0205       fDetector->SetSurfaceFinish(etchedteflonair);
0206     }
0207     else if (newValue == "etchedtioair") {
0208       fDetector->SetSurfaceFinish(etchedtioair);
0209     }
0210     else if (newValue == "etchedtyvekair") {
0211       fDetector->SetSurfaceFinish(etchedtyvekair);
0212     }
0213     else if (newValue == "etchedvm2000air") {
0214       fDetector->SetSurfaceFinish(etchedvm2000air);
0215     }
0216     else if (newValue == "etchedvm2000glue") {
0217       fDetector->SetSurfaceFinish(etchedvm2000glue);
0218     }
0219     else if (newValue == "groundlumirrorair") {
0220       fDetector->SetSurfaceFinish(groundlumirrorair);
0221     }
0222     else if (newValue == "groundlumirrorglue") {
0223       fDetector->SetSurfaceFinish(groundlumirrorglue);
0224     }
0225     else if (newValue == "groundair") {
0226       fDetector->SetSurfaceFinish(groundair);
0227     }
0228     else if (newValue == "groundteflonair") {
0229       fDetector->SetSurfaceFinish(groundteflonair);
0230     }
0231     else if (newValue == "groundtioair") {
0232       fDetector->SetSurfaceFinish(groundtioair);
0233     }
0234     else if (newValue == "groundtyvekair") {
0235       fDetector->SetSurfaceFinish(groundtyvekair);
0236     }
0237     else if (newValue == "groundvm2000air") {
0238       fDetector->SetSurfaceFinish(groundvm2000air);
0239     }
0240     else if (newValue == "groundvm2000glue") {
0241       fDetector->SetSurfaceFinish(groundvm2000glue);
0242     }
0243     //         for Davis model
0244     else if (newValue == "Rough_LUT") {
0245       fDetector->SetSurfaceFinish(Rough_LUT);
0246     }
0247     else if (newValue == "RoughTeflon_LUT") {
0248       fDetector->SetSurfaceFinish(RoughTeflon_LUT);
0249     }
0250     else if (newValue == "RoughESR_LUT") {
0251       fDetector->SetSurfaceFinish(RoughESR_LUT);
0252     }
0253     else if (newValue == "RoughESRGrease_LUT") {
0254       fDetector->SetSurfaceFinish(RoughESRGrease_LUT);
0255     }
0256     else if (newValue == "Polished_LUT") {
0257       fDetector->SetSurfaceFinish(Polished_LUT);
0258     }
0259     else if (newValue == "PolishedTeflon_LUT") {
0260       fDetector->SetSurfaceFinish(PolishedTeflon_LUT);
0261     }
0262     else if (newValue == "PolishedESR_LUT") {
0263       fDetector->SetSurfaceFinish(PolishedESR_LUT);
0264     }
0265     else if (newValue == "PolishedESRGrease_LUT") {
0266       fDetector->SetSurfaceFinish(PolishedESRGrease_LUT);
0267     }
0268     else if (newValue == "Detector_LUT") {
0269       fDetector->SetSurfaceFinish(Detector_LUT);
0270     }
0271     else {
0272       G4ExceptionDescription ed;
0273       ed << "Invalid surface finish: " << newValue;
0274       G4Exception("DetectorMessenger", "OpNovice2_003", FatalException, ed);
0275     }
0276   }
0277 
0278   //  MODEL
0279   else if (command == fSurfaceModelCmd) {
0280     if (newValue == "glisur") {
0281       fDetector->SetSurfaceModel(glisur);
0282     }
0283     else if (newValue == "unified") {
0284       fDetector->SetSurfaceModel(unified);
0285     }
0286     else if (newValue == "LUT") {
0287       fDetector->SetSurfaceModel(LUT);
0288     }
0289     else if (newValue == "DAVIS") {
0290       fDetector->SetSurfaceModel(DAVIS);
0291     }
0292     else if (newValue == "dichroic") {
0293       fDetector->SetSurfaceModel(dichroic);
0294     }
0295     else {
0296       G4ExceptionDescription ed;
0297       ed << "Invalid surface model: " << newValue;
0298       G4Exception("DetectorMessenger", "ONovice2_001", FatalException, ed);
0299     }
0300   }
0301 
0302   // TYPE
0303   else if (command == fSurfaceTypeCmd) {
0304     if (newValue == "dielectric_metal") {
0305       fDetector->SetSurfaceType(dielectric_metal);
0306     }
0307     else if (newValue == "dielectric_dielectric") {
0308       fDetector->SetSurfaceType(dielectric_dielectric);
0309     }
0310     else if (newValue == "dielectric_LUT") {
0311       fDetector->SetSurfaceType(dielectric_LUT);
0312     }
0313     else if (newValue == "dielectric_LUTDAVIS") {
0314       fDetector->SetSurfaceType(dielectric_LUTDAVIS);
0315     }
0316     else if (newValue == "coated") {
0317       fDetector->SetSurfaceType(coated);
0318     }
0319     else {
0320       G4ExceptionDescription ed;
0321       ed << "Invalid surface type: " << newValue;
0322       G4Exception("DetectorMessenger", "OpNovice2_002", FatalException, ed);
0323     }
0324   }
0325   else if (command == fSurfaceSigmaAlphaCmd) {
0326     fDetector->SetSurfaceSigmaAlpha(G4UIcmdWithADouble::GetNewDoubleValue(newValue));
0327   }
0328   else if (command == fSurfacePolishCmd) {
0329     fDetector->SetSurfacePolish(G4UIcmdWithADouble::GetNewDoubleValue(newValue));
0330   }
0331   else if (command == fTankMatPropVectorCmd) {
0332     // got a string. need to convert it to physics vector.
0333     // string format is property name, then pairs of energy, value
0334     // specify units for each value, eg 3.0*eV
0335     // space delimited
0336     auto mpv = new G4MaterialPropertyVector();
0337     std::istringstream instring(newValue);
0338     G4String prop;
0339     instring >> prop;
0340     while (instring) {
0341       G4String tmp;
0342       instring >> tmp;
0343       if (tmp == "") {
0344         break;
0345       }
0346       G4double en = G4UIcommand::ConvertToDouble(tmp);
0347       instring >> tmp;
0348       G4double val = G4UIcommand::ConvertToDouble(tmp);
0349       mpv->InsertValues(en, val);
0350     }
0351 
0352     fDetector->AddTankMPV(prop, mpv);
0353   }
0354   else if (command == fWorldMatPropVectorCmd) {
0355     // Convert string to physics vector
0356     // string format is property name, then pairs of energy, value
0357     auto mpv = new G4MaterialPropertyVector();
0358     std::istringstream instring(newValue);
0359     G4String prop;
0360     instring >> prop;
0361     while (instring) {
0362       G4String tmp;
0363       instring >> tmp;
0364       if (tmp == "") {
0365         break;
0366       }
0367       G4double en = G4UIcommand::ConvertToDouble(tmp);
0368       instring >> tmp;
0369       G4double val = G4UIcommand::ConvertToDouble(tmp);
0370       mpv->InsertValues(en, val);
0371     }
0372     fDetector->AddWorldMPV(prop, mpv);
0373   }
0374   else if (command == fSurfaceMatPropVectorCmd) {
0375     // Convert string to physics vector
0376     // string format is property name, then pairs of energy, value
0377     // space delimited
0378     auto mpv = new G4MaterialPropertyVector();
0379     G4cout << newValue << G4endl;
0380     std::istringstream instring(newValue);
0381     G4String prop;
0382     instring >> prop;
0383     while (instring) {
0384       G4String tmp;
0385       instring >> tmp;
0386       if (tmp == "") {
0387         break;
0388       }
0389       G4double en = G4UIcommand::ConvertToDouble(tmp);
0390       instring >> tmp;
0391       G4double val = G4UIcommand::ConvertToDouble(tmp);
0392       mpv->InsertValues(en, val);
0393     }
0394     fDetector->AddSurfaceMPV(prop, mpv);
0395   }
0396 
0397   else if (command == fTankMatPropConstCmd) {
0398     // Convert string to physics vector
0399     // string format is property name, then value
0400     // space delimited
0401     std::istringstream instring(newValue);
0402     G4String prop;
0403     G4String tmp;
0404     instring >> prop;
0405     instring >> tmp;
0406     G4double val = G4UIcommand::ConvertToDouble(tmp);
0407     fDetector->AddTankMPC(prop, val);
0408   }
0409   else if (command == fWorldMatPropConstCmd) {
0410     // Convert string to physics vector
0411     // string format is property name, then value
0412     // space delimited
0413     std::istringstream instring(newValue);
0414     G4String prop;
0415     G4String tmp;
0416     instring >> prop;
0417     instring >> tmp;
0418     G4double val = G4UIcommand::ConvertToDouble(tmp);
0419     fDetector->AddWorldMPC(prop, val);
0420   }
0421   else if (command == fSurfaceMatPropConstCmd) {
0422     // Convert string to physics vector
0423     // string format is property name, then value
0424     // space delimited
0425     std::istringstream instring(newValue);
0426     G4String prop;
0427     G4String tmp;
0428     instring >> prop;
0429     instring >> tmp;
0430     G4double val = G4UIcommand::ConvertToDouble(tmp);
0431     fDetector->AddSurfaceMPC(prop, val);
0432   }
0433   else if (command == fWorldMaterialCmd) {
0434     fDetector->SetWorldMaterial(newValue);
0435   }
0436   else if (command == fTankMaterialCmd) {
0437     fDetector->SetTankMaterial(newValue);
0438   }
0439 }
0440 
0441 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......