Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 08:28:42

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