Back to home page

EIC code displayed by LXR

 
 

    


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

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