Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 08:29:51

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 "G4FieldManager.hh"
0036 #include "G4GeometryManager.hh"
0037 #include "G4LogicalVolume.hh"
0038 #include "G4LogicalVolumeStore.hh"
0039 #include "G4Material.hh"
0040 #include "G4NistManager.hh"
0041 #include "G4PVPlacement.hh"
0042 #include "G4PhysicalConstants.hh"
0043 #include "G4PhysicalVolumeStore.hh"
0044 #include "G4RunManager.hh"
0045 #include "G4SolidStore.hh"
0046 #include "G4SystemOfUnits.hh"
0047 #include "G4ThreeVector.hh"
0048 #include "G4TransportationManager.hh"
0049 #include "G4Tubs.hh"
0050 #include "G4UniformMagField.hh"
0051 #include "globals.hh"
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 DetectorConstruction::DetectorConstruction()
0056   : G4VUserDetectorConstruction(),
0057     fTargetMaterial(nullptr),
0058     fLogicExperimentalHall(nullptr),
0059     fPhysExperimentalHall(nullptr),
0060     fLogicTargetLayer(nullptr),
0061     fPhysTargetLayer(nullptr),
0062     fFieldMgr(nullptr),
0063     fUniformMagField(nullptr),
0064     fDetectorMessenger(nullptr),
0065     fTargetInnerRadius(9.0 * mm),
0066     fTargetOuterRadius(11.0 * mm)  //***LOOKHERE*** Default values
0067 {
0068   fFieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
0069   //***LOOKHERE*** Default material
0070   fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Be");
0071   fDetectorMessenger = new DetectorMessenger(this);
0072 }
0073 
0074 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0075 
0076 DetectorConstruction::~DetectorConstruction()
0077 {
0078   delete fUniformMagField;
0079   delete fDetectorMessenger;
0080 }
0081 
0082 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0083 
0084 G4VPhysicalVolume* DetectorConstruction::Construct()
0085 {
0086   return ConstructLayer();
0087 }
0088 
0089 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0090 
0091 G4VPhysicalVolume* DetectorConstruction::ConstructLayer()
0092 {
0093   // Clean old geometry, if any
0094   G4GeometryManager::GetInstance()->OpenGeometry();
0095   G4PhysicalVolumeStore::GetInstance()->Clean();
0096   G4LogicalVolumeStore::GetInstance()->Clean();
0097   G4SolidStore::GetInstance()->Clean();
0098   // The geometry consists of a cylinder with axis along the z-direction, and
0099   // positioned at the center, (0.0, 0.0, 0.0). Its inner and outer radius, and
0100   // its material can be set via UI commands.
0101   // The world volume (experimental hall) is a box slightly bigger than the cylinder
0102   // and it is filled of "G4_Galactic" material.
0103   const G4double halfLength = 1.0 * m;  //***LOOKHERE*** Half-length of the cylinder
0104   const G4double expHall_x = 1.01 * halfLength;  // half dimension along x
0105   const G4double expHall_y = 1.01 * halfLength;  // half dimension along y
0106   const G4double expHall_z = 1.01 * halfLength;  // half dimension along z
0107   G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0108   G4Box* experimentalHallBox = new G4Box("expHallBox", expHall_x, expHall_y, expHall_z);
0109   fLogicExperimentalHall = new G4LogicalVolume(experimentalHallBox,  // solid
0110                                                vacuum,  // material
0111                                                "logicExpHall",  // name
0112                                                0,  // field manager
0113                                                0,  // sensitive detector
0114                                                0);  // user limits
0115   fPhysExperimentalHall = new G4PVPlacement(0,  // rotation
0116                                             G4ThreeVector(),  // translation
0117                                             "expHall",  // name
0118                                             fLogicExperimentalHall,  // logical volume
0119                                             0,  // mother physical volume
0120                                             false,  // boolean operation
0121                                             0);  // copy number
0122   // Cylinder along the z-axis, with inner and outer diameter
0123   G4Tubs* solidTargetLayer = new G4Tubs("solidTargetLayer",
0124                                         fTargetInnerRadius,  // inner radius
0125                                         fTargetOuterRadius,  // outer radius
0126                                         halfLength,  // half cylinder length in z
0127                                         0.0,  // starting phi angle in rad
0128                                         2.0 * pi);  // final phi angle in rad
0129   fLogicTargetLayer = new G4LogicalVolume(solidTargetLayer,  // solid
0130                                           fTargetMaterial,  // material
0131                                           "logicTargetLayer",  // name
0132                                           0,  // field manager
0133                                           0,  // sensitive detector
0134                                           0);  // user limits
0135   fPhysTargetLayer = new G4PVPlacement(0,  // rotation
0136                                        G4ThreeVector(),  // translation
0137                                        "physTargetLayer",  // name
0138                                        fLogicTargetLayer,  // logical volume
0139                                        fPhysExperimentalHall,  // mother physical volume
0140                                        false,  // boolean operation
0141                                        0);  // copy number
0142   PrintParameters();
0143   G4cout << G4endl << "DetectorConstruction::ConstructLayer() : " << G4endl
0144          << "\t World (box) size: " << G4endl << "\t \t x : -/+ " << expHall_x << " mm ;"
0145          << "\t y : -/+ " << expHall_y << " mm ;"
0146          << "\t z : -/+ " << expHall_z << " mm ;" << G4endl
0147          << "\t Layer (cylinder) size : " << G4endl << "\t \t radii : " << fTargetInnerRadius
0148          << " , " << fTargetOuterRadius << " mm ;"
0149          << "\t \t length (along z) : " << 2.0 * halfLength << " mm ;" << G4endl << G4endl
0150          << G4endl;
0151   return fPhysExperimentalHall;
0152 }
0153 
0154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0155 
0156 void DetectorConstruction::SetTargetMaterial(const G4String name)
0157 {
0158   fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial(name);
0159   if (!fTargetMaterial) {
0160     G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!"
0161            << G4endl << "     ===> the default  * G4_Be *  will be used." << G4endl << G4endl;
0162     //***LOOKHERE*** Default material
0163     fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Be");
0164   }
0165   if (fLogicTargetLayer) fLogicTargetLayer->SetMaterial(fTargetMaterial);
0166 }
0167 
0168 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0169 
0170 void DetectorConstruction::UpdateGeometry()
0171 {
0172   G4RunManager::GetRunManager()->ReinitializeGeometry();
0173   PrintParameters();
0174   // Update also the position of the gun
0175   const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast<const PrimaryGeneratorAction*>(
0176     G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0177   if (pPrimaryAction) pPrimaryAction->SetGunPosition();
0178 }
0179 
0180 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0181 
0182 void DetectorConstruction::PrintParameters()
0183 {
0184   G4cout << G4endl << G4endl << " ------  DetectorConstruction::PrintParameters() ------ " << G4endl
0185          << " Material            = " << fTargetMaterial->GetName() << G4endl
0186          << " Target Inner Radius = " << fTargetInnerRadius << " mm" << G4endl
0187          << " Target Outer Radius = " << fTargetOuterRadius << " mm" << G4endl
0188          << " B [T]               = "
0189          << (fUniformMagField ? fUniformMagField->GetConstantFieldValue() / CLHEP::tesla
0190                               : G4ThreeVector(0.0, 0.0, 0.0))
0191          << G4endl << " ------------------------------------------------------ " << G4endl
0192          << G4endl;
0193 }
0194 
0195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0196 
0197 void DetectorConstruction::SetMagField(const G4double fieldValue)
0198 {
0199   if (fUniformMagField) delete fUniformMagField;
0200   if (std::abs(fieldValue) > 0.0) {
0201     // Apply a global uniform magnetic field along the Z axis
0202     fUniformMagField = new G4UniformMagField(G4ThreeVector(0.0, 0.0, fieldValue));
0203     fFieldMgr->SetDetectorField(fUniformMagField);
0204     fFieldMgr->CreateChordFinder(fUniformMagField);
0205   }
0206 }
0207 
0208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......