Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:17:09

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 //
0028 // Author: Alfonso Mantero (Alfonso.Mantero@ge.infn.it)
0029 //
0030 // History:
0031 // -----------
0032 // 28 Nov 2001 Elena Guardincerri     Created
0033 //    Nov 2002 Alfonso Mantero materials added, 
0034 //             Material selection implementation
0035 // 16 Jul 2003 Alfonso Mantero Detector type selection added + minor fixes
0036 // -------------------------------------------------------------------
0037 
0038 #include "XrayFluoDetectorConstruction.hh"
0039 #include "XrayFluoDetectorMessenger.hh"
0040 #include "XrayFluoSD.hh"
0041 #include "G4PhysicalConstants.hh"
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4Material.hh"
0044 #include "G4ThreeVector.hh"
0045 #include "G4Box.hh"
0046 #include "G4Sphere.hh"
0047 #include "G4Tubs.hh"
0048 #include "G4LogicalVolume.hh"
0049 #include "G4PVPlacement.hh"
0050 #include "G4TransportationManager.hh"
0051 #include "G4SDManager.hh"
0052 #include "G4RunManager.hh"
0053 #include "G4VisAttributes.hh"
0054 #include "G4Colour.hh"
0055 #include "G4ios.hh"
0056 #include "G4PVReplica.hh"
0057 #include "G4UserLimits.hh"
0058 #include "G4GeometryManager.hh"
0059 #include "G4PhysicalVolumeStore.hh"
0060 #include "G4LogicalVolumeStore.hh"
0061 #include "G4SolidStore.hh"
0062 #include "XrayFluoNistMaterials.hh"
0063 #include "G4SDManager.hh"
0064 
0065 // #include "G4Region.hh"
0066 // #include "G4RegionStore.hh"
0067 
0068 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0069 
0070 
0071 XrayFluoDetectorConstruction::XrayFluoDetectorConstruction()
0072   : aNavigator(0), detectorType(0),sampleGranularity(false), phaseSpaceFlag(false),
0073     DeviceSizeX(0), DeviceSizeY(0),DeviceThickness(0),
0074     solidWorld(0),logicWorld(0),physiWorld(0),
0075     solidHPGe(0),logicHPGe(0),physiHPGe(0),
0076     solidSample (0),logicSample(0),physiSample (0),
0077     solidDia1(0),logicDia1(0),physiDia1(0),
0078     solidDia3(0),logicDia3(0),physiDia3(0),
0079     solidOhmicPos(0),logicOhmicPos(0), physiOhmicPos(0),
0080     solidWindow(0), logicWindow(0), physiWindow(0),
0081     solidOhmicNeg(0),logicOhmicNeg(0), physiOhmicNeg(0),
0082     solidPixel(0),logicPixel(0), physiPixel(0),
0083     OhmicPosMaterial(0), OhmicNegMaterial(0),
0084     pixelMaterial(0),sampleMaterial(0),
0085     Dia1Material(0),Dia3Material(0),
0086     defaultMaterial(0), windowMaterial (0)  
0087 { 
0088   materials = XrayFluoNistMaterials::GetInstance();
0089 
0090   HPGeSD.Put(0);
0091 
0092   aNavigator = new G4Navigator();
0093  
0094   DefineDefaultMaterials();
0095 
0096   NbOfPixelRows     =  1; // should be 1
0097   NbOfPixelColumns  =  1; // should be 1
0098   NbOfPixels        =  NbOfPixelRows*NbOfPixelColumns;
0099   PixelSizeXY       =  std::sqrt(40.) * mm;
0100   PixelThickness = 2.7 * mm; //should be 3.5 mm
0101 
0102   G4cout << "PixelThickness(mm): "<< PixelThickness/mm << G4endl;
0103   G4cout << "PixelSizeXY(cm): "<< PixelSizeXY/cm << G4endl;
0104 
0105   ContactSizeXY     = PixelSizeXY; //std::sqrt(40) * mm; //should be the same as PixelSizeXY
0106   SampleThickness = 4 * mm;
0107   SampleSizeXY = 3. * cm;
0108   Dia1Thickness = 1. *mm;
0109   Dia3Thickness = 1. *mm;
0110   Dia1SizeXY = 3. *cm;
0111   Dia3SizeXY = 3. *cm;
0112 
0113 
0114   DiaInnerSize = 2.9 * cm; //(Hole in the detector's diaphragm) it was 1 mm
0115 
0116 
0117   OhmicNegThickness = 1e-6*cm;// 0.005
0118   OhmicPosThickness = 1e-6*cm;// 0.005
0119   windowThickness = 0.008 * cm; //value for aif detector
0120   ThetaHPGe = 135. * deg;
0121   PhiHPGe = 225. * deg;
0122 
0123   ThetaDia1 = 135. * deg;
0124   PhiDia1 = 90. * deg;
0125   AlphaDia1 = 225. * deg;
0126 
0127   AlphaDia3 = 180. * deg;
0128   Dia3Dist =  66.5 * mm;
0129   Dia3InnerSize = 1. * mm;
0130   ThetaDia3 = 180. * deg;
0131   PhiDia3 = 90. * deg;
0132 
0133   DistDia = 66.5 * mm;
0134   DistDe =DistDia+ (Dia1Thickness
0135             +PixelThickness)/2+OhmicPosThickness+windowThickness ;
0136 
0137   grainDia = 1 * mm;
0138   PixelCopyNb=0;
0139   grainCopyNb=0;
0140   G4String defaultDetectorType = "sili";
0141   ComputeApparateParameters();
0142 
0143 //   G4String regName = "SampleRegion";
0144 //   sampleRegion = new G4Region(regName);  
0145 
0146   if (!phaseSpaceFlag) SetDetectorType(defaultDetectorType);
0147   
0148   // create commands for interactive definition of the apparate
0149   
0150   detectorMessenger = new XrayFluoDetectorMessenger(this);
0151 
0152   G4cout << "XrayFluoDetectorConstruction created" << G4endl;
0153 }
0154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0155 
0156 
0157 XrayFluoDetectorConstruction* XrayFluoDetectorConstruction::instance = 0;
0158 
0159 XrayFluoDetectorConstruction* XrayFluoDetectorConstruction::GetInstance()
0160 {
0161   if (instance == 0)
0162     {
0163       instance = new XrayFluoDetectorConstruction;
0164      
0165     }
0166   return instance;
0167 }
0168 
0169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0170 
0171 void XrayFluoDetectorConstruction::SetDetectorType(G4String type) 
0172 {
0173   if (type=="sili")
0174     {
0175       detectorType = XrayFluoSiLiDetectorType::GetInstance();
0176     }
0177    else if (type=="hpge")
0178      {
0179        detectorType = XrayFluoHPGeDetectorType::GetInstance();
0180     }/*
0181    else if (type=="aifira")
0182      {
0183        detectorType = XrayFluoAifSiLi::GetInstance();
0184        }*/
0185   else 
0186     {
0187       G4ExceptionDescription execp;
0188       execp << type + "detector type unknown";
0189       G4Exception("XrayFluoDataSet::LoadData()","example-xray_fluorescence06",
0190       FatalException, execp);
0191     }
0192   //GeometryHasBeenModified invoked by the messenger
0193   
0194 }
0195 
0196 XrayFluoVDetectorType* XrayFluoDetectorConstruction::GetDetectorType() const
0197 {
0198   return detectorType;
0199 }
0200 
0201 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0202 
0203 XrayFluoDetectorConstruction::~XrayFluoDetectorConstruction()
0204 
0205 { 
0206   delete detectorMessenger;
0207   delete detectorType;
0208   G4cout << "XrayFluoDetectorConstruction deleted" << G4endl;
0209 }
0210 
0211 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0212 
0213 G4VPhysicalVolume* XrayFluoDetectorConstruction::Construct()
0214 {
0215   return ConstructApparate();
0216 }
0217 
0218 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0219 
0220 void XrayFluoDetectorConstruction::DefineDefaultMaterials()
0221 {
0222 
0223 
0224   //define materials of the apparate
0225 
0226   sampleMaterial = materials->GetMaterial("Dolorite");
0227   Dia1Material = materials->GetMaterial("G4_Pb");
0228   Dia3Material = materials->GetMaterial("G4_Galactic");
0229   pixelMaterial = materials->GetMaterial("SiLi");
0230   //OhmicPosMaterial = materials->GetMaterial("G4_Cu");
0231   OhmicPosMaterial = materials->GetMaterial("G4_Ni");
0232   OhmicNegMaterial = materials->GetMaterial("G4_Pb");
0233   defaultMaterial = materials->GetMaterial("G4_Galactic");
0234   windowMaterial = materials->GetMaterial("G4_Be");
0235 }
0236 
0237 void XrayFluoDetectorConstruction::SetOhmicPosThickness(G4double val)
0238 {
0239   
0240   if (!phaseSpaceFlag) {    
0241     
0242     
0243     if (val == 0.0) {
0244       OhmicPosMaterial = materials->GetMaterial("G4_Galactic");
0245     }
0246     else {
0247       OhmicPosThickness = val;
0248       //OhmicPosMaterial = materials->GetMaterial("G4_Cu");
0249       OhmicPosMaterial = materials->GetMaterial("G4_Ni");
0250     }
0251     
0252   }
0253   else{
0254     G4cout << "Not available in this configuration" << G4endl;
0255   }
0256   
0257 }
0258 
0259 
0260 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 
0261 
0262 G4VPhysicalVolume* XrayFluoDetectorConstruction::ConstructApparate()
0263 {
0264   // complete the apparate parameters definition 
0265   
0266   //ComputeApparateParameters();
0267 
0268   //world and associated navigator
0269   
0270   solidWorld = new G4Box("World",                       //its name
0271              WorldSizeXY/2,WorldSizeXY/2,WorldSizeZ/2); //its size
0272   
0273   logicWorld = new G4LogicalVolume(solidWorld,      //its solid
0274                                    defaultMaterial, //its material
0275                                    "World");        //its name
0276   physiWorld = new G4PVPlacement(0,         //no rotation
0277                  G4ThreeVector(),   //at (0,0,0)
0278                  "World",       //its name
0279                  logicWorld,        //its logical volume
0280                  0,         //its mother  volume
0281                  false,         //no boolean operation
0282                  0);            //copy number
0283 
0284   aNavigator->SetWorldVolume(physiWorld);
0285 
0286  
0287   //HPGeDetector
0288 
0289   if (!phaseSpaceFlag) {
0290     
0291     solidHPGe = 0;  physiHPGe = 0;  logicHPGe=0;
0292     solidPixel=0; logicPixel=0; physiPixel=0;
0293     
0294     if (DeviceThickness > 0.)  
0295       {
0296     solidHPGe = new G4Box("HPGeDetector",       //its name
0297                   DeviceSizeX/2,DeviceSizeY/2,DeviceThickness/2);//size
0298     
0299     
0300     logicHPGe = new G4LogicalVolume(solidHPGe,  //its solid
0301                     defaultMaterial,    //its material 
0302                     "HPGeDetector");    //its name
0303     
0304     zRotPhiHPGe.rotateX(PhiHPGe);
0305     G4double x,y,z;
0306     z = DistDe * std::cos(ThetaHPGe);
0307     y =DistDe * std::sin(ThetaHPGe);
0308     x = 0.*cm;
0309     physiHPGe = new G4PVPlacement(G4Transform3D(zRotPhiHPGe,G4ThreeVector(x,y,z)), 
0310                       "HPGeDetector",   //its name
0311                       logicHPGe,    //its logical volume
0312                       physiWorld,   //its mother  volume
0313                       false,        //no boolean operation
0314                       0);       //copy number
0315       }
0316     // Pixel
0317     
0318     
0319     
0320     
0321     for ( G4int j=0; j < NbOfPixelColumns ; j++ )
0322       { for ( G4int i=0; i < NbOfPixelRows ; i++ )
0323     { 
0324       solidPixel=0; logicPixel=0;   physiPixel=0;
0325       if (PixelThickness > 0.)
0326         solidPixel = new G4Box("Pixel",         
0327                    PixelSizeXY/2,PixelSizeXY/2, PixelThickness/2);
0328       
0329       logicPixel = new G4LogicalVolume(solidPixel,  
0330                        pixelMaterial,   //its material
0331                        "Pixel");            //its name
0332       
0333       /*
0334         zRotPhiHPGe.rotateX(PhiHPGe);
0335         G4double x,y,z;
0336         z = DistDe * std::cos(ThetaHPGe);
0337         y =DistDe * std::sin(ThetaHPGe);
0338         x = 0.*cm;*/ 
0339       physiPixel = new G4PVPlacement(0,        
0340                      G4ThreeVector(0,
0341                                i*PixelSizeXY, 
0342                                j*PixelSizeXY ),
0343                      "Pixel",  
0344                      logicPixel,     //its logical volume
0345                      physiHPGe, //its mother  volume
0346                      false,  //no boolean operation
0347                      PixelCopyNb);//copy number
0348       
0349       
0350       
0351       
0352       
0353       
0354       // OhmicNeg
0355       
0356       solidOhmicNeg=0; logicOhmicNeg=0; physiOhmicNeg=0;  
0357       
0358       if (OhmicNegThickness > 0.) 
0359         { solidOhmicNeg = new G4Box("OhmicNeg",     //its name
0360                     PixelSizeXY/2,PixelSizeXY/2,OhmicNegThickness/2); 
0361         
0362         logicOhmicNeg = new G4LogicalVolume(solidOhmicNeg,    //its solid
0363                         OhmicNegMaterial, //its material
0364                         "OhmicNeg");      //its name
0365         
0366         physiOhmicNeg = new G4PVPlacement(0,
0367                           G4ThreeVector
0368                           (0.,
0369                            0.,
0370                            (PixelThickness+OhmicNegThickness)/2),
0371                           "OhmicNeg",        //its name
0372                           logicOhmicNeg,     //its logical volume
0373                           physiHPGe,        //its mother
0374                           false,             //no boulean operat
0375                           PixelCopyNb);                //copy number
0376         
0377         }
0378       // OhmicPos
0379       solidOhmicPos=0; logicOhmicPos=0; physiOhmicPos=0;  
0380       
0381       if (OhmicPosThickness > 0.) 
0382         { solidOhmicPos = new G4Box("OhmicPos",     //its name
0383                     PixelSizeXY/2,PixelSizeXY/2,OhmicPosThickness/2); 
0384         
0385         logicOhmicPos = new G4LogicalVolume(solidOhmicPos,    //its solid
0386                         OhmicPosMaterial, //its material
0387                         "OhmicPos");      //its name
0388         
0389         physiOhmicPos = new G4PVPlacement(0,    
0390                           G4ThreeVector(0.,
0391                                 0.,
0392                                 (-PixelThickness-OhmicPosThickness)/2),  
0393                           "OhmicPos",  
0394                           logicOhmicPos,
0395                           physiHPGe,  
0396                           false,     
0397                           PixelCopyNb); 
0398         
0399         }
0400 
0401       /////////// widow place here! ////////////////
0402       // OhmicPos
0403       solidWindow=0; logicWindow=0; physiWindow=0;  
0404       
0405       if (windowThickness > 0.) 
0406         { solidWindow = new G4Box("Window",     //its name
0407                     PixelSizeXY/2,PixelSizeXY/2,windowThickness/2); 
0408         
0409         logicWindow = new G4LogicalVolume(solidWindow,    //its solid
0410                         windowMaterial, //its material
0411                         "Window");      //its name
0412         
0413         physiWindow = new G4PVPlacement(0,  
0414                           G4ThreeVector(0.,
0415                                 0.,
0416                                 ((-PixelThickness-windowThickness)/2)
0417                                 -OhmicPosThickness),  
0418                           "OhmicWindow",  
0419                           logicWindow,
0420                           physiHPGe,  
0421                           false,     
0422                           PixelCopyNb); 
0423         
0424         }
0425 
0426 
0427     
0428       PixelCopyNb += PixelCopyNb; 
0429       G4cout << "PixelCopyNb: " << PixelCopyNb << G4endl;
0430     }
0431       
0432       }
0433     
0434   }
0435   
0436   //Sample
0437   
0438   if (sampleGranularity) {
0439 
0440     solidSample=0;  logicSample=0;  physiSample=0;
0441     if (SampleThickness > 0.)  
0442       {
0443     solidSample = new G4Box("Sample",       //its name
0444                 SampleSizeXY/2,SampleSizeXY/2,SampleThickness/2);//size
0445     
0446     logicSample= new G4LogicalVolume(solidSample,   //its solid
0447                      defaultMaterial,   //its material
0448                      "Sample"); //its name
0449     
0450     physiSample = new G4PVPlacement(0,          //no rotation
0451                     G4ThreeVector(),    //at (0,0,0)
0452                     "Sample",   //its name
0453                     logicSample,    //its logical volume
0454                     physiWorld, //its mother  volume
0455                     false,      //no boolean operation
0456                     0);     //copy number
0457     
0458       }
0459 
0460 
0461 
0462 
0463     G4int nbOfGrainsX = ((G4int)(SampleSizeXY/grainDia)) -1 ;
0464     
0465     // y dim of a max density plane is 2rn-(n-1)ar, wehere a = (1-(std::sqrt(3)/2)), n is 
0466     // number of rows and r the radius of the grain. so the Y-dim of the sample must 
0467     // be greater or equal to this. It results that nmust be <= (SampleY-a)/(1-a).
0468     // Max Y shift of the planes superimposing along Z axis is minor (2/std::sqrt(3)r)
0469 
0470     G4double a = (1.-(std::sqrt(3.)/2.));
0471     G4int nbOfGrainsY =  (G4int) ( ((SampleSizeXY/(grainDia/2.)) -a)/(2.-a) ) -1;
0472 
0473     // same for the z axis, but a = 2 * (std::sqrt(3) - std::sqrt(2))/std::sqrt(3)
0474 
0475     G4double b = 2. * (std::sqrt(3.) - std::sqrt(2.))/std::sqrt(3.);
0476     G4int nbOfGrainsZ =  (G4int) ( ((SampleThickness/(grainDia/2.)) -b)/(2.-b) )-1;
0477 
0478     if (SampleThickness > 0.){
0479       
0480       solidGrain=0; logicGrain=0; physiGrain=0;
0481       solidGrain = new G4Sphere("Grain",0.,         
0482                 grainDia/2,0., twopi, 0., pi);
0483       
0484       logicGrain = new G4LogicalVolume(solidGrain,  
0485                        sampleMaterial,  //its material
0486                        "Grain");            //its name
0487       G4ThreeVector grainPosition; 
0488       G4double grainInitPositionX = 0;
0489       G4double grainInitPositionY = 0;
0490       G4double grainInitPositionZ = (-1.*SampleThickness/2.+grainDia/2.);
0491       G4double grainStepX = grainDia = 0;
0492       G4double grainStepY = grainDia*(1.-(0.5-(std::sqrt(3.)/4.)));
0493       G4double grainStepZ = grainDia*std::sqrt(2./3.);
0494       
0495       for ( G4int k=0; k < nbOfGrainsZ ; k++ ) {
0496     for ( G4int j=0; j < nbOfGrainsY ; j++ ) {
0497       for ( G4int i=0; i < nbOfGrainsX ; i++ ) {
0498         
0499         // Now we identify the layer and the row where the grain is , to place it in the right position
0500         
0501         
0502         
0503         if (k%3 == 0) { // first or (4-multiple)th layer: structure is ABCABC
0504           grainInitPositionY = (-1.*SampleSizeXY/2.+grainDia/2.);    
0505           if (j%2 ==0) { //first or (3-multiple)th row
0506         grainInitPositionX = (-1.*SampleSizeXY/2.+grainDia/2.);
0507           }
0508           
0509           else if ( ((j+1) % 2)  == 0 ) {
0510         grainInitPositionX = (-1.*SampleSizeXY/2.+ grainDia);       
0511           }
0512           
0513         }         
0514         else if ( ((k+2) % 3) == 0 ) { // B-layer
0515           
0516           grainInitPositionY = ( (-1.*SampleSizeXY/2.) + (grainDia/2.)*(1. + (1./std::sqrt(3.)) ) );
0517           
0518           if (j%2 ==0) { //first or (3-multiple)th row
0519         grainInitPositionX = (-1.*SampleSizeXY/2.+grainDia);
0520           }
0521           
0522           else if ( (j+1)%2  == 0 ) {
0523         grainInitPositionX = (-1.*SampleSizeXY/2.+grainDia/2);      
0524           }
0525           
0526         }
0527         
0528         else if ( (k+1)%3 == 0 ) { // B-layer
0529           
0530           grainInitPositionY = (-1.*SampleSizeXY/2.+(grainDia/2.)*(1.+2./std::sqrt(3.)) );
0531           
0532           if (j%2 ==0) { //first or (3-multiple)th row
0533         grainInitPositionX = (-1.*SampleSizeXY/2.+grainDia/2.);
0534           }
0535           
0536           else if ( (j+1)%2  == 0 ) {
0537         grainInitPositionX = (-1.*SampleSizeXY/2.+grainDia);        
0538           }
0539           
0540         }
0541         
0542         physiGrain = new G4PVPlacement(0,          
0543                        G4ThreeVector( grainInitPositionX + i*grainStepX, 
0544                               grainInitPositionY + j*grainStepY,
0545                               grainInitPositionZ + k*grainStepZ),
0546                        "Grain",  
0547                        logicGrain,   //its logical volume
0548                        physiSample, //its mother  volume
0549                        false,    //no boolean operation
0550                        grainCopyNb);//copy number    
0551         
0552         grainCopyNb = grainCopyNb +1; 
0553       }
0554     }
0555       }
0556     }    
0557   }
0558   else {     
0559       
0560     solidSample=0;  logicSample=0;  physiSample=0;
0561     if (SampleThickness > 0.)  
0562       {
0563     solidSample = new G4Box("Sample",       //its name
0564                 SampleSizeXY/2,SampleSizeXY/2,SampleThickness/2);//size
0565       
0566     logicSample= new G4LogicalVolume(solidSample,   //its solid
0567                      sampleMaterial,    //its material
0568                      "Sample"); //its name
0569       
0570     physiSample = new G4PVPlacement(0,          //no rotation
0571                     G4ThreeVector(),    //at (0,0,0)
0572                     "Sample",   //its name
0573                     logicSample,    //its logical volume
0574                     physiWorld, //its mother  volume
0575                     false,      //no boolean operation
0576                     0);     //copy number
0577       
0578       }  
0579   }
0580 
0581   if (!phaseSpaceFlag) {    
0582     //Diaphragm1
0583     
0584     solidDia1 = 0;  physiDia1 = 0;  logicDia1=0;
0585     
0586     if (Dia1Thickness > 0.)  
0587       {
0588     solidDia1 = new G4Tubs("Diaphragm1",        //its name
0589                    DiaInnerSize/2,
0590                    Dia1SizeXY/2,
0591                    Dia1Thickness/2,
0592                    0,
0593                    360*deg);//size
0594     
0595     
0596     logicDia1 = new G4LogicalVolume(solidDia1,  //its solid
0597                     Dia1Material,   //its material
0598                     "Diaphragm1");  //its name
0599     
0600     zRotPhiDia1.rotateX(AlphaDia1);
0601     G4double x,y,z;
0602     z = DistDia * std::cos(ThetaDia1);
0603     y =DistDia * std::sin(ThetaDia1);
0604     x = 0.*cm;
0605     physiDia1 = new G4PVPlacement(G4Transform3D(zRotPhiDia1,G4ThreeVector(x,y,z)),
0606                       "Diaphragm1", //its name
0607                       logicDia1,    //its logical volume
0608                       physiWorld,   //its mother  volume
0609                       false,        //no boolean operation
0610                       0);       //copy number
0611       }  
0612     
0613     //Diaphragm3
0614     
0615     solidDia3 = 0;  physiDia3 = 0;  logicDia3 =0;
0616     
0617     if (Dia3Thickness > 0.)  
0618       {
0619     solidDia3 = new G4Tubs("Diaphragm3",
0620                    Dia3InnerSize/2,
0621                    Dia3SizeXY/2,
0622                    Dia3Thickness/2,
0623                    0,
0624                    360*deg);
0625     
0626     
0627       logicDia3 = new G4LogicalVolume(solidDia3,    //its solid
0628                       Dia3Material, //its material
0629                       "Diaphragm3");    //its name
0630       
0631       zRotPhiDia3.rotateX(AlphaDia3);
0632       G4double x,y,z;
0633       z = Dia3Dist * std::cos(ThetaDia3);
0634       y =Dia3Dist * std::sin(ThetaDia3);
0635       x = 0.*cm;
0636       physiDia3 = new G4PVPlacement(G4Transform3D(zRotPhiDia3,G4ThreeVector(x,y,z)),                                           "Diaphragm3",    //its name
0637                     logicDia3,  //its logical volume
0638                     physiWorld, //its mother  volume
0639                     false,      //no boolean operation
0640                     0);     //copy number
0641       }    
0642   }
0643 
0644   
0645   
0646   // Visualization attributes
0647   
0648   logicWorld->SetVisAttributes (G4VisAttributes::GetInvisible());
0649   G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
0650   G4VisAttributes * yellow= new G4VisAttributes( G4Colour(255/255. ,255/255. ,51/255. ));
0651   G4VisAttributes * red= new G4VisAttributes( G4Colour(255/255. , 0/255. , 0/255. ));
0652   G4VisAttributes * blue= new G4VisAttributes( G4Colour(0/255. , 0/255. ,  255/255. ));
0653   G4VisAttributes * grayc= new G4VisAttributes( G4Colour(128/255. , 128/255. ,  128/255. ));
0654   G4VisAttributes * lightGray= new G4VisAttributes( G4Colour(178/255. , 178/255. ,  178/255. ));
0655   G4VisAttributes * green= new G4VisAttributes( G4Colour(0/255. , 255/255. ,  0/255. ));
0656 
0657   yellow->SetVisibility(true);
0658   yellow->SetForceSolid(true);
0659   red->SetVisibility(true);
0660   red->SetForceSolid(true);
0661   blue->SetVisibility(true);
0662   green->SetVisibility(true);
0663   green->SetForceSolid(true);
0664   grayc->SetVisibility(true);
0665   grayc->SetForceSolid(true);
0666   lightGray->SetVisibility(true);
0667   lightGray->SetForceSolid(true);
0668   simpleBoxVisAtt->SetVisibility(true);
0669   if (!phaseSpaceFlag) {  
0670     logicPixel->SetVisAttributes(red); //modified!!!
0671     logicHPGe->SetVisAttributes(blue);
0672     
0673     logicDia1->SetVisAttributes(lightGray);
0674     logicDia3->SetVisAttributes(lightGray);
0675     
0676     logicOhmicNeg->SetVisAttributes(yellow);
0677     logicOhmicPos->SetVisAttributes(yellow);
0678     
0679     logicWindow->SetVisAttributes(green);
0680 
0681   }
0682   logicSample->SetVisAttributes(simpleBoxVisAtt);
0683 
0684   if (sampleGranularity) logicSample->SetVisAttributes(simpleBoxVisAtt); // mandatory
0685 
0686 
0687 
0688   if (sampleGranularity)  logicGrain->SetVisAttributes(grayc);
0689 
0690   //always return the physical World
0691     
0692   PrintApparateParameters();
0693 
0694   return physiWorld;
0695 }
0696 
0697 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0698 
0699 void XrayFluoDetectorConstruction::ConstructSDandField()
0700 {
0701   if (!phaseSpaceFlag) 
0702     {
0703 
0704       //                               
0705       // Sensitive Detectors 
0706       //
0707       if (HPGeSD.Get() == 0) 
0708     {    
0709       XrayFluoSD* SD = new XrayFluoSD ("HPGeSD",this);
0710       HPGeSD.Put( SD );
0711     }
0712       G4SDManager::GetSDMpointer()->AddNewDetector(HPGeSD.Get());
0713       if (logicPixel)    
0714     SetSensitiveDetector(logicPixel,HPGeSD.Get());
0715     }
0716   return;
0717 }
0718 
0719 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0720 
0721 void XrayFluoDetectorConstruction::PrintApparateParameters()
0722 {
0723   G4cout << "-----------------------------------------------------------------------"
0724      << G4endl
0725      << "The sample is a box whose size is: "
0726      << G4endl      
0727      << SampleThickness/cm
0728      << " cm * "
0729      << SampleSizeXY/cm
0730      << " cm * "
0731      << SampleSizeXY/cm
0732      << " cm"
0733      << G4endl
0734      <<" Material: " << logicSample->GetMaterial()->GetName() 
0735      <<G4endl;
0736   if (!phaseSpaceFlag) {  
0737     G4cout <<"The Detector is a slice  " << DeviceThickness/(1.e-6*m) <<  " micron thick of " << pixelMaterial->GetName()
0738        <<G4endl
0739        << "The Anode is a slice " << OhmicPosThickness/mm << "mm thick of "<< OhmicPosMaterial->GetName()
0740        <<G4endl;
0741       }
0742   G4cout <<"-------------------------------------------------------------------------"
0743      << G4endl;
0744 }
0745 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0746 
0747 void XrayFluoDetectorConstruction::UpdateGeometry()
0748 {
0749   G4GeometryManager::GetInstance()->OpenGeometry();
0750   G4PhysicalVolumeStore::Clean();
0751   G4LogicalVolumeStore::Clean();
0752   G4SolidStore::Clean();
0753  
0754   if (sampleRegion) 
0755     sampleRegion->RemoveRootLogicalVolume(logicSample);
0756    
0757   zRotPhiHPGe.rotateX(-1.*PhiHPGe);
0758   zRotPhiDia1.rotateX(-1.*AlphaDia1);
0759   zRotPhiDia3.rotateX(-1.*AlphaDia3);
0760 
0761   //Triggers a new call of Construct() and of all the geometry resets.
0762   G4RunManager::GetRunManager()->ReinitializeGeometry();
0763 }
0764 
0765 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0766 
0767 void XrayFluoDetectorConstruction::DeleteGrainObjects()
0768 {
0769   if (sampleGranularity) { 
0770     delete solidGrain; 
0771     delete logicGrain;
0772     delete physiGrain;
0773   }
0774 
0775 }
0776 
0777 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0778 
0779 G4ThreeVector XrayFluoDetectorConstruction::GetDetectorPosition() const
0780 {
0781   G4double  z = DistDe * std::cos(ThetaHPGe);
0782   G4double  y = DistDe * std::sin(ThetaHPGe);
0783   G4double  x = 0.*cm;
0784 
0785   G4ThreeVector position(x,y,z);
0786 
0787   return position;
0788 
0789 }
0790 
0791 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0792 
0793 void XrayFluoDetectorConstruction::SetSampleMaterial(G4String newMaterial)
0794 {
0795     G4cout << "Material Change in Progress " << newMaterial << G4endl;
0796     sampleMaterial = materials->GetMaterial(newMaterial);
0797     logicSample->SetMaterial(sampleMaterial);
0798     PrintApparateParameters();
0799     //GeometryHasBeenModified is called by the messenger
0800 }
0801 
0802 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0803 
0804 
0805 
0806 
0807 
0808 
0809 
0810 
0811 
0812 
0813