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] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 // Authors: Susanna Guatelli and Francesco Romano
 27 // susanna@uow.edu.au, francesco.romano@ct.infn.it
 28 //
 29 // Created by Jacopo Magini: j.magini@surrey.ac.uk
 30 
 31 #include "DetectorMessenger.hh"
 32 #include "G4UIdirectory.hh"
 33 #include "G4UIcmdWithADoubleAndUnit.hh"
 34 #include "G4UIcmdWithAString.hh"
 35 #include "G4UIcmdWithABool.hh"
 36 #include "G4UIcmdWithoutParameter.hh"
 37 #include "G4SystemOfUnits.hh"
 38 #include "DetectorConstruction.hh"
 39 #include "G4RunManager.hh"
 40 
 41 DetectorMessenger::DetectorMessenger(AnalysisManager* analysis_manager)
 42   : geometryHasChanged(false)
 43 {
 44     changeTheGeometryDir = new G4UIdirectory("/geometrySetup/");
 45     changeTheGeometryDir -> SetGuidance("Geometry setup");
 46     
 47     changeTheDetectorCmd = new G4UIcmdWithAString("/geometrySetup/selectDetector",this);
 48     changeTheDetectorCmd -> SetGuidance("Select the type of detector you wish to use");
 49     changeTheDetectorCmd -> SetParameterName("Material",false);
 50     changeTheDetectorCmd -> AvailableForStates(G4State_PreInit);
 51 
 52   changeDetectorDimensionDir = new G4UIdirectory("/geometrySetup/detectorDimension/");
 53   changeDetectorDimensionDir -> SetGuidance("Modify the dimensions of the detector");
 54 
 55   changeDetectorSizeWidthCmd = new G4UIcmdWithADoubleAndUnit("/geometrySetup/detectorDimension/setWidth", this);
 56   changeDetectorSizeWidthCmd -> SetGuidance("Set the width of the detector");
 57   changeDetectorSizeWidthCmd -> SetParameterName("Width", false);
 58   changeDetectorSizeWidthCmd -> SetRange("Width >= 0.1 && Width <= 150.");
 59   changeDetectorSizeWidthCmd -> SetUnitCategory("Length");
 60   changeDetectorSizeWidthCmd -> SetDefaultUnit("um");
 61   changeDetectorSizeWidthCmd -> AvailableForStates(G4State_PreInit);
 62   
 63   changeDetectorSizeThicknessCmd = new G4UIcmdWithADoubleAndUnit("/geometrySetup/detectorDimension/setThickness", this);
 64   changeDetectorSizeThicknessCmd -> SetGuidance("Set the thickness of the detector");
 65   changeDetectorSizeThicknessCmd -> SetParameterName("Thickness", false);
 66   changeDetectorSizeThicknessCmd -> SetRange("Thickness >= 0.1 && Thickness <= 50.");
 67   changeDetectorSizeThicknessCmd -> SetUnitCategory("Length");
 68   changeDetectorSizeThicknessCmd -> SetDefaultUnit("um");
 69   changeDetectorSizeThicknessCmd -> AvailableForStates(G4State_PreInit);
 70   
 71   changeSecondStageDimensionDir = new G4UIdirectory("/geometrySetup/detectorDimension/secondStage/");
 72   changeSecondStageDimensionDir -> SetGuidance("Modify the dimensions of the E stage for the telescope detector");
 73 
 74   changeSecondStageSizeWidthCmd = new G4UIcmdWithADoubleAndUnit("/geometrySetup/detectorDimension/secondStage/setWidth", this);
 75   changeSecondStageSizeWidthCmd -> SetGuidance("Set the width of the E-stage for telescope detector");
 76   changeSecondStageSizeWidthCmd -> SetParameterName("Width", false);
 77   changeSecondStageSizeWidthCmd -> SetRange("Width >= 10 && Width <= 1000.");
 78   changeSecondStageSizeWidthCmd -> SetUnitCategory("Length");
 79   changeSecondStageSizeWidthCmd -> SetDefaultUnit("um");
 80   changeSecondStageSizeWidthCmd -> AvailableForStates(G4State_PreInit);
 81   
 82   changeSecondStageSizeThicknessCmd = new G4UIcmdWithADoubleAndUnit("/geometrySetup/detectorDimension/secondStage/setThickness", this);
 83   changeSecondStageSizeThicknessCmd -> SetGuidance("Set the thickness of the E-stage for telescope detector");
 84   changeSecondStageSizeThicknessCmd -> SetParameterName("Thickness", false);
 85   changeSecondStageSizeThicknessCmd -> SetRange("Thickness >= 10 && Thickness <= 1000.");
 86   changeSecondStageSizeThicknessCmd -> SetUnitCategory("Length");
 87   changeSecondStageSizeThicknessCmd -> SetDefaultUnit("um");
 88   changeSecondStageSizeThicknessCmd -> AvailableForStates(G4State_PreInit);
 89   
 90   enableWaterPhantomCmd = new G4UIcmdWithABool("/geometrySetup/enableWaterPhantom", this);
 91   enableWaterPhantomCmd -> SetGuidance("If true, the detector is placed inside a water phantom");
 92   enableWaterPhantomCmd -> SetParameterName("Phantom", false);
 93   enableWaterPhantomCmd -> AvailableForStates(G4State_PreInit);
 94   
 95   changeDetectorPositionDir = new G4UIdirectory("/geometrySetup/detectorPosition/");
 96   changeDetectorPositionDir -> SetGuidance("Modify the placement of the detector");
 97   
 98   changeDetectorPositionDepthCmd = new G4UIcmdWithADoubleAndUnit("/geometrySetup/detectorPosition/setDepth", this);
 99   changeDetectorPositionDepthCmd -> SetGuidance("Set the detector depth inside the water phantom");
100   changeDetectorPositionDepthCmd -> SetParameterName("Depth", false);
101   changeDetectorPositionDepthCmd -> SetRange("Depth >= 1. && Depth <= 250.");
102   changeDetectorPositionDepthCmd -> SetUnitCategory("Length");
103   changeDetectorPositionDepthCmd -> SetDefaultUnit("mm");
104   changeDetectorPositionDepthCmd -> AvailableForStates(G4State_PreInit);
105   
106   applyChangesToGeometryCmd = new G4UIcmdWithoutParameter("/geometrySetup/applyChanges",this);
107     applyChangesToGeometryCmd -> SetGuidance("Apply selected changes to the geometry");
108   applyChangesToGeometryCmd -> AvailableForStates(G4State_PreInit);
109   
110   // default values
111   detectorType = "Diamond";
112   detectorWidth = 30.*um;
113   detectorThickness = 10.*um;
114   phantomEnabled = false;
115   detectorDepth = 50*mm;
116   secondStageWidth = 800.*um;
117   secondStageThickness = 500.*um;
118   
119   analysis = analysis_manager;
120 }
121 
122 DetectorMessenger::~DetectorMessenger()
123 {
124   delete changeTheDetectorCmd;
125   delete changeDetectorSizeWidthCmd;
126   delete changeDetectorSizeThicknessCmd;
127   delete changeSecondStageSizeWidthCmd;
128   delete changeSecondStageSizeThicknessCmd;
129   delete enableWaterPhantomCmd;
130   delete changeDetectorPositionDepthCmd;
131   
132   delete applyChangesToGeometryCmd;
133   
134   delete changeSecondStageDimensionDir;
135   delete changeDetectorDimensionDir;
136   delete changeDetectorPositionDir;
137   delete changeTheGeometryDir;
138 }
139 
140 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String commandContent)
141 {
142 
143   if( command == changeTheDetectorCmd )
144   {
145     if( commandContent == "Diamond" || commandContent == "MicroDiamond" || commandContent == "Silicon" || commandContent == "SiliconBridge" || commandContent == "SiCDetector" || commandContent == "DiamondTelescope")
146     {
147       detectorType = commandContent;
148       geometryHasChanged = true;
149       
150       G4cout << "Detector type changed to " << commandContent << G4endl;
151       G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
152     }
153     
154     else
155     {
156       G4cout <<"Unknown detector type: " << commandContent << ". Geometry not changed." << G4endl;
157     }
158   }
159   
160   else if( command == changeDetectorSizeWidthCmd )
161   {
162     detectorWidth = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(commandContent);
163     geometryHasChanged = true;
164     
165     G4cout << "Detector width changed to " << commandContent << G4endl;
166     G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
167   }
168   
169   else if( command == changeDetectorSizeThicknessCmd )
170   {
171     detectorThickness = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(commandContent);
172     geometryHasChanged = true;
173     
174     G4cout << "Detector thickness changed to " << commandContent << G4endl;
175     G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
176   }
177 
178   else if( command == changeSecondStageSizeWidthCmd )
179   {
180     secondStageWidth = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(commandContent);
181     geometryHasChanged = true;
182     
183     G4cout << "Telescope E-stage width changed to " << commandContent << G4endl;
184     if ( detectorType != "DiamondTelescope" )
185     {
186       G4cout << "However this setting only takes effect when using the telescope detector.";
187       G4cout << "Select it with '/geometrySetup/selectDetector DiamondTelescope' or this command will be ignored" << G4endl;
188     }
189     else G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
190   }
191   
192   else if( command == changeSecondStageSizeThicknessCmd )
193   {
194     secondStageThickness = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(commandContent);
195     geometryHasChanged = true;
196     
197     G4cout << "Telescope E-stage thickness changed to " << commandContent << G4endl;
198     if ( detectorType != "DiamondTelescope" )
199     {
200       G4cout << "However this setting only takes effect when using the telescope detector.";
201       G4cout << "Select it with '/geometrySetup/selectDetector DiamondTelescope' or this command will be ignored" << G4endl;
202     }
203     else G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
204   }
205   
206   else if( command == enableWaterPhantomCmd )
207   {
208     phantomEnabled = G4UIcmdWithABool::GetNewBoolValue(commandContent);
209     geometryHasChanged = true;
210     
211     if( phantomEnabled == true )  G4cout << "Water phantom enabled" << G4endl;
212     else G4cout << "Water phantom disabled" << G4endl;
213     G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
214   }
215   
216   else if( command == changeDetectorPositionDepthCmd )
217   {
218     detectorDepth = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(commandContent);
219     geometryHasChanged = true;
220     
221     G4cout << "Detector depth in water changed to " << commandContent << G4endl;
222     if( phantomEnabled == false )
223     {
224       G4cout << "However the water phantom is not enabled.";
225       G4cout << "Enable it with '/geometrySetup/enableWaterPhantom true' or this command will be ignored" << G4endl;
226     }
227     else G4cout << "Run /geometrySetup/applyChanges to apply" << G4endl;
228   }
229   
230   else if( command == applyChangesToGeometryCmd )
231   {
232     if( geometryHasChanged == true )
233     {
234       G4RunManager* runManager = G4RunManager::GetRunManager();
235     
236       DetectorConstruction* newDetector = new DetectorConstruction(analysis, this);
237       
238       runManager -> SetUserInitialization(newDetector);
239       runManager -> GeometryHasBeenModified();
240       
241       geometryHasChanged = false;
242       
243       G4cout << "All pending changes to geometry have been applied" << G4endl;
244     }
245     
246     else
247     {
248       G4cout << "No pending changes to geometry. This command will be ignored" << G4endl;
249     }
250   }
251 }
252