Hello, Thanks again for replying so quickly!
Here is the code for my ‘construction.cc’ file:
#include "construction.hh"
MyDetectorConstruction::MyDetectorConstruction()
{
dMessenger = new G4GenericMessenger(this, "/detector/", "Detector Construction");
wMessenger = new G4GenericMessenger(this, "/world/", "World Construction");
aMessenger = new G4GenericMessenger(this, "/aerogel/", "Aerogel Construction");
mMessenger = new G4GenericMessenger(this, "/materials/", "Materials");
dMessenger->DeclareProperty("nCols", nCols, "Number of columns");
dMessenger->DeclareProperty("nRows", nRows, "Number of rows");
dMessenger->DeclareProperty("xDet", xDet, "X length of detector");
dMessenger->DeclareProperty("yDet", yDet, "Y length of detector");
wMessenger->DeclareProperty("xWorld", xWorld, "X length of world");
wMessenger->DeclareProperty("yWorld", yWorld, "Y length of world");
wMessenger->DeclareProperty("zWorld", zWorld, "Z length of world");
aMessenger->DeclareProperty("xAerogel", xAerogel, "X length of aerogel");
aMessenger->DeclareProperty("yAerogel", yAerogel, "Y length of aerogel");
aMessenger->DeclareProperty("zAerogel", zAerogel, "Z length of aerogel");
aMessenger->DeclareProperty("dAerogel", dAerogel, "Distance from aerogel to detectors");
aMessenger->DeclareProperty("rAerogel", rAerogel, "Refractive index of aerogel");
mMessenger->DeclareProperty("mRadiator", mRadiator, "Radiator material");
mMessenger->DeclareProperty("mWorld", mWorld, "World material");
nCols = 10;
nRows = 10;
xWorld = 0.05*m;
yWorld = 0.05*m;
zWorld = 0.05*m;
xAerogel = 0.02*m;
yAerogel = 0.02*m;
zAerogel = 0.005*m;
dAerogel = 0.04*m;
rAerogel = 1.1;
xDet = 0.012*m;
yDet = 0.012*m;
xPixel = xDet/nCols;
yPixel = yDet/nRows;
zPixel = 0.001*m;
mRadiator = 2; // 1 = water, 2 = aerogel
mWorld = 3; // 3 = air
DefineMaterials();
}
MyDetectorConstruction::~MyDetectorConstruction()
{}
void MyDetectorConstruction::DefineMaterials()
{
G4NistManager *nist = G4NistManager::Instance(); //the geant4 nist material database
G4Material *SiO2 = new G4Material("SiO2", 2.201*g/cm3, 2); //defining the silicone dioxide material object
SiO2->AddElement(nist->FindOrBuildElement("Si"), 1); //adding the silicone element to the object
SiO2->AddElement(nist->FindOrBuildElement("O"), 2); //adding the oxygen element to the object
G4Material *H2O = new G4Material("H2O", 1.000*g/cm3, 2); //defining h20 material object
H2O->AddElement(nist->FindOrBuildElement("H"), 2); //adding the hydrogen element to object
H2O->AddElement(nist->FindOrBuildElement("O"), 1); //adding the oxygen element to object
G4Element *C = nist->FindOrBuildElement("C"); //creating the carbon material object
G4double energy[2] = {1.239841939*eV/0.9, 1.239841939*eV/0.2}; //momentum of photons usng conversion factor *eV / wavlength of red light and blue light
G4double rindexAerogel[2] = {rAerogel, rAerogel}; //refractive index of aerogel
G4double rindexAir[2] = {1.0, 1.0}; //refractive index of the world volume (air)
G4double rindexWater[2] = {1.333, 1.333}; //refractive index of the world volume (water)
if(mWorld == 3)
{
worldMat = nist->FindOrBuildMaterial("G4_AIR"); //createing the world material (air)
G4MaterialPropertiesTable *mptWorld = new G4MaterialPropertiesTable(); //creating properites object for air
mptWorld->AddProperty("RINDEX", energy, rindexAir, 2); //adding property to object
worldMat->SetMaterialPropertiesTable(mptWorld); //assigning properties object to world material object
}
if(mRadiator == 2)
{
radiatorMat = new G4Material("Aerogel", 0.200*g/cm3, 3); //creating the aerogel material object
radiatorMat->AddMaterial(SiO2, 62.5*perCent); //adding the silione dioxide material to aerogel object
radiatorMat->AddMaterial(H2O, 37.4*perCent); //adding the h20 material to aergoel object
radiatorMat->AddElement(C, 0.1*perCent); //adding the carbon material to aerogel object
G4MaterialPropertiesTable *mptAerogel = new G4MaterialPropertiesTable(); //creating aerogel material properties object
mptAerogel->AddProperty("RINDEX", energy, rindexAerogel, 2); //adding property to this object
radiatorMat->SetMaterialPropertiesTable(mptAerogel); //assigning the Aergoel object the properties from the previous object created
}
if(mRadiator == 1)
{
radiatorMat = nist->FindOrBuildMaterial("G4_WATER"); //createing the radiator material (water)
G4MaterialPropertiesTable *mptRadiator = new G4MaterialPropertiesTable(); //creating properites object for water
mptRadiator->AddProperty("RINDEX", energy, rindexWater, 2); //adding property to object
radiatorMat->SetMaterialPropertiesTable(mptRadiator); //assigning properties object to radiator material object
}
}
G4VPhysicalVolume *MyDetectorConstruction::Construct()
{
G4Box *solidWorld = new G4Box("solidWorld", xWorld, yWorld, zWorld); //setting up world volume as a box
G4LogicalVolume *logicWorld = new G4LogicalVolume(solidWorld, worldMat, "logicWorld"); //creating the world as dimensions from box and material
G4VPhysicalVolume *physWorld = new G4PVPlacement(0, G4ThreeVector(0., 0., 0.), logicWorld, "physWorld", 0, false, 0, true); //placing the world into geant 4 sim
G4Box *solidRadiator = new G4Box("solidRadiator", xAerogel, yAerogel, zAerogel); //setting the dimensions for the radiator
G4LogicalVolume *logicRadiator = new G4LogicalVolume(solidRadiator, radiatorMat, "logicRadiator"); //creating the aergoel radiator from dimensions
G4VPhysicalVolume *physRadiator = new G4PVPlacement(0, G4ThreeVector(0., 0., zWorld - dAerogel), logicRadiator, "physRadiator", logicWorld, false, 0, true); //placing radiator into world volume
G4Box *solidDetector = new G4Box("solidDetector", xPixel, yPixel, zPixel); //setting the dimensions for the detectors
logicDetector = new G4LogicalVolume(solidDetector, worldMat, "logicDetector"); //creating the detectors, with same material as world
for(G4int i = 0; i < nRows; i++)
{
for(G4int j = 0; j < nCols; j++)
{
posX = -xDet+(i*2*xPixel);
posY = -yDet+(j*2*yPixel);
posZ = zWorld - zPixel;
G4VPhysicalVolume *physDetector= new G4PVPlacement(0, G4ThreeVector(posX, posY, posZ), logicDetector, "physDetector", logicWorld, false, j+i*nCols, true); //placing detectors into the world
G4cout << posX << " " << posY << " " << posZ << G4endl;
}
}
return physWorld; //returning the world, including everything inside
}
void MyDetectorConstruction::ConstructSDandField()
{
MySensitiveDetector *sensDet = new MySensitiveDetector("SensitiveDetector"); //creating a sensitive detector object
if(logicDetector != NULL)
{
logicDetector->SetSensitiveDetector(sensDet); //assigning the detectors as senstive detectors (it generates a hit when a track traverses its volume)
}
}
Here is the terminal output of my detector positions upon the first run: (all in mm)
Checking overlaps for volume physRadiator:0 (G4Box) ... OK!
Checking overlaps for volume physDetector:0 (G4Box) ... OK!
-12 -12 49
Checking overlaps for volume physDetector:1 (G4Box) ... OK!
-12 -9.6 49
Checking overlaps for volume physDetector:2 (G4Box) ... OK!
-12 -7.2 49
Checking overlaps for volume physDetector:3 (G4Box) ... OK!
-12 -4.8 49
Checking overlaps for volume physDetector:4 (G4Box) ... OK!
-12 -2.4 49
Checking overlaps for volume physDetector:5 (G4Box) ... OK!
-12 0 49
Checking overlaps for volume physDetector:6 (G4Box) ... OK!
-12 2.4 49
Checking overlaps for volume physDetector:7 (G4Box) ... OK!
-12 4.8 49
Checking overlaps for volume physDetector:8 (G4Box) ... OK!
-12 7.2 49
Checking overlaps for volume physDetector:9 (G4Box) ... OK!
-12 9.6 49
Checking overlaps for volume physDetector:10 (G4Box) ... OK!
-9.6 -12 49
Checking overlaps for volume physDetector:11 (G4Box) ... OK!
-9.6 -9.6 49
Checking overlaps for volume physDetector:12 (G4Box) ... OK!
-9.6 -7.2 49
Checking overlaps for volume physDetector:13 (G4Box) ... OK!
-9.6 -4.8 49
Checking overlaps for volume physDetector:14 (G4Box) ... OK!
-9.6 -2.4 49
Checking overlaps for volume physDetector:15 (G4Box) ... OK!
-9.6 0 49
Checking overlaps for volume physDetector:16 (G4Box) ... OK!
-9.6 2.4 49
Checking overlaps for volume physDetector:17 (G4Box) ... OK!
-9.6 4.8 49
Checking overlaps for volume physDetector:18 (G4Box) ... OK!
-9.6 7.2 49
Checking overlaps for volume physDetector:19 (G4Box) ... OK!
-9.6 9.6 49
Checking overlaps for volume physDetector:20 (G4Box) ... OK!
-7.2 -12 49
Checking overlaps for volume physDetector:21 (G4Box) ... OK!
-7.2 -9.6 49
Checking overlaps for volume physDetector:22 (G4Box) ... OK!
-7.2 -7.2 49
Checking overlaps for volume physDetector:23 (G4Box) ... OK!
-7.2 -4.8 49
Checking overlaps for volume physDetector:24 (G4Box) ... OK!
-7.2 -2.4 49
Checking overlaps for volume physDetector:25 (G4Box) ... OK!
-7.2 0 49
Checking overlaps for volume physDetector:26 (G4Box) ... OK!
-7.2 2.4 49
Checking overlaps for volume physDetector:27 (G4Box) ... OK!
-7.2 4.8 49
Checking overlaps for volume physDetector:28 (G4Box) ... OK!
-7.2 7.2 49
Checking overlaps for volume physDetector:29 (G4Box) ... OK!
-7.2 9.6 49
Checking overlaps for volume physDetector:30 (G4Box) ... OK!
-4.8 -12 49
Checking overlaps for volume physDetector:31 (G4Box) ... OK!
-4.8 -9.6 49
Checking overlaps for volume physDetector:32 (G4Box) ... OK!
-4.8 -7.2 49
Checking overlaps for volume physDetector:33 (G4Box) ... OK!
-4.8 -4.8 49
Checking overlaps for volume physDetector:34 (G4Box) ... OK!
-4.8 -2.4 49
Checking overlaps for volume physDetector:35 (G4Box) ... OK!
-4.8 0 49
Checking overlaps for volume physDetector:36 (G4Box) ... OK!
-4.8 2.4 49
Checking overlaps for volume physDetector:37 (G4Box) ... OK!
-4.8 4.8 49
Checking overlaps for volume physDetector:38 (G4Box) ... OK!
-4.8 7.2 49
Checking overlaps for volume physDetector:39 (G4Box) ... OK!
-4.8 9.6 49
Checking overlaps for volume physDetector:40 (G4Box) ... OK!
-2.4 -12 49
Checking overlaps for volume physDetector:41 (G4Box) ... OK!
-2.4 -9.6 49
Checking overlaps for volume physDetector:42 (G4Box) ... OK!
-2.4 -7.2 49
Checking overlaps for volume physDetector:43 (G4Box) ... OK!
-2.4 -4.8 49
Checking overlaps for volume physDetector:44 (G4Box) ... OK!
-2.4 -2.4 49
Checking overlaps for volume physDetector:45 (G4Box) ... OK!
-2.4 0 49
Checking overlaps for volume physDetector:46 (G4Box) ... OK!
-2.4 2.4 49
Checking overlaps for volume physDetector:47 (G4Box) ... OK!
-2.4 4.8 49
Checking overlaps for volume physDetector:48 (G4Box) ... OK!
-2.4 7.2 49
Checking overlaps for volume physDetector:49 (G4Box) ... OK!
-2.4 9.6 49
Checking overlaps for volume physDetector:50 (G4Box) ... OK!
0 -12 49
Checking overlaps for volume physDetector:51 (G4Box) ... OK!
0 -9.6 49
Checking overlaps for volume physDetector:52 (G4Box) ... OK!
0 -7.2 49
Checking overlaps for volume physDetector:53 (G4Box) ... OK!
0 -4.8 49
Checking overlaps for volume physDetector:54 (G4Box) ... OK!
0 -2.4 49
Checking overlaps for volume physDetector:55 (G4Box) ... OK!
0 0 49
Checking overlaps for volume physDetector:56 (G4Box) ... OK!
0 2.4 49
Checking overlaps for volume physDetector:57 (G4Box) ... OK!
0 4.8 49
Checking overlaps for volume physDetector:58 (G4Box) ... OK!
0 7.2 49
Checking overlaps for volume physDetector:59 (G4Box) ... OK!
0 9.6 49
Checking overlaps for volume physDetector:60 (G4Box) ... OK!
2.4 -12 49
Checking overlaps for volume physDetector:61 (G4Box) ... OK!
2.4 -9.6 49
Checking overlaps for volume physDetector:62 (G4Box) ... OK!
2.4 -7.2 49
Checking overlaps for volume physDetector:63 (G4Box) ... OK!
2.4 -4.8 49
Checking overlaps for volume physDetector:64 (G4Box) ... OK!
2.4 -2.4 49
Checking overlaps for volume physDetector:65 (G4Box) ... OK!
2.4 0 49
Checking overlaps for volume physDetector:66 (G4Box) ... OK!
2.4 2.4 49
Checking overlaps for volume physDetector:67 (G4Box) ... OK!
2.4 4.8 49
Checking overlaps for volume physDetector:68 (G4Box) ... OK!
2.4 7.2 49
Checking overlaps for volume physDetector:69 (G4Box) ... OK!
2.4 9.6 49
Checking overlaps for volume physDetector:70 (G4Box) ... OK!
4.8 -12 49
Checking overlaps for volume physDetector:71 (G4Box) ... OK!
4.8 -9.6 49
Checking overlaps for volume physDetector:72 (G4Box) ... OK!
4.8 -7.2 49
Checking overlaps for volume physDetector:73 (G4Box) ... OK!
4.8 -4.8 49
Checking overlaps for volume physDetector:74 (G4Box) ... OK!
4.8 -2.4 49
Checking overlaps for volume physDetector:75 (G4Box) ... OK!
4.8 0 49
Checking overlaps for volume physDetector:76 (G4Box) ... OK!
4.8 2.4 49
Checking overlaps for volume physDetector:77 (G4Box) ... OK!
4.8 4.8 49
Checking overlaps for volume physDetector:78 (G4Box) ... OK!
4.8 7.2 49
Checking overlaps for volume physDetector:79 (G4Box) ... OK!
4.8 9.6 49
Checking overlaps for volume physDetector:80 (G4Box) ... OK!
7.2 -12 49
Checking overlaps for volume physDetector:81 (G4Box) ... OK!
7.2 -9.6 49
Checking overlaps for volume physDetector:82 (G4Box) ... OK!
7.2 -7.2 49
Checking overlaps for volume physDetector:83 (G4Box) ... OK!
7.2 -4.8 49
Checking overlaps for volume physDetector:84 (G4Box) ... OK!
7.2 -2.4 49
Checking overlaps for volume physDetector:85 (G4Box) ... OK!
7.2 0 49
Checking overlaps for volume physDetector:86 (G4Box) ... OK!
7.2 2.4 49
Checking overlaps for volume physDetector:87 (G4Box) ... OK!
7.2 4.8 49
Checking overlaps for volume physDetector:88 (G4Box) ... OK!
7.2 7.2 49
Checking overlaps for volume physDetector:89 (G4Box) ... OK!
7.2 9.6 49
Checking overlaps for volume physDetector:90 (G4Box) ... OK!
9.6 -12 49
Checking overlaps for volume physDetector:91 (G4Box) ... OK!
9.6 -9.6 49
Checking overlaps for volume physDetector:92 (G4Box) ... OK!
9.6 -7.2 49
Checking overlaps for volume physDetector:93 (G4Box) ... OK!
9.6 -4.8 49
Checking overlaps for volume physDetector:94 (G4Box) ... OK!
9.6 -2.4 49
Checking overlaps for volume physDetector:95 (G4Box) ... OK!
9.6 0 49
Checking overlaps for volume physDetector:96 (G4Box) ... OK!
9.6 2.4 49
Checking overlaps for volume physDetector:97 (G4Box) ... OK!
9.6 4.8 49
Checking overlaps for volume physDetector:98 (G4Box) ... OK!
9.6 7.2 49
Checking overlaps for volume physDetector:99 (G4Box) ... OK!
9.6 9.6 49
Based on the positions given by the errors, it seems as if none of the positions is correct. I am not sure why this is the case…