Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-25 09:22:34

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 //  Gorad (Geant4 Open-source Radiation Analysis and Design)
0027 //
0028 //  Author : Makoto Asai (SLAC National Accelerator Laboratory)
0029 //
0030 //  Development of Gorad is funded by NASA Johnson Space Center (JSC)
0031 //  under the contract NNJ15HK11B.
0032 //
0033 // ********************************************************************
0034 //
0035 // GRDetectorConstructionMessenger.cc
0036 //   A messenger class that handles geometry configuration.
0037 //
0038 // History
0039 //   September 8th, 2020 : first implementation
0040 //
0041 // ********************************************************************
0042 
0043 #include "GRDetectorConstructionMessenger.hh"
0044 
0045 #include "GRDetectorConstruction.hh"
0046 #include "G4UIcommand.hh"
0047 #include "G4UIparameter.hh"
0048 #include "G4UIdirectory.hh"
0049 #include "G4UIcmdWithAString.hh"
0050 #include "G4UIcmdWithAnInteger.hh"
0051 #include "G4UIcmdWithoutParameter.hh"
0052 
0053 GRDetectorConstructionMessenger::GRDetectorConstructionMessenger(GRDetectorConstruction* dc)
0054 : pDC(dc)
0055 {
0056   G4UIparameter* para = nullptr;
0057 
0058   geomDir = new G4UIdirectory("/gorad/geometry/");
0059   geomDir->SetGuidance("GORAD geometry selection");
0060 
0061   selectCmd = new G4UIcmdWithAString("/gorad/geometry/selectGDML",this);
0062   selectCmd->SetGuidance("Select GDML file");
0063   selectCmd->SetParameterName("gdml",false);
0064   selectCmd->AvailableForStates(G4State_PreInit);
0065   selectCmd->SetToBeBroadcasted(false);
0066 
0067   listSolidCmd = new G4UIcmdWithAnInteger("/gorad/geometry/listSolids",this);
0068   listSolidCmd->SetGuidance("List all the registered solids");
0069   listSolidCmd->SetParameterName("level",true);
0070   listSolidCmd->SetDefaultValue(0);
0071   listSolidCmd->SetRange("level>=0 && level<=2");
0072   listSolidCmd->AvailableForStates(G4State_Idle);
0073   listSolidCmd->SetToBeBroadcasted(false);
0074 
0075   listLogVolCmd = new G4UIcmdWithAnInteger("/gorad/geometry/listLogicalVolumes",this);
0076   listLogVolCmd->SetGuidance("List all the registered logical volumes");
0077   listLogVolCmd->SetParameterName("level",true);
0078   listLogVolCmd->SetDefaultValue(0);
0079   listLogVolCmd->SetRange("level>=0 && level<=2");
0080   listLogVolCmd->AvailableForStates(G4State_Idle);
0081   listLogVolCmd->SetToBeBroadcasted(false);
0082 
0083   listPhysVolCmd = new G4UIcmdWithAnInteger("/gorad/geometry/listPhysicalVolumes",this);
0084   listPhysVolCmd->SetGuidance("List all the registered physical volumes");
0085   listPhysVolCmd->SetParameterName("level",true);
0086   listPhysVolCmd->SetDefaultValue(0);
0087   listPhysVolCmd->SetRange("level>=0 && level<=2");
0088   listPhysVolCmd->AvailableForStates(G4State_Idle);
0089   listPhysVolCmd->SetToBeBroadcasted(false);
0090 
0091   listRegionCmd = new G4UIcmdWithAnInteger("/gorad/geometry/listRegions",this);
0092   listRegionCmd->SetGuidance("List all the registered regions");
0093   listRegionCmd->SetParameterName("level",true);
0094   listRegionCmd->SetDefaultValue(0);
0095   listRegionCmd->SetRange("level>=0 && level<=2");
0096   listRegionCmd->AvailableForStates(G4State_Idle);
0097   listRegionCmd->SetToBeBroadcasted(false);
0098 
0099   createRegionCmd = new G4UIcommand("/gorad/geometry/createRegion",this);
0100   createRegionCmd->SetGuidance("Create a region and set the root logical volume to it.");
0101   createRegionCmd->SetGuidance("Region propagates to the daughter volumes. So, only the root logical volume (i.e. top of the hierarchy) should be defined.");
0102   createRegionCmd->SetGuidance("If two isolated root logical volumes should share the same region, the same region name can be used.");
0103   createRegionCmd->SetGuidance("Region must not be set to the world volume.");
0104   para = new G4UIparameter("regionName",'s',false);
0105   para->SetGuidance("Name of the region to be created");
0106   createRegionCmd->SetParameter(para);
0107   para = new G4UIparameter("logVolName",'s',false);
0108   para->SetGuidance("Name of the root logical volume");
0109   createRegionCmd->SetParameter(para);
0110   createRegionCmd->AvailableForStates(G4State_Idle);
0111   createRegionCmd->SetToBeBroadcasted(false);
0112 
0113   //// This command is fragile for large-scale geometry - temporally disabled
0114   ////checkOverlapCmd = new G4UIcommand("/gorad/geometry/checkOverlap",this);
0115   ////checkOverlapCmd->SetGuidance("Check volume overlap with existing volumes");
0116   ////checkOverlapCmd->SetGuidance(" i.e. with mother volume for protrusion and with other siblings for overlap.");
0117   ////checkOverlapCmd->SetGuidance(" - This command is valid only for placement and parameterized volumes. If this command is");
0118   ////checkOverlapCmd->SetGuidance("   used for other physical volume type, e.g. replica, command will be simply ignored.");
0119   ////checkOverlapCmd->SetGuidance("   If \"**ALL**\" is used as the volume name, all physical volumes are examined (SLOW!!).");
0120   ////checkOverlapCmd->SetGuidance(" - nSpots specifies number of spots on the surface of the volume to be examined.");
0121   ////checkOverlapCmd->SetGuidance("   The more spots used, the more chances to detect overlaps, but the more time it takes.");
0122   ////checkOverlapCmd->SetGuidance(" - maxErr specifies maximum number of errors to be generated (default 1) before quiting.");
0123   ////para = new G4UIparameter("physVol",'s',true);
0124   ////para->SetDefaultValue("**ALL**");
0125   ////checkOverlapCmd->SetParameter(para);
0126   ////para = new G4UIparameter("nSpots",'i',true);
0127   ////para->SetDefaultValue(1000);
0128   ////para->SetGuidance("Number of trial spots on the volume surface");
0129   ////checkOverlapCmd->SetParameter(para);
0130   ////para = new G4UIparameter("maxErr",'i',true);
0131   ////para->SetDefaultValue(1);
0132   ////para->SetParameterRange("maxErr > 0");
0133   ////para->SetGuidance("Maxinum number of report to be generated");
0134   ////checkOverlapCmd->SetParameter(para);
0135   ////para = new G4UIparameter("tolerance",'d',true);
0136   ////para->SetDefaultValue(0.);
0137   ////para->SetParameterRange("tolerance >= 0.");
0138   ////para->SetGuidance("Tolerance (default 0.)");
0139   ////checkOverlapCmd->SetParameter(para);
0140   ////para = new G4UIparameter("unit",'s',true);
0141   ////para->SetDefaultUnit("mm");
0142   ////checkOverlapCmd->SetParameter(para);
0143   ////checkOverlapCmd->AvailableForStates(G4State_Idle);
0144   ////checkOverlapCmd->SetToBeBroadcasted(false);
0145   
0146   materialDir = new G4UIdirectory("/gorad/material/");
0147   materialDir->SetGuidance("GORAD material commands");
0148 
0149   listMatCmd = new G4UIcmdWithAString("/gorad/material/list",this);
0150   listMatCmd->SetGuidance("List material property");
0151   listMatCmd->SetGuidance(" If material name is not specified, this command list all registered materials");
0152   listMatCmd->SetParameterName("matName",true);
0153   listMatCmd->SetDefaultValue("**ALL**");
0154   listMatCmd->AvailableForStates(G4State_Idle);
0155   listMatCmd->SetToBeBroadcasted(false);
0156 
0157   dumpMatCmd = new G4UIcmdWithoutParameter("/gorad/material/dumpNistMaterials",this);
0158   dumpMatCmd->SetGuidance("List all pre-defined material names in G4NistManager.");
0159   dumpMatCmd->SetGuidance(" Note : a material has to be instantiated with /gorad/material/create before setting it to a logical volume");
0160   dumpMatCmd->AvailableForStates(G4State_Idle);
0161   dumpMatCmd->SetToBeBroadcasted(false);
0162 
0163   createMatCmd = new G4UIcmdWithAString("/gorad/material/create",this);
0164   createMatCmd->SetGuidance("Instantiate a material defined in G4NistManager");
0165   createMatCmd->SetGuidance(" If the material has already existed, this command does nothing.");
0166   createMatCmd->SetParameterName("matName",false);
0167   createMatCmd->AvailableForStates(G4State_Idle);
0168   createMatCmd->SetToBeBroadcasted(false);
0169 
0170   getMatCmd = new G4UIcmdWithAString("/gorad/material/show",this); 
0171   getMatCmd->SetGuidance("Show the current material of the specified logical volume");
0172   getMatCmd->SetParameterName("logVol",false);
0173   getMatCmd->AvailableForStates(G4State_Idle);
0174   getMatCmd->SetToBeBroadcasted(false);
0175 
0176   setMatCmd = new G4UIcommand("/gorad/material/set",this);
0177   setMatCmd->SetGuidance("Set the material to the logical volume. The material has to be instantiated in advance.");
0178   setMatCmd->SetGuidance("  [usage] /gorad/material/set logicalVolumeName materialName");
0179   para = new G4UIparameter("logVol",'s',false);
0180   setMatCmd->SetParameter(para);
0181   para = new G4UIparameter("matName",'s',false);
0182   setMatCmd->SetParameter(para);
0183   setMatCmd->AvailableForStates(G4State_Idle);
0184   setMatCmd->SetToBeBroadcasted(false);
0185 }
0186 
0187 GRDetectorConstructionMessenger::~GRDetectorConstructionMessenger()
0188 {
0189   delete selectCmd;
0190   delete listSolidCmd;
0191   delete listLogVolCmd;
0192   delete listPhysVolCmd;
0193   delete listRegionCmd;
0194   delete createRegionCmd;
0195   ////delete checkOverlapCmd;
0196   delete geomDir;
0197 
0198   delete listMatCmd;
0199   delete dumpMatCmd;
0200   delete createMatCmd;
0201   delete getMatCmd;
0202   delete setMatCmd;
0203   delete materialDir;
0204 }
0205 
0206 #include "G4Tokenizer.hh"
0207 
0208 void GRDetectorConstructionMessenger::SetNewValue(G4UIcommand* cmd, G4String val)
0209 {
0210   if(cmd==selectCmd)
0211   {
0212     auto valid = pDC->SetGDMLFile(val);
0213     if(!valid)
0214     {
0215       G4ExceptionDescription ed;
0216       ed << "<" << val << "> is not a valid GDML file.";
0217       cmd->CommandFailed(ed);
0218     }
0219   }
0220   else if(cmd==listSolidCmd)
0221   { pDC->ListSolids(listSolidCmd->GetNewIntValue(val)); }
0222   else if(cmd==listLogVolCmd)
0223   { pDC->ListLogVols(listLogVolCmd->GetNewIntValue(val)); }
0224   else if(cmd==listPhysVolCmd)
0225   { pDC->ListPhysVols(listPhysVolCmd->GetNewIntValue(val)); }
0226   else if(cmd==listRegionCmd)
0227   { pDC->ListRegions(listRegionCmd->GetNewIntValue(val)); }
0228   else if(cmd==createRegionCmd)
0229   {
0230     G4Tokenizer next(val);
0231     G4String regionName = next();
0232     G4String logVolName = next();
0233     auto valid = pDC->CreateRegion(regionName,logVolName);
0234     if(!valid)
0235     {
0236       G4ExceptionDescription ed;
0237       ed << "Logical volume <" << logVolName << "> is not defined. Command ignored.";
0238       cmd->CommandFailed(ed);
0239     }
0240   }
0241   ////else if(cmd==checkOverlapCmd)
0242   ////{
0243     ////G4Tokenizer next(val);
0244     ////G4String physVolName = next();
0245     ////G4int nSpots = StoI(next());
0246     ////G4int maxErr = StoI(next());
0247     ////G4String tolStr = next();
0248     ////G4double tol = StoD(tolStr);
0249     ////if(tol>0.)
0250     ////{
0251       ////tolStr += " ";
0252       ////tolStr += next();
0253       ////tol = checkOverlapCmd->ConvertToDimensionedDouble(tolStr);
0254     ////}
0255     ////auto valid = pDC->CheckOverlap(physVolName,nSpots,maxErr,tol);
0256     ////if(!valid)
0257     ////{
0258       ////G4ExceptionDescription ed;
0259       ////ed << "Physical volume <" << physVolName << "> is not defined. Command ignored.";
0260       ////cmd->CommandFailed(ed);
0261     ////}
0262   ////}
0263 
0264   else if(cmd==listMatCmd)
0265   { 
0266     if(val=="**ALL**") 
0267     { pDC->ListAllMaterial(); }
0268     else
0269     {
0270       auto valid = pDC->ListMaterial(val);
0271       if(!valid)
0272       {
0273         G4ExceptionDescription ed;
0274         ed << "<" << val << "> is not defined. If necessary, create it with /gorad/material/create command.";
0275         cmd->CommandFailed(ed);
0276       }
0277     }
0278   }
0279   else if(cmd==dumpMatCmd)
0280   { pDC->DumpNistMaterials(); }
0281   else if(cmd==createMatCmd)
0282   { 
0283     auto valid = pDC->CreateMaterial(val); 
0284     if(!valid)
0285     {
0286       G4ExceptionDescription ed;
0287       ed << "The material name <" << val << "> is not defined in G4NistManager.";
0288       cmd->CommandFailed(ed);
0289     }
0290   }
0291   else if(cmd==getMatCmd)
0292   {
0293     auto valid = pDC->GetMaterial(val);
0294     if(!valid)
0295     {
0296       G4ExceptionDescription ed;
0297       ed << "<" << val << "> is not a name of registered logical volume.\n"
0298          << "Check existing logical volumes with /gorad/geometry/listLogicalVolumes command.";
0299       cmd->CommandFailed(ed);
0300     }
0301   }
0302   else if(cmd==setMatCmd)
0303   {
0304     G4Tokenizer next(val);
0305     G4String logVolName = next();
0306     G4String matName = next();
0307     auto valid = pDC->SetMaterial(logVolName,matName);
0308     if(valid!=0)
0309     {
0310       G4ExceptionDescription ed;
0311       if(valid==1 || valid==3)
0312       {
0313         ed << "<" << logVolName << "> is not a name of registered logical volume.\n"
0314            << "Check existing logical volumes with /gorad/geometry/listLogicalVolumes command.\n";
0315       }
0316       if(valid==2 || valid==3)
0317       {
0318         ed << "<" << matName << "> is not defined. If necessary, create it with /gorad/material/create command.";
0319       }
0320       cmd->CommandFailed(ed);
0321     }
0322   }
0323 
0324 }
0325 
0326 G4String GRDetectorConstructionMessenger::GetCurrentValue(G4UIcommand* cmd)
0327 {
0328   G4String val("");
0329   if(cmd==selectCmd)
0330   { val = pDC->GetGDMLFile(); }
0331   return val;
0332 }
0333 
0334