Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 07:44:16

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 "G4GeometryManager.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4Material.hh"
0038 #include "G4NistManager.hh"
0039 #include "G4PVPlacement.hh"
0040 #include "G4PhysicalVolumeStore.hh"
0041 #include "G4RunManager.hh"
0042 #include "G4SolidStore.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "G4UniformMagField.hh"
0045 #include "G4UnitsTable.hh"
0046 #include "G4UserLimits.hh"
0047 
0048 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0049 
0050 DetectorConstruction::DetectorConstruction()
0051   : G4VUserDetectorConstruction(),
0052     fP_Box(0),
0053     fL_Box(0),
0054     fBoxSize(500 * m),
0055     fMaterial(0),
0056     fMagField(0),
0057     fUserLimits(0),
0058     fDetectorMessenger(0)
0059 {
0060   DefineMaterials();
0061   SetMaterial("Iron");
0062 
0063   // create UserLimits
0064   fUserLimits = new G4UserLimits();
0065 
0066   // create commands for interactive definition of the detector
0067   fDetectorMessenger = new DetectorMessenger(this);
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 DetectorConstruction::~DetectorConstruction()
0073 {
0074   delete fDetectorMessenger;
0075 }
0076 
0077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0078 
0079 G4VPhysicalVolume* DetectorConstruction::Construct()
0080 {
0081   return ConstructVolumes();
0082 }
0083 
0084 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0085 
0086 void DetectorConstruction::DefineMaterials()
0087 {
0088   G4double a, z, density;
0089 
0090   new G4Material("Beryllium", z = 4., a = 9.012182 * g / mole, density = 1.848 * g / cm3);
0091   new G4Material("Carbon", z = 6., a = 12.011 * g / mole, density = 2.265 * g / cm3);
0092   new G4Material("Iron", z = 26., a = 55.85 * g / mole, density = 7.870 * g / cm3);
0093 
0094   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0095 }
0096 
0097 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0098 
0099 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0100 {
0101   G4GeometryManager::GetInstance()->OpenGeometry();
0102   G4PhysicalVolumeStore::GetInstance()->Clean();
0103   G4LogicalVolumeStore::GetInstance()->Clean();
0104   G4SolidStore::GetInstance()->Clean();
0105 
0106   G4Box* sBox = new G4Box("Container",  // its name
0107                           fBoxSize / 2, fBoxSize / 2, fBoxSize / 2);  // its dimensions
0108 
0109   fL_Box = new G4LogicalVolume(sBox,  // its shape
0110                                fMaterial,  // its material
0111                                fMaterial->GetName());  // its name
0112 
0113   fL_Box->SetUserLimits(fUserLimits);
0114 
0115   fP_Box = new G4PVPlacement(0,  // no rotation
0116                              G4ThreeVector(),  // at (0,0,0)
0117                              fL_Box,  // its logical volume
0118                              fMaterial->GetName(),  // its name
0119                              0,  // its mother  volume
0120                              false,  // no boolean operation
0121                              0);  // copy number
0122 
0123   PrintParameters();
0124 
0125   //
0126   // always return the root volume
0127   //
0128   return fP_Box;
0129 }
0130 
0131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0132 
0133 void DetectorConstruction::PrintParameters()
0134 {
0135   G4cout << "\n The Box is " << G4BestUnit(fBoxSize, "Length") << " of " << fMaterial->GetName()
0136          << G4endl;
0137 }
0138 
0139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0140 
0141 void DetectorConstruction::SetMaterial(const G4String& name)
0142 {
0143   G4cout << "###SetMaterial" << G4endl;
0144 
0145   // get the pointer to the existing material
0146   G4Material* mat = G4Material::GetMaterial(name, false);
0147 
0148   // create the material by its name
0149   if (!mat) {
0150     mat = G4NistManager::Instance()->FindOrBuildMaterial(name);
0151   }
0152 
0153   if (mat && mat != fMaterial) {
0154     G4cout << "### New target material: " << mat->GetName() << G4endl;
0155     fMaterial = mat;
0156     if (fL_Box) {
0157       fL_Box->SetMaterial(mat);
0158       G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0159     }
0160   }
0161 }
0162 
0163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0164 
0165 void DetectorConstruction::SetSize(G4double value)
0166 {
0167   fBoxSize = value;
0168 }
0169 
0170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0171 
0172 #include "G4FieldManager.hh"
0173 #include "G4TransportationManager.hh"
0174 
0175 void DetectorConstruction::SetMagField(G4double fieldValue)
0176 {
0177   // apply a global uniform magnetic field along Z axis
0178   G4FieldManager* fieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
0179 
0180   if (fMagField) delete fMagField;  // delete the existing magn field
0181 
0182   if (fieldValue != 0.)  // create a new one if non nul
0183   {
0184     fMagField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue));
0185     fieldMgr->SetDetectorField(fMagField);
0186     fieldMgr->CreateChordFinder(fMagField);
0187   }
0188   else {
0189     fMagField = 0;
0190     fieldMgr->SetDetectorField(fMagField);
0191   }
0192 }
0193 
0194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0195 
0196 void DetectorConstruction::SetMaxStepSize(G4double val)
0197 {
0198   // set the maximum allowed step size
0199   //
0200   if (val <= DBL_MIN) {
0201     G4cout << "\n --->warning from SetMaxStepSize: maxStep " << val
0202            << " out of range. Command refused" << G4endl;
0203     return;
0204   }
0205   fUserLimits->SetMaxAllowedStep(val);
0206 }
0207 
0208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0209 
0210 #include "G4RunManager.hh"
0211 
0212 void DetectorConstruction::UpdateGeometry()
0213 {
0214   G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
0215 }
0216 
0217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......