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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/extended/electromagnetic/TestEm2/src/DetectorConstruction.cc (Version 11.3.0) and /examples/extended/electromagnetic/TestEm2/src/DetectorConstruction.cc (Version 9.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 /// \file electromagnetic/TestEm2/src/Detector <<  26 // 
 27 /// \brief Implementation of the DetectorConst <<  27 // $Id: DetectorConstruction.cc,v 1.12 2006/10/20 16:03:40 maire Exp $
 28 //                                             <<  28 // GEANT4 tag $Name: geant4-09-01 $
                                                   >>  29 
 29 //....oooOO0OOooo........oooOO0OOooo........oo     30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 30 //....oooOO0OOooo........oooOO0OOooo........oo     31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 31                                                    32 
 32 #include "DetectorConstruction.hh"                 33 #include "DetectorConstruction.hh"
 33                                                << 
 34 #include "DetectorMessenger.hh"                    34 #include "DetectorMessenger.hh"
 35                                                    35 
 36 #include "G4AutoDelete.hh"                     <<  36 #include "G4Tubs.hh"
 37 #include "G4GeometryManager.hh"                << 
 38 #include "G4GlobalMagFieldMessenger.hh"        << 
 39 #include "G4LogicalVolume.hh"                      37 #include "G4LogicalVolume.hh"
 40 #include "G4LogicalVolumeStore.hh"             << 
 41 #include "G4NistManager.hh"                    << 
 42 #include "G4PVPlacement.hh"                        38 #include "G4PVPlacement.hh"
                                                   >>  39 #include "G4UniformMagField.hh"
                                                   >>  40 
                                                   >>  41 #include "G4GeometryManager.hh"
 43 #include "G4PhysicalVolumeStore.hh"                42 #include "G4PhysicalVolumeStore.hh"
 44 #include "G4RunManager.hh"                     <<  43 #include "G4LogicalVolumeStore.hh"
 45 #include "G4SolidStore.hh"                         44 #include "G4SolidStore.hh"
 46 #include "G4SystemOfUnits.hh"                  <<  45 
 47 #include "G4Tubs.hh"                           << 
 48 #include "G4UnitsTable.hh"                         46 #include "G4UnitsTable.hh"
 49                                                    47 
 50 //....oooOO0OOooo........oooOO0OOooo........oo     48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 51                                                    49 
 52 DetectorConstruction::DetectorConstruction()       50 DetectorConstruction::DetectorConstruction()
                                                   >>  51 :nLtot(40),nRtot(50),dLradl(0.5),dRradl(0.1),
                                                   >>  52  dLlength(0.),dRlength(0.),
                                                   >>  53  myMaterial(0),magField(0),
                                                   >>  54  EcalLength(0.),EcalRadius(0.),
                                                   >>  55  solidEcal(0),logicEcal(0),physiEcal(0)
 53 {                                                  56 {
 54   DefineMaterials();                               57   DefineMaterials();
 55   SetMaterial("G4_PbWO4");                     <<  58   SetMaterial("PbWO4");
 56   fDetectorMessenger = new DetectorMessenger(t <<  59   detectorMessenger = new DetectorMessenger(this);
 57 }                                                  60 }
 58                                                    61 
 59 //....oooOO0OOooo........oooOO0OOooo........oo     62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 60                                                    63 
 61 DetectorConstruction::~DetectorConstruction()      64 DetectorConstruction::~DetectorConstruction()
                                                   >>  65 { delete detectorMessenger;}
                                                   >>  66 
                                                   >>  67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >>  68 
                                                   >>  69 G4VPhysicalVolume* DetectorConstruction::Construct()
 62 {                                                  70 {
 63   delete fDetectorMessenger;                   <<  71   return ConstructVolumes();
 64 }                                                  72 }
 65                                                    73 
 66 //....oooOO0OOooo........oooOO0OOooo........oo     74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 67                                                    75 
 68 void DetectorConstruction::DefineMaterials()       76 void DetectorConstruction::DefineMaterials()
 69 {                                                  77 {
 70   //                                               78   //
 71   // define few Elements by hand               <<  79   // define few Elements
 72   //                                               80   //
 73   G4double a, z;                                   81   G4double a, z;
 74                                                <<  82     
 75   G4Element* H = new G4Element("Hydrogen", "H" <<  83   G4Element* H  = new G4Element("Hydrogen",  "H", z= 1., a=   1.01*g/mole);
 76   G4Element* O = new G4Element("Oxygen", "O",  <<  84   G4Element* N  = new G4Element("Nitrogen",  "N", z= 7., a=  14.01*g/mole);
 77   G4Element* Ge = new G4Element("Germanium", " <<  85   G4Element* O  = new G4Element("Oxygen"  ,  "O", z= 8., a=  16.00*g/mole);
 78   G4Element* Bi = new G4Element("Bismuth", "Bi <<  86   G4Element* Ge = new G4Element("Germanium", "Ge",z=32., a=  72.59*g/mole);
                                                   >>  87   G4Element* W  = new G4Element("Tungsten",  "W", z=74., a= 183.84*g/mole);
                                                   >>  88   G4Element* Pb = new G4Element("Lead",      "Pb",z=82., a= 207.19*g/mole);
                                                   >>  89   G4Element* Bi = new G4Element("Bismuth",   "Bi",z=83., a= 208.98*g/mole);
 79                                                    90 
 80   //                                               91   //
 81   // define materials                              92   // define materials
 82   //                                               93   //
 83   G4double density;                                94   G4double density;
 84   G4int ncomponents, natoms;                   <<  95   G4double fractionmass;  G4int ncomponents, natoms;
 85                                                    96 
 86   // water with ionisation potential 78 eV     <<  97   G4Material* Air = 
 87   G4Material* H2O = new G4Material("Water", de <<  98   new G4Material("Air", density= 1.29*mg/cm3, ncomponents=2);
 88   H2O->AddElement(H, natoms = 2);              <<  99   Air->AddElement(N, fractionmass=0.7);
 89   H2O->AddElement(O, natoms = 1);              << 100   Air->AddElement(O, fractionmass=0.3);
 90   H2O->GetIonisation()->SetMeanExcitationEnerg << 
 91                                                << 
 92   // pure materails                            << 
 93   new G4Material("liquidArgon", z = 18., a = 3 << 
 94   new G4Material("Aluminium", z = 13., a = 26. << 
 95   new G4Material("Iron", z = 26., a = 55.85 *  << 
 96   new G4Material("Copper", z = 29., a = 63.55  << 
 97   new G4Material("Tungsten", z = 74., a = 183. << 
 98   new G4Material("Lead", z = 82., a = 207.19 * << 
 99   new G4Material("Uranium", z = 92., a = 238.0 << 
100                                                << 
101   // compound material                         << 
102   G4Material* BGO = new G4Material("BGO", dens << 
103   BGO->AddElement(O, natoms = 12);             << 
104   BGO->AddElement(Ge, natoms = 3);             << 
105   BGO->AddElement(Bi, natoms = 4);             << 
106                                                << 
107   ////G4cout << *(G4Material::GetMaterialTable << 
108 }                                              << 
109                                                   101 
110 //....oooOO0OOooo........oooOO0OOooo........oo << 102   G4Material* H2O = 
                                                   >> 103   new G4Material("Water", density= 1.00*g/cm3, ncomponents=2);
                                                   >> 104   H2O->AddElement(H, natoms=2);
                                                   >> 105   H2O->AddElement(O, natoms=1);
                                                   >> 106   H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV);
111                                                   107 
112 void DetectorConstruction::UpdateParameters()  << 108   new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
113 {                                              << 109 
114   G4double Radl = fMaterial->GetRadlen();      << 110   new G4Material("Aluminium",   z=13., a= 26.98*g/mole, density= 2.7*g/cm3);
115   fDLlength = fDLradl * Radl;                  << 111 
116   fDRlength = fDRradl * Radl;                  << 112   new G4Material("Iron",        z=26., a= 55.85*g/mole, density= 7.87*g/cm3);
117   fEcalLength = fNLtot * fDLlength;            << 113   
118   fEcalRadius = fNRtot * fDRlength;            << 114   new G4Material("Copper"     , z=29., a= 63.55*g/mole, density= 8.960*g/cm3);
119   if (fSolidEcal) {                            << 115   
120     fSolidEcal->SetOuterRadius(fEcalRadius);   << 116   new G4Material("Lead",        z=82., a=207.19*g/mole, density=11.35*g/cm3);
121     fSolidEcal->SetZHalfLength(0.5 * fEcalLeng << 117   
122   }                                            << 118   new G4Material("Uranium"    , z=92., a=238.03*g/mole, density= 18.95*g/cm3);
                                                   >> 119     
                                                   >> 120   G4Material* BGO = 
                                                   >> 121   new G4Material("BGO", density= 7.10*g/cm3, ncomponents=3);
                                                   >> 122   BGO->AddElement(O , natoms=12);
                                                   >> 123   BGO->AddElement(Ge, natoms= 3);
                                                   >> 124   BGO->AddElement(Bi, natoms= 4);
                                                   >> 125 
                                                   >> 126   G4Material* PbWO = 
                                                   >> 127   new G4Material("PbWO4", density= 8.28*g/cm3, ncomponents=3);
                                                   >> 128   PbWO->AddElement(O , natoms=4);
                                                   >> 129   PbWO->AddElement(Pb, natoms=1);
                                                   >> 130   PbWO->AddElement(W , natoms=1);
                                                   >> 131 
                                                   >> 132   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
123 }                                                 133 }
124                                                   134 
125 //....oooOO0OOooo........oooOO0OOooo........oo    135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
126                                                   136 
127 G4VPhysicalVolume* DetectorConstruction::Const << 137 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
128 {                                                 138 {
129   UpdateParameters();                          << 139   G4double Radl = myMaterial->GetRadlen();
                                                   >> 140 
                                                   >> 141   dLlength = dLradl*Radl; dRlength = dRradl*Radl;
                                                   >> 142   EcalLength = nLtot*dLlength;  EcalRadius = nRtot*dRlength;
                                                   >> 143 
                                                   >> 144   // Cleanup old geometry
                                                   >> 145   G4GeometryManager::GetInstance()->OpenGeometry();
                                                   >> 146   G4PhysicalVolumeStore::GetInstance()->Clean();
                                                   >> 147   G4LogicalVolumeStore::GetInstance()->Clean();
                                                   >> 148   G4SolidStore::GetInstance()->Clean();
                                                   >> 149 
130   //                                              150   //
131   // Ecal                                         151   // Ecal
132   //                                              152   //
133   if (!fPhysiEcal) {                           << 153   solidEcal = new G4Tubs("Ecal",0.,EcalRadius,0.5*EcalLength,0.,360*deg);
134     fSolidEcal = new G4Tubs("Ecal", 0., fEcalR << 154   logicEcal = new G4LogicalVolume( solidEcal,myMaterial,"Ecal",0,0,0);
135     fLogicEcal = new G4LogicalVolume(fSolidEca << 155   physiEcal = new G4PVPlacement(0,G4ThreeVector(),
136     fPhysiEcal = new G4PVPlacement(0, G4ThreeV << 156                                 logicEcal,"Ecal",0,false,0);
137   }                                            << 157 
138   G4cout << "\n Absorber is " << G4BestUnit(fE << 158   G4cout << "Absorber is " << G4BestUnit(EcalLength,"Length")
139          << "  R= " << fEcalRadius / cm << " c << 159          << " of " << myMaterial->GetName() << G4endl;
140          << G4endl;                            << 160   G4cout << myMaterial << G4endl;     
141   G4cout << fMaterial << G4endl;               << 161 
142   //                                              162   //
143   // always return the physical World          << 163   //always return the physical World
144   //                                              164   //
145   return fPhysiEcal;                           << 165   return physiEcal;
146 }                                                 166 }
147                                                   167 
148 //....oooOO0OOooo........oooOO0OOooo........oo    168 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
149                                                   169 
150 void DetectorConstruction::SetMaterial(const G    170 void DetectorConstruction::SetMaterial(const G4String& materialChoice)
151 {                                                 171 {
152   // search the material by its name              172   // search the material by its name
153   G4Material* pttoMaterial = G4NistManager::In << 173   G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
154                                                << 174   if (pttoMaterial) myMaterial = pttoMaterial;
155   if (pttoMaterial && fMaterial != pttoMateria << 
156     fMaterial = pttoMaterial;                  << 
157     if (fLogicEcal) {                          << 
158       fLogicEcal->SetMaterial(fMaterial);      << 
159     }                                          << 
160     G4RunManager::GetRunManager()->PhysicsHasB << 
161   }                                            << 
162 }                                                 175 }
163                                                   176 
164 //....oooOO0OOooo........oooOO0OOooo........oo    177 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
165                                                   178 
166 void DetectorConstruction::SetLBining(G4ThreeV    179 void DetectorConstruction::SetLBining(G4ThreeVector Value)
167 {                                                 180 {
168   fNLtot = (G4int)Value(0);                    << 181   nLtot = (G4int)Value(0);
169   if (fNLtot > kMaxBin) {                      << 182   if (nLtot > MaxBin) {
170     G4cout << "\n ---> warning from SetLBining << 183     G4cout << "\n ---> warning from SetLBining: "
171            << G4endl;                          << 184            << nLtot << " truncated to " << MaxBin << G4endl;
172     fNLtot = kMaxBin;                          << 185     nLtot = MaxBin;
173   }                                            << 186   }  
174   fDLradl = Value(1);                          << 187   dLradl = Value(1);
175   UpdateParameters();                          << 
176 }                                                 188 }
177                                                   189 
178 //....oooOO0OOooo........oooOO0OOooo........oo    190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
179                                                   191 
180 void DetectorConstruction::SetRBining(G4ThreeV    192 void DetectorConstruction::SetRBining(G4ThreeVector Value)
181 {                                                 193 {
182   fNRtot = (G4int)Value(0);                    << 194   nRtot = (G4int)Value(0);
183   if (fNRtot > kMaxBin) {                      << 195   if (nRtot > MaxBin) {
184     G4cout << "\n ---> warning from SetRBining << 196     G4cout << "\n ---> warning from SetRBining: "
185            << G4endl;                          << 197            << nRtot << " truncated to " << MaxBin << G4endl;
186     fNRtot = kMaxBin;                          << 198     nRtot = MaxBin;
187   }                                            << 199   }    
188   fDRradl = Value(1);                          << 200   dRradl = Value(1);
189   UpdateParameters();                          << 
190 }                                                 201 }
191                                                   202 
192 //....oooOO0OOooo........oooOO0OOooo........oo    203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
193                                                   204 
194 void DetectorConstruction::ConstructSDandField << 205 #include "G4FieldManager.hh"
                                                   >> 206 #include "G4TransportationManager.hh"
                                                   >> 207 
                                                   >> 208 void DetectorConstruction::SetMagField(G4double fieldValue)
195 {                                                 209 {
196   if (fFieldMessenger.Get() == nullptr) {      << 210   //apply a global uniform magnetic field along Z axis
197     // Create global magnetic field messenger. << 211   G4FieldManager* fieldMgr
198     // Uniform magnetic field is then created  << 212    = G4TransportationManager::GetTransportationManager()->GetFieldManager();
199     // the field value is not zero.            << 213 
200     G4ThreeVector fieldValue = G4ThreeVector() << 214   if(magField) delete magField;   //delete the existing magn field
201     G4GlobalMagFieldMessenger* msg = new G4Glo << 215 
202     // msg->SetVerboseLevel(1);                << 216   if(fieldValue!=0.)      // create a new one if non nul
203     G4AutoDelete::Register(msg);               << 217   { magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
204     fFieldMessenger.Put(msg);                  << 218     fieldMgr->SetDetectorField(magField);
                                                   >> 219     fieldMgr->CreateChordFinder(magField);
                                                   >> 220   } else {
                                                   >> 221     magField = 0;
                                                   >> 222     fieldMgr->SetDetectorField(magField);
205   }                                               223   }
                                                   >> 224 }
                                                   >> 225 
                                                   >> 226 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >> 227 
                                                   >> 228 #include "G4RunManager.hh"
                                                   >> 229 
                                                   >> 230 void DetectorConstruction::UpdateGeometry()
                                                   >> 231 {
                                                   >> 232   G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
206 }                                                 233 }
207                                                   234 
208 //....oooOO0OOooo........oooOO0OOooo........oo    235 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
209                                                   236