Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/examples/advanced/xray_fluorescence/src/XrayFluoDetectorConstruction.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 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 ]

Diff markup

Differences between /examples/advanced/xray_fluorescence/src/XrayFluoDetectorConstruction.cc (Version 11.3.0) and /examples/advanced/xray_fluorescence/src/XrayFluoDetectorConstruction.cc (Version 10.6.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 //                                                 27 //
 28 // Author: Alfonso Mantero (Alfonso.Mantero@ge     28 // Author: Alfonso Mantero (Alfonso.Mantero@ge.infn.it)
 29 //                                                 29 //
 30 // History:                                        30 // History:
 31 // -----------                                     31 // -----------
 32 // 28 Nov 2001 Elena Guardincerri     Created      32 // 28 Nov 2001 Elena Guardincerri     Created
 33 //    Nov 2002 Alfonso Mantero materials added     33 //    Nov 2002 Alfonso Mantero materials added, 
 34 //             Material selection implementati     34 //             Material selection implementation
 35 // 16 Jul 2003 Alfonso Mantero Detector type s     35 // 16 Jul 2003 Alfonso Mantero Detector type selection added + minor fixes
 36 // -------------------------------------------     36 // -------------------------------------------------------------------
 37                                                    37 
 38 #include "XrayFluoDetectorConstruction.hh"         38 #include "XrayFluoDetectorConstruction.hh"
 39 #include "XrayFluoDetectorMessenger.hh"            39 #include "XrayFluoDetectorMessenger.hh"
 40 #include "XrayFluoSD.hh"                           40 #include "XrayFluoSD.hh"
 41 #include "G4PhysicalConstants.hh"                  41 #include "G4PhysicalConstants.hh"
 42 #include "G4SystemOfUnits.hh"                      42 #include "G4SystemOfUnits.hh"
 43 #include "G4Material.hh"                           43 #include "G4Material.hh"
 44 #include "G4ThreeVector.hh"                        44 #include "G4ThreeVector.hh"
 45 #include "G4Box.hh"                                45 #include "G4Box.hh"
 46 #include "G4Sphere.hh"                             46 #include "G4Sphere.hh"
 47 #include "G4Tubs.hh"                               47 #include "G4Tubs.hh"
 48 #include "G4LogicalVolume.hh"                      48 #include "G4LogicalVolume.hh"
 49 #include "G4PVPlacement.hh"                        49 #include "G4PVPlacement.hh"
 50 #include "G4TransportationManager.hh"              50 #include "G4TransportationManager.hh"
 51 #include "G4SDManager.hh"                          51 #include "G4SDManager.hh"
 52 #include "G4RunManager.hh"                         52 #include "G4RunManager.hh"
 53 #include "G4VisAttributes.hh"                      53 #include "G4VisAttributes.hh"
 54 #include "G4Colour.hh"                             54 #include "G4Colour.hh"
 55 #include "G4ios.hh"                                55 #include "G4ios.hh"
 56 #include "G4PVReplica.hh"                          56 #include "G4PVReplica.hh"
 57 #include "G4UserLimits.hh"                         57 #include "G4UserLimits.hh"
 58 #include "G4GeometryManager.hh"                    58 #include "G4GeometryManager.hh"
 59 #include "G4PhysicalVolumeStore.hh"                59 #include "G4PhysicalVolumeStore.hh"
 60 #include "G4LogicalVolumeStore.hh"                 60 #include "G4LogicalVolumeStore.hh"
 61 #include "G4SolidStore.hh"                         61 #include "G4SolidStore.hh"
 62 #include "XrayFluoNistMaterials.hh"                62 #include "XrayFluoNistMaterials.hh"
 63 #include "G4SDManager.hh"                          63 #include "G4SDManager.hh"
 64                                                    64 
 65 // #include "G4Region.hh"                          65 // #include "G4Region.hh"
 66 // #include "G4RegionStore.hh"                     66 // #include "G4RegionStore.hh"
 67                                                    67 
 68 //....oooOO0OOooo........oooOO0OOooo........oo     68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 69                                                    69 
 70                                                    70 
 71 XrayFluoDetectorConstruction::XrayFluoDetector     71 XrayFluoDetectorConstruction::XrayFluoDetectorConstruction()
 72   : aNavigator(0), detectorType(0),sampleGranu     72   : aNavigator(0), detectorType(0),sampleGranularity(false), phaseSpaceFlag(false),
 73     DeviceSizeX(0), DeviceSizeY(0),DeviceThick     73     DeviceSizeX(0), DeviceSizeY(0),DeviceThickness(0),
 74     solidWorld(0),logicWorld(0),physiWorld(0),     74     solidWorld(0),logicWorld(0),physiWorld(0),
 75     solidHPGe(0),logicHPGe(0),physiHPGe(0),        75     solidHPGe(0),logicHPGe(0),physiHPGe(0),
 76     solidSample (0),logicSample(0),physiSample     76     solidSample (0),logicSample(0),physiSample (0),
 77     solidDia1(0),logicDia1(0),physiDia1(0),        77     solidDia1(0),logicDia1(0),physiDia1(0),
 78     solidDia3(0),logicDia3(0),physiDia3(0),        78     solidDia3(0),logicDia3(0),physiDia3(0),
 79     solidOhmicPos(0),logicOhmicPos(0), physiOh     79     solidOhmicPos(0),logicOhmicPos(0), physiOhmicPos(0),
 80     solidWindow(0), logicWindow(0), physiWindo     80     solidWindow(0), logicWindow(0), physiWindow(0),
 81     solidOhmicNeg(0),logicOhmicNeg(0), physiOh     81     solidOhmicNeg(0),logicOhmicNeg(0), physiOhmicNeg(0),
 82     solidPixel(0),logicPixel(0), physiPixel(0)     82     solidPixel(0),logicPixel(0), physiPixel(0),
 83     OhmicPosMaterial(0), OhmicNegMaterial(0),      83     OhmicPosMaterial(0), OhmicNegMaterial(0),
 84     pixelMaterial(0),sampleMaterial(0),            84     pixelMaterial(0),sampleMaterial(0),
 85     Dia1Material(0),Dia3Material(0),               85     Dia1Material(0),Dia3Material(0),
 86     defaultMaterial(0), windowMaterial (0)         86     defaultMaterial(0), windowMaterial (0)  
 87 {                                                  87 { 
 88   materials = XrayFluoNistMaterials::GetInstan     88   materials = XrayFluoNistMaterials::GetInstance();
 89                                                    89 
 90   HPGeSD.Put(0);                                   90   HPGeSD.Put(0);
 91                                                    91 
 92   aNavigator = new G4Navigator();                  92   aNavigator = new G4Navigator();
 93                                                    93  
 94   DefineDefaultMaterials();                        94   DefineDefaultMaterials();
 95                                                    95 
 96   NbOfPixelRows     =  1; // should be 1           96   NbOfPixelRows     =  1; // should be 1
 97   NbOfPixelColumns  =  1; // should be 1           97   NbOfPixelColumns  =  1; // should be 1
 98   NbOfPixels        =  NbOfPixelRows*NbOfPixel     98   NbOfPixels        =  NbOfPixelRows*NbOfPixelColumns;
 99   PixelSizeXY       =  std::sqrt(40.) * mm;        99   PixelSizeXY       =  std::sqrt(40.) * mm;
100   PixelThickness = 2.7 * mm; //should be 3.5 m    100   PixelThickness = 2.7 * mm; //should be 3.5 mm
101                                                   101 
102   G4cout << "PixelThickness(mm): "<< PixelThic    102   G4cout << "PixelThickness(mm): "<< PixelThickness/mm << G4endl;
103   G4cout << "PixelSizeXY(cm): "<< PixelSizeXY/    103   G4cout << "PixelSizeXY(cm): "<< PixelSizeXY/cm << G4endl;
104                                                   104 
105   ContactSizeXY     = PixelSizeXY; //std::sqrt    105   ContactSizeXY     = PixelSizeXY; //std::sqrt(40) * mm; //should be the same as PixelSizeXY
106   SampleThickness = 4 * mm;                       106   SampleThickness = 4 * mm;
107   SampleSizeXY = 3. * cm;                         107   SampleSizeXY = 3. * cm;
108   Dia1Thickness = 1. *mm;                         108   Dia1Thickness = 1. *mm;
109   Dia3Thickness = 1. *mm;                         109   Dia3Thickness = 1. *mm;
110   Dia1SizeXY = 3. *cm;                            110   Dia1SizeXY = 3. *cm;
111   Dia3SizeXY = 3. *cm;                            111   Dia3SizeXY = 3. *cm;
112                                                   112 
113                                                   113 
114   DiaInnerSize = 2.9 * cm; //(Hole in the dete    114   DiaInnerSize = 2.9 * cm; //(Hole in the detector's diaphragm) it was 1 mm
115                                                   115 
116                                                   116 
117   OhmicNegThickness = 1e-6*cm;// 0.005            117   OhmicNegThickness = 1e-6*cm;// 0.005
118   OhmicPosThickness = 1e-6*cm;// 0.005            118   OhmicPosThickness = 1e-6*cm;// 0.005
119   windowThickness = 0.008 * cm; //value for ai    119   windowThickness = 0.008 * cm; //value for aif detector
120   ThetaHPGe = 135. * deg;                         120   ThetaHPGe = 135. * deg;
121   PhiHPGe = 225. * deg;                           121   PhiHPGe = 225. * deg;
122                                                   122 
123   ThetaDia1 = 135. * deg;                         123   ThetaDia1 = 135. * deg;
124   PhiDia1 = 90. * deg;                            124   PhiDia1 = 90. * deg;
125   AlphaDia1 = 225. * deg;                         125   AlphaDia1 = 225. * deg;
126                                                   126 
127   AlphaDia3 = 180. * deg;                         127   AlphaDia3 = 180. * deg;
128   Dia3Dist =  66.5 * mm;                          128   Dia3Dist =  66.5 * mm;
129   Dia3InnerSize = 1. * mm;                        129   Dia3InnerSize = 1. * mm;
130   ThetaDia3 = 180. * deg;                         130   ThetaDia3 = 180. * deg;
131   PhiDia3 = 90. * deg;                            131   PhiDia3 = 90. * deg;
132                                                   132 
133   DistDia = 66.5 * mm;                            133   DistDia = 66.5 * mm;
134   DistDe =DistDia+ (Dia1Thickness                 134   DistDe =DistDia+ (Dia1Thickness
135         +PixelThickness)/2+OhmicPosThickness+w    135         +PixelThickness)/2+OhmicPosThickness+windowThickness ;
136                                                   136 
137   grainDia = 1 * mm;                              137   grainDia = 1 * mm;
138   PixelCopyNb=0;                                  138   PixelCopyNb=0;
139   grainCopyNb=0;                                  139   grainCopyNb=0;
140   G4String defaultDetectorType = "sili";          140   G4String defaultDetectorType = "sili";
141   ComputeApparateParameters();                    141   ComputeApparateParameters();
142                                                   142 
143 //   G4String regName = "SampleRegion";           143 //   G4String regName = "SampleRegion";
144 //   sampleRegion = new G4Region(regName);        144 //   sampleRegion = new G4Region(regName);  
145                                                   145 
146   if (!phaseSpaceFlag) SetDetectorType(default    146   if (!phaseSpaceFlag) SetDetectorType(defaultDetectorType);
147                                                   147   
148   // create commands for interactive definitio    148   // create commands for interactive definition of the apparate
149                                                   149   
150   detectorMessenger = new XrayFluoDetectorMess    150   detectorMessenger = new XrayFluoDetectorMessenger(this);
151                                                   151 
152   G4cout << "XrayFluoDetectorConstruction crea    152   G4cout << "XrayFluoDetectorConstruction created" << G4endl;
153 }                                                 153 }
154 //....oooOO0OOooo........oooOO0OOooo........oo    154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
155                                                   155 
156                                                   156 
157 XrayFluoDetectorConstruction* XrayFluoDetector    157 XrayFluoDetectorConstruction* XrayFluoDetectorConstruction::instance = 0;
158                                                   158 
159 XrayFluoDetectorConstruction* XrayFluoDetector    159 XrayFluoDetectorConstruction* XrayFluoDetectorConstruction::GetInstance()
160 {                                                 160 {
161   if (instance == 0)                              161   if (instance == 0)
162     {                                             162     {
163       instance = new XrayFluoDetectorConstruct    163       instance = new XrayFluoDetectorConstruction;
164                                                   164      
165     }                                             165     }
166   return instance;                                166   return instance;
167 }                                                 167 }
168                                                   168 
169 //....oooOO0OOooo........oooOO0OOooo........oo    169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
170                                                   170 
171 void XrayFluoDetectorConstruction::SetDetector    171 void XrayFluoDetectorConstruction::SetDetectorType(G4String type) 
172 {                                                 172 {
173   if (type=="sili")                               173   if (type=="sili")
174     {                                             174     {
175       detectorType = XrayFluoSiLiDetectorType:    175       detectorType = XrayFluoSiLiDetectorType::GetInstance();
176     }                                             176     }
177    else if (type=="hpge")                         177    else if (type=="hpge")
178      {                                            178      {
179        detectorType = XrayFluoHPGeDetectorType    179        detectorType = XrayFluoHPGeDetectorType::GetInstance();
180     }/*                                           180     }/*
181    else if (type=="aifira")                       181    else if (type=="aifira")
182      {                                            182      {
183        detectorType = XrayFluoAifSiLi::GetInst    183        detectorType = XrayFluoAifSiLi::GetInstance();
184        }*/                                        184        }*/
185   else                                            185   else 
186     {                                             186     {
187       G4ExceptionDescription execp;               187       G4ExceptionDescription execp;
188       execp << type + "detector type unknown";    188       execp << type + "detector type unknown";
189       G4Exception("XrayFluoDataSet::LoadData()    189       G4Exception("XrayFluoDataSet::LoadData()","example-xray_fluorescence06",
190     FatalException, execp);                       190     FatalException, execp);
191     }                                             191     }
192   //GeometryHasBeenModified invoked by the mes    192   //GeometryHasBeenModified invoked by the messenger
193                                                   193   
194 }                                                 194 }
195                                                   195 
196 XrayFluoVDetectorType* XrayFluoDetectorConstru    196 XrayFluoVDetectorType* XrayFluoDetectorConstruction::GetDetectorType() const
197 {                                                 197 {
198   return detectorType;                            198   return detectorType;
199 }                                                 199 }
200                                                   200 
201 //....oooOO0OOooo........oooOO0OOooo........oo    201 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
202                                                   202 
203 XrayFluoDetectorConstruction::~XrayFluoDetecto    203 XrayFluoDetectorConstruction::~XrayFluoDetectorConstruction()
204                                                   204 
205 {                                                 205 { 
206   delete detectorMessenger;                       206   delete detectorMessenger;
207   delete detectorType;                            207   delete detectorType;
208   G4cout << "XrayFluoDetectorConstruction dele    208   G4cout << "XrayFluoDetectorConstruction deleted" << G4endl;
209 }                                                 209 }
210                                                   210 
211 //....oooOO0OOooo........oooOO0OOooo........oo    211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
212                                                   212 
213 G4VPhysicalVolume* XrayFluoDetectorConstructio    213 G4VPhysicalVolume* XrayFluoDetectorConstruction::Construct()
214 {                                                 214 {
215   return ConstructApparate();                     215   return ConstructApparate();
216 }                                                 216 }
217                                                   217 
218 //....oooOO0OOooo........oooOO0OOooo........oo    218 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
219                                                   219 
220 void XrayFluoDetectorConstruction::DefineDefau    220 void XrayFluoDetectorConstruction::DefineDefaultMaterials()
221 {                                                 221 {
222                                                   222 
223                                                   223 
224   //define materials of the apparate              224   //define materials of the apparate
225                                                   225 
226   sampleMaterial = materials->GetMaterial("Dol    226   sampleMaterial = materials->GetMaterial("Dolorite");
227   Dia1Material = materials->GetMaterial("G4_Pb    227   Dia1Material = materials->GetMaterial("G4_Pb");
228   Dia3Material = materials->GetMaterial("G4_Ga    228   Dia3Material = materials->GetMaterial("G4_Galactic");
229   pixelMaterial = materials->GetMaterial("SiLi    229   pixelMaterial = materials->GetMaterial("SiLi");
230   //OhmicPosMaterial = materials->GetMaterial(    230   //OhmicPosMaterial = materials->GetMaterial("G4_Cu");
231   OhmicPosMaterial = materials->GetMaterial("G    231   OhmicPosMaterial = materials->GetMaterial("G4_Ni");
232   OhmicNegMaterial = materials->GetMaterial("G    232   OhmicNegMaterial = materials->GetMaterial("G4_Pb");
233   defaultMaterial = materials->GetMaterial("G4    233   defaultMaterial = materials->GetMaterial("G4_Galactic");
234   windowMaterial = materials->GetMaterial("G4_    234   windowMaterial = materials->GetMaterial("G4_Be");
235 }                                                 235 }
236                                                   236 
237 void XrayFluoDetectorConstruction::SetOhmicPos    237 void XrayFluoDetectorConstruction::SetOhmicPosThickness(G4double val)
238 {                                                 238 {
239                                                   239   
240   if (!phaseSpaceFlag) {                          240   if (!phaseSpaceFlag) {    
241                                                   241     
242                                                   242     
243     if (val == 0.0) {                             243     if (val == 0.0) {
244       OhmicPosMaterial = materials->GetMateria    244       OhmicPosMaterial = materials->GetMaterial("G4_Galactic");
245     }                                             245     }
246     else {                                        246     else {
247       OhmicPosThickness = val;                    247       OhmicPosThickness = val;
248       //OhmicPosMaterial = materials->GetMater    248       //OhmicPosMaterial = materials->GetMaterial("G4_Cu");
249       OhmicPosMaterial = materials->GetMateria    249       OhmicPosMaterial = materials->GetMaterial("G4_Ni");
250     }                                             250     }
251                                                   251     
252   }                                               252   }
253   else{                                           253   else{
254     G4cout << "Not available in this configura    254     G4cout << "Not available in this configuration" << G4endl;
255   }                                               255   }
256                                                   256   
257 }                                                 257 }
258                                                   258 
259                                                   259 
260 //....oooOO0OOooo........oooOO0OOooo........oo    260 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 
261                                                   261 
262 G4VPhysicalVolume* XrayFluoDetectorConstructio    262 G4VPhysicalVolume* XrayFluoDetectorConstruction::ConstructApparate()
263 {                                                 263 {
264   // complete the apparate parameters definiti    264   // complete the apparate parameters definition 
265                                                   265   
266   //ComputeApparateParameters();                  266   //ComputeApparateParameters();
267                                                   267 
268   //world and associated navigator                268   //world and associated navigator
269                                                   269   
270   solidWorld = new G4Box("World",                 270   solidWorld = new G4Box("World",                   //its name
271        WorldSizeXY/2,WorldSizeXY/2,WorldSizeZ/    271        WorldSizeXY/2,WorldSizeXY/2,WorldSizeZ/2); //its size
272                                                   272   
273   logicWorld = new G4LogicalVolume(solidWorld,    273   logicWorld = new G4LogicalVolume(solidWorld,    //its solid
274                                    defaultMate    274                                    defaultMaterial, //its material
275                                    "World");      275                                    "World");    //its name
276   physiWorld = new G4PVPlacement(0,     //no r    276   physiWorld = new G4PVPlacement(0,     //no rotation
277          G4ThreeVector(), //at (0,0,0)            277          G4ThreeVector(), //at (0,0,0)
278          "World",   //its name                    278          "World",   //its name
279          logicWorld,    //its logical volume      279          logicWorld,    //its logical volume
280          0,     //its mother  volume              280          0,     //its mother  volume
281          false,     //no boolean operation        281          false,     //no boolean operation
282          0);      //copy number                   282          0);      //copy number
283                                                   283 
284   aNavigator->SetWorldVolume(physiWorld);         284   aNavigator->SetWorldVolume(physiWorld);
285                                                   285 
286                                                   286  
287   //HPGeDetector                                  287   //HPGeDetector
288                                                   288 
289   if (!phaseSpaceFlag) {                          289   if (!phaseSpaceFlag) {
290                                                   290     
291     solidHPGe = 0;  physiHPGe = 0;  logicHPGe=    291     solidHPGe = 0;  physiHPGe = 0;  logicHPGe=0;
292     solidPixel=0; logicPixel=0; physiPixel=0;     292     solidPixel=0; logicPixel=0; physiPixel=0;
293                                                   293     
294     if (DeviceThickness > 0.)                     294     if (DeviceThickness > 0.)  
295       {                                           295       {
296   solidHPGe = new G4Box("HPGeDetector",   //it    296   solidHPGe = new G4Box("HPGeDetector",   //its name
297             DeviceSizeX/2,DeviceSizeY/2,Device    297             DeviceSizeX/2,DeviceSizeY/2,DeviceThickness/2);//size
298                                                   298   
299                                                   299   
300   logicHPGe = new G4LogicalVolume(solidHPGe,      300   logicHPGe = new G4LogicalVolume(solidHPGe,  //its solid
301           defaultMaterial,  //its material        301           defaultMaterial,  //its material 
302           "HPGeDetector");  //its name            302           "HPGeDetector");  //its name
303                                                   303   
304   zRotPhiHPGe.rotateX(PhiHPGe);                   304   zRotPhiHPGe.rotateX(PhiHPGe);
305   G4double x,y,z;                                 305   G4double x,y,z;
306   z = DistDe * std::cos(ThetaHPGe);               306   z = DistDe * std::cos(ThetaHPGe);
307   y =DistDe * std::sin(ThetaHPGe);                307   y =DistDe * std::sin(ThetaHPGe);
308   x = 0.*cm;                                      308   x = 0.*cm;
309   physiHPGe = new G4PVPlacement(G4Transform3D(    309   physiHPGe = new G4PVPlacement(G4Transform3D(zRotPhiHPGe,G4ThreeVector(x,y,z)), 
310               "HPGeDetector", //its name          310               "HPGeDetector", //its name
311               logicHPGe,  //its logical volume    311               logicHPGe,  //its logical volume
312               physiWorld, //its mother  volume    312               physiWorld, //its mother  volume
313               false,    //no boolean operation    313               false,    //no boolean operation
314               0);   //copy number                 314               0);   //copy number
315       }                                           315       }
316     // Pixel                                      316     // Pixel
317                                                   317     
318                                                   318     
319                                                   319     
320                                                   320     
321     for ( G4int j=0; j < NbOfPixelColumns ; j+    321     for ( G4int j=0; j < NbOfPixelColumns ; j++ )
322       { for ( G4int i=0; i < NbOfPixelRows ; i    322       { for ( G4int i=0; i < NbOfPixelRows ; i++ )
323   {                                               323   { 
324     solidPixel=0; logicPixel=0;   physiPixel=0    324     solidPixel=0; logicPixel=0;   physiPixel=0;
325     if (PixelThickness > 0.)                      325     if (PixelThickness > 0.)
326       solidPixel = new G4Box("Pixel",             326       solidPixel = new G4Box("Pixel",     
327            PixelSizeXY/2,PixelSizeXY/2, PixelT    327            PixelSizeXY/2,PixelSizeXY/2, PixelThickness/2);
328                                                   328     
329     logicPixel = new G4LogicalVolume(solidPixe    329     logicPixel = new G4LogicalVolume(solidPixel,  
330              pixelMaterial, //its material        330              pixelMaterial, //its material
331              "Pixel");          //its name        331              "Pixel");          //its name
332                                                   332     
333     /*                                            333     /*
334       zRotPhiHPGe.rotateX(PhiHPGe);               334       zRotPhiHPGe.rotateX(PhiHPGe);
335       G4double x,y,z;                             335       G4double x,y,z;
336       z = DistDe * std::cos(ThetaHPGe);           336       z = DistDe * std::cos(ThetaHPGe);
337       y =DistDe * std::sin(ThetaHPGe);            337       y =DistDe * std::sin(ThetaHPGe);
338       x = 0.*cm;*/                                338       x = 0.*cm;*/ 
339     physiPixel = new G4PVPlacement(0,             339     physiPixel = new G4PVPlacement(0,        
340            G4ThreeVector(0,                       340            G4ThreeVector(0,
341                    i*PixelSizeXY,                 341                    i*PixelSizeXY, 
342                    j*PixelSizeXY ),               342                    j*PixelSizeXY ),
343            "Pixel",                               343            "Pixel",  
344            logicPixel,   //its logical volume     344            logicPixel,   //its logical volume
345            physiHPGe, //its mother  volume        345            physiHPGe, //its mother  volume
346            false,  //no boolean operation         346            false,  //no boolean operation
347            PixelCopyNb);//copy number             347            PixelCopyNb);//copy number
348                                                   348     
349                                                   349     
350                                                   350     
351                                                   351     
352                                                   352     
353                                                   353     
354     // OhmicNeg                                   354     // OhmicNeg
355                                                   355     
356     solidOhmicNeg=0; logicOhmicNeg=0; physiOhm    356     solidOhmicNeg=0; logicOhmicNeg=0; physiOhmicNeg=0;  
357                                                   357     
358     if (OhmicNegThickness > 0.)                   358     if (OhmicNegThickness > 0.) 
359       { solidOhmicNeg = new G4Box("OhmicNeg",     359       { solidOhmicNeg = new G4Box("OhmicNeg",   //its name
360           PixelSizeXY/2,PixelSizeXY/2,OhmicNeg    360           PixelSizeXY/2,PixelSizeXY/2,OhmicNegThickness/2); 
361                                                   361       
362       logicOhmicNeg = new G4LogicalVolume(soli    362       logicOhmicNeg = new G4LogicalVolume(solidOhmicNeg,    //its solid
363             OhmicNegMaterial, //its material      363             OhmicNegMaterial, //its material
364             "OhmicNeg");      //its name          364             "OhmicNeg");      //its name
365                                                   365       
366       physiOhmicNeg = new G4PVPlacement(0,        366       physiOhmicNeg = new G4PVPlacement(0,
367                 G4ThreeVector                     367                 G4ThreeVector
368                 (0.,                              368                 (0.,
369                  0.,                              369                  0.,
370                  (PixelThickness+OhmicNegThick    370                  (PixelThickness+OhmicNegThickness)/2),
371                 "OhmicNeg",        //its name     371                 "OhmicNeg",        //its name
372                 logicOhmicNeg,     //its logic    372                 logicOhmicNeg,     //its logical volume
373                 physiHPGe,        //its mother    373                 physiHPGe,        //its mother
374                 false,             //no boulea    374                 false,             //no boulean operat
375                 PixelCopyNb);                /    375                 PixelCopyNb);                //copy number
376                                                   376       
377       }                                           377       }
378     // OhmicPos                                   378     // OhmicPos
379     solidOhmicPos=0; logicOhmicPos=0; physiOhm    379     solidOhmicPos=0; logicOhmicPos=0; physiOhmicPos=0;  
380                                                   380     
381     if (OhmicPosThickness > 0.)                   381     if (OhmicPosThickness > 0.) 
382       { solidOhmicPos = new G4Box("OhmicPos",     382       { solidOhmicPos = new G4Box("OhmicPos",   //its name
383           PixelSizeXY/2,PixelSizeXY/2,OhmicPos    383           PixelSizeXY/2,PixelSizeXY/2,OhmicPosThickness/2); 
384                                                   384       
385       logicOhmicPos = new G4LogicalVolume(soli    385       logicOhmicPos = new G4LogicalVolume(solidOhmicPos,    //its solid
386             OhmicPosMaterial, //its material      386             OhmicPosMaterial, //its material
387             "OhmicPos");      //its name          387             "OhmicPos");      //its name
388                                                   388       
389       physiOhmicPos = new G4PVPlacement(0,        389       physiOhmicPos = new G4PVPlacement(0,  
390                 G4ThreeVector(0.,                 390                 G4ThreeVector(0.,
391                   0.,                             391                   0.,
392                   (-PixelThickness-OhmicPosThi    392                   (-PixelThickness-OhmicPosThickness)/2),  
393                 "OhmicPos",                       393                 "OhmicPos",  
394                 logicOhmicPos,                    394                 logicOhmicPos,
395                 physiHPGe,                        395                 physiHPGe,  
396                 false,                            396                 false,     
397                 PixelCopyNb);                     397                 PixelCopyNb); 
398                                                   398       
399       }                                           399       }
400                                                   400 
401     /////////// widow place here! ////////////    401     /////////// widow place here! ////////////////
402     // OhmicPos                                   402     // OhmicPos
403     solidWindow=0; logicWindow=0; physiWindow=    403     solidWindow=0; logicWindow=0; physiWindow=0;  
404                                                   404     
405     if (windowThickness > 0.)                     405     if (windowThickness > 0.) 
406       { solidWindow = new G4Box("Window",   //    406       { solidWindow = new G4Box("Window",   //its name
407           PixelSizeXY/2,PixelSizeXY/2,windowTh    407           PixelSizeXY/2,PixelSizeXY/2,windowThickness/2); 
408                                                   408       
409       logicWindow = new G4LogicalVolume(solidW    409       logicWindow = new G4LogicalVolume(solidWindow,    //its solid
410             windowMaterial, //its material        410             windowMaterial, //its material
411             "Window");      //its name            411             "Window");      //its name
412                                                   412       
413       physiWindow = new G4PVPlacement(0,          413       physiWindow = new G4PVPlacement(0,  
414                 G4ThreeVector(0.,                 414                 G4ThreeVector(0.,
415                   0.,                             415                   0.,
416                   ((-PixelThickness-windowThic    416                   ((-PixelThickness-windowThickness)/2)
417                   -OhmicPosThickness),            417                   -OhmicPosThickness),  
418                 "OhmicWindow",                    418                 "OhmicWindow",  
419                 logicWindow,                      419                 logicWindow,
420                 physiHPGe,                        420                 physiHPGe,  
421                 false,                            421                 false,     
422                 PixelCopyNb);                     422                 PixelCopyNb); 
423                                                   423       
424       }                                           424       }
425                                                   425 
426                                                   426 
427                                                   427   
428     PixelCopyNb += PixelCopyNb;                   428     PixelCopyNb += PixelCopyNb; 
429     G4cout << "PixelCopyNb: " << PixelCopyNb <    429     G4cout << "PixelCopyNb: " << PixelCopyNb << G4endl;
430   }                                               430   }
431                                                   431       
432       }                                           432       }
433                                                   433     
434   }                                               434   }
435                                                   435   
436   //Sample                                        436   //Sample
437                                                   437   
438   if (sampleGranularity) {                        438   if (sampleGranularity) {
439                                                   439 
440     solidSample=0;  logicSample=0;  physiSampl    440     solidSample=0;  logicSample=0;  physiSample=0;
441     if (SampleThickness > 0.)                     441     if (SampleThickness > 0.)  
442       {                                           442       {
443   solidSample = new G4Box("Sample",   //its na    443   solidSample = new G4Box("Sample",   //its name
444         SampleSizeXY/2,SampleSizeXY/2,SampleTh    444         SampleSizeXY/2,SampleSizeXY/2,SampleThickness/2);//size
445                                                   445   
446   logicSample= new G4LogicalVolume(solidSample    446   logicSample= new G4LogicalVolume(solidSample, //its solid
447            defaultMaterial, //its material        447            defaultMaterial, //its material
448            "Sample"); //its name                  448            "Sample"); //its name
449                                                   449   
450   physiSample = new G4PVPlacement(0,      //no    450   physiSample = new G4PVPlacement(0,      //no rotation
451           G4ThreeVector(),  //at (0,0,0)          451           G4ThreeVector(),  //at (0,0,0)
452           "Sample", //its name                    452           "Sample", //its name
453           logicSample,  //its logical volume      453           logicSample,  //its logical volume
454           physiWorld, //its mother  volume        454           physiWorld, //its mother  volume
455           false,    //no boolean operation        455           false,    //no boolean operation
456           0);   //copy number                     456           0);   //copy number
457                                                   457   
458       }                                           458       }
459                                                   459 
460                                                   460 
461                                                   461 
462                                                   462 
463     G4int nbOfGrainsX = ((G4int)(SampleSizeXY/    463     G4int nbOfGrainsX = ((G4int)(SampleSizeXY/grainDia)) -1 ;
464                                                   464     
465     // y dim of a max density plane is 2rn-(n-    465     // y dim of a max density plane is 2rn-(n-1)ar, wehere a = (1-(std::sqrt(3)/2)), n is 
466     // number of rows and r the radius of the     466     // number of rows and r the radius of the grain. so the Y-dim of the sample must 
467     // be greater or equal to this. It results    467     // be greater or equal to this. It results that nmust be <= (SampleY-a)/(1-a).
468     // Max Y shift of the planes superimposing    468     // Max Y shift of the planes superimposing along Z axis is minor (2/std::sqrt(3)r)
469                                                   469 
470     G4double a = (1.-(std::sqrt(3.)/2.));         470     G4double a = (1.-(std::sqrt(3.)/2.));
471     G4int nbOfGrainsY =  (G4int) ( ((SampleSiz    471     G4int nbOfGrainsY =  (G4int) ( ((SampleSizeXY/(grainDia/2.)) -a)/(2.-a) ) -1;
472                                                   472 
473     // same for the z axis, but a = 2 * (std::    473     // same for the z axis, but a = 2 * (std::sqrt(3) - std::sqrt(2))/std::sqrt(3)
474                                                   474 
475     G4double b = 2. * (std::sqrt(3.) - std::sq    475     G4double b = 2. * (std::sqrt(3.) - std::sqrt(2.))/std::sqrt(3.);
476     G4int nbOfGrainsZ =  (G4int) ( ((SampleThi    476     G4int nbOfGrainsZ =  (G4int) ( ((SampleThickness/(grainDia/2.)) -b)/(2.-b) )-1;
477                                                   477 
478     if (SampleThickness > 0.){                    478     if (SampleThickness > 0.){
479                                                   479       
480       solidGrain=0; logicGrain=0; physiGrain=0    480       solidGrain=0; logicGrain=0; physiGrain=0;
481       solidGrain = new G4Sphere("Grain",0.,       481       solidGrain = new G4Sphere("Grain",0.,     
482         grainDia/2,0., twopi, 0., pi);            482         grainDia/2,0., twopi, 0., pi);
483                                                   483       
484       logicGrain = new G4LogicalVolume(solidGr    484       logicGrain = new G4LogicalVolume(solidGrain,  
485                sampleMaterial,  //its material    485                sampleMaterial,  //its material
486                "Grain");          //its name      486                "Grain");          //its name
487       G4ThreeVector grainPosition;                487       G4ThreeVector grainPosition; 
488       G4double grainInitPositionX = 0;            488       G4double grainInitPositionX = 0;
489       G4double grainInitPositionY = 0;            489       G4double grainInitPositionY = 0;
490       G4double grainInitPositionZ = (-1.*Sampl    490       G4double grainInitPositionZ = (-1.*SampleThickness/2.+grainDia/2.);
491       G4double grainStepX = grainDia = 0;         491       G4double grainStepX = grainDia = 0;
492       G4double grainStepY = grainDia*(1.-(0.5-    492       G4double grainStepY = grainDia*(1.-(0.5-(std::sqrt(3.)/4.)));
493       G4double grainStepZ = grainDia*std::sqrt    493       G4double grainStepZ = grainDia*std::sqrt(2./3.);
494                                                   494       
495       for ( G4int k=0; k < nbOfGrainsZ ; k++ )    495       for ( G4int k=0; k < nbOfGrainsZ ; k++ ) {
496   for ( G4int j=0; j < nbOfGrainsY ; j++ ) {      496   for ( G4int j=0; j < nbOfGrainsY ; j++ ) {
497     for ( G4int i=0; i < nbOfGrainsX ; i++ ) {    497     for ( G4int i=0; i < nbOfGrainsX ; i++ ) {
498                                                   498       
499       // Now we identify the layer and the row    499       // Now we identify the layer and the row where the grain is , to place it in the right position
500                                                   500       
501                                                   501       
502                                                   502       
503       if (k%3 == 0) { // first or (4-multiple)    503       if (k%3 == 0) { // first or (4-multiple)th layer: structure is ABCABC
504         grainInitPositionY = (-1.*SampleSizeXY    504         grainInitPositionY = (-1.*SampleSizeXY/2.+grainDia/2.);    
505         if (j%2 ==0) { //first or (3-multiple)    505         if (j%2 ==0) { //first or (3-multiple)th row
506     grainInitPositionX = (-1.*SampleSizeXY/2.+    506     grainInitPositionX = (-1.*SampleSizeXY/2.+grainDia/2.);
507         }                                         507         }
508                                                   508         
509         else if ( ((j+1) % 2)  == 0 ) {           509         else if ( ((j+1) % 2)  == 0 ) {
510     grainInitPositionX = (-1.*SampleSizeXY/2.+    510     grainInitPositionX = (-1.*SampleSizeXY/2.+ grainDia);   
511         }                                         511         }
512                                                   512         
513       }                                           513       }       
514       else if ( ((k+2) % 3) == 0 ) { // B-laye    514       else if ( ((k+2) % 3) == 0 ) { // B-layer
515                                                   515         
516         grainInitPositionY = ( (-1.*SampleSize    516         grainInitPositionY = ( (-1.*SampleSizeXY/2.) + (grainDia/2.)*(1. + (1./std::sqrt(3.)) ) );
517                                                   517         
518         if (j%2 ==0) { //first or (3-multiple)    518         if (j%2 ==0) { //first or (3-multiple)th row
519     grainInitPositionX = (-1.*SampleSizeXY/2.+    519     grainInitPositionX = (-1.*SampleSizeXY/2.+grainDia);
520         }                                         520         }
521                                                   521         
522         else if ( (j+1)%2  == 0 ) {               522         else if ( (j+1)%2  == 0 ) {
523     grainInitPositionX = (-1.*SampleSizeXY/2.+    523     grainInitPositionX = (-1.*SampleSizeXY/2.+grainDia/2);    
524         }                                         524         }
525                                                   525         
526       }                                           526       }
527                                                   527       
528       else if ( (k+1)%3 == 0 ) { // B-layer       528       else if ( (k+1)%3 == 0 ) { // B-layer
529                                                   529         
530         grainInitPositionY = (-1.*SampleSizeXY    530         grainInitPositionY = (-1.*SampleSizeXY/2.+(grainDia/2.)*(1.+2./std::sqrt(3.)) );
531                                                   531         
532         if (j%2 ==0) { //first or (3-multiple)    532         if (j%2 ==0) { //first or (3-multiple)th row
533     grainInitPositionX = (-1.*SampleSizeXY/2.+    533     grainInitPositionX = (-1.*SampleSizeXY/2.+grainDia/2.);
534         }                                         534         }
535                                                   535         
536         else if ( (j+1)%2  == 0 ) {               536         else if ( (j+1)%2  == 0 ) {
537     grainInitPositionX = (-1.*SampleSizeXY/2.+    537     grainInitPositionX = (-1.*SampleSizeXY/2.+grainDia);    
538         }                                         538         }
539                                                   539         
540       }                                           540       }
541                                                   541       
542       physiGrain = new G4PVPlacement(0,           542       physiGrain = new G4PVPlacement(0,        
543              G4ThreeVector( grainInitPositionX    543              G4ThreeVector( grainInitPositionX + i*grainStepX, 
544                 grainInitPositionY + j*grainSt    544                 grainInitPositionY + j*grainStepY,
545                 grainInitPositionZ + k*grainSt    545                 grainInitPositionZ + k*grainStepZ),
546              "Grain",                             546              "Grain",  
547              logicGrain,   //its logical volum    547              logicGrain,   //its logical volume
548              physiSample, //its mother  volume    548              physiSample, //its mother  volume
549              false,  //no boolean operation       549              false,  //no boolean operation
550              grainCopyNb);//copy number           550              grainCopyNb);//copy number    
551                                                   551       
552       grainCopyNb = grainCopyNb +1;               552       grainCopyNb = grainCopyNb +1; 
553     }                                             553     }
554   }                                               554   }
555       }                                           555       }
556     }                                             556     }    
557   }                                               557   }
558   else {                                          558   else {     
559                                                   559       
560     solidSample=0;  logicSample=0;  physiSampl    560     solidSample=0;  logicSample=0;  physiSample=0;
561     if (SampleThickness > 0.)                     561     if (SampleThickness > 0.)  
562       {                                           562       {
563   solidSample = new G4Box("Sample",   //its na    563   solidSample = new G4Box("Sample",   //its name
564         SampleSizeXY/2,SampleSizeXY/2,SampleTh    564         SampleSizeXY/2,SampleSizeXY/2,SampleThickness/2);//size
565                                                   565     
566   logicSample= new G4LogicalVolume(solidSample    566   logicSample= new G4LogicalVolume(solidSample, //its solid
567            sampleMaterial,  //its material        567            sampleMaterial,  //its material
568            "Sample"); //its name                  568            "Sample"); //its name
569                                                   569     
570   physiSample = new G4PVPlacement(0,      //no    570   physiSample = new G4PVPlacement(0,      //no rotation
571           G4ThreeVector(),  //at (0,0,0)          571           G4ThreeVector(),  //at (0,0,0)
572           "Sample", //its name                    572           "Sample", //its name
573           logicSample,  //its logical volume      573           logicSample,  //its logical volume
574           physiWorld, //its mother  volume        574           physiWorld, //its mother  volume
575           false,    //no boolean operation        575           false,    //no boolean operation
576           0);   //copy number                     576           0);   //copy number
577                                                   577     
578       }                                           578       }  
579   }                                               579   }
580                                                   580 
581   if (!phaseSpaceFlag) {                          581   if (!phaseSpaceFlag) {    
582     //Diaphragm1                                  582     //Diaphragm1
583                                                   583     
584     solidDia1 = 0;  physiDia1 = 0;  logicDia1=    584     solidDia1 = 0;  physiDia1 = 0;  logicDia1=0;
585                                                   585     
586     if (Dia1Thickness > 0.)                       586     if (Dia1Thickness > 0.)  
587       {                                           587       {
588   solidDia1 = new G4Tubs("Diaphragm1",    //it    588   solidDia1 = new G4Tubs("Diaphragm1",    //its name
589              DiaInnerSize/2,                      589              DiaInnerSize/2,
590              Dia1SizeXY/2,                        590              Dia1SizeXY/2,
591              Dia1Thickness/2,                     591              Dia1Thickness/2,
592              0,                                   592              0,
593              360*deg);//size                      593              360*deg);//size
594                                                   594   
595                                                   595   
596   logicDia1 = new G4LogicalVolume(solidDia1,      596   logicDia1 = new G4LogicalVolume(solidDia1,  //its solid
597           Dia1Material, //its material            597           Dia1Material, //its material
598           "Diaphragm1");  //its name              598           "Diaphragm1");  //its name
599                                                   599   
600   zRotPhiDia1.rotateX(AlphaDia1);                 600   zRotPhiDia1.rotateX(AlphaDia1);
601   G4double x,y,z;                                 601   G4double x,y,z;
602   z = DistDia * std::cos(ThetaDia1);              602   z = DistDia * std::cos(ThetaDia1);
603   y =DistDia * std::sin(ThetaDia1);               603   y =DistDia * std::sin(ThetaDia1);
604   x = 0.*cm;                                      604   x = 0.*cm;
605   physiDia1 = new G4PVPlacement(G4Transform3D(    605   physiDia1 = new G4PVPlacement(G4Transform3D(zRotPhiDia1,G4ThreeVector(x,y,z)),
606               "Diaphragm1", //its name            606               "Diaphragm1", //its name
607               logicDia1,  //its logical volume    607               logicDia1,  //its logical volume
608               physiWorld, //its mother  volume    608               physiWorld, //its mother  volume
609               false,    //no boolean operation    609               false,    //no boolean operation
610               0);   //copy number                 610               0);   //copy number
611       }                                           611       }  
612                                                   612     
613     //Diaphragm3                                  613     //Diaphragm3
614                                                   614     
615     solidDia3 = 0;  physiDia3 = 0;  logicDia3     615     solidDia3 = 0;  physiDia3 = 0;  logicDia3 =0;
616                                                   616     
617     if (Dia3Thickness > 0.)                       617     if (Dia3Thickness > 0.)  
618       {                                           618       {
619   solidDia3 = new G4Tubs("Diaphragm3",            619   solidDia3 = new G4Tubs("Diaphragm3",
620              Dia3InnerSize/2,                     620              Dia3InnerSize/2,
621              Dia3SizeXY/2,                        621              Dia3SizeXY/2,
622              Dia3Thickness/2,                     622              Dia3Thickness/2,
623              0,                                   623              0,
624              360*deg);                            624              360*deg);
625                                                   625   
626                                                   626   
627       logicDia3 = new G4LogicalVolume(solidDia    627       logicDia3 = new G4LogicalVolume(solidDia3,  //its solid
628               Dia3Material, //its material        628               Dia3Material, //its material
629               "Diaphragm3");  //its name          629               "Diaphragm3");  //its name
630                                                   630       
631       zRotPhiDia3.rotateX(AlphaDia3);             631       zRotPhiDia3.rotateX(AlphaDia3);
632       G4double x,y,z;                             632       G4double x,y,z;
633       z = Dia3Dist * std::cos(ThetaDia3);         633       z = Dia3Dist * std::cos(ThetaDia3);
634       y =Dia3Dist * std::sin(ThetaDia3);          634       y =Dia3Dist * std::sin(ThetaDia3);
635       x = 0.*cm;                                  635       x = 0.*cm;
636       physiDia3 = new G4PVPlacement(G4Transfor    636       physiDia3 = new G4PVPlacement(G4Transform3D(zRotPhiDia3,G4ThreeVector(x,y,z)),                                           "Diaphragm3",  //its name
637             logicDia3,  //its logical volume      637             logicDia3,  //its logical volume
638             physiWorld, //its mother  volume      638             physiWorld, //its mother  volume
639             false,    //no boolean operation      639             false,    //no boolean operation
640             0);   //copy number                   640             0);   //copy number
641       }                                           641       }    
642   }                                               642   }
643                                                   643 
644                                                   644   
645                                                   645   
646   // Visualization attributes                     646   // Visualization attributes
647                                                   647   
648   logicWorld->SetVisAttributes (G4VisAttribute    648   logicWorld->SetVisAttributes (G4VisAttributes::GetInvisible());
649   G4VisAttributes* simpleBoxVisAtt= new G4VisA    649   G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
650   G4VisAttributes * yellow= new G4VisAttribute    650   G4VisAttributes * yellow= new G4VisAttributes( G4Colour(255/255. ,255/255. ,51/255. ));
651   G4VisAttributes * red= new G4VisAttributes(     651   G4VisAttributes * red= new G4VisAttributes( G4Colour(255/255. , 0/255. , 0/255. ));
652   G4VisAttributes * blue= new G4VisAttributes(    652   G4VisAttributes * blue= new G4VisAttributes( G4Colour(0/255. , 0/255. ,  255/255. ));
653   G4VisAttributes * grayc= new G4VisAttributes    653   G4VisAttributes * grayc= new G4VisAttributes( G4Colour(128/255. , 128/255. ,  128/255. ));
654   G4VisAttributes * lightGray= new G4VisAttrib    654   G4VisAttributes * lightGray= new G4VisAttributes( G4Colour(178/255. , 178/255. ,  178/255. ));
655   G4VisAttributes * green= new G4VisAttributes    655   G4VisAttributes * green= new G4VisAttributes( G4Colour(0/255. , 255/255. ,  0/255. ));
656                                                   656 
657   yellow->SetVisibility(true);                    657   yellow->SetVisibility(true);
658   yellow->SetForceSolid(true);                    658   yellow->SetForceSolid(true);
659   red->SetVisibility(true);                       659   red->SetVisibility(true);
660   red->SetForceSolid(true);                       660   red->SetForceSolid(true);
661   blue->SetVisibility(true);                      661   blue->SetVisibility(true);
662   green->SetVisibility(true);                     662   green->SetVisibility(true);
663   green->SetForceSolid(true);                     663   green->SetForceSolid(true);
664   grayc->SetVisibility(true);                     664   grayc->SetVisibility(true);
665   grayc->SetForceSolid(true);                     665   grayc->SetForceSolid(true);
666   lightGray->SetVisibility(true);                 666   lightGray->SetVisibility(true);
667   lightGray->SetForceSolid(true);                 667   lightGray->SetForceSolid(true);
668   simpleBoxVisAtt->SetVisibility(true);           668   simpleBoxVisAtt->SetVisibility(true);
669   if (!phaseSpaceFlag) {                          669   if (!phaseSpaceFlag) {  
670     logicPixel->SetVisAttributes(red); //modif    670     logicPixel->SetVisAttributes(red); //modified!!!
671     logicHPGe->SetVisAttributes(blue);            671     logicHPGe->SetVisAttributes(blue);
672                                                   672     
673     logicDia1->SetVisAttributes(lightGray);       673     logicDia1->SetVisAttributes(lightGray);
674     logicDia3->SetVisAttributes(lightGray);       674     logicDia3->SetVisAttributes(lightGray);
675                                                   675     
676     logicOhmicNeg->SetVisAttributes(yellow);      676     logicOhmicNeg->SetVisAttributes(yellow);
677     logicOhmicPos->SetVisAttributes(yellow);      677     logicOhmicPos->SetVisAttributes(yellow);
678                                                   678     
679     logicWindow->SetVisAttributes(green);         679     logicWindow->SetVisAttributes(green);
680                                                   680 
681   }                                               681   }
682   logicSample->SetVisAttributes(simpleBoxVisAt    682   logicSample->SetVisAttributes(simpleBoxVisAtt);
683                                                   683 
684   if (sampleGranularity) logicSample->SetVisAt    684   if (sampleGranularity) logicSample->SetVisAttributes(simpleBoxVisAtt); // mandatory
685                                                   685 
686                                                   686 
687                                                   687 
688   if (sampleGranularity)  logicGrain->SetVisAt    688   if (sampleGranularity)  logicGrain->SetVisAttributes(grayc);
689                                                   689 
690   //always return the physical World              690   //always return the physical World
691                                                   691     
692   PrintApparateParameters();                      692   PrintApparateParameters();
693                                                   693 
694   return physiWorld;                              694   return physiWorld;
695 }                                                 695 }
696                                                   696 
697 //....oooOO0OOooo........oooOO0OOooo........oo    697 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
698                                                   698 
699 void XrayFluoDetectorConstruction::ConstructSD    699 void XrayFluoDetectorConstruction::ConstructSDandField()
700 {                                                 700 {
701   if (!phaseSpaceFlag)                            701   if (!phaseSpaceFlag) 
702     {                                             702     {
703                                                   703 
704       //                                          704       //                               
705       // Sensitive Detectors                      705       // Sensitive Detectors 
706       //                                          706       //
707       if (HPGeSD.Get() == 0)                      707       if (HPGeSD.Get() == 0) 
708   {                                               708   {    
709     XrayFluoSD* SD = new XrayFluoSD ("HPGeSD",    709     XrayFluoSD* SD = new XrayFluoSD ("HPGeSD",this);
710     HPGeSD.Put( SD );                             710     HPGeSD.Put( SD );
711   }                                               711   }
712       G4SDManager::GetSDMpointer()->AddNewDete    712       G4SDManager::GetSDMpointer()->AddNewDetector(HPGeSD.Get());
713       if (logicPixel)                             713       if (logicPixel)    
714   SetSensitiveDetector(logicPixel,HPGeSD.Get()    714   SetSensitiveDetector(logicPixel,HPGeSD.Get());
715     }                                             715     }
716   return;                                         716   return;
717 }                                                 717 }
718                                                   718 
719 //....oooOO0OOooo........oooOO0OOooo........oo    719 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
720                                                   720 
721 void XrayFluoDetectorConstruction::PrintAppara    721 void XrayFluoDetectorConstruction::PrintApparateParameters()
722 {                                                 722 {
723   G4cout << "---------------------------------    723   G4cout << "-----------------------------------------------------------------------"
724    << G4endl                                      724    << G4endl
725    << "The sample is a box whose size is: "       725    << "The sample is a box whose size is: "
726    << G4endl                                      726    << G4endl      
727    << SampleThickness/cm                          727    << SampleThickness/cm
728    << " cm * "                                    728    << " cm * "
729    << SampleSizeXY/cm                             729    << SampleSizeXY/cm
730    << " cm * "                                    730    << " cm * "
731    << SampleSizeXY/cm                             731    << SampleSizeXY/cm
732    << " cm"                                       732    << " cm"
733    << G4endl                                      733    << G4endl
734    <<" Material: " << logicSample->GetMaterial    734    <<" Material: " << logicSample->GetMaterial()->GetName() 
735    <<G4endl;                                      735    <<G4endl;
736   if (!phaseSpaceFlag) {                          736   if (!phaseSpaceFlag) {  
737     G4cout <<"The Detector is a slice  " << De    737     G4cout <<"The Detector is a slice  " << DeviceThickness/(1.e-6*m) <<  " micron thick of " << pixelMaterial->GetName()
738      <<G4endl                                     738      <<G4endl
739      << "The Anode is a slice " << OhmicPosThi    739      << "The Anode is a slice " << OhmicPosThickness/mm << "mm thick of "<< OhmicPosMaterial->GetName()
740      <<G4endl;                                    740      <<G4endl;
741       }                                           741       }
742   G4cout <<"----------------------------------    742   G4cout <<"-------------------------------------------------------------------------"
743    << G4endl;                                     743    << G4endl;
744 }                                                 744 }
745 //....oooOO0OOooo........oooOO0OOooo........oo    745 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
746                                                   746 
747 void XrayFluoDetectorConstruction::UpdateGeome    747 void XrayFluoDetectorConstruction::UpdateGeometry()
748 {                                                 748 {
749   G4GeometryManager::GetInstance()->OpenGeomet    749   G4GeometryManager::GetInstance()->OpenGeometry();
750   G4PhysicalVolumeStore::Clean();                 750   G4PhysicalVolumeStore::Clean();
751   G4LogicalVolumeStore::Clean();                  751   G4LogicalVolumeStore::Clean();
752   G4SolidStore::Clean();                          752   G4SolidStore::Clean();
753                                                   753  
754   if (sampleRegion)                               754   if (sampleRegion) 
755     sampleRegion->RemoveRootLogicalVolume(logi    755     sampleRegion->RemoveRootLogicalVolume(logicSample);
756                                                   756    
757   zRotPhiHPGe.rotateX(-1.*PhiHPGe);               757   zRotPhiHPGe.rotateX(-1.*PhiHPGe);
758   zRotPhiDia1.rotateX(-1.*AlphaDia1);             758   zRotPhiDia1.rotateX(-1.*AlphaDia1);
759   zRotPhiDia3.rotateX(-1.*AlphaDia3);             759   zRotPhiDia3.rotateX(-1.*AlphaDia3);
760                                                   760 
761   //Triggers a new call of Construct() and of     761   //Triggers a new call of Construct() and of all the geometry resets.
762   G4RunManager::GetRunManager()->ReinitializeG    762   G4RunManager::GetRunManager()->ReinitializeGeometry();
763 }                                                 763 }
764                                                   764 
765 //....oooOO0OOooo........oooOO0OOooo........oo    765 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
766                                                   766 
767 void XrayFluoDetectorConstruction::DeleteGrain    767 void XrayFluoDetectorConstruction::DeleteGrainObjects()
768 {                                                 768 {
769   if (sampleGranularity) {                        769   if (sampleGranularity) { 
770     delete solidGrain;                            770     delete solidGrain; 
771     delete logicGrain;                            771     delete logicGrain;
772     delete physiGrain;                            772     delete physiGrain;
773   }                                               773   }
774                                                   774 
775 }                                                 775 }
776                                                   776 
777 //....oooOO0OOooo........oooOO0OOooo........oo    777 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
778                                                   778 
779 G4ThreeVector XrayFluoDetectorConstruction::Ge    779 G4ThreeVector XrayFluoDetectorConstruction::GetDetectorPosition() const
780 {                                                 780 {
781   G4double  z = DistDe * std::cos(ThetaHPGe);     781   G4double  z = DistDe * std::cos(ThetaHPGe);
782   G4double  y = DistDe * std::sin(ThetaHPGe);     782   G4double  y = DistDe * std::sin(ThetaHPGe);
783   G4double  x = 0.*cm;                            783   G4double  x = 0.*cm;
784                                                   784 
785   G4ThreeVector position(x,y,z);                  785   G4ThreeVector position(x,y,z);
786                                                   786 
787   return position;                                787   return position;
788                                                   788 
789 }                                                 789 }
790                                                   790 
791 //....oooOO0OOooo........oooOO0OOooo........oo    791 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
792                                                   792 
793 void XrayFluoDetectorConstruction::SetSampleMa    793 void XrayFluoDetectorConstruction::SetSampleMaterial(G4String newMaterial)
794 {                                                 794 {
795     G4cout << "Material Change in Progress " <    795     G4cout << "Material Change in Progress " << newMaterial << G4endl;
796     sampleMaterial = materials->GetMaterial(ne    796     sampleMaterial = materials->GetMaterial(newMaterial);
797     logicSample->SetMaterial(sampleMaterial);     797     logicSample->SetMaterial(sampleMaterial);
798     PrintApparateParameters();                    798     PrintApparateParameters();
799     //GeometryHasBeenModified is called by the    799     //GeometryHasBeenModified is called by the messenger
800 }                                                 800 }
801                                                   801 
802 //....oooOO0OOooo........oooOO0OOooo........oo    802 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
803                                                   803 
804                                                   804 
805                                                   805 
806                                                   806 
807                                                   807 
808                                                   808 
809                                                   809 
810                                                   810 
811                                                   811 
812                                                   812 
813                                                   813 
814                                                   814