Commit 264fb94b authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Allow multiple detector roles

parent 563fec7a
Pipeline #574166 passed with stages
in 8 minutes and 34 seconds
......@@ -21,19 +21,24 @@
using namespace ROOT::Math;
using namespace corryvreckan;
Detector::Detector(const Configuration& config) {
Detector::Detector(const Configuration& config) : m_role(DetectorRole::NONE) {
// Role of this detector:
auto role = config.get<std::string>("role", "none");
std::transform(role.begin(), role.end(), role.begin(), ::tolower);
if(role == "none") {
m_role = DetectorRole::NONE;
} else if(role == "reference") {
m_role = DetectorRole::REFERENCE;
} else if(role == "dut") {
m_role = DetectorRole::DUT;
} else {
throw InvalidValueError(config, "role", "Detector role does not exist.");
auto roles = config.getArray<std::string>("role", std::vector<std::string>{"none"});
for(auto& role : roles) {
std::transform(role.begin(), role.end(), role.begin(), ::tolower);
if(role == "none") {
m_role |= DetectorRole::NONE;
LOG(ERROR) << config.getName() << " is none";
} else if(role == "reference") {
LOG(ERROR) << config.getName() << " is reference";
m_role |= DetectorRole::REFERENCE;
} else if(role == "dut") {
LOG(ERROR) << config.getName() << " is dut";
m_role |= DetectorRole::DUT;
} else {
throw InvalidValueError(config, "role", "Detector role does not exist.");
}
}
// Detector position and orientation
......@@ -86,11 +91,11 @@ Detector::Detector(const Configuration& config) {
}
bool Detector::isReference() {
return m_role == DetectorRole::REFERENCE;
return static_cast<bool>(m_role & DetectorRole::REFERENCE);
}
bool Detector::isDUT() {
return m_role == DetectorRole::DUT;
return static_cast<bool>(m_role & DetectorRole::DUT);
}
// Functions to set and check channel masking
......@@ -182,10 +187,16 @@ Configuration Detector::getConfiguration() {
config.set("type", m_detectorType);
// Store the role of the detector
if(m_role == DetectorRole::REFERENCE) {
config.set("role", "reference");
} else if(m_role == DetectorRole::DUT) {
config.set("role", "dut");
std::vector<std::string> roles;
if(this->isDUT()) {
roles.push_back("dut");
}
if(this->isReference()) {
roles.push_back("reference");
}
if(!roles.empty()) {
config.setArray("role", roles);
}
config.set("position", m_displacement, {"um", "mm"});
......
......@@ -30,12 +30,30 @@ namespace corryvreckan {
/**
* @brief Role of the detector
*/
enum class DetectorRole {
NONE = 0, ///< No specific detector role
REFERENCE, ///< Reference detector
DUT, ///< Detector used as device under test
enum class DetectorRole : int {
NONE = 0x0, ///< No specific detector role
REFERENCE = 0x1, ///< Reference detector
DUT = 0x2, ///< Detector used as device under test
};
inline constexpr DetectorRole operator&(DetectorRole x, DetectorRole y) {
return static_cast<DetectorRole>(static_cast<int>(x) & static_cast<int>(y));
}
inline constexpr DetectorRole operator|(DetectorRole x, DetectorRole y) {
return static_cast<DetectorRole>(static_cast<int>(x) | static_cast<int>(y));
}
inline DetectorRole& operator&=(DetectorRole& x, DetectorRole y) {
x = x & y;
return x;
}
inline DetectorRole& operator|=(DetectorRole& x, DetectorRole y) {
x = x | y;
return x;
}
/**
* @brief Detector representation in the reconstruction chain
*
......@@ -53,7 +71,6 @@ namespace corryvreckan {
const std::string name() const { return m_detectorName; }
// Detector role and helper functions
DetectorRole role() { return m_role; }
bool isReference();
bool isDUT();
......
......@@ -135,12 +135,12 @@ void ModuleManager::load_detectors() {
auto det_parm = std::make_shared<Detector>(detector);
// Check if we already found a reference plane:
if(found_reference && det_parm->role() == DetectorRole::REFERENCE) {
if(found_reference && det_parm->isReference()) {
throw InvalidValueError(global_config, "detectors_file", "Found more than one reference detector");
}
// Switch flag if we found the reference plane:
if(det_parm->role() == DetectorRole::REFERENCE) {
if(det_parm->isReference()) {
found_reference = true;
m_reference = det_parm;
}
......
......@@ -164,7 +164,7 @@ void EventLoaderTimepix3::initialise() {
// Calibration
pixelToT_beforecalibration = new TH1F("pixelToT_beforecalibration", "pixelToT_beforecalibration", 100, 0, 200);
if(m_detector->role() == DetectorRole::DUT && m_config.has("calibrationPath") && m_config.has("threshold")) {
if(m_detector->isDUT() && m_config.has("calibrationPath") && m_config.has("threshold")) {
LOG(INFO) << "Applying calibration from " << calibrationPath;
applyCalibration = true;
......
......@@ -97,7 +97,7 @@ void Prealignment::finalise() {
<< " , RMS Y = " << Units::display(rmsY, {"mm", "um"});
}
if(m_detector->role() != DetectorRole::REFERENCE) {
if(m_detector->isReference()) {
double mean_X = correlationX->GetMean();
double mean_Y = correlationY->GetMean();
LOG(INFO) << "Detector " << m_detector->name() << ": x = " << Units::display(mean_X, {"mm", "um"})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment