Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:50:41

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