File indexing completed on 2025-02-23 09:22:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #include "B2bDetectorConstruction.hh"
0031
0032 #include "B2TrackerSD.hh"
0033 #include "B2bChamberParameterisation.hh"
0034 #include "B2bDetectorMessenger.hh"
0035
0036 #include "G4Box.hh"
0037 #include "G4Colour.hh"
0038 #include "G4GeometryManager.hh"
0039 #include "G4GeometryTolerance.hh"
0040 #include "G4GlobalMagFieldMessenger.hh"
0041 #include "G4LogicalVolume.hh"
0042 #include "G4Material.hh"
0043 #include "G4NistManager.hh"
0044 #include "G4PVParameterised.hh"
0045 #include "G4PVPlacement.hh"
0046 #include "G4SDManager.hh"
0047 #include "G4SystemOfUnits.hh"
0048 #include "G4Tubs.hh"
0049 #include "G4UserLimits.hh"
0050 #include "G4VisAttributes.hh"
0051
0052
0053
0054
0055
0056 G4ThreadLocal G4GlobalMagFieldMessenger* B2bDetectorConstruction::fMagFieldMessenger = 0;
0057
0058 B2bDetectorConstruction::B2bDetectorConstruction()
0059 : G4VUserDetectorConstruction(),
0060 fLogicTarget(NULL),
0061 fLogicChamber(NULL),
0062 fTargetMaterial(NULL),
0063 fChamberMaterial(NULL),
0064 fStepLimit(NULL),
0065 fCheckOverlaps(true)
0066 {
0067 fMessenger = new B2bDetectorMessenger(this);
0068 }
0069
0070
0071
0072 B2bDetectorConstruction::~B2bDetectorConstruction()
0073 {
0074 delete fStepLimit;
0075 delete fMessenger;
0076 delete fMagFieldMessenger;
0077 fMagFieldMessenger = 0;
0078 }
0079
0080
0081
0082 G4VPhysicalVolume* B2bDetectorConstruction::Construct()
0083 {
0084
0085 DefineMaterials();
0086
0087
0088 return DefineVolumes();
0089 }
0090
0091
0092
0093 void B2bDetectorConstruction::DefineMaterials()
0094 {
0095
0096
0097 G4NistManager* nistManager = G4NistManager::Instance();
0098
0099
0100 nistManager->FindOrBuildMaterial("G4_AIR");
0101
0102
0103 fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Pb");
0104
0105
0106 fChamberMaterial = nistManager->FindOrBuildMaterial("G4_Xe");
0107
0108
0109 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0110 }
0111
0112
0113
0114 G4VPhysicalVolume* B2bDetectorConstruction::DefineVolumes()
0115 {
0116 G4Material* air = G4Material::GetMaterial("G4_AIR");
0117
0118
0119
0120 G4int NbOfChambers = 5;
0121 G4double chamberSpacing = 80 * cm;
0122
0123 G4double chamberWidth = 20.0 * cm;
0124 G4double targetLength = 5.0 * cm;
0125
0126 G4double trackerLength = (NbOfChambers + 1) * chamberSpacing;
0127
0128 G4double worldLength = 1.2 * (2 * targetLength + trackerLength);
0129
0130 G4double targetRadius = 0.5 * targetLength;
0131 targetLength = 0.5 * targetLength;
0132 G4double trackerSize = 0.5 * trackerLength;
0133
0134
0135
0136
0137
0138 G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength);
0139
0140 G4cout << "Computed tolerance = "
0141 << G4GeometryTolerance::GetInstance()->GetSurfaceTolerance() / mm << " mm" << G4endl;
0142
0143 G4Box* worldS = new G4Box("world",
0144 worldLength / 2, worldLength / 2, worldLength / 2);
0145 G4LogicalVolume* worldLV = new G4LogicalVolume(worldS,
0146 air,
0147 "World");
0148
0149
0150
0151 G4VPhysicalVolume* worldPV = new G4PVPlacement(0,
0152 G4ThreeVector(),
0153 worldLV,
0154 "World",
0155 0,
0156 false,
0157 0,
0158 fCheckOverlaps);
0159
0160
0161
0162 G4ThreeVector positionTarget = G4ThreeVector(0, 0, -(targetLength + trackerSize));
0163
0164 G4Tubs* targetS = new G4Tubs("target", 0., targetRadius, targetLength, 0. * deg, 360. * deg);
0165 fLogicTarget = new G4LogicalVolume(targetS, fTargetMaterial, "Target", 0, 0, 0);
0166 new G4PVPlacement(0,
0167 positionTarget,
0168 fLogicTarget,
0169 "Target",
0170 worldLV,
0171 false,
0172 0,
0173 fCheckOverlaps);
0174
0175 G4cout << "Target is " << 2 * targetLength / cm << " cm of " << fTargetMaterial->GetName()
0176 << G4endl;
0177
0178
0179
0180 G4ThreeVector positionTracker = G4ThreeVector(0, 0, 0);
0181
0182 G4Tubs* trackerS = new G4Tubs("tracker", 0, trackerSize, trackerSize, 0. * deg, 360. * deg);
0183 G4LogicalVolume* trackerLV = new G4LogicalVolume(trackerS, air, "Tracker", 0, 0, 0);
0184 new G4PVPlacement(0,
0185 positionTracker,
0186 trackerLV,
0187 "Tracker",
0188 worldLV,
0189 false,
0190 0,
0191 fCheckOverlaps);
0192
0193
0194
0195
0196
0197
0198 G4Tubs* chamberS = new G4Tubs("tracker", 0, 100 * cm, 100 * cm, 0. * deg, 360. * deg);
0199 fLogicChamber = new G4LogicalVolume(chamberS, fChamberMaterial, "Chamber", 0, 0, 0);
0200
0201 G4double firstPosition = -trackerSize + chamberSpacing;
0202 G4double firstLength = trackerLength / 10;
0203 G4double lastLength = trackerLength;
0204
0205 G4VPVParameterisation* chamberParam =
0206 new B2bChamberParameterisation(NbOfChambers,
0207 firstPosition,
0208 chamberSpacing,
0209 chamberWidth,
0210 firstLength,
0211 lastLength);
0212
0213
0214
0215 new G4PVParameterised("Chamber",
0216 fLogicChamber,
0217 trackerLV,
0218 kZAxis,
0219 NbOfChambers,
0220 chamberParam,
0221 fCheckOverlaps);
0222
0223 G4cout << "There are " << NbOfChambers << " chambers in the tracker region. "
0224 << "\nThe chambers are " << chamberWidth / cm << " cm of " << fChamberMaterial->GetName()
0225 << "\nThe distance between chamber is " << chamberSpacing / cm << " cm" << G4endl;
0226
0227
0228
0229 G4VisAttributes* boxVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
0230 worldLV->SetVisAttributes(boxVisAtt);
0231 fLogicTarget->SetVisAttributes(boxVisAtt);
0232 trackerLV->SetVisAttributes(boxVisAtt);
0233
0234 G4VisAttributes* chamberVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 0.0));
0235 fLogicChamber->SetVisAttributes(chamberVisAtt);
0236
0237
0238
0239
0240
0241
0242
0243
0244 G4double maxStep = 0.5 * chamberWidth;
0245 fStepLimit = new G4UserLimits(maxStep);
0246 trackerLV->SetUserLimits(fStepLimit);
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258 return worldPV;
0259 }
0260
0261
0262
0263 void B2bDetectorConstruction::ConstructSDandField()
0264 {
0265
0266
0267 G4String trackerChamberSDname = "B2/TrackerChamberSD";
0268 B2TrackerSD* aTrackerSD = new B2TrackerSD(trackerChamberSDname, "TrackerHitsCollection");
0269 G4SDManager::GetSDMpointer()->AddNewDetector(aTrackerSD);
0270 SetSensitiveDetector(fLogicChamber, aTrackerSD);
0271
0272
0273
0274
0275 G4ThreeVector fieldValue = G4ThreeVector();
0276 fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
0277 fMagFieldMessenger->SetVerboseLevel(1);
0278 }
0279
0280
0281
0282 void B2bDetectorConstruction::SetTargetMaterial(G4String materialName)
0283 {
0284 G4NistManager* nistManager = G4NistManager::Instance();
0285
0286 G4Material* pttoMaterial = nistManager->FindOrBuildMaterial(materialName);
0287
0288 if (fTargetMaterial != pttoMaterial) {
0289 if (pttoMaterial) {
0290 fTargetMaterial = pttoMaterial;
0291 if (fLogicTarget) fLogicTarget->SetMaterial(fTargetMaterial);
0292 G4cout << "\n----> The target is made of " << materialName << G4endl;
0293 }
0294 else {
0295 G4cout << "\n--> WARNING from SetTargetMaterial : " << materialName << " not found"
0296 << G4endl;
0297 }
0298 }
0299 }
0300
0301
0302
0303 void B2bDetectorConstruction::SetChamberMaterial(G4String materialName)
0304 {
0305 G4NistManager* nistManager = G4NistManager::Instance();
0306
0307 G4Material* pttoMaterial = nistManager->FindOrBuildMaterial(materialName);
0308
0309 if (fChamberMaterial != pttoMaterial) {
0310 if (pttoMaterial) {
0311 fChamberMaterial = pttoMaterial;
0312 if (fLogicChamber) fLogicChamber->SetMaterial(fChamberMaterial);
0313 G4cout << "\n----> The chambers are made of " << materialName << G4endl;
0314 }
0315 else {
0316 G4cout << "\n--> WARNING from SetChamberMaterial : " << materialName << " not found"
0317 << G4endl;
0318 }
0319 }
0320 }
0321
0322
0323
0324 void B2bDetectorConstruction::SetMaxStep(G4double maxStep)
0325 {
0326 if ((fStepLimit) && (maxStep > 0.)) fStepLimit->SetMaxAllowedStep(maxStep);
0327 }
0328
0329