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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 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 /// \file DetectorConstruction.cc
 27 /// \brief Implementation of the DetectorConstruction class
 28 //
 29 //
 30 
 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 33 
 34 #include "DetectorConstruction.hh"
 35 
 36 #include "DetectorMessenger.hh"
 37 #include "PrimaryGeneratorAction.hh"
 38 
 39 #include "G4Box.hh"
 40 #include "G4FieldManager.hh"
 41 #include "G4GeometryManager.hh"
 42 #include "G4LogicalVolume.hh"
 43 #include "G4LogicalVolumeStore.hh"
 44 #include "G4Material.hh"
 45 #include "G4NistManager.hh"
 46 #include "G4PVPlacement.hh"
 47 #include "G4PhysicalConstants.hh"
 48 #include "G4PhysicalVolumeStore.hh"
 49 #include "G4RunManager.hh"
 50 #include "G4SolidStore.hh"
 51 #include "G4SystemOfUnits.hh"
 52 #include "G4ThreeVector.hh"
 53 #include "G4TransportationManager.hh"
 54 #include "G4Tubs.hh"
 55 #include "G4UniformMagField.hh"
 56 #include "globals.hh"
 57 
 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 59 
 60 DetectorConstruction::DetectorConstruction()
 61   : G4VUserDetectorConstruction(),
 62     fTargetMaterial(nullptr),
 63     fLogicExperimentalHall(nullptr),
 64     fPhysExperimentalHall(nullptr),
 65     fLogicTargetLayer(nullptr),
 66     fPhysTargetLayer(nullptr),
 67     fFieldMgr(nullptr),
 68     fUniformMagField(nullptr),
 69     fDetectorMessenger(nullptr),
 70     fTargetInnerRadius(9.0 * mm),
 71     fTargetOuterRadius(11.0 * mm)  //***LOOKHERE*** Default values
 72 {
 73   fFieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
 74   //***LOOKHERE*** Default material
 75   fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Be");
 76   fDetectorMessenger = new DetectorMessenger(this);
 77 }
 78 
 79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 80 
 81 DetectorConstruction::~DetectorConstruction()
 82 {
 83   delete fUniformMagField;
 84   delete fDetectorMessenger;
 85 }
 86 
 87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 88 
 89 G4VPhysicalVolume* DetectorConstruction::Construct()
 90 {
 91   return ConstructLayer();
 92 }
 93 
 94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 95 
 96 G4VPhysicalVolume* DetectorConstruction::ConstructLayer()
 97 {
 98   // Clean old geometry, if any
 99   G4GeometryManager::GetInstance()->OpenGeometry();
100   G4PhysicalVolumeStore::GetInstance()->Clean();
101   G4LogicalVolumeStore::GetInstance()->Clean();
102   G4SolidStore::GetInstance()->Clean();
103   // The geometry consists of a cylinder with axis along the z-direction, and
104   // positioned at the center, (0.0, 0.0, 0.0). Its inner and outer radius, and
105   // its material can be set via UI commands.
106   // The world volume (experimental hall) is a box slightly bigger than the cylinder
107   // and it is filled of "G4_Galactic" material.
108   const G4double halfLength = 1.0 * m;  //***LOOKHERE*** Half-length of the cylinder
109   const G4double expHall_x = 1.01 * halfLength;  // half dimension along x
110   const G4double expHall_y = 1.01 * halfLength;  // half dimension along y
111   const G4double expHall_z = 1.01 * halfLength;  // half dimension along z
112   G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
113   G4Box* experimentalHallBox = new G4Box("expHallBox", expHall_x, expHall_y, expHall_z);
114   fLogicExperimentalHall = new G4LogicalVolume(experimentalHallBox,  // solid
115                                                vacuum,  // material
116                                                "logicExpHall",  // name
117                                                0,  // field manager
118                                                0,  // sensitive detector
119                                                0);  // user limits
120   fPhysExperimentalHall = new G4PVPlacement(0,  // rotation
121                                             G4ThreeVector(),  // translation
122                                             "expHall",  // name
123                                             fLogicExperimentalHall,  // logical volume
124                                             0,  // mother physical volume
125                                             false,  // boolean operation
126                                             0);  // copy number
127   // Cylinder along the z-axis, with inner and outer diameter
128   G4Tubs* solidTargetLayer = new G4Tubs("solidTargetLayer",
129                                         fTargetInnerRadius,  // inner radius
130                                         fTargetOuterRadius,  // outer radius
131                                         halfLength,  // half cylinder length in z
132                                         0.0,  // starting phi angle in rad
133                                         2.0 * pi);  // final phi angle in rad
134   fLogicTargetLayer = new G4LogicalVolume(solidTargetLayer,  // solid
135                                           fTargetMaterial,  // material
136                                           "logicTargetLayer",  // name
137                                           0,  // field manager
138                                           0,  // sensitive detector
139                                           0);  // user limits
140   fPhysTargetLayer = new G4PVPlacement(0,  // rotation
141                                        G4ThreeVector(),  // translation
142                                        "physTargetLayer",  // name
143                                        fLogicTargetLayer,  // logical volume
144                                        fPhysExperimentalHall,  // mother physical volume
145                                        false,  // boolean operation
146                                        0);  // copy number
147   PrintParameters();
148   G4cout << G4endl << "DetectorConstruction::ConstructLayer() : " << G4endl
149          << "\t World (box) size: " << G4endl << "\t \t x : -/+ " << expHall_x << " mm ;"
150          << "\t y : -/+ " << expHall_y << " mm ;"
151          << "\t z : -/+ " << expHall_z << " mm ;" << G4endl
152          << "\t Layer (cylinder) size : " << G4endl << "\t \t radii : " << fTargetInnerRadius
153          << " , " << fTargetOuterRadius << " mm ;"
154          << "\t \t length (along z) : " << 2.0 * halfLength << " mm ;" << G4endl << G4endl
155          << G4endl;
156   return fPhysExperimentalHall;
157 }
158 
159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
160 
161 void DetectorConstruction::SetTargetMaterial(const G4String name)
162 {
163   fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial(name);
164   if (!fTargetMaterial) {
165     G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!"
166            << G4endl << "     ===> the default  * G4_Be *  will be used." << G4endl << G4endl;
167     //***LOOKHERE*** Default material
168     fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Be");
169   }
170   if (fLogicTargetLayer) fLogicTargetLayer->SetMaterial(fTargetMaterial);
171 }
172 
173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
174 
175 void DetectorConstruction::UpdateGeometry()
176 {
177   G4RunManager::GetRunManager()->ReinitializeGeometry();
178   PrintParameters();
179   // Update also the position of the gun
180   const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast<const PrimaryGeneratorAction*>(
181     G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
182   if (pPrimaryAction) pPrimaryAction->SetGunPosition();
183 }
184 
185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
186 
187 void DetectorConstruction::PrintParameters()
188 {
189   G4cout << G4endl << G4endl << " ------  DetectorConstruction::PrintParameters() ------ " << G4endl
190          << " Material            = " << fTargetMaterial->GetName() << G4endl
191          << " Target Inner Radius = " << fTargetInnerRadius << " mm" << G4endl
192          << " Target Outer Radius = " << fTargetOuterRadius << " mm" << G4endl
193          << " B [T]               = "
194          << (fUniformMagField ? fUniformMagField->GetConstantFieldValue() / CLHEP::tesla
195                               : G4ThreeVector(0.0, 0.0, 0.0))
196          << G4endl << " ------------------------------------------------------ " << G4endl
197          << G4endl;
198 }
199 
200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
201 
202 void DetectorConstruction::SetMagField(const G4double fieldValue)
203 {
204   if (fUniformMagField) delete fUniformMagField;
205   if (std::abs(fieldValue) > 0.0) {
206     // Apply a global uniform magnetic field along the Z axis
207     fUniformMagField = new G4UniformMagField(G4ThreeVector(0.0, 0.0, fieldValue));
208     fFieldMgr->SetDetectorField(fUniformMagField);
209     fFieldMgr->CreateChordFinder(fUniformMagField);
210   }
211 }
212 
213 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
214