Expand|Select|Wrap|Line Numbers
- #include "DetectorMessenger.hh"
- #include "G4Material.hh"
- #include "G4NistManager.hh"
- #include "G4Box.hh"
- #include "G4LogicalVolume.hh"
- #include "G4PVPlacement.hh"
- #include "G4PVReplica.hh"
- #include "G4UniformMagField.hh"
- #include "G4GeometryManager.hh"
- #include "G4PhysicalVolumeStore.hh"
- #include "G4LogicalVolumeStore.hh"
- #include "G4SolidStore.hh"
- #include "G4VisAttributes.hh"
- #include "G4Colour.hh"
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- DetectorConstruction::DetectorConstruction()
- :SensitiveDetectorMaterial(0),BlasticBaseMaterial(0),defaultMaterial(0),
- solidWorld(0),logicWorld(0),physiWorld(0),
- solidCalor(0),logicCalor(0),physiCalor(0),
- solidLayer1(0),logicLayer1(0),physiLayer1(0),
- solidLayer2(0),logicLayer2(0),physiLayer2(0),
- solidSensitiveDetector (0),logicSensitiveDetector (0),physiSensitiveDetector (0),solidBlasticBase (0),logicBlasticBase (0),physiBlasticBase (0),
- magField(0)
- {
- // default parameter values of the calorimeter
- SensitiveDetectorThickness = 0.0044*cm;
- BlasticBaseThickness = 0.0205*cm;
- NbOfLayers1 = 2;
- NbOfLayers2 =1;
- CalorSizeYZ = 12.*cm;
- ComputeCalorParameters();
- // SensitiveDetectormaterial
- DefineMaterials();
- SetSensitiveDetectorMaterial("SILVER_HALIDES");
- // create commands for interactive definition of the calorimeter
- detectorMessenger = new DetectorMessenger(this);
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- DetectorConstruction::~DetectorConstruction()
- { delete detectorMessenger;}
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- G4VPhysicalVolume* DetectorConstruction::Construct()
- {
- return ConstructCalorimeter();
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- void DetectorConstruction::DefineMaterials()
- {
- //This function illustrates the possible ways to define materials
- G4String symbol; //a=mass of a mole;
- G4double a, z, density; //z=mean number of protons;
- G4int iz, n; //iz=number of protons in an isotope;
- // n=number of nucleons in an isotope;
- G4int ncomponents, natoms;
- G4double abundance, fractionmass;
- //
- // define Elements
- //
- G4Element* H = new G4Element("Hydrogen",symbol="H" , z= 1., a= 1.01*g/mole);
- G4Element* C = new G4Element("Carbon" ,symbol="C" , z= 6., a= 12.01*g/mole);
- G4Element* N = new G4Element("Nitrogen",symbol="N" , z= 7., a= 14.01*g/mole);
- G4Element* O = new G4Element("Oxygen" ,symbol="O" , z= 8., a= 16.00*g/mole);
- G4Element* Si = new G4Element("Silicon",symbol="Si" , z= 14., a= 28.09*g/mole);
- //
- // define an Element from isotopes, by relative abundance
- //
- G4Isotope* U5 = new G4Isotope("U235", iz=92, n=235, a=235.01*g/mole);
- G4Isotope* U8 = new G4Isotope("U238", iz=92, n=238, a=238.03*g/mole);
- G4Element* U = new G4Element("enriched Uranium",symbol="U",ncomponents=2);
- U->AddIsotope(U5, abundance= 90.*perCent);
- U->AddIsotope(U8, abundance= 10.*perCent);
- //
- // define simple materials
- //
- new G4Material("Aluminium", z=13., a=26.98*g/mole, density=2.700*g/cm3);
- new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
- new G4Material("Lead" , z=82., a= 207.19*g/mole, density= 11.35*g/cm3);
- //
- // define a material from elements. case 1: chemical molecule
- //
- G4Material* H2O =
- new G4Material("Water", density= 1.000*g/cm3, ncomponents=2);
- H2O->AddElement(H, natoms=2);
- H2O->AddElement(O, natoms=1);
- // overwrite computed meanExcitationEnergy with ICRU recommended value
- H2O->GetIonisation()->SetMeanExcitationEnergy(78.0*eV);
- G4Material* Sci =
- new G4Material("Scintillator", density= 1.032*g/cm3, ncomponents=2);
- Sci->AddElement(C, natoms=9);
- Sci->AddElement(H, natoms=10);
- G4Material* Myl =
- new G4Material("Mylar", density= 1.397*g/cm3, ncomponents=3);
- Myl->AddElement(C, natoms=10);
- Myl->AddElement(H, natoms= 8);
- Myl->AddElement(O, natoms= 4);
- G4Material* SiO2 =
- new G4Material("quartz",density= 2.200*g/cm3, ncomponents=2);
- SiO2->AddElement(Si, natoms=1);
- SiO2->AddElement(O , natoms=2);
- //
- // define a material from elements. case 2: mixture by fractional mass
- //
- G4Material* Air =
- new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2);
- Air->AddElement(N, fractionmass=0.7);
- Air->AddElement(O, fractionmass=0.3);
- //
- // define a material from elements and/or others materials (mixture of mixtures)
- //
- G4Material* Aerog =
- new G4Material("Aerogel", density= 0.200*g/cm3, ncomponents=3);
- Aerog->AddMaterial(SiO2, fractionmass=62.5*perCent);
- Aerog->AddMaterial(H2O , fractionmass=37.4*perCent);
- Aerog->AddElement (C , fractionmass= 0.1*perCent);
- //
- // examples of gas in non STP conditions
- //
- G4Material* CO2 =
- new G4Material("CarbonicGas", density= 1.842*mg/cm3, ncomponents=2,
- kStateGas, 325.*kelvin, 50.*atmosphere);
- CO2->AddElement(C, natoms=1);
- CO2->AddElement(O, natoms=2);
- G4Material* steam =
- new G4Material("WaterSteam", density= 0.3*mg/cm3, ncomponents=1,
- kStateGas, 500.*kelvin, 2.*atmosphere);
- steam->AddMaterial(H2O, fractionmass=1.);
- //
- // examples of vacuum
- //
- G4Material* Vacuum =
- new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
- kStateGas, 2.73*kelvin, 3.e-18*pascal);
- G4Material* beam =
- new G4Material("Beam", density= 1.e-5*g/cm3, ncomponents=1,
- kStateGas, STP_Temperature, 2.e-2*bar);
- beam->AddMaterial(Air, fractionmass=1.);
- //
- // or use G4-NIST materials data base
- //
- G4NistManager* man = G4NistManager::Instance();
- man->FindOrBuildMaterial("G4_SILVER_HALIDES");
- // print table
- //
- G4cout << *(G4Material::GetMaterialTable()) << G4endl;
- //default materials of the World
- defaultMaterial = Vacuum;
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- G4VPhysicalVolume* DetectorConstruction::ConstructCalorimeter()
- {
- // Clean old geometry, if any
- //
- G4GeometryManager::GetInstance()->OpenGeometry();
- G4PhysicalVolumeStore::GetInstance()->Clean();
- G4LogicalVolumeStore::GetInstance()->Clean();
- G4SolidStore::GetInstance()->Clean();
- // complete the Calor parameters definition
- ComputeCalorParameters();
- //
- // World
- //
- solidWorld = new G4Box("World", //its name
- WorldSizeX/2,WorldSizeYZ/2,WorldSizeYZ/2); //its size
- logicWorld = new G4LogicalVolume(solidWorld, //its solid
- defaultMaterial, //its material
- "World"); //its name
- physiWorld = new G4PVPlacement(0, //no rotation
- G4ThreeVector(), //at (0,0,0)
- logicWorld, //its logical volume
- "World", //its name
- 0, //its mother volume
- false, //no boolean operation
- 0); //copy number
- //
- // Calorimeter
- //
- solidCalor=0; logicCalor=0; physiCalor=0;
- solidLayer1=0; logicLayer1=0; physiLayer1=0;
- if (CalorThickness > 0.)
- { solidCalor = new G4Box("Calorimeter", //its name
- CalorThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);//size
- logicCalor = new G4LogicalVolume(solidCalor, //its solid
- defaultMaterial, //its material
- "Calorimeter"); //its name
- physiCalor = new G4PVPlacement(0, //no rotation
- G4ThreeVector(), //at (0,0,0)
- logicCalor, //its logical volume
- "Calorimeter", //its name
- logicWorld, //its mother volume
- false, //no boolean operation
- 0); //copy number
- //
- // Layer1
- //
- solidLayer1 = new G4Box("Layer1", //its name
- SensitiveDetectorThickness/2,CalorSizeYZ/2,CalorSizeYZ/2); //size
- logicLayer1 = new G4LogicalVolume(solidLayer1, //its solid
- defaultMaterial, //its material
- "Layer1"); //its name
- if (NbOfLayers1 > 1)
- physiLayer1 = new G4PVReplica("Layer1", //its name
- logicLayer1, //its logical volume
- logicCalor, //its mother
- kXAxis, //axis of replication
- NbOfLayers1, //number of replica
- Layer1Thickness); //witdth of replica
- else
- physiLayer1 = new G4PVPlacement(0, //no rotation
- G4ThreeVector(), //at (0,0,0)
- logicLayer1, //its logical volume
- "Layer1", //its name
- logicCalor, //its mother volume
- false, //no boolean operation
- 0); //copy number
- }
- //
- // SensitiveDetector
- //
- solidSensitiveDetector =0; logicSensitiveDetector =0; physiSensitiveDetector =0;
- if (SensitiveDetectorThickness > 0.)
- { solidSensitiveDetector = new G4Box("SensitiveDetector ", //its name
- SensitiveDetectorThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);
- logicSensitiveDetector = new G4LogicalVolume(solidSensitiveDetector, //its solid
- SensitiveDetectorMaterial, //its material
- SensitiveDetectorMaterial->GetName()); //name
- physiSensitiveDetector = new G4PVPlacement(0, //no rotation
- G4ThreeVector(BlasticBaseThickness/2,0.,0.), //its position
- logicSensitiveDetector, //its logical volume
- SensitiveDetectorMaterial->GetName(), //its name
- logicLayer1, //its mother
- false, //no boulean operat
- 0); //copy number
- }
- //
- // Layer2
- //
- solidLayer2 = new G4Box("Layer2", //its name
- BlasticBaseThickness/2,CalorSizeYZ/2,CalorSizeYZ/2); //size
- logicLayer2 = new G4LogicalVolume(solidLayer2, //its solid
- defaultMaterial, //its material
- "Layer2"); //its name
- if (NbOfLayers2 > 1)
- physiLayer2 = new G4PVReplica("Layer2", //its name
- logicLayer2, //its logical volume
- logicCalor, //its mother
- kXAxis, //axis of replication
- NbOfLayers2, //number of replica
- BlasticBaseThickness);//witdth of replica
- else
- physiLayer2 = new G4PVPlacement(0, //no rotation
- G4ThreeVector(), //at (0,0,0)
- logicLayer2, //its logical volume
- "Layer2", //its name
- logicCalor, //its mother volume
- false, //no boolean operation
- 0); //copy number
- } 0000000000000000
- //BlasticBase
- {
- solidBlasticBase=0; logicBlasticBase=0; physiBlasticBase=0;
- if ( BlasticBaseThickness > 0.)
- { solidSensitiveDetector = new G4Box(" BlasticBase ", //its name
- BlasticBaseThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);
- logicBlasticBase= new G4LogicalVolume(solidSensitiveDetector, //its solid
- BlasticBaseMaterial, //its material
- BlasticBaseMaterial->GetName(Lead)); //name
- physi BlasticBase = new G4PVPlacement(0, //no rotation
- G4ThreeVector( SensitiveDetectorThickness/2,0.,0.), //its position
- logic BlasticBase, //its logical volume
- BlasticBaseMaterial->GetName(Lead), //its name
- logicLayer1, //its mother
- false, //no boulean operat
- 0); //copy number
- {{}
- PrintCalorParameters();
- //
- // Visualization attributes
- //
- logicWorld->SetVisAttributes (G4VisAttributes::Invisible);
- G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
- simpleBoxVisAtt->SetVisibility(true);
- logicCalor->SetVisAttributes(simpleBoxVisAtt);
- /*
- // Below are vis attributes that permits someone to test / play
- // with the interactive expansion / contraction geometry system of the
- // vis/OpenInventor driver :
- {G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));
- simpleBoxVisAtt->SetVisibility(true);
- delete logicCalor->GetVisAttributes();
- logicCalor->SetVisAttributes(simpleBoxVisAtt);}
- {G4VisAttributes* atb= new G4VisAttributes(G4Colour(1.0,0.0,0.0));
- logicLayer->SetVisAttributes(atb);}
- {G4VisAttributes* atb= new G4VisAttributes(G4Colour(0.0,1.0,0.0));
- atb->SetForceSolid(true);
- logicSensitiveDetector->SetVisAttributes(atb);}
- {//Set opacity = 0.2 then transparency = 1 - 0.2 = 0.8
- G4VisAttributes* atb= new G4VisAttributes(G4Colour(0.0,0.0,1.0,0.2));
- atb->SetForceSolid(true);
- logicBlasticBase->SetVisAttributes(atb);}
- */
- //
- //always return the physical World
- //
- return physiWorld;
- }}
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- void DetectorConstruction::PrintCalorParameters()
- {
- G4cout << "\n------------------------------------------------------------"
- << "\n---> The calorimeter is " << NbOfLayers1 << " layers1 of: [ "
- << "\n---> The calorimeter is " << NbOfLayers2 << " layers2 of: [ "
- << SensitiveDetectorThickness/cm << "cm of " << SensitiveDetectorMaterial->GetName()
- << " + "
- << BlasticBaseThickness/cm << "cm of " << BlasticBaseMaterial->GetName() << " ] "
- << "\n------------------------------------------------------------\n";
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- void DetectorConstruction::SetSensitiveDetectorMaterial(G4String materialChoice)
- {
- // search the material by its name
- G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
- if (pttoMaterial) SensitiveDetectorMaterial = pttoMaterial;
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- void DetectorConstruction::SetBlasticBaseMaterial(G4String materialChoice)
- {
- // search the material by its name
- G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
- if (pttoMaterial) BlasticBaseMaterial = pttoMaterial;
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- void DetectorConstruction::SetSensitiveDetectorThickness(G4double val)
- {
- // change SensitiveDetector thickness and recompute the calorimeter parameters
- SensitiveDetectorThickness = val;
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- void DetectorConstruction::SetBlasticBaseThickness(G4double val)
- {
- // change BlasticBase thickness and recompute the calorimeter parameters
- BlasticBaseThickness = val;
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- void DetectorConstruction::SetCalorSizeYZ(G4double val)
- {
- // change the transverse size and recompute the calorimeter parameters
- CalorSizeYZ = val;
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- void DetectorConstruction::SetNbOfLayers1(G4int val)
- {
- NbOfLayers1 = val;
- }
- void DetectorConstruction::SetNbOfLayers2(G4int val)
- {
- NbOfLayers2 = val;
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- #include "G4FieldManager.hh"
- #include "G4TransportationManager.hh"
- void DetectorConstruction::SetMagField(G4double fieldValue)
- {
- //apply a global uniform magnetic field along Z axis
- G4FieldManager* fieldMgr
- = G4TransportationManager::GetTransportationManager()->GetFieldManager();
- if(magField) delete magField; //delete the existing magn field
- if(fieldValue!=0.) // create a new one if non nul
- { magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
- fieldMgr->SetDetectorField(magField);
- fieldMgr->CreateChordFinder(magField);
- } else {
- magField = 0;
- fieldMgr->SetDetectorField(magField);
- }
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- #include "G4RunManager.hh"
- void DetectorConstruction::UpdateGeometry()
- {
- G4RunManager::GetRunManager()->DefineWorldVolume(ConstructCalorimeter());
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......