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