Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 /// \file B2/B2a/src/DetectorConstruction.cc 28 /// \brief Implementation of the B2a::Detector 29 30 #include "DetectorConstruction.hh" 31 32 #include "DetectorMessenger.hh" 33 #include "TrackerSD.hh" 34 35 #include "G4AutoDelete.hh" 36 #include "G4Box.hh" 37 #include "G4Colour.hh" 38 #include "G4GeometryManager.hh" 39 #include "G4GeometryTolerance.hh" 40 #include "G4GlobalMagFieldMessenger.hh" 41 #include "G4LogicalVolume.hh" 42 #include "G4Material.hh" 43 #include "G4NistManager.hh" 44 #include "G4PVPlacement.hh" 45 #include "G4SDManager.hh" 46 #include "G4SystemOfUnits.hh" 47 #include "G4Tubs.hh" 48 #include "G4UserLimits.hh" 49 #include "G4VisAttributes.hh" 50 51 using namespace B2; 52 53 namespace B2a 54 { 55 56 //....oooOO0OOooo........oooOO0OOooo........oo 57 58 G4ThreadLocal G4GlobalMagFieldMessenger* Detec 59 60 DetectorConstruction::DetectorConstruction() 61 { 62 fMessenger = new DetectorMessenger(this); 63 64 fNbOfChambers = 5; 65 fLogicChamber = new G4LogicalVolume*[fNbOfCh 66 } 67 68 //....oooOO0OOooo........oooOO0OOooo........oo 69 70 DetectorConstruction::~DetectorConstruction() 71 { 72 delete[] fLogicChamber; 73 delete fStepLimit; 74 delete fMessenger; 75 } 76 77 //....oooOO0OOooo........oooOO0OOooo........oo 78 79 G4VPhysicalVolume* DetectorConstruction::Const 80 { 81 // Define materials 82 DefineMaterials(); 83 84 // Define volumes 85 return DefineVolumes(); 86 } 87 88 //....oooOO0OOooo........oooOO0OOooo........oo 89 90 void DetectorConstruction::DefineMaterials() 91 { 92 // Material definition 93 94 G4NistManager* nistManager = G4NistManager:: 95 96 // Air defined using NIST Manager 97 nistManager->FindOrBuildMaterial("G4_AIR"); 98 99 // Lead defined using NIST Manager 100 fTargetMaterial = nistManager->FindOrBuildMa 101 102 // Xenon gas defined using NIST Manager 103 fChamberMaterial = nistManager->FindOrBuildM 104 105 // Print materials 106 G4cout << *(G4Material::GetMaterialTable()) 107 } 108 109 //....oooOO0OOooo........oooOO0OOooo........oo 110 111 G4VPhysicalVolume* DetectorConstruction::Defin 112 { 113 G4Material* air = G4Material::GetMaterial("G 114 115 // Sizes of the principal geometrical compon 116 117 G4double chamberSpacing = 80 * cm; // from 118 119 G4double chamberWidth = 20.0 * cm; // width 120 G4double targetLength = 5.0 * cm; // full l 121 122 G4double trackerLength = (fNbOfChambers + 1) 123 124 G4double worldLength = 1.2 * (2 * targetLeng 125 126 G4double targetRadius = 0.5 * targetLength; 127 targetLength = 0.5 * targetLength; // Half 128 G4double trackerSize = 0.5 * trackerLength; 129 130 // Definitions of Solids, Logical Volumes, P 131 132 // World 133 134 G4GeometryManager::GetInstance()->SetWorldMa 135 136 G4cout << "Computed tolerance = " 137 << G4GeometryTolerance::GetInstance() 138 139 auto worldS = new G4Box("world", // its nam 140 worldLength / 2, wor 141 auto worldLV = new G4LogicalVolume(worldS, 142 air, // 143 "World"); 144 145 // Must place the World Physical volume unr 146 // 147 auto worldPV = new G4PVPlacement(nullptr, / 148 G4ThreeVect 149 worldLV, / 150 "World", / 151 nullptr, / 152 false, // 153 0, // copy 154 fCheckOverl 155 156 // Target 157 158 G4ThreeVector positionTarget = G4ThreeVector 159 160 auto targetS = new G4Tubs("target", 0., targ 161 fLogicTarget = new G4LogicalVolume(targetS, 162 new G4PVPlacement(nullptr, // no rotation 163 positionTarget, // at (x, 164 fLogicTarget, // its logi 165 "Target", // its name 166 worldLV, // its mother vo 167 false, // no boolean oper 168 0, // copy number 169 fCheckOverlaps); // check 170 171 G4cout << "Target is " << 2 * targetLength / 172 << G4endl; 173 174 // Tracker 175 176 G4ThreeVector positionTracker = G4ThreeVecto 177 178 auto trackerS = new G4Tubs("tracker", 0, tra 179 auto trackerLV = new G4LogicalVolume(tracker 180 new G4PVPlacement(nullptr, // no rotation 181 positionTracker, // at (x 182 trackerLV, // its logical 183 "Tracker", // its name 184 worldLV, // its mother v 185 false, // no boolean oper 186 0, // copy number 187 fCheckOverlaps); // check 188 189 // Visualization attributes 190 191 G4VisAttributes boxVisAtt(G4Colour::White()) 192 G4VisAttributes chamberVisAtt(G4Colour::Yell 193 194 worldLV->SetVisAttributes(boxVisAtt); 195 fLogicTarget->SetVisAttributes(boxVisAtt); 196 trackerLV->SetVisAttributes(boxVisAtt); 197 198 // Tracker segments 199 200 G4cout << "There are " << fNbOfChambers << " 201 << "The chambers are " << chamberWidt 202 << G4endl << "The distance between ch 203 204 G4double firstPosition = -trackerSize + cham 205 G4double firstLength = trackerLength / 10; 206 G4double lastLength = trackerLength; 207 208 G4double halfWidth = 0.5 * chamberWidth; 209 G4double rmaxFirst = 0.5 * firstLength; 210 211 G4double rmaxIncr = 0.0; 212 if (fNbOfChambers > 0) { 213 rmaxIncr = 0.5 * (lastLength - firstLength 214 if (chamberSpacing < chamberWidth) { 215 G4Exception("DetectorConstruction::Defin 216 "Width>Spacing"); 217 } 218 } 219 220 for (G4int copyNo = 0; copyNo < fNbOfChamber 221 G4double Zposition = firstPosition + copyN 222 G4double rmax = rmaxFirst + copyNo * rmaxI 223 224 auto chamberS = new G4Tubs("Chamber_solid" 225 226 fLogicChamber[copyNo] = 227 new G4LogicalVolume(chamberS, fChamberMa 228 229 fLogicChamber[copyNo]->SetVisAttributes(ch 230 231 new G4PVPlacement(nullptr, // no rotation 232 G4ThreeVector(0, 0, Zpos 233 fLogicChamber[copyNo], 234 "Chamber_PV", // its na 235 trackerLV, // its mothe 236 false, // no boolean op 237 copyNo, // copy number 238 fCheckOverlaps); // che 239 } 240 241 // Example of User Limits 242 // 243 // Below is an example of how to set trackin 244 // logical volume 245 // 246 // Sets a max step length in the tracker reg 247 248 G4double maxStep = 0.5 * chamberWidth; 249 fStepLimit = new G4UserLimits(maxStep); 250 trackerLV->SetUserLimits(fStepLimit); 251 252 /// Set additional contraints on the track, 253 /// 254 /// G4double maxLength = 2*trackerLength, ma 255 /// trackerLV->SetUserLimits(new G4UserLimit 256 /// 257 /// 258 /// 259 260 // Always return the physical world 261 262 return worldPV; 263 } 264 265 //....oooOO0OOooo........oooOO0OOooo........oo 266 267 void DetectorConstruction::ConstructSDandField 268 { 269 // Sensitive detectors 270 271 G4String trackerChamberSDname = "/TrackerCha 272 auto trackerSD = new TrackerSD(trackerChambe 273 G4SDManager::GetSDMpointer()->AddNewDetector 274 // Setting trackerSD to all logical volumes 275 // of "Chamber_LV". 276 SetSensitiveDetector("Chamber_LV", trackerSD 277 278 // Create global magnetic field messenger. 279 // Uniform magnetic field is then created au 280 // the field value is not zero. 281 G4ThreeVector fieldValue = G4ThreeVector(); 282 fMagFieldMessenger = new G4GlobalMagFieldMes 283 fMagFieldMessenger->SetVerboseLevel(1); 284 285 // Register the field messenger for deleting 286 G4AutoDelete::Register(fMagFieldMessenger); 287 } 288 289 //....oooOO0OOooo........oooOO0OOooo........oo 290 291 void DetectorConstruction::SetTargetMaterial(G 292 { 293 G4NistManager* nistManager = G4NistManager:: 294 295 G4Material* pttoMaterial = nistManager->Find 296 297 if (fTargetMaterial != pttoMaterial) { 298 if (pttoMaterial) { 299 fTargetMaterial = pttoMaterial; 300 if (fLogicTarget) fLogicTarget->SetMater 301 G4cout << G4endl << "----> The target is 302 } 303 else { 304 G4cout << G4endl << "--> WARNING from S 305 << G4endl; 306 } 307 } 308 } 309 310 //....oooOO0OOooo........oooOO0OOooo........oo 311 312 void DetectorConstruction::SetChamberMaterial( 313 { 314 G4NistManager* nistManager = G4NistManager:: 315 316 G4Material* pttoMaterial = nistManager->Find 317 318 if (fChamberMaterial != pttoMaterial) { 319 if (pttoMaterial) { 320 fChamberMaterial = pttoMaterial; 321 for (G4int copyNo = 0; copyNo < fNbOfCha 322 if (fLogicChamber[copyNo]) fLogicChamb 323 } 324 G4cout << G4endl << "----> The chambers 325 } 326 else { 327 G4cout << G4endl << "--> WARNING from S 328 << G4endl; 329 } 330 } 331 } 332 333 //....oooOO0OOooo........oooOO0OOooo........oo 334 335 void DetectorConstruction::SetMaxStep(G4double 336 { 337 if ((fStepLimit) && (maxStep > 0.)) fStepLim 338 } 339 340 //....oooOO0OOooo........oooOO0OOooo........oo 341 342 void DetectorConstruction::SetCheckOverlaps(G4 343 { 344 fCheckOverlaps = checkOverlaps; 345 } 346 347 //....oooOO0OOooo........oooOO0OOooo........oo 348 349 } // namespace B2a