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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/hadronic/Hadr02/src/DetectorConstruction.cc (Version 11.3.0) and /examples/extended/hadronic/Hadr02/src/DetectorConstruction.cc (Version 10.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 hadronic/Hadr02/src/DetectorConstruc     26 /// \file hadronic/Hadr02/src/DetectorConstruction.cc
 27 /// \brief Implementation of the DetectorConst     27 /// \brief Implementation of the DetectorConstruction class
 28 //                                                 28 //
                                                   >>  29 // $Id: DetectorConstruction.cc 81932 2014-06-06 15:39:45Z gcosmo $
 29 //                                                 30 //
 30 //////////////////////////////////////////////     31 /////////////////////////////////////////////////////////////////////////
 31 //                                                 32 //
 32 // DetectorConstruction                            33 // DetectorConstruction
 33 //                                                 34 //
 34 // Created: 31.01.2003 V.Ivanchenko                35 // Created: 31.01.2003 V.Ivanchenko
 35 //                                                 36 //
 36 // Modified:                                       37 // Modified:
 37 // 04.06.2006 Adoptation of hadr01 (V.Ivanchen     38 // 04.06.2006 Adoptation of hadr01 (V.Ivanchenko)
 38 //                                                 39 //
 39 //////////////////////////////////////////////     40 ////////////////////////////////////////////////////////////////////////
 40 //                                             <<  41 // 
 41                                                    42 
 42 #include "DetectorConstruction.hh"                 43 #include "DetectorConstruction.hh"
 43                                                << 
 44 #include "DetectorMessenger.hh"                    44 #include "DetectorMessenger.hh"
 45 #include "HistoManager.hh"                     << 
 46 #include "TargetSD.hh"                         << 
 47                                                    45 
 48 #include "G4Colour.hh"                         <<  46 #include "G4Tubs.hh"
 49 #include "G4GeometryManager.hh"                << 
 50 #include "G4LogicalVolume.hh"                      47 #include "G4LogicalVolume.hh"
 51 #include "G4LogicalVolumeStore.hh"             << 
 52 #include "G4NistManager.hh"                    << 
 53 #include "G4PVPlacement.hh"                        48 #include "G4PVPlacement.hh"
 54 #include "G4PhysicalConstants.hh"              <<  49 
 55 #include "G4PhysicalVolumeStore.hh"            << 
 56 #include "G4RunManager.hh"                         50 #include "G4RunManager.hh"
 57 #include "G4SDManager.hh"                      <<  51 
                                                   >>  52 #include "G4GeometryManager.hh"
                                                   >>  53 #include "G4PhysicalVolumeStore.hh"
                                                   >>  54 #include "G4LogicalVolumeStore.hh"
 58 #include "G4SolidStore.hh"                         55 #include "G4SolidStore.hh"
 59 #include "G4SystemOfUnits.hh"                  <<  56 
 60 #include "G4Tubs.hh"                           << 
 61 #include "G4UnitsTable.hh"                     << 
 62 #include "G4VisAttributes.hh"                      57 #include "G4VisAttributes.hh"
                                                   >>  58 #include "G4Colour.hh"
                                                   >>  59 
                                                   >>  60 #include "G4UnitsTable.hh"
 63 #include "G4ios.hh"                                61 #include "G4ios.hh"
 64                                                    62 
                                                   >>  63 #include "TargetSD.hh"
                                                   >>  64 #include "G4SDManager.hh"
                                                   >>  65 #include "HistoManager.hh"
                                                   >>  66 #include "G4NistManager.hh"
                                                   >>  67 
                                                   >>  68 #include "G4PhysicalConstants.hh"
                                                   >>  69 #include "G4SystemOfUnits.hh"
                                                   >>  70 
                                                   >>  71 
 65 //....oooOO0OOooo........oooOO0OOooo........oo     72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 66                                                    73 
 67 DetectorConstruction::DetectorConstruction()       74 DetectorConstruction::DetectorConstruction()
 68   : G4VUserDetectorConstruction(),             <<  75  : G4VUserDetectorConstruction(),
 69     fRadius(10. * cm),                         <<  76    fRadius(10.*cm),
 70     fTargetMaterial(0),                        <<  77    fTargetMaterial(0),
 71     fWorldMaterial(0),                         <<  78    fWorldMaterial(0),
 72     fTargetSD(0),                              <<  79    fTargetSD(0),
 73     fLogicTarget(0),                           <<  80    fLogicTarget(0),
 74     fLogicWorld(0),                            <<  81    fLogicWorld (0),
 75     fDetectorMessenger(0)                      <<  82    fDetectorMessenger(0)
 76                                                <<  83   
 77 {                                                  84 {
 78   fDetectorMessenger = new DetectorMessenger(t     85   fDetectorMessenger = new DetectorMessenger(this);
 79                                                    86 
 80   fTargetMaterial = G4NistManager::Instance()- <<  87   fTargetMaterial 
 81   fWorldMaterial = G4NistManager::Instance()-> <<  88     = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al");
                                                   >>  89   fWorldMaterial = 
                                                   >>  90     G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
 82   HistoManager::GetPointer()->SetTargetMateria     91   HistoManager::GetPointer()->SetTargetMaterial(fTargetMaterial);
 83                                                    92 
 84   // Prepare sensitive detectors                   93   // Prepare sensitive detectors
 85   fTargetSD = new TargetSD("targetSD");            94   fTargetSD = new TargetSD("targetSD");
 86   G4SDManager::GetSDMpointer()->AddNewDetector     95   G4SDManager::GetSDMpointer()->AddNewDetector(fTargetSD);
 87 }                                              <<  96 } 
 88                                                    97 
 89 //....oooOO0OOooo........oooOO0OOooo........oo     98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 90                                                    99 
 91 DetectorConstruction::~DetectorConstruction()     100 DetectorConstruction::~DetectorConstruction()
 92 {                                              << 101 { 
 93   delete fDetectorMessenger;                      102   delete fDetectorMessenger;
 94 }                                                 103 }
 95                                                   104 
 96 G4VPhysicalVolume* DetectorConstruction::Const    105 G4VPhysicalVolume* DetectorConstruction::Construct()
 97 {                                                 106 {
 98   // Cleanup old geometry                         107   // Cleanup old geometry
 99   G4GeometryManager::GetInstance()->OpenGeomet    108   G4GeometryManager::GetInstance()->OpenGeometry();
100   G4PhysicalVolumeStore::GetInstance()->Clean(    109   G4PhysicalVolumeStore::GetInstance()->Clean();
101   G4LogicalVolumeStore::GetInstance()->Clean()    110   G4LogicalVolumeStore::GetInstance()->Clean();
102   G4SolidStore::GetInstance()->Clean();           111   G4SolidStore::GetInstance()->Clean();
103                                                   112 
104   // Sizes                                        113   // Sizes
105   G4double checkR = fRadius + mm;              << 114   G4double checkR  = fRadius + mm;
106   G4double worldR = fRadius + cm;              << 115   G4double worldR  = fRadius + cm;
107   G4double targetZ = HistoManager::GetPointer( << 116   G4double targetZ = HistoManager::GetPointer()->Length()*0.5; 
108   G4double checkZ = targetZ + mm;              << 117   G4double checkZ  = targetZ + mm;
109   G4double worldZ = targetZ + cm;              << 118   G4double worldZ  = targetZ + cm;
110                                                << 119 
111   G4int nSlices = HistoManager::GetPointer()-> << 120   G4int nSlices    = HistoManager::GetPointer()->NumberOfSlices();
112   G4double sliceZ = targetZ / G4double(nSlices << 121   G4double sliceZ  = targetZ/G4double(nSlices);
113                                                << 122  
114   //                                              123   //
115   // World                                        124   // World
116   G4Tubs* solidW = new G4Tubs("World", 0., wor << 125   G4Tubs* solidW = new G4Tubs("World",0.,worldR,worldZ,0.,twopi);
117   fLogicWorld = new G4LogicalVolume(solidW, fW << 126   fLogicWorld = new G4LogicalVolume( solidW,fWorldMaterial,"World");
118   G4VPhysicalVolume* world =                   << 127   G4VPhysicalVolume* world = new G4PVPlacement(0,G4ThreeVector(),
119     new G4PVPlacement(0, G4ThreeVector(), fLog << 128                                        fLogicWorld,"World",0,false,0);
120   //                                              129   //
121   // Check volume                                 130   // Check volume
122   //                                              131   //
123   G4Tubs* solidC = new G4Tubs("Check", 0., che << 132   G4Tubs* solidC = new G4Tubs("Check",0.,checkR,checkZ,0.,twopi);
124   G4LogicalVolume* logicCheck = new G4LogicalV << 133   G4LogicalVolume* logicCheck 
125   new G4PVPlacement(0, G4ThreeVector(), logicC << 134     = new G4LogicalVolume( solidC,fWorldMaterial,"World");
                                                   >> 135   new G4PVPlacement(0,G4ThreeVector(),logicCheck,"World",fLogicWorld,false,0);
126                                                   136 
127   //                                              137   //
128   // Target volume                                138   // Target volume
129   //                                              139   //
130   G4Tubs* solidA = new G4Tubs("Target", 0., fR << 140   G4Tubs* solidA = new G4Tubs("Target",0.,fRadius,sliceZ,0.,twopi);
131   fLogicTarget = new G4LogicalVolume(solidA, f << 141   fLogicTarget = new G4LogicalVolume( solidA,fTargetMaterial,"Target");
132   fLogicTarget->SetSensitiveDetector(fTargetSD    142   fLogicTarget->SetSensitiveDetector(fTargetSD);
133                                                   143 
134   G4double z = sliceZ - targetZ;                  144   G4double z = sliceZ - targetZ;
135                                                   145 
136   for (G4int i = 0; i < nSlices; i++) {        << 146   for(G4int i=0; i<nSlices; i++) {
137     // physC =                                 << 147     // physC = 
138     new G4PVPlacement(0, G4ThreeVector(0.0, 0. << 148     new G4PVPlacement(0,G4ThreeVector(0.0,0.0,z),fLogicTarget,
139     z += 2.0 * sliceZ;                         << 149                       "Target",logicCheck,false,i);
                                                   >> 150     z += 2.0*sliceZ;
140   }                                               151   }
141   G4cout << "### Target consist of " << nSlice << 152   G4cout << "### Target consist of " << nSlices
142          << " disks with R(mm)= " << fRadius / << 153          << " of " << fTargetMaterial->GetName() 
143          << "  Total Length(mm)= " << 2.0 * ta << 154          << " disks with R(mm)= " << fRadius/mm
                                                   >> 155          << "  Width(mm)= " << 2.0*sliceZ/mm
                                                   >> 156          << "  Total Length(mm)= " << 2.0*targetZ/mm
                                                   >> 157          <<  "  ###" << G4endl;
144                                                   158 
145   // colors                                       159   // colors
146   G4VisAttributes zero = G4VisAttributes::GetI << 160   G4VisAttributes zero = G4VisAttributes::Invisible;
147   fLogicWorld->SetVisAttributes(zero);         << 161   fLogicWorld->SetVisAttributes(&zero);
148                                                   162 
149   G4VisAttributes regWcolor(G4Colour(0.3, 0.3,    163   G4VisAttributes regWcolor(G4Colour(0.3, 0.3, 0.3));
150   logicCheck->SetVisAttributes(regWcolor);     << 164   logicCheck->SetVisAttributes(&regWcolor);
151                                                   165 
152   G4VisAttributes regCcolor(G4Colour(0., 0.3,     166   G4VisAttributes regCcolor(G4Colour(0., 0.3, 0.7));
153   fLogicTarget->SetVisAttributes(regCcolor);   << 167   fLogicTarget->SetVisAttributes(&regCcolor);
154                                                   168 
155   G4cout << *(G4Material::GetMaterialTable())     169   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
156                                                   170 
157   return world;                                   171   return world;
158 }                                                 172 }
159                                                   173 
160 //....oooOO0OOooo........oooOO0OOooo........oo    174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
161                                                   175 
162 void DetectorConstruction::SetTargetMaterial(c    176 void DetectorConstruction::SetTargetMaterial(const G4String& mat)
163 {                                                 177 {
164   // search the material by its name              178   // search the material by its name
165   G4Material* material = G4NistManager::Instan    179   G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
166                                                << 180  
167   if (material && material != fTargetMaterial)    181   if (material && material != fTargetMaterial) {
168     HistoManager::GetPointer()->SetTargetMater    182     HistoManager::GetPointer()->SetTargetMaterial(material);
169     fTargetMaterial = material;                   183     fTargetMaterial = material;
170     if (fLogicTarget) {                        << 184     if(fLogicTarget) { fLogicTarget->SetMaterial(fTargetMaterial); }
171       fLogicTarget->SetMaterial(fTargetMateria << 
172     }                                          << 
173     G4RunManager::GetRunManager()->PhysicsHasB    185     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
174   }                                               186   }
175 }                                                 187 }
176                                                   188 
177 //....oooOO0OOooo........oooOO0OOooo........oo    189 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
178                                                   190 
179 void DetectorConstruction::SetWorldMaterial(co    191 void DetectorConstruction::SetWorldMaterial(const G4String& mat)
180 {                                                 192 {
181   // search the material by its name              193   // search the material by its name
182   G4Material* material = G4NistManager::Instan    194   G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
183                                                   195 
184   if (material && material != fWorldMaterial)     196   if (material && material != fWorldMaterial) {
185     fWorldMaterial = material;                    197     fWorldMaterial = material;
186     if (fLogicWorld) {                         << 198     if(fLogicWorld) { fLogicWorld->SetMaterial(fWorldMaterial); }
187       fLogicWorld->SetMaterial(fWorldMaterial) << 
188     }                                          << 
189     G4RunManager::GetRunManager()->PhysicsHasB    199     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
190   }                                               200   }
191 }                                                 201 }
192                                                   202 
193 //....oooOO0OOooo........oooOO0OOooo........oo    203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
194                                                   204 
195 void DetectorConstruction::SetTargetRadius(G4d << 205 void DetectorConstruction::SetTargetRadius(G4double val)  
196 {                                                 206 {
197   if (val > 0.0) {                             << 207   if(val > 0.0) {
198     fRadius = val;                                208     fRadius = val;
199     G4RunManager::GetRunManager()->GeometryHas    209     G4RunManager::GetRunManager()->GeometryHasBeenModified();
200   }                                            << 210   } 
201 }                                                 211 }
202                                                   212 
203 //....oooOO0OOooo........oooOO0OOooo........oo    213 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
204                                                   214