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.2)


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