Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 08:29:40

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 /////////////////////////////////////////////////////////////////////////
0030 //
0031 // DetectorConstruction
0032 //
0033 // Created: 31.01.2003 V.Ivanchenko
0034 //
0035 // Modified:
0036 // 04.06.2006 Adoptation of Hadr01 (V.Ivanchenko)
0037 //
0038 ////////////////////////////////////////////////////////////////////////
0039 //
0040 
0041 #include "DetectorConstruction.hh"
0042 
0043 #include "CheckVolumeSD.hh"
0044 #include "DetectorMessenger.hh"
0045 #include "HistoManager.hh"
0046 #include "TargetSD.hh"
0047 
0048 #include "G4Colour.hh"
0049 #include "G4GeometryManager.hh"
0050 #include "G4LogicalVolume.hh"
0051 #include "G4LogicalVolumeStore.hh"
0052 #include "G4NistManager.hh"
0053 #include "G4PVPlacement.hh"
0054 #include "G4PhysicalConstants.hh"
0055 #include "G4PhysicalVolumeStore.hh"
0056 #include "G4RunManager.hh"
0057 #include "G4SDManager.hh"
0058 #include "G4SolidStore.hh"
0059 #include "G4SystemOfUnits.hh"
0060 #include "G4Tubs.hh"
0061 #include "G4UnitsTable.hh"
0062 #include "G4VisAttributes.hh"
0063 #include "G4ios.hh"
0064 
0065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0066 
0067 DetectorConstruction::DetectorConstruction()
0068   : G4VUserDetectorConstruction(),
0069     fTargetMaterial(nullptr),
0070     fWorldMaterial(nullptr),
0071     fSolidW(nullptr),
0072     fSolidA(nullptr),
0073     fSolidC(nullptr),
0074     fLogicTarget(nullptr),
0075     fLogicCheck(nullptr),
0076     fLogicWorld(nullptr),
0077     fPhysWorld(nullptr),
0078     fInitialized(false)
0079 {
0080   fDetectorMessenger = new DetectorMessenger(this);
0081   G4NistManager* nist = G4NistManager::Instance();
0082   fTargetMaterial = nist->FindOrBuildMaterial("G4_Al");
0083   fWorldMaterial = nist->FindOrBuildMaterial("G4_Galactic");
0084   //
0085   // define battery material using Bugzilla 2175 data
0086   //
0087   G4Element* elH = nist->FindOrBuildElement(1);
0088   G4Element* elLi = nist->FindOrBuildElement(3);
0089   G4Element* elC = nist->FindOrBuildElement(6);
0090   G4Element* elO = nist->FindOrBuildElement(8);
0091   G4Element* elAl = nist->FindOrBuildElement(13);
0092   G4Element* elTi = nist->FindOrBuildElement(22);
0093   G4Element* elCo = nist->FindOrBuildElement(27);
0094   G4Element* elCu = nist->FindOrBuildElement(29);
0095   G4Material* bat = new G4Material("Battery", 2.165 * CLHEP::g / CLHEP::cm3, 8);
0096   bat->AddElement(elC, 0.19518445618745);
0097   bat->AddElement(elAl, 0.398);
0098   bat->AddElement(elTi, 0.02);
0099   bat->AddElement(elCu, 0.084);
0100   bat->AddElement(elLi, 0.0170098229419813);
0101   bat->AddElement(elCo, 0.144570016541753);
0102   bat->AddElement(elO, 0.134206611504321);
0103   bat->AddElement(elH, 0.0070290928244947);
0104   bat->GetIonisation()->SetMeanExcitationEnergy(144.88 * eV);
0105 
0106   ComputeGeomParameters();
0107 }
0108 
0109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0110 
0111 DetectorConstruction::~DetectorConstruction()
0112 {
0113   delete fDetectorMessenger;
0114 }
0115 
0116 void DetectorConstruction::ComputeGeomParameters()
0117 {
0118   HistoManager* histo = HistoManager::GetPointer();
0119   // Sizes
0120   fRadius = histo->Radius();
0121   fCheckR = fRadius + CLHEP::mm;
0122   fWorldR = fRadius + CLHEP::cm;
0123   fTargetZ = histo->Length() * 0.5;
0124   fCheckZ = fTargetZ + CLHEP::mm;
0125   fWorldZ = fTargetZ + CLHEP::cm;
0126 
0127   fSlices = histo->NumberOfSlices();
0128   fSliceZ = fTargetZ / G4double(fSlices);
0129   if (fPhysWorld) {
0130     fSolidW->SetOuterRadius(fWorldR);
0131     fSolidW->SetZHalfLength(fWorldZ);
0132     fSolidA->SetOuterRadius(fRadius);
0133     fSolidA->SetZHalfLength(fSliceZ);
0134     fSolidC->SetOuterRadius(fCheckR);
0135     fSolidC->SetZHalfLength(fCheckZ);
0136   }
0137 }
0138 
0139 G4VPhysicalVolume* DetectorConstruction::Construct()
0140 {
0141   if (nullptr != fPhysWorld) {
0142     return fPhysWorld;
0143   }
0144   ComputeGeomParameters();
0145 
0146   //
0147   // World
0148   //
0149   fSolidW = new G4Tubs("World", 0., fWorldR, fWorldZ, 0., twopi);
0150   fLogicWorld = new G4LogicalVolume(fSolidW, fWorldMaterial, "World");
0151   fPhysWorld =
0152     new G4PVPlacement(nullptr, G4ThreeVector(0., 0., 0.), fLogicWorld, "World", nullptr, false, 0);
0153   //
0154   // Check volume
0155   //
0156   fSolidC = new G4Tubs("Check", 0., fCheckR, fCheckZ, 0., twopi);
0157   fLogicCheck = new G4LogicalVolume(fSolidC, fWorldMaterial, "Check");
0158   new G4PVPlacement(nullptr, G4ThreeVector(0., 0., 0.), fLogicCheck, "Check", fLogicWorld, false,
0159                     0);
0160 
0161   //
0162   // Target volume
0163   //
0164   fSolidA = new G4Tubs("Target", 0., fRadius, fSliceZ, 0., twopi);
0165   fLogicTarget = new G4LogicalVolume(fSolidA, fTargetMaterial, "Target");
0166 
0167   G4double z = fSliceZ - fTargetZ;
0168 
0169   for (G4int i = 0; i < fSlices; ++i) {
0170     // physC =
0171     new G4PVPlacement(nullptr, G4ThreeVector(0.0, 0.0, z), fLogicTarget, "Target", fLogicCheck,
0172                       false, i);
0173     z += 2.0 * fSliceZ;
0174   }
0175   G4cout << "### Target consist of " << fSlices << " disks of " << fTargetMaterial->GetName()
0176          << " with R(mm)= " << fRadius / mm << "  Width(mm)= " << 2.0 * fSliceZ / mm
0177          << "  Total Length(mm)= " << 2.0 * fTargetZ / mm << "  ###" << G4endl;
0178 
0179   // colors
0180   G4VisAttributes zero = G4VisAttributes::GetInvisible();
0181   fLogicWorld->SetVisAttributes(zero);
0182 
0183   G4VisAttributes regWcolor(G4Colour(0.3, 0.3, 0.3));
0184   fLogicCheck->SetVisAttributes(regWcolor);
0185 
0186   G4VisAttributes regCcolor(G4Colour(0., 0.3, 0.7));
0187   fLogicTarget->SetVisAttributes(regCcolor);
0188 
0189   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0190 
0191   return fPhysWorld;
0192 }
0193 
0194 void DetectorConstruction::ConstructSDandField()
0195 {
0196   if (!fInitialized) {
0197     // Prepare sensitive detectors
0198     CheckVolumeSD* fCheckSD = new CheckVolumeSD("checkSD");
0199     (G4SDManager::GetSDMpointer())->AddNewDetector(fCheckSD);
0200     fLogicCheck->SetSensitiveDetector(fCheckSD);
0201 
0202     TargetSD* fTargetSD = new TargetSD("targetSD");
0203     (G4SDManager::GetSDMpointer())->AddNewDetector(fTargetSD);
0204     fLogicTarget->SetSensitiveDetector(fTargetSD);
0205     fInitialized = true;
0206   }
0207 }
0208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0209 
0210 void DetectorConstruction::SetTargetMaterial(const G4String& mat)
0211 {
0212   // search the material by its name
0213   G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0214 
0215   if (material && material != fTargetMaterial) {
0216     fTargetMaterial = material;
0217     if (fLogicTarget) {
0218       fLogicTarget->SetMaterial(fTargetMaterial);
0219     }
0220     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0221   }
0222 }
0223 
0224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0225 
0226 void DetectorConstruction::SetWorldMaterial(const G4String& mat)
0227 {
0228   // search the material by its name
0229   G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0230 
0231   if (material && material != fWorldMaterial) {
0232     fWorldMaterial = material;
0233     if (fLogicWorld) {
0234       fLogicWorld->SetMaterial(fWorldMaterial);
0235     }
0236     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0237   }
0238 }
0239 
0240 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......