Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:55

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 DetectorConstruction.cc
0028 /// \brief DetectorConstruction class
0029 //
0030 //
0031 #include "DetectorConstruction.hh"
0032 
0033 #include "G4Box.hh"
0034 #include "G4GeometryManager.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4Material.hh"
0037 #include "G4NistManager.hh"
0038 #include "G4PVPlacement.hh"
0039 #include "G4ProductionCuts.hh"
0040 #include "G4RunManager.hh"
0041 #include "G4SystemOfUnits.hh"
0042 #include "G4ThreeVector.hh"
0043 #include "G4Tubs.hh"
0044 #include "G4UnitsTable.hh"
0045 #include "G4VPhysicalVolume.hh"
0046 #include "G4VisAttributes.hh"
0047 
0048 const bool check_intersections = true;  // to control geometry for errors
0049 
0050 // new unit
0051 const G4double ug = 1.e-6 * g;
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 G4VPhysicalVolume* DetectorConstruction::Construct()
0056 {
0057   auto man = G4NistManager::Instance();
0058 
0059   // registering new useful unit
0060   new G4UnitDefinition("microgram", "ug", "Mass", ug);
0061 
0062   // geometric parameters
0063   G4double worldSize = 8 * cm;
0064   G4double worldDensity = 0.15 * mg / m3;  // imperfect vacuum as in a real-world experiment
0065 
0066   G4double IV_diameter = 10 * mm;
0067   G4double IV_height = 20 * mm;
0068   G4double IV_vertical_offset = -5 * mm;  // instead of moving beam axis, the IV is moved
0069   G4double IV_density = 0.45 * ug / cm3;
0070 
0071   G4double wall_tot_mass_thickness = 0.98 * mg / cm2;  // Mylar wall thickness -> 7 µm
0072   G4double wall_inner_layer_mass_thickness =
0073     0.02 * mg / cm2;  // inner layer of wall made of water material at Mylar density
0074 
0075   fCollDiameter = 3 * mm;  // inner diameter of the collimator, the outer is twice that
0076   fCollLength = 23 * mm;
0077   fCollExitPosition = -5.5 * mm;  // exit of the collimator, where the beam is already formed
0078 
0079   G4double enDet_diameter = 10 * mm;
0080   G4double enDet_thickness = 150 * um;
0081   G4double enDet_distance = 10 * mm;
0082 
0083   // materials
0084   auto worldMaterial =
0085     man->BuildMaterialWithNewDensity("WORLD_WATER_VACUUM", "G4_WATER", worldDensity);
0086   auto targetMaterial = man->BuildMaterialWithNewDensity("TARGET_WATER", "G4_WATER", IV_density);
0087   auto wallMaterial = man->FindOrBuildMaterial("G4_MYLAR");
0088   auto collMaterial = man->FindOrBuildMaterial("G4_BRASS");
0089   auto enDetMaterial = man->FindOrBuildMaterial("G4_Si");
0090 
0091   // auxiliary variables:
0092   G4ThreeVector origin(0, 0, 0);
0093   G4ThreeVector IV_centre(0, 0, IV_vertical_offset);
0094   G4ThreeVector enDet_centre(enDet_distance + IV_diameter / 2., 0, 0);
0095 
0096   G4double mylarDensity = wallMaterial->GetDensity();
0097   G4double wall_total_thickness = wall_tot_mass_thickness / mylarDensity;
0098   G4double wall_inner_layer_thickness = wall_inner_layer_mass_thickness / mylarDensity;
0099 
0100   // materials continued
0101   auto innerWallMaterial = man->BuildMaterialWithNewDensity("WALL_WATER", "G4_WATER", mylarDensity);
0102 
0103   // SAVING DETECTOR SETTINGS TO FILE:
0104   auto filename = "SIM_GEOMETRY_SETTINGS.txt";
0105   std::ofstream TextFile;
0106   TextFile.open(filename, std::fstream::out);
0107   TextFile << "worldSize = " << worldSize / cm << " cm\n";
0108   TextFile << "worldDensity = " << worldDensity / (mg / m3) << " mg/m3\n";
0109   TextFile << "IV_diameter = " << IV_diameter / mm << " mm\n";
0110   TextFile << "IV_height = " << IV_height / mm << " mm\n";
0111   TextFile << "IV_vertical_offset = " << IV_vertical_offset / mm << " mm\n";
0112   TextFile << "IV_density = " << IV_density / (ug / cm3) << " ug/cm3\n";
0113   TextFile << "wall_tot_mass_thickness = " << wall_tot_mass_thickness / (mg / cm2) << " mg/cm2\n";
0114   TextFile << "wall_inner_layer_mass_thickness = " << wall_inner_layer_mass_thickness / (mg / cm2)
0115            << " mg/cm2\n";
0116   TextFile << "fCollDiameter = " << fCollDiameter / mm << " mm\n";
0117   TextFile << "fCollLength = " << fCollLength / mm << " mm\n";
0118   TextFile << "fCollExitPosition = " << fCollExitPosition / mm << " mm\n";
0119   TextFile << "enDet_diameter = " << enDet_diameter / mm << " mm\n";
0120   TextFile << "enDet_thickness = " << enDet_thickness / mm << " mm\n";
0121   TextFile << "enDet_distance = " << enDet_distance / mm << " mm\n";
0122   TextFile << "worldMaterial: " << worldMaterial->GetName() << "\n";
0123   TextFile << "targetMaterial: " << targetMaterial->GetName() << "\n";
0124   TextFile << "wallMaterial: " << wallMaterial->GetName() << "\n";
0125   TextFile << "collMaterial: " << collMaterial->GetName() << "\n";
0126   TextFile << "enDetMaterial: " << enDetMaterial->GetName() << "\n";
0127   TextFile << "innerWallMaterial: " << innerWallMaterial->GetName() << "\n";
0128 
0129   // WORLD VOLUME
0130 
0131   auto worldSolid = new G4Box("worldSolid",  // its name
0132                               worldSize / 2, worldSize / 2,
0133                               worldSize / 2);  // its size
0134 
0135   auto worldLogic = new G4LogicalVolume(worldSolid,  // its solid
0136                                         worldMaterial,  // its material
0137                                         "worldLogic");  // its name
0138 
0139   auto worldPhys = new G4PVPlacement(nullptr,  // no rotation
0140                                      G4ThreeVector(0, 0, 0),  // placement
0141                                      worldLogic,  // its logical volume
0142                                      "worldPhys",  // its name
0143                                      nullptr,  // its mother volume
0144                                      false,  // no boolean operation
0145                                      0,  // copy number
0146                                      check_intersections);  // check intersections
0147 
0148   // INTERACTION VOLUME (IV, also called chamber)
0149   auto chamberSolid = new G4Tubs("chamberSolid",  // its name
0150                                  0,  // rMin
0151                                  IV_diameter / 2.,  // rMax
0152                                  IV_height / 2.,  // height/2
0153                                  0 * deg,  // phiMin
0154                                  360 * deg);  // phiMax
0155 
0156   auto chamberLogic = new G4LogicalVolume(chamberSolid,  // its solid
0157                                           targetMaterial,  // its material
0158                                           "chamberLogic");  // its name
0159 
0160   new G4PVPlacement(nullptr, IV_centre, chamberLogic, "chamberPhys", worldLogic, false, 0,
0161                     check_intersections);
0162 
0163   // SENSITIVE VOLUME (SV, also called target) - in general a sub-volume of the
0164   // IV, but in this case entire IV is the SV only ionisations that occur in the
0165   // SV will be counted
0166   auto targetSolid = new G4Tubs("targetSolid",  // name
0167                                 0,  // rMin
0168                                 IV_diameter / 2.,  // rMax
0169                                 IV_height / 2.,  // height/2
0170                                 0 * deg,  // phiMin
0171                                 360 * deg);  // phiMax
0172 
0173   auto targetLogic = new G4LogicalVolume(targetSolid, targetMaterial, "targetLogic");
0174 
0175   new G4PVPlacement(nullptr, origin, targetLogic, "targetPhys", chamberLogic, false, 0,
0176                     check_intersections);
0177 
0178   // WALLS:
0179   //
0180 
0181   auto wallSolid = new G4Tubs("wallSolid",  // name
0182                               IV_diameter / 2.,  // rMin
0183                               IV_diameter / 2. + wall_total_thickness,  // rMax
0184                               IV_height / 2.,  // height/2
0185                               0 * deg,  // phiMin
0186                               360 * deg);  // phiMax
0187 
0188   auto wallLogic = new G4LogicalVolume(wallSolid, wallMaterial, "wallSolid");
0189   new G4PVPlacement(nullptr, IV_centre, wallLogic, "wallPhys", worldLogic, false, 0,
0190                     check_intersections);
0191 
0192   // wall inner layer made of water
0193   auto innerWallSolid = new G4Tubs("innerWallSolid",  // name
0194                                    IV_diameter / 2.,  // rMin
0195                                    IV_diameter / 2. + wall_inner_layer_thickness,  // rMax
0196                                    IV_height / 2.,  // height/2
0197                                    0 * deg,  // phiMin
0198                                    360 * deg);  // phiMax
0199 
0200   auto innerWallLogic = new G4LogicalVolume(innerWallSolid, innerWallMaterial, "innerWallLogic");
0201   new G4PVPlacement(nullptr, origin, innerWallLogic, "innerWallPhys", wallLogic, false, 0,
0202                     check_intersections);
0203 
0204   // COLLIMATOR:
0205   auto collSolid = new G4Tubs("collSolid",  // name
0206                               fCollDiameter / 2.,  // rMin
0207                               fCollDiameter,  // rMax
0208                               fCollLength / 2.,  // height/2
0209                               0 * deg,  // phiMin
0210                               360 * deg);  // phiMax
0211 
0212   auto collLogic = new G4LogicalVolume(collSolid, collMaterial, "collSolid");
0213 
0214   auto rot = new G4RotationMatrix();
0215   rot->rotateY(90 * deg);
0216   new G4PVPlacement(rot, G4ThreeVector(-fCollLength / 2 + fCollExitPosition, 0, 0), collLogic,
0217                     "collPhys", worldLogic, false, 0, check_intersections);
0218 
0219   // SILICON DETECTOR - present only in macrometric geometry
0220 
0221   auto enDetSolid = new G4Tubs("enDetSolid",  // name
0222                                0,  // rMin
0223                                enDet_diameter / 2.,  // rMax
0224                                enDet_thickness / 2.,  // height/2
0225                                0 * deg, 360 * deg);
0226 
0227   auto enDetLogic = new G4LogicalVolume(enDetSolid, enDetMaterial, "enDetLogic");
0228   new G4PVPlacement(rot, enDet_centre, enDetLogic, "enDetPhys", worldLogic, false, 0,
0229                     check_intersections);
0230 
0231   // VISUALISATION ATTRIBUTES
0232 
0233   auto worldVisAtt = new G4VisAttributes(G4Colour(1, 1, 1, 0.1));
0234   worldLogic->SetVisAttributes(worldVisAtt);
0235 
0236   auto targetVisAtt = new G4VisAttributes(G4Colour(0.1, 0.5, 1, 0.7));
0237   targetLogic->SetVisAttributes(targetVisAtt);
0238 
0239   auto innerWallVisAtt = new G4VisAttributes(G4Colour(0, 1, 1, 0.7));
0240   innerWallLogic->SetVisAttributes(innerWallVisAtt);
0241 
0242   auto collVisAtt = new G4VisAttributes(G4Colour(0.7, 0.65, .25, 0.5));
0243   collLogic->SetVisAttributes(collVisAtt);
0244 
0245   auto enDetVisAtt = new G4VisAttributes(G4Colour(0.5, 0.7, .5, 1.));
0246   enDetLogic->SetVisAttributes(enDetVisAtt);
0247 
0248   // Create Target G4Region and add logical volume
0249 
0250   auto region = new G4Region("Target");
0251 
0252   auto cuts = new G4ProductionCuts();
0253 
0254   G4double defCut = 1 * nanometer;
0255   cuts->SetProductionCut(defCut, "gamma");
0256   cuts->SetProductionCut(defCut, "e-");
0257   cuts->SetProductionCut(defCut, "e+");
0258   cuts->SetProductionCut(defCut, "proton");
0259 
0260   region->SetProductionCuts(cuts);
0261   region->AddRootLogicalVolume(chamberLogic);
0262   region->AddRootLogicalVolume(targetLogic);
0263   region->AddRootLogicalVolume(innerWallLogic);
0264 
0265   return worldPhys;
0266 }
0267 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......