Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-29 07:39:22

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 "PrimaryGeneratorAction.hh"
0033 
0034 #include "G4Box.hh"
0035 #include "G4GeometryManager.hh"
0036 #include "G4LogicalVolume.hh"
0037 #include "G4LogicalVolumeStore.hh"
0038 #include "G4Material.hh"
0039 #include "G4NistManager.hh"
0040 #include "G4PVPlacement.hh"
0041 #include "G4PhysicalConstants.hh"
0042 #include "G4PhysicalVolumeStore.hh"
0043 #include "G4RunManager.hh"
0044 #include "G4SolidStore.hh"
0045 #include "G4SystemOfUnits.hh"
0046 #include "G4ThreeVector.hh"
0047 #include "G4Tubs.hh"
0048 #include "globals.hh"
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 DetectorConstruction::DetectorConstruction()
0053   : fMaterial(nullptr),
0054     fExperimentalHall_log(nullptr),
0055     fExperimentalHall_phys(nullptr),
0056     fLogicLayer(nullptr),
0057     fPhysiLayer(nullptr),
0058     fLogicScoringUpDown(nullptr),
0059     fPhysiScoringUpstream(nullptr),
0060     fPhysiScoringDownstream(nullptr),
0061     fLogicScoringSide(nullptr),
0062     fPhysiScoringSide(nullptr),
0063     fDetectorMessenger(nullptr),
0064     fThickness(2.0 * CLHEP::m),
0065     fDiameter(2.0 * CLHEP::m)  //***LOOKHERE*** Default values
0066 {
0067   fMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe");  //***LOOKHERE***
0068                                                                         // Default material
0069   fDetectorMessenger = new DetectorMessenger(this);
0070 }
0071 
0072 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0073 
0074 DetectorConstruction::~DetectorConstruction()
0075 {
0076   delete fDetectorMessenger;
0077 }
0078 
0079 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0080 
0081 G4VPhysicalVolume* DetectorConstruction::Construct()
0082 {
0083   return ConstructLayer();
0084 }
0085 
0086 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0087 
0088 G4VPhysicalVolume* DetectorConstruction::ConstructLayer()
0089 {
0090   // Clean old geometry, if any.
0091   G4GeometryManager::GetInstance()->OpenGeometry();
0092   G4PhysicalVolumeStore::GetInstance()->Clean();
0093   G4LogicalVolumeStore::GetInstance()->Clean();
0094   G4SolidStore::GetInstance()->Clean();
0095 
0096   // The target layer is a cylinder, with axis along the z-direction,
0097   // and positioned at the center, (0.0, 0.0, 0.0).
0098   // The world volume (experimental hall) is a box 20% bigger than the target layer,
0099   // and it is filled of "G4_Galactic" material.
0100 
0101   G4double expHall_x = 0.6 * fDiameter;  // half dimension along x : 20% bigger than the radius
0102                                          //                          of the target layer
0103   G4double expHall_y = 0.6 * fDiameter;  // half dimension along y : 20% bigger than the radius
0104                                          //                          of the target layer
0105   G4double expHall_z = 0.6 * fThickness;  // half dimension along z : 20% bigger than the half
0106                                           //                          thickness of the target layer
0107 
0108   G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0109 
0110   // Experimental hall
0111   G4Box* experimentalHall_box = new G4Box("expHall_box", expHall_x, expHall_y, expHall_z);
0112   fExperimentalHall_log = new G4LogicalVolume(experimentalHall_box,  // solid
0113                                               vacuum,  // material
0114                                               "expHall_log",  // name
0115                                               0,  // field manager
0116                                               0,  // sensitive detector
0117                                               0);  // user limits
0118   fExperimentalHall_phys = new G4PVPlacement(0,  // rotation
0119                                              G4ThreeVector(),  // translation
0120                                              "expHall",  // name
0121                                              fExperimentalHall_log,  // logical volume
0122                                              0,  // mother physical volume
0123                                              false,  // boolean operation
0124                                              0);  // copy number
0125 
0126   // Target
0127   G4Tubs* solidLayer = new G4Tubs("solidLayer",  // name
0128                                   0.0,  // inner radius
0129                                   0.5 * fDiameter,  // outer radius
0130                                   0.5 * fThickness,  // half cylinder length in z
0131                                   0.0,  // starting phi angle in rad
0132                                   2.0 * pi);  // final phi angle in rad
0133   fLogicLayer = new G4LogicalVolume(solidLayer,  // solid
0134                                     fMaterial,  // material
0135                                     "logicLayer",  // name
0136                                     0,  // field manager
0137                                     0,  // sensitive detector
0138                                     0);  // user limits
0139   fPhysiLayer = new G4PVPlacement(0,  // rotation
0140                                   G4ThreeVector(),  // translation
0141                                   "physiLayer",  // name
0142                                   fLogicLayer,  // logical volume
0143                                   fExperimentalHall_phys,  // mother physical volume
0144                                   false,  // boolean operation
0145                                   0);  // copy number
0146 
0147   // Three scoring volumes: one thin layer downstream of the target ("down")
0148   //                        one thin layer surrounding (lateral) of the target ("side")
0149   //                        one thin layer upstream of the target ("up")
0150   G4Tubs* solidScoringUpDown = new G4Tubs("solidScoringUpDown",  // name
0151                                           0.0,  // inner radius
0152                                           0.5 * fDiameter,  // outer radius
0153                                           0.5 * fScoringThickness,  // half cylinder length in z
0154                                           0.0,  // starting phi angle in rad
0155                                           2.0 * pi);  // final phi angle in rad
0156   fLogicScoringUpDown = new G4LogicalVolume(solidScoringUpDown,  // solid
0157                                             vacuum,  // material
0158                                             "logicScoringUpDown",  // name
0159                                             0,  // field manager
0160                                             0,  // sensitive detector
0161                                             0);  // user limits
0162   G4double zScoringUpDown = 0.5 * (fThickness + fScoringThickness);
0163   fPhysiScoringUpstream = new G4PVPlacement(0,  // rotation
0164                                             G4ThreeVector(0.0, 0.0, -zScoringUpDown),
0165                                             // translation
0166                                             "physiScoringUpstream",  // name
0167                                             fLogicScoringUpDown,  // logical volume
0168                                             fExperimentalHall_phys,  // mother physical volume
0169                                             false,  // boolean operation
0170                                             0);  // copy number
0171   fPhysiScoringDownstream = new G4PVPlacement(0,  // rotation
0172                                               G4ThreeVector(0.0, 0.0, zScoringUpDown),
0173                                               // translation
0174                                               "physiScoringDownstream",  // name
0175                                               fLogicScoringUpDown,  // logical volume
0176                                               fExperimentalHall_phys,  // mother physical volume
0177                                               false,  // boolean operation
0178                                               0);  // copy number
0179 
0180   G4Tubs* solidScoringSide = new G4Tubs("solidScoringSide",  // name
0181                                         0.5 * fDiameter,  // inner radius
0182                                         0.5 * fDiameter + fScoringThickness,  // outer radius
0183                                         0.5 * fThickness,  // half cylinder length in z
0184                                         0.0,  // starting phi angle in rad
0185                                         2.0 * pi);  // final phi angle in rad
0186   fLogicScoringSide = new G4LogicalVolume(solidScoringSide,  // solid
0187                                           vacuum,  // material
0188                                           "logicScoringSide",  // name
0189                                           0,  // field manager
0190                                           0,  // sensitive detector
0191                                           0);  // user limits
0192   fPhysiScoringSide = new G4PVPlacement(0,  // rotation
0193                                         G4ThreeVector(0.0, 0.0, 0.0),  // translation
0194                                         "physiScoringSide",  // name
0195                                         fLogicScoringSide,  // logical volume
0196                                         fExperimentalHall_phys,  // mother physical volume
0197                                         false,  // boolean operation
0198                                         0);  // copy number
0199 
0200   G4cout << G4endl << "DetectorConstruction::ConstructLayer() : " << G4endl
0201          << "\t World (box) size: " << G4endl << "\t \t x : -/+ " << expHall_x << " mm ;"
0202          << "\t y : -/+ " << expHall_y << " mm ;"
0203          << "\t z : -/+ " << expHall_z << " mm ;" << G4endl
0204          << "\t Target layer (cylinder) size: " << G4endl << "\t \t x : -/+ " << 0.5 * fDiameter
0205          << " mm ;"
0206          << "\t y : -/+ " << 0.5 * fDiameter << " mm ;"
0207          << "\t z : -/+ " << 0.5 * fThickness << " mm ;" << G4endl << G4endl << G4endl;
0208 
0209   return fExperimentalHall_phys;
0210 }
0211 
0212 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0213 
0214 void DetectorConstruction::SetMaterial(const G4String name)
0215 {
0216   fMaterial = G4NistManager::Instance()->FindOrBuildMaterial(name);
0217   if (!fMaterial) {
0218     G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!"
0219            << G4endl << "     ===> the default  * G4_Fe *  will be used." << G4endl << G4endl;
0220     fMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe");
0221   }
0222   if (fLogicLayer) fLogicLayer->SetMaterial(fMaterial);
0223 }
0224 
0225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0226 
0227 void DetectorConstruction::UpdateGeometry()
0228 {
0229   G4RunManager::GetRunManager()->ReinitializeGeometry();
0230   PrintParameters();
0231   // Update also the position of the gun
0232   const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast<const PrimaryGeneratorAction*>(
0233     G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0234   if (pPrimaryAction) pPrimaryAction->SetGunPosition();
0235 }
0236 
0237 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0238 
0239 void DetectorConstruction::PrintParameters()
0240 {
0241   G4cout << G4endl << G4endl << " ------  DetectorConstruction::PrintParameters() ------ " << G4endl
0242          << " Material         = " << fMaterial->GetName() << G4endl
0243          << " Thickness        = " << fThickness << " mm" << G4endl
0244          << " Diameter         = " << fDiameter << " mm" << G4endl
0245          << " ScoringThickness = " << fScoringThickness << " mm" << G4endl
0246          << " ------------------------------------------------------ " << G4endl << G4endl;
0247 }
0248 
0249 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......