|
Geant4 examples
|
Detector construction class to define materials and geometry. More...
#include <Doxymodules_basic.h>
Public Member Functions | |
| B2aDetectorConstruction () | |
| virtual | ~B2aDetectorConstruction () |
| virtual G4VPhysicalVolume * | Construct () |
| void | SetMagField (G4double) |
| void | SetTargetMaterial (G4String) |
| void | SetChamberMaterial (G4String) |
| void | SetMaxStep (G4double) |
| void | SetCheckOverlaps (G4bool) |
Private Member Functions | |
| void | DefineMaterials () |
| G4VPhysicalVolume * | DefineVolumes () |
Private Attributes | |
| G4int | fNbOfChambers |
| G4LogicalVolume * | fLogicTarget |
| G4LogicalVolume ** | fLogicChamber |
| G4Material * | fTargetMaterial |
| G4Material * | fChamberMaterial |
| G4UserLimits * | fStepLimit |
| B2aDetectorMessenger * | fMessenger |
| B2MagneticField * | fMagField |
| G4bool | fCheckOverlaps |
Detector construction class to define materials and geometry.
In addition a transverse uniform magnetic field is defined in SetMagField() method which can be activated via a command defined in the B2aDetectorMessenger class.
Definition at line 40 of file Doxymodules_basic.h.
| B2aDetectorConstruction::B2aDetectorConstruction | ( | ) |
Definition at line 58 of file B2aDetectorConstruction.cc.
: fNbOfChambers(0), fLogicTarget(NULL), fLogicChamber(NULL), fTargetMaterial(NULL), fChamberMaterial(NULL), fStepLimit(NULL), fCheckOverlaps(true) { fMessenger = new B2aDetectorMessenger(this); fMagField = new B2MagneticField(); fNbOfChambers = 5; fLogicChamber = new G4LogicalVolume*[fNbOfChambers]; }
| B2aDetectorConstruction::~B2aDetectorConstruction | ( | ) | [virtual] |
Definition at line 75 of file B2aDetectorConstruction.cc.
{
delete [] fLogicChamber;
delete fMagField;
delete fStepLimit;
delete fMessenger;
}
| G4VPhysicalVolume * B2aDetectorConstruction::Construct | ( | ) | [virtual] |
Implements G4VUserDetectorConstruction.
Definition at line 85 of file B2aDetectorConstruction.cc.
{
// Define materials
DefineMaterials();
// Define volumes
return DefineVolumes();
}
| void B2aDetectorConstruction::SetMagField | ( | G4double | fieldValue | ) |
Definition at line 345 of file B2aDetectorConstruction.cc.
{
fMagField->SetMagFieldValue(fieldValue);
}
| void B2aDetectorConstruction::SetTargetMaterial | ( | G4String | materialName | ) |
Definition at line 298 of file B2aDetectorConstruction.cc.
{
G4NistManager* nistManager = G4NistManager::Instance();
G4bool fromIsotopes = false;
G4Material* pttoMaterial =
nistManager->FindOrBuildMaterial(materialName, fromIsotopes);
if (fTargetMaterial != pttoMaterial) {
if ( pttoMaterial ) {
fTargetMaterial = pttoMaterial;
if (fLogicTarget) fLogicTarget->SetMaterial(fTargetMaterial);
G4cout << "\n----> The target is made of " << materialName << G4endl;
} else {
G4cout << "\n--> WARNING from SetTargetMaterial : "
<< materialName << " not found" << G4endl;
}
}
}
| void B2aDetectorConstruction::SetChamberMaterial | ( | G4String | materialName | ) |
Definition at line 320 of file B2aDetectorConstruction.cc.
{
G4NistManager* nistManager = G4NistManager::Instance();
G4bool fromIsotopes = false;
G4Material* pttoMaterial =
nistManager->FindOrBuildMaterial(materialName, fromIsotopes);
if (fChamberMaterial != pttoMaterial) {
if ( pttoMaterial ) {
fChamberMaterial = pttoMaterial;
for (G4int copyNo=0; copyNo<fNbOfChambers; copyNo++) {
if (fLogicChamber[copyNo]) fLogicChamber[copyNo]->
SetMaterial(fChamberMaterial);
}
G4cout << "\n----> The chambers are made of " << materialName << G4endl;
} else {
G4cout << "\n--> WARNING from SetChamberMaterial : "
<< materialName << " not found" << G4endl;
}
}
}
| void B2aDetectorConstruction::SetMaxStep | ( | G4double | maxStep | ) |
Definition at line 352 of file B2aDetectorConstruction.cc.
{
if ((fStepLimit)&&(maxStep>0.)) fStepLimit->SetMaxAllowedStep(maxStep);
}
| void B2aDetectorConstruction::SetCheckOverlaps | ( | G4bool | checkOverlaps | ) |
Definition at line 359 of file B2aDetectorConstruction.cc.
{
fCheckOverlaps = checkOverlaps;
}
| void B2aDetectorConstruction::DefineMaterials | ( | ) | [private] |
Definition at line 96 of file B2aDetectorConstruction.cc.
{
// Material definition
G4NistManager* nistManager = G4NistManager::Instance();
G4bool fromIsotopes = false;
// Air defined using NIST Manager
nistManager->FindOrBuildMaterial("G4_AIR", fromIsotopes);
// Lead defined using NIST Manager
fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Pb", fromIsotopes);
// Xenon gas defined using NIST Manager
fChamberMaterial = nistManager->FindOrBuildMaterial("G4_Xe", fromIsotopes);
// Print materials
G4cout << *(G4Material::GetMaterialTable()) << G4endl;
}
| G4VPhysicalVolume * B2aDetectorConstruction::DefineVolumes | ( | ) | [private] |
Set additional contraints on the track, with G4UserSpecialCuts
G4double maxLength = 2*trackerLength, maxTime = 0.1*ns, minEkin = 10*MeV; trackerLV->SetUserLimits(new G4UserLimits(maxStep, maxLength, maxTime, minEkin));
Definition at line 119 of file B2aDetectorConstruction.cc.
{
G4Material* air = G4Material::GetMaterial("G4_AIR");
// Sizes of the principal geometrical components (solids)
G4double chamberSpacing = 80*cm; // from chamber center to center!
G4double chamberWidth = 20.0*cm; // width of the chambers
G4double targetLength = 5.0*cm; // full length of Target
G4double trackerLength = (fNbOfChambers+1)*chamberSpacing;
G4double worldLength = 1.2 * (2*targetLength + trackerLength);
G4double targetRadius = 0.5*targetLength; // Radius of Target
targetLength = 0.5*targetLength; // Half length of the Target
G4double trackerSize = 0.5*trackerLength; // Half length of the Tracker
// Definitions of Solids, Logical Volumes, Physical Volumes
// World
G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength);
G4cout << "Computed tolerance = "
<< G4GeometryTolerance::GetInstance()->GetSurfaceTolerance()/mm
<< " mm" << G4endl;
G4Box* worldS
= new G4Box("world", //its name
worldLength/2,worldLength/2,worldLength/2); //its size
G4LogicalVolume* worldLV
= new G4LogicalVolume(
worldS, //its solid
air, //its material
"World"); //its name
// Must place the World Physical volume unrotated at (0,0,0).
//
G4VPhysicalVolume* worldPV
= new G4PVPlacement(
0, // no rotation
G4ThreeVector(), // at (0,0,0)
worldLV, // its logical volume
"World", // its name
0, // its mother volume
false, // no boolean operations
0, // copy number
fCheckOverlaps); // checking overlaps
// Target
G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetLength+trackerSize));
G4Tubs* targetS
= new G4Tubs("target",0.,targetRadius,targetLength,0.*deg,360.*deg);
fLogicTarget
= new G4LogicalVolume(targetS, fTargetMaterial,"Target",0,0,0);
new G4PVPlacement(0, // no rotation
positionTarget, // at (x,y,z)
fLogicTarget, // its logical volume
"Target", // its name
worldLV, // its mother volume
false, // no boolean operations
0, // copy number
fCheckOverlaps); // checking overlaps
G4cout << "Target is " << 2*targetLength/cm << " cm of "
<< fTargetMaterial->GetName() << G4endl;
// Tracker
G4ThreeVector positionTracker = G4ThreeVector(0,0,0);
G4Tubs* trackerS
= new G4Tubs("tracker",0,trackerSize,trackerSize, 0.*deg, 360.*deg);
G4LogicalVolume* trackerLV
= new G4LogicalVolume(trackerS, air, "Tracker",0,0,0);
new G4PVPlacement(0, // no rotation
positionTracker, // at (x,y,z)
trackerLV, // its logical volume
"Tracker", // its name
worldLV, // its mother volume
false, // no boolean operations
0, // copy number
fCheckOverlaps); // checking overlaps
// Visualization attributes
G4VisAttributes* boxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
G4VisAttributes* chamberVisAtt = new G4VisAttributes(G4Colour(1.0,1.0,0.0));
worldLV ->SetVisAttributes(boxVisAtt);
fLogicTarget ->SetVisAttributes(boxVisAtt);
trackerLV ->SetVisAttributes(boxVisAtt);
// Sensitive detectors
G4String trackerChamberSDname = "B2/TrackerChamberSD";
B2TrackerSD* aTrackerSD = new B2TrackerSD(trackerChamberSDname,
"TrackerHitsCollection");
G4SDManager::GetSDMpointer()->AddNewDetector( aTrackerSD );
// Tracker segments
G4cout << "There are " << fNbOfChambers << " chambers in the tracker region. "
<< "\nThe chambers are " << chamberWidth/cm << " cm of "
<< fChamberMaterial->GetName() << "\nThe distance between chamber is "
<< chamberSpacing/cm << " cm" << G4endl;
G4double firstPosition = -trackerSize + chamberSpacing;
G4double firstLength = trackerLength/10;
G4double lastLength = trackerLength;
G4double halfWidth = 0.5*chamberWidth;
G4double rmaxFirst = 0.5 * firstLength;
G4double rmaxIncr = 0.0;
if( fNbOfChambers > 0 ){
rmaxIncr = 0.5 * (lastLength-firstLength)/(fNbOfChambers-1);
if (chamberSpacing < chamberWidth) {
G4Exception("B2aDetectorConstruction::DefineVolumes()",
"InvalidSetup", FatalException,
"Width>Spacing");
}
}
for (G4int copyNo=0; copyNo<fNbOfChambers; copyNo++) {
G4double Zposition = firstPosition + copyNo * chamberSpacing;
G4double rmax = rmaxFirst + copyNo * rmaxIncr;
G4Tubs* chamberS
= new G4Tubs("chamber", 0, rmax, halfWidth, 0.*deg, 360.*deg);
fLogicChamber[copyNo] =
new G4LogicalVolume(chamberS,fChamberMaterial,"Chamber",0,0,0);
fLogicChamber[copyNo]->SetSensitiveDetector( aTrackerSD );
fLogicChamber[copyNo]->SetVisAttributes(chamberVisAtt);
new G4PVPlacement(0, // no rotation
G4ThreeVector(0,0,Zposition), // at (x,y,z)
fLogicChamber[copyNo], // its logical volume
"Chamber", // its name
trackerLV, // its mother volume
false, // no boolean operations
copyNo, // copy number
fCheckOverlaps); // checking overlaps
}
// Example of User Limits
//
// Below is an example of how to set tracking constraints in a given
// logical volume
//
// Sets a max step length in the tracker region, with G4StepLimiter
G4double maxStep = 0.5*chamberWidth;
fStepLimit = new G4UserLimits(maxStep);
trackerLV->SetUserLimits(fStepLimit);
// Always return the physical world
return worldPV;
}
G4int B2aDetectorConstruction::fNbOfChambers [private] |
Definition at line 73 of file B2aDetectorConstruction.hh.
Definition at line 75 of file B2aDetectorConstruction.hh.
Definition at line 76 of file B2aDetectorConstruction.hh.
Definition at line 78 of file B2aDetectorConstruction.hh.
Definition at line 79 of file B2aDetectorConstruction.hh.
G4UserLimits* B2aDetectorConstruction::fStepLimit [private] |
Definition at line 81 of file B2aDetectorConstruction.hh.
Definition at line 83 of file B2aDetectorConstruction.hh.
Definition at line 84 of file B2aDetectorConstruction.hh.
Definition at line 86 of file B2aDetectorConstruction.hh.
1.7.4