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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/B4c/src/DetectorConstruction.cc (Version 11.3.0) and /examples/basic/B4/B4c/src/DetectorConstruction.cc (Version 11.1.3)


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