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10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 //
 27 /// \file B4/B4c/src/DetectorConstruction.cc
 28 /// \brief Implementation of the B4c::DetectorConstruction class
 29 
 30 #include "DetectorConstruction.hh"
 31 
 32 #include "CalorimeterSD.hh"
 33 
 34 #include "G4AutoDelete.hh"
 35 #include "G4Box.hh"
 36 #include "G4Colour.hh"
 37 #include "G4GlobalMagFieldMessenger.hh"
 38 #include "G4LogicalVolume.hh"
 39 #include "G4Material.hh"
 40 #include "G4NistManager.hh"
 41 #include "G4PVPlacement.hh"
 42 #include "G4PVReplica.hh"
 43 #include "G4PhysicalConstants.hh"
 44 #include "G4SDManager.hh"
 45 #include "G4SystemOfUnits.hh"
 46 #include "G4VisAttributes.hh"
 47 
 48 namespace B4c
 49 {
 50 
 51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 52 
 53 G4ThreadLocal G4GlobalMagFieldMessenger* DetectorConstruction::fMagFieldMessenger = nullptr;
 54 
 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 56 
 57 G4VPhysicalVolume* DetectorConstruction::Construct()
 58 {
 59   // Define materials
 60   DefineMaterials();
 61 
 62   // Define volumes
 63   return DefineVolumes();
 64 }
 65 
 66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 67 
 68 void DetectorConstruction::DefineMaterials()
 69 {
 70   // Lead material defined using NIST Manager
 71   auto nistManager = G4NistManager::Instance();
 72   nistManager->FindOrBuildMaterial("G4_Pb");
 73 
 74   // Liquid argon material
 75   G4double a;  // mass of a mole;
 76   G4double z;  // z=mean number of protons;
 77   G4double density;
 78   new G4Material("liquidArgon", z = 18., a = 39.95 * g / mole, density = 1.390 * g / cm3);
 79   // The argon by NIST Manager is a gas with a different density
 80 
 81   // Vacuum
 82   new G4Material("Galactic", z = 1., a = 1.01 * g / mole, density = universe_mean_density,
 83                  kStateGas, 2.73 * kelvin, 3.e-18 * pascal);
 84 
 85   // Print materials
 86   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
 87 }
 88 
 89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 90 
 91 G4VPhysicalVolume* DetectorConstruction::DefineVolumes()
 92 {
 93   // Geometry parameters
 94   fNofLayers = 10;
 95   G4double absoThickness = 10. * mm;
 96   G4double gapThickness = 5. * mm;
 97   G4double calorSizeXY = 10. * cm;
 98 
 99   auto layerThickness = absoThickness + gapThickness;
100   auto calorThickness = fNofLayers * layerThickness;
101   auto worldSizeXY = 1.2 * calorSizeXY;
102   auto worldSizeZ = 1.2 * calorThickness;
103 
104   // Get materials
105   auto defaultMaterial = G4Material::GetMaterial("Galactic");
106   auto absorberMaterial = G4Material::GetMaterial("G4_Pb");
107   auto gapMaterial = G4Material::GetMaterial("liquidArgon");
108 
109   if (!defaultMaterial || !absorberMaterial || !gapMaterial) {
110     G4ExceptionDescription msg;
111     msg << "Cannot retrieve materials already defined.";
112     G4Exception("DetectorConstruction::DefineVolumes()", "MyCode0001", FatalException, msg);
113   }
114 
115   //
116   // World
117   //
118   auto worldS = new G4Box("World",  // its name
119                           worldSizeXY / 2, worldSizeXY / 2, worldSizeZ / 2);  // its size
120 
121   auto worldLV = new G4LogicalVolume(worldS,  // its solid
122                                      defaultMaterial,  // its material
123                                      "World");  // its name
124 
125   auto worldPV = new G4PVPlacement(nullptr,  // no rotation
126                                    G4ThreeVector(),  // at (0,0,0)
127                                    worldLV,  // its logical volume
128                                    "World",  // its name
129                                    nullptr,  // its mother  volume
130                                    false,  // no boolean operation
131                                    0,  // copy number
132                                    fCheckOverlaps);  // checking overlaps
133 
134   //
135   // Calorimeter
136   //
137   auto calorimeterS = new G4Box("Calorimeter",  // its name
138                                 calorSizeXY / 2, calorSizeXY / 2, calorThickness / 2);  // its size
139 
140   auto calorLV = new G4LogicalVolume(calorimeterS,  // its solid
141                                      defaultMaterial,  // its material
142                                      "Calorimeter");  // its name
143 
144   new G4PVPlacement(nullptr,  // no rotation
145                     G4ThreeVector(),  // at (0,0,0)
146                     calorLV,  // its logical volume
147                     "Calorimeter",  // its name
148                     worldLV,  // its mother  volume
149                     false,  // no boolean operation
150                     0,  // copy number
151                     fCheckOverlaps);  // checking overlaps
152 
153   //
154   // Layer
155   //
156   auto layerS = new G4Box("Layer",  // its name
157                           calorSizeXY / 2, calorSizeXY / 2, layerThickness / 2);  // its size
158 
159   auto layerLV = new G4LogicalVolume(layerS,  // its solid
160                                      defaultMaterial,  // its material
161                                      "Layer");  // its name
162 
163   new G4PVReplica("Layer",  // its name
164                   layerLV,  // its logical volume
165                   calorLV,  // its mother
166                   kZAxis,  // axis of replication
167                   fNofLayers,  // number of replica
168                   layerThickness);  // witdth of replica
169 
170   //
171   // Absorber
172   //
173   auto absorberS = new G4Box("Abso",  // its name
174                              calorSizeXY / 2, calorSizeXY / 2, absoThickness / 2);  // its size
175 
176   auto absorberLV = new G4LogicalVolume(absorberS,  // its solid
177                                         absorberMaterial,  // its material
178                                         "AbsoLV");  // its name
179 
180   new G4PVPlacement(nullptr,  // no rotation
181                     G4ThreeVector(0., 0., -gapThickness / 2),  // its position
182                     absorberLV,  // its logical volume
183                     "Abso",  // its name
184                     layerLV,  // its mother  volume
185                     false,  // no boolean operation
186                     0,  // copy number
187                     fCheckOverlaps);  // checking overlaps
188 
189   //
190   // Gap
191   //
192   auto gapS = new G4Box("Gap",  // its name
193                         calorSizeXY / 2, calorSizeXY / 2, gapThickness / 2);  // its size
194 
195   auto gapLV = new G4LogicalVolume(gapS,  // its solid
196                                    gapMaterial,  // its material
197                                    "GapLV");  // its name
198 
199   new G4PVPlacement(nullptr,  // no rotation
200                     G4ThreeVector(0., 0., absoThickness / 2),  // its position
201                     gapLV,  // its logical volume
202                     "Gap",  // its name
203                     layerLV,  // its mother  volume
204                     false,  // no boolean operation
205                     0,  // copy number
206                     fCheckOverlaps);  // checking overlaps
207 
208   //
209   // print parameters
210   //
211   G4cout << G4endl << "------------------------------------------------------------" << G4endl
212          << "---> The calorimeter is " << fNofLayers << " layers of: [ " << absoThickness / mm
213          << "mm of " << absorberMaterial->GetName() << " + " << gapThickness / mm << "mm of "
214          << gapMaterial->GetName() << " ] " << G4endl
215          << "------------------------------------------------------------" << G4endl;
216 
217   //
218   // Visualization attributes
219   //
220   worldLV->SetVisAttributes(G4VisAttributes::GetInvisible());
221   calorLV->SetVisAttributes(G4VisAttributes(G4Colour::White()));
222 
223   //
224   // Always return the physical World
225   //
226   return worldPV;
227 }
228 
229 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
230 
231 void DetectorConstruction::ConstructSDandField()
232 {
233   // G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
234 
235   //
236   // Sensitive detectors
237   //
238   auto absoSD = new CalorimeterSD("AbsorberSD", "AbsorberHitsCollection", fNofLayers);
239   G4SDManager::GetSDMpointer()->AddNewDetector(absoSD);
240   SetSensitiveDetector("AbsoLV", absoSD);
241 
242   auto gapSD = new CalorimeterSD("GapSD", "GapHitsCollection", fNofLayers);
243   G4SDManager::GetSDMpointer()->AddNewDetector(gapSD);
244   SetSensitiveDetector("GapLV", gapSD);
245 
246   //
247   // Magnetic field
248   //
249   // Create global magnetic field messenger.
250   // Uniform magnetic field is then created automatically if
251   // the field value is not zero.
252   G4ThreeVector fieldValue;
253   fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
254   fMagFieldMessenger->SetVerboseLevel(1);
255 
256   // Register the field messenger for deleting
257   G4AutoDelete::Register(fMagFieldMessenger);
258 }
259 
260 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
261 
262 }  // namespace B4c
263