Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-02 07:42:07

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 DetectorConstruction class
0028 
0029 #include "DetectorConstruction.hh"
0030 
0031 #include "DetectorMessenger.hh"
0032 
0033 #include "G4Box.hh"
0034 #include "G4Colour.hh"
0035 #include "G4GeometryManager.hh"
0036 #include "G4LogicalVolume.hh"
0037 #include "G4LogicalVolumeStore.hh"
0038 #include "G4Material.hh"
0039 #include "G4NistManager.hh"
0040 #include "G4PVPlacement.hh"
0041 #include "G4PVReplica.hh"
0042 #include "G4PhysicalVolumeStore.hh"
0043 #include "G4RunManager.hh"
0044 #include "G4SolidStore.hh"
0045 #include "G4StateManager.hh"
0046 #include "G4SystemOfUnits.hh"
0047 #include "G4VisAttributes.hh"
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0050 
0051 DetectorConstruction::DetectorConstruction()
0052 {
0053   ComputeCalorParameters();
0054 
0055   // materials
0056   DefineMaterials();
0057   SetAbsorberMaterial("G4_Pb");
0058   SetGapMaterial("G4_lAr");
0059 
0060   // create commands for interactive definition of the calorimeter
0061   fDetectorMessenger = new DetectorMessenger(this);
0062 }
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0065 
0066 DetectorConstruction::~DetectorConstruction()
0067 {
0068   delete fDetectorMessenger;
0069 }
0070 
0071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0072 
0073 G4VPhysicalVolume* DetectorConstruction::Construct()
0074 {
0075   return ConstructCalorimeter();
0076 }
0077 
0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0079 
0080 void DetectorConstruction::DefineMaterials()
0081 {
0082   // use G4-NIST materials data base
0083   //
0084   G4NistManager* man = G4NistManager::Instance();
0085   fDefaultMaterial = man->FindOrBuildMaterial("G4_Galactic");
0086   man->FindOrBuildMaterial("G4_Pb");
0087   man->FindOrBuildMaterial("G4_lAr");
0088 
0089   // print table
0090   //
0091   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0092 }
0093 
0094 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0095 
0096 G4VPhysicalVolume* DetectorConstruction::ConstructCalorimeter()
0097 {
0098   // Clean old geometry, if any
0099   //
0100   G4GeometryManager::GetInstance()->OpenGeometry();
0101   G4PhysicalVolumeStore::GetInstance()->Clean();
0102   G4LogicalVolumeStore::GetInstance()->Clean();
0103   G4SolidStore::GetInstance()->Clean();
0104 
0105   // complete the Calor parameters definition
0106   ComputeCalorParameters();
0107 
0108   //
0109   // World
0110   //
0111   fSolidWorld = new G4Box("World",  // its name
0112                           fWorldSizeX / 2, fWorldSizeYZ / 2, fWorldSizeYZ / 2);  // its size
0113 
0114   fLogicWorld = new G4LogicalVolume(fSolidWorld,  // its solid
0115                                     fDefaultMaterial,  // its material
0116                                     "World");  // its name
0117 
0118   fPhysiWorld = new G4PVPlacement(nullptr,  // no rotation
0119                                   G4ThreeVector(),  // at (0,0,0)
0120                                   fLogicWorld,  // its logical volume
0121                                   "World",  // its name
0122                                   nullptr,  // its mother  volume
0123                                   false,  // no boolean operation
0124                                   0);  // copy number
0125 
0126   //
0127   // Calorimeter
0128   //
0129   fSolidCalor = nullptr;
0130   fLogicCalor = nullptr;
0131   fPhysiCalor = nullptr;
0132   fSolidLayer = nullptr;
0133   fLogicLayer = nullptr;
0134   fPhysiLayer = nullptr;
0135 
0136   if (fCalorThickness > 0.) {
0137     fSolidCalor = new G4Box("Calorimeter",  // its name
0138                             fCalorThickness / 2, fCalorSizeYZ / 2, fCalorSizeYZ / 2);  // size
0139 
0140     fLogicCalor = new G4LogicalVolume(fSolidCalor,  // its solid
0141                                       fDefaultMaterial,  // its material
0142                                       "Calorimeter");  // its name
0143 
0144     fPhysiCalor = new G4PVPlacement(nullptr,  // no rotation
0145                                     G4ThreeVector(),  // at (0,0,0)
0146                                     fLogicCalor,  // its logical volume
0147                                     "Calorimeter",  // its name
0148                                     fLogicWorld,  // its mother  volume
0149                                     false,  // no boolean operation
0150                                     0);  // copy number
0151 
0152     //
0153     // Layer
0154     //
0155     fSolidLayer = new G4Box("Layer",  // its name
0156                             fLayerThickness / 2, fCalorSizeYZ / 2, fCalorSizeYZ / 2);  // size
0157 
0158     fLogicLayer = new G4LogicalVolume(fSolidLayer,  // its solid
0159                                       fDefaultMaterial,  // its material
0160                                       "Layer");  // its name
0161     if (fNbOfLayers > 1) {
0162       fPhysiLayer = new G4PVReplica("Layer",  // its name
0163                                     fLogicLayer,  // its logical volume
0164                                     fLogicCalor,  // its mother
0165                                     kXAxis,  // axis of replication
0166                                     fNbOfLayers,  // number of replica
0167                                     fLayerThickness);  // witdth of replica
0168     }
0169     else {
0170       fPhysiLayer = new G4PVPlacement(nullptr,  // no rotation
0171                                       G4ThreeVector(),  // at (0,0,0)
0172                                       fLogicLayer,  // its logical volume
0173                                       "Layer",  // its name
0174                                       fLogicCalor,  // its mother  volume
0175                                       false,  // no boolean operation
0176                                       0);  // copy number
0177     }
0178   }
0179 
0180   //
0181   // Absorber
0182   //
0183   fSolidAbsorber = nullptr;
0184   fLogicAbsorber = nullptr;
0185   fPhysiAbsorber = nullptr;
0186 
0187   if (fAbsorberThickness > 0.) {
0188     fSolidAbsorber = new G4Box("Absorber",  // its name
0189                                fAbsorberThickness / 2, fCalorSizeYZ / 2, fCalorSizeYZ / 2);  // size
0190 
0191     fLogicAbsorber = new G4LogicalVolume(fSolidAbsorber,  // its solid
0192                                          fAbsorberMaterial,  // its material
0193                                          fAbsorberMaterial->GetName());  // name
0194 
0195     fPhysiAbsorber = new G4PVPlacement(nullptr,  // no rotation
0196                                        G4ThreeVector(-fGapThickness / 2, 0., 0.),  // its position
0197                                        fLogicAbsorber,  // its logical volume
0198                                        fAbsorberMaterial->GetName(),  // its name
0199                                        fLogicLayer,  // its mother
0200                                        false,  // no boulean operat
0201                                        0);  // copy number
0202   }
0203 
0204   //
0205   // Gap
0206   //
0207   fSolidGap = nullptr;
0208   fLogicGap = nullptr;
0209   fPhysiGap = nullptr;
0210 
0211   if (fGapThickness > 0.) {
0212     fSolidGap = new G4Box("Gap", fGapThickness / 2, fCalorSizeYZ / 2, fCalorSizeYZ / 2);
0213 
0214     fLogicGap = new G4LogicalVolume(fSolidGap, fGapMaterial, fGapMaterial->GetName());
0215 
0216     fPhysiGap = new G4PVPlacement(nullptr,  // no rotation
0217                                   G4ThreeVector(fAbsorberThickness / 2, 0., 0.),  // its position
0218                                   fLogicGap,  // its logical volume
0219                                   fGapMaterial->GetName(),  // its name
0220                                   fLogicLayer,  // its mother
0221                                   false,  // no boulean operat
0222                                   0);  // copy number
0223   }
0224 
0225   PrintCalorParameters();
0226 
0227   //
0228   // Visualization attributes
0229   //
0230   fLogicWorld->SetVisAttributes(G4VisAttributes::GetInvisible());
0231 
0232   auto simpleBoxVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
0233   simpleBoxVisAtt->SetVisibility(true);
0234   fLogicCalor->SetVisAttributes(simpleBoxVisAtt);
0235 
0236   //
0237   // always return the physical World
0238   //
0239   return fPhysiWorld;
0240 }
0241 
0242 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0243 
0244 void DetectorConstruction::PrintCalorParameters()
0245 {
0246   G4cout << "\n------------------------------------------------------------"
0247          << "\n---> The calorimeter is " << fNbOfLayers << " layers of: [ "
0248          << fAbsorberThickness / mm << "mm of " << fAbsorberMaterial->GetName() << " + "
0249          << fGapThickness / mm << "mm of " << fGapMaterial->GetName() << " ] "
0250          << "\n------------------------------------------------------------\n";
0251 }
0252 
0253 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0254 
0255 void DetectorConstruction::SetAbsorberMaterial(const G4String& materialChoice)
0256 {
0257   // search the material by its name
0258   auto material = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0259   if (material != nullptr) {
0260     fAbsorberMaterial = material;
0261     if (fLogicAbsorber != nullptr) {
0262       fLogicAbsorber->SetMaterial(fAbsorberMaterial);
0263       G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0264     }
0265   }
0266 }
0267 
0268 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0269 
0270 void DetectorConstruction::SetGapMaterial(const G4String& materialChoice)
0271 {
0272   auto material = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0273   if (material != nullptr) {
0274     fGapMaterial = material;
0275     if (fLogicGap != nullptr) {
0276       fLogicGap->SetMaterial(fGapMaterial);
0277       G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0278     }
0279   }
0280 }
0281 
0282 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0283 
0284 void DetectorConstruction::SetAbsorberThickness(G4double value)
0285 {
0286   // change Absorber thickness and recompute the calorimeter parameters
0287   fAbsorberThickness = value;
0288   if (G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit) {
0289     G4RunManager::GetRunManager()->ReinitializeGeometry();
0290   }
0291 }
0292 
0293 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0294 
0295 void DetectorConstruction::SetGapThickness(G4double value)
0296 {
0297   // change Gap thickness and recompute the calorimeter parameters
0298   fGapThickness = value;
0299   if (G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit) {
0300     G4RunManager::GetRunManager()->ReinitializeGeometry();
0301   }
0302 }
0303 
0304 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0305 
0306 void DetectorConstruction::SetCalorSizeYZ(G4double value)
0307 {
0308   // change the transverse size and recompute the calorimeter parameters
0309   fCalorSizeYZ = value;
0310   if (G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit) {
0311     G4RunManager::GetRunManager()->ReinitializeGeometry();
0312   }
0313 }
0314 
0315 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0316 
0317 void DetectorConstruction::SetNbOfLayers(G4int value)
0318 {
0319   fNbOfLayers = value;
0320   if (G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit) {
0321     G4RunManager::GetRunManager()->ReinitializeGeometry();
0322   }
0323 }
0324 
0325 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......