Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:23

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