Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:36:57

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 B4::DetectorConstruction class
0028 
0029 #include "DetectorConstruction.hh"
0030 
0031 #include "G4AutoDelete.hh"
0032 #include "G4Box.hh"
0033 #include "G4Colour.hh"
0034 #include "G4GlobalMagFieldMessenger.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4Material.hh"
0037 #include "G4NistManager.hh"
0038 #include "G4PVPlacement.hh"
0039 #include "G4PVReplica.hh"
0040 #include "G4PhysicalConstants.hh"
0041 #include "G4SystemOfUnits.hh"
0042 #include "G4VisAttributes.hh"
0043 
0044 namespace B4
0045 {
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 G4ThreadLocal G4GlobalMagFieldMessenger* DetectorConstruction::fMagFieldMessenger = nullptr;
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 
0053 G4VPhysicalVolume* DetectorConstruction::Construct()
0054 {
0055   // Define materials
0056   DefineMaterials();
0057 
0058   // Define volumes
0059   return DefineVolumes();
0060 }
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 
0064 void DetectorConstruction::DefineMaterials()
0065 {
0066   // Lead material defined using NIST Manager
0067   auto nistManager = G4NistManager::Instance();
0068   nistManager->FindOrBuildMaterial("G4_Pb");
0069 
0070   // Liquid argon material
0071   G4double a;  // mass of a mole;
0072   G4double z;  // z=mean number of protons;
0073   G4double density;
0074   new G4Material("liquidArgon", z = 18., a = 39.95 * g / mole, density = 1.390 * g / cm3);
0075   // The argon by NIST Manager is a gas with a different density
0076 
0077   // Vacuum
0078   new G4Material("Galactic", z = 1., a = 1.01 * g / mole, density = universe_mean_density,
0079                  kStateGas, 2.73 * kelvin, 3.e-18 * pascal);
0080 
0081   // Print materials
0082   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0083 }
0084 
0085 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0086 
0087 G4VPhysicalVolume* DetectorConstruction::DefineVolumes()
0088 {
0089   // Geometry parameters
0090   G4int nofLayers = 10;
0091   G4double absoThickness = 10. * mm;
0092   G4double gapThickness = 5. * mm;
0093   G4double calorSizeXY = 10. * cm;
0094 
0095   auto layerThickness = absoThickness + gapThickness;
0096   auto calorThickness = nofLayers * layerThickness;
0097   auto worldSizeXY = 1.2 * calorSizeXY;
0098   auto worldSizeZ = 1.2 * calorThickness;
0099 
0100   // Get materials
0101   auto defaultMaterial = G4Material::GetMaterial("Galactic");
0102   auto absorberMaterial = G4Material::GetMaterial("G4_Pb");
0103   auto gapMaterial = G4Material::GetMaterial("liquidArgon");
0104 
0105   if (!defaultMaterial || !absorberMaterial || !gapMaterial) {
0106     G4ExceptionDescription msg;
0107     msg << "Cannot retrieve materials already defined.";
0108     G4Exception("DetectorConstruction::DefineVolumes()", "MyCode0001", FatalException, msg);
0109   }
0110 
0111   //
0112   // World
0113   //
0114   auto worldS = new G4Box("World",  // its name
0115                           worldSizeXY / 2, worldSizeXY / 2, worldSizeZ / 2);  // its size
0116 
0117   auto worldLV = new G4LogicalVolume(worldS,  // its solid
0118                                      defaultMaterial,  // its material
0119                                      "World");  // its name
0120 
0121   auto worldPV = new G4PVPlacement(nullptr,  // no rotation
0122                                    G4ThreeVector(),  // at (0,0,0)
0123                                    worldLV,  // its logical volume
0124                                    "World",  // its name
0125                                    nullptr,  // its mother  volume
0126                                    false,  // no boolean operation
0127                                    0,  // copy number
0128                                    fCheckOverlaps);  // checking overlaps
0129 
0130   //
0131   // Calorimeter
0132   //
0133   auto calorimeterS = new G4Box("Calorimeter",  // its name
0134                                 calorSizeXY / 2, calorSizeXY / 2, calorThickness / 2);  // its size
0135 
0136   auto calorLV = new G4LogicalVolume(calorimeterS,  // its solid
0137                                      defaultMaterial,  // its material
0138                                      "Calorimeter");  // its name
0139 
0140   new G4PVPlacement(nullptr,  // no rotation
0141                     G4ThreeVector(),  // at (0,0,0)
0142                     calorLV,  // its logical volume
0143                     "Calorimeter",  // its name
0144                     worldLV,  // its mother  volume
0145                     false,  // no boolean operation
0146                     0,  // copy number
0147                     fCheckOverlaps);  // checking overlaps
0148 
0149   //
0150   // Layer
0151   //
0152   auto layerS = new G4Box("Layer",  // its name
0153                           calorSizeXY / 2, calorSizeXY / 2, layerThickness / 2);  // its size
0154 
0155   auto layerLV = new G4LogicalVolume(layerS,  // its solid
0156                                      defaultMaterial,  // its material
0157                                      "Layer");  // its name
0158 
0159   new G4PVReplica("Layer",  // its name
0160                   layerLV,  // its logical volume
0161                   calorLV,  // its mother
0162                   kZAxis,  // axis of replication
0163                   nofLayers,  // number of replica
0164                   layerThickness);  // witdth of replica
0165 
0166   //
0167   // Absorber
0168   //
0169   auto absorberS = new G4Box("Abso",  // its name
0170                              calorSizeXY / 2, calorSizeXY / 2, absoThickness / 2);  // its size
0171 
0172   auto absorberLV = new G4LogicalVolume(absorberS,  // its solid
0173                                         absorberMaterial,  // its material
0174                                         "Abso");  // its name
0175 
0176   fAbsorberPV = new G4PVPlacement(nullptr,  // no rotation
0177                                   G4ThreeVector(0., 0., -gapThickness / 2),  // its position
0178                                   absorberLV,  // its logical volume
0179                                   "Abso",  // its name
0180                                   layerLV,  // its mother  volume
0181                                   false,  // no boolean operation
0182                                   0,  // copy number
0183                                   fCheckOverlaps);  // checking overlaps
0184 
0185   //
0186   // Gap
0187   //
0188   auto gapS = new G4Box("Gap",  // its name
0189                         calorSizeXY / 2, calorSizeXY / 2, gapThickness / 2);  // its size
0190 
0191   auto gapLV = new G4LogicalVolume(gapS,  // its solid
0192                                    gapMaterial,  // its material
0193                                    "Gap");  // its name
0194 
0195   fGapPV = new G4PVPlacement(nullptr,  // no rotation
0196                              G4ThreeVector(0., 0., absoThickness / 2),  // its position
0197                              gapLV,  // its logical volume
0198                              "Gap",  // its name
0199                              layerLV,  // its mother  volume
0200                              false,  // no boolean operation
0201                              0,  // copy number
0202                              fCheckOverlaps);  // checking overlaps
0203 
0204   //
0205   // print parameters
0206   //
0207   G4cout << G4endl << "------------------------------------------------------------" << G4endl
0208          << "---> The calorimeter is " << nofLayers << " layers of: [ " << absoThickness / mm
0209          << "mm of " << absorberMaterial->GetName() << " + " << gapThickness / mm << "mm of "
0210          << gapMaterial->GetName() << " ] " << G4endl
0211          << "------------------------------------------------------------" << G4endl;
0212 
0213   //
0214   // Visualization attributes
0215   //
0216   worldLV->SetVisAttributes(G4VisAttributes::GetInvisible());
0217   calorLV->SetVisAttributes(G4VisAttributes(G4Colour::White()));
0218 
0219   //
0220   // Always return the physical World
0221   //
0222   return worldPV;
0223 }
0224 
0225 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0226 
0227 void DetectorConstruction::ConstructSDandField()
0228 {
0229   // Create global magnetic field messenger.
0230   // Uniform magnetic field is then created automatically if
0231   // the field value is not zero.
0232   G4ThreeVector fieldValue;
0233   fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
0234   fMagFieldMessenger->SetVerboseLevel(1);
0235 
0236   // Register the field messenger for deleting
0237   G4AutoDelete::Register(fMagFieldMessenger);
0238 }
0239 
0240 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0241 
0242 }  // namespace B4