Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:57

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/TestEm2/src/DetectorConstruction.cc
0027 /// \brief Implementation of the DetectorConstruction class
0028 //
0029 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0030 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0031 
0032 #include "DetectorConstruction.hh"
0033 
0034 #include "DetectorMessenger.hh"
0035 
0036 #include "G4AutoDelete.hh"
0037 #include "G4GeometryManager.hh"
0038 #include "G4GlobalMagFieldMessenger.hh"
0039 #include "G4LogicalVolume.hh"
0040 #include "G4LogicalVolumeStore.hh"
0041 #include "G4NistManager.hh"
0042 #include "G4PVPlacement.hh"
0043 #include "G4PhysicalVolumeStore.hh"
0044 #include "G4RunManager.hh"
0045 #include "G4SolidStore.hh"
0046 #include "G4SystemOfUnits.hh"
0047 #include "G4Tubs.hh"
0048 #include "G4UnitsTable.hh"
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 DetectorConstruction::DetectorConstruction()
0053 {
0054   DefineMaterials();
0055   SetMaterial("G4_PbWO4");
0056   fDetectorMessenger = new DetectorMessenger(this);
0057 }
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0060 
0061 DetectorConstruction::~DetectorConstruction()
0062 {
0063   delete fDetectorMessenger;
0064 }
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 
0068 void DetectorConstruction::DefineMaterials()
0069 {
0070   //
0071   // define few Elements by hand
0072   //
0073   G4double a, z;
0074 
0075   G4Element* H = new G4Element("Hydrogen", "H", z = 1., a = 1.01 * g / mole);
0076   G4Element* O = new G4Element("Oxygen", "O", z = 8., a = 16.00 * g / mole);
0077   G4Element* Ge = new G4Element("Germanium", "Ge", z = 32., a = 72.59 * g / mole);
0078   G4Element* Bi = new G4Element("Bismuth", "Bi", z = 83., a = 208.98 * g / mole);
0079 
0080   //
0081   // define materials
0082   //
0083   G4double density;
0084   G4int ncomponents, natoms;
0085 
0086   // water with ionisation potential 78 eV
0087   G4Material* H2O = new G4Material("Water", density = 1.00 * g / cm3, ncomponents = 2);
0088   H2O->AddElement(H, natoms = 2);
0089   H2O->AddElement(O, natoms = 1);
0090   H2O->GetIonisation()->SetMeanExcitationEnergy(78.0 * eV);
0091 
0092   // pure materails
0093   new G4Material("liquidArgon", z = 18., a = 39.95 * g / mole, density = 1.390 * g / cm3);
0094   new G4Material("Aluminium", z = 13., a = 26.98 * g / mole, density = 2.7 * g / cm3);
0095   new G4Material("Iron", z = 26., a = 55.85 * g / mole, density = 7.87 * g / cm3);
0096   new G4Material("Copper", z = 29., a = 63.55 * g / mole, density = 8.960 * g / cm3);
0097   new G4Material("Tungsten", z = 74., a = 183.84 * g / mole, density = 19.35 * g / cm3);
0098   new G4Material("Lead", z = 82., a = 207.19 * g / mole, density = 11.35 * g / cm3);
0099   new G4Material("Uranium", z = 92., a = 238.03 * g / mole, density = 18.95 * g / cm3);
0100 
0101   // compound material
0102   G4Material* BGO = new G4Material("BGO", density = 7.10 * g / cm3, ncomponents = 3);
0103   BGO->AddElement(O, natoms = 12);
0104   BGO->AddElement(Ge, natoms = 3);
0105   BGO->AddElement(Bi, natoms = 4);
0106 
0107   ////G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0108 }
0109 
0110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0111 
0112 void DetectorConstruction::UpdateParameters()
0113 {
0114   G4double Radl = fMaterial->GetRadlen();
0115   fDLlength = fDLradl * Radl;
0116   fDRlength = fDRradl * Radl;
0117   fEcalLength = fNLtot * fDLlength;
0118   fEcalRadius = fNRtot * fDRlength;
0119   if (fSolidEcal) {
0120     fSolidEcal->SetOuterRadius(fEcalRadius);
0121     fSolidEcal->SetZHalfLength(0.5 * fEcalLength);
0122   }
0123 }
0124 
0125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0126 
0127 G4VPhysicalVolume* DetectorConstruction::Construct()
0128 {
0129   UpdateParameters();
0130   //
0131   // Ecal
0132   //
0133   if (!fPhysiEcal) {
0134     fSolidEcal = new G4Tubs("Ecal", 0., fEcalRadius, 0.5 * fEcalLength, 0., 360 * deg);
0135     fLogicEcal = new G4LogicalVolume(fSolidEcal, fMaterial, "Ecal", 0, 0, 0);
0136     fPhysiEcal = new G4PVPlacement(0, G4ThreeVector(), fLogicEcal, "Ecal", 0, false, 0);
0137   }
0138   G4cout << "\n Absorber is " << G4BestUnit(fEcalLength, "Length") << " of " << fMaterial->GetName()
0139          << "  R= " << fEcalRadius / cm << " cm \n"
0140          << G4endl;
0141   G4cout << fMaterial << G4endl;
0142   //
0143   // always return the physical World
0144   //
0145   return fPhysiEcal;
0146 }
0147 
0148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0149 
0150 void DetectorConstruction::SetMaterial(const G4String& materialChoice)
0151 {
0152   // search the material by its name
0153   G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0154 
0155   if (pttoMaterial && fMaterial != pttoMaterial) {
0156     fMaterial = pttoMaterial;
0157     if (fLogicEcal) {
0158       fLogicEcal->SetMaterial(fMaterial);
0159     }
0160     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0161   }
0162 }
0163 
0164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0165 
0166 void DetectorConstruction::SetLBining(G4ThreeVector Value)
0167 {
0168   fNLtot = (G4int)Value(0);
0169   if (fNLtot > kMaxBin) {
0170     G4cout << "\n ---> warning from SetLBining: " << fNLtot << " truncated to " << kMaxBin
0171            << G4endl;
0172     fNLtot = kMaxBin;
0173   }
0174   fDLradl = Value(1);
0175   UpdateParameters();
0176 }
0177 
0178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0179 
0180 void DetectorConstruction::SetRBining(G4ThreeVector Value)
0181 {
0182   fNRtot = (G4int)Value(0);
0183   if (fNRtot > kMaxBin) {
0184     G4cout << "\n ---> warning from SetRBining: " << fNRtot << " truncated to " << kMaxBin
0185            << G4endl;
0186     fNRtot = kMaxBin;
0187   }
0188   fDRradl = Value(1);
0189   UpdateParameters();
0190 }
0191 
0192 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0193 
0194 void DetectorConstruction::ConstructSDandField()
0195 {
0196   if (fFieldMessenger.Get() == nullptr) {
0197     // Create global magnetic field messenger.
0198     // Uniform magnetic field is then created automatically if
0199     // the field value is not zero.
0200     G4ThreeVector fieldValue = G4ThreeVector();
0201     G4GlobalMagFieldMessenger* msg = new G4GlobalMagFieldMessenger(fieldValue);
0202     // msg->SetVerboseLevel(1);
0203     G4AutoDelete::Register(msg);
0204     fFieldMessenger.Put(msg);
0205   }
0206 }
0207 
0208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......