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