Back to home page

EIC code displayed by LXR

 
 

    


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

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/TestEm16/src/DetectorConstruction.cc
0027 /// \brief Implementation of the DetectorConstruction class
0028 //
0029 //
0030 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 
0033 #include "DetectorConstruction.hh"
0034 
0035 #include "DetectorMessenger.hh"
0036 
0037 #include "G4Box.hh"
0038 #include "G4GDMLParser.hh"
0039 #include "G4GeometryManager.hh"
0040 #include "G4LogicalVolume.hh"
0041 #include "G4LogicalVolumeStore.hh"
0042 #include "G4Material.hh"
0043 #include "G4PVPlacement.hh"
0044 #include "G4PhysicalVolumeStore.hh"
0045 #include "G4PropagatorInField.hh"
0046 #include "G4RunManager.hh"
0047 #include "G4SolidStore.hh"
0048 #include "G4SystemOfUnits.hh"
0049 #include "G4TransportationManager.hh"
0050 #include "G4UnitsTable.hh"
0051 #include "G4UserLimits.hh"
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 DetectorConstruction::DetectorConstruction() : G4VUserDetectorConstruction(), fBoxSize(500 * m)
0056 {
0057   DefineMaterials();
0058   SetMaterial("Iron");
0059 
0060   // create UserLimits
0061   fUserLimits = new G4UserLimits();
0062 
0063   // create commands for interactive definition of the detector
0064   fDetectorMessenger = new DetectorMessenger(this);
0065 }
0066 
0067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0068 
0069 G4VPhysicalVolume* DetectorConstruction::Construct()
0070 {
0071   return ConstructVolumes();
0072 }
0073 
0074 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0075 
0076 void DetectorConstruction::DefineMaterials()
0077 {
0078   G4double a, z, density;
0079 
0080   new G4Material("Beryllium", z = 4., a = 9.012182 * g / mole, density = 1.848 * g / cm3);
0081   new G4Material("Carbon", z = 6., a = 12.011 * g / mole, density = 2.265 * g / cm3);
0082   new G4Material("Iron", z = 26., a = 55.85 * g / mole, density = 7.870 * g / cm3);
0083 
0084   // define a vacuum with a restgas pressure  typical for accelerators
0085   G4double const Torr = atmosphere / 760.;  // 1 Torr
0086   G4double pressure = 10e-9 * Torr,
0087            temperature = 296.150 * kelvin;  // 23  Celsius
0088   new G4Material("Vacuum", z = 7., a = 14.01 * g / mole, density = 1.516784e-11 * kg / m3,
0089                  kStateGas, temperature, pressure);
0090   G4cout << *(G4Material::GetMaterialTable()) << G4endl;  // print the materials defined
0091 }
0092 
0093 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0094 
0095 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0096 {
0097   G4GeometryManager::GetInstance()->OpenGeometry();
0098   G4PhysicalVolumeStore::GetInstance()->Clean();
0099   G4LogicalVolumeStore::GetInstance()->Clean();
0100   G4SolidStore::GetInstance()->Clean();
0101 
0102   if (fGeomFileName == G4String()) {
0103     auto sBox = new G4Box("Container", fBoxSize / 2, fBoxSize / 2, fBoxSize / 2);
0104     fLBox = new G4LogicalVolume(sBox, fMaterial, fMaterial->GetName());
0105     fLBox->SetUserLimits(fUserLimits);
0106     fBox = new G4PVPlacement(0, G4ThreeVector(), fLBox, fMaterial->GetName(), 0, false, 0);
0107     PrintParameters();
0108   }
0109   else {
0110     G4GDMLParser parser;
0111     std::size_t nmat = G4Material::GetNumberOfMaterials();
0112     parser.Read(fGeomFileName.c_str());  // volumes and materials
0113     if (G4Material::GetNumberOfMaterials() > nmat) {
0114       const std::vector<G4Material*> MatPtrVec = *G4Material::GetMaterialTable();
0115       if (G4Material::GetNumberOfMaterials() > nmat)
0116         G4cout << "Materials defined by " << fGeomFileName << " :" << G4endl;
0117       for (std::size_t imat = nmat; imat < MatPtrVec.size(); ++imat)
0118         G4cout << MatPtrVec[imat] << G4endl;
0119     }
0120     fBox = parser.GetWorldVolume();
0121   }
0122   return fBox;
0123 }
0124 
0125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0126 
0127 void DetectorConstruction::PrintParameters()
0128 {
0129   G4cout << "\n The Box is " << G4BestUnit(fBoxSize, "Length") << " of " << fMaterial->GetName()
0130          << G4endl;
0131 }
0132 
0133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0134 
0135 void DetectorConstruction::SetMaterial(G4String materialChoice)
0136 {
0137   // search the material by its name
0138   G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
0139   if (pttoMaterial) {
0140     fMaterial = pttoMaterial;
0141     if (fLBox) fLBox->SetMaterial(fMaterial);
0142   }
0143   G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0144 }
0145 
0146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0147 
0148 void DetectorConstruction::SetSize(G4double value)
0149 {
0150   fBoxSize = value;
0151   G4RunManager::GetRunManager()->ReinitializeGeometry();
0152 }
0153 
0154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0155 
0156 #include "G4AutoDelete.hh"
0157 #include "G4GlobalMagFieldMessenger.hh"
0158 
0159 void DetectorConstruction::ConstructSDandField()
0160 {
0161   if (fFieldMessenger.Get() == 0) {
0162     // Create global magnetic field messenger.
0163     // Uniform magnetic field is then created automatically if
0164     // the field value is not zero.
0165     G4ThreeVector fieldValue = G4ThreeVector();
0166     auto msg = new G4GlobalMagFieldMessenger(fieldValue);
0167     // msg->SetVerboseLevel(1);
0168     G4AutoDelete::Register(msg);
0169     fFieldMessenger.Put(msg);
0170   }
0171 }
0172 
0173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0174 
0175 void DetectorConstruction::SetMaxStepSize(G4double val)
0176 {
0177   // set the maximum allowed step size
0178   //
0179   if (val <= DBL_MIN) {
0180     G4cout << "\n --->warning from SetMaxStepSize: maxStep " << val
0181            << " out of range. Command refused" << G4endl;
0182     return;
0183   }
0184   fUserLimits->SetMaxAllowedStep(val);
0185 }
0186 
0187 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0188 
0189 void DetectorConstruction::SetMaxStepLength(G4double val)
0190 {
0191   // set the maximum length of tracking step
0192   //
0193   if (val <= DBL_MIN) {
0194     G4cout << "\n --->warning from SetMaxStepLength: maxStep " << val
0195            << " out of range. Command refused" << G4endl;
0196     return;
0197   }
0198   G4TransportationManager* tmanager = G4TransportationManager::GetTransportationManager();
0199   tmanager->GetPropagatorInField()->SetLargestAcceptableStep(val);
0200 }
0201 
0202 void DetectorConstruction::SetGeomFileName(G4String GeomFileName)
0203 {
0204   fGeomFileName = GeomFileName;
0205 }
0206 
0207 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......