118 lines
2.6 KiB
C++
118 lines
2.6 KiB
C++
|
|
|
|
#include "GeometryDescriptor.hh"
|
|
#include "G4VPhysicalVolume.hh"
|
|
#include "G4System.hh"
|
|
|
|
|
|
void Layer::setThickness(double thickness){
|
|
this->thickness = thickness;
|
|
}
|
|
|
|
void Layer::setMaterial(std::string material){
|
|
this->material = material;
|
|
}
|
|
|
|
void Layer::setNx(int nx){
|
|
this->nx = nx;
|
|
}
|
|
|
|
void Layer::setNy(int ny){
|
|
this->ny = ny;
|
|
}
|
|
|
|
void Layer::setIsActive(bool isActive){
|
|
this->isActive = isActive;
|
|
}
|
|
|
|
void Layer::assignPhysicalVolume(G4VPhysicalVolume* physicalVolume){
|
|
this->physicalVolume = physicalVolume;
|
|
}
|
|
|
|
GeometryDescriptor::~GeometryDescriptor() {
|
|
if(g4system != nullptr){
|
|
if(this == g4system->assigned_cw){ //unassign
|
|
g4system->assigned_cw = nullptr;}
|
|
}
|
|
};
|
|
|
|
void GeometryDescriptor::addLayer(double thickness, std::string material, bool isActive, int nx, int ny){
|
|
if(ny<0){
|
|
ny = nx;
|
|
}
|
|
|
|
Layer layer;
|
|
layer.setThickness(thickness);
|
|
layer.setMaterial(material);
|
|
layer.setIsActive(isActive);
|
|
if(!isActive){
|
|
nx = 1;
|
|
ny = 1;
|
|
}
|
|
layer.setNx(nx);
|
|
layer.setNy(ny);
|
|
layer.sens_xwidth = xywidth/(float)nx;
|
|
layer.sens_ywidth = xywidth/(float)ny;
|
|
layers.push_back(layer);
|
|
}
|
|
|
|
|
|
void GeometryDescriptor::resetSensorEnergies()const {
|
|
for(const auto & layer : layers){
|
|
for(const auto & sensor : layer.sensors){
|
|
sensor.energy = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
Layer* GeometryDescriptor::getLayerByVolume(G4VPhysicalVolume* volume){
|
|
for(auto & layer : layers){
|
|
if(layer.physicalVolume == volume){
|
|
return &layer;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
const Layer* GeometryDescriptor::getLayerByVolume(G4VPhysicalVolume* volume)const{
|
|
for(auto & layer : layers){
|
|
if(layer.physicalVolume == volume){
|
|
return &layer;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
Sensor* GeometryDescriptor::getSensorByVolume(G4VPhysicalVolume* volume){
|
|
int copyNo = volume->GetCopyNo();
|
|
auto layer = getLayerByVolume(volume);
|
|
if(layer == nullptr){
|
|
return nullptr;
|
|
}
|
|
if(copyNo >= layer->sensors.size()){
|
|
return nullptr;
|
|
}
|
|
return &layer->sensors[copyNo];
|
|
}
|
|
|
|
const Sensor* GeometryDescriptor::getSensorByVolume(G4VPhysicalVolume* volume)const{
|
|
int copyNo = volume->GetCopyNo();
|
|
auto layer = getLayerByVolume(volume);
|
|
if(layer == nullptr){
|
|
return nullptr;
|
|
}
|
|
if(copyNo >= layer->sensors.size()){
|
|
return nullptr;
|
|
}
|
|
return &layer->sensors[copyNo];
|
|
}
|
|
|
|
|
|
void GeometryDescriptor::printSensorEnergies()const{
|
|
for(const auto& layer: layers){
|
|
for(const auto& sensor: layer.sensors){
|
|
G4cout << sensor.energy << " ";
|
|
}
|
|
G4cout << G4endl;
|
|
}
|
|
} |