Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:00

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