Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:17:15

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