Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-10 08:06:17

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 //
0030 
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0033 
0034 #include "DetectorConstruction.hh"
0035 
0036 #include "DetectorMessenger.hh"
0037 #include "PrimaryGeneratorAction.hh"
0038 
0039 #include "G4Box.hh"
0040 #include "G4GeometryManager.hh"
0041 #include "G4LogicalVolume.hh"
0042 #include "G4LogicalVolumeStore.hh"
0043 #include "G4Material.hh"
0044 #include "G4NistManager.hh"
0045 #include "G4PVPlacement.hh"
0046 #include "G4PhysicalConstants.hh"
0047 #include "G4PhysicalVolumeStore.hh"
0048 #include "G4RunManager.hh"
0049 #include "G4SolidStore.hh"
0050 #include "G4Sphere.hh"
0051 #include "G4SystemOfUnits.hh"
0052 #include "G4ThreeVector.hh"
0053 #include "globals.hh"
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 DetectorConstruction::DetectorConstruction()
0058   : fMaterialTracker(nullptr),
0059     fMaterialEmCalo(nullptr),
0060     fMaterialHadCalo(nullptr),
0061     fExperimentalHall_log(nullptr),
0062     fExperimentalHall_phys(nullptr),
0063     fLogicTrackerShell(nullptr),
0064     fPhysiTrackerShell(nullptr),
0065     fLogicEmCaloShell(nullptr),
0066     fPhysiEmCaloShell(nullptr),
0067     fLogicHadCaloShell(nullptr),
0068     fPhysiHadCaloShell(nullptr),
0069     fLogicScoringTrackerShell(nullptr),
0070     fPhysiScoringTrackerShell(nullptr),
0071     fLogicScoringEmCaloShell(nullptr),
0072     fPhysiScoringEmCaloShell(nullptr),
0073     fLogicScoringHadCaloShell(nullptr),
0074     fPhysiScoringHadCaloShell(nullptr),
0075     fDetectorMessenger(nullptr),
0076     fInnerRadiusTracker(10.0 * cm),
0077     fOuterRadiusTracker(20.0 * cm),  //***LOOKHERE*** Default radii
0078     fInnerRadiusEmCalo(30.0 * cm),
0079     fOuterRadiusEmCalo(60.0 * cm),
0080     fInnerRadiusHadCalo(70.0 * cm),
0081     fOuterRadiusHadCalo(170.0 * cm)
0082 {
0083   // G4cout << " BEGIN  DetectorConstruction::DetectorConstruction()" << G4endl;
0084   fMaterialTracker = G4NistManager::Instance()->FindOrBuildMaterial("G4_Si");  //***LOOKHERE***
0085                                                                                // Default material
0086   fMaterialEmCalo = G4NistManager::Instance()->FindOrBuildMaterial("G4_PbWO4");
0087   fMaterialHadCalo = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe");
0088   fDetectorMessenger = new DetectorMessenger(this);
0089   // G4cout << " END  DetectorConstruction::DetectorConstruction()" << G4endl;
0090 }
0091 
0092 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0093 
0094 DetectorConstruction::~DetectorConstruction()
0095 {
0096   delete fDetectorMessenger;
0097 }
0098 
0099 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0100 
0101 G4VPhysicalVolume* DetectorConstruction::Construct()
0102 {
0103   // G4cout << " BEGIN  DetectorConstruction::Construct()" << G4endl;
0104   return ConstructDetector();
0105 }
0106 
0107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0108 
0109 G4VPhysicalVolume* DetectorConstruction::ConstructDetector()
0110 {
0111   // G4cout << " BEGIN  DetectorConstruction::ConstructDetector()" << G4endl;
0112 
0113   // Clean old geometry, if any.
0114   G4GeometryManager::GetInstance()->OpenGeometry();
0115 
0116   G4PhysicalVolumeStore::GetInstance()->Clean();
0117   G4LogicalVolumeStore::GetInstance()->Clean();
0118   G4SolidStore::GetInstance()->Clean();
0119 
0120   // Check that the radii are resonable
0121   G4bool isOK = true;
0122   if (fInnerRadiusTracker < 0.0 || fOuterRadiusTracker < fInnerRadiusTracker
0123       || fInnerRadiusEmCalo < fOuterRadiusTracker + fScoringThickness
0124       || fOuterRadiusEmCalo < fInnerRadiusEmCalo
0125       || fInnerRadiusHadCalo < fOuterRadiusEmCalo + fScoringThickness
0126       || fOuterRadiusHadCalo < fInnerRadiusHadCalo)
0127   {
0128     isOK = false;
0129   }
0130   if (!isOK) {
0131     G4cerr << G4endl << "ERROR: the radii are inconsistent !" << G4endl
0132            << " InnerRadiusTracker = " << fInnerRadiusTracker << " mm" << G4endl
0133            << " OuterRadiusTracker = " << fOuterRadiusTracker << " mm" << G4endl
0134            << " InnerRadiusEmCalo  = " << fInnerRadiusEmCalo << " mm" << G4endl
0135            << " OuterRadiusEmCalo  = " << fOuterRadiusEmCalo << " mm" << G4endl
0136            << " InnerRadiusHadCalo = " << fInnerRadiusHadCalo << " mm" << G4endl
0137            << " OuterRadiusHadCalo = " << fOuterRadiusHadCalo << " mm" << G4endl
0138            << " ScoringThickness   = " << fScoringThickness << " mm" << G4endl << G4endl;
0139     return nullptr;
0140   }
0141 
0142   // The detector consists of 3 concentric full spherical shells (G4Sphere),
0143   // positioned at the center, (0.0, 0.0, 0.0).
0144   // The world volume (experimental hall) is a box 10% bigger than the outmost
0145   // spherical shell.
0146   // and it is filled of "G4_Galactic" material.
0147 
0148   G4double expHall_x = 1.1 * fOuterRadiusHadCalo;  // half dimension along x
0149   G4double expHall_y = 1.1 * fOuterRadiusHadCalo;  // half dimension along y
0150   G4double expHall_z = 1.1 * fOuterRadiusHadCalo;  // half dimension along z
0151 
0152   G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0153 
0154   G4Box* experimentalHall_box = new G4Box("expHall_box", expHall_x, expHall_y, expHall_z);
0155 
0156   fExperimentalHall_log = new G4LogicalVolume(experimentalHall_box,  // solid
0157                                               vacuum,  // material
0158                                               "expHall_log",  // name
0159                                               0,  // field manager
0160                                               0,  // sensitive detector
0161                                               0);  // user limits
0162 
0163   fExperimentalHall_phys = new G4PVPlacement(0,  // rotation
0164                                              G4ThreeVector(),  // translation
0165                                              "expHall",  // name
0166                                              fExperimentalHall_log,  // logical volume
0167                                              0,  // mother physical volume
0168                                              false,  // boolean operation
0169                                              0);  // copy number
0170 
0171   // 1st (innermost) spherical shell: Tracker
0172   G4Sphere* solidTrackerShell = new G4Sphere("solidTrackerShell",  // name
0173                                              fInnerRadiusTracker,  // Inner radius
0174                                              fOuterRadiusTracker,  // Outer radius
0175                                              0.0,  // Starting Phi angle of the
0176                                                    // segment in radians
0177                                              2.0 * CLHEP::pi,  // Delta Phi angle of the
0178                                                                // segment in radians
0179                                              0.0,  // Starting Theta angle of
0180                                                    // the segment in radians
0181                                              CLHEP::pi);  // Delta Theta angle of the
0182                                                           // segment in radians
0183   fLogicTrackerShell = new G4LogicalVolume(solidTrackerShell,  // solid
0184                                            fMaterialTracker,  // material
0185                                            "logicTrackerShell",  // name
0186                                            0,  // field manager
0187                                            0,  // sensitive detector
0188                                            0);  // user limits
0189   fPhysiTrackerShell = new G4PVPlacement(0,  // rotation
0190                                          G4ThreeVector(),  // translation
0191                                          "physiTrackerShell",  // name
0192                                          fLogicTrackerShell,  // logical volume
0193                                          fExperimentalHall_phys,  // mother physical volume
0194                                          false,  // boolean operation
0195                                          0);  // copy number
0196 
0197   // Scoring tracker shell (a thin vacuum layer, immediately outside the Tracker shell)
0198   G4Sphere* solidScoringTrackerShell =
0199     new G4Sphere("solidScoringTrackerShell",  // name
0200                  fOuterRadiusTracker,  // Inner radius
0201                  fOuterRadiusTracker + fScoringThickness,  // Outer radius
0202                  0.0,  // Starting Phi angle of the segment
0203                        // in radians
0204                  2.0 * CLHEP::pi,  // Delta Phi angle of the segment
0205                                    // in radians
0206                  0.0,  // Starting Theta angle of the segment
0207                        // in radians
0208                  CLHEP::pi);  // Delta Theta angle of the segment
0209                               // in radians
0210   fLogicScoringTrackerShell = new G4LogicalVolume(solidScoringTrackerShell,  // solid
0211                                                   vacuum,  // material
0212                                                   "logicScoringTrackerShell",  // name
0213                                                   0,  // field manager
0214                                                   0,  // sensitive
0215                                                       // detector
0216                                                   0);  // user limits
0217   fPhysiScoringTrackerShell = new G4PVPlacement(0,  // rotation
0218                                                 G4ThreeVector(),  // translation
0219                                                 "physiScoringTrackerShell",  // name
0220                                                 fLogicScoringTrackerShell,  // logical volume
0221                                                 fExperimentalHall_phys,  // mother physical
0222                                                                          // volume
0223                                                 false,  // boolean
0224                                                         // operation
0225                                                 0);  // copy number
0226 
0227   // 2nd (middle) spherical shell: EM Calo
0228   G4Sphere* solidEmCaloShell = new G4Sphere("solidEmCaloShell",  // name
0229                                             fInnerRadiusEmCalo,  // Inner radius
0230                                             fOuterRadiusEmCalo,  // Outer radius
0231                                             0.0,  // Starting Phi angle of the
0232                                                   // segment in radians
0233                                             2.0 * CLHEP::pi,  // Delta Phi angle of the
0234                                                               // segment in radians
0235                                             0.0,  // Starting Theta angle of the
0236                                                   // segment in radians
0237                                             CLHEP::pi);  // Delta Theta angle of the
0238                                                          // segment in radians
0239   fLogicEmCaloShell = new G4LogicalVolume(solidEmCaloShell,  // solid
0240                                           fMaterialEmCalo,  // material
0241                                           "logicEmCaloShell",  // name
0242                                           0,  // field manager
0243                                           0,  // sensitive detector
0244                                           0);  // user limits
0245   fPhysiEmCaloShell = new G4PVPlacement(0,  // rotation
0246                                         G4ThreeVector(),  // translation
0247                                         "physiEmCaloShell",  // name
0248                                         fLogicEmCaloShell,  // logical volume
0249                                         fExperimentalHall_phys,  // mother physical volume
0250                                         false,  // boolean operation
0251                                         0);  // copy number
0252 
0253   // Scoring EmCalo shell (a thin vacuum layer, immediately outside the EmCalo shell)
0254   G4Sphere* solidScoringEmCaloShell =
0255     new G4Sphere("solidScoringEmCaloShell",  // name
0256                  fOuterRadiusEmCalo,  // Inner radius
0257                  fOuterRadiusEmCalo + fScoringThickness,  // Outer radius
0258                  0.0,  // Starting Phi angle of the segment
0259                        // in radians
0260                  2.0 * CLHEP::pi,  // Delta Phi angle of the segment
0261                                    // in radians
0262                  0.0,  // Starting Theta angle of the
0263                        // segment in radians
0264                  CLHEP::pi);  // Delta Theta angle of the segment
0265                               // in radians
0266   fLogicScoringEmCaloShell = new G4LogicalVolume(solidScoringEmCaloShell,  // solid
0267                                                  vacuum,  // material
0268                                                  "logicScoringEmCaloShell",  // name
0269                                                  0,  // field manager
0270                                                  0,  // sensitive
0271                                                      // detector
0272                                                  0);  // user limits
0273   fPhysiScoringEmCaloShell = new G4PVPlacement(0,  // rotation
0274                                                G4ThreeVector(),  // translation
0275                                                "physiScoringEmCaloShell",  // name
0276                                                fLogicScoringEmCaloShell,  // logical volume
0277                                                fExperimentalHall_phys,  // mother physical
0278                                                                         // volume
0279                                                false,  // boolean operation
0280                                                0);  // copy number
0281 
0282   // 3rd (outmost) spherical shell: HAD Calo
0283   G4Sphere* solidHadCaloShell = new G4Sphere("solidHadCaloShell",  // name
0284                                              fInnerRadiusHadCalo,  // Inner radius
0285                                              fOuterRadiusHadCalo,  // Outer radius
0286                                              0.0,  // Starting Phi angle of the
0287                                                    // segment in radians
0288                                              2.0 * CLHEP::pi,  // Delta Phi angle of the
0289                                                                // segment in radians
0290                                              0.0,  // Starting Theta angle of
0291                                                    // the segment in radians
0292                                              CLHEP::pi);  // Delta Theta angle of the
0293                                                           // segment in radians
0294   fLogicHadCaloShell = new G4LogicalVolume(solidHadCaloShell,  // solid
0295                                            fMaterialHadCalo,  // material
0296                                            "logicHadCaloShell",  // name
0297                                            0,  // field manager
0298                                            0,  // sensitive detector
0299                                            0);  // user limits
0300   fPhysiHadCaloShell = new G4PVPlacement(0,  // rotation
0301                                          G4ThreeVector(),  // translation
0302                                          "physiHadCaloShell",  // name
0303                                          fLogicHadCaloShell,  // logical volume
0304                                          fExperimentalHall_phys,  // mother physical volume
0305                                          false,  // boolean operation
0306                                          0);  // copy number
0307 
0308   // Scoring HadCalo shell (a thin vacuum layer, immediately outside the HadCalo shell)
0309   G4Sphere* solidScoringHadCaloShell =
0310     new G4Sphere("solidScoringHadCaloShell",  // name
0311                  fOuterRadiusHadCalo,  // Inner radius
0312                  fOuterRadiusHadCalo + fScoringThickness,  // Outer radius
0313                  0.0,  // Starting Phi angle of the
0314                        // segment in radians
0315                  2.0 * CLHEP::pi,  // Delta Phi angle of the segment
0316                                    // in radians
0317                  0.0,  // Starting Theta angle of the
0318                        // segment in radians
0319                  CLHEP::pi);  // Delta Theta angle of the segment
0320                               // in radians
0321   fLogicScoringHadCaloShell = new G4LogicalVolume(solidScoringHadCaloShell,  // solid
0322                                                   vacuum,  // material
0323                                                   "logicScoringHadCaloShell",  // name
0324                                                   0,  // field manager
0325                                                   0,  // sensitive
0326                                                       // detector
0327                                                   0);  // user limits
0328   fPhysiScoringHadCaloShell = new G4PVPlacement(0,  // rotation
0329                                                 G4ThreeVector(),  // translation
0330                                                 "physiScoringHadCaloShell",  // name
0331                                                 fLogicScoringHadCaloShell,  // logical volume
0332                                                 fExperimentalHall_phys,  // mother physical
0333                                                                          // volume
0334                                                 false,  // boolean
0335                                                         // operation
0336                                                 0);  // copy number
0337 
0338   G4cout << "DetectorConstruction::ConstructSphere() : " << G4endl
0339          << "\t World (box) size: " << G4endl << "\t \t x : -/+ " << expHall_x << " mm ;"
0340          << "\t y : -/+ " << expHall_y << " mm ;"
0341          << "\t z : -/+ " << expHall_z << " mm ;" << G4endl << G4endl;
0342   PrintParameters();
0343   // G4cout << " END  DetectorConstruction::ConstructDetector()
0344 
0345   return fExperimentalHall_phys;
0346 }
0347 
0348 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0349 
0350 void DetectorConstruction::SetMaterialTracker(const G4String name)
0351 {
0352   fMaterialTracker = G4NistManager::Instance()->FindOrBuildMaterial(name);
0353   if (!fMaterialTracker) {
0354     G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!"
0355            << G4endl << "     ===> the default  * G4_Si *  will be used." << G4endl << G4endl;
0356     fMaterialTracker = G4NistManager::Instance()->FindOrBuildMaterial("G4_Si");
0357   }
0358   if (fLogicTrackerShell) fLogicTrackerShell->SetMaterial(fMaterialTracker);
0359 }
0360 
0361 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0362 
0363 void DetectorConstruction::SetMaterialEmCalo(const G4String name)
0364 {
0365   fMaterialEmCalo = G4NistManager::Instance()->FindOrBuildMaterial(name);
0366   if (!fMaterialEmCalo) {
0367     G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!"
0368            << G4endl << "     ===> the default  * G4_Pb *  will be used." << G4endl << G4endl;
0369     fMaterialEmCalo = G4NistManager::Instance()->FindOrBuildMaterial("G4_Pb");
0370   }
0371   if (fLogicEmCaloShell) fLogicEmCaloShell->SetMaterial(fMaterialEmCalo);
0372 }
0373 
0374 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0375 
0376 void DetectorConstruction::SetMaterialHadCalo(const G4String name)
0377 {
0378   fMaterialHadCalo = G4NistManager::Instance()->FindOrBuildMaterial(name);
0379   if (fMaterialHadCalo == nullptr) {
0380     G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!"
0381            << G4endl << "     ===> the default  * G4_Fe *  will be used." << G4endl << G4endl;
0382     fMaterialHadCalo = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe");
0383   }
0384   if (fLogicHadCaloShell) fLogicHadCaloShell->SetMaterial(fMaterialHadCalo);
0385 }
0386 
0387 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0388 
0389 void DetectorConstruction::UpdateGeometry()
0390 {
0391   // G4cout << " BEGIN  DetectorConstruction::UpdateGeometry" << G4endl;
0392   G4RunManager::GetRunManager()->ReinitializeGeometry();
0393   PrintParameters();
0394   // Update also the position of the gun
0395   const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast<const PrimaryGeneratorAction*>(
0396     G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0397   if (pPrimaryAction) pPrimaryAction->SetGunPosition();
0398   // G4cout << " END  DetectorConstruction::UpdateGeometry" << G4endl;
0399 }
0400 
0401 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0402 
0403 void DetectorConstruction::PrintParameters()
0404 {
0405   G4cout << G4endl << " ------  DetectorConstruction::PrintParameters() ------ " << G4endl
0406          << " MaterialTracker = " << fMaterialTracker->GetName() << G4endl
0407          << " MaterialEmCalo  = " << fMaterialEmCalo->GetName() << G4endl
0408          << " MaterialHadCalo = " << fMaterialHadCalo->GetName() << G4endl
0409          << " InnerRadiusTracker = " << fInnerRadiusTracker << " mm" << G4endl
0410          << " OuterRadiusTracker = " << fOuterRadiusTracker << " mm" << G4endl
0411          << " InnerRadiusEmCalo  = " << fInnerRadiusEmCalo << " mm" << G4endl
0412          << " OuterRadiusEmCalo  = " << fOuterRadiusEmCalo << " mm" << G4endl
0413          << " InnerRadiusHadCalo = " << fInnerRadiusHadCalo << " mm" << G4endl
0414          << " OuterRadiusHadCalo = " << fOuterRadiusHadCalo << " mm" << G4endl
0415          << " ScoringThickness   = " << fScoringThickness << " mm" << G4endl
0416          << " -------------------------------------------------------- " << G4endl << G4endl;
0417 }
0418 
0419 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......