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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 ]

Diff markup

Differences between /examples/basic/B4/B4a/src/DetectorConstruction.cc (Version 11.3.0) and /examples/basic/B4/B4a/src/DetectorConstruction.cc (Version 11.2.1)


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