Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-10 08:06:18

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 //
0030 
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0033 
0034 #include "DetectorConstruction.hh"
0035 
0036 #include "DetectorMessenger.hh"
0037 #include "PrimaryGeneratorAction.hh"
0038 
0039 #include "G4Box.hh"
0040 #include "G4GeometryManager.hh"
0041 #include "G4LogicalVolume.hh"
0042 #include "G4LogicalVolumeStore.hh"
0043 #include "G4Material.hh"
0044 #include "G4NistManager.hh"
0045 #include "G4Orb.hh"
0046 #include "G4PVPlacement.hh"
0047 #include "G4PhysicalConstants.hh"
0048 #include "G4PhysicalVolumeStore.hh"
0049 #include "G4RunManager.hh"
0050 #include "G4SolidStore.hh"
0051 #include "G4Sphere.hh"
0052 #include "G4SystemOfUnits.hh"
0053 #include "G4ThreeVector.hh"
0054 #include "globals.hh"
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0057 
0058 DetectorConstruction::DetectorConstruction()
0059   : fMaterial(nullptr),
0060     fExperimentalHall_log(nullptr),
0061     fExperimentalHall_phys(nullptr),
0062     fLogicSphere(nullptr),
0063     fPhysiSphere(nullptr),
0064     fLogicScoringShell(nullptr),
0065     fPhysiScoringShell(nullptr),
0066     fDetectorMessenger(nullptr),
0067     fRadius(1.0 * CLHEP::m)  //***LOOKHERE*** Default values
0068 {
0069   // G4cout << " BEGIN  DetectorConstruction::DetectorConstruction()" << G4endl;
0070   fMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe");  //***LOOKHERE***
0071                                                                         // Default material
0072   fDetectorMessenger = new DetectorMessenger(this);
0073   // G4cout << " END  DetectorConstruction::DetectorConstruction()" << G4endl;
0074 }
0075 
0076 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0077 
0078 DetectorConstruction::~DetectorConstruction()
0079 {
0080   delete fDetectorMessenger;
0081 }
0082 
0083 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0084 
0085 G4VPhysicalVolume* DetectorConstruction::Construct()
0086 {
0087   // G4cout << " BEGIN  DetectorConstruction::Construct()" << G4endl;
0088   return ConstructSphere();
0089 }
0090 
0091 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0092 
0093 G4VPhysicalVolume* DetectorConstruction::ConstructSphere()
0094 {
0095   // G4cout << " BEGIN  DetectorConstruction::ConstructSphere()" << G4endl;
0096 
0097   // Clean old geometry, if any.
0098   G4GeometryManager::GetInstance()->OpenGeometry();
0099 
0100   G4PhysicalVolumeStore::GetInstance()->Clean();
0101   G4LogicalVolumeStore::GetInstance()->Clean();
0102   G4SolidStore::GetInstance()->Clean();
0103 
0104   // The target is a full solid sphere (G4Orb), positioned at the center, (0.0, 0.0, 0.0).
0105   // The world volume (experimental hall) is a box 10% bigger than the sphere
0106   // and it is filled of "G4_Galactic" material.
0107 
0108   G4double expHall_x = 1.1 * fRadius;  // half dimension along x
0109   G4double expHall_y = 1.1 * fRadius;  // half dimension along y
0110   G4double expHall_z = 1.1 * fRadius;  // half dimension along z
0111 
0112   G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0113 
0114   // Experimental hall
0115   G4Box* experimentalHall_box = new G4Box("expHall_box", expHall_x, expHall_y, expHall_z);
0116   fExperimentalHall_log = new G4LogicalVolume(experimentalHall_box,  // solid
0117                                               vacuum,  // material
0118                                               "expHall_log",  // name
0119                                               0,  // field manager
0120                                               0,  // sensitive detector
0121                                               0);  // user limits
0122   fExperimentalHall_phys = new G4PVPlacement(0,  // rotation
0123                                              G4ThreeVector(),  // translation
0124                                              "expHall",  // name
0125                                              fExperimentalHall_log,  // logical volume
0126                                              0,  // mother physical volume
0127                                              false,  // boolean operation
0128                                              0);  // copy number
0129 
0130   // Target sphere
0131   G4Orb* solidSphere = new G4Orb("solidSphere",  // name
0132                                  fRadius);  // outer radius
0133   fLogicSphere = new G4LogicalVolume(solidSphere,  // solid
0134                                      fMaterial,  // material
0135                                      "logicSphere",  // name
0136                                      0,  // field manager
0137                                      0,  // sensitive detector
0138                                      0);  // user limits
0139   fPhysiSphere = new G4PVPlacement(0,  // rotation
0140                                    G4ThreeVector(),  // translation
0141                                    "physiSphere",  // name
0142                                    fLogicSphere,  // logical volume
0143                                    fExperimentalHall_phys,  // mother physical volume
0144                                    false,  // boolean operation
0145                                    0);  // copy number
0146 
0147   // Scoring shell (a thin vacuum layer, immediately outside the target sphere)
0148   G4Sphere* solidScoringShell = new G4Sphere("solidScoringShell",  // name
0149                                              fRadius,  // Inner radius (the radius
0150                                                        // of the target sphere)
0151                                              fRadius + fScoringThickness,  // Outer radius
0152                                              0.0,  // Starting Phi angle of the
0153                                                    // segment in radians
0154                                              2.0 * CLHEP::pi,  // Delta Phi angle of the
0155                                                                // segment in radians
0156                                              0.0,  // Starting Theta angle of
0157                                                    // the segment in radians
0158                                              CLHEP::pi);  // Delta Theta angle of the
0159                                                           // segment in radians
0160   fLogicScoringShell = new G4LogicalVolume(solidScoringShell,  // solid
0161                                            vacuum,  // material
0162                                            "logicScoringShell",  // name
0163                                            0,  // field manager
0164                                            0,  // sensitive detector
0165                                            0);  // user limits
0166   fPhysiScoringShell = new G4PVPlacement(0,  // rotation
0167                                          G4ThreeVector(),  // translation
0168                                          "physiScoringShell",  // name
0169                                          fLogicScoringShell,  // logical volume
0170                                          fExperimentalHall_phys,  // mother physical volume
0171                                          false,  // boolean operation
0172                                          0);  // copy number
0173 
0174   G4cout << G4endl << "DetectorConstruction::ConstructSphere() : " << G4endl
0175          << "\t World (box) size: " << G4endl << "\t \t x : -/+ " << expHall_x << " mm ;"
0176          << "\t y : -/+ " << expHall_y << " mm ;"
0177          << "\t z : -/+ " << expHall_z << " mm ;" << G4endl << G4endl << G4endl;
0178 
0179   // G4cout << " END  DetectorConstruction::ConstructSphere()
0180 
0181   return fExperimentalHall_phys;
0182 }
0183 
0184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0185 
0186 void DetectorConstruction::SetMaterial(const G4String name)
0187 {
0188   fMaterial = G4NistManager::Instance()->FindOrBuildMaterial(name);
0189   if (fMaterial == nullptr) {
0190     G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!"
0191            << G4endl << "     ===> the default  * G4_Fe *  will be used." << G4endl << G4endl;
0192     fMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe");
0193   }
0194   if (fLogicSphere) fLogicSphere->SetMaterial(fMaterial);
0195   // G4cout << " Absorber Material = " << logicSphere->GetMaterial()->GetName() << G4endl;
0196 }
0197 
0198 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0199 
0200 void DetectorConstruction::UpdateGeometry()
0201 {
0202   // G4cout << " BEGIN  DetectorConstruction::UpdateGeometry" << G4endl;
0203   G4RunManager::GetRunManager()->ReinitializeGeometry();
0204   PrintParameters();
0205   // Update also the position of the gun
0206   const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast<const PrimaryGeneratorAction*>(
0207     G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0208   if (pPrimaryAction) pPrimaryAction->SetGunPosition();
0209   // G4cout << " END  DetectorConstruction::UpdateGeometry" << G4endl;
0210 }
0211 
0212 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0213 
0214 void DetectorConstruction::PrintParameters()
0215 {
0216   G4cout << G4endl << G4endl << " ------  DetectorConstruction::PrintParameters() ------ " << G4endl
0217          << " Material         = " << fMaterial->GetName() << G4endl
0218          << " Radius           = " << fRadius << " mm" << G4endl
0219          << " ScoringThickness = " << fScoringThickness << " mm" << G4endl
0220          << " -------------------------------------------------------- " << G4endl << G4endl;
0221 }
0222 
0223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......