Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-24 07:52:58

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 #include "TargetSD.hh"
0033 
0034 #include "G4Box.hh"
0035 #include "G4FieldManager.hh"
0036 #include "G4GeometryManager.hh"
0037 #include "G4LogicalVolume.hh"
0038 #include "G4Material.hh"
0039 #include "G4NistManager.hh"
0040 #include "G4PVPlacement.hh"
0041 #include "G4RunManager.hh"
0042 #include "G4SDManager.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "G4ThreeVector.hh"
0045 #include "G4UnitsTable.hh"
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 DetectorConstruction::DetectorConstruction()
0050   : G4VUserDetectorConstruction(), fAbsorMaterial(nullptr), fLogAbsor(nullptr), fWorld(nullptr)
0051 {
0052   // default parameter values
0053   fAbsorSizeZ = fAbsorSizeXY = 10 * cm;
0054   fWorldSizeZ = fWorldSizeXY = 1.2 * fAbsorSizeZ;
0055 
0056   SetMaterial("G4_Al");
0057   fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0058 
0059   // create commands for interactive definition of the detector
0060   fDetectorMessenger = new DetectorMessenger(this);
0061 }
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0064 
0065 DetectorConstruction::~DetectorConstruction()
0066 {
0067   delete fDetectorMessenger;
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 G4VPhysicalVolume* DetectorConstruction::Construct()
0073 {
0074   if (fWorld) {
0075     return fWorld;
0076   }
0077 
0078   /****************************    World   *****************************/
0079   G4Box* sWorld = new G4Box("world", fWorldSizeXY / 2, fWorldSizeXY / 2, fWorldSizeZ / 2);
0080 
0081   G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld, fWorldMaterial, "world");
0082 
0083   fWorld = new G4PVPlacement(0,  // no rotation
0084                              G4ThreeVector(),  // at (0,0,0)
0085                              lWorld,  // logical volume
0086                              "world",  // name
0087                              0,  // mother  volume
0088                              false,  // no boolean operation
0089                              0);  // copy number
0090 
0091   /**************************    Absorber    ***************************/
0092 
0093   G4Box* sAbsor = new G4Box("Absorber", fAbsorSizeXY / 2, fAbsorSizeXY / 2, fAbsorSizeZ / 2);
0094 
0095   fLogAbsor = new G4LogicalVolume(sAbsor, fAbsorMaterial, "Absorber");
0096 
0097   new G4PVPlacement(0,  // no rotation
0098                     G4ThreeVector(),  // at (0,0,0)
0099                     fLogAbsor,  // logical volume
0100                     "Absorber",  // name
0101                     lWorld,  // mother  volume
0102                     false,  // no boolean operation
0103                     0);  // copy number
0104 
0105   PrintParameters();
0106 
0107   /************     always return the World volume     *****************/
0108   return fWorld;
0109 }
0110 
0111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0112 
0113 void DetectorConstruction::PrintParameters()
0114 {
0115   G4cout << "\n---------------------------------------------------------\n";
0116   G4cout << "---> The Absorber is " << G4BestUnit(fAbsorSizeZ, "Length") << " of "
0117          << fAbsorMaterial->GetName() << G4endl;
0118   G4cout << "\n---------------------------------------------------------\n";
0119 }
0120 
0121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0122 
0123 void DetectorConstruction::SetSizeZ(G4double value)
0124 {
0125   if (value > 0.0) {
0126     fAbsorSizeZ = value;
0127     fWorldSizeZ = 1.2 * fAbsorSizeZ;
0128   }
0129 }
0130 
0131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0132 
0133 void DetectorConstruction::SetSizeXY(G4double value)
0134 {
0135   if (value > 0.0) {
0136     fAbsorSizeXY = value;
0137     fWorldSizeXY = 1.2 * fAbsorSizeXY;
0138   }
0139 }
0140 
0141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0142 
0143 void DetectorConstruction::SetMaterial(const G4String& namemat)
0144 {
0145   // search the material by its name
0146 
0147   G4Material* mat = G4NistManager::Instance()->FindOrBuildMaterial(namemat);
0148   if (!mat) {
0149     G4cout << "!!! DetectorConstruction::SetMaterial: WARNING Material <" << namemat
0150            << "> does not exist in DB" << G4endl;
0151     return;
0152   }
0153   // new material is found out
0154   if (mat != fAbsorMaterial) {
0155     fAbsorMaterial = mat;
0156     if (fLogAbsor) {
0157       fLogAbsor->SetMaterial(mat);
0158     }
0159     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0160   }
0161 }
0162 
0163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0164 
0165 void DetectorConstruction::ConstructSDandField()
0166 {
0167   auto sd = new TargetSD("Target");
0168   G4SDManager::GetSDMpointer()->AddNewDetector(sd);
0169   SetSensitiveDetector(fLogAbsor, sd);
0170 }
0171 
0172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......