Geant4 Cross Reference |
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 // 27 /// \file B2/B2b/src/DetectorConstruction.cc 28 /// \brief Implementation of the B2b::DetectorConstruction class 29 30 #include "DetectorConstruction.hh" 31 32 #include "ChamberParameterisation.hh" 33 #include "DetectorMessenger.hh" 34 #include "TrackerSD.hh" 35 36 #include "G4AutoDelete.hh" 37 #include "G4Box.hh" 38 #include "G4Colour.hh" 39 #include "G4GeometryManager.hh" 40 #include "G4GeometryTolerance.hh" 41 #include "G4GlobalMagFieldMessenger.hh" 42 #include "G4LogicalVolume.hh" 43 #include "G4Material.hh" 44 #include "G4NistManager.hh" 45 #include "G4PVParameterised.hh" 46 #include "G4PVPlacement.hh" 47 #include "G4SDManager.hh" 48 #include "G4SystemOfUnits.hh" 49 #include "G4ThreeVector.hh" 50 #include "G4Tubs.hh" 51 #include "G4UserLimits.hh" 52 #include "G4VisAttributes.hh" 53 54 using namespace B2; 55 56 namespace B2b 57 { 58 59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 60 61 G4ThreadLocal G4GlobalMagFieldMessenger* DetectorConstruction::fMagFieldMessenger = nullptr; 62 63 DetectorConstruction::DetectorConstruction() 64 { 65 fMessenger = new DetectorMessenger(this); 66 } 67 68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 69 70 DetectorConstruction::~DetectorConstruction() 71 { 72 delete fStepLimit; 73 delete fMessenger; 74 } 75 76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 77 78 G4VPhysicalVolume* DetectorConstruction::Construct() 79 { 80 // Define materials 81 DefineMaterials(); 82 83 // Define volumes 84 return DefineVolumes(); 85 } 86 87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 88 89 void DetectorConstruction::DefineMaterials() 90 { 91 // Material definition 92 93 G4NistManager* nistManager = G4NistManager::Instance(); 94 95 // Air defined using NIST Manager 96 nistManager->FindOrBuildMaterial("G4_AIR"); 97 98 // Lead defined using NIST Manager 99 fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Pb"); 100 101 // Xenon gas defined using NIST Manager 102 fChamberMaterial = nistManager->FindOrBuildMaterial("G4_Xe"); 103 104 // Print materials 105 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 106 } 107 108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 109 110 G4VPhysicalVolume* DetectorConstruction::DefineVolumes() 111 { 112 G4Material* air = G4Material::GetMaterial("G4_AIR"); 113 114 // Sizes of the principal geometrical components (solids) 115 116 G4int NbOfChambers = 5; 117 G4double chamberSpacing = 80 * cm; // from chamber center to center! 118 119 G4double chamberWidth = 20.0 * cm; // width of the chambers 120 G4double targetLength = 5.0 * cm; // full length of Target 121 122 G4double trackerLength = (NbOfChambers + 1) * chamberSpacing; 123 124 G4double worldLength = 1.2 * (2 * targetLength + trackerLength); 125 126 G4double targetRadius = 0.5 * targetLength; // Radius of Target 127 targetLength = 0.5 * targetLength; // Half length of the Target 128 G4double trackerSize = 0.5 * trackerLength; // Half length of the Tracker 129 130 // Definitions of Solids, Logical Volumes, Physical Volumes 131 132 // World 133 134 G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength); 135 136 G4cout << "Computed tolerance = " 137 << G4GeometryTolerance::GetInstance()->GetSurfaceTolerance() / mm << " mm" << G4endl; 138 139 auto worldS = new G4Box("world", // its name 140 worldLength / 2, worldLength / 2, worldLength / 2); // its size 141 auto worldLV = new G4LogicalVolume(worldS, // its solid 142 air, // its material 143 "World"); // its name 144 145 // Must place the World Physical volume unrotated at (0,0,0). 146 // 147 auto worldPV = new G4PVPlacement(nullptr, // no rotation 148 G4ThreeVector(), // at (0,0,0) 149 worldLV, // its logical volume 150 "World", // its name 151 nullptr, // its mother volume 152 false, // no boolean operations 153 0, // copy number 154 fCheckOverlaps); // checking overlaps 155 156 // Target 157 158 G4ThreeVector positionTarget = G4ThreeVector(0, 0, -(targetLength + trackerSize)); 159 160 auto targetS = new G4Tubs("target", 0., targetRadius, targetLength, 0. * deg, 360. * deg); 161 fLogicTarget = new G4LogicalVolume(targetS, fTargetMaterial, "Target", nullptr, nullptr, nullptr); 162 new G4PVPlacement(nullptr, // no rotation 163 positionTarget, // at (x,y,z) 164 fLogicTarget, // its logical volume 165 "Target", // its name 166 worldLV, // its mother volume 167 false, // no boolean operations 168 0, // copy number 169 fCheckOverlaps); // checking overlaps 170 171 G4cout << "Target is " << 2 * targetLength / cm << " cm of " << fTargetMaterial->GetName() 172 << G4endl; 173 174 // Tracker 175 176 G4ThreeVector positionTracker = G4ThreeVector(0, 0, 0); 177 178 auto trackerS = new G4Tubs("tracker", 0, trackerSize, trackerSize, 0. * deg, 360. * deg); 179 auto trackerLV = new G4LogicalVolume(trackerS, air, "Tracker", nullptr, nullptr, nullptr); 180 new G4PVPlacement(nullptr, // no rotation 181 positionTracker, // at (x,y,z) 182 trackerLV, // its logical volume 183 "Tracker", // its name 184 worldLV, // its mother volume 185 false, // no boolean operations 186 0, // copy number 187 fCheckOverlaps); // checking overlaps 188 189 // Tracker segments 190 191 // An example of Parameterised volumes 192 // Dummy values for G4Tubs -- modified by parameterised volume 193 194 auto chamberS = new G4Tubs("tracker", 0, 100 * cm, 100 * cm, 0. * deg, 360. * deg); 195 fLogicChamber = 196 new G4LogicalVolume(chamberS, fChamberMaterial, "Chamber", nullptr, nullptr, nullptr); 197 198 G4double firstPosition = -trackerSize + chamberSpacing; 199 G4double firstLength = trackerLength / 10; 200 G4double lastLength = trackerLength; 201 202 G4VPVParameterisation* chamberParam = 203 new ChamberParameterisation(NbOfChambers, // NoChambers 204 firstPosition, // Z of center of first 205 chamberSpacing, // Z spacing of centers 206 chamberWidth, // chamber width 207 firstLength, // initial length 208 lastLength); // final length 209 210 // dummy value : kZAxis -- modified by parameterised volume 211 212 new G4PVParameterised("Chamber", // their name 213 fLogicChamber, // their logical volume 214 trackerLV, // Mother logical volume 215 kZAxis, // Are placed along this axis 216 NbOfChambers, // Number of chambers 217 chamberParam, // The parametrisation 218 fCheckOverlaps); // checking overlaps 219 220 G4cout << "There are " << NbOfChambers << " chambers in the tracker region. " << G4endl 221 << "The chambers are " << chamberWidth / cm << " cm of " << fChamberMaterial->GetName() 222 << G4endl << "The distance between chamber is " << chamberSpacing / cm << " cm" << G4endl; 223 224 // Visualization attributes 225 226 G4VisAttributes boxVisAtt(G4Colour::White()); 227 228 worldLV->SetVisAttributes(boxVisAtt); 229 fLogicTarget->SetVisAttributes(boxVisAtt); 230 trackerLV->SetVisAttributes(boxVisAtt); 231 232 G4VisAttributes chamberVisAtt(G4Colour::Yellow()); 233 fLogicChamber->SetVisAttributes(chamberVisAtt); 234 235 // Example of User Limits 236 // 237 // Below is an example of how to set tracking constraints in a given 238 // logical volume 239 // 240 // Sets a max step length in the tracker region, with G4StepLimiter 241 242 G4double maxStep = 0.5 * chamberWidth; 243 fStepLimit = new G4UserLimits(maxStep); 244 trackerLV->SetUserLimits(fStepLimit); 245 246 /// Set additional contraints on the track, with G4UserSpecialCuts 247 /// 248 /// G4double maxLength = 2*trackerLength, maxTime = 0.1*ns, minEkin = 10*MeV; 249 /// trackerLV->SetUserLimits(new G4UserLimits(maxStep, 250 /// maxLength, 251 /// maxTime, 252 /// minEkin)); 253 254 // Always return the physical world 255 256 return worldPV; 257 } 258 259 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 260 261 void DetectorConstruction::ConstructSDandField() 262 { 263 // Sensitive detectors 264 265 G4String trackerChamberSDname = "B2/TrackerChamberSD"; 266 auto trackerSD = new TrackerSD(trackerChamberSDname, "TrackerHitsCollection"); 267 G4SDManager::GetSDMpointer()->AddNewDetector(trackerSD); 268 SetSensitiveDetector(fLogicChamber, trackerSD); 269 270 // Create global magnetic field messenger. 271 // Uniform magnetic field is then created automatically if 272 // the field value is not zero. 273 G4ThreeVector fieldValue = G4ThreeVector(); 274 fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue); 275 fMagFieldMessenger->SetVerboseLevel(1); 276 277 // Register the field messenger for deleting 278 G4AutoDelete::Register(fMagFieldMessenger); 279 } 280 281 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 282 283 void DetectorConstruction::SetTargetMaterial(G4String materialName) 284 { 285 G4NistManager* nistManager = G4NistManager::Instance(); 286 287 G4Material* pttoMaterial = nistManager->FindOrBuildMaterial(materialName); 288 289 if (fTargetMaterial != pttoMaterial) { 290 if (pttoMaterial) { 291 fTargetMaterial = pttoMaterial; 292 if (fLogicTarget) fLogicTarget->SetMaterial(fTargetMaterial); 293 G4cout << G4endl << "----> The target is made of " << materialName << G4endl; 294 } 295 else { 296 G4cout << G4endl << "--> WARNING from SetTargetMaterial : " << materialName << " not found" 297 << G4endl; 298 } 299 } 300 } 301 302 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 303 304 void DetectorConstruction::SetChamberMaterial(G4String materialName) 305 { 306 G4NistManager* nistManager = G4NistManager::Instance(); 307 308 G4Material* pttoMaterial = nistManager->FindOrBuildMaterial(materialName); 309 310 if (fChamberMaterial != pttoMaterial) { 311 if (pttoMaterial) { 312 fChamberMaterial = pttoMaterial; 313 if (fLogicChamber) fLogicChamber->SetMaterial(fChamberMaterial); 314 G4cout << G4endl << "----> The chambers are made of " << materialName << G4endl; 315 } 316 else { 317 G4cout << G4endl << "--> WARNING from SetChamberMaterial : " << materialName << " not found" 318 << G4endl; 319 } 320 } 321 } 322 323 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 324 325 void DetectorConstruction::SetMaxStep(G4double maxStep) 326 { 327 if ((fStepLimit) && (maxStep > 0.)) fStepLimit->SetMaxAllowedStep(maxStep); 328 } 329 330 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 331 332 } // namespace B2b 333