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 /// \file persistency/P01/src/ExP01DetectorCon 26 /// \file persistency/P01/src/ExP01DetectorConstruction.cc 27 /// \brief Implementation of the ExP01Detector 27 /// \brief Implementation of the ExP01DetectorConstruction class 28 // 28 // 29 // 29 // >> 30 // $Id: ExP01DetectorConstruction.cc 98770 2016-08-09 14:22:25Z gcosmo $ 30 // 31 // >> 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 //....oooOO0OOooo........oooOO0OOooo........oo << 34 33 << 34 #include "ExP01DetectorConstruction.hh" 35 #include "ExP01DetectorConstruction.hh" 35 << 36 #include "ExP01ChamberParameterisation.hh" << 37 #include "ExP01DetectorMessenger.hh" 36 #include "ExP01DetectorMessenger.hh" >> 37 #include "ExP01ChamberParameterisation.hh" 38 #include "ExP01MagneticField.hh" 38 #include "ExP01MagneticField.hh" 39 #include "ExP01TrackerSD.hh" 39 #include "ExP01TrackerSD.hh" 40 40 >> 41 #include "G4Material.hh" 41 #include "G4Box.hh" 42 #include "G4Box.hh" 42 #include "G4Colour.hh" << 43 #include "G4LogicalVolume.hh" 43 #include "G4LogicalVolume.hh" 44 #include "G4Material.hh" << 45 #include "G4PVParameterised.hh" << 46 #include "G4PVPlacement.hh" 44 #include "G4PVPlacement.hh" >> 45 #include "G4PVParameterised.hh" 47 #include "G4SDManager.hh" 46 #include "G4SDManager.hh" 48 #include "G4SystemOfUnits.hh" << 47 49 #include "G4UserLimits.hh" 48 #include "G4UserLimits.hh" >> 49 50 #include "G4VisAttributes.hh" 50 #include "G4VisAttributes.hh" >> 51 #include "G4Colour.hh" >> 52 >> 53 #include "G4SystemOfUnits.hh" 51 #include "G4ios.hh" 54 #include "G4ios.hh" 52 55 53 //....oooOO0OOooo........oooOO0OOooo........oo 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 54 << 57 55 ExP01DetectorConstruction::ExP01DetectorConstr 58 ExP01DetectorConstruction::ExP01DetectorConstruction() 56 : G4VUserDetectorConstruction(), << 59 :G4VUserDetectorConstruction(), 57 fSolidWorld(0), << 60 fSolidWorld(0), fLogicWorld(0), fPhysiWorld(0), 58 fLogicWorld(0), << 61 fSolidTarget(0), fLogicTarget(0), fPhysiTarget(0), 59 fPhysiWorld(0), << 62 fSolidTracker(0), fLogicTracker(0), fPhysiTracker(0), 60 fSolidTarget(0), << 63 fSolidChamber(0), fLogicChamber(0), fPhysiChamber(0), 61 fLogicTarget(0), << 64 fTargetMater(0), fChamberMater(0), fPMagField(0), fDetectorMessenger(0), 62 fPhysiTarget(0), << 65 fWorldLength(0.), fTargetLength(0.), fTrackerLength(0.), 63 fSolidTracker(0), << 66 fNbOfChambers(0), fChamberWidth(0.), fChamberSpacing(0.) 64 fLogicTracker(0), << 65 fPhysiTracker(0), << 66 fSolidChamber(0), << 67 fLogicChamber(0), << 68 fPhysiChamber(0), << 69 fTargetMater(0), << 70 fChamberMater(0), << 71 fPMagField(0), << 72 fDetectorMessenger(0), << 73 fWorldLength(0.), << 74 fTargetLength(0.), << 75 fTrackerLength(0.), << 76 fNbOfChambers(0), << 77 fChamberWidth(0.), << 78 fChamberSpacing(0.) << 79 { 67 { 80 fPMagField = new ExP01MagneticField(); 68 fPMagField = new ExP01MagneticField(); 81 fDetectorMessenger = new ExP01DetectorMessen 69 fDetectorMessenger = new ExP01DetectorMessenger(this); 82 } 70 } 83 71 84 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 85 << 73 86 ExP01DetectorConstruction::~ExP01DetectorConst 74 ExP01DetectorConstruction::~ExP01DetectorConstruction() 87 { 75 { 88 delete fPMagField; 76 delete fPMagField; 89 delete fDetectorMessenger; << 77 delete fDetectorMessenger; 90 } 78 } 91 79 92 //....oooOO0OOooo........oooOO0OOooo........oo 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 93 << 81 94 G4VPhysicalVolume* ExP01DetectorConstruction:: 82 G4VPhysicalVolume* ExP01DetectorConstruction::Construct() 95 { 83 { 96 //--------- Material definition --------- << 84 //--------- Material definition --------- 97 85 98 G4double a, z; 86 G4double a, z; 99 G4double density, temperature, pressure; 87 G4double density, temperature, pressure; 100 G4int nel; 88 G4int nel; 101 89 102 // Air << 90 //Air 103 G4Element* N = new G4Element("Nitrogen", "N" << 91 G4Element* N = new G4Element("Nitrogen", "N", z=7., a= 14.01*g/mole); 104 G4Element* O = new G4Element("Oxygen", "O", << 92 G4Element* O = new G4Element("Oxygen" , "O", z=8., a= 16.00*g/mole); 105 << 93 106 G4Material* Air = new G4Material("Air", dens << 94 G4Material* Air = new G4Material("Air", density= 1.29*mg/cm3, nel=2); 107 Air->AddElement(N, 70 * perCent); << 95 Air->AddElement(N, 70*perCent); 108 Air->AddElement(O, 30 * perCent); << 96 Air->AddElement(O, 30*perCent); 109 << 97 110 // Lead << 98 //Lead 111 G4Material* Pb = << 99 G4Material* Pb = 112 new G4Material("Lead", z = 82., a = 207.19 << 100 new G4Material("Lead", z=82., a= 207.19*g/mole, density= 11.35*g/cm3); 113 << 101 114 // Xenon gas << 102 //Xenon gas 115 G4Material* Xenon = << 103 G4Material* Xenon = 116 new G4Material("XenonGas", z = 54., a = 13 << 104 new G4Material("XenonGas", z=54., a=131.29*g/mole, density= 5.458*mg/cm3, 117 kStateGas, temperature = 29 << 105 kStateGas, temperature= 293.15*kelvin, pressure= 1*atmosphere); 118 106 119 // Print all the materials defined. 107 // Print all the materials defined. 120 // 108 // 121 G4cout << G4endl << "The materials defined a 109 G4cout << G4endl << "The materials defined are : " << G4endl << G4endl; 122 G4cout << *(G4Material::GetMaterialTable()) 110 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 123 111 124 //--------- Sizes of the principal geometric << 112 //--------- Sizes of the principal geometrical components (solids) --------- 125 << 113 126 fNbOfChambers = 5; 114 fNbOfChambers = 5; 127 fChamberWidth = 20 * cm; << 115 fChamberWidth = 20*cm; 128 fChamberSpacing = 80 * cm; << 116 fChamberSpacing = 80*cm; 129 << 117 130 fTrackerLength = (fNbOfChambers + 1) * fCham << 118 fTrackerLength = (fNbOfChambers+1)*fChamberSpacing; // Full length of Tracker 131 fTargetLength = 5.0 * cm; // Full length of << 119 fTargetLength = 5.0 * cm; // Full length of Target 132 << 120 133 fTargetMater = Pb; << 121 fTargetMater = Pb; 134 fChamberMater = Xenon; 122 fChamberMater = Xenon; 135 << 123 136 fWorldLength = 1.2 * (fTargetLength + fTrack << 124 fWorldLength= 1.2 *(fTargetLength+fTrackerLength); 137 << 125 138 G4double targetSize = 0.5 * fTargetLength; << 126 G4double targetSize = 0.5*fTargetLength; // Half length of the Target 139 G4double trackerSize = 0.5 * fTrackerLength; << 127 G4double trackerSize = 0.5*fTrackerLength; // Half length of the Tracker 140 << 128 141 //--------- Definitions of Solids, Logical V << 129 //--------- Definitions of Solids, Logical Volumes, Physical Volumes --------- 142 << 130 143 //------------------------------ << 131 //------------------------------ 144 // World 132 // World 145 //------------------------------ << 133 //------------------------------ 146 << 147 G4double HalfWorldLength = 0.5 * fWorldLengt << 148 << 149 fSolidWorld = new G4Box("world", HalfWorldLe << 150 fLogicWorld = new G4LogicalVolume(fSolidWorl << 151 134 >> 135 G4double HalfWorldLength = 0.5*fWorldLength; >> 136 >> 137 fSolidWorld= new G4Box("world",HalfWorldLength,HalfWorldLength,HalfWorldLength); >> 138 fLogicWorld= new G4LogicalVolume( fSolidWorld, Air, "World", 0, 0, 0); >> 139 152 // Must place the World Physical volume unr 140 // Must place the World Physical volume unrotated at (0,0,0). 153 // << 141 // 154 fPhysiWorld = new G4PVPlacement(0, // no ro << 142 fPhysiWorld = new G4PVPlacement(0, // no rotation 155 G4ThreeVecto << 143 G4ThreeVector(), // at (0,0,0) 156 fLogicWorld, << 144 fLogicWorld, // its logical volume 157 "World", // << 145 "World", // its name 158 0, // its m << 146 0, // its mother volume 159 false, // n << 147 false, // no boolean operations 160 0); // copy << 148 0); // copy number 161 << 149 162 //------------------------------ << 150 //------------------------------ 163 // Target 151 // Target 164 //------------------------------ 152 //------------------------------ >> 153 >> 154 G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetSize+trackerSize)); >> 155 >> 156 fSolidTarget = new G4Box("target",targetSize,targetSize,targetSize); >> 157 fLogicTarget = new G4LogicalVolume(fSolidTarget,fTargetMater,"Target",0,0,0); >> 158 fPhysiTarget = new G4PVPlacement(0, // no rotation >> 159 positionTarget, // at (x,y,z) >> 160 fLogicTarget, // its logical volume >> 161 "Target", // its name >> 162 fLogicWorld, // its mother volume >> 163 false, // no boolean operations >> 164 0); // copy number 165 165 166 G4ThreeVector positionTarget = G4ThreeVector << 166 G4cout << "Target is " << fTargetLength/cm << " cm of " >> 167 << fTargetMater->GetName() << G4endl; 167 168 168 fSolidTarget = new G4Box("target", targetSiz << 169 //------------------------------ 169 fLogicTarget = new G4LogicalVolume(fSolidTar << 170 fPhysiTarget = new G4PVPlacement(0, // no r << 171 positionTar << 172 fLogicTarge << 173 "Target", << 174 fLogicWorld << 175 false, // << 176 0); // cop << 177 << 178 G4cout << "Target is " << fTargetLength / cm << 179 << 180 //------------------------------ << 181 // Tracker 170 // Tracker 182 //------------------------------ 171 //------------------------------ >> 172 >> 173 G4ThreeVector positionTracker = G4ThreeVector(0,0,0); >> 174 >> 175 fSolidTracker = new G4Box("tracker",trackerSize,trackerSize,trackerSize); >> 176 fLogicTracker = new G4LogicalVolume(fSolidTracker , Air, "Tracker",0,0,0); >> 177 fPhysiTracker = new G4PVPlacement(0, // no rotation >> 178 positionTracker, // at (x,y,z) >> 179 fLogicTracker, // its logical volume >> 180 "Tracker", // its name >> 181 fLogicWorld, // its mother volume >> 182 false, // no boolean operations >> 183 0); // copy number 183 184 184 G4ThreeVector positionTracker = G4ThreeVecto << 185 //------------------------------ 185 << 186 fSolidTracker = new G4Box("tracker", tracker << 187 fLogicTracker = new G4LogicalVolume(fSolidTr << 188 fPhysiTracker = new G4PVPlacement(0, // no << 189 positionTr << 190 fLogicTrac << 191 "Tracker", << 192 fLogicWorl << 193 false, // << 194 0); // co << 195 << 196 //------------------------------ << 197 // Tracker segments 186 // Tracker segments 198 //------------------------------ 187 //------------------------------ 199 // << 188 // 200 // An example of Parameterised volumes 189 // An example of Parameterised volumes 201 // dummy values for G4Box -- modified by par 190 // dummy values for G4Box -- modified by parameterised volume 202 191 203 fSolidChamber = new G4Box("chamber", 100 * c << 192 fSolidChamber = new G4Box("chamber", 100*cm, 100*cm, 10*cm); 204 fLogicChamber = new G4LogicalVolume(fSolidCh << 193 fLogicChamber = new G4LogicalVolume(fSolidChamber, fChamberMater,"Chamber",0,0,0); 205 << 194 206 G4double firstPosition = -trackerSize + 0.5 << 195 G4double firstPosition = -trackerSize + 0.5*fChamberWidth; 207 G4double firstLength = fTrackerLength / 10; << 196 G4double firstLength = fTrackerLength/10; 208 G4double lastLength = fTrackerLength; << 197 G4double lastLength = fTrackerLength; 209 << 198 210 G4VPVParameterisation* chamberParam = << 199 G4VPVParameterisation* chamberParam = new ExP01ChamberParameterisation( 211 new ExP01ChamberParameterisation(fNbOfCham << 200 fNbOfChambers, // NoChambers 212 firstPosi << 201 firstPosition, // Z of center of first 213 fChamberS << 202 fChamberSpacing, // Z spacing of centers 214 fChamberW << 203 fChamberWidth, // Width Chamber 215 firstLeng << 204 firstLength, // lengthInitial 216 lastLengt << 205 lastLength); // lengthFinal 217 << 206 218 // dummy value : kZAxis -- modified by param 207 // dummy value : kZAxis -- modified by parameterised volume 219 // 208 // 220 fPhysiChamber = new G4PVParameterised("Chamb << 209 fPhysiChamber = new G4PVParameterised( 221 fLogic << 210 "Chamber", // their name 222 fLogic << 211 fLogicChamber, // their logical volume 223 kZAxis << 212 fLogicTracker, // Mother logical volume 224 fNbOfC << 213 kZAxis, // Are placed along this axis 225 chambe << 214 fNbOfChambers, // Number of chambers >> 215 chamberParam); // The parametrisation 226 216 227 G4cout << "There are " << fNbOfChambers << " 217 G4cout << "There are " << fNbOfChambers << " chambers in the tracker region. " 228 << "The chambers are " << fChamberWid << 218 << "The chambers are " << fChamberWidth/mm << " mm of " 229 << "\n The distance between chamber i << 219 << fChamberMater->GetName() << "\n The distance between chamber is " 230 << 220 << fChamberSpacing/cm << " cm" << G4endl; 231 //------------------------------------------ << 221 >> 222 //------------------------------------------------ 232 // Sensitive detectors 223 // Sensitive detectors 233 //------------------------------------------ << 224 //------------------------------------------------ 234 225 235 G4SDManager* SDman = G4SDManager::GetSDMpoin 226 G4SDManager* SDman = G4SDManager::GetSDMpointer(); 236 227 237 G4String trackerChamberSDname = "ExP01/Track 228 G4String trackerChamberSDname = "ExP01/TrackerChamberSD"; 238 ExP01TrackerSD* aTrackerSD = new ExP01Tracke << 229 ExP01TrackerSD* aTrackerSD = new ExP01TrackerSD( trackerChamberSDname ); 239 SDman->AddNewDetector(aTrackerSD); << 230 SDman->AddNewDetector( aTrackerSD ); 240 fLogicChamber->SetSensitiveDetector(aTracker << 231 fLogicChamber->SetSensitiveDetector( aTrackerSD ); 241 << 232 242 //--------- Visualization attributes ------- << 233 //--------- Visualization attributes ------------------------------- 243 << 234 244 G4VisAttributes* BoxVisAtt = new G4VisAttrib << 235 G4VisAttributes* BoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0)); 245 fLogicWorld->SetVisAttributes(BoxVisAtt); << 236 fLogicWorld ->SetVisAttributes(BoxVisAtt); 246 fLogicTarget->SetVisAttributes(BoxVisAtt); << 237 fLogicTarget ->SetVisAttributes(BoxVisAtt); 247 fLogicTracker->SetVisAttributes(BoxVisAtt); 238 fLogicTracker->SetVisAttributes(BoxVisAtt); 248 << 239 249 G4VisAttributes* ChamberVisAtt = new G4VisAt << 240 G4VisAttributes* ChamberVisAtt = new G4VisAttributes(G4Colour(1.0,1.0,0.0)); 250 fLogicChamber->SetVisAttributes(ChamberVisAt 241 fLogicChamber->SetVisAttributes(ChamberVisAtt); 251 << 242 252 //--------- example of User Limits --------- << 243 //--------- example of User Limits ------------------------------- 253 244 254 // below is an example of how to set trackin 245 // below is an example of how to set tracking constraints in a given 255 // logical volume(see also in N02PhysicsList 246 // logical volume(see also in N02PhysicsList how to setup the processes 256 // G4StepLimiter or G4UserSpecialCuts). 247 // G4StepLimiter or G4UserSpecialCuts). 257 << 248 258 // Sets a max Step length in the tracker reg 249 // Sets a max Step length in the tracker region, with G4StepLimiter 259 // 250 // 260 G4double maxStep = 0.5 * fChamberWidth; << 251 G4double maxStep = 0.5*fChamberWidth; 261 fLogicTracker->SetUserLimits(new G4UserLimit 252 fLogicTracker->SetUserLimits(new G4UserLimits(maxStep)); 262 << 253 263 // Set additional contraints on the track, w 254 // Set additional contraints on the track, with G4UserSpecialCuts 264 // 255 // 265 // G4double maxLength = 2*fTrackerLength, ma 256 // G4double maxLength = 2*fTrackerLength, maxTime = 0.1*ns, minEkin = 10*MeV; 266 // logicTracker->SetUserLimits(new G4UserLim 257 // logicTracker->SetUserLimits(new G4UserLimits(maxStep,maxLength,maxTime, 267 // 258 // minEkin)); 268 << 259 269 return fPhysiWorld; 260 return fPhysiWorld; 270 } 261 } 271 262 272 //....oooOO0OOooo........oooOO0OOooo........oo 263 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 273 << 264 274 void ExP01DetectorConstruction::SetTargetMater 265 void ExP01DetectorConstruction::SetTargetMaterial(G4String materialName) 275 { 266 { 276 // search the material by its name << 267 // search the material by its name 277 G4Material* pttoMaterial = G4Material::GetMa << 268 G4Material* pttoMaterial = G4Material::GetMaterial(materialName); 278 if (pttoMaterial) { << 269 if (pttoMaterial) 279 fTargetMater = pttoMaterial; << 270 {fTargetMater = pttoMaterial; 280 fLogicTarget->SetMaterial(pttoMaterial); << 271 fLogicTarget->SetMaterial(pttoMaterial); 281 G4cout << "\n----> The target is " << fTar << 272 G4cout << "\n----> The target is " << fTargetLength/cm << " cm of " 282 } << 273 << materialName << G4endl; >> 274 } 283 } 275 } 284 << 276 285 //....oooOO0OOooo........oooOO0OOooo........oo 277 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 286 278 287 void ExP01DetectorConstruction::SetChamberMate 279 void ExP01DetectorConstruction::SetChamberMaterial(G4String materialName) 288 { 280 { 289 // search the material by its name << 281 // search the material by its name 290 G4Material* pttoMaterial = G4Material::GetMa << 282 G4Material* pttoMaterial = G4Material::GetMaterial(materialName); 291 if (pttoMaterial) { << 283 if (pttoMaterial) 292 fChamberMater = pttoMaterial; << 284 {fChamberMater = pttoMaterial; 293 fLogicChamber->SetMaterial(pttoMaterial); << 285 fLogicChamber->SetMaterial(pttoMaterial); 294 G4cout << "\n----> The chambers are " << f << 286 G4cout << "\n----> The chambers are " << fChamberWidth/cm << " cm of " 295 << G4endl; << 287 << materialName << G4endl; 296 } << 288 } 297 } 289 } 298 << 290 299 //....oooOO0OOooo........oooOO0OOooo........oo 291 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 300 << 292 301 void ExP01DetectorConstruction::SetMagField(G4 293 void ExP01DetectorConstruction::SetMagField(G4double fieldValue) 302 { 294 { 303 fPMagField->SetFieldValue(fieldValue); 295 fPMagField->SetFieldValue(fieldValue); 304 } 296 } 305 297 306 //....oooOO0OOooo........oooOO0OOooo........oo 298 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 307 299