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 9.6.p1)


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