Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-19 07:54:22

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 DetectorConstruction.cc
0027 /// \brief Implementation of the DetectorConstruction class
0028 
0029 #include "DetectorConstruction.hh"
0030 
0031 #include "DetectorMessenger.hh"
0032 
0033 #include "G4Box.hh"
0034 #include "G4Element.hh"
0035 #include "G4LogicalBorderSurface.hh"
0036 #include "G4LogicalSkinSurface.hh"
0037 #include "G4LogicalVolume.hh"
0038 #include "G4Material.hh"
0039 #include "G4NistManager.hh"
0040 #include "G4OpticalSurface.hh"
0041 #include "G4PVPlacement.hh"
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4ThreeVector.hh"
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 
0047 DetectorConstruction::DetectorConstruction()
0048   : G4VUserDetectorConstruction(), fDetectorMessenger(nullptr)
0049 {
0050   fTankMPT = new G4MaterialPropertiesTable();
0051   fWorldMPT = new G4MaterialPropertiesTable();
0052   fSurfaceMPT = new G4MaterialPropertiesTable();
0053 
0054   fSurface = new G4OpticalSurface("Surface");
0055   fSurface->SetType(dielectric_dielectric);
0056   fSurface->SetFinish(ground);
0057   fSurface->SetModel(unified);
0058   fSurface->SetMaterialPropertiesTable(fSurfaceMPT);
0059 
0060   fTankMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER");
0061   fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR");
0062 
0063   fDetectorMessenger = new DetectorMessenger(this);
0064 }
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 
0068 DetectorConstruction::~DetectorConstruction()
0069 {
0070   delete fTankMPT;
0071   delete fWorldMPT;
0072   delete fSurfaceMPT;
0073   delete fSurface;
0074   delete fDetectorMessenger;
0075 }
0076 
0077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0078 
0079 G4VPhysicalVolume* DetectorConstruction::Construct()
0080 {
0081   fTankMaterial->SetMaterialPropertiesTable(fTankMPT);
0082   fTankMaterial->GetIonisation()->SetBirksConstant(0.126 * mm / MeV);
0083 
0084   fWorldMaterial->SetMaterialPropertiesTable(fWorldMPT);
0085 
0086   // ------------- Volumes --------------
0087   // The experimental Hall
0088   auto world_box = new G4Box("World", fExpHall_x, fExpHall_y, fExpHall_z);
0089 
0090   fWorld_LV = new G4LogicalVolume(world_box, fWorldMaterial, "World");
0091 
0092   G4VPhysicalVolume* world_PV =
0093     new G4PVPlacement(nullptr, G4ThreeVector(), fWorld_LV, "World", nullptr, false, 0);
0094 
0095   // The tank
0096   auto tank_box = new G4Box("Tank", fTank_x, fTank_y, fTank_z);
0097 
0098   fTank_LV = new G4LogicalVolume(tank_box, fTankMaterial, "Tank");
0099 
0100   fTank = new G4PVPlacement(nullptr, G4ThreeVector(), fTank_LV, "Tank", fWorld_LV, false, 0);
0101 
0102   // ------------- Surface --------------
0103 
0104   auto surface = new G4LogicalBorderSurface("Surface", fTank, world_PV, fSurface);
0105 
0106   auto opticalSurface =
0107     dynamic_cast<G4OpticalSurface*>(surface->GetSurface(fTank, world_PV)->GetSurfaceProperty());
0108   G4cout << "******  opticalSurface->DumpInfo:" << G4endl;
0109   if (opticalSurface) {
0110     opticalSurface->DumpInfo();
0111   }
0112   G4cout << "******  end of opticalSurface->DumpInfo" << G4endl;
0113 
0114   return world_PV;
0115 }
0116 
0117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0118 void DetectorConstruction::SetSurfaceSigmaAlpha(G4double v)
0119 {
0120   fSurface->SetSigmaAlpha(v);
0121   G4RunManager::GetRunManager()->GeometryHasBeenModified();
0122 
0123   G4cout << "Surface sigma alpha set to: " << fSurface->GetSigmaAlpha() << G4endl;
0124 }
0125 
0126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0127 void DetectorConstruction::SetSurfacePolish(G4double v)
0128 {
0129   fSurface->SetPolish(v);
0130   G4RunManager::GetRunManager()->GeometryHasBeenModified();
0131 
0132   G4cout << "Surface polish set to: " << fSurface->GetPolish() << G4endl;
0133 }
0134 
0135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0136 void DetectorConstruction::AddTankMPV(const G4String& prop, G4MaterialPropertyVector* mpv)
0137 {
0138   fTankMPT->AddProperty(prop, mpv);
0139   G4cout << "The MPT for the box is now: " << G4endl;
0140   fTankMPT->DumpTable();
0141   G4cout << "............." << G4endl;
0142 }
0143 
0144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0145 void DetectorConstruction::AddWorldMPV(const G4String& prop, G4MaterialPropertyVector* mpv)
0146 {
0147   fWorldMPT->AddProperty(prop, mpv);
0148   G4cout << "The MPT for the world is now: " << G4endl;
0149   fWorldMPT->DumpTable();
0150   G4cout << "............." << G4endl;
0151 }
0152 
0153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0154 void DetectorConstruction::AddSurfaceMPV(const G4String& prop, G4MaterialPropertyVector* mpv)
0155 {
0156   fSurfaceMPT->AddProperty(prop, mpv);
0157   G4cout << "The MPT for the surface is now: " << G4endl;
0158   fSurfaceMPT->DumpTable();
0159   G4cout << "............." << G4endl;
0160 }
0161 
0162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0163 void DetectorConstruction::AddTankMPC(const G4String& prop, G4double v)
0164 {
0165   fTankMPT->AddConstProperty(prop, v);
0166   G4cout << "The MPT for the box is now: " << G4endl;
0167   fTankMPT->DumpTable();
0168   G4cout << "............." << G4endl;
0169 }
0170 
0171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0172 void DetectorConstruction::AddWorldMPC(const G4String& prop, G4double v)
0173 {
0174   fWorldMPT->AddConstProperty(prop, v);
0175   G4cout << "The MPT for the world is now: " << G4endl;
0176   fWorldMPT->DumpTable();
0177   G4cout << "............." << G4endl;
0178 }
0179 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0180 void DetectorConstruction::AddSurfaceMPC(const G4String& prop, G4double v)
0181 {
0182   fSurfaceMPT->AddConstProperty(prop, v);
0183   G4cout << "The MPT for the surface is now: " << G4endl;
0184   fSurfaceMPT->DumpTable();
0185   G4cout << "............." << G4endl;
0186 }
0187 
0188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0189 void DetectorConstruction::SetWorldMaterial(const G4String& mat)
0190 {
0191   G4Material* pmat = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0192   if (pmat && fWorldMaterial != pmat) {
0193     fWorldMaterial = pmat;
0194     if (fWorld_LV) {
0195       fWorld_LV->SetMaterial(fWorldMaterial);
0196       fWorldMaterial->SetMaterialPropertiesTable(fWorldMPT);
0197     }
0198     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0199     G4cout << "World material set to " << fWorldMaterial->GetName() << G4endl;
0200   }
0201 }
0202 
0203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0204 void DetectorConstruction::SetTankMaterial(const G4String& mat)
0205 {
0206   G4Material* pmat = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0207   if (pmat && fTankMaterial != pmat) {
0208     fTankMaterial = pmat;
0209     if (fTank_LV) {
0210       fTank_LV->SetMaterial(fTankMaterial);
0211       fTankMaterial->SetMaterialPropertiesTable(fTankMPT);
0212       fTankMaterial->GetIonisation()->SetBirksConstant(0.126 * mm / MeV);
0213     }
0214     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0215     G4cout << "Tank material set to " << fTankMaterial->GetName() << G4endl;
0216   }
0217 }