Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 08:29:27

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