Back to home page

EIC code displayed by LXR

 
 

    


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

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