Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:51:43

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 /// \file electromagnetic/TestEm14/src/DetectorConstruction.cc
0027 /// \brief Implementation of the DetectorConstruction class
0028 //
0029 // $Id: DetectorConstruction.cc 92996 2015-09-28 08:03:50Z gcosmo $
0030 //
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0033 
0034 #include "DetectorConstruction.hh"
0035 #include "DetectorMessenger.hh"
0036 
0037 #include "G4Material.hh"
0038 #include "G4NistManager.hh"
0039 #include "G4Box.hh"
0040 #include "G4LogicalVolume.hh"
0041 #include "G4PVPlacement.hh"
0042 #include "G4AutoDelete.hh"
0043 #include "G4GeometryManager.hh"
0044 #include "G4PhysicalVolumeStore.hh"
0045 #include "G4LogicalVolumeStore.hh"
0046 #include "G4SolidStore.hh"
0047 #include "G4SDManager.hh"
0048 #include "G4PhysicalConstants.hh"
0049 #include "G4SystemOfUnits.hh"
0050 #include "G4UnitsTable.hh"
0051 #include "G4SystemOfUnits.hh"
0052 #include "G4UserLimits.hh"
0053 #include "G4NistManager.hh"
0054 #include <vector>
0055 #include "G4ProductionCuts.hh"
0056 #include "G4Region.hh"
0057 
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0060 
0061 //vector <G4VPhysicalVolume*> All_Detectors_info;
0062 
0063 DetectorConstruction::DetectorConstruction()
0064 :G4VUserDetectorConstruction(),World_Material(NULL), fSolidWorld(NULL), fLogicWorld(NULL), fPhysiWorld(NULL)
0065 , fLBox(0),fPBox(0), fMaterial(0),detectorMat(NULL), fDetectorMessenger(0)
0066 {
0067   fBoxSize = 1*mm;
0068   fBoxWidth = 1*mm;
0069   fBoxSizeSurface = 0.1*fBoxSize;
0070   fBoxSizeLayer1 = 0.1*fBoxSize;
0071   fBoxSizeLayer2 = 0.1*fBoxSize;
0072   fBoxSizeLayer3 = 0.1*fBoxSize;
0073   fBoxSizeLayer4 = 0.1*fBoxSize;
0074   fWorldSizeX = fBoxSize *5;
0075   fWorldSizeY = fBoxSize *5;
0076   fWorldSizeZ = (fBoxWidth + fBoxSizeLayer4 + fBoxSizeLayer3 + fBoxSizeLayer2 + fBoxSizeLayer1+ fBoxSizeSurface) * 5;
0077   WorldDim = std::max(fWorldSizeX, fWorldSizeZ);
0078   WorldRay = WorldDim / 2;
0079   DetectorRay = WorldRay*0.8;
0080 
0081   DefineMaterials();
0082   SetMaterial("G4_Si");
0083   SetMaterialSurface("G4_Si");
0084   SetMaterialLayer1("G4_Si");
0085   SetMaterialLayer2("G4_Si");
0086   SetMaterialLayer3("G4_Si");
0087   SetMaterialLayer4("G4_Si");
0088 
0089   fDetectorMessenger = new DetectorMessenger(this);
0090 
0091   //pSDTrajectoires = NULL;
0092 }
0093 
0094 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0095 
0096 DetectorConstruction::~DetectorConstruction()
0097 { 
0098     delete fDetectorMessenger;
0099     }
0100 
0101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0102 
0103 G4VPhysicalVolume* DetectorConstruction::Construct()
0104 {
0105     DefineMaterials();
0106     return ConstructVolumes();
0107 }
0108 
0109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0110 
0111 void DetectorConstruction::DefineMaterials()
0112 {
0113   G4double a,z,density,fractionmass;
0114   G4double pressure, temperature;
0115   G4String name,symbol;
0116   G4int nel;
0117 
0118   a=1.01*g/mole;
0119   G4Element *elH=new G4Element(name="Hydrogen",symbol="H",z=1.,a);
0120   a=12.01*g/mole;
0121   G4Element* elB = new G4Element(name = "Boron", symbol = "B", z = 5., a);
0122   a = 10.811 * g / mole;
0123   G4Element *elC=new G4Element(name="Carbon",symbol="C",z=6.,a);
0124   a=14.01*g/mole;
0125   G4Element *elN=new G4Element(name="Nitrogen",symbol="N",z=7.,a);
0126   a=16.*g/mole;
0127   G4Element *elO=new G4Element(name="Oxygen",symbol="O",z=8.,a);
0128   a=28.0855*g/mole;
0129   G4Element* elSi = new G4Element("Silicon", "Si", z=14., a);
0130   a = 47.9 * g / mole;
0131   G4Element* elTi = new G4Element(name = "Titanium", symbol = "Ti", z = 22., a);
0132 
0133   
0134   // G4_SILICON_DIOXIDE and G4_KAPTON forced declaration and present in NIST database
0135   // G4TITANIUM_NITRIDE and G4_BORON_NITRIDE do not exist in the G4 NIST database
0136   My_SiO2 = G4NistManager::Instance()->FindOrBuildMaterial("G4_SILICON_DIOXIDE");
0137   My_Kapton = G4NistManager::Instance()->FindOrBuildMaterial("G4_KAPTON");
0138   My_BN = G4NistManager::Instance()->FindOrBuildMaterial("G4_BORON_NITRIDE");
0139   My_TiN = G4NistManager::Instance()->FindOrBuildMaterial("G4_TITANIUM_NITRIDE");
0140   
0141   if (!My_SiO2) {
0142         density = 2.32*g/cm3;
0143         My_SiO2 = new G4Material("G4_SILICON_DIOXIDE", density, 2);
0144         My_SiO2->AddElement(elSi, 1);
0145         My_SiO2->AddElement(elO , 2);
0146     }
0147   if (!My_Kapton) {
0148         density = 1.42*g/cm3;
0149         My_Kapton = new G4Material(name="G4_KAPTON",density, nel=4);
0150         My_Kapton->AddElement(elH, fractionmass = 0.0273);
0151         My_Kapton->AddElement(elC, fractionmass = 0.7213);
0152         My_Kapton->AddElement(elN, fractionmass = 0.0765);
0153         My_Kapton->AddElement(elO, fractionmass = 0.1749);
0154     }
0155   if (!My_BN) {
0156         density = 2.1 * g / cm3;
0157         My_BN = new G4Material(name = "G4_BORON_NITRIDE", density, nel = 2);
0158         My_BN->AddElement(elB, fractionmass = 0.436);
0159         My_BN->AddElement(elN, fractionmass = 0.564);
0160      } 
0161   if (!My_TiN) {
0162         density = 5.4*g / cm3;
0163         My_TiN = new G4Material(name = "G4_TITANIUM_NITRIDE", density, nel = 2);
0164         My_TiN->AddElement(elTi, fractionmass = 0.7737);
0165         My_TiN->AddElement(elN, fractionmass = 0.2263);
0166      } 
0167 
0168   // Vaccum must be created for MicroElec, should use G4_GALACTIC and changing the name to Vacuum
0169   a = 1.01*g / mole;
0170   pressure = 1.e-19*pascal;
0171   temperature = 0.1*kelvin;
0172   density = universe_mean_density;
0173 
0174   G4Material* Vide = new G4Material(name = "Vacuum", z = 1., a, density, kStateGas, temperature, pressure);
0175 
0176   // LayerX materials, Surface material and Substrate materials are initialized in the detector construction
0177   World_Material = Vide;
0178   detectorMat = Vide;
0179   DefaultMaterial = My_TiN;
0180   fMaterial = My_BN;
0181   fMaterialSurface = G4NistManager::Instance()->FindOrBuildMaterial("G4_Si");
0182   fMaterialLayer1 = G4NistManager::Instance()->FindOrBuildMaterial("G4_Si");
0183   fMaterialLayer2 = G4NistManager::Instance()->FindOrBuildMaterial("G4_Si");
0184   fMaterialLayer3 = G4NistManager::Instance()->FindOrBuildMaterial("G4_Si");
0185   fMaterialLayer4 = G4NistManager::Instance()->FindOrBuildMaterial("G4_Si");
0186 
0187   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0188 }
0189 
0190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0191 
0192 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0193 {
0194   // Cleanup old geometry and spectrum variable
0195   G4GeometryManager::GetInstance()->OpenGeometry();
0196   G4PhysicalVolumeStore::GetInstance()->Clean();
0197   G4LogicalVolumeStore::GetInstance()->Clean();
0198   G4SolidStore::GetInstance()->Clean();
0199   
0200   G4cout << "MicroELec - SEY modellling - Creating geometry" << G4endl;
0201   // world volume                         
0202   fWorldSizeX = fBoxSize * 5;
0203   fWorldSizeY = fBoxSize * 5;
0204   fWorldSizeZ = (fBoxWidth + fBoxSizeLayer4 + fBoxSizeLayer3 + fBoxSizeLayer2 + fBoxSizeLayer1+ fBoxSizeSurface) * 5;
0205   WorldDim = std::max(fWorldSizeX, fWorldSizeZ);
0206   WorldRay = WorldDim / 2;
0207   DetectorRay = WorldRay * 0.8;
0208 
0209   fSolidWorld = new G4Box("World", WorldDim/2.0, WorldDim / 2.0, WorldDim / 2.0);
0210   //fLogicWorld = new G4LogicalVolume(fSolidWorld, World_Material, "World", 0, 0, 0);
0211   fLogicWorld = new G4LogicalVolume(fSolidWorld, World_Material, "World");
0212   fPhysiWorld = new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), "World", fLogicWorld, 0, false, 0);
0213   
0214 
0215   // construct geometry substrate volume 
0216   
0217   fSBox = new G4Box("Substrate",                        //its name
0218       fBoxSize , fBoxSize ,fBoxWidth/2);                //its dimensions
0219 
0220   fLBox = new G4LogicalVolume(fSBox,                    //its shape
0221                                 fMaterial,             //its material
0222                                 "Substrate");          //fMaterial->GetName());    //its name
0223 
0224   fPBox = new G4PVPlacement(0,                         //no rotation
0225                            G4ThreeVector(0.0, (0*fBoxSize), fBoxSizeSurface + fBoxSizeLayer1 + fBoxSizeLayer2 + fBoxSizeLayer3 + fBoxSizeLayer4 + fBoxWidth / 2 ),//(fBoxSize / 2 + fBoxSizeSurface)),            //at (0,0,fBoxSize/2+fBoxSizeSurface)
0226                             "Substrate",                //fMaterial->GetName() its name
0227                             fLBox,                      //its logical volume
0228                             fPhysiWorld,                //its mother  volume
0229                             false,                      //no boolean operation
0230                             0);                         //copy number//*/
0231   
0232 // construct geometry surface volume 
0233   
0234   fSBoxSurface = new G4Box("Surface",                   //its name
0235           fBoxSize , fBoxSize , fBoxSizeSurface / 2);  //its dimensions X & Y leteral dimensions = sBox
0236 
0237   fLBoxSurface = new G4LogicalVolume(fSBoxSurface,                  //its shape
0238                                         fMaterialSurface,           //its material
0239                                         "Surface");                 // fMaterialSurface->GetName());    //its name
0240 
0241   fPBoxSurface = new G4PVPlacement(0,                         //no rotation
0242                                     G4ThreeVector(0.0, 0.0, fBoxSizeSurface/2),            //at (0,0,0) on the top of the sbox surface at Z= 0.
0243                                     "Surface",                  //  fMaterialSurface->GetName(), its name
0244                                     fLBoxSurface,               //its logical volume
0245                                     fPhysiWorld,                //its mother  volume
0246                                     false,                      //no boolean operation
0247                                     0);                         //copy number
0248 
0249   
0250       // construct geometry Layer1 volume 
0251   
0252   fSBoxLayer1 = new G4Box("Layer1",                 //its name
0253           fBoxSize, fBoxSize, fBoxSizeLayer1 / 2);  //its dimensions X & Y leteral dimensions = sBox
0254 
0255   fLBoxLayer1 = new G4LogicalVolume(fSBoxLayer1,               //its shape
0256                                     fMaterialLayer1,           //its material
0257                                     "Layer1");                 // fMaterialSurface->GetName());    //its name
0258 
0259   fPBoxLayer1 = new G4PVPlacement(0,                         //no rotation
0260                                     G4ThreeVector(0.0, 0.0, fBoxSizeSurface + fBoxSizeLayer1 / 2),            //at (0,0,0) on the top of the sbox surface at Z= 0.
0261                                     "Layer1",                   //  fMaterialSurface->GetName(),       //its name
0262                                     fLBoxLayer1,                //its logical volume
0263                                     fPhysiWorld,                //its mother  volume
0264                                     false,                      //no boolean operation
0265                                     0);                         //copy number
0266     // construct geometry Layer2 volume 
0267 
0268   fSBoxLayer2 = new G4Box("Layer2",                 //its name
0269           fBoxSize, fBoxSize, fBoxSizeLayer2 / 2);  //its dimensions X & Y leteral dimensions = sBox
0270 
0271   fLBoxLayer2 = new G4LogicalVolume(fSBoxLayer2,               //its shape
0272                                     fMaterialLayer2,           //its material
0273                                     "Layer2");              // fMaterialSurface->GetName());    //its name
0274 
0275   fPBoxLayer2 = new G4PVPlacement(0,                         //no rotation
0276                                     G4ThreeVector(0.0, 0.0, fBoxSizeSurface + fBoxSizeLayer1 +fBoxSizeLayer2 / 2),            //at (0,0,0) on the top of the sbox surface at Z= 0.
0277                                     "Layer2",                   //fMaterialSurface->GetName(),       //its name
0278                                     fLBoxLayer2,                //its logical volume
0279                                     fPhysiWorld,                //its mother  volume
0280                                     false,                      //no boolean operation
0281                                     0);                         //copy number
0282 
0283     // construct geometry Layer3 volume 
0284   
0285   fSBoxLayer3 = new G4Box("Layer3",                        //its name
0286           fBoxSize, fBoxSize, fBoxSizeLayer3 / 2);         //its dimensions X & Y leteral dimensions = sBox
0287 
0288   fLBoxLayer3 = new G4LogicalVolume(fSBoxLayer3,               //its shape
0289                                     fMaterialLayer3,           //its material
0290                                     "Layer3");              // fMaterialSurface->GetName());    //its name
0291 
0292   fPBoxLayer3 = new G4PVPlacement(0,                         //no rotation
0293                                     G4ThreeVector(0.0, 0.0, fBoxSizeSurface + fBoxSizeLayer1 + fBoxSizeLayer2 + fBoxSizeLayer3 / 2),            //at (0,0,0) on the top of the sbox surface at Z= 0.
0294                                     "Layer3",                   //fMaterialSurface->GetName(),       //its name
0295                                     fLBoxLayer3,                //its logical volume
0296                                     fPhysiWorld,                //its mother  volume
0297                                     false,                      //no boolean operation
0298                                     0);                         //copy number
0299 
0300     // construct geometry Layer4 volume 
0301   
0302   fSBoxLayer4 = new G4Box("Layer4",                        //its name
0303           fBoxSize, fBoxSize, fBoxSizeLayer4 / 2);         //its dimensions X & Y leteral dimensions = sBox
0304 
0305   fLBoxLayer4 = new G4LogicalVolume(fSBoxLayer4,               //its shape
0306                                     fMaterialLayer4,           //its material
0307                                     "Layer4");                 // fMaterialSurface->GetName());    //its name
0308 
0309   fPBoxLayer4 = new G4PVPlacement(0,                         //no rotation
0310                                     G4ThreeVector(0.0, 0.0, fBoxSizeSurface + fBoxSizeLayer1 + fBoxSizeLayer2 + fBoxSizeLayer3 + fBoxSizeLayer4 / 2),            //at (0,0,0) on the top of the sbox surface at Z= 0.
0311                                     "Layer4",                //fMaterialSurface->GetName(),       //its name
0312                                     fLBoxLayer4,             //its logical volume
0313                                     fPhysiWorld,             //its mother  volume
0314                                     false,                   //no boolean operation
0315                                     0);                      //copy number
0316 
0317 
0318 
0319      // ---------------------------- - detector 1
0320      // ----------------------------------------
0321 
0322   Detector_1_box = new G4Sphere("Detector_1", DetectorRay, DetectorRay + 1*angstrom, 0.0, 2.0*3.1415, 0.0, 3.1415);
0323   Detector_1_log = new G4LogicalVolume(Detector_1_box, detectorMat, "Detector_1");
0324   Detector_1_phys = new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), "Detector_1", Detector_1_log, fPhysiWorld, false, 0);//*/
0325 
0326 
0327   fRegion = new G4Region("Target");
0328   G4ProductionCuts* cuts = new G4ProductionCuts();
0329 
0330 
0331   // for detailed transport 
0332   G4double defCut = 1 * nanometer;
0333   cuts->SetProductionCut(defCut, "gamma");
0334   cuts->SetProductionCut(defCut, "e-");
0335   cuts->SetProductionCut(defCut, "e+");
0336   cuts->SetProductionCut(defCut, "proton");
0337 
0338   fRegion->SetProductionCuts(cuts);
0339   fRegion->AddRootLogicalVolume(fLBoxSurface);
0340   fRegion->AddRootLogicalVolume(fLBox);
0341   fRegion->AddRootLogicalVolume(fLBoxLayer1);
0342   fRegion->AddRootLogicalVolume(fLBoxLayer2);
0343   fRegion->AddRootLogicalVolume(fLBoxLayer3);
0344   fRegion->AddRootLogicalVolume(fLBoxLayer4);
0345 
0346 
0347   G4VisAttributes* subVisAtt = new G4VisAttributes(G4Colour(1, 0, 0)); //Red, //subVisAtt->SetForceSolid(true);                                           
0348   fLBoxSurface->SetVisAttributes(subVisAtt);
0349   fLBoxLayer1->SetVisAttributes(subVisAtt);
0350   fLBoxLayer2->SetVisAttributes(subVisAtt);
0351   fLBoxLayer3->SetVisAttributes(subVisAtt);
0352   fLBoxLayer4->SetVisAttributes(subVisAtt);
0353   
0354 
0355   G4VisAttributes* subVisAtt2 = new G4VisAttributes(G4Colour(0, 1, 0)); //green     //subVisAtt->SetForceSolid(true);                                   
0356   fLBox->SetVisAttributes(subVisAtt2); 
0357   
0358   G4VisAttributes* subVisAtt3 = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0)); //White
0359   subVisAtt3->SetVisibility(true);
0360   Detector_1_log->SetVisAttributes(subVisAtt3);
0361 
0362 
0363   G4cout << "MicroELec - SEY modellling - End geometry creation " << G4endl;
0364   PrintParameters();
0365   G4cout << fPhysiWorld->GetLogicalVolume()->GetMaterial()->GetName() << G4endl;
0366   G4cout << fPhysiWorld->GetLogicalVolume()->GetDaughter(0)->GetLogicalVolume()->GetMaterial()->GetName() << G4endl;
0367   return fPhysiWorld;
0368 
0369   //always return the root volume
0370   return fPhysiWorld;
0371 }
0372 
0373 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0374 void DetectorConstruction::ConstructSDandField()
0375 {
0376     // sensitive detectors -----------------------------------------------------
0377     auto sdManager = G4SDManager::GetSDMpointer();
0378     G4String SDname;
0379     
0380     auto MypMicroElecSdSey = new MicroElecSdSey(SDname = "/SdSey", "DetecteurMicroElecSdSey");
0381     sdManager->AddNewDetector(MypMicroElecSdSey);
0382     Detector_1_log->SetSensitiveDetector(MypMicroElecSdSey);
0383     G4cout<<"Sensitive Detector Name : "<<MypMicroElecSdSey->GetName()<<G4endl;
0384 }
0385 
0386 
0387 
0388 
0389 
0390 
0391 
0392 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0393 
0394 void DetectorConstruction::PrintParameters()
0395 {
0396   G4cout << "\n The Box is " << G4BestUnit(fBoxSize,"Length")
0397          << " of " << fMaterial->GetName() << G4endl;
0398 }
0399 
0400 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0401 
0402 #include "G4RunManager.hh"
0403 
0404 void DetectorConstruction::SetMaterial(G4String materialChoice)
0405 {
0406     G4Material* pttoMaterial = nullptr;
0407   // search the material by its name, or build it from nist data base
0408     if (materialChoice == "G4_SiO2"|| materialChoice == "G4_SILICON_DIOXIDE") {
0409         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_SILICON_DIOXIDE");
0410     }
0411     else if (materialChoice == "G4_KAPTON"|| materialChoice == "G4_KAPTON_FILM"|| materialChoice == "Kapton") {
0412         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_KAPTON");
0413     }
0414     else if (materialChoice == "G4_Al2O3"|| materialChoice == "G4_ALUMINUM_OXIDE") {
0415         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_ALUMINUM_OXIDE");
0416     }
0417     else if (materialChoice == "G4_TiN" || materialChoice == "G4_TITANIUM_NITRIDE") {
0418         pttoMaterial = My_TiN;
0419         pttoMaterial->SetName("G4_TITANIUM_NITRIDE");
0420     }
0421     else if (materialChoice == "G4_BN" || materialChoice == "G4_BORON_NITRIDE") {
0422         pttoMaterial = My_BN;
0423         pttoMaterial->SetName("G4_BORON_NITRIDE");
0424     }
0425     else { pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); }
0426 
0427   if (pttoMaterial) {
0428    fMaterial = pttoMaterial;
0429    G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0430   } else {
0431       G4String str = "Material ";
0432       str += materialChoice + " does not exist";
0433       G4Exception("DetectorConstruction::SetMaterial", "em0002", FatalException, str);
0434   } 
0435 }
0436 
0437 void DetectorConstruction::SetMaterialSurface(G4String materialChoice)
0438 {
0439     G4Material* pttoMaterial = nullptr;
0440     // search the material by its name, or build it from nist data base
0441     if (materialChoice == "G4_SiO2"|| materialChoice == "G4_SILICON_DIOXIDE") {
0442         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_SILICON_DIOXIDE");
0443     }
0444     else if (materialChoice == "G4_KAPTON" || materialChoice == "G4_KAPTON_FILM" || materialChoice == "Kapton") {
0445         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_KAPTON");
0446     }
0447     else if (materialChoice == "G4_Al2O3"|| materialChoice == "G4_ALUMINUM_OXIDE") {
0448         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_ALUMINUM_OXIDE");
0449     }
0450     else if (materialChoice == "G4_TiN" || materialChoice == "G4_TITANIUM_NITRIDE") {
0451         pttoMaterial = My_TiN;
0452         pttoMaterial->SetName("G4_TITANIUM_NITRIDE");
0453     }
0454     else if (materialChoice == "G4_BN" || materialChoice == "G4_BORON_NITRIDE") {
0455         pttoMaterial = My_BN;
0456         pttoMaterial->SetName("G4_BORON_NITRIDE");
0457     }
0458     else { pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); }
0459 
0460     if (pttoMaterial) {
0461         fMaterialSurface = pttoMaterial;
0462         G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0463     }
0464     else {
0465         G4String str = "Material ";
0466         str += materialChoice + " does not exist";
0467         G4Exception("DetectorConstruction::SetMaterialSurface", "em0002", FatalException, str);
0468     }
0469 }
0470 
0471 void DetectorConstruction::SetMaterialLayer1(G4String materialChoice)
0472 {
0473     G4Material* pttoMaterial = nullptr;
0474     // search the material by its name, or build it from nist data base
0475     if (materialChoice == "G4_SiO2"|| materialChoice == "G4_SILICON_DIOXIDE") {
0476         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_SILICON_DIOXIDE");
0477     }
0478     else if (materialChoice == "G4_KAPTON" || materialChoice == "G4_KAPTON_FILM" || materialChoice == "Kapton") {
0479         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_KAPTON");
0480     }
0481     else if (materialChoice == "G4_Al2O3"|| materialChoice == "G4_ALUMINUM_OXIDE") {
0482         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_ALUMINUM_OXIDE");
0483     }
0484     else if (materialChoice == "G4_TiN" || materialChoice == "G4_TITANIUM_NITRIDE") {
0485         pttoMaterial = My_TiN;
0486         pttoMaterial->SetName("G4_TITANIUM_NITRIDE");
0487     }
0488     else if (materialChoice == "G4_BN" || materialChoice == "G4_BORON_NITRIDE") {
0489         pttoMaterial = My_BN;
0490         pttoMaterial->SetName("G4_BORON_NITRIDE");
0491     }
0492     else { pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); }
0493 
0494     if (pttoMaterial) {
0495         fMaterialLayer1 = pttoMaterial;
0496         G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0497     }
0498     else {
0499         G4String str = "Material ";
0500         str += materialChoice + " does not exist";
0501         G4Exception("DetectorConstruction::SetMaterialSurface", "em0002", FatalException, str);
0502     }
0503 }
0504 
0505 void DetectorConstruction::SetMaterialLayer2(G4String materialChoice)
0506 {
0507     G4Material* pttoMaterial = nullptr;
0508     // search the material by its name, or build it from nist data base
0509     if (materialChoice == "G4_SiO2"|| materialChoice == "G4_SILICON_DIOXIDE") {
0510         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_SILICON_DIOXIDE");
0511     }
0512     else if (materialChoice == "G4_KAPTON" || materialChoice == "G4_KAPTON_FILM" || materialChoice == "Kapton") {
0513         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_KAPTON");
0514     }
0515     else if (materialChoice == "G4_Al2O3"|| materialChoice == "G4_ALUMINUM_OXIDE") {
0516         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_ALUMINUM_OXIDE");
0517     }
0518     else if (materialChoice == "G4_TiN" || materialChoice == "G4_TITANIUM_NITRIDE") {
0519         pttoMaterial = My_TiN;
0520         pttoMaterial->SetName("G4_TITANIUM_NITRIDE");
0521     }
0522     else if (materialChoice == "G4_BN" || materialChoice == "G4_BORON_NITRIDE") {
0523         pttoMaterial = My_BN;
0524         pttoMaterial->SetName("G4_BORON_NITRIDE");
0525     }
0526     else { pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); }
0527 
0528     if (pttoMaterial) {
0529         fMaterialLayer2 = pttoMaterial;
0530         G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0531     }
0532     else {
0533         G4String str = "Material ";
0534         str += materialChoice + " does not exist";
0535         G4Exception("DetectorConstruction::SetMaterialSurface", "em0002", FatalException, str);
0536     }
0537 }
0538 
0539 void DetectorConstruction::SetMaterialLayer3(G4String materialChoice)
0540 {
0541     G4Material* pttoMaterial = nullptr;
0542     // search the material by its name, or build it from nist data base
0543     if (materialChoice == "G4_SiO2"|| materialChoice == "G4_SILICON_DIOXIDE") {
0544         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_SILICON_DIOXIDE");
0545     }
0546     else if (materialChoice == "G4_KAPTON" || materialChoice == "G4_KAPTON_FILM" || materialChoice == "Kapton") {
0547         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_KAPTON");
0548     }
0549     else if (materialChoice == "G4_Al2O3"|| materialChoice == "G4_ALUMINUM_OXIDE") {
0550         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_ALUMINUM_OXIDE");
0551     }
0552     else if (materialChoice == "G4_TiN" || materialChoice == "G4_TITANIUM_NITRIDE") {
0553         pttoMaterial = My_TiN;
0554         pttoMaterial->SetName("G4_TITANIUM_NITRIDE");
0555     }
0556     else if (materialChoice == "G4_BN" || materialChoice == "G4_BORON_NITRIDE") {
0557         pttoMaterial = My_BN;
0558         pttoMaterial->SetName("G4_BORON_NITRIDE");
0559     }
0560     else { pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); }
0561 
0562     if (pttoMaterial) {
0563         fMaterialLayer3 = pttoMaterial;
0564         G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0565     }
0566     else {
0567         G4String str = "Material ";
0568         str += materialChoice + " does not exist";
0569         G4Exception("DetectorConstruction::SetMaterialSurface", "em0002", FatalException, str);
0570     }
0571 }
0572 
0573 void DetectorConstruction::SetMaterialLayer4(G4String materialChoice)
0574 {
0575     G4Material* pttoMaterial = nullptr;
0576     // search the material by its name, or build it from nist data base
0577     if (materialChoice == "G4_SiO2"|| materialChoice == "G4_SILICON_DIOXIDE") {
0578         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_SILICON_DIOXIDE");
0579     }
0580     else if (materialChoice == "G4_KAPTON" || materialChoice == "G4_KAPTON_FILM" || materialChoice == "Kapton") {
0581         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_KAPTON");
0582     }
0583     else if (materialChoice == "G4_Al2O3"|| materialChoice == "G4_ALUMINUM_OXIDE") {
0584         pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_ALUMINUM_OXIDE");
0585     }
0586     else if (materialChoice == "G4_TiN" || materialChoice == "G4_TITANIUM_NITRIDE") {
0587         pttoMaterial = My_TiN;
0588         pttoMaterial->SetName("G4_TITANIUM_NITRIDE");
0589     }
0590     else if (materialChoice == "G4_BN" || materialChoice == "G4_BORON_NITRIDE") {
0591         pttoMaterial = My_BN;
0592         pttoMaterial->SetName("G4_BORON_NITRIDE");
0593     }
0594     else { pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); }
0595 
0596     if (pttoMaterial) {
0597         fMaterialLayer4 = pttoMaterial;
0598         G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0599     }
0600     else {
0601         G4String str = "Material ";
0602         str += materialChoice + " does not exist";
0603         G4Exception("DetectorConstruction::SetMaterialSurface", "em0002", FatalException, str);
0604     }
0605 }
0606 
0607 
0608 
0609 
0610 void DetectorConstruction::UpdateGeometry()
0611 {
0612     G4cout << "UpdateGeometry Begin" << G4endl;
0613     G4GeometryManager::GetInstance()->OpenGeometry();
0614 
0615     fWorldSizeX = fBoxSize * 5;
0616     fWorldSizeY = fBoxSize * 5;
0617     fWorldSizeZ = (fBoxWidth + fBoxSizeLayer4 + fBoxSizeLayer3 + fBoxSizeLayer2 + fBoxSizeLayer1+ fBoxSizeSurface) * 5;
0618     WorldDim = std::max(fWorldSizeX, fWorldSizeZ);
0619     WorldRay = WorldDim / 2;
0620     DetectorRay = WorldRay * 0.8;
0621     
0622     if (fSolidWorld) {
0623         fSolidWorld->SetXHalfLength(WorldDim / 2);
0624         fSolidWorld->SetYHalfLength(WorldDim / 2);
0625         fSolidWorld->SetZHalfLength(WorldDim / 2);
0626     }
0627 
0628     if (fLBox) { fLBox->SetMaterial(fMaterial);}
0629     if (fLBoxSurface) { fLBoxSurface->SetMaterial(fMaterialSurface); }
0630     if (fLBoxLayer1) { fLBoxLayer1->SetMaterial(fMaterialLayer1); }
0631     if (fLBoxLayer2) { fLBoxLayer2->SetMaterial(fMaterialLayer2); }
0632     if (fLBoxLayer3) { fLBoxLayer3->SetMaterial(fMaterialLayer3); }
0633     if (fLBoxLayer4) { fLBoxLayer4->SetMaterial(fMaterialLayer4); }
0634 
0635     if (fSBox) { 
0636         fSBox->SetZHalfLength(fBoxWidth / 2);
0637         fSBox->SetXHalfLength(fBoxSize / 2);
0638         fSBox->SetYHalfLength(fBoxSize / 2);
0639         fPBox->SetTranslation(G4ThreeVector(0.0, 0.0, fBoxSizeSurface + fBoxSizeLayer1 + fBoxSizeLayer2 + fBoxSizeLayer3 + fBoxSizeLayer4 + fBoxSize / 2));
0640     }
0641     if (fSBoxSurface) { 
0642         fSBoxSurface->SetZHalfLength(fBoxSizeSurface / 2);
0643         fSBoxSurface->SetXHalfLength(fBoxSize / 2);
0644         fSBoxSurface->SetYHalfLength(fBoxSize / 2);
0645         fPBoxSurface->SetTranslation(G4ThreeVector(0.0, 0.0, fBoxSizeSurface / 2));
0646     }
0647     if (fSBoxLayer1) { 
0648         fSBoxLayer1->SetZHalfLength(fBoxSizeLayer1 / 2); 
0649         fSBoxLayer1->SetXHalfLength(fBoxSize / 2);
0650         fSBoxLayer1->SetYHalfLength(fBoxSize / 2);
0651         fPBoxLayer1->SetTranslation(G4ThreeVector(0.0, 0.0, fBoxSizeSurface + fBoxSizeLayer1 / 2));
0652     }
0653     if (fSBoxLayer2) { 
0654         fSBoxLayer2->SetZHalfLength(fBoxSizeLayer2 / 2);
0655         fSBoxLayer2->SetXHalfLength(fBoxSize / 2);
0656         fSBoxLayer2->SetYHalfLength(fBoxSize / 2);
0657         fPBoxLayer2->SetTranslation(G4ThreeVector(0.0, 0.0, fBoxSizeSurface + fBoxSizeLayer1 + fBoxSizeLayer2 / 2));
0658     }
0659     if (fSBoxLayer3) { 
0660         fSBoxLayer3->SetZHalfLength(fBoxSizeLayer3 / 2); 
0661         fSBoxLayer3->SetXHalfLength(fBoxSize / 2);
0662         fSBoxLayer3->SetYHalfLength(fBoxSize / 2);
0663         fPBoxLayer3->SetTranslation(G4ThreeVector(0.0, 0.0, fBoxSizeSurface + fBoxSizeLayer1 + fBoxSizeLayer2 + fBoxSizeLayer3 / 2));
0664     }
0665     if (fSBoxLayer4) {
0666         fSBoxLayer4->SetZHalfLength(fBoxSizeLayer4 / 2);
0667         fSBoxLayer4->SetXHalfLength(fBoxSize / 2);
0668         fSBoxLayer4->SetYHalfLength(fBoxSize / 2);
0669         fPBoxLayer4->SetTranslation(G4ThreeVector(0.0, 0.0, fBoxSizeSurface + fBoxSizeLayer1 + fBoxSizeLayer2 + fBoxSizeLayer3 + fBoxSizeLayer4 / 2));
0670     }
0671     
0672     if (Detector_1_box) {
0673         Detector_1_box->SetInnerRadius(DetectorRay);
0674         Detector_1_box->SetOuterRadius(DetectorRay + 1 * angstrom);
0675     }
0676     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0677     G4RunManager::GetRunManager()->GeometryHasBeenModified();
0678     
0679 
0680     G4cout << "Substrate:" << this->GetMaterial()->GetName()<< ", 4:" << this->GetMaterialLayer4()->GetName() << ", 3:" << this->GetMaterialLayer3()->GetName() << ", 2:" << this->GetMaterialLayer2()->GetName() << ", 1:" << this->GetMaterialLayer1()->GetName() << ", surf:" << this->GetMaterialSurface()->GetName() << G4endl;
0681     G4cout << "Substrate:" << this->GetSize() << ", 4:" << this->GetSizeLayer4()<< ", 3:" << this->GetSizeLayer3() << ", 2:" << this->GetSizeLayer2() << ", 1:" << this->GetSizeLayer1() << ", surf:" << this->GetSizeSurface()<< G4endl;
0682     G4cout << "UpdateGeometry End" << G4endl;
0683 
0684 }
0685 
0686 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0687 
0688 void DetectorConstruction::SetSize(G4double value)
0689 {
0690   fBoxSize = value;
0691 }
0692 
0693 void DetectorConstruction::SetWidth(G4double value)
0694 {
0695     fBoxWidth = value;
0696     //G4RunManager::GetRunManager()->ReinitializeGeometry();
0697 }
0698 
0699 void DetectorConstruction::SetSizeSurface(G4double value)
0700 {
0701     fBoxSizeSurface = value;
0702     //G4RunManager::GetRunManager()->ReinitializeGeometry();
0703 }
0704 
0705 void DetectorConstruction::SetSizeLayer1(G4double value)
0706 {
0707     fBoxSizeLayer1 = value;
0708     //G4RunManager::GetRunManager()->ReinitializeGeometry();
0709 }
0710 void DetectorConstruction::SetSizeLayer2(G4double value)
0711 {
0712     fBoxSizeLayer2 = value;
0713     //G4RunManager::GetRunManager()->ReinitializeGeometry();
0714 }
0715 void DetectorConstruction::SetSizeLayer3(G4double value)
0716 {
0717     fBoxSizeLayer3 = value;
0718     //G4RunManager::GetRunManager()->ReinitializeGeometry();
0719 }
0720 void DetectorConstruction::SetSizeLayer4(G4double value)
0721 {
0722     fBoxSizeLayer4 = value;
0723     //G4RunManager::GetRunManager()->ReinitializeGeometry();
0724 }
0725