Geant4  10.02
XrayFluoPlaneDetectorConstruction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: XrayFluoPlaneDetectorConstruction.cc
28 // GEANT4 tag $Name: xray_fluo-V03-02-00
29 //
30 // Author: Alfonso Mantero (Alfonso.Mantero@ge.infn.it)
31 //
32 // History:
33 // -----------
34 // 29 aug 2003 Alfonso Mantero Created
35 // -------------------------------------------------------------------
36 
39 #include "XrayFluoSD.hh"
40 #include "XrayFluoNistMaterials.hh"
41 #include "G4PhysicalConstants.hh"
42 #include "G4SystemOfUnits.hh"
43 #include "G4Material.hh"
44 #include "G4ThreeVector.hh"
45 #include "G4Box.hh"
46 #include "G4Sphere.hh"
47 #include "G4LogicalVolume.hh"
48 #include "G4PVPlacement.hh"
50 #include "G4SDManager.hh"
51 #include "G4RunManager.hh"
52 #include "G4VisAttributes.hh"
53 #include "G4Colour.hh"
54 #include "G4PVReplica.hh"
55 #include "G4UserLimits.hh"
56 #include "G4GeometryManager.hh"
57 #include "G4PhysicalVolumeStore.hh"
58 #include "G4LogicalVolumeStore.hh"
59 #include "G4SolidStore.hh"
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
62 
63 
65  : detectorType(0),planeGranularity(false), DeviceSizeX(0),
66  DeviceSizeY(0),DeviceThickness(0),
67  solidWorld(0),logicWorld(0),physiWorld(0),
68  solidHPGe(0),logicHPGe(0),physiHPGe(0),
69  solidScreen(0),logicScreen(0),physiScreen(0),
70  solidPlane (0),logicPlane(0),physiPlane (0),
71  solidOhmicPos(0),logicOhmicPos(0), physiOhmicPos(0),
72  solidOhmicNeg(0),logicOhmicNeg(0), physiOhmicNeg(0),
73  solidPixel(0),logicPixel(0), physiPixel(0),
74  screenMaterial(0),OhmicPosMaterial(0), OhmicNegMaterial(0),
75  pixelMaterial(0),planeMaterial(0),
76  defaultMaterial(0),HPGeSD(0)
77 
78 {
80 
82 
83  NbOfPixelRows = 1; // should be 1
84  NbOfPixelColumns = 1; // should be 1
86  PixelSizeXY = 5 * cm; // should be 5
87  PixelThickness = 3.5 * mm; //changed should be 3.5 mm
88 
89  G4cout << "PixelThickness(mm): "<< PixelThickness/mm << G4endl;
90  G4cout << "PixelSizeXY(cm): "<< PixelSizeXY/cm << G4endl;
91 
92  ContactSizeXY = 5 * cm; //should be the same as pixelSizeXY
93  planeThickness = 5 * cm;
94  planeSizeXY = 5. * m;
95 
96  OhmicNegThickness = 0.005*mm;
97  OhmicPosThickness = 0.005*mm;
98 
99  screenThickness = 5 * mm;
100 
101  ThetaHPGe = 0. * deg;
102  PhiHPGe = 0. * deg;
103 
104 
105  DistDe = 0.5 * m;
106 
108 
109  grainDia = 1 * mm;
110 
111 
112  PixelCopyNb=0;
113  grainCopyNb=0;
114  G4String defaultDetectorType = "sili";
116  SetDetectorType(defaultDetectorType);
117 
118  // create commands for interactive definition of the apparate
119 
121  G4cout << "XrayFluoPlaneDetectorConstruction created" << G4endl;
122 }
123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
124 
125 
127 
129 {
130  if (instance == 0)
131  {
133 
134  }
135  return instance;
136 }
137 
139 {
140 
141  if (type=="sili")
142  {
144  }
145  else if (type=="hpge")
146  {
148  }
149  else
150  {
152  execp << type + "detector type unknown";
153  G4Exception("XrayFluoPlaneDetectorConstruction::SetDetectorType()","example-xray_fluorescence03",
154  FatalException, execp);
155  }
156 }
157 
158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
159 
161 {
162  return detectorType;
163 }
164 
165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
166 
168 
169 {
170  delete detectorMessenger;
171  delete detectorType;
172  G4cout << "XrayFluoPlaneDetectorConstruction deleted" << G4endl;
173 }
174 
175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
176 
178 {
179  return ConstructApparate();
180 }
181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
182 
184 {
185 
186 
187  //define materials of the apparate
188 
189  planeMaterial = materials->GetMaterial("Anorthosite");
191  pixelMaterial = materials->GetMaterial("G4_Si");
194  defaultMaterial = materials->GetMaterial("G4_Galactic");
195 }
196 
197 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
198 
200 {
201  // complete the apparate parameters definition
202 
203  //ComputeApparateParameters();
204 
205  //world
206 
207  solidWorld = new G4Box("World", //its name
208  WorldSizeXY/2,WorldSizeXY/2,WorldSizeZ/2); //its size
209 
210  logicWorld = new G4LogicalVolume(solidWorld, //its solid
211  defaultMaterial, //its material
212  "World"); //its name
213  physiWorld = new G4PVPlacement(0, //no rotation
214  G4ThreeVector(), //at (0,0,0)
215  "World", //its name
216  logicWorld, //its logical volume
217  0, //its mother volume
218  false, //no boolean operation
219  0); //copy number
220 
221  //detector
222 
223  solidHPGe = 0; physiHPGe = 0; logicHPGe=0;
225 
226  if (DeviceThickness > 0.)
227  {
228  solidHPGe = new G4Box("HPGeDetector", //its name
230 
231 
232  logicHPGe = new G4LogicalVolume(solidHPGe, //its solid
233  defaultMaterial, //its material
234  "HPGeDetector"); //its name
235 
236  zRotPhiHPGe.rotateX(PhiHPGe);
237  G4double x,y,z;
238 
239  z = -1. * DistDe; //* std::cos(ThetaHPGe);
240  y = 0.*cm; //distScreen * std::sin(ThetaHPGe);
241  x = 0.*cm;
242 
244  "HPGeDetector", //its name
245  logicHPGe, //its logical volume
246  physiWorld, //its mother volume
247  false, //no boolean operation
248  0); //copy number
249  }
250  // Pixel
251 
252 
253 
254 
255  for ( G4int j=0; j < NbOfPixelColumns ; j++ )
256  { for ( G4int i=0; i < NbOfPixelRows ; i++ )
257  {
259  if (PixelThickness > 0.)
260  solidPixel = new G4Box("Pixel",
262 
264  pixelMaterial, //its material
265  "Pixel"); //its name
266 
267  /*
268  zRotPhiHPGe.rotateX(PhiHPGe);
269  G4double x,y,z;
270  z = DistDe * std::cos(ThetaHPGe);
271  y =DistDe * std::sin(ThetaHPGe);
272  x = 0.*cm;*/
273  physiPixel = new G4PVPlacement(0,
274  G4ThreeVector(0,
275  i*PixelSizeXY,
276  j*PixelSizeXY ),
277  "Pixel",
278  logicPixel, //its logical volume
279  physiHPGe, //its mother volume
280  false, //no boolean operation
281  PixelCopyNb);//copy number
282 
283 
284 
285 
286 
287 
288  // OhmicNeg
289 
291 
292  if (OhmicNegThickness > 0.)
293  { solidOhmicNeg = new G4Box("OhmicNeg", //its name
294  PixelSizeXY/2,PixelSizeXY/2,OhmicNegThickness/2);
295 
296  logicOhmicNeg = new G4LogicalVolume(solidOhmicNeg, //its solid
297  OhmicNegMaterial, //its material
298  "OhmicNeg"); //its name
299 
302  (0.,
303  0.,
305  "OhmicNeg", //its name
306  logicOhmicNeg, //its logical volume
307  physiHPGe, //its mother
308  false, //no boulean operat
309  PixelCopyNb); //copy number
310 
311  }
312  // OhmicPos
314 
315  if (OhmicPosThickness > 0.)
316  { solidOhmicPos = new G4Box("OhmicPos", //its name
317  PixelSizeXY/2,PixelSizeXY/2,OhmicPosThickness/2);
318 
319  logicOhmicPos = new G4LogicalVolume(solidOhmicPos, //its solid
320  OhmicPosMaterial, //its material
321  "OhmicPos"); //its name
322 
323  physiOhmicPos = new G4PVPlacement(0,
324  G4ThreeVector(0.,
325  0.,
327  "OhmicPos",
329  physiHPGe,
330  false,
331  PixelCopyNb);
332 
333  }
334 
336  G4cout << "PixelCopyNb: " << PixelCopyNb << G4endl;
337  }
338 
339  }
340 
341  // Screen
342 
343  if (DeviceThickness > 0.)
344  {
345  solidScreen = new G4Box("DetectorScreen", //its name
347 
348 
349  logicScreen = new G4LogicalVolume(solidScreen, //its solid
350  defaultMaterial, //its material
351  "DetectorScreen"); //its name
352 
353  //zRotPhiHPGe.rotateX(PhiHPGe);
354  G4double x,y,z;
355  G4cout << "distScreen: "<< distScreen/m <<G4endl;
356  z = -1 * distScreen; //* std::cos(ThetaHPGe);
357  y = 0.*cm; //distScreen * std::sin(ThetaHPGe);
358  x = 0.*cm;
360  "DetectorScreen", //its name
361  logicScreen, //its logical volume
362  physiWorld, //its mother volume
363  false, //no boolean operation
364  0); //copy number
365  }
366 
367  //Plane
368 
369  if (planeGranularity) {
370 
372  if (planeThickness > 0.)
373  {
374  solidPlane = new G4Box("Plane", //its name
376 
377  logicPlane= new G4LogicalVolume(solidPlane, //its solid
378  defaultMaterial, //its material
379  "Plane"); //its name
380 
381  physiPlane = new G4PVPlacement(0, //no rotation
382  G4ThreeVector(), //at (0,0,0)
383  "Plane", //its name
384  logicPlane, //its logical volume
385  physiWorld, //its mother volume
386  false, //no boolean operation
387  0); //copy number
388 
389  }
390 
391 
392 
393 
394  G4int nbOfGrainsX = ((G4int)(planeSizeXY/grainDia)) -1 ;
395 
396  // y dim of a max density plane is 2rn-(n-1)ar, wehere a = (1-(std::sqrt(3)/2)), n is
397  // number of rows and r the radius of the grain. so the Y-dim of the plane must
398  // be greater or equal to this. It results that nmust be <= (PlaneY-a)/(1-a).
399  // Max Y shift of the planes superimposing along Z axis is minor (2/std::sqrt(3)r)
400 
401  G4double a = (1.-(std::sqrt(3.)/2.));
402  G4int nbOfGrainsY = (G4int) ( ((planeSizeXY/(grainDia/2.)) -a)/(2.-a) ) -1;
403 
404  // same for the z axis, but a = 2 * (std::sqrt(3) - std::sqrt(2))/std::sqrt(3)
405 
406  G4double b = 2. * (std::sqrt(3.) - std::sqrt(2.))/std::sqrt(3.);
407  G4int nbOfGrainsZ = (G4int) ( ((planeThickness/(grainDia/2.)) -b)/(2.-b) )-1;
408 
409  if (planeThickness > 0.){
410 
412  solidGrain = new G4Sphere("Grain",0.,
413  grainDia/2,0., twopi, 0., pi);
414 
416  planeMaterial, //its material
417  "Grain"); //its name
418  G4ThreeVector grainPosition;
419  G4double grainInitPositionX = 0;
420  G4double grainInitPositionY = 0;
421  G4double grainInitPositionZ = (-1.*planeThickness/2.+grainDia/2.);
422  G4double grainStepX = grainDia = 0;
423  G4double grainStepY = grainDia*(1.-(0.5-(std::sqrt(3.)/4.)));
424  G4double grainStepZ = grainDia*std::sqrt(2./3.);
425 
426  for ( G4int k=0; k < nbOfGrainsZ ; k++ ) {
427  for ( G4int j=0; j < nbOfGrainsY ; j++ ) {
428  for ( G4int i=0; i < nbOfGrainsX ; i++ ) {
429 
430  // Now we identify the layer and the row where the grain is , to place it in the right position
431 
432 
433 
434  if (k%3 == 0) { // first or (4-multiple)th layer: structure is ABCABC
435  grainInitPositionY = (-1.*planeSizeXY/2.+grainDia/2.);
436  if (j%2 ==0) { //first or (3-multiple)th row
437  grainInitPositionX = (-1.*planeSizeXY/2.+grainDia/2.);
438  }
439 
440  else if ( ((j+1) % 2) == 0 ) {
441  grainInitPositionX = (-1.*planeSizeXY/2.+ grainDia);
442  }
443 
444  }
445  else if ( ((k+2) % 3) == 0 ) { // B-layer
446 
447  grainInitPositionY = ( (-1.*planeSizeXY/2.) + (grainDia/2.)*(1. + (1./std::sqrt(3.)) ) );
448 
449  if (j%2 ==0) { //first or (3-multiple)th row
450  grainInitPositionX = (-1.*planeSizeXY/2.+grainDia);
451  }
452 
453  else if ( (j+1)%2 == 0 ) {
454  grainInitPositionX = (-1.*planeSizeXY/2.+grainDia/2);
455  }
456 
457  }
458 
459  else if ( (k+1)%3 == 0 ) { // B-layer
460 
461  grainInitPositionY = (-1.*planeSizeXY/2.+(grainDia/2.)*(1.+2./std::sqrt(3.)) );
462 
463  if (j%2 ==0) { //first or (3-multiple)th row
464  grainInitPositionX = (-1.*planeSizeXY/2.+grainDia/2.);
465  }
466 
467  else if ( (j+1)%2 == 0 ) {
468  grainInitPositionX = (-1.*planeSizeXY/2.+grainDia);
469  }
470 
471  }
472 
473  physiGrain = new G4PVPlacement(0,
474  G4ThreeVector( grainInitPositionX + i*grainStepX,
475  grainInitPositionY + j*grainStepY,
476  grainInitPositionZ + k*grainStepZ),
477  "Grain",
478  logicGrain, //its logical volume
479  physiPlane, //its mother volume
480  false, //no boolean operation
481  grainCopyNb);//copy number
482 
483  grainCopyNb = grainCopyNb +1;
484  }
485  }
486  }
487  }
488  }
489  else {
490 
492  if (planeThickness > 0.)
493  {
494  solidPlane = new G4Box("Plane", //its name
496 
497  logicPlane= new G4LogicalVolume(solidPlane, //its solid
498  planeMaterial, //its material
499  "Plane"); //its name
500 
501  physiPlane = new G4PVPlacement(0, //no rotation
502  G4ThreeVector(), //at (0,0,0)
503  "Plane", //its name
504  logicPlane, //its logical volume
505  physiWorld, //its mother volume
506  false, //no boolean operation
507  0); //copy number
508 
509  }
510  }
511 
512  // Visualization attributes
513 
515  G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
516  G4VisAttributes * yellow= new G4VisAttributes( G4Colour(255/255. ,255/255. ,51/255. ));
517  G4VisAttributes * red= new G4VisAttributes( G4Colour(255/255. , 0/255. , 0/255. ));
518  G4VisAttributes * blue= new G4VisAttributes( G4Colour(0/255. , 0/255. , 255/255. ));
519  G4VisAttributes * grayc= new G4VisAttributes( G4Colour(128/255. , 128/255. , 128/255. ));
520  G4VisAttributes * lightGray= new G4VisAttributes( G4Colour(178/255. , 178/255. , 178/255. ));
521  yellow->SetVisibility(true);
522  yellow->SetForceSolid(true);
523  red->SetVisibility(true);
524  red->SetForceSolid(true);
525  blue->SetVisibility(true);
526  grayc->SetVisibility(true);
527  grayc->SetForceSolid(true);
528  lightGray->SetVisibility(true);
529  lightGray->SetForceSolid(true);
530  simpleBoxVisAtt->SetVisibility(true);
531 
532  logicPixel->SetVisAttributes(red); //modified!!!
534 
535  logicPlane->SetVisAttributes(lightGray);
536 
537 
541 
542 
543 
545 
546  //always return the physical World
547 
549 
550  return physiWorld;
551 }
552 
553 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...
554 
556 {
557  //
558  // Sensitive Detectors
559  //
560  if (HPGeSD.Get() == 0)
561  {
562  XrayFluoSD* SD = new XrayFluoSD ("HPGeSD",this);
563  HPGeSD.Put( SD );
564  }
565 
566  if (logicPixel)
568 }
569 
570 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
571 
573 {
574  G4cout << "-----------------------------------------------------------------------"
575  << G4endl
576  << "The plane is a box whose size is: "
577  << G4endl
578  << planeThickness/cm
579  << " cm * "
580  << planeSizeXY/cm
581  << " cm * "
582  << planeSizeXY/cm
583  << " cm"
584  << G4endl
585  <<" Material: " << logicPlane->GetMaterial()->GetName()
586  <<G4endl
587  <<"The Detector is a slice " << DeviceThickness/(1.e-6*m) << " micron thick of " << pixelMaterial->GetName()
588  <<G4endl
589 
590 
591 <<"-------------------------------------------------------------------------"
592  << G4endl;
593 }
594 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
595 
597 {
602 
603  zRotPhiHPGe.rotateX(-1.*PhiHPGe);
604  //Triggers a new call of Construct() and of all the geometry resets.
606 }
607 
608 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
609 
611 {
612  if (planeGranularity) {
613  delete solidGrain;
614  delete logicGrain;
615  delete physiGrain;
616  }
617 
618 }
619 
620 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
621 
623 {
624  //G4cout << "Material!!!!" << newMaterial << G4endl;
627  //GeometryHasBeenModified is called by the messenger
628 
629 }
630 
631 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
632 
633 
634 
635 
636 
637 
638 
639 
640 
641 
642 
643 
static const double cm
Definition: G4SIunits.hh:118
Definition: test07.cc:36
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
CLHEP::Hep3Vector G4ThreeVector
G4double z
Definition: TRTMaterials.hh:39
G4Material * GetMaterial() const
Definition: G4Box.hh:64
const G4String & GetName() const
Definition: G4Material.hh:178
void SetVisibility(G4bool)
value_type & Get() const
Definition: G4Cache.hh:282
static void Clean()
Definition: G4SolidStore.cc:79
XrayFluoVDetectorType * GetDetectorType() const
G4double a
Definition: TRTMaterials.hh:39
void SetForceSolid(G4bool)
Definition: test07.cc:36
Definition: test07.cc:36
int G4int
Definition: G4Types.hh:78
static XrayFluoPlaneDetectorConstruction * GetInstance()
static XrayFluoNistMaterials * GetInstance()
static XrayFluoSiLiDetectorType * GetInstance()
G4GLOB_DLL std::ostream G4cout
static const double deg
Definition: G4SIunits.hh:151
XrayFluoPlaneDetectorMessenger * detectorMessenger
static const double twopi
Definition: G4SIunits.hh:75
HepGeom::Transform3D G4Transform3D
static G4GeometryManager * GetInstance()
static XrayFluoPlaneDetectorConstruction * instance
G4Material * GetMaterial(G4String)
void SetSensitiveDetector(const G4String &logVolName, G4VSensitiveDetector *aSD, G4bool multi=false)
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
static const double pi
Definition: G4SIunits.hh:74
const G4double x[NPOINTSGL]
static const G4VisAttributes Invisible
static XrayFluoHPGeDetectorType * GetInstance()
#define G4endl
Definition: G4ios.hh:61
static const double m
Definition: G4SIunits.hh:128
void OpenGeometry(G4VPhysicalVolume *vol=0)
double G4double
Definition: G4Types.hh:76
void SetMaterial(G4Material *pMaterial)
void Put(const value_type &val) const
Definition: G4Cache.hh:286
static const double mm
Definition: G4SIunits.hh:114
void SetVisAttributes(const G4VisAttributes *pVA)