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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.0.p2)


  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 DetectorConstruction.cc
 28 /// \brief Implementation of the B4::DetectorC <<  28 /// \brief Implementation of the 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;
                                                   >>  60 
                                                   >>  61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >>  62 
                                                   >>  63 DetectorConstruction::DetectorConstruction()
                                                   >>  64 {
                                                   >>  65 }
                                                   >>  66 
                                                   >>  67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >>  68 
                                                   >>  69 DetectorConstruction::~DetectorConstruction()
                                                   >>  70 {
                                                   >>  71 }
 51                                                    72 
 52 //....oooOO0OOooo........oooOO0OOooo........oo     73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 53                                                    74 
 54 G4VPhysicalVolume* DetectorConstruction::Const     75 G4VPhysicalVolume* DetectorConstruction::Construct()
 55 {                                                  76 {
 56   // Define materials                              77   // Define materials
 57   DefineMaterials();                               78   DefineMaterials();
 58                                                    79 
 59   // Define volumes                                80   // Define volumes
 60   return DefineVolumes();                          81   return DefineVolumes();
 61 }                                                  82 }
 62                                                    83 
 63 //....oooOO0OOooo........oooOO0OOooo........oo     84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 64                                                    85 
 65 void DetectorConstruction::DefineMaterials()       86 void DetectorConstruction::DefineMaterials()
 66 {                                                  87 {
 67   // Lead material defined using NIST Manager      88   // Lead material defined using NIST Manager
 68   auto nistManager = G4NistManager::Instance()     89   auto nistManager = G4NistManager::Instance();
 69   nistManager->FindOrBuildMaterial("G4_Pb");       90   nistManager->FindOrBuildMaterial("G4_Pb");
 70                                                    91 
 71   // Liquid argon material                         92   // Liquid argon material
 72   G4double a;  // mass of a mole;                  93   G4double a;  // mass of a mole;
 73   G4double z;  // z=mean number of protons;        94   G4double z;  // z=mean number of protons;
 74   G4double density;                                95   G4double density;
 75   new G4Material("liquidArgon", z = 18., a = 3 <<  96   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 <<  97          // The argon by NIST Manager is a gas with a different density
 77                                                    98 
 78   // Vacuum                                        99   // Vacuum
 79   new G4Material("Galactic", z = 1., a = 1.01  << 100   new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
 80                  kStateGas, 2.73 * kelvin, 3.e << 101                   kStateGas, 2.73*kelvin, 3.e-18*pascal);
 81                                                   102 
 82   // Print materials                              103   // Print materials
 83   G4cout << *(G4Material::GetMaterialTable())     104   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
 84 }                                                 105 }
 85                                                   106 
 86 //....oooOO0OOooo........oooOO0OOooo........oo    107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 87                                                   108 
 88 G4VPhysicalVolume* DetectorConstruction::Defin    109 G4VPhysicalVolume* DetectorConstruction::DefineVolumes()
 89 {                                                 110 {
 90   // Geometry parameters                          111   // Geometry parameters
 91   G4int nofLayers = 10;                           112   G4int nofLayers = 10;
 92   G4double absoThickness = 10. * mm;           << 113   G4double absoThickness = 10.*mm;
 93   G4double gapThickness = 5. * mm;             << 114   G4double gapThickness =  5.*mm;
 94   G4double calorSizeXY = 10. * cm;             << 115   G4double calorSizeXY  = 10.*cm;
 95                                                   116 
 96   auto layerThickness = absoThickness + gapThi    117   auto layerThickness = absoThickness + gapThickness;
 97   auto calorThickness = nofLayers * layerThick    118   auto calorThickness = nofLayers * layerThickness;
 98   auto worldSizeXY = 1.2 * calorSizeXY;           119   auto worldSizeXY = 1.2 * calorSizeXY;
 99   auto worldSizeZ = 1.2 * calorThickness;      << 120   auto worldSizeZ  = 1.2 * calorThickness;
100                                                   121 
101   // Get materials                                122   // Get materials
102   auto defaultMaterial = G4Material::GetMateri    123   auto defaultMaterial = G4Material::GetMaterial("Galactic");
103   auto absorberMaterial = G4Material::GetMater    124   auto absorberMaterial = G4Material::GetMaterial("G4_Pb");
104   auto gapMaterial = G4Material::GetMaterial("    125   auto gapMaterial = G4Material::GetMaterial("liquidArgon");
105                                                   126 
106   if (!defaultMaterial || !absorberMaterial || << 127   if ( ! defaultMaterial || ! absorberMaterial || ! gapMaterial ) {
107     G4ExceptionDescription msg;                   128     G4ExceptionDescription msg;
108     msg << "Cannot retrieve materials already     129     msg << "Cannot retrieve materials already defined.";
109     G4Exception("DetectorConstruction::DefineV << 130     G4Exception("DetectorConstruction::DefineVolumes()",
                                                   >> 131       "MyCode0001", FatalException, msg);
110   }                                               132   }
111                                                   133 
112   //                                              134   //
113   // World                                        135   // World
114   //                                              136   //
115   auto worldS = new G4Box("World",  // its nam << 137   auto worldS
116                           worldSizeXY / 2, wor << 138     = new G4Box("World",           // its name
117                                                << 139                  worldSizeXY/2, worldSizeXY/2, worldSizeZ/2); // its size
118   auto worldLV = new G4LogicalVolume(worldS,   << 140 
119                                      defaultMa << 141   auto worldLV
120                                      "World"); << 142     = new G4LogicalVolume(
121                                                << 143                  worldS,           // its solid
122   auto worldPV = new G4PVPlacement(nullptr,  / << 144                  defaultMaterial,  // its material
123                                    G4ThreeVect << 145                  "World");         // its name
124                                    worldLV,  / << 146 
125                                    "World",  / << 147   auto worldPV
126                                    nullptr,  / << 148     = new G4PVPlacement(
127                                    false,  //  << 149                  0,                // no rotation
128                                    0,  // copy << 150                  G4ThreeVector(),  // at (0,0,0)
129                                    fCheckOverl << 151                  worldLV,          // its logical volume
                                                   >> 152                  "World",          // its name
                                                   >> 153                  0,                // its mother  volume
                                                   >> 154                  false,            // no boolean operation
                                                   >> 155                  0,                // copy number
                                                   >> 156                  fCheckOverlaps);  // checking overlaps
130                                                   157 
131   //                                              158   //
132   // Calorimeter                                  159   // Calorimeter
133   //                                              160   //
134   auto calorimeterS = new G4Box("Calorimeter", << 161   auto calorimeterS
135                                 calorSizeXY /  << 162     = new G4Box("Calorimeter",     // its name
136                                                << 163                  calorSizeXY/2, calorSizeXY/2, calorThickness/2); // its size
137   auto calorLV = new G4LogicalVolume(calorimet << 164 
138                                      defaultMa << 165   auto calorLV
139                                      "Calorime << 166     = new G4LogicalVolume(
140                                                << 167                  calorimeterS,     // its solid
141   new G4PVPlacement(nullptr,  // no rotation   << 168                  defaultMaterial,  // its material
142                     G4ThreeVector(),  // at (0 << 169                  "Calorimeter");   // its name
143                     calorLV,  // its logical v << 170 
144                     "Calorimeter",  // its nam << 171   new G4PVPlacement(
145                     worldLV,  // its mother  v << 172                  0,                // no rotation
146                     false,  // no boolean oper << 173                  G4ThreeVector(),  // at (0,0,0)
147                     0,  // copy number         << 174                  calorLV,          // its logical volume
148                     fCheckOverlaps);  // check << 175                  "Calorimeter",    // its name
                                                   >> 176                  worldLV,          // its mother  volume
                                                   >> 177                  false,            // no boolean operation
                                                   >> 178                  0,                // copy number
                                                   >> 179                  fCheckOverlaps);  // checking overlaps
149                                                   180 
150   //                                              181   //
151   // Layer                                        182   // Layer
152   //                                              183   //
153   auto layerS = new G4Box("Layer",  // its nam << 184   auto layerS
154                           calorSizeXY / 2, cal << 185     = new G4Box("Layer",           // its name
155                                                << 186                  calorSizeXY/2, calorSizeXY/2, layerThickness/2); // its size
156   auto layerLV = new G4LogicalVolume(layerS,   << 187 
157                                      defaultMa << 188   auto layerLV
158                                      "Layer"); << 189     = new G4LogicalVolume(
159                                                << 190                  layerS,           // its solid
160   new G4PVReplica("Layer",  // its name        << 191                  defaultMaterial,  // its material
161                   layerLV,  // its logical vol << 192                  "Layer");         // its name
162                   calorLV,  // its mother      << 193 
163                   kZAxis,  // axis of replicat << 194   new G4PVReplica(
164                   nofLayers,  // number of rep << 195                  "Layer",          // its name
165                   layerThickness);  // witdth  << 196                  layerLV,          // its logical volume
                                                   >> 197                  calorLV,          // its mother
                                                   >> 198                  kZAxis,           // axis of replication
                                                   >> 199                  nofLayers,        // number of replica
                                                   >> 200                  layerThickness);  // witdth of replica
166                                                   201 
167   //                                              202   //
168   // Absorber                                     203   // Absorber
169   //                                              204   //
170   auto absorberS = new G4Box("Abso",  // its n << 205   auto absorberS
171                              calorSizeXY / 2,  << 206     = new G4Box("Abso",            // its name
172                                                << 207                  calorSizeXY/2, calorSizeXY/2, absoThickness/2); // its size
173   auto absorberLV = new G4LogicalVolume(absorb << 208 
174                                         absorb << 209   auto absorberLV
175                                         "Abso" << 210     = new G4LogicalVolume(
176                                                << 211                  absorberS,        // its solid
177   fAbsorberPV = new G4PVPlacement(nullptr,  // << 212                  absorberMaterial, // its material
178                                   G4ThreeVecto << 213                  "Abso");          // its name
179                                   absorberLV,  << 214 
180                                   "Abso",  //  << 215   fAbsorberPV
181                                   layerLV,  // << 216     = new G4PVPlacement(
182                                   false,  // n << 217                  0,                // no rotation
183                                   0,  // copy  << 218                  G4ThreeVector(0., 0., -gapThickness/2), // its position
184                                   fCheckOverla << 219                  absorberLV,       // its logical volume
                                                   >> 220                  "Abso",           // its name
                                                   >> 221                  layerLV,          // its mother  volume
                                                   >> 222                  false,            // no boolean operation
                                                   >> 223                  0,                // copy number
                                                   >> 224                  fCheckOverlaps);  // checking overlaps
185                                                   225 
186   //                                              226   //
187   // Gap                                          227   // Gap
188   //                                              228   //
189   auto gapS = new G4Box("Gap",  // its name    << 229   auto gapS
190                         calorSizeXY / 2, calor << 230     = new G4Box("Gap",             // its name
191                                                << 231                  calorSizeXY/2, calorSizeXY/2, gapThickness/2); // its size
192   auto gapLV = new G4LogicalVolume(gapS,  // i << 232 
193                                    gapMaterial << 233   auto gapLV
194                                    "Gap");  // << 234     = new G4LogicalVolume(
195                                                << 235                  gapS,             // its solid
196   fGapPV = new G4PVPlacement(nullptr,  // no r << 236                  gapMaterial,      // its material
197                              G4ThreeVector(0., << 237                  "Gap");           // its name
198                              gapLV,  // its lo << 238 
199                              "Gap",  // its na << 239   fGapPV
200                              layerLV,  // its  << 240     = new G4PVPlacement(
201                              false,  // no boo << 241                  0,                // no rotation
202                              0,  // copy numbe << 242                  G4ThreeVector(0., 0., absoThickness/2), // its position
203                              fCheckOverlaps);  << 243                  gapLV,            // its logical volume
                                                   >> 244                  "Gap",            // its name
                                                   >> 245                  layerLV,          // its mother  volume
                                                   >> 246                  false,            // no boolean operation
                                                   >> 247                  0,                // copy number
                                                   >> 248                  fCheckOverlaps);  // checking overlaps
204                                                   249 
205   //                                              250   //
206   // print parameters                             251   // print parameters
207   //                                              252   //
208   G4cout << G4endl << "----------------------- << 253   G4cout
209          << "---> The calorimeter is " << nofL << 254     << G4endl
210          << "mm of " << absorberMaterial->GetN << 255     << "------------------------------------------------------------" << G4endl
211          << gapMaterial->GetName() << " ] " << << 256     << "---> The calorimeter is " << nofLayers << " layers of: [ "
212          << "--------------------------------- << 257     << absoThickness/mm << "mm of " << absorberMaterial->GetName()
                                                   >> 258     << " + "
                                                   >> 259     << gapThickness/mm << "mm of " << gapMaterial->GetName() << " ] " << G4endl
                                                   >> 260     << "------------------------------------------------------------" << G4endl;
213                                                   261 
214   //                                              262   //
215   // Visualization attributes                     263   // Visualization attributes
216   //                                              264   //
217   worldLV->SetVisAttributes(G4VisAttributes::G << 265   worldLV->SetVisAttributes (G4VisAttributes::GetInvisible());
218   calorLV->SetVisAttributes(G4VisAttributes(G4 << 266 
                                                   >> 267   auto simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
                                                   >> 268   simpleBoxVisAtt->SetVisibility(true);
                                                   >> 269   calorLV->SetVisAttributes(simpleBoxVisAtt);
219                                                   270 
220   //                                              271   //
221   // Always return the physical World             272   // Always return the physical World
222   //                                              273   //
223   return worldPV;                                 274   return worldPV;
224 }                                                 275 }
225                                                   276 
226 //....oooOO0OOooo........oooOO0OOooo........oo    277 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
227                                                   278 
228 void DetectorConstruction::ConstructSDandField    279 void DetectorConstruction::ConstructSDandField()
229 {                                                 280 {
230   // Create global magnetic field messenger.      281   // Create global magnetic field messenger.
231   // Uniform magnetic field is then created au    282   // Uniform magnetic field is then created automatically if
232   // the field value is not zero.                 283   // the field value is not zero.
233   G4ThreeVector fieldValue;                       284   G4ThreeVector fieldValue;
234   fMagFieldMessenger = new G4GlobalMagFieldMes    285   fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
235   fMagFieldMessenger->SetVerboseLevel(1);         286   fMagFieldMessenger->SetVerboseLevel(1);
236                                                   287 
237   // Register the field messenger for deleting    288   // Register the field messenger for deleting
238   G4AutoDelete::Register(fMagFieldMessenger);     289   G4AutoDelete::Register(fMagFieldMessenger);
239 }                                                 290 }
240                                                   291 
241 //....oooOO0OOooo........oooOO0OOooo........oo    292 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
242                                                   293 
243 }  // namespace B4                             << 294 }
                                                   >> 295 
244                                                   296